§
    OŠtjœI  ã                   ó    — d dl Z d dlmZmZmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZ  G d„ d	¦  «        Zdd„Zd„ Zd„ Zd„ Zdd„Zd„ ZdS )é    N)ÚFpGroupÚ
FpSubgroupÚsimplify_presentation)Ú	FreeGroup)ÚPermutationGroup)Úigcd)Útotient)ÚSc                   ól   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
d	„ Zd
„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ ZdS )ÚGroupHomomorphismzÖ
    A class representing group homomorphisms. Instantiate using `homomorphism()`.

    References
    ==========

    .. [1] Holt, D., Eick, B. and O'Brien, E. (2005). Handbook of computational group theory.

    c                 óZ   — || _         || _        || _        d | _        d | _        d | _        d S ©N)ÚdomainÚcodomainÚimagesÚ	_inversesÚ_kernelÚ_image)Úselfr   r   r   s       ú_/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/sympy/combinatorics/homomorphisms.pyÚ__init__zGroupHomomorphism.__init__   s0   € ØˆŒØ ˆŒØˆŒØˆŒØˆŒØˆŒˆˆó    c                 ó  — |                       ¦   «         }i }t          | j                             ¦   «         ¦  «        D ]}| j        |         }||v s|j        s|||<   Œ t          | j        t          ¦  «        r|j        }n|j	        }|D ]x}||v s|j        rŒ| j
        j        }t          | j        t          ¦  «        r|j        |         ddd…         }n|}|D ]#}	|	|v r|||	         z  }Œ|||	dz           dz  z  }Œ$|||<   Œy|S )zÚ
        Return a dictionary with `{gen: inverse}` where `gen` is a rewriting
        generator of `codomain` (e.g. strong generator for permutation groups)
        and `inverse` is an element of its preimage

        Néÿÿÿÿ)ÚimageÚlistr   ÚkeysÚis_identityÚ
isinstancer   r   Ústrong_gensÚ
generatorsr   ÚidentityÚ_strong_gens_slp)
r   r   ÚinversesÚkÚvÚgensÚgÚwÚpartsÚss
             r   Ú_invszGroupHomomorphism._invs   s9  € ð —
’
‘”ˆØˆÝ�d”k×&Ò&Ñ(Ô(Ñ)Ô)ð 	 ð 	 ˆAØ”˜A”ˆAØ˜�M�MØ”}ð "à�˜‘øÝ�d”mÕ%5Ñ6Ô6ð 	$ØÔ$ˆDˆDàÔ#ˆDØð 	ð 	ˆAØ�Hˆ}ˆ} ¤ˆ}ØØ”Ô$ˆAÝ˜$œ-Õ)9Ñ:Ô:ð ØÔ.¨qÔ1°$°$°B°$Ô7��à�Øð .ð .�Ø˜�=�=Ø˜( 1œ+™�A�Aà˜( 1 b¡5œ/¨2Ñ-Ñ-�A�AØˆH�Q‰KˆKàˆr   c                 ó¬  ‡ — ddl m} ddlm} t	          |||f¦  «        �rt	          ‰ j        t          ¦  «        r‰ j                             |¦  «        }‰ j        €‰  	                    ¦   «         ‰ _        ‰  
                    ¦   «         }‰ j        j        }t	          ‰ j        t          ¦  «        r|                     |¦  «        ddd…         }n|}t          t!          |¦  «        ¦  «        D ]B}||         }|j        rŒ|‰ j        v r|‰ j        |         z  }Œ,|‰ j        |dz           dz  z  }ŒC|S t	          |t$          ¦  «        rˆ fd„|D ¦   «         S dS )aÏ  
        Return an element of the preimage of ``g`` or of each element
        of ``g`` if ``g`` is a list.

        Explanation
        ===========

        If the codomain is an FpGroup, the inverse for equal
        elements might not always be the same unless the FpGroup's
        rewriting system is confluent. However, making a system
        confluent can be time-consuming. If it's important, try
        `self.codomain.make_confluent()` first.

        r   ©ÚPermutation)ÚFreeGroupElementNr   c                 ó:   •— g | ]}‰                      |¦  «        ‘ŒS © )Úinvert©Ú.0Úer   s     €r   ú
<listcomp>z,GroupHomomorphism.invert.<locals>.<listcomp>k   s#   ø€ Ð.Ð.Ð. q�D—K’K ‘N”NÐ.Ð.Ð.r   )Úsympy.combinatoricsr/   Úsympy.combinatorics.free_groupsr0   r   r   r   Úreducer   r,   r   r   r"   r   Úgenerator_productÚrangeÚlenr   r   )	r   r(   r/   r0   r   r)   r'   Úir+   s	   `        r   r3   zGroupHomomorphism.invert?   s~  ø€ ð 	4Ð3Ð3Ð3Ð3Ð3ØDÐDÐDÐDÐDÐDÝ�a˜+Ð'7Ð8Ñ9Ô9ñ 	/Ý˜$œ-­Ñ1Ô1ð ,Ø”M×(Ò(¨Ñ+Ô+�ØŒ~Ð%Ø!%§¢¡¤�”Ø—J’J‘L”LˆEØ”Ô$ˆAÝ˜$œ-Õ)9Ñ:Ô:ð Ø×.Ò.¨qÑ1Ô1°$°$°B°$Ô7��à�õ �3˜t™9œ9Ñ%Ô%ð 4ð 4�Ø˜”G�Ø”=ð ØØ˜œÐ&Ð&Ø˜$œ.¨Ô+Ñ+�A�Aà˜$œ.¨¨B©Ô/°Ñ3Ñ3�A�AØˆHÝ˜�4Ñ Ô ð 	/Ø.Ð.Ð.Ð.¨AÐ.Ñ.Ô.Ð.ð	/ð 	/r   c                 óP   — | j         €|                      ¦   «         | _         | j         S )z0
        Compute the kernel of `self`.

        )r   Ú_compute_kernel©r   s    r   ÚkernelzGroupHomomorphism.kernelm   s'   € ð
 Œ<ÐØ×/Ò/Ñ1Ô1ˆDŒLØŒ|Ðr   c                 óº  — | j         }|                     ¦   «         }|t          j        u rt	          d¦  «        ‚g }t          |t          ¦  «        rt          |j        ¦  «        }nt          ||d¬¦  «        }|  	                    ¦   «                              ¦   «         }|                     ¦   «         |z  |k    r£| 
                    ¦   «         }||                       | |¦  «        ¦  «        dz  z  }||vrL|                     |¦  «         t          |t          ¦  «        rt          |¦  «        }nt          ||d¬¦  «        }|                     ¦   «         |z  |k    °£|S )Nz9Kernel computation is not implemented for infinite groupsT)Únormalr   )r   Úorderr
   ÚInfinityÚNotImplementedErrorr   r   r"   r   r   Úrandomr3   Úappend)r   ÚGÚG_orderr'   ÚKr>   Úrr%   s           r   r@   z!GroupHomomorphism._compute_kernelv   sF  € ØŒKˆØ—'’'‘)”)ˆØ•a”jÐ Ð Ý%ØKñMô Mð MàˆÝ�aÕ)Ñ*Ô*ð 	1Ý  ¤Ñ,Ô,ˆAˆAå˜1˜d¨4Ð0Ñ0Ô0ˆAØ�JŠJ‰LŒL×ÒÑ Ô ˆØ�gŠg‰iŒi˜‰k˜WÒ$Ð$Ø—’‘
”
ˆAØ�$—+’+˜d˜d 1™gœgÑ&Ô&¨Ñ*Ñ*ˆAØ˜ˆzˆzØ—’˜A‘”�Ý˜aÕ!1Ñ2Ô2ð 9Ý(¨Ñ.Ô.�A�Aå" 1 d°4Ð8Ñ8Ô8�Að �gŠg‰iŒi˜‰k˜WÒ$Ð$ð ˆr   c                 ó,  — | j         €‡t          t          | j                             ¦   «         ¦  «        ¦  «        }t          | j        t          ¦  «        r | j                             |¦  «        | _         nt          | j        |¦  «        | _         | j         S )z/
        Compute the image of `self`.

        )
r   r   Úsetr   Úvaluesr   r   r   Úsubgroupr   )r   rP   s     r   r   zGroupHomomorphism.image�   sy   € ð
 Œ;ÐÝ�#˜dœk×0Ò0Ñ2Ô2Ñ3Ô3Ñ4Ô4ˆFÝ˜$œ-Õ)9Ñ:Ô:ð @Ø"œm×4Ò4°VÑ<Ô<�”�å(¨¬¸Ñ?Ô?�”ØŒ{Ðr   c                 ó.  ‡ — |‰ j         vr9t          |t          t          f¦  «        rˆ fd„|D ¦   «         S t	          d¦  «        ‚|j        r‰ j        j        S ‰ j        }‰ j        j        }t          ‰ j         t          ¦  «        rH‰ j          
                    |d¬¦  «        }|D ](}|‰ j        v r||         |z  }Œ||dz           dz  |z  }Œ)nId}|j        D ]?\  }}|dk     r||         dz  }n||         }|||         |z  z  }|t          |¦  «        z  }Œ@|S )z*
        Apply `self` to `elem`.

        c                 ó:   •— g | ]}‰                      |¦  «        ‘ŒS r2   ©Ú_applyr4   s     €r   r7   z,GroupHomomorphism._apply.<locals>.<listcomp>¡   s#   ø€ Ð5Ð5Ð5¨1˜Ÿš A™œÐ5Ð5Ð5r   z2The supplied element does not belong to the domainT)Úoriginalr   r   )r   r   r   ÚtupleÚ
ValueErrorr   r   r"   r   r   r;   Ú
array_formÚabs)	r   Úelemr   Úvaluer'   r(   r>   Ú_Úps	   `        r   rU   zGroupHomomorphism._applyš   sU  ø€ ð
 �t”{Ð"Ð"Ý˜$¥¥u Ñ.Ô.ð 6Ø5Ð5Ð5Ð5°Ð5Ñ5Ô5Ð5ÝÐQÑRÔRÐRØÔð 	 Ø”=Ô)Ð)à”[ˆFØ”MÔ*ˆEÝ˜$œ+Õ'7Ñ8Ô8ð  Ø”{×4Ò4°TÀDÐ4ÑIÔI�Øð 8ð 8�AØ˜DœKÐ'Ð'Ø & q¤	¨%¡˜˜à & q¨"¡u¤¨rÑ 1°%Ñ 7˜˜ð	8ð �Ø œOð  ð  ‘D�A�qØ˜1’u�uØ  œG R™K˜˜à  œG˜Ø! &¨¤)¨Q¡,Ñ.�EØ�˜Q™œ‘K�A�AØˆr   c                 ó,   — |                       |¦  «        S r   rT   )r   r[   s     r   Ú__call__zGroupHomomorphism.__call__º   s   € Ø�{Š{˜4Ñ Ô Ð r   c                 óV   — |                       ¦   «                              ¦   «         dk    S )z9
        Check if the homomorphism is injective

        é   )rB   rE   rA   s    r   Úis_injectivezGroupHomomorphism.is_injective½   s#   € ð
 �{Š{‰}Œ}×"Ò"Ñ$Ô$¨Ò)Ð)r   c                 óÈ   — |                       ¦   «                              ¦   «         }| j                             ¦   «         }|t          j        u r|t          j        u rdS ||k    S )z:
        Check if the homomorphism is surjective

        N)r   rE   r   r
   rF   )r   ÚimÚoths      r   Úis_surjectivezGroupHomomorphism.is_surjectiveÄ   sX   € ð
 �ZŠZ‰\Œ\×ÒÑ!Ô!ˆØŒm×!Ò!Ñ#Ô#ˆØ•”ÐÐ ¥q¤zÐ 1Ð 1Ø�4à˜’9Ðr   c                 óR   — |                       ¦   «         o|                      ¦   «         S )z5
        Check if `self` is an isomorphism.

        )rc   rg   rA   s    r   Úis_isomorphismz GroupHomomorphism.is_isomorphismÐ   s'   € ð
 × Ò Ñ"Ô"Ð; t×'9Ò'9Ñ';Ô';Ð;r   c                 óV   — |                       ¦   «                              ¦   «         dk    S )zs
        Check is `self` is a trivial homomorphism, i.e. all elements
        are mapped to the identity.

        rb   )r   rE   rA   s    r   Ú
