3.4 Algebraic evaluator: reval, aeval, aeval*

The main entries to the algebraic evaluator are the symbolic mode functions reval and aeval. Both have as input an algebraic expression and return the fully evaluated result. Reval always returns an algebraic form in full prefix operator form, while aeval tries to keep the result in *SQ-form whenever possible. Almost all algebraic functionality of REDUCE can be invoked by calling these procedures, e.g.

  reval ’(solve (plus (expt x 2) 3) x);

If you turn on the switch defn in algebraic mode you will see that REDUCE translates most statements into calls for aeval.

Reval and aeval are also adequate tools for accessing the values of algebraic quantities and for evaluation of unevaluated procedure parameters; they do the complete job for you.

However, there is one exception: the left-hand side of an equation in general is not evaluated by reval and aeval. E.g. 

    l:= a=b;  
    a:=17;b:=4;  
    symbolic reval ’l;

produces the output (EQUAL A 4). If you write a program for equations you either should evaluate the left-hand sides yourself by calling reval or rebind the internal switch *evallhseqp 8 locally(!) by t - then REDUCE will evaluate both sides of an equation.

REDUCE maintains an internal buffer alglist* where all evaluation results are stored such that a repeated request for the same evaluation can be satisfied by a simple and fast table lookup9 . As a side effect, aeval resets alglist* empty before starting a computation10 . There is a second function aeval*: this function performs the same operation, but in contrast to aeval it does not reset alglist* and can profit from previous results. The REDUCE uses both, aeval and aeval* depending of the specific environment of a translated statement.