ó
¡¼™\c           @  sÉ   d  Z  d d l m Z m Z d d l m Z d d l m Z m Z m	 Z	 m
 Z
 m Z d d l m Z d e f d „  ƒ  YZ d e f d	 „  ƒ  YZ d
 e f d „  ƒ  YZ d e f d „  ƒ  YZ d „  Z d S(   s   
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.
iÿÿÿÿ(   t   print_functiont   division(   t   range(   t   Modulet
   FreeModulet   QuotientModulet	   SubModulet   SubQuotientModule(   t   CoercionFailedt   ModuleHomomorphismc           B  s  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 e Z d „  Z e Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z  d „  Z! RS(   s"  
    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         C  s£   t  | t ƒ s" t d | ƒ ‚ n  t  | t ƒ sD t d | ƒ ‚ n  | j | j k ro t d | | f ƒ ‚ n  | |  _ | |  _ | j |  _ d  |  _ d  |  _	 d  S(   Ns   Source must be a module, got %ss   Target must be a module, got %ss8   Source and codomain must be over same ring, got %s != %s(
   t
   isinstanceR   t	   TypeErrort   ringt
   ValueErrort   domaint   codomaint   Nonet   _kert   _img(   t   selfR   R   (    (    s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pyt   __init__:   s    			c         C  s(   |  j  d k r! |  j ƒ  |  _  n  |  j  S(   sî  
        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]>
        N(   R   R   t   _kernel(   R   (    (    s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pyt   kernelH   s    c         C  s(   |  j  d k r! |  j ƒ  |  _  n  |  j  S(   sú  
        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
        N(   R   R   t   _image(   R   (    (    s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pyt   image^   s    c         C  s
   t  ‚ d S(   s   Compute the kernel of ``self``.N(   t   NotImplementedError(   R   (    (    s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pyR   t   s    c         C  s
   t  ‚ d S(   s   Compute the image of ``self``.N(   R   (   R   (    (    s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pyR   x   s    c         C  s
   t  ‚ d S(   s%   Implementation of domain restriction.N(   R   (   R   t   sm(    (    s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pyt   _restrict_domain|   s    c         C  s
   t  ‚ d S(   s'   Implementation of codomain restriction.N(   R   (   R   R   (    (    s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pyt   _restrict_codomain€   s    c         C  s
   t  ‚ d S(   s"   Implementation of domain quotient.N(   R   (   R   R   (    (    s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pyt   _quotient_domain„   s    c         C  s
   t  ‚ d S(   s$   Implementation of codomain quotient.N(   R   (   R   R   (    (    s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pyt   _quotient_codomainˆ   s    c         C  sN   |  j  j | ƒ s. t d |  j  | f ƒ ‚ n  | |  j  k rA |  S|  j | ƒ S(   s?  
        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]])
        s$   sm must be a submodule of %s, got %s(   R   t   is_submoduleR   R   (   R   R   (    (    s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pyt   restrict_domainŒ   s     c         C  sT   | j  |  j ƒ  ƒ s4 t d |  j ƒ  | f ƒ ‚ n  | |  j k rG |  S|  j | ƒ S(   s„  
        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]])
        s$   the image %s must contain sm, got %s(   R   R   R   R   R   (   R   R   (    (    s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pyt   restrict_codomain³   s    c         C  sQ   |  j  ƒ  j | ƒ s4 t d |  j  ƒ  | f ƒ ‚ n  | j ƒ  rD |  S|  j | ƒ S(   sm  
        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]])
        s!   kernel %s must contain sm, got %s(   R   R   R   t   is_zeroR   (   R   R   (    (    s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pyt   quotient_domainÓ   s    c         C  sK   |  j  j | ƒ s. t d |  j  | f ƒ ‚ n  | j ƒ  r> |  S|  j | ƒ S(   s:  
        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]])
        s-   sm must be a submodule of codomain %s, got %s(   R   R   R   R"   R   (   R   R   (    (    s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pyt   quotient_codomainò   s    c         C  s
   t  ‚ d S(   s   Apply ``self`` to ``elem``.N(   R   (   R   t   elem(    (    s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pyt   _apply  s    c         C  s%   |  j  j |  j |  j j | ƒ ƒ ƒ S(   N(   R   t   convertR&   R   (   R   R%   (    (    s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pyt   __call__  s    c         C  s
   t  ‚ d S(   s	  
        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.)
        N(   R   (   R   t   oth(    (    s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pyt   _compose  s    c         C  s
   t  ‚ d S(   s8   Scalar multiplication. ``c`` is guaranteed in self.ring.N(   R   (   R   t   c(    (    s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pyt   _mul_scalar)  s    c         C  s
   t  ‚ d S(   sv   
        Homomorphism addition.
        ``oth`` is guaranteed to be a homomorphism with same domain/codomain.
        N(   R   (   R   R)   (    (    s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pyt   _add-  s    c         C  s5   t  | t ƒ s t S| j |  j k o4 | j |  j k S(   sE   Helper to check that oth is a homomorphism with same domain/codomain.(   R
   R	   t   FalseR   R   (   R   R)   (    (    s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pyt
   _check_hom4  s    c         C  sd   t  | t ƒ r. |  j | j k r. | j |  ƒ Sy |  j |  j j | ƒ ƒ SWn t k
 r_ t	 SXd  S(   N(
   R
   R	   R   R   R*   R,   R   R'   R   t   NotImplemented(   R   R)   (    (    s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pyt   __mul__:  s    !c         C  s:   y! |  j  d |  j j | ƒ ƒ SWn t k
 r5 t SXd  S(   Ni   (   R,   R   R'   R   R0   (   R   R)   (    (    s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pyt   __div__E  s    !c         C  s    |  j  | ƒ r |  j | ƒ St S(   N(   R/   R-   R0   (   R   R)   (    (    s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pyt   __add__M  s    c         C  s5   |  j  | ƒ r1 |  j | j |  j j d ƒ ƒ ƒ St S(   Niÿÿÿÿ(   R/   R-   R,   R   R'   R0   (   R   R)   (    (    s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pyt   __sub__R  s    "c         C  s   |  j  ƒ  j ƒ  S(   s  
        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=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pyt   is_injectiveW  s    c         C  s   |  j  ƒ  |  j k S(   s  
        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=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pyt   is_surjectiven  s    c         C  s   |  j  ƒ  o |  j ƒ  S(   s~  
        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
        (   R5   R6   (   R   (    (    s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pyt   is_isomorphism…  s    c         C  s   |  j  ƒ  j ƒ  S(   sN  
        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=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pyR"     s    c         C  s+   y |  | j  ƒ  SWn t k
 r& t SXd  S(   N(   R"   R   R.   (   R   R)   (    (    s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pyt   __eq__¶  s    c         C  s   |  | k S(   N(    (   R   R)   (    (    s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pyt   __ne__¼  s    ("   t   __name__t
   __module__t   __doc__R   R   R   R   R   R   R   R   R   R    R!   R#   R$   R&   R(   R*   R,   R-   R/   R1   t   __rmul__R2   t   __truediv__R3   R4   R5   R6   R7   R"   R8   R9   (    (    (    s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pyR	      s@   $										'	 		&			
													t   MatrixHomomorphismc           B  sh   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z RS(   sí  
    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           s£   t  j |  | | ƒ t | ƒ | j k rJ t d | j t | ƒ f ƒ ‚ n  |  j j ‰  t |  j t t	 f ƒ r€ |  j j
 j ‰  n  t ‡  f d †  | Dƒ ƒ |  _ d  S(   Ns#   Need to provide %s elements, got %sc         3  s   |  ] } ˆ  | ƒ Vq d  S(   N(    (   t   .0t   x(   t	   converter(    s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pys	   <genexpr>ç  s    (   R	   R   t   lent   rankR   R   R'   R
   R   R   t	   containert   tuplet   matrix(   R   R   R   RG   (    (   RB   s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pyR   Þ  s    c         C  s…   d d l  m } d „  } t |  j t t f ƒ r= d „  } n  | g  |  j D]1 } g  | | ƒ D] } |  j j | ƒ ^ q] ^ qJ ƒ j	 S(   s=   Helper function which returns a sympy matrix ``self.matrix``.iÿÿÿÿ(   t   Matrixc         S  s   |  S(   N(    (   RA   (    (    s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pyt   <lambda>ì  t    c         S  s   |  j  S(   N(   t   data(   RA   (    (    s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pyRI   î  RJ   (
   t   sympy.matricesRH   R
   R   R   R   RG   R   t   to_sympyt   T(   R   RH   R+   RA   t   y(    (    s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pyt   _sympy_matrixé  s
    	c         C  sË   t  |  j ƒ  ƒ j d ƒ } d |  j |  j f } d t | ƒ } t | ƒ } x( t | d ƒ D] } | | c | 7<q^ W| | d c | 7<x/ t | d d | ƒ D] } | | c | 7<q¤ Wd j | ƒ S(   Ns   
s    : %s -> %st    i   i   (   t   reprRP   t   splitR   R   RC   R   t   join(   R   t   linest   tt   st   nt   i(    (    s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pyt   __repr__ñ  s    c         C  s   t  | |  j |  j ƒ S(   s%   Implementation of domain restriction.(   t   SubModuleHomomorphismR   RG   (   R   R   (    (    s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pyR   ý  s    c         C  s   |  j  |  j | |  j ƒ S(   s'   Implementation of codomain restriction.(   t	   __class__R   RG   (   R   R   (    (    s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pyR     s    c         C  s    |  j  |  j | |  j |  j ƒ S(   s"   Implementation of domain quotient.(   R\   R   R   RG   (   R   R   (    (    s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pyR     s    c         C  sp   |  j  | } | j } t |  j  t ƒ r7 | j j } n  |  j |  j |  j  | g  |  j D] } | | ƒ ^ qW ƒ S(   s$   Implementation of codomain quotient.(   R   R'   R
   R   RE   R\   R   RG   (   R   R   t   QRB   RA   (    (    s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pyR   	  s    	c         C  sE   |  j  |  j |  j g  t |  j | j ƒ D] \ } } | | ^ q( ƒ S(   N(   R\   R   R   t   zipRG   (   R   R)   RA   RO   (    (    s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pyR-     s    c         C  s3   |  j  |  j |  j g  |  j D] } | | ^ q ƒ S(   N(   R\   R   R   RG   (   R   R+   RA   (    (    s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pyR,     s    c         C  s5   |  j  |  j | j g  |  j D] } | | ƒ ^ q ƒ S(   N(   R\   R   R   RG   (   R   R)   RA   (    (    s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pyR*     s    (   R:   R;   R<   R   RP   RZ   R   R   R   R   R-   R,   R*   (    (    (    s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pyR?   À  s   										t   FreeModuleHomomorphismc           B  s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   sð  
    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         C  s>   t  |  j t ƒ r | j } n  t d „  t | |  j ƒ Dƒ ƒ S(   Nc         s  s   |  ] \ } } | | Vq d  S(   N(    (   R@   RA   t   e(    (    s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pys	   <genexpr>3  s    (   R
   R   R   RK   t   sumR^   RG   (   R   R%   (    (    s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pyR&   0  s    c         C  s   |  j  j |  j Œ  S(   N(   R   t	   submoduleRG   (   R   (    (    s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pyR   5  s    c         C  s%   |  j  ƒ  j ƒ  } |  j j | j Œ  S(   N(   R   t   syzygy_moduleR   Rb   t   gens(   R   t   syz(    (    s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pyR   8  s    (   R:   R;   R<   R&   R   R   (    (    (    s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pyR_     s   		R[   c           B  s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s  
    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         C  s>   t  |  j t ƒ r | j } n  t d „  t | |  j ƒ Dƒ ƒ S(   Nc         s  s   |  ] \ } } | | Vq d  S(   N(    (   R@   RA   R`   (    (    s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pys	   <genexpr>X  s    (   R
   R   R   RK   Ra   R^   RG   (   R   R%   (    (    s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pyR&   U  s    c         C  s/   |  j  j g  |  j j D] } |  | ƒ ^ q Œ  S(   N(   R   Rb   R   Rd   (   R   RA   (    (    s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pyR   Z  s    c         C  sW   |  j  ƒ  j ƒ  } |  j j g  | j D]+ } t d „  t | |  j j ƒ Dƒ ƒ ^ q% Œ  S(   Nc         s  s   |  ] \ } } | | Vq d  S(   N(    (   R@   t   xit   gi(    (    s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pys	   <genexpr>`  s    (   R   Rc   R   Rb   Rd   Ra   R^   (   R   Re   RW   (    (    s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pyR   ]  s    	(   R:   R;   R<   R&   R   R   (    (    (    s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pyR[   B  s   		c         C  s†   d „  } | |  ƒ \ } } } } | | ƒ \ } }	 }
 } t  | | g  | D] } | | ƒ ^ qI ƒ j | ƒ j |	 ƒ j |
 ƒ j | ƒ S(   s>  
    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           sµ   t  ˆ  t ƒ r. ˆ  ˆ  ˆ  j ƒ  ‡  f d †  f St  ˆ  t ƒ r_ ˆ  j ˆ  j ˆ  j ‡  f d †  f St  ˆ  t ƒ r“ ˆ  j j ˆ  j ˆ  j ‡  f d †  f Sˆ  j ˆ  ˆ  j ƒ  ‡  f d †  f S(   sÞ   
        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   ˆ  j  |  ƒ S(   N(   R'   (   RA   (   t   module(    s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pyRI   §  RJ   c           s   ˆ  j  |  ƒ j S(   N(   R'   RK   (   RA   (   Rh   (    s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pyRI   ª  RJ   c           s   ˆ  j  j |  ƒ j S(   N(   RE   R'   RK   (   RA   (   Rh   (    s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pyRI   ­  RJ   c           s   ˆ  j  j |  ƒ S(   N(   RE   R'   (   RA   (   Rh   (    s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pyRI   °  RJ   (   R
   R   Rb   R   t   baset   killed_moduleR   RE   (   Rh   (    (   Rh   s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pyt   freepres   s    (   R_   R    R!   R$   R#   (   R   R   RG   Rk   t   SFt   SSt   SQt   _t   TFt   TSt   TQR+   RA   (    (    s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pyt   homomorphismd  s    <	+N(   R<   t
   __future__R    R   t   sympy.core.compatibilityR   t   sympy.polys.agca.modulesR   R   R   R   R   t   sympy.polys.polyerrorsR   t   objectR	   R?   R_   R[   Rs   (    (    (    s=   lib/python2.7/site-packages/sympy/polys/agca/homomorphisms.pyt   <module>   s   (ÿ ­]%"