
    \h"                      S SK Jr  S SKJr  S SKJr  S SKJr  S SKJ	r	  S SK
Jr  S SKJrJr  S SKJrJr  S S	KJr  S S
KJr  S SKJr  S SKJrJr  S SKJrJr  S SKJr  S SK J!r!  S SK"J#r#J$r$J%r%  S SK&J'r'  S SK(J)r)J*r*J+r+  S SK,J-r-J.r.  S SK/J0r0  S SK1J2r2  S SK3J4r4  S SK5J6r6J7r7  S SK8J9r9J:r:  S SK;r<S SKJ=r=  S SK>J?r?  S SK@JArA  S SKBJCrC  S SKJDrD  SS KEJFrFJGrH  S S!KIJJrJ  S S"K>JKrKJLrL  S S#KMJNrNJOrO  S S$KPJQrQ  S S%KRJSrSJTrT  S S&KUJVrV  S S'K>JWrW  SS(KEJXrX  SS)KYJZrZ  SS*K[J\r\J]r]J^r^J_r_  SS+KEJ`r`Jara  SS,KbJcrcJdrdJereJfrfJgrgJhrhJiriJjrjJkrkJlrlJmrmJnrnJoroJprpJqrq  SS-KrJsrsJtrtJuruJvrv  SS.KwJxrxJyryJzrzJ{r{J|r|J}r}J~r~JrJrJrJrJr  SS/KJrJrJrJrJrJrJrJrJr  SS0KJrJrJrJr  SS1KJrJrJrJrJrJrJrJrJrJrJrJrJrJr  SS2KJrJrJrJrJrJrJrJrJr  SS3KJrJrJrJr  S4S5/0r " S6 S7\25      rS8 rS9 rS: rS; rS< rS= rSAS> jr " S? S@\\W5      rg)B    )annotations)defaultdict)Iterable)
isfunction)reducerefine)SympifyErrorAdd)AtomBasic)UndefinedKind)IntegerMod)SymbolDummy)sympify_sympifydiff)cancel)Absreimsstr)MaxMinsqrt)KroneckerDelta
LeviCivita)S)	Printable)
StrPrinter)explog)binomial	factorialN)Callable)reshape)Expr)Pow)uniquely_named_symbol   )_dotprodsimp	_simplify)Poly)flattenis_sequence)as_int
filldedent)call_highest_priority)	fuzzy_and	FuzzyBool)	NDimArray)NotIterable)_get_intermediate_simp_bool)
MatrixKind)MatrixError
ShapeErrorNonSquareMatrixErrorNonInvertibleMatrixError)_iszero_is_zero_after_expand_mul)_find_reasonable_pivot_find_reasonable_pivot_naive	_adjugate	_charpoly	_cofactor_cofactor_matrix_per_det_det_bareiss_det_berkowitz	_det_bird_det_laplace_det_LU_minor_minor_submatrix)_is_echelon_echelon_form_rank_rref)_diagonal_solve_lower_triangular_solve_upper_triangular_solve_cholesky_solve	_LDLsolve_LUsolve_QRsolve_gauss_jordan_solve_pinv_solve_cramer_solve_solve_solve_least_squares)	_pinv_inv_ADJ_inv_GE_inv_LU_inv_CH_inv_LDL_inv_QR_inv
_inv_block)_columnspace
_nullspace	_rowspace_orthogonalize)
_eigenvals_eigenvects_bidiagonalize_bidiagonal_decomposition_is_diagonalizable_diagonalize_is_positive_definite_is_positive_semidefinite_is_negative_definite_is_negative_semidefinite_is_indefinite_jordan_form_left_eigenvects_singular_values)	_rank_decomposition	_cholesky_LDLdecomposition_LUdecomposition_LUdecomposition_Simple_LUdecompositionFF_singular_value_decomposition_QRdecomposition_upper_hessenberg_decomposition)_connected_components#_connected_components_decomposition_strongly_connected_components,_strongly_connected_components_decomposition)zMatrixBase.is_indefinitezMatrixBase.is_positive_definitez#MatrixBase.is_positive_semidefinitezMatrixBase.is_negative_definitez#MatrixBase.is_negative_semidefinite
matplotlibc                     \ rS rSr% SrSrSrSrSr\	" \
5      r\R                  r\R                  rSrS\S'   S	\S
'   S	\S'   Sr\S 5       rS rS r\S 5       rS rS rS rS rS rS rS r S r!S r"S r#\S 5       r$S r%S r&S r'S r(S  r)S! r*S" r+S# r,\S$ 5       r-S% r.S& r/S' r0S( r1GS9S) jr2S* r3S+ r4\S, 5       r5S- r6S. r7S/ r8GS:S0 jr9\S1 5       r:\S2 5       r;\S3 5       r<\GS;GS<S5 jj5       r=\S6 5       r>\S7 5       r?\S8 5       r@\S9SSSS:.S; j5       rA\GS=S< j5       rB\GS>S4S=.S> jj5       rC\GS=S? j5       rD\GS=S@ j5       rE\SA 5       rF\SB 5       rGSC rHSD rISE rJSF rKSG rLSH rMSI rNSJ rOSK rPGS?SL jrQSM rRSN rSSO rTSP rUSQ rVSR rWSS rXST rYSU rZSV r[\SW 5       r\SX r]GS@SY jr^SZ r_\S[ 5       r`\S\ 5       ra\S] 5       rb\GS?S^ j5       rc\S_ 5       rd\S` 5       re\Sa 5       rfSb rgGS@Sc jrh\Sd 5       ri\Se 5       rj\Sf 5       rkSg rlSh rmSi rnSj roSk rpSl rqSm rrSn rsSo rtSp ruSq rvSr rwSs rxGS@St jrySu rzSv r{GSASw jr|  GSBSx jr}\Sy 5       r~GSCSz jrGSDS{ jrGSDS| jrGS@S} jrGSES~ jrGSFS jrS rS rS rS r\S 5       r\S 5       rS rS rS rS rGS9S jrGS9S jrS rS rS rS rS rS rS rGS=S jrS rS rS rS r\" S5      S 5       r\" S5      S 5       r\" S5      S 5       rS r\" S5      S 5       rGS=S jrS rS r\" S5      S 5       rGS=S jr\" S5      S 5       r\" S5      S 5       r\" S5      S 5       rGS=S jr\" S5      S 5       r\" S5      S 5       r\4S jrS r\S4S jrS rS rS rGSGS jrS\4S jrGSGS jrGSGS jrGSHS jrS rGSGS jrS r\R                  \l        \R                  \l        \R                  \l        \R                  \l        \R                  \l        \R                  \l        \R                  \l        \R                  \l        \R                  \l        \R                  \l        \R                  \l        \R                  \l        \R                  \l        \R                  \l        \R                  \l        \R                  \l        \S9S94S jr\S 5       r\S94S jrS r\S9SS4S jr\R                  \l        \R                  \l        \R                  \l        \R                  \l        GSIS jrS rS rS rS rS rS rGSJS jrGSJS jrGSKS jrS9\4S jrGSKS jrS r\R                  \l        \R                  \l        \R                  \l        \R                  \l        \" \5      rGS@S jrS\4S jrGSKS jrGSLS jrGS@S jrGS@S jr\S 5       r\S 5       r\S 5       r\S 5       r\S 5       rGS@S jrS rS r\R                  \l        \R                  \l        \R                  \l        \R                  \l        \R                  \l        \R                  \l        \R                  \l        \R                  \l        \R                  \l        \R                  \l        G\ R                  \l        G\R                  \l        G\R                  \l        G\R                  \l        SS.S jGrS GrS GrS GrS GrG\	" S5      \4S jGr
S GrS GrS GrS GrGSGS jGrS GrS GrS GrGS@S jGrGSGS jGrS GrS GrS Gr\GSMS j5       GrS GrG\S4S jGrS GrS GrS GrGS=S jGr\S 5       Gr \S 5       Gr!\S 5       Gr"S Gr#GS  Gr$GS Gr%GS Gr&GS Gr'GS Gr(GS Gr)\GS 5       Gr*GS>GS jGr+GS Gr,GS	 Gr-GS
 Gr.GS Gr/GS Gr0G\14GS jGr2GS Gr3GS Gr4GS Gr5\4GS jGr6GS=GS jGr7GSNGS jGr8GS Gr9  GSOGS jGr:\S94GS jGr;GS@GS jGr<GS@GS jGr=\SS94GS jGr>\SS94GS jGr?GS Gr@GS GrAGS GrBGS GrCGS GrDGS  GrEGS! GrFGS" GrGGS# GrH\4GS$ jGrIGS% GrJGSKGS& jGrKGS=GS' jGrLGSPGS( jGrMGSQGS) jGrNGSRGS* jGrOGSSGS+ jGrP\4GS, jGrQ\4GS- jGrR\4GS. jGrS\4GS/ jGrT\4GS0 jGrU\4GS1 jGrV\4GS2 jGrWS\S94GS3 jGrXGS4 GrYGS5 GrZGS6 Gr[GS@GS7 jGr\G\]GR                  Gr^G\_R                  G\;l        G\`R                  G\<l        G\aR                  G\=l        G\bR                  G\>l        G\cR                  G\?l        G\dR                  G\@l        G\eR                  G\Al        G\fR                  G\Bl        G\gR                  G\Cl        G\hR                  G\Dl        G\iR                  G\El        G\jR                  G\Fl        G\kR                  G\Gl        G\lR                  G\Hl        G\mR                  G\Il        G\nR                  G\Jl        G\oR                  G\Kl        G\pR                  G\Ll        G\qR                  G\Ml        G\rR                  G\Nl        G\sR                  G\Ol        G\tR                  G\Pl        G\uR                  G\Ql        G\vR                  G\Sl        G\wR                  G\Tl        G\xR                  G\Ul        G\yR                  G\Vl        G\zR                  G\Wl        G\{R                  G\Rl        G\|R                  G\Xl        G\}R                  G\Yl        G\~R                  G\Zl        G\R                  G\[l        G\R                  G\\l        GS8Grg(T  
MatrixBasec   zoAll common matrix operations including basic arithmetic, shaping,
and special matrices like `zeros`, and `eye`.gQ$@   T   bool	_diff_wrtintrowscolsNc                    [        S5      e)zv`_new` must, at minimum, be callable as
`_new(rows, cols, mat) where mat is a flat list of the
elements of the matrix.Subclasses must implement this.NotImplementedError)clsargskwargss      Q/var/www/auris/envauris/lib/python3.13/site-packages/sympy/matrices/matrixbase.py_newMatrixBase._neww       
 ""CDD    c                    [        S5      e)Nr   r   selfothers     r   __eq__MatrixBase.__eq__~   s    !"CDDr   c                    [        S5      e)zImplementations of __getitem__ should accept ints, in which
case the matrix is indexed as a flat list, tuples (i,j) in which
case the (i,j) entry is returned, slices, or mixed tuples (a,b)
where a and b are any combination of slices and integers.r   r   )r   keys     r   __getitem__MatrixBase.__getitem__   r   r   c                2    U R                   U R                  4$ )zThe shape (dimensions) of the matrix as the 2-tuple (rows, cols).

Examples
========

>>> from sympy import zeros
>>> M = zeros(2, 3)
>>> M.shape
(2, 3)
>>> M.rows
2
>>> M.cols
3
r   r   r   s    r   shapeMatrixBase.shape   s      		499%%r   c                h   ^ ^ UU 4S jnT R                  T R                  T R                  S-
  U5      $ )Nc                .   > UT:  a  TX4   $ TXS-   4   $ Nr/    )ijcolr   s     r   entry'MatrixBase._eval_col_del.<locals>.entry   s$    !"S4:<d1!e8n<r   r/   r   r   r   )r   r   r   s   `` r   _eval_col_delMatrixBase._eval_col_del   s'    	=yyDIIM599r   c                   ^ ^^ UUU 4S jnT R                  T R                  T R                  TR                  -   U5      $ )Nc                   > UT:  a  TX4   $ TUs=::  a  TTR                   -   :  a  O  O	TXT-
  4   $ TXTR                   -
  4   $ Nr   )r   r   r   posr   s     r   r   *MatrixBase._eval_col_insert.<locals>.entry   sS    3wADz!,C%**,,QCZ((uzz>)**r   r   )r   r   r   r   s   ``` r   _eval_col_insertMatrixBase._eval_col_insert   s.    	+ yyDII

$:EBBr   c                   ^ ^^ T R                   mUUU 4S jn[        T T5      R                  T R                   TR                   -   T R                  U5      $ )Nc                0   > U T:  a  TX4   $ TU T-
  U4   $ r   r   )r   r   r   r   r   s     r   r   (MatrixBase._eval_col_join.<locals>.entry   s)    4xADz!T1%%r   )r   classofr   r   )r   r   r   r   s   `` @r   _eval_col_joinMatrixBase._eval_col_join   sE    yy	&
 tU#((UZZ)?).0 	0r   c           	        ^^ [        U 5      nU R                  mUU4S jU 5       nU R                  [        U5      [        T5      U Vs/ s H  oSU   PM	     sn5      $ s  snf )Nc              3  F   >#    U  H  nT  H  o!T-  U-   v   M     M     g 7fr   r   ).0r   r   r   colsLists      r   	<genexpr>+MatrixBase._eval_extract.<locals>.<genexpr>   s     DA8at8a<8<s   !)listr   r   len)r   rowsListr   matindicesr   r   s     `   @r   _eval_extractMatrixBase._eval_extract   sS    4jyyDDyyXH*12'Qa&'24 	42s   
Ac                ,   ^^ / mUU4S jmT" U 5        T$ )Nc                  > [        SU R                  S   S-   5       H  nUS:X  a  U SUS 24   nXS 2S4   nOU S U2US 24   nXS 2S U24   n[        U5      (       d  [        U5      (       a  MR  TR                  U S U2S U24   5        U R                  U S U2S U24   R                  :w  a  T" XS 2US 24   5          g    g )Nr/   r   )ranger   anyappend)Mr   to_the_rightto_the_bottomrecurse_sub_blocks
sub_blockss       r   r   <MatrixBase._eval_get_diag_blocks.<locals>.recurse_sub_blocks   s    1aggaj1n-6#$QU8L$%b!eHM#$RaRV9L$%b"1"fIM|$$M(:(:!!!BQBF),77aBQBioo-&qQRy1 .r   r   )r   r   r   s    @@r   _eval_get_diag_blocks MatrixBase._eval_get_diag_blocks   s    
	 	4 r   c                h   ^ ^ UU 4S jnT R                  T R                  S-
  T R                  U5      $ )Nc                0   > U T:  a  TX4   $ TU S-   U4   $ r   r   )r   r   rowr   s     r   r   'MatrixBase._eval_row_del.<locals>.entry   s&    !"S4:<d1q5!8n<r   r/   r   )r   r   r   s   `` r   _eval_row_delMatrixBase._eval_row_del   s'    	=yyQ		599r   c                    [        U 5      nXR                  -  n[        U5      X4U& U R                  U R                  UR                  -   U R                  U5      $ r   )r   r   r   r   )r   r   r   entries
insert_poss        r   _eval_row_insertMatrixBase._eval_row_insert   sH    t*99_
)-e:&yyUZZ/GDDr   c                   ^ ^^ T R                   mUUU 4S jn[        T T5      R                  T R                  T R                   TR                   -   U5      $ )Nc                .   > UT:  a  TX4   $ TXT-
  4   $ r   r   )r   r   r   r   r   s     r   r   (MatrixBase._eval_row_join.<locals>.entry   s'    4xADz!H%%r   )r   r   r   r   )r   r   r   r   s   `` @r   _eval_row_joinMatrixBase._eval_row_join   sE    yy	&
 tU#((DII

4J).0 	0r   c           	     v    [        U R                  5       Vs/ s H  n[        XS S 24   5      PM     sn$ s  snf r   )r   r   r   r   r   s     r   _eval_tolistMatrixBase._eval_tolist   s/    ).tyy)9:)9ATA#Y)9:::s   6c                    0 nU R                   u  p#[        U5       H1  n[        U5       H  nXU4   nX`R                  :w  d  M  XaXE4'   M!     M3     U$ r   )r   r   zero)r   dokr   r   r   r   vals          r   _eval_todokMatrixBase._eval_todok   sS    ZZ
tA4[a4j))# #I ! 
 
r   c                    U R                   /X-  -  nUR                  5        H  u  u  pVnXtXR-  U-   '   M     U R                  XU5      $ r   )r   itemsr   )r   r   r   r   out_flatr   r   r   s           r   _eval_from_dokMatrixBase._eval_from_dok   sI    HH:-99;KFQC%(QX\" 'xxH--r   c                d   ^ ^ T R                   mUU 4S jnT R                  [        T 5      SU5      $ )Nc                (   > U T-  nXT-  -
  nTX24   $ r   r   )n_r   r   r   r   s       r   r   #MatrixBase._eval_vec.<locals>.entry   s#    T	AHA:r   r/   )r   r   r   )r   r   r   s   ` @r   	_eval_vecMatrixBase._eval_vec   s*    yy	 yyTAu--r   c                R   U R                   n/ nU(       a:  [        U5       H*  n[        XB5       H  nUR                  XU4   5        M     M,     O=[        U5       H.  n[        US-   U5       H  nUR                  XU4   5        M     M0     U R                  [	        U5      SU5      $ r   )r   r   r   r   r   )r   diagonalcvr   r   s         r   
_eval_vechMatrixBase._eval_vech  s    II1XqAHHTQ$Z( %  1Xq1uaAHHTQ$Z( )  yyQA&&r   c                    US:  a  XR                   -  nSUs=::  a  U R                   :  d  O  [        SR                  U5      5      eU R                  U5      $ )zDelete the specified column.r   zColumn {} is out of range.)r   
IndexErrorformatr   )r   r   s     r   col_delMatrixBase.col_del  sN    799CC#$))#9@@EFF!!#&&r   c                n   U (       d  [        U 5      " U5      $ [        U5      nUS:  a  U R                  U-   nUS:  a  SnOXR                  :  a  U R                  nU R                  UR                  :w  a/  [	        SR                  U R                  UR                  5      5      eU R                  X5      $ )a  Insert one or more columns at the given column position.

Examples
========

>>> from sympy import zeros, ones
>>> M = zeros(3)
>>> V = ones(3, 1)
>>> M.col_insert(1, V)
Matrix([
[0, 1, 0, 0],
[0, 1, 0, 0],
[0, 1, 0, 0]])

See Also
========

col
row_insert
r   9The matrices have incompatible number of rows ({} and {}))typer5   r   r   r?   r  r   r   r   r   s      r   
col_insertMatrixBase.col_insert  s    , :e$$Sk7))c/C7C99_))C99

"K		5::.0 0 $$S00r   c                b   U R                   S:X  aF  U R                  UR                  :w  a,  U R                  SUR                  / 5      R                  U5      $ U R                  UR                  :w  a/  [	        SR                  U R                  UR                  5      5      eU R                  U5      $ )a  Concatenates two matrices along self's last and other's first row.

Examples
========

>>> from sympy import zeros, ones
>>> M = zeros(3)
>>> V = ones(1, 3)
>>> M.col_join(V)
Matrix([
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[1, 1, 1]])

See Also
========

col
row_join
r   <The matrices have incompatible number of columns ({} and {}))r   r   r   col_joinr?   r  r   r   s     r   r  MatrixBase.col_joinD  s    . 99>dii5::599Q

B/88??99

"N		5::.0 0 ""5))r   c                    U SS2U4   $ )zElementary column selector.

Examples
========

>>> from sympy import eye
>>> eye(2).col(0)
Matrix([
[1],
[0]])

See Also
========

