
    EdU                        d dl mZ d dlmZ d dlmZ d dlmZm	Z	m
Z
 d dlmZmZ d dlmZmZ d dlmZ d dlmZmZmZ d d	lmZ d d
lmZ d dlmZ d dlmZ ddlm Z  ddl!m"Z"m#Z#m$Z$  G d de"          Z% G d de%          Z&d Z'dS )    )defaultdict)index)Expr)Kind
NumberKindUndefinedKind)IntegerRational)_sympifySympifyError)S)ZZQQEXRAW)DomainMatrix)sympy_deprecation_warning)is_sequence)
filldedent   )classof)
MatrixBase
MatrixKind
ShapeErrorc                   D   e Zd ZU dZeed<   d Zed             Zed             Z	ed             Z
ed             Zd Zd	 Zd
 Zd Zd Zedefd            Zd Zd Zd Zd Zd Zd Zd Zd Zed             Zed             Zd Zd Zd Z d Z!d Z"d Z#d Z$d#d!Z%d"S )$	RepMatrixa<  Matrix implementation based on DomainMatrix as an internal representation.

    The RepMatrix class is a superclass for Matrix, ImmutableMatrix,
    SparseMatrix and ImmutableSparseMatrix which are the main usable matrix
    classes in SymPy. Most methods on this class are simply forwarded to
    DomainMatrix.
    _repc                     t          |t                    sD	 t          |          }n# t          $ r
 t          cY S w xY wt          |t                    st          S | j                            |j                  S N)
isinstancer   r   r   NotImplementedr   unify_eqselfothers     8lib/python3.11/site-packages/sympy/matrices/repmatrix.py__eq__zRepMatrix.__eq__2   s}    %++ 	&&  & & &%%%%&eY// &%%y!!%*---s   ' ;;c                 l   |j         }t          |          }|t          k    r]|j        r|}n|j        rt
          }nt          }||k    r|                    |          }|}|t          k    r|                    |          }|t          k    r(t          |t                    st          dddd           ||fS )N+  
                non-Expr objects in a Matrix is deprecated. Matrix represents
                a mathematical matrix. To represent a container of non-numeric
                entities, Use a list of lists, TableForm, NumPy array, or some
                other data structure instead.
                1.9deprecated-non-expr-in-matrix   deprecated_since_versionactive_deprecations_target
stacklevel)domainr   r   
is_Integeris_Rationalr   
convert_to
from_sympyr   r   r   )clsrepelementr0   
new_domains        r%   _unify_element_sympyzRepMatrix._unify_element_sympy>   s    7##U? 	9! ##

$ #

"

 V# $nnZ00# 9$//88U? 	:gt#<#< 	% */+J
 
 
 
 G|    c                 \   t          d |D                       st          dddd           t          |||ft                    }t          d |D                       rNt          d |D                       r|                    t
                    }n|                    t                    }|S )	Nc              3   @   K   | ]}t          |t                    V  d S r   )
issubclassr   .0typs     r%   	<genexpr>z1RepMatrix._dod_to_DomainMatrix.<locals>.<genexpr>h   s,      ::S:c4((::::::r:   r(   r)   r*      r,   c              3   @   K   | ]}t          |t                    V  d S r   )r=   r
   r>   s     r%   rA   z1RepMatrix._dod_to_DomainMatrix.<locals>.<genexpr>w   s,      ::Sz#x((::::::r:   c              3   @   K   | ]}t          |t                    V  d S r   )r=   r	   r>   s     r%   rA   z1RepMatrix._dod_to_DomainMatrix.<locals>.<genexpr>x   s,      ==:c7++======r:   )allr   r   r   r3   r   r   )r5   rowscolsdodtypesr6   s         r%   _dod_to_DomainMatrixzRepMatrix._dod_to_DomainMatrixe   s     ::E::::: 	% */+J
 
 
 
 3te44::E::::: 	)==u===== )nnR((nnR((
r:   c                    t          t                    }t          |          D ])\  }}|dk    rt          ||          \  }}|||         |<   *t	          t          t          |                    }	|                     ||||	          }
|
S Nr   )r   dict	enumeratedivmodsetmaptyperJ   )r5   rF   rG   	flat_listelements_dodnr7   ijrI   r6   s              r%   _flat_list_to_DomainMatrixz$RepMatrix._flat_list_to_DomainMatrix   s     #4((#I.. 	- 	-JAw!| -a1%,Q"Ci(())&&tT<GG
r:   c                 "   t          t                    }|                                D ]\  \  }}}|dk    r|||         |<   t          t	          t
          |                                                    }|                     ||||          }	|	S rL   )r   rM   itemsrP   rQ   rR   valuesrJ   )
