Bill Allombert on Mon, 02 Oct 2023 20:54:42 +0200


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

Re: How to generate wolframscript "PowersRepresentations[...]" output in PARI/GP


On Mon, Oct 02, 2023 at 08:38:54PM +0200, hermann@stamm-wilbrandt.de wrote:
> https://reference.wolfram.com/language/ref/PowersRepresentations.html
> "PowersRepresentations[n,k,p]
>     gives the distinct representations of the integer n as
>     a sum of k non-negative p^(th) integer powers."
> 
> I searched for all hits for "powers" and "representations" in GP user
> manual and found nothing. How to compute sum of 4 squares of here
> 17*29 semiprime with PARI/GP by using any builtin function?

If you want only one solution, you can do

foursquare(n) = abs(qfsolve(matdiagonal([1,1,1,1,-n]))[1..4]);

? foursquare(17*29)
%15 = [0,0,13,18]~

? foursquare(2^127-1)
%13 = [3485713606461563310,6176908041673972933,4510469025815889567,9974590734764851407]~

Cheers,
Bill