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

inconsistent integer hashing on 64bit systems with python 2.7 #11986

Closed
kiwifb opened this issue Nov 3, 2011 · 11 comments
Closed

inconsistent integer hashing on 64bit systems with python 2.7 #11986

kiwifb opened this issue Nov 3, 2011 · 11 comments

Comments

@kiwifb
Copy link
Member

kiwifb commented Nov 3, 2011

With python 2.7 integer hashing is broken on 64bit systems in a similar way than [
#4957 comment:3] in #4957 which was fixed 3 years ago. The following tests

sage -t -long -force_lib "devel/sage-main/sage/rings/padics/padic_capped_relative_element.pyx"
**********************************************************************
File "/usr/share/sage/devel/sage-main/sage/rings/padics/padic_capped_relative_element.pyx", line 2339:
    sage: hash(R(-1)) 
Expected:
    95367431640624
Got:
    1977800240
**********************************************************************

and (which is reminiscent of #4957):

sage -t -long -force_lib "devel/sage-main/sage/rings/integer.pyx"
**********************************************************************
File "/usr/share/sage/devel/sage-main/sage/rings/integer.pyx", line 3046:
    sage: n = -920390823904823094890238490238484; n.__hash__()
Expected:
    6874330978542788722   
Got:
    -2623069716
**********************************************************************
File "/usr/share/sage/devel/sage-main/sage/rings/integer.pyx", line 3061:
    sage: hash(n)
Expected:
    -9223372036854767616      
Got:
    8192
**********************************************************************
File "/usr/share/sage/devel/sage-main/sage/rings/integer.pyx", line 3064:
    sage: hash(n) == hash(int(n))
Expected:
    True
Got:
    False
**********************************************************************

On my 64bit system with python-2.7:

sage: n=2^63+2^13
sage: n
9223372036854784000
sage: hash(n)
8192
sage: int(n)
9223372036854784000L
sage: hash(int(n))
-9223372036854767616

Depends on #9958

Component: c_lib

Author: Jeroen Demeyer

Reviewer: François Bissey

Merged: sage-5.0.beta0

Issue created by migration from https://trac.sagemath.org/ticket/11986

@kiwifb kiwifb added this to the sage-4.8 milestone Nov 3, 2011
@kiwifb kiwifb added the t: bug label Nov 3, 2011
@jdemeyer
Copy link
Contributor

jdemeyer commented Nov 3, 2011

Milestone sage-4.7.3 deleted

@jdemeyer jdemeyer removed this from the sage-4.8 milestone Nov 3, 2011
@jdemeyer
Copy link
Contributor

jdemeyer commented Nov 3, 2011

Dependencies: #9958

@jdemeyer jdemeyer added this to the sage-4.8 milestone Nov 3, 2011
@jdemeyer
Copy link
Contributor

jdemeyer commented Dec 3, 2011

Attachment: 11986_integer_hash.patch.gz

@jdemeyer
Copy link
Contributor

jdemeyer commented Dec 3, 2011

Author: Jeroen Demeyer

@jdemeyer
Copy link
Contributor

jdemeyer commented Dec 3, 2011

comment:4

Attached patch fixes the problem on x86_64 Linux, not yet tested on other systems.

@jdemeyer
Copy link
Contributor

jdemeyer commented Dec 5, 2011

comment:5

Works fine on 32-bit i386 Linux.

@kiwifb
Copy link
Member Author

kiwifb commented Dec 14, 2011

comment:6

I tried this on one of my amd64 machine with a vanilla sage-4.8.alpha3 (using python-2.6) and got this back:

sage -t -long -force_lib "devel/sage-main/sage/rings/integer.pyx"
**********************************************************************
File "/home/work/fbissey/sandbox/sage-4.8.alpha3/devel/sage-main/sage/rings/integer.pyx", line 3075:
    sage: hash(n) == hash(long(n))
Expected:
    True
Got:
    False
**********************************************************************
File "/home/work/fbissey/sandbox/sage-4.8.alpha3/devel/sage-main/sage/rings/integer.pyx", line 3077:
    sage: hash(n-1) == hash(long(n-1))
Expected:
    True
Got:
    False
**********************************************************************
File "/home/work/fbissey/sandbox/sage-4.8.alpha3/devel/sage-main/sage/rings/integer.pyx", line 3079:
    sage: hash(-n) == hash(long(-n))
Expected:
    True
Got:
    False
**********************************************************************
File "/home/work/fbissey/sandbox/sage-4.8.alpha3/devel/sage-main/sage/rings/integer.pyx", line 3081:
    sage: hash(1-n) == hash(long(1-n))
Expected:
    True
Got:
    False
**********************************************************************
1 items had failures:
   4 of  25 in __main__.example_63
***Test Failed*** 4 failures.

Everything is working as intended with python-2.7 on that machine.

@kiwifb
Copy link
Member Author

kiwifb commented Dec 21, 2011

Reviewer: François Bissey

@kiwifb
Copy link
Member Author

kiwifb commented Dec 21, 2011

comment:7

It's fine on a 32bit OS (OS X 10.5.8) with python 2.6. 4.8.alpha3 fails as above on my linux 64bit box but with 4.8.alpha4 (and python 2.6) on the same box everything is fine. I am setting this to positive review.

@strogdon
Copy link
Contributor

comment:8

I applied just 11986_integer_hash.patch on top of a fresh build of sage-4.8.alpha4 with python-2.6. Both the padic_capped_relative_element.pyx and integer.pyx tests mentioned above pass here on 32-bit i686 and 64-bit amd64. The tests also pass when sage is built with python-2.7 on the same architectures.

@jdemeyer jdemeyer modified the milestones: sage-4.8, sage-5.0 Dec 21, 2011
@jdemeyer
Copy link
Contributor

Merged: sage-5.0.beta0

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

No branches or pull requests

3 participants