§
    OŠtj±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dS )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!dS ) Ú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        k    rt	          d|›d|›�¦  «        ‚|| _        || _        |j        | _        d | _        d | _        d S )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/html/CA-Chatbot/venv/lib/python3.11/site-packages/sympy/polys/agca/homomorphisms.pyÚ__init__zModuleHomomorphism.__init__8   s°   € Ý˜&¥&Ñ)Ô)ð 	HÝÐ=ÀÑFÑGÔGÐGÝ˜(¥FÑ+Ô+ð 	JÝÐ=ÀÑHÑIÔIÐIØŒ;˜(œ-Ò'Ð'Ý�*Ø/5¨v¨v°x°xðAñ Bô Bð BàˆŒØ ˆŒØ”KˆŒ	ØˆŒ	ØˆŒ	ˆ	ˆ	ó    c                 óP   — | 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ÐØŸš™œˆDŒIØŒyÐr   c                 óP   — | 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ÐØŸš™œˆDŒIØŒ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           ‚)ú$Implementation of codomain quotient.r    r&   s     r   Ú_quotient_codomainz%ModuleHomomorphism._quotient_codomain†   r"   r   c                 ó®   — | j                              |¦  «        st          d| j         ›d|›�¦  «        ‚|| j         k    r| S |                      |¦  «        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Š   si   € ð@ Œ{×'Ò'¨Ñ+Ô+ð 	2Ý�*Ø $¤  ¨R¨Rð1ñ 2ô 2ð 2à�”ÒÐØˆKØ×$Ò$ RÑ(Ô(Ð(r   c                 óâ   — |                      |                      ¦   «         ¦  «        s't          d|                      ¦   «         ›d|›�¦  «        ‚|| j        k    r| S |                      |¦  «        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±   sr   € ð2 �Š˜tŸzšz™|œ|Ñ,Ô,ð 	3Ý�*Ø $§
¢
¡¤  ¨b¨bð2ñ 3ô 3ð 3à�”ÒÐØˆKØ×&Ò& rÑ*Ô*Ð*r   c                 óô   — |                       ¦   «                              |¦  «        s't          d|                       ¦   «         ›d|›�¦  «        ‚|                     ¦   «         r| S |                      |¦  «        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Ñ   sw   € ð0 �{Š{‰}Œ}×)Ò)¨"Ñ-Ô-ð 	2Ý�*Ø"Ÿkšk™mœm˜m˜m¨R¨Rð1ñ 2ô 2ð 2à�:Š:‰<Œ<ð 	ØˆKØ×$Ò$ RÑ(Ô(Ð(r   c                 óÀ   — | j                              |¦  «        st          d| j         ›d|›�¦  «        ‚|                     ¦   «         r| S |                      |¦  «        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ð   sk   € ð> Œ}×)Ò)¨"Ñ-Ô-ð 	4Ý�*Ø $¤  ¨r¨rð3ñ 4ô 4ð 4à�:Š:‰<Œ<ð 	ØˆKØ×&Ò& rÑ*Ô*Ð*r   c                 ó   — t           ‚)zApply ``self`` to ``elem``.r    ©r   Úelems     r   Ú_applyzModuleHomomorphism._apply  r"   r   c                 óŒ   — | j                              |                      | j                             |¦  «        ¦  «        ¦  «        S ©N)r   ÚconvertrA   r   r?   s     r   Ú__call__zModuleHomomorphism.__call__  s4   € ØŒ}×$Ò$ T§[¢[°´×1DÒ1DÀTÑ1JÔ1JÑ%KÔ%KÑLÔ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                 óp   — t          |t          ¦  «        sdS |j        | j        k    o|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  s7   € å˜#Õ1Ñ2Ô2ð 	Ø�5ØŒz˜Tœ[Ò(ÐJ¨S¬\¸T¼]Ò-JÐJr   c                 ó   — t          |t          ¦  «        r%| j        |j        k    r|                     | ¦  «        S 	 |                      | j                             |¦  «        ¦  «        S # t          $ r
 t          cY S w xY wrC   )
