#C6.txt, Feb. 8, 2016, Dr. Z.'s ExpMath class RU (Spring 2016) #c=introducing Dr. Z.'s second-most favorite "ansatz" Help:=proc() print(` RecToSeq(R,N), RecToSeqW(R,N,w)`): end: #RecToSeq(R,N): inputs a C-finite sequence [ini,rec] where ini is a list #of numbers of length k say, and rec is a list of coefficients of the #C-finite sequence defined UNIQELY by #x(n)=ini[n+1], for n=0..k-1, #and rec is a list of numbers [c1,c2,...,ck] #and for n>=k defined recursively by #x(n)=c1*x(n-1)+c2*x(n-2)+...+ck*x(n-k). #For example the sequence 2^n is coded as #[[1],[2]], and the sequence of Fib. numbers are given by #[[0,1],[1,1]] #It outputs the list consisting of the first N terms of that sequence starting at n=0 RecToSeq:=proc(R,N) local ini,rec,Se,k,n,nt: ini:=R[1]: rec:=R[2]: k:=nops(ini): if nops(rec)<>k then RETURN(FAIL): fi: Se:=ini: for n from k+1 to N do #nt:=c1*Se[n]+c2*Se[n-1]+...+ ck*se[n-k+1] nt:=add(rec[i]*Se[n-i],i=1..k): Se:=[op(Se),nt]: od: Se: end: #RecToSeqW(R,N,w): inputs a C-finite sequence [ini,rec] where ini is a list #of numbers of length k say, and rec is a list of coefficients of the #C-finite sequence defined UNIQELY by #x(n)=ini[n+1], for n=0..k-1, #and rec is a list of numbers [c1,c2,...,ck] #and for n>=k defined recursively by #x(n)=c1*x(n-1)+c2*x(n-2)+...+ck*x(n-k). #For example the sequence 2^n is coded as #[[1],[2]], and the sequence of Fib. numbers are given by #[[0,1],[1,1]] #It outputs the list consisting of the terms N-w+1 through w of that sequence starting at n=N-w+1 RecToSeqW:=proc(R,N,w) local ini,rec,Se,k,n,nt: ini:=R[1]: rec:=R[2]: k:=nops(ini): if nops(rec)<>k then RETURN(FAIL): fi: if w