Skip to content

Commit

Permalink
Trac #34824: do not include parent in hash of parking functions
Browse files Browse the repository at this point in the history
We do not want the following:
{{{
sage: P = ParkingFunctions(3)
sage: f = P([1,1,1])
sage: g = ParkingFunction([1,1,1])
sage: f in P
True
sage: g in P
True
sage: f in list(P)
True
sage: g in list(P)
True
sage: f in set(P)
True
sage: g in set(P)
False
}}}

URL: https://trac.sagemath.org/34824
Reported by: mantepse
Ticket author(s): Martin Rubey
Reviewer(s): Travis Scrimshaw
  • Loading branch information
Release Manager committed Jan 3, 2023
2 parents 9a7b631 + 49ff03d commit acebbc1
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 97 deletions.
6 changes: 3 additions & 3 deletions build/pkgs/configure/checksums.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tarball=configure-VERSION.tar.gz
sha1=88ae976578786fa200bf86cf01ecfdb8432005e1
md5=586346fa566bd96e98f1e7d972c41699
cksum=3389588783
sha1=9816c00fcfc3ba11d0a9b61033df4915a15ccf0b
md5=dff4e185544cf5dd1f2bbeb4f4761cbf
cksum=655542759
2 changes: 1 addition & 1 deletion build/pkgs/configure/package-version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
d5aad9b8b0fe53109085c2a490e487386e430670
0e1a60596d521bf69572e1484066f4015749735e
12 changes: 0 additions & 12 deletions src/sage/combinat/crystals/tensor_product_element.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,6 @@ cdef class ImmutableListWithParent(ClonableArray):
"""
ClonableArray.__init__(self, parent, list, check=False)

cpdef long _hash_(self) except? -1:
"""
Return the hash of ``self``.
TESTS::
sage: b = crystals.Tableaux(['A',2], shape=[2,1]).module_generators[0]
sage: b._hash_() == hash(b)
True
"""
return hash(tuple(self._list))

def __setstate__(self, state):
"""
For unpickling old pickles.
Expand Down
71 changes: 20 additions & 51 deletions src/sage/combinat/decorated_permutation.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,26 @@ def __classcall_private__(cls, pi):
sage: DecoratedPermutation([2, 1, -3])
[2, 1, -3]
TESTS:
Check that hashing and comparison works::
sage: S = DecoratedPermutations(3)
sage: elt1 = S([2, 1, -3])
sage: elt2 = DecoratedPermutation([2, 1, -3])
sage: elt1 == elt2
True
sage: elt1 == [2, 1, -3]
False
sage: elt2 = DecoratedPermutation([2, 1, 3])
sage: elt1 != elt2
True
sage: hash(elt1) # random
915443076393556996
"""
pi = list(pi)
return DecoratedPermutations(len(pi))(pi)
Expand Down Expand Up @@ -86,57 +106,6 @@ def check(self):
if self not in self.parent():
raise ValueError("{} is not a decorated permutation".format(self))

def __hash__(self):
r"""
Return a hash of ``self``.
TESTS::
sage: len(set(hash(pi) for pi in DecoratedPermutations(3)))
16
"""
return hash(tuple(self))

def __eq__(self, other):
"""
Check whether ``self`` is equal to ``other``.
INPUT:
- ``other`` -- the element that ``self`` is compared to
OUTPUT: Boolean
EXAMPLES::
sage: S = DecoratedPermutations(3)
sage: elt1 = S([2, 1, -3])
sage: elt2 = DecoratedPermutation([2, 1, -3])
sage: elt1 == elt2
True
"""
return isinstance(other, DecoratedPermutation) and list(self) == list(other)

def __ne__(self, other):
"""
Check whether ``self`` is not equal to ``other``.
INPUT:
- ``other`` -- the element that ``self`` is compared to
OUTPUT: Boolean
EXAMPLES::
sage: S = DecoratedPermutations(3)
sage: elt1 = S([2, 1, -3])
sage: elt2 = DecoratedPermutation([2, 1, 3])
sage: elt1 != elt2
True
"""
return not (self == other)

def size(self):
"""
Return the size of the decorated permutation.
Expand Down
14 changes: 0 additions & 14 deletions src/sage/combinat/set_partition_ordered.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,20 +234,6 @@ def check(self):
par = parent(self)
assert self in par, "%s not in %s" % (self, par)

def _hash_(self):
"""
Return the hash of ``self``.
EXAMPLES::
sage: OS = OrderedSetPartitions(4)
sage: s = OS([[1, 3], [2, 4]])
sage: OSP = OrderedSetPartitions()
sage: hash(s) == hash(OSP(s))
True
"""
return hash(tuple(self))

def base_set(self):
"""
Return the base set of ``self``.
Expand Down
12 changes: 0 additions & 12 deletions src/sage/combinat/superpartition.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,18 +200,6 @@ def __richcmp__(self, other, op) -> bool:
else:
return richcmp(list(self), other, op)

def _hash_(self):
"""
Return the hash of ``self``.
EXAMPLES::
sage: SP = SuperPartition([[1],[1]])
sage: hash(tuple(SP)) == hash(SP)
True
"""
return hash(tuple(self))

def _repr_(self) -> str:
r"""
Return a string representation of ``self``.
Expand Down
6 changes: 2 additions & 4 deletions src/sage/structure/list_clone.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -921,9 +921,7 @@ cdef class ClonableArray(ClonableElement):
sage: type(el._hash_()) == int
True
"""
cdef long hv
hv = hash(tuple(self._list))
return hash(self._parent) + hv
return hash(tuple(self._list))

def __reduce__(self):
"""
Expand Down Expand Up @@ -1709,7 +1707,7 @@ cdef class ClonableIntArray(ClonableElement):
hv = hash(None)
else:
hv = hash(tuple(self))
return hash(self._parent) + hv
return hv

def __reduce__(self):
"""
Expand Down

0 comments on commit acebbc1

Please sign in to comment.