ó
¡¼™\c           @  sd   d  d l  m Z d  d l m Z d  d l m Z d  d l m Z d e f d „  ƒ  YZ e Z	 Z
 d S(   iÿÿÿÿ(   t   print_function(   t   MutableDenseMatrix(   t   Poly(   t   EXt   MutablePolyDenseMatrixc           B  sG   e  Z d  Z d Z e d „  ƒ Z d „  Z d „  Z d „  Z d „  Z	 RS(   s  
    A mutable matrix of objects from poly module or to operate with them.

    Examples
    ========

    >>> from sympy.polys.polymatrix import PolyMatrix
    >>> from sympy import Symbol, Poly, ZZ
    >>> x = Symbol('x')
    >>> pm1 = PolyMatrix([[Poly(x**2, x), Poly(-x, x)], [Poly(x**3, x), Poly(-1 + x, x)]])
    >>> v1 = PolyMatrix([[1, 0], [-1, 0]])
    >>> pm1*v1
    Matrix([
    [    Poly(x**2 + x, x, domain='ZZ'), Poly(0, x, domain='ZZ')],
    [Poly(x**3 - x + 1, x, domain='ZZ'), Poly(0, x, domain='ZZ')]])

    >>> pm1.ring
    ZZ[x]

    >>> v1*pm1
    Matrix([
    [ Poly(x**2, x, domain='ZZ'), Poly(-x, x, domain='ZZ')],
    [Poly(-x**2, x, domain='ZZ'),  Poly(x, x, domain='ZZ')]])

    >>> pm2 = PolyMatrix([[Poly(x**2, x, domain='QQ'), Poly(0, x, domain='QQ'), Poly(1, x, domain='QQ'),             Poly(x**3, x, domain='QQ'), Poly(0, x, domain='QQ'), Poly(-x**3, x, domain='QQ')]])
    >>> v2 = PolyMatrix([1, 0, 0, 0, 0, 0], ring=ZZ)
    >>> v2.ring
    ZZ
    >>> pm2*v2
    Matrix([[Poly(x**2, x, domain='QQ')]])

    i
   c         C  s   |  S(   N(    (   t   x(    (    s5   lib/python2.7/site-packages/sympy/polys/polymatrix.pyt   <lambda>-   t    c         O  s­   | j  d t ƒ } t d „  |  j Dƒ ƒ r  |  j r  t g  |  j D] } | j | j ^ qA ƒ } | d } x3 t d t | ƒ ƒ D] } | j	 | | ƒ } q€ Wn  | |  _
 d  S(   Nt   ringc         s  s   |  ] } t  | t ƒ Vq d  S(   N(   t
   isinstanceR   (   t   .0t   p(    (    s5   lib/python2.7/site-packages/sympy/polys/polymatrix.pys	   <genexpr>3   s    i    i   (   t   getR   t   allt   _matt   tuplet   domaint   genst   ranget   lent   unifyR   (   t   selft   argst   kwargsR   R   R   t   i(    (    s5   lib/python2.7/site-packages/sympy/polys/polymatrix.pyt   __init__/   s    ",
c           s0  |  j  |  j } } | j  | j } } | | } |  j  } | j } d g | | }	 |  j d k r| j  d k r|  j ‰  | j ‰ x‘ t t |	 ƒ ƒ D]z }
 |
 | |
 | } } t | | | | d ƒ } t | | | ƒ } ‡  ‡ f d †  t | | ƒ Dƒ } t | ƒ |	 |
 <q– Wn  |  j | | |	 d t ƒS(   Ni    i   c         3  s'   |  ] \ } } ˆ  | ˆ | Vq d  S(   N(    (   R
   t   at   b(   t   matt	   other_mat(    s5   lib/python2.7/site-packages/sympy/polys/polymatrix.pys	   <genexpr>J   s    t   copy(	   t   rowst   colsR   R   R   t   zipt   sumt	   __class__t   False(   R   t   othert	   self_rowst	   self_colst
   other_rowst
   other_colst	   other_lent   new_mat_rowst   new_mat_colst   new_matR   t   rowt   colt   row_indicest   col_indicest   vec(    (   R   R   s5   lib/python2.7/site-packages/sympy/polys/polymatrix.pyt   _eval_matrix_mul:   s     
				"c         C  sj   g  |  j  D]; } t | t ƒ r; t | j ƒ  | | j Œ n | | ^ q
 } |  j |  j |  j | d t ƒS(   NR   (	   R   R	   R   t   as_exprR   R#   R   R    R$   (   R   R%   R   R   (    (    s5   lib/python2.7/site-packages/sympy/polys/polymatrix.pyt   _eval_scalar_mulP   s    Kc         C  sj   g  |  j  D]; } t | t ƒ r; t | | j ƒ  | j Œ n | | ^ q
 } |  j |  j |  j | d t ƒS(   NR   (	   R   R	   R   R4   R   R#   R   R    R$   (   R   R%   R   R   (    (    s5   lib/python2.7/site-packages/sympy/polys/polymatrix.pyt   _eval_scalar_rmulT   s    K(
   t   __name__t
   __module__t   __doc__t   _class_priorityt   staticmethodt   _sympifyR   R3   R5   R6   (    (    (    s5   lib/python2.7/site-packages/sympy/polys/polymatrix.pyR   	   s   !			N(   t
   __future__R    t   sympy.matrices.denseR   t   sympy.polys.polytoolsR   t   sympy.polys.domainsR   R   t   MutablePolyMatrixt
   PolyMatrix(    (    (    s5   lib/python2.7/site-packages/sympy/polys/polymatrix.pyt   <module>   s
   P