r5   rF   rG   smatrT   rV   rW   r7   rI   r6   s
             r%   _smat_to_DomainMatrixzRepMatrix._smat_to_DomainMatrix   s     #4((#zz|| 	- 	-OFQG!| -%,Q"Cdkkmm,,--&&tT<GG
r:   c                 X    | j                                                                         S r   )r   to_sympyto_list_flatr#   s    r%   flatzRepMatrix.flat   s"    y!!##00222r:   c                 X    | j                                                                         S r   )r   r_   to_listra   s    r%   _eval_tolistzRepMatrix._eval_tolist   s"    y!!##++---r:   c                 X    | j                                                                         S r   )r   r_   to_dokra   s    r%   _eval_todokzRepMatrix._eval_todok   s"    y!!##**,,,r:   c                 h    t          |                                                                           S r   )listtodokr[   ra   s    r%   _eval_valueszRepMatrix._eval_values   s$    DJJLL''))***r:   c                 Z    |                      | j                                                  S r   _fromrepr   copyra   s    r%   rp   zRepMatrix.copy        }}TY^^--...r:   returnc                 2   | j         j        }|t          t          fv rt          }ne|t
          k    rKt          d |                                 D                       }t          |          dk    r|\  }nt          }nt          d          t          |          S )Nc              3   $   K   | ]}|j         V  d S r   )kind)r?   es     r%   rA   z!RepMatrix.kind.<locals>.<genexpr>   s$      661666666r:   r   z%Domain should only be ZZ, QQ or EXRAW)r   r0   r   r   r   r   rP   r[   lenr   RuntimeErrorr   )r#   r0   element_kindkindss       r%   ru   zRepMatrix.kind   s    !b"X 		H%LLu_ 	H6666666E5zzQ -!&,FGGG,'''r:   c                     d}|                                  }t          |          | j        | j        z  k    rt	          j        j         }|p,t          fd|                                D                       S )NFc              3   ,   K   | ]} |j          V  d S r   )has)r?   valuepatternss     r%   rA   z&RepMatrix._eval_has.<locals>.<genexpr>   s,      JJE959h/JJJJJJr:   )	rk   rw   rF   rG   r   Zeror}   anyr[   )r#   r   zhasdoks    `  r%   	_eval_haszRepMatrix._eval_has   sq     jjlls88ty** 	)6:x(DJsJJJJSZZ\\JJJJJJr:   c                      t           fdt           j                  D                       sdS t                                                      j        k    S )Nc              3   4   K   | ]}||f         d k    V  dS )r   N )r?   rV   r#   s     r%   rA   z.RepMatrix._eval_is_Identity.<locals>.<genexpr>   s/      ==q41:?======r:   F)rE   rangerF   rw   rk   ra   s   `r%   _eval_is_IdentityzRepMatrix._eval_is_Identity   sT    ====E$),<,<===== 	54::<<  DI--r:   c                     | | j         z
                      |          }t          |                                          dk    S rL   )T	applyfuncrw   r[   )r#   simpfuncdiffs      r%   _eval_is_symmetriczRepMatrix._eval_is_symmetric   s6    tv((224;;==!!Q&&r:   c                 Z    |                      | j                                                  S )aB  Returns the transposed SparseMatrix of this SparseMatrix.

        Examples
        ========

        >>> from sympy import SparseMatrix
        >>> a = SparseMatrix(((1, 2), (3, 4)))
        >>> a
        Matrix([
        [1, 2],
        [3, 4]])
        >>> a.T
        Matrix([
        [1, 3],
        [2, 4]])
        )ro   r   	transposera   s    r%   _eval_transposezRepMatrix._eval_transpose   s$    " }}TY0022333r:   c                 f    |                      | j                            |j                            S r   )ro   r   vstackr"   s     r%   _eval_col_joinzRepMatrix._eval_col_join   &    }}TY--ej99:::r:   c                 f    |                      | j                            |j                            S r   )ro   r   hstackr"   s     r%   _eval_row_joinzRepMatrix._eval_row_join   r   r:   c                 ^    |                      | j                            ||                    S r   )ro   r   extract)r#   rowsListcolsLists      r%   _eval_extractzRepMatrix._eval_extract   s&    }}TY..xBBCCCr:   c                 "    t          | |          S r   )_getitem_RepMatrix)r#   keys     r%   __getitem__zRepMatrix.__getitem__   s    !$,,,r:   c                 d    t          j        ||ft                    }|                     |          S r   )r   zerosr   ro   r5   rF   rG   r6   s       r%   _eval_zeroszRepMatrix._eval_zeros   s*     $r22||C   r:   c                 d    t          j        ||ft                    }|                     |          S r   )r   eyer   ro   r   s       r%   	_eval_eyezRepMatrix._eval_eye   s*    d|R00||C   r:   c                 b    t          | |                              | j        |j        z             S r   r   ro   r   r"   s     r%   	_eval_addzRepMatrix._eval_add   )    tU##,,TY-CDDDr:   c                 b    t          | |                              | j        |j        z            S r   r   r"   s     r%   _eval_matrix_mulzRepMatrix._eval_matrix_mul   r   r:   c                     | j                             |j                   \  }}|                    |          }t          | |                              |          S r   )r   unifymul_elementwiser   ro   )r#   r$   selfrepotherrepnewreps        r%   _eval_matrix_mul_elementwisez&RepMatrix._eval_matrix_mul_elementwise   sM     IOOEJ77((22tU##,,V444r:   c                     |                      | j        |          \  }}|                     |                    |                    S r   )r9   r   ro   	scalarmulr#   r$   r6   s      r%   _eval_scalar_mulzRepMatrix._eval_scalar_mul   s;    ..ty%@@
