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
Equal PARI integers have different hashes #11611
Comments
Changed keywords from none to pari ideal hnf |
comment:2
I have not been able to reproduce this error through the string interface:
|
comment:3
The problem lies with the conversion between PARI and Sage:
|
Changed keywords from pari ideal hnf to pari integer ideal hnf |
This comment has been minimized.
This comment has been minimized.
comment:4
The issue is already visible on the level of PARI |
Changed keywords from pari integer ideal hnf to pari cgetg integer ideal hnf |
This comment has been minimized.
This comment has been minimized.
Attachment: 11611.patch.gz |
Author: Jeroen Demeyer |
comment:8
I read the patch, which is mostly about rewriting Cython code against the PARI library in a way that looks much cleaner and makes sense. I don't quite understand precisely what it is about the code here that fixes the bug though. All tests pass, and the new code looks and reads well. |
comment:9
As William, I read the ticket description and the patch and I don't understand what is really the cause of the issue and why the patch fixes it. I'd encourage Jeroen to add a comment explaining this bit and, if possible, to split the patch in two parts: a "fix the issue" part and a "cleanup" part (in the order that is most convenient). I'm also wondering if the hash of a pari integer should match the hash of the corresponding sage or python integers. That is carefully considered in the sage integers/rationals, etc. The principle is that two values that are equivalent (for the purposes of equality comparision) should have the same hash to avoid nastiness in using the values as dictionary keys. The same would be true for some other pari types. |
comment:10
The code which is purely about the bug fix is in lines 9005--9007 of the new I also rewrote some code which was similar in spirit to the buggy code, even though I could not obviously produce bugs from that code. Then I also did some general cleanup, like getting rid of |
comment:11
Replying to @tornaria:
This looks quite hard. You would really have to rewrite the PARI hash function for this to match the Sage hash functions or the other way around. Also, consider that PARI objects are rarely directly visible in Sage. They usually live in private members of classes, so are unlikely to end up as dictionary keys. And even if they do, it would be even rarer to mix PARI and Sage types. |
Merged: sage-4.7.2.alpha1 |
Reviewer: William Stein |
comment:13
See #11854 for a follow-up (it turns out this ticket does not fully fix the problem). |
In the code below,
a5
andb5
are PARI integers equal to 5 but they have different hashes:This bug was discovered for ideals having different hashes.
The problem is with the initialization of integers in
new_gen_from_mpz_t()
. The attached patch fixes various instances of bad PARI object initialization.Component: number fields
Keywords: pari cgetg integer ideal hnf
Author: Jeroen Demeyer
Reviewer: William Stein
Merged: sage-4.7.2.alpha1
Issue created by migration from https://trac.sagemath.org/ticket/11611
The text was updated successfully, but these errors were encountered: