A boolean expression returns a truth value. In the algebraic mode of REDUCE, boolean expressions have the syntactical form:
⟨boolean expression⟩⟨logical operator⟩⟨boolean expression⟩.
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:
determines if the number U is even or not;
determines if the expression U is integer or not;
determines if the expression U does not contain the kernel V anywhere in its structure;
determines if U is a number or not;
determines if U is ordered ahead of V by some canonical ordering (based on the expression structure and an internal ordering of identifiers);
true if U is a prime object, i.e., any object other than 0 and plus or minus 1 which is only exactly divisible by itself or a unit.
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
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
One can then use this in a boolean construct, such as
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.