Skip to content

Commit

Permalink
Trac #34647: some details in permutation groups
Browse files Browse the repository at this point in the history
mostly a few pep8 changes

URL: https://trac.sagemath.org/34647
Reported by: chapoton
Ticket author(s): Frédéric Chapoton
Reviewer(s): Travis Scrimshaw
  • Loading branch information
Release Manager committed Oct 11, 2022
2 parents 1a1d67d + 16fd967 commit 66a62fa
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 42 deletions.
19 changes: 11 additions & 8 deletions src/sage/groups/perm_gps/all.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
from .permgroup_named import (SymmetricGroup, AlternatingGroup,
DihedralGroup, SplitMetacyclicGroup, SemidihedralGroup, CyclicPermutationGroup,
DiCyclicGroup, TransitiveGroup, PGL, PSL, PSp,PSU,PGU,
MathieuGroup, KleinFourGroup, QuaternionGroup,
PrimitiveGroup, PrimitiveGroups,
SuzukiGroup, TransitiveGroups, GeneralDihedralGroup)
DihedralGroup, SplitMetacyclicGroup,
SemidihedralGroup, CyclicPermutationGroup,
DiCyclicGroup, TransitiveGroup,
PGL, PSL, PSp, PSU, PGU,
MathieuGroup, KleinFourGroup, QuaternionGroup,
PrimitiveGroup, PrimitiveGroups,
SuzukiGroup, TransitiveGroups,
GeneralDihedralGroup)

from .permgroup import PermutationGroup, PermutationGroup_generic, PermutationGroup_subgroup, direct_product_permgroups
from .permgroup import PermutationGroup, PermutationGroup_generic, PermutationGroup_subgroup, direct_product_permgroups

from .constructor import PermutationGroupElement

from .permgroup_morphism import (PermutationGroupMorphism as PermutationGroupMap,
PermutationGroupMorphism_im_gens,
PermutationGroupMorphism_id)
PermutationGroupMorphism_im_gens,
PermutationGroupMorphism_id)
PermutationGroupMorphism = PermutationGroupMorphism_im_gens

from .cubegroup import CubeGroup, RubiksCube
15 changes: 9 additions & 6 deletions src/sage/groups/perm_gps/constructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
objects have a more group theoretic flavor than the more combinatorial
:class:`~sage.combinat.permutation.Permutation`.
"""
#*****************************************************************************
# ****************************************************************************
# Copyright (C) 2006 William Stein <wstein@gmail.com>
# Copyright (C) 2006 David Joyner
# Copyright (C) 2019 Vincent Delecroix <20100.delecroix@gmail.com>
Expand All @@ -16,16 +16,17 @@
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
# http://www.gnu.org/licenses/
#*****************************************************************************
# https://www.gnu.org/licenses/
# ****************************************************************************

from . import permgroup_element
from sage.misc.sage_eval import sage_eval
from sage.misc.lazy_import import lazy_import
from sage.interfaces.gap import GapElement
lazy_import('sage.combinat.permutation', ['Permutation', 'from_cycles'])
from sage.libs.pari.all import pari_gen
from sage.libs.gap.element import GapElement_Permutation
lazy_import('sage.combinat.permutation', ['Permutation', 'from_cycles'])


def PermutationGroupElement(g, parent=None, check=True):
r"""
Expand Down Expand Up @@ -118,6 +119,7 @@ def PermutationGroupElement(g, parent=None, check=True):

return parent.element_class(g, parent, check)


def string_to_tuples(g):
"""
EXAMPLES::
Expand All @@ -136,10 +138,11 @@ def string_to_tuples(g):
raise ValueError("g (= %s) must be a string" % g)
elif g == '()':
return []
g = g.replace('\n','').replace(' ', '').replace(')(', '),(').replace(')', ',)')
g = g.replace('\n', '').replace(' ', '').replace(')(', '),(').replace(')', ',)')
g = '[' + g + ']'
return sage_eval(g, preparse=False)


def standardize_generator(g, convert_dict=None, as_cycles=False):
r"""
Standardize the input for permutation group elements to a list
Expand Down Expand Up @@ -258,6 +261,6 @@ def standardize_generator(g, convert_dict=None, as_cycles=False):
if convert_dict is not None and needs_conversion:
g = [tuple([convert_dict[x] for x in cycle]) for cycle in g]
if not as_cycles:
degree = max([1] + [max(cycle+(1,)) for cycle in g])
degree = max([1] + [max(cycle + (1,)) for cycle in g])
g = from_cycles(degree, g)
return g
8 changes: 3 additions & 5 deletions src/sage/groups/perm_gps/partn_ref/refinement_graphs.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ EXAMPLES::
REFERENCE:
- [1] McKay, Brendan D. Practical Graph Isomorphism. Congressus Numerantium,
- [1] McKay, Brendan D. *Practical Graph Isomorphism*. Congressus Numerantium,
Vol. 30 (1981), pp. 45-87.
"""

# ****************************************************************************
# Copyright (C) 2006 - 2011 Robert L. Miller <rlmillster@gmail.com>
#
Expand Down Expand Up @@ -643,9 +642,8 @@ cdef int compare_graphs(int *gamma_1, int *gamma_2, void *S1, void *S2, int degr
r"""
Compare gamma_1(S1) and gamma_2(S2).
Return return -1 if gamma_1(S1) < gamma_2(S2), 0 if gamma_1(S1) ==
gamma_2(S2), 1 if gamma_1(S1) > gamma_2(S2). (Just like the python
\code{cmp}) function.
Return -1 if gamma_1(S1) < gamma_2(S2), 0 if gamma_1(S1) ==
gamma_2(S2), 1 if gamma_1(S1) > gamma_2(S2).
INPUT:
Expand Down
38 changes: 22 additions & 16 deletions src/sage/groups/perm_gps/permgroup_morphism.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,26 @@
Cyclic group of order 4 as a permutation group
"""

#*****************************************************************************
# ****************************************************************************
# Copyright (C) 2006 David Joyner and William Stein <wstein@gmail.com>
#
# Distributed under the terms of the GNU General Public License (GPL)
# http://www.gnu.org/licenses/
#*****************************************************************************
# https://www.gnu.org/licenses/
# ****************************************************************************

from sage.categories.morphism import Morphism
from sage.groups.perm_gps.permgroup import PermutationGroup, PermutationGroup_generic


class PermutationGroupMorphism(Morphism):
"""
A set-theoretic map between PermutationGroups.
"""
def _repr_type(self):
"""
Returns the type of this morphism. This is used for printing
the morphism.
Return the type of this morphism.
This is used for printing the morphism.
EXAMPLES::
Expand All @@ -60,7 +62,7 @@ def _repr_type(self):

def kernel(self):
"""
Returns the kernel of this homomorphism as a permutation group.
Return the kernel of this homomorphism as a permutation group.
EXAMPLES::
Expand Down Expand Up @@ -134,7 +136,7 @@ def image(self, J):
def __call__(self, g):
"""
Some python code for wrapping GAP's Images function but only for
permutation groups. Returns an error if g is not in G.
permutation groups. This returns an error if g is not in G.
EXAMPLES::
Expand All @@ -148,9 +150,11 @@ def __call__(self, g):
"""
return self.image(g)


class PermutationGroupMorphism_id(PermutationGroupMorphism):
pass


class PermutationGroupMorphism_from_gap(PermutationGroupMorphism):
def __init__(self, G, H, gap_hom):
"""
Expand Down Expand Up @@ -201,7 +205,7 @@ def _repr_defn(self):

def _gap_(self, gap=None):
"""
Returns a GAP version of this morphism.
Return a GAP version of this morphism.
EXAMPLES::
Expand All @@ -217,7 +221,7 @@ def _gap_(self, gap=None):
def __call__(self, g):
"""
Some python code for wrapping GAP's Images function but only for
permutation groups. Returns an error if g is not in G.
permutation groups. This returns an error if g is not in G.
EXAMPLES::
Expand All @@ -236,7 +240,7 @@ def __init__(self, G, H, gens=None):
"""
Some python code for wrapping GAP's GroupHomomorphismByImages
function but only for permutation groups. Can be expensive if G is
large. Returns "fail" if gens does not generate self or if the map
large. This returns "fail" if gens does not generate self or if the map
does not extend to a group homomorphism, self - other.
EXAMPLES::
Expand Down Expand Up @@ -270,8 +274,9 @@ def __init__(self, G, H, gens=None):

def _repr_defn(self):
"""
Returns the definition of this morphism. This is used when
printing the morphism.
Return the definition of this morphism.
This is used when printing the morphism.
EXAMPLES::
Expand All @@ -281,11 +286,11 @@ def _repr_defn(self):
sage: phi._repr_defn()
'[(1,2,3,4)] -> [(1,2,3,4)]'
"""
return "%s -> %s"%(list(self.domain().gens()), self._images)
return "%s -> %s" % (list(self.domain().gens()), self._images)

def _gap_(self):
"""
Returns a GAP representation of this morphism.
Return a GAP representation of this morphism.
EXAMPLES::
Expand All @@ -298,9 +303,10 @@ def _gap_(self):
"""
return self.domain()._gap_().GroupHomomorphismByImages(self.codomain(), self.domain().gens(), self._images)

def is_PermutationGroupMorphism(f):

def is_PermutationGroupMorphism(f) -> bool:
"""
Returns True if the argument ``f`` is a PermutationGroupMorphism.
Return True if the argument ``f`` is a PermutationGroupMorphism.
EXAMPLES::
Expand Down
2 changes: 1 addition & 1 deletion src/sage/groups/perm_gps/permutation_groups_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
from .permgroup_named import JankoGroup as Janko
from .permgroup_named import SuzukiSporadicGroup as SuzukiSporadic
from .permgroup_named import SuzukiGroup as Suzuki
from .permgroup_named import (PGL, PSL, PSp,PSU,PGU,)
from .permgroup_named import (PGL, PSL, PSp, PSU, PGU)
from .permgroup_named import TransitiveGroup as Transitive
from .cubegroup import CubeGroup as RubiksCube
14 changes: 8 additions & 6 deletions src/sage/groups/perm_gps/symgp_conjugacy_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def _repr_(self):
Conjugacy class of cycle type [4] in
Symmetric group of order 4! as a permutation group
"""
return "Conjugacy class of cycle type %s in %s"%(self._part, self._parent)
return "Conjugacy class of cycle type %s in %s" % (self._part, self._parent)

def __eq__(self, other):
r"""
Expand Down Expand Up @@ -167,9 +167,10 @@ def set(self):
"""
if not self._set:
self._set = Set(self._parent.element_class(x, self._parent, check=False)
for x in conjugacy_class_iterator(self._part, self._domain) )
for x in conjugacy_class_iterator(self._part, self._domain))
return self._set


class PermutationsConjugacyClass(SymmetricGroupConjugacyClassMixin, ConjugacyClass):
"""
A conjugacy class of the permutations of `n`.
Expand Down Expand Up @@ -197,7 +198,7 @@ def __init__(self, P, part):
part = elt.cycle_type()
else:
elt = P.element_in_conjugacy_classes(part)
SymmetricGroupConjugacyClassMixin.__init__(self, range(1, P.n+1), part)
SymmetricGroupConjugacyClassMixin.__init__(self, range(1, P.n + 1), part)
ConjugacyClass.__init__(self, P, elt)

def __iter__(self):
Expand Down Expand Up @@ -241,11 +242,12 @@ def set(self):
"""
if not self._set:
self._set = Set(from_cycles(self._parent.n, x, self._parent)
for x in conjugacy_class_iterator(self._part, self._domain) )
for x in conjugacy_class_iterator(self._part, self._domain))
return self._set


#####################################################################
## Helper functions
# Helper functions

def default_representative(part, G):
r"""
Expand Down Expand Up @@ -284,7 +286,7 @@ def default_representative(part, G):
total = 0
cycles = []
for p in part:
cycles.append(tuple(D[total:total+p]))
cycles.append(tuple(D[total:total + p]))
total += p
return G.element_class(cycles, G, check=False)

Expand Down

0 comments on commit 66a62fa

Please sign in to comment.