r   r
   r   r   rI   rM   r   rD   r   ÚNotImplementedrG   s     r   Ú__mul__zModuleHomomorphism.__mul__8  s…   € Ý�cÕ-Ñ.Ô.ð 	&°4´;À#Ä,Ò3NÐ3NØ—<’< Ñ%Ô%Ð%ð	"Ø×#Ò# D¤I×$5Ò$5°cÑ$:Ô$:Ñ;Ô;Ð;øÝð 	"ð 	"ð 	"Ý!Ð!Ð!Ð!ð	"øøøs   ¼,A) Á)A=Á<A=c                 ó’   — 	 |                       d| j                             |¦  «        z  ¦  «        S # t          $ r
 t          cY S w xY w)Né   )rM   r   rD   r   rS   rG   s     r   Ú__truediv__zModuleHomomorphism.__truediv__C  sW   € ð	"Ø×#Ò# A d¤i×&7Ò&7¸Ñ&<Ô&<Ñ$<Ñ=Ô=Ð=øÝð 	"ð 	"ð 	"Ý!Ð!Ð!Ð!ð	"øøøs   ‚/2 ²AÁAc                 ód   — |                       |¦  «        r|                      |¦  «        S t          S rC   )rQ   rO   rS   rG   s     r   Ú__add__zModuleHomomorphism.__add__I  s,   € Ø�?Š?˜3ÑÔð 	"Ø—9’9˜S‘>”>Ð!ÝÐr   c                 óº   — |                       |¦  «        r@|                      |                     | j                             d¦  «        ¦  «        ¦  «        S t
          S )Néÿÿÿÿ)rQ   rO   rM   r   rD   rS   rG   s     r   Ú__sub__zModuleHomomorphism.__sub__N  sK   € Ø�?Š?˜3ÑÔð 	EØ—9’9˜SŸ_š_¨T¬Y×->Ò->¸rÑ-BÔ-BÑCÔCÑDÔDÐDÝÐr   c                 óN   — |                       ¦   «                              ¦   «         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        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                 óR   — |                       ¦   «         o|                      ¦   «         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                 óN   — |                       ¦   «                              ¦   «         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                 óT   — 	 | |z
                        ¦   «         S # t          $ r Y dS w xY w)NF)r:   r   rG   s     r   Ú__eq__zModuleHomomorphism.__eq__²  s?   € ð	Ø˜3‘J×'Ò'Ñ)Ô)Ð)øÝð 	ð 	ð 	Ø�5�5ð	øøø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   rM   rO   rQ   rT   Ú__rmul__rW   rY   r\   r^   r`   rb   r:   re   rh   rg   r   r   r
   r
      sâ  € € € € € ð#ð #ðJð ð ðð ð ð,ð ð ð,"ð "ð "ð"ð "ð "ð"ð "ð "ð"ð "ð "ð"ð "ð "ð"ð "ð "ð%)ð %)ð %)ðN+ð +ð +ð@)ð )ð )ð>$+ð $+ð $+ðL"ð "ð "ðMð Mð Mð"ð "ð "ð"ð "ð "ð"ð "ð "ðKð Kð Kð"ð "ð "ð €Hð"ð "ð "ðð ð ð
