REMEMBER Statement
Date: 2020-10-07 18:10:00

Up | Prev | PrevTail | Tail

### 15.6 REMEMBER Statement

Setting the remember option for an algebraic procedure by

REMEMBER (PROCNAME:procedure);

saves all intermediate results of such procedure evaluations, including recursive calls. Subsequent calls to the procedure can then be determined from the saved results, and thus the number of evaluations (or the complexity) can be reduced. This mode of evalation costs extra memory, of course. In addition, the procedure must be free of side–eﬀects.

The following examples show the eﬀect of the remember statement on two well–known examples.

procedure H(n); % Hofstadter’s function
if numberp n then
<< cnn := cnn +1; % counts the calls
if n < 3 then 1 else H(n-H(n-1))+H(n-H(n-2))>>;
remember h;
<< cnn := 0; H(100); cnn>>;
100
% H has been called 100 times only.
procedure A(m,n); % Ackermann function
if m=0 then n+1 else
if n=0 then A(m-1,1) else
A(m-1,A(m,n-1));
remember a;
A(3,3);

Up | Prev | PrevTail | Front