
    gU                         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      Z/var/www/html/ai-engine/env/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;(-''*/5vvxx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DI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DI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* $RR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 tzz||,, 	3* $

bb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*"kkmmmmRR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* $rr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[[1D1DT1J1J%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zT[(JS\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;#,3N3N<<%%%	"##DI$5$5c$:$:;;; 	" 	" 	"!!!!	"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    	"##Adi&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 	"99S>>!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99S__TY->->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    * zz||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    . zz||##%%%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?    	3J''))) 	 	 	55	s    
''c                     | |k     S rC    rG   s     r   __ne__zModuleHomomorphism.__ne__  s    CK  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9QIIaLL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)	dmi1B%CDD 	8/7I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<<<<qqtt<<<RRRr   )sympy.matricesr}   r   r   r   r   r{   T)r   r}   rL   s   ` @r   _sympy_matrixz MatrixHomomorphism._sympy_matrix  sl    ))))))Kdmn6G%HII 	!  AvRRRRRdk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JJqAv 	 	A!HHHMHHHHa1fq!tax## 	 	A!HHHMHHHHyy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    ~~dk2t{;;;r   c                 T    |                      | j        |z  | j        | j                  S r-   r   r   r   r{   r&   s     r   r.   z#MatrixHomomorphism._quotient_domain  s"    ~~dk"ndmT[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!    ///aYYq\\///r   )r   rD   r   r   ry   r   r   r{   )r   r'   Qru   s      @r   r1   z%MatrixHomomorphism._quotient_codomain  sp    M"I	dmY// 	,+I~~dk4=+;////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Aq1uNNNr   )r   r   r   zipr{   rG   s     r   rO   zMatrixHomomorphism._add  sB    ~~dk4=NNT[#*1M1M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:T11Q3:T:T:Tr   r   rK   s    `r   rM   zMatrixHomomorphism._mul_scalar  s4    ~~dk4=: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!    9V9V9VQ##a&&9V9V9Vr   r   rG   s    `r   rI   zMatrixHomomorphism._compose  s4    ~~dk3<9V9V9V9V$+9V9V9V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>/  *      <<TQ1q5<<<<<<r   )r   r   r   r   sumr   r{   r?   s     r   rA   zFreeModuleHomomorphism._apply,  sF    dk>22 	9D<<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     jjll((**$t{$ch//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    dk#455 	9D<<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(KQ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*      ??FB"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    jjll((**$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    PQARAR r   c                 8                         |           j        S rC   )rD   r   r   s    r   r   z0homomorphism.<locals>.freepres.<locals>.<lambda>  s    fnnQ//4 r   c                 B    j                             |           j        S rC   )ry   rD   r   r   s    r   r   z0homomorphism.<locals>.freepres.<locals>.<lambda>  s    f.66q99> r   c                 8    j                             |           S rC   )ry   rD   r   s    r   r   z0homomorphism.<locals>.freepres.<locals>.<lambda>  s    &*22155 r   )r   r   r   r   basekilled_moduler   ry   )r   s   `r   freepreszhomomorphism.<locals>.freepres  s     fj)) 	S66#3#3#5#57R7R7R7RRRfn-- 	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!    *@*@*@A11Q44*@*@*@r   )r   r5   r8   r=   r;   )r   r   r{   r   SFSSSQ_TFTSTQrL   s              @r   homomorphismr   `  s    x7 7 7$ HV$$MBBHX&&MB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 "0J" " " " ". " " "DS5 S5 S5 S5 S5r   