Boolean Expressions
Description
Evaluation
Boolean Types
Thread Safety
Examples
Boolean expressions are formed by using the logical operators and, or, not, implies, and xor (exclusive disjunction), and the relational operators <, <=, >, >=, =, and <>.
In 2-D math, the relational operators <=, >=, and <> display as ≤, ≥, and ≠.
For information on the order of precedence of these operators, see operators/precedence.
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 falsity. 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 evaluated to a truth value (one of true, false, or FAIL). 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 evaluation of expressions involving the logical operators uses the McCarthy evaluation rules (also called short-circuit evaluation). 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
if⁢d≠0⁢and⁢fdd>1⁢then⁢…⁢end⁢if
does not cause a division by zero error when d=0, because when that condition holds, then the left operand of and becomes false and the right operand of and will not be evaluated.
Truth Table for Logical Operators
The evaluation of a logical expression yields true, false, or FAIL according to the following table.
and
or
not
true
false
FAIL
xor
implies
An expression is of type boolean if it is of type logical, type relation or one of the Boolean constants true, false, or FAIL.
An expression is of type logical if it is of type `and`, `or`, `xor`, `implies`, or `not`.
An expression is of type relation if it is of type `=`, `<>`, `<`, or `<=`.
Note: Expressions formed using the operators > and >= are automatically converted to expressions using `<` and `<=`, respectively.
The boolean operators are thread safe as of Maple 15.
For more information on thread safety, see index/threadsafe.
a≔true:b≔false:c≔true:
aorb
aandb
aandc
nota
axorb
axorc
aorborc
aandbandc
aandnotbandc
c≔1<2
evalb⁡c
ifcthen1else0endif
1
a≔true:
b≔FAIL:
notb
is⁡γ,real
is⁡γ,rational
See Also
equation
evalb
Logic
operators/precedence
type
type/boolean
type/logical
type/truefalse
Download Help Document