Opened 9 years ago
Closed 7 years ago
#14432 closed defect (fixed)
Hash broken for unions, intersections, differences, and symmetric differences of sets
Reported by:  saraedum  Owned by:  sagecombinat 

Priority:  minor  Milestone:  sage6.4 
Component:  combinatorics  Keywords:  hash, set, sd59 
Cc:  Merged in:  
Authors:  Julian Rueth  Reviewers:  Travis Scrimshaw 
Report Upstream:  N/A  Work issues:  
Branch:  05ed037 (Commits, GitHub, GitLab)  Commit:  05ed0370f6a08b0e181f1f520b7df7ec6312a15c 
Dependencies:  Stopgaps: 
Description (last modified by )
The following code raises an exception
sage: S=Set(ZZ).union(Set([infinity])) sage: hash(S) Traceback (most recent call last): ... RuntimeError: maximum recursion depth exceeded
The same should happen for intersections, differences, and symmetric differences.
Attachments (1)
Change History (21)
Changed 9 years ago by
comment:1 Changed 9 years ago by
 Status changed from new to needs_review
comment:2 Changed 9 years ago by
comment:3 Changed 9 years ago by
I decided to remove some duplicated code rather than adding a __hash__
method to all the implementations  hope that is ok.
comment:4 Changed 9 years ago by
To test hashing, it is better to do tests like hash(s) == hash(s)
that do not depend upon the specific value but instead show that the object is hashable and it's value does not change.
comment:5 Changed 9 years ago by
 Status changed from needs_review to needs_work
That's a good point. Thanks for the input. I will change my patch accordingly.
comment:6 Changed 9 years ago by
 Milestone changed from sage5.11 to sage5.12
comment:7 Changed 9 years ago by
 Branch set to u/saraedum/ticket/14432
 Created changed from 04/09/13 17:48:28 to 04/09/13 17:48:28
 Modified changed from 08/13/13 15:35:53 to 08/13/13 15:35:53
comment:8 Changed 9 years ago by
 Description modified (diff)
 Milestone changed from sage5.12 to sage6.0
 Status changed from needs_work to needs_review
comment:9 Changed 9 years ago by
 Commit set to e851c6f179661e67e79e8aac44aa82371e7ff963
This patch does not apply cleanly on 5.13.beta0. And it's probably because it contains many dependencies #14482 O_o
~/sage$ git fetch trac u/saraedum/ticket/14432:hash remote: Counting objects: 17, done. remote: Compressing objects: 100% (12/12), done. remote: Total 12 (delta 10), reused 0 (delta 0) Unpacking objects: 100% (12/12), done. From ssh://trac.sagemath.org:2222/sage * [new branch] u/saraedum/ticket/14432 > hash ~/sage$ git merge hash Automerging src/sage/sets/set.py CONFLICT (content): Merge conflict in src/sage/sets/set.py Automerging src/sage/doctest/forker.py CONFLICT (content): Merge conflict in src/sage/doctest/forker.py Automerging build/pkgs/sagenb/packageversion.txt CONFLICT (content): Merge conflict in build/pkgs/sagenb/packageversion.txt Automerging build/pkgs/sagenb/checksums.ini CONFLICT (content): Merge conflict in build/pkgs/sagenb/checksums.ini Automerging build/pkgs/sagenb/SPKG.txt CONFLICT (content): Merge conflict in build/pkgs/sagenb/SPKG.txt Automatic merge failed; fix conflicts and then commit the result.
Last 10 new commits:
[changeset:e851c6f]  fixed doctest for the hash of a union/intersection/... of sets 
[changeset:10a3d1b]  (HEAD, refs/heads/stefan) Trac #14432: Fix hash for unions of sets 
[changeset:a10bc4f]  Merge branch 'ticket/14482' 
[changeset:fda55a9]  Merge branch 'u/saraedum/ticket/14482' of ssh://trac.sagemath.org:2222/sage into HEAD 
[changeset:61236da]  Merge remotetracking branch 'trac/public/sagegit/ticket/14482' 
[changeset:08d3e94]  Merge branch 'ticket/14482' 
[changeset:50e1ece]  Merge branch 'ticket/14482' 
[changeset:1ca56cf]  Merge branch 'ticket/14273' into tip 
[changeset:aa60895]  remove workaround for sagenb pull request 84 (#14273) 
[changeset:133785b]  Merge branch 'ticket/14482' into tip 
comment:10 Changed 9 years ago by
 Status changed from needs_review to needs_work
comment:11 Changed 8 years ago by
 Milestone changed from sage6.0 to sage6.1
comment:12 Changed 8 years ago by
 Milestone changed from sage6.1 to sage6.2
comment:13 Changed 8 years ago by
 Milestone changed from sage6.2 to sage6.3
comment:14 Changed 8 years ago by
 Commit changed from e851c6f179661e67e79e8aac44aa82371e7ff963 to 08f5ee0aa8c89827781849ef560bb228a770b8e7
Branch pushed to git repo; I updated commit sha1. New commits:
08f5ee0  Merge branch 'develop' into ticket/14432

comment:15 Changed 8 years ago by
 Keywords sd59 added
 Modified changed from 06/26/14 05:34:47 to 06/26/14 05:34:47
 Status changed from needs_work to needs_review
comment:16 Changed 8 years ago by
 Branch changed from u/saraedum/ticket/14432 to public/ticket/14432
 Commit changed from 08f5ee0aa8c89827781849ef560bb228a770b8e7 to 0190e4d1140c1f6c892b16f49e4670071a41a0b7
 Reviewers set to Travis Scrimshaw
I've made some minor review tweaks. If you're happy with them, then positive review.
New commits:
0190e4d  Some review changes to set.py.

comment:17 Changed 8 years ago by
 Commit changed from 0190e4d1140c1f6c892b16f49e4670071a41a0b7 to 05ed0370f6a08b0e181f1f520b7df7ec6312a15c
Branch pushed to git repo; I updated commit sha1. New commits:
05ed037  Fix typo.

comment:18 Changed 8 years ago by
 Milestone changed from sage6.3 to sage6.4
comment:19 Changed 7 years ago by
 Status changed from needs_review to positive_review
comment:20 Changed 7 years ago by
 Branch changed from public/ticket/14432 to 05ed0370f6a08b0e181f1f520b7df7ec6312a15c
 Resolution set to fixed
 Status changed from positive_review to closed
I do not have access to a 32bit machine right now. Could someone fill in the missing hash values? Is there a way to compute them from the 64bit values btw?