Boolean Expressions - Maple Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Programming : Logic : Operations : boolean

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 , , 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&equals;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

a:=true&colon;b:=false&colon;c:=true&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)

c:=1<2

c:=1<2

(10)

evalbc

true

(11)

ifcthen1else0end if

1

(12)

a:=true&colon;

b:=FAIL&colon;

aorb

true

(13)

aandb

FAIL

(14)

notb

FAIL

(15)

is&gamma;&comma;real

true

(16)

is&gamma;&comma;rational

FAIL

(17)

See Also

equation, evalb, FAIL, Logic, operators[precedence], type, type/boolean, type/logical, type/truefalse


Download Help Document

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam