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

fix hash of PermutationGroup_generic #38871

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions src/sage/groups/perm_gps/permgroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,22 @@ def _magma_init_(self, magma):
g = ', '.join([g._gap_cycle_string() for g in self.gens()])
return 'PermutationGroup<%s | %s>' % (self.degree(), g)

def __hash__(self):
r"""
Return a hash value for ``self``.

TESTS::

sage: G = PermutationGroup([(1,2,3), (1,3)])
sage: G == SymmetricGroup(3)
True
sage: G.gens() == SymmetricGroup(3).gens()
False
sage: G in set([SymmetricGroup(3)])
True
"""
return hash(self.cardinality())

def __richcmp__(self, right, op):
"""
Compare ``self`` and ``right``.
Expand Down Expand Up @@ -2338,7 +2354,8 @@ def _order(self):
# Compute the order.
return Integer(len(unique)).factorial()

def order(self):
@cached_method
def cardinality(self):
"""
Return the number of elements of this group.

Expand All @@ -2356,7 +2373,7 @@ def order(self):
sage: G.order()
1

:meth:`cardinality` is just an alias::
:meth:`cardinality` is an alias::
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is no longer true with this change. Although I still don't see why you need to change how this is done with defining order and then making cardinality an alias. There is no harm in having it IMO.


sage: PermutationGroup([(1,2,3)]).cardinality()
3
Expand All @@ -2374,8 +2391,6 @@ def order(self):

return Integer(self.gap().Size())

cardinality = order

def random_element(self):
"""
Return a random element of this group.
Expand Down
12 changes: 3 additions & 9 deletions src/sage/groups/perm_gps/permgroup_named.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,21 +109,15 @@

class PermutationGroup_unique(CachedRepresentation, PermutationGroup_generic):
"""
.. TODO::

Fix the broken hash. ::

sage: G = SymmetricGroup(6)
sage: G3 = G.subgroup([G((1,2,3,4,5,6)),G((1,2))])
sage: hash(G) == hash(G3) # todo: Should be True!
False

TESTS::

sage: G = SymmetricGroup(6)
sage: G3 = G.subgroup([G((1,2,3,4,5,6)),G((1,2))])
sage: G == G3
True

sage: hash(G) == hash(G3)
True
"""
@weak_cached_function
def __classcall__(cls, *args, **kwds):
Expand Down Expand Up @@ -3513,7 +3507,7 @@
[ 2 0 -1 -2 0 1]
[ 2 0 -1 2 0 -1]
sage: def numgps(n): return ZZ(libgap.NumberSmallGroups(n))
sage: all(SmallPermutationGroup(n,k).id() == [n,k]

Check warning on line 3510 in src/sage/groups/perm_gps/permgroup_named.py

View workflow job for this annotation

GitHub Actions / test-new

Warning: slow doctest:

slow doctest:

Check warning on line 3510 in src/sage/groups/perm_gps/permgroup_named.py

View workflow job for this annotation

GitHub Actions / test-long (src/sage/[g-o]*)

Warning: slow doctest:

slow doctest:
....: for n in [1..64] for k in [1..numgps(n)])
True
sage: H = SmallPermutationGroup(6,1)
Expand Down
6 changes: 3 additions & 3 deletions src/sage/sets/set_from_iterator.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,11 +514,11 @@ def _sage_src_lines_(self):
sage: from sage.misc.sageinspect import sage_getsourcelines
sage: from sage.sets.set_from_iterator import Decorator
sage: d = Decorator()
sage: d.f = MathieuGroup.order
sage: d.f = MathieuGroup.cardinality
sage: S = sage_getsourcelines(d) # indirect doctest
sage: S[0][2]
sage: S[0][3]
' Return the number of elements of this group.\n'
sage: S[0][25]
sage: S[0][26]
' if not gens:\n'
"""
from sage.misc.sageinspect import sage_getsourcelines
Expand Down
Loading