hermann on Fri, 23 Jun 2023 12:20:26 +0200


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

Why is "lift(Mod(qnr, n)^(n\4))" 16% slower than C libgmp "powm(r, qnr, n/4, n)" ?


My Linux gp-2.15 runs with GMP kernel:

$ gp-2.15
Reading GPRC: /etc/gprc
GPRC Done.

                  GP/PARI CALCULATOR Version 2.15.3 (released)
          amd64 running linux (x86-64/GMP-6.1.2 kernel) 64-bit version
...

I used sqrtm1.cc
https://github.com/Hermann-SW/RSA_numbers_factored/blob/main/c%2B%2B/sqrtm1.cc

to efficiently determine "sqrt(-1) (mod p)" for primes up to 1million digits.
I had to hardcode the primes in C source, a bit ugly.


Now I implemented sqrtm1.gp doing the same:
https://github.com/Hermann-SW/RSA_numbers_factored/blob/main/pari/sqrtm1.gp

Nice feature here is that because of "eval(getenv())" I can pass formulas. The program flow is the same as in sqrtm1.cc, with determination of smallest quadratic non-residue as learned from Bill:
https://pari.math.u-bordeaux.fr/archives/pari-users-2306/msg00044.html


sqrtm1 gets written to "/dev/stderr", allowing to store it into file while seeing other output:
$ n='(10^10000-1)\3 - 10^6333'  gp -q < sqrtm1.gp 2>err
2
  ***   last result computed in 3,013 ms.
$ wc err
    1     1 10001 err
$


I did run sqrtm1.cc last night (./sqrtm1 4) on 272770-digit prime, and it completed in 5139s. Then I did run "n='1705*2^906110+1' gp -q < sqrtm1.gp" and it completed in 1:39h.

So why is "lift(Mod(qnr, n)^(n\4))" 16% slower than C libgmp "powm(r, qnr, n/4, n)" on same Intel CPU (running at boost frequency with single running process both times)?


Regards,

Hermann.