is_trivialzGroupHomomorphism.is_trivial×   s#   € ð �zŠz‰|Œ|×!Ò!Ñ#Ô# qÒ(Ð(r   c                 óÚ   ‡ ‡— ‰                      ¦   «                              ‰ j        ¦  «        st          d¦  «        ‚ˆˆ fd„‰j        D ¦   «         }t          ‰j        ‰ j        |¦  «        S )z°
        Return the composition of `self` and `other`, i.e.
        the homomorphism phi such that for all g in the domain
        of `other`, phi(g) = self(other(g))

        z?The image of `other` must be a subgroup of the domain of `self`c                 ó:   •— i | ]}| ‰ ‰|¦  «        ¦  «        “ŒS r2   r2   )r5   r(   Úotherr   s     €€r   ú
<dictcomp>z-GroupHomomorphism.compose.<locals>.<dictcomp>é   s+   ø€ Ð:Ð:Ð:¨�!�T�T˜%˜% ™(œ(‘^”^Ð:Ð:Ð:r   )r   Úis_subgroupr   rX   r   r   r   )r   rn   r   s   `` r   ÚcomposezGroupHomomorphism.composeß   sq   øø€ ð �{Š{‰}Œ}×(Ò(¨¬Ñ5Ô5ð 	,Ýð +ñ ,ô ,ð ,à:Ð:Ð:Ð:Ð:¨U¬\Ð:Ñ:Ô:ˆÝ  ¤¨t¬}¸fÑEÔEÐEr   c                 óÖ   ‡ — t          |t          ¦  «        r|                     ‰ j        ¦  «        st	          d¦  «        ‚|}ˆ fd„|j        D ¦   «         }t          |‰ j        |¦  «        S )zh
        Return the restriction of the homomorphism to the subgroup `H`
        of the domain.

        z'Given H is not a subgroup of the domainc                 ó(   •— i | ]}| ‰|¦  «        “ŒS r2   r2   )r5   r(   r   s     €r   ro   z1GroupHomomorphism.restrict_to.<locals>.<dictcomp>õ   s#   ø€ Ð3Ð3Ð3 �!�T�T˜!‘W”WÐ3Ð3Ð3r   )r   r   rp   r   rX   r!   r   r   )r   ÚHr   r   s   `   r   Úrestrict_tozGroupHomomorphism.restrict_toì   sr   ø€ õ ˜!Õ-Ñ.Ô.ð 	H°a·m²mÀDÄKÑ6PÔ6Pð 	HÝÐFÑGÔGÐGØˆØ3Ð3Ð3Ð3 a¤lÐ3Ñ3Ô3ˆÝ  ¨¬¸Ñ?Ô?Ð?r   c                 óä  — |                      |                      ¦   «         ¦  «        st          d¦  «        ‚g }t          |                      ¦   «         j        ¦  «        }|j        D ]‰}|                      |¦  «        }||vr$|                     |¦  «         t          |¦  «        }|                      ¦   «         j        D ]0}||z  |vr'|                     ||z  ¦  «         t          |¦  «        }Œ1ŒŠ|S )z†
        Return the subgroup of the domain that is the inverse image
        of the subgroup ``H`` of the homomorphism image

        z&Given H is not a subgroup of the image)	rp   r   rX   r   r"   r!   r3   rI   rB   )r   rt   r'   ÚPÚhÚh_ir%   s          r   Úinvert_subgroupz!GroupHomomorphism.invert_subgroupø   sì   € ð �}Š}˜TŸZšZ™\œ\Ñ*Ô*ð 	GÝÐEÑFÔFÐFØˆÝ˜TŸZšZ™\œ\Ô2Ñ3Ô3ˆØ”ð 	/ð 	/ˆAØ—+’+˜a‘.”.ˆCØ˜!ˆ|ˆ|Ø—’˜CÑ Ô Ð Ý$ TÑ*Ô*�Ø—[’[‘]”]Ô-ð /ð /�Ø�S‘5 �>�>Ø—K’K  #¡Ñ&Ô&Ð&Ý(¨Ñ.Ô.�Aøð/ð ˆr   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r,   r3   rB   r@   r   rU   r`   rc   rg   ri   rk   rq   ru   rz   r2   r   r   r   r   	   s  € € € € € ðð ðð ð ð!ð !ð !ðF,/ð ,/ð ,/ð\ð ð ðð ð ð.ð ð ðð ð ð@!ð !ð !ð*ð *ð *ð
ð 
ð 
ð<ð <ð <ð)ð )ð )ðFð Fð Fð
@ð 
@ð 
@ðð ð ð ð r   r   r2   Tc                 óx  ‡‡‡— t          | t          t          t          f¦  «        st	          d¦  «        ‚t          ‰t          t          t          f¦  «        st	          d¦  «        ‚| j        Št          ˆfd„‰D ¦   «         ¦  «        st          d¦  «        ‚t          ˆfd„|D ¦   «         ¦  «        st          d¦  «        ‚|r/t          |¦  «        t          ‰¦  «        k    rt          d¦  «        ‚t          ‰¦  «        Št          |¦  «        }| 
                    ‰j        gt          ‰¦  «        t          |¦  «        z
  z  ¦  «         ‰ 
                    ˆfd„‰D ¦   «         ¦  «         t          t          ‰|¦  «        ¦  «        }|r t          | ‰|¦  «        st          d	¦  «        ‚t          | ‰|¦  «        S )
