loda-cpp
loda-cpp copied to clipboard
Vector-based PARI output
For faster computation using PARI, use vectors to cache previously computed terms, e.g. for a(n)=if(n<2,1,a(n-1)+a(n-2)) use
a(n)=
{
my(V=vector(n));
V[1]=1; V[2]=1;
for(i=3, n,
V[i] = V[i-1] + V[i-2]
);
V;
}
simple test for two vectors:
? V=vector(10)
%1 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
? W=vector(10)
%2 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
? V[1]=1
%3 = 1
? W[1]=1
%4 = 1
? for(i=2, 10, V[i]=V[i-1]+W[i-1]; W[i]=i)
? V
%6 = [1, 2, 4, 7, 11, 16, 22, 29, 37, 46]
? W
%7 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Preparation work done:
$ ./loda export -o pari-vector A58
(a[n] = b[n]+1); (b[n] = b[n-1]*(b[n-1]+1)); (b[0] = 1)