From 0c49d81a6571d1f1c8e85fb95fd51e1f10124129 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Thu, 11 Apr 2024 13:41:52 +0200 Subject: [PATCH] various ruff fixes in groups (PERF, etc) --- .../additive_abelian_wrapper.py | 31 ++++++------ src/sage/groups/braid.py | 4 +- src/sage/groups/class_function.py | 28 +++++------ src/sage/groups/cubic_braid.py | 47 +++++++++--------- src/sage/groups/finitely_presented.py | 7 ++- src/sage/groups/generic.py | 3 +- src/sage/groups/kernel_subgroup.py | 1 + src/sage/groups/libgap_mixin.py | 12 ++--- .../matrix_gps/finitely_generated_gap.py | 10 ++-- src/sage/groups/matrix_gps/orthogonal.py | 19 ++++---- src/sage/groups/perm_gps/permgroup.py | 48 ++++++++++--------- src/sage/groups/perm_gps/permgroup_named.py | 25 +++++----- .../semimonomial_transformation_group.py | 4 +- 13 files changed, 116 insertions(+), 123 deletions(-) diff --git a/src/sage/groups/additive_abelian/additive_abelian_wrapper.py b/src/sage/groups/additive_abelian/additive_abelian_wrapper.py index bf16874d97f..3edddea25e7 100644 --- a/src/sage/groups/additive_abelian/additive_abelian_wrapper.py +++ b/src/sage/groups/additive_abelian/additive_abelian_wrapper.py @@ -77,6 +77,7 @@ from sage.misc.superseded import deprecated_function_alias + class UnwrappingMorphism(Morphism): r""" The embedding into the ambient group. Used by the coercion framework. @@ -213,7 +214,7 @@ def __init__(self, universe, gens, invariants): self._universe = universe self._gen_elements = tuple(universe(x) for x in gens) self._gen_orders = invariants - cover,rels = addgp.cover_and_relations_from_invariants(invariants) + cover, rels = addgp.cover_and_relations_from_invariants(invariants) addgp.AdditiveAbelianGroup_fixed_gens.__init__(self, cover, rels, cover.gens()) self._unset_coercions_used() self.register_embedding(UnwrappingMorphism(self)) @@ -488,13 +489,13 @@ def torsion_subgroup(self, n=None): if n <= 0: raise ValueError('n must be a positive integer') gens, ords = [], [] - for g,o in genords: + for g, o in genords: if not o: continue d = n.gcd(o) if d == 1: continue - gens.append(o//d * g) + gens.append(o // d * g) ords.append(d) return AdditiveAbelianGroupWrapper(self.universe(), gens, ords) @@ -691,9 +692,9 @@ def _expand_basis_pgroup(p, alphas, vals, beta, h, rel): if not (isinstance(alphas, list) and isinstance(vals, list)): raise TypeError('alphas and vals must be lists for mutability') if not len(alphas) == len(vals) == k - 1: - raise ValueError(f'alphas and/or vals have incorrect length') -# assert not sum(r*a for r,a in zip(rel, alphas+[beta])) -# assert all(a.order() == p**v for a,v in zip(alphas,vals)) + raise ValueError('alphas and/or vals have incorrect length') + # assert not sum(r*a for r,a in zip(rel, alphas+[beta])) + # assert all(a.order() == p**v for a,v in zip(alphas,vals)) if rel[-1] < 0: raise ValueError('rel must have nonnegative entries') @@ -726,8 +727,8 @@ def _expand_basis_pgroup(p, alphas, vals, beta, h, rel): return # step 3 - j = next(j for j,r in enumerate(rel) if r == min_r) - alphas[j] = sum(a * (r//rel[j]) for a,r in zip(alphas+[beta], rel)) + j = next(j for j, r in enumerate(rel) if r == min_r) + alphas[j] = sum(a * (r // rel[j]) for a, r in zip(alphas + [beta], rel)) # step 4 if not alphas[j]: @@ -752,7 +753,8 @@ def _expand_basis_pgroup(p, alphas, vals, beta, h, rel): else: alphas.append(beta) vals.append(h) -# assert alphas[-1].order() == p**vals[-1] + # assert alphas[-1].order() == p**vals[-1] + def basis_from_generators(gens, ords=None): r""" @@ -803,7 +805,8 @@ def basis_from_generators(gens, ords=None): gammas = [] ms = [] for p in ps: - pgens = [(o.prime_to_m_part(p) * g, o.p_primary_part(p)) for g, o in zip(gens, ords) if not o % p] + pgens = [(o.prime_to_m_part(p) * g, o.p_primary_part(p)) + for g, o in zip(gens, ords) if not o % p] assert pgens pgens.sort(key=lambda tup: tup[1]) @@ -814,7 +817,7 @@ def basis_from_generators(gens, ords=None): while pgens: beta, ord_beta = pgens.pop() try: - dlog = _discrete_log_pgroup(p, vals, alphas, beta) + _ = _discrete_log_pgroup(p, vals, alphas, beta) except ValueError: pass else: @@ -845,8 +848,8 @@ def basis_from_generators(gens, ords=None): gammas.append(a) ms.append(p ** v) -## assert len({sum(i*g for i,g in zip(vec,gammas)) -## for vec in __import__('itertools').product(*map(range,ms))}) \ -## == __import__('sage').misc.misc_c.prod(ms) +# assert len({sum(i*g for i,g in zip(vec,gammas)) +# for vec in __import__('itertools').product(*map(range,ms))}) \ +# == __import__('sage').misc.misc_c.prod(ms) return gammas, ms diff --git a/src/sage/groups/braid.py b/src/sage/groups/braid.py index fb52b074218..3b48e00effd 100644 --- a/src/sage/groups/braid.py +++ b/src/sage/groups/braid.py @@ -2590,8 +2590,8 @@ def __init__(self, names): rels = [] for i in range(1, n): rels.append(free_group([i, i + 1, i, -i - 1, -i, -i - 1])) - for j in range(i + 2, n + 1): - rels.append(free_group([i, j, -i, -j])) + rels.extend(free_group([i, j, -i, -j]) + for j in range(i + 2, n + 1)) cat = Groups().Infinite() FinitelyPresentedGroup.__init__(self, free_group, tuple(rels), category=cat) diff --git a/src/sage/groups/class_function.py b/src/sage/groups/class_function.py index 901b0083b49..6ca0d9ee2cb 100644 --- a/src/sage/groups/class_function.py +++ b/src/sage/groups/class_function.py @@ -605,10 +605,9 @@ def irreducible_constituents(self): L = self._gap_classfunction.ConstituentsOfCharacter() return tuple(ClassFunction(self._group, list(l)) for l in L) - def decompose(self): + def decompose(self) -> tuple: r""" - Returns a list of the characters that appear in the decomposition - of chi. + Return a list of the characters appearing the decomposition of ``self``. EXAMPLES:: @@ -618,14 +617,13 @@ def decompose(self): ((3, Character of Symmetric group of order 5! as a permutation group), (2, Character of Symmetric group of order 5! as a permutation group)) """ - L = [] - for irr in self.irreducible_constituents(): - L.append((self.scalar_product(irr), irr)) + L = [(self.scalar_product(irr), irr) + for irr in self.irreducible_constituents()] return tuple(L) def norm(self): r""" - Returns the norm of self. + Return the norm of ``self``. EXAMPLES:: @@ -635,7 +633,7 @@ def norm(self): """ return self._gap_classfunction.Norm() - def values(self): + def values(self) -> list: r""" Return the list of values of self on the conjugacy classes. @@ -665,7 +663,7 @@ def values(self): def central_character(self): r""" - Returns the central character of self. + Return the central character of ``self``. EXAMPLES:: @@ -677,7 +675,7 @@ def central_character(self): def determinant_character(self): r""" - Returns the determinant character of self. + Return the determinant character of ``self``. EXAMPLES:: @@ -1310,10 +1308,9 @@ def irreducible_constituents(self): L = self._gap_classfunction.ConstituentsOfCharacter() return tuple(ClassFunction_libgap(self._group, l) for l in L) - def decompose(self): + def decompose(self) -> tuple: r""" - Return a list of the characters that appear in the decomposition - of ``self``. + Return a list of the characters appearing the decomposition of ``self``. EXAMPLES:: @@ -1323,9 +1320,8 @@ def decompose(self): ((3, Character of Symmetric group of order 5! as a permutation group), (2, Character of Symmetric group of order 5! as a permutation group)) """ - L = [] - for irr in self.irreducible_constituents(): - L.append((self.scalar_product(irr), irr)) + L = [(self.scalar_product(irr), irr) + for irr in self.irreducible_constituents()] return tuple(L) def norm(self): diff --git a/src/sage/groups/cubic_braid.py b/src/sage/groups/cubic_braid.py index 9dd59e069f9..c80da80520e 100644 --- a/src/sage/groups/cubic_braid.py +++ b/src/sage/groups/cubic_braid.py @@ -128,7 +128,7 @@ def eliminate_item(tietze_list): return None first = tietze_list[0] second = None - for i in range(1,l): + for i in range(1, l): if tietze_list[i] in (first, -first): if i == 1: second = tietze_list[i] @@ -502,9 +502,9 @@ def find_root(domain): # -------------------------------------------------------------------- cbg_type = self.parent()._cbg_type if cbg_type == CubicBraidGroup.type.AssionS: - characteristic = 3 # making Assion type S relations vanish + characteristic = 3 # making Assion type S relations vanish elif cbg_type == CubicBraidGroup.type.AssionU: - characteristic = 2 # making Assion type U relations vanish + characteristic = 2 # making Assion type U relations vanish else: characteristic = 0 try: @@ -512,7 +512,7 @@ def find_root(domain): except ValueError: raise ValueError('characteristic must be in integer') - if not characteristic.is_zero() and not characteristic.is_prime(): + if not characteristic.is_zero() and not characteristic.is_prime(): raise ValueError('characteristic must be a prime') if characteristic.is_zero(): from sage.rings.number_field.number_field import CyclotomicField @@ -526,7 +526,7 @@ def find_root(domain): root_bur = find_root(domain) domain = root_bur.parent() - else: # domain is not None + else: # domain is not None root_bur = find_root(domain) else: # root_bur is not None @@ -550,11 +550,11 @@ def conv2domain(laur_pol): from sage.matrix.constructor import matrix d1, d2 = burau_ori.dimensions() - burau_mat = matrix(d1, d2, lambda i,j: conv2domain(burau_ori[i,j])) + burau_mat = matrix(d1, d2, lambda i, j: conv2domain(burau_ori[i, j])) if unitary: - burau_mat_adj = matrix(d1, d2, lambda i,j: conv2domain(burau_ori_adj[i,j])) - herm_form = matrix(d1, d2, lambda i,j: conv2domain(herm_form_ori[i,j])) + burau_mat_adj = matrix(d1, d2, lambda i, j: conv2domain(burau_ori_adj[i, j])) + herm_form = matrix(d1, d2, lambda i, j: conv2domain(herm_form_ori[i, j])) return burau_mat, burau_mat_adj, herm_form return burau_mat @@ -764,15 +764,14 @@ def __init__(self, names, cbg_type=None): # internal naming of elements for convenience b = [free_group([i]) for i in range(1, n+1)] - t = [free_group([i, i+1]) ** 3 for i in range(1, n)] + t = [free_group([i, i+1]) ** 3 for i in range(1, n)] ti = [free_group([-i, -i-1]) ** 3 for i in range(1, n)] - # first the braid relation + # first the braid relations rels = list(self._braid_group.relations()) - # than the cubic relation - for i in range(n): - rels.append(b[i]**3) + # than the cubic relations + rels.extend(b[i]**3 for i in range(n)) # than Assion's relation Satz 2.2 for cbg_type=CubicBraidGroup.type.AssionS # and Satz 2.4 for cbg_type=CubicBraidGroup.type.AssionU @@ -1276,7 +1275,7 @@ def create_unitary_realization(self, m): if pos + 1 < m: transvections.append(xbas[pos-1]+xbas[pos]+xbas[pos+1]) # t_{3i+1} = x_{3i-1} + x_{3i} + x_{3i+1} if pos + 3 < m: - transvections.append(xbas[pos+1]+xbas[pos+2]+xbas[pos+3]) # t_{3i+2} = x_{3i+1} + x_{3i+2} + x_{3i+3} + transvections.append(xbas[pos+1]+xbas[pos+2]+xbas[pos+3]) # t_{3i+2} = x_{3i+1} + x_{3i+2} + x_{3i+3} # ----------------------------------------------------------- # Conversion-Map from transvection vector to transvection @@ -1299,15 +1298,14 @@ def transvec2mat(v, bas=bas, bform=bform, fact=a): set_classical_realization(self, base_group, proj_group, centralizing_matrix, transvec_matrices) return - #---------------------------------------------------------------------------------------------------------- - #---------------------------------------------------------------------------------------------------------- + # ---------------------------------------------------------------- # local functions declaration section finishes here - #---------------------------------------------------------------------------------------------------------- - #---------------------------------------------------------------------------------------------------------- + # ---------------------------------------------------------------- - # ------------------------------------------------------------------------------- + # ---------------------------------------------------------------- # initialization of constants - # ------------------------------------------------------------------------------- + # ---------------------------------------------------------------- + n = self.strands() # ------------------------------------------------------------------------------- @@ -1317,7 +1315,7 @@ def transvec2mat(v, bas=bas, bform=bform, fact=a): dim_sympl_group = n-1 # S(n-1) = Sp(n-1, 3) if n % 2 == 0: dim_sympl_group = n # S(n-1) = subgroup of PSp(n, 3) - create_sympl_realization(self, dim_sympl_group) + create_sympl_realization(self, dim_sympl_group) elif self._cbg_type == CubicBraidGroup.type.AssionU: dim_unitary_group = n-1 # U(n-1) = GU(n-1, 2) if n % 3 == 0: @@ -1543,8 +1541,9 @@ def as_matrix_group(self, root_bur=None, domain=None, characteristic=None, var=' unitary = True gen_list = [] for braid_gen in self.gens(): - bur_mat = braid_gen.burau_matrix(root_bur=root_bur, domain=domain, characteristic=characteristic, - var=var, reduced=reduced) + bur_mat = braid_gen.burau_matrix(root_bur=root_bur, domain=domain, + characteristic=characteristic, + var=var, reduced=reduced) if unitary: bur_mat, bur_mat_ad, herm_form = bur_mat @@ -1809,7 +1808,7 @@ def as_reflection_group(self): if not is_chevie_available(): raise ImportError("the GAP3 package 'CHEVIE' is needed to obtain the corresponding reflection groups") - if self._cbg_type != CubicBraidGroup.type.Coxeter or self.strands() > 5 or self.strands() < 2: + if self._cbg_type != CubicBraidGroup.type.Coxeter or self.strands() > 5 or self.strands() < 2: raise ValueError("no reflection group defined") # ------------------------------------------------------------------------------- diff --git a/src/sage/groups/finitely_presented.py b/src/sage/groups/finitely_presented.py index 3388c41d954..7d96975fe22 100644 --- a/src/sage/groups/finitely_presented.py +++ b/src/sage/groups/finitely_presented.py @@ -1005,7 +1005,7 @@ def as_permutation_group(self, limit=4096000): from sage.combinat.permutation import Permutation from sage.groups.perm_gps.permgroup import PermutationGroup return PermutationGroup([ - Permutation(coset_table[2*i]) for i in range(len(coset_table)//2)]) + Permutation(coset_table[2*i]) for i in range(len(coset_table)//2)]) def direct_product(self, H, reduced=False, new_names=True): r""" @@ -1548,14 +1548,13 @@ def sorted_presentation(self): L1 = [] for rel in L0: C = [rel] - for j in range(len(rel) - 1): - C.append(rel[j + 1:] + rel[:j + 1]) + C.extend(rel[j + 1:] + rel[:j + 1] for j in range(len(rel) - 1)) C1 = [tuple(-j for j in reversed(l)) for l in C] C += C1 C.sort() L1.append(C[0]) L1.sort() - return F/L1 + return F / L1 def epimorphisms(self, H): r""" diff --git a/src/sage/groups/generic.py b/src/sage/groups/generic.py index cb406b444af..fccb76fe0ef 100644 --- a/src/sage/groups/generic.py +++ b/src/sage/groups/generic.py @@ -901,7 +901,7 @@ def discrete_log(a, base, ord=None, bounds=None, operation='*', identity=None, i power = lambda x, y: multiple(x, y, operation=operation, identity=identity, inverse=inverse, op=op) if bounds: lb, ub = map(integer_ring.ZZ, bounds) - if (op is None or identity is None or inverse is None or ord is None) and operation not in addition_names+multiplication_names: + if (op is None or identity is None or inverse is None or ord is None) and operation not in addition_names + multiplication_names: raise ValueError("ord, op, identity, and inverse must all be specified for this operation") if ord is None: if operation in multiplication_names: @@ -1500,7 +1500,6 @@ def has_order(P, n, operation='+'): return False n = n.factor() - G = P.parent() if operation in addition_names: isid = lambda el: not el mult = lambda el, n: multiple(el, n, operation='+') diff --git a/src/sage/groups/kernel_subgroup.py b/src/sage/groups/kernel_subgroup.py index dec7a0be573..6a20b673c57 100644 --- a/src/sage/groups/kernel_subgroup.py +++ b/src/sage/groups/kernel_subgroup.py @@ -21,6 +21,7 @@ from sage.structure.parent import Parent from sage.structure.unique_representation import UniqueRepresentation + class KernelSubgroup(UniqueRepresentation, Parent): r""" The kernel (normal) subgroup. diff --git a/src/sage/groups/libgap_mixin.py b/src/sage/groups/libgap_mixin.py index 50f8fdf2678..476fb4e9416 100644 --- a/src/sage/groups/libgap_mixin.py +++ b/src/sage/groups/libgap_mixin.py @@ -277,7 +277,7 @@ def conjugacy_classes_representatives(self): if not self.is_finite(): raise NotImplementedError("only implemented for finite groups") G = self.gap() - reps = [ cc.Representative() for cc in G.ConjugacyClasses() ] + reps = [cc.Representative() for cc in G.ConjugacyClasses()] return tuple(self(g) for g in reps) def conjugacy_classes(self): @@ -676,9 +676,7 @@ def irreducible_characters(self): if not self.is_finite(): raise NotImplementedError("only implemented for finite groups") Irr = self.gap().Irr() - L = [] - for irr in Irr: - L.append(ClassFunction_libgap(self, irr)) + L = [ClassFunction_libgap(self, irr) for irr in Irr] return tuple(L) def character(self, values): @@ -731,7 +729,7 @@ def trivial_character(self): """ if not self.is_finite(): raise NotImplementedError("only implemented for finite groups") - values = [1]*self._gap_().NrConjugacyClasses().sage() + values = [1] * self._gap_().NrConjugacyClasses().sage() return self.character(values) def character_table(self): @@ -763,8 +761,8 @@ def character_table(self): [ 4 0 -1 -1 2 1 0] [ 1 1 1 1 1 1 1] """ - #code from function in permgroup.py, but modified for - #how gap handles these groups. + # code from function in permgroup.py, but modified for + # how gap handles these groups. G = self._gap_() cl = self.conjugacy_classes() from sage.rings.integer import Integer diff --git a/src/sage/groups/matrix_gps/finitely_generated_gap.py b/src/sage/groups/matrix_gps/finitely_generated_gap.py index 14bf551789f..b1623f543f9 100644 --- a/src/sage/groups/matrix_gps/finitely_generated_gap.py +++ b/src/sage/groups/matrix_gps/finitely_generated_gap.py @@ -29,7 +29,6 @@ from sage.groups.matrix_gps.finitely_generated import MatrixGroup from sage.groups.matrix_gps.matrix_group_gap import MatrixGroup_gap from sage.matrix.matrix_space import MatrixSpace -from sage.misc.cachefunc import cached_method from sage.misc.functional import cyclotomic_polynomial from sage.modules.free_module_element import vector from sage.rings.fraction_field import FractionField @@ -72,7 +71,7 @@ def __reduce__(self): ) """ return (MatrixGroup, - tuple(g.matrix() for g in self.gens()) + ({'check':False},)) + tuple(g.matrix() for g in self.gens()) + ({'check': False},)) def as_permutation_group(self, algorithm=None, seed=None): r""" @@ -321,7 +320,7 @@ def invariant_generators(self): # test if the field is admissible if F.gen() == 1: # we got the rationals or GF(prime) FieldStr = str(F.characteristic()) - elif hasattr(F,'polynomial'): # we got an algebraic extension + elif hasattr(F, 'polynomial'): # we got an algebraic extension if len(F.gens()) > 1: raise NotImplementedError("can only deal with finite fields and (simple algebraic extensions of) the rationals") FieldStr = '(%d,%s)' % (F.characteristic(), str(F.gen())) @@ -794,10 +793,7 @@ def reynolds_operator(self, poly, chi=None): elif not C.is_absolute() or not K.is_absolute() or not R.is_absolute(): raise NotImplementedError("only implemented for absolute fields") else: - fields = [] - for M in [R,K,C]: - if M.absolute_degree() != 1: - fields.append(M) + fields = [M for M in [R, K, C] if M.absolute_degree() != 1] l = len(fields) if l == 0: # all are QQ diff --git a/src/sage/groups/matrix_gps/orthogonal.py b/src/sage/groups/matrix_gps/orthogonal.py index 3ce9915dfec..c30fc14a331 100644 --- a/src/sage/groups/matrix_gps/orthogonal.py +++ b/src/sage/groups/matrix_gps/orthogonal.py @@ -196,18 +196,18 @@ def _OG(n, R, special, e=0, var='a', invariant_form=None): inserted_text = "with respect to symmetric form" name = '{0} Orthogonal Group of degree {1} over {2} {3}\n{4}'.format( - prefix, degree, ring, inserted_text,invariant_form) + prefix, degree, ring, inserted_text, invariant_form) ltx = r'\text{{{0}O}}_{{{1}}}({2})\text{{ {3} }}{4}'.format( - ltx_prefix, degree, latex(ring), inserted_text, - latex(invariant_form)) + ltx_prefix, degree, latex(ring), inserted_text, + latex(invariant_form)) else: name = '{0} Orthogonal Group of degree {1} over {2}'.format(prefix, degree, ring) ltx = r'\text{{{0}O}}_{{{1}}}({2})'.format(ltx_prefix, degree, latex(ring)) else: name = '{0} Orthogonal Group of degree {1} and form parameter {2} over {3}'.format(prefix, degree, e, ring) ltx = r'\text{{{0}O}}_{{{1}}}({2}, {3})'.format(ltx_prefix, degree, - latex(ring), - '+' if e == 1 else '-') + latex(ring), + '+' if e == 1 else '-') if isinstance(ring, FiniteField): try: @@ -522,11 +522,14 @@ def invariant_bilinear_form(self): m.set_immutable() return m - invariant_quadratic_form = invariant_bilinear_form # this is identical in the generic case - invariant_form = invariant_bilinear_form # alias (analogues to symplectic and unitary cases) + invariant_quadratic_form = invariant_bilinear_form + # this is identical in the generic case + + invariant_form = invariant_bilinear_form + # alias (analogues to symplectic and unitary cases) def _check_matrix(self, x, *args): - """a + """ Check whether the matrix ``x`` is orthogonal. See :meth:`~sage.groups.matrix_gps.matrix_group._check_matrix` diff --git a/src/sage/groups/perm_gps/permgroup.py b/src/sage/groups/perm_gps/permgroup.py index f001126ed84..3f6431948ea 100644 --- a/src/sage/groups/perm_gps/permgroup.py +++ b/src/sage/groups/perm_gps/permgroup.py @@ -203,6 +203,7 @@ def wrapped(self, n, p=0): return f(self, n, p=p) return wrapped + def direct_product_permgroups(P): """ Takes the direct product of the permutation groups listed in ``P``. @@ -230,6 +231,7 @@ def direct_product_permgroups(P): G = libgap.DirectProduct(*P) return PermutationGroup(gap_group=G) + def from_gap_list(G, src): r""" Convert a string giving a list of GAP permutations into a list of @@ -249,7 +251,7 @@ def from_gap_list(G, src): # src is a list of strings, each of which is a permutation of # integers in cycle notation. It may contain \n and spaces. src = [str(g)[1:].split(")(") - for g in str(src).replace(" ","").replace("\n","")[1:-2].split("),")] + for g in str(src).replace(" ", "").replace("\n", "")[1:-2].split("),")] # src is a list of list of strings. Each string is a list of # integers separated by ',' @@ -260,6 +262,7 @@ def from_gap_list(G, src): # src is now a list of group elements return src + def PermutationGroup(gens=None, *args, **kwds): """ Return the permutation group associated to `x` (typically a @@ -539,7 +542,7 @@ def __init__(self, gens=None, gap_group=None, canonicalize=True, # to make the domain contain all integers up to the max. # This is needed for backward compatibility if all(isinstance(p, (int, Integer)) for p in domain): - domain = list(range(min([1] + domain), max([1] + domain)+1)) + domain = list(range(min([1] + domain), max([1] + domain) + 1)) if domain not in FiniteEnumeratedSets(): domain = FiniteEnumeratedSet(domain) @@ -823,7 +826,7 @@ def __richcmp__(self, right, op): gSelf = self._libgap_() gRight = right._libgap_() - if op in [op_EQ,op_NE]: + if op in [op_EQ, op_NE]: return gSelf._richcmp_(gRight, op) if gSelf.IsSubgroup(gRight): @@ -906,7 +909,7 @@ def _element_constructor_(self, x, check=True): # We check if we can lift ``x`` to ``self`` directly # so we can pass check=False for speed. if (isinstance(x_parent, PermutationGroup_subgroup) - and x_parent._ambient_group is self): + and x_parent._ambient_group is self): return self.element_class(x, self, check=False) from sage.groups.perm_gps.permgroup_named import SymmetricGroup @@ -1268,9 +1271,9 @@ def elements(SGS): else: enumeration = "depth" return iter(RecursivelyEnumeratedSet( - seeds=seeds, - successors=successors, - enumeration=enumeration)) + seeds=seeds, + successors=successors, + enumeration=enumeration)) else: raise ValueError("the input algorithm (='%s') must be 'SGS', 'BFS' or 'DFS'" % algorithm) @@ -1558,12 +1561,12 @@ def _domain_gap(self, domain=None): '[1, 2, 3, 4, 5]' """ if domain is None: - return repr(list(range(1, self.degree()+1))) - else: - try: - return repr([self._domain_to_gap[point] for point in domain]) - except KeyError: - raise ValueError("domain must be a subdomain of self.domain()") + return repr(list(range(1, self.degree() + 1))) + + try: + return repr([self._domain_to_gap[point] for point in domain]) + except KeyError: + raise ValueError("domain must be a subdomain of self.domain()") @cached_method def smallest_moved_point(self): @@ -1588,7 +1591,7 @@ def smallest_moved_point(self): p = self._libgap_().SmallestMovedPoint() return self._domain_from_gap[Integer(p)] - def representative_action(self,x,y): + def representative_action(self, x, y): r""" Return an element of self that maps `x` to `y` if it exists. @@ -3709,12 +3712,9 @@ def subgroups(self): - Rob Beezer (2011-01-24) """ - all_sg = [] ccs = self._libgap_().ConjugacyClassesSubgroups() - for cc in ccs: - for h in cc.Elements(): - all_sg.append(self.subgroup(gap_group=h)) - return all_sg + return [self.subgroup(gap_group=h) for cc in ccs + for h in cc.Elements()] @cached_method def _regular_subgroup_gap(self): @@ -4166,7 +4166,7 @@ def maximal_normal_subgroups(self): return [self.subgroup(gap_group=gap_subgroup) for gap_subgroup in self._libgap_().MaximalNormalSubgroups()] - ###################### Boolean tests ##################### + # ##################### Boolean tests ##################### def is_abelian(self): """ @@ -4715,7 +4715,7 @@ def normalizes(self, other): """ return bool(self._libgap_().IsNormal(other)) - ############## Series ###################### + # ############# Series ###################### def composition_series(self): """ @@ -4857,7 +4857,8 @@ def molien_series(self): sage: PG.molien_series() == PG1.molien_series()*(1-x)^2 True """ - pi = self._libgap_().PermutationCharacter(list(self.domain()),libgap.OnPoints) + pi = self._libgap_().PermutationCharacter(list(self.domain()), + libgap.OnPoints) M = pi.MolienSeries() R = QQ['x'] @@ -5217,7 +5218,7 @@ def _latex_(self): gens = '\\langle ' + \ ', '.join([x._latex_() for x in self.gens()]) + ' \\rangle' return '\\hbox{Subgroup } %s \\hbox{ of } %s' % \ - (gens, self.ambient_group()._latex_()) + (gens, self.ambient_group()._latex_()) def ambient_group(self): """ @@ -5263,6 +5264,7 @@ def is_normal(self, other=None): # Allow for subclasses to use a different subgroup class PermutationGroup_generic.Subgroup = PermutationGroup_subgroup + class PermutationGroup_action(PermutationGroup_generic): """ A permutation group given by a finite group action. diff --git a/src/sage/groups/perm_gps/permgroup_named.py b/src/sage/groups/perm_gps/permgroup_named.py index 69014066364..6e979561e43 100644 --- a/src/sage/groups/perm_gps/permgroup_named.py +++ b/src/sage/groups/perm_gps/permgroup_named.py @@ -191,7 +191,7 @@ def __classcall__(cls, domain): if domain < 0: raise ValueError("domain (={}) must be an integer >= 0 or a list".format(domain)) - domain = list(range(1, domain+1)) + domain = list(range(1, domain + 1)) v = FiniteEnumeratedSet(domain) else: v = domain @@ -469,17 +469,17 @@ def young_subgroup(self, comp): gens = [] pos = 0 for c in comp: - for i in range(c - 1): - gens.append(self((domain[pos + i], domain[pos + i + 1]))) + gens.extend(self((domain[pos + i], domain[pos + i + 1])) + for i in range(c - 1)) pos += c return self.subgroup(gens) def major_index(self, parameter=None): r""" - Return the *major index generating polynomial* of ``self``, - which is a gadget counting the elements of ``self`` by major - index. + Return the *major index generating polynomial* of ``self``. + + This is a gadget counting the elements of ``self`` by major index. INPUT: @@ -1395,13 +1395,12 @@ def __init__(self, factors): jumppoint = Integer(1) for a in simplified: # create one of the generators for the abelian group - gens.append([tuple(range(jumppoint, jumppoint+a))]) + gens.append([tuple(range(jumppoint, jumppoint + a))]) # make contribution to the generator that dihedralizes the # abelian group - for i in range(1, (a//2)+1): - if i != a-i: - genx.append((jumppoint+i, jumppoint+a-i)) - jumppoint = jumppoint + a + genx.extend((jumppoint+i, jumppoint+a-i) + for i in range(1, (a//2)+1) if i != a-i) + jumppoint += a # If all of the direct factors are C2, then the action turning # each element into its inverse is trivial, and the # semi-direct product becomes a direct product, so we simply @@ -1419,9 +1418,7 @@ def _repr_(self): sage: G Generalized dihedral group generated by C2 x C4 x C8 """ - grouplist = [] - for n in self.factors: - grouplist.append('C{}'.format(n)) + grouplist = [f'C{n}' for n in self.factors] return 'Generalized dihedral group generated by ' + ' x '.join(grouplist) diff --git a/src/sage/groups/semimonomial_transformations/semimonomial_transformation_group.py b/src/sage/groups/semimonomial_transformations/semimonomial_transformation_group.py index e61c7bf64c7..602896e3ee8 100644 --- a/src/sage/groups/semimonomial_transformations/semimonomial_transformation_group.py +++ b/src/sage/groups/semimonomial_transformations/semimonomial_transformation_group.py @@ -311,8 +311,8 @@ def gens(self) -> tuple: from sage.groups.perm_gps.permgroup_named import SymmetricGroup R = self.base_ring() l = [self(v=([R.primitive_element()] + [R.one()] * (self.degree() - 1)))] - for g in SymmetricGroup(self.degree()).gens(): - l.append(self(perm=Permutation(g))) + l.extend(self(perm=Permutation(g)) + for g in SymmetricGroup(self.degree()).gens()) if R.is_field() and not R.is_prime_field(): l.append(self(autom=R.hom([R.primitive_element()**R.characteristic()]))) return tuple(l)