Ruud H.G. van Tol on Wed, 03 Jan 2024 18:16:37 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: Can I speed up / reduce the stack used by this PARI/GP script?



On 2024-01-03 02:13, Joe Slater wrote:
I wrote the following script to calculate terms of A060322. It does a
decent job, but takes a lot of memory: at present I can only calculate
around 70 terms. Can anyone suggest a way to push it further?


The first differences are in A131450.

A direct port of a variant of Jon E. Schoenfield's Magma-code there to PARI:

first(N) = {
  my( a= Vec([1, 0, 0, 0], N), Y= [], X= [5], Z );
  for( n=5, N
  , Z= Y;
    Y= X;
    X= List();
    foreach( Z, x,             listput(X, 4*x+1     ));
    foreach( Z, x, if( 1==x%6, listput(X, (4*x-1)\3)));
    foreach( Y, x, if( 5==x%6, listput(X, (2*x-1)\3)));
    X= Set(X);
    a[n]= #X;
 \\ print1( n, "=", a[n], ", " );
  );
  a;
}



? default(parisizemax,2^33)
  ***   Warning: new maximum stack size = 8589934592 (8192.000 Mbytes).

Then, this first(70) takes about 6 minutes, using 4 GB RAM.

For comparison, your A060322(70) takes about 4 minutes here, using 8 GB RAM.
So that delta-approach isn't really getting it much further.

-- Ruud