3.3 Boolean Expressions

A boolean expression returns a truth value. In the algebraic mode of REDUCE, boolean expressions have the syntactical form:

expressionrelational operatorexpression


boolean operator(arguments)


boolean expressionlogical operatorboolean 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.


        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.