row
col_del
col_join
col_insert
Nr   )r   r   s     r   r   MatrixBase.cold  s    ( AqDzr   c                R   [        U5      (       a  [        U5      (       d  [        S5      eU(       a?  [        S U 5       5      (       a(  [        U5       VVs/ s H  u  p4U(       d  M  UPM     nnnU(       a?  [        S U 5       5      (       a(  [        U5       VVs/ s H  u  p4U(       d  M  UPM     nnnU Vs/ s H  n[	        XPR
                  5      PM     nnU Vs/ s H  n[	        XPR                  5      PM     nnU R                  X5      $ s  snnf s  snnf s  snf s  snf )a\  Return a submatrix by specifying a list of rows and columns.
Negative indices can be given. All indices must be in the range
$-n \le i < n$ where $n$ is the number of rows or columns.

Examples
========

>>> from sympy import Matrix
>>> m = Matrix(4, 3, range(12))
>>> m
Matrix([
[0,  1,  2],
[3,  4,  5],
[6,  7,  8],
[9, 10, 11]])
>>> m.extract([0, 1, 3], [0, 1])
Matrix([
[0,  1],
[3,  4],
[9, 10]])

Rows or columns can be repeated:

>>> m.extract([0, 0, 1], [-1])
Matrix([
[2],
[2],
[5]])

Every other row can be taken by using range to provide the indices:

>>> m.extract(range(0, m.rows, 2), [-1])
Matrix([
[2],
[8]])

RowsList or colsList can also be a list of booleans, in which case
the rows or columns corresponding to the True values will be selected:

>>> m.extract([0, 1, 2, 3], [True, False, True])
Matrix([
[0,  2],
[3,  5],
[6,  8],
[9, 11]])
z&rowsList and colsList must be iterablec              3  B   #    U  H  n[        U[        5      v   M     g 7fr   
isinstancer   r   r   s     r   r   %MatrixBase.extract.<locals>.<genexpr>       BAJq$//   c              3  B   #    U  H  n[        U[        5      v   M     g 7fr   r$  r&  s     r   r   r'    r(  r)  )r4   	TypeErrorall	enumeratea2idxr   r   r   )r   r   r   indexitemks         r   extractMatrixBase.extractz  s    ` 8$$K,A,ADEEBBBB1:81DM1D+%1DHMBBBB1:81DM1D+%1DHM 2::AE!YY':19:AE!YY':!!(55 NM ;:s$   D)DD/D<D!D$c                "    U R                  5       $ )a  Obtains the square sub-matrices on the main diagonal of a square matrix.

Useful for inverting symbolic matrices or solving systems of
linear equations which may be decoupled by having a block diagonal
structure.

Examples
========

>>> from sympy import Matrix
>>> from sympy.abc import x, y, z
>>> A = Matrix([[1, 3, 0, 0], [y, z*z, 0, 0], [0, 0, x, 0], [0, 0, 0, 0]])
>>> a1, a2, a3 = A.get_diag_blocks()
>>> a1
Matrix([
[1,    3],
[y, z**2]])
>>> a2
Matrix([[x]])
>>> a3
Matrix([[0]])

)r   r   s    r   get_diag_blocksMatrixBase.get_diag_blocks  s    0 ))++r   c                    [        U5      S:X  a  U R                  5       $ [        US   5      n[        UR                  U5      $ )zReturn a matrix formed by joining args horizontally (i.e.
by repeated application of row_join).

Examples
========

>>> from sympy import Matrix, eye
>>> Matrix.hstack(eye(2), 2*eye(2))
Matrix([
[1, 0, 2, 0],
[0, 1, 0, 2]])
r   )r   r   r  r   row_joinr   r   klss      r   hstackMatrixBase.hstack  s9     t9>88:47mcllD))r   c           	     2   U R                   U R                  -  X-  :w  a  [        SX4-  5      eU R                  5       R	                  5        VVVs0 s H$  u  u  p4n[        X0R                  -  U-   U5      U_M&     nnnnU R                  XU5      $ s  snnnf )a'  Reshape the matrix. Total number of elements must remain the same.

Examples
========

>>> from sympy import Matrix
>>> m = Matrix(2, 3, lambda i, j: 1)
>>> m
Matrix([
[1, 1, 1],
[1, 1, 1]])
>>> m.reshape(1, 6)
Matrix([[1, 1, 1, 1, 1, 1]])
>>> m.reshape(3, 2)
Matrix([
[1, 1],
[1, 1],
[1, 1]])

z Invalid reshape parameters %d %d)r   r   
ValueErrortodokr   divmodr  )r   r   r   r   r   r  r   s          r   r+   MatrixBase.reshape  s    * 99tyy DK/?4,NOO#zz|11353)&1! a		kAot,3 	 5""4s335s   +Bc                    US:  a  XR                   -  nSUs=::  a  U R                   :  d  O  [        SR                  U5      5      eU R                  U5      $ )zDelete the specified row.r   zRow {} is out of range.)r   r  r  r   )r   r   s     r   row_delMatrixBase.row_del  sN    799CC#$))#6==cBCC!!#&&r   c                n   U (       d  U R                  U5      $ [        U5      nUS:  a  U R                  U-   nUS:  a  SnOXR                  :  a  U R                  nU R                  UR                  :w  a/  [	        SR                  U R                  UR                  5      5      eU R                  X5      $ )zInsert one or more rows at the given row position.

Examples
========

>>> from sympy import zeros, ones
>>> M = zeros(3)
>>> V = ones(1, 3)
>>> M.row_insert(1, V)
Matrix([
[0, 0, 0],
[1, 1, 1],
[0, 0, 0],
[0, 0, 0]])

See Also
========

row
col_insert
r   r  )r   r5   r   r   r?   r  r   r  s      r   
row_insertMatrixBase.row_insert
  s    . 99U##Sk7))c/C7C99_))C99

"N		5::.0 0 $$S00r   c                b   U R                   S:X  aF  U R                  UR                  :w  a,  U R                  UR                  S/ 5      R                  U5      $ U R                  UR                  :w  a/  [	        SR                  U R                  UR                  5      5      eU R                  U5      $ )a  Concatenates two matrices along self's last and rhs's first column

Examples
========

>>> from sympy import zeros, ones
>>> M = zeros(3)
>>> V = ones(3, 1)
>>> M.row_join(V)
Matrix([
[0, 0, 0, 1],
[0, 0, 0, 1],
[0, 0, 0, 1]])

See Also
========

row
col_join
r   r  )r   r   r   r8  r?   r  r   r   s     r   r8  MatrixBase.row_join4  s    , 99>dii5::599UZZB/88??99

"K		5::.0 0 ""5))r   c                   / n[        U5      nUS:  a  SOU* nU(       a  SOUn X0R                  :X  d  X@R                  :X  a  O!UR                  XU4   5        US-  nUS-  nM@  U(       d;  [	        [        SU< SSU R                  -
  < SU R                  S-
  < S35      5      eU R                  S[        U5      U5      $ )a  Returns the kth diagonal of self. The main diagonal
corresponds to `k=0`; diagonals above and below correspond to
`k > 0` and `k < 0`, respectively. The values of `self[i, j]`
for which `j - i = k`, are returned in order of increasing
`i + j`, starting with `i + j = |k|`.

Examples
========

>>> from sympy import Matrix
>>> m = Matrix(3, 3, lambda i, j: j - i); m
Matrix([
[ 0,  1, 2],
[-1,  0, 1],
[-2, -1, 0]])
>>> _.diagonal()
Matrix([[0, 0, 0]])
>>> m.diagonal(1)
Matrix([[1, 1]])
>>> m.diagonal(-2)
Matrix([[-2]])

Even though the diagonal is returned as a Matrix, the element
retrieval can be done with a single index:

>>> Matrix.diag(1, 2, 3).diagonal()[1]  # instead of [0, 1]
2

See Also
========

diag
r   r/   z
            The z diagonal is out of range [, ])r5   r   r   r   r>  r6   r   r   )r   r1  rvrr  s        r   r  MatrixBase.diagonalS  s    D 1IQAQBAII~iiIIda4j!FAFA  Zq499}dii!m)- . / / yyCGR((r   c                    XSS24   $ )zElementary row selector.

Examples
========

>>> from sympy import eye
>>> eye(2).row(0)
Matrix([[1, 0]])

See Also
========

col
row_del
row_join
row_insert
Nr   r   s     r   r   MatrixBase.row  s    $ qDzr   c                "    U R                  5       $ )zReturn the matrix as dictionary of keys.

Examples
========

>>> from sympy import Matrix
>>> M = Matrix.eye(3)
>>> M.todok()
{(0, 0): 1, (1, 1): 1, (2, 2): 1}
)r   r   s    r   r?  MatrixBase.todok  s     !!r   c                    UR                  5        VVs0 s H  u  pEX@R                  U5      _M     nnnU R                  XU5      $ s  snnf )zCreate a matrix from a dictionary of keys.

Examples
========

>>> from sympy import Matrix
>>> d = {(0, 0): 1, (1, 2): 3, (2, 1): 4}
>>> Matrix.from_dok(3, 3, d)
Matrix([
[1, 0, 0],
[0, 0, 3],
[0, 4, 0]])
)r   r   r  )r   r   r   r   ijr   s         r   from_dokMatrixBase.from_dok  sE     58IIK@Kr<<$$K@!!$c22 As   Ac                    U R                   (       d  / $ U R                  (       d&  [        U R                   5       Vs/ s H  n/ PM     sn$ U R                  5       $ s  snf )a  Return the Matrix as a nested Python list.

Examples
========

>>> from sympy import Matrix, ones
>>> m = Matrix(3, 3, range(9))
>>> m
Matrix([
[0, 1, 2],
[3, 4, 5],
[6, 7, 8]])
>>> m.tolist()
[[0, 1, 2], [3, 4, 5], [6, 7, 8]]
>>> ones(3, 0).tolist()
[[], [], []]

When there are no rows then it will not be possible to tell how
many columns were in the original matrix:

>>> ones(0, 3).tolist()
[]

)r   r   r   r   r   s     r   tolistMatrixBase.tolist  sK    2 yyIyy %dii 01 01B 011  "" 2s   Ac                    0 nU R                  5       n[        U5       H:  u  p4[        U5       VVs0 s H  u  pVU(       d  M  XV_M     nnnU(       d  M6  XqU'   M<     U$ s  snnf )zReturns matrix as dict of dicts containing non-zero elements of the Matrix

Examples
========

>>> from sympy import Matrix
>>> A = Matrix([[0, 1],[0, 3]])
>>> A
Matrix([
[0, 1],
[0, 3]])
>>> A.todod()
{0: {1: 1}, 1: {1: 3}}


)rY  r-  )r   rowsdictMlolr   Mir   Mijr   s           r   tododMatrixBase.todod  s\    " xxzt_EA(1"=fa616C=s! %  >s   AAc                "    U R                  5       $ )zReturn the Matrix converted into a one column matrix by stacking columns

Examples
========

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

See Also
========

vech
)r	  r   s    r   vecMatrixBase.vec  s    0 ~~r   c                    U R                   (       d  [        eU(       a   U R                  5       (       d  [        S5      eU R	                  U5      $ )a  Reshapes the matrix into a column vector by stacking the
elements in the lower triangle.

Parameters
==========

diagonal : bool, optional
    If ``True``, it includes the diagonal elements.

check_symmetry : bool, optional
    If ``True``, it checks whether the matrix is symmetric.

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]])

Notes
=====

This should work for symmetric matrices and ``vech`` can
represent symmetric matrices in vector form with less size than
``vec``.

See Also
========

vec
zThe matrix is not symmetric.)	is_squarer@   is_symmetricr>  r  )r   r  check_symmetrys      r   vechMatrixBase.vech
  s>    T ~~&&$"3"3"5"5;<<x((r   c                    [        U5      S:X  a  U R                  5       $ [        US   5      n[        UR                  U5      $ )zReturn a matrix formed by joining args vertically (i.e.
by repeated application of col_join).

Examples
========

>>> from sympy import Matrix, eye
>>> Matrix.vstack(eye(2), 2*eye(2))
Matrix([
[1, 0],
[0, 1],
[2, 0],
[0, 2]])
r   )r   r   r  r   r  r9  s      r   vstackMatrixBase.vstack<  s9      t9>88:47mcllD))r   c                4   ^ U4S jnU R                  XU5      $ )zMdiag_dict is a defaultdict containing
all the entries of the diagonal matrix.c                   > TX4   $ r   r   )r   r   	diag_dicts     r   r   $MatrixBase._eval_diag.<locals>.entryV  s    aV$$r   r   )r   r   r   rp  r   s      ` r   
_eval_diagMatrixBase._eval_diagR  s    	%xxE**r   c                    U R                   /X-  -  nU R                  /[        X5      -  US S US-   2'   U R                  XUSS9$ )Nr/   Fcopy)r   oneminr   )r   r   r   valss       r   	_eval_eyeMatrixBase._eval_eyeZ  sI    z49%''3t?2XtAvXxxDux55r   upperc                T   ^ ^ US:X  a  U U4S jnOU U4S jnT R                  XU5      $ )Nlowerc                T   > X:X  a  T$ US-   U :X  a  TR                   $ TR                  $ r   rx  r   r   r   r   
eigenvalues     r   r   ,MatrixBase._eval_jordan_block.<locals>.entryc  +    6%%UaZ77Nxxr   c                T   > X:X  a  T$ U S-   U:X  a  TR                   $ TR                  $ r   r  r  s     r   r   r  j  r  r   rr  )r   sizer  bandr   s   ` `  r   _eval_jordan_blockMatrixBase._eval_jordan_block`  s'    7?   xxE**r   c                4   ^  U 4S jnT R                  XU5      $ )Nc                   > TR                   $ r   rx  r   r   r   s     r   r   $MatrixBase._eval_ones.<locals>.entryt  s    77Nr   rr  )r   r   r   r   s   `   r   
_eval_onesMatrixBase._eval_onesr  s    	xxE**r   c                D    U R                  XU R                  /X-  -  SS9$ )NFrv  )r   r   )r   r   r   s      r   _eval_zerosMatrixBase._eval_zerosx  s$    xxSXXJ	$:xGGr   c                B  ^  U 4S jnT R                  SU-  S-   SU-  S-   U5      nT R                  [        [        U* US-   5      5      SS9U-   UR                  -   n[        T R                  [        [        U* US-   5      5      SS95      U-   UR                  -   nXE4$ )Nc                F   > U S-   U:X  a  TR                   $ TR                  $ r   r  r  s     r   r   )MatrixBase._eval_wilkinson.<locals>.entry~  s     !eqj3776chh6r      r/   T)unpack)r   diagr   r   Tabs)r   r  r   Dwminuswpluss   `     r   _eval_wilkinsonMatrixBase._eval_wilkinson|  s    	7 HHQqS1WacAgu-$uaRQ/0>BQSSHCHHT%AE"23DHABQFL}r   F)strictr  r   r   c          
        SSK Jn  SSKJn  SSKJn	  UR                  SU 5      n
U(       a;  [        U5      S:X  a,  [        US   5      (       a  [        US   U5      (       d  US   n[        [        5      nS=pU GH  n[        U[        5      (       ap  U(       a(  U" U5      nUR                  u  nnUR                  5       nOU	R                  U5      u  nnnUR!                  5        H  u  u  nnnXUU-   UU-   4'   M     / nOB[#        US5      (       a   UR                  u  nnUR                  5       nOXX4'   US-  nUS-  nM  [%        U5       H'  u  nn[%        U5       H  u  nnXUU-   UU-   4'   M     M)     UU-  nUU-  nGM     Uc  XCpCUc  XpCOUc  UOUnX<:  d  XM:  a$  ['        [)        SR+                  XX45      5      5      eU
R-                  X4U5      $ )	a)  Returns a matrix with the specified diagonal.
If matrices are passed, a block-diagonal matrix
is created (i.e. the "direct sum" of the matrices).

kwargs
======

rows : rows of the resulting matrix; computed if
       not given.

cols : columns of the resulting matrix; computed if
       not given.

cls : class for the resulting matrix

unpack : bool which, when True (default), unpacks a single
sequence rather than interpreting it as a Matrix.

strict : bool which, when False (default), allows Matrices to
have variable-length rows.

Examples
========

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

The current default is to unpack a single sequence. If this is
not desired, set `unpack=False` and it will be interpreted as
a matrix.

>>> Matrix.diag([1, 2, 3]) == Matrix.diag(1, 2, 3)
True

When more than one element is passed, each is interpreted as
something to put on the diagonal. Lists are converted to
matrices. Filling of the diagonal always continues from
the bottom right hand corner of the previous item: this
will create a block-diagonal matrix whether the matrices
are square or not.

>>> col = [1, 2, 3]
>>> row = [[4, 5]]
>>> Matrix.diag(col, row)
Matrix([
[1, 0, 0],
[2, 0, 0],
[3, 0, 0],
[0, 4, 5]])

When `unpack` is False, elements within a list need not all be
of the same length. Setting `strict` to True would raise a
ValueError for the following:

>>> Matrix.diag([[1, 2, 3], [4, 5], [6]], unpack=False)
Matrix([
[1, 2, 3],
[4, 5, 0],
[6, 0, 0]])

The type of the returned matrix can be set with the ``cls``
keyword.

>>> from sympy import ImmutableMatrix
>>> from sympy.utilities.misc import func_name
>>> func_name(Matrix.diag(1, cls=ImmutableMatrix))
'ImmutableDenseMatrix'

A zero dimension matrix can be used to position the start of
the filling at the start of an arbitrary row or column:

>>> from sympy import ones
>>> r2 = ones(0, 2)
>>> Matrix.diag(r2, 1, 2)
Matrix([
[0, 0, 1, 0],
[0, 0, 0, 2]])

See Also
========
eye
diagonal
.dense.diag
.expressions.blockmatrix.BlockMatrix
.sparsetools.banded
r   r   MatrixSparseMatrixr   r/   r   zg
                The constructed matrix is {} x {} but a size of {} x {}
                was specified.)sympy.matrices.matrixbaser   sympy.matrices.denser  sympy.matricesr  getr   r4   r%  r   r   r   r   rY  _handle_creation_inputsr   hasattrr-  r>  r6   r  rs  )r:  r  r  r   r   r   r   r   r  r  klassdiag_entriesrmaxcmaxmr  rN  r  smatr   r   mis                         r   r  MatrixBase.diag  s   x 	9//

5#&c$i1nT!W)=)=tAw
337D #3'A!T""q	A77DAq
A!-!E!Ea!HJAq$%)ZZ\	A=>a$hD%9: &2AG$$ww1HHJ-.d\*		"12%bMDAq9:!d(AH!56 * & AIDAID5 6 <$<$<4TD;$+Z )""(&T"@B C C L99r   c                    Uc  UnUS:  d  US:  a  [        SR                  X5      5      eUR                  SU 5      n[        U5      [        U5      p!UR	                  X5      $ )zReturns an identity matrix.

Parameters
==========

rows : rows of the matrix
cols : cols of the matrix (if None, cols=rows)

kwargs
======
cls : class of the returned matrix
r   @Cannot create a {} x {} matrix. Both dimensions must be positiver   )r>  r  r  r5   r{  r:  r   r   r   r  s        r   eyeMatrixBase.eye  sh     <D!8tax @@Ft@RT T

5#&D\6$<dt**r   )r  c                  UR                  SU 5      nUR                  SS5      nUc  Uc  [        S5      eX&:w  a!  SXb4;  a  [        SR                  Xb5      5      eUb  UnUc  [        S5      e[	        U5      nUR                  XU5      $ )a  Returns a Jordan block

Parameters
==========

size : Integer, optional
    Specifies the shape of the Jordan block matrix.

eigenvalue : Number or Symbol
    Specifies the value for the main diagonal of the matrix.

    .. note::
        The keyword ``eigenval`` is also specified as an alias
        of this keyword, but it is not recommended to use.

        We may deprecate the alias in later release.

band : 'upper' or 'lower', optional
    Specifies the position of the off-diagonal to put `1` s on.

cls : Matrix, optional
    Specifies the matrix class of the output form.

    If it is not specified, the class type where the method is
    being executed on will be returned.

Returns
=======

Matrix
    A Jordan block matrix.

Raises
======

ValueError
    If insufficient arguments are given for matrix size
    specification, or no eigenvalue is given.

Examples
========

Creating a default Jordan block:

>>> from sympy import Matrix
>>> from sympy.abc import x
>>> Matrix.jordan_block(4, x)
Matrix([
[x, 1, 0, 0],
[0, x, 1, 0],
[0, 0, x, 1],
[0, 0, 0, x]])

Creating an alternative Jordan block matrix where `1` is on
lower off-diagonal:

>>> Matrix.jordan_block(4, x, band='lower')
Matrix([
[x, 0, 0, 0],
[1, x, 0, 0],
[0, 1, x, 0],
[0, 0, 1, x]])

Creating a Jordan block with keyword arguments

>>> Matrix.jordan_block(size=4, eigenvalue=x)
Matrix([
[x, 1, 0, 0],
[0, x, 1, 0],
[0, 0, x, 1],
[0, 0, 0, x]])

References
==========

.. [1] https://en.wikipedia.org/wiki/Jordan_matrix
r   eigenvalNzMust supply an eigenvaluez=Inconsistent values are given: 'eigenval'={}, 'eigenvalue'={}zMust supply a matrix size)popr  r>  r  r5   r  )r:  r  r  r  r   r  r  s          r   jordan_blockMatrixBase.jordan_block.  s    ^ 

5#&::j$/("2899#X4J(J""(&">@ @ #%
<899d|''$??r   c                |    Uc  UnUR                  SU 5      n[        U5      [        U5      p!UR                  X5      $ )zReturns a matrix of ones.

Parameters
==========

rows : rows of the matrix
cols : cols of the matrix (if None, cols=rows)

kwargs
======
cls : class of the returned matrix
r   )r  r5   r  r  s        r   onesMatrixBase.ones  s>     <D

5#&D\6$<d++r   c                    Uc  UnUS:  d  US:  a  [        SR                  X5      5      eUR                  SU 5      n[        U5      [        U5      p!UR	                  X5      $ )zReturns a matrix of zeros.

Parameters
==========

rows : rows of the matrix
cols : cols of the matrix (if None, cols=rows)

kwargs
======
cls : class of the returned matrix
r   r  r   )r>  r  r  r5   r  r  s        r   zerosMatrixBase.zeros  sj     <D!8tax @@Ft@RT T

5#&D\6$<d  ,,r   c                  ^ ^^ T R                  U5      n[        U[        5      (       d  [        SR	                  U5      5      eUR
                  (       d  [        SR	                  U5      5      eUR                  (       d  [        SR	                  U5      5      eUR                  5       mTS:  d  [        SR	                  U5      5      eUR                  5       mUU U4S jnT R                  TTU5      $ )ar  Returns a companion matrix of a polynomial.

Examples
========

>>> from sympy import Matrix, Poly, Symbol, symbols
>>> x = Symbol('x')
>>> c0, c1, c2, c3, c4 = symbols('c0:5')
>>> p = Poly(c0 + c1*x + c2*x**2 + c3*x**3 + c4*x**4 + x**5, x)
>>> Matrix.companion(p)
Matrix([
[0, 0, 0, 0, -c0],
[1, 0, 0, 0, -c1],
[0, 1, 0, 0, -c2],
[0, 0, 1, 0, -c3],
[0, 0, 0, 1, -c4]])
z{} must be a Poly instance.z{} must be a monic polynomial.z#{} must be a univariate polynomial.r/   z${} must have degree not less than 1.c                h   > UTS-
  :X  a	  TSU -
     * $ XS-   :X  a  TR                   $ TR                  $ )Nr/   r  )r   r   coeffsr:  r  s     r   r   #MatrixBase.companion.<locals>.entry  s9    D1H}rAv&!eww88Or   )
r   r%  r2   r>  r  is_monicis_univariatedegree
all_coeffsr   )r:  polyr   r  r  s   `  @@r   	companionMatrixBase.companion  s    & ||D!$%%:AA$GHH}}=DDTJKK!!5<<TBD D {{}qy6==dCE E "	 xxdE**r   c                ^    UR                  SU 5      n[        U5      nUR                  U5      $ )a  Returns two square Wilkinson Matrix of size 2*n + 1
$W_{2n + 1}^-, W_{2n + 1}^+ =$ Wilkinson(n)

Examples
========

>>> from sympy import Matrix
>>> wminus, wplus = Matrix.wilkinson(3)
>>> wminus
Matrix([
[-3,  1,  0, 0, 0, 0, 0],
[ 1, -2,  1, 0, 0, 0, 0],
[ 0,  1, -1, 1, 0, 0, 0],
[ 0,  0,  1, 0, 1, 0, 0],
[ 0,  0,  0, 1, 1, 1, 0],
[ 0,  0,  0, 0, 1, 2, 1],
[ 0,  0,  0, 0, 0, 1, 3]])
>>> wplus
Matrix([
[3, 1, 0, 0, 0, 0, 0],
[1, 2, 1, 0, 0, 0, 0],
[0, 1, 1, 1, 0, 0, 0],
[0, 0, 1, 0, 1, 0, 0],
[0, 0, 0, 1, 1, 1, 0],
[0, 0, 0, 0, 1, 2, 1],
[0, 0, 0, 0, 0, 1, 3]])

References
==========

.. [1] https://blogs.mathworks.com/cleve/2013/04/15/wilkinsons-matrices-2/
.. [2] J. H. Wilkinson, The Algebraic Eigenvalue Problem, Claredon Press, Oxford, 1965, 662 pp.

r   )r  r5   r  )r:  r  r   r  s       r   	wilkinsonMatrixBase.wilkinson  s/    H 

5#&1I$$Q''r   c                    S U  5       $ )Nc              3  N   #    U  H  o[         R                  Ld  M  Uv   M     g 7fr   )r#   Zeror&  s     r   r   /MatrixBase._eval_iter_values.<locals>.<genexpr>  s     34aAFF?4s   %	%r   r   s    r   _eval_iter_valuesMatrixBase._eval_iter_values  s    3433r   c                4    [        U R                  5       5      $ r   )r   iter_valuesr   s    r   _eval_valuesMatrixBase._eval_values  s    D$$&''r   c              #     #    [        U R                  5       H7  n[        U R                  5       H  nXU4   (       d  M  X4XU4   4v   M     M9     g 7fr   r   r   r   r   r   r   s      r   _eval_iter_itemsMatrixBase._eval_iter_items  sI     tyy!A499%1::&$!t*,, & "s   :A Ac                F   U R                  5       n[        U5      U R                  U R                  -  :  a1  [	        [
        R                  U5      (       a  [
        R                  1nO
[        5       nUR                  " U Vs/ s H  oDR                  " U6 PM     sn6 $ s  snf r   )
valuesr   r   r   r%  r#   r  setunionatoms)r   typesr  sr  s        r   _eval_atomsMatrixBase._eval_atoms  so    v;TYY..:affe3L3LAAww&9&Q%&9::9s   Bc                l    [        5       R                  " S [        U R                  5       5       5       6 $ )Nc              3  8   #    U  H  oR                   v   M     g 7fr   )free_symbolsr&  s     r   r   0MatrixBase._eval_free_symbols.<locals>.<genexpr>(  s     H5G^^5G   )r  r  r  r   s    r   _eval_free_symbolsMatrixBase._eval_free_symbols'  s$    u{{HS5GHIIr   c                J   ^ [        U4S jU R                  5        5       5      $ )Nc              3  @   >#    U  H  oR                   " T6 v   M     g 7fr   )has)r   apatternss     r   r   'MatrixBase._eval_has.<locals>.<genexpr>+  s     @-?55(#-?   )r   r  r   r  s    `r   	_eval_hasMatrixBase._eval_has*  s    @T-=-=-?@@@r   c                ,    U R                  [        5      $ r   )r  r   r   s    r   _eval_is_symbolicMatrixBase._eval_is_symbolic-  s    xxr   c                \   ^ ^^ U U4S jm[        U4S jT R                  5        5       5      $ )Nc                Z   > T" TX4   TX4   R                  5       -
  5      R                  $ r   )adjointis_zeror   r   r   simpfuncs     r   <lambda>6MatrixBase._eval_is_matrix_hermitian.<locals>.<lambda>4  s*    HT!$Z$qt*2D2D2F%FGOOr   c              3  >   >#    U  H  u  u  pnT" X5      v   M     g 7fr   r   )r   r   r   r  herms       r   r   7MatrixBase._eval_is_matrix_hermitian.<locals>.<genexpr>5       G5F	a5F   r8   
iter_items)r   r  r  s   ``@r   _eval_is_matrix_hermitian$MatrixBase._eval_is_matrix_hermitian3  s     OGT__5FGGGr   c                B    [        S U R                  5        5       5      $ )Nc              3  8   #    U  H  oR                   v   M     g 7fr   r  )r   r  s     r   r   2MatrixBase._eval_is_zero_matrix.<locals>.<genexpr>8  s     ?,>q,>r  )r8   r  r   s    r   _eval_is_zero_matrixMatrixBase._eval_is_zero_matrix7  s    ?D,<,<,>???r   c                   ^^^ U R                   mU R                  mUU4S jm[        U4S jU R                  5        5       5      $ )Nc                   > X:X  a  UTL $ UTL $ r   r   )r   r   r  rx  r   s      r   r  .MatrixBase._eval_is_Identity.<locals>.<lambda>=  s    AFS AT	 Ar   c              3  @   >#    U  H  u  u  pnT" XU5      v   M     g 7fr   r   )r   r   r   r  idents       r   r   /MatrixBase._eval_is_Identity.<locals>.<genexpr>>  s!     E3Difqa5q>>3Dr  )rx  r   r,  r  )r   r  rx  r   s    @@@r   _eval_is_IdentityMatrixBase._eval_is_Identity:  s2    hhyyAE4??3DEEEr   c                B    [        S U R                  5        5       5      $ )Nc              3  R   #    U  H  u  u  po1U:w  d  M  UR                   v   M     g 7fr   r  r   r   r   r  s       r   r   /MatrixBase._eval_is_diagonal.<locals>.<genexpr>A  s"     P4Eyvqa4E   ''r  r   s    r   _eval_is_diagonalMatrixBase._eval_is_diagonal@  s    PDOO4EPPPr   c                B    [        S U R                  5        5       5      $ )Nc              3  R   #    U  H  u  u  po1U:  d  M  UR                   v   M     g 7fr   r  r#  s       r   r   ,MatrixBase._eval_is_lower.<locals>.<genexpr>D  "     I.?!q59199.?r%  r,  r  r   s    r   _eval_is_lowerMatrixBase._eval_is_lowerC      Idoo.?IIIr   c                B    [        S U R                  5        5       5      $ )Nc              3  R   #    U  H  u  u  po1U:  d  M  UR                   v   M     g 7fr   r  r#  s       r   r   ,MatrixBase._eval_is_upper.<locals>.<genexpr>G  r+  r%  r,  r   s    r   _eval_is_upperMatrixBase._eval_is_upperF  r/  r   c                B    [        S U R                  5        5       5      $ )Nc              3  X   #    U  H   u  u  po1S -   U:  d  M  UR                   v   M"     g7fr/   Nr  r#  s       r   r   7MatrixBase._eval_is_lower_hessenberg.<locals>.<genexpr>J  s&     M.?!q5199199.?   **r,  r   s    r   _eval_is_lower_hessenberg$MatrixBase._eval_is_lower_hessenbergI      Mdoo.?MMMr   c                B    [        S U R                  5        5       5      $ )Nc              3  X   #    U  H   u  u  po1US -   :  d  M  UR                   v   M"     g7fr7  r  r#  s       r   r   7MatrixBase._eval_is_upper_hessenberg.<locals>.<genexpr>M  s&     M.?!q1u99199.?r9  r,  r   s    r   _eval_is_upper_hessenberg$MatrixBase._eval_is_upper_hessenbergL  r<  r   c                \   ^ ^^ U U4S jm[        U4S jT R                  5        5       5      $ )Nc                >   > T" TX4   TX4   -
  5      R                   $ r   r  r  s     r   r  /MatrixBase._eval_is_symmetric.<locals>.<lambda>P  s!    8DJad$;<DDr   c              3  >   >#    U  H  u  u  pnT" X5      v   M     g 7fr   r   )r   r   r   r  syms       r   r   0MatrixBase._eval_is_symmetric.<locals>.<genexpr>Q  s     F4EyvqQ4Er  r  )r   r  rF  s   ``@r   _eval_is_symmetricMatrixBase._eval_is_symmetricO  s     DFDOO4EFFFr   c                \   ^ ^^ U U4S jm[        U4S jT R                  5        5       5      $ )Nc                >   > T" TX4   TX4   -   5      R                   $ r   r  r  s     r   r  4MatrixBase._eval_is_anti_symmetric.<locals>.<lambda>T  s!    HT!$Z$qt*%<=EEr   c              3  >   >#    U  H  u  u  pnT" X5      v   M     g 7fr   r   )r   r   r   r  antis       r   r   5MatrixBase._eval_is_anti_symmetric.<locals>.<genexpr>U  r  r  r  )r   r  rN  s   ``@r   _eval_is_anti_symmetric"MatrixBase._eval_is_anti_symmetricS  s     EGT__5FGGGr   c                f   ^  U 4S j[        T R                  5       5       n[        S U 5       5      $ )Nc              3  0   >#    U  H  nTX4   v   M     g 7fr   r   r   r   r   s     r   r   5MatrixBase._has_positive_diagonals.<locals>.<genexpr>X       A0@1DJ0@   c              3  8   #    U  H  oR                   v   M     g 7fr   )is_positiver   xs     r   r   rU  Y  s     A0@10@r  r   r   r8   r   diagonal_entriess   ` r   _has_positive_diagonals"MatrixBase._has_positive_diagonalsW  s)    Adii0@AA0@AAAr   c                f   ^  U 4S j[        T R                  5       5       n[        S U 5       5      $ )Nc              3  0   >#    U  H  nTX4   v   M     g 7fr   r   rT  s     r   r   8MatrixBase._has_nonnegative_diagonals.<locals>.<genexpr>\  rV  rW  c              3  8   #    U  H  oR                   v   M     g 7fr   )is_nonnegativerZ  s     r   r   rc  ]  s     D3Ca))3Cr  r\  r]  s   ` r   _has_nonnegative_diagonals%MatrixBase._has_nonnegative_diagonals[  s)    Adii0@AD3CDDDr   c                `    [        S U 5       5      nU(       d  [        4nU R                  " U6 $ )zReturns the atoms that form the current object.

Examples
========

>>> from sympy.abc import x, y
>>> from sympy import Matrix
>>> Matrix([[x]])
Matrix([[x]])
>>> _.atoms()
{x}
>>> Matrix([[x, y], [y, x]])
Matrix([
[x, y],
[y, x]])
>>> _.atoms()
{x, y}
c              3  f   #    U  H'  n[        U[        5      (       a  UO
[        U5      v   M)     g 7fr   )r%  r  )r   ts     r   r   #MatrixBase.atoms.<locals>.<genexpr>s  s%     KU:a..aDG;Us   /1)tupler   r  )r   r  s     r   r  MatrixBase.atoms_  s/    ( KUKKGE''r   c                "    U R                  5       $ )zReturns the free symbols within the matrix.

Examples
========

>>> from sympy.abc import x
>>> from sympy import Matrix
>>> Matrix([[x], [1]]).free_symbols
{x}
)r  r   s    r   r  MatrixBase.free_symbolsx  s     &&((r   c                     U R                   " U6 $ )ac  Test whether any subexpression matches any of the patterns.

Examples
========

>>> from sympy import Matrix, SparseMatrix, Float
>>> from sympy.abc import x, y
>>> A = Matrix(((1, x), (0.2, 3)))
>>> B = SparseMatrix(((1, x), (0.2, 3)))
>>> A.has(x)
True
>>> A.has(y)
False
>>> A.has(Float)
True
>>> B.has(x)
True
>>> B.has(y)
False
>>> B.has(Float)
True
)r  r  s     r   r  MatrixBase.has  s    . ~~x((r   c                    Un[        U5      (       d  U(       a  [        OS nU R                  (       d  gU R                  U5      $ )a  Check if matrix M is an antisymmetric matrix,
that is, M is a square matrix with all M[i, j] == -M[j, i].

When ``simplify=True`` (default), the sum M[i, j] + M[j, i] is
simplified before testing to see if it is zero. By default,
the SymPy simplify function is used. To use a custom function
set simplify to a function that accepts a single argument which
returns a simplified expression. To skip simplification, set
simplify to False but note that although this will be faster,
it may induce false negatives.

Examples
========

>>> from sympy import Matrix, symbols
>>> m = Matrix(2, 2, [0, 1, -1, 0])
>>> m
Matrix([
[ 0, 1],
[-1, 0]])
>>> m.is_anti_symmetric()
True
>>> x, y = symbols('x y')
>>> m = Matrix(2, 3, [0, 0, x, -y, 0, 0])
>>> m
Matrix([
[ 0, 0, x],
[-y, 0, 0]])
>>> m.is_anti_symmetric()
False

>>> from sympy.abc import x, y
>>> m = Matrix(3, 3, [0, x**2 + 2*x + 1, y,
...                   -(x + 1)**2, 0, x*y,
...                   -y, -x*y, 0])

Simplification of matrix elements is done by default so even
though two elements which should be equal and opposite would not
pass an equality test, the matrix is still reported as
anti-symmetric:

>>> m[0, 1] == -m[1, 0]
False
>>> m.is_anti_symmetric()
True

If ``simplify=False`` is used for the case when a Matrix is already
simplified, this will speed things up. Here, we see that without
simplification the matrix does not appear anti-symmetric:

>>> print(m.is_anti_symmetric(simplify=False))
None

But if the matrix were already expanded, then it would appear
anti-symmetric and simplification in the is_anti_symmetric routine
is not needed:

>>> m = m.expand()
>>> m.is_anti_symmetric(simplify=False)
True
c                    U $ r   r   r[  s    r   r  .MatrixBase.is_anti_symmetric.<locals>.<lambda>      ar   F)r   _utilities_simplifyrf  rP  r   simplifyr  s      r   is_anti_symmetricMatrixBase.is_anti_symmetric  s:    ~ (##.6*KH~~++H55r   c                "    U R                  5       $ )a$  Check if matrix is diagonal,
that is matrix in which the entries outside the main diagonal are all zero.

Examples
========

>>> from sympy import Matrix, diag
>>> m = Matrix(2, 2, [1, 0, 0, 2])
>>> m
Matrix([
[1, 0],
[0, 2]])
>>> m.is_diagonal()
True

>>> m = Matrix(2, 2, [1, 1, 0, 2])
>>> m
Matrix([
[1, 1],
[0, 2]])
>>> m.is_diagonal()
False

>>> m = diag(1, 2, 3)
>>> m
Matrix([
[1, 0, 0],
[0, 2, 0],
[0, 0, 3]])
>>> m.is_diagonal()
True

See Also
========

is_lower
is_upper
sympy.matrices.matrixbase.MatrixBase.is_diagonalizable
diagonalize
)r&  r   s    r   is_diagonalMatrixBase.is_diagonal  s    R %%''r   c                   ^ ^^ T R                   (       d  gT R                  u  nmUU 4S jm[        U4S j[        U5       5       5      $ )a  Tests if the matrix is row weakly diagonally dominant.

Explanation
===========

A $n, n$ matrix $A$ is row weakly diagonally dominant if

.. math::
    \left|A_{i, i}\right| \ge \sum_{j = 0, j \neq i}^{n-1}
    \left|A_{i, j}\right| \quad {\text{for all }}
    i \in \{ 0, ..., n-1 \}

Examples
========

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

>>> A = Matrix([[-2, 2, 1], [1, 3, 2], [1, -2, 0]])
>>> A.is_weakly_diagonally_dominant
False

>>> A = Matrix([[-4, 2, 1], [1, 6, 2], [1, -2, 5]])
>>> A.is_weakly_diagonally_dominant
True

Notes
=====

If you want to test whether a matrix is column diagonally
dominant, you can apply the test after transposing the matrix.
Fc                   > TR                   n[        T5       H  nX:w  d  M
  U[        TX4   5      -  nM     [        TX 4   5      U-
  R                  $ r   )r   r   r   re  r   	summationr   r   r   s      r   test_row:MatrixBase.is_weakly_diagonally_dominant.<locals>.test_row:  sP    		I4[6T!$Z0I ! QT
Oi/???r   c              3  4   >#    U  H  nT" U5      v   M     g 7fr   r   r   r   r  s     r   r   ;MatrixBase.is_weakly_diagonally_dominant.<locals>.<genexpr>A       :k!k   rf  r   r8   r   r   r   r   r  s   ` @@r   is_weakly_diagonally_dominant(MatrixBase.is_weakly_diagonally_dominant  s:    H ~~ZZ
d	@ :eDk:::r   c                   ^ ^^ T R                   (       d  gT R                  u  nmUU 4S jm[        U4S j[        U5       5       5      $ )a  Tests if the matrix is row strongly diagonally dominant.

Explanation
===========

A $n, n$ matrix $A$ is row strongly diagonally dominant if

.. math::
    \left|A_{i, i}\right| > \sum_{j = 0, j \neq i}^{n-1}
    \left|A_{i, j}\right| \quad {\text{for all }}
    i \in \{ 0, ..., n-1 \}

Examples
========

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

>>> A = Matrix([[-2, 2, 1], [1, 3, 2], [1, -2, 0]])
>>> A.is_strongly_diagonally_dominant
False

>>> A = Matrix([[-4, 2, 1], [1, 6, 2], [1, -2, 5]])
>>> A.is_strongly_diagonally_dominant
True

Notes
=====

If you want to test whether a matrix is column diagonally
dominant, you can apply the test after transposing the matrix.
Fc                   > TR                   n[        T5       H  nX:w  d  M
  U[        TX4   5      -  nM     [        TX 4   5      U-
  R                  $ r   )r   r   r   rY  r  s      r   r  <MatrixBase.is_strongly_diagonally_dominant.<locals>.test_rowl  sP    		I4[6T!$Z0I ! QT
Oi/<<<r   c              3  4   >#    U  H  nT" U5      v   M     g 7fr   r   r  s     r   r   =MatrixBase.is_strongly_diagonally_dominant.<locals>.<genexpr>s  r  r  r  r  s   ` @@r   is_strongly_diagonally_dominant*MatrixBase.is_strongly_diagonally_dominantC  s9    H ~~ZZ
d	= :eDk:::r   c                P    U R                   (       d  gU R                  [        5      $ )a  Checks if the matrix is Hermitian.

In a Hermitian matrix element i,j is the complex conjugate of
element j,i.

Examples
========

>>> from sympy import Matrix
>>> from sympy import I
>>> from sympy.abc import x
>>> a = Matrix([[1, I], [-I, 1]])
>>> a
Matrix([
[ 1, I],
[-I, 1]])
>>> a.is_hermitian
True
>>> a[0, 0] = 2*I
>>> a.is_hermitian
False
>>> a[0, 0] = x
>>> a.is_hermitian
>>> a[0, 1] = a[1, 0]*I
>>> a.is_hermitian
False
F)rf  r  rw  r   s    r   is_hermitianMatrixBase.is_hermitianu  s     : ~~--.ABBr   c                F    U R                   (       d  gU R                  5       $ )NF)rf  r  r   s    r   is_IdentityMatrixBase.is_Identity  s    ~~%%''r   c                "    U R                  5       $ )a  Checks if the matrix is in the lower-Hessenberg form.

The lower hessenberg matrix has zero entries
above the first superdiagonal.

Examples
========

>>> from sympy import Matrix
>>> a = Matrix([[1, 2, 0, 0], [5, 2, 3, 0], [3, 4, 3, 7], [5, 6, 1, 1]])
>>> a
Matrix([
[1, 2, 0, 0],
[5, 2, 3, 0],
[3, 4, 3, 7],
[5, 6, 1, 1]])
>>> a.is_lower_hessenberg
True

See Also
========

is_upper_hessenberg
is_lower
)r:  r   s    r   is_lower_hessenbergMatrixBase.is_lower_hessenberg      6 --//r   c                "    U R                  5       $ )a\  Check if matrix is a lower triangular matrix. True can be returned
even if the matrix is not square.

Examples
========

>>> from sympy import Matrix
>>> m = Matrix(2, 2, [1, 0, 0, 1])
>>> m
Matrix([
[1, 0],
[0, 1]])
>>> m.is_lower
True

>>> m = Matrix(4, 3, [0, 0, 0, 2, 0, 0, 1, 4, 0, 6, 6, 5])
>>> m
Matrix([
[0, 0, 0],
[2, 0, 0],
[1, 4, 0],
[6, 6, 5]])
>>> m.is_lower
True

>>> from sympy.abc import x, y
>>> m = Matrix(2, 2, [x**2 + y, y**2 + x, 0, x + y])
>>> m
Matrix([
[x**2 + y, x + y**2],
[       0,    x + y]])
>>> m.is_lower
False

See Also
========

is_upper
is_diagonal
is_lower_hessenberg
)r-  r   s    r   is_lowerMatrixBase.is_lower  s    V ""$$r   c                4    U R                   U R                  :H  $ )a  Checks if a matrix is square.

A matrix is square if the number of rows equals the number of columns.
The empty matrix is square by definition, since the number of rows and
the number of columns are both zero.

Examples
========

>>> from sympy import Matrix
>>> a = Matrix([[1, 2, 3], [4, 5, 6]])
>>> b = Matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
>>> c = Matrix([])
>>> a.is_square
False
>>> b.is_square
True
>>> c.is_square
True
r   r   s    r   rf  MatrixBase.is_square  s    , yyDII%%r   c                "    U R                  5       $ )zChecks if any elements contain Symbols.

Examples
========

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

)r   r   s    r   is_symbolicMatrixBase.is_symbolic  s     %%''r   c                    Un[        U5      (       d  U(       a  [        OS nU R                  (       d  gU R                  U5      $ )a(  Check if matrix is symmetric matrix,
that is square matrix and is equal to its transpose.

By default, simplifications occur before testing symmetry.
They can be skipped using 'simplify=False'; while speeding things a bit,
this may however induce false negatives.

Examples
========

>>> from sympy import Matrix
>>> m = Matrix(2, 2, [0, 1, 1, 2])
>>> m
Matrix([
[0, 1],
[1, 2]])
>>> m.is_symmetric()
True

>>> m = Matrix(2, 2, [0, 1, 2, 0])
>>> m
Matrix([
[0, 1],
[2, 0]])
>>> m.is_symmetric()
False

>>> m = Matrix(2, 3, [0, 0, 0, 0, 0, 0])
>>> m
Matrix([
[0, 0, 0],
[0, 0, 0]])
>>> m.is_symmetric()
False

>>> from sympy.abc import x, y
>>> m = Matrix(3, 3, [1, x**2 + 2*x + 1, y, (x + 1)**2, 2, 0, y, 0, 3])
>>> m
Matrix([
[         1, x**2 + 2*x + 1, y],
[(x + 1)**2,              2, 0],
[         y,              0, 3]])
>>> m.is_symmetric()
True

If the matrix is already simplified, you may speed-up is_symmetric()
test by using 'simplify=False'.

>>> bool(m.is_symmetric(simplify=False))
False
>>> m1 = m.expand()
>>> m1.is_symmetric(simplify=False)
True
c                    U $ r   r   rt  s    r   r  )MatrixBase.is_symmetric.<locals>.<lambda>G  rv  r   F)r   rw  rf  rH  rx  s      r   rg  MatrixBase.is_symmetric  s:    n (##.6*KH~~&&x00r   c                "    U R                  5       $ )a  Checks if the matrix is the upper-Hessenberg form.

The upper hessenberg matrix has zero entries
below the first subdiagonal.

Examples
========

>>> from sympy import Matrix
>>> a = Matrix([[1, 4, 2, 3], [3, 4, 1, 7], [0, 2, 3, 4], [0, 0, 1, 3]])
>>> a
Matrix([
[1, 4, 2, 3],
[3, 4, 1, 7],
[0, 2, 3, 4],
[0, 0, 1, 3]])
>>> a.is_upper_hessenberg
True

See Also
========

is_lower_hessenberg
is_upper
)r@  r   s    r   is_upper_hessenbergMatrixBase.is_upper_hessenbergN  r  r   c                "    U R                  5       $ )a  Check if matrix is an upper triangular matrix. True can be returned
even if the matrix is not square.

Examples
========

>>> from sympy import Matrix
>>> m = Matrix(2, 2, [1, 0, 0, 1])
>>> m
Matrix([
[1, 0],
[0, 1]])
>>> m.is_upper
True

>>> m = Matrix(4, 3, [5, 1, 9, 0, 4, 6, 0, 0, 5, 0, 0, 0])
>>> m
Matrix([
[5, 1, 9],
[0, 4, 6],
[0, 0, 5],
[0, 0, 0]])
>>> m.is_upper
True

>>> m = Matrix(2, 3, [4, 2, 5, 6, 1, 1])
>>> m
Matrix([
[4, 2, 5],
[6, 1, 1]])
>>> m.is_upper
False

See Also
========

is_lower
is_diagonal
is_upper_hessenberg
)r3  r   s    r   is_upperMatrixBase.is_upperk  s    T ""$$r   c                "    U R                  5       $ )at  Checks if a matrix is a zero matrix.

A matrix is zero if every element is zero.  A matrix need not be square
to be considered zero.  The empty matrix is zero by the principle of
vacuous truth.  For a matrix that may or may not be zero (e.g.
contains a symbol), this will be None

Examples
========

>>> from sympy import Matrix, zeros
>>> from sympy.abc import x
>>> a = Matrix([[0, 0], [0, 0]])
>>> b = zeros(3, 4)
>>> c = Matrix([[0, 1], [0, 0]])
>>> d = Matrix([])
>>> e = Matrix([[x, 0], [0, 0]])
>>> a.is_zero_matrix
True
>>> b.is_zero_matrix
True
>>> c.is_zero_matrix
False
>>> d.is_zero_matrix
True
>>> e.is_zero_matrix
)r  r   s    r   is_zero_matrixMatrixBase.is_zero_matrix  s    : ((**r   c                "    U R                  5       $ )zReturn non-zero values of self.

Examples
========

>>> from sympy import Matrix
>>> m = Matrix([[0, 1], [2, 3]])
>>> m.values()
[1, 2, 3]

See Also
========

iter_values
tolist
flat
)r  r   s    r   r  MatrixBase.values  s    $   ""r   c                "    U R                  5       $ )z
Iterate over non-zero values of self.

Examples
========

>>> from sympy import Matrix
>>> m = Matrix([[0, 1], [2, 3]])
>>> list(m.iter_values())
[1, 2, 3]

See Also
========

values
)r  r   s    r   r  MatrixBase.iter_values  s    " %%''r   c                "    U R                  5       $ )zIterate over indices and values of nonzero items.

Examples
========

>>> from sympy import Matrix
>>> m = Matrix([[0, 1], [2, 3]])
>>> list(m.iter_items())
[((0, 1), 1), ((1, 0), 2), ((1, 1), 3)]

See Also
========

iter_values
todok
)r  r   s    r   r  MatrixBase.iter_items  s    " $$&&r   c                B    U R                  5       R                  S 5      $ )Nc                "    U R                  5       $ r   r  rt  s    r   r  *MatrixBase._eval_adjoint.<locals>.<lambda>  s
    AIIKr   )	transpose	applyfuncr   s    r   _eval_adjointMatrixBase._eval_adjoint  s    ~~))*?@@r   c                   U R                   nU R                  U R                   -  nU R                  5       nUR                  5        Vs0 s H  oUU" U5      _M     nn[	        U5      U:  a  U" [
        R                  5      =n[
        R                  LaW  U/U-  nUR                  5        H  u  u  pnXe   XU-  U
-   '   M     U R                  U R                  U R                   U5      nU$ UR                  5        VVs0 s H
  u  pXU   _M     nnnU R                  U R                  U R                   U5      nU$ s  snf s  snnf r   )
r   r   r?  r  r   r#   r  r   r   rV  )r   fr   r  r   r  valmapfzeror  r   r   outrU  fdoks                 r   _eval_applyfuncMatrixBase._eval_applyfunc  s   yyyy"jjl#&::<0<aQqT'<0s8d?!AFF)!3AFF Bwt|H YY[	'-y4!$ )))DIItyy(;C
 
 03yy{;{ebBq	M{D;--		499d;C
 1 <s   D;>E c                V    U R                  [        5      U R                  [        5      4$ r   )r  r   r   r   s    r   _eval_as_real_imagMatrixBase._eval_as_real_imag  s    r"DNN2$677r   c                &    U R                  S 5      $ )Nc                "    U R                  5       $ r   	conjugatert  s    r   r  ,MatrixBase._eval_conjugate.<locals>.<lambda>	  s
    r   r  r   s    r   _eval_conjugateMatrixBase._eval_conjugate  s    ~~566r   c                x   ^ ^ [        U5      mUU 4S jnT R                  T R                  T R                  U5      $ )Nc                   > TU TU   4   $ r   r   r   r   mappingr   s     r   r   ,MatrixBase._eval_permute_cols.<locals>.entry  s    71:&&r   r   r   r   r   r   permr   r  s   `  @r   _eval_permute_colsMatrixBase._eval_permute_cols  .    t*	' yyDIIu55r   c                x   ^ ^ [        U5      mUU 4S jnT R                  T R                  T R                  U5      $ )Nc                   > TTU    U4   $ r   r   r  s     r   r   ,MatrixBase._eval_permute_rows.<locals>.entry  s    
A&&r   r  r  s   `  @r   _eval_permute_rowsMatrixBase._eval_permute_rows  r  r   c                T   ^  [        U 4S j[        T R                  5       5       5      $ )Nc              3  0   >#    U  H  nTX4   v   M     g 7fr   r   rT  s     r   r   )MatrixBase._eval_trace.<locals>.<genexpr>  s     8'7!4:'7rW  )sumr   r   r   s   `r   _eval_traceMatrixBase._eval_trace  s    8uTYY'7888r   c                Z   ^  T R                  T R                  T R                  U 4S j5      $ )Nc                   > TX4   $ r   r   r   r   r   s     r   r  ,MatrixBase._eval_transpose.<locals>.<lambda>!  s    DJr   )r   r   r   r   s   `r   _eval_transposeMatrixBase._eval_transpose   s    yyDII/FGGr   c                "    U R                  5       $ )z-Conjugate transpose or Hermitian conjugation.)r  r   s    r   r  MatrixBase.adjoint#  s    !!##r   c                Z    [        U5      (       d  [        S5      eU R                  U5      $ )zApply a function to each element of the matrix.

Examples
========

>>> from sympy import Matrix
>>> m = Matrix(2, 2, lambda i, j: i*2+j)
>>> m
Matrix([
[0, 1],
[2, 3]])
>>> m.applyfunc(lambda i: 2*i)
Matrix([
[0, 2],
[4, 6]])

z`f` must be callable.)callabler+  r  )r   r  s     r   r  MatrixBase.applyfunc'  s*    $ {{344##A&&r   c                "    U R                  5       $ )z@Returns a tuple containing the (real, imaginary) part of matrix.)r  )r   deephintss      r   as_real_imagMatrixBase.as_real_imag>  s     &&((r   c                "    U R                  5       $ )a  Return the by-element conjugation.

Examples
========

>>> from sympy import SparseMatrix, I
>>> a = SparseMatrix(((1, 2 + I), (3, 4), (I, -I)))
>>> a
Matrix([
[1, 2 + I],
[3,     4],
[I,    -I]])
>>> a.C
Matrix([
[ 1, 2 - I],
[ 3,     4],
[-I,     I]])

See Also
========

transpose: Matrix transposition
H: Hermite conjugation
sympy.matrices.matrixbase.MatrixBase.D: Dirac conjugation
)r  r   s    r   r  MatrixBase.conjugateC  s    4 ##%%r   c                .   ^ U R                  U4S j5      $ )Nc                (   > U R                   " S0 TD6$ Nr   )doit)r[  r  s    r   r  !MatrixBase.doit.<locals>.<lambda>`  s    r   r  )r   r  s    `r   r   MatrixBase.doit_  s    ~~788r   c                >   ^^ X#XEXgS.mU R                  UU4S j5      $ )&Apply evalf() to each element of self.)subsmaxnchopr  quadverbosec                *   > U R                   " T40 TD6$ r   evalf)r   r  optionss    r   r  "MatrixBase.evalf.<locals>.<lambda>f  s    (=W(=r   r  )	r   r  r  r  r  r  r  r	  r  s	    `      @r   r  MatrixBase.evalfb  s"    D0~~=>>r   c	                N   ^^^^^^^^^	 U R                  UUU	UUUUUU4	S j5      $ )zApply core.function.expand to each entry of the matrix.

Examples
========

>>> from sympy.abc import x
>>> from sympy import Matrix
>>> Matrix(1, 1, [x*(x+1)])
Matrix([[x*(x + 1)]])
>>> _.expand()
Matrix([[x**2 + x]])

c           
     8   >	 U R                   " TTTT	TTTT40 TD6$ r   )expand)
r[  basicr  r  r'   modulusmulmultinomial
power_base	power_exps
    r   r  #MatrixBase.expand.<locals>.<lambda>w  s'    ':y#sK))r   r  )
r   r  r  r  r  r  r'   r  r  r  s
    `````````r   r  MatrixBase.expandh  s!     ~~    	r   c                "    U R                  5       $ )a6  Return Hermite conjugate.

Examples
========

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

See Also
========

conjugate: By-element conjugation
sympy.matrices.matrixbase.MatrixBase.D: Dirac conjugation
r  r   s    r   HMatrixBase.H{  s    0 ||~r   c                  ^ SSK Jn  US:X  a  SnUS:X  a  SnUS:X  a  SnUS	;  a  [        S
R                  U5      5      eUS;  a  [        SR                  U5      5      e[	        X[
        45      (       d  [        SR                  U5      5      eUS:X  a  U R                  OU R                  m[        U4S j[        [        U5      5       5       5      (       d  [        S5      eU(       aM  [	        X5      (       d=  [	        US   [
        5      (       a%  US:X  a  [        [        U5      5      nU" UTS-   S9nO
U" UTS-   S9nUS:X  a  U R                  U5      $ US:X  a  U R                  U5      $ g)a	  Permute the rows or columns of a matrix by the given list of
swaps.

Parameters
==========

perm : Permutation, list, or list of lists
    A representation for the permutation.

    If it is ``Permutation``, it is used directly with some
    resizing with respect to the matrix size.

    If it is specified as list of lists,
    (e.g., ``[[0, 1], [0, 2]]``), then the permutation is formed
    from applying the product of cycles. The direction how the
    cyclic product is applied is described in below.

    If it is specified as a list, the list should represent
    an array form of a permutation. (e.g., ``[1, 2, 0]``) which
    would would form the swapping function
    `0 \mapsto 1, 1 \mapsto 2, 2\mapsto 0`.

orientation : 'rows', 'cols'
    A flag to control whether to permute the rows or the columns

direction : 'forward', 'backward'
    A flag to control whether to apply the permutations from
    the start of the list first, or from the back of the list
    first.

    For example, if the permutation specification is
    ``[[0, 1], [0, 2]]``,

    If the flag is set to ``'forward'``, the cycle would be
    formed as `0 \mapsto 2, 2 \mapsto 1, 1 \mapsto 0`.

    If the flag is set to ``'backward'``, the cycle would be
    formed as `0 \mapsto 1, 1 \mapsto 2, 2 \mapsto 0`.

    If the argument ``perm`` is not in a form of list of lists,
    this flag takes no effect.

Examples
========

>>> from sympy import eye
>>> M = eye(3)
>>> M.permute([[0, 1], [0, 2]], orientation='rows', direction='forward')
Matrix([
[0, 0, 1],
[1, 0, 0],
[0, 1, 0]])

>>> from sympy import eye
>>> M = eye(3)
>>> M.permute([[0, 1], [0, 2]], orientation='rows', direction='backward')
Matrix([
[0, 1, 0],
[0, 0, 1],
[1, 0, 0]])

Notes
=====

If a bijective function
`\sigma : \mathbb{N}_0 \rightarrow \mathbb{N}_0` denotes the
permutation.

If the matrix `A` is the matrix to permute, represented as
a horizontal or a vertical stack of vectors:

.. math::
    A =
    \begin{bmatrix}
    a_0 \\ a_1 \\ \vdots \\ a_{n-1}
    \end{bmatrix} =
    \begin{bmatrix}
    \alpha_0 & \alpha_1 & \cdots & \alpha_{n-1}
    \end{bmatrix}

If the matrix `B` is the result, the permutation of matrix rows
is defined as:

.. math::
    B := \begin{bmatrix}
    a_{\sigma(0)} \\ a_{\sigma(1)} \\ \vdots \\ a_{\sigma(n-1)}
    \end{bmatrix}

And the permutation of matrix columns is defined as:

.. math::
    B := \begin{bmatrix}
    \alpha_{\sigma(0)} & \alpha_{\sigma(1)} &
    \cdots & \alpha_{\sigma(n-1)}
    \end{bmatrix}
r   )Permutationforwardsforward	backwardsbackwardcolumnsr   )r!  r#  z?direction='{}' is an invalid kwarg. Try 'forward' or 'backward'r   z:orientation='{}' is an invalid kwarg. Try 'rows' or 'cols'zB{} must be a list, a list of lists, or a SymPy permutation object.r   c              3  N   >#    U  H  nS Us=:*  =(       a    T:*  Os  v   M     g7fr   Nr   )r   rj  	max_indexs     r   r   %MatrixBase.permute.<locals>.<genexpr>	  s#     D0C11&&Y&&0Cs   "%z`swap` indices out of range.r/   )r  N)sympy.combinatoricsr  r+  r  r%  r   r>  r   r   r,  r3   r   r  reversedr  r  )r   r  orientation	directionr  r'  s        @r   permuteMatrixBase.permute  sv   B 	4 
"!I#"I)# K33 ::@&:KM M.. 3396+3FH H $h 788117? ?
 "-!6DIIDII	DT
0CDDD;<<
455tAw))I%HTN+t)A+6Dt)A+6D& **400& **400 !r   c                $    U R                  USUS9$ )zgAlias for
``self.permute(swaps, orientation='cols', direction=direction)``

See Also
========

permute
r   r+  r,  r-  r   swapsr,  s      r   permute_colsMatrixBase.permute_cols	       ||Ev|KKr   c                $    U R                  USUS9$ )zgAlias for
``self.permute(swaps, orientation='rows', direction=direction)``

See Also
========

permute
r   r0  r1  r2  s      r   permute_rowsMatrixBase.permute_rows)	  r6  r   c                .   ^ U R                  U4S j5      $ )aJ  Apply refine to each element of the matrix.

Examples
========

>>> from sympy import Symbol, Matrix, Abs, sqrt, Q
>>> x = Symbol('x')
>>> Matrix([[Abs(x)**2, sqrt(x**2)],[sqrt(x**2), Abs(x)**2]])
Matrix([
[ Abs(x)**2, sqrt(x**2)],
[sqrt(x**2),  Abs(x)**2]])
>>> _.refine(Q.real(x))
Matrix([
[  x**2, Abs(x)],
[Abs(x),   x**2]])

c                   > [        U T5      $ r   r   )r[  assumptionss    r   r  #MatrixBase.refine.<locals>.<lambda>F	  s    q+(>r   r  )r   r<  s    `r   r	   MatrixBase.refine4	  s    $ ~~>??r   c                   ^^^^	 X4US.m	U(       a   0 mUUUU	4S jnU R                  U5      nUT4$ U R                  UUU	4S j5      $ )a;  Replaces Function F in Matrix entries with Function G.

Examples
========

>>> from sympy import symbols, Function, Matrix
>>> F, G = symbols('F, G', cls=Function)
>>> M = Matrix(2, 2, lambda i, j: F(i+j)) ; M
Matrix([
[F(0), F(1)],
[F(1), F(2)]])
>>> N = M.replace(F,G)
>>> N
Matrix([
[G(0), G(1)],
[G(1), G(2)]])
)mapsimultaneousexactc                V   > U R                   " TT40 TD6u  pTR                  U5        U $ r   )replaceupdate)eijdijFGdr   s     r   func MatrixBase.replace.<locals>.func_	  s*    ;;q!6v6
r   c                ,   > U R                   " TT40 TD6$ r   )rD  )r   rH  rI  r   s    r   r  $MatrixBase.replace.<locals>.<lambda>h	  s    AIIa,Ef,Er   r  )
r   rH  rI  r@  rA  rB  rK  r   rJ  r   s
    ``     @@r   rD  MatrixBase.replaceH	  sL    $ UKA 
 t$Aa4K >>"EFFr   c                    US-  nUS:X  a  U $ US:X  a  U SSS2SS24   R                   $ US:X  a  U SSS2SSS24   $ US:X  a  U SS2SSS24   R                   $ g)a  Rotates Matrix by 90 degrees

Parameters
==========

k : int
    Specifies how many times the matrix is rotated by 90 degrees
    (clockwise when positive, counter-clockwise when negative).

Examples
========

>>> from sympy import Matrix, symbols
>>> A = Matrix(2, 2, symbols('a:d'))
>>> A
Matrix([
[a, b],
[c, d]])

Rotating the matrix clockwise one time:

>>> A.rot90(1)
Matrix([
[c, a],
[d, b]])

Rotating the matrix anticlockwise two times:

>>> A.rot90(-2)
Matrix([
[d, c],
[b, a]])
   r   r/   Nr  r  r   )r  )r   r1  mods      r   rot90MatrixBase.rot90j	  s{    F c!8K!8"b>###!8"dd
##!8DbD>### r   c                .   ^ U R                  U4S j5      $ )a  Apply simplify to each element of the matrix.

Examples
========

>>> from sympy.abc import x, y
>>> from sympy import SparseMatrix, sin, cos
>>> SparseMatrix(1, 1, [x*sin(y)**2 + x*cos(y)**2])
Matrix([[x*sin(y)**2 + x*cos(y)**2]])
>>> _.simplify()
Matrix([[x]])
c                (   > U R                   " S0 TD6$ r  ry  r[  r   s    r   r  %MatrixBase.simplify.<locals>.<lambda>	      

(<V(<r   r  r   r   s    `r   ry  MatrixBase.simplify	  s     ~~<==r   c                   ^^ [        T5      S:X  aS  [        TS   [        [        45      (       d5  [	        TS   5      (       a"  [        TS   5      (       d  [        TS   5      4mU R                  UU4S j5      $ )a  Return a new matrix with subs applied to each entry.

Examples
========

>>> from sympy.abc import x, y
>>> from sympy import SparseMatrix, Matrix
>>> SparseMatrix(1, 1, [x])
Matrix([[x]])
>>> _.subs(x, y)
Matrix([[y]])
>>> Matrix(_).subs(y, x)
Matrix([[x]])
r/   r   c                (   > U R                   " T0 TD6$ r   )r  r[  r   r   s    r   r  !MatrixBase.subs.<locals>.<lambda>	  s    (?(?r   )r   r%  dictr  iterr4   r   r  r   r   r   s    ``r   r  MatrixBase.subs	  sc      t9>:d1gc{#C#CTRSW^ijnopjq^r^raM#D~~?@@r   c                j    U R                   U R                  :w  a
  [        5       eU R                  5       $ )z
Returns the trace of a square matrix i.e. the sum of the
diagonal elements.

Examples
========

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

)r   r   r@   r  r   s    r   traceMatrixBase.trace	  s,     99		!&((!!r   c                "    U R                  5       $ )a  
Returns the transpose of the matrix.

Examples
========

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

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

See Also
========

conjugate: By-element conjugation

)r  r   s    r   r  MatrixBase.transpose	  s    B ##%%r   c                "    U R                  5       $ )zMatrix transposition)r  r   s    r   r  MatrixBase.T	       ~~r   c                "    U R                  5       $ )zBy-element conjugationr  r   s    r   CMatrixBase.C	  rl  r   c                &    U R                   " U0 UD6$ )r  r  rc  s      r   r  MatrixBase.n	  s    zz4*6**r   c                .   ^ U R                  U4S j5      $ )a  Return a new matrix with xreplace applied to each entry.

Examples
========

>>> from sympy.abc import x, y
>>> from sympy import SparseMatrix, Matrix
>>> SparseMatrix(1, 1, [x])
Matrix([[x]])
>>> _.xreplace({x: y})
Matrix([[y]])
>>> Matrix(_).xreplace({y: x})
Matrix([[x]])
c                &   > U R                  T5      $ r   )xreplace)r[  rules    r   r  %MatrixBase.xreplace.<locals>.<lambda>
  s    

4(8r   r  )r   ru  s    `r   rt  MatrixBase.xreplace	  s     ~~899r   c                .   ^ U R                  U4S j5      $ )Nc                (   > U R                   " S0 TD6$ r  rW  rX  s    r   r  +MatrixBase._eval_simplify.<locals>.<lambda>
  rZ  r   r  r[  s    `r   _eval_simplifyMatrixBase._eval_simplify
  s     ~~<==r   c                >   ^^ SSK Jm  U R                  UU4S j5      $ )Nr   )trigsimpc                   > T" U 40 TD6$ r   r   )r[  optsr~  s    r   r  +MatrixBase._eval_trigsimp.<locals>.<lambda>
  s    (;d(;r   )sympy.simplify.trigsimpr~  r  )r   r  r~  s    `@r   _eval_trigsimpMatrixBase._eval_trigsimp
  s    4~~;<<r   c                b   ^ ^ UU 4S jnT R                  T R                  T R                  U5      $ )a  Return the elements on and above the kth diagonal of a matrix.
If k is not specified then simply returns upper-triangular portion
of a matrix

Examples
========

>>> from sympy import ones
>>> A = ones(4)
>>> A.upper_triangular()
Matrix([
[1, 1, 1, 1],
[0, 1, 1, 1],
[0, 0, 1, 1],
[0, 0, 0, 1]])

>>> A.upper_triangular(2)
Matrix([
[0, 0, 1, 1],
[0, 0, 0, 1],
[0, 0, 0, 0],
[0, 0, 0, 0]])

>>> A.upper_triangular(-1)
Matrix([
[1, 1, 1, 1],
[1, 1, 1, 1],
[0, 1, 1, 1],
[0, 0, 1, 1]])

c                :   > U T-   U::  a  TX4   $ TR                   $ r   r   r   r   r1  r   s     r   r   *MatrixBase.upper_triangular.<locals>.entry9
  "    !"Q!4:::r   r   r   r1  r   s   `` r   upper_triangularMatrixBase.upper_triangular
  &    B	; yyDIIu55r   c                b   ^ ^ UU 4S jnT R                  T R                  T R                  U5      $ )a  Return the elements on and below the kth diagonal of a matrix.
If k is not specified then simply returns lower-triangular portion
of a matrix

Examples
========

>>> from sympy import ones
>>> A = ones(4)
>>> A.lower_triangular()
Matrix([
[1, 0, 0, 0],
[1, 1, 0, 0],
[1, 1, 1, 0],
[1, 1, 1, 1]])

>>> A.lower_triangular(-2)
Matrix([
[0, 0, 0, 0],
[0, 0, 0, 0],
[1, 0, 0, 0],
[1, 1, 0, 0]])

>>> A.lower_triangular(1)
Matrix([
[1, 1, 0, 0],
[1, 1, 1, 0],
[1, 1, 1, 1],
[1, 1, 1, 1]])

c                :   > U T-   U:  a  TX4   $ TR                   $ r   r  r  s     r   r   *MatrixBase.lower_triangular.<locals>.entry_
  r  r   r   r  s   `` r   lower_triangularMatrixBase.lower_triangular>
  r  r   c                Z   ^  T R                  T R                  T R                  U 4S j5      $ )Nc                "   > [        TX4   5      $ r   )r   r  s     r   r  &MatrixBase._eval_Abs.<locals>.<lambda>e
  s    CQT
Or   r   r   s   `r   	_eval_AbsMatrixBase._eval_Absd
  s    yyDII/KLLr   c                ^   ^ ^ T R                  T R                  T R                  UU 4S j5      $ )Nc                   > TX4   TX4   -   $ r   r   r   r   r   r   s     r   r  &MatrixBase._eval_add.<locals>.<lambda>i
  s    d14j5;&>r   r   r   s   ``r   	_eval_addMatrixBase._eval_addg
  s%    yyDII>@ 	@r   c                b   ^ ^ UU 4S jnT R                  T R                  TR                  U5      $ )Nc                   > [        TR                  5       Vs/ s H  nTX4   TX!4   -  PM     nn [        U6 $ s  snf ! [        [        4 a    [        S U5      s $ f = f)Nc                
    X-   $ r   r   )r  bs     r   r  <MatrixBase._eval_matrix_mul.<locals>.entry.<locals>.<lambda>t
  s    15r   )r   r   r   r+  r
   r   )r   r   r1  rc  r   r   s       r   r   *MatrixBase._eval_matrix_mul.<locals>.entryl
  sn    16tyy1AB1AA49U13Z'1ACB7Cy  C |, 7 0#66	7s   ;A   A A r   r   r   r   s   `` r   _eval_matrix_mulMatrixBase._eval_matrix_mulk
  s%    	7 yyEJJ66r   c                ^   ^ ^ T R                  T R                  T R                  UU 4S j5      $ )Nc                   > TX4   TX4   -  $ r   r   r  s     r   r  9MatrixBase._eval_matrix_mul_elementwise.<locals>.<lambda>y
  s    DIeACj<Pr   r   r   s   ``r   _eval_matrix_mul_elementwise'MatrixBase._eval_matrix_mul_elementwisex
  s    yyDII/PQQr   c                b   ^ ^ UU 4S jnT R                  TR                  T R                  U5      $ )Nc                ^   >^ ^ [        U UUU4S j[        TR                  5       5       5      $ )Nc              3  B   >#    U  H  nTTU4   TUT4   -  v   M     g 7fr   r   )r   r1  r   r   r   r   s     r   r   >MatrixBase._eval_matrix_rmul.<locals>.entry.<locals>.<genexpr>}
  s(     G5FuQqSz$qs)+5F   )r  r   r   r  s   ``r   r   +MatrixBase._eval_matrix_rmul.<locals>.entry|
  s    GU5::5FGGGr   r   r  s   `` r   _eval_matrix_rmulMatrixBase._eval_matrix_rmul{
  s$    	HyyTYY66r   c                    US:X  a  U $ US-  S:X  a  X R                  US-
  5      p2OU R                  US-  5      =p#UR                  U5      $ )Nr/   r  )_eval_pow_by_recursionmultiply)r   numr  r  s       r   r  !MatrixBase._eval_pow_by_recursion
  sR    !8K7a<44S1W=q//q99Azz!}r   c                   SSK Jn  U R                  S   nU R                  5       nU* R	                  5       SS  nU" XQ5      nU R                  U5      nU R                  U5      n[        U5       H  nXuU   U-  -  nX`-  nM     U$ )Nr   )linrec_coeffsr/   )sympy.discrete.recurrencesr  r   charpolyr  r  r  r   )	r   r&   r  r   pr  new_matansr   s	            r   _eval_pow_by_cayleyMatrixBase._eval_pow_by_cayley
  s    <jjmMMO""12&v+((3-jjosA!9W$$COG  
r   c                   Uc  S/[        U 5      -  nUS:X  a  U $ US-  S:X  a  X R                  US-
  US9pCOU R                  US-  US9=p4UR                  USS9n[        U5      nS /U-  n[        U5       H'  nX(   (       a  [	        XX   SS9u  Xx'   X('   M!  XX   Xx'   M)     UR                  UR                  UR                  U5      $ )NTr/   r  )prevsimpFdotprodsimp)withsimp)r   "_eval_pow_by_recursion_dotprodsimpr  r   r0   r   r   r   )	r   r  r  r  r  r  lenmelemsr   s	            r   r  -MatrixBase._eval_pow_by_recursion_dotprodsimp
  s    vc$i'H!8K7a<@@q% A 'q ;;C1H% < ' 'A 

1%
0AttA{(4QTD(I%(+4	  vvaffaffe,,r   c                ^   ^ ^ T R                  T R                  T R                  UU 4S j5      $ )Nc                   > TX4   T-  $ r   r   r  s     r   r  -MatrixBase._eval_scalar_mul.<locals>.<lambda>
  s    DIeOr   r   r   s   ``r   _eval_scalar_mulMatrixBase._eval_scalar_mul
      yyDII/KLLr   c                ^   ^ ^ T R                  T R                  T R                  UU 4S j5      $ )Nc                   > TTX4   -  $ r   r   r  s     r   r  .MatrixBase._eval_scalar_rmul.<locals>.<lambda>
  s    E$qs)Or   r   r   s   ``r   _eval_scalar_rmulMatrixBase._eval_scalar_rmul
  r  r   c                ^   ^ ^ T R                  T R                  T R                  UU 4S j5      $ )Nc                $   > [        TX4   T5      $ r   r   r  s     r   r  &MatrixBase._eval_Mod.<locals>.<lambda>
  s    CQT
E<Rr   r   r   s   ``r   	_eval_ModMatrixBase._eval_Mod
  s    yyDII/RSSr   c                "    U R                  5       $ )z5Returns a new matrix with entry-wise absolute values.)r  r   s    r   __abs__MatrixBase.__abs__
  s    ~~r   __radd__c                   [        X5      u  pUS:w  a  [        $ U R                  UR                  :w  a&  [        SU R                   SUR                   S35      eXpCUR                  [        X45      :w  a  X4p4UR                  U5      $ )z?Return self + other, raising ShapeError if shapes do not match.	is_matrixMatrix size mismatch: z + .)_coerce_operandNotImplementedr   r?   	__class__r   r  )r   r   r  r  r  s        r   __add__MatrixBase.__add__
  s|     #4/!!::$5djj\U[[MQRSTT 1;;'!-'q{{1~r   __rtruediv__c                $    X R                   U-  -  $ r   r  r   s     r   __truediv__MatrixBase.__truediv__
  s    xx%'((r   __rmatmul__c                X    [        X5      u  pnUS:w  a  [        $ U R                  U5      $ Nr  )_unify_with_otherr  __mul__r   r   r  s      r   
__matmul__MatrixBase.__matmul__
  s-    *47Q!!||E""r   c                .   ^ U R                  U4S j5      $ )Nc                   > U T-  $ r   r   )r[  r   s    r   r  $MatrixBase.__mod__.<locals>.<lambda>
  s	    E	r   r  r   s    `r   __mod__MatrixBase.__mod__
  s    ~~122r   __rmul__c                $    U R                  U5      $ )a  Return self*other where other is either a scalar or a matrix
of compatible dimensions.

Examples
========

>>> from sympy import Matrix
>>> A = Matrix([[1, 2, 3], [4, 5, 6]])
>>> 2*A == A*2 == Matrix([[2, 4, 6], [8, 10, 12]])
True
>>> B = Matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
>>> A*B
Matrix([
[30, 36, 42],
[66, 81, 96]])
>>> B*A
Traceback (most recent call last):
...
ShapeError: Matrices size mismatch.
>>>

See Also
========

matrix_multiply_elementwise
)r  r   s     r   r  MatrixBase.__mul__
  s    : }}U##r   c           
        [        SU5      n[        X5      u  pnUS:X  a   U R                  U5      $ US:X  a  U R
                  S   UR
                  S   :w  a&  [        SU R
                   SUR
                   S35      eU R                  U5      nU(       aA  UR                  UR                  UR                  U Vs/ s H  n[        U5      PM     sn5      nU$ [        $ ! [         a	    [        s $ f = fs  snf )	a$  Same as __mul__() but with optional simplification.

Parameters
==========

dotprodsimp : bool, optional
    Specifies whether intermediate term algebraic simplification is used
    during matrix multiplications to control expression blowup and thus
    speed up calculation. Default is off.
Fpossible_scalarr  r/   r   r  z * r  )r<   r  r  r+  r  r   r?   r  r   r   r   r0   r   r   r  	isimpboolr  r  es          r   r  MatrixBase.multiply  s     0{C	*47Q!!&,,U33 +zz!}A. #9$**SUV!WXX%%e,AFF166166Q+GQLOQ+GHH "!!  &%%& ,Hs   C  <C6 C32C3c                    U R                   UR                   :w  a/  [        SR                  U R                   UR                   5      5      eU R                  U5      $ )a{  Return the Hadamard product (elementwise product) of A and B

Examples
========

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

See Also
========

sympy.matrices.matrixbase.MatrixBase.cross
sympy.matrices.matrixbase.MatrixBase.dot
multiply
z!Matrix shapes must agree {} != {})r   r?   r  r  r   s     r   multiply_elementwiseMatrixBase.multiply_elementwise*  sI    * ::$@GG

TYT_T_`aa0077r   c                $    U R                  S5      $ )Nr  )r  r   s    r   __neg__MatrixBase.__neg__D  s    $$R((r   __rpow__c                $    U R                  U5      $ )z$Return self**exp a scalar or symbol.)pow)r   r&   s     r   __pow__MatrixBase.__pow__G  s     xx}r   c                  ^^ Ub  US;  a  [        S5      eU R                  U R                  :w  a
  [        5       eU m[	        TSS5      n[        T5      mTR                  (       a(  TR                  TR                  TR                  S 5      $ TS:X  a  T$ [	        TSS5      nUb8  U" 5       (       a,  TR                  TR                  TR                  UU4S j5      $ TR                  (       aK  TS-  S	:X  aB  TR                  S:X  a  TR                  TS	   T-  //5      $ TS	:  a  T* mTR                  5       mUS
:X  a	   U" T5      $ US:X  a6  TR                  (       a	  TS-  S	:w  a  [        S5      eTR                  T5      $ US:X  a6  TR                  (       a	  TS-  S	:w  a  [        S5      eTR                  T5      $ US:X  a6  TR                  (       a	  TS-  S	:w  a  [        S5      eTR                  T5      $ Uc  TR                  (       a  TS-  S	:X  a  TR                  (       a  [!        T5      mTR                  S:X  a  TS:  a  U" T5      $ [#        SS5      (       a  TR                  T5      $ TS:  a  TR                  T5      $ TR                  T5      $ U(       a	   U" T5      $ S	SKJn  U" TT5      $ ! [         a
    US
:X  a  e  N2f = f! [$         a"    TR&                  SL d  TR(                  SL a  e  NQf = f)as  Return self**exp a scalar or symbol.

Parameters
==========

method : multiply, mulsimp, jordan, cayley
    If multiply then it returns exponentiation using recursion.
    If jordan then Jordan form exponentiation will be used.
    If cayley then the exponentiation is done using Cayley-Hamilton
    theorem.
    If mulsimp then the exponentiation is done using recursion
    with dotprodsimp. This specifies whether intermediate term
    algebraic simplification is used during naive matrix power to
    control expression blowup and thus speed up calculation.
    If None, then it heuristically decides which method to use.

N)r  mulsimpjordancayleyzNo such method_matrix_pow_by_jordan_blocksc                    [        X:H  5      $ r   )r   )r   r   s     r   r   MatrixBase.pow.<locals>.<lambda>j  s
    s16{r   r/   r}  c                $   > X:X  a	  TX4   T-  $ S$ )Nr   r   )r   r   r  r&   s     r   r  r  p  s    afqvs{7SRS7Sr   r   r  r  z.cayley method is only valid for integer powersr  z/mulsimp method is only valid for integer powersr  z0multiply method is only valid for integer powersr  i Ti'  F)MatPow)r+  r   r   r@   getattrr   r  r   	is_Numberinvr>   r>  r  r  r  is_Floatr   r<   rA   
is_integerre  sympy.matrices.expressionsr  )r   r&   method
jordan_powr  r  r  s    `    @r   r  MatrixBase.powN  s   & &0["[,--99		!&((Q >E
cl;;66!&&!&&*BCC!8H1mT2HJJ66!&&!&&*STT==S1W\vv{vv!c	{m,,QwdEEG X!#&
 x==C!GqL !QRR((--y ==C!GqL !RSS77<<z!==C!GqL !STT++C00^#'Q,||clvv{sV|!#&,T488;;C@@u,,S11//44!#& 	6a~Y  X% &F , 
 >>U*c.@.@E.I /Js$   J= &K =KK)L ?L r  c                $    U R                  U5      $ r   )r  r   s     r   r  MatrixBase.__radd__  s    ||E""r   r  c                X    [        X5      u  pnUS:w  a  [        $ U R                  U5      $ r  )r  r  r  r  s      r   r  MatrixBase.__rmatmul__  s-    *47Q!!}}U##r   r  c                $    U R                  U5      $ r   )	rmultiplyr   s     r   r  MatrixBase.__rmul__  s    ~~e$$r   c           
        [        SU5      n[        X5      u  pnUS:X  a   U R                  U5      $ US:X  a  U R
                  S   UR
                  S   :w  a  [        S5      eU R                  U5      nU(       aA  UR                  UR                  UR                  U Vs/ s H  n[        U5      PM     sn5      $ U$ [        $ ! [         a	    [        s $ f = fs  snf )a%  Same as __rmul__() but with optional simplification.

Parameters
==========

dotprodsimp : bool, optional
    Specifies whether intermediate term algebraic simplification is used
    during matrix multiplications to control expression blowup and thus
    speed up calculation. Default is off.
Fr  r  r   r/   zMatrix size mismatch.)r<   r  r  r+  r  r   r?   r  r   r   r   r0   r  s          r   r%  MatrixBase.rmultiply  s     0{C	*47Q!!&--e44 +zz!}A. !899&&u-Avvaffaff.J1|A.JKKH "!  &%%& /Ks   C !CCC__sub__c                    U * U-   $ r   r   r   r  s     r   __rsub__MatrixBase.__rsub__  s    {r   r,  c                    X* -   $ r   r   r+  s     r   r)  MatrixBase.__sub__  s    r{r   c                    [        XS9$ N)
iszerofuncrL   r   r2  s     r   _eval_det_bareissMatrixBase._eval_det_bareiss  s    D88r   c                    [        U 5      $ r   )rM   r   s    r   _eval_det_berkowitzMatrixBase._eval_det_berkowitz  s    d##r   c                    [        XUS9$ )N)r2  r  )rP   )r   r2  r  s      r   _eval_det_luMatrixBase._eval_det_lu  s    tXFFr   c                    [        U 5      $ r   )rN   r   s    r   _eval_det_birdMatrixBase._eval_det_bird  s    r   c                    [        U 5      $ r   )rO   r   s    r   _eval_det_laplaceMatrixBase._eval_det_laplace      D!!r   c                    [        U 5      $ r   rK   r   s    r   _eval_determinantMatrixBase._eval_determinant      Dzr   c                    [        XS9$ Nr  )rF   r   r  s     r   adjugateMatrixBase.adjugate  s    --r   lambdac                    [        XUS9$ )N)r[  ry  )rG   r   r[  ry  s      r   r  MatrixBase.charpoly  s    X66r   c                    [        XX#S9$ rJ  )rH   r   r   r   r  s       r   cofactorMatrixBase.cofactor  s    !33r   c                    [        XS9$ rJ  )rI   rL  s     r   cofactor_matrixMatrixBase.cofactor_matrix  s    44r   c                    [        XUS9$ )N)r  r2  rE  )r   r  r2  s      r   detMatrixBase.det  s    DJ??r   c                    [        U 5      $ r   )rJ   r   s    r   perMatrixBase.per  rH  r   c                    [        XX#S9$ rJ  )rQ   rT  s       r   minorMatrixBase.minor  s    dq00r   c                    [        XU5      $ r   )rR   r  s      r   minor_submatrixMatrixBase.minor_submatrix  s    ++r   c                    [        XUUS9$ )N)r2  ry  with_pivots)rT   )r   r2  ry  rg  s       r   echelon_formMatrixBase.echelon_form"  s    T8') 	)r   c                    [        U 5      $ r   )rS   r   s    r   
is_echelonMatrixBase.is_echelon&  s    4  r   c                    [        XUS9$ N)r2  ry  )rU   r   r2  ry  s      r   rankMatrixBase.rank*  s    T8DDr   c                    [        U R                  X R                  U R                  5      U5      5      u  p#USS2SU R                  24   USS2UR                  * S24   4$ )a]  Return reduced row-echelon form of matrix, matrix showing
rhs after reduction steps. ``rhs`` must have the same number
of rows as ``self``.

Examples
========

>>> from sympy import Matrix, symbols
>>> r1, r2 = symbols('r1 r2')
>>> Matrix([[1, 1], [2, 1]]).rref_rhs(Matrix([r1, r2]))
(Matrix([
[1, 0],
[0, 1]]), Matrix([
[ -r1 + r2],
[2*r1 - r2]]))
N)rV   r;  r  r   r   )r   rhsrN  r  s       r   rref_rhsMatrixBase.rref_rhs-  sU    " T[[xx		':C@AJTYYJ1sxxij=!111r   c                    [        XUX4S9$ )N)r2  ry  pivotsnormalize_last)rV   )r   r2  ry  rw  rx  s        r   rrefMatrixBase.rrefA  s    T8: 	:r   c                2   US;  a  [        SR                  Xa5      5      eUS:X  a  U R                  OU R                  nUS:X  aR  Ub  UOUnUb  Uc  [        SR                  U5      5      eSUs=::  a  U:  d  O  [        SR                  Xb5      5      eGO}US	:X  a  X#XE1R	                  S/5      n[        U5      S
:  a  X$U1R	                  S/5      n[        U5      S
:w  a  [        SR                  U5      5      eUu  pESUs=::  a  U:  d  O  [        SR                  Xd5      5      eSUs=::  a  U:  d  O  [        SR                  Xe5      5      eOUS:X  a  Uc  UOUnUc  UOUnUb  Ub  Uc  [        SR                  U5      5      eX%:X  a  [        SR                  U5      5      eSUs=::  a  U:  d  O  [        SR                  Xb5      5      eSUs=::  a  U:  d  O  [        SR                  Xe5      5      eO[        S[        U5      -  5      eXX4U4$ )zValidate the arguments for a row/column operation.  ``error_str``
can be one of "row" or "col" depending on the arguments being parsed.)n->knn<->mn->n+kmzOUnknown {} operation '{}'. Valid col operations are 'n->kn', 'n<->m', 'n->n+km'r   r|  NzEFor a {0} operation 'n->kn' you must provide the kwargs `{0}` and `k`r   z#This matrix does not have a {} '{}'r}  r  zIFor a {0} operation 'n<->m' you must provide the kwargs `{0}1` and `{0}2`r~  zPFor a {0} operation 'n->n+km' you must provide the kwargs `{0}`, `k`, and `{0}2`zAFor a {0} operation 'n->n+km' `{0}` and `{0}2` must be different.zinvalid operation %s)r>  r  r   r   
differencer   repr)	r   opr   r1  col1col2	error_str	self_colsr   s	            r   _normalize_op_argsMatrixBase._normalize_op_argsK  sG    22 ??Evi?TV V "+e!3DII	 =#dC{ai  "88>y8IK K'i' !F!M!Mi!]^^ ( 7] D'22D6:D4y1}4(33TF;4yA~  "<<BF9<MO OJD(y( !F!M!Mi!^__(y( !F!M!Mi!^__ ) 9_+$3C<4TD{dlai  "AAG	ART T{  "117	1BD D'i' !F!M!Mi!]^^(y( !F!M!Mi!^__ ) 3d2h>??%%r   c                f   ^ ^^ UUU 4S jnT R                  T R                  T R                  U5      $ )Nc                .   > UT:X  a	  TTX4   -  $ TX4   $ r   r   )r   r   r   r1  r   s     r   r   <MatrixBase._eval_col_op_multiply_col_by_const.<locals>.entry  &    Cx4:~%:r   r   )r   r   r1  r   s   ``` r   "_eval_col_op_multiply_col_by_const-MatrixBase._eval_col_op_multiply_col_by_const  %    	 yyDIIu55r   c                f   ^ ^^ UUU 4S jnT R                  T R                  T R                  U5      $ )Nc                D   > UT:X  a  TU T4   $ UT:X  a  TU T4   $ TX4   $ r   r   )r   r   r  r  r   s     r   r   +MatrixBase._eval_col_op_swap.<locals>.entry  s9    DyAtG}$dAtG}$:r   r   )r   r  r  r   s   ``` r   _eval_col_op_swapMatrixBase._eval_col_op_swap  %    	 yyDIIu55r   c                j   ^ ^^^ UUUU 4S jnT R                  T R                  T R                  U5      $ )Nc                >   > UT:X  a  TX4   TTU T4   -  -   $ TX4   $ r   r   )r   r   r   r  r1  r   s     r   r   @MatrixBase._eval_col_op_add_multiple_to_other_col.<locals>.entry  s4    CxADzAQW$555:r   r   )r   r   r1  r  r   s   ```` r   &_eval_col_op_add_multiple_to_other_col1MatrixBase._eval_col_op_add_multiple_to_other_col  *    	 	 yyDIIu55r   c                f   ^ ^^ UUU 4S jnT R                  T R                  T R                  U5      $ )Nc                D   > U T:X  a  TTU4   $ U T:X  a  TTU4   $ TX4   $ r   r   )r   r   row1row2r   s     r   r   +MatrixBase._eval_row_op_swap.<locals>.entry  s9    DyD!G}$dD!G}$:r   r   )r   r  r  r   s   ``` r   _eval_row_op_swapMatrixBase._eval_row_op_swap  r  r   c                f   ^ ^^ UUU 4S jnT R                  T R                  T R                  U5      $ )Nc                .   > U T:X  a	  TTX4   -  $ TX4   $ r   r   )r   r   r1  r   r   s     r   r   <MatrixBase._eval_row_op_multiply_row_by_const.<locals>.entry  r  r   r   )r   r   r1  r   s   ``` r   "_eval_row_op_multiply_row_by_const-MatrixBase._eval_row_op_multiply_row_by_const  r  r   c                j   ^ ^^^ UUUU 4S jnT R                  T R                  T R                  U5      $ )Nc                >   > U T:X  a  TX4   TTTU4   -  -   $ TX4   $ r   r   )r   r   r1  r   r  r   s     r   r   @MatrixBase._eval_row_op_add_multiple_to_other_row.<locals>.entry  s4    CxADzAT1W$555:r   r   )r   r   r1  r  r   s   ```` r   &_eval_row_op_add_multiple_to_other_row1MatrixBase._eval_row_op_add_multiple_to_other_row  r  r   c                    U R                  XX4US5      u  pp4nUS:X  a  U R                  X#5      $ US:X  a  U R                  XE5      $ US:X  a  U R                  X#U5      $ g)a  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   r|  r}  r~  N)r  r  r  r  )r   r  r   r1  r  r  s         r   elementary_col_opMatrixBase.elementary_col_op  s    ( "&!8!8!4QV!W$ =::3BB=))$55?>>stLL r   c                    U R                  XX4US5      u  pp4nUS:X  a  U R                  X#5      $ US:X  a  U R                  XE5      $ US:X  a  U R                  X#U5      $ g)a  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   r|  r}  r~  N)r  r  r  r  )r   r  r   r1  r  r  s         r   elementary_row_opMatrixBase.elementary_row_op  r  r   c                    [        XS9$ NrW  )rl   r   ry  s     r   columnspaceMatrixBase.columnspace  s    D44r   c                    [        XUS9$ )N)ry  r2  )rm   )r   ry  r2  s      r   	nullspaceMatrixBase.nullspace  s    $jIIr   c                    [        XS9$ r  )rn   r  s     r   rowspaceMatrixBase.rowspace  s    11r   c                     [        U /UQ70 UD6$ r   )ro   )r   vecsr   s      r   orthogonalizeMatrixBase.orthogonalize  s    c3D3F33r   c                    [        U 4SU0UD6$ )Nerror_when_incomplete)rp   )r   r  flagss      r   	eigenvalsMatrixBase.eigenvals  s    $U6KUuUUr   c                     [        U 4UUS.UD6$ )N)r  r2  )rq   )r   r  r2  r  s       r   
eigenvectsMatrixBase.eigenvects  s$    4 07L%0).0 	0r   c                    [        U 4SU0UD6$ )N
reals_only)rt   )r   r  r   s      r   is_diagonalizableMatrixBase.is_diagonalizable	  s    !$H:HHHr   c                    [        XUUS9$ )N)r  sort	normalize)ru   )r   r  r  r  s       r   diagonalizeMatrixBase.diagonalize  s    Dd#% 	%r   c                    [        XS9$ Nr}  )rr   r   r}  s     r   bidiagonalizeMatrixBase.bidiagonalize  s    d00r   c                    [        XS9$ r  )rs   r  s     r   bidiagonal_decomposition#MatrixBase.bidiagonal_decomposition  s    (;;r   c                    [        U 5      $ r   )rv   r   s    r   is_positive_definiteMatrixBase.is_positive_definite      $T**r   c                    [        U 5      $ r   )rw   r   s    r   is_positive_semidefinite#MatrixBase.is_positive_semidefinite      (..r   c                    [        U 5      $ r   )rx   r   s    r   is_negative_definiteMatrixBase.is_negative_definite  r  r   c                    [        U 5      $ r   )ry   r   s    r   is_negative_semidefinite#MatrixBase.is_negative_semidefinite"  r  r   c                    [        U 5      $ r   )rz   r   s    r   is_indefiniteMatrixBase.is_indefinite&  s    d##r   c                    [        U 4SU0UD6$ )Ncalc_transform)r{   )r   r  r   s      r   jordan_formMatrixBase.jordan_form*  s    DJJ6JJr   c                    [        U 40 UD6$ r   )r|   r   r  s     r   left_eigenvectsMatrixBase.left_eigenvects-  s    ...r   c                    [        U 5      $ r   )r}   r   s    r   singular_valuesMatrixBase.singular_values0      %%r   )evaluatec                   SSK Jn  U" U /UQ7SU06n[        U [        5      (       d  U(       a  UR	                  5       $ U$ )zCalculate the derivative of each element in the matrix.

Examples
========

>>> from sympy 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
r   )ArrayDerivativer  )$sympy.tensor.array.array_derivativesr  r%  r   
as_mutable)r   r  r   r   r  derivs         r   r   MatrixBase.diffB  s?    * 	I?t?h?$&&8##%%r   c                .   ^ U R                  U4S j5      $ )Nc                &   > U R                  T5      $ r   r   )r[  args    r   r  -MatrixBase._eval_derivative.<locals>.<lambda>_  s    sr   r  )r   r  s    `r   _eval_derivativeMatrixBase._eval_derivative^  s    ~~344r   c                2   ^^ U R                  UU4S j5      $ )af  Integrate each element of the matrix.  ``args`` will
be passed to the ``integrate`` function.