ð ð ð
'ð 'ð 'ð.-ð -ð -ð.<ð <ð <ð0&ð &ð &ð2ð ð ð!ð !ð !ð !ð !r   r
   c                   óN   — 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S )Ú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                 óz  ‡— t                                | ||¦  «         t          |¦  «        |j        k    r't	          d|j        ›dt          |¦  «        ›�¦  «        ‚| j        j        Št          | j        t          t          f¦  «        r| j        j
        j        Št          ˆfd„|D ¦   «         ¦  «        | _        d S )NzNeed to provide z elements, got c              3   ó.   •K  — | ]} ‰|¦  «        V — Œd S rC   rg   ©Ú.0ÚxÚ	converters     €r   ú	<genexpr>z.MatrixHomomorphism.__init__.<locals>.<genexpr>ã  s+   øè è € Ð9Ð9¨Q˜I˜I a™LœLÐ9Ð9Ð9Ð9Ð9Ð9r   )r
   r   ÚlenÚrankr   r   rD   r   r   r   Ú	containerÚtupleÚmatrix)r   r   r   r{   ru   s       @r   r   zMatrixHomomorphism.__init__Ú  sµ   ø€ Ý×#Ò# D¨&°(Ñ;Ô;Ð;Ýˆv‰;Œ;˜&œ+Ò%Ð%Ý�*Ø &¤  ­S°©[¬[¨[ð:ñ ;ô ;ð ;ð ”MÔ)ˆ	Ý�d”m¥iÕ1BÐ%CÑDÔDð 	8ØœÔ/Ô7ˆIÝÐ9Ð9Ð9Ð9°&Ð9Ñ9Ô9Ñ9Ô9ˆŒˆˆr   c                 ó¤   ‡ ‡— ddl m} d„ Št          ‰ j        t          t
          f¦  «        rd„ Š |ˆˆ fd„‰ j        D ¦   «         ¦  «        j        S )z=Helper function which returns a SymPy matrix ``self.matrix``.r   )ÚMatrixc                 ó   — | S rC   rg   ©rt   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   c                 ó>   •— g | ]}ˆfd „ ‰|¦  «        D ¦   «         ‘ŒS )c                 óD   •— g | ]}‰j                              |¦  «        ‘ŒS rg   )r   Úto_sympy)rs   Úyr   s     €r   ú
