Up | Next | Prev | PrevTail | Tail |
A boolean expression returns a truth value. In the algebraic mode of REDUCE, boolean expressions have the syntactical form:
or
(
\(\langle \)arguments\(\rangle \))
or
Parentheses can also be used to control the precedence of expressions.
In addition to the logical and relational operators defined earlier as infix operators, the
following boolean operators are also defined:
evenp(u) | determines if the number |
fixp(u) | determines if the expression |
freeof(u,v) | determines if the expression |
numberp(u) | determines if |
ordp(u,v) | determines if |
primep(u) | true if |
Examples:
j<1 x>0 or x=-2 numberp x fixp x and evenp x numberp x and x neq 0
Boolean expressions can only appear directly within if
, for
, while
, and until
statements, as described in other sections. Such expressions cannot be used in place of
ordinary algebraic expressions, or assigned to a variable.
NB: For those familiar with symbolic mode, the meaning of some of these operators is
different in that mode. For example, numberp
is true only for integers and reals in
symbolic mode.
When two or more boolean expressions are combined with and
, they are evaluated one
by one until a false expression is found. The rest are not evaluated. Thus
numberp x and numberp y and x>y
does not attempt to make the x>y
comparison unless x
and y
are both verified to be
numbers.
Similarly, evaluation of a sequence of boolean expressions connected by or
stops as
soon as a true expression is found.
NB: In a boolean expression, and in a place where a boolean expression is expected, the algebraic value 0 is interpreted as false, while all other algebraic values are converted to true. So in algebraic mode a procedure can be written for direct usage in boolean expressions, returning say 1 or 0 as its value as in
procedure polynomialp(u,x); if den(u)=1 and deg(u,x)>=1 then 1 else 0;
One can then use this in a boolean construct, such as
if polynomialp(q,z) and not polynomialp(q,y) then ...
In addition, any procedure that does not have a defined return value (for example, a block
without a return
statement in it) has the boolean value false.
Up | Next | Prev | PrevTail | Front |