Joe Slater on Wed, 03 Jan 2024 02:14:08 +0100


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

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


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]);
            v[x]=concat(v2);
        )
    );
    v3=vector(#v,i,#v[i]);
    v4=vector(#v,i,vecsum(v3[1..i]));
    return(v4)
}

All the best,
Joe Slater