Examples
========

>>> from sympy 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                (   > U R                   " T0 TD6$ r   )	integrater_  s    r   r  &MatrixBase.integrate.<locals>.<lambda>z  s    T(DV(Dr   r  rc  s    ``r   r  MatrixBase.integratea  s    2 ~~DEEr   c                  ^ ^ SSK Jn  [        TU5      (       d  T R                  T5      mT R                  S   S:X  a  T R                  S   nO.T R                  S   S:X  a  T R                  S   nO[        S5      eTR                  S   S:X  a  TR                  S   nO.TR                  S   S:X  a  TR                  S   nO[        S5      eT R                  X4UU 4S j5      $ )a  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
r   r  r/   z)``self`` must be a row or a column matrixz"X must be a row or a column matrixc                2   > TU    R                  TU   5      $ r   r   )r   r   Xr   s     r   r  %MatrixBase.jacobian.<locals>.<lambda>  s    DGLL1,>r   )r  r   r%  r   r   r+  )r   r  r   r  r  s   ``   r   jacobianMatrixBase.jacobian|  s    H 	9!Z((		!A ::a=A

1AZZ]a

1AGHH771:?
AWWQZ1_
A@AA yy>??r   c                .   ^ U R                  U4S j5      $ )a&  Calculate the limit of each element in the matrix.
``args`` will be passed to the ``limit`` function.

