K itdZddlmZddlmZddlmZmZmZddl m Z ddl m Z m Z mZddlmZddlmZdd lmZdd lmZdd lmZdd lmZdd lmZddlmZed&dZed&dZ edZ!dZ"GddeZ#GddeZ$d&dZ%dZ&dZ'd&dZ(dddZ)dZ*dZ+d'd Z,d!Z-d"Z.d#Z/d(d%Z0eZ1y$))z.Finitely Presented Groups and its algorithms. )S)symbols) FreeGroupFreeGroupElement free_group)RewritingSystem) CosetTablecoset_enumeration_rcoset_enumeration_c)PermutationGroup)invariant_factors)Matrix)gcd)DefaultPrinting)public)pollute)productcLt||}|ft|jzSN)FpGrouptuple _generatorsfr_grprelators _fp_groups c/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/combinatorics/fp_groups.pyfp_grouprs&)I <% 5 56 66c6t||}||jfSr)rrrs r xfp_groupr!s)I y,, --rctt|}t|jDcgc]}|jc}|j|Scc}wr)rrrname generators)fr_grpmrrsyms r vfp_groupr'!s>*I !2!2 3#SXX 3Y5I5IJ  4sA c|S)zParse the passed relators.)relss r_parse_relatorsr+(s Krc<eZdZdZdZdZdZdZdZdZ dZ dZ e d Z d Zd'd Z d(d ZdZ d(dZd)dZdZd*dZdZdZd)dZdZeZdZdZdZdZdZdZ dZ!dZ"dZ#e d Z$e d!Z%e d"Z&e d#Z'e d$Z(d%Z)d&Z*y )+rz The FpGroup would take a FreeGroup and a list/tuple of relators, the relators would be specified in such a way that each of them be equal to the identity of the provided free group. TFct|}||_||_|j|_t dt fd|i|_d|_d|_ d|_ d|_ t||_ d|_y)NFpGroupElementgroupF)r+rrrr$typer.dtype _coset_table_is_standardized_order_centerr_rewriting_system_perm_isomorphism)selfrrs r__init__zFpGroup.__init__=s|"8,   **,*^,=O !!&  !0!6!%rc.|jjSr)rr$r8s rrzFpGroup._generatorsQs)))rc8|jjy)zE Try to make the group's rewriting system confluent N)r6make_confluentr;s rr=zFpGroup.make_confluentTs --/rc8|jj|S)z Return the reduced form of `word` in `self` according to the group's rewriting system. If it's confluent, the reduced form is the unique normal form of the word in the group. )r6reduce)r8words rr?zFpGroup.reduce\s%%,,T22rc||j||dzz|jk(ry|jjryy)a+ Compare `word1` and `word2` for equality in the group using the group's rewriting system. If the system is confluent, the returned answer is necessarily correct. (If it is not, `False` could be returned in some cases where in fact `word1 == word2`) TFN)r?identityr6 is_confluent)r8word1word2s requalszFpGroup.equalses9 ;;uUBY '4== 8  # # 0 0rc.|jjSr)rrCr;s rrCzFpGroup.identityts'''rc||jvSr)r)r8gs r __contains__zFpGroup.__contains__xsDOO##rNcxtd|Ds tdtfd|Ds td|rt||d\}}}nt||\}}|rt|dj|}ntt d dg}|rdd lm}||||jd fS|S) a Return the subgroup generated by `gens` using the Reidemeister-Schreier algorithm homomorphism -- When set to True, return a dictionary containing the images of the presentation generators in the original group. Examples ======== >>> from sympy.combinatorics.fp_groups import FpGroup >>> from sympy.combinatorics import free_group >>> F, x, y = free_group("x, y") >>> f = FpGroup(F, [x**3, y**5, (x*y)**2]) >>> H = [x*y, x**-1*y**-1*x*y*x] >>> K, T = f.subgroup(H, homomorphism=True) >>> T(K.generators) [x*y, x**-1*y**2*x**-1] c3<K|]}t|tywr) isinstancer).0rJs r z#FpGroup.subgroup..sAq:a!12Asz&Generators must be `FreeGroupElement`sc3PK|]}|jjk(ywr)r/r)rOrJr8s rrPz#FpGroup.subgroup..s>> from sympy.combinatorics import free_group >>> from sympy.combinatorics.fp_groups import FpGroup >>> F, x, y = free_group("x, y") >>> f = FpGroup(F, [x, y**2]) >>> f.order(strategy="coset_table_based") 2 rrT)r4r2lenrqrrorderr$absr array_form _is_infiniterInfinity_finite_index_subgroupr_index)r8rkrr]rRinds rrvz FpGroup.orders_ ;; ";;     (d//556DK{{ 1 $////1DK{{ !Q &ct}}"M!1<<?1#5"MNODK{{   **DK{{ 113GD!!''l!$---":"@"@"BB {{#jjn {{#NsF/ c t}|jD]!}|j|j#t|j|ksyg}|jD]:}|j |jDcgc]}|j |c}<tt|}dt|vryycc}w)zq Test if the group is infinite. Return `True` if the test succeeds and `None` otherwise TrN) setrupdatecontains_generatorsr$append exponent_sumrr )r8 used_gensr} abelian_relsrelrJms rryzFpGroup._is_infinites E  6A   Q224 5 64??#y0 == PC   doo N!1!1!!4 N O P 6,' ( !!$ $ !Os>C c|j}t|j}|j|j|st |jdk(r%|g|jDcgc] }||k7s | c}z}n|j j}d}||vs|dz|vs |jr7|dkr2|j}|dz }||vs|dz|vs |jr|dkr2||g|jDcgc] }||k7s | c}z}t |dzdz}|d|}||d} d} d} d} d} | s| dz tjkrt| tj} |j|| | d } | jr| } |}n)|j| | | d } | jr| } | }| s| dz} | s| dz tjkr| sy | j| fScc}wcc}w) z Find the elements of `self` that generate a finite index subgroup and, if found, return the list of elements and the coset table of `self` by the subgroup, otherwise return `(None, None)` rrB rtNTrb)NN)most_frequent_generatorlistr$extendrrurrC is_identityrandomr rfminrlrgrh)r8sgenr*rJrandimidhalf1half2draft1draft2rrRhalfs rr{zFpGroup._finite_index_subgroups **,DOO$ DMM"4??#q(ED118QDD// bD(8D.Hs8aQ&&q)8s)r$rsumr|max)r8r]r*rJfreqss ` rrzFpGroup.most_frequent_generatorEsQ}}BFGQ8488GGEKKE +,,HsAcddl}|jj}t|j ddD]4}||j |j |j ddgzz}6|S)NrrrtrB)rrrCrangerandintchoicer$)r8rr}rs rrzFpGroup.randomKsc OO $ $v~~a*+ HA&--0&--22GGGA Hrcz|gk(r|jS|j||}t|jS)ae Return the index of subgroup ``H`` in group ``self``. Examples ======== >>> from sympy.combinatorics import free_group >>> from sympy.combinatorics.fp_groups import FpGroup >>> F, x, y = free_group("x, y") >>> f = FpGroup(F, [x**5, y**4, y*x*y**3*x**3]) >>> f.index([x]) 4 )rvrlrurq)r8rjrkrRs rr|z FpGroup.indexRs7$ 7::< &&q(3Aqww< rc|jjdkDrd|jjz}|Sdt|jz}|S)Nzz)rrankstrr$r8str_forms r__str__zFpGroup.__str__jsI ??  " $69M9MMH93t;OOHrc $ddlm}ddlm}|j t j ur td|jr |j}|j}||fS|jg}|j}|Dcgc]<}tt|Dcgc]}||d|j|zc}>} }}| Dcgc] }|| } }t| }||||| d}||_||fScc}wcc}}wcc}w)z Return an isomorphic permutation group and the isomorphism. The implementation is dependent on coset enumeration so will only terminate for finite groups. r) PermutationrVz>Permutation presentation of infinite groups is not implementedrFrW)sympy.combinatoricsrr\rSrvrrzNotImplementedErrorr7imagerrr$rrur|r ) r8rrSTPrRr]rJrimagess r_to_perm_groupzFpGroup._to_perm_groupws 4B ::<1:: %%'NO O  ! !&&A A!t   $A??DNRSeCFmDqtAdjjmO,DSFS.45k!n5F5 (AT1dF%@A%&D "!t ES5sD!!D DD Dc|j\}}t|||}d}t|tr|gd}}g}|D].}|j} |j |j | 0|r|dS|S)a4 Given the name of a `PermutationGroup` method (returning a subgroup or a list of subgroups) and (optionally) additional arguments it takes, return a list or a list of lists containing the generators of this (or these) subgroups in terms of the generators of `self`. FTr)rgetattrrNr r$rinvert) r8 method_nameargsrr perm_resultsingleresultr/r]s r_perm_group_listzFpGroup._perm_group_lists""$1-ga-t4  k#3 4#.-K  *E##D MM!((4. ) *#vay..rc$|jdS)z Return the list of lists containing the generators of the subgroups in the derived series of `self`. derived_seriesrr;s rrzFpGroup.derived_seriess $$%566rc$|jdS)z Return the list of lists containing the generators of the subgroups in the lower central series of `self`. lower_central_seriesrr;s rrzFpGroup.lower_central_seriess $$%;<22rc$|jdS)z/ Check if `self` is solvable. is_solvablerr;s rrzFpGroup.is_solvables ""=11rc^|j\}}|j|jS)z/ List the elements of `self`. )rrelementsr8rrs rrzFpGroup.elementss) ""$1xx ##rct|jdkry |j\}}|jS#t$r tdwxYw)z6 Return ``True`` if group is Cyclic. rtTz2Check for infinite Cyclic group is not implemented)rur$rr is_cyclicrs rrzFpGroup.is_cyclics^ t 1 $ <&&(DAq{{# <%';< <  113322$$   & &rrc@eZdZdZdfd ZdZdZdZdZeZ xZ S) FpSubgroupz The class implementing a subgroup of an FpGroup or a FreeGroup (only finite index subgroups are supported at this point). This is to be used if one wishes to check if an element of the original group belongs to the subgroup ct|||_t|Dchc]}||jk7s|c}|_d|_d|_||_ycc}wr) superr9parentrrCr$ _min_wordsrRnormal)r8Gr]rrJ __class__s rr9zFpSubgroup.__init__/sQ  4Ca1 ?CD  Ds AAcNtjtrjd}g}jD]5}j r|j }|j||7|D]^}|D]U}||k(st|ts |dz|k(r"t|tr|dd|dddz}}n|d|t|dz }}t|tr|dd|dddz} } n|d|t|dz } } ||} } t|tr|d|dz|ddzz} t|tr|d|dz|ddzz} | dz|k(r/| | zjs || | z} | |vr|j| | dz|k(s#| | zjr4|| | z} | |vsE|j| Xa|_jfdifdj r|j }|Sj,jjj}|_ d}j}tt|D]$}|j||j||}&|dk(S)Nc\|jd\}}|js||fgS||dzgS)NTremovedrB)cyclic_reductionr)wpr}s r_processz)FpSubgroup.__contains__.._processAs;--d-;DAq==!"Ax !1b5z)rrBrrtc|jd\}}|js jr|vSDcgc] }t|ts|d|k(r|d"}}|Dcgc]}|j |s|c}gk7Scc}wcc}w)NTrrrt)rrrrNrpower_of)rr}rt min_wordsr8s r _is_subwordz,FpSubgroup.__contains__.._is_subwords))$)71==DKK >)'0O!Jq%4HDEaDAI1OAO'(:!AJJqMA:b@@O:sB B"B9Bct|dk(ryd}|t|kr_|dz }|jd|}|s.|j|t|}|vr ||<|ry|t|kr_y)NrTrtF)rusubword)rrprefixrestr _word_breakknowns rr z,FpSubgroup.__contains__.._word_breaksq6Q;#a&jFAYYq!_F&v. 99QA/D5(&1$&7d T{##a&jr)rNrrrr$rrrrrurrRrlrrqA_dict)r8rJrr]rw1w2s1s2r1r2p1p2newrRrjrr r rs` @@@@rrKzFpSubgroup.__contains__7s dkk9 -& *-A{{..0KK ,- '1B"&18Jr5,A<>FbL$ &b%0%'U1Xr!uQx|B%'UBs2wqyMB%b%0%'U1Xr!uQx|B%'UBs2wqyMB"$RB%b%0!#Ar!uRUBY!6B%b%0!#Ar!uRUBY!6Br6R<B0C0C"*2b5/C"$ $ C 0r6R<B0C0C"*2b5/C"$ $ C 0M&1'1R#'I AE ${{&&(q> !vv~KK11$//BAA3q6] /GGAJqxx!~. /6Mrcr|jstjSt|jt rtj S|j,|jj|j}||_|jjt|jjz Sr) r$rOnerNrrrzrRrlrvrurq)r8rRs rrvzFpSubgroup.ordersy55L dkk9 -::  66> --doo>ADF{{  "3tvv||#444rc"t|jtrKtt |j Dcgc]}d|z }}t dj|dS|jj|jScc}w)Nzx_%d, rrT) rNrrrrur$rjoinr_rR)r8rgen_symss r to_FpGroupzFpSubgroup.to_FpGroupsp dkk9 -,1#doo2F,GHqHHHdii1215 5{{##dff#--Is B ct|jdkDrdt|jz}|Sdt|jz}|S)Nrz z")rur$rrs rrzFpSubgroup.__str__sG t " $9CRRHrF) rrrrr9rKrvrrr __classcell__)rs@rrr's*wr 5. Hrrc >t|g}|j}d}|Dchc]}t||kDs|}}t||z Dchc]}|j }}|j |} g} t | || |jd|||| Scc}wcc}w)aL Implements the Low Index Subgroups algorithm, i.e find all subgroups of ``G`` upto a given index ``N``. This implements the method described in [Sim94]. This procedure involves a backtrack search over incomplete Coset Tables, rather than over forced coincidences. Parameters ========== G: An FpGroup < X|R > N: positive integer, representing the maximum index value for subgroups Y: (an optional argument) specifying a list of subgroup generators, such that each of the resulting subgroup contains the subgroup generated by Y. Examples ======== >>> from sympy.combinatorics import free_group >>> from sympy.combinatorics.fp_groups import FpGroup, low_index_subgroups >>> F, x, y = free_group("x, y") >>> f = FpGroup(F, [x**2, y**3, (x*y)**4]) >>> L = low_index_subgroups(f, 4) >>> for coset_table in L: ... print(coset_table.table) [[0, 0, 0, 0]] [[0, 0, 1, 2], [1, 1, 2, 0], [3, 3, 0, 1], [2, 2, 3, 3]] [[0, 0, 1, 2], [2, 2, 2, 0], [1, 1, 0, 1]] [[1, 1, 0, 0], [0, 0, 1, 1]] References ========== .. [1] Holt, D., Eick, B., O'Brien, E. "Handbook of Computational Group Theory" Section 5.4 .. [2] Marston Conder and Peter Dobcsanyi "Applications and Adaptions of the Low Index Subgroups Procedure" r)r rruridentity_cyclic_reduction conjugatesdescendant_subgroupsA) rNYrRR len_short_relrR2R1 R1_c_listrs rlow_index_subgroupsr/sR 1bA AM 7#c#h6# 7B 769Vb[ Ac# ' ' ) AB A R I AAy!##a&"a; H 8 BsBB Bc F|j}|j}|jrEt||jD]\} } |j | | ry|j |yttt|j|jD] \} }|j| ||| |} } n|j|jgz} | D]@}||ks ||jk(s|j|| .t|||||  || Byr) r  A_dict_invrgromega scan_checkrrrurqr'ntry_descendant)rrRr.xr,r(r)r r1ralphaundefined_coset undefined_genreachbetas rr&r& s XXFJ}} AGG, HAu<<q)    c!''l 3QSS9 HE1wwu~fQi(016  133% 4Dax133;!''$- =0I"J"R"1aB?)44 4rc t|j} || jk(rR||krM| jjdgt | j z| j j||| j|| j|<|| j|| j|<| jj||f| j|| j||| j|sy|D]} | jd| ryt| |rt|| |||||yy)zZ Solves the problem of trying out each individual possibility for `\alpha^x. Nr)copyr4rqrrur'rr r1deduction_stackprocess_deductions_checkr3first_in_classr&) rrRr.r,r(r7r6r;r)Drs rr5r5%s A qss{tax vc!##h'  4"&AGGEN188A;%*AGGDM!,,q/"eQZ( % %i &< all1o & ( ||Aq! aQ9aQ:rcH|j}d}dg|z}dg|z}d}td|D]}t|dzD] }d|||< |D](} |j||j| |k7s&d}n|rd}P||d<d||<d}t|D]}|jD]w} |j||j| } |j|||j| } | | d}n.|| |dz }||| <| ||<|| | kry|| | kDsud}n|sd}y)a Checks whether the subgroup ``H=G1`` corresponding to the Coset Table could possibly be the canonical representative of its conjugacy class. Parameters ========== C: CosetTable Returns ======= bool: True/False If this returns False, then no descendant of C can have that property, and so we can abandon C. If it returns True, then we need to process further the node of the search tree corresponding to C, and so we call ``descendant_subgroups`` recursively on C. Examples ======== >>> from sympy.combinatorics import free_group >>> from sympy.combinatorics.fp_groups import FpGroup, CosetTable, first_in_class >>> F, x, y = free_group("x, y") >>> f = FpGroup(F, [x**2, y**3, (x*y)**4]) >>> C = CosetTable(f, []) >>> C.table = [[0, 0, None, None]] >>> first_in_class(C) True >>> C.table = [[1, 1, 1, None], [0, 0, None, 1]]; C.p = [0, 1] >>> first_in_class(C) True >>> C.table = [[1, 1, 2, 1], [0, 0, 0, None], [None, None, None, 0]] >>> C.p = [0, 1, 2] >>> first_in_class(C) False >>> C.table = [[1, 1, 1, 2], [0, 0, 2, 0], [2, None, 0, 1]] >>> first_in_class(C) False # TODO:: Sims points out in [Sim94] that performance can be improved by # remembering some of the information computed by ``first_in_class``. If # the ``continue alpha`` statement is executed at line 14, then the same thing # will happen for that value of alpha in any descendant of the table C, and so # the values the values of alpha for which this occurs could profitably be # stored and passed through to the descendants of C. Of course this would # make the code more complicated. # The code below is taken directly from the function on page 208 of [Sim94] # nu[alpha] rBNFrtTr)r4rrqr r') rRr)r4lamdanumu next_alphar7r;rr6gammadeltas rr@r@<sl A E B BJq!.%'N DBr$xL  Awwu~ahhqk*e3!    J 15 !H DSS  ahhqk24)!((1+6=EM!%Je9$QJE %BuI %BuIe9u$ e9u$!%J' (" / /.^ rF change_gensc$t|dk(rxt|dts td|d}t |j |j |\}}|rt|dj|SttggSt|dk(r0|ddd|ddd}}|s||fS|djj}n(t|dk(r d}t|d}t|g}g}t|t|k(sj|}|rCt|t|k(s,|}t|||\}}|rt|t|k(s,t|}t|t|k(sj|r|D cgc]} | jdd} } t| d} | j}| j }t!t#| |} t%|D]-\} }|j}|}|D]\}}|| ||zz}||| </||fScc} w) a For an instance of `FpGroup`, return a simplified isomorphic copy of the group (e.g. remove redundant generators or relators). Alternatively, a list of generators and relators can be passed in which case the simplified lists will be returned. By default, the generators of the group are unchanged. If you would like to remove redundant generators, set the keyword argument `change_gens = True`. rtrz+The argument must be an instance of FpGrouprIrNzNot enough argumentszToo many arguments)rurNr TypeErrorsimplify_presentationr$rr/rrC RuntimeErrorrelimination_technique_1_simplify_relatorsrxrdictzip enumerate)rJrrr]r*rCr prev_gens prev_relsrJsymsFsubsrr}arr&rs rrMrMs 4yA~$q'7+IJ J G*1<<:EG d 47==$/ /y}b)) Ta!WQZad: 7==)) t9>&A1o%A1oII)nD ) #i.CI"=I0tXFJD$#i.CI"="$' )nD ),01q Q"11 t Q ::||CdO$dO DAq AC 'Q$s)Q,& 'DG   :2s8H c|dd}|sgS|djj}i}tt|D]}||}|j dk(s|d}t |j dd}|j dddkr||dz||<|dz}||vrt|||j dd}||z||<t|j}t|D]\}}||vr |j|d}|jD]`}||vs||j dd}|dzdz}|j||z|||z zd}|j|| z|||z zd}b|||<|D cgc]} | j}} ||z }tt|}|j! |j#||Scc} w#t$$rY|SwxYw)a Simplifies a set of relators. All relators are checked to see if they are of the form `gen^n`. If any such relators are found then all other relators are processed for strings in the `gen` known order. Examples ======== >>> from sympy.combinatorics import free_group >>> from sympy.combinatorics.fp_groups import _simplify_relators >>> F, x, y = free_group("x, y") >>> w1 = [x**2*y**4, x**3] >>> _simplify_relators(w1) [x**3, x**-1*y**4] >>> w2 = [x**2*y**-4*x**5, x**3, x**2*y**8, y**5] >>> _simplify_relators(w2) [x**-1*y**-2, x**-1*y*x**-1, x**3, y**5] >>> w3 = [x**6*y**4, x**4] >>> _simplify_relators(w3) [x**4, x**2*y**4] >>> w4 = [x**2, x**5, y**3] >>> _simplify_relators(w4) [x, y**3] NrrtrBT_allr)r/rCrrunumber_syllablesrwrxrrvaluesrSeliminate_wordsreliminate_wordr$rsortremoverZ) r*rCexpsrrrJexpone_syllables_wordsmax_expr}s rrPrPsK: 7D  Aw}}%%H D 3t9  1g    !Q &AAcnnQ'*+C~~a #a'q'2+QrEDy#tAw11!4Q78fDG t{{}-D/ 3 % % !!"5d!C((* ZADy1g((+A.7Q,((Wq73;7GPT(U((gXgckN8KTX(Y  Z Q 48 8aA ' ' ) 8D 8 D D ?DIIK  H K 9   K sG G"" G/.G/c|dd}|j|dd}i}g}t}|D]}|jtfd|Dr(t jdD]}|j |dk(s||vs|j |}|j||z} |j| dzt|} |jd| } | | z} | d|zz||<|j| j|j||D cgc] } | |vs|  }} |D cgc]#} | j|dj%}} t t|} |j||Dcgc] }||vs| }}||fScc} wcc} w#t$rY-wxYwcc}w)Nc3&K|]}|v ywrr))rOrJcontained_genss rrPz*elimination_technique_1..Ks;qqN";sTreversertrrBr[)rarranyrrrr|rrurrr_r$rbrZ)r]r*rCredundant_gensredundant_relsrrrk gen_indexbkfwchir}rJris @rrOrO<s 7D IIK 7DNNI002 ;N; ; n-d+! C""3'1,I1E$$S)IIc1f- [[QC9[[I.e&)BqDks#  !8!8!:;%%c* & 7!q6A 7D 7`d e[\A  nT  : T T V eD e D ?D  H 7!q6A 7D 7 : 8 e    7s0. F*8F*(F/F4 G G4 G?Gcg}d}|j}|j}|ri}i}|j|d<t|jDcgc]}dgt |j zc}|_t|j|j D]\} } |j| |j| } | |k(rRd|j| |j| <d|j| |j| <|dz }|sp| | z|| <|| |vs|j| |j| | d| } |j| | |j| |j| <|s| | z|| dzz| <ttdj!|} | j#d|_| |_|r|_ttt |jtt |j D]\}}|j||dk(r'|j$j|j||<Bt+|j||t,sc|j&|j/|j||}||j||<|j||} |dz|j| |dz<ycc}w)z Parameters ========== C -- Coset table. homomorphism -- When set to True, return a dictionary containing the images of the presentation generators in the original group. rtrNz _rBr)rr$rCrr4rur'rrr2rqr r1rrrrpop_schreier_free_group_schreier_generators_schreier_gen_elemrNrr|)rRrSyrGfXr^taurr7r6r; y_alpha_xgrp_gensrr}s rdefine_schreier_generatorsrjs A E A AA$)!##J /qD6#acc(? /ACAGGQSS) >qwwu~ahhqk* 5=&2ACCJqxx{ #)5ACCIall1o & QJEJqLD !VE 188A;/7#$e,I HHY &/ACCJqxx{ ##&u:a<D 2 #=i  >Jtyy|,-H%\\!_A%A$c!##hs133x9%1 33q6!9 $..77ACCF1I Aq 3 '&&qwwqss1vay'9:AACCF1I771:a=D "uACCIa!e %+ 0s Kc |jj}|Dcgc])}t|jD]}t |||+}}}|Dchc]}t |dk(s|c}t tfd|}tt |D]}||}|jd}|||<!|jDcgc]}|vs |dzvs|c}|_ d}|t |krX||}|dz}|t |kr,|j||r||=n|dz }|t |kr,|dz }|t |krX||_ ycc}}wcc}wcc}w)Nrtc |vSrr))r order_1_genss rz'reidemeister_relators..s 3l#:rTr[rBr) rrrr4rewriterurfilterr_rxis_cyclic_conjugate_reidemeister_relators) rRr*r@cosetr*rrrrs @rreidemeister_relatorsrsx A01 JuQSSz JeGAud # J # JD J#3!s1v{A3L :DA BD3t9  G  l  6Q *+)?)?IA-B,1F IA A c$i- G E#d)m$$T!W-GQ #d)m Q c$i- $A9 K3Is.EE&E E c|jj}tt|D]H}||}||j||j |z}|j ||j |}J|S)a Parameters ========== C: CosetTable alpha: A live coset w: A word in `A*` Returns ======= rho(tau(alpha), w) Examples ======== >>> from sympy.combinatorics.fp_groups import FpGroup, CosetTable, define_schreier_generators, rewrite >>> from sympy.combinatorics import free_group >>> F, x, y = free_group("x, y") >>> f = FpGroup(F, [x**2, y**3, (x*y)**6]) >>> C = CosetTable(f, []) >>> C.table = [[1, 1, 2, 3], [0, 0, 4, 5], [4, 4, 3, 0], [5, 5, 0, 2], [2, 2, 5, 1], [3, 3, 1, 4]] >>> C.p = [0, 1, 2, 3, 4, 5] >>> define_schreier_generators(C) >>> rewrite(C, 0, (x*y)**6) x_4*y_2*x_3*x_1*x_2*y_4*x_5 )rwrCrrurr rq)rRr7rvrx_is rrrsu: ''A 3q6].d acc%j#' 'qxx}-. Hrc n|j}|jd|j}tt |dz ddD]}||}tt |dz ddD]}||}|j |dk(s|j |}|j||z}|j|dzt |} |jd|} | | zd|zz} ||=||=|Dcgc]}|j|| }}||_||_|j|jfScc}w)a  This technique eliminates one generator at a time. Heuristically this seems superior in that we may select for elimination the generator with shortest equivalent string at each stage. >>> from sympy.combinatorics import free_group >>> from sympy.combinatorics.fp_groups import FpGroup, coset_enumeration_r, reidemeister_relators, define_schreier_generators, elimination_technique_2 >>> F, x, y = free_group("x, y") >>> f = FpGroup(F, [x**3, y**5, (x*y)**2]); H = [x*y, x**-1*y**-1*x*y*x] >>> C = coset_enumeration_r(f, H) >>> C.compress(); C.standardize() >>> define_schreier_generators(C) >>> reidemeister_relators(C) >>> elimination_technique_2(C) ([y_1, y_2], [y_2**-3, y_2*y_1*y_2*y_1*y_2*y_1, y_1**2]) TrjrtrBr) rrarxrrurrr|rr`) rRr*r]rrrrrorprqrrrep_bys relimination_technique_2rsH& # #DIIdI ! !D 3t9q="b ) 1gs4y1}b"- Aq'C""3'1,$$S)IIc1f- [[QC9[[I.R%2a4GGCGHC**37HH   $A!A ! !1#;#; ;; Is,D2Nc|s t||}|j|jt||t ||j |j }}t||d\}}t||_ t||_|r>|Dcgc]}|jt|}}|j|j|fS|j|jfScc}w)a Parameters ========== fp_group: A finitely presented group, an instance of FpGroup H: A subgroup whose presentation is to be found, given as a list of words in generators of `fp_grp` homomorphism: When set to True, return a homomorphism from the subgroup to the parent group Examples ======== >>> from sympy.combinatorics import free_group >>> from sympy.combinatorics.fp_groups import FpGroup, reidemeister_presentation >>> F, x, y = free_group("x, y") Example 5.6 Pg. 177 from [1] >>> f = FpGroup(F, [x**3, y**5, (x*y)**2]) >>> H = [x*y, x**-1*y**-1*x*y*x] >>> reidemeister_presentation(f, H) ((y_1, y_2), (y_1**2, y_2**3, y_2*y_1*y_2*y_1*y_2*y_1)) Example 5.8 Pg. 183 from [1] >>> f = FpGroup(F, [x**3, y**3, (x*y)**3]) >>> H = [x*y, x*y**-1] >>> reidemeister_presentation(f, H) ((x_0, y_0), (x_0**3, y_0**3, x_0*y_0*x_0*y_0*x_0*y_0)) Exercises Q2. Pg 187 from [1] >>> f = FpGroup(F, [x**2*y**2, y**-1*x*y*x**-3]) >>> H = [x] >>> reidemeister_presentation(f, H) ((x_0,), (x_0**4,)) Example 5.9 Pg. 183 from [1] >>> f = FpGroup(F, [x**3*y**-3, (x*y)**3, (x*y**-1)**2]) >>> H = [x] >>> reidemeister_presentation(f, H) ((x_0,), (x_0**6,)) rVTrI) r rhrnrrrxrrMrschreier_generatorsryr)fp_grprjrRrSr]r*rr^s rr[r[ sV  *JJL!--/q|<!'')A)A$D&tTtDJD$!$KA#DkA;?@C%%c#h/@@$$a&=&=uDD !"9"9 99AsC()r)r r)2rsympy.core.singletonrsympy.core.symbolrsympy.combinatorics.free_groupsrrr#sympy.combinatorics.rewritingsystemrsympy.combinatorics.coset_tabler r r rr sympy.matrices.normalformsr sympy.matricesrsympy.polys.polytoolsrsympy.printing.defaultsrsympy.utilitiesrsympy.utilities.magicr itertoolsrrr!r'r+rrr/r&r5r@rMrPrOrrrrr[r.r)rrrs4"%<<?BB18!%3")77..  r&or&jbbR6 r48;.qn.36pNb'\1%f$B" J&