Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt to precision changes in pari 2.17 #166

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

antonio-rojas
Copy link
Contributor

@antonio-rojas antonio-rojas commented Oct 4, 2024

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

  • Rename prec_bits_to_words to prec_bits_to_pari and outsource it to upstream's nbits2prec, so it works with all pari versions
  • Remove unused and no longer useful prec_words_to_bits, prec_dec_to_words and prec_words_to_dec functions
  • Use upstream's LOWDEFAULTPREC as default precision

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

- Rename prec_bits_to_words to prec_bits_to_pari and outsource it to upstream's nbits2prec, so it works with all pari versions
- Remove unused and no longer needed prec_words_to_bits and prec_words_to_dec functions
- Use upstream's LOWDEFAULTPREC as default precision
@dimpase
Copy link
Member

dimpase commented Oct 5, 2024

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
Copy link
Contributor Author

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
Copy link
Contributor Author

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
Copy link
Collaborator

videlec commented Oct 6, 2024

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
Copy link
Contributor Author

antonio-rojas commented Oct 6, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants