§
    OŠtj†+  ã                   ó\   — d dl mZ d dlmZ ej        Zd„ Zdd„Zd„ Zdd„Zdd	„Z	d
„ Z
d„ ZdS )é    ©ÚPermutation)Ú_distribute_gens_by_basec                 ó6   — d„ | D ¦   «         d„ |D ¦   «         k    S )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

    c                 ó,   — h | ]}t          |¦  «        ’ŒS © ©Útuple©Ú.0Úas     úZ/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/sympy/combinatorics/testutil.pyú	<setcomp>z"_cmp_perm_lists.<locals>.<setcomp>    s   € Ð$Ð$Ð$˜�E�!‰HŒHÐ$Ð$Ð$ó    c                 ó,   — h | ]}t          |¦  «        ’ŒS r   r	   r   s     r   r   z"_cmp_perm_lists.<locals>.<setcomp>!   s   € Ð%Ð%Ð%˜�E�!‰HŒHÐ%Ð%Ð%r   r   )ÚfirstÚseconds     r   Ú_cmp_perm_listsr      s0   € ð2 %Ð$˜eÐ$Ñ$Ô$Ø%Ð%˜fÐ%Ñ%Ô%ò&ð &r   Fc                 ó(  ‡‡	— ddl m} 	 ddlmŠ t	          |d¦  «        r�t          |                      d¬¦  «        ¦  «        }d„ |j        D ¦   «         Š	ˆˆ	fd„}g }|s8|D ]4} ||¦  «        r'|                     t          j
        |¦  «        ¦  «         Œ5n%|D ]"} ||¦  «        r|                     |¦  «         Œ#|S t	          |d	¦  «        rt          |  ||¦  «        |¦  «        S t	          |d
¦  «        rt          |  ||g¦  «        |¦  «        S d S )Nr   ©ÚPermutationGroup)Ú_af_commutes_withÚ
generatorsT©Úafc                 ó   — g | ]	}|j         ‘Œ
S r   )Ú_array_form©r   Úxs     r   ú
<listcomp>z+_naive_list_centralizer.<locals>.<listcomp>B   s   € Ð8Ð8Ð8 !�”Ð8Ð8Ð8r   c                 ó>   •‡ — t          ˆˆ fd„‰D ¦   «         ¦  «        S )Nc              3   ó0   •K  — | ]} ‰‰|¦  «        V — Œd S ©Nr   )r   Úgenr   r   s     €€r   ú	<genexpr>z<_naive_list_centralizer.<locals>.<lambda>.<locals>.<genexpr>C   s1   øè è € Ð*UÐ*UÈÐ+<Ð+<¸QÀÑ+DÔ+DÐ*UÐ*UÐ*UÐ*UÐ*UÐ*Ur   )Úall)r   r   Úgenss   `€€r   ú<lambda>z)_naive_list_centralizer.<locals>.<lambda>C   s)   øø€ ¥sÐ*UÐ*UÐ*UÐ*UÐ*UÐPTÐ*UÑ*UÔ*UÑ'UÔ'U€ r   ÚgetitemÚ
array_form)Úsympy.combinatorics.perm_groupsr   Ú sympy.combinatorics.permutationsr   ÚhasattrÚlistÚgenerate_diminor   Úappendr   Ú_af_newÚ_naive_list_centralizer)
ÚselfÚotherr   r   ÚelementsÚcommutes_with_gensÚcentralizer_listÚelementr   r'   s
           @@r   r2   r2   $   s‘  øø€ Ø@Ð@Ð@Ð@Ð@Ð@ðð2 CÐBÐBÐBÐBÐBÝˆu�lÑ#Ô#ð LÝ˜×,Ò,°Ð,Ñ5Ô5Ñ6Ô6ˆØ8Ð8 uÔ'7Ð8Ñ8Ô8ˆØUÐUÐUÐUÐUÐØÐØð 	5Ø#ð Jð J�Ø%Ð% gÑ.Ô.ð JØ$×+Ò+­KÔ,?ÀÑ,HÔ,HÑIÔIÐIøðJð $ð 5ð 5�Ø%Ð% gÑ.Ô.ð 5Ø$×+Ò+¨GÑ4Ô4Ð4øØÐÝ	�˜	Ñ	"Ô	"ð LÝ& tÐ-=Ð-=¸eÑ-DÔ-DÀbÑIÔIÐIÝ	�˜Ñ	%Ô	%ð LÝ& tÐ-=Ð-=¸u¸gÑ-FÔ-FÈÑKÔKÐKðLð Lr   c                 óZ  — ddl m} t          ||¦  «        }| }t          t	          |¦  «        ¦  «        D ][} |||         ¦  «        }|                     ¦   «         |                     ¦   «         k    r dS |                     ||         ¦  «        }Œ\|                     ¦   «         dk    rdS dS )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

    r   r   Fé   T)r+   r   r   ÚrangeÚlenÚorderÚ
stabilizer)ÚgroupÚbaser'   r   Ústrong_gens_distrÚcurrent_stabilizerÚiÚ	candidates           r   Ú_verify_bsgsrE   T   sÆ   € ð8 AÐ@Ð@Ð@Ð@Ð@Ý0°°tÑ<Ô<ÐØÐÝ•3�t‘9”9ÑÔð Dð DˆØ$Ð$Ð%6°qÔ%9Ñ:Ô:ˆ	Ø×#Ò#Ñ%Ô%¨¯ªÑ):Ô):Ò:Ð:Ø�5�5Ø/×:Ò:¸4À¼7ÑCÔCÐÐØ×ÒÑ!Ô! QÒ&Ð&ØˆuØˆ4r   Nc                 óº   — |€|                       |¦  «        }t          |                     d¬¦  «        ¦  «        }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

    NTr   )Úcentralizerr.   r/   r2   r   )r?   ÚargÚcentrÚ
centr_listÚcentr_list_naives        r   Ú_verify_centralizerrL   }   s`   € ð: €}Ø×!Ò! #Ñ&Ô&ˆÝ�e×+Ò+¨tÐ+Ñ4Ô4Ñ5Ô5€JÝ.¨u°c¸dÐCÑCÔCÐÝ˜:Ð'7Ñ8Ô8Ð8r   c                 ó¢  ‡— ddl m} 	 |€|                      |¦  «        }t          ¦   «         }t	          |d¦  «        r|j        }n&t	          |d¦  «        r|}nt	          |d¦  «        r|g}|                      ¦   «         D ]#Š|                     ˆfd„|D ¦   «         ¦  «         Œ$ |t          |¦  «        ¦  «        }| 	                    |¦  «        S )Nr   r   r   Ú__getitem__r*   c              3   ó"   •K  — | ]	}|‰z  V — Œ
d S r#   r   )r   r$   Úels     €r   r%   z)_verify_normal_closure.<locals>.<genexpr>Ä   s'   øè è € Ð9Ð9 s˜# ™(Ð9Ð9Ð9Ð9Ð9Ð9r   )
r+   r   Únormal_closureÚsetr-   r   r/   Úupdater.   Úis_subgroup)r?   rH   Úclosurer   Ú
conjugatesÚ
subgr_gensÚnaive_closurerP   s          @r   Ú_verify_normal_closurerY   ¡   sý   ø€ Ø@Ð@Ð@Ð@Ð@Ð@ðð. €Ø×&Ò& sÑ+Ô+ˆÝ‘”€JÝˆs�LÑ!Ô!ð Ø”^ˆ
ˆ
Ý	��mÑ	$Ô	$ð Øˆ
ˆ
Ý	��lÑ	#Ô	#ð Ø�Uˆ
Ø×#Ò#Ñ%Ô%ð :ð :ˆØ×ÒÐ9Ð9Ð9Ð9¨jÐ9Ñ9Ô9Ñ9Ô9Ð9Ð9Ø$Ð$¥T¨*Ñ%5Ô%5Ñ6Ô6€MØ×Ò˜}Ñ-Ô-Ð-r   c           	      ó  — ddl m} ddlm}m} ddlm} g }t          t          |¦  «        ¦  «        D ],}	||	         \  }
}}}| 	                    |
|g g|z  |f¦  «         Œ- ||Ž \  }}} ||||dz
  ¦  «        }t          |t          ¦  «        r	d}|g}|g}nt          |¦  «        }g }t          |¦  «        D ]1}	|                      |||	         ||	         |dz
  ¦  «        ¦  «         Œ2 ||¦  «        } |d„ |D ¦   «         ¦  «        }t          |                     d¬	¦  «        ¦  «        }| j        } t!          ¦   «         }|                     d¬	¦  «        D ]A} || |¦  «        }|D ]0}t#           |||¦  «        ¦  «        }|                     |¦  «         Œ1ŒBt          |¦  «        }|                     ¦   «          d
|z  }|D ]/}|dd…         |dd…         k    r|d         |d         k    r dS |}Œ0t          |d         ¦  «        S )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]
    r   r   )Úgens_productsÚ	dummy_sgs)Ú_af_rmulé   r:   c                 ó,   — g | ]}t          |¦  «        ‘ŒS r   r   r   s     r   r    z&canonicalize_naive.<locals>.<listcomp>  s   € Ð8Ð8Ð8¨Q�+ a™.œ.Ð8Ð8Ð8r   Tr   ©r   Néþÿÿÿéÿÿÿÿ)r+   r   Úsympy.combinatorics.tensor_canr[   r\   r,   r]   r;   r<   r0   Ú
isinstanceÚintÚextendr.   Úgenerater*   rR   r
   ÚaddÚsort)ÚgÚdummiesÚsymÚvr   r[   r\   r]   Úv1rC   Úbase_iÚgens_iÚn_iÚsym_iÚsizeÚsbaseÚsgensÚdgensÚ	num_typesÚSÚDÚdlistÚstÚsÚhÚdÚqr   Úprevs                                r   Úcanonicalize_naiver�   É   s  € ðN AÐ@Ð@Ð@Ð@Ð@ØGÐGÐGÐGÐGÐGÐGÐGØ9Ð9Ð9Ð9Ð9Ð9Ø	€BÝ•3�q‘6”6‰]Œ]ð 5ð 5ˆØ%& q¤TÑ"ˆ�˜˜UØ
�	Š	�6˜6 B 4¨¡8¨UÐ3Ñ4Ô4Ð4Ð4Ø&˜¨Ð+Ñ€Dˆ%�ØˆI�g˜s D¨¡FÑ+Ô+€EÝ�#•sÑÔð Øˆ	Ø�)ˆØˆeˆˆå˜‘H”Hˆ	Ø€EÝ�9ÑÔð >ð >ˆØ�Š�Y�Y˜w qœz¨3¨q¬6°4¸!±8Ñ<Ô<Ñ=Ô=Ð=Ð=ØÐ˜ÑÔ€AØÐÐ8Ð8°%Ð8Ñ8Ô8Ñ9Ô9€AÝ�—’˜t�Ñ$Ô$Ñ%Ô%€EØ	Œ€AÝ	‰Œ€BØ�ZŠZ˜4ˆZÑ Ô ð ð ˆØˆH�Q˜‰NŒNˆØð 	ð 	ˆAÝ�h�h˜q !‘n”nÑ%Ô%ˆAØ�FŠF�1‰IŒIˆIˆIð	õ 	ˆR‰Œ€AØ‡F‚F�H„H€HØ�‰9€DØð ð ˆØˆSˆbˆSŒ6�T˜#˜2˜#”YÒÐØ�Œu˜˜RœÒ Ð Ø�q�qØˆˆÝ��!”‰:Œ:Ðr   c                 óz  — ddl m} ddlm}m} t          |                      ¦   «         ¦  «        }|                     d„ d¬¦  «         d„ |D ¦   «         } ||¦  «        }d}|D ]\  }}|t          |¦  «        z  }Œd„ |D ¦   «         }	d}
|D ]f\  }}|D ]^}||         ||         k     rJ|	||                   	                    |
¦  «         |	||                   	                    |
d	z   ¦  «         |
d
z  }
Œ_Œgg }|	D ]}| 
                    |¦  «         Œt          |¦  «        |k    sJ ‚|||d	z   gz  }|d
