LREtools
REtoproc
convert a recurrence into a procedure
Calling Sequence
Parameters
Description
Examples
REtoproc(problem, options)
problem
-
options
optional arguments described below
This procedure returns a Maple procedure that, given a non-negative integer n as input, gives the nth term of the linear recurrence.
If the argument 'remember' or 'remember'=true is specified, then the procedure will compute the sequence via a recursive procedure using option remember. By default, 'remember'=false and the sequence is computed iteratively.
The argument 'remember' should be given when one needs a large number of values of the sequence.
When 'remember'=false and the coefficients of the recurrence are nonconstant polynomials, the returned procedure will run in a straight loop, using a linear number of arithmetic operations and without wasting extra space.
When 'remember'=false and the coefficients are constant, the procedure will employ a binary-based optimization strategy (for large index values only), and runs with a logarithmic number of arithmetic operations. This optimization can be disabled by specifying constantoptimize=false.
When 'remember'=false, by default the initial terms of the recurrence are embedded in the code. This can be changed to put the initial terms of the recurrence in the remember table by specifying initialremember=true.
When the first terms of the recurrence are not explicitly supplied, they are represented symbolically.
The command with(LREtools,REtoproc) allows the use of the abbreviated form of this command.
with⁡LREtools:interface⁡verboseproc=3:
fib := REtoproc(f(i)=f(i-1)+f(i-2),f(i),{f(0)=0,f(1)=1});
fib ≔ procn::nonnegint, $locali,u0,u1,u2,a,res,l;u0 ≔ 0;u1 ≔ 1;ifn=0thenu0elifn=1thenu1elifn<=44thenforifrom2ton − 1dou2 ≔ u0+u1;u0 ≔ u1;u1 ≔ u2end do;u0+u1elsea ≔ array⁡1..2,1..2,1,1,1,0;res ≔ array⁡1..2,u1,u0;l ≔ convert⁡n − 1,'base',2;ifl[1]=1thenres ≔ array⁡1..2,1=a[1,1]*res[1]+a[1,2]*res[2],2=a[2,1]*res[1]+a[2,2]*res[2]end if;ifl=1thenres[1]elseforiinl[2..−2]doa ≔ array⁡1..2,1..2,2,2=a[1,2]*a[2,1]+a[2,2]^2,1,2=a[1,1]*a[1,2]+a[1,2]*a[2,2],2,1=a[1,1]*a[2,1]+a[2,1]*a[2,2],1,1=a[1,1]^2+a[1,2]*a[2,1];ifi=1thenres ≔ array⁡1..2,1=a[1,1]*res[1]+a[1,2]*res[2],2=a[2,1]*res[1]+a[2,2]*res[2]end ifend do;a[1,1]^2+a[1,2]*a[2,1]*res[1]+a[1,1]*a[1,2]+a[1,2]*a[2,2]*res[2]end ifend ifend proc
fib⁡100
354224848179261915075
fib2 := REtoproc(f(i)=f(i-1)+f(i-2),f(i),{f(0)=0,f(1)=1},'remember');
fib2 ≔ procn::nonnegint, $optionremember;procname⁡n − 2+procname⁡n − 1end proc
fib2⁡100
rec := REtoproc(f(i)=i^2*f(i-1)+f(i-2),f(i),{},'remember');
rec ≔ procn::nonnegint, $optionremember;n^2*procname⁡n − 1+procname⁡n − 2end proc
rec⁡100
9058477158744039108901484875567483833514619274297483550856232216805415823966784458605109749449017462079827918537250156488348819998559536412999537100386489240766568099262887636990141071242906533135806432242520067765428965147272705161620549611736618446171403767978982293333281882312513474668524116583587067499136325876⁢f⁡1+2203823124569416698291075403023306063089022127683403942005208386556556750073849332403233124551522569729148712230224505771905205727903820151912839068030542989769962446264480000034834468134656141631555555405058769399965103438352643881658179110007643158335872008434125847040069584050780045011709372240155319761920733361⁢f⁡0
See Also
LREtools[REcreate]
RESol
rsolve
Download Help Document