hermann on Tue, 05 Sep 2023 18:05:29 +0200


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

Questions on PARI/GP formatting


There seems to be no PARI/GP formatter tool:
https://pari.math.u-bordeaux.fr/archives/pari-dev-2308/msg00029.html

I added "\" suffix for multiline functions.
Is there a simpler way?

I added whitespace where it helped me, but overall it is not consistent.
Are there best practices wrt GP optional whitespace use?

I use "break", should it be "break()" instead?

Is there a GP formatting best practices document?


GP gist (determines sqrt(-1) (mod n) for rsa semiprime n and verifies by squaring):
https://gist.github.com/Hermann-SW/50514eaf06b4d91ec6bcee5e49732dff

\r RSA_numbers_factored

test(v) = {\
  if(#v < 4, break);\
  [l,n,p,q] = v;\
  if ((p%4 != 1) || (q%4 != 1), break);\
  forprime(t=2, oo, if(kronecker(t, p)==-1, pnr=t;break) );\
  forprime(t=2, oo, if(kronecker(t, q)==-1, qnr=t;break) );\
r=centerlift( chinese( Mod(pnr, p)^((p-1)/4), Mod(qnr, q)^((q-1)/4) )^2 );\
  print(l," ",r);\
};

foreach(rsa, v, test(v))


Output:

hermann@i7-11850h:~/RSA_numbers_factored/pari$ gp -q < rsa_test.gp
validate(rsa): ✓
59 -1
129 -1
180 -1
230 -1
768 -1
hermann@i7-11850h:~/RSA_numbers_factored/pari$


Regards,

Hermann.