Subsections

Compound Boolean formulæ

Formulæ yielding TRUE or FALSE can be combined. For example, here is a formula which tests whether π lies between 3 and 4

   pi > 3 & pi < 4

which yields TRUE. The priorities of <, > and & are so defined that parentheses are unnecessary in this case. Likewise, we may write

   "ab" < "aac" OR 3 < 2

which yields FALSE. More complicated formulæ can be written:

   3.4 > 2 & "a" < "c" OR "b" >= "ab"

which yields TRUE. Because the priority of the operator & is higher than the priority of OR, the & in the above formula is elaborated first. The order of elaboration can be changed using parentheses.

There does not seem much point to these formulæ since everything is known beforehand, but all will become clear in the next chapter.

Compound Boolean formulæ can be confusing. Being aware of the converse of a compound condition helps you to ensure you have considered all possibilities. For example, the converse of the formula

   a < b & c = d

is the formula

   a >= b OR c /= d

One of the formulæ would yield TRUE and the other FALSE.


Exercises

4.3
What is the value of each of the following: Ans[*]
(a)
NOT ODD 3 OR 3 < 4

(b)
3 > 2 & (5 > 12 OR 7 <= 8)

(c)
(TRUE OR FALSE) AND (FALSE OR TRUE)

(d)

(e)
3<4 & 4<5 & 5<6 & 6>7

4.4
For each condition, write out its converse: Ans[*]
(a)
FALSE

(b)
4 > 2

(c)
a > b AND b > c

(d)
x = y OR x = z


Sian Mountbatten 2012-01-19