sagemath / cypari2

Python interface to the number theory library PARI/GP. Source repository for https://pypi.org/project/cypari2/
https://cypari2.readthedocs.io/en/latest/
GNU General Public License v2.0
30 stars 28 forks source link

Adapt to precision changes in pari 2.17 #166

Open antonio-rojas opened 3 days ago

antonio-rojas commented 3 days ago

Since 2.17 pari stores the precision in bits instead of words. Port cypari2 to work with it:

dimpase commented 3 days ago

there are doctest failures like this.

https://github.com/sagemath/cypari2/actions/runs/11186104097/job/31100414929#step:5:322

in cypari2.pari_instance.__test__.default_bitprec (line 367)
Failed example:
    default_bitprec()
Differences (ndiff with -expected +actual):
    - 64
    + 3

it's probably hard to avoid differentiating between pari versions up to 2.15 and 2.17+ in this test.

antonio-rojas commented 2 days ago

it's probably hard to avoid differentiating between pari versions up to 2.15 and 2.17+ in this test.

That was actally an issue with my code, this test should always return 64.

antonio-rojas commented 2 days ago

Tests seem fine now. However, I'm seeing a weird issue that I don't understand. With this patch, in sage I get

sage: N = 1715761513; E = EllipticCurve(Integers(N), [3,-13]); P = E(2,1); LCM([2..60])*P
[...]
PariError: impossible inverse in Fp_inv: Mod(26927, 1715761513)

which shows that the PariError is not being intercepted in https://github.com/sagemath/sage/blob/10.5.beta6/src/sage/schemes/elliptic_curves/ell_point.py#L3915. If I change except PariError to except Exception it works, and querying the exception type shows that it is indeed a PariError.

The issue doesn't happen without this patch (but of course lots of precision related stuff is broken). Any idea what's going on here? Why should these changes affect PariError handling?

videlec commented 1 day ago

Tests seem fine now. However, I'm seeing a weird issue that I don't understand. With this patch, in sage I get

sage: N = 1715761513; E = EllipticCurve(Integers(N), [3,-13]); P = E(2,1); LCM([2..60])*P
[...]
PariError: impossible inverse in Fp_inv: Mod(26927, 1715761513)

which shows that the PariError is not being intercepted in https://github.com/sagemath/sage/blob/10.5.beta6/src/sage/schemes/elliptic_curves/ell_point.py#L3915. If I change except PariError to except Exception it works, and querying the exception type shows that it is indeed a PariError.

The issue doesn't happen without this patch (but of course lots of precision related stuff is broken). Any idea what's going on here? Why should these changes affect PariError handling?

Could it be a PariError from an other cypari2 (sounds super weird)? Did you check in the catch whether PariError == PariError?

antonio-rojas commented 1 day ago

Ah, found the issue. sage/schemes/elliptic_curves/ell_point.py has

try:
    from sage.libs.pari.all import pari, PariError
    from cypari2.pari_instance import prec_words_to_bits
except ImportError:
    PariError = ()

which of course fails to properly import PariError after prec_words_to_bits removal.