<listcomp>z?MatrixHomomorphism._sympy_matrix.<locals>.<listcomp>.<listcomp>ë  s)   ø€ Ð<Ð<Ð<°!˜œ	×*Ò*¨1Ñ-Ô-Ð<Ð<Ð<r   rg   )rs   rt   rL   r   s     €€r   r‡   z4MatrixHomomorphism._sympy_matrix.<locals>.<listcomp>ë  s6   ø€ ÐRÐRÐRÀÐ<Ð<Ð<Ð<°q°q¸±t´tÐ<Ñ<Ô<ÐRÐRÐRr   )Úsympy.matricesr}   r   r   r   r   r{   ÚT)r   r}   rL   s   ` @r   Ú_sympy_matrixz MatrixHomomorphism._sympy_matrixå  sl   øø€ à)Ð)Ð)Ð)Ð)Ð)ØˆKˆÝ�d”m¥nÕ6GÐ%HÑIÔIð 	!Ø Ð ˆAØˆvÐRÐRÐRÐRÐRÀdÄkÐRÑRÔRÑSÔSÔUÐUr   c                 ó¼  — t          |                      ¦   «         ¦  «                             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                     |¦  «        S )Nú
z : z -> ú é   rV   )ÚreprrŠ   Úsplitr   r   rw   ÚrangeÚjoin)r   ÚlinesÚtÚsÚnÚis         r   Ú__repr__zMatrixHomomorphism.__repr__í  sí   € Ý�T×'Ò'Ñ)Ô)Ñ*Ô*×0Ò0°Ñ6Ô6ˆˆØ!œ[˜[˜[¨$¬-¨-Ð8ˆØ•�A‘”‰JˆÝ�‰JŒJˆÝ�q˜A‘v‘”ð 	ð 	ˆAØ�!ˆHˆHŒH˜‰MˆHˆH‰HˆHØˆa�1‰fˆˆŒ˜Ñˆˆ‰Ý�q˜!‘t˜a‘x Ñ#Ô#ð 	ð 	ˆAØ�!ˆHˆHŒH˜‰MˆHˆH‰HˆHØ�yŠy˜ÑÔÐr   c                 ó8   — t          || j        | j        ¦  «        S r%   )ÚSubModuleHomomorphismr   r{   r&   s     r   r(   z#MatrixHomomorphism._restrict_domainù  s   € å$ R¨¬¸¼ÑDÔDÐDr   c                 óD   — |                       | j        || j        ¦  «        S r*   )Ú	__class__r   r{   r&   s     r   r+   z%MatrixHomomorphism._restrict_codomainý  s   € à�~Š~˜dœk¨2¨t¬{Ñ;Ô;Ð;r   c                 óT   — |                       | j        |z  | j        | j        ¦  «        S r-   ©rœ   r   r   r{   r&   s     r   r.   z#MatrixHomomorphism._quotient_domain  s"   € à�~Š~˜dœk¨"™n¨d¬m¸T¼[ÑIÔIÐIr   c                 óÜ   ‡— | j         |z  }|j        Št          | j         t          ¦  «        r|j        j        Š|                      | j        | j         |z  ˆfd„| j        D ¦   «         ¦  «        S )r0   c                 ó&   •— g | ]} ‰|¦  «        ‘ŒS rg   rg   rr   s     €r   r‡   z9MatrixHomomorphism._quotient_codomain.<locals>.<listcomp>  s!   ø€ Ð/Ð/Ð/˜aˆYˆY�q‰\Œ\Ð/Ð/Ð/r   )r   rD   r   r   ry   rœ   r   r{   )r   r'   ÚQru   s      @r   r1   z%MatrixHomomorphism._quotient_codomain  sp   ø€ àŒM˜"ÑˆØ”Iˆ	Ý�d”m¥YÑ/Ô/ð 	,ØœÔ+ˆIØ�~Š~˜dœk¨4¬=¸Ñ+;Ø/Ð/Ð/Ð/ 4¤;Ð/Ñ/Ô/ñ1ô 1ð 	1r   c           	      óˆ   — |                       | j        | j        d„ t          | j        |j        ¦  «        D ¦   «         ¦  «        S )Nc                 ó   — g | ]
\  }}||z   ‘ŒS rg   rg   )rs   rt   r†   s      r   r‡   z+MatrixHomomorphism._add.<locals>.<listcomp>  s    € ÐNÐNÐN©¨¨A˜q 1™uÐNÐNÐNr   )rœ   r   r   Úzipr{   rG   s     r   rO   zMatrixHomomorphism._add  sB   € Ø�~Š~˜dœk¨4¬=ØNÐNµ°T´[À#Ä*Ñ1MÔ1MÐNÑNÔNñPô Pð 	Pr   c                 óh   ‡— |                       | j        | j        ˆfd„| j        D ¦   «         ¦  «        S )Nc                 ó   •— g | ]}‰|z  ‘ŒS rg   rg   ©rs   rt   rL   s     €r   r‡   z2MatrixHomomorphism._mul_scalar.<locals>.<listcomp>  s   ø€ Ð:TÐ:TÐ:TÀ1¸1¸Q¹3Ð:TÐ:TÐ:Tr   rž   rK   s    `r   rM   zMatrixHomomorphism._mul_scalar  s4   ø€ Ø�~Š~˜dœk¨4¬=Ð:TÐ:TÐ:TÐ:TÈÌÐ:TÑ:TÔ:TÑUÔUÐUr   c                 óh   ‡— |                       | j        ‰j        ˆfd„| j        D ¦   «         ¦  «        S )Nc                 ó&   •— g | ]} ‰|¦  «        ‘ŒS rg   rg   )rs   rt   rH   s     €r   r‡   z/MatrixHomomorphism._compose.<locals>.<listcomp>  s!   ø€ Ð9VÐ9VÐ9VÀQ¸#¸#¸a¹&¼&Ð9VÐ9VÐ9Vr   rž   rG   s    `r   rI   zMatrixHomomorphism._compose  s4   ø€ Ø�~Š~˜dœk¨3¬<Ð9VÐ9VÐ9VÐ9VÈ$Ì+Ð9VÑ9VÔ9VÑWÔWÐWr   N)ri   rj   rk   rl   r   rŠ   r˜   r(   r+   r.   r1   rO   rM   rI   rg   r   r   ro   ro   ¼  sÈ   € € € € € ðð ð:	:ð 	:ð 	:ðVð Vð Vð
 ð 
 ð 
 ðEð Eð Eð<ð <ð <ðJð Jð Jð1ð 1ð 1ðPð Pð PðVð Vð VðXð Xð Xð Xð Xr   ro   c                   ó$   — e Zd ZdZd„ Zd„ Zd„ ZdS )Ú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  V — Œd S rC   rg   ©rs   rt   Úes      r   rv   z0FreeModuleHomomorphism._apply.<locals>.<genexpr>/  ó*   è è € Ð<Ð<™T˜Q �1�q‘5Ð<Ð<Ð<Ð<Ð<Ð<r   )r   r   r   r‚   Úsumr¤   r{   r?   s     r   rA   zFreeModuleHomomorphism._apply,  sF   € Ý�d”k¥>Ñ2Ô2ð 	Ø”9ˆDÝÐ<Ð<¥S¨¨t¬{Ñ%;Ô%;Ð<Ñ<Ô<Ñ<Ô<Ð<r   c                 ó*   —  | j         j        | j        Ž S rC   )r   Ú	submoduler{   r   s    r   r   zFreeModuleHomomorphism._image1  s   € Ø&ˆtŒ}Ô&¨¬Ð4Ð4r   c                 óv   — |                       ¦   «                              ¦   «         } | j        j        |j        Ž S rC   ©r   Úsyzygy_moduler   r³   Úgens©r   Úsyzs     r   r   zFreeModuleHomomorphism._kernel4  s1   € ð �jŠj‰lŒl×(Ò(Ñ*Ô*ˆØ$ˆtŒ{Ô$ c¤hÐ/Ð/r   N©ri   rj   rk   rl   rA   r   r   rg   r   r   r«   r«     sK   € € € € € ðð ð$=ð =ð =ð
5ð 5ð 5ð0ð 0ð 0ð 0ð 0r   r«   c                   ó$   — e Zd ZdZd„ Zd„ Zd„ ZdS )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  V — Œd S rC   rg   r®   s      r   rv   z/SubModuleHomomorphism._apply.<locals>.<genexpr>T  r°   r   )r   r   r   r‚   r±   r¤   r{   r?   s     r   rA   zSubModuleHomomorphism._applyQ  sG   € Ý�d”kÕ#4Ñ5Ô5ð 	Ø”9ˆDÝÐ<Ð<¥S¨¨t¬{Ñ%;Ô%;Ð<Ñ<Ô<Ñ<Ô<Ð<r   c                 óN   ‡ —  ‰ j         j        ˆ fd„‰ j        j        D ¦   «         Ž S )Nc                 ó&   •— g | ]} ‰|¦  «        ‘ŒS rg   rg   )rs   rt   r   s     €r   r‡   z0SubModuleHomomorphism._image.<locals>.<listcomp>W  s!   ø€ Ð(KÐ(KÐ(K°Q¨¨¨a©¬Ð(KÐ(KÐ(Kr   )r   r³   r   r·   r   s   `r   r   zSubModuleHomomorphism._imageV  s/   ø€ Ø&ˆtŒ}Ô&Ð(KÐ(KÐ(KÐ(K¸$¼+Ô:JÐ(KÑ(KÔ(KÐLÐLr   c                 ó�   ‡ — ‰                       ¦   «                              ¦   «         } ‰ j        j        ˆ fd„|j        D ¦   «         Ž S )Nc           	      ór   •— g | ]3}t          d „ t          |‰j        j        ¦  «        D ¦   «         ¦  «        ‘Œ4S )c              3   ó&   K  — | ]\  }}||z  V — Œd S rC   rg   )rs   ÚxiÚgis      r   rv   z;SubModuleHomomorphism._kernel.<locals>.<listcomp>.<genexpr>\  s*   è è € Ð?Ð?™F˜B �"�R‘%Ð?Ð?Ð?Ð?Ð?Ð?r   )r±   r¤   r   r·   )rs   r•   r   s     €r   r‡   z1SubModuleHomomorphism._kernel.<locals>.<listcomp>\  sO   ø€ ð !ð !ð !Øõ Ð?Ð?¥c¨!¨T¬[Ô-=Ñ&>Ô&>Ð?Ñ?Ô?Ñ?Ô?ð !ð !ð !r   rµ   r¸   s   ` r   r   zSubModuleHomomorphism._kernelY  sX   ø€ Ø�jŠj‰lŒl×(Ò(Ñ*Ô*ˆØ$ˆtŒ{Ô$ð!ð !ð !ð !Ø”xð!ñ !ô !ð"ð 	"r   Nrº   rg   r   r   rš   rš   >  sN   € € € € € ðð ð$=ð =ð =ð
Mð Mð Mð"ð "ð "ð "ð "r   rš   c                 ó  ‡— d„ } || ¦  «        \  }}}} ||¦  «        \  }}	}
Št          ||ˆfd„|D ¦   «         ¦  «                             |¦  «                             |	¦  «                             |
¦  «                             |¦  «        S )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                 ób  ‡ — t          ‰ t          ¦  «        r‰ ‰ ‰                      ¦   «         ˆ fd„fS t          ‰ t          ¦  «        r‰ j        ‰ j        ‰ j        ˆ fd„fS t          ‰ t          ¦  «        r‰ j        j        ‰ j        ‰ j        ˆ fd„fS ‰ 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                 ó.   •— ‰                      | ¦  «        S rC   )rD   ©rt   Úmodules    €r   r€   z0homomorphism.<locals>.freepres.<locals>.<lambda>£  s   ø€ ÀÇÂÐPQÑARÔAR€ r   c                 ó8   •— ‰                      | ¦  «        j        S rC   )rD   r‚   rÈ   s    €r   r€   z0homomorphism.<locals>.freepres.<locals>.<lambda>¦  s   ø€ ˜fŸnšn¨QÑ/Ô/Ô4€ r   c                 óB   •— ‰j                              | ¦  «        j        S rC   )ry   rD   r‚   rÈ   s    €r   r€   z0homomorphism.<locals>.freepres.<locals>.<lambda>©  s   ø€ ˜fÔ.×6Ò6°qÑ9Ô9Ô>€ r   c                 ó8   •— ‰j                              | ¦  «        S rC   )ry   rD   rÈ   s    €r   r€   z0homomorphism.<locals>.freepres.<locals>.<lambda>¬  s   ø€ ˜&Ô*×2Ò2°1Ñ5Ô5€ r   )r   r   r³   r   ÚbaseÚkilled_moduler   ry   )rÉ   s   `r   Úfreepreszhomomorphism.<locals>.freepresœ  sÞ   ø€ õ �f�jÑ)Ô)ð 	SØ˜6 6×#3Ò#3Ñ#5Ô#5Ð7RÐ7RÐ7RÐ7RÐRÐRÝ�f�nÑ-Ô-ð 	6Ø”K ¤¨fÔ.BØ4Ð4Ð4Ð4ð6ð 6å�fÕ/Ñ0Ô0ð 	@Ø”KÔ)¨6¬;¸Ô8LØ>Ð>Ð>Ð>ð@ð @ð Ô  &¨&×*:Ò*:Ñ*<Ô*<Ø5Ð5Ð5Ð5ð7ð 	7r   c                 ó&   •— g | ]} ‰|¦  «        ‘ŒS rg   rg   r§   s     €r   r‡   z homomorphism.<locals>.<listcomp>±  s!   ø€ Ð*@Ð*@Ð*@°A¨1¨1¨Q©4¬4Ð*@Ð*@Ð*@r   )r«   r5   r8   r=   r;   )r   r   r{   rÏ   ÚSFÚSSÚSQÚ_ÚTFÚTSÚTQrL   s              @r   ÚhomomorphismrØ   `  s©   ø€ ðx7ð 7ð 7ð$ �H˜VÑ$Ô$�M€BˆˆB�Ø�H˜XÑ&Ô&�M€BˆˆB�å! " bÐ*@Ð*@Ð*@Ð*@¸Ð*@Ñ*@Ô*@ñ ô ßŠ?˜2ÑÔ×0Ò0°ñ  ô  ßÒ˜RÑ Ô §¢°Ñ!4Ô!4ð5r   N)rl   Úsympy.polys.agca.modulesr   r   r   r   r   Úsympy.polys.polyerrorsr   r
   ro   r«   rš   rØ   rg   r   r   ú<module>rÛ      sJ  ððð ð"ð "ð "ð "ð "ð "ð "ð "ð "ð "ð "ð "ð "ð "à 1Ð 1Ð 1Ð 1Ð 1Ð 1ðg!ð g!ð g!ð g!ð g!ñ g!ô g!ð g!ðTZXð ZXð ZXð ZXð ZXÐ+ñ ZXô ZXð ZXðz"0ð "0ð "0ð "0ð "0Ð/ñ "0ô "0ð "0ðJ"ð "ð "ð "ð "Ð.ñ "ô "ð "ðDS5ð S5ð S5ð S5ð S5r   