K i+dddlmZddlmZejZdZd dZdZd dZd dZ d Z d Z y) ) Permutation)_distribute_gens_by_basec||Dchc] }t|c}|Dchc] }t|c}k(Scc}wcc}w)ao Compare two lists of permutations as sets. Explanation =========== This is used for testing purposes. Since the array form of a permutation is currently a list, Permutation is not hashable and cannot be put into a set. Examples ======== >>> from sympy.combinatorics.permutations import Permutation >>> from sympy.combinatorics.testutil import _cmp_perm_lists >>> a = Permutation([0, 2, 3, 4, 1]) >>> b = Permutation([1, 2, 0, 4, 3]) >>> c = Permutation([3, 4, 0, 1, 2]) >>> ls1 = [a, b, c] >>> ls2 = [b, c, a] >>> _cmp_perm_lists(ls1, ls2) True )tuple)firstsecondas b/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/combinatorics/testutil.py_cmp_perm_listsr s82$ $E!H $$ %E!H % && $ %s49c ddlm} ddlm t |drt |j d}|jDcgc]}|jc} fd}g}|s6|D]/}||s |jtj|1|S|D]}||s |j||St |drt||||St |d rt|||g|Sycc}w) NrPermutationGroup)_af_commutes_with generatorsTafc0tfdDS)Nc30K|] }|ywN).0genrxs r z<_naive_list_centralizer....Cs*U+z)_naive_list_centralizer..Css*UPT*U'Ugetitem array_form) sympy.combinatorics.perm_groupsr sympy.combinatorics.permutationsrhasattrlistgenerate_diminor _array_formappendr_af_new_naive_list_centralizer) selfotherrrelementsrcommutes_with_genscentralizer_listelementrrs @@r r)r)$s@2Cul#,,,56','7'78! 8U# J%g.$++K,?,?,HI J $ 5%g.$++G4 5   "&t-=e-DbII  %&t-=ug-FKK &9sC>c ddlm}t||}|}tt |D]D}|||}|j |j k7ry|j ||}F|j dk7ryy)a Verify the correctness of a base and strong generating set. Explanation =========== This is a naive implementation using the definition of a base and a strong generating set relative to it. There are other procedures for verifying a base and strong generating set, but this one will serve for more robust testing. Examples ======== >>> from sympy.combinatorics.named_groups import AlternatingGroup >>> from sympy.combinatorics.testutil import _verify_bsgs >>> A = AlternatingGroup(4) >>> A.schreier_sims() >>> _verify_bsgs(A, A.base, A.strong_gens) True See Also ======== sympy.combinatorics.perm_groups.PermutationGroup.schreier_sims rr FT)r!rrrangelenorder stabilizer)groupbaserrstrong_gens_distrcurrent_stabilizeri candidates r _verify_bsgsr<Ts8A0t< 3t9 D$%6q%9:  # # %): :/::47C D !Q& rNc||j|}t|jd}t||d}t ||S)a3 Verify the centralizer of a group/set/element inside another group. This is used for testing ``.centralizer()`` from ``sympy.combinatorics.perm_groups`` Examples ======== >>> from sympy.combinatorics.named_groups import (SymmetricGroup, ... AlternatingGroup) >>> from sympy.combinatorics.perm_groups import PermutationGroup >>> from sympy.combinatorics.permutations import Permutation >>> from sympy.combinatorics.testutil import _verify_centralizer >>> S = SymmetricGroup(5) >>> A = AlternatingGroup(5) >>> centr = PermutationGroup([Permutation([0, 1, 2, 3, 4])]) >>> _verify_centralizer(S, A, centr) True See Also ======== _naive_list_centralizer, sympy.combinatorics.perm_groups.PermutationGroup.centralizer, _cmp_perm_lists Tr) centralizerr$r%r)r )r6argcentr centr_listcentr_list_naives r _verify_centralizerrC}sN: }!!#&e++t+45J.ucdC :'7 88rc\ddlm} ||j|}t}t |dr |j }nt |dr|}nt |dr|g}|j D]|jfdD|t|}|j|S)Nrr r __getitem__r c3(K|] }|z  ywrr)rrels r rz)_verify_normal_closure..s9s#(9s) r!rnormal_closuresetr#rr%updater$ is_subgroup)r6r?closurer conjugates subgr_gens naive_closurerGs @r _verify_normal_closurerPs@.&&s+JsL!^^ m $ l #U ##%:9j99:$T*%56M   } --rc nddlm}ddlm}m}ddlm}g}tt|D]%} || \} } } } |j| | gg| z| f'||\}}}||||dz }t|tr d}|g}|g}n t|}g}t|D]$} |j||| || |dz &||}||Dcgc] }t|c}}t|jd}|j }t#}|jdD]5}|||}|D]%}t%|||}|j'|'7t|}|j)d |z}|D]}|d d |d d k(r |d |d k7ry|}t|dScc}w) au Canonicalize tensor formed by tensors of the different types. Explanation =========== sym_i symmetry under exchange of two component tensors of type `i` None no symmetry 0 commuting 1 anticommuting Parameters ========== g : Permutation representing the tensor. dummies : List of dummy indices. msym : Symmetry of the metric. v : A list of (base_i, gens_i, n_i, sym_i) for tensors of type `i`. base_i, gens_i BSGS for tensors of this type n_i number of tensors of type `i` Returns ======= Returns 0 if the tensor is zero, else returns the array form of the permutation representing the canonical form of the tensor. Examples ======== >>> from sympy.combinatorics.testutil import canonicalize_naive >>> from sympy.combinatorics.tensor_can import get_symmetric_group_sgs >>> from sympy.combinatorics import Permutation >>> g = Permutation([1, 3, 2, 0, 4, 5]) >>> base2, gens2 = get_symmetric_group_sgs(2) >>> canonicalize_naive(g, [2, 3], 0, (base2, gens2, 2, 0)) [0, 2, 1, 3, 4, 5] rr ) gens_products dummy_sgs)_af_rmulr1Tr)rN)r!rsympy.combinatorics.tensor_canrRrSr"rTr2r3r' isinstanceintextendrr$generater rIraddsort)gdummiessymvrrRrSrTv1r:base_igens_in_isym_isizesbasesgensdgens num_typesSrDdliststshdqr prevs r canonicalize_naivervsNAG9 B 3q6]5%&qT"U 66B48U345'+D% gsDF +E#s )eH E 9 > Ywqz3q64!8<=>A%8Q+a.89A t$ %E A B ZZ4Z  QN Ahq!n%A FF1I  RAFFH 9D  Sb6T#2Y uR   !:#9sF2cddlm}ddlm}m}t |j }|jdd|Dcgc]}|d }}||}d}|D]\}} |t| z }|D cgc]} g} } d} |D]N\}} | D]D} |||| ks| ||j| | || j| dz| dz } FPg} | D]}| j|t| |k(sJ| ||dzgz } |dz}t| t t|k(sJt| } dgt| ddzz}| D]} |t| xxdz cc<g}tt|D]*} || }|s || \}}|j|||df,|jt t|}|| |dg|}|Scc}wcc} w) a Return a certificate for the graph Parameters ========== gr : adjacency list Explanation =========== The graph is assumed to be unoriented and without external lines. Associate to each vertex of the graph a symmetric tensor with number of indices equal to the degree of the vertex; indices are contracted when they correspond to the same line of the graph. The canonical form of the tensor gives a certificate for the graph. This is not an efficient algorithm to get the certificate of a graph. Examples ======== >>> from sympy.combinatorics.testutil import graph_certificate >>> gr1 = {0:[1, 2, 3, 5], 1:[0, 2, 4], 2:[0, 1, 3, 4], 3:[0, 2, 4], 4:[1, 2, 3, 5], 5:[0, 4]} >>> gr2 = {0:[1, 5], 1:[0, 2, 3, 4], 2:[1, 3, 5], 3:[1, 2, 4, 5], 4:[1, 3, 5], 5:[0, 2, 3, 4]} >>> c1 = graph_certificate(gr1) >>> c2 = graph_certificate(gr2) >>> c1 [0, 2, 4, 6, 1, 8, 10, 12, 3, 14, 16, 18, 5, 9, 15, 7, 11, 17, 13, 19, 20, 21] >>> c1 == c2 True r) _af_invert)get_symmetric_group_sgs canonicalizect|dS)Nr1)r3)rs r rz#graph_certificate..=sS1YrT)keyreverser1rU)r"rxrXryrzr$itemsr^r3r'r[sortedr2rr})grrxryrzr~rpvert num_indicesrbneighr:verticesv2r_rhvlennr7rr`cans r graph_certificaters5F<T  E JJ&J5 !aQqT !E ! u EK"5s5z! " ""q"H" A5 BQx%)#q"))!,r#**1Q3/Q   A    q6[  +{Q ''A ?D !9U4[) )) )AA 3HQK " #D SZA A 3t9 ) G 03JD$ HHdD!Q' ( ) IIK5%&G q'1 )q )C JO "#s G 4 G%)Fr) sympy.combinatoricsrsympy.combinatorics.utilrrmulr r)r<rCrPrvrrrr rsA+=&:-L`&R!9H%.PK\Nr