Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
src/sage/sets/cartesian_product.py: Implement __eq__, __hash__ for no…
Browse files Browse the repository at this point in the history
…n-UniqueRepresentation case (mockup)
  • Loading branch information
Matthias Koeppe committed Aug 17, 2022
1 parent aabcca5 commit 6268de8
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/sage/sets/cartesian_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,22 @@ def __contains__(self, x):
return ( len(x) == len(self._sets)
and all(elt in self._sets[i] for i,elt in enumerate(x)) )

def __eq__(self, other):
if not any(isinstance(set, EnumeratedSetFromIterator) and set not in FiniteEnumeratedSets()
for set in self._sets):
# Use WithIdentityById
return super().__eq__(other)
# No flattening, hence we are equal if and only if our factors are equal
return self.cartesian_factors() == other.cartesian_factors()

def __hash__(self):
if not any(isinstance(set, EnumeratedSetFromIterator) and set not in FiniteEnumeratedSets()
for set in self._sets):
# Use WithIdentityById
return super().__hash__()
# No flattening, hence we are equal if and only if our factors are equal
return hash(self.cartesian_factors())

def cartesian_factors(self):
"""
Return the Cartesian factors of ``self``.
Expand Down

0 comments on commit 6268de8

Please sign in to comment.