Bug in __hash__ for PermutationGroupElement

17 views
Skip to first unread message

Johannes Schwab

unread,
Jan 14, 2021, 5:31:51 AM1/14/21
to sage-devel
Dear all,

the current implementation of __hash__ for PermutationGroupElement returns a hash that not only depends on the given permutation, but also on the group the permutation lives in.
Thus the "same" permutation (when compared with __eq__) may have different hash values, which is not in line with the Python documentation (https://docs.python.org/3.5/reference/datamodel.html#object.__hash__) and leads to unexpected situations as the following.

sage: G = SymmetricGroup(2)
sage: H = SymmetricGroup(1)
sage: d = {G.one() : "FooBaa"}
sage: H.one() in list(d.keys())
True
sage: H.one() in d
False

Best,
Johannes Schwab

Vincent Delecroix

unread,
Jan 14, 2021, 7:01:41 AM1/14/21
to sage-...@googlegroups.com
Dear Johannes,

Thanks for the report. This is indeed unfortunate. I opened
the following ticket

https://trac.sagemath.org/ticket/31236

Best
Vincent
Reply all
Reply to author
Forward
0 new messages