Max Alekseyev on Mon, 27 Nov 2017 02:36:15 +0100


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

Re: suppress warnings in GP


Dear Karim,

Thank you for addressing this issue.
The warning was useful in *some* cases as raising awareness of a possible speedup.
However, in other cases, when base b itself is large and varying, computing of eulerphi(b) may, in fact, result in slowdown as compared to powering without reduction the exponent modulo eulerphi(b).
Personally, I'd not mind having this warning turned on, given a way to turn it off when needed.

Regards,
Max

On Sun, Nov 26, 2017 at 3:37 PM, Karim Belabas <Karim.Belabas@math.u-bordeaux.fr> wrote:
* Max Alekseyev [2017-11-26 18:21]:
> Is there a way to suppress warnings in GP like this one?
>
> *** _^_: Warning: Mod(a,b)^n with n >> b : wasteful.

I just killed it in the 'master' branch, together with the section of
code which attempted to improve on user's programming in this case.

The warning meant that we were computing Mod(a,b)^n with b < 2^64 <= |n|.
It is usually the case that gcd(a,b) = 1, in which case n can
be reduced mod eulerphi(b); if not, the computation should be simplified
by using CRT. Etc.

Compare

  ? p=1009; n = 2^64+1; N = n%(p-1);
  ? for(i=2,10^5, Mod(i,p)^N)  \\ correct
  time = 30 ms.
  ? for(i=2,10^5, Mod(i,p)^n)  \\ silly => 6 times slower
  time = 190 ms.

The corresponding library code was complicated and error-prone (because of the
need to cater for gcd(a,b) > 1); I actually spotted an error when I
reviewed it because of your mail.

I decided it was not worth it, the recovery code and warning are both
gone: let users fix their code if they care about efficiency, they know best.

Cheers,

    K.B.
--
Karim Belabas, IMB (UMR 5251)  Tel: (+33) (0)5 40 00 26 17
Universite de Bordeaux         Fax: (+33) (0)5 40 00 21 23
351, cours de la Liberation    http://www.math.u-bordeaux.fr/~kbelabas/
F-33405
Talence (France)       http://pari.math.u-bordeaux.fr/  [PARI/GP]
`