Up | Prev | PrevTail | Tail |
Setting the remember option for an algebraic procedure by
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–effects.
The following examples show the effect 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 |