Bill Allombert on Wed, 03 Jan 2024 11:33:02 +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 Wed, Jan 03, 2024 at 12:13:52PM +1100, 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?
> 
> A060322(n)= /* Provide an array from 1..n of the number of integers with a
> stopping time of _n_ */
> {
>     my(v=vector(n,i,[]));
>     v[1]=[1];
>     my(v2=v3=v4=[]);
>     if(n>4,
>         for(x=5,n,
>             v2=vector(x-1,i,[(x-1)/3| x<-2^(x-i)*v[i],(x%3)==1]);

Just an advice: you are using x for two different loop indices which makes
you code a bit difficult to read.

v2=vector(x-1,i,[(y-1)/3| y<-2^(x-i)*v[i],(y%3)==1]);
is easier to understand.

Now the computational problem is that the vector v2 become exponentially large with n.
I do not know how to avoid that.

Cheers,
Bill