Boolean Expressions
|
Description
|
|
•
|
Boolean expressions are formed by using the logical operators and, or, xor (exclusive disjunction), implies, and not, and the relational operators <, <=, >, >=, =, and <>.
|
•
|
Maple uses three-valued logic for all of its Boolean operations. The special names true and false are used to represent logical truth and logical false. A third special name FAIL is used to represent an expression whose truth is unknown.
|
•
|
The evalb function evaluates its argument as a Boolean expression. For example, x = x is an algebraic equation in Maple and normally it is not treated as a Boolean expression. However, evalb(x = x) evaluates to true.
|
|
Evaluation as a Boolean expression takes place automatically if the expression:
|
–
|
contains a logical operator,
|
–
|
is in the if clause of a conditional statement, or
|
–
|
is in the while clause of a repetition statement.
|
•
|
The following type names are used: `=`, `<>`, `<`, `<=`, relation (means any of the preceding four), `and`, `or`, `xor`, `implies`, `not`, and logical (means any of the preceding five).
|
|
The type boolean is defined to be any of the above or the special names true, false, and FAIL.
|
|
Note: In 1-D Math notation, the boolean type names must be enclosed in left quotes (` `) as above. In 2-D Math notation, left quotes are not necessary.
|
|
Note: Expressions that use the operators > and >= are automatically converted to expressions of type `<` and `<=`, respectively.
|
•
|
The evaluation of expressions involving the logical operators uses the McCarthy evaluation rules. Namely, the left operand of the four operators and, or, xor, implies is always evaluated first, and the evaluation of the right operand is avoided if the truth value of the expression can be deduced from the value of the left operand alone. For example, the construct
|
|
does not cause a division by zero error because if , then the left operand of and becomes false and the right operand of and will not be evaluated.
|
•
|
The evaluation of a Boolean expression yields true, false, or FAIL according to the following table.
|
|
|
|
and
|
|
|
|
or
|
|
|
not
|
|
|
true
|
false
|
FAIL
|
|
true
|
false
|
FAIL
|
|
|
true
|
|
true
|
false
|
FAIL
|
|
true
|
true
|
true
|
|
false
|
false
|
|
false
|
false
|
false
|
|
true
|
false
|
FAIL
|
|
true
|
FAIL
|
|
FAIL
|
false
|
FAIL
|
|
true
|
FAIL
|
FAIL
|
|
FAIL
|
|
|
|
|
|
xor
|
|
|
|
implies
|
|
|
|
true
|
false
|
FAIL
|
|
true
|
false
|
FAIL
|
true
|
|
false
|
true
|
FAIL
|
|
true
|
false
|
FAIL
|
false
|
|
true
|
false
|
FAIL
|
|
true
|
true
|
true
|
FAIL
|
|
FAIL
|
FAIL
|
FAIL
|
|
true
|
FAIL
|
FAIL
|
|
|
|
|
Thread Safety
|
|
•
|
The boolean operators are thread safe as of Maple 15.
|
|
|
Examples
|
|
>
|
|
>
|
|
>
|
|
>
|
|
| (1) |
>
|
|
| (2) |
>
|
|
| (3) |
>
|
|
| (4) |
>
|
|
| (5) |
>
|
|
| (6) |
>
|
|
| (7) |
>
|
|
| (8) |
>
|
|
| (9) |
>
|
|
| (10) |
>
|
|
| (11) |
>
|
|
| (12) |
>
|
|
>
|
|
>
|
|
| (13) |
>
|
|
| (14) |
>
|
|
| (15) |
|
|