Boolean - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


Boolean Expressions

 

Description

Evaluation

Boolean Types

Thread Safety

Examples

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 , , and .

• 

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

ifd0andfdd>1thenendif

  

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 `=`, `<>`, `<`, or `<=`.

• 

Note: Expressions formed using the operators > and >= are automatically converted to expressions using `<` and `<=`, respectively.

Thread Safety

• 

The boolean operators are thread safe as of Maple 15.

• 

For more information on thread safety, see index/threadsafe.

Examples

atrue&colon;bfalse&colon;ctrue&colon;

aorb

true

(1)

aandb

false

(2)

aandc

true

(3)

nota

false

(4)

axorb

true

(5)

axorc

false

(6)

aorborc

true

(7)

aandbandc

false

(8)

aandnotbandc

true

(9)

c1<2

c1<2

(10)

evalbc

true

(11)

ifcthen1else0endif

1

(12)

atrue&colon;

bFAIL&colon;

aorb

true

(13)

aandb

FAIL

(14)

notb

FAIL

(15)

isγ&comma;real

true

(16)

isγ&comma;rational

FAIL

(17)

See Also

equation

evalb

FAIL

Logic

operators/precedence

type

type/boolean

type/logical

type/truefalse