ó
    ‰*£hƒ›  ã                   ób  • S SK Jr  S SKJr  S SKJrJr  S SKJr  S SK	J
r
  S SKJrJr  S SKJrJr  S SKJr  S S	KJr  S S
KJr  S SKJrJrJrJrJr  S SKJr  S SKJ r J!r!  S SK"J#r#  SSK$J%r%J&r&  SSK'J(r(  SSK)J*r*J+r+  SS/0r,S r-S:S jr.S r/ S;SSSS.S jjr0Sr1 S<S jr2 S<S jr3\*S4S jr4S  r5S;S! jr6S\*4SS".S# jjr7S:S$ jr8S:S% jr9S& r:S' r;S( r<S;S) jr=S;S* jr>S=S+ jr?S, r@S- rAS. rBS/ rCS0 rDS1 rES2 rFS3 rGS4 rHS5rI\I\BlJ        \I\ClJ        \I\DlJ        \I\ElJ        \I\FlJ        S;SS".S6 jjrKS7 rLS8 rMg9)>é    )ÚFunctionType)ÚCounter)ÚmpÚworkprec)Úprec_to_dps©Údefault_sort_key)ÚDEFAULT_MAXPRECÚPrecisionExhausted)Ú	fuzzy_andÚfuzzy_or)ÚFloat)Ú_sympify)Úsqrt)ÚrootsÚCRootOfÚZZÚQQÚEX)ÚDomainMatrix)Údom_eigenvectsÚdom_eigenvects_to_sympy)Úgcdé   )ÚMatrixErrorÚNonSquareMatrixError)Ú_find_reasonable_pivot)Ú_iszeroÚ	_simplify)Ú_is_indefiniteÚ_is_negative_definiteÚ_is_negative_semidefiniteÚ_is_positive_definiteÚ_is_positive_semidefiniteÚ
matplotlibc                 óx  • S nS n[        S U R                  [        5       5       5      nSU* -  nU[        :  aä  [	        U5         [
        R                  " U R                  [        U5      S95      n[
        R                  " U5      u  pgU" U VV	s/ s H8  n[
        R                  " U5      [
        R                  " U5      4  H  o™PM     M:     sn	n5      n
Ub(  [
        R                  " X*-
  5      U:  a  Xg4sS S S 5        $ U
nS S S 5        US-  nU[        :  a  Mä  [        es  sn	nf ! , (       d  f       N+= f)Nc                 óN   • [         R                  " [        S U  5       5      5      $ )Nc              3   ó*   #   • U  H	  oS -  v •  M     g7f)é   N© )Ú.0Úis     ÚQ/home/mande/repo/quber/.venv/lib/python3.13/site-packages/sympy/matrices/eigen.pyÚ	<genexpr>ÚA_eigenvals_eigenvects_mpmath.<locals>.<lambda>.<locals>.<genexpr>"   s   é € Ð!2²¨1 Q¦$²ùó   ‚)r   r   Úsum)Úvs    r-   Ú<lambda>Ú._eigenvals_eigenvects_mpmath.<locals>.<lambda>"   s   € ”b—g’gœcÑ!2±Ó!2Ó2Ô3ó    c              3   ó8   #   • U  H  oR                   v •  M     g 7f©N)Ú_prec©r+   Úxs     r-   r.   Ú/_eigenvals_eigenvects_mpmath.<locals>.<genexpr>%   s   é € Ð/¢˜1�wŽw¢ùó   ‚r)   )Ún)ÚmaxÚatomsr   r
   r   r   ÚmatrixÚevalfr   ÚeigÚreÚimÚfabsr   )ÚMÚnorm2Úv1ÚprecÚepsÚAÚEÚERÚer,   Úv2s              r-   Ú_eigenvals_eigenvects_mpmathrP   !   sü   € Ù3€Eà	€BÜÑ/ §¡¬¤Ó/Ó/€DØ
ˆdˆU‰(€Cà
”Ó
 Ü�d�^Ü—	’	˜!Ÿ'™'¤K°Ó$5˜'Ð6Ó7ˆAÜ—F’F˜1“I‰EˆAÙ¡1ÔC¢1˜a¬r¯uªu°Q«x¼¿º¸q»Ô.B¨šÑ.B™¡1ÒCÓDˆBØ‰~¤"§'¢'¨"©'Ó"2°SÓ"8Ø�u÷ ‰^ð ˆB÷ ð 	�‰	ˆð ”Õ
 ô  Ðùó D÷ �^ús%   ÁAD+Â?D%Ã)D+ÄD+Ä%D+Ä+
D9Fc                 ó–   • [        U 5      u  p#U Vs/ s H  n[        U5      PM     nnU(       a  U$ [        [        U5      5      $ s  snf )z Compute eigenvalues using mpmath)rP   r   Údictr   )rF   ÚmultiplerL   Ú_r:   Úresults         r-   Ú_eigenvals_mpmathrV   ;   sB   € ä'¨Ó*�D€AÙ#$Ó%¢1˜aŒh�qŽk¡1€FÐ%ÞØˆÜ”˜“Ó Ð ùò &s   ’Ac                 óÄ   • [        U 5      u  p/ n[        U R                  5       H7  n[        X   5      n[        US S 2U4   5      nUR	                  USU/45        M9     U$ )Nr   )rP   ÚrangeÚrowsr   Úappend)rF   rL   rM   rU   r,   ÚeigenvalÚ	eigenvects          r-   Ú_eigenvects_mpmathr]   D   s^   € Ü(¨Ó+�E€AØ€FÜ�1—6‘6Ž]ˆÜ˜A™D“>ˆÜ˜R¢ 1 ™XÓ&ˆ	Ø�‰�x  Y KÐ0Ö1ñ ð
 €Mr5   T)ÚsimplifyrS   Úrationalc                óÄ  ^• U (       d  U(       a  / $ 0 $ U R                   (       d  [        SR                  U 5      5      eU R                  R                  [
        [        4;  a:  [        S U  5       5      (       a#  U R                  [        5      (       a	  [        XS9$ U(       a  SSKJm  U R                  U4S j5      n U(       a  [        U 4XS.UD6$ [        U 4XS.UD6$ )aÎ  Compute eigenvalues of the matrix.

Parameters
==========

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

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

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

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

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

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

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

Returns
=======

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

Raises
======

MatrixError
    If not enough roots had got computed.

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

Examples
========

>>> from sympy import Matrix
>>> M = Matrix(3, 3, [0, 1, 1, 1, 0, 0, 1, 1, 1])
>>> M.eigenvals()
{-1: 1, 0: 1, 2: 1}

See Also
========

MatrixBase.charpoly
eigenvects

Notes
=====

Eigenvalues of a matrix $A$ can be computed by solving a matrix
equation $\det(A - \lambda I) = 0$

It's not always possible to return radical solutions for
eigenvalues for matrices larger than $4, 4$ shape due to
Abel-Ruffini theorem.

If there is no radical solution is found for the eigenvalue,
it may return eigenvalues in the form of
:class:`sympy.polys.rootoftools.ComplexRootOf`.
z{} must be a square matrix.c              3   ó8   #   • U  H  oR                   v •  M     g 7fr7   ©Ú	is_numberr9   s     r-   r.   Ú_eigenvals.<locals>.<genexpr>ª   ó   é € Ð&¢A˜q�{Ž{¢Aùr<   ©rS   r   ©Ú	nsimplifyc                 óJ   >• U R                  [        5      (       a  T" U SS9$ U $ ©NT)r_   )Úhasr   ©r:   rh   s    €r-   r3   Ú_eigenvals.<locals>.<lambda>°   s    ø€ °Q·U±U¼5·\±\‘i ¨DÑ1ÐHÀqÐHr5   )Úerror_when_incompleter^   )Ú	is_squarer   ÚformatÚ_repÚdomainr   r   Úallrk   r   rV   Úsympy.simplifyrh   Ú	applyfuncÚ_eigenvals_listÚ_eigenvals_dict)rF   rn   r^   rS   r_   Úflagsrh   s         @r-   Ú
_eigenvalsry   P   sÏ   ø€ ö` ÞØˆIØˆ	à�;�;Ü"Ð#@×#GÑ#GÈÓ#JÓKÐKà‡v�v‡}�}œR¤˜HÓ$äÑ&¡AÓ&×&Ñ&¨1¯5©5´¯<©<Ü$ QÑ:Ð:æÝ,Ø�K‰KÜHóJˆö ÜØðØ%:ñàñð 	ô Ø	ðØ!6ñà
ñð r5   ad  It is not always possible to express the eigenvalues of a matrix of size 5x5 or higher in radicals. We have CRootOf, but domains other than the rationals are not currently supported. If there are no symbols in the matrix, it should still be possible to compute numeric approximations of the eigenvalues using M.evalf().eigenvals() or M.charpoly().nroots().c                 ó¤  • U R                  5       n/ nU R                  R                  [        [        4;   nU H­  nU(       a-  [        U5      S:X  a  US   nXU4   n	UR                  U	5        M7  XU4   n
[        U[        5      (       a  U
R                  US9nOU
R                  5       n[        U4SS0UD6n[        U5      U
R                  :w  a   UR                  SS9nX\-  nM¯     U(       d  U$ [        U[        5      (       d  [         nU Vs/ s H
  oÒ" U5      PM     sn$ ! [         a    U(       a  [        [        5      e/ n Nhf = fs  snf )Nr   r   ©r^   rS   Trf   )Ústrongly_connected_componentsrq   rr   r   r   ÚlenrZ   Ú
isinstancer   Úcharpolyr   rY   Ú	all_rootsÚNotImplementedErrorr   Úeigenvals_error_messager   )rF   rn   r^   rx   ÚiblocksÚall_eigsÚis_domÚbÚindexÚvalÚblockr   ÚeigsÚvalues                 r-   rv   rv   Æ   s?  € à×-Ñ-Ó/€GØ€HØ�V‰V�]‰]œr¤2˜hÑ&€FÛˆö ”c˜!“f “kØ�a‘DˆEØ˜5�L‘/ˆCØ�O‰O˜CÔ Ùà�Q�$‘ˆä�h¤×-Ñ-Ø—~‘~¨x�~Ð8‰Hà—~‘~Ó'ˆHä�XÑ6¨Ð6°Ñ6ˆäˆt‹9˜Ÿ
™
Ó"ðØ×)Ñ)°4Ð)Ð8�ð 	ÑŠñ7 ö: ØˆÜ�h¤×-Ñ-ÜˆÙ)1Ó2ª ˆH�UŽO©Ñ2Ð2øô 'ó Þ(Ü%Ô&=Ó>Ð>à’Dð	üò 3s   ÃD%ÄEÄ%"E
Å	E
c                 ób  • U R                  5       n0 nU R                  R                  [        [        4;   nU Hö  nU(       a3  [        U5      S:X  a$  US   nXU4   n	UR                  U	S5      S-   XY'   M=  XU4   n
[        U[        5      (       a  U
R                  US9nOU
R                  5       n[        U4SS0UD6n[        UR                  5       5      U
R                  :w  a   [        UR                  SS95      nUR'                  5        H  u  pÞXÕ;   a  X]==   U-  ss'   M  XåU'   M     Mø     U(       d  U$ [        U[        5      (       d  [(        nUR'                  5        VVs0 s H  u  nnU" U5      U_M     snn$ ! [          a    U(       a  [#        [$        5      e0 n N©f = fs  snnf )Nr   r   r{   rS   Frf   )r|   rq   rr   r   r   r}   Úgetr~   r   r   r   r1   ÚvaluesrY   rR   r€   r�   r   r‚   Úitemsr   )rF   rn   r^   rx   rƒ   r„   r…   r†   r‡   rˆ   r‰   r   rŠ   Úkr2   Úkeyr‹   s                    r-   rw   rw   ï   sŒ  € à×-Ñ-Ó/€GØ€HØ�V‰V�]‰]œr¤2˜hÑ&€FÛˆö ”c˜!“f “kØ�a‘DˆEØ˜5�L‘/ˆCØ$ŸL™L¨¨aÓ0°1Ñ4ˆH‰MÙà�Q�$‘ˆä�h¤×-Ñ-Ø—~‘~¨x�~Ð8‰Hà—~‘~Ó'ˆHä�XÑ7¨Ð7°Ñ7ˆäˆt�{‰{‹}Ó §¡Ó+ðÜ˜H×.Ñ.¸Ð.Ð>Ó?�ð —J‘J–L‰DˆAØ‹}Ø“˜qÑ •à˜“ó	 !ñ7 öB ØˆÜ�h¤×-Ñ-ÜˆØ3;·>±>Ô3CÔDÒ3C¡Z S¨%‰H�S‹M˜5Ò Ñ3CÒDÐDøô! 'ó Þ(Ü%Ô&=Ó>Ð>à’Dð	üó  Es   Ã&FÅ)F+Æ"F(Æ'F(c                 ó  • X R                  U R                  5      U-  -
  nUR                  US9n[        U5      S:X  a  U(       a  UR                  USS9n[        U5      S:X  a  [	        SR                  U5      5      eU$ )z:Get a basis for the eigenspace for a particular eigenvalue)Ú
iszerofuncr   T©r“   r^   z,Can't evaluate eigenvector for eigenvalue {})ÚeyerY   Ú	nullspacer}   r�   rp   )rF   r[   r“   r^   ÚmÚrets         r-   Ú_eigenspacer™     sy   € à
�e‰e�A—F‘F‹m˜hÑ&Ñ
&€AØ
�+‰+ ˆ+Ð
,€Cô ˆ3ƒx�1ƒ}žØ�k‰k Z¸$ˆkÐ?ˆÜ
ˆ3ƒx�1ƒ}Ü!Ø:×AÑAÀ(ÓKóMð 	Mà€Jr5   c                 óÚ   • [         R                  " U SSS9nUR                  5       nUR                  [        :w  a1  [        U5      u  p4[        X4U R                  40 UD6n[        US S9nU$ g )NT)ÚfieldÚ	extensionc                 ó   • [        U S   5      $ )Nr   r   ©r:   s    r-   r3   Ú!_eigenvects_DOM.<locals>.<lambda>3  s   € Ô6FÀqÈÁtÔ6Lr5   ©r‘   )	r   Úfrom_MatrixÚto_denserr   r   r   r   Ú	__class__Úsorted)rF   ÚkwargsÚDOMr_   Ú	algebraicÚ
eigenvectss         r-   Ú_eigenvects_DOMr©   +  sk   € Ü
×
"Ò
" 1¨D¸DÑ
A€CØ
�,‰,‹.€Cà
‡z�z”RÓÜ,¨SÓ1ÑˆÜ,Ø §¡ñ8Ø06ñ8ˆ
ä˜JÑ,LÑMˆ
àÐØr5   c                 ó  • U R                   " SSS0UD6nU H(  nUR                  [        5      (       d  M  [        S5      e   [	        UR                  5       [        S9n/ nU H"  u  px[        XXS9n	UR                  XxU	45        M$     U$ )Nr_   FzYEigenvector computation is not implemented if the matrix have eigenvalues in CRootOf formr    r”   r*   )	Ú	eigenvalsrk   r   r   r¤   r�   r	   r™   rZ   )
rF   r“   r^   rx   r«   r:   r˜   rˆ   ÚmultÚvectss
             r-   Ú_eigenvects_sympyr®   9  sŽ   € Ø—’Ñ4 UÐ4¨eÑ4€Ió ˆØ�5‰5”�>‹>Üð.ó/ð /ñ ô �y—‘Ó(Ô.>Ñ?€IØ
€CÛ‰	ˆÜ˜A¨zÑMˆØ�
‰
�C˜uÐ%Ö&ñ ð €Jr5   ©Úchopc                óì  ^^• UR                  SS5      nUR                  SS5      nUR                  SS5        UR                  SS5        [        U[        5      (       d  U(       a  [        OS mU R                  [        5      nU(       a=  [        S U  5       5      (       a  [        U 5      $ SS	K	J
m  U R                  U4S
 j5      n [        U 5      nUc  [        X4SU0UD6nU(       a&  U4S jn	U V
VVs/ s H  u  p«oÊX¹" U5      4PM     nnn
nU(       aG  U V
VVVs/ s H4  u  p«nU
R                  US9X¼ Vs/ s H  oÝR                  US9PM     sn4PM6     nnnn
nU$ s  snnn
f s  snf s  snnnn
f )aç  Compute eigenvectors of the matrix.

Parameters
==========

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

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

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

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

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

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

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

Returns
=======

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

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

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

Raises
======

NotImplementedError
    If failed to compute nullspace.

Examples
========

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

See Also
========

eigenvals
MatrixBase.nullspace
r^   TFNrS   c                 ó   • U $ r7   r*   rž   s    r-   r3   Ú_eigenvects.<locals>.<lambda>ž  s   € ¹r5   c              3   ó8   #   • U  H  oR                   v •  M     g 7fr7   rb   r9   s     r-   r.   Ú_eigenvects.<locals>.<genexpr>¢  re   r<   r   rg   c                 ó   >• T" U SS9$ rj   r*   rl   s    €r-   r3   r³   ¥  s   ø€ ¡)¨A¸Ò"=r5   c           	      óz   >• U  Vs/ s H(  o[        [        U5      5      -  R                  T5      PM*     sn$ s  snf r7   )r   Úlistru   )Úlr2   Úsimpfuncs     €r-   Údenom_cleanÚ _eigenvects.<locals>.denom_clean®  s1   ø€ ÙDEÓFÂA¸qœœT !›W›Ñ%×0Ñ0°Ö:ÁAÑFÐFùÒFs   †/8r¯   )r�   Úpopr~   r   r   rk   r   rs   r]   rt   rh   ru   r©   r®   rA   )rF   rn   r“   r°   rx   r^   Ú	primitiveÚ
has_floatsr˜   r»   rˆ   r¬   Úesr2   rh   rº   s                 @@r-   Ú_eigenvectsrÁ   L  sR  ù€ ðX �y‰y˜ TÓ*€HØ—	‘	˜* eÓ,€IØ	‡I�Iˆj˜$ÔØ	‡I�Iˆj˜$Ôä�h¤×-Ñ-Þ (•9©kˆà—‘”u“€JÞÜÑ&¡AÓ&×&Ñ&Ü% aÓ(Ð(Ý,Ø�K‰KÔ=Ó>ˆä
˜!Ó
€CØ
�{Ü ÑJ¸ÐJÀEÑJˆæõ	Gñ BEÕEÂ±°¸2�T˜; r›?Ó+ÁˆÒEæñ &)ö*Ú%(‘M�C˜rð —	‘	˜t�	Ð$ dÈÓ,LÊÀA¯W©W¸$¨WÓ-?ÉÑ,LÓMÙ%(ð 	ó *ð €Jùô Fùò -Mùõ *s   Ã8E"Ä E.
Ä;E)ÅE.
Å)E.
c                 óÐ   • U R                   (       d  S/ 4$ U R                  SS9nU H9  u  p4nU(       a  UR                  (       d  SU4s  $ U[        U5      :w  d  M5  SU4s  $    SU4$ )z•See _is_diagonalizable. This function returns the bool along with the
eigenvectors to avoid calculating them again in functions like
``diagonalize``.FTr{   )ro   r¨   Úis_realr}   )rF   Ú
reals_onlyÚ	eigenvecsrˆ   r¬   Úbasiss         r-   Ú_is_diagonalizable_with_eigenrÇ   »  sk   € ð
 �;�;Ø�bˆyÐà—‘ d�Ð+€Iã%Ñˆ�5Þ˜cŸkŸkØ˜)Ð#Ò#à”3�u“:ÕØ˜)Ð#Ò#ñ &ð �ˆ?Ðr5   c                 óê   • U R                   (       d  g[        S U  5       5      (       a  U R                  5       (       a  g[        S U  5       5      (       a  U R                  (       a  g[	        XS9S   $ )a|  Returns ``True`` if a matrix is diagonalizable.

Parameters
==========

reals_only : bool, optional
    If ``True``, it tests whether the matrix can be diagonalized
    to contain only real numbers on the diagonal.


    If ``False``, it tests whether the matrix can be diagonalized
    at all, even with numbers that may not be real.

Examples
========

Example of a diagonalizable matrix:

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

Example of a non-diagonalizable matrix:

>>> M = Matrix([[0, 1], [0, 0]])
>>> M.is_diagonalizable()
False

Example of a matrix that is diagonalized in terms of non-real entries:

>>> M = Matrix([[0, 1], [-1, 0]])
>>> M.is_diagonalizable(reals_only=False)
True
>>> M.is_diagonalizable(reals_only=True)
False

See Also
========

sympy.matrices.matrixbase.MatrixBase.is_diagonal
diagonalize
Fc              3   ó8   #   • U  H  oR                   v •  M     g 7fr7   )rÃ   ©r+   rN   s     r-   r.   Ú%_is_diagonalizable.<locals>.<genexpr>ý  s   é € Ð
 ša˜�9Ž9šaùr<   Tc              3   ó8   #   • U  H  oR                   v •  M     g 7fr7   )Ú
is_complexrÊ   s     r-   r.   rË      s   é € Ð
#¢˜A�<Ž<¢ùr<   ©rÄ   r   )ro   rs   Úis_symmetricÚis_hermitianrÇ   )rF   rÄ   r¥   s      r-   Ú_is_diagonalizablerÑ   Î  sY   € ðX �;�;Øä
Ñ
 ™aÓ
 × Ñ  Q§^¡^×%5Ñ%5Øä
Ñ
#¡Ó
#×#Ñ#¨¯¯Øä(¨ÑBÀ1ÑEÐEr5   c                 óì  • U R                   S:X  d  [        S5      eU R                  5       nU R                  5       nU R                  5       nU S   [        U S   5      -  nU R	                  5       nU S   XE-  -   US'   U S   XE-  -
  US'   U SS 2S4   R	                  5       S:X  a
  SnSUS'   X4$ UR	                  5       UR	                  5       ::  a  UnOUnXS   -  nSUR	                  5       S-  -  nX4$ )Nr   zInput must be a column matrix)r   r   r   r)   )ÚcolsÚ
ValueErrorÚcopyÚabsÚnorm)r:   r2   Úv_plusÚv_minusÚqÚnorm_xÚbets          r-   Ú_householder_vectorrÝ     sø   € Ø�6‰6�Q‹;ÜÐ8Ó9Ð9Ø	�‰‹€AØ�V‰V‹X€FØ�f‰f‹h€GØ	ˆ$‰”#�a˜‘g“,Ñ€AØ�V‰V‹X€FØ�T‘7˜Q™ZÑ'€Fˆ4�LØ�d‘G˜a™jÑ(€GˆD�MØˆ‰ˆQˆ�x‡}�}ƒ˜!ÓØˆØˆˆ$‰ð ˆ6€Mð �;‰;‹=˜GŸL™L›NÓ*Ø‰AàˆAØ�!‘‰HˆØ�1—6‘6“8˜q‘=Ñ!ˆØˆ6€Mr5   c                 óÚ  • U R                   nU R                  nU R                  5       nUR                  U5      UR                  U5      pT[	        [        X5      5       GH  n[        X6S 2U4   5      u  pxUR                  X-
  5      X‡-  UR                  -  -
  n	X“US 2US 24   -  X6S 2US 24'   UR                  U5      n
XšUS 2US 24'   XJ-  nUS-   US-
  ::  d  M~  [        X6US-   S 24   R                  5      u  pxUR                  X&-
  S-
  5      X‡-  UR                  -  -
  n	X6S 2US-   S 24   U	-  X6S 2US-   S 24'   UR                  U5      n
XšUS-   S 2US-   S 24'   X¥-  nGM	     XCU4$ ©Nr   r)   )	rY   rÓ   Ú
as_mutabler•   rX   ÚminrÝ   ÚHÚT)rF   r—   r=   rK   ÚUÚVr,   r2   rÜ   Úhh_matÚtemps              r-   Ú_bidiagonal_decmp_hholderrè     sg  € Ø	�‰€AØ	�‰€AØ	�‰‹€AØ�5‰5�‹8�Q—U‘U˜1“X€qÜ”3�q“9×ˆÜ$ Q¡r¨1 u¡XÓ.‰ˆØ—‘�q‘u“ ¡¨!¯#©#¡Ñ-ˆØ˜q™r 1¡2˜v™YÑ&ˆ‰"ˆa‰bˆ&‰	Ø�u‰u�Q‹xˆØˆQ‰R�‘ˆV‰Ø‰HˆØˆq‰5�A˜‘E�>Ü(¨¨a°©c©d¨7©¯©Ó6‰FˆAØ—U‘U˜1™5 1™9Ó%¨©°!·#±#©Ñ5ˆFØ™B  !¡¡˜H™+¨Ñ.ˆA‰b�!�A‘#‘$ˆh‰KØ—5‘5˜“8ˆDØ%��1‘‘�q˜‘s‘t�ÑØ‘‹Añ ð �ˆ7€Nr5   c                 ó  • U R                   nU R                  nU R                  5       n[        [	        X5      5       HÁ  n[        X4S 2U4   5      u  pVUR                  X-
  5      Xe-  UR                  -  -
  nXsUS 2US 24   -  X4S 2US 24'   US-   US-
  ::  d  M^  [        X4US-   S 24   R                  5      u  pVUR                  X$-
  S-
  5      Xe-  UR                  -  -
  nX4S 2US-   S 24   U-  X4S 2US-   S 24'   MÃ     U$ rß   )	rY   rÓ   rà   rX   rá   rÝ   r•   râ   rã   )rF   r—   r=   rK   r,   r2   rÜ   ræ   s           r-   Ú_eval_bidiag_hholderrê   4  sý   € Ø	�‰€AØ	�‰€AØ	�‰‹€AÜ”3�q“9ÖˆÜ$ Q¡r¨1 u¡XÓ.‰ˆØ—‘�q‘s“˜c™g¨¯©™mÑ+ˆØ˜q™r 1¡2˜v™YÑ&ˆ‰"ˆa‰bˆ&‰	Øˆq‰5�A˜‘E�>Ü(¨¨a°©c©d¨7©¯©Ó6‰FˆAØ—U‘U˜1™5 1™9Ó%¨©°!·#±#©Ñ5ˆFØ™B  !¡¡˜H™+¨Ñ.ˆA‰b�!�A‘#‘$ˆh‹Kñ ð €Hr5   c                 óè   • [        U[        5      (       d  [        S5      eU(       a  [        U 5      $ [        U R                  5      nUS   R                  US   R                  US   R                  4$ )aû  
Returns $(U,B,V.H)$ for

$$A = UBV^{H}$$

where $A$ is the input matrix, and $B$ is its Bidiagonalized form

Note: Bidiagonal Computation can hang for symbolic matrices.

Parameters
==========

upper : bool. Whether to do upper bidiagnalization or lower.
            True for upper and False for lower.

References
==========

.. [1] Algorithm 5.4.2, Matrix computations by Golub and Van Loan, 4th edition
.. [2] Complex Matrix Bidiagonalization, https://github.com/vslobody/Householder-Bidiagonalization

úupper must be a booleanr)   r   r   )r~   ÚboolrÔ   rè   râ   )rF   ÚupperÚXs      r-   Ú_bidiagonal_decompositionrð   C  s^   € ô0 �eœT×"Ñ"ÜÐ2Ó3Ð3æÜ(¨Ó+Ð+ä! !§#¡#Ó&€AØˆQ‰4�6‰6�1�Q‘4—6‘6˜1˜Q™4Ÿ6™6Ð!Ð!r5   c                 ó¤   • [        U[        5      (       d  [        S5      eU(       a  [        U 5      $ [        U R                  5      R                  $ )aÊ  
Returns $B$, the Bidiagonalized form of the input matrix.

Note: Bidiagonal Computation can hang for symbolic matrices.

Parameters
==========

upper : bool. Whether to do upper bidiagnalization or lower.
            True for upper and False for lower.

References
==========

.. [1] Algorithm 5.4.2, Matrix computations by Golub and Van Loan, 4th edition
.. [2] Complex Matrix Bidiagonalization : https://github.com/vslobody/Householder-Bidiagonalization

rì   )r~   rí   rÔ   rê   râ   )rF   rî   s     r-   Ú_bidiagonalizerò   e  s@   € ô( �eœT×"Ñ"ÜÐ2Ó3Ð3æÜ# AÓ&Ð&Ü §¡Ó$×&Ñ&Ð&r5   c                 ól  • U R                   (       d
  [        5       e[        U US9u  pEU(       d  [        S5      eU(       a  [	        U[
        S9n/ / pvU H  u  p‰n
Xx/U	-  -  nXj-  nM     U(       a"  U Vs/ s H  o»UR                  5       -  PM     nnU R                  " U6 U R                  " U6 4$ s  snf )a0  
Return (P, D), where D is diagonal and

    D = P^-1 * M * P

where M is current matrix.

Parameters
==========

reals_only : bool. Whether to throw an error if complex numbers are need
                to diagonalize. (Default: False)

sort : bool. Sort the eigenvalues along the diagonal. (Default: False)

normalize : bool. If True, normalize the columns of P. (Default: False)

Examples
========

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

See Also
========

sympy.matrices.matrixbase.MatrixBase.is_diagonal
is_diagonalizable
rÎ   zMatrix is not diagonalizabler    )	ro   r   rÇ   r   r¤   r	   r×   ÚhstackÚdiag)rF   rÄ   ÚsortÚ	normalizeÚis_diagonalizablerÅ   Úp_colsrõ   rˆ   r¬   rÆ   r2   s               r-   Ú_diagonalizerú   �  s¶   € ðh �;�;Ü"Ó$Ð$ä#@ÀØ%ñ$'Ñ Ðö ÜÐ8Ó9Ð9æÜ˜9Ô*:Ñ;ˆ	à�rˆDã%Ñˆ�5Ø�%˜$‘,ÑˆØ‰Šñ &ö Ù(.Ó/ª 1�a—f‘f“h”,©ˆÐ/à�8Š8�VÐ˜aŸfšf d˜mÐ+Ð+ùò 0s   Á5B1c                 ób   • U R                  5       nUSL a  gU(       a  U R                  (       a  gg ©NFT)Ú_has_positive_diagonalsÚis_strongly_diagonally_dominant)rF   Úpositive_diagonalss     r-   Ú_fuzzy_positive_definiter   Í  s-   € Ø×2Ñ2Ó4ÐØ˜UÒ"Øæ˜a×?×?Øàr5   c                 ób   • U R                  5       nUSL a  gU(       a  U R                  (       a  gg rü   )Ú_has_nonnegative_diagonalsÚis_weakly_diagonally_dominant)rF   Únonnegative_diagonalss     r-   Ú_fuzzy_positive_semidefiniter  Ø  s-   € Ø×8Ñ8Ó:ÐØ Ò%Øæ ×!@×!@Øàr5   c                 óš   • U R                   (       d   U R                  (       d  gX R                  -   n [        U 5      nUb  U$ [	        U 5      $ ©NF)rÐ   ro   râ   r   Ú_is_positive_definite_GE©rF   Úfuzzys     r-   r#   r#   ã  s>   € Ø�>�>Ø�{�{ØØ—‘‰Gˆä$ QÓ'€EØÑØˆä# AÓ&Ð&r5   c                 óš   • U R                   (       d   U R                  (       d  gX R                  -   n [        U 5      nUb  U$ [	        U 5      $ r  )rÐ   ro   râ   r  Ú"_is_positive_semidefinite_choleskyr	  s     r-   r$   r$   ð  s>   € Ø�>�>Ø�{�{ØØ—‘‰Gˆä(¨Ó+€EØÑØˆä-¨aÓ0Ð0r5   c                 ó   • [        U * 5      $ r7   )r#   ©rF   s    r-   r!   r!   ý  s   € Ü  ! Ó$Ð$r5   c                 ó   • [        U * 5      $ r7   )r$   r  s    r-   r"   r"     s   € Ü$ a RÓ(Ð(r5   c                 ó”  • U R                   (       a„  U R                  5       nUR                  5        Vs/ s H  o"R                  PM     nn[	        U5      nUR                  5        Vs/ s H  o"R
                  PM     nn[	        U5      n[        XF/5      $ U R                  (       a  X R                  -   R                  $ gs  snf s  snf r  )
rÐ   r«   ÚkeysÚis_positiver   Úis_negativer   ro   râ   Úis_indefinite)rF   Úeigenr:   Úargs1Úany_positiveÚargs2Úany_negatives          r-   r    r      s�   € Ø‡~‡~Ø—‘“ˆØ/4¯z©z¬|Ó<ª|¨!Ÿœ©|ˆÐ<Ü “ˆØ/4¯z©z¬|Ó<ª|¨!Ÿœ©|ˆÐ<Ü “ˆä˜,Ð5Ó6Ð6à	
��Ø—C‘C‘×&Ñ&Ð&àùò =ùâ<s   ´C Á(Cc                 ó  • U R                  5       n U R                  n[        U5       H`  nXU4   R                  nUSLa  Us  $ [        US-   U5       H1  nXU4   XUS-   S24   -  XU4   XUS-   S24   -  -
  XUS-   S24'   M3     Mb     g)zNA division-free gaussian elimination method for testing
positive-definiteness.Tr   N)rà   rY   rX   r  )rF   Úsizer,   r  Újs        r-   r  r    s£   € ð 	
�‰‹€AØ�6‰6€Dä�4Ž[ˆØ˜1˜‘g×)Ñ)ˆØ˜dÒ"ØÒÜ�q˜‘s˜DÖ!ˆAØ˜a˜4™ 1¨¨!©© W¡:Ñ-°°Q°$±¸!¸qÀ¹s¹t¸G¹*Ñ0DÑDˆA��1‘‘ˆg‹Jó "ñ	 ð r5   c           	      ó„  • U R                  5       n [        U R                  5       GHƒ  n[        XR                  5       Vs/ s H  o X"4   PM
     nn[        U5      u  pEpgU(       a    gUc^  [        US-   U R                  5       H?  n[        XR                  5       H#  nXU4   R
                  n	U	c        gU	SL d  M!        g   MA       gXU4   R                  (       d  UR                  (       a    gXU4   R                  (       a  UR                  (       d    gUS:”  a(  U R                  XU-   5        U R                  XU-   5        [        XU4   5      XU4'   XUS-   S24==   XU4   -  ss'   XS-   S2US-   S24==   XUS-   S24   R                  XUS-   S24   -  -  ss'   GM†     U S   R                  $ s  snf )zÏUses Cholesky factorization with complete pivoting

References
==========

.. [1] http://eprints.ma.man.ac.uk/1199/1/covered/MIMS_ep2008_116.pdf

.. [2] https://www.value-at-risk.net/cholesky-factorization/
Nr   FTr   )éÿÿÿÿr  )rà   rX   rY   r   rÓ   Úis_zeror  Úis_nonnegativeÚcol_swapÚrow_swapr   râ   )
rF   r�   r,   ÚdiagsÚpivotÚ	pivot_valÚnonzerorT   r  Úiszeros
             r-   r  r  $  s�  € ð 	
�‰‹€AÜ�1—6‘6�]ˆÜ"'¨¯6©6Ô"2Ó3Ò"2˜Q�1�4”Ñ"2ˆÐ3Ü'=¸eÓ'DÑ$ˆ˜'æÙà‰=Ü˜1˜Q™3 §¡Ö'�Ü˜q§&¡&Ö)�AØ !˜t™WŸ_™_�FØ‘~Û#Ø 5œÛ$ó *ñ (ñ à�ˆT‰7×× )×"7×"7ÙØ�q�D‘'×(×(¨Y×-E×-EÙà�1‹9Ø�J‰J�q˜E™'Ô"Ø�J‰J�q˜E™'Ô"ä�q˜A˜‘w“-ˆˆQˆ$‰Ø	ˆQˆq‰S‰Tˆ'‹
�a˜1˜‘gÑ‹
Ø	ˆA‰#‰$��!‘‘ˆ*‹˜˜a ™c™d˜7™Ÿ™¨¨Q¨q©S©T¨'©
Ñ2Ñ2Žñ9 ð< ˆV‰9×#Ñ#Ð#ùò; 4s   ÁF=aP  Finds out the definiteness of a matrix.

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

    A square real matrix $A$ is:

    - A positive definite matrix if $x^T A x > 0$
      for all non-zero real vectors $x$.
    - A positive semidefinite matrix if $x^T A x \geq 0$
      for all non-zero real vectors $x$.
    - A negative definite matrix if $x^T A x < 0$
      for all non-zero real vectors $x$.
    - A negative semidefinite matrix if $x^T A x \leq 0$
      for all non-zero real vectors $x$.
    - An indefinite matrix if there exists non-zero real vectors
      $x, y$ with $x^T A x > 0 > y^T A y$.

    A square complex matrix $A$ is:

    - A positive definite matrix if $\text{re}(x^H A x) > 0$
      for all non-zero complex vectors $x$.
    - A positive semidefinite matrix if $\text{re}(x^H A x) \geq 0$
      for all non-zero complex vectors $x$.
    - A negative definite matrix if $\text{re}(x^H A x) < 0$
      for all non-zero complex vectors $x$.
    - A negative semidefinite matrix if $\text{re}(x^H A x) \leq 0$
      for all non-zero complex vectors $x$.
    - An indefinite matrix if there exists non-zero complex vectors
      $x, y$ with $\text{re}(x^H A x) > 0 > \text{re}(y^H A y)$.

    A matrix need not be symmetric or hermitian to be positive definite.

    - A real non-symmetric matrix is positive definite if and only if
      $\frac{A + A^T}{2}$ is positive definite.
    - A complex non-hermitian matrix is positive definite if and only if
      $\frac{A + A^H}{2}$ is positive definite.

    And this extension can apply for all the definitions above.

    However, for complex cases, you can restrict the definition of
    $\text{re}(x^H A x) > 0$ to $x^H A x > 0$ and require the matrix
    to be hermitian.
    But we do not present this restriction for computation because you
    can check ``M.is_hermitian`` independently with this and use
    the same procedure.

    Examples
    ========

    An example of symmetric positive definite matrix:

    .. plot::
        :context: reset
        :format: doctest
        :include-source: True

        >>> from sympy import Matrix, symbols
        >>> from sympy.plotting import plot3d
        >>> a, b = symbols('a b')
        >>> x = Matrix([a, b])

        >>> A = Matrix([[1, 0], [0, 1]])
        >>> A.is_positive_definite
        True
        >>> A.is_positive_semidefinite
        True

        >>> p = plot3d((x.T*A*x)[0, 0], (a, -1, 1), (b, -1, 1))

    An example of symmetric positive semidefinite matrix:

    .. plot::
        :context: close-figs
        :format: doctest
        :include-source: True

        >>> A = Matrix([[1, -1], [-1, 1]])
        >>> A.is_positive_definite
        False
        >>> A.is_positive_semidefinite
        True

        >>> p = plot3d((x.T*A*x)[0, 0], (a, -1, 1), (b, -1, 1))

    An example of symmetric negative definite matrix:

    .. plot::
        :context: close-figs
        :format: doctest
        :include-source: True

        >>> A = Matrix([[-1, 0], [0, -1]])
        >>> A.is_negative_definite
        True
        >>> A.is_negative_semidefinite
        True
        >>> A.is_indefinite
        False

        >>> p = plot3d((x.T*A*x)[0, 0], (a, -1, 1), (b, -1, 1))

    An example of symmetric indefinite matrix:

    .. plot::
        :context: close-figs
        :format: doctest
        :include-source: True

        >>> A = Matrix([[1, 2], [2, -1]])
        >>> A.is_indefinite
        True

        >>> p = plot3d((x.T*A*x)[0, 0], (a, -1, 1), (b, -1, 1))

    An example of non-symmetric positive definite matrix.

    .. plot::
        :context: close-figs
        :format: doctest
        :include-source: True

        >>> A = Matrix([[1, 2], [-2, 1]])
        >>> A.is_positive_definite
        True
        >>> A.is_positive_semidefinite
        True

        >>> p = plot3d((x.T*A*x)[0, 0], (a, -1, 1), (b, -1, 1))

    Notes
    =====

    Although some people trivialize the definition of positive definite
    matrices only for symmetric or hermitian matrices, this restriction
    is not correct because it does not classify all instances of
    positive definite matrices from the definition $x^T A x > 0$ or
    $\text{re}(x^H A x) > 0$.

    For instance, ``Matrix([[1, 2], [-2, 1]])`` presented in
    the example above is an example of real positive definite matrix
    that is not symmetric.

    However, since the following formula holds true;

    .. math::
        \text{re}(x^H A x) > 0 \iff
        \text{re}(x^H \frac{A + A^H}{2} x) > 0

    We can classify all positive definite matrices that may or may not
    be symmetric or hermitian by transforming the matrix to
    $\frac{A + A^T}{2}$ or $\frac{A + A^H}{2}$
    (which is guaranteed to be always real symmetric or complex
    hermitian) and we can defer most of the studies to symmetric or
    hermitian positive definite matrices.

    But it is a different problem for the existence of Cholesky
    decomposition. Because even though a non symmetric or a non
    hermitian matrix can be positive definite, Cholesky or LDL
    decomposition does not exist because the decompositions require the
    matrix to be symmetric or hermitian.

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Definiteness_of_a_matrix#Eigenvalues

    .. [2] https://mathworld.wolfram.com/PositiveDefiniteMatrix.html

    .. [3] Johnson, C. R. "Positive Definite Matrices." Amer.
        Math. Monthly 77, 259-264 1970.
    c                óˆ  ^ ^^^ ^!^"^#^$• T R                   (       d  [        S5      eT m!T R                  [        5      m T (       a6   [	        S T R                  5        5       5      n[	        [        U5      S5      m#UU U#4S jn0 m"U U!U"4S jmU U4S jnS nU 4S	 jnT (       a  S
SKJ	m$  T!R                  U$4S j5      m!T!R                  5       nU H(  n	U	R                  [        5      (       d  M  [        S5      e   [        UR                  5       5      T!R                   :X  a{  [#        UR                  5       [$        S9n
T!R&                  " U
6 nU(       d  U" U5      $ U
 Vs/ s H  nT" US5      R)                  5       S
   PM     nnT!R*                  " U6 nU" Xë5      $ / n[#        UR                  5       [$        S9 H‹  nXŒ   nU" UU5      nU" U5      n[-        U5       VVs/ s H  u  nnUS-   U4PM     nnnUR/                  5         UR1                  U VVVs/ s H  u  nn[3        U5        H  nUU4PM	     M     snnn5        M�     [5        S U 5       5      nUT R6                  :w  a  [        SR9                  T 5      5      eU!4S jU 5       n
T!R&                  " U
6 nU(       d  U" U5      $ / n[#        UR                  5       [$        S9 H±  n/ nU H¦  u  nnUU:w  a  M  T" UU5      R)                  5       nT" UUS-
  5      R)                  5       nU" UU-   U5      n[3        U5       Vs/ s H  nT" UU5      R;                  USS9PM     nnUR1                  U5        UR1                  [=        U5      5        M¨     M³     T!R*                  " U6 nU" Xë5      $ ! [         a    Sn GNEf = fs  snf s  snnf s  snnnf s  snf )a¤  Return $(P, J)$ where $J$ is a Jordan block
matrix and $P$ is a matrix such that $M = P J P^{-1}$

Parameters
==========

calc_transform : bool
    If ``False``, then only $J$ is returned.

chop : bool
    All matrices are converted to exact types when computing
    eigenvalues and eigenvectors.  As a result, there may be
    approximation errors.  If ``chop==True``, these errors
    will be truncated.

Examples
========

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

See Also
========

jordan_block
z&Only square matrices have Jordan formsc              3   óh   #   • U  H(  n[        U[        5      (       d  M  UR                  v •  M*     g 7fr7   )r~   r   r8   )r+   Úterms     r-   r.   Ú_jordan_form.<locals>.<genexpr>0  s    é € ÐX²*¨$Ä
È4ÔQV×@W›:˜4Ÿ:ž:²*ùs   ‚2Ÿ2é5   é   c                  ó†   >• T(       a  U  Vs/ s H  oR                  TTS9PM     n n[        U 5      S:X  a  U S   $ U $ s  snf )zEIf ``has_floats`` is `True`, cast all ``args`` as
matrices of floats.)r=   r°   r   r   )rA   r}   )Úargsr—   r°   r¿   Úmax_dpss     €€€r-   Úrestore_floatsÚ$_jordan_form.<locals>.restore_floats:  sF   ø€ ö Ù;?Ó@º4°a—G‘G˜g¨D�GÓ1¹4ˆDÐ@Üˆt‹9˜‹>Ø˜‘7ˆNàˆùò	 As   �>c                 óè   >• X4T;   a  TX4   $ XS-
  4T;   a!  TXS-
  4   R                  TU S4   SS9TX4'   O4TU TR                  TR                  5      -  -
  R                  U5      TX4'   TX4   $ )z>Cache computations of ``(M - val*I)**pow`` for quick
retrievalr   N©Údotprodsimp)Úmultiplyr•   rY   Úpow)rˆ   r7  rF   ÚmatÚ	mat_caches     €€€r-   Úeig_matÚ_jordan_form.<locals>.eig_matH  sœ   ø€ ð ˆ:˜Ó"Ø˜c˜ZÑ(Ð(à�q‘ˆ>˜YÓ&Ø$-¨s¸!±G¨nÑ$=×$FÑ$FØ˜s A˜hÑ'°Tð %Gð %;ˆI�s�jÒ!ð &)¨3¨q¯u©u°Q·V±V«}Ñ+<Ñ%<×$AÑ$AÀ#Ó$FˆI�s�jÑ!à˜#˜Ñ$Ð$r5   c                 ó>  >• TR                   nS/nUT" U S5      R                  5       -
  nSnXCS   :w  ah  UR                  U5        XA:X  a   U$ UT" X5      R                  5       -
  nUS-  nXCS   :  d  XA:”  a  [        SR	                  T5      5      eXCS   :w  a  Mh  U$ )zhCalculate the sequence  [0, nullity(E), nullity(E**2), ...]
until it is constant where ``E = M - val*I``r   r   r)   r  zMSymPy had encountered an inconsistent result while computing Jordan block: {})rÓ   ÚrankrZ   r   rp   )rˆ   Úalgebraic_multiplicityrÓ   r˜   Únullityr,   rF   r:  s         €€r-   Únullity_chainÚ#_jordan_form.<locals>.nullity_chainX  sº   ø€ ð —&‘&ˆØ�#ˆØ™  a›×-Ñ-Ó/Ñ/ˆØˆà˜R™Ó Ø�J‰J�wÔàÓ0Øð ˆ
ð ™g c›o×2Ñ2Ó4Ñ4ˆGØ�q‰LˆAð
 ˜R™Ó  GÓ$DÜ!ðç™ ›ó$ð $ð ˜R™Õ ð$ ˆ
r5   c                 óÐ   • [        S[        U 5      S-
  5       Vs/ s H  nSX   -  XS-
     -
  XS-      -
  PM     nn[        U 5      S:”  a  U S   U S   -
  /OU S   /nX#-   $ s  snf )z›Return a list of the size of each Jordan block.
If d_n is the nullity of E**n, then the number
of Jordan blocks of size n is

    2*d_n - d_(n-1) - d_(n+1)r   r)   r  éþÿÿÿr   )rX   r}   )Údr=   ÚmidÚends       r-   Úblocks_from_nullity_chainÚ/_jordan_form.<locals>.blocks_from_nullity_chainw  sz   € ô 6;¸1¼cÀ!»fÀq¹jÔ5IÓJÒ5I°ˆq�‘‰v˜˜a™%™Ñ  1¨¡U¡8Ô+Ñ5IˆÐJô "% Q£¨!£ˆq�‰u�q˜‘u‰}‰o°!°A±$°ˆà‰yÐùò Ks   ›!A#c                 ó®   >• [        U 5      S:X  a  US   $ U H:  nTR                  " X/-   6 R                  SS9u  p4US   [        U 5      :X  d  M8  Us  $    g)zOPicks a vector from big_basis that isn't in
the subspace spanned by small_basisr   T)Úwith_pivotsr  N)r}   rô   Úechelon_form)Úsmall_basisÚ	big_basisr2   rT   ÚpivotsrF   s        €r-   Úpick_vecÚ_jordan_form.<locals>.pick_vec†  sg   ø€ ô ˆ{Ó˜qÓ Ø˜Q‘<ÐãˆAØŸš ;°Ñ#4Ð6×CÑCØ $ð Dð &‰IˆAð �b‰zœS Ó-Õ-Ø’ò r5   r   rg   c                 ó   >• T" U SS9$ rj   r*   rl   s    €r-   r3   Ú_jordan_form.<locals>.<lambda>—  s   ø€ ¡i°¸DÒ&Ar5   zTJordan normal form is not implemented if the matrix have eigenvalues in CRootOf formr    r   c              3   ó*   #   • U  H	  u  pUv •  M     g 7fr7   r*   )r+   rB   r  s      r-   r.   r+  Æ  s   é € ÐA²¡I C�4²ùr0   zOSymPy had encountered an inconsistent result while computing Jordan block. : {}c              3   óF   >#   • U  H  u  pTR                  X!S 9v •  M     g7f))r  Ú
eigenvalueN)Újordan_block)r+   rB   r  r8  s      €r-   r.   r+  Í  s!   øé € Ð_ÊÁ)À#�#×"Ñ"¨Ð"Õ=Êùs   ƒ!Nr4  )ro   r   rk   r   r>   rŽ   rÔ   r   rt   rh   ru   r«   r   r   r}   r  rÓ   r¤   r	   rõ   r–   rô   Ú	enumerateÚreverseÚextendrX   r1   rY   rp   r6  Úreversed)%rF   Úcalc_transformr°   Úmax_precr1  r@  rG  rO  rŠ   r:   ÚblocksÚ
jordan_matrB   Újordan_basisÚ	basis_matÚblock_structurer>  ÚchainÚblock_sizesr,   ÚnumÚ	size_numsr  rT   Újordan_form_sizeÚ	eig_basisÚ	block_eigÚnull_bigÚ
null_smallÚvecÚnew_vecsr:  r¿   r8  r9  r0  rh   s%   ` `                            @@@@@@r-   Ú_jordan_formrm    s“  ÿ€ ðF �;�;Ü"Ð#KÓLÐLà€CØ—‘”u“€Jæð	ÜÑX°!·(±(´*ÓXÓXˆHô ”k (Ó+¨RÓ0ˆ÷	ð €I÷%ö ò>õö Ý,Ø�m‰mÔAÓBˆð �=‰=‹?€Dó ˆØ�5‰5”�>‹>Üð.ó/ð /ñ ô ˆ4�9‰9‹;Ó˜3Ÿ8™8Ó#Ü˜DŸI™I›KÔ-=Ñ>ˆØ—X’X˜vÐ&ˆ
æÙ! *Ó-Ð-ñ "ó#Ú!�Cñ    Q›×1Ñ1Ó3°AÔ6Ù!ð 	ð #à—z’z <Ð0ˆ	á˜iÓ4Ð4à€Oä�d—i‘i“kÔ'7Ô8ˆØ!%¡ÐÙ˜cÐ#9Ó:ˆÙ/°Ó6ˆô /8¸Ô.DÔEÒ.D¡F A s�a˜‘c˜3“ZÑ.Dˆ	ÑEð 	×ÑÔà×ÑÙ*3ÕHª)™Y˜T 3¼UÀ3¿Z¸ˆc�4‹[¹Z‰[©)ÓHö	Jñ 9ô" ÑA±ÓAÓAÐà˜1Ÿ6™6Ó!Üð+ß+1©6°!«9ó6ð 	6ô `ÉÓ_€FØ—’˜6Ð"€JæÙ˜jÓ)Ð)ð €Lä�d—i‘i“kÔ'7Ô8ˆØˆ	ã.‰OˆI�tØ˜CÓÙá! # tÓ,×7Ñ7Ó9ˆHÙ! # t¨a¡xÓ0×;Ñ;Ó=ˆJñ   
¨YÑ 6¸ÓAˆCä" 4œ[ó*Ú(˜ñ    Q›×0Ñ0°À$Ð0ÓGÙ(ð ð *ð ×Ñ˜XÔ&Ø×Ñ¤¨Ó 2Ö3ó!  /ñ 9ð* —
’
˜LÐ)€Iá˜)Ó0Ð0øôM ó 	ð ‹Hð	üòx#ùó" Fùô IùòV*s*   Á N Å $N-Ç!N2È$N8Ì-!N?ÎN*Î)N*c                 óÒ   • U R                  5       R                  " S0 UD6nU VVVVs/ s H'  u  p4oSXE Vs/ s H  ofR                  5       PM     sn4PM)     snnnn$ s  snf s  snnnnf )ak  Returns left eigenvectors and eigenvalues.

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

Examples
========

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

r*   )Ú	transposer¨   )rF   rx   rŠ   rˆ   r¬   rÆ   r¹   s          r-   Ú_left_eigenvectsrp  ú  sW   € ð< �;‰;‹=×#Ò#Ñ, eÑ,€DáPTÖUÒPTÑ<L¸CÀu�$°Ó6²¨1Ÿ™ž±Ñ6Ó7ÑPTÔUÐUùÒ6ùÕUs   ¨A!
µAÁA!
ÁA!
c                 óä  • U R                   U R                  :¼  a*  U R                  R                  U 5      R	                  5       nO)U R                  U R                  5      R	                  5       n/ nUR                  5        H  u  p4U[        U5      /U-  -  nM     [        U5      U R                  :  a(  X R                  /U R                  [        U5      -
  -  -  nUR                  S[        S9  U$ )a  Compute the singular values of a Matrix

Examples
========

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

See Also
========

condition_number
T)rX  r‘   )rY   rÓ   râ   r6  r«   r�   r   r}   Úzerorö   r	   )rF   ÚvalmultpairsÚvalsr�   r2   s        r-   Ú_singular_valuesru    sÂ   € ð$ 	‡v�v�—‘ÓØ—s‘s—|‘| A“×0Ñ0Ó2‰à—z‘z !§#¡#“×0Ñ0Ó2ˆð €Dà×"Ñ"Ö$‰ˆØ”�a“�	˜A‘ÑŠñ %ô
 ˆ4ƒy�1—6‘6ÓØ—‘�˜AŸF™F¤S¨£YÑ.Ñ/Ñ/ˆð 	‡I�I�dÔ 0€IÑ1à€Kr5   N)F)T)TF)FFF)NÚtypesr   Úcollectionsr   Úmpmathr   r   Úmpmath.libmp.libmpfr   Úsympy.core.sortingr	   Úsympy.core.evalfr
   r   Úsympy.core.logicr   r   Úsympy.core.numbersr   Úsympy.core.sympifyr   Ú(sympy.functions.elementary.miscellaneousr   Úsympy.polysr   r   r   r   r   Úsympy.polys.matricesr   Úsympy.polys.matrices.eigenr   r   Úsympy.polys.polytoolsr   Ú
exceptionsr   r   Údeterminantr   Ú	utilitiesr   r   Ú__doctest_requires__rP   rV   r]   ry   r‚   rv   rw   r™   r©   r®   rÁ   rÇ   rÑ   rÝ   rè   rê   rð   rò   rú   r   r  r#   r$   r!   r"   r    r  r  Ú_doc_positive_definiteÚ__doc__rm  rp  ru  r*   r5   r-   Ú<module>rŠ     su  ðÝ Ý ç Ý +å /ß @ß 0Ý $Ý 'Ý 9ß 2Õ 2Ý -ß NÝ %ç 9Ý /ç )ð"ð %1 >ðÐ òô4!òð "ðhØ/4¸uØöhðX2ð ð -2ô&3ðT -2ô*EðZ )0¸%ô òôð& *.¸'ð lÈ5ö lô^ô&5Fòrò.ò,ô"ôD'ô8I,òXòò
'ò
1ò%ò)òò ò)$ðZkð ð\ %;Ð Ô Ø$:Ð Ô !Ø$:Ð Ô Ø$:Ð Ô !Ø$:€Ô ðr1°ö r1òj VóF%r5   