Examples
========

>>> from sympy 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                "   > U R                   " T6 $ r   )limit)r[  r   s    r   r  "MatrixBase.limit.<locals>.<lambda>  s    r   r  )r   r   s    `r   r  MatrixBase.limit  s    * ~~677r   c                     U R                  US9$ )Nrt  )r  rQ  s      r   berkowitz_charpolyMatrixBase.berkowitz_charpoly  s    }}q}!!r   c                     U R                  SS9$ )zEComputes determinant using Berkowitz method.

See Also
========

det
	berkowitzrK  r[  r   s    r   berkowitz_detMatrixBase.berkowitz_det  s     xx{x++r   c                &    U R                   " S0 UD6$ )z8Computes eigenvalues of a Matrix using Berkowitz method.r   )r  r  s     r   berkowitz_eigenvalsMatrixBase.berkowitz_eigenvals  s    ~~&&&r   c                    U R                   / p!U R                  5        H  nUR                  XS   -  5        U* nM     [        U5      $ )z1Computes principal minors using Berkowitz method.r  )rx  r  r   rl  )r   signminorsr  s       r   berkowitz_minorsMatrixBase.berkowitz_minors  sC    xxfNN$DMM$b/*5D % V}r   c                   SSK Jn  SnU (       d  U$ U R                  (       d
  [        5       eX R                  pCS/US-
  -  n[        USS5       H  nU" US-   U5      US-
  pX8S U24   * US U2U4   pUS U2S U24   X8U4   * pU
/n[        SUS-
  5       H  nUR                  X<U   -  5        M     [        U5       H  u  pX-  S   X'   M     U R                  U/U-   n[        U5       H  nUS Xm-
  S-    X}S 2U4'   M     XuUS-
  '   M     U R                  U R                  US   * /5      /n[        U5       H  u  pUR                  XU   -  5        M     U[        [        [        U5      5      -   $ )Nr   r  )r/   r/   r  r  r   r   )r  r  rf  r@   r   r   r   r-  rx  r   rl  r@  )r   r  berkAN
transformsr  r  r1  Rrn  r  r   r   Bpolyss                   r   r  MatrixBase.berkowitz  s   (K~~&((YY1SAE]
q!RAQ?AEq!eH9aAhqRaR!V9qAwhqCE1a!e_Qq\* % "%(E4= ) XXqME)E1X !%!),"a%  !"q1u' !* DHHqwh/01j)DALL1X& * eCu-...r   c                     U R                  US9$ rJ  )rX  rL  s     r   cofactorMatrixMatrixBase.cofactorMatrix  s    ##6#22r   c                    [        U 5      $ r   r3  r   s    r   
det_bareisMatrixBase.det_bareis  rC  r   c                     U R                  SS9$ )aP  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
berkowitz_det
lurK  r  r   s    r   det_LU_decompositionMatrixBase.det_LU_decomposition  s    $ xxtx$$r   c                     U R                  X!S9$ )N)r  r  )r  )r   r  r  s      r   jordan_cellMatrixBase.jordan_cell*  s      a ==r   c                H    U R                  5       u  p#X#R                  5       4$ r   )r  r5  )r   calc_transformationPJs       r   jordan_cellsMatrixBase.jordan_cells-  s$    !##%%%r   c                "    U R                  XUS9$ rJ  )ra  rT  s       r   
minorEntryMatrixBase.minorEntry1  s    zz!vz..r   c                $    U R                  X5      $ r   )rd  r  s      r   minorMatrixMatrixBase.minorMatrix4  s    ##A))r   c                "    U R                  USS9$ )zEPermute the rows of the matrix with the given permutation in reverse.r#  r,  r8  r   r  s     r   permuteBkwdMatrixBase.permuteBkwd7  s       <<r   c                "    U R                  USS9$ )z:Permute the rows of the matrix with the given permutation.r!  rL  rM  rN  s     r   
permuteFwdMatrixBase.permuteFwd;  s       ;;r   c                    U R                  5        Vs1 s H  oR                  iM     nn[        U5      S:X  a  Uu  nO[        n[	        U5      $ s  snf r   )flatkindr   r   r=   )r   r  
elem_kindselemkinds       r   rV  MatrixBase.kind?  sF    &*iik2kffk
2z?a"IH$H(## 3s   Ac                    [        U R                  5       VVs/ s H%  n[        U R                  5        H  o X4   PM
     M'     snn$ s  snnf )z
Returns a flat list of all elements in the matrix.

Examples
========

>>> from sympy import Matrix
>>> m = Matrix([[0, 2], [3, 4]])
>>> m.flat()
[0, 2, 3, 4]

See Also
========

tolist
values
r  r  s      r   rU  MatrixBase.flatH  s=    $ %*$))$4O$4qeDII>NQT
>N
$4OOOs   ,A	c                D    Ub  U(       d  [        S5      eSSKJn  U" XS9$ )Nz=Cannot implement copy=False when converting Matrix to ndarrayr/   )matrix2numpy)dtype)r+  denser]  )r   r^  rw  r]  s       r   	__array__MatrixBase.__array__\  s$    D[\\'D..r   c                4    U R                   U R                  -  $ )z[Return the number of elements of ``self``.

Implemented mainly so bool(Matrix()) == False.
r   r   s    r   __len__MatrixBase.__len__b  s    
 yy499$$r   c                6   SSK JnJn  S nU R                  5       u  pVUR	                  5       nU Vs/ s H
  o" U5      PM     nnU H  nU" X5        M     U R                  UR                  U" U6 5      R                  UR                  5       5      5      $ s  snf )Nr   )r  MutableMatrixc                D   U R                   S   nU S   nUR                  (       ao  US:X  a  UR                  (       a  X1-  U S'   OUR                  (       a  UR                  (       d  [	        S5      e[        U5       H  n[        XA5      U SU4'   M     OQ[        U5       HB  n[        X5      n[        U[        5      (       a  UR                  5       nX1U-
  -  U-  U SU4'   MD     [        U5       H,  n[        SX$-
  5       H  nXS-
  XF-   S-
  4   XXF-   4'   M     M.     g )Nr   r)  r/   zANon-invertible matrix can only be raised to a nonnegative integer)
r   r  re  r  rA   r   r!   r(   r%  _eval_expand_func)jcr  r,  lr   bnr   s          r   jordan_cell_powerBMatrixBase._matrix_pow_by_jordan_blocks.<locals>.jordan_cell_powerl  s    A3Ayy6a..dBsG,,1+;+;23vww"1X"0"61Q3 & qA!!B!"h//113A#hrkBqsG	 "
 1Xq!#A "aCAIBuI ' r   )r  r  rf  r  r5  r   r  r  )	r   r  r  rf  rl  rA  rB  rC  r   s	            r   r  'MatrixBase._matrix_pow_by_jordan_blocksi  s    6	/* !((*2>?,Qa(,?Aa% yyD,$78!%%'"$ 	$ @s   Bc                    [         R                  U R                  ;   a  SU R                  < SU R                  < S3$ S[        U R                  5       5      -  $ )NMatrix(rK  , [])z
Matrix(%s))r#   r  r   r   r   strrY  r   s    r   __str__MatrixBase.__str__  s;    66TZZ+/99dii@@c$++-000r   c                
   U(       d
  [        5       n[        R                  U R                  ;   a  SU R                  < SU R
                  < S3$ U R                  S:X  a  SU R                  USS9-  $ SU R                  USS9-  $ )	Nrp  rK  rq  r/   zMatrix([%s])z,
)rowsepzMatrix([
%s]))r%   r#   r  r   r   r   table)r   printers     r   _format_strMatrixBase._format_str  sj     lG66TZZ+/99dii@@99>!DJJwuJ$EEE$**WU*"CCCr   c                *  ^ [        U5      nU Vs/ s H&  n[        US5      (       a  UR                  5       OUPM(     snm[        [	        [        T5      5      5      nT Vs/ s H  oDR                  PM     nn[	        U5       Vs/ s H  ouR                  S5      PM     nn[        U4S jU 5       5      n	/ n
[        U5      (       a  / n[        U5       HU  u  pUR                  TU   Xm   * SS24   5        Xm==   S-  ss'   Xm   S:X  d  M9  U(       d  MB  UR                  S5      X'   MW     [        U5      U	:w  a  [        [        S5      5      eU
R                  U5        [        U5      (       a  M  U R                  U
5      $ s  snf s  snf s  snf )a  Return a matrix filled by the given matrices which
are listed in order of appearance from left to right, top to
bottom as they first appear in the matrix. They must fill the
matrix completely.

Examples
========

>>> from sympy import ones, Matrix
>>> Matrix.irregular(3, ones(2,1), ones(3,3)*2, ones(2,2)*3,
...   ones(1,1)*4, ones(2,2)*5, ones(1,2)*6, ones(1,2)*7)
Matrix([
    [1, 2, 2, 2, 3, 3],
    [1, 2, 2, 2, 3, 3],
    [4, 2, 2, 2, 5, 5],
    [6, 6, 7, 7, 5, 5]])
as_explicitr   c              3  B   >#    U  H  nTU   R                   v   M     g 7fr   r   )r   r   r  s     r   r   'MatrixBase.irregular.<locals>.<genexpr>  s     -f1Q499fr  Nr/   zf
                    Matrices provided do not appear to fill
                    the space completely.)r5   r  r|  r   r   r   r   r  r  r   r-  extendr>  r6   r   r   )r   ntopmatricesr   r   qdatr  activer   r   rN  r  r   r  s                 @r   	irregularMatrixBase.irregular  s]   & d|  !(= 9 9Q]]_q@s1v !q!vvq!$)$K0Kq%%(K0-f--#hhA!&)1svgqj)*!6Q;11 !aFI	 *
 1v~  -- ". / / KKN #hh xx~' "0s   -F"FFc                   UR                  5       n[        UR                  5      S:X  aO  UR                  S   UR                  S   pCUR                  5        Vs/ s H  oPR	                  U5      PM     nnX4U4$ [        UR                  5      S:X  a2  U Vs/ s H  oPR	                  U5      PM     nnUR                  S   SU4$ [        S5      es  snf s  snf )Nr  r   r/   z&SymPy supports just 1D and 2D matrices)r`  r   r   ravelr   r   )r   r  arrr   r   r   	flat_lists          r   _handle_ndarrayMatrixBase._handle_ndarray  s    
 mmosyy>Q1syy|$25))+>+Qa+I>y((^q 256#Qa#I699Q<I--%8: : ? 7s   CCc                  ^^^^^^ SSK Jn  SSKJm  SSKJm  Sn[        U5      S:X  Ga  [        US   U5      (       a9  US   R                  US   R                  [        US   R                  5       5      4$ [        US   [        5      (       a0  US   R                  US   R                  US   R                  5       4$ [        US   [        5      (       aR  US   R                  (       a>  US   R                  US   R                  US   R!                  5       R                  5       4$ [        US   ["        R$                  5      (       a>  US   nU Vs/ s H  o`R'                  U5      PM     nnUR                  UR                  U4$ [)        US   S5      (       a  U R+                  US   5      $ [-        US   5      (       GaA  [        US   [.        5      (       Gd(  [1        US   5      nUUU4S jmU4S	 jmUR3                  S
S5      mT(       a?  UU4S jmU4S jn[        U[0        [4        45      (       a  U V	s/ s H
  o" U	5      PM     nn	[        U5      S:X  a  S=p/ nGO
[7        U4S jU 5       5      (       aE  [        US   5      S:X  a3  [7        S U 5       5      (       d  [9        S5      e[        U5      n
Sn/ nGO[;        UU4S jU 5       5      (       d8  U Vs/ s H  oR'                  U5      PM     nn[        U5      n
U
(       a  SOSnGOXT(       a  [7        U4S jU 5       5      (       a  U Vs1 s H+  n[;        UR<                  5      (       d  M  UR                  iM-     nnU(       ao  [        U5      S:w  a  [9        S5      eU VVVs/ s H$  oR                  5         H  o  H  oPM     M     M&     nnnnUR?                  5       n[        U5      U-  n
GOS=p/ nGOT(       Gam  [;        U4S jU 5       5      (       GaR  [A        5       n/ nU GH  nT" U5      (       ar  URC                  UR                  5        VVs/ s H  nU  H  nUPM     M     snn5        [;        UR<                  5      (       a  URE                  UR                  5        OT" U5      (       aS  U(       aK  URE                  [        U5      5        URC                  U Vs/ s H  nU R'                  U5      PM     sn5        O"URE                  S5        URG                  U5        [        U5      S:  d  GM  [9        S5      e   UR?                  5       n[        U5      U-  n
GO/ n[A        5       nS=pU GHr  n	[-        U	5      (       d  [I        U	SS5      (       d  [9        S5      e[)        U	S5      (       a  SU	R<                  ;   a  MT  T(       a  [7        U4S jU	 5       5      (       ax  U RK                  U	 Vs/ s H  oRL                  PM     sn5      u  nnn[O        UU/5      n[Q        U5       VVs/ s H  n[Q        U5        H  nUU   U   PM     M      snnnUUnnOESn[I        U	SS5      (       a  SnU	/nO+[        U	5      nU	 Vs/ s H  oR'                  U5      PM     nnURE                  U5        [        U5      S:  a  [9        S5      eURC                  U5        X-  n
GMu     U(       a  UR?                  5       OSnGOj[        U5      S:X  GaF  [S        US   5      n
[S        US   5      nU
S:  d  US:  a  [9        SRU                  X5      5      e[        U5      S:X  a  [        US   [V        5      (       ay  US   n/ n[Q        U
5       Hb  nURC                  [Q        U5       Vs/ s H9  nU R'                  U" U R'                  U5      U R'                  U5      5      5      PM;     sn5        Md     Ox[        U5      S:X  aT  [-        US   5      (       aA  US   n[        U5      X-  :w  a  [9        S5      eU Vs/ s H  oR'                  U5      PM     nnO[        U5      S:X  a  S=p/ nUc  [Y        [[        S5      5      eW
WU4$ s  snf s  sn	f s  snf s  snf s  snnnf s  snnf s  snf s  snf s  snnf s  snf s  snf s  snf )a  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]])

See Also
========
irregular - filling a matrix with irregular blocks
r   r  )MatrixSymbol)BlockMatrixNr/   r`  c                `   > [        U [        5      =(       a    T=(       d    [        U TT45      $ r   )r%  r   )r   r  r  r  s    r   r  4MatrixBase._handle_creation_inputs.<locals>.<lambda>"  s,    *Q
"; #LJ
1{L.I J#Lr   c                B   > [        U 5      =(       a    T" U 5      (       + $ r   )r4   )r   ismats    r   r  r  $  s    A ?uQx< ?r   r  Tc                   > [        U T5      (       a  U R                  5       $ [        U T5      (       a1  [        S U R                   5       5      (       a  U R                  5       $ U $ )zmake Block and Symbol explicitc              3  8   #    U  H  oR                   v   M     g 7fr   )
is_Integer)r   r  s     r   r   LMatrixBase._handle_creation_inputs.<locals>.make_explicit.<locals>.<genexpr>.  s     @_W^RSW^r  )r%  r|  r,  r   )r[  r  r  s    r   make_explicit9MatrixBase._handle_creation_inputs.<locals>.make_explicit*  sQ    %a55#$==?2'<88S@_WXW^W^@_=_=_#$==?2#$Hr   c                   > [        U [        [        45      (       a  U  Vs/ s H  nT" U5      PM     sn$ T" U 5      $ s  snf r   )r%  r   rl  )r   r[  r  s     r   make_explicit_row=MatrixBase._handle_creation_inputs.<locals>.make_explicit_row3  s?    %cD%=99>A#BcM!$4c#BB#0#55 $Cs   >c              3  4   >#    U  H  nT" U5      v   M     g 7fr   r   )r   r   raws     r   r   5MatrixBase._handle_creation_inputs.<locals>.<genexpr>@  s     -AQr  c              3  >   #    U  H  n[        U5      S :H  v   M     g7fr&  )r   r&  s     r   r   r  A  s     8Cqs1v{C   zmismatched dimensionsc              3  R   >#    U  H  nT" U5      =(       d    T" U5      v   M     g 7fr   r   )r   r   r  r  s     r   r   r  F  s!     =ASV/uQx/s   $'c              3  4   >#    U  H  nT" U5      v   M     g 7fr   r   r   r   r  s     r   r   r  K       %<1eAhhr  c              3  4   >#    U  H  nT" U5      v   M     g 7fr   r   r  s     r   r   r  W  r  r  	is_MatrixFzexpecting list of listsc              3  4   >#    U  H  nT" U5      v   M     g 7fr   r   r  s     r   r   r  {  s     +BcE!HHcr  r   r  r  z+List length should be equal to rows*columnszf
                Data type not understood; expecting list of lists
                or lists of values.).r  r  "sympy.matrices.expressions.matexprr  &sympy.matrices.expressions.blockmatrixr  r   r%  r   r   r3   rY  r   rU  r   r  r|  mpmatrixr   r  r  r4   DeferredVectorr   r  rl  r,  r>  r   r   r  r  r  addr   r  r  r  r+   r   r5   r  r*   r+  r6   )r   r   r   r  r  r   r[  r  r  r   r   r   r   ncolrN  r  r   r1  rU  r  flatTr  rU  r  r  r  r  r  r  r  s                           @@@@@@r   r  "MatrixBase._handle_creation_inputs  sk   \ 	0CF	t9>$q'<00Aw||T!W\\747>>;K3LLL DGZ00Aw||T!W\\47<<>AA DGU++Q0A0AAw||T!W\\473F3F3H3M3M3OOODGRYY//G678a\\!_a	8vvqvvy00 a+..**4733 T!W%%&tAw??47mL?!::j$7 %6 "#e}55ADE#05Es8q="#OD "I----#c!f+2B8C888()@AAs8DD "I====:= >#Qa#I >y>D $1!D#%<%<"<"<,/@Cq3qww<FAFFCD@t9>",-D"EE03$S1XXZQRAQQRQZQ	$S#xxz"9~t3&'$&	#%<%<"<"<5D "I  88%,,,-HHJ BJq1J BD"177|| $ 0 VV  $Q 0 ) 0 0Q1OQr#,,r2BQ1O P HHQK%,,Q/t9q=",-D"EE !  88:Dy>4/D
 !#I5D"#OD"*3//$+Ce$D$D",-F"GG"344 CII~ (#+Bc+B(B(B*-*E*E.1 2cc 2+4KAq% 's 3A27( M(QE!Hq1aH( M !#$aqAq !A&sK??$%(+u$'HAD'EAQ'Et9q=",-D"EE!((.	9  #: *.488:1DY!^$q'?D$q'?Dax4!8  "DDJF4DVX X 4yA~*T!Wh"?"?!W	tA$$"'+/"-Q ba#,,q/&JK"-/0 % TaKQ$8$8 G	y>T[0$EG G6?@i\\!_i	@ Y!^ODIJ (' ( ) ) T9$$ 9H F !?
 A %T !C 2P4 !3 !N (F,/ AsO   b b'b b"b+b#b*"b0
;b5
6%b:c /A c
c
c                (   SSK Jn  [        U[        5      nU R	                  U5      =u  pVn[        U[
        5      n[        U[        5      (       d  [        U[        5      (       a^  U(       a  U R                  X5        g[        U[        5      (       d"  [        U5      (       a  U R                  X5        g[        SU-  5      eU(       d/  [        U[        5      (       d  [        U5      (       a
  U" U5      nSnU(       a  U(       a7  [        [        XPR                  5      6 [        [        X`R                  5      6 4nO0[        XUUR                  -   5      [        XfUR                  -   5      4nU R                  X5        gXVU R                  U5      4$ )am  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]])
r/   r  Nzunexpected value: %sT)r_  r  r%  slicekey2ijr   copyin_matrixr,   r4   copyin_listr>  r   r@  r   r   r   )r   r   valuer  is_slicer   r   is_mats           r   _setitemMatrixBase._setitem  sD   P 	"c5)[[%%sE:.a:a#7#7""3.eT**{5/A/A  ,3e;<<"5%00[5G5Gu &II"67 &II"679C !

N3 

N35C""3.  T]]5111r   c                
    X-   $ )zReturn self + b.r   r   r  s     r   r  MatrixBase.add  s	    xr   c                j    U (       d  U R                   $ U R                  5       n[        U6 [        U6 -  $ )a#  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  r   r   )r   singularvaluess     r   condition_numberMatrixBase.condition_number  s4    & 99--/N#c>&:::r   c                l    U R                  U R                  U R                  U R                  5       5      $ )z
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]])

)r   r   r   rU  r   s    r   rw  MatrixBase.copy  s%     yyDIItyy{;;r   c           
     N   SSK Jn  [        U[        U45      (       d$  [	        SR                  U[        U5      5      5      eU R                  U R                  -  UR                  UR                  -  s=:X  a  S:X  dA  O  [        SU R                  U R                  4< SUR                  UR                  4< 35      eU R                  U R                  U R                  U S   US   -  U S   US   -  -
  U S   US   -  U S   US   -  -
  U S   US   -  U S   US   -  -
  45      $ )	a  
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
hat
vee
multiply
multiply_elementwise
r   )
MatrixExprz{} must be a Matrix, not {}.r   z(Dimensions incorrect for cross product: z x r/   r  )r  r  r%  r   r+  r  r  r   r   r?   r   )r   r  r  s      r   crossMatrixBase.cross+  s   * 	B!j*566.55aaAC C 		DII%!&&=A=#yy$))4qvvqvv6FH I I 99TYY		a1Q4$q'AaD.0a1Q4$q'AaD.0a1Q4$q'AaD.043 4 4r   c                    U R                   S:w  a!  [        S[        U R                   5      -   5      eU u  pnU R                  SSSU* UUSU* U* US4	5      $ )a  
Return the skew-symmetric matrix representing the cross product,
so that ``self.hat() * b`` is equivalent to  ``self.cross(b)``.

Examples
========

Calling ``hat`` creates a skew-symmetric 3x3 Matrix from a 3x1 Matrix:

>>> from sympy import Matrix
>>> a = Matrix([1, 2, 3])
>>> a.hat()
Matrix([
[ 0, -3,  2],
[ 3,  0, -1],
[-2,  1,  0]])

Multiplying it with another 3x1 Matrix calculates the cross product:

>>> b = Matrix([3, 2, 1])
>>> a.hat() * b
Matrix([
[-4],
[ 8],
[-4]])

Which is equivalent to calling the ``cross`` method:

>>> a.cross(b)
Matrix([
[-4],
[ 8],
[-4]])

See Also
========

dot
cross
vee
multiply
multiply_elementwise
)r   r/   z+Dimensions incorrect, expected (3, 1), got r   r   )r   r?   rr  r   )r   r[  yzs       r   hatMatrixBase.hatO  sq    Z ::J _- . . GA!99QQBQQ$  r   c                    U R                   S:w  a!  [        S[        U R                   5      -   5      eU R                  5       (       d  [	        S5      eU R                  SSU S   U S   U S   45      $ )	a  
Return a 3x1 vector from a skew-symmetric matrix representing the cross product,
so that ``self * b`` is equivalent to  ``self.vee().cross(b)``.

Examples
========

Calling ``vee`` creates a vector from a skew-symmetric Matrix:

>>> from sympy import Matrix
>>> A = Matrix([[0, -3, 2], [3, 0, -1], [-2, 1, 0]])
>>> a = A.vee()
>>> a
Matrix([
[1],
[2],
[3]])

Calculating the matrix product of the original matrix with a vector
is equivalent to a cross product:

>>> b = Matrix([3, 2, 1])
>>> A * b
Matrix([
[-4],
[ 8],
[-4]])

>>> a.cross(b)
Matrix([
[-4],
[ 8],
[-4]])

``vee`` can also be used to retrieve angular velocity expressions.
Defining a rotation matrix:

>>> from sympy import rot_ccw_axis3, trigsimp
>>> from sympy.physics.mechanics import dynamicsymbols
>>> theta = dynamicsymbols('theta')
>>> R = rot_ccw_axis3(theta)
>>> R
Matrix([
[cos(theta(t)), -sin(theta(t)), 0],
[sin(theta(t)),  cos(theta(t)), 0],
[            0,              0, 1]])

We can retrieve the angular velocity:

>>> Omega = R.T * R.diff()
>>> Omega = trigsimp(Omega)
>>> Omega.vee()
Matrix([
[                      0],
[                      0],
[Derivative(theta(t), t)]])

See Also
========

dot
cross
hat
multiply
multiply_elementwise
)r   r   z+Dimensions incorrect, expected (3, 3), got zMatrix is not skew-symmetricr   r/   )r  r/   )r   r  )r/   r   )r   r?   rr  rz  r>  r   r   s    r   veeMatrixBase.vee  s{    H ::J _- . .''));<<99Qddd$  r   c                d    SSK Jn  U R                  S:w  a  [        eU R                  U" S5      -  $ )a  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
========

sympy.matrices.matrixbase.MatrixBase.conjugate: By-element conjugation
sympy.matrices.matrixbase.MatrixBase.H: Hermite conjugation
r   )mgammarQ  )sympy.physics.matricesr  r   AttributeErrorr  )r   r  s     r   r  MatrixBase.D  s.    D 	299>
 ! vvq	!!r   c                   SSK Jn  [        U[        5      (       d  [	        U5      (       ao  [        U5      U R                  :w  a?  [        U5      U R                  :w  a&  [        SU R                  < S[        U5      < 35      eU R                  U" U5      5      $ [        S[        U5      -  5      eSU R                  ;  d  SUR                  ;  a  [        e[        U 5      [        U5      :w  a'  [        SU R                  < SUR                  < 35      eU n[        U5      nUR                  SU4:w  a  UR                  SU5      nUR                  US4:w  a  UR                  US5      nUb  Uc  SnU(       a  Uc  SnUS:X  a9  US;   a  UR                  5       nO"US	;   a  UR                  5       nO[        S
5      eXQ-  S   $ )a  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
r/   r  z&Dimensions incorrect for dot product: rK  z2`b` must be an ordered iterable or Matrix, not %s.Tmaths)r  leftmath)physicsrightzUnknown conjugate_convention was entered. conjugate_convention must be one of the following: math, maths, left, physics or right.r   )r_  r  r%  r   r4   r   r   r   r?   r   dotr+  r  r+   r  r>  )r   r  	hermitianconjugate_conventionr  r   r  s          r   r  MatrixBase.dot   s   h 	"!Z((1~~q6TYY&3q6TYY+>$ JJA01 1 xxq	**HG  TZZQagg%5t9ABF**aggVX X H99A++a#C77q!f		!QA  +	0AI-5#* #'@@mmo%)==KKM  "T U U |r   c           
        SSK Jn  U SS2SS24   U R                  p2U" U5      nU R                  5       (       a  U$ [	        SU5       HO  n[	        SU5       H<  nSn[	        SU5       H  nU[        XVSU5      USU4   -  -  nM     XtXV4'   U* XFU4'   M>     MQ     [	        SU5       HU  n	Sn[	        SU5       H-  n
[	        SU5       H  nU[        SXU5      X*U4   -  -  nM     M/     US-  nU* USU	4'   XtU	S4'   MW     U$ )a  Returns the dual of a matrix.

A dual of a matrix 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.

r   r'  Nr/   r  )r  r  r   rg  r   r"   )r   r  r   r  workr   r   acumr1  rj  r  r  s               r   dualMatrixBase.dualf  s#    	)AqDz4991QxKq!A1a[q!AJqQ2Qq!tW<<D %!QT
"UT
 !  q!AD1a[q!AJq!2Q!tW<<D % ! AIDDAJAJ  r   c                    U R                   nU S   n[        U5      n[        U5       Vs0 s H  oDU[        U5      -  _M     nnSSKJn  U R                  U" X5      5      $ s  snf )a`  A helper function to compute an exponential of a Jordan block
matrix

Examples
========

>>> from sympy import Symbol, Matrix
>>> l = Symbol('lamda')

A trivial example of 1*1 Jordan block:

>>> m = Matrix.jordan_block(1, l)
>>> m._eval_matrix_exp_jblock()
Matrix([[exp(lamda)]])

An example of 3*3 Jordan block:

>>> m = Matrix.jordan_block(3, l)
>>> m._eval_matrix_exp_jblock()
Matrix([
[exp(lamda), exp(lamda), exp(lamda)/2],
[         0, exp(lamda),   exp(lamda)],
[         0,          0,   exp(lamda)]])

References
==========

.. [1] https://en.wikipedia.org/wiki/Matrix_function#Jordan_decomposition
r)  r/   banded)r   r&   r   r)   sparsetoolsr  r  )r   r  rj  exp_lr   bandsr  s          r   _eval_matrix_exp_jblock"MatrixBase._eval_matrix_exp_jblock  s_    < yyJA27+>+QEIaL((+>'~~fT122 ?s   A!c                   [        U5      [        U5      p!U R                  (       d  [        eUR                  (       d  [	        SR                  U5      5      eX!R                  ;  a  [	        SR                  X!5      5      eX R                  ;   a  [	        SR                  X 5      5      eU R                  5       n[        UR                  5       5      n0 nUn[        US-
  5       H  n[        Xb5      nXeUS-   '   M     U R                  S   nU R                  U5      n	U R                  US5      n
SnU GHl  nX7   nUR                  X'5      X'   X   R                  (       a0  X   R                   (       d  [	        SR                  XU   5      5      eSn[        U5       H  nXX4'   X-  nM     US:  a  [        U5       Vs/ s H  nSPM     nnSnUS:  a  US-   nUS-  nUU   R                  X'5      nUR                  (       a/  UR                   (       d  [	        SR                  UU   U5      5      eUX'   [        U5       HE  nUU-
  S-   S::  a  SXU4'   SUU'   M  UU   UU-
  S-   -  UU'   UU   [#        X~U-
  5      -  XU4'   MG     US-  nUS:  a  M  US-  nGMo     U	R%                  U
5      nU R                  U5      nU R'                  U5      n[        U5       H  nUUU   U-  -   nUU -  nM     U$ s  snf )a  
Computes f(A) where A is a Square Matrix
and f is an analytic function.

Examples
========

>>> from sympy import Symbol, Matrix, S, log

>>> x = Symbol('x')
>>> m = Matrix([[S(5)/4, S(3)/4], [S(3)/4, S(5)/4]])
>>> f = log(x)
>>> m.analytic_func(f, x)
Matrix([
[     0, log(2)],
[log(2),      0]])

Parameters
==========

f : Expr
    Analytic Function
x : Symbol
    parameter of f

z{} must be a symbol.z{} must be a parameter of {}.z!{} must not be a parameter of {}.r/   r   z_Cannot evaluate the function because the function {} is not analytic at the given eigenvalue {}zaCannot evaluate the function because the derivative {} is not analytic at the given eigenvalue {})r   rf  r@   	is_symbolr>  r  r  r  maxr  r   r   r   r  r  	is_number
is_complexr  solver  )r   r  r[  eigenmax_mul
derivativeddr   r  rN  f_valr   r  r   r  iicoederid_ir  r  pres                         r   analytic_funcMatrixBase.analytic_func  s    8 {HQK1~~&&{{3::1=>>NN"/66q<> >!!!3::1CE E  elln%
w{#AbB "q1u $ JJqMJJqM

1a A(CEJz##EJ,A,A $$*F1Cj$9; ; C1X#&	  Qw#(8,8Rq8,Ag'C1HC$T*//5C}}S^^(,,2F:d3CS,IK K "%EJ"1Xt8a<1,()A1fI%&CF$!$QTA!6A$'F3qd(+;$;q&	 & AID# Ag$ 1HCC D GGENjjmhhqkqA!S.C4KC  
7 -s   K<c                   U R                   (       d  [        S5      e U R                  5       u  pUR                  5       nU Vs/ s H  oDR                  5       PM     nnSSKJn  U" U6 nUR                  USS9R                  UR                  5       SS9n[        S U R                  5        5       5      (       a  [        U 5      " [        U5      5      $ [        U 5      " U5      $ ! [         a    [        S5      ef = fs  snf )a3  Return the exponential of a square matrix.

Examples
========

>>> from sympy import Symbol, Matrix

>>> t = Symbol('t')
>>> m = Matrix([[0, 1], [-1, 0]]) * t
>>> m.exp()
Matrix([
[    exp(I*t)/2 + exp(-I*t)/2, -I*exp(I*t)/2 + I*exp(-I*t)/2],
[I*exp(I*t)/2 - I*exp(-I*t)/2,      exp(I*t)/2 + exp(-I*t)/2]])
z0Exponentiation is valid only for square matricesz`Exponentiation is implemented only for matrices for which the Jordan normal form can be computedr   r  Nr  c              3  8   #    U  H  oR                   v   M     g 7fr   )is_real)r   r  s     r   r   !MatrixBase.exp.<locals>.<genexpr>3  s     8-}}-r  )rf  r@   r  r5  r>   r   r  r  r  r  r  r,  r  r  r   )	r   rA  rB  cellscellblocksr  eJrets	            r   r&   MatrixBase.exp  s     ~~&BD D	t##%DA%%'E
 >CCUT..0UC'6]jjj.77T7R8$++-888:bg&&:c?"  	t%rt t	t Ds   "C& C?&C<c                   U R                   nU S   nUR                  (       a  [        SR                  U5      5      eS[	        U5      0n[        SU5       H  nU* U* -  * U-  X4'   M     SSKJn  U R                  U" X5      5      $ )a  Helper function to compute logarithm of a jordan block.

Examples
========

>>> from sympy import Symbol, Matrix
>>> l = Symbol('lamda')

A trivial example of 1*1 Jordan block:

>>> m = Matrix.jordan_block(1, l)
>>> m._eval_matrix_log_jblock()
Matrix([[log(lamda)]])

An example of 3*3 Jordan block:

>>> m = Matrix.jordan_block(3, l)
>>> m._eval_matrix_log_jblock()
Matrix([
[log(lamda),    1/lamda, -1/(2*lamda**2)],
[         0, log(lamda),         1/lamda],
[         0,          0,      log(lamda)]])
r)  zBCould not take logarithm or reciprocal for the given eigenvalue {}r   r/   r  )	r   r  r>   r  r'   r   r  r  r  )r   r  rj  r  r   r  s         r   _eval_matrix_log_jblock"MatrixBase._eval_matrix_log_jblock8  s    0 yyJ99  &q	+ + CFq$A"!}q(EH   	(~~fT122r   c                   U R                   (       d  [        S5      e U(       a  U" U 5      R                  5       u  p#OU R                  5       u  p#UR                  5       nU Vs/ s H  nUR                  5       PM     nnSSKJn  U" U6 nU(       a4  U" X(-  U" UR                  5       5      -  5      n	U R                  U	5      n	U	$ X(-  UR                  5       -  n	U	$ ! [         a    [        S5      ef = fs  snf )a  Return the logarithm of a square matrix.

Parameters
==========

simplify : function, bool
    The function to simplify the result with.

    Default is ``cancel``, which is effective to reduce the
    expression growing for taking reciprocals and inverses for
    symbolic matrices.

Examples
========

>>> from sympy import S, Matrix

Examples for positive-definite matrices:

>>> m = Matrix([[1, 1], [0, 1]])
>>> m.log()
Matrix([
[0, 1],
[0, 0]])

>>> m = Matrix([[S(5)/4, S(3)/4], [S(3)/4, S(5)/4]])
>>> m.log()
Matrix([
[     0, log(2)],
[log(2),      0]])

Examples for non positive-definite matrices:

>>> m = Matrix([[S(3)/4, S(5)/4], [S(5)/4, S(3)/4]])
>>> m.log()
Matrix([
[         I*pi/2, log(2) - I*pi/2],
[log(2) - I*pi/2,          I*pi/2]])

>>> m = Matrix(
...     [[0, 0, 0, 1],
...      [0, 0, 1, 0],
...      [0, 1, 0, 0],
...      [1, 0, 0, 0]])
>>> m.log()
Matrix([
[ I*pi/2,       0,       0, -I*pi/2],
[      0,  I*pi/2, -I*pi/2,       0],
[      0, -I*pi/2,  I*pi/2,       0],
[-I*pi/2,       0,       0,  I*pi/2]])
z+Logarithm is valid only for square matricesz[Logarithm is implemented only for matrices for which the Jordan normal form can be computedr   r   )rf  r@   r  r5  r>   r   r  r  r  r  r  )
r   ry  rA  rB  r  r  r  r  r  r  s
             r   r'   MatrixBase.log_  s   h ~~&=? ?
	:~1131'')%%'E  ((* 	  	(6]16HQUUW$556C..%C 
 &1557"C
#  	:%9: :	:
s   AC $C6C3c                    U (       d  gU R                   (       d  [        S5      e[        SU S S9nU R                  U5      nUR                  S   XR
                  -  :X  a  gg)a3  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
Tz,Nilpotency is valid only for square matricesr[  c                    SU -   $ )Nr  r   )r  s    r   r  )MatrixBase.is_nilpotent.<locals>.<lambda>  s    cAgr   )modifyr   F)rf  r@   r.   r  r   r   )r   r[  r  s      r   is_nilpotentMatrixBase.is_nilpotent  s\    $ ~~&>@ @!#t4EFMM!66!9YY&r   c                   U Vs/ s H  n[        U[        5      PM     snu  p4U(       a9  U R                  (       d  S=pVOBUS   R                  U R                  5      SS u  pVO[	        US   U R                  5      nUS-   nU(       a9  U R
                  (       d  S=pxOBUS   R                  U R
                  5      SS u  pxO[	        US   U R
                  5      nUS-   nXVXx4$ s  snf )zConverts 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
r   Nr  r/   )r%  r  r   r   r.  r   )	r   keysr1  islicejslicerlorhiclochis	            r   
key2boundsMatrixBase.key2bounds  s     9==1*Q.=99c7??4995bq9SQ+C'C99c7??4995bq9SQ+C'C!!# >s   C$c                   [        U5      (       ad  [        U5      S:X  d  [        S5      e[        XR                  5       VVs/ s H'  u  p#[        U[        5      (       d  [        X#5      OUPM)     snn$ [        U[        5      (       a  UR                  [        U 5      5      SS $ [        [        U[        U 5      5      U R                  5      $ s  snnf )zConverts key into canonical form, converting integers or indexable
items into valid integers for ``self``'s range or returning slices
unchanged.

See Also
========

key2bounds
r  z"key must be a sequence of length 2N)r4   r   r+  zipr   r%  r  r.  r   r@  r   )r   r   r   r  s       r   r  MatrixBase.key2ij  s     ss8q= DEE #C 46 4 (2!U';';E!KB 46 6U##;;s4y)"1--%SY/;;6s   .Cc                  ^ U R                   S:w  a  U R                  S:w  a  [        S5      eU R                  5       mU" T5      (       a(  U R	                  U R                   U R                  5      nU$ U R                  U4S j5      nU$ )a  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
r/   z'A Matrix must be a vector to normalize.c                   > U T-  $ r   r   )r   norms    r   r  'MatrixBase.normalized.<locals>.<lambda>#  s	    1t8r   )r   r   r?   r$  r  r  )r   r2  r  r$  s      @r   
normalizedMatrixBase.normalized  sq    < 99>dii1nFGGyy{d**TYY		2C 
 ..!34C
r   c           
     0  ^ [        U R                  5       5      =(       d    S/n[        R                  U R                  ;   a  TS;   a  [        [        S U 5       6 5      $ TS:X  a  [        S U 5       6 $ T[        R                  L a"  [        U Vs/ s H  n[        U5      PM     sn6 $ T[        R                  L a"  [        U Vs/ s H  n[        U5      PM     sn6 $  [        [        U4S jU 5       6 [        R                  T-  5      $ TS:X  aY  U R!                  [        5      n[        [#        UR$                  5       Vs/ s H  n['        UR)                  U5      5      PM     sn6 $ TS:X  a  [        U R+                  5       6 $ TS	:X  a  [        U R+                  5       6 $ T[        R                  L aY  U R!                  [        5      n[        [#        UR,                  5       Vs/ s H  n['        UR/                  U5      5      PM     sn6 $ Tb)  [1        T[2        5      (       a1  TR5                  5       S
;   a  U R7                  5       R9                  SS9$ [        S5      es  snf s  snf ! [        [        4 a    [        S5      ef = fs  snf s  snf )a  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
r   r  Nc              3  >   #    U  H  n[        U5      S -  v   M     g7fr)  r  r&  s     r   r   "MatrixBase.norm.<locals>.<genexpr>^  s     !<t!#a&A+tr  r/   c              3  8   #    U  H  n[        U5      v   M     g 7fr   r+  r&  s     r   r   r,  a  s     2TSVVTr  c              3  @   >#    U  H  n[        U5      T-  v   M     g 7fr   r+  )r   r   ords     r   r   r,  l  s      =1Q3r  z'Expected order to be Number, Symbol, oor  )r  fro	frobeniusvector)r/  zMatrix Norms under development)r   r  r#   Oner   r    r   Infinityr   r  NegativeInfinityr   r-   r   r+  r>  r  r   r   r  r   r  r   r   r%  rr  r  rc  r$  )r   r/  rz  r   r  s    `   r   r$  MatrixBase.norm&  s*   j DKKM")qc55DJJiC!<t!<=>>2T233

"T2TSVT233***T2TSVT233L3 = =>LL axNN3'E!&&MBMqSq]MBCCD00233D00233

"NN3'E!&&MBMqSq]MBCC+C,/"1 "158YY[364 xxz1-- **JKKK 3 3 (3 L !JKKL C Cs$   I%I*!,I/ $J)$J/Jc                d   / n[        U R                  5       H{  n/ n[        U R                  5       H:  nXU4   S:X  a  UR                  S5        M   UR                  [	        U5      5        M<     UR                  SSR                  U5      -  5        M}     [        SR                  U5      5        g)a&  Shows location of non-zero entries for fast shape lookup.

Examples
========

>>> from sympy 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]

r    z[%s] 
N)r   r   r   r   rr  joinprint)r   symbr  r   liner   s         r   print_nonzeroMatrixBase.print_nonzero  s    . tyy!AD499%1:?KK$KKD	*	 &
 HHVbggdm+, " 	diilr   c                L    XR                  U5      UR                  U5      -  -  $ )a  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  )r   r  s     r   projectMatrixBase.project  s"     HHQK!%%(*++r   c                ^   [         R                  U R                  ;   a  g/ nS/U R                  -  n[	        U R
                  5       Hr  n	UR                  / 5        [	        U R                  5       HE  n
UR                  X	U
4   5      nUS   R                  U5        [        [        U5      X   5      X'   MG     Mt     SSSSSSS.U   n[        U5       HF  u  p[        U5       H  u  p[        X5      " X   5      X'   M     X%R                  U5      -   U-   Xy'   MH     UR                  U5      $ )a  
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, 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}
z[]r   r  ljustrjustcenter)r  r  rH  <>^)r#   r  r   r   r   r   r   _printr  r   r-  r  r<  )r   rx  rowstartrowendrv  colsepalignresmaxlenr   r   r  r   elems                 r   rw  MatrixBase.table  s   d 66TZZtyytyy!AJJrN499%NN41:.Bq!A	2	 & " 
   nFA$S> -fi8 *C 0069CF % {{3r   c                    [        XUS9$ rn  )r~   ro  s      r   rank_decompositionMatrixBase.rank_decomposition
  s    "4!# 	#r   c                    [        S5      eNz;This function is implemented in DenseMatrix or SparseMatrixr   r   r  s     r   choleskyMatrixBase.cholesky      !"_``r   c                    [        S5      erY  r   rZ  s     r   LDLdecompositionMatrixBase.LDLdecomposition  r]  r   c                    [        XUUS9$ N)r2  r  	rankcheck)r   r   r2  r  rc  s       r   LUdecompositionMatrixBase.LUdecomposition  s    h#% 	%r   c                    [        XX#S9$ rb  )r   rd  s       r   LUdecomposition_Simple!MatrixBase.LUdecomposition_Simple  s    &t!8 	8r   c                    [        U 5      $ r   )r   r   s    r   LUdecompositionFFMatrixBase.LUdecompositionFF  s    !$''r   c                    [        U 5      $ r   )r   r   s    r   singular_value_decomposition'MatrixBase.singular_value_decomposition!  s    ,T22r   c                    [        U 5      $ r   )r   r   s    r   QRdecompositionMatrixBase.QRdecomposition$  r  r   c                    [        U 5      $ r   )r   r   s    r   upper_hessenberg_decomposition)MatrixBase.upper_hessenberg_decomposition'  s    .t44r   c                    [        X5      $ r   )rW   r   rs  s     r   diagonal_solveMatrixBase.diagonal_solve*      t))r   c                    [        S5      erY  r   rw  s     r   lower_triangular_solve!MatrixBase.lower_triangular_solve-  r]  r   c                    [        S5      erY  r   rw  s     r   upper_triangular_solve!MatrixBase.upper_triangular_solve0  r]  r   c                    [        X5      $ r   )rZ   rw  s     r   cholesky_solveMatrixBase.cholesky_solve3  rz  r   c                    [        X5      $ r   )r[   rw  s     r   LDLsolveMatrixBase.LDLsolve6  s    ##r   c                    [        XUS9$ r1  )r\   )r   rs  r2  s      r   LUsolveMatrixBase.LUsolve9  s    j99r   c                    [        X5      $ r   )r]   r  s     r   QRsolveMatrixBase.QRsolve<  s      r   c                    [        XUS9$ )N)freevar)r^   )r   r/  r  s      r   gauss_jordan_solveMatrixBase.gauss_jordan_solve?  s    "4G<<r   c                    [        XUS9$ )N)arbitrary_matrix)r_   )r   r/  r  s      r   
pinv_solveMatrixBase.pinv_solveB  s    45EFFr   c                    [        XUS9$ )N)
det_method)r`   )r   rs  r  s      r   cramer_solveMatrixBase.cramer_solveE  s    T:>>r   c                    [        XUS9$ rJ  )ra   r   rs  r  s      r   r  MatrixBase.solveH  s    d//r   c                    [        XUS9$ rJ  )rb   r  s      r   solve_least_squaresMatrixBase.solve_least_squaresK  s    #Df==r   c                    [        XS9$ rJ  )rc   rL  s     r   pinvMatrixBase.pinvN  s    T))r   c                    [        XS9$ r1  )rd   r4  s     r   inverse_ADJMatrixBase.inverse_ADJQ      44r   c                    [        XS9$ r1  )rk   r4  s     r   inverse_BLOCKMatrixBase.inverse_BLOCKT  s    $66r   c                    [        XS9$ r1  )re   r4  s     r   
inverse_GEMatrixBase.inverse_GEW      t33r   c                    [        XS9$ r1  )rf   r4  s     r   
inverse_LUMatrixBase.inverse_LUZ  r  r   c                    [        XS9$ r1  )rg   r4  s     r   
inverse_CHMatrixBase.inverse_CH]  r  r   c                    [        XS9$ r1  )rh   r4  s     r   inverse_LDLMatrixBase.inverse_LDL`  r  r   c                    [        XS9$ r1  )ri   r4  s     r   
inverse_QRMatrixBase.inverse_QRc  r  r   c                    [        XUUS9$ )N)r  r2  try_block_diag)rj   )r   r  r2  r  s       r   r  MatrixBase.invf  s    DJ-/ 	/r   c                    [        U 5      $ r   )r   r   s    r   connected_componentsMatrixBase.connected_componentsj  s    $T**r   c                    [        U 5      $ r   )r   r   s    r   "connected_components_decomposition-MatrixBase.connected_components_decompositionm  s    2488r   c                    [        U 5      $ r   )r   r   s    r   strongly_connected_components(MatrixBase.strongly_connected_componentsp  s    -d33r   c                    [        XS9$ )N)r  )r   )r   r  s     r   +strongly_connected_components_decomposition6MatrixBase.strongly_connected_components_decompositions  s    ;DNNr   r   )r   )TTr  )r  r   r   )NN)returnr9   )T)   Nd   FFNF)TNTTTTTT)r   r!  )r!  )FTNr(  )r  )bareissN)r   )r|  NNNN)F)FFF)r  r=   )r  )[rL  r;  rK  r  )laplace)GJ)CH)RD(  __name__
__module____qualname____firstlineno____doc___op_priority__array_priority__r  _class_prioritystaticmethodr   r   r#   r  r   r4  rx  r   __annotations__r1   classmethodr   r   r   propertyr   r   r   r   r   r   r   r   r   r   r   r  r	  r  r  r  r  r   r2  r5  r;  r+   rC  rF  r8  r  r   r?  rV  rY  r`  rc  ri  rl  rs  r{  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r  r&  r-  r3  r:  r@  rH  rP  r_  rf  r  r  r  rz  r}  r  r  r  r  r  r  rf  r  rg  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r  r-  r4  r8  r	   rD  rS  ry  r  rf  r  r  rn  r  rt  r{  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r7   r  r  r  r  r  r  r  r  r  r  r  r  r  r%  r,  r)  rC   r5  r8  rB   r;  r>  rA  rF  rM  rw  r  rU  rX  r[  r^  ra  rd  rD   rE   rL   rM   rN   rO   rP   rK   rF   rG   rH   rI   rJ   rQ   rR   rh  rk  rp  rt  ry  rT   rS   rU   rV   r  r  r  r  r  r  r  r  r  r  r  r  r  rl   rm   rn   ro   r  r  r  r  r  r  r  r  r  r  r  r  r  r  rp   rq   rt   ru   rv   rw   rx   ry   rz   r{   r|   r}   rr   rs   r   r  r  r  r  r   r  r  r  r$  r  r3  r6  r:  r=  rC  rF  rI  rO  rR  rV  rU  objectr`  rc  r  rs  ry  r  r  r  r  r  r  rw  r  r  r  r  r  r  r  r  r&   r  r   r'   r  r  r  r&  r$  r@  rC  rw  rV  r[  r_  re  rh  rk  rn  rq  rt  rx  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   _sage_r~   r   r   r   r   r   r   r   r   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   ra   rb   rc   rd   re   rf   rg   rh   ri   rk   rj   r   r   r   r   __static_attributes__r   r   r   r   r   c   s   5 L IOG$H66D
%%CIt
I
IIE EEE & &":
	C	04*:
E	0; . .	.'''1R*@,<6|,4 * *&46'(1T*>0)d(" 3 3"#>2 40)d * ** + + 6 6
 + +" + +
 H H 	 	  %dD K: K:Z + +. _@g _@ _@B , ,( - -. '+ '+T %( %(T4(-;JA H@FQJJNNGHBE(2 ) ))2E6N)(V /; /;b /; /;b C CB ( (
 0 08 *% *%X & &.(>1@ 0 08 )% )%V + +<#((&'&A$87669H$'.)
&89? JN;?&  2G1R	L	L@( GD+$Z>A*"$!&F        +:">
=$6L$6LM@7R7
	 -4MMT  :& '$ >*) +) =)# *#3 :&$ '$<#"J84) :& '\| 9%# &# <($ )$ 9%% &% "D 9% & :& ' ,E 9$ '. G". ",? 745@1, ,B+I+I"+G+O+O (+7+?+?+9+A+A(1(9(9N+7+?+?+2??L+/<<+4+<+<H+4+<+<H+4+<+<H+;+C+CO+/<<CK+/<<CK+1>>EM+;+C+CO&-5 ) ! ! & E2( &d:
 )00L&..J ==DL ==DL5&n666666M<M<5 "'7 J24 )00K&..I%--H*22M'6MV 04 0I%1< + + / / + + / / $ $K/& *4););I)4)<)<J);)C)C)5)=)=K)>)F)F )B)J)J$)>)F)F )B)J)J$)7)?)?M)5)=)=K)9)A)AO)9)A)AO)7)?)?M)B)J)J$#' 85F68@t8. $)?=P ",'&/P3"%(>&/*=< $ $P( %4 /%$B1
D ' 'R : :  a% a%FDL;0<""4H5nM^ (" ("TdL&P%3P\~!#F%3N " Pd:":<( %, %NcLJ D,  ?C!(K Z -4e #aa *14%
 18$8
(3&5*aa*$ '. :!=G?0>* &- 5 (/ 7 %, 4 %, 4 %, 4 &- 5 %, 4 '% /+94O \\F%8%@%@%.%6%6H%6%>%>%5%=%=O%<%D%D"%7%?%?+H+P+P (%5%=%=O-L-T-T"*%4%<%<N%<%D%D"%<%D%D"%4%<%<N%.%6%6H%-%5%5GO%-%5%5GO%8%@%@%0%8%8J%2%:%:L%+^^EM%9%A%A%*]]DL%-%5%5K%,__J%,__J%,__J%-%5%5K%,__J%/%7%7M%)\\CK%:%B%B +33 '. 	'.. ") 	5<< 077r   r   c                    SSK Jn  [        USS5      (       a-  [        X5      (       d  U " / UR                  Q[        U5      P76 $ U " U5      $ )z$Convert mat to a Matrix of type typ.r   r  r  F)r  r   r  r%  r   r   )typr   r   s      r   _convert_matrixr    sD    4sK''
30K0K
 )CII)tCy))3xr   c                n    [        U SS 5      nUc  g[        U[        5      =(       a    [        U5      S:H  $ )Nr   Fr  )r  r%  rl  r   )r   r   s     r   _has_matrix_shaper    s2    E7D)E}eU#7E
a7r   c                @    [        U S5      =(       a    [        U S5      $ )Nr   r   )r  )r   s    r   _has_rows_colsr    s    5&!<geV&<<r   c                   Sn[        U[        5      (       a  U$ [        USS5      nU(       a  US4$ Uc7  [        U5      (       d  [	        U5      (       a  [        [        U 5      U5      S4$ [        U[        5      (       d  US4$ U$ )z8Convert other to a Matrix, or check for possible scalar.)Ninvalid_typer  Nr  r  )r%  r:   r  r  r  r  r  r   )r   r   INVALIDr  s       r   r  r    s     #G %##{D1I k!! U##~e'<'<"4:u5{BB eX&&'''Nr   c                   [        U SS5      n[        USS5      nSX#4;  a2  U R                  UR                  :  a  U R                  $ UR                  $  SSKn[	        XR
                  5      (       a  UR                  $ [	        XR
                  5      (       a  U R                  $  [        SU R                  < SUR                  < 35      e! [         a     N3f = f)a  
Get the type of the result when combining matrices of different types.

Currently the strategy is that immutability is contagious.

Examples
========

>>> from sympy import Matrix, ImmutableMatrix
>>> from sympy.matrices.matrixbase import classof
>>> M = Matrix([[1, 2], [3, 4]]) # a Mutable Matrix
>>> IM = ImmutableMatrix([[1, 2], [3, 4]])
>>> classof(M, IM)
<class 'sympy.matrices.immutable.ImmutableDenseMatrix'>
r  Nr   zIncompatible classes rK  )r  r  r  numpyr%  ndarrayImportErrorr+  )r+  r/  
priority_A
priority_Br  s        r   r   r     s      -t4J-t4JJ++q000;;;; a'';;a'';; ( Q[[!++N
OO  s   C 
CCc                    [        X5      u  pUS:X  a?  [        X5      nX0R                  :w  a  [        X05      n X1R                  :w  a  [        X15      nXU4$ )zDUnify self and other into a single matrix type, or check for scalar.r  )r  r   r  r  )r   r   r  r  s       r   r  r    sR    t+HEKd".. "3-D//!#C/E>r   c                    [        U [        5      (       d(  [        U SS5      nUb  U" 5       n O[        SU < S35      eUb%  U S:  a  X-  n U S:  a  X:  d  [        SU < S35      e[        U 5      $ )z>Return integer after making positive and validating against n.	__index__NzInvalid index a[rL  r   zIndex out of range: a[)r%  r   r  r  )r   r  jindexs      r   r.  r.    sm    aK.Aa9::}q5FAQ15A?@@q6Mr   c                  *    \ rS rSrSrS rS rS rSrg)r  i  a	  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                l    US:X  a  SnUS:  a  [        S5      eSU R                  U4-  n[        U5      $ )Nr   z!DeferredVector index out of rangez%s[%d])r  namer   )r   r   component_names      r   r   DeferredVector.__getitem__(  s>    7Aq5@AA!TYYN2n%%r   c                    [        U 5      $ r   r   r   s    r   rs  DeferredVector.__str__0  rH  r   c                     SU R                   -  $ )NzDeferredVector('%s'))r  r   s    r   __repr__DeferredVector.__repr__3  s    %		11r   r   N)	r  r  r  r  r  r   rs  r  r  r   r   r   r  r    s    &2r   r  r   )
__future__r   collectionsr   collections.abcr   inspectr   	functoolsr   sympy.assumptions.refiner	   
sympy.corer
   r   sympy.core.basicr   r   sympy.core.kindr   sympy.core.numbersr   sympy.core.modr   sympy.core.symbolr   r   sympy.core.sympifyr   r   sympy.core.functionr   sympy.polysr   $sympy.functions.elementary.complexesr   r   r   sympy.printingr   (sympy.functions.elementary.miscellaneousr   r   r    (sympy.functions.special.tensor_functionsr!   r"   sympy.core.singletonr#   sympy.printing.defaultsr$   sympy.printing.strr%   &sympy.functions.elementary.exponentialr&   r'   (sympy.functions.combinatorial.factorialsr(   r)   mpmathr  r*   sympy.utilities.iterablesr+   sympy.core.exprr,   sympy.core.powerr-   r.   	utilitiesr0   r1   rw  sympy.polys.polytoolsr2   r3   r4   sympy.utilities.miscr5   r6   sympy.core.decoratorsr7   sympy.core.logicr8   r9   sympy.tensor.arrayr:   r;   r<   rV  r=   
exceptionsr>   r?   r@   rA   rB   rC   determinantrD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   
reductionsrS   rT   rU   rV   solversrW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   ra   rb   inverserc   rd   re   rf   rg   rh   ri   rj   rk   	subspacesrl   rm   rn   ro   r  rp   rq   rr   rs   rt   ru   rv   rw   rx   ry   rz   r{   r|   r}   decompositionsr~   r   r   r   r   r   r   r   r   graphr   r   r   r   __doctest_requires__r   r  r  r  r  r   r  r.  r  r   r   r   <module>r)     sk   " # $   + ( ( ) &  + 0 $  < <  C C O " - ) ; H  $ -     3 E & : 3 7 1 ( 1 2   :     A @> > > >
   K J6 6 6 6V V V
R R, /;^ |P= |P=~a
8=6"PJ 2V[ 2r   