U}}S]]511222r:   c                     |                      | j        |          \  }}|                     |                    |                    S r   )r9   r   ro   
rscalarmulr   s      r%   _eval_scalar_rmulzRepMatrix._eval_scalar_rmul  s;    ..ty%@@
U}}S^^E22333r:   c                 f    |                      | j                            t                              S r   )ro   r   r   absra   s    r%   	_eval_AbszRepMatrix._eval_Abs  s$    }}TY0055666r:   c                     | j         }|j        }|t          t          fv r|                                 S |                     |                    d                     S )Nc                 *    |                                  S r   )	conjugate)rv   s    r%   <lambda>z+RepMatrix._eval_conjugate.<locals>.<lambda>  s     r:   )r   r0   r   r   rp   ro   r   )r#   r6   r0   s      r%   _eval_conjugatezRepMatrix._eval_conjugate  sR    ib"X 	I99;;==/F/F!G!GHHHr:   Fc                    | j         t          |dd          k    rdS d}t          | j                  D ]Q}t          | j                  D ]:}| ||f                             |||f         |          }|du r  dS |dur|du r|};R|S )a1  Applies ``equals`` to corresponding elements of the matrices,
        trying to prove that the elements are equivalent, returning True
        if they are, False if any pair is not, and None (or the first
        failing expression if failing_expression is True) if it cannot
        be decided if the expressions are equivalent or not. This is, in
        general, an expensive operation.

        Examples
        ========

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

        See Also
        ========
        sympy.core.expr.Expr.equals
        shapeNFT)r   getattrr   rF   rG   equals)r#   r$   failing_expressionrvrV   rW   anss          r%   r   zRepMatrix.equals  s    8 :666 	5ty!! 	 	A49%%  1a4j''ad5GHH%<  555_ t B 	r:   N)F)&__name__
__module____qualname____doc__r   __annotations__r&   classmethodr9   rJ   rX   r]   rb   re   rh   rl   rp   propertyr   ru   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r:   r%   r   r      sV         6 
. 
. 
. $ $ [$L   [2   [ 
 
 [
3 3 3. . .- - -+ + +/ / / (j ( ( ( X(K K K. . .
' ' '4 4 4&; ; ;; ; ;D D D- - - ! ! [! ! ! [!E E EE E E5 5 5
3 3 34 4 47 7 7I I I' ' ' ' ' 'r:   r   c                        e Zd ZdZdZd Zeddd            Ze fd            Zd Z	d	 Z
d
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z xZS )MutableRepMatrixzCMutable matrix based on DomainMatrix as the internal representationFc                      | j         |i |S r   )_new)r5   argskwargss      r%   __new__zMutableRepMatrix.__new__H  s    sx((((r:   Trp   c                    |du r)t          |          dk    rt          d          |\  }}}n  | j        |i |\  }}}t          |          }|                     |||          }|                     |          S )NF   zA'copy=False' requires a matrix be initialized as rows,cols,[list])rw   	TypeError_handle_creation_inputsrj   rX   ro   )r5   rp   r   r   rF   rG   rS   r6   s           r%   r   zMutableRepMatrix._newK  s    5= 	( 4yyA~ e cddd$(!D$		$?C$?$P$P$P!D$	YI,,T4CC||C   r:   c                     t                                          |           }|j        \  |_        |_        ||_        |S r   )superr   r   rF   rG   r   )r5   r6   obj	__class__s      r%   ro   zMutableRepMatrix._fromrep[  s4    ggooc"" Y#(
r:   c                 Z    |                      | j                                                  S r   rn   ra   s    r%   rp   zMutableRepMatrix.copyb  rq   r:   c                 *    |                                  S r   r   ra   s    r%   
as_mutablezMutableRepMatrix.as_mutablee  s    yy{{r:   c                     |                      ||          }|L|\  }}}|                     | j        |          \  | _        }| j        j                            |||           dS dS )a@  

        Examples
        ========

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

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

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

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

        >>> M[2] = ones(m, 1)*4; M
        Matrix([
        [0, 0, 4, 0],
        [0, 0, 4, 0],
        [0, 0, 4, 0],
        [2, 2, 4, 2]])
        N)_setitemr9   r   r6   setitem)r#   r   r~   r   rV   rW   s         r%   __setitem__zMutableRepMatrix.__setitem__h  su    P ]]3&& 	/KAq%#88EJJDIuIM!!!Q.....	/ 	/r:   c                     t          j        | j        d d d |f         | j        d d |dz   d f                   | _        | xj        dz  c_        d S Nr   )r   r   r   rG   )r#   cols     r%   _eval_col_delzMutableRepMatrix._eval_col_del  sS     '	!!!DSD&(949QQQs1uvvX;NOO			Q				r:   c                     t          j        | j        d |d d f         | j        |dz   d d d f                   | _        | xj        dz  c_        d S r   )r   r   r   rF   )r#   rows     r%   _eval_row_delzMutableRepMatrix._eval_row_del  sS     '	$3$qqq&(949SUVVQQQY;OPP			Q				r:   c                     |                      |          }|                     | d d d |f         || d d |d f                   S r   )r   r   )r#   r   r$   s      r%   _eval_col_insertz!MutableRepMatrix._eval_col_insert  sI    		%  {{4$3$<QQQsttV===r:   c                     |                      |          }|                     | d |d d f         || |d d d f                   S r   )r   r   )r#   r   r$   s      r%   _eval_row_insertz!MutableRepMatrix._eval_row_insert  sI    		%  {{4QQQ<STT!!!V===r:   c                 f    t          | j                  D ]} || ||f         |          | ||f<   dS )a  In-place operation on col j using two-arg functor whose args are
        interpreted as (self[i, j], i).

        Examples
        ========

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

        See Also
        ========
        col
        row_op
        Nr   rF   )r#   rW   frV   s       r%   col_opzMutableRepMatrix.col_op  sJ    ( ty!! 	* 	*A41:q))DAJJ	* 	*r:   c                 t    t          d| j                  D ]!}| ||f         | ||f         c| ||f<   | ||f<   "dS )a  Swap the two given columns of the matrix in-place.

        Examples
        ========

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

        See Also
        ========

        col
        row_swap
        r   Nr   r#   rV   rW   ks       r%   col_swapzMutableRepMatrix.col_swap  W    0 q$)$$ 	< 	<A%)!Q$Zad"DAJQT

	< 	<r:   c                 f    t          | j                  D ]} || ||f         |          | ||f<   dS )a  In-place operation on row ``i`` using two-arg functor whose args are
        interpreted as ``(self[i, j], j)``.

        Examples
        ========

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

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

        Nr   rG   )r#   rV   r   rW   s       r%   row_opzMutableRepMatrix.row_op  sJ    , ty!! 	* 	*A41:q))DAJJ	* 	*r:   c                 t    t          d| j                  D ]!}| ||f         | ||f         c| ||f<   | ||f<   "dS )a  Swap the two given rows of the matrix in-place.

        Examples
        ========

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

        See Also
        ========

        row
        col_swap
        r   Nr   r   s       r%   row_swapzMutableRepMatrix.row_swap  r   r:   c                 v    t          | j                  D ]#} || ||f         | ||f                   | ||f<   $dS )a  In-place operation on row ``i`` using two-arg functor whose args are
        interpreted as ``(self[i, j], self[k, j])``.

        Examples
        ========

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

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

        Nr   )r#   rV   r   r   rW   s        r%   
zip_row_opzMutableRepMatrix.zip_row_op  sR    , ty!! 	3 	3A41:tAqDz22DAJJ	3 	3r:   c                     t          |          st          dt          |          z            |                     | t          |           |                    S )ai  Copy in elements from a list.

        Parameters
        ==========

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

        Examples
        ========

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

        See Also
        ========

        copyin_matrix
        z,`value` must be an ordered iterable, not %s.)r   r   rR   copyin_matrix)r#   r   r~   s      r%   copyin_listzMutableRepMatrix.copyin_list%  sW    D 5!! 	ZJTRW[[XYYY!!#ztDzz%'8'8999r:   c                 *   |                      |          \  }}}}|j        }||z
  ||z
  }	}|||	fk    rt          t          d                    t	          |j                  D ].}
t	          |j                  D ]}||
|f         | |
|z   ||z   f<   /dS )a  Copy in values from a matrix into the given bounds.

        Parameters
        ==========

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

        Examples
        ========

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

        See Also
        ========

        copyin_list
        zXThe Matrix `value` doesn't have the same dimensions as the in sub-Matrix given by `key`.N)
key2boundsr   r   r   r   rF   rG   )r#   r   r~   rlorhiclochir   drdcrV   rW   s               r%   r  zMutableRepMatrix.copyin_matrixK  s    F "__S11S#ssC#IBRH 	QZ )O P P Q Q Q uz"" 	5 	5A5:&& 5 5).q!tQWa#g%&&5	5 	5r:   c                      t                    s&t          j         j        t                     _        dS  fdt           j                  D             }t          | j        t                     _        dS )aN  Fill self with the given value.

        Notes
        =====

        Unless many values are going to be deleted (i.e. set to zero)
        this will create a matrix that is slower than a dense matrix in
        operations.

        Examples
        ========

        >>> from sympy import SparseMatrix
        >>> M = SparseMatrix.zeros(3); M
        Matrix([
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0]])
        >>> M.fill(1); M
        Matrix([
        [1, 1, 1],
        [1, 1, 1],
        [1, 1, 1]])

        See Also
        ========

        zeros
        ones
        c                 R    i | ]#}|fd t          j                  D             $S )c                     i | ]}|S r   r   )r?   rW   r~   s     r%   
