REDUCE

21 Symbolic Mode

At the system level, REDUCE is based on a version of the programming language Lisp known as Standard Lisp which is described in [MHGG80]. We shall assume in this section that the reader is familiar with the material in that paper. This also assumes implicitly that the reader has a reasonable knowledge about Lisp in general, say at the level of the LISP 1.5 Programmer’s Manual ([MAE\(^{+}\)62]) or any of the books mentioned at the end of this section. Persons unfamiliar with this material will have some difficulty understanding this section.

Although REDUCE is designed primarily for algebraic calculations, its source language is general enough to allow for a full range of Lisp-like symbolic calculations. To achieve this generality, however, it is necessary to provide the user with two modes of evaluation, namely an algebraic mode and a symbolic mode. To enter symbolic mode, the user types symbolic; (or lisp;) and to return to algebraic mode one types algebraic;. Evaluations proceed differently in each mode so the user is advised to check what mode he is in if a puzzling error arises. He can find his mode by typing

        eval_mode;

The current mode will then be printed as algebraic or symbolic.

Expression evaluation may proceed in either mode at any level of a calculation, provided the results are passed from mode to mode in a compatible manner. One simply prefixes the relevant expression by the appropriate mode. If the mode name prefixes an expression at the top level, it will then be handled as if the global system mode had been changed for the scope of that particular calculation.

For example, if the current mode is algebraic, then the commands

        symbolic car ’(a);
        x+y;

will cause the first expression to be evaluated and printed in symbolic mode and the second in algebraic mode. Only the second evaluation will thus affect the expression workspace. On the other hand, the statement

        x + symbolic car ’(12);

will result in the algebraic value X+12.

The use of symbolic (and equivalently algebraic) in this manner is the same as any operator. That means that parentheses could be omitted in the above examples since the meaning is obvious. In other cases, parentheses must be used, as in

        symbolic(x := ’a);

Omitting the parentheses, as in

        symbolic x := a;

would be wrong, since it would parse as

        symbolic(x) := a;

For convenience, it is assumed that any operator whose first argument is quoted is being evaluated in symbolic mode, regardless of the mode in effect at that time. Thus, the first example above could be equally well written:

        car ’(a);

Except where explicit limitations have been made, most REDUCE algebraic constructions carry over into symbolic mode. However, there are some differences. First, expression evaluation now becomes Lisp evaluation. Secondly, assignment statements are handled differently, as we shall discuss shortly. Thirdly, local variables and array elements are initialized to nil rather than 0. (In fact, any variables not explicitly declared integer are also initialized to nil in algebraic mode, but the algebraic evaluator recognizes nil as 0.) Finally, function definitions follow the conventions of Standard Lisp.

To begin with, we mention a few extensions to our basic syntax which are designed primarily if not exclusively for symbolic mode.

 21.1 Symbolic Infix Operators
 21.2 Symbolic Expressions
 21.3 Quoted Expressions
 21.4 Lambda Expressions
 21.5 Symbolic Assignment Statements
 21.6 FOR EACH Statement
 21.7 Symbolic Procedures
 21.8 Standard Lisp Equivalent of REDUCE Input
 21.9 Communicating with Algebraic Mode
 21.10 Rlisp ’88
 21.11 References

Hosted by Download REDUCE Powered by MathJax