Yet another way of specifying logic functions is to use programming language constructs such as WHEN-THEN-ELSE. If we want to use this construct instead of the Boolean expressions stated earlier we would replace the EQUATIONS section by :
EQUATIONS
WHEN (month == 2) THEN { "if its February
WHEN (leap == 1) THEN "and its a leap year
days = [0,1,0,0]; "then its 29 days
ELSE
days = [1,0,0,0]; "otherwise its 28 days
}
ELSE {
WHEN ( (month == 4) # (month == 6) # (month == 9) # (month == 11) ) THEN
days = [0,0,1,0]; "cases where its 30 days
ELSE days = [0,0,0,1]; "31 days for others regardless of month }
Now, if we compile the equations as we did for the truth table method we'll see that minimized equations are not exactly same as before. The reason is that, in the truth table method we used don't cares .X. whereas here we are asking for the output to be [0,0,0,1] for all cases besides 2, 4, 6, 9, 11. Hence, the compiled equations look like:
Equations:
d28 = ( !leap & !m1 & m2 & !m4 & !m8);
d29 = ( leap & !m1 & m2 & !m4 & !m8);
d30 = ( !m1 & m4 & !m8 # m1 & !m4 & m8);
d31 = ( !m2 & !m4 & !m8 # m4 & m8 # m1 & !m8 # !m1 & m8);
In the above compiled equations, note that although the equations for d28, d29, and d30 are the same, the equation for d31 is quite different. In fact it includes 0,13,14, and 15. In order to get the same equations as before we need to specify that we don't care what the values are for 0, 13, 14 and 15. We can do that as follows:
EQUATIONS
WHEN (month == 2) THEN { "if its February
WHEN (leap == 1) THEN "and its a leap year
days = [0,1,0,0]; "then its 29 days
ELSE
days = [1,0,0,0]; "otherwise its 28 days
}
ELSE {
WHEN ( (month == 4) # (month == 6) # (month == 9) # (month == 11) ) THEN
days = [0,0,1,0]; "cases where its 30 days
ELSE WHEN ( (month == 1) # (month == 3) # (month == 5) # (month == 7) # (month == 8) # (month == 10) # (month == 12) ) THEN
days = [0,0,0,1]; "cases where its 31 days
ELSE days = [.X.,.X.,.X.,.X.]; "don't care about others
}
The compiled equations now obtained should be the same as we are providing the same information.