<dictcomp>z4MutableRepMatrix.fill.<locals>.<dictcomp>.<dictcomp>  s    CCCQ5CCCr:   r   )r?   rV   r#   r~   s     r%   r  z)MutableRepMatrix.fill.<locals>.<dictcomp>  s:    ^^^ACCCC%	2B2BCCC^^^r:   N)r   r   r   r   r   r   r   rF   )r#   r~   rT   s   `` r%   fillzMutableRepMatrix.fillz  su    >  	F$*4:u==DIII^^^^^USWS\M]M]^^^L$\4:uEEDIIIr:   )r   r   r   r   is_zeror   r   r   ro   rp   r   r   r   r   r   r   r   r   r  r  r  r  r  r  __classcell__)r   s   @r%   r   r   =  ss       MM G) ) ) " ! ! ! ! [!     [/ / /  ,/ ,/ ,/\    > > >> > >* * *.< < <6* * *2< < <63 3 32$: $: $:L-5 -5 -5^$F $F $F $F $F $F $Fr:   r   c                   	
 t          |t                    r|\  }}	 | j                            t	          |          t	          |                    S # t
          t          f$ r1 t          |t                    r|j        rt          |t                    ra|j        sZ|dk     du s.|| j	        d         k    du s|dk     du s|| j	        d         k    du rt          d          ddlm}  || ||          cY S t          |t                    rt          | j                  |         }nt!          |          rn|g}t          |t                    rt          | j                  |         }nt!          |          rn|g}|                     ||          cY S w xY w| j	        \  }	|	z  sg |         S | j        j        

j        }t          |t                    }|r&	
fdt          |	z            |         D             }n& 
j        t-          t	          |          	           g}|t.          k    r|j        fd|D             }|r|S |d         S )a2  Return portion of self defined by key. If the key involves a slice
    then a list will be returned (if key is a single slice) or a matrix
    (if key was a tuple involving a slice).

    Examples
    ========

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

    If the key is a tuple that does not involve a slice then that element
    is returned:

    >>> m[1, 0]
    3

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

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

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

    >>> m[0]
    1
    >>> m[::2]
    [1, 3]
    r   Tr   zindex out of boundary)MatrixElementc                 @    g | ]} j         t          |           S r   )getitemrO   )r?   rU   rG   r6   s     r%   
<listcomp>z&_getitem_RepMatrix.<locals>.<listcomp>  s*    UUUkck6!T??3UUUr:   c                 &    g | ]} |          S r   r   )r?   valr_   s     r%   r  z&_getitem_RepMatrix.<locals>.<listcomp>  s!    666hhsmm666r:   )r   tupler   getitem_sympyindex_r   
IndexErrorr   	is_numberr   
ValueError"sympy.matrices.expressions.matexprr  slicer   rF   r   rG   r   r6   r0   r  rO   r   r_   )r#   r   rV   rW   r  rF   r0   is_slicer[   rG   r6   r_   s            @@@r%   r   r     s   H #u 21	&9**6!99fQii@@@:& 	& 	& 	&1d## 1AK 1Z4=P=P 1YZYd 1UtO >!tz!}*<)E >UtO>*+tz!}*<)E>$%<===LLLLLL$}T1a00000!U## $)$$Q'Q C!U## $)$$Q'Q C<<1%%%%%)	&0 Z
d d{ 	c7Nimc5)) 	?UUUUUU4$;=O=OPS=TUUUFF!ck6&++t#<#<=>FU? 	7H6666v666F 	M!9s   4A B"F9BFFN)(collectionsr   operatorr   r!  sympy.core.exprr   sympy.core.kindr   r   r   sympy.core.numbersr	   r
   sympy.core.sympifyr   r   sympy.core.singletonr   sympy.polys.domainsr   r   r   sympy.polys.matricesr   sympy.utilities.exceptionsr   sympy.utilities.iterablesr   sympy.utilities.miscr   commonr   matricesr   r   r   r   r   r   r   r:   r%   <module>r6     s   # # # # # # $ $ $ $ $ $             ; ; ; ; ; ; ; ; ; ; 0 0 0 0 0 0 0 0 5 5 5 5 5 5 5 5 " " " " " " - - - - - - - - - - - - - - - - @ @ @ @ @ @ 1 1 1 1 1 1 + + + + + +       8 8 8 8 8 8 8 8 8 8f f f f f
 f f fR	aF aF aF aF aFy aF aF aFHV V V V Vr:   