
~9\c           @  s/  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
 d  d l 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 d  d	 l m Z d  d
 l m Z m Z m Z d  d l m Z d  d l  m! Z! d  d l" m# Z# m$ Z$ m% Z% m& Z& d  d l' m( Z( d  d l) m* Z* m+ Z+ d  d l, m- Z- m. Z. m/ Z/ d  d l0 m1 Z1 m2 Z2 m3 Z3 d  d l4 m5 Z5 d  d l6 m7 Z7 d  d l6 m8 Z9 d  d l: m; Z; d  d l< m= Z= m> Z> d d l? m@ Z@ mA ZA mB ZB mC ZC d   ZD d   ZE d e$ e f d     YZF d e@ f d     YZG d eG f d      YZH d! eH f d"     YZI d# eI f d$     YZJ d% e@ f d&     YZK d' e@ f d(     YZL d) eL eK eJ e@ f d*     YZM e d+ d, d- d. d/ d0  d1    ZN e d+ d, d/ d0 d- d2  eO d3   ZP eD e9 d4  ZQ eD eO d5  ZR d6 S(7   i(   t   divisiont   print_function(   t   FunctionType(   t   prec_to_dps(   t   Add(   t   Basic(   t   Callablet   NotIterablet   as_intt   default_sort_keyt   is_sequencet   ranget   reducet   string_types(   t
   deprecated(   t   Expr(   t
   expand_mul(   t   Floatt   Integert   mod_inverse(   t   Pow(   t   S(   t   Dummyt   Symbolt   _uniquely_named_symbolt   symbols(   t   sympify(   t   expt	   factorial(   t   Maxt   Mint   sqrt(   t   PurePolyt   cancelt   roots(   t   sstr(   t	   nsimplify(   t   simplify(   t   SymPyDeprecationWarning(   t   flattent   numbered_symbolsi   (   t   MatrixCommont   MatrixErrort   NonSquareMatrixErrort
   ShapeErrorc         C  s   t  |  d d  S(   s   Returns True if x is zero.t   is_zeroN(   t   getattrt   None(   t   x(    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   _iszero!   s    c         C  s   t  |   d k S(   sN   Tests by expand_mul only, suitable for polynomials and rational
    functions.i    (   R   (   R0   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   _is_zero_after_expand_mul&   s    t   DeferredVectorc           B  s)   e  Z d  Z d   Z d   Z d   Z RS(   s4  A vector whose components are deferred (e.g. for use with lambdify)

    Examples
    ========

    >>> from sympy import DeferredVector, lambdify
    >>> X = DeferredVector( 'X' )
    >>> X
    X
    >>> expr = (X[0] + 2, X[2] + 3)
    >>> func = lambdify( X, expr)
    >>> func( [1, 2, 3] )
    (3, 6)
    c         C  sM   | d k r d } n  | d k  r0 t  d   n  d |  j | f } t |  S(   Ni    s!   DeferredVector index out of ranges   %s[%d](   t
   IndexErrort   nameR   (   t   selft   it   component_name(    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   __getitem__<   s    	c         C  s
   t  |   S(   N(   R#   (   R6   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   __str__D   s    c         C  s   d |  j  S(   Ns   DeferredVector('%s')(   R5   (   R6   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   __repr__G   s    (   t   __name__t
   __module__t   __doc__R9   R:   R;   (    (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyR3   ,   s   		t   MatrixDeterminantc           B  s   e  Z d  Z d   Z d   Z e d  Z d   Z e d d  Z
 d   Z d d  Z d	 e d
  Z d d  Z d d  Z d d d  Z d d  Z d   Z RS(   sV   Provides basic matrix determinant operations.
    Should not be instantiated directly.c   	        s5  |  j  d k r7 |  j d k r7 |  j d d t j g  S|  d |  d d d  f } } |  d d  d f |  d d  d d  f } } | g   x0 t |  j  d  D] }   j |   |  q Wg    D] } | | d ^ q   t j | g       f d   } |  j |  j d |  j  |  } | | f S(   s   Return (A,T) where T the Toeplitz matrix used in the Berkowitz algorithm
        corresponding to ``self`` and A is the first principal submatrix.i    i   Ni   c           s   | |  k r t  j S  |  | S(   N(   R   t   Zero(   R7   t   j(   t   diags(    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   entrys   s    (   i    i    (   i    i    (   t   rowst   colst   _newR   t   OneR   t   append(	   R6   t   at   Rt   Ct   AR7   t   dRC   t   toeplitz(    (   RB   s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   _eval_berkowitz_toeplitz_matrixO   s    !3	"c         C  s   |  j  d k r7 |  j d k r7 |  j d d t j g  S|  j  d k rv |  j d k rv |  j d d t j |  d g  S|  j   \ } } | | j   S(   s   Run the Berkowitz algorithm and return a vector whose entries
            are the coefficients of the characteristic polynomial of ``self``.

            Given N x N matrix, efficiently compute
            coefficients of characteristic polynomials of ``self``
            without division in the ground domain.

            This method is particularly useful for computing determinant,
            principal minors and characteristic polynomial when ``self``
            has complicated coefficients e.g. polynomials. Semi-direct
            usage of this algorithm is also important in computing
            efficiently sub-resultant PRS.

            Assuming that M is a square matrix of dimension N x N and
            I is N x N identity matrix, then the Berkowitz vector is
            an N x 1 vector whose entries are coefficients of the
            polynomial

                           charpoly(M) = det(t*I - M)

            As a consequence, all polynomials generated by Berkowitz
            algorithm are monic.

           For more information on the implemented algorithm refer to:

           [1] S.J. Berkowitz, On computing the determinant in small
               parallel time using a small number of processors, ACM,
               Information Processing Letters 18, 1984, pp. 147-150

           [2] M. Keber, Division-Free computation of sub-resultants
               using Bezout matrices, Tech. Report MPI-I-2006-1-006,
               Saarbrucken, 2006
        i    i   i   (   i    i    (   RD   RE   RF   R   RG   RO   t   _eval_berkowitz_vector(   R6   t   submatRN   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyRP   {   s    $!c           s(   d     f d    t       S(   s  Compute matrix determinant using Bareiss' fraction-free
        algorithm which is an extension of the well known Gaussian
        elimination method. This approach is best suited for dense
        symbolic matrices and will result in a determinant with
        minimal number of fractions. It means that less term
        rewriting is needed on resulting formulae.

        TODO: Implement algorithm for sparse matrices (SFF),
        http://www.eecis.udel.edu/~saunders/papers/sffge/it5.ps.
        i   c           s   j  d k r t j S j  d k r-  d St  d  d   d f d  \   } }  d  k rn t j Sd  d } t  f d   t  j   D  } t t  j   }  j	 | |         f d   } |   j
  j  d  j d |    S(	   Ni    i   t
   iszerofuncii   c         3  s!   |  ] } |   k r | Vq d  S(   N(    (   t   .0R7   (   t	   pivot_pos(    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pys	   <genexpr>   s    c           sS     |  | d f   | d f  |  d f   } | j  sO t |  S| S(   Ni   i    (   t   is_AtomR!   (   R7   RA   t   ret(   t   cummt   matRT   t	   pivot_valt   tmp_mat(    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyRC      s    <	
(   i    i    (   RD   R   RG   t   _find_reasonable_pivotR/   R@   t   listR   RE   t   extractRF   (   RX   RW   t   _t   signRD   RE   RC   (   t   bareissRR   R6   (   RW   RX   RT   RY   RZ   s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyR`      s    %(   R!   (   R6   RR   (    (   R`   RR   R6   s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   _eval_det_bareiss   s     c         C  s&   |  j    } d t |  d | d S(   s8    Use the Berkowitz algorithm to compute the determinant.ii   (   RP   t   len(   R6   t   berk_vector(    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   _eval_det_berkowitz   s    c         C  s   |  j  d k r t j S|  j d | d d  \ } } | | | j  d | j  d f  r_ t j St |  d ry t j n t j } x+ t | j   D] } | | | | f 9} q W| S(   s   Computes the determinant of a matrix from its LU decomposition.
        This function uses the LU decomposition computed by
        LUDecomposition_Simple().

        The keyword arguments iszerofunc and simpfunc are passed to
        LUDecomposition_Simple().
        iszerofunc is a callable that returns a boolean indicating if its
        input is zero, or None if it cannot make the determination.
        simpfunc is a callable that simplifies its input.
        The default is simpfunc=None, which indicate that the pivot search
        algorithm should not attempt to simplify any candidate pivots.
        If simpfunc fails to simplify its input, then it must return its input
        instead of a copy.i    RR   t   simpfunci   i   N(   RD   R   RG   t   LUdecomposition_SimpleR/   R@   Rb   R   (   R6   RR   Re   t   lut	   row_swapst   dett   k(    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   _eval_det_lu   s    $#c         C  s
   |  j    S(   su   Assumed to exist by matrix expressions; If we subclass
        MatrixDeterminant, we can fully evaluate determinants.(   Ri   (   R6   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   _eval_determinant  s    t	   berkowitzc         C  s   |  j  |  j   S(   s   Returns the adjugate, or classical adjoint, of
        a matrix.  That is, the transpose of the matrix of cofactors.


        https://en.wikipedia.org/wiki/Adjugate

        See Also
        ========

        cofactor_matrix
        transpose
        (   t   cofactor_matrixt	   transpose(   R6   t   method(    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   adjugate  s    t   lambdac         C  sV   |  j  s t    n  |  j   } t | |  } t g  | D] } | |  ^ q: |  S(   s  Computes characteristic polynomial det(x*I - self) where I is
        the identity matrix.

        A PurePoly is returned, so using different variables for ``x`` does
        not affect the comparison or the polynomials:

        Examples
        ========

        >>> from sympy import Matrix
        >>> from sympy.abc import x, y
        >>> A = Matrix([[1, 3], [2, 0]])
        >>> A.charpoly(x) == A.charpoly(y)
        True

        Specifying ``x`` is optional; a symbol named ``lambda`` is used by
        default (which looks good when pretty-printed in unicode):

        >>> A.charpoly().as_expr()
        lambda**2 - lambda - 6

        And if ``x`` clashes with an existing symbol, underscores will
        be preppended to the name to make it unique:

        >>> A = Matrix([[1, 2], [x, 0]])
        >>> A.charpoly(x).as_expr()
        _x**2 - _x - 2*x

        Whether you pass a symbol or not, the generator can be obtained
        with the gen attribute since it may not be the same as the symbol
        that was passed:

        >>> A.charpoly(x).gen
        _x
        >>> A.charpoly(x).gen == x
        False

        Notes
        =====

        The Samuelson-Berkowitz algorithm is used to compute
        the characteristic polynomial efficiently and without any
        division operations.  Thus the characteristic polynomial over any
        commutative ring without zero divisors can be computed.

        See Also
        ========

        det
        (   t	   is_squareR+   RP   R   R    (   R6   R0   R%   Rc   RI   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   charpoly  s
    4	c         C  sH   |  j  s |  j d k  r% t    n  d | | d |  j | | |  S(   s   Calculate the cofactor of an element.

        See Also
        ========

        cofactor_matrix
        minor
        minor_submatrix
        i   ii   (   Rs   RD   R+   t   minor(   R6   R7   RA   Rp   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   cofactorZ  s    c           sJ    j  s  j d k  r% t    n   j  j  j    f d    S(   s   Return a matrix containing the cofactor of each element.

        See Also
        ========

        cofactor
        minor
        minor_submatrix
        adjugate
        i   c           s    j  |  |    S(   N(   Rv   (   R7   RA   (   Rp   R6   (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   <lambda>z  t    (   Rs   RD   R+   RF   RE   (   R6   Rp   (    (   Rp   R6   s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyRn   j  s    R`   c         C  s  | j    } | d k r! d } n  | d k r6 d } n  | d d d f k r^ t d |   n  | t k r | d k r t } n | d k r t } n  n# t | t  r t d |   n  |  j r t    n  |  j	 } | d k r t
 j Sno| d	 k r|  d d f SnR| d
 k rS|  d d f |  d	 d	 f |  d d	 f |  d	 d f Sn| d k r^|  d d f |  d	 d	 f |  d
 d
 f |  d d	 f |  d	 d
 f |  d
 d f |  d d
 f |  d	 d f |  d
 d	 f |  d d
 f |  d	 d	 f |  d
 d f |  d d f |  d	 d
 f |  d
 d	 f |  d d	 f |  d	 d f |  d
 d
 f Sn  | d k r}|  j d |  Sn8 | d k r|  j   Sn | d k r|  j d |  Sn  d S(   sW  Computes the determinant of a matrix.

        Parameters
        ==========

        method : string, optional
            Specifies the algorithm used for computing the matrix determinant.

            If the matrix is at most 3x3, a hard-coded formula is used and the
            specified method is ignored. Otherwise, it defaults to
            ``'bareiss'``.

            If it is set to ``'bareiss'``, Bareiss' fraction-free algorithm will
            be used.

            If it is set to ``'berkowitz'``, Berkowitz' algorithm will be used.

            Otherwise, if it is set to ``'lu'``, LU decomposition will be used.

            .. note::
                For backward compatibility, legacy keys like "bareis" and
                "det_lu" can still be used to indicate the corresponding
                methods.
                And the keys are also case-insensitive for now. However, it is
                suggested to use the precise keys for specifying the method.

        iszerofunc : FunctionType or None, optional
            If it is set to ``None``, it will be defaulted to ``_iszero`` if the
            method is set to ``'bareiss'``, and ``_is_zero_after_expand_mul`` if
            the method is set to ``'lu'``.

            It can also accept any user-specified zero testing function, if it
            is formatted as a function which accepts a single symbolic argument
            and returns ``True`` if it is tested as zero and ``False`` if it
            tested as non-zero, and also ``None`` if it is undecidable.

        Returns
        =======

        det : Basic
            Result of determinant.

        Raises
        ======

        ValueError
            If unrecognized keys are given for ``method`` or ``iszerofunc``.

        NonSquareMatrixError
            If attempted to calculate determinant from a non-square matrix.
        t   bareisR`   t   det_luRg   Rm   s$   Determinant method '%s' unrecognizeds%   Zero testing method '%s' unrecognizedi    i   i   i   RR   N(   t   lowert
   ValueErrorR/   R2   R1   t
   isinstanceR   Rs   R+   RD   R   RG   Ra   Rd   Rk   (   R6   Rp   RR   t   n(    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyRi   |  s>    6			
	
;c         C  sA   |  j  s |  j d k  r% t    n  |  j | |  j d |  S(   s  Return the (i,j) minor of ``self``.  That is,
        return the determinant of the matrix obtained by deleting
        the `i`th row and `j`th column from ``self``.

        See Also
        ========

        minor_submatrix
        cofactor
        det
        i   Rp   (   Rs   RD   R+   t   minor_submatrixRi   (   R6   R7   RA   Rp   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyRu     s    c         C  s  | d k  r | |  j  7} n  | d k  r8 | |  j 7} n  d | k oR |  j  k  n sx d | k or |  j k  n r t d |  j  d |  j   n  g  t |  j   D] } | | k r | ^ q } g  t |  j  D] } | | k r | ^ q } |  j | |  S(   s   Return the submatrix obtained by removing the `i`th row
        and `j`th column from ``self``.

        See Also
        ========

        minor
        cofactor
        i    s4   `i` and `j` must satisfy 0 <= i < ``self.rows`` (%d)s    and 0 <= j < ``self.cols`` (%d).(   RD   RE   R|   R   R]   (   R6   R7   RA   RI   RD   RE   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyR     s    @..N(   R<   R=   R>   RO   RP   R2   Ra   Rd   R1   R/   Rk   Rl   Rq   t	   _simplifyRt   Rv   Rn   Ri   Ru   R   (    (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyR?   K   s   	,	,0	/	;bt   MatrixReductionsc           B  s  e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 e d	  Z d
 d  Z d   Z e e e d  Z e e e d  Z d d d d d d  Z d d d d d d  Z e e d   Z e e d  Z e e e e d  Z RS(   sU   Provides basic matrix row/column operations.
    Should not be instantiated directly.c           s.       f d   }  j   j  j |  S(   Nc           sB   |   k r  |   f S|  k r4  |    f S |  | f S(   N(    (   R7   RA   (   t   col1t   col2R6   (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyRC     s
    (   RF   RD   RE   (   R6   R   R   RC   (    (   R   R   R6   s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   _eval_col_op_swap  s    c           s.       f d   }  j   j  j |  S(   Nc           s,   |   k r   |  | f S |  | f S(   N(    (   R7   RA   (   t   colRj   R6   (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyRC     s    (   RF   RD   RE   (   R6   R   Rj   RC   (    (   R   Rj   R6   s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt"   _eval_col_op_multiply_col_by_const  s    c           s1        f d   }  j   j  j |  S(   Nc           s:   |   k r,  |  | f   |   f S |  | f S(   N(    (   R7   RA   (   R   R   Rj   R6   (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyRC     s     (   RF   RD   RE   (   R6   R   Rj   R   RC   (    (   R   R   Rj   R6   s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt&   _eval_col_op_add_multiple_to_other_col  s    c           s.       f d   }  j   j  j |  S(   Nc           sB   |    k r   | f S|   k r4    | f S |  | f S(   N(    (   R7   RA   (   t   row1t   row2R6   (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyRC   %  s
    (   RF   RD   RE   (   R6   R   R   RC   (    (   R   R   R6   s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   _eval_row_op_swap$  s    c           s.       f d   }  j   j  j |  S(   Nc           s,   |   k r    |  | f S |  | f S(   N(    (   R7   RA   (   Rj   t   rowR6   (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyRC   .  s    (   RF   RD   RE   (   R6   R   Rj   RC   (    (   Rj   R   R6   s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt"   _eval_row_op_multiply_row_by_const-  s    c           s1        f d   }  j   j  j |  S(   Nc           s:   |   k r,  |  | f     | f S |  | f S(   N(    (   R7   RA   (   Rj   R   R   R6   (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyRC   5  s     (   RF   RD   RE   (   R6   R   Rj   R   RC   (    (   Rj   R   R   R6   s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt&   _eval_row_op_add_multiple_to_other_row4  s    c      	   C  s:   |  j  | | d t d t d t \ } } } | | | f S(   s   Returns (mat, swaps) where ``mat`` is a row-equivalent matrix
        in echelon form and ``swaps`` is a list of row-swaps performed.t   normalize_lastt	   normalizet
   zero_above(   t   _row_reducet   Truet   False(   R6   RR   Re   t   reducedt
   pivot_colst   swaps(    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   _eval_echelon_form;  s
    c           s   |  j  d k s |  j d k r" t St   f d   |  d d   d f D  }   |  d  r | o |  d  d   d d   f j    S| o |  d d   d d   f j    S(   Ni    c         3  s   |  ] }   |  Vq d  S(   N(    (   RS   t   t(   RR   (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pys	   <genexpr>G  s    i   (   i    i    (   RD   RE   R   t   allt   _eval_is_echelon(   R6   RR   t   zeros_below(    (   RR   s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyR   D  s    ,)c         C  s4   |  j  | | | d t d t \ } } } | | f S(   NR   R   (   R   R   (   R6   RR   Re   R   R   R   R   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt
   _eval_rrefL  s    R   c         C  s  | d k r' t  d j | |    n  | d k r | d k	 rE | n | } | d k sc | d k r{ t  d j |    n  d | k o |  j k n s t  d j | |    q n  | d k rt | | | | f  j d g  } t |  d k rt | | | f  j d g  } n  t |  d k rHt  d	 j |    n  | \ } } d | k on|  j k n st  d j | |    n  d | k o|  j k n st  d j | |    qn  | d k r| d k r| n | } | d k r| n | } | d k s+| d k s+| d k rCt  d
 j |    n  | | k rgt  d j |    n  d | k o|  j k n st  d j | |    n  d | k o|  j k n st  d j | |    qn  | | | | | f S(   s   Validate the arguments for a row/column operation.  ``error_str``
        can be one of "row" or "col" depending on the arguments being parsed.s   n->kns   n<->ms   n->n+kmsO   Unknown {} operation '{}'. Valid col operations are 'n->kn', 'n<->m', 'n->n+km'sE   For a {0} operation 'n->kn' you must provide the kwargs `{0}` and `k`i    s"   This matrix doesn't have a {} '{}'i   sI   For a {0} operation 'n<->m' you must provide the kwargs `{0}1` and `{0}2`sP   For a {0} operation 'n->n+km' you must provide the kwargs `{0}`, `k`, and `{0}2`sA   For a {0} operation 'n->n+km' `{0}` and `{0}2` must be different.(   s   n->kns   n<->ms   n->n+kmN(   R|   t   formatR/   RE   t   sett
   differenceRb   (   R6   t   opR   Rj   R   R   t	   error_strRE   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   _normalize_op_argsR  sH    		$$	$		c           s~      f d   } g  t   j  D] } | |  | f ^ q" } g  t |  D] \ } } | ^ qM }  j | d d | f S(   s  Permute columns with complicated elements as
        far right as they can go.  Since the ``sympy`` row reduction
        algorithms start on the left, having complexity right-shifted
        speeds things up.

        Returns a tuple (mat, perm) where perm is a permutation
        of the columns to perform to shift the complex columns right, and mat
        is the permuted matrix.c           s*   t    f d    d  d   |  f D  S(   Nc         3  s-   |  ]# }   |  d k r! d  n d Vq d S(   i   i    N(   R/   (   RS   t   e(   RR   (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pys	   <genexpr>  s    (   t   sum(   R7   (   RR   R6   (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt
   complexity  s    t   orientationRE   (   R   RE   t   sortedt   permute(   R6   RR   R   R7   t   complexRA   t   perm(    (   RR   R6   s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   _permute_complexity_right  s    
.%c           s  |  j  |  j }   t |       f d   }    f d   }    f d   }	 d \ }
 } g  } g  } x|   k  rH|
 | k  rHt | |  |
 | |  \ } } } } x0 | D]( \ } } | |
 7} |  |   | <q W| d k r | d 7} qp n  | j |  | d k rC| |
 | |
  | j |
 | |
 f  n  | t k r|
 | } } t j  |   | <x= t	 |   | d | d    D] }  | |  | <qWt j } n  x{ t	 |  D]m } | |
 k rqn  | t k r | |
 k  r qn   |   | } | |  r$qn  |	 | | | |
  qW|
 d 7}
 qp W| t
 k r| t
 k rx t |  D]s \ } }  |   | } t j  |   | <x= t	 |   | d | d    D] }  | |  | <qWqnWn  |  j |  j  |  j   t |  t |  f S(   s  Row reduce ``self`` and return a tuple (rref_matrix,
        pivot_cols, swaps) where pivot_cols are the pivot columns
        and swaps are any row swaps that were used in the process
        of row reduction.

        Parameters
        ==========

        iszerofunc : determines if an entry can be used as a pivot
        simpfunc : used to simplify elements and test if they are
            zero if ``iszerofunc`` returns `None`
        normalize_last : indicates where all row reduction should
            happen in a fraction-free manner and then the rows are
            normalized (so that the pivots are 1), or whether
            rows should be normalized along the way (like the naive
            row reduction algorithm)
        normalize : whether pivot rows should be normalized so that
            the pivot value is 1
        zero_above : whether entries above the pivot should be zeroed.
            If ``zero_above=False``, an echelon matrix will be returned.
        c           s    |  d     S(   N(    (   R7   (   RE   RX   (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   get_col  s    c           s]    |   | d   ! |    |  d   ! |    |  d   + |   | d   +d  S(   Ni   (    (   R7   RA   (   RE   RX   (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   row_swap  s    c           sZ   | |   } xE t  |   | d    D]( } |   | |  | |  | <q* Wd S(   s,   Does the row op row[i] = a*row[i] - b*row[j]i   N(   R   (   RI   R7   t   bRA   t   qt   p(   RE   RX   (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   cross_cancel  s    "i    i   (   i    i    N(   RD   RE   R\   R[   R/   RH   R   R   RG   R   R   t	   enumerateRF   t   tuple(   R6   RR   Re   R   R   R   RD   R   R   R   t   piv_rowt   piv_colR   R   t   pivot_offsetRY   t   assumed_nonzerot   newly_determinedt   offsett   valR7   RA   R   R   t   piv_it   piv_j(    (   RE   RX   s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyR     sX    %

**c         C  sJ   t  | t  r | n t } |  j | |  \ } } } | rF | | f S| S(   s   Returns a matrix row-equivalent to ``self`` that is
        in echelon form.  Note that echelon form of a matrix
        is *not* unique, however, properties like the row
        space and the null space are preserved.(   R}   R   R   R   (   R6   RR   R%   t   with_pivotsRe   RX   t   pivotsR   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   echelon_form  s    
s   n->knc         C  s   |  j  | | | | | d  \ } } } } } | d k rI |  j | |  S| d k re |  j | |  S| d k r |  j | | |  Sd S(   sX  Performs the elementary column operation `op`.

        `op` may be one of

            * "n->kn" (column n goes to k*n)
            * "n<->m" (swap column n and column m)
            * "n->n+km" (column n goes to column n + k*column m)

        Parameters
        ==========

        op : string; the elementary row operation
        col : the column to apply the column operation
        k : the multiple to apply in the column operation
        col1 : one column of a column swap
        col2 : second column of a column swap or column "m" in the column operation
               "n->n+km"
        R   s   n->kns   n<->ms   n->n+kmN(   R   R   R   R   (   R6   R   R   Rj   R   R   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   elementary_col_op  s    -c         C  s   |  j  | | | | | d  \ } } } } } | d k rI |  j | |  S| d k re |  j | |  S| d k r |  j | | |  Sd S(   s(  Performs the elementary row operation `op`.

        `op` may be one of

            * "n->kn" (row n goes to k*n)
            * "n<->m" (swap row n and row m)
            * "n->n+km" (row n goes to row n + k*row m)

        Parameters
        ==========

        op : string; the elementary row operation
        row : the row to apply the row operation
        k : the multiple to apply in the row operation
        row1 : one row of a row swap
        row2 : second row of a row swap or row "m" in the row operation
               "n->n+km"
        R   s   n->kns   n<->ms   n->n+kmN(   R   R   R   R   (   R6   R   R   Rj   R   R   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   elementary_row_op#  s    -c         C  s   |  j  |  S(   s   Returns `True` if the matrix is in echelon form.
        That is, all rows of zeros are at the bottom, and below
        each leading non-zero in a row are exclusively zeros.(   R   (   R6   RR   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt
   is_echelonA  s    c         C  sj  t  | t  r | n t } |  j d k s9 |  j d k r= d S|  j d k s[ |  j d k r g  |  D] } | |  ^ qb } t | k r d Sn  |  j d k r'|  j d k r'g  |  D] } | |  ^ q } t | k r d | k r d S|  j   } | |  rt | k rd S| |  t k r'd Sn  |  j d |  \ } } | j	 d | d |  \ }	 }
 } t
 |
  S(   s  
        Returns the rank of a matrix

        >>> from sympy import Matrix
        >>> from sympy.abc import x
        >>> m = Matrix([[1, 2], [x, 1 - 1/x]])
        >>> m.rank()
        2
        >>> n = Matrix(3, 3, range(1, 10))
        >>> n.rank()
        2
        i    i   i   RR   Re   N(   R}   R   R   RD   RE   R   R/   Ri   R   R   Rb   (   R6   RR   R%   Re   R0   t   zerosRi   RX   R^   R   R   R   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   rankI  s(    !c         C  sX   t  | t  r | n t } |  j d | d | d |  \ } } | rT | | f } n  | S(   s-  Return reduced row-echelon form of matrix and indices of pivot vars.

        Parameters
        ==========

        iszerofunc : Function
            A function used for detecting whether an element can
            act as a pivot.  ``lambda x: x.is_zero`` is used by default.
        simplify : Function
            A function used to simplify elements when looking for a pivot.
            By default SymPy's ``simplify`` is used.
        pivots : True or False
            If ``True``, a tuple containing the row-reduced matrix and a tuple
            of pivot columns is returned.  If ``False`` just the row-reduced
            matrix is returned.
        normalize_last : True or False
            If ``True``, no pivots are normalized to `1` until after all
            entries above and below each pivot are zeroed.  This means the row
            reduction algorithm is fraction free until the very last step.
            If ``False``, the naive row reduction procedure is used where
            each pivot is normalized to be `1` before row operations are
            used to zero above and below the pivot.

        Notes
        =====

        The default value of ``normalize_last=True`` can provide significant
        speedup to row reduction, especially on matrices with symbols.  However,
        if you depend on the form row reduction algorithm leaves entries
        of the matrix, set ``noramlize_last=False``


        Examples
        ========

        >>> from sympy import Matrix
        >>> from sympy.abc import x
        >>> m = Matrix([[1, 2], [x, 1 - 1/x]])
        >>> m.rref()
        (Matrix([
        [1, 0],
        [0, 1]]), (0, 1))
        >>> rref_matrix, rref_pivots = m.rref()
        >>> rref_matrix
        Matrix([
        [1, 0],
        [0, 1]])
        >>> rref_pivots
        (0, 1)
        RR   Re   R   (   R}   R   R   R   (   R6   RR   R%   R   R   Re   RV   R   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   rrefp  s    3N(   R<   R=   R>   R   R   R   R   R   R   R   R   R   R   R   R   R   R1   R   R   R/   R   R   t   propertyR   R   R   (    (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyR   	  s*   											1	a't   MatrixSubspacesc           B  sD   e  Z d  Z e d  Z e e d  Z e d  Z e d    Z	 RS(   sm   Provides methods relating to the fundamental subspaces
    of a matrix.  Should not be instantiated directly.c         C  s>   |  j  d | d t  \ } } g  | D] } |  j |  ^ q% S(   s  Returns a list of vectors (Matrix objects) that span columnspace of ``self``

        Examples
        ========

        >>> from sympy.matrices import Matrix
        >>> m = Matrix(3, 3, [1, 3, 0, -2, -6, 0, 3, 9, 6])
        >>> m
        Matrix([
        [ 1,  3, 0],
        [-2, -6, 0],
        [ 3,  9, 6]])
        >>> m.columnspace()
        [Matrix([
        [ 1],
        [-2],
        [ 3]]), Matrix([
        [0],
        [0],
        [6]])]

        See Also
        ========

        nullspace
        rowspace
        R%   R   (   R   R   R   (   R6   R%   R   R   R7   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   columnspace  s    c         C  s   |  j  d | d |  \ } } g  t |  j  D] } | | k r. | ^ q. } g  } xr | D]j } t j g |  j }	 t j |	 | <x4 t |  D]& \ }
 } |	 | c | |
 | f 8<q W| j |	  qY Wg  | D] } |  j |  j d |  ^ q S(   s  Returns list of vectors (Matrix objects) that span nullspace of ``self``

        Examples
        ========

        >>> from sympy.matrices import Matrix
        >>> m = Matrix(3, 3, [1, 3, 0, -2, -6, 0, 3, 9, 6])
        >>> m
        Matrix([
        [ 1,  3, 0],
        [-2, -6, 0],
        [ 3,  9, 6]])
        >>> m.nullspace()
        [Matrix([
        [-3],
        [ 1],
        [ 0]])]

        See Also
        ========

        columnspace
        rowspace
        RR   R%   i   (	   R   R   RE   R   R@   RG   R   RH   RF   (   R6   R%   RR   R   R   R7   t	   free_varst   basist   free_vart   vecR   R   R   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt	   nullspace  s    .c         C  sJ   |  j  d | d t  \ } } g  t t |   D] } | j |  ^ q1 S(   s>   Returns a list of vectors that span the row space of ``self``.R%   R   (   R   R   R   Rb   R   (   R6   R%   R   R   R7   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   rowspace  s    c           s   | j  d t  } d       f d   } g  } t |  } x* t |  d k rh | d j rh | d =q? Wx6 | D]. } | | |  } | j sp | j |  qp qp W| r g  | D] } | | j   ^ q } n  | S(   s  Apply the Gram-Schmidt orthogonalization procedure
        to vectors supplied in ``vecs``.

        Parameters
        ==========

        vecs
            vectors to be made orthogonal

        normalize : bool
            If true, return an orthonormal basis.
        R   c         S  s   | |  j  |  | j  |  S(   N(   t   dot(   RI   R   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   project  s    c           sL   g  | D] }   |  |  ^ q } t  |  d k r8 |  S|  t d   |  S(   sR   projects vec onto the subspace given
            by the orthogonal basis ``basis``i    c         S  s   |  | S(   N(    (   RI   R   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyRw     Rx   (   Rb   R   (   R   R   R   t
   components(   R   (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   perp_to_subspace  s    "i    (   t   getR   R\   Rb   R-   RH   t   norm(   t   clst   vecst   kwargsR   R   RV   R   t   perp(    (   R   s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   orthogonalize  s    	"	&(
   R<   R=   R>   R   R   R1   R   R   t   classmethodR   (    (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyR     s
    *t   MatrixEigenc           B  s   e  Z d  Z e d    Z e d    Z e e e d  Z e d  Z	 e e
 d  Z e d  Z e d  Z d   Z d	   Z RS(
   s\   Provides basic matrix eigenvalue/vector operations.
    Should not be instantiated directly.c         C  s#   t  d d d d d d  j   d  S(   Nt   featuret   _cache_is_diagonalizablet   deprecated_since_versions   1.4t   issuei>  (   R&   t   warnR/   (   R6   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyR   4  s
    c         C  s#   t  d d d d d d  j   d  S(   NR   t   _cache_eigenvectsR   s   1.4R   i>  (   R&   R   R/   (   R6   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyR   =  s
    c         C  s   |  j  s t    n  |  j d |  s6 t d   n  |  j d t  } | rc t | d t } n  g  g  } } x2 | D]* \ } } }	 | | g | 7} | |	 7} qw W| r g  | D] }
 |
 |
 j   ^ q } n  |  j	 |   |  j
 |   f S(   s>  
        Return (P, D), where D is diagonal and

            D = P^-1 * M * P

        where M is current matrix.

        Parameters
        ==========

        reals_only : bool. Whether to throw an error if complex numbers are need
                     to diagonalize. (Default: False)
        sort : bool. Sort the eigenvalues along the diagonal. (Default: False)
        normalize : bool. If True, normalize the columns of P. (Default: False)

        Examples
        ========

        >>> from sympy import Matrix
        >>> m = Matrix(3, 3, [1, 2, 0, 0, 3, 0, 2, -4, 2])
        >>> m
        Matrix([
        [1,  2, 0],
        [0,  3, 0],
        [2, -4, 2]])
        >>> (P, D) = m.diagonalize()
        >>> D
        Matrix([
        [1, 0, 0],
        [0, 2, 0],
        [0, 0, 3]])
        >>> P
        Matrix([
        [-1, 0, -1],
        [ 0, 0, -1],
        [ 2, 1,  2]])
        >>> P.inv() * m * P
        Matrix([
        [1, 0, 0],
        [0, 2, 0],
        [0, 0, 3]])

        See Also
        ========

        is_diagonal
        is_diagonalizable
        t
   reals_onlys   Matrix is not diagonalizableR%   t   key(   Rs   R+   t   is_diagonalizableR*   t
   eigenvectsR   R   R	   R   t   hstackt   diag(   R6   R   t   sortR   t	   eigenvecst   p_colsR   R   t   multR   t   v(    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   diagonalizeF  s    2	&c           s'  | j  d t    | j  d t  } | j d t  } |  } | sF i  S| ra | j d    } n  | j ss | j r|  j s t    n  g  t	 | j
  D] } | | | f ^ q } | r | } qpi  } x | D]/ }	 |	 | k r d | |	 <n  | |	 c d 7<q Wnj | j d d
  t   t  rOt | j d t d  d    |  } n! t | j d t d   |  } | rt | t  rt | j    n	 t |  |  j k rt d j |     n    s| St   t  st   n  | s  f d	   | j   D Sg  | D] }
   |
  ^ qSd
 S(   s  Return eigenvalues using the Berkowitz agorithm to compute
        the characteristic polynomial.

        Parameters
        ==========

        error_when_incomplete : bool, optional
            If it is set to ``True``, it will raise an error if not all
            eigenvalues are computed. This is caused by ``roots`` not returning
            a full list of eigenvalues.

        simplify : bool or function, optional
            If it is set to ``True``, it attempts to return the most
            simplified form of expressions returned by applying default
            simplification method in every routine.

            If it is set to ``False``, it will skip simplification in this
            particular routine to save computation resources.

            If a function is passed to, it will attempt to apply
            the particular function as simplification method.

        rational : bool, optional
            If it is set to ``True``, every floating point numbers would be
            replaced with rationals before computation. It can solve some
            issues of ``roots`` routine not working well with floats.

        multiple : bool, optional
            If it is set to ``True``, the result will be in the form of a
            list.

            If it is set to ``False``, the result will be in the form of a
            dictionary.

        Returns
        =======

        eigs : list or dict
            Eigenvalues of a matrix. The return format would be specified by
            the key ``multiple``.

        Raises
        ======

        MatrixError
            If not enough roots had got computed.

        NonSquareMatrixError
            If attempted to compute eigenvalues from a non-square matrix.

        See Also
        ========

        MatrixDeterminant.charpoly
        eigenvects

        Notes
        =====

        Eigenvalues of a matrix `A` can be computed by solving a matrix
        equation `\det(A - \lambda I) = 0`
        R%   t   multiplet   rationalc         S  s#   |  j  t  r t |  d t S|  S(   NR   (   t   hasR   R$   R   (   R0   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyRw     Rx   i    i   R0   s$   Could not compute eigenvalues for {}c           s%   i  |  ] \ } } |   |   q S(    (    (   RS   R   t   value(   R%   (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pys
   <dictcomp>  s   	 N(   R   R   t   popR   t	   applyfunct   is_uppert   is_lowerRs   R+   R   RD   R/   R}   R   R"   Rt   R   t   dictR   t   valuesRb   RE   R*   R   R   t   items(   R6   t   error_when_incompletet   flagsR   R   RX   R7   t   diagonal_entriest   eigst   diagonal_entryR   (    (   R%   s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt	   eigenvals  sD    ?	,	*!6	c      	     s  d d l  m } | j d t   t  t  sI  r= t n d    n  | j d t  } | j d t  } | j d d     j
 t  } | r  j d     n       f d   }  j d	 t d
 | |  }	 g  t |	 j   d t D]! \ }
 } |
 | | |
  f ^ q } | ri f d   } g  | D]$ \ }
 } } |
 | | |  f ^ q<} n  | rg  | D]I \ }
 } } |
 j d |  | g  | D] } | j d |  ^ qf ^ qv} n  | S(   s\  Return list of triples (eigenval, multiplicity, eigenspace).

        Parameters
        ==========

        error_when_incomplete : bool, optional
            Raise an error when not all eigenvalues are computed. This is
            caused by ``roots`` not returning a full list of eigenvalues.

        iszerofunc : function, optional
            Specifies a zero testing function to be used in ``rref``.

            Default value is ``_iszero``, which uses SymPy's naive and fast
            default assumption handler.

            It can also accept any user-specified zero testing function, if it
            is formatted as a function which accepts a single symbolic argument
            and returns ``True`` if it is tested as zero and ``False`` if it
            is tested as non-zero, and ``None`` if it is undecidable.

        simplify : bool or function, optional
            If ``True``, ``as_content_primitive()`` will be used to tidy up
            normalization artifacts.

            It will also be used by the ``nullspace`` routine.

        chop : bool or positive number, optional
            If the matrix contains any Floats, they will be changed to Rationals
            for computation purposes, but the answers will be returned after
            being evaluated with evalf. The ``chop`` flag is passed to ``evalf``.
            When ``chop=True`` a default precision will be used; a number will
            be interpreted as the desired level of precision.

        Returns
        =======
        ret : [(eigenval, multiplicity, eigenspace), ...]
            A ragged list containing tuples of data obtained by ``eigenvals``
            and ``nullspace``.

            ``eigenspace`` is a list containing the ``eigenvector`` for each
            eigenvalue.

            ``eigenvector`` is a vector in the form of a ``Matrix``. e.g.
            a vector of length 3 is returned as ``Matrix([a_1, a_2, a_3])``.

        Raises
        ======

        NotImplementedError
            If failed to compute nullspace.

        See Also
        ========

        eigenvals
        MatrixSubspaces.nullspace
        i(   t   eyeR%   c         S  s   |  S(   N(    (   R0   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyRw   >  Rx   t   chopR   c         S  s   t  |  d t S(   NR   (   R$   R   (   R0   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyRw   H  Rx   c           s     j   j  |  } | j d    } t |  d k r_  r_ | j d   d t  } n  t |  d k r t d |    n  | S(   s:   Get a basis for the eigenspace for a particular eigenvalueRR   i    R%   s,   Can't evaluate eigenvector for eigenvalue %s(   R   RD   R   Rb   R   t   NotImplementedError(   t   eigenvalt   mRV   (   RR   RX   R6   R%   (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt
   eigenspaceJ  s    R   R   R   c           s@   d d l  m } g  |  D]% } | | t |   j    ^ q S(   Ni(   t   gcd(   t   sympyR  R\   R   (   t   lR  R   (   Re   (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   denom_clean`  s    N(   t   sympy.matricesR   R   R   R}   R   R   R   R   R/   R   R   R   R   R   R   R	   t   evalf(   R6   R   RR   R   R   t	   primitiveR   t
   has_floatsR  R   R   R   RV   R  t   esR   (    (   RR   RX   R6   Re   R%   s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyR      s.    :	=4Yc         K  s   d | k r. t  d d d d d d  j   n  d | k r\ t  d d d d d d  j   n  |  j si t St d   |  D  r |  j   r t S|  j d	 t  } t } xK | D]C \ } } } | r | j r t } n  | t	 |  k r t } q q W| S(
   sl  Returns true if a matrix is diagonalizable.

        Parameters
        ==========

        reals_only : bool. If reals_only=True, determine whether the matrix can be
                     diagonalized without complex numbers. (Default: False)

        kwargs
        ======

        clear_cache : bool. If True, clear the result of any computations when finished.
                      (Default: True)

        Examples
        ========

        >>> from sympy import Matrix
        >>> m = Matrix(3, 3, [1, 2, 0, 0, 3, 0, 2, -4, 2])
        >>> m
        Matrix([
        [1,  2, 0],
        [0,  3, 0],
        [2, -4, 2]])
        >>> m.is_diagonalizable()
        True
        >>> m = Matrix(2, 2, [0, 1, 0, 0])
        >>> m
        Matrix([
        [0, 1],
        [0, 0]])
        >>> m.is_diagonalizable()
        False
        >>> m = Matrix(2, 2, [0, 1, -1, 0])
        >>> m
        Matrix([
        [ 0, 1],
        [-1, 0]])
        >>> m.is_diagonalizable()
        True
        >>> m.is_diagonalizable(reals_only=True)
        False

        See Also
        ========

        is_diagonal
        diagonalize
        t   clear_cacheR   R   gffffff?R   i>  t   clear_subproductsc         s  s   |  ] } | j  Vq d  S(   N(   t   is_real(   RS   R   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pys	   <genexpr>  s    R%   (
   R&   R   Rs   R   R   t   is_symmetricR   R   R  Rb   (   R6   R   R   R   RV   R   R   R   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyR   i  s,    2	"	c           s	   j  s t d   n  | j d t       j t    r y t d    j D  } Wn t k
 r{ d } n Xt t	 |  d   n      f d   } i      f d      f d   } d	   }  f d
   }  r	 j
 d     n   j   } t d   | j   D   j k rRt d j     n  t | j     j k rt t | j   d t  }	  j |	   }
 | s| |
  Sg  |	 D]    d  j   d ^ q}  j |   } | | |
  Sg  } x t | j   d t D]  |  } |  |  } | |  } g  t |  D] \ } } | d | f ^ qI} | j   | j  f d   | D  qWt d   | D  } |  j k rt d j     n   f d   | D }	  j |	   }
 | s| |
  Sg  } x t | j   d t D]  g  } x | D] \ } } |  k rXq:n    |  j   }   | d  j   } | | | |  } g  t |  D] }   |  | ^ q} | j |  | j t |   q:Wq'W j |   } | | |
  S(   s  Return ``(P, J)`` where `J` is a Jordan block
        matrix and `P` is a matrix such that

            ``self == P*J*P**-1``


        Parameters
        ==========

        calc_transform : bool
            If ``False``, then only `J` is returned.
        chop : bool
            All matrices are convered to exact types when computing
            eigenvalues and eigenvectors.  As a result, there may be
            approximation errors.  If ``chop==True``, these errors
            will be truncated.

        Examples
        ========

        >>> from sympy import Matrix
        >>> m = Matrix([[ 6,  5, -2, -3], [-3, -1,  3,  3], [ 2,  1, -2, -3], [-1,  1,  5,  5]])
        >>> P, J = m.jordan_form()
        >>> J
        Matrix([
        [2, 1, 0, 0],
        [0, 2, 0, 0],
        [0, 0, 2, 1],
        [0, 0, 0, 2]])

        See Also
        ========

        jordan_block
        s&   Only square matrices have Jordan formsR   c         s  s'   |  ] } t  | t  r | j Vq d  S(   N(   R}   R   t   _prec(   RS   t   term(    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pys	   <genexpr>  s    i5   i   c            sR    r4 g  |  D] } | j  d  d    ^ q }  n  t |   d k rN |  d S|  S(   sQ   If ``has_floats`` is `True`, cast all ``args`` as
            matrices of floats.t   precR   i   i    (   R
  Rb   (   t   argsR  (   R   R  t   max_dps(    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   restore_floats  s
    .c           s   |  | f  k r   |  | f S|  | d f  k re  |  | d f  |  d f  |  | f <n(   |   j   j  |  |  | f < |  | f S(   sM   Cache computations of ``(self - val*I)**pow`` for quick
            retrievali   (   R   RD   (   R   t   pow(   RX   t	   mat_cacheR6   (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   eig_mat  s    /(c           s    j  } d g } |   |  d  j   } d } x | | d k r | j |  | | k ra Pn  |   |  |  j   } | d 7} | | d k  s | | k r4 t d j     q4 q4 W| S(   sw   Calculate the sequence  [0, nullity(E), nullity(E**2), ...]
            until it is constant where ``E = self - val*I``i    i   i   isM   SymPy had encountered an inconsistent result while computing Jordan block: {}(   RE   R   RH   R*   R   (   R   t   algebraic_multiplicityRE   RV   t   nullityR7   (   R  R6   (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   nullity_chain  s    		
c         S  s   g  t  d t |   d  D], } d |  | |  | d |  | d ^ q } t |   d k rs |  d |  d g n
 |  d g } | | S(   s   Return a list of the size of each Jordan block.
            If d_n is the nullity of E**n, then the number
            of Jordan blocks of size n is

                2*d_n - d_(n-1) - d_(n+1)i   i   iii    (   R   Rb   (   RM   R~   t   midt   end(    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   blocks_from_nullity_chain#  s    L4c           sq   t  |   d k r | d SxP | D]H }   j |  | g   j d t  \ } } | d t  |   k r! | Sq! Wd S(   s[   Picks a vector from big_basis that isn't in
            the subspace spanned by small_basisi    R   iN(   Rb   R   R   R   (   t   small_basist	   big_basisR   R^   R   (   R6   (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   pick_vec0  s    (c         S  s   t  |  d t S(   NR   (   R$   R   (   R0   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyRw   <  Rx   c         s  s   |  ] } | Vq d  S(   N(    (   RS   R  (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pys	   <genexpr>C  s    s$   Could not compute eigenvalues for {}R   i   i    c         3  s4   |  ]* \ } } t  |  D] }   | f Vq q d  S(   N(   R   (   RS   t   sizet   numR^   (   t   eig(    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pys	   <genexpr>`  s    c         s  s   |  ] \ } } | Vq d  S(   N(    (   RS   R&  R$  (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pys	   <genexpr>b  s    sO   SymPy had encountered an inconsistent result while computing Jordan block. : {}c         3  s-   |  ]# \ } }   j  d  | d |  Vq d S(   R$  t
   eigenvalueN(   t   jordan_block(   RS   R&  R$  (   RX   (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pys	   <genexpr>i  s    (   Rs   R+   R   R   R   R   t   maxt   _matR|   R   R   R   R   R   RE   R*   R   Rb   t   keysR\   R   R	   R   R   R   R   t   reverset   extendRD   R   t   reversed(   R6   t   calc_transformR   t   max_precR  R  R   R#  R   t   blockst
   jordan_matt   jordan_basist	   basis_matt   block_structureR  t   chaint   block_sizesR7   R%  t	   size_numst   jordan_form_sizet	   eig_basist	   block_eigR$  t   null_bigt
   null_smallR   t   new_vecs(    (   R   R&  R  R  RX   R  R  R6   s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   jordan_form  s|    $	

	%
,
/

,c         K  sW   |  j    j |   } g  | D]7 \ } } } | | g  | D] } | j    ^ q8 f ^ q S(   s#  Returns left eigenvectors and eigenvalues.

        This function returns the list of triples (eigenval, multiplicity,
        basis) for the left eigenvectors. Options are the same as for
        eigenvects(), i.e. the ``**flags`` arguments gets passed directly to
        eigenvects().

        Examples
        ========

        >>> from sympy import Matrix
        >>> M = Matrix([[0, 1, 1], [1, 0, 0], [1, 1, 1]])
        >>> M.eigenvects()
        [(-1, 1, [Matrix([
        [-1],
        [ 1],
        [ 0]])]), (0, 1, [Matrix([
        [ 0],
        [-1],
        [ 1]])]), (2, 1, [Matrix([
        [2/3],
        [1/3],
        [  1]])])]
        >>> M.left_eigenvects()
        [(-1, 1, [Matrix([[-2, 1, 1]])]), (0, 1, [Matrix([[-1, -1, 1]])]), (2,
        1, [Matrix([[1, 1, 1]])])]

        (   Ro   R   (   R6   R   R   R   R   R   R  (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   left_eigenvects  s    c         C  s   |  } |  j  |  j k r. | j | j   } n | | j j   } g  } x1 | j   D]# \ } } | t |  g | 7} qT Wt |  |  j k  r | t j g |  j t |  7} n  | j	 d t
 d t  | S(   s_  Compute the singular values of a Matrix

        Examples
        ========

        >>> from sympy import Matrix, Symbol
        >>> x = Symbol('x', real=True)
        >>> A = Matrix([[0, 1, 0], [0, x, 0], [-1, 0, 0]])
        >>> A.singular_values()
        [sqrt(x**2 + 1), 1, 0]

        See Also
        ========

        condition_number
        R,  R   (   RD   RE   t   HR   R   R   Rb   R   R@   R   R   R	   (   R6   RX   t   valmultpairst   valsRj   R   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   singular_values  s    $(   R<   R=   R>   R   R   R   R   R   R   R   R1   R   R   R?  R@  RD  (    (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyR   0  s   		GsiR	!t   MatrixCalculusc           B  sV   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 RS(	   s,   Provides calculus-related matrix operations.c         O  sV   d d l  m } | j d t  | |  d t | } t |  t  sN | j   S| Sd S(   s  Calculate the derivative of each element in the matrix.
        ``args`` will be passed to the ``integrate`` function.

        Examples
        ========

        >>> from sympy.matrices import Matrix
        >>> from sympy.abc import x, y
        >>> M = Matrix([[x, y], [1, 0]])
        >>> M.diff(x)
        Matrix([
        [1, 0],
        [0, 0]])

        See Also
        ========

        integrate
        limit
        i(   t
   Derivativet   evaluateN(   R  RF  t
   setdefaultR   R}   R   t
   as_mutable(   R6   R  R   RF  t   deriv(    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   diff  s    
c           s   |  j    f d    S(   Nc           s   |  j     S(   N(   RK  (   R0   (   t   arg(    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyRw     Rx   (   R   (   R6   RL  (    (   RL  s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   _eval_derivative  s    c         C  s   | j  |   S(   N(   t   _visit_eval_derivative_array(   R6   t   s(    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   _accept_eval_derivative  s    c           s   |  j    f d    S(   Nc           s     j  |   S(   N(   RK  (   R0   (   t   base(    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyRw     Rx   (   R   (   R6   RQ  (    (   RQ  s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   _visit_eval_derivative_scalar   s    c         C  s   d d l  m } | | |   S(   Ni(   t   derive_by_array(   R  RS  (   R6   RQ  RS  (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyRN    s    c           s   |  j    f d    S(   s  Integrate each element of the matrix.  ``args`` will
        be passed to the ``integrate`` function.

        Examples
        ========

        >>> from sympy.matrices import Matrix
        >>> from sympy.abc import x, y
        >>> M = Matrix([[x, y], [1, 0]])
        >>> M.integrate((x, ))
        Matrix([
        [x**2/2, x*y],
        [     x,   0]])
        >>> M.integrate((x, 0, 2))
        Matrix([
        [2, 2*y],
        [2,   0]])

        See Also
        ========

        limit
        diff
        c           s   |  j      S(   N(   t	   integrate(   R0   (   R  (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyRw   "  Rx   (   R   (   R6   R  (    (   R  s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyRT  	  s    c           s   t    t  s!  j      n   j d d k rD  j d } n/  j d d k rg  j d } n t d     j d d k r   j d } n/   j d d k r   j d } n t d    j | |    f d    S(   s  Calculates the Jacobian matrix (derivative of a vector-valued function).

        Parameters
        ==========

        ``self`` : vector of expressions representing functions f_i(x_1, ..., x_n).
        X : set of x_i's in order, it can be a list or a Matrix

        Both ``self`` and X can be a row or a column matrix in any order
        (i.e., jacobian() should always work).

        Examples
        ========

        >>> from sympy import sin, cos, Matrix
        >>> from sympy.abc import rho, phi
        >>> X = Matrix([rho*cos(phi), rho*sin(phi), rho**2])
        >>> Y = Matrix([rho, phi])
        >>> X.jacobian(Y)
        Matrix([
        [cos(phi), -rho*sin(phi)],
        [sin(phi),  rho*cos(phi)],
        [   2*rho,             0]])
        >>> X = Matrix([rho*cos(phi), rho*sin(phi)])
        >>> X.jacobian(Y)
        Matrix([
        [cos(phi), -rho*sin(phi)],
        [sin(phi),  rho*cos(phi)]])

        See Also
        ========

        hessian
        wronskian
        i    i   s)   ``self`` must be a row or a column matrixs"   X must be a row or a column matrixc           s    |  j    |  S(   N(   RK  (   RA   R7   (   t   XR6   (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyRw   [  Rx   (   R}   t
   MatrixBaseRF   t   shapet	   TypeError(   R6   RU  R  R~   (    (   RU  R6   s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   jacobian$  s    $c           s   |  j    f d    S(   s  Calculate the limit of each element in the matrix.
        ``args`` will be passed to the ``limit`` function.

        Examples
        ========

        >>> from sympy.matrices import Matrix
        >>> from sympy.abc import x, y
        >>> M = Matrix([[x, y], [1, 0]])
        >>> M.limit(x, 2)
        Matrix([
        [2, y],
        [1, 0]])

        See Also
        ========

        integrate
        diff
        c           s   |  j      S(   N(   t   limit(   R0   (   R  (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyRw   r  Rx   (   R   (   R6   R  (    (   R  s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyRZ  ]  s    (   R<   R=   R>   RK  RM  RP  RR  RN  RT  RY  RZ  (    (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyRE    s   							9t   MatrixDeprecatedc           B  s   e  Z d  Z d   Z e d  e d  Z d   Z d   Z d   Z	 d   Z
 d d	  Z d
   Z d   Z d   Z d   Z e d  Z d d  Z d   Z d   Z d   Z RS(   s+   A class to house deprecated matrix methods.c         C  s]  d d l  m } t | t  s t |  r t |  |  j k rw t |  |  j k rw t d |  j	 t |  f   n  |  j
 | |   St d t |    n  |  } | j | j k r | j d k r | j } | j } n  t | | j    } | S| j | j k r| j
 | j  S| j | j k r=| j j
 |  St d |  j	 | j	 f   d S(   sQ   Compatibility function for deprecated behavior of ``matrix.dot(vector)``
        i   (   t   Matrixs,   Dimensions incorrect for dot product: %s, %ss2   `b` must be an ordered iterable or Matrix, not %s.N(   t   denseR\  R}   RV  R
   Rb   RE   RD   R,   RW  R   RX  t   typet   TR'   t   tolist(   R6   R   R\  RX   t   prod(    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   _legacy_array_dotx  s0    *	Rr   c         C  s   |  j  d |  S(   NR0   (   Rt   (   R6   R0   R%   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   berkowitz_charpoly  s    c         C  s   |  j  d d  S(   sw   Computes determinant using Berkowitz method.

        See Also
        ========

        det
        berkowitz
        Rp   Rm   (   Ri   (   R6   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   berkowitz_det  s    	c         K  s   |  j  |   S(   sw   Computes eigenvalues of a Matrix using Berkowitz method.

        See Also
        ========

        berkowitz
        (   R   (   R6   R   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   berkowitz_eigenvals  s    c         C  sM   t  j g  } } x0 |  j   D]" } | j | | d  | } q Wt |  S(   sp   Computes principal minors using Berkowitz method.

        See Also
        ========

        berkowitz
        i(   R   RG   Rm   RH   R   (   R6   R_   t   minorst   poly(    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   berkowitz_minors  s
    c         C  s  d d l  m } d } |  s  | S|  j s5 t    n  |  |  j } } d g | d } xYt | d d  D]E} | | d |  | d } } | | d  |  f | d  |  | f }	 }
 | d  |  d  |  f | | | f } } |
 g } x0 t d | d  D] } | j | | |  qWx, t |  D] \ } } |	 | d | | <q2Wt j	 | g | } x6 t |  D]( } | | | d  | | d   | f <qtW| | | d <qi W|  j
 t j	 | d	 g  g } x/ t |  D]! \ } } | j | | |  qW| t t t |   S(
   Ni(   R   i   i    i   (   i   (   (   i   (   i    i    (   i    i    (   R	  R   Rs   R+   RD   R   RH   R   R   RG   RF   R   t   map(   R6   R   t   berkRL   t   Nt
   transformsR~   R_  Rj   RJ   RK   RI   R   R7   t   Bt   polys(    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyRm     s2    	..	& Rm   c         C  s   |  j  d |  S(   NRp   (   Rn   (   R6   Rp   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   cofactorMatrix  s    c         C  s   |  j  d d  S(   NRp   R`   (   Ri   (   R6   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt
   det_bareis  s    c         C  s   |  j  d d  S(   s;  Compute matrix determinant using Bareiss' fraction-free
        algorithm which is an extension of the well known Gaussian
        elimination method. This approach is best suited for dense
        symbolic matrices and will result in a determinant with
        minimal number of fractions. It means that less term
        rewriting is needed on resulting formulae.

        TODO: Implement algorithm for sparse matrices (SFF),
        http://www.eecis.udel.edu/~saunders/papers/sffge/it5.ps.

        See Also
        ========

        det
        berkowitz_det
        Rp   R`   (   Ri   (   R6   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   det_bareiss  s    c         C  s   |  j  d d  S(   s  Compute matrix determinant using LU decomposition


        Note that this method fails if the LU decomposition itself
        fails. In particular, if the matrix has no inverse this method
        will fail.

        TODO: Implement algorithm for sparse matrices (SFF),
        http://www.eecis.udel.edu/~saunders/papers/sffge/it5.ps.

        See Also
        ========


        det
        det_bareiss
        berkowitz_det
        Rp   Rg   (   Ri   (   R6   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   det_LU_decomposition  s    c         C  s   |  j  d | d |  S(   NR$  R'  (   R(  (   R6   R  R~   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   jordan_cell  s    c         C  s"   |  j    \ } } | | j   f S(   N(   R?  t   get_diag_blocks(   R6   t   calc_transformationt   Pt   J(    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   jordan_cells  s    c         C  s   |  j  | | d | S(   NRp   (   Ru   (   R6   R7   RA   Rp   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt
   minorEntry  s    c         C  s   |  j  | |  S(   N(   R   (   R6   R7   RA   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   minorMatrix!  s    c         C  s   |  j  | d d S(   sE   Permute the rows of the matrix with the given permutation in reverse.t	   directiont   backward(   t   permute_rows(   R6   R   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   permuteBkwd$  s    c         C  s   |  j  | d d S(   s:   Permute the rows of the matrix with the given permutation.R{  t   forward(   R}  (   R6   R   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt
   permuteFwd(  s    (   R<   R=   R>   Rb  R   R   Rc  Rd  Re  Rh  Rm   Ro  Rp  Rq  Rr  Rs  R   Rx  Ry  Rz  R~  R  (    (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyR[  v  s"   	!		
		(						RV  c           B  s  e  Z d  Z d Z e Z d Z e e  Z	 dB Z d   Z e Z e d  Z d   Z d   Z d   Z d   Z d	   Z d
   Z d   Z d   Z dB d  Z e d    Z d   Z d   Z d   Z e d  Z d   Z d   Z  d   Z! e" d    Z# d   Z$ dB dB d  Z% d   Z& d   Z' e( d  Z) d   Z* e+ d  Z, e+ d  Z- e+ d  Z. dB d   Z/ d!   Z0 d"   Z1 d#   Z2 e d$  Z3 d%   Z4 d&   Z5 e+ dB e( d'  Z6 e+ dB e( d(  Z7 d)   Z8 e+ d*  Z9 d+   Z: e+ d,  Z; dB d-  Z< dB d.  Z= d/   Z> d0 d1  Z? d2   Z@ d3   ZA d4   ZB e+ e( d5  ZC d6 d7  ZD d8 d9  ZE d: d; d< d= d> d?  ZF d@   ZG e e dA  ZH RS(C   s   Base class for matrix objects.i   i   c         C  s*   d d l  m } | |  d d } d | S(   s^  
        IPython/Jupyter LaTeX printing

        To change the behavior of this (e.g., pass in some settings to LaTeX),
        use init_printing(). init_printing() will also enable LaTeX printing
        for built in numeric types like ints and container types that contain
        SymPy objects, like lists and dictionaries of expressions.
        i(   t   latext   modet   plains   $\displaystyle %s$(   t   sympy.printing.latexR  (   R6   R  RO  (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   _repr_latex_A  s    	c         C  s    d d l  m } | |  d | S(   Ni   (   t   matrix2numpyt   dtype(   R]  R  (   R6   R  R  (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt	   __array__P  s    c           sB     d k r"    f d   } | St  d  j j   f   d  S(   NRK  RT  RZ  c            s      f d   }  j  |  S(   Nc           s   t  |        S(   N(   R.   (   t   item(   R  t   attr(    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyRw   W  Rx   (   R   (   R  t	   item_doit(   R  R6   (   R  s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   doitV  s    s   %s has no attribute %s.(   RK  RT  RZ  (   t   AttributeErrort	   __class__R<   (   R6   R  R  (    (   R  R6   s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   __getattr__T  s
    c         C  s   |  j  |  j S(   sk   Return the number of elements of ``self``.

        Implemented mainly so bool(Matrix()) == False.
        (   RD   RE   (   R6   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   __len___  s    c         C  st   d } x_ t  |  j  D]N } | d 7} x1 t  |  j  D]  } | |  | | f j   7} q6 W| d 7} q Wd | d S(   NRx   s   <matrixrow>s   </matrixrow>s   <matrix>s	   </matrix>(   R   RD   RE   t
   __mathml__(   R6   t   mmlR7   RA   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyR  f  s    
c         C  s   |  | k S(   N(    (   R6   t   other(    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   __ne__p  s    c   	        s   d d l  m } m } d d l m     f d   } |  j   \ } } | j   } g  | D] } | |  ^ qZ } x | D] } | | |  qy W|  j | | |   | j    S(   Ni(   R   t   MutableMatrix(   t   binomialc           s  |  j  d } |  d } | d k rH | | d k  t k rH t d   n7 | d k r | d k r | d d k r t d   n  x| t |  D]n } xe t | |  D]S }   | |  } t |    r | j   } n  | | | | |  | | | f <q Wq Wd  S(   Ni    i   s   Matrix det == 0; not invertibles%   Non-integer power cannot be evaluated(   i    i    (   RW  R   R|   R   R}   t   _eval_expand_func(   t   jcR~   Rk  R  R7   RA   t   bn(   R  (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   jordan_cell_powerw  s    
"((	   R	  R   R  R  R  R?  Rt  RF   t   inv(	   R6   R%  R   R  R  Rv  Rw  Rx  RA   (    (   R  s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   _matrix_pow_by_jordan_blockss  s    c         C  s
   t  |   S(   N(   R#   (   R6   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyR;     s    c         C  sF   |  j  d k s |  j d k r2 d |  j  |  j f Sd t |  j    S(   Ni    s   Matrix(%s, %s, [])s
   Matrix(%s)(   RD   RE   t   strR`  (   R6   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyR:     s    c         C  s   |  `  |  ` |  ` d  S(   N(   t   _is_symbolict   _is_symmetrict   _eigenvects(   R6   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   _diagonalize_clear_subproducts  s    c         C  s   | s" d d l  m } |   } n  |  j d k s@ |  j d k rT d |  j |  j f S|  j d k rz d |  j | d d Sd	 |  j | d d S(
   Ni(   t
   StrPrinteri    s   Matrix(%s, %s, [])i   s   Matrix([%s])t   rowseps   ,
s   Matrix([
%s])(   t   sympy.printing.strR  RD   RE   t   table(   R6   t   printerR  (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   _format_str  s    c      	   O  s  d d l  m } d } t |  d k rt | d |  rf | d j | d j t | d j    f St | d t	  r | d j | d j | d j
 f St | d t  r | d j r | d j | d j | d j   j
 f St | d d  r| d j   } t | j  d k rk| j d | j d } } g  | j   D] } |  j |  ^ qC} | | | f St | j  d k r| j d d } } t j g | } x1 t t |   D] } |  j | |  | | <qW| | | f St d   qnt | d  rnt | d t  rng  }	 t   }
 x | d D] } t | t	  r|	 j | j    | j sl| j r|
 j | j  qq2|	 j |  y |
 j t |   Wq2t k
 r|
 j d  q2Xq2Wt |
  d k rt d t t  |
     n  |
 r|
 j!   n d } | r&t |	  n d } | rzt |	 d  szd } g  |	 D] } |  j |  ^ qO} | | | f Sn  g  } xL t |  D]; } x2 t |  D]$ } | j |  j |	 | |   qWqWqnnt |  d	 k rIt" | d  } t" | d  } | d k  s| d k  r7t d
 j# | |    n  t |  d	 k rt | d t$  r| d } g  } x t |  D]P } | j g  t |  D]0 } |  j | |  j |  |  j |    ^ q qyWqnt |  d	 k rnt | d  rn| d } t |  | | k r!t d   n  g  | D] } |  j |  ^ q(} qnn% t |  d k rnd } } g  } n  | d k rt d   n  | | | f S(   s   Return the number of rows, cols and flat matrix elements.

        Examples
        ========

        >>> from sympy import Matrix, I

        Matrix can be constructed as follows:

        * from a nested list of iterables

        >>> Matrix( ((1, 2+I), (3, 4)) )
        Matrix([
        [1, 2 + I],
        [3,     4]])

        * from un-nested iterable (interpreted as a column)

        >>> Matrix( [1, 2] )
        Matrix([
        [1],
        [2]])

        * from un-nested iterable with dimensions

        >>> Matrix(1, 2, [1, 2] )
        Matrix([[1, 2]])

        * from no arguments (a 0 x 0 matrix)

        >>> Matrix()
        Matrix(0, 0, [])

        * from a rule

        >>> Matrix(2, 2, lambda i, j: i/(j + 1) )
        Matrix([
        [0,   0],
        [1, 1/2]])

        i(   t   SparseMatrixi   i    R  i   s&   SymPy supports just 1D and 2D matricess    Got rows of variable lengths: %si   s@   Cannot create a {} x {} matrix. Both dimensions must be positives+   List length should be equal to rows*columnss   Data type not understoodN(%   t   sympy.matrices.sparseR  R/   Rb   R}   RD   RE   R'   R`  RV  R*  R   t	   is_Matrixt   as_explicitt   hasattrR  RW  t   ravelt   _sympifyR   R@   R   R  R
   R3   R   R-  t   addRH   RX  R|   R   R\   R   R   R   R   (   R   R  R   R  t	   flat_listt   arrRD   RE   R7   t   in_matt   ncolR   RA   R   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   _handle_creation_inputs  s    ++" ((	",	%
H"
(
	c         C  s  d d l  m } t | t  } |  j |  \ } } } t | t  } t |  t k sk t |  t k r | r |  j | |  d St | t  r t	 |  r |  j
 | |  d St d |   n | r t | t  r t	 |  r | |  } t } n  | r~| r?t t | |  j    t t | |  j    f } n, t | | | j  t | | | j  f } |  j | |  n | | |  j |  f Sd Sd S(   sm  Helper to set value at location given by key.

        Examples
        ========

        >>> from sympy import Matrix, I, zeros, ones
        >>> m = Matrix(((1, 2+I), (3, 4)))
        >>> m
        Matrix([
        [1, 2 + I],
        [3,     4]])
        >>> m[1, 0] = 9
        >>> m
        Matrix([
        [1, 2 + I],
        [9,     4]])
        >>> m[1, 0] = [[0, 1]]

        To replace row r you assign to position r*m where m
        is the number of columns:

        >>> M = zeros(4)
        >>> m = M.cols
        >>> M[3*m] = ones(1, m)*2; M
        Matrix([
        [0, 0, 0, 0],
        [0, 0, 0, 0],
        [0, 0, 0, 0],
        [2, 2, 2, 2]])

        And to replace column c you can assign to position c:

        >>> M[2] = ones(m, 1)*4; M
        Matrix([
        [0, 0, 4, 0],
        [0, 0, 4, 0],
        [0, 0, 4, 0],
        [2, 2, 4, 2]])
        i   (   R\  Ns   unexpected value: %s(   R]  R\  R}   t   slicet   key2ijRV  R^  t   copyin_matrixR   R
   t   copyin_listR|   R   R   t   divmodRE   RD   R  (   R6   R   R   R\  t   is_sliceR7   RA   t   is_mat(    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   _setitem9	  s2    ($	c         C  s   |  | S(   s   Return self + b (    (   R6   R   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyR  	  s    c         C  s   t  } |  j   r- t } |  j d |  } ne |  j rK |  j d |  } nG |  j |  j k r |  j |  j d |  } |  j | } n t d   | j	 |  } | r | j j
 |  S| j j
 |  Sd S(   s  Solves ``Ax = B`` using Cholesky decomposition,
        for a general square non-singular matrix.
        For a non-square matrix with rows > cols,
        the least squares solution is returned.

        See Also
        ========

        lower_triangular_solve
        upper_triangular_solve
        gauss_jordan_solve
        diagonal_solve
        LDLsolve
        LUsolve
        QRsolve
        pinv_solve
        t	   hermitians6   Under-determined System. Try M.gauss_jordan_solve(rhs)N(   R   R  R   t	   _choleskyt   is_hermitianRD   RE   RA  R  t   _lower_triangular_solvet   _upper_triangular_solveR_  (   R6   t   rhsR  t   Lt   Y(    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   cholesky_solve	  s    	c         C  sj   |  j  s t d   n  | r7 |  j r7 t d   n  | rZ |  j   rZ t d   n  |  j d |  S(   sw  Returns the Cholesky-type decomposition L of a matrix A
        such that L * L.H == A if hermitian flag is True,
        or L * L.T == A if hermitian is False.

        A must be a Hermitian positive-definite matrix if hermitian is True,
        or a symmetric matrix if it is False.

        Examples
        ========

        >>> from sympy.matrices import Matrix
        >>> A = Matrix(((25, 15, -5), (15, 18, 0), (-5, 0, 11)))
        >>> A.cholesky()
        Matrix([
        [ 5, 0, 0],
        [ 3, 3, 0],
        [-1, 1, 3]])
        >>> A.cholesky() * A.cholesky().T
        Matrix([
        [25, 15, -5],
        [15, 18,  0],
        [-5,  0, 11]])

        The matrix can have complex entries:

        >>> from sympy import I
        >>> A = Matrix(((9, 3*I), (-3*I, 5)))
        >>> A.cholesky()
        Matrix([
        [ 3, 0],
        [-I, 2]])
        >>> A.cholesky() * A.cholesky().H
        Matrix([
        [   9, 3*I],
        [-3*I,   5]])

        Non-hermitian Cholesky-type decomposition may be useful when the
        matrix is not positive-definite.

        >>> A = Matrix([[1, 2], [2, 1]])
        >>> L = A.cholesky(hermitian=False)
        >>> L
        Matrix([
        [1,         0],
        [2, sqrt(3)*I]])
        >>> L*L.T == A
        True

        See Also
        ========

        LDLdecomposition
        LUdecomposition
        QRdecomposition
        s   Matrix must be square.s   Matrix must be Hermitian.s   Matrix must be symmetric.R  (   Rs   R+   R  R|   R  R  (   R6   R  (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   cholesky	  s    9	c         C  s-   |  s t  j S|  j   } t |   t |   S(   s{  Returns the condition number of a matrix.

        This is the maximum singular value divided by the minimum singular value

        Examples
        ========

        >>> from sympy import Matrix, S
        >>> A = Matrix([[1, 0, 0], [0, 10, 0], [0, 0, S.One/10]])
        >>> A.condition_number()
        100

        See Also
        ========

        singular_values
        (   R   R@   RD  R   R   (   R6   t   singularvalues(    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   condition_number	  s    c         C  s   |  j  |  j |  j |  j  S(   s   
        Returns the copy of a matrix.

        Examples
        ========

        >>> from sympy import Matrix
        >>> A = Matrix(2, 2, [1, 2, 3, 4])
        >>> A.copy()
        Matrix([
        [1, 2],
        [3, 4]])

        (   RF   RD   RE   R*  (   R6   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   copy	  s    c      	   C  s   t  |  s% t d t |    n  |  j |  j | j | j k oP d k n s t d |  j |  j f | j | j f f   nv |  j |  j |  j |  d | d |  d | d |  d | d |  d | d |  d | d |  d | d f  Sd S(   s  
        Return the cross product of ``self`` and ``b`` relaxing the condition
        of compatible dimensions: if each has 3 elements, a matrix of the
        same type and shape as ``self`` will be returned. If ``b`` has the same
        shape as ``self`` then common identities for the cross product (like
        `a \times b = - b \times a`) will hold.

        Parameters
        ==========
            b : 3x1 or 1x3 Matrix

        See Also
        ========

        dot
        multiply
        multiply_elementwise
        s2   `b` must be an ordered iterable or Matrix, not %s.i   s/   Dimensions incorrect for cross product: %s x %si   i   i    N(   R
   RX  R^  RD   RE   R,   RF   (   R6   R   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   cross
  s    0+c         C  s9   d d l  m } |  j d k r( t  n  |  j | d  S(   so  Return Dirac conjugate (if ``self.rows == 4``).

        Examples
        ========

        >>> from sympy import Matrix, I, eye
        >>> m = Matrix((0, 1 + I, 2, 3))
        >>> m.D
        Matrix([[0, 1 - I, -2, -3]])
        >>> m = (eye(4) + I*eye(4))
        >>> m[0, 3] = 2
        >>> m.D
        Matrix([
        [1 - I,     0,      0,      0],
        [    0, 1 - I,      0,      0],
        [    0,     0, -1 + I,      0],
        [    2,     0,      0, -1 + I]])

        If the matrix does not have 4 rows an AttributeError will be raised
        because this property is only defined for matrices with 4 rows.

        >>> Matrix(eye(2)).D
        Traceback (most recent call last):
        ...
        AttributeError: Matrix has no attribute D.

        See Also
        ========

        conjugate: By-element conjugation
        H: Hermite conjugation
        i(   t   mgammai   i    (   t   sympy.physics.matricesR  RD   R  RA  (   R6   R  (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   D0
  s    "	c         C  sI   |  j    s t d   n  | j |  j k r< t d   n  |  j |  S(   s  Solves ``Ax = B`` efficiently, where A is a diagonal Matrix,
        with non-zero diagonal entries.

        Examples
        ========

        >>> from sympy.matrices import Matrix, eye
        >>> A = eye(2)*2
        >>> B = Matrix([[1, 2], [3, 4]])
        >>> A.diagonal_solve(B) == B/2
        True

        See Also
        ========

        lower_triangular_solve
        upper_triangular_solve
        gauss_jordan_solve
        cholesky_solve
        LDLsolve
        LUsolve
        QRsolve
        pinv_solve
        s   Matrix should be diagonals   Size mis-match(   t   is_diagonalRX  RD   t   _diagonal_solve(   R6   R  (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   diagonal_solve[
  s
    c      	   C  s)  d d l  m } t | t  s t |  r t |  |  j k rw t |  |  j k rw t d |  j	 t |  f   n  |  j
 | |   St d t |    n  |  } d | j	 k s d | j	 k r t d d d d d	 d
 d d  j   | j |  St |  t |  k r0t d |  j	 | j	 f   n  t |  } | j	 d | f k rf| j d |  } n  | j	 | d f k r| j | d  } n  | d k	 r| d k rt } n  | r| d k rd } n  | t k r| d k r| j   } q| d k r| j   } qt d   n  | | d S(   s4  Return the dot or inner product of two vectors of equal length.
        Here ``self`` must be a ``Matrix`` of size 1 x n or n x 1, and ``b``
        must be either a matrix of size 1 x n, n x 1, or a list/tuple of length n.
        A scalar is returned.

        By default, ``dot`` does not conjugate ``self`` or ``b``, even if there are
        complex entries. Set ``hermitian=True`` (and optionally a ``conjugate_convention``)
        to compute the hermitian inner product.

        Possible kwargs are ``hermitian`` and ``conjugate_convention``.

        If ``conjugate_convention`` is ``"left"``, ``"math"`` or ``"maths"``,
        the conjugate of the first vector (``self``) is used.  If ``"right"``
        or ``"physics"`` is specified, the conjugate of the second vector ``b`` is used.

        Examples
        ========

        >>> from sympy import Matrix
        >>> M = Matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
        >>> v = Matrix([1, 1, 1])
        >>> M.row(0).dot(v)
        6
        >>> M.col(0).dot(v)
        12
        >>> v = [3, 2, 1]
        >>> M.row(0).dot(v)
        10

        >>> from sympy import I
        >>> q = Matrix([1*I, 1*I, 1*I])
        >>> q.dot(q, hermitian=False)
        -3

        >>> q.dot(q, hermitian=True)
        3

        >>> q1 = Matrix([1, 1, 1*I])
        >>> q.dot(q1, hermitian=True, conjugate_convention="maths")
        1 - 2*I
        >>> q.dot(q1, hermitian=True, conjugate_convention="physics")
        1 + 2*I


        See Also
        ========

        cross
        multiply
        multiply_elementwise
        i   (   R\  s,   Dimensions incorrect for dot product: %s, %ss2   `b` must be an ordered iterable or Matrix, not %s.R   s%   Dot product of non row/column vectorsR   i5  R   s   1.2t
   useinsteads   * to take matrix productst   mathst   leftt   matht   physicst   rights   Unknown conjugate_convention was entered. conjugate_convention must be one of the following: math, maths, left, physics or right.i    N(   R  R  R  (   R  R  (   R]  R\  R}   RV  R
   Rb   RE   RD   R,   RW  R   RX  R^  R&   R   Rb  t   reshapeR/   R   t	   conjugateR|   (   R6   R   R  t   conjugate_conventionR\  RX   R~   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyR   z
  sJ    4*			c      	   C  s  d d l  m } d d l m } |  d d  d d  f |  j } } | |  } |  j   rb | Sx t d |  D] } x t d |  D]n } d } x> t d |  D]- }	 | | | | d |	  | d |	 f 7} q W| | | | f <| | | | f <q Wqr Wx t d |  D] }
 d } xX t d |  D]G } x> t d |  D]- } | | d |
 | |  | | | f 7} q@Wq*W| d } | | d |
 f <| | |
 d f <qW| S(   s  Returns the dual of a matrix, which is:

        ``(1/2)*levicivita(i, j, k, l)*M(k, l)`` summed over indices `k` and `l`

        Since the levicivita method is anti_symmetric for any pairwise
        exchange of indices, the dual of a symmetric matrix is the zero
        matrix. Strictly speaking the dual defined here assumes that the
        'matrix' `M` is a contravariant anti_symmetric second rank tensor,
        so that the dual is a covariant second rank tensor.

        i(   t
   LeviCivita(   R   Ni   i    i   (   R  R  R	  R   RD   R  R   (   R6   R  R   t   MR~   t   workR7   RA   t   acumRj   R  RI   R   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   dual
  s,    &+/
c   
      C  s   |  j  s t d   n  y" |  j   \ } } | j   } Wn t k
 rY t d   n Xd   } t t | |   } d d l m	 } d d l
 m } | |   } | | | j   }	 t d   |  j   D  r t |   | |	   St |   |	  Sd S(	   s-   Return the exponentiation of a square matrix.s0   Exponentiation is valid only for square matricess`   Exponentiation is implemented only for matrices for which the Jordan normal form can be computedc   	      S  s   |  j  } |  d } | d k r. t |  } n d d l m } |  d | |  } |  | } | |  } x/ t d |  D] } | | | t |  } qx Wt |  d  | } | S(   Ni    i   i(   R   (   i    i    (   i    i    (   i    i    (   RD   R   R  R   R   R   (	   R   t   nrR  t   resR   RM   R~   t   nexR7   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   _jblock_exponential  s    	

i(   R   (   t   rec         s  s   |  ] } | j  Vq d  S(   N(   R  (   RS   R   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pys	   <genexpr>0  s    N(   Rs   R+   R?  Rt  R*   R  R\   Ri  R	  R   R  R  R  R   R   R^  (
   R6   Rv  Rw  t   cellsR  R1  R   R  t   eJRV   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyR   
  s$    		c           s  d d l  m } m } |  j |  j   | j    } | j } | d d  d |  f j \ }   | j d t  \ } }	 | d d  d |  f | d d  | d  f } }
 t	 t
   f d   |	   }	 t |	  } | t     j } x* t |	  D] \ } } | j | |  qW|
 | d  d d  f j sPt d   n  | t |	  } t d | d d	   j } t |  } | g  t   | |  D] } t |  ^ q j   | |  } | d |  d d  f } x! t |	  D] } | j |  qW|
 d |  d d  f } | j | | | |  } |   |  } x> t    D]0 } | | d d  f | | | d d  f <q\W| r| | | f S| | f Sd S(
   s  
        Solves ``Ax = B`` using Gauss Jordan elimination.

        There may be zero, one, or infinite solutions.  If one solution
        exists, it will be returned. If infinite solutions exist, it will
        be returned parametrically. If no solutions exist, It will throw
        ValueError.

        Parameters
        ==========

        B : Matrix
            The right hand side of the equation to be solved for.  Must have
            the same number of rows as matrix A.

        freevar : List
            If the system is underdetermined (e.g. A has more columns than
            rows), infinite solutions are possible, in terms of arbitrary
            values of free variables. Then the index of the free variables
            in the solutions (column Matrix) will be returned by freevar, if
            the flag `freevar` is set to `True`.

        Returns
        =======

        x : Matrix
            The matrix that will satisfy ``Ax = B``.  Will have as many rows as
            matrix A has columns, and as many columns as matrix B.

        params : Matrix
            If the system is underdetermined (e.g. A has more columns than
            rows), infinite solutions are possible, in terms of arbitrary
            parameters. These arbitrary parameters are returned as params
            Matrix.

        Examples
        ========

        >>> from sympy import Matrix
        >>> A = Matrix([[1, 2, 1, 1], [1, 2, 2, -1], [2, 4, 0, 6]])
        >>> B = Matrix([7, 12, 4])
        >>> sol, params = A.gauss_jordan_solve(B)
        >>> sol
        Matrix([
        [-2*tau0 - 3*tau1 + 2],
        [                 tau0],
        [           2*tau1 + 5],
        [                 tau1]])
        >>> params
        Matrix([
        [tau0],
        [tau1]])
        >>> taus_zeroes = { tau:0 for tau in params }
        >>> sol_unique = sol.xreplace(taus_zeroes)
        >>> sol_unique
         Matrix([
        [2],
        [0],
        [5],
        [0]])


        >>> A = Matrix([[1, 2, 3], [4, 5, 6], [7, 8, 10]])
        >>> B = Matrix([3, 6, 9])
        >>> sol, params = A.gauss_jordan_solve(B)
        >>> sol
        Matrix([
        [-1],
        [ 2],
        [ 0]])
        >>> params
        Matrix(0, 1, [])

        >>> A = Matrix([[2, -7], [-1, 4]])
        >>> B = Matrix([[-21, 3], [12, -2]])
        >>> sol, params = A.gauss_jordan_solve(B)
        >>> sol
        Matrix([
        [0, -2],
        [3, -1]])
        >>> params
        Matrix(0, 2, [])

        See Also
        ========

        lower_triangular_solve
        upper_triangular_solve
        cholesky_solve
        diagonal_solve
        LDLsolve
        LUsolve
        QRsolve
        pinv

        References
        ==========

        .. [1] https://en.wikipedia.org/wiki/Gaussian_elimination

        i(   R\  R   NR%   c           s
   |    k  S(   N(    (   R   (   R   (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyRw     Rx   s   Linear system has no solutiont   taut   comparec         S  s   t  |   j d  S(   Nt
   1234567890(   R  t   rstrip(   R7   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyRw     Rx   (   R	  R\  R   R   R  RE   RW  R   R   R\   t   filterRb   R   R_  R   t   col_swapR-   R|   R   R5   R(   t   nextR  R.  t   col_delt   vstack(   R6   Rm  t   freevarR\  R   t   augt   B_colsR   RL   R   R   R   t   permutationR7   t   ct   free_var_indexR5   t   genRj   R  t   Vt   vtt   free_solt   sol(    (   R   s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   gauss_jordan_solve5  s>    f	&;3.c   	   
   C  s   |  j  s t    n  |  j } |  j   } d } y t | |  } Wn! t k
 rf t d |   n X|  j   } |  j | | g  t	 |  D]1 } t	 |  D] } | | | | f | ^ q q  } | S(   st  
        Returns the inverse of the matrix `K` (mod `m`), if it exists.

        Method to find the matrix inverse of `K` (mod `m`) implemented in this function:

        * Compute `\mathrm{adj}(K) = \mathrm{cof}(K)^t`, the adjoint matrix of `K`.

        * Compute `r = 1/\mathrm{det}(K) \pmod m`.

        * `K^{-1} = r\cdot \mathrm{adj}(K) \pmod m`.

        Examples
        ========

        >>> from sympy import Matrix
        >>> A = Matrix(2, 2, [1, 2, 3, 4])
        >>> A.inv_mod(5)
        Matrix([
        [3, 1],
        [4, 2]])
        >>> A.inv_mod(3)
        Matrix([
        [1, 1],
        [0, 1]])

        s!   Matrix is not invertible (mod %d)N(
   Rs   R+   RE   Ri   R/   R   R|   Rq   R  R   (	   R6   R  Rk  t   det_Kt   det_invt   K_adjR7   RA   t   K_inv(    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   inv_mod  s    		4c           s   |  j  s t d   n  |  j d d  } | j d  } | d k r |  j d t  d  t    f d   t  j	  D  } n  | r t
 d   n  |  j   | S(	   s   Calculates the inverse using the adjugate matrix and a determinant.

        See Also
        ========

        inv
        inverse_LU
        inverse_GE
        s"   A Matrix must be square to invert.Rp   Rm   i    R%   c         3  s%   |  ] }    | | f  Vq d  S(   N(    (   RS   RA   (   RR   t   ok(    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pys	   <genexpr>  s    s    Matrix det == 0; not invertible.N(   Rs   R+   Ri   t   equalsR/   R   R   t   anyR   RD   R|   Rq   (   R6   RR   RM   t   zero(    (   RR   R   s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   inverse_ADJ  s    
	+c           s   d d l  m } |  j s( t d   n  | j |  j   | j |  j   } | j d   d t	  d  t
    f d   t  j  D  r t d   n  |  j  d	 d	  | j d	  f  S(
   s   Calculates the inverse using Gaussian elimination.

        See Also
        ========

        inv
        inverse_LU
        inverse_ADJ
        i   (   R\  s"   A Matrix must be square to invert.RR   R%   i    c         3  s%   |  ] }    | | f  Vq d  S(   N(    (   RS   RA   (   RR   t   red(    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pys	   <genexpr>$  s    s    Matrix det == 0; not invertible.N(   R]  R\  Rs   R+   R   RI  R   RD   R   R   R  R   R|   RF   (   R6   RR   R\  t   big(    (   RR   R  s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt
   inverse_GE  s    
	$(c           s   |  j  s t    n  |  j d t  d  t    f d   t  j  D  rb t d   n  |  j |  j	 |  j  d t
 S(   s   Calculates the inverse using LU decomposition.

        See Also
        ========

        inv
        inverse_GE
        inverse_ADJ
        R%   i    c         3  s%   |  ] }    | | f  Vq d  S(   N(    (   RS   RA   (   RR   R   (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pys	   <genexpr>7  s    s    Matrix det == 0; not invertible.RR   (   Rs   R+   R   R   R  R   RD   R|   t   LUsolveR   R1   (   R6   RR   (    (   RR   R   s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt
   inverse_LU)  s    
	(c         K  s;   |  j  s t    n  | d k	 r. | | d <n  |  j |   S(   s  
        Return the inverse of a matrix.

        CASE 1: If the matrix is a dense matrix.

        Return the matrix inverse using the method indicated (default
        is Gauss elimination).

        Parameters
        ==========

        method : ('GE', 'LU', or 'ADJ')

        Notes
        =====

        According to the ``method`` keyword, it calls the appropriate method:

          GE .... inverse_GE(); default
          LU .... inverse_LU()
          ADJ ... inverse_ADJ()

        See Also
        ========

        inverse_LU
        inverse_GE
        inverse_ADJ

        Raises
        ------
        ValueError
            If the determinant of the matrix is zero.

        CASE 2: If the matrix is a sparse matrix.

        Return the matrix inverse using Cholesky or LDL (default).

        kwargs
        ======

        method : ('CH', 'LDL')

        Notes
        =====

        According to the ``method`` keyword, it calls the appropriate method:

          LDL ... inverse_LDL(); default
          CH .... inverse_CH()

        Raises
        ------
        ValueError
            If the determinant of the matrix is zero.

        Rp   N(   Rs   R+   R/   t   _eval_inverse(   R6   Rp   R   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyR  <  s
    :	c         C  sb   |  s
 t  S|  j s" t d   n  t d |   } |  j |  } | j d | |  j k r^ t  St S(   s  Checks if a matrix is nilpotent.

        A matrix B is nilpotent if for some integer k, B**k is
        a zero matrix.

        Examples
        ========

        >>> from sympy import Matrix
        >>> a = Matrix([[0, 0, 0], [1, 0, 0], [1, 1, 0]])
        >>> a.is_nilpotent()
        True

        >>> a = Matrix([[1, 0, 1], [1, 0, 0], [1, 1, 0]])
        >>> a.is_nilpotent()
        False
        s,   Nilpotency is valid only for square matricesR0   i    (   R   Rs   R+   R   Rt   R  RD   R   (   R6   R0   R   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   is_nilpotent|  s    	c   
      C  s  d d l  m } g  | D] } t | t  ^ q \ } } | rw |  j sT d } } q | d j |  j  d  \ } } n  | | d |  j  } | d } | r |  j s d } }	 q | d j |  j  d  \ } }	 n  | | d |  j  } | d }	 | | | |	 f S(   s   Converts a key with potentially mixed types of keys (integer and slice)
        into a tuple of ranges and raises an error if any index is out of ``self``'s
        range.

        See Also
        ========

        key2ij
        i(   t   a2idxi    i   i   (   t   sympy.matrices.commonR  R}   R  RD   t   indicesRE   (
   R6   R+  t   a2idx_Rj   t   islicet   jslicet   rlot   rhit   clot   chi(    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt
   key2bounds  s    
(	#
	#
c         C  s   d d l  m } t |  r t |  d k s= t d   n  g  t | |  j  D]0 \ } } t | t  sz | | |  n | ^ qP St | t  r | j	 t |    d  St
 | | t |    |  j  Sd S(   s   Converts key into canonical form, converting integers or indexable
        items into valid integers for ``self``'s range or returning slices
        unchanged.

        See Also
        ========

        key2bounds
        i(   R  i   s"   key must be a sequence of length 2N(   R  R  R
   Rb   RX  t   zipRW  R}   R  R  R  RE   (   R6   R   R  R7   R~   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyR    s    
Dc         C  sj   |  j  s t d   n  | r7 |  j r7 t d   n  | rZ |  j   rZ t d   n  |  j d |  S(   s  Returns the LDL Decomposition (L, D) of matrix A,
        such that L * D * L.H == A if hermitian flag is True, or
        L * D * L.T == A if hermitian is False.
        This method eliminates the use of square root.
        Further this ensures that all the diagonal entries of L are 1.
        A must be a Hermitian positive-definite matrix if hermitian is True,
        or a symmetric matrix otherwise.

        Examples
        ========

        >>> from sympy.matrices import Matrix, eye
        >>> A = Matrix(((25, 15, -5), (15, 18, 0), (-5, 0, 11)))
        >>> L, D = A.LDLdecomposition()
        >>> L
        Matrix([
        [   1,   0, 0],
        [ 3/5,   1, 0],
        [-1/5, 1/3, 1]])
        >>> D
        Matrix([
        [25, 0, 0],
        [ 0, 9, 0],
        [ 0, 0, 9]])
        >>> L * D * L.T * A.inv() == eye(A.rows)
        True

        The matrix can have complex entries:

        >>> from sympy import I
        >>> A = Matrix(((9, 3*I), (-3*I, 5)))
        >>> L, D = A.LDLdecomposition()
        >>> L
        Matrix([
        [   1, 0],
        [-I/3, 1]])
        >>> D
        Matrix([
        [9, 0],
        [0, 4]])
        >>> L*D*L.H == A
        True

        See Also
        ========

        cholesky
        LUdecomposition
        QRdecomposition
        s   Matrix must be square.s   Matrix must be Hermitian.s   Matrix must be symmetric.R  (   Rs   R+   R  R|   R  t   _LDLdecomposition(   R6   R  (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   LDLdecomposition  s    3	c         C  s   t  } |  j   r3 t } |  j d |  \ } } nq |  j rW |  j d |  \ } } nM |  j |  j k r |  j |  j d |  \ } } |  j | } n t d   | j	 |  } | j
 |  } | r | j j |  S| j j |  Sd S(   s  Solves ``Ax = B`` using LDL decomposition,
        for a general square and non-singular matrix.

        For a non-square matrix with rows > cols,
        the least squares solution is returned.

        Examples
        ========

        >>> from sympy.matrices import Matrix, eye
        >>> A = eye(2)*2
        >>> B = Matrix([[1, 2], [3, 4]])
        >>> A.LDLsolve(B) == B/2
        True

        See Also
        ========

        LDLdecomposition
        lower_triangular_solve
        upper_triangular_solve
        gauss_jordan_solve
        cholesky_solve
        diagonal_solve
        LUsolve
        QRsolve
        pinv_solve
        R  s6   Under-determined System. Try M.gauss_jordan_solve(rhs)N(   R   R  R   R  R  RD   RE   RA  R  R  R  R  R_  (   R6   R  R  R  R  R  t   Z(    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   LDLsolve	  s    	c         C  s^   |  j  s t d   n  | j |  j k r9 t d   n  |  j sQ t d   n  |  j |  S(   s  Solves ``Ax = B``, where A is a lower triangular matrix.

        See Also
        ========

        upper_triangular_solve
        gauss_jordan_solve
        cholesky_solve
        diagonal_solve
        LDLsolve
        LUsolve
        QRsolve
        pinv_solve
        s   Matrix must be square.s   Matrices size mismatch.s    Matrix must be lower triangular.(   Rs   R+   RD   R,   R   R|   R  (   R6   R  (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   lower_triangular_solve9  s    		c   	        s   |  j  d | d | d |  \   }   f d   }   f d   } |  j   j   j |  } |  j   j   j |  } | | | f S(   s  Returns (L, U, perm) where L is a lower triangular matrix with unit
        diagonal, U is an upper triangular matrix, and perm is a list of row
        swap index pairs. If A is the original matrix, then
        A = (L*U).permuteBkwd(perm), and the row permutation matrix P such
        that P*A = L*U can be computed by P=eye(A.row).permuteFwd(perm).

        See documentation for LUCombined for details about the keyword argument
        rankcheck, iszerofunc, and simpfunc.

        Examples
        ========

        >>> from sympy import Matrix
        >>> a = Matrix([[4, 3], [6, 3]])
        >>> L, U, _ = a.LUdecomposition()
        >>> L
        Matrix([
        [  1, 0],
        [3/2, 1]])
        >>> U
        Matrix([
        [4,    3],
        [0, -3/2]])

        See Also
        ========

        cholesky
        LDLdecomposition
        QRdecomposition
        LUdecomposition_Simple
        LUdecompositionFF
        LUsolve
        RR   Re   t	   rankcheckc           sJ   |  | k  r t  j S|  | k r& t  j S|   j k  rC   |  | f St  j S(   N(   R   R@   RG   RE   (   R7   RA   (   t   combined(    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   entry_L  s    c           s!   |  | k r t  j S  |  | f S(   N(   R   R@   (   R7   RA   (   R  (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   entry_U  s    (   Rf   RF   RD   RE   (	   R6   RR   Re   R  R   R  R   R  t   U(    (   R  s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   LUdecompositionQ  s    '	c           s  | r	 n  |  j  d k s' |  j d k rC |  j |  j  |  j  g  f S|  j     g  } d  xt d   j  d  D]} t } x{  |  j k r | r    f d   t | |  j   D } t | | |  \ } }	 }
 } |	 d k } | r  d 7 q q W| r | k rt d   n  | d k r/d n | | } | d k rU| rU  | f Sx( | D]  \ } } |   | |  f <q\W| | k rH| j	 | | g    | d |  f   | d |  f   | d |  f <  | d |  f <  |    j  f   |    j  f   |    j  f <  |    j  f <n   d } x t | d   j   D] }   |  f   |  f   | | f <xP t |   j  D]< }   | | f   | | f   | | f   | | f <qWqiW|  k r1x4 t | d   j   D] } t
 j   |  f <qWn   d 7    j k rr   | f Sqr W| r|   t   j    j  d t   j    j  d f  rt d   qn    | f S(   s$  Compute an lu decomposition of m x n matrix A, where P*A = L*U

        * L is m x m lower triangular with unit diagonal
        * U is m x n upper triangular
        * P is an m x m permutation matrix

        Returns an m x n matrix lu, and an m element list perm where each
        element of perm is a pair of row exchange indices.

        The factors L and U are stored in lu as follows:
        The subdiagonal elements of L are stored in the subdiagonal elements
        of lu, that is lu[i, j] = L[i, j] whenever i > j.
        The elements on the diagonal of L are all 1, and are not explicitly
        stored.
        U is stored in the upper triangular portion of lu, that is
        lu[i ,j] = U[i, j] whenever i <= j.
        The output matrix can be visualized as:

            Matrix([
                [u, u, u, u],
                [l, u, u, u],
                [l, l, u, u],
                [l, l, l, u]])

        where l represents a subdiagonal entry of the L factor, and u
        represents an entry from the upper triangular entry of the U
        factor.

        perm is a list row swap index pairs such that if A is the original
        matrix, then A = (L*U).permuteBkwd(perm), and the row permutation
        matrix P such that ``P*A = L*U`` can be computed by
        ``P=eye(A.row).permuteFwd(perm)``.

        The keyword argument rankcheck determines if this function raises a
        ValueError when passed a matrix whose rank is strictly less than
        min(num rows, num cols). The default behavior is to decompose a rank
        deficient matrix. Pass rankcheck=True to raise a
        ValueError instead. (This mimics the previous behavior of this function).

        The keyword arguments iszerofunc and simpfunc are used by the pivot
        search algorithm.
        iszerofunc is a callable that returns a boolean indicating if its
        input is zero, or None if it cannot make the determination.
        simpfunc is a callable that simplifies its input.
        The default is simpfunc=None, which indicate that the pivot search
        algorithm should not attempt to simplify any candidate pivots.
        If simpfunc fails to simplify its input, then it must return its input
        instead of a copy.

        When a matrix contains symbolic entries, the pivot search algorithm
        differs from the case where every entry can be categorized as zero or
        nonzero.
        The algorithm searches column by column through the submatrix whose
        top left entry coincides with the pivot position.
        If it exists, the pivot is the first entry in the current search
        column that iszerofunc guarantees is nonzero.
        If no such candidate exists, then each candidate pivot is simplified
        if simpfunc is not None.
        The search is repeated, with the difference that a candidate may be
        the pivot if ``iszerofunc()`` cannot guarantee that it is nonzero.
        In the second search the pivot is the first candidate that
        iszerofunc can guarantee is nonzero.
        If no such candidate exists, then the pivot is the first candidate
        for which iszerofunc returns None.
        If no such candidate exists, then the search is repeated in the next
        column to the right.
        The pivot search algorithm differs from the one in ``rref()``, which
        relies on ``_find_reasonable_pivot()``.
        Future versions of ``LUdecomposition_simple()`` may use
        ``_find_reasonable_pivot()``.

        See Also
        ========

        LUdecomposition
        LUdecompositionFF
        LUsolve
        i    i   c         3  s   |  ] }   |  f Vq d  S(   N(    (   RS   t   r(   Rg   t	   pivot_col(    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pys	   <genexpr>  s    s   Rank of matrix is strictly less than number of rows or columns. Pass keyword argument rankcheck=False to compute the LU decomposition of this matrix.N(   RD   RE   R   RI  R   R   t   _find_reasonable_pivot_naiveR/   R|   RH   R   R@   R   (   R6   RR   Re   R  Rh   t	   pivot_rowt   iszeropivott   sub_colt   pivot_row_offsett   pivot_valuet   is_assumed_non_zerot   ind_simplified_pairst   candidate_pivot_rowR   R   t	   start_colR   R  (    (   Rg   R$  s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyRf     sT    S%
M\
(>
9c         C  s  d d l  m } | j } | j } |  j |  j } } |  j   | |  | |  } } } | | |  }	 d }
 x,t | d  D]} | | | f d k rx; t | d |  D] } | | | f r Pq q Wt d   | | | d  f | | | d  f | | | d  f <| | | d  f <| | d |  f | | d |  f | | d |  f <| | d |  f <| | d d  f | | d d  f | | d d  f <| | d d  f <n  | | | f | | | f <} |
 | |	 | | f <x t | d |  D] } | | | f | | | f <} xO t | d |  D]: } | | | | f | | | f | |
 | | | f <qCWd | | | f <qW| }
 q W|
 |	 | d | d f <| | |	 | f S(   sN  Compute a fraction-free LU decomposition.

        Returns 4 matrices P, L, D, U such that PA = L D**-1 U.
        If the elements of the matrix belong to some integral domain I, then all
        elements of L, D and U are guaranteed to belong to I.

        **Reference**
            - W. Zhou & D.J. Jeffrey, "Fraction-free matrix factors: new forms
              for LU and QR factors". Frontiers in Computer Science in China,
              Vol 2, no. 1, pp. 67-80, 2008.

        See Also
        ========

        LUdecomposition
        LUdecomposition_Simple
        LUsolve
        i(   R  i   i    s   Matrix is not full rankN(	   R	  R  R   R   RD   RE   RI  R   R|   (   R6   R  R   R   R~   R  R!  R  Rv  t   DDt   oldpivotRj   t   kpivott   UkkR7   t   UikRA   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   LUdecompositionFFf  s4    		&MMP8
c   
        s-  | j  |  j  k r! t d   n  |  j  } |  j } | | k  rN t d   n  y" |  j d t d t  \ } } Wn t k
 r t d   n X| j |  j	   } x` t
 |  D]R } xI t
 t | |   D]2 }	 | | |	 f   | j | |	   f d    q Wq W| | k rxV t
 | |  D]E } x< t
 | j  D]+ }	 | | | |	 f  s:t d   q:q:Wq$W| d |  d d  f } n  x t
 | d	 d
 d
  D]y } xG t
 | d	 |  D]2 }	 | | |	 f   | j | |	   f d    qW| | | f   | j |   f d    qW| j |  S(   s  Solve the linear system ``Ax = rhs`` for ``x`` where ``A = self``.

        This is for symbolic matrices, for real or complex ones use
        mpmath.lu_solve or mpmath.qr_solve.

        See Also
        ========

        lower_triangular_solve
        upper_triangular_solve
        gauss_jordan_solve
        cholesky_solve
        diagonal_solve
        LDLsolve
        QRsolve
        pinv_solve
        LUdecomposition
        s7   ``self`` and ``rhs`` must have the same number of rows.s&   Underdetermined systems not supported.RR   R  c           s   |  |   S(   N(    (   R0   t   y(   t   scale(    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyRw     Rx   s   The system is inconsistent.i    Ni   ic           s   |  |   S(   N(    (   R0   R5  (   R6  (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyRw     Rx   c           s   |    S(   N(    (   R0   R^   (   R6  (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyRw     Rx   (   RD   R,   RE   R  Rf   R1   R   R|   R}  RI  R   t   mint
   zip_row_opt   row_opR  (
   R6   R  RR   R  R~   RL   R   R   R7   RA   (    (   R6  s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyR    s<    			$ c         C  s   |  | S(   sv   Returns ``self*b``

        See Also
        ========

        dot
        cross
        multiply_elementwise
        (    (   R6   R   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   multiply  s    
c           s|   |  j  d k r- |  j d k r- t d   n  |  j     |    r` |  j |  j  |  j  } n |  j   f d    } | S(   s  Return the normalized version of ``self``.

        Parameters
        ==========

        iszerofunc : Function, optional
            A function to determine whether ``self`` is a zero vector.
            The default ``_iszero`` tests to see if each element is
            exactly zero.

        Returns
        =======

        Matrix
            Normalized vector form of ``self``.
            It has the same length as a unit vector. However, a zero vector
            will be returned for a vector with norm 0.

        Raises
        ======

        ShapeError
            If the matrix is not in a vector form.

        See Also
        ========

        norm
        i   s'   A Matrix must be a vector to normalize.c           s   |    S(   N(    (   R7   (   R   (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyRw     Rx   (   RD   RE   R,   R   R   R   (   R6   RR   t   out(    (   R   s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt
   normalized  s    c           sw  t  |  j    p d g } |  j d k s9 |  j d k rI  d k sQ   d k rk t t d   | D    S  d k r t d   | D   S  t j k r t	 g  | D] } t
 |  ^ q   S  t j k r t g  | D] } t
 |  ^ q   Sy1 t t   f d   | D   t d     SWqst t f k
 rEt d   qsXn*  d k r|  j t
  } t	 g  t | j  D] } t | j |   ^ qw  S  d k rt	 |  j     S  d k rt |  j     S  t j k r$|  j t
  } t	 g  t | j  D] } t | j |   ^ q  S  d k sQt   t  rg  j   d k rg|  j   j d d  St d   d S(   s  Return the Norm of a Matrix or Vector.
        In the simplest case this is the geometric size of the vector
        Other norms can be specified by the ord parameter


        =====  ============================  ==========================
        ord    norm for matrices             norm for vectors
        =====  ============================  ==========================
        None   Frobenius norm                2-norm
        'fro'  Frobenius norm                - does not exist
        inf    maximum row sum               max(abs(x))
        -inf   --                            min(abs(x))
        1      maximum column sum            as below
        -1     --                            as below
        2      2-norm (largest sing. value)  as below
        -2     smallest singular value       as below
        other  - does not exist              sum(abs(x)**ord)**(1./ord)
        =====  ============================  ==========================

        Examples
        ========

        >>> from sympy import Matrix, Symbol, trigsimp, cos, sin, oo
        >>> x = Symbol('x', real=True)
        >>> v = Matrix([cos(x), sin(x)])
        >>> trigsimp( v.norm() )
        1
        >>> v.norm(10)
        (sin(x)**10 + cos(x)**10)**(1/10)
        >>> A = Matrix([[1, 1], [1, 1]])
        >>> A.norm(1) # maximum sum of absolute values of A is 2
        2
        >>> A.norm(2) # Spectral norm (max of |Ax|/|x| under 2-vector-norm)
        2
        >>> A.norm(-2) # Inverse spectral norm (smallest singular value)
        0
        >>> A.norm() # Frobenius Norm
        2
        >>> A.norm(oo) # Infinity Norm
        2
        >>> Matrix([1, -2]).norm(oo)
        2
        >>> Matrix([-1, 2]).norm(-oo)
        1

        See Also
        ========

        normalized
        i    i   i   c         s  s   |  ] } t  |  d  Vq d S(   i   N(   t   abs(   RS   R7   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pys	   <genexpr>9  s    c         s  s   |  ] } t  |  Vq d  S(   N(   R=  (   RS   R7   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pys	   <genexpr><  s    c         3  s   |  ] } t  |    Vq d  S(   N(   R=  (   RS   R7   (   t   ord(    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pys	   <genexpr>G  s    s'   Expected order to be Number, Symbol, ooit   ft   frot	   frobeniust   vectorR>  s   Matrix Norms under developmentN(   R?  R@  RA  RB  (   R\   R   RD   RE   R/   R   R   R   t   InfinityR   R=  t   NegativeInfinityR   R   R  RX  R|   R   R   R   R   RD  R   R}   R   R{   R   R   (   R6   R>  RC  R7   R  (    (   R>  s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyR     s:    4##155	c   	      C  s   d d l  m } |  } |  j   } | d k rz | j | j } } t d j | |  d t } |  j | | |  j	 } n  | | | | j  | | | S(   sC
  Solve ``Ax = B`` using the Moore-Penrose pseudoinverse.

        There may be zero, one, or infinite solutions.  If one solution
        exists, it will be returned.  If infinite solutions exist, one will
        be returned based on the value of arbitrary_matrix.  If no solutions
        exist, the least-squares solution is returned.

        Parameters
        ==========

        B : Matrix
            The right hand side of the equation to be solved for.  Must have
            the same number of rows as matrix A.
        arbitrary_matrix : Matrix
            If the system is underdetermined (e.g. A has more columns than
            rows), infinite solutions are possible, in terms of an arbitrary
            matrix.  This parameter may be set to a specific matrix to use
            for that purpose; if so, it must be the same shape as x, with as
            many rows as matrix A has columns, and as many columns as matrix
            B.  If left as None, an appropriate matrix containing dummy
            symbols in the form of ``wn_m`` will be used, with n and m being
            row and column position of each symbol.

        Returns
        =======

        x : Matrix
            The matrix that will satisfy ``Ax = B``.  Will have as many rows as
            matrix A has columns, and as many columns as matrix B.

        Examples
        ========

        >>> from sympy import Matrix
        >>> A = Matrix([[1, 2, 3], [4, 5, 6]])
        >>> B = Matrix([7, 8])
        >>> A.pinv_solve(B)
        Matrix([
        [ _w0_0/6 - _w1_0/3 + _w2_0/6 - 55/18],
        [-_w0_0/3 + 2*_w1_0/3 - _w2_0/3 + 1/9],
        [ _w0_0/6 - _w1_0/3 + _w2_0/6 + 59/18]])
        >>> A.pinv_solve(B, arbitrary_matrix=Matrix([0, 0, 0]))
        Matrix([
        [-55/18],
        [   1/9],
        [ 59/18]])

        See Also
        ========

        lower_triangular_solve
        upper_triangular_solve
        gauss_jordan_solve
        cholesky_solve
        diagonal_solve
        LDLsolve
        LUsolve
        QRsolve
        pinv

        Notes
        =====

        This may return either exact solutions or least squares solutions.
        To determine which, check ``A * A.pinv() * B == B``.  It will be
        True if exact solutions exist, and False if only a least-squares
        solution exists.  Be aware that the left hand side of that equation
        may need to be simplified to correctly compare to the right hand
        side.

        References
        ==========

        .. [1] https://en.wikipedia.org/wiki/Moore-Penrose_pseudoinverse#Obtaining_all_solutions_of_a_linear_system

        i(   R   s
   w:{0}_:{1}R   N(
   R	  R   t   pinvR/   RE   R   R   R   R  R_  (	   R6   Rm  t   arbitrary_matrixR   RL   t   A_pinvRD   RE   t   w(    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt
   pinv_solvef  s    Mc         C  s&  |  } |  j  } | j r | Sy: |  j |  j k rC | | j   | S| | | j   SWn t k
 ri n Xy |  j |  j k r | | j d t  \ } } | j d    } | | | j  | S| | j d t  \ } } | j d    } | | | | j  SWn t	 k
 r!t
 d   n Xd S(   st  Calculate the Moore-Penrose pseudoinverse of the matrix.

        The Moore-Penrose pseudoinverse exists and is unique for any matrix.
        If the matrix is invertible, the pseudoinverse is the same as the
        inverse.

        Examples
        ========

        >>> from sympy import Matrix
        >>> Matrix([[1, 2, 3], [4, 5, 6]]).pinv()
        Matrix([
        [-17/18,  4/9],
        [  -1/9,  1/9],
        [ 13/18, -2/9]])

        See Also
        ========

        inv
        pinv_solve

        References
        ==========

        .. [1] https://en.wikipedia.org/wiki/Moore-Penrose_pseudoinverse

        R   c         S  s   t  |   r d Sd |  S(   Ni    i   (   R1   (   R0   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyRw     Rx   c         S  s   t  |   r d Sd |  S(   Ni    i   (   R1   (   R0   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyRw     Rx   s[   pinv for rank-deficient matrices where diagonalization of A.H*A fails is not supported yet.N(   RA  R-   RD   RE   R  R|   R   R   R   R*   R  (   R6   RL   t   AHRv  R  t   D_pinv(    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyRE    s(    		RU  c         C  s   g  } x t  |  j  D]y } g  } xP t  |  j  D]? } |  | | f d k r^ | j d  q2 | j t |   q2 W| j d d j |   q Wt d j |   d S(   s  Shows location of non-zero entries for fast shape lookup.

        Examples
        ========

        >>> from sympy.matrices import Matrix, eye
        >>> m = Matrix(2, 3, lambda i, j: i*3+j)
        >>> m
        Matrix([
        [0, 1, 2],
        [3, 4, 5]])
        >>> m.print_nonzero()
        [ XX]
        [XXX]
        >>> m = eye(4)
        >>> m.print_nonzero("x")
        [x   ]
        [ x  ]
        [  x ]
        [   x]

        i    t    s   [%s]Rx   s   
N(   R   RD   RE   RH   R  t   joint   print(   R6   t   symbRO  R7   t   lineRA   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   print_nonzero  s    c         C  s   | |  j  |  | j  |  S(   s^  Return the projection of ``self`` onto the line containing ``v``.

        Examples
        ========

        >>> from sympy import Matrix, S, sqrt
        >>> V = Matrix([sqrt(3)/2, S.Half])
        >>> x = Matrix([[1, 0]])
        >>> V.project(x)
        Matrix([[sqrt(3)/2, 0]])
        >>> V.project(-x)
        Matrix([[sqrt(3)/2, 0]])
        (   R   (   R6   R   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyR     s    c         C  s|  |  j  } |  j   } | j } | j } t   } | | k  rj | } | } | j | j | | |   } n | } | j | |  | j |  } } x	t |  D] }	 | d d  |	 f }
 x t |	  D]q } | d d  | f j | d d  |	 f  | | |	 f <|
 | d d  | f | | |	 f 8}
 |
 j	   q W|
 j
   | |	 |	 f <| |	 |	 f j s | j |	  |
 | |	 |	 f | d d  |	 f <q q Wt |  d k r| | j t |  |   | | j | t | j    f Sx- t t | |   D] } d | | | f <qW| | j t |  t t | |     | | j t t | |   t | j    f Sd S(   s  Return Q, R where A = Q*R, Q is orthogonal and R is upper triangular.

        Examples
        ========

        This is the example from wikipedia:

        >>> from sympy import Matrix
        >>> A = Matrix([[12, -51, 4], [6, 167, -68], [-4, 24, -41]])
        >>> Q, R = A.QRdecomposition()
        >>> Q
        Matrix([
        [ 6/7, -69/175, -58/175],
        [ 3/7, 158/175,   6/175],
        [-2/7,    6/35,  -33/35]])
        >>> R
        Matrix([
        [14,  21, -14],
        [ 0, 175, -70],
        [ 0,   0,  35]])
        >>> A == Q*R
        True

        QR factorization of an identity matrix:

        >>> A = Matrix([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
        >>> Q, R = A.QRdecomposition()
        >>> Q
        Matrix([
        [1, 0, 0],
        [0, 1, 0],
        [0, 0, 1]])
        >>> R
        Matrix([
        [1, 0, 0],
        [0, 1, 0],
        [0, 0, 1]])

        See Also
        ========

        cholesky
        LDLdecomposition
        LUdecomposition
        QRsolve
        Ni    i   (   R  RI  RD   RE   R\   t   col_joinR   R   R   t   expandR   R-   RH   Rb   R]   R   (   R6   R   RX   R~   R  t   rankedt   nOrigt   QRJ   RA   t   tmpR7   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   QRdecomposition&  s8    /				""9(+"*c         C  s   |  j    j   \ } } | j | } g  } | j } x t | d d d  D]y } | | d d  f } x? t | d |  D]* }	 | | | |	 f | | d |	 8} q{ W| j | | | | f  qK W|  j g  t |  D] }
 |
 j ^ q  S(   s  Solve the linear system ``Ax = b``.

        ``self`` is the matrix ``A``, the method argument is the vector
        ``b``.  The method returns the solution vector ``x``.  If ``b`` is a
        matrix, the system is solved for each column of ``b`` and the
        return value is a matrix of the same shape as ``b``.

        This method is slower (approximately by a factor of 2) but
        more stable for floating-point arithmetic than the LUsolve method.
        However, LUsolve usually uses an exact arithmetic, so you don't need
        to use QRsolve.

        This is mainly for educational purposes and symbolic matrices, for real
        (or complex) matrices use mpmath.qr_solve.

        See Also
        ========

        lower_triangular_solve
        upper_triangular_solve
        gauss_jordan_solve
        cholesky_solve
        diagonal_solve
        LDLsolve
        LUsolve
        pinv_solve
        QRdecomposition
        i   iN(	   RI  RX  R_  RD   R   RH   RF   R.  R*  (   R6   R   RV  RJ   R5  R0   R~   RA   RW  Rj   R   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   QRsolve  s    	(c         C  sq   |  j  d | d | d t  \ } } t |  } |  j t |  j  |  } | d |  d d  f } | | f S(   s  Returns a pair of matrices (`C`, `F`) with matching rank
        such that `A = C F`.

        Parameters
        ==========

        iszerofunc : Function, optional
            A function used for detecting whether an element can
            act as a pivot.  ``lambda x: x.is_zero`` is used by default.

        simplify : Bool or Function, optional
            A function used to simplify elements when looking for a
            pivot. By default SymPy's ``simplify`` is used.

        Returns
        =======

        (C, F) : Matrices
            `C` and `F` are full-rank matrices with rank as same as `A`,
            whose product gives `A`.

            See Notes for additional mathematical details.

        Examples
        ========

        >>> from sympy.matrices import Matrix
        >>> A = Matrix([
        ...     [1, 3, 1, 4],
        ...     [2, 7, 3, 9],
        ...     [1, 5, 3, 1],
        ...     [1, 2, 0, 8]
        ... ])
        >>> C, F = A.rank_decomposition()
        >>> C
        Matrix([
        [1, 3, 4],
        [2, 7, 9],
        [1, 5, 1],
        [1, 2, 8]])
        >>> F
        Matrix([
        [1, 0, -2, 0],
        [0, 1,  1, 0],
        [0, 0,  0, 1]])
        >>> C * F == A
        True

        Notes
        =====

        Obtaining `F`, an RREF of `A`, is equivalent to creating a
        product

        .. math::
            E_n E_{n-1} ... E_1 A = F

        where `E_n, E_{n-1}, ... , E_1` are the elimination matrices or
        permutation matrices equivalent to each row-reduction step.

        The inverse of the same product of elimination matrices gives
        `C`:

        .. math::
            C = (E_n E_{n-1} ... E_1)^{-1}

        It is not necessary, however, to actually compute the inverse:
        the columns of `C` are those from the original matrix with the
        same column indices as the indices of the pivot columns of `F`.

        References
        ==========

        .. [1] https://en.wikipedia.org/wiki/Rank_factorization

        .. [2] Piziak, R.; Odell, P. L. (1 June 1999).
            "Full Rank Factorization of Matrices".
            Mathematics Magazine. 72 (3): 193. doi:10.2307/2690882

        See Also
        ========

        rref
        R%   RR   R   N(   R   R   Rb   R]   R   RD   (   R6   RR   R%   t   FR   R   RK   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   rank_decomposition  s    U	t   CHc         C  s   | d k r |  j  |  S| d k r2 |  j |  S| d k rK |  j |  S| d k rd |  j |  S|  j } | |  j | | d | Sd S(   s  Return the least-square fit to the data.

        Parameters
        ==========

        rhs : Matrix
            Vector representing the right hand side of the linear equation.

        method : string or boolean, optional
            If set to ``'CH'``, ``cholesky_solve`` routine will be used.

            If set to ``'LDL'``, ``LDLsolve`` routine will be used.

            If set to ``'QR'``, ``QRsolve`` routine will be used.

            If set to ``'PINV'``, ``pinv_solve`` routine will be used.

            Otherwise, the conjugate of ``self`` will be used to create a system
            of equations that is passed to ``solve`` along with the hint
            defined by ``method``.

        Returns
        =======

        solutions : Matrix
            Vector representing the solution.

        Examples
        ========

        >>> from sympy.matrices import Matrix, ones
        >>> A = Matrix([1, 2, 3])
        >>> B = Matrix([2, 3, 4])
        >>> S = Matrix(A.row_join(B))
        >>> S
        Matrix([
        [1, 2],
        [2, 3],
        [3, 4]])

        If each line of S represent coefficients of Ax + By
        and x and y are [2, 3] then S*xy is:

        >>> r = S*Matrix([2, 3]); r
        Matrix([
        [ 8],
        [13],
        [18]])

        But let's add 1 to the middle value and then solve for the
        least-squares value of xy:

        >>> xy = S.solve_least_squares(Matrix([8, 14, 18])); xy
        Matrix([
        [ 5/3],
        [10/3]])

        The error is given by S*xy - r:

        >>> S*xy - r
        Matrix([
        [1/3],
        [1/3],
        [1/3]])
        >>> _.norm().n(2)
        0.58

        If a different xy is used, the norm will be higher:

        >>> xy += ones(2, 1)/10
        >>> (S*xy - r).norm().n(2)
        1.5

        R\  t   QRt   LDLt   PINVRp   N(   R  RY  R  RI  RA  t   solve(   R6   R  Rp   R   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   solve_least_squares  s    K	t   GJc         C  s   | d k re y. |  j  |  \ } } | r9 t d   n  Wn$ t k
 r` |  j d  j   n X| S| d k r~ |  j |  S| d k r |  j |  S| d k r |  j |  S| d k r |  j |  S| d k r |  j |  S|  j d	 |  | Sd
 S(   s`  Solves linear equation where the unique solution exists.

        Parameters
        ==========

        rhs : Matrix
            Vector representing the right hand side of the linear equation.

        method : string, optional
           If set to ``'GJ'``, the Gauss-Jordan elimination will be used, which
           is implemented in the routine ``gauss_jordan_solve``.

           If set to ``'LU'``, ``LUsolve`` routine will be used.

           If set to ``'QR'``, ``QRsolve`` routine will be used.

           If set to ``'PINV'``, ``pinv_solve`` routine will be used.

           It also supports the methods available for special linear systems

           For positive definite systems:

           If set to ``'CH'``, ``cholesky_solve`` routine will be used.

           If set to ``'LDL'``, ``LDLsolve`` routine will be used.

           To use a different method and to compute the solution via the
           inverse, use a method defined in the .inv() docstring.

        Returns
        =======

        solutions : Matrix
            Vector representing the solution.

        Raises
        ======

        ValueError
            If there is not a unique solution then a ``ValueError`` will be
            raised.

            If ``self`` is not square, a ``ValueError`` and a different routine
            for solving the system will be suggested.
        Rb  sf   Matrix det == 0; not invertible. Try ``self.gauss_jordan_solve(rhs)`` to obtain a parametric solution.i   t   LUR\  R]  R^  R_  Rp   N(	   R  R|   R   R  R  R  RY  R  RI  (   R6   R  Rp   t   solnt   param(    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyR`  e  s&    /t   [t   ]s   
s   , R  c         C  ss  |  j  d k s |  j d k r" d Sg  } d g |  j } x t |  j   D]t }	 | j g   x^ t |  j  D]M }
 | j |  |	 |
 f  } | d j |  t t |  | |
  | |
 <qk WqH Wi d d 6d d 6d d 6d d	 6d d
 6d d 6| } xo t |  D]a \ }	 } x7 t |  D]) \ }
 } t | |  | |
  | |
 <qW| | j	 |  | | |	 <qW| j	 |  S(   s  
        String form of Matrix as a table.

        ``printer`` is the printer to use for on the elements (generally
        something like StrPrinter())

        ``rowstart`` is the string used to start each row (by default '[').

        ``rowend`` is the string used to end each row (by default ']').

        ``rowsep`` is the string used to separate rows (by default a newline).

        ``colsep`` is the string used to separate columns (by default ', ').

        ``align`` defines how the elements are aligned. Must be one of 'left',
        'right', or 'center'.  You can also use '<', '>', and '^' to mean the
        same thing, respectively.

        This is used by the string printer for Matrix.

        Examples
        ========

        >>> from sympy import Matrix
        >>> from sympy.printing.str import StrPrinter
        >>> M = Matrix([[1, 2], [-33, 4]])
        >>> printer = StrPrinter()
        >>> M.table(printer)
        '[  1, 2]\n[-33, 4]'
        >>> print(M.table(printer))
        [  1, 2]
        [-33, 4]
        >>> print(M.table(printer, rowsep=',\n'))
        [  1, 2],
        [-33, 4]
        >>> print('[%s]' % M.table(printer, rowsep=',\n'))
        [[  1, 2],
        [-33, 4]]
        >>> print(M.table(printer, colsep=' '))
        [  1 2]
        [-33 4]
        >>> print(M.table(printer, align='center'))
        [ 1 , 2]
        [-33, 4]
        >>> print(M.table(printer, rowstart='{', rowend='}'))
        {  1, 2}
        {-33, 4}
        i    s   []it   ljustR  t   rjustR  t   centert   <t   >t   ^(
   RD   RE   R   RH   t   _printR)  Rb   R   R.   RM  (   R6   R  t   rowstartt   rowendR  t   colsept   alignR  t   maxlenR7   RA   RO  R   t   elem(    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyR    s.    3%!c         C  s^   |  j  s t d   n  | j |  j k r9 t d   n  |  j sQ t d   n  |  j |  S(   s  Solves ``Ax = B``, where A is an upper triangular matrix.

        See Also
        ========

        lower_triangular_solve
        gauss_jordan_solve
        cholesky_solve
        diagonal_solve
        LDLsolve
        LUsolve
        QRsolve
        pinv_solve
        s   Matrix must be square.s   Matrix size mismatch.s   Matrix is not upper triangular.(   Rs   R+   RD   RX  R   R  (   R6   R  (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   upper_triangular_solve  s    		c   	      C  sV  d d l  m } |  j } | |  j k r7 t d   n  | rk |  j   |  |  j   k rk t d   qk n  d } | r | | | d d d  } x t |  D]> } x5 t | |  D]$ } |  | | f | | <| d 7} q Wq Wnn | | | d d d  } xP t |  D]B } x9 t | d |  D]$ } |  | | f | | <| d 7} q&WqW| S(   s  Return the unique elements of a symmetric Matrix as a one column matrix
        by stacking the elements in the lower triangle.

        Arguments:
        diagonal -- include the diagonal cells of ``self`` or not
        check_symmetry -- checks symmetry of ``self`` but not completely reliably

        Examples
        ========

        >>> from sympy import Matrix
        >>> m=Matrix([[1, 2], [2, 3]])
        >>> m
        Matrix([
        [1, 2],
        [2, 3]])
        >>> m.vech()
        Matrix([
        [1],
        [2],
        [3]])
        >>> m.vech(diagonal=False)
        Matrix([[2]])

        See Also
        ========

        vec
        i(   R   s   Matrix must be squares>   Matrix appears to be asymmetric; consider check_symmetry=Falsei    i   i   (	   R	  R   RE   RD   R,   R%   Ro   R|   R   (	   R6   t   diagonalt   check_symmetryR   R  t   countR   RA   R7   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   vech  s,    	
N(I   R<   R=   R>   t   __array_priority__R   R  t   _class_priorityt   staticmethodR   R  R/   t   __hash__R  t   _repr_latex_origt   objectR  R  R  R  R  R  R;   R:   R  R  R   R  R  R  R  R  R  R  R  R   R  R  R   R  R   R   R  R  R1   R  R  R	  R  R  R  R  R  R  R  R"  Rf   R4  R  R:  R<  R   RI  RE  RQ  R   RX  RY  R[  Ra  R`  R  Ru  Ry  (    (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyRV  -  s   				
						F		$A			 +	i	'	+	,@			;	0	E	18	'dV	8"		]	-^WF	M	R   i;  R  s)   from sympy.matrices.common import classofR   s   1.3c         C  s   d d l  m } | |  |  S(   Ni(   t   classof(   R  R  (   RL   Rm  t   classof_(    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyR  G  s    s'   from sympy.matrices.common import a2idxc         C  s   d d l  m } | |  |  S(   Ni(   R  (   R  R  (   RA   R~   R  (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyR  O  s    c         C  s  g  } t  |   }  t d   |  D  r t d   |  D  r g  |  D] } t |  ^ qE } t |  } | |  r | d k r g  t |   D]$ \ } } | d k r | d f ^ q } n  d d t | f S| j |  } | |  | t | f Sg  }	 xO t |   D]A \ } } | |  }
 |
 t k r5| | t | f S|	 j	 |
  qWt |	  rbd d t | f Sx t |   D] \ } } |	 | d k	 rqon  | |  } | |  }
 |
 t
 k s|
 t k r| j	 | | f  n  |
 t k r| | t | f S|
 |	 | <qoWt |	  rd d t | f Sxe t |   D]W \ } } |	 | d k	 rLq*n  | j t j  r*t
 |	 | <| j	 | t j f  q*q*Wt |	  rd d t | f S|	 j d  } | |  | t
 | f S(   s   Find the lowest index of an item in ``col`` that is
    suitable for a pivot.  If ``col`` consists only of
    Floats, the pivot with the largest norm is returned.
    Otherwise, the first element where ``iszerofunc`` returns
    False is used.  If ``iszerofunc`` doesn't return false,
    items are simplified and retested until a suitable
    pivot is found.

    Returns a 4-tuple
        (pivot_offset, pivot_val, assumed_nonzero, newly_determined)
    where pivot_offset is the index of the pivot, pivot_val is
    the (possibly simplified) value of the pivot, assumed_nonzero
    is True if an assumption that the pivot was non-zero
    was made without being proved, and newly_determined are
    elements that were simplified during the process of pivot
    finding.c         s  s$   |  ] } t  | t t f  Vq d  S(   N(   R}   R   R   (   RS   R0   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pys	   <genexpr>o  s    c         s  s   |  ] } t  | t  Vq d  S(   N(   R}   R   (   RS   R0   (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pys	   <genexpr>p  s    i    N(   R\   R   R  R=  R)  R   R/   R   t   indexRH   R   R  R   R@   (   R   RR   Re   R   R0   t   col_abst	   max_valueR7   R  t   possible_zerosR-   t   simped(    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyR[   X  sT    :
c   	      C  sT  g  } xd t  |   D]V \ } } | |  } | t k rG | | t g  f S| d k r | j | | f  q q Wt |  d k r d d t g  f S| d k r | d d | d d t g  f Sg  } xp | D]h \ } } | |  } t |  t |  k r | j | | f  | |  t k r0| | t | f Sq q W| d d | d d t | f S(   s  
    Helper that computes the pivot value and location from a
    sequence of contiguous matrix column elements. As a side effect
    of the pivot search, this function may simplify some of the elements
    of the input column. A list of these simplified entries and their
    indices are also returned.
    This function mimics the behavior of _find_reasonable_pivot(),
    but does less work trying to determine if an indeterminate candidate
    pivot simplifies to zero. This more naive approach can be much faster,
    with the trade-off that it may erroneously return a pivot that is zero.

    ``col`` is a sequence of contiguous column entries to be searched for
    a suitable pivot.
    ``iszerofunc`` is a callable that returns a Boolean that indicates
    if its input is zero, or None if no such determination can be made.
    ``simpfunc`` is a callable that simplifies its input. It must return
    its input if it does not simplify its input. Passing in
    ``simpfunc=None`` indicates that the pivot search should not attempt
    to simplify any candidate pivots.

    Returns a 4-tuple:
    (pivot_offset, pivot_val, assumed_nonzero, newly_determined)
    ``pivot_offset`` is the sequence index of the pivot.
    ``pivot_val`` is the value of the pivot.
    pivot_val and col[pivot_index] are equivalent, but will be different
    when col[pivot_index] was simplified during the pivot search.
    ``assumed_nonzero`` is a boolean indicating if the pivot cannot be
    guaranteed to be zero. If assumed_nonzero is true, then the pivot
    may or may not be non-zero. If assumed_nonzero is false, then
    the pivot is non-zero.
    ``newly_determined`` is a list of index-value pairs of pivot candidates
    that were simplified during the pivot search.
    i    i   N(   R   R   R/   RH   Rb   R   t   id(	   R   RR   Re   t   indeterminatesR7   t   col_valt   col_val_is_zeroR   t   tmp_col_val(    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyR%    s&    + N(S   t
   __future__R    R   t   typesR   t   mpmath.libmp.libmpfR   t   sympy.core.addR   t   sympy.core.basicR   t   sympy.core.compatibilityR   R   R   R	   R
   R   R   R   t   sympy.core.decoratorsR   t   sympy.core.exprR   t   sympy.core.functionR   t   sympy.core.numbersR   R   R   t   sympy.core.powerR   t   sympy.core.singletonR   t   sympy.core.symbolR   R   R   R   t   sympy.core.sympifyR   t   sympy.functionsR   R   t(   sympy.functions.elementary.miscellaneousR   R   R   t   sympy.polysR    R!   R"   t   sympy.printingR#   t   sympy.simplifyR$   R%   R   t   sympy.utilities.exceptionsR&   t   sympy.utilities.iterablesR'   R(   t   commonR)   R*   R+   R,   R1   R2   R3   R?   R   R   R   RE  R[  RV  R  R/   R  R[   R%  (    (    (    s6   lib/python2.7/site-packages/sympy/matrices/matrices.pyt   <module>   sx   :""		              !g