aŠ  
    Create (if possible) a group homomorphism from the group ``domain``
    to the group ``codomain`` defined by the images of the domain's
    generators ``gens``. ``gens`` and ``images`` can be either lists or tuples
    of equal sizes. If ``gens`` is a proper subset of the group's generators,
    the unspecified generators will be mapped to the identity. If the
    images are not specified, a trivial homomorphism will be created.

    If the given images of the generators do not define a homomorphism,
    an exception is raised.

    If ``check`` is ``False``, do not check whether the given images actually
    define a homomorphism.

    zThe domain must be a groupzThe codomain must be a groupc              3   ó    •K  — | ]}|‰v V — Œ	d S r   r2   )r5   r(   r!   s     €r   ú	<genexpr>zhomomorphism.<locals>.<genexpr>#  s'   øè è € Ð-Ð- 1ˆq�JˆÐ-Ð-Ð-Ð-Ð-Ð-r   zCThe supplied generators must be a subset of the domain's generatorsc              3   ó    •K  — | ]}|‰v V — Œ	d S r   r2   )r5   r(   r   s     €r   r�   zhomomorphism.<locals>.<genexpr>%  s'   øè è € Ð-Ð- ˆq�Hˆ}Ð-Ð-Ð-Ð-Ð-Ð-r   z+The images must be elements of the codomainz>The number of images must be equal to the number of generatorsc                 ó   •— g | ]}|‰v¯|‘Œ	S r2   r2   )r5   r(   r'   s     €r   r7   z homomorphism.<locals>.<listcomp>/  s   ø€ Ð8Ð8Ð8�q¨!°4¨-¨-�¨-¨-¨-r   z-The given images do not define a homomorphism)r   r   r   r   Ú	TypeErrorr!   ÚallrX   r=   r   Úextendr"   ÚdictÚzipÚ_check_homomorphismr   )r   r   r'   r   Úcheckr!   s    ``  @r   Úhomomorphismr‹     sº  øøø€ õ  �fÕ/µ½)ÐDÑEÔEð 6ÝÐ4Ñ5Ô5Ð5Ý�hÕ!1µ7½IÐ FÑGÔGð 8ÝÐ6Ñ7Ô7Ð7àÔ"€JÝÐ-Ð-Ð-Ð-¨Ð-Ñ-Ô-Ñ-Ô-ð `ÝÐ^Ñ_Ô_Ð_ÝÐ-Ð-Ð-Ð- fÐ-Ñ-Ô-Ñ-Ô-ð HÝÐFÑGÔGÐGàð [•#�f‘+”+¥ T¡¤Ò*Ð*ÝÐYÑZÔZÐZå�‰:Œ:€DÝ�&‰\Œ\€Fà
‡M‚M�8Ô$Ð%¥s¨:¡¤µs¸6±{´{Ñ'BÑCÑDÔDÐDØ‡K‚KÐ8Ð8Ð8Ð8˜JÐ8Ñ8Ô8Ñ9Ô9Ð9Ý•#�d˜6Ñ"Ô"Ñ#Ô#€Fàð JÕ(¨°¸6ÑBÔBð JÝÐHÑIÔIÐIÝ˜V X¨vÑ6Ô6Ð6r   c                 ó  ‡‡‡— t          | d¦  «        r| n|                      ¦   «         }|j        }|j        }d„ |D ¦   «         }t	          t          || j        ¦  «        ¦  «        Š|j        Šˆˆˆfd„}|D ]”}t          |t          ¦  «        rh| 	                     ||¦  «        ‰¦  «        }	|	€F| 
                    ¦   «         }
| 	                     ||¦  «        ‰¦  «        }	|	€|
st          d¦  «        ‚n ||¦  «        j        }	|	s dS Œ•dS )a]  
    Check that a given mapping of generators to images defines a homomorphism.

    Parameters
    ==========
    domain : PermutationGroup, FpGroup, FreeGroup
    codomain : PermutationGroup, FpGroup, FreeGroup
    images : dict
        The set of keys must be equal to domain.generators.
        The values must be elements of the codomain.

    Úrelatorsc                 ó(   — g | ]}|j         d          ‘ŒS )r   )Úext_rep)r5   r(   s     r   r7   z'_check_homomorphism.<locals>.<listcomp>F  s   € Ð*Ð*Ð* ˆqŒy˜Œ|Ð*Ð*Ð*r   c                 óR   •— ‰}| j         D ]\  }}‰|         }|‰|         |z  z  }Œ|S r   )rY   )rM   r)   ÚsymbolÚpowerr(   r"   r   Úsymbols_to_domain_generatorss        €€€r   r   z#_check_homomorphism.<locals>._imageJ  sA   ø€ ØˆØœ\ð 	"ð 	"‰MˆF�EØ,¨VÔ4ˆAØ�˜”˜EÑ!Ñ!ˆAˆAØˆr   NzÖCan't determine if the images define a homomorphism. Try increasing the maximum number of rewriting rules (group._rewriting_system.set_max(new_value); the current value is stored in group._rewriting_system.maxeqns)FT)ÚhasattrÚpresentationr�   r!   r‡   rˆ   r"   r   r   ÚequalsÚmake_confluentÚRuntimeErrorr   )r   r   r   ÚpresÚrelsr'   Úsymbolsr   rM   r+   Úsuccessr"   r“   s     `        @@r   r‰   r‰   6  sO  øøø€ õ ˜V ZÑ0Ô0ÐKˆ6ˆ6°f×6IÒ6IÑ6KÔ6K€DØŒ=€DØŒ?€DØ*Ð* TÐ*Ñ*Ô*€GÝ#'­¨G°VÔ5FÑ(GÔ(GÑ#HÔ#HÐ ØÔ €Hðð ð ð ð ð ð ð ð ð ˆÝ�h¥Ñ(Ô(ð 	&Ø—’   q¡	¤	¨8Ñ4Ô4ˆAØˆyð #×1Ò1Ñ3Ô3�Ø—O’O F F¨1¡I¤I¨xÑ8Ô8�Ø�9 W�9Ý&ð (+ñ ,ô ,ð ,øð ��q‘	”	Ô%ˆAØð 	Ø�5�5ð	àˆ4r   c                 ó¶  ‡‡‡— ddl mŠ ddlm}  |t	          ‰¦  «        ¦  «        }|j        Št          ‰¦  «        Šˆˆˆfd„| j        D ¦   «         }|                      ‰¬¦  «         t          | ||¦  «        }t	          | j
        ¦  «        t	          ‰¦  «        k    r | j
        t	          ‰¦  «                 |_        nt          | j        g¦  «        |_        |S )z•
    Return the homomorphism induced by the action of the permutation
    group ``group`` on the set ``omega`` that is closed under the action.

    r   r.   ©ÚSymmetricGroupc                 óJ   •‡— i | ]Š‰‰ ‰ˆˆfd „‰D ¦   «         ¦  «        z  “ŒS )c                 ó@   •— g | ]}‰                      |‰z  ¦  «        ‘ŒS r2   )Úindex)r5   Úor(   Úomegas     €€r   r7   z1orbit_homomorphism.<locals>.<dictcomp>.<listcomp>r  s)   ø€ Ð&GÐ&GÐ&G¸A u§{¢{°1°Q±3Ñ'7Ô'7Ð&GÐ&GÐ&Gr   r2   )r5   r(   r/   r"   r¤   s    @€€€r   ro   z&orbit_homomorphism.<locals>.<dictcomp>r  sC   øø€ ÐcÐcÐcÈQˆa�˜+˜+Ð&GÐ&GÐ&GÐ&GÐ&GÀÐ&GÑ&GÔ&GÑHÔHÑHÐcÐcÐcr   )Úbase)r8   r/   Ú sympy.combinatorics.named_groupsrŸ   r=   r"   r   r!   Ú_schreier_simsr   Úbasic_stabilizersr   r   )Úgroupr¤   rŸ   r   r   rt   r/   r"   s    `    @@r   Úorbit_homomorphismrª   g  sê   øøø€ ð 0Ð/Ð/Ð/Ð/Ð/Ø?Ð?Ð?Ð?Ð?Ð?Øˆ~�c %™jœjÑ)Ô)€HØÔ €HÝ�‰KŒK€EØcÐcÐcÐcÐcÐcÐRWÔRbÐcÑcÔc€FØ	×Ò˜eÐÑ$Ô$Ð$Ý˜% ¨6Ñ2Ô2€AÝ
ˆ5Ô"Ñ#Ô#¥c¨%¡j¤jÒ0Ð0ØÔ+­C°©J¬JÔ7ˆŒ	ˆ	å$ e¤nÐ%5Ñ6Ô6ˆŒ	Ø€Hr   c                 óš  ‡	‡
‡‡— ddl mŠ	 ddlm} t	          |¦  «        }d}g Šdg|z  Š
t          |¦  «        D ]-}||         |k    r‰                     |¦  «         |‰
|<   |dz  }Œ.t          |¦  «        D ]}‰
||                  ‰
|<   Œ ||¦  «        }t          |¦  «        Šˆ	ˆ
ˆˆfd„| j        D ¦   «         }t          | ||¦  «        }|S )ab  
    Return the homomorphism induced by the action of the permutation
    group ``group`` on the block system ``blocks``. The latter should be
    of the same form as returned by the ``minimal_block`` method for
    permutation groups, namely a list of length ``group.degree`` where
    the i-th entry is a representative of the block i belongs to.

    r   r.   rž   Nrb   c                 óF   •‡— i | ]Š‰ ‰ˆˆˆfd „‰D ¦   «         ¦  «        “ŒS )c                 ó2   •— g | ]}‰‰|         ‰z           ‘ŒS r2   r2   )r5   r>   Úbr(   r^   s     €€€r   r7   z1block_homomorphism.<locals>.<dictcomp>.<listcomp>›  s%   ø€ Ð:Ð:Ð:¨A˜a  !¤ Q¡œiÐ:Ð:Ð:r   r2   )r5   r(   r/   r®   r"   r^   s    @€€€€r   ro   z&block_homomorphism.<locals>.<dictcomp>›  sA   øø€ ÐVÐVÐVÀˆa��Ð:Ð:Ð:Ð:Ð:Ð:°Ð:Ñ:Ô:Ñ;Ô;ÐVÐVÐVr   )	r8   r/   r¦   rŸ   r=   r<   rI   r!   r   )r©   ÚblocksrŸ   ÚnÚmr>   r   r   rt   r/   r®   r"   r^   s            @@@@r   Úblock_homomorphismr²   {  s  øøøø€ ð 0Ð/Ð/Ð/Ð/Ð/Ø?Ð?Ð?Ð?Ð?Ð?åˆF‰Œ€Að 	
€AØ
€AØ	ˆˆq‰€AÝ�1‰XŒXð ð ˆØ�!Œ9˜Š>ˆ>Ø�HŠH�Q‰KŒKˆKØˆAˆa‰DØ�‰FˆAøÝ�1‰XŒXð ð ˆØ�˜”Œ|ˆˆ!‰ˆàˆ~˜aÑ Ô €Hå�Q‰xŒx€HØVÐVÐVÐVÐVÐVÐVÀUÔEUÐVÑVÔV€FÝ˜% ¨6Ñ2Ô2€AØ€Hr   c                 óì  — t          | t          t          f¦  «        st          d¦  «        ‚t          |t          t          f¦  «        st          d¦  «        ‚t          | t          ¦  «        r™t          |t          ¦  «        r„t	          | ¦  «        } t	          |¦  «        }| j        |j        k    rV| j                             ¦   «         |j                             ¦   «         k    r"|sdS dt          | || j        |j        ¦  «        fS |}|  	                    ¦   «         }| 	                    ¦   «         }|t          j        u rt          d¦  «        ‚t          |t          ¦  «        r4|t          j        u rt          d¦  «        ‚|                     ¦   «         \  }}||k    s| j        |j        k    r|sdS dS |s%|}t          |t!          |¦  «        ¦  «        dk    rdS t#          | j        ¦  «        }t%          j        |t)          |¦  «        ¦  «        D ]á}	t#          |	¦  «        }
|
                     |j        gt)          | j        ¦  «        t)          |
¦  «        z
  z  ¦  «         t/          t1          ||
¦  «        ¦  «        }t3          | ||¦  «        rbt          |t          ¦  «        r|                     |
¦  «        }
t          | || j        |
d¬¦  «        }|                     ¦   «         r|s dS d|fc S Œâ|sdS dS )aE  
    Compute an isomorphism between 2 given groups.

    Parameters
    ==========

    G : A finite ``FpGroup`` or a ``PermutationGroup``.
        First group.

    H : A finite ``FpGroup`` or a ``PermutationGroup``
        Second group.

    isomorphism : bool
        This is used to avoid the computation of homomorphism
        when the user only wants to check if there exists
        an isomorphism between the groups.

    Returns
    =======

    If isomorphism = False -- Returns a boolean.
    If isomorphism = True  -- Returns a boolean and an isomorphism between `G` and `H`.

    Examples
    ========

    >>> from sympy.combinatorics import free_group, Permutation
    >>> from sympy.combinatorics.perm_groups import PermutationGroup
    >>> from sympy.combinatorics.fp_groups import FpGroup
    >>> from sympy.combinatorics.homomorphisms import group_isomorphism
    >>> from sympy.combinatorics.named_groups import DihedralGroup, AlternatingGroup

    >>> D = DihedralGroup(8)
    >>> p = Permutation(0, 1, 2, 3, 4, 5, 6, 7)
    >>> P = PermutationGroup(p)
    >>> group_isomorphism(D, P)
    (False, None)

    >>> F, a, b = free_group("a, b")
    >>> G = FpGroup(F, [a**3, b**3, (a*b)**2])
    >>> H = AlternatingGroup(4)
    >>> (check, T) = group_isomorphism(G, H)
    >>> check
    True
    >>> T(b*a*b**-1*a**-1*b**-1)
    (0 2 3)

    Notes
    =====

    Uses the approach suggested by Robert Tarjan to compute the isomorphism between two groups.
    First, the generators of ``G`` are mapped to the elements of ``H`` and
    we check if the mapping induces an isomorphism.

    z2The group must be a PermutationGroup or an FpGroupTz<Isomorphism methods are not implemented for infinite groups.F)FNrb   )rŠ   )r   r   r   r„   r   r!   r�   Úsortr‹   rE   r
   rF   rG   Ú_to_perm_groupÚ
is_abelianr   r	   r   Ú	itertoolsÚpermutationsr=   r†   r"   r‡   rˆ   r‰   r3   ri   )rJ   rt   ÚisomorphismÚ_HÚg_orderÚh_orderÚh_isomorphismr°   r'   Úsubsetr   Ú_imagesÚTs                r   Úgroup_isomorphismrÁ   Ÿ  sî  € õp �aÕ*­GÐ4Ñ5Ô5ð NÝÐLÑMÔMÐMÝ�aÕ*­GÐ4Ñ5Ô5ð NÝÐLÑMÔMÐMå�!•WÑÔð J¥*¨QµÑ"8Ô"8ð JÝ! !Ñ$Ô$ˆÝ! !Ñ$Ô$ˆð Œ<˜1œ<Ò'Ð'¨Q¬Z×,=Ò,=Ñ,?Ô,?ÀAÄJ×CTÒCTÑCVÔCVÒ,VÐ,VØð Ø�tØ�, q¨!¨Q¬\¸1¼<ÑHÔHÐIÐIð 
€BØ�gŠg‰iŒi€GØ�gŠg‰iŒi€Gà•!”*ÐÐÝ!Ð"`ÑaÔaÐaå�!•WÑÔð /Ø•a”jÐ Ð Ý%Ð&dÑeÔeÐeØ×,Ò,Ñ.Ô.ÑˆˆMà�7ÒÐ ¤°´Ò <Ð <Øð 	Ø�5Øˆ}àð ð ˆÝ�•G˜A‘J”JÑÔ AÒ%Ð%Ø�4õ �”ÑÔ€DÝÔ(¨­S°©Y¬YÑ7Ô7ð !ð !ˆÝ�f‘”ˆØ�Š�r”{�m¥S¨¬Ñ%6Ô%6µs¸6±{´{Ñ%BÑCÑDÔDÐDÝ•s˜4 Ñ'Ô'Ñ(Ô(ˆÝ˜q " gÑ.Ô.ð 	!Ý˜!�WÑ%Ô%ð 6Ø&×-Ò-¨fÑ5Ô5�Ý˜a  A¤L°&ÀÐFÑFÔFˆAØ×ÒÑ!Ô!ð !à"ð  Ø˜4˜4Ø˜a�yÐ Ð Ð øàð ØˆuØˆ=r   c                 ó&   — t          | |d¬¦  «        S )a  
    Check if the groups are isomorphic to each other

    Parameters
    ==========

    G : A finite ``FpGroup`` or a ``PermutationGroup``
        First group.

    H : A finite ``FpGroup`` or a ``PermutationGroup``
        Second group.

    Returns
    =======

    boolean
    F)r¹   )rÁ   )rJ   rt   s     r   Úis_isomorphicrÃ     s   € õ$ ˜Q ¨uÐ5Ñ5Ô5Ð5r   )r2   T)T)r·   Úsympy.combinatorics.fp_groupsr   r   r   r9   r   Úsympy.combinatorics.perm_groupsr   Úsympy.core.intfuncr   Ú%sympy.functions.combinatorial.numbersr	   Úsympy.core.singletonr
   r   r‹   r‰   rª   r²   rÁ   rÃ   r2   r   r   ú<module>rÉ      s0  ðØ Ð Ð Ð Ø TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TØ 5Ð 5Ð 5Ð 5Ð 5Ð 5Ø <Ð <Ð <Ð <Ð <Ð <Ø #Ð #Ð #Ð #Ð #Ð #Ø 9Ð 9Ð 9Ð 9Ð 9Ð 9Ø "Ð "Ð "Ð "Ð "Ð "ðBð Bð Bð Bð Bñ Bô Bð BðH'7ð '7ð '7ð '7ðR/ð /ð /ðbð ð ð("ð "ð "ðHrð rð rð rðh6ð 6ð 6ð 6ð 6r   