+
    iI                         ^ RI t ^ RIHtHtHt ^ RIHt ^ RIHt ^ RI	H
t
 ^ RIHt ^ RIHt  ! R R	4      tRR
 ltR tR tR tRR ltR tR# )    N)FpGroup
FpSubgroupsimplify_presentation)	FreeGroup)PermutationGroup)igcd)totient)Sc                   ~   a  ] tR t^	t o RtR tR tR tR tR t	R t
R tR	 tR
 tR tR tR tR tR tR tRtV tR# )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                T    Wn         W n        W0n        R V n        R V n        R V n        R # N)domaincodomainimages	_inverses_kernel_image)selfr   r   r   s   &&&&_/var/www/html/photoedit/myenv/lib/python3.14/site-packages/sympy/combinatorics/homomorphisms.py__init__GroupHomomorphism.__init__   s&         c                   V P                  4       p/ p\        V P                  P                  4       4       F6  pV P                  V,          pWB9   d   K  VP                  '       d   K2  W2V&   K8  	  \        V P                  \        4      '       d   VP                  pMVP                  pV F  pWb9   g   VP                  '       d   K  V P                  P                  p\        V P                  \        4      '       d   VP                  V,          RRR1,          pMTpV F7  p	W9   d   WrV	,          ,          pK  WrV	R,          ,          R,          ,          pK9  	  WrV&   K  	  V# )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   _invsGroupHomomorphism._invs   s    

dkk&&()AAAM}}}	 *
 dmm%566$$D##DA}$$A$--)9::..q1$B$7=1+A1b5/2--A	 
 QK  r   c                V   ^ RI Hp ^ RIHp \	        WV34      '       EdN   \	        V P
                  \        4      '       d   V P
                  P                  V4      pV P                  f   V P                  4       V n        V P                  4       pV P                  P                  p\	        V P
                  \        4      '       d   VP                  V4      RRR1,          pMTp\        \!        V4      4       Fq  pWg,          pVP"                  '       d   K  WP                  9   d   WPP                  V,          ,          pKJ  WPP                  VR,          ,          R,          ,          pKs  	  V# \	        V\$        4      '       d!   V U	u. uF  qP'                  V	4      NK  	  up	# R# u up	i )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.

Permutation)FreeGroupElementNr   )sympy.combinatoricsr1   sympy.combinatorics.free_groupsr2   r    r   r   reducer   r-   r   r   r#   r   generator_productrangelenr   r   invert)
r   r)   r1   r2   r   r*   r(   ir,   es
   &&        r   r9   GroupHomomorphism.invert?   s5    	4Da'7899$--11MM((+~~%!%JJLE$$A$--)9::..q1$B$7 3t9%G===&..++A..B/33A & H4  ,-.AqKKNA.. !.s   F&c                `    V P                   f   V P                  4       V n         V P                   # )z 
Compute the kernel of `self`.

)r   _compute_kernelr   s   &r   kernelGroupHomomorphism.kernelm   s(    
 <<//1DL||r   c                d   V P                   pVP                  4       pV\        P                  J d   \	        R 4      h. p\        V\        4      '       d   \        VP                  4      pM\        WRR7      pV P                  4       P                  4       pVP                  4       V,          V8w  d   VP                  4       pW`P                  V ! V4      4      R,          ,          pWt9  g   KX  VP                  V4       \        V\        4      '       d   \        V4      pK  \        WRR7      pK  V# )z9Kernel computation is not implemented for infinite groupsT)normalr   )r   orderr
   InfinityNotImplementedErrorr    r   r#   r   r   randomr9   append)r   GG_orderr(   Kr:   rr&   s   &       r   r>   !GroupHomomorphism._compute_kernelv   s    KK'')ajj %KM Ma)** ,A140AJJL ggikW$
A++d1g&**AzAa!122(.A"148Ar   c                \   V P                   f   \        \        V P                  P	                  4       4      4      p\        V P                  \        4      '       d-   V P                  P                  V4      V n         V P                   # \        V P                  V4      V n         V P                   # )z
Compute the image of `self`.

)
r   r   setr   valuesr    r   r   subgroupr   )r   rP   s   & r   r   GroupHomomorphism.image   s|    
 ;;#dkk00234F$--)9::"mm44V< {{ )?{{r   c                   WP                   9  dH   \        V\        \        34      '       d!   V Uu. uF  q P	                  V4      NK  	  up# \        R4      hVP                  '       d   V P                  P                  # V P                  pV P                  P                  p\        V P                   \        4      '       dg   V P                   P                  VRR7      pV FA  pW`P                  9   d   W6,          V,          pK$  W6R,          ,          R,          V,          pKC  	  V# ^ pVP                   FL  w  rV	^ 8  d   W,          R,          pMW,          pWCV,          V	,          ,          pV\        V	4      ,          pKN  	  V# u upi )z
