 Boolean - Maple Help

Boolean Expressions Description

 • 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 $\le$, $\ge$, and $\ne$.
 • For information on the order of precedence of these operators, see operators[precedence]. Evaluation

 • 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

$\mathbf{if}d\ne 0\mathbf{and}\frac{f\left(d\right)}{d}>1\mathbf{then}\dots \mathbf{end}\mathbf{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 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 Boolean Types

 • 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 $\mathrm{=}$, $\mathrm{<>}$, $\mathrm{<}$, or $\mathrm{<=}$.
 • 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. Examples

 > $a≔\mathrm{true}:$$b≔\mathrm{false}:$$c≔\mathrm{true}:$
 > $a\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{or}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}b$
 ${\mathrm{true}}$ (1)
 > $a\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{and}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}b$
 ${\mathrm{false}}$ (2)
 > $a\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{and}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}c$
 ${\mathrm{true}}$ (3)
 > $\mathbf{not}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}a$
 ${\mathrm{false}}$ (4)
 > $a\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{xor}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}b$
 ${\mathrm{true}}$ (5)
 > $a\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{xor}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}c$
 ${\mathrm{false}}$ (6)
 > $a\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{or}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}b\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{or}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}c$
 ${\mathrm{true}}$ (7)
 > $a\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{and}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}b\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{and}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}c$
 ${\mathrm{false}}$ (8)
 > $a\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{and}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{not}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}b\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{and}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}c$
 ${\mathrm{true}}$ (9)
 > $c≔1<2$
 ${c}{≔}{1}{<}{2}$ (10)
 > $\mathrm{evalb}\left(c\right)$
 ${\mathrm{true}}$ (11)
 > $\mathbf{if}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}c\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{then}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}1\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{else}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}0\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{end if}$
 ${1}$ (12)
 > $a≔\mathrm{true}:$
 > $b≔\mathrm{FAIL}:$
 > $a\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{or}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}b$
 ${\mathrm{true}}$ (13)
 > $a\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{and}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}b$
 ${\mathrm{FAIL}}$ (14)
 > $\mathbf{not}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}b$
 ${\mathrm{FAIL}}$ (15)
 > $\mathrm{is}\left(\mathrm{gamma},\mathrm{real}\right)$
 ${\mathrm{true}}$ (16)
 > $\mathrm{is}\left(\mathrm{gamma},\mathrm{rational}\right)$
 ${\mathrm{FAIL}}$ (17)