K iddlmZmZmZddlmZmZddlm Z ddl m Z m Z m Z mZmZmZddlmZmZmZmZmZmZmZmZddlmZddlmZmZmZddl m!Z!dd l"m#Z#dd l$mZdd l%m&Z&m'Z'dd l(m)Z)m*Z*dd l+m,Z,ddl-m.Z.m/Z/m0Z0e jbZ2e jfZ3GddeZ4ddZ5dZ6ddZ7dZ8e4Z9GddeZ:GddeZ;y)) factoriallogprod)chainproduct) Permutation)_af_commutes_with _af_invert_af_rmul _af_rmuln_af_powCycle)_check_cycles_alt_sym_distribute_gens_by_base_orbits_transversals_from_bsgs_handle_precomputed_bsgs_base_ordering_strong_gens_from_distr_strip _strip_af)Basic) _randrange randrangechoice)Symbol)_sympify)r) primefactorssieve) factorint multiplicity)isprime) has_variety is_sequenceuniqcjeZdZdZdZdddZdZdZdZdZ d Z d Z dad Z d Z dZedZ dbdZedZedZedZdZdZdZdZdZdZdZdcdZdcdZdZdcdZedZ ed Z!ed!Z"d"Z#d#Z$ddd$Z%dcd%Z&dcd&Z'ed'Z(ded(Z)ed)Z*ed*Z+d+Z,d,Z-dfd-Z.dgd.Z/dgd/Z0ed0Z1ded1Z2ded2Z3ded3Z4ed4Z5ded5Z6ed6Z7ded7Z8ed8Z9d9Z:ed:Z;d;Zdhd>Z?did?Z@dad@ZAdcdAZBdcdBZCdCZDdDZEedEZFedFZGeHdGZIedHZJedIZKdedJZLdadKZMdcdLZNdjdMZOdkdNZPdOZQdadPZRdldQZS dmdRZTdSZUdTZVedUZWdVZX dndWZYedXZZdYZ[dZZ\d[Z]d\Z^d]Z_d^Z`ded_Zad`Zby )oPermutationGroupaJ The class defining a Permutation group. Explanation =========== ``PermutationGroup([p1, p2, ..., pn])`` returns the permutation group generated by the list of permutations. This group can be supplied to Polyhedron if one desires to decorate the elements to which the indices of the permutation refer. Examples ======== >>> from sympy.combinatorics import Permutation, PermutationGroup >>> from sympy.combinatorics import Polyhedron The permutations corresponding to motion of the front, right and bottom face of a $2 \times 2$ Rubik's cube are defined: >>> F = Permutation(2, 19, 21, 8)(3, 17, 20, 10)(4, 6, 7, 5) >>> R = Permutation(1, 5, 21, 14)(3, 7, 23, 12)(8, 10, 11, 9) >>> D = Permutation(6, 18, 14, 10)(7, 19, 15, 11)(20, 22, 23, 21) These are passed as permutations to PermutationGroup: >>> G = PermutationGroup(F, R, D) >>> G.order() 3674160 The group can be supplied to a Polyhedron in order to track the objects being moved. An example involving the $2 \times 2$ Rubik's cube is given there, but here is a simple demonstration: >>> a = Permutation(2, 1) >>> b = Permutation(1, 0) >>> G = PermutationGroup(a, b) >>> P = Polyhedron(list('ABC'), pgroup=G) >>> P.corners (A, B, C) >>> P.rotate(0) # apply permutation 0 >>> P.corners (A, C, B) >>> P.reset() >>> P.corners (A, B, C) Or one can make a permutation as a product of selected permutations and apply them to an iterable directly: >>> P10 = G.make_perm([0, 1]) >>> P10('ABC') ['C', 'A', 'B'] See Also ======== sympy.combinatorics.polyhedron.Polyhedron, sympy.combinatorics.permutations.Permutation References ========== .. [1] Holt, D., Eick, B., O'Brien, E. "Handbook of Computational Group Theory" .. [2] Seress, A. "Permutation Group Algorithms" .. [3] https://en.wikipedia.org/wiki/Schreier_vector .. [4] https://en.wikipedia.org/wiki/Nielsen_transformation#Product_replacement_algorithm .. [5] Frank Celler, Charles R.Leedham-Green, Scott H.Murray, Alice C.Niemeyer, and E.A.O'Brien. "Generating Random Elements of a Finite Group" .. [6] https://en.wikipedia.org/wiki/Block_%28permutation_group_theory%29 .. [7] https://algorithmist.com/wiki/Union_find .. [8] https://en.wikipedia.org/wiki/Multiply_transitive_group#Multiply_transitive_groups .. [9] https://en.wikipedia.org/wiki/Center_%28group_theory%29 .. [10] https://en.wikipedia.org/wiki/Centralizer_and_normalizer .. [11] https://groupprops.subwiki.org/wiki/Derived_subgroup .. [12] https://en.wikipedia.org/wiki/Nilpotent_group .. [13] https://www.math.colostate.edu/~hulpke/CGT/cgtnotes.pdf .. [14] https://docs.gap-system.org/doc/ref/manual.pdf T)dupsc |s tg}n+tt|dr|dn|}|s tg}td|Dr|Dcgc] }t|}}t d|Dre|j dd}|t d|D}tt|D](}||j|k7st|||||<*|r4tt|Dcgc]}tt|c}}t|dkDr|Dcgc]}|jr|}}tj|g|i|Scc}wcc}wcc}w) zThe default constructor. Accepts Cycle and Permutation forms. Removes duplicates unless ``dups`` keyword is ``False``. rc3<K|]}t|tywN) isinstancer.0as e/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/combinatorics/perm_groups.py z+PermutationGroup.__new__..s2z!U#2sc34K|]}|jywr*sizer,s r/r0z+PermutationGroup.__new__..s,!qvv,degreeNc34K|]}|jywr*r2r,s r/r0z+PermutationGroup.__new__..s2QVV2r4r2)rlistr#anyr"popmaxrangelenr3r$_af_new is_identityr__new__)clsr'argskwargsr.r5igs r/r@zPermutationGroup.__new__|s?M?D;tAw#7QTBD#  2T2 2,01qKN1D1 ,t, ,ZZ$/F~2T223t9% @7<<6))$q'?DG @ =1gd1g.=>?D t9q=#9!1==A9D9}}S2426222>9sE+E #E5Ect|j|_d|_g|_d|_d|_d|_d|_d|_ d|_ d|_ d|_ d|_ d|_d|_d|_d|_d|_t'|j|_|jdj*|_g|_g|_g|_g|_g|_g|_g|_d|_yNr)r8rB _generators_order _elements_center _is_abelian_is_transitive_is_sym_is_alt _is_primitive _is_nilpotent _is_solvable _is_trivial_transitivity_degree_max_div _is_perfect _is_cyclic _is_dihedralr=_rr3_degree_base _strong_gens_strong_gens_slp _basic_orbits _transversals_transversal_slp _random_gens_fp_presentationselfrBrCs r/__init__zPermutationGroup.__init__s ?  "  !! $(!  d&&'''*//   " "!%c |j|Sr*rHrdrDs r/ __getitem__zPermutationGroup.__getitem__s""rfcrt|tstdt|z|j |S)aReturn ``True`` if *i* is contained in PermutationGroup. Examples ======== >>> from sympy.combinatorics import Permutation, PermutationGroup >>> p = Permutation(1, 2, 3) >>> Permutation(3) in PermutationGroup(p) True zRA PermutationGroup contains only Permutations as elements, not elements of type %s)r+r TypeErrortypecontainsris r/ __contains__zPermutationGroup.__contains__s?![)@BFq'JK K}}Qrfc,t|jSr*)r=rHrds r/__len__zPermutationGroup.__len__s4##$$rfct|tsyt|j}t|j}||k(ry|D]}|j |ry|D]}|j |ryy)aReturn ``True`` if PermutationGroup generated by elements in the group are same i.e they represent the same PermutationGroup. Examples ======== >>> from sympy.combinatorics import Permutation, PermutationGroup >>> p = Permutation(0, 1, 2, 3, 4, 5) >>> G = PermutationGroup([p, p**2]) >>> H = PermutationGroup([p**2, p]) >>> G.generators == H.generators False >>> G.equals(H) True FT)r+r&set generatorsrn)rdother set_self_gensset_other_gensgen1gen2s r/equalszPermutationGroup.equalss"%!12DOO, U--. N *" D>>$' # D==& rfct|trt||dS|jDcgc]}|j}}|jDcgc]}|j}}|j }|j }t t|}t t|||z}tt|D]} || D cgc]} | |z c} || <|D cgc]} || z }} |D cgc]} | |z }} ||z} | D cgc] } t| } } t| Scc}wcc}wcc} wcc} wcc} wcc} w)a Return the direct product of two permutation groups as a permutation group. Explanation =========== This implementation realizes the direct product by shifting the index set for the generators of the second group: so if we have ``G`` acting on ``n1`` points and ``H`` acting on ``n2`` points, ``G*H`` acts on ``n1 + n2`` points. Examples ======== >>> from sympy.combinatorics.named_groups import CyclicGroup >>> G = CyclicGroup(5) >>> H = G*G >>> H PermutationGroup([ (9)(0 1 2 3 4), (5 6 7 8 9)]) >>> H.order() 25 +)dir) r+rCosetru _array_formrZr8r<r=r>r&)rdrvpermgens1gens2n1n2startendrDxgentogethergenss r/__mul__zPermutationGroup.__mul__s06 e[ )#. ..2oo>d!!>>.3.>.>?d!!?? \\ ]]U2Y5R"W%&s5z" 2A(-a11B1E!H 2(-...&+,ss,,5=$,-q --%%?? 2.,-s#D'D, D1 D61 D;ENc|j}|jDcgc]}|j}}t|}||kr(t ||D]}|j |||z t t |} |j | ||_|!t |D]}|jyt |D]}|j||ycc}w)aInitialize random generators for the product replacement algorithm. Explanation =========== The implementation uses a modification of the original product replacement algorithm due to Leedham-Green, as described in [1], pp. 69-71; also, see [2], pp. 27-29 for a detailed theoretical analysis of the original product replacement algorithm, and [4]. The product replacement algorithm is used for producing random, uniformly distributed elements of a group `G` with a set of generators `S`. For the initialization ``_random_pr_init``, a list ``R`` of `\max\{r, |S|\}` group generators is created as the attribute ``G._random_gens``, repeating elements of `S` if necessary, and the identity element of `G` is appended to ``R`` - we shall refer to this last element as the accumulator. Then the function ``random_pr()`` is called ``n`` times, randomizing the list ``R`` while preserving the generation of `G` by ``R``. The function ``random_pr()`` itself takes two random elements ``g, h`` among all elements of ``R`` but the accumulator and replaces ``g`` with a randomly chosen element from `\{gh, g(~h), hg, (~h)g\}`. Then the accumulator is multiplied by whatever ``g`` was replaced by. The new value of the accumulator is then returned by ``random_pr()``. The elements returned will eventually (for ``n`` large enough) become uniformly distributed across `G` ([5]). For practical purposes however, the values ``n = 50, r = 11`` are suggested in [1]. Notes ===== THIS FUNCTION HAS SIDE EFFECTS: it changes the attribute self._random_gens See Also ======== random_pr N) _random_prec) r5rurr=r<appendr8ra random_pr) rdrn_random_prec_ndegr random_genskrDaccs r/_random_pr_initz PermutationGroup._random_pr_init!sTkk.2oo>q}}> >   q51a[ 7"";q1u#56 75:3'  !1X !  !1X ?N1,=> ??sCc|j||}|j||}||k7rK||||k\r||} }n||} }|||| z} | |jkDry||| <| ||<|j| yy)aCMerges two classes in a union-find data structure. Explanation =========== Used in the implementation of Atkinson's algorithm as suggested in [1], pp. 83-87. The class merging process uses union by rank as an optimization. ([7]) Notes ===== THIS FUNCTION HAS SIDE EFFECTS: the list of class representatives, ``parents``, the list of class sizes, ``ranks``, and the list of elements that are not representatives, ``not_rep``, are changed due to class merging. See Also ======== minimal_block, _union_find_rep References ========== .. [1] Holt, D., Eick, B., O'Brien, E. "Handbook of computational group theory" .. [7] https://algorithmist.com/wiki/Union_find r7r)_union_find_repmax_divr) rdfirstsecondranksparentsnot_rep rep_first rep_secondnew_1new_2 total_ranks r/_union_find_mergez"PermutationGroup._union_find_merge]s@((8 ))&':  "Y5#44(*u)9uue 4JDLL("GEN%E%L NN5 !rfct|||}}||k7r |}||}||k7r |||}}||k7r|||<|}||}||k7r|S)aFind representative of a class in a union-find data structure. Explanation =========== Used in the implementation of Atkinson's algorithm as suggested in [1], pp. 83-87. After the representative of the class to which ``num`` belongs is found, path compression is performed as an optimization ([7]). Notes ===== THIS FUNCTION HAS SIDE EFFECTS: the list of class representatives, ``parents``, is altered due to path compression. See Also ======== minimal_block, _union_find_merge References ========== .. [1] Holt, D., Eick, B., O'Brien, E. "Handbook of computational group theory" .. [7] https://algorithmist.com/wiki/Union_find )rdnumrrepparenttemps r/rz PermutationGroup._union_find_repsl>73>> from sympy.combinatorics import Permutation, PermutationGroup >>> G = PermutationGroup([Permutation(0, 1, 3)(2, 4)]) >>> G.base [0, 2] See Also ======== strong_gens, basic_transversals, basic_orbits, basic_stabilizers )r[ schreier_simsrqs r/basezPermutationGroup.bases&> ::     zzrfc $t|||||\}}}t|}|j} t||t||dzztt| ||||dzz} |dz|dz kDrg} n ||dzdd} |durt ||} | j ||dz} tt| | ||| k7rs| j ||dz| }| j|tt| | ||| k7rGn*t||}|j||||dz|vr|j||dztt| | ||| k7rtt|}|||}|jj||dz}|||dzvr|t| | |z }nV||dz|}t||}|||t| | ||vr$| j||t| | ||z }tt| | ||| k7r|dd}| ||dz<|dd}||dz||c||<||dz<t|}| D]}||vs|j|||fS)a Swap two consecutive base points in base and strong generating set. Explanation =========== If a base for a group `G` is given by `(b_1, b_2, \dots, b_k)`, this function returns a base `(b_1, b_2, \dots, b_{i+1}, b_i, \dots, b_k)`, where `i` is given by ``pos``, and a strong generating set relative to that base. The original base and strong generating set are not modified. The randomized version (default) is of Las Vegas type. Parameters ========== base, strong_gens The base and strong generating set. pos The position at which swapping is performed. randomized A switch between randomized and deterministic version. transversals The transversals for the basic orbits, if known. basic_orbits The basic orbits, if known. strong_gens_distr The strong generators distributed by basic stabilizers, if known. Returns ======= (base, strong_gens) ``base`` is the new base, and ``strong_gens`` is a generating set relative to it. Examples ======== >>> from sympy.combinatorics.named_groups import SymmetricGroup >>> from sympy.combinatorics.testutil import _verify_bsgs >>> from sympy.combinatorics.perm_groups import PermutationGroup >>> S = SymmetricGroup(4) >>> S.schreier_sims() >>> S.base [0, 1, 2] >>> base, gens = S.baseswap(S.base, S.strong_gens, 1, randomized=False) >>> base, gens ([0, 2, 1], [(0 1 2 3), (3)(0 1), (1 3 2), (2 3), (1 3)]) check that base, gens is a BSGS >>> S1 = PermutationGroup(gens) >>> _verify_bsgs(S1, base, gens) True See Also ======== schreier_sims Notes ===== The deterministic version of the algorithm is discussed in [1], pp. 102-103; the randomized version is discussed in [1], p.103, and [2], p.98. It is of Las Vegas type. Notice that [1] contains a mistake in the pseudocode and discussion of BASESWAP: on line 3 of the pseudocode, `|\beta_{i+1}^{\left\langle T\right\rangle}|` should be replaced by `|\beta_{i}^{\left\langle T\right\rangle}|`, and the same for the discussion of the algorithm. r7NT)schreier_vector)rr=r5_orbitr&r random_stabrrtremovenextiterrindexrmulr)rdr strong_genspos randomized transversals basic_orbitsstrong_gens_distrbase_lenr5r3Tstab_posrnewGammagammarryelstrong_gens_new_distrbase_newstrong_gens_newrs r/baseswapzPermutationGroup.baseswapsb %T; !-/@ B 6 l$5t9<$%c,sQw*?&@@&!23!7cAgGHI 7X\ !A!#'*1-A  '(9#(>?H&66tC!G}EOfVQS 23t;**4a=;J+L fVQS 23t;  S)*E LLc #C!G}% T#']+fVQS 23t;T%[) %e,}}**4a=9|C!G44!F61e$<>> from sympy.combinatorics.named_groups import SymmetricGroup >>> S = SymmetricGroup(4) >>> S.basic_orbits [[0, 1, 2, 3], [1, 2, 3], [2, 3]] See Also ======== base, strong_gens, basic_transversals, basic_stabilizers )r^rrqs r/rzPermutationGroup.basic_orbitsbs*8    #    !!!rfc|jgk(r|j|j}|j}|sgSt ||}g}|D]}|j t ||S)aD Return a chain of stabilizers relative to a base and strong generating set. Explanation =========== The ``i``-th basic stabilizer `G^{(i)}` relative to a base `(b_1, b_2, \dots, b_k)` is `G_{b_1, b_2, \dots, b_{i-1}}`. For more information, see [1], pp. 87-89. Examples ======== >>> from sympy.combinatorics.named_groups import AlternatingGroup >>> A = AlternatingGroup(4) >>> A.schreier_sims() >>> A.base [0, 1] >>> for g in A.basic_stabilizers: ... print(g) ... PermutationGroup([ (3)(0 1 2), (1 2 3)]) PermutationGroup([ (1 2 3)]) See Also ======== base, strong_gens, basic_orbits, basic_transversals )r_rr\r[rrr&)rdrrrbasic_stabilizersrs r/rz"PermutationGroup.basic_stabilizersswJ    #    '' zzI4T;G% =D  $ $%5d%; < =  rfcX|jgk(r|j|jS)a, Return basic transversals relative to a base and strong generating set. Explanation =========== The basic transversals are transversals of the basic orbits. They are provided as a list of dictionaries, each dictionary having keys - the elements of one of the basic orbits, and values - the corresponding transversal elements. See [1], pp. 87-89 for more information. Examples ======== >>> from sympy.combinatorics.named_groups import AlternatingGroup >>> A = AlternatingGroup(4) >>> A.basic_transversals [{0: (3), 1: (3)(0 1 2), 2: (3)(0 2 1), 3: (0 3 1)}, {1: (3), 2: (1 2 3), 3: (1 3 2)}] See Also ======== strong_gens, base, basic_orbits, basic_stabilizers )r_rrqs r/basic_transversalsz#PermutationGroup.basic_transversalss*:    #    !!!rfc |j}td|djDs tdg}t t |dz D]}||dz}g}||jD]}t |g|jz}|j|jz}g} t|jD]B\} } t | D]/} | jt |g|jz|| z}1D| |z}|}|||d<|j||j|d|S)a Return the composition series for a group as a list of permutation groups. Explanation =========== The composition series for a group `G` is defined as a subnormal series `G = H_0 > H_1 > H_2 \ldots` A composition series is a subnormal series such that each factor group `H(i+1) / H(i)` is simple. A subnormal series is a composition series only if it is of maximum length. The algorithm works as follows: Starting with the derived series the idea is to fill the gap between `G = der[i]` and `H = der[i+1]` for each `i` independently. Since, all subgroups of the abelian group `G/H` are normal so, first step is to take the generators `g` of `G` and add them to generators of `H` one by one. The factor groups formed are not simple in general. Each group is obtained from the previous one by adding one generator `g`, if the previous group is denoted by `H` then the next group `K` is generated by `g` and `H`. The factor group `K/H` is cyclic and it's order is `K.order()//G.order()`. The series is then extended between `K` and `H` by groups generated by powers of `g` and `H`. The series formed is then prepended to the already existing series. Examples ======== >>> from sympy.combinatorics.named_groups import SymmetricGroup >>> from sympy.combinatorics.named_groups import CyclicGroup >>> S = SymmetricGroup(12) >>> G = S.sylow_subgroup(2) >>> C = G.composition_series() >>> [H.order() for H in C] [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1] >>> G = S.sylow_subgroup(3) >>> C = G.composition_series() >>> [H.order() for H in C] [243, 81, 27, 9, 3, 1] >>> G = CyclicGroup(12) >>> C = G.composition_series() >>> [H.order() for H in C] [12, 6, 3, 1] c34K|]}|jywr*)r?r-rEs r/r0z6PermutationGroup.composition_series..s=Q1===r4rzGroup should be solvabler7r) derived_seriesallruNotImplementedErrorr<r=r&orderritemsrextend) rdderseriesrDHup_segrEKrdown_segpe_s r/composition_seriesz#PermutationGroup.composition_seriessPf!!#=#b'*<*<==%&@A As3xz" "AAaCAFV&& $aS1<<%78 QWWY.%e,224!DAq"1X! (8!q||9K(LMqD!!"F* AF1I MM& ! "  c"g rfc|j|s td|jdk(r |jS|j |j |j t |jt|jdz }|jdd}t|D](\}t|jfd|<*|j}|j}|j}t||D cgc]&\}} |j| jz(} }} t!|t!|kDr|t!|j} n|g} t!|dz t!| } dkDrg} |D]u}||k(r |z | D]G}||zt#fd|Dr| j%| t!| z| k(sGn| t!| z| k(sun| | z } | t!| z } dzdkDr| j'||g| z} | Scc} }w) zReturn a transversal of the right cosets of self by its subgroup H using the second method described in [1], Subsection 4.6.7 The argument must be a subgroupr7rNc|z Sr*r)rr base_orderingls r/z4PermutationGroup.coset_transversal..6s d1gai0Hrfkeyrc34K|]}|z k\ywr*r)r-hbrrs r/r0z5PermutationGroup.coset_transversal..PsFq=1-2F) is_subgroup ValueErrorrelements_schreier_simsrrr5rr enumeratesortedvaluesrrzipr=rrr)rdridentityrtorbitsh_stabsg_stabsrrindicesrt_lenT_nexturrrrrs @@@@@r/coset_transversalz"PermutationGroup.coset_transversals? }}T">? ? 779>==  (yy&tT[[9 t{{Q/..q1 l+ JDAq$QXXZ&HJLO J%%((474IJDAq1779aggi'JJ w<#g, &G %..A A LNA"fF!!_ =!$q'!),A!AFF1IFF a(s6{*gaj8  3v;&'!*4  KA S[ E FA!"f"  JN?Ks+Ic. |jdk(r|S|jdt|j|jk(s|j|j|jdd|j Dcgc]}t |jc}|j Dcgc]}t |jc} |jt|j fdd|Scc}wcc}w)zReturn the representative of Hg from the transversal that would be computed by ``self.coset_transversal(H)``. r7Nrc(t |fd}|Dcgc] }||z  c}j|}||z|t dz kr2 |D]}||z |z k(sn |dzdzz|zScc}w)Nc|z Sr*r)rrrs r/rzFPermutationGroup._coset_representative..step..ms=13Erfrr7r)minrr=) rrrrrDrrrh_transversalsrsteprs ` r/r z4PermutationGroup._coset_representative..steplsq )EFE$21$56qa6<Hyy#aff+&!&&0   QVV  ,"454H4HIq$qxxz*I262I2IJQQXXZ(J yy&tT[[9   AqzJJs  D 5 Dc|j|s td|j|}t|}t t j d|jD}g}t|D]V}|Dcgc]}|j|||z|}}|D cgc]} |j| }} |j|Xtt|}d} tt||D]\} } || | } | | k\rg| | kDr]|D]X}|| |}|| ||| |<||| |<t|D]*}|||| k(r | |||<|||| k(s#| |||<,Z| dz } | |dz k\s|cSycc}wcc} w)z]Return the standardised (right) coset table of self in H as a list of lists. rc3*K|] }||dzf yw)rNr)r-rs r/r0z/PermutationGroup.coset_table..s %0'*37^%0sr7N) rrrr=r8r from_iterablerur<r rrr)rdrrrAtablerDrrowrralphar.betazs r/ coset_tablezPermutationGroup.coset_tablexs}}T">? ?  " "1 % F $$%0#%00 1q ABCDQ4--ad1fa8DCD'*+!1771:+C+ LL   #a&Ma!, HE1<?Du}%<3!%LO*/+a.e Q)*d A!&q3A$Qx{d2.3a !&q!!5.2a 3 3 !|  E+s <F!Fc^|js|j||_|jS)a  Return the center of a permutation group. Explanation =========== The center for a group `G` is defined as `Z(G) = \{z\in G | \forall g\in G, zg = gz \}`, the set of elements of `G` that commute with all elements of `G`. It is equal to the centralizer of `G` inside `G`, and is naturally a subgroup of `G` ([9]). Examples ======== >>> from sympy.combinatorics.named_groups import DihedralGroup >>> D = DihedralGroup(4) >>> G = D.center() >>> G.order() 2 See Also ======== centralizer Notes ===== This is a naive implementation that is a straightforward application of ``.centralizer()`` )rK centralizerrqs r/centerzPermutationGroup.centers(D||++D1DL||rfc~tdrӉjs |jr|S|j}tt t |}j }t|}|jdg}dg|zdg|z}dg|zt |D]7}t ||} | d|<t|||<| D]} || < || z}9|j|\} t| } d}t tD] }| ||gk(s nd||} t |D]}| dz ||vsn|ddz}t|}dg|zt |D]&}|}tj|d |<(d }dg| z}t | D]}|vr|||<|ffd }|||< fd }|j|| | Stdr%t }|jt|Stdr|jtgSy)a Return the centralizer of a group/set/element. Explanation =========== The centralizer of a set of permutations ``S`` inside a group ``G`` is the set of elements of ``G`` that commute with all elements of ``S``:: `C_G(S) = \{ g \in G | gs = sg \forall s \in S\}` ([10]) Usually, ``S`` is a subset of ``G``, but if ``G`` is a proper subgroup of the full symmetric group, we allow for ``S`` to have elements outside ``G``. It is naturally a subgroup of ``G``; the centralizer of a permutation group is equal to the centralizer of any set of generators for that group, since any element commuting with the generators commutes with any product of the generators. Parameters ========== other a permutation group/list of permutations/single permutation Examples ======== >>> from sympy.combinatorics.named_groups import (SymmetricGroup, ... CyclicGroup) >>> S = SymmetricGroup(6) >>> C = CyclicGroup(6) >>> H = S.centralizer(C) >>> H.is_subgroup(C) True See Also ======== subgroup_search Notes ===== The implementation is an application of ``.subgroup_search()`` with tests using a specific base for the group ``G``. ruct| Sr*r=rs r/rz.PermutationGroup.centralizer..s s1vgrfrNrrr7TpairscyNTrrs r/rz.PermutationGroup.centralizer.."rfc||} |} |}|j|}|j|} ||}||j|k(Sr*r) computed_wordsrrE rep_orb_indexrimim_reptr_elr orbit_descr orbit_repsrs r/testz*PermutationGroup.centralizer..test(sp*1-(3DG(< (7]]473!"s!3 ,] ;DG D "U%6%6v%>>>rfcjDcgc]}t||c}jDcgc]}t||c}k(Scc}wcc}wr*)rur)rErrvs r/propz*PermutationGroup.centralizer..prop6sI050@0@AQ A050@0@AS! ABBAAs A A)rrtestsrj array_form)hasattr is_trivialr5r>r8r<rr=sortschreier_sims_incrementalrdictorbit_transversalsubgroup_searchrr&)rdrvr5rr num_orbits long_baseorbit_reps_indicesrDorbitpointrrrj rel_orbitsnum_rel_orbitsr trivial_testr-rr*r,rrr(r)rs ` @@@@r/rzPermutationGroup.centralizersf 5, '4?? [[FtE&M23H\\^FVJ KK-K .I *J"& !2 &-K:& .VAY %a 1 (+I"1%"+E)*K&+%-  .!% > >I > N D+ 8{ K A3t9% $Q'H:5 8DH:& 1 %2  !a%J _N 6.0L>* > m"&++Ct+<#> Q >*LF8OE8_ $7j(+E!H/0 ? ? $E!H! $$ B''44?u(N N UM *;D##$4T$:; ; UL )##$4eW$=> >*rfc|j}|j}g}|D]/}|D](}t||||}||vs|j|*1|j|} | S)a Return the commutator of two subgroups. Explanation =========== For a permutation group ``K`` and subgroups ``G``, ``H``, the commutator of ``G`` and ``H`` is defined as the group generated by all the commutators `[g, h] = hgh^{-1}g^{-1}` for ``g`` in ``G`` and ``h`` in ``H``. It is naturally a subgroup of ``K`` ([1], p.27). Examples ======== >>> from sympy.combinatorics.named_groups import (SymmetricGroup, ... AlternatingGroup) >>> S = SymmetricGroup(5) >>> A = AlternatingGroup(5) >>> G = S.commutator(S, A) >>> G.is_subgroup(A) True See Also ======== derived_subgroup Notes ===== The commutator of two subgroups `H, G` is equal to the normal closure of the commutators of all the generators, i.e. `hgh^{-1}g^{-1}` for `h` a generator of `H` and `g` a generator of `G` ([1], p.28) )rurrnormal_closure) rdGrggenshgens commutatorsggenhgen commutatorress r/rGzPermutationGroup.commutatorAs{H    3D 3!$tedU; [0&&z2 3 3 !!+. rfct|ttfr|j}t ||j k7r t dtt|j }|j}|j}g}|j}|}tt |D]g} ||| } | || k(r|j| %| || vrgcS|| | j} tt| |}|j| i||k7rgS|r|S|j} tt |D cgc] } | | || }} |Scc} w)aReturn ``G``'s (self's) coset factorization of ``g`` Explanation =========== If ``g`` is an element of ``G`` then it can be written as the product of permutations drawn from the Schreier-Sims coset decomposition, The permutations returned in ``f`` are those for which the product gives ``g``: ``g = f[n]*...f[1]*f[0]`` where ``n = len(B)`` and ``B = G.base``. f[i] is one of the permutations in ``self._basic_orbits[i]``. If factor_index==True, returns a tuple ``[b[0],..,b[n]]``, where ``b[i]`` belongs to ``self._basic_orbits[i]`` Examples ======== >>> from sympy.combinatorics import Permutation, PermutationGroup >>> a = Permutation(0, 1, 3, 7, 6, 4)(2, 5) >>> b = Permutation(0, 1, 3, 2)(4, 5, 7, 6) >>> G = PermutationGroup([a, b]) Define g: >>> g = Permutation(7)(1, 2, 4)(3, 6, 5) Confirm that it is an element of G: >>> G.contains(g) True Thus, it can be written as a product of factors (up to 3) drawn from u. See below that a factor from u1 and u2 and the Identity permutation have been used: >>> f = G.coset_factor(g) >>> f[2]*f[1]*f[0] == g True >>> f1 = G.coset_factor(g, True); f1 [0, 4, 4] >>> tr = G.basic_transversals >>> f[0] == tr[0][f1[0]] True If g is not an element of G then [] is returned: >>> c = Permutation(5, 6, 7) >>> G.coset_factor(c) [] See Also ======== sympy.combinatorics.util._strip z.g should be the same size as permutations of G)r+rrr8r=rZrr<rr_rrrr r r) rdrE factor_indexIrrfactorsrrrDrrtrs r/ coset_factorzPermutationGroup.coset_factorpsNx a%- .A q6T\\ !MN N t||$ %(( )) yy s4y! !AT!W:DtAwt$<?* Q%11AA*A NN4  ! 6I N  $ $.3CI.>?2a5$??@s;Ec8g}|jrgS||jvrN|r||jvr|gS|j|}|D]%}|j|j |d'|S|dz|jvr|dz}|r||jvr|dzgS|j|}|D]%}|j|j |d't |}t|Dcgc]}|||z dz dz}}|S|j|d}t|D]r\}} |j|| }|D]V}|s |j|j|%|j|}|j|j |dXt|Scc}w)z Return a list of strong generators `[s1, \dots, sn]` s.t `g = sn \times \dots \times s1`. If ``original=True``, make the list contain only the original group generators Toriginalrr7) r?rrur]rgenerator_productr=r<rNrr`r) rdrErQrslpsrrDfr;s r/rRz"PermutationGroup.generator_products ==I   qDOO3s ++A.MA"GNN4#9#9!d#9#KLM Ud&& &2AqDOO32w++A.MA"GNN4#9#9!d#9#KLML72-@@   a &aL MDAq''*1-C M"GNN4#3#3A#67((+A"GNN4#9#9!d#9#KL  M MAs*Fc|j|d}|syd}d}|j}|j}|j}t t |D]4}||} ||j | } ||| zz }|t ||z}6|S)a;rank using Schreier-Sims representation. Explanation =========== The coset rank of ``g`` is the ordering number in which it appears in the lexicographic listing according to the coset decomposition The ordering is the same as in G.generate(method='coset'). If ``g`` does not belong to the group it returns None. Examples ======== >>> from sympy.combinatorics import Permutation, PermutationGroup >>> a = Permutation(0, 1, 3, 7, 6, 4)(2, 5) >>> b = Permutation(0, 1, 3, 2)(4, 5, 7, 6) >>> G = PermutationGroup([a, b]) >>> c = Permutation(7)(2, 4)(3, 5) >>> G.coset_rank(c) 16 >>> G.coset_unrank(16) (7)(2 4)(3 5) See Also ======== coset_factor TNrr7)rNr_r[r^r<r=r) rdrErLrankrrrrrDrr;s r/ coset_rankzPermutationGroup.coset_ranks@##At, )) zz)) s4y! 'A AQ%%a(A AaCKD#l1o&&A  '  rfc|dks||jk\ry|j}|j}|j}t |}dg|z}t |D](}t |t ||\}} ||| ||<*t |Dcgc]}||||j} }t| } |r| St| Scc}w)zunrank using Schreier-Sims representation coset_unrank is the inverse operation of coset_rank if 0 <= rank < order; otherwise it returns None. rN) rrrrr=r<divmodrr r>) rdrWafrrrmvrDcr.rs r/ coset_unrankzPermutationGroup.coset_unrank#s !8ttzz|+yy.. (( I CEq &AT3|A#78GD!?1%AaD &9>a A1\!_QqT " . . A A qM H1:  BsCc|jS)aReturns the size of the permutations in the group. Explanation =========== The number of permutations comprising the group is given by ``len(group)``; the number of permutations that can be generated by the group is given by ``group.order()``. Examples ======== >>> from sympy.combinatorics import Permutation, PermutationGroup >>> a = Permutation([1, 0, 2]) >>> G = PermutationGroup([a]) >>> G.degree 3 >>> len(G) 1 >>> G.order() 2 >>> list(G.generate()) [(2), (2)(0 1)] See Also ======== order )rZrqs r/r5zPermutationGroup.degree;s>||rfcPttt|jS)zH Return the identity element of the permutation group. )r>r8r<r5rqs r/rzPermutationGroup.identity\s tE$++./00rfcn|jst|j|_|jS)aIReturns all the elements of the permutation group as a list Examples ======== >>> from sympy.combinatorics import Permutation, PermutationGroup >>> p = PermutationGroup(Permutation(1, 3), Permutation(1, 2)) >>> p.elements [(3), (3)(1 2), (1 3), (2 3), (1 2 3), (1 3 2)] )rJr8generaterqs r/rzPermutationGroup.elementsds'~~!$--/2DN~~rfc|g}|}|j}|j|s5|j||}|j}|j|s5|S)aIReturn the derived series for the group. Explanation =========== The derived series for a group `G` is defined as `G = G_0 > G_1 > G_2 > \ldots` where `G_i = [G_{i-1}, G_{i-1}]`, i.e. `G_i` is the derived subgroup of `G_{i-1}`, for `i\in\mathbb{N}`. When we have `G_k = G_{k-1}` for some `k\in\mathbb{N}`, the series terminates. Returns ======= A list of permutation groups containing the members of the derived series in the order `G = G_0, G_1, G_2, \ldots`. Examples ======== >>> from sympy.combinatorics.named_groups import (SymmetricGroup, ... AlternatingGroup, DihedralGroup) >>> A = AlternatingGroup(5) >>> len(A.derived_series()) 1 >>> S = SymmetricGroup(4) >>> len(S.derived_series()) 4 >>> S.derived_series()[1].is_subgroup(AlternatingGroup(4)) True >>> S.derived_series()[2].is_subgroup(DihedralGroup(2)) True See Also ======== derived_subgroup )derived_subgrouprrrdrHcurrentnxts r/rzPermutationGroup.derived_seriesvsbPf##%%%c* JJsOG&&(C%%c* rfc |j}|jDcgc]}|j}}t}|j}t t |}t |D]i}t |D]Y}||} ||} t t |} |D]} | | | | | | | <t| } | |vsI|j| [k|Dcgc] }t|}}|j|}|Scc}wcc}w)a Compute the derived subgroup. Explanation =========== The derived subgroup, or commutator subgroup is the subgroup generated by all commutators `[g, h] = hgh^{-1}g^{-1}` for `g, h\in G` ; it is equal to the normal closure of the set of commutators of the generators ([1], p.28, [11]). Examples ======== >>> from sympy.combinatorics import Permutation, PermutationGroup >>> a = Permutation([1, 0, 2, 4, 3]) >>> b = Permutation([0, 1, 3, 2, 4]) >>> G = PermutationGroup([a, b]) >>> C = G.derived_subgroup() >>> list(C.generate(af=True)) [[0, 1, 2, 3, 4], [0, 1, 3, 4, 2], [0, 1, 4, 2, 3]] See Also ======== derived_series ) rYrurrtrZr8r<tupleaddr>r@)rdrrrset_commutatorsr5rngrDr;p1p2r^rctcmsG2s r/rez!PermutationGroup.derived_subgroups 8 GG'+7! 77%5=!q ,A1X ,!W!Wv'-A#%be9AbAiL-1X_,#''+ , ,$33awqz33   % !84s C<Dcv|dk(r|j|S|dk(r|j|Std|z)aReturn iterator to generate the elements of the group. Explanation =========== Iteration is done with one of these methods:: method='coset' using the Schreier-Sims coset representation method='dimino' using the Dimino method If ``af = True`` it yields the array form of the permutations Examples ======== >>> from sympy.combinatorics import PermutationGroup >>> from sympy.combinatorics.polyhedron import tetrahedron The permutation group given in the tetrahedron object is also true groups: >>> G = tetrahedron.pgroup >>> G.is_group True Also the group generated by the permutations in the tetrahedron pgroup -- even the first two -- is a proper group: >>> H = PermutationGroup(G[0], G[1]) >>> J = PermutationGroup(list(H.generate())); J PermutationGroup([ (0 1)(2 3), (1 2 3), (1 3 2), (0 3 1), (0 2 3), (0 3)(1 2), (0 1 3), (3)(0 2 1), (0 3 2), (3)(0 1 2), (0 2)(1 3)]) >>> _.is_group True cosetdiminozNo generation defined for %s)generate_schreier_simsgenerate_diminor)rdmethodr[s r/rczPermutationGroup.generatesH\ W ..r2 2 x ''+ +%&Dv&MN Nrfc #Ktt|j}d}|g}t|h}|r|n t ||j Dcgc]}|j }}tt|D]}|j} |g} | s| } g} | D]} |d|dzD]} t| | }t||vs| D]e}|dz }t||}|r|nt |}||j||jt|| j|g| rt||_ ycc}ww)aYield group elements using Dimino's algorithm. If ``af == True`` it yields the array form of the permutations. Examples ======== >>> from sympy.combinatorics import Permutation, PermutationGroup >>> a = Permutation([0, 2, 1, 3]) >>> b = Permutation([0, 2, 3, 1]) >>> g = PermutationGroup([a, b]) >>> list(g.generate_dimino(af=True)) [[0, 1, 2, 3], [0, 2, 1, 3], [0, 2, 3, 1], [0, 1, 3, 2], [0, 3, 2, 1], [0, 3, 1, 2]] References ========== .. [1] The Implementation of Various Algorithms for Permutation Groups in the Computer Algebra System: AXIOM, N.J. Doye, M.Sc. Thesis rNr7) r8r<r5rjr>rurr=copyr rrkrI)rdr[idnr element_listset_element_listrrrDDNrr.rEagdaps r/rwz PermutationGroup.generate_dimino sV.5%&u !#J< I#, '+7! 77s4y! -A!!#AA-A!&1q5\-%a^ 9,<<%& - % %-a_#%*,H(/ A*+G , 3 3B 7 0 4 4U2Y ? !  - --  -.,' 38s%AE E'.E -E A0E 5E c#K|j}|j}|j}t|dk(r'|jD]}|r|j |yt|dk(r,|dD]#}|r|d|j |d|%yt t|}|ddd}t t|g}|Dcgc] }t|}}t|dz } dg| z} d} | | || k\r!| dk(ryd| | <| dz} |j-t|| || | | j |d} | | xxdz cc<|j| | dz } | | k(r}|r.|dD]%}t|d|j |d} | 'n8|dD]0}t|d|j |d} t| } | 2|j| dz} cc}ww)a,Yield group elements using the Schreier-Sims representation in coset_rank order If ``af = True`` it yields the array form of the permutations Examples ======== >>> from sympy.combinatorics import Permutation, PermutationGroup >>> a = Permutation([0, 2, 1, 3]) >>> b = Permutation([0, 2, 3, 1]) >>> g = PermutationGroup([a, b]) >>> list(g.generate_schreier_sims(af=True)) [[0, 1, 2, 3], [0, 2, 1, 3], [0, 3, 2, 1], [0, 1, 3, 2], [0, 2, 3, 1], [0, 3, 1, 2]] rNr7r) rZrr^r=rurr8reversedr<r:r rr>)rdr[rrrrrDstgposmaxrrrrrns r/rvz'PermutationGroup.generate_schreier_simsEs,$ LL  # #)) q6Q;__ --'G    q6Q;!!_ "A$q'---A$q'M  "  ! #DbD) E!H~"#$Q#a&$$ [1_c"f 1v"6AQ 1l1oc!f56BBCGLA FaKF JJqM FABw)"- $QrU1X%9%93r7C *"-!$QrU1X%9%93r7C$QZ ! Q1 %sC G5 G0DG5c|jS)aFReturns the generators of the group. Examples ======== >>> from sympy.combinatorics import Permutation, PermutationGroup >>> a = Permutation([0, 2, 1]) >>> b = Permutation([1, 0, 2]) >>> G = PermutationGroup([a, b]) >>> G.generators [(1 2), (2)(0 1)] rhrqs r/ruzPermutationGroup.generatorssrfct|tsy|j|jk7r|ryt||j}||jvryt |j |jdS)aTest if permutation ``g`` belong to self, ``G``. Explanation =========== If ``g`` is an element of ``G`` it can be written as a product of factors drawn from the cosets of ``G``'s stabilizers. To see if ``g`` is one of the actual generators defining the group use ``G.has(g)``. If ``strict`` is not ``True``, ``g`` will be resized, if necessary, to match the size of permutations in ``self``. Examples ======== >>> from sympy.combinatorics import Permutation, PermutationGroup >>> a = Permutation(1, 2) >>> b = Permutation(2, 3, 1) >>> G = PermutationGroup(a, b, degree=5) >>> G.contains(G[0]) # trivial check True >>> elem = Permutation([[2, 3]], size=5) >>> G.contains(elem) True >>> G.contains(Permutation(4)(0, 1, 2, 3)) False If strict is False, a permutation will be resized, if necessary: >>> H = PermutationGroup(Permutation(5)) >>> H.contains(Permutation(3)) False >>> H.contains(Permutation(3), strict=False) True To test if a given permutation is present in the group: >>> elem in G.generators False >>> G.has(elem) False See Also ======== coset_factor, sympy.core.basic.Basic.has, __contains__ Fr2T)r+rr3r5ruboolrNr.)rdrEstricts r/rnzPermutationGroup.containssch![) 66T[[ ADKK0A  D%%allD9::rfcz|j$|j|j|_|jS)aReturn ``True`` if the group is perfect. A group is perfect if it equals to its derived subgroup. Examples ======== >>> from sympy.combinatorics import Permutation, PermutationGroup >>> a = Permutation(1,2,3)(4,5) >>> b = Permutation(1,2,3,4,5) >>> G = PermutationGroup([a, b]) >>> G.is_perfect False )rVr{rerqs r/ is_perfectzPermutationGroup.is_perfects6    ##{{4+@+@+BCD rfc|j |jSd|_|jDcgc]}|j}}|D]%}|D]}||kr t||rd|_y'ycc}w)aTest if the group is Abelian. Examples ======== >>> from sympy.combinatorics import Permutation, PermutationGroup >>> a = Permutation([0, 2, 1]) >>> b = Permutation([1, 0, 2]) >>> G = PermutationGroup([a, b]) >>> G.is_abelian False >>> a = Permutation([0, 2, 1]) >>> G = PermutationGroup([a]) >>> G.is_abelian True TF)rLrurr )rdrrrrs r/ is_abelianzPermutationGroup.is_abelians&    '## #'+7! 77 !A !6(A.',D$  ! !8sA.cn|jrgS|j}g}|}|j}|j}t|j D]}g} g}|D]*} | |z} |j | r|j | ,|rt||zn|} |j | j z} | }|}| dk(rn|j t|| |sdg|dz}|D]} t| D] }|||z||<|j||j|S)aF Returns the abelian invariants for the given group. Let ``G`` be a nontrivial finite abelian group. Then G is isomorphic to the direct product of finitely many nontrivial cyclic groups of prime-power order. Explanation =========== The prime-powers that occur as the orders of the factors are uniquely determined by G. More precisely, the primes that occur in the orders of the factors in any such decomposition of ``G`` are exactly the primes that divide ``|G|`` and for any such prime ``p``, if the orders of the factors that are p-groups in one such decomposition of ``G`` are ``p^{t_1} >= p^{t_2} >= ... p^{t_r}``, then the orders of the factors that are p-groups in any such decomposition of ``G`` are ``p^{t_1} >= p^{t_2} >= ... p^{t_r}``. The uniquely determined integers ``p^{t_1} >= p^{t_2} >= ... p^{t_r}``, taken for all primes that divide ``|G|`` are called the invariants of the nontrivial group ``G`` as suggested in ([14], p. 542). Notes ===== We adopt the convention that the invariants of a trivial group are []. Examples ======== >>> from sympy.combinatorics import Permutation, PermutationGroup >>> a = Permutation([0, 2, 1]) >>> b = Permutation([1, 0, 2]) >>> G = PermutationGroup([a, b]) >>> G.abelian_invariants() [2] >>> from sympy.combinatorics import CyclicGroup >>> G = CyclicGroup(7) >>> G.abelian_invariants() [7] r7r) r0rurerrrnrr&r r<rr1)rdgnsinvrArHgensrrpowsrEelmrrrDr;s r/abelian_invariantsz#PermutationGroup.abelian_invariantssMT ??Ioo     aggi( !AE)AQ$C::c? C()7;$UT\2GGIqwwy(6 \!Q/0s58|,A"1X,"&q'!)Q,, 4 + !,   rfc\|jxrtfd|jDS)aReturn ``True`` if the group is elementary abelian. An elementary abelian group is a finite abelian group, where every nontrivial element has order `p`, where `p` is a prime. Examples ======== >>> from sympy.combinatorics import Permutation, PermutationGroup >>> a = Permutation([0, 2, 1]) >>> G = PermutationGroup([a]) >>> G.is_elementary(2) True >>> a = Permutation([0, 2, 1, 3]) >>> b = Permutation([3, 1, 2, 0]) >>> G = PermutationGroup([a, b]) >>> G.is_elementary(2) True >>> G.is_elementary(3) False c3DK|]}|jk(ywr*r)r-rErs r/r0z1PermutationGroup.is_elementary..os&O!qwwyA~&O )rrru)rdrs `r/ is_elementaryzPermutationGroup.is_elementaryYs#,O3&Ot&O#OOrfc|r|rtdj|||j}t|}|j }||k(rd|_d|_| Sd|z|k(rd|_d|_| Sy)z#A naive test using the group order.z$Both {} and {} cannot be set to TrueTFr)rformatr5 _factorialrrNrO)rdonly_symonly_altr sym_orderrs r/_eval_is_alt_sym_naivez'PermutationGroup._eval_is_alt_sym_naiveqs 6(+- - KKqM   I DL DL<  U7i  DLDL< rfc|nj}|dkrd}nd}|tdzt|z }tt| |z }fdt|D}j |S|D]}t |syy) aA test using monte-carlo algorithm. Parameters ========== eps : float, optional The criterion for the incorrect ``False`` return. perms : list[Permutation], optional If explicitly given, it tests over the given candidates for testing. If ``None``, it randomly computes ``N_eps`` and chooses ``N_eps`` sample of the permutation from the group. See Also ======== _check_cycles_alt_sym g(\?g= ףp=?rc3>K|]}jywr*)r)r-rDrds r/r0z@PermutationGroup._eval_is_alt_sym_monte_carlo..s= 8. Explanation =========== More specifically, it is one-sided Monte Carlo with the answer True (i.e., G is symmetric/alternating) guaranteed to be correct, and the answer False being incorrect with probability eps. For degree < 8, the order of the group is checked so the test is deterministic. Notes ===== The algorithm itself uses some nontrivial results from group theory and number theory: 1) If a transitive group ``G`` of degree ``n`` contains an element with a cycle of length ``n/2 < p < n-2`` for ``p`` a prime, ``G`` is the symmetric or alternating group ([1], pp. 81-82) 2) The proportion of elements in the symmetric/alternating group having the property described in 1) is approximately `\log(2)/\log(n)` ([1], p.82; [2], pp. 226-227). The helper function ``_check_cycles_alt_sym`` is used to go over the cycles in a permutation and look for ones satisfying 1). Examples ======== >>> from sympy.combinatorics.named_groups import DihedralGroup >>> D = DihedralGroup(10) >>> D.is_alt_sym() False See Also ======== _check_cycles_alt_sym rc3(K|] }| ywr*r)r-rDrs r/r0z.PermutationGroup.is_alt_sym..s:LO:rTF)rFF)r<rrNrOr5r is_transitive)rdrrrrrs ` r/ is_alt_symzPermutationGroup.is_alt_symsT  # )E:U5\:E4454A A <<4<< <<5 T\\U%: KK q5..0 0    !444= =%1" dlrfc6|j|j}|t|dz }|j}|j}t t t|tfd|Drd|_ d|_yd|_y|jS)aTest if the group is nilpotent. Explanation =========== A group `G` is nilpotent if it has a central series of finite length. Alternatively, `G` is nilpotent if its lower central series terminates with the trivial group. Every nilpotent group is also solvable ([1], p.29, [12]). Examples ======== >>> from sympy.combinatorics.named_groups import (SymmetricGroup, ... CyclicGroup) >>> C = CyclicGroup(6) >>> C.is_nilpotent True >>> S = SymmetricGroup(5) >>> S.is_nilpotent False See Also ======== lower_central_series, is_solvable r7c3(K|] }|k( ywr*rr-rErs r/r0z0PermutationGroup.is_nilpotent../Q1=/rTF) rQlower_central_seriesr=rur5r>r8r<rrR)rdlcs terminatorrr5rs @r/ is_nilpotentzPermutationGroup.is_nilpotents<    %++-CSX\*J((D[[FtE&M23H/$//$(!%)"%*"%% %rfc ~|j||sy|j}|j}|jr||k(s|sy|jry|j }|sU||k7rP||kr&t |j t|dz gz}n%t |j t|dz gz}|j Dcgc]}|j}}|j Dcgc]}|j}}|D]4} |D]-} t| | t| }|j|dr,y6ycc}wcc}w)azTest if ``G=self`` is a normal subgroup of ``gr``. Explanation =========== G is normal in gr if for each g2 in G, g1 in gr, ``g = g1*g2*g1**-1`` belongs to G It is sufficient to check this for each g1 in gr.generators and g2 in G.generators. Examples ======== >>> from sympy.combinatorics import Permutation, PermutationGroup >>> a = Permutation([1, 2, 0]) >>> b = Permutation([1, 0, 2]) >>> G = PermutationGroup([a, b]) >>> G1 = PermutationGroup([a, Permutation([2, 0, 1])]) >>> G1.is_normal(G) True rFTr7) rr5r0rLrz PermGrouprurrr r rN) rdgrrd_selfd_grnew_selfrrrg1g2s r/ is_normalzPermutationGroup.is_normals-.62yy ??$f   99;&D.}$X%8%8Kq>> from sympy.combinatorics.named_groups import DihedralGroup >>> D = DihedralGroup(10) >>> D.is_primitive() False See Also ======== minimal_block, random_stab Frc3&K|] }|dk7 ywrNrr-rs r/r0z0PermutationGroup.is_primitive..sIa1fIT) rPrrr<r=rrr& stabilizerrr:r9 minimal_block) rdrrandom_stab_gensr]rstabrorbrs r/ is_primitivezPermutationGroup.is_primitiveGsP    )%% %    5 ( ! $$Q'A3t9% @ ''(8(8A(>? @#$45D??1%D C AAv#Id.@.@!Q.HII%*"   "rfczd}|jsyg}g}g}|rYg}|jd}tt|D]#}|j |j d|%t |} n|jd} | j} | D]} | j} | dk7s|jd| g} || \}}t|jDchc] }||dk(s |}}d}dgt|z}t|D]`\}}t|t|kDr|j|rd||<4t|t|ksL|j|s^d}nt|Dcgc] \}}||r |}}}t|Dcgc] \}}||r |}}}t|Dcgc] \}}||r |}}}|sO||vsU|j | |j ||j ||Scc}wcc}}wcc}}wcc}}w)aX For a transitive group, return the list of all minimal block systems. If a group is intransitive, return `False`. Examples ======== >>> from sympy.combinatorics import Permutation, PermutationGroup >>> from sympy.combinatorics.named_groups import DihedralGroup >>> DihedralGroup(6).minimal_blocks() [[0, 1, 0, 1, 0, 1], [0, 1, 2, 0, 1, 2]] >>> G = PermutationGroup(Permutation(1,2,5)) >>> G.minimal_blocks() False See Also ======== minimal_block, is_transitive, is_primitive ct|}i}d}dg|z}t|D]'}|||vr||||<|||<|dz }|||||<)t||fS)Nrr7)r=r<rj)blocksrappearedr\rrDs r/_number_blocksz7PermutationGroup.minimal_blocks.._number_blockss F AHAqA1X /!9H,*+HVAY'AaDFA#F1I.AaD  /8Q; rfFrT)rrr<r=rrr&rrr:rr5rissubset)rdrrr num_blocks rep_blocksrr]rDrrrrblock num_blockrr;rminimalblocks_remove_maskrrrs r/minimal_blockszPermutationGroup.minimal_blockss6* $!!#  ! $$Q'A3t9% @ ''(8(8A(>? @#$45D??1%D +C AAv**Aq62-e4 1"' "4JQ ! 8IqJJ&+Ws6{%:"%j1DAq1vC(S\\!_04*1-Q#c(*qzz#"')2&(9W1ASTUAV!WW,5j,A_DAqI[\]I^a_ _,5j,A_DAqI[\]I^a_ _y :MM%(%%i0%%c*7 +8 -KX__s0( H&6H& H+H+, H1:H1 H7H7cV|j|jdzdk7ry|j}|t|dz }|j}|j }t tt|tfd|Drd|_yd|_y|jS)aTest if the group is solvable. ``G`` is solvable if its derived series terminates with the trivial group ([1], p.29). Examples ======== >>> from sympy.combinatorics.named_groups import SymmetricGroup >>> S = SymmetricGroup(3) >>> S.is_solvable True See Also ======== is_nilpotent, derived_series rrTr7c3(K|] }|k( ywr*rrs r/r0z/PermutationGroup.is_solvable..rrF) rRrrr=rur5r>r8r<r)rddsrrr5rs @r/ is_solvablezPermutationGroup.is_solvables*    $zz|a1$$$&BCGaKJ((D[[FtE&M23H/$//$(!$)!$$ $rfcttr|jjk7ryyttsy|k(s|jdt k(ryj |j zdk7ry|jjk(s|jjkrs |j}nytfd|DS)aNReturn ``True`` if all elements of ``self`` belong to ``G``. If ``strict`` is ``False`` then if ``self``'s degree is smaller than ``G``'s, the elements will be resized to have the same degree. Examples ======== >>> from sympy.combinatorics import Permutation, PermutationGroup >>> from sympy.combinatorics import SymmetricGroup, CyclicGroup Testing is strict by default: the degree of each group must be the same: >>> p = Permutation(0, 1, 2, 3, 4, 5) >>> G1 = PermutationGroup([Permutation(0, 1, 2), Permutation(0, 1)]) >>> G2 = PermutationGroup([Permutation(0, 2), Permutation(0, 1, 2)]) >>> G3 = PermutationGroup([p, p**2]) >>> assert G1.order() == G2.order() == G3.order() == 6 >>> G1.is_subgroup(G2) True >>> G1.is_subgroup(G3) False >>> G3.is_subgroup(PermutationGroup(G3[1])) False >>> G3.is_subgroup(PermutationGroup(G3[0])) True To ignore the size, set ``strict`` to ``False``: >>> S3 = SymmetricGroup(3) >>> S5 = SymmetricGroup(5) >>> S3.is_subgroup(S5, strict=False) True >>> C7 = CyclicGroup(7) >>> G = S5*C7 >>> S5.is_subgroup(G, False) True >>> C7.is_subgroup(G, 0) False FTrc3DK|]}j|yw)rN)rn)r-rErArs r/r0z/PermutationGroup.is_subgroup..9 s>A1::a:/>r)r+SymmetricPermutationGroupr5r&rurrr)rdrArrs `` r/rzPermutationGroup.is_subgroupsV a2 3{{ahh&!-. 19*KM9 779tzz| #q ( ;;!(( "qxx'??D>>>>rfc|jS)aReturn ``True`` if a group is polycyclic. A group is polycyclic if it has a subnormal series with cyclic factors. For finite groups, this is the same as if the group is solvable. Examples ======== >>> from sympy.combinatorics import Permutation, PermutationGroup >>> a = Permutation([0, 2, 1, 3]) >>> b = Permutation([2, 0, 1, 3]) >>> G = PermutationGroup([a, b]) >>> G.is_polycyclic True )rrqs r/ is_polycycliczPermutationGroup.is_polycyclic; s"rfc"|jr |jS|rH|j |jSt|jd|jk(}||_|Sd}|j D]}t|dkDs|ryd}|S)aTest if the group is transitive. Explanation =========== A group is transitive if it has a single orbit. If ``strict`` is ``False`` the group is transitive if it has a single orbit of length different from 1. Examples ======== >>> from sympy.combinatorics import Permutation, PermutationGroup >>> a = Permutation([0, 2, 1, 3]) >>> b = Permutation([2, 0, 1, 3]) >>> G1 = PermutationGroup([a, b]) >>> G1.is_transitive() False >>> G1.is_transitive(strict=False) True >>> c = Permutation([2, 3, 0, 1]) >>> G2 = PermutationGroup([a, c]) >>> G2.is_transitive() True >>> d = Permutation([1, 0, 2, 3]) >>> e = Permutation([0, 1, 3, 2]) >>> G3 = PermutationGroup([d, e]) >>> G3.is_transitive() or G3.is_transitive(strict=False) False rFr7T)rMr=r9r5r)rdransgot_orbrs r/rzPermutationGroup.is_transitiveN sB   && & "".***djjm$ 3C"%D J A1vz    rfcz|j$t|dk(xr|dj|_|jS)aKTest if the group is the trivial group. This is true if the group contains only the identity permutation. Examples ======== >>> from sympy.combinatorics import Permutation, PermutationGroup >>> G = PermutationGroup([Permutation([0, 1, 2])]) >>> G.is_trivial True r7r)rSr= is_Identityrqs r/r0zPermutationGroup.is_trivial s;    #"4yA~E$q'2E2ED rfc|g}|}|j||}|j|s7|j||}|j||}|j|s7|S)a%Return the lower central series for the group. The lower central series for a group `G` is the series `G = G_0 > G_1 > G_2 > \ldots` where `G_k = [G, G_{k-1}]`, i.e. every term after the first is equal to the commutator of `G` and the previous term in `G1` ([1], p.29). Returns ======= A list of permutation groups in the order `G = G_0, G_1, G_2, \ldots` Examples ======== >>> from sympy.combinatorics.named_groups import (AlternatingGroup, ... DihedralGroup) >>> A = AlternatingGroup(4) >>> len(A.lower_central_series()) 2 >>> A.lower_central_series()[1].is_subgroup(DihedralGroup(2)) True See Also ======== commutator, derived_series )rGrrrfs r/rz%PermutationGroup.lower_central_series se<foodG,%%c* JJsOG//$0C%%c* rfc|j |jS|j}|dk(rytD]}||zdk(s ||z}||_|cSy)aMaximum proper divisor of the degree of a permutation group. Explanation =========== Obviously, this is the degree divided by its minimal proper divisor (larger than ``1``, if one exists). As it is guaranteed to be prime, the ``sieve`` from ``sympy.ntheory`` is used. This function is also used as an optimization tool for the functions ``minimal_block`` and ``_union_find_merge``. Examples ======== >>> from sympy.combinatorics import Permutation, PermutationGroup >>> G = PermutationGroup([Permutation([0, 2, 1, 3])]) >>> G.max_div 2 See Also ======== minimal_block, _union_find_merge Nr7r)rUr5r)rdrrrs r/rzPermutationGroup.max_div sZ6 == $== KK 6 A1uzqD !   rfc|jsy|j}|j}tt |}dg|z}g}t |}||j kDrdg|zSt |dz D]'}|d|||dz<|j||dz)|||d<d}|dz } || kr\||} |dz }|D]G} |j| |} |j| | | | |||} | dk(rdg|zcS| | z } I|| kr\t |D]}|j||i}t|Dcgc]\}}|j||c}}Scc}}w)aFor a transitive group, finds the block system generated by ``points``. Explanation =========== If a group ``G`` acts on a set ``S``, a nonempty subset ``B`` of ``S`` is called a block under the action of ``G`` if for all ``g`` in ``G`` we have ``gB = B`` (``g`` fixes ``B``) or ``gB`` and ``B`` have no common points (``g`` moves ``B`` entirely). ([1], p.23; [6]). The distinct translates ``gB`` of a block ``B`` for ``g`` in ``G`` partition the set ``S`` and this set of translates is known as a block system. Moreover, we obviously have that all blocks in the partition have the same size, hence the block size divides ``|S|`` ([1], p.23). A ``G``-congruence is an equivalence relation ``~`` on the set ``S`` such that ``a ~ b`` implies ``g(a) ~ g(b)`` for all ``g`` in ``G``. For a transitive group, the equivalence classes of a ``G``-congruence and the blocks of a block system are the same thing ([1], p.23). The algorithm below checks the group for transitivity, and then finds the ``G``-congruence generated by the pairs ``(p_0, p_1), (p_0, p_2), ..., (p_0,p_{k-1})`` which is the same as finding the maximal block system (i.e., the one with minimum block size) such that ``p_0, ..., p_{k-1}`` are in the same block ([1], p.83). It is an implementation of Atkinson's algorithm, as suggested in [1], and manipulates an equivalence relation on the set ``S`` using a union-find data structure. The running time is just above `O(|points||S|)`. ([1], pp. 83-87; [7]). Examples ======== >>> from sympy.combinatorics.named_groups import DihedralGroup >>> D = DihedralGroup(10) >>> D.minimal_block([0, 5]) [0, 1, 2, 3, 4, 0, 1, 2, 3, 4] >>> D.minimal_block([0, 1]) [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] See Also ======== _union_find_rep, _union_find_merge, is_transitive, is_primitive Fr7rr) rr5rur8r<r=rrrrr setdefault)rdpointsrrrrrrrD len_not_reprrdeltarnew_repsrs r/rzPermutationGroup.minimal_block s`!!# KKuQx.A K t|| 3q5Lq1u *A%+AYGF1q5M " NN6!a%= ) *fQi !e +oAJE FA $,,UG<--c%j#e*e.5w@2:3q5Lt#  $+oq -A  G , - 6?6HIda##Aq)IIIsE c|h}|}t|dkDrct}|D]2}|jD]!}||z|z}||vs|j|#4|j ||}t|dkDrc|S)a|Return the conjugacy class of an element in the group. Explanation =========== The conjugacy class of an element ``g`` in a group ``G`` is the set of elements ``x`` in ``G`` that are conjugate with ``g``, i.e. for which ``g = xax^{-1}`` for some ``a`` in ``G``. Note that conjugacy is an equivalence relation, and therefore that conjugacy classes are partitions of ``G``. For a list of all the conjugacy classes of the group, use the conjugacy_classes() method. In a permutation group, each conjugacy class corresponds to a particular `cycle structure': for example, in ``S_3``, the conjugacy classes are: * the identity class, ``{()}`` * all transpositions, ``{(1 2), (1 3), (2 3)}`` * all 3-cycles, ``{(1 2 3), (1 3 2)}`` Examples ======== >>> from sympy.combinatorics import Permutation, SymmetricGroup >>> S3 = SymmetricGroup(3) >>> S3.conjugacy_class(Permutation(0, 1, 2)) {(0 1 2), (0 2 1)} Notes ===== This procedure computes the conjugacy class directly by finding the orbit of the element under conjugation in G. This algorithm is only feasible for permutation groups of relatively small order, but is like the orbit() function itself in that respect. r)r=rtrurkupdate)rdr new_classlast_iterationthis_iterationrrT conjugateds r/conjugacy_classz PermutationGroup.conjugacy_class: sTC ".!A% UN# 77A!"Q1"J!2&**:67 7   ^ ,+N.!A%rfcttt|j}|h}|j g}|j D]:}||vs|j |}|j||j|<|S)a,Return the conjugacy classes of the group. Explanation =========== As described in the documentation for the .conjugacy_class() function, conjugacy is an equivalence relation on a group G which partitions the set of elements. This method returns a list of all these conjugacy classes of G. Examples ======== >>> from sympy.combinatorics import SymmetricGroup >>> SymmetricGroup(3).conjugacy_classes() [{(2)}, {(0 1 2), (0 2 1)}, {(0 2), (1 2), (2)(0 1)}] ) r>r8r<r5rzrcrrr)rdrknown_elementsclassesrrs r/conjugacy_classesz"PermutationGroup.conjugacy_classesv s&4dkk 234"!&&() 1A& 003 y)%%i0  1 rfct|dr|j}ttt |t fd|j Dr|St|j dd}|j\}}t||}t||\}} |jddd} | r?|jddt |D]} |j} |j} | | z }t|||| }|dk7s|d t|d zk7sS|j }|j|t|}|j||j||\}}||}}t||}t||\}} d } |j D]J} |j D]5} | | z }t|||| }|dk7s|d t|d zk7s3d} n| sJn| r?|St|d r|j!t|St|d r|j!t|gSy) aReturn the normal closure of a subgroup/set of permutations. Explanation =========== If ``S`` is a subset of a group ``G``, the normal closure of ``A`` in ``G`` is defined as the intersection of all normal subgroups of ``G`` that contain ``A`` ([1], p.14). Alternatively, it is the group generated by the conjugates ``x^{-1}yx`` for ``x`` a generator of ``G`` and ``y`` a generator of the subgroup ``\left\langle S\right\rangle`` generated by ``S`` (for some chosen generating set for ``\left\langle S\right\rangle``) ([1], p.73). Parameters ========== other a subgroup/list of permutations/single permutation k an implementation-specific parameter that determines the number of conjugates that are adjoined to ``other`` at once Examples ======== >>> from sympy.combinatorics.named_groups import (SymmetricGroup, ... CyclicGroup, AlternatingGroup) >>> S = SymmetricGroup(5) >>> C = CyclicGroup(5) >>> G = S.normal_closure(C) >>> G.order() 60 >>> G.is_subgroup(AlternatingGroup(5)) True See Also ======== commutator, derived_subgroup, random_pr Notes ===== The algorithm is described in [1], pp. 73-74; it makes use of the generation of random elements for permutation groups by the product replacement algorithm. ruc3(K|] }|k( ywr*rrs r/r0z2PermutationGroup.normal_closure.. s;Q1=;rN )rrTrr7Frjr.)r/r5r>r8r<rrur&r2rrrrrr=rr@)rdrvrr5Zrrrrr_looprrErconjrHr temp_basetemp_strong_gensrs @r/r@zPermutationGroup.normal_closure shb 5, '[[FtE&M23H;%*:*:;;  !1!1!!45A ! ; ; = D+ 8{ K .t5FG -L,  2 ,E!!B"!-q3A(A AQ3D t\;MNC1v)SVs4y1}-D || D),T2#**4077kJ4 #3,57Gk4T;G*;4 139 &83$ A\\" s$T4%79q6X-Q3t9q=1H$(E! " +>H UM *&&'7'>? ? UL )&&'7'@A A*rfcFt|j|j||S)aCompute the orbit of alpha `\{g(\alpha) | g \in G\}` as a set. Explanation =========== The time complexity of the algorithm used here is `O(|Orb|*r)` where `|Orb|` is the size of the orbit and ``r`` is the number of generators of the group. For a more detailed analysis, see [1], p.78, [2], pp. 19-21. Here alpha can be a single point, or a list of points. If alpha is a single point, the ordinary orbit is computed. if alpha is a list of points, there are three available options: 'union' - computes the union of the orbits of the points in the list 'tuples' - computes the orbit of the list interpreted as an ordered tuple under the group action ( i.e., g((1,2,3)) = (g(1), g(2), g(3)) ) 'sets' - computes the orbit of the list interpreted as a sets Examples ======== >>> from sympy.combinatorics import Permutation, PermutationGroup >>> a = Permutation([1, 2, 0, 4, 5, 6, 3]) >>> G = PermutationGroup([a]) >>> G.orbit(0) {0, 1, 2} >>> G.orbit([0, 4], 'union') {0, 1, 2, 3, 4, 5, 6} See Also ======== orbit_transversal )rr5ru)rdractions r/r9zPermutationGroup.orbit sHdkk4??E6BBrfcv||j|}||y||}|jDcgc]}|j}}g}|dk7r3|j||||j |}||}|dk7r3|rt t |St tt|jScc}w)a3Return a group element which sends ``alpha`` to ``beta``. Explanation =========== If ``beta`` is not in the orbit of ``alpha``, the function returns ``False``. This implementation makes use of the schreier vector. For a proof of correctness, see [1], p.80 Examples ======== >>> from sympy.combinatorics.named_groups import AlternatingGroup >>> G = AlternatingGroup(5) >>> G.orbit_rep(0, 4) (0 4 1 2 3) See Also ======== schreier_vector Fr) rrurrrr>r r8r<rZ)rdrrrrrrr.s r/ orbit_repzPermutationGroup.orbit_rep s0  ""2259O 4 ( D !'+7! 77 2g HHT!W 7==&D%A2g 9a=) )4dll 345 58sB6cFt|j|j||S)a4Computes a transversal for the orbit of ``alpha`` as a set. Explanation =========== For a permutation group `G`, a transversal for the orbit `Orb = \{g(\alpha) | g \in G\}` is a set `\{g_\beta | g_\beta(\alpha) = \beta\}` for `\beta \in Orb`. Note that there may be more than one possible transversal. If ``pairs`` is set to ``True``, it returns the list of pairs `(\beta, g_\beta)`. For a proof of correctness, see [1], p.79 Examples ======== >>> from sympy.combinatorics.named_groups import DihedralGroup >>> G = DihedralGroup(6) >>> G.orbit_transversal(0) [(5), (0 1 2 3 4 5), (0 5)(1 4)(2 3), (0 2 4)(1 3 5), (5)(0 4)(1 3), (0 3)(1 4)(2 5)] See Also ======== orbit )_orbit_transversalrZru)rdrrs r/r4z"PermutationGroup.orbit_transversalH s6"$,,NNrfcBt|j|jS)aReturn the orbits of ``self``, ordered according to lowest element in each orbit. Examples ======== >>> from sympy.combinatorics import Permutation, PermutationGroup >>> a = Permutation(1, 5)(2, 3)(4, 0, 6) >>> b = Permutation(1, 5)(3, 4)(2, 6, 0) >>> G = PermutationGroup([a, b]) >>> G.orbits() [{0, 2, 3, 4, 6}, {1, 5}] )_orbitsrZrH)rdrs r/rzPermutationGroup.orbitse st||T%5%566rfc||j |jS|jr(|j}t||_|jS|jr+|j}t|dz |_|jSt |j Dcgc] }t|c}}||_|Scc}w)aDReturn the order of the group: the number of permutations that can be generated from elements of the group. The number of permutations comprising the group is given by ``len(group)``; the length of each permutation in the group is given by ``group.size``. Examples ======== >>> from sympy.combinatorics import Permutation, PermutationGroup >>> a = Permutation([1, 0, 2]) >>> G = PermutationGroup([a]) >>> G.degree 3 >>> len(G) 1 >>> G.order() 2 >>> list(G.generate()) [(2), (2)(0 1)] >>> a = Permutation([0, 2, 1]) >>> b = Permutation([1, 0, 2]) >>> G = PermutationGroup([a, b]) >>> G.order() 6 See Also ======== degree r)rIrNrZrrOrrr=)rdrrr\s r/rzPermutationGroup.orderu sH ;; ";;  << A#A,DK;;  << A#A,q.DK;;  $"9"9:Q#a&: ; ;sB9ch|j|r!|j|jzSy)aX Returns the index of a permutation group. Examples ======== >>> from sympy.combinatorics import Permutation, PermutationGroup >>> a = Permutation(1,2,3) >>> b =Permutation(3) >>> G = PermutationGroup([a]) >>> H = PermutationGroup([b]) >>> G.index(H) 3 N)rr)rdrs r/rzPermutationGroup.index s, == ::<* * rfch|j}||S|j}|dk\r|jr`|j}|r>> from sympy.combinatorics import SymmetricGroup >>> g = SymmetricGroup(5) >>> g.is_symmetric True >>> from sympy.combinatorics import Permutation, PermutationGroup >>> g = PermutationGroup( ... Permutation(0, 1, 2, 3, 4), ... Permutation(2, 3)) >>> g.is_symmetric True Notes ===== This uses a naive test involving the computation of the full group order. If you need more quicker taxonomy for large groups, you can use :meth:`PermutationGroup.is_alt_sym`. However, :meth:`PermutationGroup.is_alt_sym` may not be accurate and is not able to distinguish between an alternating group and a symmetric group. See Also ======== is_alt_sym rc34K|]}|jywr*)is_oddrs r/r0z0PermutationGroup.is_symmetric.. s=188=r4TFTFTF)rr)rNr5rrr9rurOr)rdrNr _is_alt_syms r/ is_symmetriczPermutationGroup.is_symmetric sF,,  N KK 6!!#"??A =T__==5@2 dl#1<.DL$, 22D2AA)5 &DL$,**D*99rfch|j}||S|j}|dk\r|jr`|j}|r>> from sympy.combinatorics import AlternatingGroup >>> g = AlternatingGroup(5) >>> g.is_alternating True >>> from sympy.combinatorics import Permutation, PermutationGroup >>> g = PermutationGroup( ... Permutation(0, 1, 2, 3, 4), ... Permutation(2, 3, 4)) >>> g.is_alternating True Notes ===== This uses a naive test involving the computation of the full group order. If you need more quicker taxonomy for large groups, you can use :meth:`PermutationGroup.is_alt_sym`. However, :meth:`PermutationGroup.is_alt_sym` may not be accurate and is not able to distinguish between an alternating group and a symmetric group. See Also ======== is_alt_sym rc34K|]}|jywr*is_evenrs r/r0z2PermutationGroup.is_alternating.." s>199>r4rTrF)rr)rOr5rrrrurNr)rdrOrrs r/is_alternatingzPermutationGroup.is_alternating sF,,  N KK 6!!#"??A >doo>>5@2 dl#1<.DL$, 22D2AA)5 &DL$,**D*99rfct|}t|}t|D]'}t|dz|D]}||||zdk(sy)y)zKSubroutine to test if there is only one cyclic group for the order.r7NT)rr=r<)rAprimesrrDr;s r/_distinct_primes_lemmaz'PermutationGroup._distinct_primes_lemma0 s_ Kq A1Q3] !9vay(A-  rfcj jStjdk(rd_d_yjdurd_yj dkrd_dk7rd_yt }t d|jDrSjrd_yt|j}tj|durd_d_yjsd_yt fd|jD_jS)a1 Return ``True`` if the group is Cyclic. Examples ======== >>> from sympy.combinatorics.named_groups import AbelianGroup >>> G = AbelianGroup(3, 4) >>> G.is_cyclic True >>> G = AbelianGroup(4, 4) >>> G.is_cyclic False Notes ===== If the order of a group $n$ can be factored into the distinct primes $p_1, p_2, \dots , p_s$ and if .. math:: \forall i, j \in \{1, 2, \dots, s \}: p_i \not \equiv 1 \pmod {p_j} holds true, there is only one group of the order $n$ which is a cyclic group [1]_. This is a generalization of the lemma that the group of order $15, 35, \dots$ are cyclic. And also, these additional lemmas can be used to test if a group is cyclic if the order of the group is already found. - If the group is abelian and the order of the group is square-free, the group is cyclic. - If the order of the group is less than $6$ and is not $4$, the group is cyclic. - If the order of the group is prime, the group is cyclic. References ========== .. [1] 1978: John S. Rose: A Course on Group Theory, Introduction to Finite Group Theory: 1.4 r7TFc3&K|] }|dk( yw)r7Nr)r-r]s r/r0z-PermutationGroup.is_cyclic..~ s0!qAv0rc3pK|],\}|dkDr"tfdjD.yw)r7c3HK|]}|zzjk7ywr*)r)r-rErrrds r/r0z7PermutationGroup.is_cyclic... s"H1E1H .Hs"N)r9ru)r-rrrrds @r/r0z-PermutationGroup.is_cyclic.. s2 11q5 HH H s26)rWr=rurLrrrrr8keysr&r rr)rdrLrrs` @r/ is_cycliczPermutationGroup.is_cyclic< s#Z ?? &?? " t 1 $"DO#D    u $#DO  19#D z"&E" 0w~~/0 0"&',,.)F66v>$F"&#' #DO    rfc||j |jS|j}|dzdk(rd|_y|dk(rd|_y|dk(r|j |_|jS|jrd|_y|dz}|j}t |dk(rg|\}}|j|j}}||kr ||||f\}}}}|dcxk(r |k(r d|_y||k(r|dk(r||z|z|k(rd|_ygg} }|j D]@} | j} | dk(r|j| *| |k(s0| j| Bt ||dz|dzz k7rd|_y| sd|_y| d}|d}|dzdk(r|||dzzk(r|d}||z|z|k(|_|jS)a Return ``True`` if the group is dihedral. Examples ======== >>> from sympy.combinatorics.perm_groups import PermutationGroup >>> from sympy.combinatorics.permutations import Permutation >>> from sympy.combinatorics.named_groups import SymmetricGroup, CyclicGroup >>> G = PermutationGroup(Permutation(1, 6)(2, 5)(3, 4), Permutation(0, 1, 2, 3, 4, 5, 6)) >>> G.is_dihedral True >>> G = SymmetricGroup(3) >>> G.is_dihedral True >>> G = CyclicGroup(6) >>> G.is_dihedral False References ========== .. [Di1] https://math.stackexchange.com/questions/827230/given-a-cayley-table-is-there-an-algorithm-to-determine-if-it-is-a-dihedral-gro/827273#827273 .. [Di2] https://kconrad.math.uconn.edu/blurbs/grouptheory/dihedral.pdf .. [Di3] https://kconrad.math.uconn.edu/blurbs/grouptheory/dihedral2.pdf .. [Di4] https://en.wikipedia.org/wiki/Dihedral_group rr7FTr#r)rXrr(rrur=rr) rdrrrrrr.rorder_2order_nrrs r/ is_dihedralzPermutationGroup.is_dihedral s:    ($$ $  19> %D  A: $D  A:$(NN 2D $$ $ ?? %D  QJ t9>DAq779aggiqA1u1aZ 1aA{{$(!Av!q&QqSUqb[$(!r "A AAvq!aq!  " w<1q5AE? * %D  %D  AJ AJ q5A:!q1a4y. AqSUqb[   rfc||r|j|\}}g}|j}|D]-}|Dcgc] }|| c}|k(s|j|/|stt t |}t |S|j} |j}|D]} t|| | } t | Scc}w)aReturn the pointwise stabilizer for a set of points. Explanation =========== For a permutation group `G` and a set of points `\{p_1, p_2,\ldots, p_k\}`, the pointwise stabilizer of `p_1, p_2, \ldots, p_k` is defined as `G_{p_1,\ldots, p_k} = \{g\in G | g(p_i) = p_i \forall i\in\{1, 2,\ldots,k\}\}` ([1],p20). It is a subgroup of `G`. Examples ======== >>> from sympy.combinatorics.named_groups import SymmetricGroup >>> S = SymmetricGroup(7) >>> Stab = S.pointwise_stabilizer([2, 3, 5]) >>> Stab.is_subgroup(S.stabilizer(2).stabilizer(3).stabilizer(5)) True See Also ======== stabilizer, schreier_sims_incremental Notes ===== When incremental == True, rather than the obvious implementation using successive calls to ``.stabilizer()``, this uses the incremental Schreier-Sims algorithm to obtain a base with starting segment - the given points. r) r2r5rr>r8r<r&rH _stabilizer) rdr incrementalrr stab_gensr5rr:rrs r/pointwise_stabilizerz%PermutationGroup.pointwise_stabilizer sH  $ > >F > K D+I[[F" *,235CJ3v=$$S) *#Dv$78 #I. .##D[[F 4"643 4%%4sB9cbt|r| tdt||}}n t|}t |}t tt|j}t|}t|D]}|||}t||}|S#t$r tdwxYw)a5 Multiply ``n`` randomly selected permutations from pgroup together, starting with the identity permutation. If ``n`` is a list of integers, those integers will be used to select the permutations and they will be applied in L to R order: make_perm((A, B, C)) will give CBA(I) where I is the identity permutation. ``seed`` is used to set the seed for the random selection of permutations from pgroup. If this is a list of integers, the corresponding permutations from pgroup will be selected in the order give. This is mainly used for testing purposes. Examples ======== >>> from sympy.combinatorics import Permutation, PermutationGroup >>> a, b = [Permutation([1, 0, 3, 2]), Permutation([1, 3, 0, 2])] >>> G = PermutationGroup([a, b]) >>> G.make_perm(1, [0]) (0 1)(2 3) >>> G.make_perm(3, [0, 1, 0]) (0 2 3 1) >>> G.make_perm([0, 1, 0]) (0 2 3 1) See Also ======== random z'If n is a sequence, seed should be Nonez#n must be an integer or a sequence.) r#rr=rrlrrr8r<r5r)rdrseed randomrangeresultr\rrs r/ make_permzPermutationGroup.make_perm) s@ q> !JKK!fatA HF!& T% "456 Iq %A[^$A&!_F %  H !FGG Hs BB.cXt|j}|j||S)z&Return a random group element )rrr_)rdr[rWs r/randomzPermutationGroup.random\ s'&  r**rfc,|jgk(r|j|||j}t|dz }|>t|}t|dz }||k(r|dz }t ddg}t ddg} n|d}|d}||k(r|dz }|d}|d} |dk(r5t ||t ||| ||<t ||||||<n4t t ||| ||||<t ||||||<t||S)aReturn a random group element using product replacement. Explanation =========== For the details of the product replacement algorithm, see ``_random_pr_init`` In ``random_pr`` the actual 'product replacement' is performed. Notice that if the attribute ``_random_gens`` is empty, it needs to be initialized by ``_random_pr_init``. See Also ======== _random_pr_init r7rrrTrrr)rarr=rrr r r>) rd gen_count iterationsrrrrTrrrs r/rzPermutationGroup.random_prb sA"    "  J 7''  q   ! A!a% AAvE1vAAwAS!AS!AAvES!AS!A 6%k!ngk!na6PQKN%k!nk!nEKN%gk!na&@+a.QKN%k!nk!nEKN{1~&&rfc||j|}||j}n|d}||}|j|||}t||S)aRandom element from the stabilizer of ``alpha``. The schreier vector for ``alpha`` is an optional argument used for speeding up repeated calls. The algorithm is described in [1], p.81 See Also ======== random_pr, orbit_rep rand)rrr r)rdrrrr=rrs r/rzPermutationGroup.random_stab s_  ""2259O  >>#D'DE{ NN5$ 8QB~rfc>|jry|jy)aSchreier-Sims algorithm. Explanation =========== It computes the generators of the chain of stabilizers `G > G_{b_1} > .. > G_{b1,..,b_r} > 1` in which `G_{b_1,..,b_i}` stabilizes `b_1,..,b_i`, and the corresponding ``s`` cosets. An element of the group can be written as the product `h_1*..*h_s`. We use the incremental Schreier-Sims algorithm. Examples ======== >>> from sympy.combinatorics import Permutation, PermutationGroup >>> a = Permutation([0, 2, 1]) >>> b = Permutation([1, 0, 2]) >>> G = PermutationGroup([a, b]) >>> G.schreier_sims() >>> G.basic_transversals [{0: (2)(0 1), 1: (2), 2: (1 2)}, {0: (2), 2: (0 2)}] N)r_rrqs r/rzPermutationGroup.schreier_sims s6     rfc |j|d}|dd\}}||_||_|d|_|sg|_g|_yt ||}t||d\}}}t|D]9\}} ||} | D]*} | | D cgc]} |j| | c} | | <,;||_|D cgc] } t| c} |_||_ ycc} wcc} w)NT)rslp_dictr)rS) r2r[r\r]r_r^rrrrrr`)rdrschreierrrrrslpsrDrSrrrTrs r/rzPermutationGroup._schreier_sims s11td1K$RaLk ' ( !#D !#D  4T;G+I$!t,-( lD o FFAs$Q'D F>A!fE+++DG4EA F F *1=>AfQi> $ F?s C5Cc &|g}||jdd}|j}tt|}t |dk(r#|dj r|r|||d|dgifS||fS|dd|dd}}|Dcgc]}|j r|}}|D]E&t &fd|Ds|D]} &j| | k7snJ|j| Gt||} g} i} i} i}t |}t|D]R}t|| |||ddd\| |<||<t| || |<t| |j| |<T|dz }|dk\rd}i}t| |jD]\}}t| |D]\}&&j|}| ||}t&j|}|||Dcgc]}||f}}||fg|z}||k7rHd} ||}t||}|||dd}|j%|Dcgc]}||ff }}||z}t'||| | |||\}}}||krd}nC|rAd}d} || | k(r| dz } || | k(r|j| |dz }| jg|durt)|}| j||ft|dz|D]f}!| |!j|t|| |!||!ddd\| |!<||!<t| |!| |!<t| |!j| |!<h|dz }d}|dusn|dusn|dur|dz}|dk\r|dd}"|r| D]p\}#}|"j|#tt |D]C}||}$t+|$dt,r| |$d|$ddd z||<3| |$d|$d||<Ert| } |D]}|g| |< ||"| fS|"j/| D#%cgc]\}#}%|# c}%}#||"fScc}wcc}w#t $rt#|x}||<YKwxYwcc}wcc}%}#w) aExtend a sequence of points and generating set to a base and strong generating set. Parameters ========== base The sequence of points to be extended to a base. Optional parameter with default value ``[]``. gens The generating set to be extended to a strong generating set relative to the base obtained. Optional parameter with default value ``self.generators``. slp_dict If `True`, return a dictionary `{g: gens}` for each strong generator `g` where `gens` is a list of strong generators coming before `g` in `strong_gens`, such that the product of the elements of `gens` is equal to `g`. Returns ======= (base, strong_gens) ``base`` is the base obtained, and ``strong_gens`` is the strong generating set relative to it. The original parameters ``base``, ``gens`` remain unchanged. Examples ======== >>> from sympy.combinatorics.named_groups import AlternatingGroup >>> from sympy.combinatorics.testutil import _verify_bsgs >>> A = AlternatingGroup(7) >>> base = [2, 3] >>> seq = [2, 3] >>> base, strong_gens = A.schreier_sims_incremental(base=seq) >>> _verify_bsgs(A, base, strong_gens) True >>> base[:2] [2, 3] Notes ===== This version of the Schreier-Sims algorithm runs in polynomial time. There are certain assumptions in the implementation - if the trivial group is provided, ``base`` and ``gens`` are returned immediately, as any sequence of points is a base for the trivial group. If the identity is present in the generators ``gens``, it is removed as it is a redundant generator. The implementation is described in [1], pp. 90-93. See Also ======== schreier_sims, schreier_sims_random Nr7rc3BK|]}|j|k(ywr*r"r-rrs r/r0z=PermutationGroup.schreier_sims_incremental..,s:q1**:sT)rr[rSF)rSrBr)rur5r8r<r=rrrrrr r3r'rrr KeyErrorr reverserr>r+rjr)'rdrrr@r5id_afr[_gensrrrstrong_gens_slporbsrrBrrD continue_idbru_betar;gbu1rrErSru1_inv schreier_gen u1_inv_slprmovedrrrrTrrs' @r/r2z*PermutationGroup.schreier_sims_incremental shx <D <??1%DU6]# t9>d1g11TDGd1gY#777: AwQu!7q77 "C:E::  Cs+s2  4 S! "5UEB u:x 3A'9&BSTUBVa4(9 $LOT!W"<?3LO<?//12DG  3 qL1fJB $\!_%:%:%< =3  f'(9!(<=0FAs.B%a,B!#//6:B+/74=9aAq69C9q6(S.CRx!=%'VF(0'; %)!WR[^ "**,9C%DAq1$i%D %D(3.$-lE4WX^ahl$m 1c= %A %A$%E"#E(e"3 % #$E(e"3!LL/$MH-44R8:!( A+22As8<%*1q5!_G 1! 4 ; ;A > 26;LQ;O$)!HDTt!M!9 Qa37|A2G Q*.|A/C/C/E*FQ G!"AA)-J!T)a0b%g3 hT! FAy1f|Ah * ?3""1%s3x?AAA!!A$.!21Q4!81a!A2!EA!21Q4!81!>A ? ?#?3O )&'S" );8 8/:$!QA:;k!![8J: (=.8n>> from sympy.combinatorics.testutil import _verify_bsgs >>> from sympy.combinatorics.named_groups import SymmetricGroup >>> S = SymmetricGroup(5) >>> base, strong_gens = S.schreier_sims_random(consec_succ=5) >>> _verify_bsgs(S, base, strong_gens) #doctest: +SKIP True Notes ===== The algorithm is described in detail in [1], pp. 97-98. It extends the orbits ``orbs`` and the permutation groups ``stabs`` to basic orbits and basic stabilizers for the base and strong generating set produced in the end. The idea of the extension process is to "sift" random group elements through the stabilizer chain and amend the stabilizers/orbits along the way when a sift is not successful. The helper function ``_strip`` is used to attempt to decompose a random group element according to the current state of the stabilizer chain and report whether the element was fully decomposed (successful sift) or not (unsuccessful sift). In the latter case, the level at which the sift failed is reported and used to amend ``stabs``, ``base``, ``gens`` and ``orbs`` accordingly. The halting condition is for ``consec_succ`` consecutive successful sifts to pass. This makes sure that the current ``base`` and ``gens`` form a BSGS with probability at least `1 - 1/\text{consec\_succ}`. See Also ======== schreier_sims Nc34K|]}||k(ywr*rrEs r/r0z8PermutationGroup.schreier_sims_random..s-13q6Q;-rrr7TrrEF)rur=r5rrrrr<r3r r8r'rr:rr)rdrr consec_succrrrrrrrKrDr^rErr;rrTrrrs @r/schreier_sims_randomz%PermutationGroup.schreier_sims_randomsJ <D <??Dt9 KK C---ooc*c11HCooc*c1 C A   5T4@ x 3A"#5a9J19MQt$%&LO<?//12DG 3 +o#NN$ %))+!T46DAqAH}]]h%'QJEh%' E"A !((,Ezq!;A%a(//2&*+=a)!,d1gT,C'DLO"<?#7#7#9:DG ; Q9+o<(*1- $Q' (C+%""3' ([  rfc|j}dg|z}d||<|g}dg|z}d||<|j}t|}|D]G}t|D]7} || j|} || dus|j | d|| <| || <9I|S)a(Computes the schreier vector for ``alpha``. Explanation =========== The Schreier vector efficiently stores information about the orbit of ``alpha``. It can later be used to quickly obtain elements of the group that send ``alpha`` to a particular element in the orbit. Notice that the Schreier vector depends on the order in which the group generators are listed. For a definition, see [3]. Since list indices start from zero, we adopt the convention to use "None" instead of 0 to signify that an element does not belong to the orbit. For the algorithm and its correctness, see [2], pp.78-80. Examples ======== >>> from sympy.combinatorics import Permutation, PermutationGroup >>> a = Permutation([2, 4, 6, 3, 1, 5, 0]) >>> b = Permutation([0, 1, 3, 5, 4, 6, 2]) >>> G = PermutationGroup([a, b]) >>> G.schreier_vector(0) [-1, None, 0, 1, None, 1, 0] See Also ======== orbit NrFT)r5rur=r<rr) rdrrr]rusedrrrrDrs r/rz PermutationGroup.schreier_vectors@ KK F1H%gwqyU  I A1X Aw**1-:&JJt$!%DJAdG   rfcVtt|j|j|S)a Return the stabilizer subgroup of ``alpha``. Explanation =========== The stabilizer of `\alpha` is the group `G_\alpha = \{g \in G | g(\alpha) = \alpha\}`. For a proof of correctness, see [1], p.79. Examples ======== >>> from sympy.combinatorics.named_groups import DihedralGroup >>> G = DihedralGroup(6) >>> G.stabilizer(5) PermutationGroup([ (5)(0 4)(1 3)]) See Also ======== orbit )rr.rZrH)rdrs r/rzPermutationGroup.stabilizerMs"2T\\43C3CUKLLrfcX|jgk(r|j|jS)aReturn a strong generating set from the Schreier-Sims algorithm. Explanation =========== A generating set `S = \{g_1, g_2, \dots, g_t\}` for a permutation group `G` is a strong generating set relative to the sequence of points (referred to as a "base") `(b_1, b_2, \dots, b_k)` if, for `1 \leq i \leq k` we have that the intersection of the pointwise stabilizer `G^{(i+1)} := G_{b_1, b_2, \dots, b_i}` with `S` generates the pointwise stabilizer `G^{(i+1)}`. The concepts of a base and strong generating set and their applications are discussed in depth in [1], pp. 87-89 and [2], pp. 55-57. Examples ======== >>> from sympy.combinatorics.named_groups import DihedralGroup >>> D = DihedralGroup(4) >>> D.strong_gens [(0 1 2 3), (0 3)(1 2), (1 3)] >>> D.base [0, 1] See Also ======== base, basic_transversals, basic_orbits, basic_stabilizers )r\rrqs r/rzPermutationGroup.strong_genshs+@    "       rfc\tfd|Ds tdt|}|S)zp Return the subgroup generated by `gens` which is a list of elements of the group c3&K|]}|v ywr*r)r-rErds r/r0z,PermutationGroup.subgroup..s+19+sz2The group does not contain the supplied generators)rrr&)rdrrAs` r/subgroupzPermutationGroup.subgroups. +d++QR R T "rfc Z &'()*+&fd}&'()*+fd}||j\}}t|}|j(tt t (} t |(&&j(&jdt||} t|| \'} | t| g}|&d} g}t |D]} |j| |}|dz }|dz }|dd}|j|\}}t||}|j}t |D cgc]} t(|| || c} *dg|z}t(||}||||<||j||dg|z}| g|z}dg|z+t |D]%} '| dd+| <+| j&fd  'dg|z}dg|z)(dz||<||| g|z} ||dz kr||||||vr&||&||||cxkr &)|krnn||||rp||||}|||<t!(|||}|||dz<t(|}||||dz<|dz }'|Dcgc]}||dz |}}|j&fd  |+|<(dz}t |D])} ||*| vs|| || } &| &|kDs(| }+|||<||d||<+|||}!||dz j"j%|!}"| ||"||<t'||dz ||||<||dz krI||||||vr6&||&||||cxkr &)|krnn |||rp||}#|#||}!||dz k(r&||&|!cxkr &)|krnn|!||vr}|||rr||#rj|j|#|dd}|j|#t||}t |D cgc]} t(|| || c} *||||<|}|dk\r9||t'|dz k(r"|dz }|dk\r||t'|dz k(r"|dk(r t|S||krn|}d||<t(||}$||$||<(dz||<t'|dzt*|z }%|%t+|k\r &()|<n +||%)|<||xxdz cc<|dk(r +|||}"n*||dz j"j%+|||}"| ||"||<|dk(r ||||<nt'||dz ||||<cc} wcc}wcc} w) a Find the subgroup of all elements satisfying the property ``prop``. Explanation =========== This is done by a depth-first search with respect to base images that uses several tests to prune the search tree. Parameters ========== prop The property to be used. Has to be callable on group elements and always return ``True`` or ``False``. It is assumed that all group elements satisfying ``prop`` indeed form a subgroup. base A base for the supergroup. strong_gens A strong generating set for the supergroup. tests A list of callables of length equal to the length of ``base``. These are used to rule out group elements by partial base images, so that ``tests[l](g)`` returns False if the element ``g`` is known not to satisfy prop base on where g sends the first ``l + 1`` base points. init_subgroup if a subgroup of the sought group is known in advance, it can be passed to the function as this parameter. Returns ======= res The subgroup of all elements satisfying ``prop``. The generating set for this group is guaranteed to be a strong generating set relative to the base ``base``. Examples ======== >>> from sympy.combinatorics.named_groups import (SymmetricGroup, ... AlternatingGroup) >>> from sympy.combinatorics.testutil import _verify_bsgs >>> S = SymmetricGroup(7) >>> prop_even = lambda x: x.is_even >>> base, strong_gens = S.schreier_sims_incremental() >>> G = S.subgroup_search(prop_even, base=base, strong_gens=strong_gens) >>> G.is_subgroup(AlternatingGroup(7)) True >>> _verify_bsgs(G, base, G.generators) True Notes ===== This function is extremely lengthy and complicated and will require some careful attention. The implementation is described in [1], pp. 114-117, and the comments for the code here follow the lines of the pseudocode in the book for clarity. The complexity is exponential in general, since the search process by itself visits all members of the supergroup. However, there are a lot of tests which are used to prune the search tree, and users can define their own tests via the ``tests`` parameter, so in practice, and for some computations, it's not terrible. A crucial part in the procedure is the frequent base change performed (this is line 11 in the pseudocode) in order to obtain a new basic stabilizer. The book mentiones that this can be done by using ``.baseswap(...)``, however the current implementation uses a more straightforward way to find the next basic stabilizer - calling the function ``.stabilizer(...)`` on the previous basic stabilizer. cJ|Dcgc]}t|fdc}Scc}w)Nc|Sr*r)rrs r/rzDPermutationGroup.subgroup_search..get_reps..s }Q/?rfr)r)rr9rs r/get_repsz2PermutationGroup.subgroup_search..get_repss-"#%?@# ##s ct|dzt|z }|t|k\r |<y|||<y)Nr7r)r temp_indexrrr5nures_basic_orbits_init_base sorted_orbitss r/ update_nuz3PermutationGroup.subgroup_search..update_nus^\!_-17:;.r rfr7rrc|Sr*rr:rs r/rz2PermutationGroup.subgroup_search..'s M%4Hrfrc|Sr*rrls r/rz2PermutationGroup.subgroup_search..Gs -2Frf)r2r=r5r>r8r<rrrrr&rurrrr1r.rrr),rdr,rrr- init_subgrouprcrirrrrr>rDrHrUrres_baseres_strong_gensres_strong_gens_distrres_generatorsr)rr^rmur# new_point new_stab_gensr: temp_orbitnew_mu candidate temp_pointrrE temp_orbitsrerrr5rfrgrhs, @@@@@@r/r5z PermutationGroup.subgroup_searchsc\ #  5 5 < $ > > @ D+t94f ./&tV4 V$R 4T;G%CD%6&8" l  ,hZ8M =)LE8_ + \* + qL qL7$'$A$A%B%!/ 8 /!1/ #  -a0(1+ > # #VH_ !6q!9: ( 1  1 T!W% CL Jx x x JA+Aq1M!  !  ! !&H ! I JVH_VH_ 1! "H,hl"!q!$q'*jm;be$/nQ/Q89%be$%E!H^,-N1-d1g6 ' +F4I!4L!!# /<%a!e,!7$,V$4 1q5!Q ,Q1u3nQU3E:1 1$FG#- a !q/AAw" (3mF6KK%.F / 1! !*1-ad3 &q1u-99?? K#Au-!$(A)>!$Eq!Khl"!q!$q'*jm;be$/nQ/Q89%be$%E!H^,Dq!A47JHqL be$j)A,9"Q%,@Ajm+a(G%%a(7&&q)(@:I)K% /+ 5a 8(1+F++ !) 0 1 q&QqTSa%9A%==Eq&QqTSa%9A%==Bw'771u!%f.CA.FG ( 5 1  1 a1A521567 ]1%5!66)&1BqE)!,Z8BqE aDAIDAv&q)!A$/&q1u-99?? a@PQRSTQU@VW?5)AaDAv$%aDq!$(A)>!$Eq!E5 #\1J+s)V V#8V(c|je|j}|}t|D]@}|j|}t |||z k7r ||_|cS|j |}B||_|S|jS)auCompute the degree of transitivity of the group. Explanation =========== A permutation group `G` acting on `\Omega = \{0, 1, \dots, n-1\}` is ``k``-fold transitive, if, for any `k` points `(a_1, a_2, \dots, a_k) \in \Omega` and any `k` points `(b_1, b_2, \dots, b_k) \in \Omega` there exists `g \in G` such that `g(a_1) = b_1, g(a_2) = b_2, \dots, g(a_k) = b_k` The degree of transitivity of `G` is the maximum ``k`` such that `G` is ``k``-fold transitive. ([8]) Examples ======== >>> from sympy.combinatorics import Permutation, PermutationGroup >>> a = Permutation([1, 2, 0]) >>> b = Permutation([1, 0, 2]) >>> G = PermutationGroup([a, b]) >>> G.transitivity_degree 3 See Also ======== is_transitive, orbit )rTr5r<r9r=r)rdrrArDrs r/transitivity_degreez$PermutationGroup.transitivity_degrees>  $ $ , AA1X $ggajs8q1u$01D-HLLO  $ )*D %H,, ,rfc|jdd}t|dd}|Dcgc]}||j|z z}}g}tt |D] }||}|j}|||z z} |dkDrt |d|} nt |j } |||z z| vr|j|||z zl| j| d}|D] } || dzz} ||z }||=||=|dz } | t |kr@|| j|k\r*| dz } | t |kr|| j|k\r*|d| |gz|| dz}|d| |gz|| dz} t |Scc}w) z For an abelian p-group, return the subgroup consisting of all elements of order p (and the identity) Nc"|jSr*rrs r/rz4PermutationGroup._p_elements_group..s !'')rfT)rrGrrPrr7) rurrr<r=r&rrrR) rdrrrEgens_pgens_rrDrx_orderx_pPrTr;s r/_p_elements_groupz"PermutationGroup._p_elements_groups q!d 3TB,01q!aggik"11s4y! 7AQAggiGgai.C1u$VBQZ0$T]]3719~Q& a'!)n-''d'; A!R%A !!)G1IE#d)mQ 7(BFA#d)mQ 7(BBQx1#~QR0qc)F12J63 74 ''92sE0c |j}g}t|dz }|dk(xrtd|jD}g}|}|dkDr|j ||z||z}|dkDrt |dz }t d|dzD]} | dk(r|r tt || zD cgc]} | || dz zz|| zzc} } |j || z|sVtdd| ztddz| z} |j | d} |dkDr||} t | D]}t}| dkDrt ||zD]} || | | z}|r9tdd|ztddz|z} |j | d|dz z} n|} t|d| D])\} } |r | dzdk(r|| z|z} |j | +| ||zz } |dz }|dkDr|Scc} w)a Return a p-Sylow subgroup of a symmetric or an alternating group. Explanation =========== The algorithm for this is hinted at in [1], Chapter 4, Exercise 4. For Sym(n) with n = p^i, the idea is as follows. Partition the interval [0..n-1] into p equal parts, each of length p^(i-1): [0..p^(i-1)-1], [p^(i-1)..2*p^(i-1)-1]...[(p-1)*p^(i-1)..p^i-1]. Find a p-Sylow subgroup of Sym(p^(i-1)) (treated as a subgroup of ``self``) acting on each of the parts. Call the subgroups P_1, P_2...P_p. The generators for the subgroups P_2...P_p can be obtained from those of P_1 by applying a "shifting" permutation to them, that is, a permutation mapping [0..p^(i-1)-1] to the second part (the other parts are obtained by using the shift multiple times). The union of this permutation and the generators of P_1 is a p-Sylow subgroup of ``self``. For n not equal to a power of p, partition [0..n-1] in accordance with how n would be written in base p. E.g. for p=2 and n=11, 11 = 2^3 + 2^2 + 1 so the partition is [[0..7], [8..9], {10}]. To generate a p-Sylow subgroup, take the union of the generators for each of the parts. For the above example, {(0 1), (0 2)(1 3), (0 4), (1 5)(2 7)} from the first part, {(8 9)} from the second part and nothing from the third. This gives 4 generators in total, and the subgroup they generate is p-Sylow. Alternating groups are treated the same except when p=2. In this case, (0 1)(s s+1) should be added for an appropriate s (the start of a part) for each part in the partitions. See Also ======== sylow_subgroup, is_alt_sym r7rc34K|]}|jywr*rrs r/r0z2PermutationGroup._sylow_alt_sym..s@1QYY@r4rN)r5rrrurr=r<r)rdrrrraltcoeffsr\powerrDr;rrr.rshifts r/_sylow_alt_symzPermutationGroup._sylow_alt_syms@V KKqs#1f@@@@ !e MM!a% QA!eF A q%'" !AAv#eAqDkJA!H 14JKC KK %!!Q'+K1,==cA C  !aiu A1X "# 19"1e8_4 %a 34)!Q/5k!Q6GGM C(uqyM!"+D!H"5)31q5A:$$Cio C( )E!+ ",!GE7ai: OKs%G# cddlm}m}ts t dfd}fd}|j }|zdk7rt |jgS||\}}|r|S|jrt |jS|j} | D cgc]%} t| zdk7st| dk7s$| '} } | r<|jt| dj} | jS|j!sNt#| t} | j} | dj$| }||| }|||}|||S|j'}t|dkDr!|||d}|||d}|||St|dk(rt|d}t)d|Dra|||}||j+ds?|j+j}|j-|jS|j/}|j }|zdk7s|dk(r/|j/}|j }|zdk7r)|dk(r/||zz}|d zzdk7r t |S|j1|}|j |zzdk7r|j}|j }|j3}|j5}|j/}|j1|}|j z|zdk7r;|j/}|j1|}|j z|zdk7r;|}|j |zzdk7r|jScc} w) a  Return a p-Sylow subgroup of the group. The algorithm is described in [1], Chapter 4, Section 7 Examples ======== >>> from sympy.combinatorics.named_groups import DihedralGroup >>> from sympy.combinatorics.named_groups import SymmetricGroup >>> from sympy.combinatorics.named_groups import AlternatingGroup >>> D = DihedralGroup(6) >>> S = D.sylow_subgroup(2) >>> S.order() 4 >>> G = SymmetricGroup(6) >>> S = G.sylow_subgroup(5) >>> S.order() 5 >>> G1 = AlternatingGroup(3) >>> G2 = AlternatingGroup(5) >>> G3 = AlternatingGroup(9) >>> S1 = G1.sylow_subgroup(3) >>> S2 = G2.sylow_subgroup(3) >>> S3 = G3.sylow_subgroup(3) >>> len1 = len(S1.lower_central_series()) >>> len2 = len(S2.lower_central_series()) >>> len3 = len(S3.lower_central_series()) >>> len1 == len2 True >>> len1 < len3 True r)orbit_homomorphismblock_homomorphismzp must be a primecx|j}d}|zdk(r|z }|dz }|dk(rd|fS|zdk(rd|fS)Nrr7TFr)rAr\rrs r/ is_p_groupz3PermutationGroup.sylow_subgroup..is_p_groupsZ AAa%1*aCQ67N a%1* !8Orfc|jj}|j|}|j|}|jj}|j|Sr*)imagesylow_subgroupinvert_subgroup restrict_to)rsrfQRrs r/ _sylow_reducez6PermutationGroup.sylow_subgroup.._sylow_reduces` ))!,A""1%A"B ))!,A%%a( (rfr7rc3&K|] }|dk7 ywrrrs r/r0z2PermutationGroup.sylow_subgroup..s)a16)rr)!sympy.combinatorics.homomorphismsrrr!rrr&rrrrr=rr8r:rrrunionrr9rrr8rrr)rdrrrrrrp_grouprro non_p_orbitsrAomega1omega2rsrfrrSrEg_orderCs_orderrrrC_hs ` r/rzPermutationGroup.sylow_subgroupXsN 8qz01 1  )  19>#T]]O4 4%  K ?? #D$7$7$:; ; #)MaSVaZ1_Q1M M \!_ 5 9 9 ; of ``K`` on a subset of ``gens_h`` is a finite presentation of ``H``. Explanation =========== ``H`` should be generated by the union of ``K.generators`` and ``z`` (a single generator), and ``H.stabilizer(alpha) == K``; ``phi`` is a canonical injection from a free group into a permutation group containing ``H``. The algorithm is described in [1], Chapter 6. Examples ======== >>> from sympy.combinatorics import free_group, Permutation, PermutationGroup >>> from sympy.combinatorics.homomorphisms import homomorphism >>> from sympy.combinatorics.fp_groups import FpGroup >>> H = PermutationGroup(Permutation(0, 2), Permutation (1, 5)) >>> K = PermutationGroup(Permutation(5)(0, 2)) >>> F = free_group("x_0 x_1")[0] >>> gens = F.generators >>> phi = homomorphism(F, H, F.generators, H.generators) >>> rels_k = [gens[0]**2] # relators for presentation of K >>> z= Permutation(1, 5) >>> check, rels_h = H._verify(K, phi, z, 1) >>> check True >>> rels = rels_k + rels_h >>> G = FpGroup(F, rels) # presentation of H >>> G.order() == H.order() True See also ======== strong_presentation, presentation, stabilizer rrTrrPNF) r9rr8rjrinvertrr4rr=rurRr)rrphirrr9rK_betagammasrrrr)rbetas transversalrTrErrrrelsrk_gensrnew_relrrs r/_verifyzPermutationGroup._verifys\ae}d#u=!uV\\!_-=>(./c!f/ / #C&  c" #  cjj4dCJJq"uaA~ Q)4U);CJJqM)I A$%$7$7$7$FNDAq 31/V"' $;&' #d{" #s/!L5$ L:,L?(M? MM M('M(cddlm}m}ddlm}ddlm}m}m}|jdd}|jdd}|jdd} tt|D cgc]} d| z } } |dj| d} || || j|} t!|j"}|r| j%}|}|j%}|jDcgc] }||vs| }}|j'dk(r?|j%}| jd |j'zg}|g}t!|}|rf|j%}|gz}t!|}|j)|}|j)|}||k(r||vr| j+|}|}nC|j-|||z }| j+|| j+|d zz}||d zz}|j/|d D]}|| j+|d zz}|g}nlt|dk(r|j1|| ||\}}nE|j3||\}}|r-|||}|j4j6} |j6}!t9}"t| D]} |"t9| | |!zz}"|j:}#|#Dcic]}|||"z|#|z|"z}$}|jdt|j D]}||$|< t!t=|$j?}%|||%|$}&t!|jDcgc] }|&| c}}'|%j1|'|&jA| |&||!\}}D]}(|(vs|jC|(|}|rf|r|| })||)Scc} wcc}wcc}wcc}w) a3 Return a strong finite presentation of group. The generators of the returned group are in the same order as the strong generators of group. The algorithm is based on Sims' Verify algorithm described in [1], Chapter 6. Examples ======== >>> from sympy.combinatorics.named_groups import DihedralGroup >>> P = DihedralGroup(4) >>> G = P.strong_presentation() >>> P.order() == G.order() True See Also ======== presentation, _verify rFpGroupsimplify_presentation free_group)r homomorphismGroupHomomorphismNx_%d, r7rTrP)"sympy.combinatorics.fp_groupsrrsympy.combinatorics.free_groupsrrrrrrrrr<r=joinrur&rr:rr9rr rRrrcodomainr5rimagesr8rcomposer)*rdrrrrrrrstabsrrDgen_symsFrrrrrEnew_gensrrintermediate_gensK_sr9orbit_krelrrnew_relssuccesscheckrr\rrt_imgrK_s_actrUK_actrgroups* r/strong_presentationz$PermutationGroup.strong_presentations0 C> L L&&q) &&q)yy|).c+.>(?@1VAX@@ tyy* +A .1dALL+> T]] +HHJEA A#$<<>a1A:>H>wwyA~LLN R(!'')34%&C!$%67LLN%&C*;$;!&'89 %(''%.e#Av!jjm KKuQw7!jjmCJJqM2,== Bw000E4!#**Q-"334 #uH\Q&), AsAu(E%GX$'#4#4Q#>LE5 /sE:JJ--JJ (M!&q5AQ!!44A5!">C!C!QqSq\!^"3!C!C!%!1!12GC4G3G!H*A()F1I*"24 3H"I-dGVD 0 1M1!A$1M N,3OOE199S>STUVSWYZ,[)!'A} A'\4 $U++iA?x"D 2Ns O! O+OO Oc(#ddlm#m}ddlm}ddlm}ddlm}|jr |jS#fd}|j}t|}|dk(r;|dj} | dk(r |gdS|d\} } #| | | zgS|jd kDr|jd|dzd z} ng} t| } | j}t|j}|j| }t|}t!t|Dcgc]}d |z }}|d j#|d} t!|Dcgc]}| j|}}||| |j|d }||j$}#| |}||||j|}||g}t!|Dcgc] }dgd |zz c}|_dg|z}|j(|d<t!d |zD]}d|j&d|<d}t+t!|t!d |zD]r\}} ||| }||k(s|j| d zd| d zzz}|||z||<||j&|| <||j&|| d| d zzz<|dz }||k(srnt-t!||_dx}} |j1s |j&|| ||| k(r4| dzd |zz} | dk(r|dz|z}|j&|| ||| k(r4|j| d zd| d zzz}|||z|||| dzz}||} |j(}!| j3| dD]}"|!|j5|"dzz}!||!z}|||g}|j7d||j9gd||d}|j1s |||_ |jScc}wcc}wcc}w)zz Return an `FpGroup` presentation of the group. The algorithm is described in [1], Chapter 6.1. rr) CosetTabler)rct|r@|j|j|jt t |S||Sr*)r+rrelatorsrr8rt)rArrs r/_factor_group_by_relsz._factor_group_by_relssC!W% AJJ'q||T#d)_==1d# #rfr7rrrrrF)rNrTrPr)strategydraft max_cosets incomplete)rrrsympy.combinatorics.coset_tablerrrrrrbrur=rr& presentationrr<rrrrrr8r is_completerRr scan_and_fillcoset_enumeration)$rdeliminate_gensrrrrrrlen_grrr half_gensrH_plen_hrrrDrrrrG_prC_prrrrrrrrhrTrs$ @r/rzPermutationGroup.presentation sS C>>B  (( ( $ D  A:GMMOEz!"~a((c?DAq1q%xj) ) ::<" 57Q,7II Y 'nnCNN#   Q  F(-c$i(891VAX99 tyy* +A .,1<8a!,,q/88 au Ea dCNND 9b!/4Qx8!dVQuW%8 fQh  Aqw ACIIaLO a%%.9 HE1U8A;Du}nnQT*bAE];$/$6s$: D!&* % #5: $R1q5M 12 A: U1X q//#))D/!$$ 2Uqw'6 1H>D))D/!$$ 2 ..A&"A7C!$'+K$ ,CR,GGGW:D,,C(((= *!((1+r/) *ckG(gY7C   a )'']&)aD(JC'//#,!6c :$$$A:99s PP Pc2ddlm}|js td|j }g}g}g}|j |d|j tt|dz D]}||}||dzjD]}||vst|g|jz}|jd||jd||dj} |dj} |jd| | z||||dS)aU Return the PolycyclicGroup instance with below parameters: Explanation =========== * pc_sequence : Polycyclic sequence is formed by collecting all the missing generators between the adjacent groups in the derived series of given permutation group. * pc_series : Polycyclic series is formed by adding all the missing generators of ``der[i+1]`` in ``der[i]``, where ``der`` represents the derived series. * relative_order : A list, computed by the ratio of adjacent groups in pc_series. r)PolycyclicGroupzThe group must be solvablerr7N) collector) sympy.combinatorics.pc_groupsrrrrrrGr<r=rur&insertr) rdrr pc_series pc_sequencerelative_orderrDrrEG1rrs r/polycyclic_groupz!PermutationGroup.polycyclic_group{s& B!!9: :!!#  R! s3xz" 7AAA1X(( 7A:(!q||);.!.!`""@HT=~6*X$Lu?n-^Yv'R-^0@11"/b-^3Oj8(tDL  <;|  &@HTP0.$L;z+&+&Z,\=~Qf#%#%J:?x  $1f  $%N##JWJr9x>cBJ$CL&6PO:7 1f+&7:7:t7:7:r  TTl^!^!@3&j1f+ ,'\,@%2w"rFH*.B!H/bM6!!!!F HL&*{Fz0-0-d$(LhTE#N;ztlx,tm%^*Wrfr&c (t|ds|g}|Dcgc]}|j}}t|dk(s|dk(rQ|}dg|z}|D]}d||< |D]-} |D]&} | | } || dk(s|j| d|| <(/t |S|dk(rmt |}|g}|h}|D]L} |D]E} t | Dcgc]}| | c}} | |vs$|j| |j | GNt |S|dk(r{t|}|g}|h}|D]L} |D]E} t| Dcgc]}| | c}} | |vs$|j| |j | GN|Dchc] }t |c}Sycc}wcc}wcc}wcc}w) aCompute the orbit of alpha `\{g(\alpha) | g \in G\}` as a set. Explanation =========== The time complexity of the algorithm used here is `O(|Orb|*r)` where `|Orb|` is the size of the orbit and ``r`` is the number of generators of the group. For a more detailed analysis, see [1], p.78, [2], pp. 19-21. Here alpha can be a single point, or a list of points. If alpha is a single point, the ordinary orbit is computed. if alpha is a list of points, there are three available options: 'union' - computes the union of the orbits of the points in the list 'tuples' - computes the orbit of the list interpreted as an ordered tuple under the group action ( i.e., g((1, 2, 3)) = (g(1), g(2), g(3)) ) 'sets' - computes the orbit of the list interpreted as a sets Examples ======== >>> from sympy.combinatorics import Permutation, PermutationGroup >>> from sympy.combinatorics.perm_groups import _orbit >>> a = Permutation([1, 2, 0, 4, 5, 6, 3]) >>> G = PermutationGroup([a]) >>> _orbit(G.degree, G.generators, 0) {0, 1, 2} >>> _orbit(G.degree, G.generators, [0, 4], 'union') {0, 1, 2, 3, 4, 5, 6} See Also ======== orbit, orbit_transversal rjr7rFTrsetsN)r/rr=rrtrjrk frozenset) r5rurr rrrrZrrrrs r/rrsJ 5- (#- .aAMM .D . 5zQ&G+wv~ BDH  &A &1v:&JJt$!%DJ  & & 3x 8 e gw #A #a0c!f01t#JJt$HHTN  # # 3x 6 % gw #A # !!4Q#a&!45t#JJt$HHTN  # # #&&Qa&& 1 /&1"5'sF6 F ( F *Fcg}tt|}t|}|r?|d}t|||}|j |||z}|Dcgc] }||vs| }}|r?|Scc}w)aCompute the orbits of G. If ``rep=False`` it returns a list of sets else it returns a list of representatives of the orbits Examples ======== >>> from sympy.combinatorics import Permutation >>> from sympy.combinatorics.perm_groups import _orbits >>> a = Permutation([0, 2, 1]) >>> b = Permutation([1, 0, 2]) >>> _orbits(a.size, [a, b]) [{0, 1, 2}] r)r8r<rtrr)r5rurKsorted_IrKrDrs r/rrsy" DE&M"H H A QKVZ+ C S'8!1C>> from sympy.combinatorics.named_groups import DihedralGroup >>> from sympy.combinatorics.perm_groups import _orbit_transversal >>> G = DihedralGroup(6) >>> _orbit_transversal(G.degree, G.generators, 0, False) [(5), (0 1 2 3 4 5), (0 5)(1 4)(2 3), (0 2 4)(1 3 5), (5)(0 4)(1 3), (0 3)(1 4)(2 5)] FT)r8r<rrrr r>)r5rurrr[rSrMr@rZrrpxpx_slprrrrs r/r r soB $uV}% & 'Br{H 76>DDK#- .aAMM .D ."2! "Cq6DDzU""&**S/!2V!; 4#r!234!T  "" .01da1gaj/1B1I8|  DAqa  I8|!# $A'!* $B $  x<3 /2  %sD 'D D,Dc|g}|tt|i}|tt|i}dg|z}d||<|Dcgc]}|j}}g} |D]w} |D]p} | | } || dur9t| || } |j | | || <t | || <d|| <Ht || | || }|| vs`| j |ry| Dcgc] }t|c}Scc}wcc}w)aOReturn the stabilizer subgroup of ``alpha``. Explanation =========== The stabilizer of `\alpha` is the group `G_\alpha = \{g \in G | g(\alpha) = \alpha\}`. For a proof of correctness, see [1], p.79. degree : degree of G generators : generators of G Examples ======== >>> from sympy.combinatorics.perm_groups import _stabilizer >>> from sympy.combinatorics.named_groups import DihedralGroup >>> G = DihedralGroup(6) >>> _stabilizer(G.degree, G.generators, 5) [(5)(0 4)(1 3), (5)] See Also ======== orbit FT)r8r<rr rr r r>)r5rurrr table_invrZrrr0rrrgen_temprRs r/r.r.Ts8 'C Dv' (EU6]+,I 76>DDK#- .aAMM .D .I  3 3Cq6DDzU"#Cq2 4 &d ",X"6 $!T (4#uQxH y0$$\2 3 3!* *1GAJ ** / +s C+C0cHeZdZdZdZdZdZdZedZ edZ y) rzM The class defining the lazy form of SymmetricGroup. deg : int cHt|}tj||}|Sr*)rrr@)rArobjs r/r@z!SymmetricPermutationGroup.__new__s smmmC% rfc:|jd|_d|_yrG)rB_degrIrcs r/rez"SymmetricPermutationGroup.__init__sIIaL  rfct|tstdt|z|j|j k(S)a"Return ``True`` if *i* is contained in SymmetricPermutationGroup. Examples ======== >>> from sympy.combinatorics import Permutation, SymmetricPermutationGroup >>> G = SymmetricPermutationGroup(4) >>> Permutation(1, 2, 3) in G True z[A SymmetricPermutationGroup contains only Permutations as elements, not elements of type %s)r+rrlrmr3r5ris r/roz&SymmetricPermutationGroup.__contains__sC![)@BFq'JK Kvv$$rfc|j |jS|j}t||_|jS)z Return the order of the SymmetricPermutationGroup. Examples ======== >>> from sympy.combinatorics import SymmetricPermutationGroup >>> G = SymmetricPermutationGroup(4) >>> G.order() 24 )rIrr)rdrs r/rzSymmetricPermutationGroup.orders6 ;; ";;  IIl {{rfc|jS)z Return the degree of the SymmetricPermutationGroup. Examples ======== >>> from sympy.combinatorics import SymmetricPermutationGroup >>> G = SymmetricPermutationGroup(4) >>> G.degree 4 )rrqs r/r5z SymmetricPermutationGroup.degreesyyrfcPttt|jS)a  Return the identity element of the SymmetricPermutationGroup. Examples ======== >>> from sympy.combinatorics import SymmetricPermutationGroup >>> G = SymmetricPermutationGroup(4) >>> G.identity() (3) )r>r8r<rrqs r/rz"SymmetricPermutationGroup.identitystE$)),-..rfN) rrrrr@rerorrr5rrrfr/rrsC  %"$   / /rfrcDeZdZdZddZdZedZedZdZ y) raA left coset of a permutation group with respect to an element. Parameters ========== g : Permutation H : PermutationGroup dir : "+" or "-", If not specified by default it will be "+" here ``dir`` specified the type of coset "+" represent the right coset and "-" represent the left coset. G : PermutationGroup, optional The group which contains *H* as its subgroup and *g* as its element. If not specified, it would automatically become a symmetric group ``SymmetricPermutationGroup(g.size)`` and ``SymmetricPermutationGroup(H.degree)`` if ``g.size`` and ``H.degree`` are matching.``SymmetricPermutationGroup`` is a lazy form of SymmetricGroup used for representation purpose. Nct|}t|tstt|}t|tst|rt|}t|tt fst|j |stdj||||vrhtdj|||j}|j}||k7rtdj||t |j}t|tr t|}n't|tstdt|zt|dvrtd|ztj |||||}|S)Nz{} must be a subgroup of {}.z{} must be an element of {}.z]The size of the permutation {} and the degree of the permutation group {} should be matching z0dir must be of type basestring or Symbol, not %s)r}-z$dir must be one of '+' or '-' not %s)rr+rrr&rrrrr3r5strrrlrmrr@)rArErrAr~g_sizeh_degreers r/r@z Coset.__new__sZ QK![)% % QK!-.% % = Aa"24M!NO))==# !?!F!Fq!!LMMz !?!F!Fq!!LMMVVFxxH! CVAq\##*!&&1A c3 +CC(%'+Cy12 2 s8: %CcIJ JmmCAq#. rfc,|jd|_y)N)rB_dirrcs r/rezCoset.__init__sIIaL rfc2t|jdk(S)aw Check if the coset is left coset that is ``gH``. Examples ======== >>> from sympy.combinatorics import Permutation, PermutationGroup, Coset >>> a = Permutation(1, 2) >>> b = Permutation(0, 1) >>> G = PermutationGroup([a, b]) >>> cst = Coset(a, G, dir="-") >>> cst.is_left_coset True rrr!rqs r/ is_left_cosetzCoset.is_left_coset "499~$$rfc2t|jdk(S)ay Check if the coset is right coset that is ``Hg``. Examples ======== >>> from sympy.combinatorics import Permutation, PermutationGroup, Coset >>> a = Permutation(1, 2) >>> b = Permutation(0, 1) >>> G = PermutationGroup([a, b]) >>> cst = Coset(a, G, dir="+") >>> cst.is_right_coset True r}r#rqs r/is_right_cosetzCoset.is_right_coset3r%rfc|jd}|jd}g}t|jdk(r'|jD]}|j ||z|S|jD]}|j ||z|S)zG Return all the elements of coset in the form of list. rr7r})rBrr!rr)rdrErcstrs r/as_listz Coset.as_listFs IIaL IIaL tyy>S ZZ  1Q3  ZZ  1Q3  rf)Nr}) rrrrr@rerr$r'r*rrfr/rrs?2#J!%%$%%$ rfrNrr)<mathrrrr itertoolsrrsympy.combinatoricsr sympy.combinatorics.permutationsr r r r r rsympy.combinatorics.utilrrrrrrrr sympy.corersympy.core.randomrrrsympy.core.symbolrsympy.core.sympifyr(sympy.functions.combinatorial.factorials sympy.ntheoryrrsympy.ntheory.factor_rr sympy.ntheory.primetestr!sympy.utilities.iterablesr"r#r$ rmul_with_afrr>r&rrr r.rrrrrfr/r:s33$,));;$'>-;+DD   KNWuKNW\\J'Z<>B0+f  Q/Q/huEurf