Apply `self` to `elem`.

z2The supplied element does not belong to the domainT)originalr   )r   r    r   tuple_apply
ValueErrorr   r   r#   r   r   r6   
array_formabs)
r   elemr;   r   valuer(   r)   r:   _ps
   &&        r   rV   GroupHomomorphism._apply   s9   
 {{"$u..0451A55QRR==)))[[FMM**E$++'788{{44TD4IAKK' &	% &"ur 1% 7	    OODA1u GRK G!)Q,.EQKA , / 6s   Fc                $    V P                  V4      # r   )rV   )r   rZ   s   &&r   __call__GroupHomomorphism.__call__   s    {{4  r   c                D    V P                  4       P                  4       ^8H  # )z)
Check if the homomorphism is injective

)r@   rD   r?   s   &r   is_injectiveGroupHomomorphism.is_injective   s    
 {{}""$))r   c                    V P                  4       P                  4       pV P                  P                  4       pV\        P                  J d   V\        P                  J d   R# W8H  # )z*
Check if the homomorphism is surjective

N)r   rD   r   r
   rE   )r   imoths   &  r   is_surjectiveGroupHomomorphism.is_surjective   sL    
 ZZ\!mm!!#qzz 19r   c                R    V P                  4       ;'       d    V P                  4       # )z%
Check if `self` is an isomorphism.

)rc   rh   r?   s   &r   is_isomorphism GroupHomomorphism.is_isomorphism   s$    
   ";;t'9'9';;r   c                D    V P                  4       P                  4       ^8H  # )z[
Check is `self` is a trivial homomorphism, i.e. all elements
are mapped to the identity.

)r   rD   r?   s   &r   
is_trivialGroupHomomorphism.is_trivial   s     zz|!!#q((r   c           	        VP                  4       P                  V P                  4      '       g   \        R4      hVP                   Uu/ uF  q"V ! V! V4      4      bK  	  pp\        VP                  V P                  V4      # u upi )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`)r   is_subgroupr   rW   r   r   r   )r   otherr)   r   s   &&  r   composeGroupHomomorphism.compose   sp     {{}((55 + , ,-2\\:\T%(^#\: t}}fEE ;s   	Bc                   \        V\        4      '       d"   VP                  V P                  4      '       g   \	        R4      hTpVP
                   Uu/ uF  q3V ! V4      bK  	  pp\        W P                  V4      # u upi )zP
Return the restriction of the homomorphism to the subgroup `H`
of the domain.

