Up Next Prev PrevTail Tail

#### 2.3 Evaluation model, symbols, and variables

The main difference between algebraic and symbolic mode lies in the evaluation model:

• In algebraic mode a symbol stands for itself as unknown as long as no value is assigned; after an assignment it plays the role of a representative for that value just like a variable in a standard programming language:
1: x;
X
2: x:=y+1\$
3: x;
Y + 1

In symbolic mode there is a clear barrier between the role of a symbol as variable of the programming language RLISP, a named item which represents some variable value, and the role to be part of an algebraic expression. If you mean the symbol x you must write x; without the quote tag x is considered as variable x and it will be asked for its value which is NOT x initially. Uninitialized variables cause bugs.

• Consequently all variables must be declared.
• In algebraic mode u := (x + 1)2; 1 means it compute a formula by expanding (x+1)*(x+1); if a value had been assigned to x, substitute the value for x. In symbolic mode an algebraic expression is interpreted as statement to compute a numeric value, just like in C or Pascal. So u := (x + 1)2; in symbolic mode means: “take the value of variable x which is expected to be number, add 1, square and assign the resulting number to the variable u”.
• If you want to refer to an algebraic expression as a data object, you must code it as an algebraic form (see below) and mark it as constant by a quote character. The only constants which don’t need a quote are numbers and strings. Example:
u:=’(expt (plus x 1) 2);

assigns the (algebraic) expression (x + 1)2 to the variable u.

• algebraic mode implicitly supports standard arithmetic and algebraic evaluation for mathematical expressions of arbitrary complexity and for numbers from various domains. In symbolic mode, arithmetic with infix operators + - *is supported only for the basic LISP numbers (mainly integers). All arithmetic for formulas, even for domain elements such as rounded numbers, complex numbers etc. has to be performed by calling explicitly the functions which can do that job or by calling explicitly the REDUCE evaluator reval resp aeval (see below).

So symbolic mode programs are much more similar to programs in conventional programming languages such as Pascal or C. All algebraic functionality of REDUCE is available only as an explicit subroutine interface. In contrast to algebraic mode nothing is done implicitly for you.

 Up Next Prev PrevTail Front