Ë
    7^(h±U  ã                   óŒ   — d Z ddlmZmZmZmZmZ ddlmZ  G d„ d«      Z	 G d„ de	«      Z
 G d„ d	e
«      Z G d
„ de
«      Zd„ Zy)a   
Computations with homomorphisms of modules and rings.

This module implements classes for representing homomorphisms of rings and
their modules. Instead of instantiating the classes directly, you should use
the function ``homomorphism(from, to, matrix)`` to create homomorphism objects.
é    )ÚModuleÚ
FreeModuleÚQuotientModuleÚ	SubModuleÚSubQuotientModule)ÚCoercionFailedc                   óÂ   — 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„ Zd„ Zd„ Zd„ Zd„ ZeZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z d„ Z!y) ÚModuleHomomorphisma"  
    Abstract base class for module homomoprhisms. Do not instantiate.

    Instead, use the ``homomorphism`` function:

    >>> from sympy import QQ
    >>> from sympy.abc import x
    >>> from sympy.polys.agca import homomorphism

    >>> F = QQ.old_poly_ring(x).free_module(2)
    >>> homomorphism(F, F, [[1, 0], [0, 1]])
    Matrix([
    [1, 0], : QQ[x]**2 -> QQ[x]**2
    [0, 1]])

    Attributes:

    - ring - the ring over which we are considering modules
    - domain - the domain module
    - codomain - the codomain module
    - _ker - cached kernel
    - _img - cached image

    Non-implemented methods:

    - _kernel
    - _image
    - _restrict_domain
    - _restrict_codomain
    - _quotient_domain
    - _quotient_codomain
    - _apply
    - _mul_scalar
    - _compose
    - _add
    c                 ó*  — t        |t        «      st        d|z  «      ‚t        |t        «      st        d|z  «      ‚|j                  |j                  k7  rt	        d|›d|›�«      ‚|| _        || _        |j                  | _        d | _        d | _        y )NzSource must be a module, got %szTarget must be a module, got %sz0Source and codomain must be over same ring, got z != )	Ú
isinstancer   Ú	TypeErrorÚringÚ
ValueErrorÚdomainÚcodomainÚ_kerÚ_img)Úselfr   r   s      ú\/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/sympy/polys/agca/homomorphisms.pyÚ__init__zModuleHomomorphism.__init__8   s‰   € Ü˜&¤&Ô)ÜÐ=ÀÑFÓGÐGÜ˜(¤FÔ+ÜÐ=ÀÑHÓIÐIØ�;‰;˜(Ÿ-™-Ò'ÝÚ/5±xðAó Bð BàˆŒØ ˆŒØ—K‘KˆŒ	ØˆŒ	Øˆ�	ó    c                 ó\   — | j                   €| j                  «       | _         | j                   S )aî  
        Compute the kernel of ``self``.

        That is, if ``self`` is the homomorphism `\phi: M \to N`, then compute
        `ker(\phi) = \{x \in M | \phi(x) = 0\}`.  This is a submodule of `M`.

        Examples
        ========

        >>> from sympy import QQ
        >>> from sympy.abc import x
        >>> from sympy.polys.agca import homomorphism

        >>> F = QQ.old_poly_ring(x).free_module(2)
        >>> homomorphism(F, F, [[1, 0], [x, 0]]).kernel()
        <[x, -1]>
        )r   Ú_kernel©r   s    r   ÚkernelzModuleHomomorphism.kernelF   s%   € ð$ �9‰9ÐØŸ™›ˆDŒIØ�y‰yÐr   c                 ó\   — | j                   €| j                  «       | _         | j                   S )aú  
        Compute the image of ``self``.

        That is, if ``self`` is the homomorphism `\phi: M \to N`, then compute
        `im(\phi) = \{\phi(x) | x \in M \}`.  This is a submodule of `N`.

        Examples
        ========

        >>> from sympy import QQ
        >>> from sympy.abc import x
        >>> from sympy.polys.agca import homomorphism

        >>> F = QQ.old_poly_ring(x).free_module(2)
        >>> homomorphism(F, F, [[1, 0], [x, 0]]).image() == F.submodule([1, 0])
        True
        )r   Ú_imager   s    r   ÚimagezModuleHomomorphism.image\   s%   € ð$ �9‰9ÐØŸ™›ˆDŒIØ�y‰yÐr   c                 ó   — t         ‚)zCompute the kernel of ``self``.©ÚNotImplementedErrorr   s    r   r   zModuleHomomorphism._kernelr   ó   € ä!Ð!r   c                 ó   — t         ‚)zCompute the image of ``self``.r    r   s    r   r   zModuleHomomorphism._imagev   r"   r   c                 ó   — t         ‚©z%Implementation of domain restriction.r    ©r   Úsms     r   Ú_restrict_domainz#ModuleHomomorphism._restrict_domainz   r"   r   c                 ó   — t         ‚©z'Implementation of codomain restriction.r    r&   s     r   Ú_restrict_codomainz%ModuleHomomorphism._restrict_codomain~   r"   r   c                 ó   — t         ‚©z"Implementation of domain quotient.r    r&   s     r   Ú_quotient_domainz#ModuleHomomorphism._quotient_domain‚   r"   r   c                 ó   — t         ‚©z$Implementation of codomain quotient.r    r&   s     r   Ú_quotient_codomainz%ModuleHomomorphism._quotient_codomain†   r"   r   c                 ó²   — | j                   j                  |«      st        d| j                   ›d|›�«      ‚|| j                   k(  r| S | j                  |«      S )a?  
        Return ``self``, with the domain restricted to ``sm``.

        Here ``sm`` has to be a submodule of ``self.domain``.

        Examples
        ========

        >>> from sympy import QQ
        >>> from sympy.abc import x
        >>> from sympy.polys.agca import homomorphism

        >>> F = QQ.old_poly_ring(x).free_module(2)
        >>> h = homomorphism(F, F, [[1, 0], [x, 0]])
        >>> h
        Matrix([
        [1, x], : QQ[x]**2 -> QQ[x]**2
        [0, 0]])
        >>> h.restrict_domain(F.submodule([1, 0]))
        Matrix([
        [1, x], : <[1, 0]> -> QQ[x]**2
        [0, 0]])

        This is the same as just composing on the right with the submodule
        inclusion:

        >>> h * F.submodule([1, 0]).inclusion_hom()
        Matrix([
        [1, x], : <[1, 0]> -> QQ[x]**2
        [0, 0]])
        zsm must be a submodule of ú, got )r   Úis_submoduler   r(   r&   s     r   Úrestrict_domainz"ModuleHomomorphism.restrict_domainŠ   sT   € ð@ �{‰{×'Ñ'¨Ô+ÝØ $§£©Rð1ó 2ð 2à�—‘ÒØˆKØ×$Ñ$ RÓ(Ð(r   c                 óÂ   — |j                  | j                  «       «      st        d| j                  «       ›d|›�«      ‚|| j                  k(  r| S | j	                  |«      S )a„  
        Return ``self``, with codomain restricted to to ``sm``.

        Here ``sm`` has to be a submodule of ``self.codomain`` containing the
        image.

        Examples
        ========

        >>> from sympy import QQ
        >>> from sympy.abc import x
        >>> from sympy.polys.agca import homomorphism

        >>> F = QQ.old_poly_ring(x).free_module(2)
        >>> h = homomorphism(F, F, [[1, 0], [x, 0]])
        >>> h
        Matrix([
        [1, x], : QQ[x]**2 -> QQ[x]**2
        [0, 0]])
        >>> h.restrict_codomain(F.submodule([1, 0]))
        Matrix([
        [1, x], : QQ[x]**2 -> <[1, 0]>
        [0, 0]])
        z
the image ú must contain sm, got )r4   r   r   r   r+   r&   s     r   Úrestrict_codomainz$ModuleHomomorphism.restrict_codomain±   sU   € ð2 �‰˜tŸz™z›|Ô,ÝØ $§
¡
¥©bð2ó 3ð 3à�—‘ÒØˆKØ×&Ñ& rÓ*Ð*r   c                 óÄ   — | j                  «       j                  |«      st        d| j                  «       ›d|›�«      ‚|j                  «       r| S | j	                  |«      S )am  
        Return ``self`` with domain replaced by ``domain/sm``.

        Here ``sm`` must be a submodule of ``self.kernel()``.

        Examples
        ========

        >>> from sympy import QQ
        >>> from sympy.abc import x
        >>> from sympy.polys.agca import homomorphism

        >>> F = QQ.old_poly_ring(x).free_module(2)
        >>> h = homomorphism(F, F, [[1, 0], [x, 0]])
        >>> h
        Matrix([
        [1, x], : QQ[x]**2 -> QQ[x]**2
        [0, 0]])
        >>> h.quotient_domain(F.submodule([-x, 1]))
        Matrix([
        [1, x], : QQ[x]**2/<[-x, 1]> -> QQ[x]**2
        [0, 0]])
        zkernel r7   )r   r4   r   Úis_zeror.   r&   s     r   Úquotient_domainz"ModuleHomomorphism.quotient_domainÑ   sT   € ð0 �{‰{‹}×)Ñ)¨"Ô-ÝØ"Ÿk™k�m©Rð1ó 2ð 2à�:‰:Œ<ØˆKØ×$Ñ$ RÓ(Ð(r   c                 ó´   — | j                   j                  |«      st        d| j                   ›d|›�«      ‚|j                  «       r| S | j	                  |«      S )a:  
        Return ``self`` with codomain replaced by ``codomain/sm``.

        Here ``sm`` must be a submodule of ``self.codomain``.

        Examples
        ========

        >>> from sympy import QQ
        >>> from sympy.abc import x
        >>> from sympy.polys.agca import homomorphism

        >>> F = QQ.old_poly_ring(x).free_module(2)
        >>> h = homomorphism(F, F, [[1, 0], [x, 0]])
        >>> h
        Matrix([
        [1, x], : QQ[x]**2 -> QQ[x]**2
        [0, 0]])
        >>> h.quotient_codomain(F.submodule([1, 1]))
        Matrix([
        [1, x], : QQ[x]**2 -> QQ[x]**2/<[1, 1]>
        [0, 0]])

        This is the same as composing with the quotient map on the left:

        >>> (F/[(1, 1)]).quotient_hom() * h
        Matrix([
        [1, x], : QQ[x]**2 -> QQ[x]**2/<[1, 1]>
        [0, 0]])
        z#sm must be a submodule of codomain r3   )r   r4   r   r:   r1   r&   s     r   Úquotient_codomainz$ModuleHomomorphism.quotient_codomainð   sP   € ð> �}‰}×)Ñ)¨"Ô-ÝØ $§£©rð3ó 4ð 4à�:‰:Œ<ØˆKØ×&Ñ& rÓ*Ð*r   c                 ó   — t         ‚)zApply ``self`` to ``elem``.r    ©r   Úelems     r   Ú_applyzModuleHomomorphism._apply  r"   r   c                 óˆ   — | j                   j                  | j                  | j                  j                  |«      «      «      S ©N)r   ÚconvertrA   r   r?   s     r   Ú__call__zModuleHomomorphism.__call__  s/   € Ø�}‰}×$Ñ$ T§[¡[°·±×1DÑ1DÀTÓ1JÓ%KÓLÐLr   c                 ó   — t         ‚)a	  
        Compose ``self`` with ``oth``, that is, return the homomorphism
        obtained by first applying then ``self``, then ``oth``.

        (This method is private since in this syntax, it is non-obvious which
        homomorphism is executed first.)
        r    ©r   Úoths     r   Ú_composezModuleHomomorphism._compose  s
   € ô "Ð!r   c                 ó   — t         ‚)z8Scalar multiplication. ``c`` is guaranteed in self.ring.r    )r   Úcs     r   Ú_mul_scalarzModuleHomomorphism._mul_scalar'  r"   r   c                 ó   — t         ‚)zv
        Homomorphism addition.
        ``oth`` is guaranteed to be a homomorphism with same domain/codomain.
        r    rG   s     r   Ú_addzModuleHomomorphism._add+  s
   € ô
 "Ð!r   c                 óŒ   — t        |t        «      sy|j                  | j                  k(  xr |j                  | j                  k(  S )zEHelper to check that oth is a homomorphism with same domain/codomain.F)r   r
   r   r   rG   s     r   Ú
_check_homzModuleHomomorphism._check_hom2  s5   € ä˜#Ô1Ô2ØØ�z‰z˜TŸ[™[Ñ(ÒJ¨S¯\©\¸T¿]¹]Ñ-JÐJr   c                 óö   — t        |t        «      r*| j                  |j                  k(  r|j	                  | «      S 	 | j                  | j                  j                  |«      «      S # t        $ r	 t        cY S w xY wrC   )
r   r
   r   r   rI   rL   r   rD   r   ÚNotImplementedrG   s     r   Ú__mul__zModuleHomomorphism.__mul__8  se   € Ü�cÔ-Ô.°4·;±;À#Ç,Á,Ò3NØ—<‘< Ó%Ð%ð	"Ø×#Ñ# D§I¡I×$5Ñ$5°cÓ$:Ó;Ð;øÜò 	"Ü!Ò!ð	"ús   ¼)A& Á&A8Á7A8c                 óˆ   — 	 | j                  d| j                  j                  |«      z  «      S # t        $ r	 t        cY S w xY w)Né   )rL   r   rD   r   rR   rG   s     r   Ú__truediv__zModuleHomomorphism.__truediv__C  sA   € ð	"Ø×#Ñ# A d§i¡i×&7Ñ&7¸Ó&<Ñ$<Ó=Ð=øÜò 	"Ü!Ò!ð	"ús   ‚,/ ¯AÁ Ac                 óR   — | j                  |«      r| j                  |«      S t        S rC   )rP   rN   rR   rG   s     r   Ú__add__zModuleHomomorphism.__add__I  s"   € Ø�?‰?˜3ÔØ—9‘9˜S“>Ð!ÜÐr   c                 ó¢   — | j                  |«      r9| j                  |j                  | j                  j	                  d«      «      «      S t
        S )Néÿÿÿÿ)rP   rN   rL   r   rD   rR   rG   s     r   Ú__sub__zModuleHomomorphism.__sub__N  s;   € Ø�?‰?˜3ÔØ—9‘9˜SŸ_™_¨T¯Y©Y×->Ñ->¸rÓ-BÓCÓDÐDÜÐr   c                 ó>   — | j                  «       j                  «       S )a  
        Return True if ``self`` is injective.

        That is, check if the elements of the domain are mapped to the same
        codomain element.

        Examples
        ========

        >>> from sympy import QQ
        >>> from sympy.abc import x
        >>> from sympy.polys.agca import homomorphism

        >>> F = QQ.old_poly_ring(x).free_module(2)
        >>> h = homomorphism(F, F, [[1, 0], [x, 0]])
        >>> h.is_injective()
        False
        >>> h.quotient_domain(h.kernel()).is_injective()
        True
        )r   r:   r   s    r   Úis_injectivezModuleHomomorphism.is_injectiveS  s   € ð* �{‰{‹}×$Ñ$Ó&Ð&r   c                 ó<   — | j                  «       | j                  k(  S )a  
        Return True if ``self`` is surjective.

        That is, check if every element of the codomain has at least one
        preimage.

        Examples
        ========

        >>> from sympy import QQ
        >>> from sympy.abc import x
        >>> from sympy.polys.agca import homomorphism

        >>> F = QQ.old_poly_ring(x).free_module(2)
        >>> h = homomorphism(F, F, [[1, 0], [x, 0]])
        >>> h.is_surjective()
        False
        >>> h.restrict_codomain(h.image()).is_surjective()
        True
        )r   r   r   s    r   Úis_surjectivez ModuleHomomorphism.is_surjectivej  s   € ð* �z‰z‹|˜tŸ}™}Ñ,Ð,r   c                 óF   — | j                  «       xr | j                  «       S )a~  
        Return True if ``self`` is an isomorphism.

        That is, check if every element of the codomain has precisely one
        preimage. Equivalently, ``self`` is both injective and surjective.

        Examples
        ========

        >>> from sympy import QQ
        >>> from sympy.abc import x
        >>> from sympy.polys.agca import homomorphism

        >>> F = QQ.old_poly_ring(x).free_module(2)
        >>> h = homomorphism(F, F, [[1, 0], [x, 0]])
        >>> h = h.restrict_codomain(h.image())
        >>> h.is_isomorphism()
        False
        >>> h.quotient_domain(h.kernel()).is_isomorphism()
        True
        )r]   r_   r   s    r   Úis_isomorphismz!ModuleHomomorphism.is_isomorphism�  s!   € ð, × Ñ Ó"Ò; t×'9Ñ'9Ó';Ð;r   c                 ó>   — | j                  «       j                  «       S )aN  
        Return True if ``self`` is a zero morphism.

        That is, check if every element of the domain is mapped to zero
        under self.

        Examples
        ========

        >>> from sympy import QQ
        >>> from sympy.abc import x
        >>> from sympy.polys.agca import homomorphism

        >>> F = QQ.old_poly_ring(x).free_module(2)
        >>> h = homomorphism(F, F, [[1, 0], [x, 0]])
        >>> h.is_zero()
        False
        >>> h.restrict_domain(F.submodule()).is_zero()
        True
        >>> h.quotient_codomain(h.image()).is_zero()
        True
        )r   r:   r   s    r   r:   zModuleHomomorphism.is_zero™  s   € ð. �z‰z‹|×#Ñ#Ó%Ð%r   c                 óH   — 	 | |z
  j                  «       S # t        $ r Y yw xY w)NF)r:   r   rG   s     r   Ú__eq__zModuleHomomorphism.__eq__²  s,   € ð	Ø˜3‘J×'Ñ'Ó)Ð)øÜò 	Ùð	ús   ‚ •	! !c                 ó   — | |k(   S rC   © rG   s     r   Ú__ne__zModuleHomomorphism.__ne__¸  s   € Ø˜C‘KÐ Ð r   N)"Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r(   r+   r.   r1   r5   r8   r;   r=   rA   rE   rI   rL   rN   rP   rS   Ú__rmul__rV   rX   r[   r]   r_   ra   r:   rd   rg   rf   r   r   r
   r
      s¥   „ ñ#òJòò,ò,"ò"ò"ò"ò"ò"ò%)òN+ò@)ò>$+òL"òMò"ò"ò"òKò"ð €Hò"òò
ò
'ò.-ò.<ò0&ò2ó!r   r
   c                   ó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y)ÚMatrixHomomorphismaí  
    Helper class for all homomoprhisms which are expressed via a matrix.

    That is, for such homomorphisms ``domain`` is contained in a module
    generated by finitely many elements `e_1, \ldots, e_n`, so that the
    homomorphism is determined uniquely by its action on the `e_i`. It
    can thus be represented as a vector of elements of the codomain module,
    or potentially a supermodule of the codomain module
    (and hence conventionally as a matrix, if there is a similar interpretation
    for elements of the codomain module).

    Note that this class does *not* assume that the `e_i` freely generate a
    submodule, nor that ``domain`` is even all of this submodule. It exists
    only to unify the interface.

    Do not instantiate.

    Attributes:

    - matrix - the list of images determining the homomorphism.
    NOTE: the elements of matrix belong to either self.codomain or
          self.codomain.container

    Still non-implemented methods:

    - kernel
    - _apply
    c                 óŠ  ‡— t         j                  | ||«       t        |«      |j                  k7  r$t	        d|j                  ›dt        |«      ›�«      ‚| j
                  j                  Št        | j
                  t        t        f«      r | j
                  j                  j                  Št        ˆfd„|D «       «      | _        y )NzNeed to provide z elements, got c              3   ó.   •K  — | ]  } ‰|«      –— Œ y ­wrC   rf   )Ú.0ÚxÚ	converters     €r   ú	<genexpr>z.MatrixHomomorphism.__init__.<locals>.<genexpr>ã  s   øè ø€ Ò9¨Q™I aŸLÑ9ùs   ƒ)r
   r   ÚlenÚrankr   r   rD   r   r   r   Ú	containerÚtupleÚmatrix)r   r   r   ry   rs   s       @r   r   zMatrixHomomorphism.__init__Ú  s�   ø€ Ü×#Ñ# D¨&°(Ô;Üˆv‹;˜&Ÿ+™+Ò%ÝØ &§£¬S°¬[ð:ó ;ð ;ð —M‘M×)Ñ)ˆ	Ü�d—m‘m¤iÔ1BÐ%CÔDØŸ™×/Ñ/×7Ñ7ˆIÜÓ9°&Ô9Ó9ˆ�r   c                 ó"  — ddl m} d„ }t        | j                  t        t
        f«      rd„ } || j                  D ��cg c]1  } ||«      D �cg c]  }| j                  j                  |«      ‘Œ c}‘Œ3 c}}«      j                  S c c}w c c}}w )z=Helper function which returns a SymPy matrix ``self.matrix``.r   )ÚMatrixc                 ó   — | S rC   rf   ©rr   s    r   ú<lambda>z2MatrixHomomorphism._sympy_matrix.<locals>.<lambda>è  s   € �a€ r   c                 ó   — | j                   S rC   )Údatar}   s    r   r~   z2MatrixHomomorphism._sympy_matrix.<locals>.<lambda>ê  s
   € ˜!Ÿ&™&€ r   )
Úsympy.matricesr{   r   r   r   r   ry   r   Úto_sympyÚT)r   r{   rK   rr   Úys        r   Ú_sympy_matrixz MatrixHomomorphism._sympy_matrixå  sg   € å)ÙˆÜ�d—m‘m¤nÔ6GÐ%HÔIÙ ˆAÙÀdÇkÁk×RÀ±q¸³tÖ<°!˜Ÿ	™	×*Ñ*¨1Õ-Ô<ÓRÓS×UÑUÐUùÒ<ùÓRs   ¾B
Á"BÁ/B
ÂB
c                 ó†  — t        | j                  «       «      j                  d«      }d| j                  ›d| j                  ›�}dt        |«      z  }t        |«      }t        |dz  «      D ]  }||xx   |z  cc<   Œ ||dz  xx   |z  cc<   t        |dz  dz   |«      D ]  }||xx   |z  cc<   Œ dj                  |«      S )Nú
z : z -> ú é   rU   )Úreprr…   Úsplitr   r   ru   ÚrangeÚjoin)r   ÚlinesÚtÚsÚnÚis         r   Ú__repr__zMatrixHomomorphism.__repr__í  s¸   € Ü�T×'Ñ'Ó)Ó*×0Ñ0°Ó6‰Ø!Ÿ[›[¨$¯-ª-Ð8ˆØ”�A“‰JˆÜ�‹JˆÜ�q˜A‘v“ò 	ˆAØ�!‹H˜‰MŒHð	àˆa�1‰f‹˜Ñ‹Ü�q˜!‘t˜a‘x Ó#ò 	ˆAØ�!‹H˜‰MŒHð	à�y‰y˜ÓÐr   c                 óD   — t        || j                  | j                  «      S r%   )ÚSubModuleHomomorphismr   ry   r&   s     r   r(   z#MatrixHomomorphism._restrict_domainù  s   € ä$ R¨¯©¸¿¹ÓDÐDr   c                 óP   — | j                  | j                  || j                  «      S r*   )Ú	__class__r   ry   r&   s     r   r+   z%MatrixHomomorphism._restrict_codomainý  s   € à�~‰~˜dŸk™k¨2¨t¯{©{Ó;Ð;r   c                 ój   — | j                  | j                  |z  | j                  | j                  «      S r-   ©r—   r   r   ry   r&   s     r   r.   z#MatrixHomomorphism._quotient_domain  s%   € à�~‰~˜dŸk™k¨"™n¨d¯m©m¸T¿[¹[ÓIÐIr   c           
      ó2  — | j                   |z  }|j                  }t        | j                   t        «      r|j                  j                  }| j                  | j                  | j                   |z  | j                  D �cg c]
  } ||«      ‘Œ c}«      S c c}w r0   )r   rD   r   r   rw   r—   r   ry   )r   r'   ÚQrs   rr   s        r   r1   z%MatrixHomomorphism._quotient_codomain  sq   € à�M‰M˜"ÑˆØ—I‘Iˆ	Ü�d—m‘m¤YÔ/ØŸ™×+Ñ+ˆIØ�~‰~˜dŸk™k¨4¯=©=¸Ñ+;Ø#'§;¡;Ö/˜a‰Y�q�\Ò/ó1ð 	1ùÚ/s   Á>Bc           
      óÄ   — | j                  | j                  | j                  t        | j                  |j                  «      D ��cg c]
  \  }}||z   ‘Œ c}}«      S c c}}w rC   )r—   r   r   Úzipry   )r   rH   rr   r„   s       r   rN   zMatrixHomomorphism._add  sI   € Ø�~‰~˜dŸk™k¨4¯=©=Ü14°T·[±[À#Ç*Á*Ó1M×N©¨¨A˜q 1›uÓNóPð 	PùÛNs   ÁAc           	      ó�   — | j                  | j                  | j                  | j                  D �cg c]  }||z  ‘Œ	 c}«      S c c}w rC   r™   )r   rK   rr   s      r   rL   zMatrixHomomorphism._mul_scalar  s3   € Ø�~‰~˜dŸk™k¨4¯=©=ÈÏÉÖ:TÀ1¸1¸Q»3Ò:TÓUÐUùÒ:Ts   °Ac           
      ó–   — | j                  | j                  |j                  | j                  D �cg c]
  } ||«      ‘Œ c}«      S c c}w rC   r™   )r   rH   rr   s      r   rI   zMatrixHomomorphism._compose  s3   € Ø�~‰~˜dŸk™k¨3¯<©<È$Ï+É+Ö9VÀQ¹#¸a½&Ò9VÓWÐWùÒ9Vs   °AN)rh   ri   rj   rk   r   r…   r“   r(   r+   r.   r1   rN   rL   rI   rf   r   r   rn   rn   ¼  s?   „ ñò:	:òVò
 òEò<òJò1òPòVóXr   rn   c                   ó"   — e Zd ZdZd„ Zd„ Zd„ Zy)ÚFreeModuleHomomorphismað  
    Concrete class for homomorphisms with domain a free module or a quotient
    thereof.

    Do not instantiate; the constructor does not check that your data is well
    defined. Use the ``homomorphism`` function instead:

    >>> from sympy import QQ
    >>> from sympy.abc import x
    >>> from sympy.polys.agca import homomorphism

    >>> F = QQ.old_poly_ring(x).free_module(2)
    >>> homomorphism(F, F, [[1, 0], [0, 1]])
    Matrix([
    [1, 0], : QQ[x]**2 -> QQ[x]**2
    [0, 1]])
    c                 óš   — t        | j                  t        «      r|j                  }t	        d„ t        || j                  «      D «       «      S )Nc              3   ó,   K  — | ]  \  }}||z  –— Œ y ­wrC   rf   ©rq   rr   Úes      r   rt   z0FreeModuleHomomorphism._apply.<locals>.<genexpr>/  ó   è ø€ Ò<™T˜Q �1�q•5Ñ<ùó   ‚)r   r   r   r€   Úsumr�   ry   r?   s     r   rA   zFreeModuleHomomorphism._apply,  s5   € Ü�d—k‘k¤>Ô2Ø—9‘9ˆDÜÑ<¤S¨¨t¯{©{Ó%;Ô<Ó<Ð<r   c                 óH   —  | j                   j                  | j                  Ž S rC   )r   Ú	submodulery   r   s    r   r   zFreeModuleHomomorphism._image1  s   € Ø&ˆt�}‰}×&Ñ&¨¯©Ð4Ð4r   c                 ó„   — | j                  «       j                  «       } | j                  j                  |j                  Ž S rC   )r   Úsyzygy_moduler   rª   Úgens)r   Úsyzs     r   r   zFreeModuleHomomorphism._kernel4  s3   € ð �j‰j‹l×(Ñ(Ó*ˆØ$ˆt�{‰{×$Ñ$ c§h¡hÐ/Ð/r   N©rh   ri   rj   rk   rA   r   r   rf   r   r   r¡   r¡     s   „ ñò$=ò
5ó0r   r¡   c                   ó"   — e Zd ZdZd„ Zd„ Zd„ Zy)r•   a  
    Concrete class for homomorphism with domain a submodule of a free module
    or a quotient thereof.

    Do not instantiate; the constructor does not check that your data is well
    defined. Use the ``homomorphism`` function instead:

    >>> from sympy import QQ
    >>> from sympy.abc import x
    >>> from sympy.polys.agca import homomorphism

    >>> M = QQ.old_poly_ring(x).free_module(2)*x
    >>> homomorphism(M, M, [[1, 0], [0, 1]])
    Matrix([
    [1, 0], : <[x, 0], [0, x]> -> <[x, 0], [0, x]>
    [0, 1]])
    c                 óš   — t        | j                  t        «      r|j                  }t	        d„ t        || j                  «      D «       «      S )Nc              3   ó,   K  — | ]  \  }}||z  –— Œ y ­wrC   rf   r¤   s      r   rt   z/SubModuleHomomorphism._apply.<locals>.<genexpr>T  r¦   r§   )r   r   r   r€   r¨   r�   ry   r?   s     r   rA   zSubModuleHomomorphism._applyQ  s6   € Ü�d—k‘kÔ#4Ô5Ø—9‘9ˆDÜÑ<¤S¨¨t¯{©{Ó%;Ô<Ó<Ð<r   c                 óŽ   —  | j                   j                  | j                  j                  D �cg c]
  } | |«      ‘Œ c}Ž S c c}w rC   )r   rª   r   r­   )r   rr   s     r   r   zSubModuleHomomorphism._imageV  s5   € Ø&ˆt�}‰}×&Ñ&¸$¿+¹+×:JÑ:JÖ(K°Q©¨a­Ò(KÐLÐLùÒ(Ks   ¯Ac                 ó  — | j                  «       j                  «       } | j                  j                  |j                  D �cg c]2  }t        d„ t        || j                  j                  «      D «       «      ‘Œ4 c}Ž S c c}w )Nc              3   ó,   K  — | ]  \  }}||z  –— Œ y ­wrC   rf   )rq   ÚxiÚgis      r   rt   z0SubModuleHomomorphism._kernel.<locals>.<genexpr>\  s   è ø€ Ò?™F˜B �"�R•%Ñ?ùr§   )r   r¬   r   rª   r­   r¨   r�   )r   r®   r�   s      r   r   zSubModuleHomomorphism._kernelY  sj   € Ø�j‰j‹l×(Ñ(Ó*ˆØ$ˆt�{‰{×$Ñ$à—x‘xö!Øô Ñ?¤c¨!¨T¯[©[×-=Ñ-=Ó&>Ô?Õ?ò !ð"ð 	"ùò!s   Á7A>Nr¯   rf   r   r   r•   r•   >  s   „ ñò$=ò
Mó"r   r•   c           
      ó   — d„ } || «      \  }}}} ||«      \  }}	}
}t        |||D �cg c]
  } ||«      ‘Œ c}«      j                  |«      j                  |	«      j                  |
«      j	                  |«      S c c}w )a>  
    Create a homomorphism object.

    This function tries to build a homomorphism from ``domain`` to ``codomain``
    via the matrix ``matrix``.

    Examples
    ========

    >>> from sympy import QQ
    >>> from sympy.abc import x
    >>> from sympy.polys.agca import homomorphism

    >>> R = QQ.old_poly_ring(x)
    >>> T = R.free_module(2)

    If ``domain`` is a free module generated by `e_1, \ldots, e_n`, then
    ``matrix`` should be an n-element iterable `(b_1, \ldots, b_n)` where
    the `b_i` are elements of ``codomain``. The constructed homomorphism is the
    unique homomorphism sending `e_i` to `b_i`.

    >>> F = R.free_module(2)
    >>> h = homomorphism(F, T, [[1, x], [x**2, 0]])
    >>> h
    Matrix([
    [1, x**2], : QQ[x]**2 -> QQ[x]**2
    [x,    0]])
    >>> h([1, 0])
    [1, x]
    >>> h([0, 1])
    [x**2, 0]
    >>> h([1, 1])
    [x**2 + 1, x]

    If ``domain`` is a submodule of a free module, them ``matrix`` determines
    a homomoprhism from the containing free module to ``codomain``, and the
    homomorphism returned is obtained by restriction to ``domain``.

    >>> S = F.submodule([1, 0], [0, x])
    >>> homomorphism(S, T, [[1, x], [x**2, 0]])
    Matrix([
    [1, x**2], : <[1, 0], [0, x]> -> QQ[x]**2
    [x,    0]])

    If ``domain`` is a (sub)quotient `N/K`, then ``matrix`` determines a
    homomorphism from `N` to ``codomain``. If the kernel contains `K`, this
    homomorphism descends to ``domain`` and is returned; otherwise an exception
    is raised.

    >>> homomorphism(S/[(1, 0)], T, [0, [x**2, 0]])
    Matrix([
    [0, x**2], : <[1, 0] + <[1, 0]>, [0, x] + <[1, 0]>, [1, 0] + <[1, 0]>> -> QQ[x]**2
    [0,    0]])
    >>> homomorphism(S/[(0, x)], T, [0, [x**2, 0]])
    Traceback (most recent call last):
    ...
    ValueError: kernel <[1, 0], [0, 0]> must contain sm, got <[0,x]>

    c                 ó„  ‡ — t        ‰ t        «      r‰ ‰ ‰ j                  «       ˆ fd„fS t        ‰ t        «      r'‰ j                  ‰ j                  ‰ j
                  ˆ fd„fS t        ‰ t        «      r1‰ j                  j                  ‰ j                  ‰ j
                  ˆ fd„fS ‰ j                  ‰ ‰ j                  «       ˆ fd„fS )zÞ
        Return a tuple ``(F, S, Q, c)`` where ``F`` is a free module, ``S`` is a
        submodule of ``F``, and ``Q`` a submodule of ``S``, such that
        ``module = S/Q``, and ``c`` is a conversion function.
        c                 ó&   •— ‰j                  | «      S rC   )rD   ©rr   Úmodules    €r   r~   z0homomorphism.<locals>.freepres.<locals>.<lambda>£  s   ø€ ÀÇÁÐPQÓAR€ r   c                 ó:   •— ‰j                  | «      j                  S rC   )rD   r€   r»   s    €r   r~   z0homomorphism.<locals>.freepres.<locals>.<lambda>¦  s   ø€ ˜fŸn™n¨QÓ/×4Ñ4€ r   c                 óN   •— ‰j                   j                  | «      j                  S rC   )rw   rD   r€   r»   s    €r   r~   z0homomorphism.<locals>.freepres.<locals>.<lambda>©  s   ø€ ˜f×.Ñ.×6Ñ6°qÓ9×>Ñ>€ r   c                 ó:   •— ‰j                   j                  | «      S rC   )rw   rD   r»   s    €r   r~   z0homomorphism.<locals>.freepres.<locals>.<lambda>¬  s   ø€ ˜&×*Ñ*×2Ñ2°1Ó5€ r   )r   r   rª   r   ÚbaseÚkilled_moduler   rw   )r¼   s   `r   Úfreepreszhomomorphism.<locals>.freepresœ  s®   ø€ ô �fœjÔ)Ø˜6 6×#3Ñ#3Ó#5Ó7RÐRÐRÜ�fœnÔ-Ø—K‘K §¡¨f×.BÑ.BÛ4ð6ð 6ä�fÔ/Ô0Ø—K‘K×)Ñ)¨6¯;©;¸×8LÑ8LÛ>ð@ð @ð × Ñ  &¨&×*:Ñ*:Ó*<Û5ð7ð 	7r   )r¡   r5   r8   r=   r;   )r   r   ry   rÂ   ÚSFÚSSÚSQÚ_ÚTFÚTSÚTQrK   rr   s                r   ÚhomomorphismrÊ   `  s~   € òx7ñ$ ˜VÓ$�M€BˆˆB�Ù˜XÓ&�M€BˆˆB�ä! " b¸Ö*@°A©1¨Q­4Ò*@ó ß‰?˜2Ó×0Ñ0°ó  ßÑ˜RÓ §¡°Ó!4ð5ùÒ*@s   ©A;N)rk   Úsympy.polys.agca.modulesr   r   r   r   r   Úsympy.polys.polyerrorsr   r
   rn   r¡   r•   rÊ   rf   r   r   ú<module>rÍ      sX   ðñ÷"õ "å 1÷g!ñ g!ôTZXÐ+ô ZXôz"0Ð/ô "0ôJ"Ð.ô "óDS5r   