
~9\c           @  sn  d  d l  m Z m Z d  d l m Z m Z d  d l Z d  d l m Z m	 Z	 m
 Z
 m Z m Z m Z m Z m Z m Z d  d l m Z d  d l m Z m Z m Z m Z d  d l m Z m Z d  d l m Z m Z d  d	 l m Z d  d
 l  m! Z! d  d l" m# Z# d  d l$ m% Z% e& d  Z' d e f d     YZ( d   Z) i e) e  g d 6e) e  g d 6e j* e( <d   Z+ d e f d     YZ, d e( f d     YZ- d e( f d     YZ. d e. f d     YZ/ d e( f d     YZ0 d e0 f d     YZ1 d    Z2 d! e3 f d"     YZ4 d# d$ l5 m6 Z6 d# d% l7 m8 Z8 d# d& l9 m: Z: d# d' l; m< Z< d# d( l= m> Z> d S()   i(   t   print_functiont   division(   t   wrapst   reduceN(	   t   St   Symbolt   Tuplet   Integert   Basict   Exprt   Eqt   Mult   Add(   t   call_highest_priority(   t   ranget
   SYMPY_INTSt   default_sort_keyt   string_types(   t   SympifyErrort   _sympify(   t	   conjugatet   adjoint(   t   KroneckerDelta(   t
   ShapeError(   t   simplify(   t
   filldedentc           s     f d   } | S(   Nc           s"   t        f d    } | S(   Nc           s6   y t  |  }   |  |  SWn t k
 r1  SXd  S(   N(   R   R   (   t   at   b(   t   funct   retval(    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyt   __sympifyit_wrapper   s
    (   R   (   R   R   (   R   (   R   sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyt   deco   s    (    (   t   argR   R   (    (   R   sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyt
   _sympifyit   s    t
   MatrixExprc           B  s  e  Z d  Z e Z d Z e Z e Z d> Z
 e Z e Z e Z e Z e Z e Z e Z e Z d   Z d   Z d   Z e d e  e d  d     Z e d e  e d  d	     Z e d e  e d
  d     Z e d e  e d  d     Z e d e  e d  d     Z e d e  e d  d     Z e d e  e d  d     Z e d e  e d  d     Z  e d e  e d  d     Z! e d e  e d  d     Z" e d e  e d  d     Z# e d e  e d  d     Z$ e# Z% e$ Z& e' d    Z( e' d    Z) e' d    Z* d   Z+ d    Z, d!   Z- d"   Z. d#   Z/ d$   Z0 d%   Z1 d&   Z2 d'   Z3 d(   Z4 d)   Z5 d*   Z6 d+   Z7 d,   Z8 e d-  Z9 d.   Z: d/   Z; e' e; d> d> d0  Z< d1   Z= e= Z> e' d2    Z? d3   Z@ d4   ZA d5   ZB d6   ZC d7   ZD d8   ZE d9   ZF d:   ZG eH d> d> d> d;   ZI d<   ZJ d=   ZK RS(?   s  Superclass for Matrix Expressions

    MatrixExprs represent abstract matrices, linear transformations represented
    within a particular basis.

    Examples
    ========

    >>> from sympy import MatrixSymbol
    >>> A = MatrixSymbol('A', 3, 3)
    >>> y = MatrixSymbol('y', 3, 1)
    >>> x = (A.T*A).I * A * y

    See Also
    ========

    MatrixSymbol, MatAdd, MatMul, Transpose, Inverse
    g      &@c         O  s"   t  t |  } t j |  | |  S(   N(   t   mapR   R   t   __new__(   t   clst   argst   kwargs(    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyR$   I   s    c         C  s   t  t j |   j   S(   N(   t   MatMulR   t   NegativeOnet   doit(   t   self(    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyt   __neg__N   s    c         C  s
   t   d  S(   N(   t   NotImplementedError(   R+   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyt   __abs__Q   s    t   othert   __radd__c         C  s   t  |  | d t j   S(   Nt   check(   t   MatAddt   TrueR*   (   R+   R/   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyt   __add__T   s    R4   c         C  s   t  | |  d t j   S(   NR1   (   R2   R3   R*   (   R+   R/   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyR0   Y   s    t   __rsub__c         C  s   t  |  | d t j   S(   NR1   (   R2   R3   R*   (   R+   R/   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyt   __sub__^   s    R6   c         C  s   t  | |  d t j   S(   NR1   (   R2   R3   R*   (   R+   R/   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyR5   c   s    t   __rmul__c         C  s   t  |  |  j   S(   N(   R(   R*   (   R+   R/   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyt   __mul__h   s    c         C  s   t  |  |  j   S(   N(   R(   R*   (   R+   R/   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyt
   __matmul__m   s    R8   c         C  s   t  | |   j   S(   N(   R(   R*   (   R+   R/   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyR7   r   s    c         C  s   t  | |   j   S(   N(   R(   R*   (   R+   R/   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyt   __rmatmul__w   s    t   __rpow__c         C  sq   |  j  s t d |    n< |  j r) |  S| t j k rE t |  j  S| t j k rX |  St |  |  j	 d t
  S(   Ns   Power of non-square matrix %st   deep(   t	   is_squareR   t   is_IdentityR   t   Zerot   Identityt   rowst   Onet   MatPowR*   t   False(   R+   R/   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyt   __pow__|   s    		RE   c         C  s   t  d   d  S(   Ns   Matrix Power not defined(   R-   (   R+   R/   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyR;      s    t   __rdiv__c         C  s   |  | t  j S(   N(   R   R)   (   R+   R/   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyt   __div__   s    RG   c         C  s   t     d  S(   N(   R-   (   R+   R/   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyRF      s    c         C  s   |  j  d S(   Ni    (   t   shape(   R+   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyRA      s    c         C  s   |  j  d S(   Ni   (   RH   (   R+   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyt   cols   s    c         C  s   |  j  |  j k S(   N(   RA   RI   (   R+   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyR=      s    c         C  s0   d d l  m } d d l m } | | |    S(   Ni(   t   Adjoint(   t	   Transpose(   t"   sympy.matrices.expressions.adjointRJ   t$   sympy.matrices.expressions.transposeRK   (   R+   RJ   RK   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyt   _eval_conjugate   s    c         C  sP   d d l  m } t d  d |  |  j   } |  |  j   d | } | | f S(   Ni(   t   Ii   i   (   t   sympyRO   R   RN   (   R+   RO   t   realt   im(    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyt   as_real_imag   s    c         C  s   d d l  m } | |   S(   Ni(   t   Inverse(   t"   sympy.matrices.expressions.inverseRT   (   R+   RT   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyt   _eval_inverse   s    c         C  s
   t  |   S(   N(   RK   (   R+   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyt   _eval_transpose   s    c         C  s   t  |  |  S(   N(   RC   (   R+   t   exp(    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyt   _eval_power   s    c         K  s=   |  j  r |  S|  j g  |  j D] } t | |  ^ q   Sd  S(   N(   t   is_Atomt	   __class__R&   R   (   R+   R'   t   x(    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyt   _eval_simplify   s    	c         C  s   d d l  m } | |   S(   Ni(   RJ   (   RL   RJ   (   R+   RJ   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyt   _eval_adjoint   s    c         C  s   t  |  |  S(   N(   t   _matrix_derivative(   R+   R\   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyt   _eval_derivative   s    c         C  s   t  j |  | |  S(   N(   R   t   _eval_derivative_n_times(   R+   R\   t   n(    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyRa      s    c         C  s-   | j  |   r t | |   St |  j   Sd  S(   N(   t   hasR_   t
   ZeroMatrixRH   (   R+   R\   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyt   _visit_eval_derivative_scalar   s    c         C  s=   | j  |   r t | |   Sd d l m } | | |   Sd  S(   Ni(   t
   Derivative(   Rc   R_   RP   Rf   (   R+   R\   Rf   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyt   _visit_eval_derivative_array   s    c         C  s   | j  |   S(   N(   Rg   (   R+   t   s(    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyt   _accept_eval_derivative   s    c         K  s   t  d |  j j   d  S(   Ns   Indexing not implemented for %s(   R-   R[   t   __name__(   R+   t   it   jR'   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyt   _entry   s    c         C  s
   t  |   S(   N(   R   (   R+   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyR      s    c         C  s   t  j |  f S(   s2   Efficiently extract the coefficient of a product. (   R   RB   (   R+   t   rational(    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyt   as_coeff_Mul   s    c         C  s
   t  |   S(   N(   R   (   R+   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyR      s    c         C  s   d d l  m } | |   S(   Ni(   t	   transpose(   RM   Rp   (   R+   Rp   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyRp      s    s   Matrix transposition.c         C  s
   |  j    S(   N(   RV   (   R+   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyt   inverse   s    c         C  s
   |  j    S(   N(   Rq   (   R+   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyRO      s    c         C  s|   d   } | |  o{ | |  o{ |  j  d  k sW d | k t k o{ | |  j  k  t k o{ d | k t k o{ | |  j k  t k S(   Nc         S  s   t  |  t t t t f  S(   N(   t
   isinstancet   intR   R   R	   (   t   idx(    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyt   is_valid   s    i    (   RA   t   NoneRD   RI   (   R+   Rk   Rl   Ru   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyt   valid_index   s
    	'c         C  s  t  | t  r? t  | t  r? d d l m } | |  | d  St  | t  rt |  d k r| \ } } t  | t  s t  | t  r d d l m } | |  | |  St |  t |  } } |  j | |  t	 k r |  j
 | |  St d | | f   n t  | t t f  r|  j \ } } t  | t  sLt t d    n  t |  } | | } | | } |  j | |  t	 k r|  j
 | |  St d |   n* t  | t t f  rt t d	    n  t d
 |    d  S(   Ni(   t   MatrixSlicei    i   i   s   Invalid indices (%s, %s)so   
                    Single indexing is only supported when the number
                    of columns is known.s   Invalid index %ssr   
                    Only integers may be used when addressing the matrix
                    with a single index.s   Invalid index, wanted %s[i,j](   i    Ni   (   Rr   t   tuplet   slicet    sympy.matrices.expressions.sliceRx   Rv   t   lenR   Rw   RD   Rm   t
   IndexErrorR   R   RH   R   R   R	   (   R+   t   keyRx   Rk   Rl   RA   RI   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyt   __getitem__  s6    !

c         C  s\   d d l  m } | g  t |  j  D]2 } g  t |  j  D] } |  | | f ^ q9 ^ q#  S(   s  
        Returns a dense Matrix with elements represented explicitly

        Returns an object of type ImmutableDenseMatrix.

        Examples
        ========

        >>> from sympy import Identity
        >>> I = Identity(3)
        >>> I
        I
        >>> I.as_explicit()
        Matrix([
        [1, 0, 0],
        [0, 1, 0],
        [0, 0, 1]])

        See Also
        ========
        as_mutable: returns mutable Matrix type

        i(   t   ImmutableDenseMatrix(   t   sympy.matrices.immutableR   R   RA   RI   (   R+   R   Rk   Rl   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyt   as_explicit&  s    c         C  s   |  j    j   S(   s  
        Returns a dense, mutable matrix with elements represented explicitly

        Examples
        ========

        >>> from sympy import Identity
        >>> I = Identity(3)
        >>> I
        I
        >>> I.shape
        (3, 3)
        >>> I.as_mutable()
        Matrix([
        [1, 0, 0],
        [0, 1, 0],
        [0, 0, 1]])

        See Also
        ========
        as_explicit: returns ImmutableDenseMatrix
        (   R   t
   as_mutable(   R+   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyR   C  s    c         C  sw   d d l  m } | |  j d t } xK t |  j  D]: } x1 t |  j  D]  } |  | | f | | | f <qK Wq5 W| S(   Ni(   t   emptyt   dtype(   t   numpyR   RH   t   objectR   RA   RI   (   R+   R   R   Rk   Rl   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyt	   __array__\  s    "c         C  s   |  j    j |  S(   s   
        Test elementwise equality between matrices, potentially of different
        types

        >>> from sympy import Identity, eye
        >>> Identity(3).equals(eye(3))
        True
        (   R   t   equals(   R+   R/   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyR   d  s    	c         C  s   |  S(   N(    (   R+   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyt   canonicalizeo  s    c         C  s   d t  |   f S(   Ni   (   R(   (   R+   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyt   as_coeff_mmulr  s    c   
   
     s2  d d l  m  m  m   m  m 	 m  d d l m     	 f d    i           	 f	 d    |   } t	 |   \ } }  j
 |  } t |  d k s t t |   d g k r | S| d k rx$ | D] } | d k	 r | }	 Pq q W | |	  S | | |  Sd S(   s  
        Parse expression of matrices with explicitly summed indices into a
        matrix expression without indices, if possible.

        This transformation expressed in mathematical notation:

        `\sum_{j=0}^{N-1} A_{i,j} B_{j,k} \Longrightarrow \mathbf{A}\cdot \mathbf{B}`

        Optional parameter ``first_index``: specify which free index to use as
        the index starting the expression.

        Examples
        ========

        >>> from sympy import MatrixSymbol, MatrixExpr, Sum, Symbol
        >>> from sympy.abc import i, j, k, l, N
        >>> A = MatrixSymbol("A", N, N)
        >>> B = MatrixSymbol("B", N, N)
        >>> expr = Sum(A[i, j]*B[j, k], (j, 0, N-1))
        >>> MatrixExpr.from_index_summation(expr)
        A*B

        Transposition is detected:

        >>> expr = Sum(A[j, i]*B[j, k], (j, 0, N-1))
        >>> MatrixExpr.from_index_summation(expr)
        A.T*B

        Detect the trace:

        >>> expr = Sum(A[i, i], (i, 0, N-1))
        >>> MatrixExpr.from_index_summation(expr)
        Trace(A)

        More complicated expressions:

        >>> expr = Sum(A[i, j]*B[k, j]*A[l, k], (j, 0, N-1), (k, 0, N-1))
        >>> MatrixExpr.from_index_summation(expr)
        A*B.T*A.T
        i(   t   SumR   R   R(   Rp   t   trace(   t	   bottom_upc           sm     f d   } |  j  | d  d    }  |  j  | d   f d    }     f d    } | |   S(   Nc           s      f d   } | S(   Nc           sn   t  |  t  s t S|  j    k r* t S|  j d  d k rj |  j d j d  d k rc t St Sn  t S(   Ni   i    i   i   (   Rr   t   MatrixElementRD   R&   RH   R3   (   R\   (   t   i1t   pos(    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyR     s    (    (   R   R   (   R   (   R   sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyt
   repl_match  s    i   c         S  s   |  j  d S(   Ni    (   R&   (   R\   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyt   <lambda>  t    i   c           s     |  j  d  S(   Ni    (   R&   (   R\   (   Rp   (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyR     R   c           s,   t  |     f  r( t d   |  j  S|  S(   Nc         S  s   |  | S(   N(    (   R   R   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyR     R   (   Rr   R   R&   (   R\   (   R(   R   (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyR     R   (   t   replace(   t   exprR   t   i2R   t   rule(   R(   R   R   Rp   (   R   sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyt   remove_matelement  s    c   +        se  |  j  rg  } g  } g  } i  } g  } d } g  } xr |  j D]g }	  |	 |  }
 t |
 t  sg t  t |
 t  r x+ |
 D] } | j |  q} Wq= | j |
  q= Wx | D] \ } } | d  k r | j |  q n  t | t  r | j d } n  | j |  | j |  | j d  g t |   xm t	 |  D]_ \ } } | | k r| | } | | | | <| | f | | d | d <n  | | f | | <q:W| d 7} q Wd } i  } x?| t |  k  rx? t	 |  D]1 \ } } d  | k r| | j
 d   f } PqqW| } g  } | | d | d } x t r| \ } } | | d k r| d d k r| j  | |   q| j | |  n  | | d | } | d 7} d | | <| d  k r| | d | } | | | | f <Pn  | } q3WqWt d   | D  }  f d   | j   D }  j |  d  f g g  | j   D]0 \ \ } } } t | | |  | | f f ^ qMS|  j ryg  |  j D] }  |  ^ q} t j t  } x | D]w } d }  xh | D]` \ }! }" |" d  k r|! }  qn  t t |" d t  }" | |" j |   |! |"   d }  qWqWg  | j   D]* \ }# }$ t   j |$  |#  |# f ^ qKSt |  t  r|  j \ }% }&  d  k	 rt  d  }' n	 t j }' t |' |% |&  |% |& f f g St |  t  r|  j \ }( }% }& |% | k ri| |% \ }) }* |) d k s>|( j d |* d k rit d j |) |* f |( j d    qin  |& | k r| |& \ }) }* |) d k s|( j d |* d k rt d j |) |* f |( j d    qn  |% |& k r|% | k r |(  d  f g St |( |% |&  |% |& f f g St |    rT |  j d d	 d
   |  j d D S|  d  f g Sd  S(   Ni    i   i   ic         s  s"   |  ] } | D] } | Vq q d  S(   N(    (   t   .0Rk   Rl   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pys	   <genexpr>  s    c           sD   i  |  ]: \ } } t  |  d  k r3   j |  n | d |  q S(   i   i    (   R|   t   fromiter(   R   t   kt   v(   R(   (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pys
   <dictcomp>  s   	 R~   s&   index range mismatch: {0} vs. (0, {1})t   index_rangesc         S  s!   i  |  ] } | d  | d  q S(   i   i    (    (   R   Rk   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pys
   <dictcomp>"  s   	 (   ii(   t   is_MulR&   Rr   t   listt   AssertionErrort   appendRv   R   R|   t	   enumeratet   indexR3   t   itemsR   t   is_Addt   collectionst   defaultdictRy   t   sortedR   R   R@   R   RB   RH   t
   ValueErrort   format(+   R   R   t
   nonmatargst   pos_argt   pos_indt   dlinkst   link_indt   countert   args_indR    t   retvalsRk   t
   arg_symbolt   arg_indicest   indt   other_it   counter2t   linest   et   line_start_indext   cur_ind_post   cur_linet   index1t   dt   rt   next_ind_post   index2t   ret_indicesRl   R   t   rest
   res_addendt   scalart   elemt   indicesR   R   R   R   t   identityt   matrix_symbolt   r1t   r2(	   R   R(   R   R   t
   dimensionst   recurse_exprR   R   Rp   (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyR     s    	
	

B	";	#	"#	"i    N(   RP   R   R   R   R(   Rp   R   t   sympy.strategies.traverseR   t   zipR   R|   R   t   setRv   (
   R   t   first_indext
   last_indexR   R   t   factorsR   t   retexprRk   t   ind0(    (
   R   R(   R   R   R   R   R   R   R   Rp   sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyt   from_index_summationu  s     *.*k-c         C  s   d d l  m } | | |   S(   Ni   (   t   ElementwiseApplyFunction(   t	   applyfuncR   (   R+   R   R   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyR   5  s    c         C  sM   t  | t  s t S|  j | j k r) t S|  | j r: t St |  | d t S(   Nt   evaluate(   Rr   R"   RD   RH   t   is_ZeroMatrixR3   R
   (   R+   R/   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyt   _eval_Eq9  s    N(L   Rj   t
   __module__t   __doc__RD   t	   _iterablet   _op_priorityR3   t	   is_Matrixt   is_MatrixExprRv   R>   t
   is_Inverset   is_TransposeR   t	   is_MatAddt	   is_MatMult   is_commutativet	   is_numbert	   is_symbolR$   R,   R.   R!   t   NotImplementedR   R4   R0   R6   R5   R8   R9   R7   R:   RE   R;   RG   RF   t   __truediv__t   __rtruediv__t   propertyRA   RI   R=   RN   RS   RV   RW   RY   R]   R^   R`   Ra   Re   Rg   Ri   Rm   R   Ro   R   Rp   t   TRq   t   invRO   Rw   R   R   R   R   R   R   R   t   staticmethodR   R   R   (    (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyR"   !   s   																						#							c           s     f d   } | S(   Nc           s+  i t  t 6t t 6  } g  } g  } x= |  j D]2 } t | t  rS | j |  q. | j |  q. W| sw   j |  S| r	  t k r xz t	 t
 |   D]= } | | j s | | j   j |   | | <g  } Pq q Wq	  j | | |   j d t  g  Sn  |   j |  |  j d t  S(   NR<   (   R(   R   R2   R   R&   Rr   R"   R   t
   _from_argsR   R|   R   R8   R*   RD   (   R   t	   mat_classt   nonmatricest   matricest   termRk   (   R%   (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyt   _postprocessorC  s$     )(    (   R%   R   (    (   R%   sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyt   get_postprocessorB  s    !R   R   c         C  s   d d l  m } |  j |  } g  | D] } | j   ^ q& } t t |   d k s\ t  | d } | d k r t j g  | D] } | j	   ^ q  S| |  |  S(   Ni(   Rf   i   i    i   (
   RP   Rf   t   _eval_derivative_matrix_linest   rankR|   R   R   R   R   t   matrix_form(   R   R\   Rf   R   Rk   t   ranksR   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyR_   l  s    
&R   c           B  sq   e  Z e d     Z e d    Z e d    Z e Z e Z e Z	 d   Z
 d   Z e d    Z d   Z RS(   c         C  s   |  j  d S(   Ni    (   R&   (   R+   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyR   {  R   c         C  s   |  j  d S(   Ni   (   R&   (   R+   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyR   |  R   c         C  s   |  j  d S(   Ni   (   R&   (   R+   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyR   }  R   c         C  s   t  t | | f  \ } } d d l m } t | | f  r` | j r` | j r` | | | f Sn  t | t  r~ t |  } n  t |  } t j	 |  | | |  } | S(   Ni(   t
   MatrixBase(
   R#   R   RP   R   Rr   t
   is_IntegerR   R   R	   R$   (   R%   t   nameRb   t   mR   t   obj(    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyR$     s    c         K  sc   | j  d t  } | r@ g  |  j D] } | j |   ^ q" } n	 |  j } | d | d | d f S(   NR<   i    i   i   (   t   getR3   R&   R*   (   R+   R'   R<   R    R&   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyR*     s
    (	c         C  s   |  j  d S(   Ni   (   R&   (   R+   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyR     s    c         C  s  d d l  m } m } m } t | t  st d d l  m } t |  j |  rm |  j j |  |  j	 |  j
 f St j S|  j d } | | j d k r t |  j d | j d  t |  j d | j d  St | t  rz|  j d \ } } | d d | \ }	 }
 | j d } | j \ } } | | | |	 f | |	 |
 f j |  | |
 | f |	 d | d f |
 d | d f  S|  j | j d  rd  St j S(	   Ni(   R   t   symbolst   Dummy(   R   i    i   i   s   z1, z2R%   (   RP   R   R  R  Rr   R   R   t   parentt   diffRk   Rl   R   R?   R&   R   RT   RH   Rc   Rv   (   R+   R   R   R  R  R   t   MRk   Rl   R   R   t   YR   R   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyR`     s$     6Z(   Rj   R   R   R  Rk   Rl   R3   t	   _diff_wrtR   R   R$   R*   R   R`   (    (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyR   z  s   		t   MatrixSymbolc           B  s   e  Z d  Z e Z e Z e Z d   Z d   Z	 e
 d    Z e
 d    Z d   Z d   Z d   Z e
 d    Z d	   Z d
   Z d   Z RS(   s  Symbolic representation of a Matrix object

    Creates a SymPy Symbol to represent a Matrix. This matrix has a shape and
    can be included in Matrix Expressions

    Examples
    ========

    >>> from sympy import MatrixSymbol, Identity
    >>> A = MatrixSymbol('A', 3, 4) # A 3 by 4 Matrix
    >>> B = MatrixSymbol('B', 4, 3) # A 4 by 3 Matrix
    >>> A.shape
    (3, 4)
    >>> 2*A*B + Identity(3)
    I + 2*A*B
    c         C  sS   t  |  t  |  } } t | t  r7 t |  } n  t j |  | | |  } | S(   N(   R   Rr   R   R   R   R$   (   R%   R   Rb   R   R   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyR$     s
    c         C  s   |  j  |  j f S(   N(   R   RH   (   R+   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyt   _hashable_content  s    c         C  s   |  j  d d !S(   Ni   i   (   R&   (   R+   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyRH     s    c         C  s   |  j  d j S(   Ni    (   R&   R   (   R+   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyR     s    c         C  s+   t  |  j   j | |  } t |  j |  S(   N(   R   RH   t   _subsR	  R   (   R+   t   oldt   newRH   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyt
   _eval_subs  s    c         G  s   t  d |  j   d  S(   Ns   %s object is not callable(   t	   TypeErrorR[   (   R+   R&   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyt   __call__  s    c         K  s   t  |  | |  S(   N(   R   (   R+   Rk   Rl   R'   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyRm     s    c         C  s   t  |  f  S(   N(   R   (   R+   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyt   free_symbols  s    c         K  sS   | j  d t  rK t |   |  j |  j d j |   |  j d j |    S|  Sd  S(   NR<   i   i   (   R  R3   t   typeR   R&   R*   (   R+   t   hints(    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyR*     s    "c         K  s   |  S(   N(    (   R+   R'   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyR]     s    c         C  s   |  | k rP t  t | j d |  j d  t | j d |  j d  d t g St |  j d  } t |  j d  } t  d | d | d t  g Sd  S(   Ni    i   t
   transposedt   firstt   second(   t   _LeftRightArgsRd   RH   RD   R@   (   R+   R\   R  R  (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyR     s    
(   Rj   R   R   RD   R   R3   R   R  R$   R
  R   RH   R   R  R  Rm   R  R*   R]   R   (    (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyR	    s   							R@   c           B  s   e  Z d  Z e Z d   Z e d    Z e d    Z e d    Z	 e d    Z
 d   Z d   Z d   Z d	   Z d
   Z d   Z RS(   s   The Matrix Identity I - multiplicative identity

    Examples
    ========

    >>> from sympy.matrices import Identity, MatrixSymbol
    >>> A = MatrixSymbol('A', 3, 5)
    >>> I = Identity(3)
    >>> I*A
    A
    c         C  s   t  t |   j |  t |   S(   N(   t   superR@   R$   R   (   R%   Rb   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyR$     s    c         C  s   |  j  d S(   Ni    (   R&   (   R+   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyRA     s    c         C  s   |  j  d S(   Ni    (   R&   (   R+   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyRI     s    c         C  s   |  j  d |  j  d f S(   Ni    (   R&   (   R+   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyRH      s    c         C  s   t  S(   N(   R3   (   R+   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyR=   $  s    c         C  s   |  S(   N(    (   R+   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyRW   (  s    c         C  s   |  j  S(   N(   RA   (   R+   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyt   _eval_trace+  s    c         C  s   |  S(   N(    (   R+   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyRV   .  s    c         C  s   |  S(   N(    (   R+   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyR   1  s    c         K  sH   t  | |  } | t j k r% t j S| t j k r; t j St | |  S(   N(   R
   R   t   trueRB   t   falseR?   R   (   R+   Rk   Rl   R'   t   eq(    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyRm   4  s    c         C  s   t  j S(   N(   R   RB   (   R+   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyt   _eval_determinant<  s    (   Rj   R   R   R3   R>   R$   R   RA   RI   RH   R=   RW   R  RV   R   Rm   R  (    (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyR@     s   						t   GenericIdentityc           B  s_   e  Z d  Z d   Z e d    Z e d    Z e d    Z d   Z d   Z	 d   Z
 RS(   s   
    An identity matrix without a specified shape

    This exists primarily so MatMul() with no arguments can return something
    meaningful.
    c         C  s   t  t |   j |   S(   N(   R  R@   R$   (   R%   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyR$   F  s    c         C  s   t  d   d  S(   Ns/   GenericIdentity does not have a specified shape(   R  (   R+   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyRA   K  s    c         C  s   t  d   d  S(   Ns/   GenericIdentity does not have a specified shape(   R  (   R+   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyRI   O  s    c         C  s   t  d   d  S(   Ns/   GenericIdentity does not have a specified shape(   R  (   R+   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyRH   S  s    c         C  s   t  | t  S(   N(   Rr   R  (   R+   R/   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyt   __eq__X  s    c         C  s   |  | k S(   N(    (   R+   R/   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyt   __ne__[  s    c         C  s   t  t |   j   S(   N(   R  R  t   __hash__(   R+   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyR!  ^  s    (   Rj   R   R   R$   R   RA   RI   RH   R  R   R!  (    (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyR  ?  s   			Rd   c           B  s   e  Z d  Z e Z d   Z e d    Z e d e	  e
 d  d     Z d   Z d   Z d   Z d	   Z d
   Z d   Z e Z RS(   s   The Matrix Zero 0 - additive identity

    Examples
    ========

    >>> from sympy import MatrixSymbol, ZeroMatrix
    >>> A = MatrixSymbol('A', 3, 5)
    >>> Z = ZeroMatrix(3, 5)
    >>> A + Z
    A
    >>> Z*A.T
    0
    c         C  s   t  t |   j |  | |  S(   N(   R  Rd   R$   (   R%   R   Rb   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyR$   r  s    c         C  s   |  j  d |  j  d f S(   Ni    i   (   R&   (   R+   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyRH   u  s    R/   R;   c         C  sa   | d k r) |  j  r) t d |    n  | d k rB t |  j  S| d k  r] t d   n  |  S(   Ni   s   Power of non-square matrix %si    s    Matrix det == 0; not invertible.(   R=   R   R@   RA   R   (   R+   R/   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyRE   y  s    c         C  s   t  |  j |  j  S(   N(   Rd   RI   RA   (   R+   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyRW     s    c         C  s   t  j S(   N(   R   R?   (   R+   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyR    s    c         C  s   t  j S(   N(   R   R?   (   R+   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyR    s    c         C  s   |  S(   N(    (   R+   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyR     s    c         K  s   t  j S(   N(   R   R?   (   R+   Rk   Rl   R'   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyRm     s    c         C  s   t  S(   N(   RD   (   R+   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyt   __nonzero__  s    (   Rj   R   R   R3   R   R$   R   RH   R!   R   R   RE   RW   R  R  R   Rm   R"  t   __bool__(    (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyRd   b  s   	
						t   GenericZeroMatrixc           B  s_   e  Z d  Z d   Z e d    Z e d    Z e d    Z d   Z d   Z	 d   Z
 RS(   s   
    A zero matrix without a specified shape

    This exists primarily so MatAdd() with no arguments can return something
    meaningful.
    c         C  s   t  t |   j |   S(   N(   R  Rd   R$   (   R%   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyR$     s    c         C  s   t  d   d  S(   Ns1   GenericZeroMatrix does not have a specified shape(   R  (   R+   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyRA     s    c         C  s   t  d   d  S(   Ns1   GenericZeroMatrix does not have a specified shape(   R  (   R+   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyRI     s    c         C  s   t  d   d  S(   Ns1   GenericZeroMatrix does not have a specified shape(   R  (   R+   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyRH     s    c         C  s   t  | t  S(   N(   Rr   R$  (   R+   R/   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyR    s    c         C  s   |  | k S(   N(    (   R+   R/   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyR     s    c         C  s   t  t |   j   S(   N(   R  R$  R!  (   R+   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyR!    s    (   Rj   R   R   R$   R   RA   RI   RH   R  R   R!  (    (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyR$    s   			c         C  s#   g  |  j  D] } | j r
 | ^ q
 S(   N(   R  R   (   R   t   sym(    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyt   matrix_symbols  s    R  c           B  sh   e  Z d  Z e j e d  Z d   Z d   Z d   Z	 d   Z
 d   Z d   Z d   Z d	   Z RS(
   s  
    Helper class to compute matrix derivatives.

    The logic: when an expression is derived by a matrix `X_{mn}`, two lines of
    matrix multiplications are created: the one contracted to `m` (first line),
    and the one contracted to `n` (second line).

    Transposition flips the side by which new matrices are connected to the
    lines.

    The trace connects the end of the two lines.
    c         C  s(   | |  _  | |  _ | |  _ | |  _ d  S(   N(   R  R  t   higherR  (   R+   R  R  R'  R  (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyt   __init__  s    			c         C  sb   d |  j  t |  j  t  r' |  j  j n d  |  j t |  j t  rN |  j j n d  |  j |  j f S(   NsE   _LeftRightArgs(first=%s[%s], second=%s[%s], higher=%s, transposed=%s)(   R  Rr   R"   RH   Rv   R  R'  R  (   R+   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyt   __repr__  s
    ''c         C  s   |  j  |  _  |  S(   N(   R  (   R+   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyRp     s    c         C  s   |  j  d k r- |  j d k r- t d   n  |  j  t d  k rL |  j j S|  j t d  k rh |  j  S|  j  d k r |  j  |  j j S|  j Sd  S(   Ni   s.   higher dimensional array cannot be represented(   R  R'  R   R@   R  R   (   R+   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyR     s    
c         C  s   d } |  j  d k rG | t g  |  j  j D] } | d k ^ q(  7} n  |  j d k r | t g  |  j j D] } | d k ^ qi  7} n  |  j d k r | d 7} n  | S(   sl   
        Number of dimensions different from trivial (warning: not related to
        matrix rank).
        i    i   i   (   R  t   sumRH   R  R'  (   R+   R   Rk   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyR     s    22c         C  s   |  j  | 9_  d  S(   N(   R  (   R+   R/   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyt   append_first  s    c         C  s   |  j  | 9_  d  S(   N(   R  (   R+   R/   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyt   append_second   s    c         C  s   t  |  j |  j |  j f  S(   N(   t   hashR  R  R  (   R+   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyR!    s    c         C  sG   t  | t  s t S|  j | j k oF |  j | j k oF |  j | j k S(   N(   Rr   R  RD   R  R  R  (   R+   R/   (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyR    s    (   Rj   R   R   R   RB   RD   R(  R)  Rp   R   R   R+  R,  R!  R  (    (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyR    s   							i   (   R(   (   R2   (   RC   (   RK   (   RT   (?   t
   __future__R    R   t	   functoolsR   R   R   t
   sympy.coreR   R   R   R   R   R	   R
   R   R   t   sympy.core.decoratorsR   t   sympy.core.compatibilityR   R   R   R   t   sympy.core.sympifyR   R   t   sympy.functionsR   R   t(   sympy.functions.special.tensor_functionsR   t   sympy.matricesR   t   sympy.simplifyR   t   sympy.utilities.miscR   Rv   R!   R"   R   t"   _constructor_postprocessor_mappingR_   R   R	  R@   R  Rd   R$  R&  R   R  t   matmulR(   t   mataddR2   t   matpowRC   Rp   RK   Rq   RT   (    (    (    sA   lib/python2.7/site-packages/sympy/matrices/expressions/matexpr.pyt   <module>   sB   @"  #	$	;Q9#7$	K