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
.
NOT ODD 3 OR 3 < 4
3 > 2 & (5 > 12 OR 7 <= 8)
(TRUE OR FALSE) AND (FALSE OR TRUE)
3<4 & 4<5 & 5<6 & 6>7
FALSE
4 > 2
a > b AND b > c
x = y OR x = z
Sian Mountbatten 2012-01-19