z'Given H is not a subgroup of the domain)r    r   rq   r   rW   r"   r   r   )r   Hr   r)   r   s   &&   r   restrict_toGroupHomomorphism.restrict_to   si     !-..ammDKK6P6PFGG&'ll3lT!W*l3 ?? 4s   A<c                   VP                  V P                  4       4      '       g   \        R4      h. p\        V P                  4       P                  4      pVP
                   F  pV P                  V4      pWS9  d   VP                  V4       \        V4      pV P                  4       P
                   F4  pWe,          V9  g   K  VP                  We,          4       \        V4      pK6  	  K  	  V# )zn
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)	rq   r   rW   r   r#   r"   r9   rH   r@   )r   rv   r(   Phh_ir&   s   &&     r   invert_subgroup!GroupHomomorphism.invert_subgroup   s     }}TZZ\**EFFTZZ\223A++a.C|C $T*[[]--5>KK&(.A .  r   )r   r   r   r   r   r   N)__name__
__module____qualname____firstlineno____doc__r   r-   r9   r@   r>   r   rV   r`   rc   rh   rk   rn   rs   rw   r}   __static_attributes____classdictcell__)__classdict__s   @r   r   r   	   s_     !F,/\.@!*
<)F
@ r   r   c                  aa \        V \        \        \        34      '       g   \	        R4      h\        S\        \        \        34      '       g   \	        R4      hV P
                  o\        ;QJ d    V3R lV 4       F  '       d   K   RM	  RM! V3R lV 4       4      '       g   \        R4      h\        ;QJ d    V3R lV 4       F  '       d   K   RM	  RM! V3R lV 4       4      '       g   \        R4      hV'       d%   \        V4      \        V4      8w  d   \        R	4      h\        V4      p\        V4      pVP                  SP                  .\        S4      \        V4      ,
          ,          4       TP                  S Uu. uF  qUV9  g   K  VNK  	  up4       \        \        W#4      4      pV'       d   \        V SV4      '       g   \        R
4      h\        V SV4      # u upi )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   ,   <"   T F	  qS9   x  K  	  R # 5ir    ).0r)   r"   s   & r   	<genexpr>homomorphism.<locals>.<genexpr>#  s     -1J   FTzCThe supplied generators must be a subset of the domain's generatorsc              3   ,   <"   T F	  qS9   x  K  	  R # 5ir   r   )r   r)   r   s   & r   r   r   %  s     -fH}fr   z+The images must be elements of the codomainz>The number of images must be equal to the number of generatorsz-The given images do not define a homomorphism)r    r   r   r   	TypeErrorr"   allrW   r8   r   extendr#   dictzip_check_homomorphismr   )r   r   r(   r   checkr)   r"   s   &f&&& @r   homomorphismr     se     f/)DEE455h!17I FGG677""J3--333----^__3-f-333-f---FGG#f+T*YZZ:D&\F
MM8$$%s:s6{'BCDKKJ8Jq4-J89#d"#F(6BBHIIVXv66 9s   
G+G+c                d  aaa \        V R4      '       d   T MV P                  4       pVP                  pVP                  pV Uu. uF  qfP                  ^ ,          NK  	  pp\        \        WpP                  4      4      oVP                  oVVV3R lpV F  p	\        V\        4      '       d]   VP                  V! V	4      S4      p
V
f@   VP                  4       pVP                  V! V	4      S4      p
V
f   V'       g   \        R4      hMV! V	4      P                  p
V
'       d   K   R# 	  R# u upi )a9  
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                 v   < SpV P                    F%  w  r#SV,          pVSV,          V,          ,          pK'  	  V# r   )rX   )rL   r*   symbolpowerr)   r#   r   symbols_to_domain_generatorss   &    r   r   #_check_homomorphism.<locals>._imageJ  s<    \\MF,V4AE!!A * r   zCan'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"   ext_repr   r   r#   r    r   equalsmake_confluentRuntimeErrorr   )r   r   r   presrelsr(   r)   symbolsr   rL   r,   successr#   r   s   &&f         @@r   r   r   6  s    VZ006f6I6I6KD==D??D%)*Tyy||TG*#'G5F5F(G#H   H h((q	84Ay #113OOF1Ix89W& (+ , , q	%%Aq' ( ? +s   D-c                   ^ RI Hp ^ RIHp V! \	        V4      4      pVP
                  p\        V4      pV P                   UUu/ uF5  qfYR! V Uu. uF  qqP                  Wv,          4      NK  	  up4      ,          bK7  	  pppV P                  VR7       \        WV4      p	\	        V P                  4      \	        V4      8  d$   V P                  \	        V4      ,          V	n        V	# \        V P
                  .4      V	n        V	# u upi u uppi )z
Return the homomorphism induced by the action of the permutation
group ``group`` on the set ``omega`` that is closed under the action.

r0   SymmetricGroup)base)r3   r1    sympy.combinatorics.named_groupsr   r8   r#   r   r"   index_schreier_simsr   basic_stabilizersr   r   )
groupomegar1   r   r   r#   r)   or   rv   s
   &&        r   orbit_homomorphismr   g  s     0?c%j)H  HKERWRbRbcRbQ+&GA{{13'7&GHHHRbFc	e$%62A
5""#c%j0++CJ7	 H %enn%56	H 'Hcs   DD.DDc                   ^ RI Hp ^ RIHp \	        V4      p^ p. pR.V,          p\        V4       F0  pW,          V8X  g   K  VP                  V4       WWV&   V^,          pK2  	  \        V4       F  pWqV,          ,          Wx&   K  	  V! V4      p	\        V4      p
V P                   UUu/ uF.  qT! V
 Uu. uF  qWh,          V,          ,          NK  	  up4      bK0  	  ppp\        W	V4      pV# u upi u uppi )aJ  
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.

r0   r   N)	r3   r1   r   r   r8   r7   rH   r"   r   )r   blocksr1   r   nmr]   br:   r   r#   r)   r   rv   s   &&            r   block_homomorphismr   {  s     0?FA 	
A
A	qA1X9>HHQKaDFA	 
 1X|  a HQxHEJEUEUVEU:AQii:;;EUFV%62AH ;Vs   *C45C/C4/C4c           	     &   \        V \        \        34      '       g   \        R4      h\        V\        \        34      '       g   \        R4      h\        V \        4      '       d   \        V\        4      '       d   \	        V 4      p \	        V4      pV P
                  VP
                  8X  de   V P                  P                  4       VP                  P                  4       8X  d.   V'       g   R# R\        WV P
                  VP
                  4      3# TpV P                  4       pVP                  4       pV\        P                  J d   \        R4      h\        V\        4      '       d2   V\        P                  J d   \        R4      hVP                  4       w  r6WE8w  g   V P                  VP                  8w  d   V'       g   R# R# V'       g   Tp\        V\!        V4      4      ^8X  d   R# \#        V P
                  4      p\$        P&                  ! V\)        V4      4       F  p	\#        V	4      p
V
P+                  VP,                  .\)        V P
                  4      \)        V
4      ,
          ,          4       \/        \1        W4      4      p\3        WV4      '       g   K|  \        V\        4      '       d   XP5                  V
4      p
\        WV P
                  V
RR7      pVP7                  4       '       g   K  V'       g    R# RV3u # 	  V'       g   R# R# )a  
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)r   )FN)r    r   r   r   r   r"   r   sortr   rD   r
   rE   rF   _to_perm_group
is_abelianr   r	   r   	itertoolspermutationsr8   r   r#   r   r   r   r9   rk   )rI   rv   isomorphism_Hg_orderh_orderh_isomorphismr   r(   subsetr   _imagesTs   &&&          r   group_isomorphismr     sH   p a*G455LMMa*G455LMM!W*Q"8"8!!$!!$ <<1<<'QZZ,=,=,?AJJCTCTCV,V,qQ\\1<<HII 
BggiGggiG!**!"`aa!Wajj %&dee,,. < GAJA% D((SY7fr{{mS%6s6{%BCDs4'(qg..!W%%&--f5aALL&FA!!"ay  8 r   c                    \        WRR7      # )z
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   )rI   rv   s   &&r   is_isomorphicr     s    $ Qu55r   )r   T)T)r   sympy.combinatorics.fp_groupsr   r   r   r4   r   sympy.combinatorics.perm_groupsr   sympy.core.intfuncr   %sympy.functions.combinatorial.numbersr	   sympy.core.singletonr
   r   r   r   r   r   r   r   r   r   r   <module>r      sM     T T 5 < # 9 "B BH'7R/b("Hrh6r   