� ��gЄ���ddlmZddlmZddlmZddlmZddlm Z ddl m Z m Z ddl mZmZddlmZdd lmZdd lmZdd lmZmZdd lmZmZdd lmZddlmZddl m!Z!m"Z"m#Z#ddl$m%Z%ddl&m'Z'm(Z(m)Z)ddl*m+Z+m,Z,ddl-m.Z.ddl/m0Z0ddl1m2Z2ddl3m4Z4m5Z5ddl6m7Z7m8Z8ddl9Z:ddlm;Z;ddl<m=Z=ddl>m?Z?ddl@mAZAddlmBZBddlCmDZDmEZFdd lGmHZHdd!l<mIZImJZJdd"lKmLZLmMZMdd#lNmOZOdd$lPmQZQmRZRdd%lSmTZTdd&l<mUZUdd'lCmVZVdd(lWmXZXdd)lYmZZZm[Z[m\Z\m]Z]dd*lCm^Z^m_Z_dd+l`maZambZbmcZcmdZdmeZemfZfmgZgmhZhmiZimjZjmkZkmlZlmmZmmnZnmoZodd,lpmqZqmrZrmsZsmtZtdd-lumvZvmwZwmxZxmyZymzZzm{Z{m|Z|m}Z}m~Z~mZm�Z�m�Z�dd.l�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�dd/l�m�Z�m�Z�m�Z�m�Z�dd0l�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�dd1l�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�dd2l�m�Z�m�Z�m�Z�m�Z�d3d4giZ�Gd5�d6e0��Z�d7�Z�d8�Z�d9�Z�d:�Z�d;�Z�d<�Z�d@d=�Z�Gd>�d?eeU��Z�dS)A�)� 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)zMatrixBase.is_indefinitezMatrixBase.is_positive_definitez#MatrixBase.is_positive_semidefinitezMatrixBase.is_negative_definitez#MatrixBase.is_negative_semidefinite� matplotlibc�|�eZdZdZdZdZdZdZee ��Z e j Z e jZdZdZdZdZed���Zd�Zd �Zed ���Zd �Zd �Zd �Zd�Zd�Zd�Zd�Z d�Z!d�Z"d�Z#ed���Z$d�Z%d�Z&d�Z'd�Z(d�Z)d�Z*d�Z+d�Z,ed���Z-d�Z.d �Z/d!�Z0d"�Z1�dHd$�Z2d%�Z3d&�Z4ed'���Z5d(�Z6d)�Z7d*�Z8�dId+�Z9ed,���Z:ed-���Z;ed.���Z<e�dJd0e=fd1���Z>ed2���Z?ed3���Z@ed4���ZAed5dddd6�d7���ZBe�dKd8���ZCe�dLd/d9�d:���ZDe�dKd;���ZEe�dKd<���ZFed=���ZGed>���ZHd?�ZId@�ZJdA�ZKdB�ZLdC�ZMdD�ZNdE�ZOdF�ZPdG�ZQdHeRfdI�ZSdJ�ZTdK�ZUdL�ZVdM�ZWdN�ZXdO�ZYdP�ZZdQ�Z[dR�Z\dS�Z]edT���Z^dU�Z_�dMdV�Z`dW�ZaedX���ZbedY���ZcedZ���ZdedHeRfd[���Zeed\���Zfed]���Zged^���Zhd_�Zi�dMd`�Zjeda���Zkedb���Zledc���Zmdd�Znde�Zodf�Zpdg�Zqdh�Zrdi�Zsdj�Ztdk�Zudl�Zvdm�Zwdn�Zxdo�Zydp�Zz�dMdq�Z{dr�Z|ds�Z}�dNdv�Z~ �dOdw�Zedx���Z��dPd{�Z��dQd|�Z��dQd}�Z��dMd~�Z��dRd�Z��dSd��Z�d��Z�d��Z�d��Z�d��Z�ed����Z�ed����Z�d��Z�d��Z�d��Z�d��Z��dHd��Z��dHd��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z��dKd��Z�d��Z�d��Z�d��Z�d��Z�e�d���d����Z�e�d���d����Z�e�d���d����Z�d��Z�e�d���d����Z��dKd��Z�d��Z�d��Z�e�d���d����Z��dKd��Z�e�d���d����Z�e�d���d����Z�e�d���d����Z��dKd��Z�e�d���d����Z�e�d���d����Z�e�fd��Z�d��Z�e�dfd��Z�d��Z�d��Z�d��Z��dTd��Z�d�e�fd��Z��dTd��Z��dTd��Z��dUd��Z�d„Z��dTdÄZ�dĄZ�e�je�_e�je�_e�je�_e�je�_e�je�_e�je�_e�je�_e�je�_e�je�_e�je�_e�je�_e�je�_e�je�_e�je�_e�je�_e�je�_e�d5d5fdńZ�edƄ��Z�e�d5fdDŽZ�dȄZ�e�d5ddfdɄZ�e�je�_e�je�_e�je�_e�je�_�dVd˄Z�d̄Z�d̈́Z�d΄Z�dτZ�dЄZ�dфZߐdWdӄZ��dWdԄZ�dXdՄZ�d5e�fdքZ�dXdׄZ�d؄Z�e�je�_e�je�_e�je�_e�je�_ee��Z�dMdلZ�de�fdڄZ�dXdۄZ�dYd܄Z�dMd݄Z�dMdބZ�ed߄��Z�ed����Z�ed���Z�ed���Z�ed���Z��dMd�Z�d�Z�d�Z�e�je�_e�je�_e�je�_e�je�_e�je�_e�je�_e�je�_e�je�_�eje�_�eje�_�eje�_�eje�_�eje�_�eje�_dd�d��Zd��Zd��Zd��Z d��Z �e d���e�fd��Z d��Z d��Zd���Zd��Z�dTd��Zd��Zd��Zd���Z�dMd���Z�dTd���Zd���Zd���Zd���ZedH�efd�����Zd���Z�edfd���Zd���Zd���Z �d��Z!�dK�d��Z"e�d����Z#e�d����Z$e�d����Z%�d��Z&�d��Z'�d��Z(�d��Z)�d ��Z*�d ��Z+�d ��Z,e�d ����Z-�dL�d ��Z.�d��Z/�d��Z0�d��Z1�d��Z2�d��Z3�e4f�d��Z5�d��Z6�d��Z7�d��Z8e�f�d��Z9�dK�d��Z:�dZ�d��Z;�d��Z< �d[�d!��Z=e�d5f�d"��Z>�dM�d#��Z?�dM�d$��Z@e�dd5f�d%��ZAe�dd5f�d&��ZB�d'��ZC�d(��ZD�d)��ZE�d*��ZF�d+��ZG�d,��ZH�d-��ZI�d.��ZJ�d/��ZKe�f�d0��ZL�d1��ZM�dX�d2��ZN�dK�d3��ZO�d\�d5��ZP�d]�d7��ZQ�d^�d9��ZR�d_�d;��ZSe�f�d<��ZTe�f�d=��ZUe�f�d>��ZVe�f�d?��ZWe�f�d@��ZXe�f�dA��ZYe�f�dB��ZZde�d5f�dC��Z[�dD��Z\�dE��Z]�dF��Z^�dM�dG��Z_�e`�ja�Za�ebj�e>_�ecj�e?_�edj�e@_�eej�eA_�efj�eB_�egj�eC_�ehj�eD_�eij�eE_�ejj�eF_�ekj�eG_�elj�eH_�emj�eI_�enj�eJ_�eoj�eK_�epj�eL_�eqj�eM_�erj�eN_�esj�eO_�etj�eP_�euj�eQ_�evj�eR_�ewj�eS_�exj�eT_�eyj�eV_�ezj�eW_�e{j�eX_�e|j�eY_�e}j�eZ_�e~j�eU_�ej�e[_�e�j�e\_�e�j�e]_�e�j�e^_�e�j�e__dS(`� MatrixBasezsAll common matrix operations including basic arithmetic, shaping, and special matrices like `zeros`, and `eye`.g��Q�$@� T�Nc� �td���)z�`_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 �i/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/sympy/matrices/matrixbase.py�_newzMatrixBase._newv��� "�"C�D�D�D�c� �td���)Nr�r���self�others r��__eq__zMatrixBase.__eq__}s��!�"C�D�D�Dr�c� �td���)aImplementations 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__zMatrixBase.__getitem__�r�r�c��|j|jfS)a The 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 ��rows�cols�r�s r��shapezMatrixBase.shape�s�� � �4�9�%�%r�c�Z�����fd�}���j�jdz |��S)Nc�>��|�kr �||fn �||dzfS�Nr.�)�i�j�colr�s ��r��entryz'MatrixBase._eval_col_del.<locals>.entry�s)���!"�S���4��1��:�:�d�1�a�!�e�8�n� <r�r.�r�r�r�)r�r�r�s`` r�� _eval_col_delzMatrixBase._eval_col_del�s@���� =� =� =� =� =� =��y�y���D�I��M�5�9�9�9r�c�h�������fd�}���j�j�jz|��S)Nc���|�kr �||fS�|cxkr��jzkrnn �||�z fS�||�jz fS�N�r�)r�r�r��posr�s ���r�r�z*MatrixBase._eval_col_insert.<locals>.entry�sl����3�w�w��A�q�D�z�!���,�,�,�,�C�%�*�,�,�,�,�,�,��Q��C��Z�(�(���1�u�z�>�)�*� *r�r�)r�r�r�r�s``` r��_eval_col_insertzMatrixBase._eval_col_insert�sK����� +� +� +� +� +� +� +��y�y���D�I�� �$:�E�B�B�Br�c������j����fd�}t������j�jz�j|��S)Nc�>��|�kr �||fS�|�z |fSr�r�)r�r�r�r�r�s ���r�r�z(MatrixBase._eval_col_join.<locals>.entry�s-����4�x�x��A�q�D�z�!���T��1��%� %r�)r��classofr�r�)r�r�r�r�s`` @r��_eval_col_joinzMatrixBase._eval_col_join�se������y�� &� &� &� &� &� &� &� �t�U�#�#�(�(���U�Z�)?���).�0�0� 0r�c������t|���|j���fd�|D��}|�t|��t����fd�|D����S)Nc3�2�K�|]}�D] }|�z|zV�� �dSr�r�)�.0r�r�r��colsLists ��r�� <genexpr>z+MatrixBase._eval_extract.<locals>.<genexpr>�s8�����D�D�A�8�D�D�a�1�t�8�a�<�D�D�D�D�D�D�Dr�c� ��g|] }�|�� Sr�r�)r�r��mats �r�� <listcomp>z,MatrixBase._eval_extract.<locals>.<listcomp>�s���2�2�2�Q�#�a�&�2�2�2r�)�listr�r��len)r��rowsListr��indicesr�r�s ` @@r�� _eval_extractzMatrixBase._eval_extract�sp������4�j�j���y��D�D�D�D�D��D�D�D���y�y��X����H� � �2�2�2�2�'�2�2�2�4�4� 4r�c�0���g���fd���|���S)Nc���d}||jdkr�|dkr|d|d�f}||d�df}n|d|�|d�f}||d�d|�f}t|��st|��r|dz }�p��|d|�d|�f��|j|d|�d|�fjkrdS�||d�|d�f��dSdS)Nr.r)r��any�append)�Mr�� to_the_right� to_the_bottom�recurse_sub_blocks� sub_blockss ��r�r�z<MatrixBase._eval_get_diag_blocks.<locals>.recurse_sub_blocks�s����A��q�w�q�z�/�/���6�6�#$�Q����U�8�L�$%�a�b�b�!�e�H�M�M�#$�R�a�R����V�9�L�$%�a�b�b�"�1�"�f�I�M��|�$�$� ��M�(:�(:� ���F�A���%�%�a����B�Q�B��i�0�0�0��w�!�B�Q�B����F�)�/�1�1���*�*�1�Q�R�R����V�9�5�5�5���!"�/r�r�)r�r�r�s @@r��_eval_get_diag_blocksz MatrixBase._eval_get_diag_blocks�s@����� � � � � � � �( ��4� � � ��r�c�Z�����fd�}���jdz �j|��S)Nc�>��|�kr �||fn �|dz|fSr�r�)r�r��rowr�s ��r�r�z'MatrixBase._eval_row_del.<locals>.entry�s)���!"�S���4��1��:�:�d�1�q�5�!�8�n� <r�r.r�)r�r�r�s`` r�� _eval_row_delzMatrixBase._eval_row_del�s@���� =� =� =� =� =� =��y�y���Q��� �5�9�9�9r�c��t|��}||jz}t|��|||�<|�|j|jz|j|��Sr�)r�r�r�r�)r�r�r��entries� insert_poss r��_eval_row_insertzMatrixBase._eval_row_insert�sN���t�*�*���4�9�_� �)-�e���� �:�%�&��y�y���U�Z�/���G�D�D�Dr�c������j����fd�}t������j�j�jz|��S)Nc�>��|�kr �||fS�||�z fSr�r�)r�r�r�r�r�s ���r�r�z(MatrixBase._eval_row_join.<locals>.entry�s-����4�x�x��A�q�D�z�!���A��H��%� %r�)r�r�r�r�)r�r�r�r�s`` @r��_eval_row_joinzMatrixBase._eval_row_join�se������y�� &� &� &� &� &� &� &� �t�U�#�#�(�(���D�I�� �4J�).�0�0� 0r�c�D���fd�t�j��D��S)Nc�B��g|]}t�|dd�f����Sr�)r��r�r�r�s �r�r�z+MatrixBase._eval_tolist.<locals>.<listcomp>�s+���:�:�:�A��T�!�A�A�A�#�Y���:�:�:r���ranger�r�s`r�� _eval_tolistzMatrixBase._eval_tolist�s'���:�:�:�:��t�y�)9�)9�:�:�:�:r�c��i}|j\}}t|��D]0}t|��D]}|||f}||jkr||||f<��1|Sr�)r�r��zero)r��dokr�r�r�r��vals r�� _eval_todokzMatrixBase._eval_todok�sp�����Z� ��d��t��� $� $�A��4�[�[� $� $���1�a�4�j���$�)�#�#� #�C��1��I�� $�� r�c��|jg||zz}|���D]\\}}}||||z|z<�|�|||��Sr�)r��itemsr�)r�r�r�r��out_flatr�r�r�s r��_eval_from_dokzMatrixBase._eval_from_dok�s^���H�:����-���9�9�;�;� )� )�K�F�Q��C�%(�H�Q��X��\� "� "��x�x��d�H�-�-�-r�c�h����j���fd�}��t���d|��S)Nc�2��|�z}||�zz }�||fSr�r�)�n�_r�r�r�r�s ��r�r�z#MatrixBase._eval_vec.<locals>.entrys'����T� �A��A��H� �A���1��:� r�r.)r�r�r�)r�r�r�s` @r�� _eval_veczMatrixBase._eval_vec�sG�����y�� � � � � � � �y�y��T���A�u�-�-�-r�c�p�|j}g}|rCt|��D]2}t||��D]}|�|||f��� �3nEt|��D]5}t|dz|��D]}|�|||f��� �6|�t |��d|��Sr�)r�r�r�r�r�)r��diagonal�c�vr�r�s r�� _eval_vechzMatrixBase._eval_vech s��� �I�� �� � )��1�X�X� )� )���q�!���)�)�A��H�H�T�!�Q�$�Z�(�(�(�(�)� )��1�X�X� )� )���q�1�u�a���)�)�A��H�H�T�!�Q�$�Z�(�(�(�(�)��y�y��Q����A�&�&�&r�c��|dkr ||jz }d|cxkr |jks$ntd�|�����|�|��S)zDelete the specified column.rzColumn {} is out of range.)r�� IndexError�formatr�)r�r�s r��col_delzMatrixBase.col_delsi�� ��7�7� �4�9� �C��C�#�#�#�#�$�)�#�#�#�#��9�@�@��E�E�F�F� F��!�!�#�&�&�&r�c�P�|st|��|��St|��}|dkr |j|z}|dkrd}n||jkr|j}|j|jkr-t d�|j|j�����|�||��S)ayInsert 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 {}))�typer4r�r�r>r�r��r�r�r�s r�� col_insertzMatrixBase.col_inserts���,� %��4��:�:�e�$�$� $��S�k�k�� ��7�7��)�c�/�C� ��7�7��C�C� �4�9�_�_��)�C� �9�� � "� "��K���� �5�:�.�.�0�0� 0��$�$�S�%�0�0�0r�c�:�|jdkr?|j|jkr/|�d|jg���|��S|j|jkr-t d�|j|j�����|�|��S)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�rzMatrixBase.col_joinHs���. �9��>�>�d�i�5�:�5�5��9�9�Q�� �B�/�/�8�8��?�?� ?� �9�� � "� "��N���� �5�:�.�.�0�0� 0��"�"�5�)�)�)r�c��|dd�|fS)aElementary 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�zMatrixBase.colhs��(�A�A�A�q�D�z�r�c���t|��rt|��std���|r2td�|D����rd�t|��D��}|r2td�|D����rd�t|��D��}�fd�|D��}�fd�|D��}��||��S)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 iterablec3�@K�|]}t|t��V��dSr��� isinstance�bool�r�r�s r�r�z%MatrixBase.extract.<locals>.<genexpr>��,����B�B�A�J�q�$�/�/�B�B�B�B�B�Br�c��g|] \}}|�|�� Sr�r��r��index�items r�r�z&MatrixBase.extract.<locals>.<listcomp>��!��M�M�M�+�%���M��M�M�Mr�c3�@K�|]}t|t��V��dSr�rr s r�r�z%MatrixBase.extract.<locals>.<genexpr>�r r�c��g|] \}}|�|�� Sr�r�r s r�r�z&MatrixBase.extract.<locals>.<listcomp>�rr�c�:��g|]}t|�j����Sr�)�a2idxr��r��kr�s �r�r�z&MatrixBase.extract.<locals>.<listcomp>��%���:�:�:�A�E�!�T�Y�'�'�:�:�:r�c�:��g|]}t|�j����Sr�)rr�rs �r�r�z&MatrixBase.extract.<locals>.<listcomp>�rr�)r3� TypeError�all� enumerater�)r�r�r�s` r��extractzMatrixBase.extract~s���`�8�$�$� F�K��,A�,A� F��D�E�E� E� � N��B�B��B�B�B�B�B� N�M�M��8�1D�1D�M�M�M�H� � N��B�B��B�B�B�B�B� N�M�M��8�1D�1D�M�M�M�H�;�:�:�:��:�:�:��:�:�:�:��:�:�:���!�!�(�H�5�5�5r�c�*�|���S)azObtains 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_blockszMatrixBase.get_diag_blocks�s��0�)�)�+�+�+r�c��t|��dkr|���St|d��}t|j|��S)a(Return 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��hstackzMatrixBase.hstack�sB�� �t�9�9��>�>��8�8�:�:� ��4��7�m�m���c�l�D�)�)�)r�c�����j�jz|�zkrtd|�fz�����|���fd���S)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 %dc� ���|�z|zSr�r�)r�r�r�r�s ��r��<lambda>z$MatrixBase.reshape.<locals>.<lambda>s���$�q�4�x�!�|�2D�r�)r�r�� ValueErrorr�)r�r�r�s` `r�r*zMatrixBase.reshape�sY����* �9�t�y� �D�4�K� /� /��?�4��,�N�O�O� O��y�y��t�%D�%D�%D�%D�%D�E�E�Er�c��|dkr ||jz }d|cxkr |jks$ntd�|�����|�|��S)zDelete the specified row.rzRow {} is out of range.)r�r�r�r�)r�r�s r��row_delzMatrixBase.row_delsi�� ��7�7� �4�9� �C��C�#�#�#�#�$�)�#�#�#�#��6�=�=�c�B�B�C�C� C��!�!�#�&�&�&r�c�J�|s|�|��St|��}|dkr |j|z}|dkrd}n||jkr|j}|j|jkr-t d�|j|j�����|�||��S)a}Insert 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 rr)r�r4r�r�r>r�r�r�s r�� row_insertzMatrixBase.row_insert s���.� $��9�9�U�#�#� #��S�k�k�� ��7�7��)�c�/�C� ��7�7��C�C� �4�9�_�_��)�C� �9�� � "� "��N���� �5�:�.�.�0�0� 0��$�$�S�%�0�0�0r�c�:�|jdkr?|j|jkr/|�|jdg���|��S|j|jkr-t d�|j|j�����|�|��S)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 rr�)r�r�r�r r>r�r�r�s r�r zMatrixBase.row_join6s���, �9��>�>�d�i�5�:�5�5��9�9�U�Z��B�/�/�8�8��?�?� ?� �9�� � "� "��K���� �5�:�.�.�0�0� 0��"�"�5�)�)�)r�rc �~�g}t|��}|dkrdn| }|rdn|} ||jks ||jkrn(|�|||f��|dz }|dz }�?|s6t t d|�dd|jz �d|jdz �d������|�dt|��|��S)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 rTr.z The z diagonal is out of range [�, �])r4r�r�r�r'r5r�r�)r�r�rv�rr�s r�r�zMatrixBase.diagonalUs���D�� �1�I�I���Q���A�A�Q�B���M�A�A��� ��D�I�~�~��d�i���� �I�I�d�1�a�4�j� !� !� !� ��F�A� ��F�A�  � � /��Z�Z� �A�A�q�4�9�}�}�}�d�i�!�m�m�m�)-�.�.�/�/� /��y�y��C��G�G�R�(�(�(r�c��||dd�fS)z�Elementary 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�r�s r�r�zMatrixBase.row�s��$�A�q�q�q�D�z�r�c�*�|���S)z�Return 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��todokzMatrixBase.todok�s�����!�!�!r�c�r���fd�|���D��}��|||��S)aCreate 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]]) c�B��i|]\}}|��|����Sr��r)r��ijr�r�s �r�� <dictcomp>z'MatrixBase.from_dok.<locals>.<dictcomp>�s+���@�@�@���S�r�3�<�<��$�$�@�@�@r�)r�r�)r�r�r�r�s` r��from_dokzMatrixBase.from_dok�s?���A�@�@�@�C�I�I�K�K�@�@�@���!�!�$��c�2�2�2r�c��|jsgS|jsd�t|j��D��S|���S)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() [] c��g|]}g��Sr�r�r s r�r�z%MatrixBase.tolist.<locals>.<listcomp>�s��1�1�1�1�B�1�1�1r�)r�r�r�r�r�s r��tolistzMatrixBase.tolist�sM��2�y� ��I��y� 2�1�1��d�i� 0� 0�1�1�1� 1�� � �"�"�"r�c��i}|���}t|��D]%\}}d�t|��D��}|r|||<�&|S)a;Returns 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}} c��i|] \}}|�||�� Sr�r�)r�r��Mijs r�r9z$MatrixBase.todod.<locals>.<dictcomp>�s#��=�=�=�f�a���=�1�c�=�=�=r�)r=r)r��rowsdict�Mlolr��Mir�s r��tododzMatrixBase.todod�s_��"���x�x�z�z���t�_�_� "� "�E�A�r�=�=� �"� � �=�=�=�C�� "�!��� ���r�c�*�|���S)a�Return 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��veczMatrixBase.vec�s��0�~�~���r�c��|jst�|r#|���std���|�|��S)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 zThe matrix is not symmetric.)� is_squarer?� is_symmetricr'r�)r�r��check_symmetrys r��vechzMatrixBase.vech sQ��T�~� '�&� &� � =�$�"3�"3�"5�"5� =��;�<�<� <����x�(�(�(r�c��t|��dkr|���St|d��}t|j|��S)a:Return 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�rrr!s r��vstackzMatrixBase.vstack>sB�� �t�9�9��>�>��8�8�:�:� ��4��7�m�m���c�l�D�)�)�)r�c�<���fd�}|�|||��S)zUdiag_dict is a defaultdict containing all the entries of the diagonal matrix.c����||fSr�r�)r�r�� diag_dicts �r�r�z$MatrixBase._eval_diag.<locals>.entryXs����a��V�$� $r��r�)r�r�r�rPr�s ` r�� _eval_diagzMatrixBase._eval_diagTs2��� %� %� %� %� %��x�x��d�E�*�*�*r�c��|jg||zz}|jgt||��z|dd|dz�<|�|||d���S)Nr.F��copy)r��one�minr�)r�r�r��valss r�� _eval_eyezMatrixBase._eval_eye\sR����z�4��9�%���'��3�t�T�?�?�2��X�X�t�A�v�X���x�x��d�D�u�x�5�5�5r��upper�sizec�Z���|dkr��fd�}n��fd�}��|||��S)N�lowerc�B��||kr�S|dz|kr�jS�jSr��rVr��r�r�r�� eigenvalues ��r�r�z,MatrixBase._eval_jordan_block.<locals>.entrye�-�����6�6�%�%���U�a�Z�Z��7�N��x�r�c�B��||kr�S|dz|kr�jS�jSr�r_r`s ��r�r�z,MatrixBase._eval_jordan_block.<locals>.entrylrbr�rQ)r�r[ra�bandr�s` ` r��_eval_jordan_blockzMatrixBase._eval_jordan_blockbsf���� �7�?�?� � � � � � � � � � � � � � �x�x��d�E�*�*�*r�c�<���fd�}��|||��S)Nc����jSr��rV�r�r�r�s �r�r�z$MatrixBase._eval_ones.<locals>.entryvs ����7�Nr�rQ)r�r�r�r�s` r�� _eval_oneszMatrixBase._eval_onests2��� � � � � ��x�x��d�E�*�*�*r�c�L�|�|||jg||zzd���S)NFrT)r�r�)r�r�r�s r�� _eval_zeroszMatrixBase._eval_zeroszs)���x�x��d�S�X�J��T� �$:��x�G�G�Gr�c �z���fd�}��d|zdzd|zdz|��}��tt| |dz����d���|z|jz}t ��tt| |dz����d�����|z|jz}||fS)Nc�2��|dz|kr�jn�jSr�r_ris �r�r�z)MatrixBase._eval_wilkinson.<locals>.entry�s����!�e�q�j�j�3�7�7�c�h� 6r��r.T)�unpack)r��diagr�r��T�abs)r�r�r��D�wminus�wpluss` r��_eval_wilkinsonzMatrixBase._eval_wilkinson~s���� 7� 7� 7� 7� 7� �H�H�Q�q�S�1�W�a��c�A�g�u� -� -�����$�u�a�R��Q��/�/�0�0���>�>��B�Q�S�H���C�H�H�T�%���A��E�"2�"2�3�3�D�H�A�A�B�B�Q�F���L���u�}�r�F)�strictrpr�r�c ��ddlm}ddlm}ddlm} |�d|��} |rFt|��dkr3t|d��rt|d|��s|d}tt��} dx} } |D�] }t|t��rr|r*||��}|j \}}|���}n�| �|��\}}}|���D]\\}}}|| || z|| zf<�g}nAt#|d��r|j \}}|���}n|| | | f<| dz } | dz } ��t%|��D]'\}}t%|��D]\}}|| || z|| zf<��(| |z } | |z } ��|�||}}|�| | }}n|�|n|}|| ks|| kr2t't)d �| | ||�������| �||| ��S) aX 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�Nzg The constructed matrix is {} x {} but a size of {} x {} was specified.)�sympy.matrices.matrixbaser��sympy.matrices.denser|�sympy.matricesr~�getr�r3rr�intr�r�r=�_handle_creation_inputsr��hasattrrr'r5r�rR)r"rxrpr�r�r�r�r�r|r~�klass� diag_entries�rmax�cmax�mr�r1r��smatr�r��mis r�rqzMatrixBase.diag�s���x 9�8�8�8�8�8�/�/�/�/�/�/�/�/�/�/�/�/�� � �5�#�&�&�� � �c�$�i�i�1�n�n��T�!�W�)=�)=�n��t�A�w� �3�3�%���7�D�#�3�'�'� ����t�� � �A��!�T�"�"� �� ���q� � �A��7�D�A�q���� � �A�A�!-�!E�!E�a�!H�!H�J�A�q�$�%)�Z�Z�\�\�?�?� ���A��=>� �a�$�h��D��%9�:�:��A�A���G�$�$� ��w���1��H�H�J�J���-.� �d�D�\�*��� ���� ���"�1��� ;� ;���2�%�b�M�M�;�;�D�A�q�9:�L�!�d�(�A��H�!5�6�6�;� �A�I�D� �A�I�D�D� �<��t�$�D� �<��t�$�D�D��<�4�4�T�D� �$�;�;�$��+�+��Z�)"�"(�&��t�T�4�"@�"@�B�B�C�C� C�����d�L�9�9�9r�c ���|�|}|dks|dkr#td�||�����|�d|��}t|��t|��}}|�||��S)z�Returns 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 Nr�@Cannot create a {} x {} matrix. Both dimensions must be positiver�)r'r�r�r4rY�r"r�r�r�r�s r��eyezMatrixBase.eyes��� �<��D� �!�8�8�t�a�x�x��@�@F��t�T�@R�@R�T�T� T�� � �5�#�&�&���D�\�\�6�$�<�<�d�����t�T�*�*�*r�)rdc �T�|�d|��}|�dd��}|�|�td���||kr)d||fvr#td�||�����|�|}|�td���t |��}|�|||��S)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��eigenvalNzMust supply an eigenvaluez=Inconsistent values are given: 'eigenval'={}, 'eigenvalue'={}zMust supply a matrix size)�popr�r'r�r4re)r"r[rardr�r�r�s r�� jordan_blockzMatrixBase.jordan_block0s���^� � �5�#�&�&���:�:�j�$�/�/�� � �(�"2��8�9�9� 9� �8� #� #��X�z�4J�(J�(J��"�"(�&��:�">�">�@�@� @��#�%� � �<��8�9�9� 9��d�|�|���'�'��j�$�?�?�?r�c ��|�|}|�d|��}t|��t|��}}|�||��S)z�Returns 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 Nr�)r�r4rjr�s r��oneszMatrixBase.ones�sL�� �<��D�� � �5�#�&�&���D�\�\�6�$�<�<�d������d�+�+�+r�c ���|�|}|dks|dkr#td�||�����|�d|��}t|��t|��}}|�||��S)z�Returns 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 Nrr�r�)r'r�r�r4rlr�s r��zeroszMatrixBase.zeros�s��� �<��D� �!�8�8�t�a�x�x��@�@F��t�T�@R�@R�T�T� T�� � �5�#�&�&���D�\�\�6�$�<�<�d��� � ��t�,�,�,r�c� ������|��}t|t��s"td�|�����|js"td�|�����|js"td�|�����|�����dks"td�|�����|�������fd�}�� ��|��S)a�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�\��|�dz kr �d|z  S||dzkr�jS�jS)Nr.�����r_)r�r��coeffsr"r[s ���r�r�z#MatrixBase.companion.<locals>.entry�s;����D�1�H�}�}��r�A�v���&��a�!�e����w���8�Or�) rrr1r'r��is_monic� is_univariate�degree� all_coeffsr�)r"�polyr�r�r[s` @@r�� companionzMatrixBase.companion�s,�����&�|�|�D�!�!���$��%�%� I��:�A�A�$�G�G�H�H� H��}� L��=�D�D�T�J�J�K�K� K��!� D��5�<�<�T�B�B�D�D� D��{�{�}�}���q�y�y��6�=�=�d�C�C�E�E� E����"�"�� � � � � � � � �x�x��d�E�*�*�*r�c �v�|�d|��}t|��}|�|��S)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�r4rw)r"r�r�r�s r�� wilkinsonzMatrixBase.wilkinson�s7��H� � �5�#�&�&�� �1�I�I���$�$�Q�'�'�'r�c��d�|D��S)Nc3�6K�|]}|tju�|V��dSr�)r"�Zeror s r�r�z/MatrixBase._eval_iter_values.<locals>.<genexpr>s(����3�3�a�1�A�F�?�?��?�?�?�?�3�3r�r�r�s r��_eval_iter_valueszMatrixBase._eval_iter_valuess��3�3�4�3�3�3�3r�c�D�t|�����Sr�)r�� iter_valuesr�s r�� _eval_valueszMatrixBase._eval_valuess���D�$�$�&�&�'�'�'r�c#�K�t|j��D]3}t|j��D]}|||fr||f|||ffV���4dSr�)r�r�r��r�r�r�s r��_eval_iter_itemszMatrixBase._eval_iter_itemssu�����t�y�!�!� -� -�A��4�9�%�%� -� -����1��:�-��a�&�$�q�!�t�*�,�,�,�,�� -� -� -r�c���|���}t|��|j|jzkr(t t j���rt jh}nt��}|j�fd�|D���S)Nc�$��g|] }|j���� Sr�)�atoms)r�r��typess �r�r�z*MatrixBase._eval_atoms.<locals>.<listcomp>'s!���9�9�9�Q����%��9�9�9r�) �valuesr�r�r�rr"r��set�union)r�r�r��ss ` r�� _eval_atomszMatrixBase._eval_atoms!ss��������� �v�;�;���T�Y�.� .� .�:�a�f�e�3L�3L� .����A�A����A��q�w�9�9�9�9�&�9�9�9�:�:r�c��t��jd�t|�����D���S)Nc3�$K�|] }|jV�� dSr�)� free_symbolsr s r�r�z0MatrixBase._eval_free_symbols.<locals>.<genexpr>*s$����H�H��Q�^�H�H�H�H�H�Hr�)r�r�r�r�s r��_eval_free_symbolszMatrixBase._eval_free_symbols)s4���s�u�u�{�H�H�S������5G�5G�H�H�H�I�Ir�c�^��t�fd�|���D����S)Nc3�,�K�|]}|j��V��dSr�)�has)r��a�patternss �r�r�z'MatrixBase._eval_has.<locals>.<genexpr>-s,�����@�@��5�1�5�(�#�@�@�@�@�@�@r�)r�r��r�r�s `r�� _eval_haszMatrixBase._eval_has,s2����@�@�@�@�T�-=�-=�-?�-?�@�@�@�@�@�@r�c�6�|�t��Sr�)r�rr�s r��_eval_is_symboliczMatrixBase._eval_is_symbolic/s���x�x����r�c�n������fd��t�fd�����D����S)Nc�n����||f�||f���z ��jSr�)� conjugate�is_zero�r�r�r��simpfuncs ��r�r&z6MatrixBase._eval_is_matrix_hermitian.<locals>.<lambda>6s5���H�H�T�!�Q�$�Z�$�q�!�t�*�2F�2F�2H�2H�%H�I�I�Q�r�c3�<�K�|]\\}}}�||��V��dSr�r�)r�r�r�r��herms �r�r�z7MatrixBase._eval_is_matrix_hermitian.<locals>.<genexpr>7�5�����G�G� ���A����a����G�G�G�G�G�Gr��r7� iter_items)r�r�r�s``@r��_eval_is_matrix_hermitianz$MatrixBase._eval_is_matrix_hermitian5sC�����Q�Q�Q�Q�Q���G�G�G�G�T�_�_�5F�5F�G�G�G�G�G�Gr�c�X�td�|���D����S)Nc3�$K�|] }|jV�� dSr��r�)r�r�s r�r�z2MatrixBase._eval_is_zero_matrix.<locals>.<genexpr>:s$����?�?�q���?�?�?�?�?�?r�)r7r�r�s r��_eval_is_zero_matrixzMatrixBase._eval_is_zero_matrix9s+���?�?�D�,<�,<�,>�,>�?�?�?�?�?�?r��returnc�����|j�|j���fd��t�fd�|���D����S)Nc� ��||kr|�un|�uSr�r�)r�r�r�rVr�s ��r�r&z.MatrixBase._eval_is_Identity.<locals>.<lambda>?s���A��F�F��S����T� �r�c3�>�K�|]\\}}}�|||��V��dSr�r�)r�r�r�r��idents �r�r�z/MatrixBase._eval_is_Identity.<locals>.<genexpr>@s7�����E�E�i�f�q�!�a�5�5��A�q�>�>�E�E�E�E�E�Er�)rVr�rr�)r�r�rVr�s @@@r��_eval_is_IdentityzMatrixBase._eval_is_Identity<sQ������h���y��A�A�A�A�A���E�E�E�E�4�?�?�3D�3D�E�E�E�E�E�Er�c�X�td�|���D����S)Nc3�<K�|]\\}}}||k�|jV��dSr�r��r�r�r�r�s r�r�z/MatrixBase._eval_is_diagonal.<locals>.<genexpr>Cs0����P�P�y�v��1�q��a���������P�Pr�r�r�s r��_eval_is_diagonalzMatrixBase._eval_is_diagonalBs)���P�P�D�O�O�4E�4E�P�P�P�P�P�Pr�c�X�td�|���D����S)Nc3�<K�|]\\}}}||k�|jV��dSr�r�r�s r�r�z,MatrixBase._eval_is_lower.<locals>.<genexpr>F�0����I�I���!�Q��1�q�5�5�1�9�5�5�5�5�I�Ir��rr�r�s r��_eval_is_lowerzMatrixBase._eval_is_lowerE�)���I�I�d�o�o�.?�.?�I�I�I�I�I�Ir�c�X�td�|���D����S)Nc3�<K�|]\\}}}||k�|jV��dSr�r�r�s r�r�z,MatrixBase._eval_is_upper.<locals>.<genexpr>Ir�r�r�r�s r��_eval_is_upperzMatrixBase._eval_is_upperHr�r�c�X�td�|���D����S)Nc3�BK�|]\\}}}|dz|k�|jV��dS�r.Nr�r�s r�r�z7MatrixBase._eval_is_lower_hessenberg.<locals>.<genexpr>Ls4����M�M���!�Q��1�q�5�1�9�9�1�9�9�9�9�9�M�Mr�r�r�s r��_eval_is_lower_hessenbergz$MatrixBase._eval_is_lower_hessenbergK�)���M�M�d�o�o�.?�.?�M�M�M�M�M�Mr�c�X�td�|���D����S)Nc3�BK�|]\\}}}||dzk�|jV��dSr�r�r�s r�r�z7MatrixBase._eval_is_upper_hessenberg.<locals>.<genexpr>Os4����M�M���!�Q��1�q�1�u�9�9�1�9�9�9�9�9�M�Mr�r�r�s r��_eval_is_upper_hessenbergz$MatrixBase._eval_is_upper_hessenbergNr�r�c�n������fd��t�fd�����D����S)Nc�J����||f�||fz ��jSr�r�r�s ��r�r&z/MatrixBase._eval_is_symmetric.<locals>.<lambda>Rs)���8�8�D��A��J��a��d��$;�<�<�D�r�c3�<�K�|]\\}}}�||��V��dSr�r�)r�r�r�r��syms �r�r�z0MatrixBase._eval_is_symmetric.<locals>.<genexpr>Ss5�����F�F�y�v��1�q���Q����F�F�F�F�F�Fr�r�)r�r�r�s``@r��_eval_is_symmetriczMatrixBase._eval_is_symmetricQsC�����D�D�D�D�D���F�F�F�F�D�O�O�4E�4E�F�F�F�F�F�Fr�c�n������fd��t�fd�����D����S)Nc�J����||f�||fz��jSr�r�r�s ��r�r&z4MatrixBase._eval_is_anti_symmetric.<locals>.<lambda>Vs)���H�H�T�!�Q�$�Z�$�q�!�t�*�%<�=�=�E�r�c3�<�K�|]\\}}}�||��V��dSr�r�)r�r�r�r��antis �r�r�z5MatrixBase._eval_is_anti_symmetric.<locals>.<genexpr>Wr�r�r�)r�r�r�s``@r��_eval_is_anti_symmetricz"MatrixBase._eval_is_anti_symmetricUsC�����E�E�E�E�E���G�G�G�G�T�_�_�5F�5F�G�G�G�G�G�Gr�c�v���fd�t�j��D��}td�|D����S)Nc3�,�K�|]}�||fV��dSr�r�r�s �r�r�z5MatrixBase._has_positive_diagonals.<locals>.<genexpr>Z�+�����A�A�1�D��A��J�A�A�A�A�A�Ar�c3�$K�|] }|jV�� dSr�)� is_positive�r��xs r�r�z5MatrixBase._has_positive_diagonals.<locals>.<genexpr>[s$����A�A�1���A�A�A�A�A�Ar��r�r�r7�r��diagonal_entriess` r��_has_positive_diagonalsz"MatrixBase._has_positive_diagonalsYsE���A�A�A�A��d�i�0@�0@�A�A�A���A�A�0@�A�A�A�A�A�Ar�c�v���fd�t�j��D��}td�|D����S)Nc3�,�K�|]}�||fV��dSr�r�r�s �r�r�z8MatrixBase._has_nonnegative_diagonals.<locals>.<genexpr>^r�r�c3�$K�|] }|jV�� dSr�)�is_nonnegativer�s r�r�z8MatrixBase._has_nonnegative_diagonals.<locals>.<genexpr>_s%����D�D�a��)�D�D�D�D�D�Dr�rrs` r��_has_nonnegative_diagonalsz%MatrixBase._has_nonnegative_diagonals]sE���A�A�A�A��d�i�0@�0@�A�A�A���D�D�3C�D�D�D�D�D�Dr�c�\�td�|D����}|stf}|j|�S)avReturns 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} c3�bK�|]*}t|t��r|nt|��V��+dSr�)rr�)r��ts r�r�z#MatrixBase.atoms.<locals>.<genexpr>us;����K�K��:�a��.�.�;�a�a�D��G�G�K�K�K�K�K�Kr�)�tupler r�)r�r�s r�r�zMatrixBase.atomsas?��(�K�K�U�K�K�K�K�K��� ��G�E��t���'�'r�c�*�|���S)z�Returns 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�zMatrixBase.free_symbolszs���&�&�(�(�(r�c��|j|�S)a�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�zMatrixBase.has�s��.�t�~�x�(�(r�c�x�|}t|��s |rtnd�}|jsdS|�|��S)aCheck 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��|Sr�r��rs r�r&z.MatrixBase.is_anti_symmetric.<locals>.<lambda>����a�r�F)r�_utilities_simplifyrHr��r��simplifyr�s r��is_anti_symmetriczMatrixBase.is_anti_symmetric�sP��~���(�#�#� H�.6�G�*�*�K�K�H��~� ��5��+�+�H�5�5�5r�c�*�|���S)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_diagonalzMatrixBase.is_diagonal�s��R�%�%�'�'�'r�c������jsdS�j\}���fd��t�fd�t|��D����S)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����j}t���D]"}||kr|t�||f��z }�#t�||f��|z jSr�)r�r�rr�r�� summationr�r�r�s ��r��test_rowz:MatrixBase.is_weakly_diagonally_dominant.<locals>.test_row<s]���� �I��4�[�[� 1� 1����6�6���T�!�Q�$�Z���0�I����Q��T� �O�O�i�/�?� ?r�c3�.�K�|]}�|��V��dSr�r��r�r�rs �r�r�z;MatrixBase.is_weakly_diagonally_dominant.<locals>.<genexpr>C�+�����:�:����!���:�:�:�:�:�:r��rHr�r7r��r�r�r�rs` @@r��is_weakly_diagonally_dominantz(MatrixBase.is_weakly_diagonally_dominantsq�����H�~� ��5��Z� ��d� @� @� @� @� @� @��:�:�:�:�e�D�k�k�:�:�:�:�:�:r�c������jsdS�j\}���fd��t�fd�t|��D����S)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����j}t���D]"}||kr|t�||f��z }�#t�||f��|z jSr�)r�r�rr�rs ��r�rz<MatrixBase.is_strongly_diagonally_dominant.<locals>.test_rowns]���� �I��4�[�[� 1� 1����6�6���T�!�Q�$�Z���0�I����Q��T� �O�O�i�/�<� <r�c3�.�K�|]}�|��V��dSr�r�r s �r�r�z=MatrixBase.is_strongly_diagonally_dominant.<locals>.<genexpr>ur!r�r"r#s` @@r��is_strongly_diagonally_dominantz*MatrixBase.is_strongly_diagonally_dominantEsk�����H�~� ��5��Z� ��d� =� =� =� =� =� =��:�:�:�:�e�D�k�k�:�:�:�:�:�:r�c�H�|jsdS|�t��S)agChecks 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)rHr�rr�s r�� is_hermitianzMatrixBase.is_hermitianws(��:�~� ��5��-�-�.A�B�B�Br�c�<�|jsdS|���S)NF)rHr�r�s r�� is_IdentityzMatrixBase.is_Identity�s#���~� ��5��%�%�'�'�'r�c�*�|���S)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_hessenbergzMatrixBase.is_lower_hessenberg����6�-�-�/�/�/r�c�*�|���S)alCheck 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_lowerzMatrixBase.is_lower�s��V�"�"�$�$�$r�c�"�|j|jkS)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�rHzMatrixBase.is_square�s��,�y�D�I�%�%r�c�*�|���S)z�Checks 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_symboliczMatrixBase.is_symbolics���%�%�'�'�'r�c�x�|}t|��s |rtnd�}|jsdS|�|��S)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��|Sr�r�rs r�r&z)MatrixBase.is_symmetric.<locals>.<lambda>Irr�F)rrrHr�rs r�rIzMatrixBase.is_symmetricsP��n���(�#�#� H�.6�G�*�*�K�K�H��~� ��5��&�&�x�0�0�0r�c�*�|���S)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_hessenbergzMatrixBase.is_upper_hessenbergPr/r�c�*�|���S)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 )r�r�s r��is_upperzMatrixBase.is_upperms��T�"�"�$�$�$r�c�*�|���S)a,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_matrixzMatrixBase.is_zero_matrix�s��:�(�(�*�*�*r�c�*�|���S)aReturn 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�zMatrixBase.values�s��$� � �"�"�"r�c�*�|���S)a 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�zMatrixBase.iter_values�s��"�%�%�'�'�'r�c�*�|���S)aCIterate 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�zMatrixBase.iter_items�s��"�$�$�&�&�&r�c�N�|������Sr�)� transposer�r�s r�� _eval_adjointzMatrixBase._eval_adjoint�s���~�~���)�)�+�+�+r�c�8�� �|j}|j|jz}|���}�fd�|���D��� t |��|kry�t j��x}t jurV|g|z}|���D]\\}}} � | |||z|z<�|�|j|j|��} nA� fd�|���D��} |� |j|j| ��} | S)Nc�(��i|]}|�|����Sr�r�)r�r��fs �r�r9z.MatrixBase._eval_applyfunc.<locals>.<dictcomp>�s#���0�0�0�a�!�Q�Q�q�T�T�0�0�0r�c�(��i|]\}}|�|��Sr�r�)r�r8r��valmaps �r�r9z.MatrixBase._eval_applyfunc.<locals>.<dictcomp>s#���;�;�;�e�b�!�B��q� �;�;�;r�) r�r�r4r�r�r"r�r�r�r:) r�rEr�r[r��fzeror�r�r�r��out�fdokrGs ` @r��_eval_applyfunczMatrixBase._eval_applyfunc�s�����y���y���"���j�j�l�l��0�0�0�0�3�:�:�<�<�0�0�0�� �s�8�8�d�?�?�!�!�A�F�)�)�!3��A�F� B� B��w�t�|�H� �Y�Y�[�[� 1� 1� ���A��'-�a�y���4��!��$�$��)�)�D�I�t�y�(�;�;�C�C�;�;�;�;�s�y�y�{�{�;�;�;�D��-�-�� �4�9�d�;�;�C�� r�c�j�|�t��|�t��fSr�)� applyfuncrrr�s r��_eval_as_real_imagzMatrixBase._eval_as_real_imags%�����r�"�"�D�N�N�2�$6�$6�7�7r�c�.�|�d���S)Nc�*�|���Sr��r�rs r�r&z,MatrixBase._eval_conjugate.<locals>.<lambda> s��� � � � �r��rMr�s r��_eval_conjugatezMatrixBase._eval_conjugate s���~�~�5�5�6�6�6r�c�r���t|�����fd�}���j�j|��S)Nc�$���|�|fSr�r��r�r��mappingr�s ��r�r�z,MatrixBase._eval_permute_cols.<locals>.entrys�����7�1�:� �&� &r��r�r�r�r��r��permr�rWs` @r��_eval_permute_colszMatrixBase._eval_permute_cols �I�����t�*�*�� '� '� '� '� '� '��y�y���D�I�u�5�5�5r�c�r���t|�����fd�}���j�j|��S)Nc�$����||fSr�r�rVs ��r�r�z,MatrixBase._eval_permute_rows.<locals>.entrys������ �A� �&� &r�rXrYs` @r��_eval_permute_rowszMatrixBase._eval_permute_rowsr\r�c�^��t�fd�t�j��D����S)Nc3�,�K�|]}�||fV��dSr�r�r�s �r�r�z)MatrixBase._eval_trace.<locals>.<genexpr> s+�����8�8�!�4��1��:�8�8�8�8�8�8r�)�sumr�r�r�s`r�� _eval_tracezMatrixBase._eval_traces0����8�8�8�8�u�T�Y�'7�'7�8�8�8�8�8�8r�c�L�����j�j�fd���S)Nc����||fSr�r��r�r�r�s �r�r&z,MatrixBase._eval_transpose.<locals>.<lambda>#s���D��A��J�r�)r�r�r�r�s`r��_eval_transposezMatrixBase._eval_transpose"s'����y�y���D�I�/F�/F�/F�/F�G�G�Gr�c�*�|���S)z-Conjugate transpose or Hermitian conjugation.)rBr�s r��adjointzMatrixBase.adjoint%s���!�!�#�#�#r�c�h�t|��std���|�|��S)aLApply 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.)�callablerrK)r�rEs r�rMzMatrixBase.applyfunc)s5��$��{�{� 5��3�4�4� 4��#�#�A�&�&�&r�c �*�|���S)z@Returns a tuple containing the (real, imaginary) part of matrix.)rN)r��deep�hintss r�� as_real_imagzMatrixBase.as_real_imag@s���&�&�(�(�(r�c�*�|���S)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 )rSr�s r�r�zMatrixBase.conjugateEs��4�#�#�%�%�%r�c �4��|��fd���S)Nc���|jdi���S�Nr�)�doit)rrns �r�r&z!MatrixBase.doit.<locals>.<lambda>bs�����������r�rR)r�rns `r�rtzMatrixBase.doitas����~�~�7�7�7�7�8�8�8r���dc�J���||||||d��|���fd���S)�&Apply evalf() to each element of self.)�subs�maxn�choprx�quad�verbosec� ��|j�fi���Sr���evalf)r�r��optionss ��r�r&z"MatrixBase.evalf.<locals>.<lambda>hs�������(=�(=�W�(=�(=�r�rR) r�r�ryrzr{rxr|r}r�s ` @r�r�zMatrixBase.evalfds=�����t�D�6��w�0�0���~�~�=�=�=�=�=�>�>�>r�c �T��������� �|���� ������f d���S)a$Apply 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 �.� �|j���� ����fi���Sr�)�expand) r�basicrmrnr&�modulus�mul� multinomial� power_base� power_exps ���������r�r&z#MatrixBase.expand.<locals>.<lambda>ys3������ �'�:�y�#�s�K��)�)��)�)�r�rR) r�rmr�r�r�r�r&r�r�rns `````````r�r�zMatrixBase.expandjs_������������~�~��������������� r�c��|jjS)a�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 )rr�Cr�s r��Hz MatrixBase.H}s ��0�v�x�r�r��forwardc�J��ddlm}|dkrd}|dkrd}|dkrd}|d vr"td �|�����|d vr"td �|�����t ||t f��s"t d �|�����|dkr|jn|j�t�fd�tt|����D����std���|r^t ||��sNt |dt ��r3|dkrtt|����}||�dz���}n||�dz���}|dkr|�|��S|dkr|�|��SdS)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�forwardsr�� 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�c3�8�K�|]}d|cxko�kncV��dS�rNr�)r�r � max_indexs �r�r�z%MatrixBase.permute.<locals>.<genexpr> s?�����D�D�1�1��&�&�&�&�Y�&�&�&�&�D�D�D�D�D�Dr�z`swap` indices out of range.r.)r[N)�sympy.combinatoricsr�rr�rrr'r�r�rr2r�r��reversedr_r[)r�rZ� orientation� directionr�r�s @r��permutezMatrixBase.permute�s ���B 4�3�3�3�3�3� � � "� "�!�I� � � #� #�"�I� �)� #� #� �K� �3� 3� 3��:�:@�&��:K�:K�M�M� M� �.� .� .��3�39�6�+�3F�3F�H�H� H��$��h� 7�8�8� ?��1�17�����?�?� ?� "-��!6�!6�D�I�I�D�I� ��D�D�D�D���T� � �0C�0C�D�D�D�D�D� =��;�<�<� <� � 7� �4��5�5� 7� �t�A�w�� )� )� 7��I�%�%��H�T�N�N�+�+���;�t�)�A�+�6�6�6�D�D��;�t�)�A�+�6�6�6�D� �&� � ��*�*�4�0�0� 0� �&� � ��*�*�4�0�0� 0� !� r�c�2�|�|d|���S)z�Alias for ``self.permute(swaps, orientation='cols', direction=direction)`` See Also ======== permute r��r�r��r��r��swapsr�s r�� permute_colszMatrixBase.permute_cols ����|�|�E�v��|�K�K�Kr�c�2�|�|d|���S)z�Alias for ``self.permute(swaps, orientation='rows', direction=direction)`` See Also ======== permute r�r�r�r�s r�� permute_rowszMatrixBase.permute_rows+ r�r�c�4��|��fd���S)a�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�$��t|���Sr�r)r� assumptionss �r�r&z#MatrixBase.refine.<locals>.<lambda>H s����q�+�(>�(>�r�rR)r�r�s `r�rzMatrixBase.refine6 s!���$�~�~�>�>�>�>�?�?�?r�c����� �|||d�� |r#i����� fd�}|�|��}|�fS|���� fd���S)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��|j��fi���\}}��|��|Sr�)�replace�update)�eij�dij�F�G�dr�s ����r��funcz MatrixBase.replace.<locals>.funca s6���&�3�;�q�!�6�6�v�6�6���S����� � � �� r�c�"��|j��fi���Sr�)r�)r�r�r�r�s ���r�r&z$MatrixBase.replace.<locals>.<lambda>j s���I�A�I�a��,E�,E�f�,E�,E�r�rR) r�r�r�r�r�r�r�r�r�r�s `` @@r�r�zMatrixBase.replaceJ s�������$�l�U�K�K�� � G��A� � � � � � � � � ���t�$�$�A��a�4�K��>�>�"E�"E�"E�"E�"E�"E�F�F� Fr�r.c��|dz}|dkr|S|dkr|ddd�dd�fjS|dkr|ddd�ddd�fS|dkr|dd�ddd�fjSdS)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]]) �rr.Nr�ror��rr)r�r�mods r��rot90zMatrixBase.rot90l s���F��c�� �!�8�8��K� �!�8�8����"��b�b�b��>�#� #� �!�8�8����"��d�d��d� �#� #� �!�8�8�����D�D�b�D��>�#� #� �8r�c �4��|��fd���S)aOApply 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���|jdi���Srs�r�rr�s �r�r&z%MatrixBase.simplify.<locals>.<lambda>� ���� �� �(<�(<�V�(<�(<�r�rR�r�r�s `r�rzMatrixBase.simplify� s!����~�~�<�<�<�<�=�=�=r�c�"���t���dkrbt�dttf��s@t �d��r+t �d��st �d��f�|���fd���S)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.rc���|j�i���Sr�)ry�rr�r�s ��r�r&z!MatrixBase.subs.<locals>.<lambda>� s�������(?��(?�(?�r�)r�r�dictr��iterr3r�rM�r�r�r�s ``r�ryzMatrixBase.subs� s���� �t�9�9��>�>�:�d�1�g��c�{�#C�#C�>��T�RS�W� � �>�^i�jn�op�jq�^r�^r�>���a��M�M�#�D��~�~�?�?�?�?�?�@�@�@r�c�f�|j|jkrt���|���S)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?rcr�s r��tracezMatrixBase.trace� s1�� �9�� � !� !�&�(�(� (����!�!�!r�c�*�|���S)aa 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 )rgr�s r�rAzMatrixBase.transpose� s��B�#�#�%�%�%r�c�*�|���S)zMatrix transposition)rAr�s r�rrz MatrixBase.T� ����~�~���r�c�*�|���S)zBy-element conjugationrQr�s r�r�z MatrixBase.C� r�r�c��|j|i|��S)rxrr�s r�r�z MatrixBase.n� s���t�z�4�*�6�*�*�*r�c�4��|��fd���S)akReturn 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�.��|����Sr�)�xreplace)r�rules �r�r&z%MatrixBase.xreplace.<locals>.<lambda> s���� � �4�(8�(8�r�rR)r�r�s `r�r�zMatrixBase.xreplace s!����~�~�8�8�8�8�9�9�9r�c �4��|��fd���S)Nc���|jdi���Srsr�r�s �r�r&z+MatrixBase._eval_simplify.<locals>.<lambda> r�r�rRr�s `r��_eval_simplifyzMatrixBase._eval_simplify s!����~�~�<�<�<�<�=�=�=r�c �D���ddlm�|���fd���S)Nr)�trigsimpc����|fi���Sr�r�)r�optsr�s ��r�r&z+MatrixBase._eval_trigsimp.<locals>.<lambda> s������(;�(;�d�(;�(;�r�)�sympy.simplify.trigsimpr�rM)r�r�r�s `@r��_eval_trigsimpzMatrixBase._eval_trigsimp s5����4�4�4�4�4�4��~�~�;�;�;�;�;�<�<�<r�c�T�����fd�}���j�j|��S)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�8��|�z|kr �||fn�jSr��r��r�r�rr�s ��r�r�z*MatrixBase.upper_triangular.<locals>.entry; �#���!"�Q��!���4��1��:�:��� :r�r��r�rr�s`` r��upper_triangularzMatrixBase.upper_triangular �?����B ;� ;� ;� ;� ;� ;��y�y���D�I�u�5�5�5r�c�T�����fd�}���j�j|��S)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�8��|�z|kr �||fn�jSr�r�r�s ��r�r�z*MatrixBase.lower_triangular.<locals>.entrya r�r�r�r�s`` r��lower_triangularzMatrixBase.lower_triangular@ r�r�c�L�����j�j�fd���S)Nc�2��t�||f��Sr�)rrfs �r�r&z&MatrixBase._eval_Abs.<locals>.<lambda>g s���C��Q��T� �O�O�r�r�r�s`r�� _eval_AbszMatrixBase._eval_Absf s'����y�y���D�I�/K�/K�/K�/K�L�L�Lr�c�P������j�j��fd���S)Nc�.���||f�||fzSr�r��r�r�r�r�s ��r�r&z&MatrixBase._eval_add.<locals>.<lambda>k s���d�1�a�4�j�5��A��;�&>�r�r�r�s``r�� _eval_addzMatrixBase._eval_addi s4�����y�y���D�I�>�>�>�>�>�@�@� @r�c�T�����fd�}���j�j|��S)Nc���������fd�t�j��D��} t|�S#ttf$rt d�|��cYSwxYw)Nc�:��g|]}��|f�|�fz��Sr�r��r�rr�r�r�r�s ����r�r�z>MatrixBase._eval_matrix_mul.<locals>.entry.<locals>.<listcomp>o s.���B�B�B�A�4��!��9�U�1�Q�3�Z�'�B�B�Br�c� �||zSr�r�)r��bs r�r&z<MatrixBase._eval_matrix_mul.<locals>.entry.<locals>.<lambda>v s ��1�q�5�r�)r�r�r rr r)r�r�rFr�r�s`` ��r�r�z*MatrixBase._eval_matrix_mul.<locals>.entryn s|�����B�B�B�B�B�B�B��t�y�1A�1A�B�B�B�C� 7��C�y� ���|�,� 7� 7� 7��0�0�#�6�6�6�6�6�  7���s�1�"A�Ar��r�r�r�s`` r��_eval_matrix_mulzMatrixBase._eval_matrix_mulm s>���� 7� 7� 7� 7� 7� 7��y�y���E�J��6�6�6r�c�P������j�j��fd���S)Nc�.���||f�||fzSr�r�r�s ��r�r&z9MatrixBase._eval_matrix_mul_elementwise.<locals>.<lambda>{ s���D��1��I�e�A�a�C�j�<P�r�r�r�s``r��_eval_matrix_mul_elementwisez'MatrixBase._eval_matrix_mul_elementwisez s+�����y�y���D�I�/P�/P�/P�/P�/P�Q�Q�Qr�c�T�����fd�}���j�j|��S)Nc�h����t����fd�t�j��D����S)Nc3�B�K�|]}��|f�|�fzV��dSr�r�r�s ����r�r�z>MatrixBase._eval_matrix_rmul.<locals>.entry.<locals>.<genexpr> s8�����G�G��u�Q�q�S�z�$�q��s�)�+�G�G�G�G�G�Gr�)rbr�r�r�s``��r�r�z+MatrixBase._eval_matrix_rmul.<locals>.entry~ s;������G�G�G�G�G�G�G�U�5�:�5F�5F�G�G�G�G�G� Gr�r�r�s`` r��_eval_matrix_rmulzMatrixBase._eval_matrix_rmul} sB���� H� H� H� H� H� H��y�y���T�Y��6�6�6r�c��|dkr|S|dzdkr||�|dz ��}}n|�|dz��x}}|�|��S)Nr.ro)�_eval_pow_by_recursion�multiply)r��numr�r�s r�r�z!MatrixBase._eval_pow_by_recursion� sf�� �!�8�8��K� ��7�a�<�<���4�4�S�1�W�=�=�q�A�A��/�/��q��9�9� 9�A���z�z�!�}�}�r�c�D�ddlm}|jd}|���}| ���dd�}|||��}|�|��}|�|��}t|��D]}||||zz }||z}�|S)Nr)� linrec_coeffsr.)�sympy.discrete.recurrencesrr��charpolyr�r�r�r�) r�r%rr��pr��new_mat�ansr�s r��_eval_pow_by_cayleyzMatrixBase._eval_pow_by_cayley� s���<�<�<�<�<�<��j��m�� �M�M�O�O���"���"�"�1�2�2�&����v�s�+�+���(�(�3�-�-���j�j��o�o���s��� � �A� �6�!�9�W�$� $�C� �t�O�G�G�� r�c���|�dgt|��z}|dkr|S|dzdkr||�|dz |���}}n|�|dz|���x}}|�|d���}t|��}dg|z}t|��D]6}||r!t ||d���\||<||<�+||||<�7|�|j|j|��S)NTr.ro)�prevsimpF�� dotprodsimp)�withsimp)r��"_eval_pow_by_recursion_dotprodsimpr�r�r/r�r�r�) r�rr r�r�r��lenm�elemsr�s r�rz-MatrixBase._eval_pow_by_recursion_dotprodsimp� s'�� � ��v�c�$�i�i�'�H� �!�8�8��K� ��7�a�<�<���@�@��q��%�A�'�'�q�A�A��;�;�C�1�H�%�<�'�'� '�A��� � �1�%� �0�0���A������t� ���t��� � �A���{� �(4�Q�q�T�D�(I�(I�(I�%��a��(�1�+�+��Q�4��a����v�v�a�f�a�f�e�,�,�,r�c�P������j�j��fd���S)Nc����||f�zSr�r�r�s ��r�r&z-MatrixBase._eval_scalar_mul.<locals>.<lambda>� s���D��1��I�e�O�r�r�r�s``r��_eval_scalar_mulzMatrixBase._eval_scalar_mul� �+�����y�y���D�I�/K�/K�/K�/K�/K�L�L�Lr�c�P������j�j��fd���S)Nc�����||fzSr�r�r�s ��r�r&z.MatrixBase._eval_scalar_rmul.<locals>.<lambda>� s���E�$�q��s�)�O�r�r�r�s``r��_eval_scalar_rmulzMatrixBase._eval_scalar_rmul� rr�c�P������j�j��fd���S)Nc�4��t�||f���Sr�rr�s ��r�r&z&MatrixBase._eval_Mod.<locals>.<lambda>� s���C��Q��T� �E�<R�<R�r�r�r�s``r�� _eval_ModzMatrixBase._eval_Mod� s+�����y�y���D�I�/R�/R�/R�/R�/R�S�S�Sr�c�*�|���S)z5Returns a new matrix with entry-wise absolute values.)r�r�s r��__abs__zMatrixBase.__abs__� s���~�~���r��__radd__c��t||��\}}|dkrtS|j|jkr td|j�d|j�d����||}}|jt ||��kr||}}|�|��S)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�rrr�r�s r��__add__zMatrixBase.__add__� s���#�4��/�/���q� � � � �!� !� �:��� $� $��S�d�j�S�S�U�[�S�S�S�T�T� T��U�1�� �;�'�!�Q�-�-� '� '��a�q�A��{�{�1�~�~�r�� __rtruediv__c��||j|z zSr�rhr�s r�� __truediv__zMatrixBase.__truediv__� s���t�x�%�'�(�(r�� __rmatmul__c�n�t||��\}}}|dkrtS|�|��S�Nr)�_unify_with_otherr#�__mul__�r�r�rrs r�� __matmul__zMatrixBase.__matmul__� s:��*�4��7�7���e�Q� � � � �!� !��|�|�E�"�"�"r�c�4��|��fd���S)Nc���|�zSr�r�)rr�s �r�r&z$MatrixBase.__mod__.<locals>.<lambda>� s ����E� �r�rRr�s `r��__mod__zMatrixBase.__mod__� s����~�~�1�1�1�1�2�2�2r��__rmul__c�,�|�|��S)avReturn 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-zMatrixBase.__mul__� s��:�}�}�U�#�#�#r�c���td|��}t||��\}}}|dkr- |�|��S#t$r tcYSwxYw|dkr�|jd|jdkr t d|j�d|j�d����|�|��}|r+|�|j |j d �|D����}|StS) 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_scalarrr.rr z * r!c�,�g|]}t|����Sr��r/�r��es r�r�z'MatrixBase.multiply.<locals>.<listcomp>% s��+G�+G�+G��L��O�O�+G�+G�+Gr�) r;r,rrr#r�r>r�r�r�r��r�r�r � isimpboolrrr�s r�r�zMatrixBase.multiply s��0��{�C�C� �*�4��7�7���e�Q� �!� !� !� &��,�,�U�3�3�3��� &� &� &�%�%�%�%� &�����+� � ��z�!�}�� �A��.�.� �!W�$�*�!W�!W���!W�!W�!W�X�X�X��%�%�e�,�,�A�� I��F�F�1�6�1�6�+G�+G�Q�+G�+G�+G�H�H���H�"� !��A�A�Ac��|j|jkr-td�|j|j�����|�|��S)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_elementwisezMatrixBase.multiply_elementwise, sL��* �:��� $� $��@�G�G�� �TY�T_�`�`�a�a� a��0�0��7�7�7r�c�,�|�d��S)Nr�)rr�s r��__neg__zMatrixBase.__neg__F s���$�$�R�(�(�(r��__rpow__c�,�|�|��S)z$Return self**exp a scalar or symbol.)�pow)r�r%s r��__pow__zMatrixBase.__pow__I s���x�x��}�}�r�c����|�|dvrtd���|j|jkrt���|�t �dd��}t �����jr"���j�jd���S�dkr�St �dd��}|�/|��r%���j�j��fd���S�jrQ�dzd krH�jdkr ���d �zgg��S�d kr� ��� ���|d kr$ |���S#t$r |d kr�Y�nKwxYw|d kr4�jr �dzd krtd ����� ���S|d kr4�jr �dzd krtd����� ���S|dkr4�jr �dzd krtd��������S|���jr��dzd kr��jrt!�����jdkr�dkr |���St#dd��r�� ���S�dkr�� ���S�����S|r/ |���S#t$$r�jdus �jdur�YnwxYwd dlm}|����S)a�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�cayleyzNo such method�_matrix_pow_by_jordan_blocksc�(�t||k��Sr�)r�)r�r�s r�r&z MatrixBase.pow.<locals>.<lambda>l s��s�1��6�{�{�r�r.rc�.��||kr �||f�zndS)Nrr�)r�r�r�r%s ��r�r&z MatrixBase.pow.<locals>.<lambda>r s ���a�1�f�f�q��1��v�s�{�{�RS�r�rrHrIz.cayley method is only valid for integer powersrGz/mulsimp method is only valid for integer powersr�z0multiply method is only valid for integer powersroi��Ti'F)�MatPow)rr�r�r?�getattrrr�r�� is_Number�invr=r'rrr��is_Floatrr;r@� is_integerr�sympy.matrices.expressionsrM)r�r%�method� jordan_powr�rMr�s ` @r�rDzMatrixBase.powP s�����& � �&�0[�"[�"[��,�-�-� -� �9�� � !� !�&�(�(� (� ���Q� >��E�E� ��c�l�l�� �;� D��6�6�!�&�!�&�*B�*B�C�C� C� �!�8�8��H��1�m�T�2�2�� � �H�H�J�J� ��6�6�!�&�!�&�*S�*S�*S�*S�*S�T�T� T� �=� �S�1�W��\�\��v��{�{��v�v��!��c� �{�m�,�,�,��Q�w�w��d���E�E�G�G�� �X� � � �!�z�#���&��� � � ��X�%�%��&�%� �����x� � ��=� S�C�!�G�q�L�L� �!Q�R�R�R��(�(��-�-� -� �y� � ��=� T�C�!�G�q�L�L� �!R�S�S�S��7�7��<�<� <� �z� !� !��=� U�C�!�G�q�L�L� �!S�T�T�T��+�+�C�0�0� 0� �^�� �^�#��'�Q�,�,��|� #��c�l�l���v��{�{�s�V�|�|�!�z�#���&�,�T�4�8�8� 5��;�;�C�@�@�@��u����,�,�S�1�1�1��/�/��4�4�4� � � �!�z�#���&��+� � � � �>�U�*�*�c�.@�E�.I�.I��/J�.I�  ���� 6�5�5�5�5�5��v�a��~�~�s$�* D5�5E � E � J"�"K�Kr%c� �||zSr�r�r�s r�rzMatrixBase.__radd__� s ���e�|�r�r/c�n�t||��\}}}|dkrtS|�|��Sr+)r,r#r3r.s r�r)zMatrixBase.__rmatmul__� s:��*�4��7�7���e�Q� � � � �!� !��}�}�U�#�#�#r�r-c�,�|�|��Sr�)� rmultiplyr�s r�r3zMatrixBase.__rmul__� s���~�~�e�$�$�$r�c��td|��}t||��\}}}|dkr- |�|��S#t$r tcYSwxYw|dkro|jd|jdkrt d���|�|��}|r+|�|j |j d�|D����S|StS)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. Fr6rrr.zMatrix size mismatch.c�,�g|]}t|����Sr�r8r9s r�r�z(MatrixBase.rmultiply.<locals>.<listcomp>� s��.J�.J�.J�1�|�A���.J�.J�.Jr�) r;r,rrr#r�r>r�r�r�r�r;s r�rYzMatrixBase.rmultiply� s���0��{�C�C� �*�4��7�7���e�Q� �!� !� !� &��-�-�e�4�4�4��� &� &� &�%�%�%�%� &�����+� � ��z�!�}�� �A��.�.� �!8�9�9�9��&�&�u�-�-�A�� L��v�v�a�f�a�f�.J�.J��.J�.J�.J�K�K�K��H�"� !r=�__sub__c��| |zSr�r��r�r�s r��__rsub__zMatrixBase.__rsub__� s�����{�r�r_c��|| zSr�r�r^s r�r\zMatrixBase.__sub__� s����r�{�r�c�$�t||���S�N)� iszerofunc�rK�r�rcs r��_eval_det_bareisszMatrixBase._eval_det_bareiss� s���D�Z�8�8�8�8r�c� �t|��Sr�)rLr�s r��_eval_det_berkowitzzMatrixBase._eval_det_berkowitz� s���d�#�#�#r�c�&�t|||���S)N)rcr�)rO)r�rcr�s r�� _eval_det_luzMatrixBase._eval_det_lu� s���t� �X�F�F�F�Fr�c� �t|��Sr�)rMr�s r��_eval_det_birdzMatrixBase._eval_det_bird� s������r�c� �t|��Sr�)rNr�s r��_eval_det_laplacezMatrixBase._eval_det_laplace� ����D�!�!�!r�c� �t|��Sr��rJr�s r��_eval_determinantzMatrixBase._eval_determinant� ����D�z�z�r�� berkowitzc�$�t||���S�N�rT)rE�r�rTs r��adjugatezMatrixBase.adjugate� s����f�-�-�-�-r��lambdac�&�t|||���S)N)rr)rF�r�rrs r�rzMatrixBase.charpoly� s�����X�6�6�6�6r�c�(�t||||���Srv)rG�r�r�r�rTs r��cofactorzMatrixBase.cofactor s����q�!�F�3�3�3�3r�c�$�t||���Srv)rHrxs r��cofactor_matrixzMatrixBase.cofactor_matrix s����V�4�4�4�4r��bareissc�&�t|||���S)N)rTrcrq)r�rTrcs r��detzMatrixBase.det s���D��J�?�?�?�?r�c� �t|��Sr�)rIr�s r��perzMatrixBase.per rsr�c�(�t||||���Srv)rPr~s r��minorzMatrixBase.minor s���d�A�q��0�0�0�0r�c�$�t|||��Sr�)rQr�s r��minor_submatrixzMatrixBase.minor_submatrix s����a��+�+�+r�c�(�t||||���S)N)rcr� with_pivots)rS)r�rcrr�s r�� echelon_formzMatrixBase.echelon_form$ s"���T�j�8�'�)�)�)� )r�c� �t|��Sr�)rRr�s r�� is_echelonzMatrixBase.is_echelon( s���4� � � r�c�&�t|||���S�N)rcr)rT�r�rcrs r��rankzMatrixBase.rank, s���T�j�8�D�D�D�Dr�c���t|�||�|j��|����\}}|dd�d|j�f|dd�|j d�ffS)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)rUr#r�r�r�)r��rhsr1r�s r��rref_rhszMatrixBase.rref_rhs/ sf��"�T�[�[��t�x�x�� �':�':�C�@�@�A�A���1�����J�T�Y�J����1�1�1�s�x�i�j�j�=�!1�1�1r�c�*�t|||||���S)N)rcr�pivots�normalize_last)rU)r�rcrr�r�s r��rrefzMatrixBase.rrefC s$���T�j�8��.�:�:�:� :r�r�c���|dvr#td�||�����|dkr|jn|j}|dkr`|�|n|}|�|�"td�|�����d|cxkr|ks%ntd�||������n�|d kr�||||h�dg��}t |��d kr|||h�dg��}t |��d kr"td �|�����|\}}d|cxkr|ks%ntd�||�����d|cxkr|ks%ntd�||�����n�|d kr�|�|n|}|�|n|}|�|�|�"td �|�����||kr"td�|�����d|cxkr|ks%ntd�||�����d|cxkr|ks%ntd�||�����ntdt |��z���|||||fS)z�Validate 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`rz#This matrix does not have a {} '{}'r�rozIFor 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.zinvalid operation %s)r'r�r�r�� differencer��repr) r��opr�r�col1�col2� error_str� self_colsr�s r��_normalize_op_argszMatrixBase._normalize_op_argsM s1�� �2� 2� 2��?�?E�v�i�QS�?T�?T�V�V� V�"+�e�!3�!3�D�I�I��� � ��=�=���#�#�d�C��{�a�i� �"8�8>��y�8I�8I�K�K�K���'�'�'�'�i�'�'�'�'� �!F�!M�!M�i�Y\�!]�!]�^�^�^�(��7�]�]���D�$�'�2�2�D�6�:�:�D��4�y�y�1�}�}��T�4�(�3�3�T�F�;�;���4�y�y�A�~�~� �"<�<B�F�9�<M�<M�O�O�O��J�D�$���(�(�(�(�y�(�(�(�(� �!F�!M�!M�i�Y]�!^�!^�_�_�_���(�(�(�(�y�(�(�(�(� �!F�!M�!M�i�Y]�!^�!^�_�_�_�)��9�_�_��+�$�$�3�C��<�4�4�T�D��{�d�l�a�i� �"A�AG�� �AR�AR�T�T�T��d�{�{� �"1�17�� �1B�1B�D�D�D���'�'�'�'�i�'�'�'�'� �!F�!M�!M�i�Y\�!]�!]�^�^�^���(�(�(�(�y�(�(�(�(� �!F�!M�!M�i�Y]�!^�!^�_�_�_�)��3�d�2�h�h�>�?�?� ?��3��4��%�%r�c�X�������fd�}���j�j|��S)Nc�>��|�kr ��||fzS�||fSr�r�)r�r�r�rr�s ���r�r�z<MatrixBase._eval_col_op_multiply_col_by_const.<locals>.entry� �,����C�x�x��4��1��:�~�%���1��:� r�r�)r�r�rr�s``` r��"_eval_col_op_multiply_col_by_constz-MatrixBase._eval_col_op_multiply_col_by_const� �D����� � � � � � � ��y�y���D�I�u�5�5�5r�c�X�������fd�}���j�j|��S)Nc�X��|�kr �|�fS|�kr �|�fS�||fSr�r�)r�r�r�r�r�s ���r�r�z+MatrixBase._eval_col_op_swap.<locals>.entry� s?����D�y�y��A�t�G�}�$��d����A�t�G�}�$���1��:� r�r�)r�r�r�r�s``` r��_eval_col_op_swapzMatrixBase._eval_col_op_swap� �D����� � � � � � � � �y�y���D�I�u�5�5�5r�c�\���������fd�}���j�j|��S)Nc�T��|�kr�||f��|�fzzS�||fSr�r�)r�r�r�r�rr�s ����r�r�z@MatrixBase._eval_col_op_add_multiple_to_other_col.<locals>.entry� s:����C�x�x��A�q�D�z�A��Q��W� �$5�5�5���1��:� r�r�)r�r�rr�r�s```` r��&_eval_col_op_add_multiple_to_other_colz1MatrixBase._eval_col_op_add_multiple_to_other_col� �J������ � � � � � � � ��y�y���D�I�u�5�5�5r�c�X�������fd�}���j�j|��S)Nc�X��|�kr ��|fS|�kr ��|fS�||fSr�r�)r�r��row1�row2r�s ���r�r�z+MatrixBase._eval_row_op_swap.<locals>.entry� s?����D�y�y��D�!�G�}�$��d����D�!�G�}�$���1��:� r�r�)r�r�r�r�s``` r��_eval_row_op_swapzMatrixBase._eval_row_op_swap� r�r�c�X�������fd�}���j�j|��S)Nc�>��|�kr ��||fzS�||fSr�r�)r�r�rr�r�s ���r�r�z<MatrixBase._eval_row_op_multiply_row_by_const.<locals>.entry� r�r�r�)r�r�rr�s``` r��"_eval_row_op_multiply_row_by_constz-MatrixBase._eval_row_op_multiply_row_by_const� r�r�c�\���������fd�}���j�j|��S)Nc�T��|�kr�||f���|fzzS�||fSr�r�)r�r�rr�r�r�s ����r�r�z@MatrixBase._eval_row_op_add_multiple_to_other_row.<locals>.entry� s:����C�x�x��A�q�D�z�A��T�1�W� �$5�5�5���1��:� r�r�)r�r�rr�r�s```` r��&_eval_row_op_add_multiple_to_other_rowz1MatrixBase._eval_row_op_add_multiple_to_other_row� r�r�r�c���|�|||||d��\}}}}}|dkr|�||��S|dkr|�||��S|dkr|�|||��SdS)adPerforms 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�rr�r�s r��elementary_col_opzMatrixBase.elementary_col_op� ���("&�!8�!8��S�!�T�4�QV�!W�!W���C��D�$� ��=�=��:�:�3��B�B� B� ��=�=��)�)�$��5�5� 5� ��?�?��>�>�s�A�t�L�L� L� �?r�c���|�|||||d��\}}}}}|dkr|�||��S|dkr|�||��S|dkr|�|||��SdS)a4Performs 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�rr�r�s r��elementary_row_opzMatrixBase.elementary_row_op� r�r�c�$�t||���S�Nr�)rk�r�rs r�� columnspacezMatrixBase.columnspace� s���D�8�4�4�4�4r�c�&�t|||���S)N)rrc)rl)r�rrcs r�� nullspacezMatrixBase.nullspace� s���$��j�I�I�I�Ir�c�$�t||���Sr�)rmr�s r��rowspacezMatrixBase.rowspace� s�����1�1�1�1r�c�"�t|g|�Ri|��Sr�)rn)r��vecsr�s r�� orthogonalizezMatrixBase.orthogonalize� s ���c�3�D�3�3�3�F�3�3�3r�c � �t|fd|i|��S)N�error_when_incomplete)ro)r�r��flagss r�� eigenvalszMatrixBase.eigenvals s���$�U�U�6K�U�u�U�U�Ur�c �"�t|f||d�|��S)N)r�rc)rp)r�r�rcr�s r�� eigenvectszMatrixBase.eigenvects s.���4�0�7L�%�0�0�).�0�0� 0r�c � �t|fd|i|��S)N� reals_only)rs)r�r�r�s r��is_diagonalizablezMatrixBase.is_diagonalizable s��!�$�H�H�:�H��H�H�Hr�c�(�t||||���S)N)r��sort� normalize)rt)r�r�r�r�s r�� diagonalizezMatrixBase.diagonalize s"���D�Z�d�#�%�%�%� %r�c�$�t||���S�N�rZ)rq�r�rZs r�� bidiagonalizezMatrixBase.bidiagonalize s���d�%�0�0�0�0r�c�$�t||���Sr�)rrr�s r��bidiagonal_decompositionz#MatrixBase.bidiagonal_decomposition s��(��U�;�;�;�;r�c� �t|��Sr�)rur�s r��is_positive_definitezMatrixBase.is_positive_definite ���$�T�*�*�*r�c� �t|��Sr�)rvr�s r��is_positive_semidefinitez#MatrixBase.is_positive_semidefinite ���(��.�.�.r�c� �t|��Sr�)rwr�s r��is_negative_definitezMatrixBase.is_negative_definite r�r�c� �t|��Sr�)rxr�s r��is_negative_semidefinitez#MatrixBase.is_negative_semidefinite$ r�r�c� �t|��Sr�)ryr�s r�� is_indefinitezMatrixBase.is_indefinite( s���d�#�#�#r�c � �t|fd|i|��S)N�calc_transform)rz)r�r�r�s r�� jordan_formzMatrixBase.jordan_form, s���D�J�J��J�6�J�J�Jr�c ��t|fi|��Sr�)r{�r�r�s r��left_eigenvectszMatrixBase.left_eigenvects/ s����.�.��.�.�.r�c� �t|��Sr�)r|r�s r��singular_valueszMatrixBase.singular_values2 �����%�%�%r�)�evaluatec��ddlm}||g|�Rd|i�}t|t��s|r|���S|S)aeCalculate 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�rr � as_mutable)r�r�r�r�r��derivs r�rzMatrixBase.diffD sf��* I�H�H�H�H�H����?�t�?�?�?�h�?�?���$��&�&� &�8� &��#�#�%�%� %�� r�c�4��|��fd���S)Nc�.��|����Sr�r)r�args �r�r&z-MatrixBase._eval_derivative.<locals>.<lambda>a s������s� � �r�rR)r�rs `r��_eval_derivativezMatrixBase._eval_derivative` s����~�~�3�3�3�3�4�4�4r�c�8���|���fd���S)a�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���|j�i���Sr�)� integrater�s ��r�r&z&MatrixBase.integrate.<locals>.<lambda>| s��� �� �T�(D�V�(D�(D�r�rRr�s ``r�rzMatrixBase.integratec s%����2�~�~�D�D�D�D�D�E�E�Er�c�����ddlm}t�|��s�������jddkr�jd}n.�jddkr�jd}nt d����jddkr�jd}n.�jddkr�jd}nt d�����||��fd���S)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 rrzr.z)``self`` must be a row or a column matrixz"X must be a row or a column matrixc�F���|��|��Sr�r)r�r��Xr�s ��r�r&z%MatrixBase.jacobian.<locals>.<lambda>� s���D��G�L�L��1��,>�,>�r�)rr�rr�r�r)r�rr�r�r�s`` r��jacobianzMatrixBase.jacobian~ s�����H 9�8�8�8�8�8��!�Z�(�(� �� � �!� � �A� �:�a�=�A� � �� �1� �A�A� �Z��]�a� � �� �1� �A�A��G�H�H� H� �7�1�:��?�?���� �A�A� �W�Q�Z�1�_�_���� �A�A��@�A�A� A��y�y��A�>�>�>�>�>�?�?�?r�c�4��|��fd���S)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���|j��Sr�)�limit)rr�s �r�r&z"MatrixBase.limit.<locals>.<lambda>� s��������r�rR)r�r�s `r�r zMatrixBase.limit� s!���*�~�~�6�6�6�6�7�7�7r�c�.�|�|���S)Nr)rr|s r��berkowitz_charpolyzMatrixBase.berkowitz_charpoly� s���}�}�q�}�!�!�!r�c�.�|�d���S)zeComputes determinant using Berkowitz method. See Also ======== det rtrw�r�r�s r�� berkowitz_detzMatrixBase.berkowitz_det� s���x�x�{�x�+�+�+r�c ��|jdi|��S)z8Computes eigenvalues of a Matrix using Berkowitz method.r�)r�r�s r��berkowitz_eigenvalszMatrixBase.berkowitz_eigenvals� s���t�~�&�&��&�&�&r�c��|jg}}|���D]#}|�||dz��| }�$t|��S)z1Computes principal minors using Berkowitz method.r�)rVrtr�r )r��sign�minorsr�s r��berkowitz_minorszMatrixBase.berkowitz_minors� sU���x��f���N�N�$�$� � �D� �M�M�$��b��/� *� *� *��5�D�D��V�}�}�r�c�B�ddlm}d}|s|S|jst���||j}}dg|dz z}t |dd��D]�}||dz|��|dz }}||d|�f |d|�|f} } |d|�d|�f|||f } }| g} t d|dz ��D] } | �|| | z���!t| ��D]\} }| |zd| | <�|j| g| z} t |��D]} | d|| z dz�|| d�| f<�|||dz <��|� |j|d g��g}t|��D]#\} }|�||| z���$|ttt|����zS)Nr�r�)�r.r.r�ro�rr) r�r�rHr?r�r�r�rrVr�r r�)r�r��berk�A�N� transformsr�rrr�Rr�r�r�r��B�polyss r�rtzMatrixBase.berkowitz� s ��(�(�(�(�(�(���� ��K��~� )�&�(�(� (��T�Y�1���S�A��E�]� ��q�!�R��� "� "�A��5��Q���?�?�A��E�q�A��a��!��e�H�9�a����A��h�q�A��R�a�R��!��V�9�q��A��w�h�q�A��C�E��1�a�!�e�_�_� +� +��� � �Q��q��\�*�*�*�*�!�%�(�(� )� )���1���E�4�=��a����X�q�M�E�)�E��1�X�X� -� -�� ��!�a�%�!�)��,��!�"�"�a�%��� !�J�q�1�u� � ����D�H�q��w�h�/�0�0�1���j�)�)� '� '�D�A�q� �L�L��U�1�X�� &� &� &� &��e�C��u�-�-�.�.�.�.r�c�.�|�|���Srv)r�rxs r��cofactorMatrixzMatrixBase.cofactorMatrixs���#�#�6�#�2�2�2r�c� �t|��Sr�rdr�s r�� det_bareiszMatrixBase.det_bareisror�c�.�|�d���S)a�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 �lurwrr�s r��det_LU_decompositionzMatrixBase.det_LU_decompositions��$�x�x�t�x�$�$�$r�c�0�|�||���S)N)r[ra)r�)r�r�r�s r�� jordan_cellzMatrixBase.jordan_cell,s��� � �a�H� �=�=�=r�c�\�|���\}}||���fSr�)r�r)r��calc_transformation�P�Js r�� jordan_cellszMatrixBase.jordan_cells/s.�����!�!���1��!�#�#�%�%�%�%r�c�2�|�|||���Srv)r�r~s r�� minorEntryzMatrixBase.minorEntry3s���z�z�!�Q�v�z�.�.�.r�c�.�|�||��Sr�)r�r�s r�� minorMatrixzMatrixBase.minorMatrix6s���#�#�A�q�)�)�)r�c�0�|�|d���S)zEPermute the rows of the matrix with the given permutation in reverse.r��r��r��r�rZs r�� permuteBkwdzMatrixBase.permuteBkwd9s��� � ��� �<�<�<r�c�0�|�|d���S)z:Permute the rows of the matrix with the given permutation.r�r5r6r7s r�� permuteFwdzMatrixBase.permuteFwd=s��� � ��� �;�;�;r�c��d�|���D��}t|��dkr|\}nt}t|��S)Nc��h|] }|j�� Sr�)�kindr9s r�� <setcomp>z"MatrixBase.kind.<locals>.<setcomp>Cs��2�2�2��a�f�2�2�2r�r.)�flatr�r r<)r�� elem_kinds�elemkinds r�r=zMatrixBase.kindAsJ��2�2�d�i�i�k�k�2�2�2� � �z�?�?�a� � �"�I�H�H�$�H��(�#�#�#r�c�D���fd�t�j��D��S)a" 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 c�R��g|]#}t�j��D] }�||f�� �$Sr�)r�r�)r�r�r�r�s �r�r�z#MatrixBase.flat.<locals>.<listcomp>\s8���O�O�O�q�e�D�I�>N�>N�O�O���Q��T� �O�O�O�Or�r�r�s`r�r?zMatrixBase.flatJs*���$P�O�O�O�E�$�)�$4�$4�O�O�O�Or�c�N�|�|std���ddlm}|||���S)Nz=Cannot implement copy=False when converting Matrix to ndarrayr.)� matrix2numpy)�dtype)r�denserE)r�rFrUrEs r�� __array__zMatrixBase.__array__^sC�� � �D� ��[�\�\� \�'�'�'�'�'�'��|�D��.�.�.�.r�c� �|j|jzS)zkReturn the number of elements of ``self``. Implemented mainly so bool(Matrix()) == False. r�r�s r��__len__zMatrixBase.__len__ds�� �y�4�9�$�$r�c�N��ddlm}m�d�}|���\}}|���}�fd�|D��}|D]}|||���|�|�||����|�������S)Nr)rq� MutableMatrixc�0�|jd}|d}|jr[|dkr|jr ||z|d<n�|jr|jst d���t |��D]}t ||��|d|f<�n[t |��D]K}t||��}t|t��r|� ��}|||z z|z|d|f<�Lt |��D]3}t d||z ��D]}||dz ||zdz f||||zf<��4dS)Nrrr.zANon-invertible matrix can only be raised to a nonnegative integer) r�r�rrRr@r�r r'r�_eval_expand_func)�jcr�r�lr��bnr�s r��jordan_cell_powerzBMatrixBase._matrix_pow_by_jordan_blocks.<locals>.jordan_cell_powerns]����� �A��3��A��y� *���6�6�a�.�6���d�B�s�G�G��,�7�1�+;�7�2�3v�w�w�w�"�1�X�X�7�7��"0��A�"6�"6��1�Q�3���7��q���*�*�A�!�!�Q���B�!�"�h�/�/�4��1�1�3�3���!�A�#�h�r�k�B�q��s�G�G��1�X�X� /� /���q�!�A�#���/�/�A� "�A�a�C��!��A��I��B�q��1��u�I�I�/� /� /r�c�&��g|] }�|����Sr�r�)r�r�rLs �r�r�z;MatrixBase._matrix_pow_by_jordan_blocks.<locals>.<listcomp>�s#���?�?�?�Q� � �a�(�(�?�?�?r�)r�rqrLr�rr�r�rP) r�rrqrRr-r.r/r�rLs @r�rJz'MatrixBase._matrix_pow_by_jordan_blocksks����6�6�6�6�6�6�6�6� /� /� /�*���!�!���1��(�(�*�*� �?�?�?�?�,�?�?�?� �� &� &�A� � �a�� %� %� %� %��y�y����D�D�,�$7�8�8���!�%�%�'�'�"�"�$�$� $r�c��tj|jvrd|j�d|j�d�Sdt |�����zS)N�Matrix(r.�, [])z Matrix(%s))r"r�r�r�r��strr=r�s r��__str__zMatrixBase.__str__�sF�� �6�T�Z� � � �+/�9�9�9�d�i�i�i�@� @��c�$�+�+�-�-�0�0�0�0r�c���|st��}tj|jvrd|j�d|j�d�S|jdkrd|�|d���zSd|�|d���zS) NrUr.rVr.z Matrix([%s])z, )�rowsepz Matrix([ %s]))r$r"r�r�r�r��table)r��printers r�� _format_strzMatrixBase._format_str�s}��� #� �l�l�G� �6�T�Z� � � �+/�9�9�9�d�i�i�i�@� @� �9��>�>�!�D�J�J�w�u�J�$E�$E�E� E��$�*�*�W�U�*�"C�"C�C�Cr�c��� � �t|��}d�|D��� ttt� ������� d�� D��}� fd�t|��D��}t � fd�|D����}g}t |��r�g}t |��D]g\} } |�� | ||  dd�f��|| xxdzcc<|| dkr� r� �d��|| <�ht|��|krttd�����|� |��t |����|� |��S) 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]]) c�Z�g|](}t|d��r|���n|��)S)� as_explicit)r�r`r s r�r�z(MatrixBase.irregular.<locals>.<listcomp>�sC�� � � ��&�a��7�7� >�1�=�=�?�?�?�Q� � � r�c��g|] }|j�� Sr�)r�r s r�r�z(MatrixBase.irregular.<locals>.<listcomp>�s�� � � ��Q�V� � � r�c�:��g|]}��d����S�r)r�)r�r��qs �r�r�z(MatrixBase.irregular.<locals>.<listcomp>�s#���.�.�.�Q����a���.�.�.r�c3�2�K�|]}�|jV��dSr�r�)r�r�r�s �r�r�z'MatrixBase.irregular.<locals>.<genexpr>�s)�����+�+�q��1���+�+�+�+�+�+r�Nr.rz^ Matrices provided do not appear to fill the space completely.) r4r�r�r�rbr�r�extendr�r'r5r�r�) r��ntop�matricesr��dat�activer�r�r1r�r�r�rds @@r�� irregularzMatrixBase.irregular�s�����&�D�\�\�d� � �� � � �a� �u�S��V�V�}�}� � �a� � �Q� � � �c�.�.�.�.�%��+�+�.�.�.�f� �+�+�+�+�F�+�+�+� +� +�d� �d� ��H�H� ��!���'�'� '� '�d�a���h�h�q��t�S��V�G�Q�Q�Q�J�'�(�(�(��!�f�f�f��k�f�f�f��Q��1������e�e�A�h�h�&��)�� ��V�V�t�^�^��Z�))�*�*�+�+� +� �+�+�a�.�.�.� ��H�H� ��X�X�d�^�^�r�c�d��|���}t|j��dkr?|jd|jd}}�fd�|���D��}|||fSt|j��dkr�fd�|D��}|jdd|fSt d���)Nrorr.c�:��g|]}��|����Sr�r7�r�r�r�s �r�r�z.MatrixBase._handle_ndarray.<locals>.<listcomp>�s#���>�>�>�Q����a���>�>�>r�c�:��g|]}��|����Sr�r7rns �r�r�z.MatrixBase._handle_ndarray.<locals>.<listcomp>�s#���6�6�6�Q����a���6�6�6r�z&SymPy supports just 1D and 2D matrices)rHr�r��ravelr�)r�r�arrr�r�� flat_lists` r��_handle_ndarrayzMatrixBase._handle_ndarray�s���� �m�m�o�o�� �s�y�>�>�Q� � ���1��s�y��|�$�D�>�>�>�>�#�)�)�+�+�>�>�>�I���y�(� (� ���^�^�q� � �6�6�6�6�#�6�6�6�I��9�Q�<��I�-� -�%�8�:�:� :r�c�0�������������ddlm}ddlm�ddlm�d}t |��dk�r[t|d|��r@|dj|dj t|d� ����fSt|dt��r3|dj|dj |d� ��fSt|dt��rR|djrE|dj|dj |d���� ��fSt|dt"j��r%|d}�fd�|D��}|j|j |fSt'|dd��r��|d��St+|d���r�t|dt,���s�t/|d��}���fd ���fd ��|�d d ����r5��fd ���fd��t|t.t2f��r�fd�|D��}t |��dkrdx}}g}�n~t5�fd�|D����rVt |d��dkr=t5d�|D����st7d���t |��}d}g}�n t9��fd�|D����s%�fd�|D��}t |��}|rdnd}�n̉r�t5�fd�|D����rld�|D��} | rVt | ��dkrt7d���d�|D��}| ���}t |��|z}�nKdx}}g}�nC��rct9�fd�|D�����rGt=��} g}|D�] �����r`|�d��� ��D����t9�j ��r| �!�j ��n{����rF�rC| �!t �����|��fd��D����n*| �!d��|�"���t | ��dkrt7d����� | ���}t |��|z}�n�g}t=��} dx}}|D�]F} t+| ��s tG| dd��st7d���t'| d��r d| j vr�L�rqt5�fd�| D����rV��$d�| D����\�} } tK| | g�����fd �tM| ��D��} | �c�} n6d�tG| dd��rd} | g} nt | ��} �fd!�| D��} | �!| ��t | ��dkrt7d���|�| ��|�z }��H| r| ���nd}�net |��d"k�r8tO|d��}tO|d��}|dks|dkr#t7d#�(||�����t |��d"krht|d$tR��rM|d$�g}tM|��D]2�|����fd%�tM|��D�����3n}t |��d"krPt+|d$��r;|d$}t |��||zkrt7d&����fd'�|D��}nt |��dkrdx}}g}|�tUtWd(�����|||fS))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 rr})� MatrixSymbol)� BlockMatrixNr.c�:��g|]}��|����Sr�r7)r�rr�s �r�r�z6MatrixBase._handle_creation_inputs.<locals>.<listcomp>s#���8�8�8��S�\�\�!�_�_�8�8�8r�rHc�V��t|t��o�pt|��f��Sr�)rr�)r�rvrur�s ���r�r&z4MatrixBase._handle_creation_inputs.<locals>.<lambda>$s1���*�Q� �";�";�#L��J� �1�{�L�.I� J� J�r�c�:��t|��o �|�� Sr�)r3)r��ismats �r�r&z4MatrixBase._handle_creation_inputs.<locals>.<lambda>&s��� �A��� ?�u�u�Q�x�x�<�r�r�Tc����t|���r|���St|���r2td�|jD����r|���S|S)zmake Block and Symbol explicitc3�$K�|] }|jV�� dSr�)� is_Integer)r�r�s r�r�zLMatrixBase._handle_creation_inputs.<locals>.make_explicit.<locals>.<genexpr>0s%����@_�@_�RS���@_�@_�@_�@_�@_�@_r�)rr`rr�)rrvrus ��r�� make_explicitz9MatrixBase._handle_creation_inputs.<locals>.make_explicit,sj���%�a��5�5�%�#$�=�=�?�?�2�'��<�8�8�%�S�@_�@_�WX�W^�@_�@_�@_�=_�=_�%�#$�=�=�?�?�2�#$�Hr�c�n��t|ttf��r�fd�|D��S�|��S)Nc�&��g|] }�|����Sr�r�)r�rr~s �r�r�zQMatrixBase._handle_creation_inputs.<locals>.make_explicit_row.<locals>.<listcomp>8s#���#B�#B�#B��M�M�!�$4�$4�#B�#B�#Br�)rr�r )r�r~s �r��make_explicit_rowz=MatrixBase._handle_creation_inputs.<locals>.make_explicit_row5sC���%�c�D�%�=�9�9�6�#B�#B�#B�#B�c�#B�#B�#B�B�#0�=��#5�#5�5r�c�&��g|] }�|����Sr�r�)r�r�r�s �r�r�z6MatrixBase._handle_creation_inputs.<locals>.<listcomp>=s%���E�E�E�#�0�0��5�5�E�E�Er�c3�.�K�|]}�|��V��dSr�r�)r�r��raws �r�r�z5MatrixBase._handle_creation_inputs.<locals>.<genexpr>Bs+�����-�-�A���Q���-�-�-�-�-�-r�c3�<K�|]}t|��dkV��dSr�)r�r s r�r�z5MatrixBase._handle_creation_inputs.<locals>.<genexpr>Cs,����8�8�q�s�1�v�v��{�8�8�8�8�8�8r�zmismatched dimensionsc3�D�K�|]}�|��p �|��V��dSr�r�)r�r�rzr�s ��r�r�z5MatrixBase._handle_creation_inputs.<locals>.<genexpr>Hs8�����=�=�A�S�S��V�V�/�u�u�Q�x�x�=�=�=�=�=�=r�c�:��g|]}��|����Sr�r7rns �r�r�z6MatrixBase._handle_creation_inputs.<locals>.<listcomp>Js#��� >� >� >�Q����a��� >� >� >r�c3�.�K�|]}�|��V��dSr�r��r�r�rzs �r�r�z5MatrixBase._handle_creation_inputs.<locals>.<genexpr>M�+�����%<�%<�1�e�e�A�h�h�%<�%<�%<�%<�%<�%<r�c�D�h|]}t|j���|j��Sr�)r�r�r�r s r�r>z5MatrixBase._handle_creation_inputs.<locals>.<setcomp>Os'��@�@�@�q�3�q�w�<�<�@�A�F�@�@�@r�c�J�g|] }|���D] }|D]}|��� �!Sr�)r=)r�r�r1r�s r�r�z6MatrixBase._handle_creation_inputs.<locals>.<listcomp>Ss;��$S�$S�$S�1�Q�X�X�Z�Z�$S�$S��QR�$S�$S�A�Q�$S�$S�$S�$S�$Sr�c3�.�K�|]}�|��V��dSr�r�r�s �r�r�z5MatrixBase._handle_creation_inputs.<locals>.<genexpr>Yr�r�c��g|] }|D]}|��� Sr�r�)r�r�rs r�r�z6MatrixBase._handle_creation_inputs.<locals>.<listcomp>_s%�� B� B� B�q�� B� B�1�� B� B� B� Br�c�:��g|]}��|����Sr�r7)r�r8r�s �r�r�z6MatrixBase._handle_creation_inputs.<locals>.<listcomp>es%���1O�1O�1O�r�#�,�,�r�2B�2B�1O�1O�1Or�� is_MatrixFzexpecting list of listsc3�.�K�|]}�|��V��dSr�r�r�s �r�r�z5MatrixBase._handle_creation_inputs.<locals>.<genexpr>}s+�����+B�+B��E�E�!�H�H�+B�+B�+B�+B�+B�+Br�c��g|] }|j�� Sr�r�r s r�r�z6MatrixBase._handle_creation_inputs.<locals>.<listcomp>s�� 2� 2� 2���� 2� 2� 2r�c�P��g|]"}t���D]}�||���#Sr�)r�)r�r�r�rrr1s ��r�r�z6MatrixBase._handle_creation_inputs.<locals>.<listcomp>�s4��� M� M� M�Q�E�!�H�H� M� M�q��1��a�� M� M� M� Mr�c�:��g|]}��|����Sr�r7rns �r�r�z6MatrixBase._handle_creation_inputs.<locals>.<listcomp>�s#���'E�'E�'E�A�� � �Q���'E�'E�'Er�r�r�roc ���g|]G}����������|��������HSr�r7)r�r�r�r�r�s ���r�r�z6MatrixBase._handle_creation_inputs.<locals>.<listcomp>�sU���/�/�/�����b�b����a���#�,�,�q�/�/�&J�&J�K�K�/�/�/r�z+List length should be equal to rows*columnsc�:��g|]}��|����Sr�r7rns �r�r�z6MatrixBase._handle_creation_inputs.<locals>.<listcomp>�s#���@�@�@��S�\�\�!�_�_�@�@�@r�zf Data type not understood; expecting list of lists or lists of values.),r�r~�"sympy.matrices.expressions.matexprru�&sympy.matrices.expressions.blockmatrixrvr�rr�r�r2r=r�r?r r�r`�mp�matrixr�rsr3�DeferredVectorr�r�r rr'r�r�r�rfr��addr�rNr�r*r�r4r�r)rr5)r�r�r�r~rrr�rir�r��ncolr�r��flatTr?rvrurrr�r�rzr~r�r�r1r�s` @@@@@@@@@@@r�r�z"MatrixBase._handle_creation_inputs�sb ��������������\ 0�/�/�/�/�/�C�C�C�C�C�C�F�F�F�F�F�F�� � �t�9�9��>�>��$�q�'�<�0�0�E 5��A�w�|�T�!�W�\�7�4��7�>�>�;K�;K�3L�3L�L�L��D��G�Z�0�0�A 5��A�w�|�T�!�W�\�4��7�<�<�>�>�A�A��D��G�U�+�+�} 5��Q��0A�} 5��A�w�|�T�!�W�\�4��7�3F�3F�3H�3H�3M�3M�3O�3O�O�O��D��G�R�Y�/�/�z 5���G��8�8�8�8�a�8�8�8� ��v�q�v�y�0�0���a��+�.�.�t 5��*�*�4��7�3�3�3��T�!�W�%�%�p 5�&�t�A�w��?�?�p 5��4��7�m�m��L�L�L�L�L�L��?�?�?�?��!�:�:�j�$�7�7���F�%�%�%�%�%�%�6�6�6�6�6�"�#��e�}�5�5�F�E�E�E�E��E�E�E���s�8�8�q�=�=�"#�O�D�4� "�I�I��-�-�-�-��-�-�-�-�-�O5�#�c�!�f�+�+��2B�2B��8�8�C�8�8�8�8�8�B�(�)@�A�A�A��s�8�8�D��D� "�I�I��=�=�=�=�=��=�=�=�=�=�I5� >� >� >� >�#� >� >� >�I��y�>�>�D� $�+�1�1�!�D�D��D5�#�%<�%<�%<�%<��%<�%<�%<�"<�"<�D5�@�@�C�@�@�@�D��'��t�9�9��>�>�",�-D�"E�"E�E�$S�$S��$S�$S�$S� �#�x�x�z�z��"�9�~�~�t�3���&'���t�$&� � ��85�#�%<�%<�%<�%<��%<�%<�%<�"<�"<�85��5�5�D� "�I� �F�F�� �5��8�8� 0�%�,�,� B� B�A�H�H�J�J� B� B� B�D�D�D�"�1�7�|�|�1� $����� 0� 0� 0�� �S��V�V�0� �Q� $����Q��� 0� 0� 0� )� 0� 0�1O�1O�1O�1O�Q�1O�1O�1O� P� P� P�� �H�H�Q�K�K�K�%�,�,�Q�/�/�/��t�9�9�q�=�=�",�-D�"E�"E�E�)��8�8�:�:�D��y�>�>�4�/�D�D� !#�I��5�5�D�"#�O�D�4�"�"�"��*�3�/�/�H�$+�C��e�$D�$D�H�",�-F�"G�"G�G�"�3� �4�4�)� �C�I�~�~� (�#�F��+B�+B�+B�+B�c�+B�+B�+B�(B�(B�F�*-�*E�*E� 2� 2�c� 2� 2� 2�+4�+4�K�A�q�%� '���s� 3� 3�A� M� M� M� M� M�%��(�(� M� M� M�!�#$�a�D�A�q�q� !�A�&�s�K��?�?�F�$%��(+�u���$'��H�H��'E�'E�'E�'E��'E�'E�'E������ � � ��t�9�9�q�=�=�",�-D�"E�"E�E�!�(�(��.�.�.��� ���)-�4�4�8�8�:�:�:�1�D�� ��Y�Y�!�^�^��$�q�'�?�?�D��$�q�'�?�?�D��a�x�x�4�!�8�8� �"D�DJ�F�4�QU�DV�DV�X�X�X��4�y�y�A�~�~�*�T�!�W�h�"?�"?�~��!�W��� ��t���0�0�A��$�$�/�/�/�/�/�/�"'��+�+�/�/�/�0�0�0�0�0� �T���a���K��Q��$8�$8�� ��G� ��y�>�>�T�D�[�0�0�$�E�G�G�G�@�@�@�@�i�@�@�@� ����Y�Y�!�^�^��O�D�4��I� � ��J�('�(�(�)�)� )��T�9�$�$r�c�\�ddlm}t|t��}|�|��x\}}}t|t ��}t|t��st|t��rh|r|�||��dSt|t��s't|��r|� ||��dStd|z���|s1t|t��st|��r ||��}d}|r�|r9tt||j ���tt||j ���f}n0t|||jz��t|||j z��f}|�||��n|||�|��fSdS)amHelper 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{Nzunexpected value: %sT)rGr|r�slice�key2ijr�� copyin_matrixr+r3� copyin_listr'r �divmodr�r�r)r�r��valuer|�is_slicer�r��is_mats r��_setitemzMatrixBase._setitem�s���P "�!�!�!�!�!��c�5�)�)���[�[��%�%�%���1�s��E�:�.�.�� �a�� � � �:�a��#7�#7� �� ��"�"�3��.�.�.����e�T�*�*� �{�5�/A�/A� �� � ��e�,�,�,����3�e�;�<�<� <�� �"�5�%�0�0� �5@��5G�5G� ���u� � ����� 2��5� �&��D�I�"6�"6�7� �&��D�I�"6�"6�7�9�C�C�!��A�� �N�3�3� ��A�� �N�3�3�5�C��"�"�3��.�.�.�.��!�T�]�]�5�1�1�1�1� �Fr�c� �||zS)zReturn self + b.r��r�r�s r�r�zMatrixBase.adds ���a�x�r�c�b�|s|jS|���}t|�t|�z S)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�rr)r��singularvaluess r��condition_numberzMatrixBase.condition_numbers:��&� ��9� ��-�-�/�/���N�#�c�>�&:�:�:r�c�h�|�|j|j|�����S)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�r?r�s r�rUzMatrixBase.copys&���y�y���D�I�t�y�y�{�{�;�;�;r�c �V�ddlm}t|t|f��s0t d�|t |�������|j|jz|j|jzcxkrdks/ntd|j|jf�d|j|jf�����|� |j|j|d|dz|d|dzz |d|dz|d|dzz |d|dz|d|dzz f��S) 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.ro) r�r�rr�rr�r�r�r�r>r�)r�r�r�s r��crosszMatrixBase.cross-sQ��* B�A�A�A�A�A��!�j�*�5�6�6� C��.�5�5�a��a���A�A�C�C� C�� �D�I�%���!�&��=�=�=�=�A�=�=�=�=��*�#�y�$�)�4�4�4�q�v�q�v�6F�6F�H�I�I� I��9�9�T�Y�� ��a��1�Q�4��$�q�'�A�a�D�.�0��a��1�Q�4��$�q�'�A�a�D�.�0��a��1�Q�4��$�q�'�A�a�D�.�0�43�4�4� 4r�c ��|jdkr$tdt|j��z���|\}}}|�ddd| ||d| | |df ��S)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>rWr�)r�r�y�zs r��hatzMatrixBase.hatQs~��Z �:�� � ��J� ���_�_�-�.�.� .��G�A�q�!��9�9�Q���Q�B���Q�����Q��$��� r�c���|jdkr$tdt|j��z���|���st d���|�dd|d|d|df��S) ao 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 retrive 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 zMatrix is not skew-symmetricr�r.)ror.)rro)r.r)r�r>rWrr'r�r�s r��veezMatrixBase.vee�s���H �:�� � ��J� ���_�_�-�.�.� .��'�'�)�)� ��;�<�<� <��9�9�Q���d���d���d��$��� r�c�X�ddlm}|jdkrt�|j|d��zS)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)�mgammar�)�sympy.physics.matricesr�r��AttributeErrorr�)r�r�s r�rtz MatrixBase.D�s?��D 2�1�1�1�1�1� �9��>�>� !� ��v���q� � �!�!r�c��ddlm}t|t��s�t |��rut |��|jkr?t |��|jkr'td|j �dt |�������|� ||����Stdt|��z���d|j vs d|j vrt�t |��t |��krtd|j �d|j �����|}t |��}|j d|fkr|� d|��}|j |dfkr|� |d��}|�|�d}|r|�d}|dkrA|d vr|���}n(|d vr|���}ntd ���||zd S) a4Return 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: r.z2`b` must be an ordered iterable or Matrix, not %s.NT�maths)r��left�math)�physics�rightz�Unknown conjugate_convention was entered. conjugate_convention must be one of the following: math, maths, left, physics or right.r)rGr|rr�r3r�r�r�r>r��dotrr�r*r�r')r�r�� hermitian�conjugate_conventionr|r�r�s r�r�zMatrixBase.dots��h "�!�!�!�!�!��!�Z�(�(� ��1�~�~� ��q�6�6�T�Y�&�&�3�q�6�6�T�Y�+>�+>�$�*� �J�J�J��A����0�1�1�1��x�x���q� � �*�*�*��H���G�G����� �T�Z� � �Q�a�g�%5�%5�� � �t�9�9��A��� � ��*�BF�*�*�*�a�g�g�V�X�X� X��� ��H�H�� �9��A�� � ��+�+�a��#�#�C� �7�q�!�f� � �� � �!�Q���A� � +� �0A��I� � +�-�5�#*� � �� � �#�'@�@�@��m�m�o�o���%�)=�=�=��K�K�M�M��� �"T�U�U�U��a���|�r�c �0�ddlm}|dd�dd�f|j}}||��}|���r|St d|��D]Y}t d|��D]F}d}t d|��D]"}|t ||d|��|d|fzz }�#||||f<| |||f<�G�Zt d|��D]^} d}t d|��D]5} t d|��D]"} |t d| | | ��|| | fzz }�#�6|dz}| |d| f<||| df<�_|S)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. rrNr.ro)r�r�r�rIr�r!) r�r�r�r��workr�r��acumrrPr�r�s r��dualzMatrixBase.dualhs��� )�(�(�(�(�(��A�A�A�q�q�q�D�z�4�9�1���u�Q�x�x�� � � � � � ��K��q�!��� #� #�A��1�a�[�[� #� #�����q�!���=�=�A��J�q�!�Q��2�2�Q�q�!�t�W�<�<�D�D�!��Q��T� �"�U��Q��T� � �  #��q�!��� � �A��D��1�a�[�[� =� =���q�!���=�=�A��J�q�!�Q��2�2�Q�q�!�t�W�<�<�D�D�=� �A�I�D���D��A��J��D��A��J�J�� r�c����|j}|d}t|����fd�t|��D��}ddlm}|�|||����S)aA 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 rc�6��i|]}|�t|��z ��Sr�)r()r�r��exp_ls �r�r9z6MatrixBase._eval_matrix_exp_jblock.<locals>.<dictcomp>�s&���>�>�>�Q��E�I�a�L�L�(�>�>�>r�r.��banded)r�r%r�� sparsetoolsr�r$)r�r[rP�bandsr�r�s @r��_eval_matrix_exp_jblockz"MatrixBase._eval_matrix_exp_jblock�so���<�y�� ��J���A����>�>�>�>�%��+�+�>�>�>��'�'�'�'�'�'��~�~�f�f�T�5�1�1�2�2�2r�c�p�t|��t|��}}|jst�|js"t d�|�����||jvr#t d�||�����||jvr#t d�||�����|���}t|� ����}i}|}t|dz ��D]}t||��}|||dz<�|j d}|� |��} |� |d��} d} |D�]�}||} |�||��| | <| | jr6| | js)t d�|| | �����d} t|��D]}| | | |f<| |z} �| dkr�d�t|��D��}d}| dkr�| dz} | dz} ||�||��}|jr0|js)t d�|||�����|| | <t|��D]P}||z dzdkr d| | |f<d||<�||||z dzz||<||t#|||z ��z| | |f<�Q|dz }| dk��| dz } ���| �| ��}|� |��}|�|��}t|��D]}||||zz}||z}�|S) 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.rz_Cannot evaluate the function because the function {} is not analytic at the given eigenvalue {}c��g|]}d��Srr�)r��iis r�r�z,MatrixBase.analytic_func.<locals>.<listcomp>�s��,�,�,�R�q�,�,�,r�zaCannot evaluate the function because the derivative {} is not analytic at the given eigenvalue {})rrHr?� is_symbolr'r�r�r��maxr�r�rr�r�ry� is_number� is_complexrD�solver�)r�rEr�eigen�max_mul� derivative�ddr�r�r1�f_valr�r�r�r��coe�deri�d_ir�r�pres r�� analytic_funczMatrixBase.analytic_func�s���8��{�{�H�Q�K�K�1���~� '�&� &��{� ?��3�:�:�1�=�=�>�>� >� �A�N� "� "��/�6�6�q�!�<�<�>�>� >� ��!� !� !��3�:�:�1�d�C�C�E�E� E���� � ���e�l�l�n�n�%�%��� � ���w��{�#�#� #� #�A��b�!���B� "�J�q�1�u� � � �J�q�M�� �J�J�q�M�M��� � �1�a� � �����! �! �A���(�C�����1���E�#�J��S�z�#� ;�E�#�J�,A� ;� �$�$*�F�1�e�C�j�$9�$9�;�;�;��C��1�X�X� � ����#�q�&� ��q�����Q�w�w�,�,�5��8�8�,�,�,�����A�g�g���'�C��1�H�C�$�T�*�/�/��1�5�5�C��}�K�S�^�K�(�,�,2�F�:�d�3C�S�,I�,I�K�K�K�"%�E�#�J�"�1�X�X�<�<���t�8�a�<�1�,�,�()�A�c�1�f�I�%&�C��F�$�!$�Q���T��A��!6��A��$'��F�3�q�!�d�(�+;�+;�$;��#�q�&� � ��A�I�D�#�A�g�g�$ �1�H�C�C� �G�G�E�N�N���j�j��m�m���h�h�q�k�k���q��� � �A���!��S��.�C� �4�K�C�C�� r�c�<�|jstd��� |���\}}|���}n#t$rt d���wxYwd�|D��}ddlm}||�}|�|d����|� ��d���}td�|� ��D����r%t|��t|����St|��|��S) a�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 computedc�6�g|]}|�����Sr�)r��r��cells r�r�z"MatrixBase.exp.<locals>.<listcomp>0s$��C�C�C�T�$�.�.�0�0�C�C�Cr�r�rqNr c3�$K�|] }|jV�� dSr�)�is_real)r�r�s r�r�z!MatrixBase.exp.<locals>.<genexpr>5s$����8�8��u�}�8�8�8�8�8�8r�)rHr?r�rr=r�r�rqr�rPrr�r�r)r�r-r.�cells�blocksrq�eJ�rets r�r%zMatrixBase.expsF���~� D�&�B�D�D� D� t��#�#�%�%�D�A�q��%�%�'�'�E�E��� t� t� t�%�r�t�t� t� t����D�C�U�C�C�C��'�'�'�'�'�'� �T�6�]���j�j���j�.�.�7�7������T�7�R�R�� �8�8�$�+�+�-�-�8�8�8� 8� 8� #��4��:�:�b��g�g�&�&� &��4��:�:�c�?�?� "s �+A�Ac� �|j}|d}|jr"td�|�����dt |��i}t d|��D]}| | z |z ||<�ddlm}|�|||����S)azHelper 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)]]) rzBCould not take logarithm or reciprocal for the given eigenvalue {}rr.r�) r�r�r=r�r&r�r�r�r$)r�r[rPr�r�r�s r��_eval_matrix_log_jblockz"MatrixBase._eval_matrix_log_jblock:s���0�y�� ��J�� �9� +�� � &��q� � �+�+� +��C��F�F� ���q�$��� )� )�A��"�!���}�q�(�E�!�H�H�'�'�'�'�'�'��~�~�f�f�T�5�1�1�2�2�2r�c���|jstd��� |r!||�����\}}n|���\}}|���}n#t$rt d���wxYwd�|D��}ddlm}||�}|rB|||z||�����z��}|� |��}n||z|���z}|S)aHReturn 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 computedc�6�g|]}|�����Sr�)r�r�s r�r�z"MatrixBase.log.<locals>.<listcomp>�s4������ � (� (� *� *���r�rr�) rHr?r�rr=r�r�rqrPr$) r�rr-r.r�r�rqr�r�s r�r&zMatrixBase.logasG��h�~� ?�&�=�?�?� ?� :�� *��x��~�~�1�1�3�3���1�1��'�'�)�)���1��%�%�'�'�E�E��� :� :� :�%�9�:�:� :� :���� ������� (�'�'�'�'�'� �T�6�]�� � #��(�1�r�6�H�H�Q�U�U�W�W�$5�$5�5�6�6�C��.�.��%�%�C�C��b�&�1�5�5�7�7�"�C�� s �AA'�'Bc���|sdS|jstd���td|d����}|�|��}|jd||jzkrdSdS)a�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 matricesrc� �d|zS)Nr�r�)r�s r�r&z)MatrixBase.is_nilpotent.<locals>.<lambda>�s ��c�A�g�r�)�modifyrF)rHr?r-rr�r�)r�rrs r�� is_nilpotentzMatrixBase.is_nilpotent�s~��$� ��4��~� @�&�>�@�@� @� !�#�t�4E�4E� F� F� F�� �M�M�!� � �� �6�!�9��T�Y�� &� &��4��ur�c��d�|D��\}}|r8|jsdx}}nL|d�|j��dd�\}}n t|d|j��}|dz}|r8|jsdx}}nL|d�|j��dd�\}}n t|d|j��}|dz}||||fS)z�Converts a key with potentially mixed types of keys (integer and slice) into a tuple of ranges and raises an error if any index is out of ``self``'s range. See Also ======== key2ij c�8�g|]}t|t����Sr�)rr�)r�rs r�r�z)MatrixBase.key2bounds.<locals>.<listcomp>�s"��=�=�=�1�*�Q��.�.�=�=�=r�rNror.)r�r�rr�)r��keys�islice�jslice�rlo�rhi�clo�chis r�� key2boundszMatrixBase.key2bounds�s���>�=��=�=�=���� � ��9� :�� ��c�c���7�?�?�4�9�5�5�b�q�b�9���S�S���Q����+�+�C���'�C� � ��9� :�� ��c�c���7�?�?�4�9�5�5�b�q�b�9���S�S���Q����+�+�C���'�C��C��c�!�!r�c��t|��rAt|��dkstd���d�t||j��D��St |t ��r*|�t|����dd�Stt|t|����|j ��S)z�Converts key into canonical form, converting integers or indexable items into valid integers for ``self``'s range or returning slices unchanged. See Also ======== key2bounds roz"key must be a sequence of length 2c�b�g|],\}}t|t��st||��n|��-Sr�)rr�r)r�r�r�s r�r�z%MatrixBase.key2ij.<locals>.<listcomp>�sG��6�6�6���1�(2�!�U�';�';�B�E�!�Q�K�K�K��6�6�6r�N) r3r�r�zipr�rr�r�r�rr�r�s r�r�zMatrixBase.key2ij�s��� �s� � � <��s�8�8�q�=�=�� D�E�E�E�6�6� #�C��� 4� 4�6�6�6� 6� ��U� #� #� <��;�;�s�4�y�y�)�)�"�1�"�-� -��%��S��Y�Y�/�/���;�;� ;r�c���|jdkr|jdkrtd���|����|���r!|�|j|j��}n|��fd���}|S)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���|�z Sr�r�)r��norms �r�r&z'MatrixBase.normalized.<locals>.<lambda>%s ���1�t�8�r�)r�r�r>rr�rM)r�rcrIrs @r�� normalizedzMatrixBase.normalizeds����< �9��>�>�d�i�1�n�n��F�G�G� G��y�y�{�{�� �:�d� � � 5��*�*�T�Y�� �2�2�C�C��.�.�!3�!3�!3�!3�4�4�C�� r�c����t|�����pdg}tj|jvrԉdvr t t d�|D�����S�dkrt d�|D���S�tjurtd�|D���S�tj urtd�|D���S tt �fd�|D���tj�z ��S#ttf$rtd ���wxYw�dkrA|�t ���t�fd �t#�j��D���S�d krt|����S�d krt|����S�tjurA|�t ���t�fd �t#�j��D���S��+t+�t,��r>����dvr(|����d ���Std���)aReturn 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�roNc3�:K�|]}t|��dzV��dSr�rsr s r�r�z"MatrixBase.norm.<locals>.<genexpr>`s,����!<�!<�!�#�a�&�&�A�+�!<�!<�!<�!<�!<�!<r�r.c3�4K�|]}t|��V��dSr�r r s r�r�z"MatrixBase.norm.<locals>.<genexpr>cs(����2�2��S��V�V�2�2�2�2�2�2r�c�,�g|]}t|����Sr�r r s r�r�z#MatrixBase.norm.<locals>.<listcomp>f���2�2�2��S��V�V�2�2�2r�c�,�g|]}t|����Sr�r r s r�r�z#MatrixBase.norm.<locals>.<listcomp>ir r�c3�<�K�|]}t|���zV��dSr�r )r�r��ords �r�r�z"MatrixBase.norm.<locals>.<genexpr>ns-����� =� =�1��Q���3�� =� =� =� =� =� =r�z'Expected order to be Number, Symbol, ooc�T��g|]$}t��|������%Sr�)rbr��r�r�r�s �r�r�z#MatrixBase.norm.<locals>.<listcomp>v�)���B�B�B�q�S����q���]�]�B�B�Br�ro�����c�T��g|]$}t��|������%Sr�)rbr�rs �r�r�z#MatrixBase.norm.<locals>.<listcomp>�rr�N)rE�fro� frobenius�vector)rzMatrix Norms under development)r�r�r"�Oner�rr �Infinityr�NegativeInfinityrr,r�rr'rMrsr�r�r�r�rrWr]rFr)r�rrXr�s ` @r�rzMatrixBase.norm(sc����j�D�K�K�M�M�"�"�)�q�c�� �5�D�J� � ��i����C�!<�!<�t�!<�!<�!<�=�>�>�>������2�2�T�2�2�2�3�3��� �"�"��2�2�T�2�2�2�3�3���*�*�*��2�2�T�2�2�2�3�3� L��3� =� =� =� =�� =� =� =�>���� �L�L�L��'��3� L� L� L� �!J�K�K�K� L���� �a�x�x��N�N�3�'�'���B�B�B�B�E�!�&�M�M�B�B�B�C�C������D�0�0�2�2�3�3������D�0�0�2�2�3�3��� �"�"��N�N�3�'�'���B�B�B�B�E�!�&�M�M�B�B�B�C�C��+��C�,/�"1�"1�+�58�Y�Y�[�[�3�64�64��x�x�z�z���1��-�-�-�*�*J�K�K�Ks �:/C*�*!D rc��g}t|j��D]�}g}t|j��D]H}|||fdkr|�d���&|�t |�����I|�dd�|��z����t d�|����dS)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�rW�join�print)r��symbr�r��liner�s r�� print_nonzerozMatrixBase.print_nonzero�s���. ���t�y�!�!� -� -�A��D��4�9�%�%� +� +����1��:��?�?��K�K��$�$�$�$��K�K��D� � �*�*�*�*� �H�H�V�b�g�g�d�m�m�+� ,� ,� ,� ,� �d�i�i��l�l�����r�c�^�||�|��|�|��z zS)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��projectzMatrixBase.project�s(���D�H�H�Q�K�K�!�%�%��(�(�*�+�+r��[r/rr.r�c��tj|jvrdSg}dg|jz}t |j��D]�} |�g��t |j��D]`} |�|| | f��} |d�| ��tt| ��|| ��|| <�a��ddddddd�|}t|��D]Z\} } t| ��D]'\} } t| |��|| ��| | <�(||� | ��z|z|| <�[|� |��S)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[]rr��ljust�rjust�center)r�r�r+�<�>�^) r"r�r�r�r�r�r��_printr�r�rrNr )r�r\�rowstart�rowendrZ�colsep�align�res�maxlenr�r�r�r��elems r�r[zMatrixBase.table�ss��d �6�T�Z� � ��4�����t�y����t�y�!�!� 3� 3�A� �J�J�r�N�N�N��4�9�%�%� 3� 3���N�N�4��1��:�.�.���B����q�!�!�!���A����q� �2�2��q� � � 3� ������  � � ��� ��n�n� :� :�F�A�s�$�S�>�>� 9� 9���4�-���u�-�-�f�Q�i�8�8��A����� � �C� 0� 0�0�6�9�C��F�F��{�{�3���r�c�&�t|||���Sr�)r}r�s r��rank_decompositionzMatrixBase.rank_decomposition s ��"�4�J�!�#�#�#� #r�c� �td����Nz;This function is implemented in DenseMatrix or SparseMatrixr��r�r�s r��choleskyzMatrixBase.cholesky���!�"_�`�`�`r�c� �td���r:r�r;s r��LDLdecompositionzMatrixBase.LDLdecompositionr=r�c�(�t||||���S�N)rcr�� rankcheck)r��r�rcr�rBs r��LUdecompositionzMatrixBase.LUdecompositions"�����h�#�%�%�%� %r�c�(�t||||���SrA)r�rCs r��LUdecomposition_Simplez!MatrixBase.LUdecomposition_Simples"��&�t� �!�Y�8�8�8� 8r�c� �t|��Sr�)r�r�s r��LUdecompositionFFzMatrixBase.LUdecompositionFF s��!�$�'�'�'r�c� �t|��Sr�)r�r�s r��singular_value_decompositionz'MatrixBase.singular_value_decomposition#s��,�T�2�2�2r�c� �t|��Sr�)r�r�s r��QRdecompositionzMatrixBase.QRdecomposition&r�r�c� �t|��Sr�)r�r�s r��upper_hessenberg_decompositionz)MatrixBase.upper_hessenberg_decomposition)s��.�t�4�4�4r�c�"�t||��Sr�)rV�r�r�s r��diagonal_solvezMatrixBase.diagonal_solve,����t�S�)�)�)r�c� �td���r:r�rPs r��lower_triangular_solvez!MatrixBase.lower_triangular_solve/r=r�c� �td���r:r�rPs r��upper_triangular_solvez!MatrixBase.upper_triangular_solve2r=r�c�"�t||��Sr�)rYrPs r��cholesky_solvezMatrixBase.cholesky_solve5rRr�c�"�t||��Sr�)rZrPs r��LDLsolvezMatrixBase.LDLsolve8s����s�#�#�#r�c�&�t|||���Srb)r[)r�r�rcs r��LUsolvezMatrixBase.LUsolve;s����c�j�9�9�9�9r�c�"�t||��Sr�)r\r�s r��QRsolvezMatrixBase.QRsolve>s����a� � � r�c�&�t|||���S)N)�freevar)r])r�r r`s r��gauss_jordan_solvezMatrixBase.gauss_jordan_solveAs��"�4��G�<�<�<�<r�c�&�t|||���S)N)�arbitrary_matrix)r^)r�r rcs r�� pinv_solvezMatrixBase.pinv_solveDs���4��5E�F�F�F�Fr��laplacec�&�t|||���S)N)� det_method)r_)r�r�rgs r�� cramer_solvezMatrixBase.cramer_solveGs���T�3�:�>�>�>�>r��GJc�&�t|||���Srv)r`�r�r�rTs r�r�zMatrixBase.solveJs���d�C��/�/�/�/r��CHc�&�t|||���Srv)rarks r��solve_least_squareszMatrixBase.solve_least_squaresMs��#�D�#�f�=�=�=�=r��RDc�$�t||���Srv)rbrxs r��pinvzMatrixBase.pinvPs���T�&�)�)�)�)r�c�$�t||���Srb)rcres r�� inverse_ADJzMatrixBase.inverse_ADJS������4�4�4�4r�c�$�t||���Srb)rjres r�� inverse_BLOCKzMatrixBase.inverse_BLOCKVs���$�:�6�6�6�6r�c�$�t||���Srb)rdres r�� inverse_GEzMatrixBase.inverse_GEY����t� �3�3�3�3r�c�$�t||���Srb)reres r�� inverse_LUzMatrixBase.inverse_LU\ryr�c�$�t||���Srb)rfres r�� inverse_CHzMatrixBase.inverse_CH_ryr�c�$�t||���Srb)rgres r�� inverse_LDLzMatrixBase.inverse_LDLbrtr�c�$�t||���Srb)rhres r�� inverse_QRzMatrixBase.inverse_QReryr�c�(�t||||���S)N)rTrc�try_block_diag)ri)r�rTrcr�s r�rPzMatrixBase.invhs"���D��J�-�/�/�/� /r�c� �t|��Sr�)r�r�s r��connected_componentszMatrixBase.connected_componentsls��$�T�*�*�*r�c� �t|��Sr�)r�r�s r��"connected_components_decompositionz-MatrixBase.connected_components_decompositionos��2�4�8�8�8r�c� �t|��Sr�)r�r�s r��strongly_connected_componentsz(MatrixBase.strongly_connected_componentsrs��-�d�3�3�3r�c�$�t||���S)N)r])r�)r�r]s r��+strongly_connected_components_decompositionz6MatrixBase.strongly_connected_components_decompositionus��;�D��N�N�N�Nr�rc)TTr�r�)NN)T)ruNrvFFNF)TNTTTTTT)r�r�)r�)FTNr)rt)r�N)r�)r�NNNN)F)FFF)r)r'r/rr.r�)re)ri)rl)ro(��__name__� __module__� __qualname__�__doc__� _op_priority�__array_priority__r��_class_priority� staticmethodrrr"r�r�rrV� _diff_wrtr�r�r0� classmethodr�r�r��propertyr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrr�rrr#r*r)r+r r�r�r4r:r=rDrFrKrMrRrYr�rerjrlrwrqr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r8r�r�r�r�r�r�r�r�rr r�r�r�rrr$r(r*r,r.r1rHr4rIr8r:r<r�r�r�rBrKrNrSr[r_rcrgrirMror�rtr�r�r�r�r�r�rr�r�rryr�rArrr�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrrr6r%r(r/r2r-r�r?rArErDrr)r3rYr_r\rBrfrhrArjrlrnrrryrrrr�r�r�r�r�rCrDrKrLrMrNrOrJrErFrGrHrIrPrQr�r�r�r�r�rSrRrTrUr�r�r�r�r�r�r�r�r�r�r�r�r�rkrlrmrnr�r�r�r�r�r�r�r�r�r�r�r�r�r�rorprsrtrurvrwrxryrzr{r|rqrrrrrrr rr rrrrtr#r%r(r*r/r1r3r8r:r<r=r?�objectrHrJrJrXr]rkrsr�r�r�r�rUr�r�r�rtr�r�r�r�r%r�rr&r�r�r�rrr$r&r[r8r<r?rDrFrHrJrLrNrQrTrVrXrZr\r^rardrhr�rnrqrsrvrxr{r}rr�rPr�r�r�r�r �_sage_r}r~rr�r�r�r�r�r�rVrWrXrYrZr[r\r]r^r_r`rarbrcrdrerfrgrhrjrir�r�r�r�r�r�r�r�r�bs ������5�5��L����I��O��|�G�$�$�H� �6�D� �%�C��I� �D� �D��I��E�E��[�E� E�E�E�E�E�E��&�&��X�&�":�:�:� C� C� C� 0� 0� 0�4�4�4����4:�:�:� E�E�E� 0� 0� 0�;�;�;�����.�.��[�.� .� .� .� '� '� '�'�'�'�'1�'1�'1�R*�*�*�@���,<6�<6�<6�|,�,�,�4�*�*��[�*�&F�F�F�2'�'�'�(1�(1�(1�T*�*�*�>0)�0)�0)�0)�d���( "� "� "��3�3��[�3�"#�#�#�>���2 � � �40)�0)�0)�0)�d�*�*��[�*�*�+�+��[�+��6�6��[�6� �+�+�c�+�+�+��[�+�"�+�+��[�+� �H�H��[�H�� � ��[� �� %�d��D�K:�K:�K:�K:��[�K:�Z�+�+�+��[�+�.�_@�g�_@�_@�_@�_@��[�_@�B�,�,�,��[�,�(�-�-�-��[�-�.�'+�'+��[�'+�T�%(�%(��[�%(�T4�4�4�(�(�(�-�-�-� ;�;�;�J�J�J�A�A�A� � � � H�H�H�@�@�@�F�9�F�F�F�F� Q�Q�Q�J�J�J�J�J�J�N�N�N�N�N�N�G�G�G�H�H�H�B�B�B�E�E�E�(�(�(�2� )� )��X� )�)�)�)�2E6�E6�E6�E6�N)(�)(�)(�V�/;�/;��X�/;�b�/;�/;��X�/;�b�C�C��X�C�B�(�Y�(�(�(��X�(� �0�0��X�0�8�*%�*%��X�*%�X�&�&��X�&�. (� (� (�>1�>1�>1�>1�@�0�0��X�0�8�)%�)%��X�)%�V�+�+��X�+�<#�#�#�((�(�(�&'�'�'�&,�,�,����$8�8�8�7�7�7�6�6�6�6�6�6�9�9�9�H�H�H�$�$�$�'�'�'�.)�)�)�)� &�&�&�89�9�9�?�?�?�?� JN�;?�����&����X��2G1�G1�G1�G1�R L� L� L� L� L� L� L� L�@�@�@�@�( G� G� G� G�D+$�+$�+$�+$�Z >� >� >�A�A�A�*"�"�"�$!&�!&�!&�F� � ��X� �� � ��X� �+�+�+�:�:�:�">�>�>� =�=�=�$6�$6�$6�$6�L$6�$6�$6�$6�LM�M�M�@�@�@� 7� 7� 7�R�R�R�7�7�7� � � ���� -�-�-�-�4M�M�M�M�M�M�T�T�T� � � ���:�&�&���'�&��$��>�*�*�)�)�+�*�)���=�)�)�#�#�*�)�#�3�3�3���:�&�&�$�$�'�&�$�<#"�#"�#"�#"�J8�8�8�4)�)�)���:�&�&���'�&�� \�\�\�\�|��9�%�%���&�%����<�(�(�$�$�)�(�$���9�%�%�%�%�&�%�%� "� "� "� "�D��9�%�%���&�%����:�&�&���'�&��,E�9�9�9�9�$�$�$�'.��G�G�G�G����"�"�"����.�.�.�.�"�,?�7�7�7�7�4�4�4�4�5�5�5�5�@�@�@�@����1�1�1�1�,�,�,�,B�+I��"�+G�+O� �(�+7�+?���+9�+A���(1�(9�N��+7�+?���+2�?�L��+/�<���+4�+<�H��+4�+<�H��+4�+<�H��+;�+C�O��+/�<�C�K�+/�<�C�K�+1�>�E�M�+;�+C�O��&-��5�)�)�)�)��!�!��X�!�&��E�E�E�E�2�2�2�(&��d��:�:�:�:� )�0�L��&�.�J�� �=�D�L� �=�D�L�5&�5&�5&�5&�n6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�M�M�M�M�<M�M�M�M�<5�5�5�5�"'�7�J�J�J�J�2�2�2�2� 4�4�4�)�0�K��&�.�I��%�-�H��*�2�M��'�K� �6�6�M�V�V�V�V�04��0�0�0�0�I�I�I�I�%�%�%�%�1�1�1�1�<�<�<�<��+�+��X�+��/�/��X�/��+�+��X�+��/�/��X�/��$�$��X�$�K�K�K�K�/�/�/�&�&�&�*4�);�I��)4�)<�J��);�)C���)5�)=�K��)>�)F�� �)B�)J��$�)>�)F�� �)B�)J��$�)7�)?�M��)5�)=�K��)9�)A�O��)9�)A�O��)7�)?�M��)B�)J��$�#'������85�5�5�F�F�F�68@�8@�8@�t8�8�8�.$)�5��?�?�=P�"�"�"�"�,�,�,�'�'�'����&/�&/�&/�P3�3�3�3�"�"�"�%�%�%�(>�>�>�&�&�&�&�/�/�/�/�*�*�*�=�=�=�<�<�<��$�j�$�$�$��X�$�P�P�P�(%�4�/�/�/�/� %�%�%�$�$�$�B1�1�1� D�D�D�D��'�'��[�'�R�:�:��[�:� �a%�a%��[�a%�FD�D�D�L���;�;�;�0<�<�<�""4�"4�"4�H5�5�5�nM�M�M�^�("�("��X�("�Td�d�d�d�L&�&�&�P%3�%3�%3�P\�\�\�~!#�!#�!#�F%3�%3�%3�N"�P�P�P�P�d���:"�"�"�:<�<�<�(%,�%�%�%�%�NcL�cL�cL�cL�J � � � �D,�,�,� ?C�!(�K �K �K �K �Z-4�e�#�#�#�#�a�a�a�a�a�a�a�a�*1�4��%�%�%�%� 18�$��8�8�8�8� (�(�(�3�3�3�&�&�&�5�5�5�*�*�*�a�a�a�a�a�a�*�*�*�$�$�$�'.�:�:�:�:�!�!�!�=�=�=�=�G�G�G�G�?�?�?�?�0�0�0�0�>�>�>�>�*�*�*�*�&-�5�5�5�5�(/�7�7�7�7�%,�4�4�4�4�%,�4�4�4�4�%,�4�4�4�4�&-�5�5�5�5�%,�4�4�4�4��'�%�/�/�/�/�+�+�+�9�9�9�4�4�4�O�O�O�O��\�F�%8�%@���%.�%6�H��%6�%>���%5�%=�O��%<�%D��"�%7�%?���+H�+P� �(�%5�%=�O��-L�-T�"�*�%4�%<�N��%<�%D��"�%<�%D��"�%4�%<�N��%.�%6�H��%-�%5�G�O�%-�%5�G�O�%8�%@���%0�%8�J��%2�%:�L��%+�^�E�M�%9�%A���%*�]�D�L�%-�%5�K��%,�_�J��%,�_�J��%,�_�J��%-�%5�K��%,�_�J��%/�%7�M��%)�\�C�K�%:�%B�� �+�3�'�.� '�.�"�)� 5�<�0�7�7�7r�r�c��ddlm}t|dd��r,t||��s|g|j�t |���R�S||��S)z$Convert mat to a Matrix of type typ.rrzr�F)rr�rNrr�r�)�typr�r�s r��_convert_matrixr��sk��4�4�4�4�4�4��s�K��'�'�� �3� �0K�0K�� �s�)�C�I�)�t�C�y�y�)�)�)�)��s�3�x�x�r�c�|�t|dd��}|�dSt|t��ot|��dkS)Nr�Fro)rNrr r�)r�r�s r��_has_matrix_shaper��s<�� �E�7�D� )� )�E� �}��u� �e�U� #� #� 7��E� � �a��7r�c�B�t|d��ot|d��S)Nr�r�)r�)r�s r��_has_rows_colsr��s!�� �5�&� !� !� <�g�e�V�&<�&<�<r�c��d}t|t��r|St|dd��}|r|dfS|�=t|��st |��rt t |��|��dfSt|t��s|dfS|S)z8Convert other to a Matrix, or check for possible scalar.)N� invalid_typer�Nrr6)rr9rNr�r�r�r�r)r�r��INVALIDr�s r�r"r"�s���#�G��%��#�#������{�D�1�1�I��"��k�!�!��� �U� #� #� C�~�e�'<�'<� C�"�4��:�:�u�5�5�{�B� B� �e�X� &� &�(��'�'�'� �Nr�c�h�t|dd��}t|dd��}d||fvr|j|jkr|jS|jS ddl}t ||j��r|jSt ||j��r|jSn#t $rYnwxYwtd|j�d|j�����)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�NrzIncompatible classes r.)rNr�r$�numpyr�ndarray� ImportErrorr)rr � priority_A� priority_Br�s r�r�r��s��� ��-�t�4�4�J���-�t�4�4�J� �J� �+�+�+� � �q�0� 0� 0��;� ��;� ��� � � � �a��� '� '� ��;� � �a��� '� '� ��;� � �� � � � � �� ���� �)�Q�[�[�[�!�+�+�N� O� O�Os�B� B�Bc���t||��\}}|dkrFt||��}||jkrt||��}||jkrt||��}|||fS)zDUnify self and other into a single matrix type, or check for scalar.r)r"r�r$r�)r�r�rrr�s r�r,r,�ss���t�U�+�+�H�E�1��K����d�E�"�"�� �$�.� � �"�3��-�-�D� �%�/� !� !�#�C��/�/�E� ���>�r�c��t|t��s1t|dd��}|� |��}ntd|�d����|�*|dkr||z }|dkr||kstd|�d����t|��S)z>Return integer after making positive and validating against n.� __index__NzInvalid index a[r/rzIndex out of range: a[)rr�rNr�)r�r��jindexs r�rr s��� �a�� � �;���K��.�.�� � �����A�A��*�a�a�a�9�:�:� :��}� �q�5�5� ��F�A��Q���1�q�5�5��*�A�A�A�?�@�@� @� �q�6�6�Mr�c�$�eZdZdZd�Zd�Zd�ZdS)r�a5A 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�r�|dkrd}|dkrtd���d|j|fz}t|��S)Nrz!DeferredVector index out of rangez%s[%d])r��namer)r�r��component_names r�r�zDeferredVector.__getitem__*sF�� ��7�7��A� �q�5�5��@�A�A� A�!�T�Y��N�2���n�%�%�%r�c� �t|��Sr�rr�s r�rXzDeferredVector.__str__2rsr�c��d|jzS)NzDeferredVector('%s'))r�r�s r��__repr__zDeferredVector.__repr__5s��%�� �1�1r�N)r�r�r�r�r�rXr�r�r�r�r�r�sK������ � �&�&�&����2�2�2�2�2r�r�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.symbolrr�sympy.core.sympifyrr�sympy.core.functionr� sympy.polysr�$sympy.functions.elementary.complexesrrr�sympy.printingr�(sympy.functions.elementary.miscellaneousrrr�(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-� utilitiesr/r0r�sympy.polys.polytoolsr1r2r3�sympy.utilities.miscr4r5�sympy.core.decoratorsr6�sympy.core.logicr7r8�sympy.tensor.arrayr9r:r;r=r<� exceptionsr=r>r?r@rArB� determinantrCrDrErFrGrHrIrJrKrLrMrNrOrPrQ� reductionsrRrSrTrU�solversrVrWrXrYrZr[r\r]r^r_r`ra�inverserbrcrdrerfrgrhrirj� subspacesrkrlrmrnr�rorprqrrrsrtrurvrwrxryrzr{r|�decompositionsr}r~rr�r�r�r�r�r��graphr�r�r�r��__doctest_requires__r�r�r�r�r"r�r,rr�r�r�r��<module>r�s���#�#�#�#�#�#�$�$�$�$�$�$�������������+�+�+�+�+�+�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�)�)�)�)�)�)�&�&�&�&�&�&�������+�+�+�+�+�+�+�+�0�0�0�0�0�0�0�0�$�$�$�$�$�$�������<�<�<�<�<�<�<�<�<�<�������C�C�C�C�C�C�C�C�C�C�O�O�O�O�O�O�O�O�"�"�"�"�"�"�-�-�-�-�-�-�)�)�)�)�)�)�;�;�;�;�;�;�;�;�H�H�H�H�H�H�H�H�����$�$�$�$�$�$�-�-�-�-�-�-� � � � � � � � � � � � �3�3�3�3�3�3�E�E�E�E�E�E�E�E�&�&�&�&�&�&�:�:�:�:�:�:�:�:�3�3�3�3�3�3�3�3�7�7�7�7�7�7�1�1�1�1�1�1�1�1�(�(�(�(�(�(�1�1�1�1�1�1�2�2�2�2�2�2�������������������:�9�9�9�9�9�9�9����������������������������������� A�@�@�@�@�@�@�@�@�@�@�@�>�>�>�>�>�>�>�>�>�>�>�>�>�>�>�>�>�>�>�>�>�>�>�>�>�>�>�>� ����������������������K�J�J�J�J�J�J�J�J�J�J�J�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�V�V�V�V�V�V�V�V�V�V�V�V�V�V�V�V�V�V�V�V�V�V� R�R�R�R�R�R�R�R�R�R�R�R� ,�/;�^� ��P=�P=�P=�P=�P=��P=�P=�P=�Db � � �8�8�8�=�=�=����6"P�"P�"P�J � � � � � � � 2�2�2�2�2�V�[�2�2�2�2�2r�
Memory