z   }t          |¦  «        t          t          |¦  «        ¦  «        k    sJ ‚t          |¦  «        }dgt          |	d         ¦  «        d	z   z  }|	D ]}|t          |¦  «        xx         d	z  cc<   Œ g }t          t          |¦  «        ¦  «        D ]3}
||
         }|r' ||
¦  «        \  }}| 	                    |||df¦  «         Œ4|                     ¦   «          t          t          |¦  «        ¦  «        } |||dg|¢R Ž }|S )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Úcanonicalizec                 ó,   — t          | d         ¦  «        S )Nr:   )r<   )r   s    r   r(   z#graph_certificate.<locals>.<lambda>=  s   € �S  1¤™YœY€ r   T)ÚkeyÚreversec                 ó   — g | ]
}|d          ‘ŒS r`   r   r   s     r   r    z%graph_certificate.<locals>.<listcomp>>  s   € Ð!Ð!Ð!�aˆQˆqŒTÐ!Ð!Ð!r   c                 ó   — g | ]}g ‘ŒS r   r   )r   rC   s     r   r    z%graph_certificate.<locals>.<listcomp>I  s   € Ð"Ð"Ð"�q�Ð"Ð"Ð"r   r:   r^   )r,   rƒ   rc   r„   r…   r.   Úitemsri   r<   r0   rf   Úsortedr;   r   rˆ   )Úgrrƒ   r„   r…   r‹   ÚpvertÚnum_indicesrm   ÚneighÚverticesrC   Úv2rj   rs   ÚvlenÚnr@   r'   rk   Úcans                       r   Úgraph_certificater–     sÈ  € ðF <Ð;Ð;Ð;Ð;Ð;ØTÐTÐTÐTÐTÐTÐTÐTÝ�—’‘”ÑÔ€EØ	‡J‚JÐ&Ð&°€JÑ5Ô5Ð5Ø!Ð!˜5Ð!Ñ!Ô!€EØˆJ�uÑÔ€Eð €KØð "ð "‰ˆˆ5Ø•s˜5‘z”zÑ!ˆˆð
 #Ð"˜EÐ"Ñ"Ô"€HØ	€AØð ð ‰ˆˆ5Øð 	ð 	ˆBØ�QŒx˜% œ)Ò#Ð#Ø˜˜qœÔ"×)Ò)¨!Ñ,Ô,Ð,Ø˜˜rœÔ#×*Ò*¨1¨Q©3Ñ/Ô/Ð/Ø�Q‘�øð		ð
 	€AØð ð ˆØ	�Š�‰ŒˆˆÝˆq‰6Œ6�[Ò Ð Ð Ð Øˆ+�{ Q‘Ð	'Ñ'€AØ˜‰?€DÝ�!‰9Œ9��U 4™[œ[Ñ)Ô)Ò)Ð)Ð)Ð)Ý�A‰Œ€AØˆ3•�H˜Q”KÑ Ô  Ñ"Ñ#€DØð ð ˆØ�S�‰ZŒZÐÐÔ˜AÑÐÐÑÐØ
€AÝ•3�t‘9”9ÑÔð )ð )ˆØ�ŒGˆØð 	)Ø0Ð0°Ñ3Ô3‰JˆD�$Ø�HŠH�d˜D ! QÐ'Ñ(Ô(Ð(øØ‡I‚I�K„K€KÝ•5˜Ñ%Ô%Ñ&Ô&€GØ
ˆ,�q˜' 1Ð
) qÐ
)Ð
)Ð
)€CØ€Jr   )Fr#   )Úsympy.combinatoricsr   Úsympy.combinatorics.utilr   Úrmulr   r2   rE   rL   rY   r�   r–   r   r   r   ú<module>rš      sÄ   ðØ +Ð +Ð +Ð +Ð +Ð +Ø =Ð =Ð =Ð =Ð =Ð =àÔ€ð&ð &ð &ð:-Lð -Lð -Lð -Lð`&ð &ð &ðR!9ð !9ð !9ð !9ðH%.ð %.ð %.ð %.ðPKð Kð Kð\Nð Nð Nð Nð Nr   