hermann on Sat, 06 Jul 2024 12:14:38 +0200 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: How to generate wolframscript "PowersRepresentations[...]" output in PARI/GP |
On 2024-03-11 15:30, hermann@stamm-wilbrandt.de wrote:
... While wolframscript is free on Raspberry computers, a license is needed for other computers. So I implemented "it" from scratch in PARI/GP to have no dependency. With "it" I mean I implemented for p=2 only, and renamed accordingly. It creates unique entries with non-negative non-decreasing values: hermann@7950x:~$ cat SquaresRepresentations.gp SquaresRepresentations(n,k,a=0)={ my(R=List(),m=sqrtint(n\k)); if(k==1,return(if(m>=a&&n==m^2,[m],[])));for(b=a,m,foreach(SquaresRepresentations(n-b^2,k-1,b),s,listput(R,concat([b],s))));Vec(R); } n=eval(getenv("n")); print(SquaresRepresentations(n,4)); hermann@7950x:~$ hermann@7950x:~$ n=17*29 gp -q < SquaresRepresentations.gp [[0, 0, 3, 22], [0, 0, 13, 18], [0, 4, 6, 21], [0, 5, 12, 18], [1, 2, 2, 22], [1, 10, 14, 14], [2, 2, 14, 17], [2, 5, 8, 20], [2, 8, 8, 19], [2, 8, 13, 16], [2, 10, 10, 17], [3, 4, 12, 18], [3, 12, 12, 14], [4, 4, 10, 19], [4, 5, 14, 16], [4, 10, 11, 16], [6, 6, 14, 15], [6, 12, 12, 13], [8, 8, 13, 14]] hermann@7950x:~$
I enhanced above script and made it a gist with version control: https://gist.github.com/Hermann-SW/18423ac08eda224dd06683883c7b10acAbove output gave all non-negative monotonic increasing sums of k squares (≥a).
Gist allows to return all (signed+permuted) versions as in addition. Or only the count of all determined sums of k squares, which is r_k(n). In case k==3, sum of 3 squares function for n https://en.wikipedia.org/wiki/Sum_of_squares_function#k_=_3 is asserted to be the count determined by script (for verification). Regards, Hermann.