ó
~9­\c           @  s`  d  d l  m Z m Z d  d l 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 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 d  d l m Z m Z d  d l m  Z  m! Z! d  d l" m# Z$ d  d l% m& Z& d  d l' m( Z( d „  Z) d „  Z* d e  f d „  ƒ  YZ+ d „  Z, d e+ e  f d „  ƒ  YZ- e- Z. Z/ e0 d „ Z1 e0 d „ Z2 d „  Z3 d „  Z4 d „  Z5 e& d d f ƒ d  „  ƒ Z6 e7 d! „ Z8 d" „  Z9 d# „  Z: e; d$ „ Z< g  d% „ Z= d& „  Z> d' „  Z? d( „  Z@ eA d) d* eA e; d+ eA d, „ ZB d- d. „ ZC d/ „  ZD d S(0   iÿÿÿÿ(   t   divisiont   print_functionN(   t   SympifyError(   t   Basic(   t   is_sequencet   ranget   reduce(   t   Expr(   t	   count_opst
   expand_mul(   t   S(   t   Symbol(   t   sympify(   t   sqrt(   t   cost   sin(   t   a2idxt   classof(   t
   MatrixBaset
   ShapeError(   t   simplify(   t   doctest_depends_on(   t
   filldedentc         C  s   |  j  S(   s   Returns True if x is zero.(   t   is_zero(   t   x(    (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pyt   _iszero   s    c         C  s8   t  |  ƒ t  | ƒ k r" |  | k St |  ƒ t | ƒ k S(   s—   Compares the elements of a list/tuple `a`
    and a list/tuple `b`.  `_compare_sequence((1,2), [1, 2])`
    is True, whereas `(1,2) == [1, 2]` is False(   t   typet   tuple(   t   at   b(    (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pyt   _compare_sequence   s    
t   DenseMatrixc           B  sÎ   e  Z e Z d  Z d Z d „  Z d „  Z d „  Z e	 d „ Z
 d „  Z d „  Z d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z e	 d „ Z d „  Z d „  Z d „  Z d „  Z e d „ Z RS(   g…ëQ¸$@i   c         C  s¤   t  | ƒ } t |  d d  ƒ } t | d d  ƒ } d  | | f k rF t S| | k rV t St | t ƒ rx t |  j | j ƒ St | t ƒ r  t |  j t | ƒ j ƒ Sd  S(   Nt   shape(	   R   t   getattrt   Nonet   Falset
   isinstancet   MatrixR   t   _matR   (   t   selft   othert
   self_shapet   other_shape(    (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pyt   __eq__-   s    c         C  sà  t  | t ƒ r±| \ } } y/ |  j | ƒ \ } } |  j | |  j | SWqÜt t f k
 r­t  | t ƒ ry | j s’ t  | t ƒ r| j r| d k  t	 k sè | |  j
 d k t	 k sè | d k  t	 k sè | |  j
 d k t	 k r÷ t d ƒ ‚ n  d d l m } | |  | | ƒ St  | t ƒ rBt t |  j ƒ ƒ | } n t | ƒ rQn	 | g } t  | t ƒ r…t t |  j ƒ ƒ | } n t | ƒ r”n	 | g } |  j | | ƒ SXn+ t  | t ƒ rË|  j | S|  j t | ƒ Sd S(   s™  Return portion of self defined by key. If the key involves a slice
        then a list will be returned (if key is a single slice) or a matrix
        (if key was a tuple involving a slice).

        Examples
        ========

        >>> from sympy import Matrix, I
        >>> m = Matrix([
        ... [1, 2 + I],
        ... [3, 4    ]])

        If the key is a tuple that doesn't involve a slice then that element
        is returned:

        >>> m[1, 0]
        3

        When a tuple key involves a slice, a matrix is returned. Here, the
        first column is selected (all rows, column 0):

        >>> m[:, 0]
        Matrix([
        [1],
        [3]])

        If the slice is not a tuple then it selects from the underlying
        list of elements that are arranged in row order and a list is
        returned if a slice is involved:

        >>> m[0]
        1
        >>> m[::2]
        [1, 3]
        i    i   s   index out of boundaryiÿÿÿÿ(   t   MatrixElementN(   R$   R   t   key2ijR&   t   colst	   TypeErrort
   IndexErrorR   t	   is_numbert   TrueR    t
   ValueErrort"   sympy.matrices.expressions.matexprR,   t   slicet   listR   t   rowsR   t   extractR   (   R'   t   keyt   it   jR,   (    (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pyt   __getitem__:   s4    $2++		c         C  s   t  ƒ  ‚ d  S(   N(   t   NotImplementedError(   R'   R9   t   value(    (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pyt   __setitem__€   s    c      	     sç  t  |  j |  j ƒ ‰  | rx¼t |  j ƒ D]â ‰ xl t ˆ ƒ D]^ ‰ d ˆ  ˆ ˆ f t |  ˆ ˆ f t ‡  ‡ ‡ f d †  t ˆ ƒ Dƒ ƒ ƒ ˆ  ˆ ˆ f <q> Wt |  ˆ ˆ f t ‡  ‡ f d †  t ˆ ƒ Dƒ ƒ ƒ } | j t k r÷ t d ƒ ‚ n  t | ƒ ˆ  ˆ ˆ f <q+ WnÆ xÃ t |  j ƒ D]² ‰ xf t ˆ ƒ D]X ‰ d ˆ  ˆ ˆ f |  ˆ ˆ f t ‡  ‡ ‡ f d †  t ˆ ƒ Dƒ ƒ ˆ  ˆ ˆ f <q7Wt |  ˆ ˆ f t ‡  ‡ f d †  t ˆ ƒ Dƒ ƒ ƒ ˆ  ˆ ˆ f <q$W|  j	 ˆ  ƒ S(   s  Helper function of cholesky.
        Without the error checks.
        To be used privately.
        Implements the Cholesky-Banachiewicz algorithm.
        Returns L such that L*L.H == self if hermitian flag is True,
        or L*L.T == self if hermitian is False.
        i   c         3  s3   |  ]) } ˆ  ˆ | f ˆ  ˆ | f j  ƒ  Vq d  S(   N(   t	   conjugate(   t   .0t   k(   t   LR:   R;   (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pys	   <genexpr>   s    c         3  s3   |  ]) } ˆ  ˆ | f ˆ  ˆ | f j  ƒ  Vq d  S(   N(   R@   (   RA   RB   (   RC   R:   (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pys	   <genexpr>’   s    s    Matrix must be positive-definitec         3  s-   |  ]# } ˆ  ˆ | f ˆ  ˆ | f Vq d  S(   N(    (   RA   RB   (   RC   R:   R;   (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pys	   <genexpr>š   s    c         3  s#   |  ] } ˆ  ˆ | f d  Vq d S(   i   N(    (   RA   RB   (   RC   R:   (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pys	   <genexpr>œ   s    (
   t   zerosR7   R   R	   t   sumt   is_positiveR#   R3   R   t   _new(   R'   t	   hermitiant   Lii2(    (   RC   R:   R;   s3   lib/python2.7/site-packages/sympy/matrices/dense.pyt	   _choleskyƒ   s$    !;)87c           s%   ˆ j  ˆ  j ˆ  j ‡  ‡ f d †  ƒ S(   sl   Helper function of function diagonal_solve,
        without the error checks, to be used privately.
        c           s   ˆ  |  | f ˆ |  |  f S(   N(    (   R:   R;   (   t   rhsR'   (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pyt   <lambda>£   t    (   RG   R7   R.   (   R'   RK   (    (   RK   R'   s3   lib/python2.7/site-packages/sympy/matrices/dense.pyt   _diagonal_solveŸ   s    c         C  sZ   g  t  |  j | j ƒ D] \ } } | | ^ q } t |  | ƒ j |  j |  j | d t ƒS(   Nt   copy(   t   zipR&   R   RG   R7   R.   R#   (   R'   R(   R   R   t   mat(    (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pyt	   _eval_add¥   s    2c           sf   |  j  ‰ |  j ‰  ‡  ‡ f d †  | Dƒ } |  j t | ƒ t ˆ ƒ t ‡ f d †  | Dƒ ƒ d t ƒS(   Nc         3  s*   |  ]  } ˆ D] } | ˆ  | Vq q d  S(   N(    (   RA   R:   R;   (   R.   t   colsList(    s3   lib/python2.7/site-packages/sympy/matrices/dense.pys	   <genexpr>®   s    c         3  s   |  ] } ˆ  | Vq d  S(   N(    (   RA   R:   (   RQ   (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pys	   <genexpr>°   s    RO   (   R&   R.   RG   t   lenR6   R#   (   R'   t   rowsListRS   t   indices(    (   R.   RS   RQ   s3   lib/python2.7/site-packages/sympy/matrices/dense.pyt   _eval_extract«   s
    		c           s¢  d d l  m } |  j |  j } } | j | j } } | | } |  j } | j }	 t j g | |	 }
 |  j d k r€| j d k r€|  j ‰  | j ‰ xç t t |
 ƒ ƒ D]Ð } | |	 | |	 } } t | | | | d ƒ } t | | | ƒ } ‡  ‡ f d †  t	 | | ƒ Dƒ } y | | Œ  |
 | <Wq© t
 t f k
 rx‡  ‡ f d †  t	 | | ƒ Dƒ } t d „  | ƒ |
 | <q© Xq© Wn  t |  | ƒ j | |	 |
 d t ƒS(	   Niÿÿÿÿ(   t   Addi    i   c         3  s'   |  ] \ } } ˆ  | ˆ | Vq d  S(   N(    (   RA   R   R   (   RQ   t	   other_mat(    s3   lib/python2.7/site-packages/sympy/matrices/dense.pys	   <genexpr>È   s    c         3  s'   |  ] \ } } ˆ  | ˆ | Vq d  S(   N(    (   RA   R   R   (   RQ   RY   (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pys	   <genexpr>Ñ   s    c         S  s   |  | S(   N(    (   R   R   (    (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pyRL   Ò   RM   RO   (   t   sympyRX   R7   R.   R
   t   ZeroR&   R   RT   RP   R/   R   R   R   RG   R#   (   R'   R(   RX   t	   self_rowst	   self_colst
   other_rowst
   other_colst	   other_lent   new_mat_rowst   new_mat_colst   new_matR:   t   rowt   colt   row_indicest   col_indicest   vec(    (   RQ   RY   s3   lib/python2.7/site-packages/sympy/matrices/dense.pyt   _eval_matrix_mul²   s*    
				""!c         C  sZ   g  t  |  j | j ƒ D] \ } } | | ^ q } t |  | ƒ j |  j |  j | d t ƒS(   NRO   (   RP   R&   R   RG   R7   R.   R#   (   R'   R(   R   R   RQ   (    (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pyt   _eval_matrix_mul_elementwiseÕ   s    2c   
      K  s  d d l  m } | j d d ƒ } | j d t ƒ } | j d t ƒ r’ |  j ƒ  } g  } x- | D]% } | j | j d | d | ƒ ƒ q_ W| | Œ  S|  j ƒ  } | d k r¿ | j	 d | ƒ }	 nN | d k rà | j
 d | ƒ }	 n- | d k r| j d | ƒ }	 n t d	 ƒ ‚ |  j |	 ƒ S(
   sÞ  Return the matrix inverse using the method indicated (default
        is Gauss elimination).

        kwargs
        ======

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

        Notes
        =====

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

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

        According to the ``try_block_diag`` keyword, it will try to form block
        diagonal matrices using the method get_diag_blocks(), invert these
        individually, and then reconstruct the full inverse matrix.

        Note, the GE and LU methods may require the matrix to be simplified
        before it is inverted in order to properly detect zeros during
        pivoting. In difficult cases a custom zero detection function can
        be provided by setting the ``iszerosfunc`` argument to a function that
        should return True if its argument is zero. The ADJ routine computes
        the determinant and uses that to detect singular matrices in addition
        to testing for zeros on the diagonal.

        See Also
        ========

        inverse_LU
        inverse_GE
        inverse_ADJ
        iÿÿÿÿ(   t   diagt   methodt   GEt
   iszerofunct   try_block_diagt   LUt   ADJs   Inversion method unrecognized(   t   sympy.matricesRk   t   getR   R#   t   get_diag_blockst   appendt   invt
   as_mutablet
   inverse_GEt
   inverse_LUt   inverse_ADJR3   RG   (
   R'   t   kwargsRk   Rl   Rn   t   blockst   rt   blockt   Mt   rv(    (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pyt   _eval_inverseÙ   s$    '#
c         C  s?   g  |  j  D] } | | ^ q
 } |  j |  j |  j | d t ƒS(   NRO   (   R&   RG   R7   R.   R#   (   R'   R(   R   RQ   (    (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pyt   _eval_scalar_mul  s     c         C  s?   g  |  j  D] } | | ^ q
 } |  j |  j |  j | d t ƒS(   NRO   (   R&   RG   R7   R.   R#   (   R'   R(   R   RQ   (    (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pyt   _eval_scalar_rmul  s     c         C  sK   t  |  j ƒ } |  j } g  t |  j ƒ D] } | | | | d | !^ q( S(   Ni   (   R6   R&   R.   R   R7   (   R'   RQ   R.   R:   (    (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pyt   _eval_tolist   s    	c      
     s	  t  |  j |  j ƒ ‰  t |  j ƒ ‰ | r'xÀt |  j ƒ D]æ ‰ xo t ˆ ƒ D]a ‰ d ˆ  ˆ ˆ f t |  ˆ ˆ f t ‡  ‡ ‡ ‡ f d †  t ˆ ƒ Dƒ ƒ ƒ ˆ ˆ ˆ f <qM Wt |  ˆ ˆ f t ‡  ‡ ‡ f d †  t ˆ ƒ Dƒ ƒ ƒ ˆ  ˆ ˆ f <ˆ  ˆ ˆ f j t k r: t d ƒ ‚ q: q: WnÆ xÃ t |  j ƒ D]² ‰ xi t ˆ ƒ D][ ‰ d ˆ  ˆ ˆ f |  ˆ ˆ f t ‡  ‡ ‡ ‡ f d †  t ˆ ƒ Dƒ ƒ ˆ ˆ ˆ f <qJW|  ˆ ˆ f t ‡  ‡ ‡ f d †  t ˆ ƒ Dƒ ƒ ˆ  ˆ ˆ f <q7W|  j	 ˆ ƒ |  j	 ˆ  ƒ f S(   sì   Helper function of LDLdecomposition.
        Without the error checks.
        To be used privately.
        Returns L and D such that L*D*L.H == self if hermitian flag is True,
        or L*D*L.T == self if hermitian is False.
        i   c         3  sA   |  ]7 } ˆ ˆ | f ˆ ˆ | f j  ƒ  ˆ  | | f Vq d  S(   N(   R@   (   RA   RB   (   t   DRC   R:   R;   (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pys	   <genexpr>3  s    c         3  sA   |  ]7 } ˆ ˆ | f ˆ ˆ | f j  ƒ  ˆ  | | f Vq d  S(   N(   R@   (   RA   RB   (   R…   RC   R:   (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pys	   <genexpr>5  s    s    Matrix must be positive-definitec         3  s;   |  ]1 } ˆ ˆ | f ˆ ˆ | f ˆ  | | f Vq d  S(   N(    (   RA   RB   (   R…   RC   R:   R;   (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pys	   <genexpr><  s    c         3  s1   |  ]' } ˆ ˆ | f d  ˆ  | | f Vq d S(   i   N(    (   RA   RB   (   R…   RC   R:   (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pys	   <genexpr>=  s    (
   RD   R7   t   eyeR   R	   RE   RF   R#   R3   RG   (   R'   RH   (    (   R…   RC   R:   R;   s3   lib/python2.7/site-packages/sympy/matrices/dense.pyt   _LDLdecomposition%  s"    $;6!8Dc           sÌ   t  ˆ j | j ƒ ‰  x§ t | j ƒ D]– ‰ x t ˆ j ƒ D]| ‰ ˆ ˆ ˆ f d k rf t d ƒ ‚ n  | ˆ ˆ f t ‡  ‡ ‡ ‡ f d †  t ˆ ƒ Dƒ ƒ ˆ ˆ ˆ f ˆ  ˆ ˆ f <q; Wq% Wˆ j ˆ  ƒ S(   s|   Helper function of function lower_triangular_solve.
        Without the error checks.
        To be used privately.
        i    s   Matrix must be non-singular.c         3  s-   |  ]# } ˆ ˆ | f ˆ  | ˆ f Vq d  S(   N(    (   RA   RB   (   t   XR:   R;   R'   (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pys	   <genexpr>J  s   (   RD   R7   R.   R   R/   RE   RG   (   R'   RK   (    (   Rˆ   R:   R;   R'   s3   lib/python2.7/site-packages/sympy/matrices/dense.pyt   _lower_triangular_solve@  s    %4c           sÜ   t  ˆ j | j ƒ ‰  x· t | j ƒ D]¦ ‰ x t t ˆ j ƒ ƒ D]† ‰ ˆ ˆ ˆ f d k rl t d ƒ ‚ n  | ˆ ˆ f t ‡  ‡ ‡ ‡ f d †  t ˆ d ˆ j ƒ Dƒ ƒ ˆ ˆ ˆ f ˆ  ˆ ˆ f <qA Wq% Wˆ j ˆ  ƒ S(   sl   Helper function of function upper_triangular_solve.
        Without the error checks, to be used privately. i    s   Matrix must be non-singular.c         3  s-   |  ]# } ˆ ˆ | f ˆ  | ˆ f Vq d  S(   N(    (   RA   RB   (   Rˆ   R:   R;   R'   (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pys	   <genexpr>V  s   i   (   RD   R7   R.   R   t   reversedR3   RE   RG   (   R'   RK   (    (   Rˆ   R:   R;   R'   s3   lib/python2.7/site-packages/sympy/matrices/dense.pyt   _upper_triangular_solveN  s    %>c         C  sN   d d l  m } |  j r5 |  j r5 | j |  j ƒ  ƒ S| j |  j |  j g  ƒ S(   s4   Returns an Immutable version of this Matrix
        i   (   t   ImmutableDenseMatrix(   t	   immutableRŒ   R7   R.   RG   t   tolist(   R'   t   cls(    (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pyt   as_immutableZ  s    c         C  s
   t  |  ƒ S(   sB  Returns a mutable version of this matrix

        Examples
        ========

        >>> from sympy import ImmutableMatrix
        >>> X = ImmutableMatrix([[1, 2], [3, 4]])
        >>> Y = X.as_mutable()
        >>> Y[1, 1] = 5 # Can set values in Y
        >>> Y
        Matrix([
        [1, 2],
        [3, 5]])
        (   R%   (   R'   (    (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pyRw   b  s    c   	      C  sß   t  |  d d ƒ } t  | d d ƒ } d | | f k r: t S| | k rJ t St } xˆ t |  j ƒ D]w } xn t |  j ƒ D]] } |  | | f j | | | f | ƒ } | t k r² t S| t k	 rv | t k rv | } qv qv Wq` W| S(   sW  Applies ``equals`` to corresponding elements of the matrices,
        trying to prove that the elements are equivalent, returning True
        if they are, False if any pair is not, and None (or the first
        failing expression if failing_expression is True) if it cannot
        be decided if the expressions are equivalent or not. This is, in
        general, an expensive operation.

        Examples
        ========

        >>> from sympy.matrices import Matrix
        >>> from sympy.abc import x
        >>> from sympy import cos
        >>> A = Matrix([x*(x - 1), 0])
        >>> B = Matrix([x**2 - x, 0])
        >>> A == B
        False
        >>> A.simplify() == B.simplify()
        True
        >>> A.equals(B)
        True
        >>> A.equals(2)
        False

        See Also
        ========
        sympy.core.expr.equals
        R    N(   R!   R"   R#   R2   R   R7   R.   t   equals(	   R'   R(   t   failing_expressionR)   R*   R€   R:   R;   t   ans(    (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pyR‘   s  s    &(   t   __name__t
   __module__R#   t   is_MatrixExprt   _op_priorityt   _class_priorityR+   R<   R?   R2   RJ   RN   RR   RW   Ri   Rj   R   R‚   Rƒ   R„   R‡   R‰   R‹   R   Rw   R‘   (    (    (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pyR   &   s,   		F					#		?							c         C  sw   t  |  d t ƒ r |  j ƒ  St |  t ƒ r/ |  St |  d ƒ rs |  j ƒ  } t | j ƒ d k ri t	 | ƒ St
 |  ƒ S|  S(   s0   Return a matrix as a Matrix, otherwise return x.t	   is_Matrixt	   __array__i    (   R!   R#   Rw   R$   R   t   hasattrRš   RT   R    R   R%   (   R   R   (    (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pyt   _force_mutable¡  s    


t   MutableDenseMatrixc           B  s¡   e  Z d  „  Z e d „  ƒ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d e e e d „ Z d „  Z RS(   c         O  s   |  j  | | Ž  S(   N(   RG   (   R   t   argsR{   (    (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pyt   __new__°  s    c         O  s    | j  d t ƒ t k rK t | ƒ d k r9 t d ƒ ‚ n  | \ } } } n' |  j | | Ž  \ } } } t | ƒ } t j |  ƒ } | | _	 | | _
 | | _ | S(   NRO   i   sA   'copy=False' requires a matrix be initialized as rows,cols,[list](   Rs   R2   R#   RT   R/   t   _handle_creation_inputsR6   t   objectRŸ   R7   R.   R&   (   R   Rž   R{   R7   R.   t	   flat_listR'   (    (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pyRG   ³  s    			c         C  sL   |  j  | | ƒ } | d k	 rH | \ } } } | |  j | |  j | <n  d S(   s@  

        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]])
        N(   t   _setitemR"   R&   R.   (   R'   R9   R>   R€   R:   R;   (    (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pyR?   Å  s    (c         C  s
   |  j  ƒ  S(   N(   RO   (   R'   (    (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pyRw   ò  s    c         C  s   | |  j  k  s | |  j  k rA t d | |  j  |  j  f ƒ ‚ n  x6 t |  j d d d ƒ D] } |  j | | |  j  =q[ W|  j  d 8_  d S(   s0  Delete the given column.

        Examples
        ========

        >>> from sympy.matrices import eye
        >>> M = eye(3)
        >>> M.col_del(1)
        >>> M
        Matrix([
        [1, 0],
        [0, 0],
        [0, 1]])

        See Also
        ========

        col
        row_del
        s/   Index out of range: 'i=%s', valid -%s <= i < %si   iÿÿÿÿN(   R.   R0   R   R7   R&   (   R'   R:   R;   (    (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pyt   col_delõ  s     c         C  sg   g  t  t |  j | d |  j … t  t |  j ƒ ƒ ƒ ƒ D] } | | Œ  ^ q8 |  j | d |  j … <d S(   s—  In-place operation on col j using two-arg functor whose args are
        interpreted as (self[i, j], i).

        Examples
        ========

        >>> from sympy.matrices import eye
        >>> M = eye(3)
        >>> M.col_op(1, lambda v, i: v + 2*M[i, 0]); M
        Matrix([
        [1, 2, 0],
        [0, 1, 0],
        [0, 0, 1]])

        See Also
        ========
        col
        row_op
        N(   R6   RP   R&   R.   R   R7   (   R'   R;   t   ft   t(    (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pyt   col_op  s    c         C  sV   xO t  d |  j ƒ D]; } |  | | f |  | | f |  | | f <|  | | f <q Wd S(   s”  Swap the two given columns of the matrix in-place.

        Examples
        ========

        >>> from sympy.matrices import Matrix
        >>> M = Matrix([[1, 0], [1, 0]])
        >>> M
        Matrix([
        [1, 0],
        [1, 0]])
        >>> M.col_swap(0, 1)
        >>> M
        Matrix([
        [0, 1],
        [0, 1]])

        See Also
        ========

        col
        row_swap
        i    N(   R   R7   (   R'   R:   R;   RB   (    (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pyt   col_swap'  s    c         C  s;   t  | ƒ s% t d t | ƒ ƒ ‚ n  |  j | t | ƒ ƒ S(   sr  Copy in elements from a list.

        Parameters
        ==========

        key : slice
            The section of this matrix to replace.
        value : iterable
            The iterable to copy values from.

        Examples
        ========

        >>> from sympy.matrices import eye
        >>> I = eye(3)
        >>> I[:2, 0] = [1, 2] # col
        >>> I
        Matrix([
        [1, 0, 0],
        [2, 1, 0],
        [0, 0, 1]])
        >>> I[1, :2] = [[3, 4]]
        >>> I
        Matrix([
        [1, 0, 0],
        [3, 4, 0],
        [0, 0, 1]])

        See Also
        ========

        copyin_matrix
        s,   `value` must be an ordered iterable, not %s.(   R   R/   R   t   copyin_matrixR%   (   R'   R9   R>   (    (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pyt   copyin_listB  s    "c         C  sº   |  j  | ƒ \ } } } } | j } | | | | } }	 | | |	 f k r` t t d ƒ ƒ ‚ n  xS t | j ƒ D]B }
 x9 t | j ƒ D]( } | |
 | f |  |
 | | | f <q† Wqp Wd S(   s©  Copy in values from a matrix into the given bounds.

        Parameters
        ==========

        key : slice
            The section of this matrix to replace.
        value : Matrix
            The matrix to copy values from.

        Examples
        ========

        >>> from sympy.matrices import Matrix, eye
        >>> M = Matrix([[0, 1], [2, 3], [4, 5]])
        >>> I = eye(3)
        >>> I[:3, :2] = M
        >>> I
        Matrix([
        [0, 1, 0],
        [2, 3, 0],
        [4, 5, 1]])
        >>> I[0, 1] = M
        >>> I
        Matrix([
        [0, 0, 1],
        [2, 2, 3],
        [4, 4, 5]])

        See Also
        ========

        copyin_list
        sX   The Matrix `value` doesn't have the same dimensions as the in sub-Matrix given by `key`.N(   t
   key2boundsR    R   R   R   R7   R.   (   R'   R9   R>   t   rlot   rhit   clot   chiR    t   drt   dcR:   R;   (    (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pyR©   h  s    #	c         C  s   | g t  |  ƒ |  _ d S(   sn   Fill the matrix with the scalar value.

        See Also
        ========

        zeros
        ones
        N(   RT   R&   (   R'   R>   (    (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pyt   fill—  s    	c         C  s   | |  j  k  s | |  j  k rA t d | |  j  |  j  f ƒ ‚ n  | d k  r] | |  j  7} n  |  j | |  j | d |  j 5|  j  d 8_  d S(   s#  Delete the given row.

        Examples
        ========

        >>> from sympy.matrices import eye
        >>> M = eye(3)
        >>> M.row_del(1)
        >>> M
        Matrix([
        [1, 0, 0],
        [0, 0, 1]])

        See Also
        ========

        row
        col_del
        s1   Index out of range: 'i = %s', valid -%s <= i < %si    i   N(   R7   R0   R&   R.   (   R'   R:   (    (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pyt   row_del¢  s    c         C  sy   | |  j  } |  j | | |  j  !} g  t | t t |  j  ƒ ƒ ƒ D] \ } } | | | ƒ ^ qC |  j | | |  j  +d S(   s³  In-place operation on row ``i`` using two-arg functor whose args are
        interpreted as ``(self[i, j], j)``.

        Examples
        ========

        >>> from sympy.matrices import eye
        >>> M = eye(3)
        >>> M.row_op(1, lambda v, j: v + 2*M[0, j]); M
        Matrix([
        [1, 0, 0],
        [2, 1, 0],
        [0, 0, 1]])

        See Also
        ========
        row
        zip_row_op
        col_op

        N(   R.   R&   RP   R6   R   (   R'   R:   R¥   t   i0t   riR   R;   (    (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pyt   row_op¾  s    c         C  sV   xO t  d |  j ƒ D]; } |  | | f |  | | f |  | | f <|  | | f <q Wd S(   s‘  Swap the two given rows of the matrix in-place.

        Examples
        ========

        >>> from sympy.matrices import Matrix
        >>> M = Matrix([[0, 1], [1, 0]])
        >>> M
        Matrix([
        [0, 1],
        [1, 0]])
        >>> M.row_swap(0, 1)
        >>> M
        Matrix([
        [1, 0],
        [0, 1]])

        See Also
        ========

        row
        col_swap
        i    N(   R   R.   (   R'   R:   R;   RB   (    (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pyt   row_swapØ  s    g333333û?c         C  sV   xO t  t |  j ƒ ƒ D]8 } t |  j | d | d | d | d | ƒ|  j | <q Wd S(   sß   Applies simplify to the elements of a matrix in place.

        This is a shortcut for M.applyfunc(lambda x: simplify(x, ratio, measure))

        See Also
        ========

        sympy.simplify.simplify.simplify
        t   ratiot   measuret   rationalt   inverseN(   R   RT   R&   t	   _simplify(   R'   R¸   R¹   Rº   R»   R:   (    (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pyR   ó  s    
c   
      C  sŽ   | |  j  } | |  j  } |  j | | |  j  !} |  j | | |  j  !} g  t | | ƒ D] \ } }	 | | |	 ƒ ^ qX |  j | | |  j  +d S(   s¹  In-place operation on row ``i`` using two-arg functor whose args are
        interpreted as ``(self[i, j], self[k, j])``.

        Examples
        ========

        >>> from sympy.matrices import eye
        >>> M = eye(3)
        >>> M.zip_row_op(1, 0, lambda v, u: v + 2*u); M
        Matrix([
        [1, 0, 0],
        [2, 1, 0],
        [0, 0, 1]])

        See Also
        ========
        row
        row_op
        col_op

        N(   R.   R&   RP   (
   R'   R:   RB   R¥   R´   t   k0Rµ   t   rkR   t   y(    (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pyt
   zip_row_op  s
    (   R”   R•   RŸ   t   classmethodRG   R?   Rw   R¤   R§   R¨   Rª   R©   R²   R³   R¶   R·   R   R#   R   RÀ   (    (    (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pyR   ¯  s   		-					&	/				c         C  sP   d d l  m } | t |  ƒ | ƒ } x$ t |  ƒ D] \ } } | | | <q2 W| S(   sm   Converts python list of SymPy expressions to a NumPy array.

    See Also
    ========

    matrix2numpy
    iÿÿÿÿ(   t   empty(   t   numpyRÂ   RT   t	   enumerate(   t   lt   dtypeRÂ   R   R:   t   s(    (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pyt
   list2numpy)  s
    c         C  st   d d l  m } | |  j | ƒ } xK t |  j ƒ D]: } x1 t |  j ƒ D]  } |  | | f | | | f <qH Wq2 W| S(   sY   Converts SymPy's matrix to a NumPy array.

    See Also
    ========

    list2numpy
    iÿÿÿÿ(   RÂ   (   RÃ   RÂ   R    R   R7   R.   (   t   mRÆ   RÂ   R   R:   R;   (    (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pyt   matrix2numpy8  s    "c         C  sD   t  |  ƒ } t |  ƒ } | | d f | | d f d f } t | ƒ S(   së  Returns a rotation matrix for a rotation of theta (in radians) about
    the 3-axis.

    Examples
    ========

    >>> from sympy import pi
    >>> from sympy.matrices import rot_axis3

    A rotation of pi/3 (60 degrees):

    >>> theta = pi/3
    >>> rot_axis3(theta)
    Matrix([
    [       1/2, sqrt(3)/2, 0],
    [-sqrt(3)/2,       1/2, 0],
    [         0,         0, 1]])

    If we rotate by pi/2 (90 degrees):

    >>> rot_axis3(pi/2)
    Matrix([
    [ 0, 1, 0],
    [-1, 0, 0],
    [ 0, 0, 1]])

    See Also
    ========

    rot_axis1: Returns a rotation matrix for a rotation of theta (in radians)
        about the 1-axis
    rot_axis2: Returns a rotation matrix for a rotation of theta (in radians)
        about the 2-axis
    i    i   (   i    i    i   (   R   R   R%   (   t   thetat   ctt   stt   lil(    (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pyt	   rot_axis3H  s    #	c         C  sD   t  |  ƒ } t |  ƒ } | d | f d | d | f f } t | ƒ S(   së  Returns a rotation matrix for a rotation of theta (in radians) about
    the 2-axis.

    Examples
    ========

    >>> from sympy import pi
    >>> from sympy.matrices import rot_axis2

    A rotation of pi/3 (60 degrees):

    >>> theta = pi/3
    >>> rot_axis2(theta)
    Matrix([
    [      1/2, 0, -sqrt(3)/2],
    [        0, 1,          0],
    [sqrt(3)/2, 0,        1/2]])

    If we rotate by pi/2 (90 degrees):

    >>> rot_axis2(pi/2)
    Matrix([
    [0, 0, -1],
    [0, 1,  0],
    [1, 0,  0]])

    See Also
    ========

    rot_axis1: Returns a rotation matrix for a rotation of theta (in radians)
        about the 1-axis
    rot_axis3: Returns a rotation matrix for a rotation of theta (in radians)
        about the 3-axis
    i    i   (   i    i   i    (   R   R   R%   (   RË   RÌ   RÍ   RÎ   (    (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pyt	   rot_axis2s  s    #c         C  sD   t  |  ƒ } t |  ƒ } d d | | f d | | f f } t | ƒ S(   së  Returns a rotation matrix for a rotation of theta (in radians) about
    the 1-axis.

    Examples
    ========

    >>> from sympy import pi
    >>> from sympy.matrices import rot_axis1

    A rotation of pi/3 (60 degrees):

    >>> theta = pi/3
    >>> rot_axis1(theta)
    Matrix([
    [1,          0,         0],
    [0,        1/2, sqrt(3)/2],
    [0, -sqrt(3)/2,       1/2]])

    If we rotate by pi/2 (90 degrees):

    >>> rot_axis1(pi/2)
    Matrix([
    [1,  0, 0],
    [0,  0, 1],
    [0, -1, 0]])

    See Also
    ========

    rot_axis2: Returns a rotation matrix for a rotation of theta (in radians)
        about the 2-axis
    rot_axis3: Returns a rotation matrix for a rotation of theta (in radians)
        about the 3-axis
    i   i    (   i   i    i    (   R   R   R%   (   RË   RÌ   RÍ   RÎ   (    (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pyt	   rot_axis1ž  s    #t   modulesRÃ   c         K  sr   d d l  m } m } | | d t ƒ} xC | | ƒ D]5 } t d |  d j t t | ƒ ƒ f |  | | <q5 W| S(   sI  Create a numpy ndarray of symbols (as an object array).

    The created symbols are named ``prefix_i1_i2_``...  You should thus provide a
    non-empty prefix if you want your symbols to be unique for different output
    arrays, as SymPy symbols with identical names are the same object.

    Parameters
    ----------

    prefix : string
      A prefix prepended to the name of every symbol.

    shape : int or tuple
      Shape of the created array.  If an int, the array is one-dimensional; for
      more than one dimension the shape must be a tuple.

    \*\*kwargs : dict
      keyword arguments passed on to Symbol

    Examples
    ========
    These doctests require numpy.

    >>> from sympy import symarray
    >>> symarray('', 3)
    [_0 _1 _2]

    If you want multiple symarrays to contain distinct symbols, you *must*
    provide unique prefixes:

    >>> a = symarray('', 3)
    >>> b = symarray('', 3)
    >>> a[0] == b[0]
    True
    >>> a = symarray('a', 3)
    >>> b = symarray('b', 3)
    >>> a[0] == b[0]
    False

    Creating symarrays with a prefix:

    >>> symarray('a', 3)
    [a_0 a_1 a_2]

    For more than one dimension, the shape must be given as a tuple:

    >>> symarray('a', (2, 3))
    [[a_0_0 a_0_1 a_0_2]
     [a_1_0 a_1_1 a_1_2]]
    >>> symarray('a', (2, 3, 2))
    [[[a_0_0_0 a_0_0_1]
      [a_0_1_0 a_0_1_1]
      [a_0_2_0 a_0_2_1]]
    <BLANKLINE>
     [[a_1_0_0 a_1_0_1]
      [a_1_1_0 a_1_1_1]
      [a_1_2_0 a_1_2_1]]]

    For setting assumptions of the underlying Symbols:

    >>> [s.is_real for s in symarray('a', 2, real=True)]
    [True, True]
    iÿÿÿÿ(   RÂ   t   ndindexRÆ   s   %s_%st   _(   RÃ   RÂ   RÓ   R¡   R   t   joint   mapt   str(   t   prefixR    R{   RÂ   RÓ   t   arrt   index(    (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pyt   symarrayÉ  s    A"c           st   d d l  m } t t t ˆ ƒ ƒ ‰ | s@ ‡  ‡ f d †  } n ‡  ‡ f d †  } t ˆ ƒ } | | | | ƒ j ƒ  S(   sY  Given linear difference operator L of order 'k' and homogeneous
       equation Ly = 0 we want to compute kernel of L, which is a set
       of 'k' sequences: a(n), b(n), ... z(n).

       Solutions of L are linearly independent iff their Casoratian,
       denoted as C(a, b, ..., z), do not vanish for n = 0.

       Casoratian is defined by k x k determinant::

                  +  a(n)     b(n)     . . . z(n)     +
                  |  a(n+1)   b(n+1)   . . . z(n+1)   |
                  |    .         .     .        .     |
                  |    .         .       .      .     |
                  |    .         .         .    .     |
                  +  a(n+k-1) b(n+k-1) . . . z(n+k-1) +

       It proves very useful in rsolve_hyper() where it is applied
       to a generating set of a recurrence to factor out linearly
       dependent solutions and return a basis:

       >>> from sympy import Symbol, casoratian, factorial
       >>> n = Symbol('n', integer=True)

       Exponential and factorial are linearly independent:

       >>> casoratian([2**n, factorial(n)], n) != 0
       True

    i   (   R%   c           s   ˆ | j  ˆ  ˆ  |  ƒ S(   N(   t   subs(   R:   R;   (   t   nt   seqs(    s3   lib/python2.7/site-packages/sympy/matrices/dense.pyRL   9  RM   c           s   ˆ | j  ˆ  |  ƒ S(   N(   RÜ   (   R:   R;   (   RÝ   RÞ   (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pyRL   ;  RM   (   t   denseR%   R6   RÖ   R   RT   t   det(   RÞ   RÝ   t   zeroR%   R¥   RB   (    (   RÝ   RÞ   s3   lib/python2.7/site-packages/sympy/matrices/dense.pyt
   casoratian  s    c          O  s    d d l  m } | j |  | Ž  S(   s`   Create square identity matrix n x n

    See Also
    ========

    diag
    zeros
    ones
    i   (   R%   (   Rß   R%   R†   (   Rž   R{   R%   (    (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pyR†   B  s    
c            sE   d d l  m ‰  ‡  f d †  ‰ ‡ f d †  |  Dƒ }  ˆ  j |  | Ž  S(   sÅ  Create a sparse, diagonal matrix from a list of diagonal values.

    Notes
    =====

    When arguments are matrices they are fitted in resultant matrix.

    The returned matrix is a mutable, dense matrix. To make it a different
    type, send the desired class for keyword ``cls``.

    Examples
    ========

    >>> from sympy.matrices import diag, Matrix, ones
    >>> diag(1, 2, 3)
    Matrix([
    [1, 0, 0],
    [0, 2, 0],
    [0, 0, 3]])
    >>> diag(*[1, 2, 3])
    Matrix([
    [1, 0, 0],
    [0, 2, 0],
    [0, 0, 3]])

    The diagonal elements can be matrices; diagonal filling will
    continue on the diagonal from the last element of the matrix:

    >>> from sympy.abc import x, y, z
    >>> a = Matrix([x, y, z])
    >>> b = Matrix([[1, 2], [3, 4]])
    >>> c = Matrix([[5, 6]])
    >>> diag(a, 7, b, c)
    Matrix([
    [x, 0, 0, 0, 0, 0],
    [y, 0, 0, 0, 0, 0],
    [z, 0, 0, 0, 0, 0],
    [0, 7, 0, 0, 0, 0],
    [0, 0, 1, 2, 0, 0],
    [0, 0, 3, 4, 0, 0],
    [0, 0, 0, 0, 5, 6]])

    When diagonal elements are lists, they will be treated as arguments
    to Matrix:

    >>> diag([1, 2, 3], 4)
    Matrix([
    [1, 0],
    [2, 0],
    [3, 0],
    [0, 4]])
    >>> diag([[1, 2, 3]], 4)
    Matrix([
    [1, 2, 3, 0],
    [0, 0, 0, 4]])

    A given band off the diagonal can be made by padding with a
    vertical or horizontal "kerning" vector:

    >>> hpad = ones(0, 2)
    >>> vpad = ones(2, 0)
    >>> diag(vpad, 1, 2, 3, hpad) + diag(hpad, 4, 5, 6, vpad)
    Matrix([
    [0, 0, 4, 0, 0],
    [0, 0, 0, 5, 0],
    [1, 0, 0, 0, 6],
    [0, 2, 0, 0, 0],
    [0, 0, 3, 0, 0]])



    The type is mutable by default but can be made immutable by setting
    the ``mutable`` flag to False:

    >>> type(diag(1))
    <class 'sympy.matrices.dense.MutableDenseMatrix'>
    >>> from sympy.matrices import ImmutableMatrix
    >>> type(diag(1, cls=ImmutableMatrix))
    <class 'sympy.matrices.immutable.ImmutableDenseMatrix'>

    See Also
    ========

    eye
    i   (   R%   c           s*   t  |  ƒ r& t |  t ƒ r& ˆ  |  ƒ S|  S(   N(   R   R$   R   (   RÉ   (   R%   (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pyt	   normalize¬  s    
c         3  s   |  ] } ˆ  | ƒ Vq d  S(   N(    (   RA   RÉ   (   Rã   (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pys	   <genexpr>°  s    (   Rß   R%   Rk   (   t   valuesR{   (    (   R%   Rã   s3   lib/python2.7/site-packages/sympy/matrices/dense.pyRk   Q  s    Wc         C  sË   g  } t  |  ƒ } xx t | ƒ D]j } |  | } x/ t | ƒ D]! } | |  | j | | ƒ 8} q< W| j ƒ  s| t d ƒ ‚ n  | j | ƒ q W| rÇ x1 t t  | ƒ ƒ D] } | | j ƒ  | | <q¦ Wn  | S(   s‚   
    Apply the Gram-Schmidt process to a set of vectors.

    see: https://en.wikipedia.org/wiki/Gram%E2%80%93Schmidt_process
    s0   GramSchmidt: vector set not linearly independent(   RT   R   t   projectRä   R3   Ru   t
   normalized(   t   vlistt   orthonormalt   outRÉ   R:   t   tmpR;   (    (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pyt   GramSchmidtµ  s    
c         C  s  t  | t ƒ r[ d | j k r- t d ƒ ‚ n  | j d k rH | j } n  | j ƒ  d } n  t | ƒ r‹ t | ƒ } | s— t d ƒ ‚ q— n t	 d ƒ ‚ t
 |  d ƒ s¹ t	 d |  ƒ ‚ n  t | ƒ } | | } t | ƒ } xt t | ƒ D]f \ } } t
 | d ƒ st	 d |  ƒ ‚ n  x5 t | ƒ D]' }	 | j | |	 ƒ | | |	 | f <q#Wqè Wx` t | ƒ D]R }	 xI t |	 | ƒ D]8 }
 |  j | |	 ƒ j | |
 ƒ | |	 | |
 | f <quWq_WxL t | ƒ D]> }	 x5 t |	 d | ƒ D]  }
 | |	 |
 f | |
 |	 f <qÜWqÂW| S(   sü  Compute Hessian matrix for a function f wrt parameters in varlist
    which may be given as a sequence or a row/column vector. A list of
    constraints may optionally be given.

    Examples
    ========

    >>> from sympy import Function, hessian, pprint
    >>> from sympy.abc import x, y
    >>> f = Function('f')(x, y)
    >>> g1 = Function('g')(x, y)
    >>> g2 = x**2 + 3*y
    >>> pprint(hessian(f, (x, y), [g1, g2]))
    [                   d               d            ]
    [     0        0    --(g(x, y))     --(g(x, y))  ]
    [                   dx              dy           ]
    [                                                ]
    [     0        0        2*x              3       ]
    [                                                ]
    [                     2               2          ]
    [d                   d               d           ]
    [--(g(x, y))  2*x   ---(f(x, y))   -----(f(x, y))]
    [dx                   2            dy dx         ]
    [                   dx                           ]
    [                                                ]
    [                     2               2          ]
    [d                   d               d           ]
    [--(g(x, y))   3   -----(f(x, y))   ---(f(x, y)) ]
    [dy                dy dx              2          ]
    [                                   dy           ]

    References
    ==========

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

    See Also
    ========

    sympy.matrices.mutable.Matrix.jacobian
    wronskian
    i   s)   `varlist` must be a column or row vector.i    s    `len(varlist)` must not be zero.s*   Improper variable list in hessian functiont   diffs'   Function `f` (%s) is not differentiable(   R$   R   R    R   R.   t   TRŽ   R   RT   R3   R!   RD   RÄ   R   Rì   (   R¥   t   varlistt   constraintsRÝ   RÉ   t   NRé   RB   t   gR:   R;   (    (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pyt   hessianË  s8    ,
):"c         C  s&   d d l  m } | j d | d |  ƒ S(   sû   
    Create a Jordan block:

    Examples
    ========

    >>> from sympy.matrices import jordan_cell
    >>> from sympy.abc import x
    >>> jordan_cell(x, 4)
    Matrix([
    [x, 1, 0, 0],
    [0, x, 1, 0],
    [0, 0, x, 1],
    [0, 0, 0, x]])
    i   (   R%   t   sizet
   eigenvalue(   Rß   R%   t   jordan_block(   t   eigenvalRÝ   R%   (    (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pyt   jordan_cell  s    c         C  s   |  j  | ƒ S(   s  Return the Hadamard product (elementwise product) of A and B

    >>> from sympy.matrices import matrix_multiply_elementwise
    >>> from sympy.matrices import Matrix
    >>> A = Matrix([[0, 1, 2], [3, 4, 5]])
    >>> B = Matrix([[1, 10, 100], [100, 10, 1]])
    >>> matrix_multiply_elementwise(A, B)
    Matrix([
    [  0, 10, 200],
    [300, 40,   5]])

    See Also
    ========

    __mul__
    (   t   multiply_elementwise(   t   At   B(    (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pyt   matrix_multiply_elementwise-  s    c          O  sB   d | k r" | j  d ƒ | d <n  d d l m } | j |  | Ž  S(   sº   Returns a matrix of ones with ``rows`` rows and ``cols`` columns;
    if ``cols`` is omitted a square matrix will be returned.

    See Also
    ========

    zeros
    eye
    diag
    t   cR.   i   (   R%   (   t   popRß   R%   t   ones(   Rž   R{   R%   (    (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pyRþ   A  s    i    ic   id   c           s—  | d k r |  } n  ˆ p' t j | ƒ ‰ | s« t j |  | ‡  ‡ ‡ f d †  ƒ } | d k rd | St |  | d | d ƒ }	 t j g |	 | j |	 *ˆ j	 | j ƒ | S|  | k rÐ t
 d |  | f ƒ ‚ n  t |  ƒ } g  t |  ƒ D]( }
 t |
 |  ƒ D] } |
 | f ^ qü qé } | d k rLˆ j | t t | ƒ | d ƒ ƒ } n  xD | D]< \ }
 } ˆ j ˆ ˆ  ƒ } | | |
 | f <| | |
 f <qSW| S(   sç  Create random matrix with dimensions ``r`` x ``c``. If ``c`` is omitted
    the matrix will be square. If ``symmetric`` is True the matrix must be
    square. If ``percent`` is less than 100 then only approximately the given
    percentage of elements will be non-zero.

    The pseudo-random number generator used to generate matrix is chosen in the
    following way.

    * If ``prng`` is supplied, it will be used as random number generator.
      It should be an instance of :class:`random.Random`, or at least have
      ``randint`` and ``shuffle`` methods with same signatures.
    * if ``prng`` is not supplied but ``seed`` is supplied, then new
      :class:`random.Random` with given ``seed`` will be created;
    * otherwise, a new :class:`random.Random` with default seed will be used.

    Examples
    ========

    >>> from sympy.matrices import randMatrix
    >>> randMatrix(3) # doctest:+SKIP
    [25, 45, 27]
    [44, 54,  9]
    [23, 96, 46]
    >>> randMatrix(3, 2) # doctest:+SKIP
    [87, 29]
    [23, 37]
    [90, 26]
    >>> randMatrix(3, 3, 0, 2) # doctest:+SKIP
    [0, 2, 0]
    [2, 0, 1]
    [0, 0, 1]
    >>> randMatrix(3, symmetric=True) # doctest:+SKIP
    [85, 26, 29]
    [26, 71, 43]
    [29, 43, 57]
    >>> A = randMatrix(3, seed=1)
    >>> B = randMatrix(3, seed=2)
    >>> A == B # doctest:+SKIP
    False
    >>> A == randMatrix(3, seed=1)
    True
    >>> randMatrix(3, symmetric=True, percent=50) # doctest:+SKIP
    [77, 70,  0],
    [70,  0,  0],
    [ 0,  0, 88]
    c           s   ˆ j  ˆ ˆ  ƒ S(   N(   t   randint(   R:   R;   (   t   maxt   mint   prng(    s3   lib/python2.7/site-packages/sympy/matrices/dense.pyRL   Š  RM   id   s4   For symmetric matrices, r must equal c, but %i != %iN(   R"   t   randomt   RandomR%   RG   t   intR
   R[   R&   t   shuffleR3   RD   R   t   sampleRT   Rÿ   (   R}   Rü   R  R   t   seedt	   symmetrict   percentR  RÉ   t   zR:   R;   t   ijR>   (    (   R   R  R  s3   lib/python2.7/site-packages/sympy/matrices/dense.pyt
   randMatrixT  s*    0	$;)"t   bareissc           s‹   d d l  m } x1 t d t ˆ  ƒ ƒ D] } t ˆ  | ƒ ˆ  | <q& Wt ˆ  ƒ } | d k r` d S| | | ‡  ‡ f d †  ƒ } | j | ƒ S(   so  
    Compute Wronskian for [] of functions

    ::

                         | f1       f2        ...   fn      |
                         | f1'      f2'       ...   fn'     |
                         |  .        .        .      .      |
        W(f1, ..., fn) = |  .        .         .     .      |
                         |  .        .          .    .      |
                         |  (n)      (n)            (n)     |
                         | D   (f1) D   (f2)  ...  D   (fn) |

    see: https://en.wikipedia.org/wiki/Wronskian

    See Also
    ========

    sympy.matrices.mutable.Matrix.jacobian
    hessian
    i   (   R%   i    c           s   ˆ  |  j  ˆ | ƒ S(   N(   Rì   (   R:   R;   (   t	   functionst   var(    s3   lib/python2.7/site-packages/sympy/matrices/dense.pyRL   ¾  RM   (   Rß   R%   R   RT   R   Rà   (   R  R  Rl   R%   RÚ   RÝ   t   W(    (   R  R  s3   lib/python2.7/site-packages/sympy/matrices/dense.pyt	   wronskian¡  s    c          O  sB   d | k r" | j  d ƒ | d <n  d d l m } | j |  | Ž  S(   sº   Returns a matrix of zeros with ``rows`` rows and ``cols`` columns;
    if ``cols`` is omitted a square matrix will be returned.

    See Also
    ========

    ones
    eye
    diag
    Rü   R.   i   (   R%   (   Rý   Rß   R%   RD   (   Rž   R{   R%   (    (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pyRD   Â  s    (E   t
   __future__R    R   R  t
   sympy.coreR   t   sympy.core.basicR   t   sympy.core.compatibilityR   R   R   t   sympy.core.exprR   t   sympy.core.functionR   R	   t   sympy.core.singletonR
   t   sympy.core.symbolR   t   sympy.core.sympifyR   t(   sympy.functions.elementary.miscellaneousR   t(   sympy.functions.elementary.trigonometricR   R   t   sympy.matrices.commonR   R   t   sympy.matrices.matricesR   R   t   sympy.simplifyR   R¼   t   sympy.utilities.decoratorR   t   sympy.utilities.miscR   R   R   R   Rœ   R   t   MutableMatrixR%   R¡   RÈ   RÊ   RÏ   RÐ   RÑ   RÛ   R2   Râ   R†   Rk   R#   Rë   Rò   R÷   Rû   Rþ   R"   R  R  RD   (    (    (    s3   lib/python2.7/site-packages/sympy/matrices/dense.pyt   <module>   sT   		ÿ |	ÿ s
	+	+	+M,		dM			L!