Mathematics of if-else statements

"Bora Eryilmaz" <>
5 Sep 2001 22:11:55 -0400

          From comp.compilers

Related articles
Mathematics of if-else statements (Bora Eryilmaz) (2001-09-05)
Re: Mathematics of if-else statements (Adrian 'Dagurashibanipal' von Bidder) (2001-09-10)
Re: Mathematics of if-else statements (2001-09-10)
Re: Mathematics of if-else statements (Joachim Durchholz) (2001-09-11)
Re:Mathematics of if-else statements (Dmitry Shaporenkov) (2001-09-11)
Kleene Algebra (was: Mathematics of if-else statements) (2001-09-11)
| List of all articles for this month |

From: "Bora Eryilmaz" <>
Newsgroups: comp.compilers
Date: 5 Sep 2001 22:11:55 -0400
Organization: The MathWorks, Inc., Natick, MA 01760
Keywords: optimize, question
Posted-Date: 05 Sep 2001 22:11:55 EDT

Are there any mathematical/logical approaches to analyze nested
if-else statements in order to simplify or optimize them, or to
understand the flow of successive tests. For example, if I have

if (a > 10) {
      if (a < 20) {
      } else {
} else {
where a is an integer, say.

Now, I can define the logical parameters C1 : (a>10), and C2 = (a<20)
Then I can write the truth table

C1 C2 Result
--- --- -----------
  T T statement1
  F T statement3
  T F statement2
  F F statement3

Then I can rearrange the if-else statements noting that the above truth
table can also be written as (!C1 means not(C1))

!C1 !C2 Result
--- --- -----------
  F F statement1
  T F statement3
  F T statement2
  T T statement3

so that

if (a < 10) {
} else {
        if (a > 20) {
        } else {

My point is that such an analysis tool using math/logic may help
re-organize or optimize code, but I don't claim that the above example
is very useful. So any body familiar with such tools?

Bora Eryilmaz

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.