For example I use the case of a finite continued fraction.
Defining the recurrence like this:
remarray(P)$
P[0]:a[0];
P[n]:=a[n]+1/P[n-1];
Asking for a depth of 3:
P[3];
Results is:
depth is 3, numbering of indices is bottom up
On can ask for a different depth, any time:
P[4];
Result is:
depth is 4, numbering of indices is bottom up
How can one write a similar definition that has the numbering of indices reverted like this:
depth is 3, numbering of indices is top down
Asking for a different depth should be possible, without extra efford.
depth is 4, numbering of indices is top down
I tried:
kill(M)$
remarray(P)$
P[0]:a[M];
P[n]:=a[M-n]+1/P[n-1];
P[3]$
%,M=3;
P[4]$
%,M=4;
Result is ok, but I don't like the extra symbol M. enter image description here
Here's a possibility. I use
subst
to substitute a new value into the most deeply nested term.Calling
subst
is a little clumsy; maybe there is a more elegant way.