ó
    ‰*£hKb  ã                   óÎ   • S SK Jr  S SKJrJrJr  S SKJr  SSKJ	r	J
r
Jr  SSKJr  SSKJrJr  S rS	 rS
 rS rS rS rS r\4S jrS rSS jrSS jrSS jrSS jrSS jrg)é    )Ú
expand_mul)ÚDummyÚuniquely_named_symbolÚsymbols)Únumbered_symbolsé   )Ú
ShapeErrorÚNonSquareMatrixErrorÚNonInvertibleMatrixError)Ú_fuzzy_positive_definite)Ú_get_intermediate_simpÚ_iszeroc                 óè   ^ ^• T R                  5       (       d  [        S5      eTR                  T R                  :w  a  [        S5      eT R                  TR                  TR                  U U4S j5      $ )aÀ  Solves ``Ax = B`` efficiently, where A is a diagonal Matrix,
with non-zero diagonal entries.

Examples
========

>>> from sympy import Matrix, eye
>>> A = eye(2)*2
>>> B = Matrix([[1, 2], [3, 4]])
>>> A.diagonal_solve(B) == B/2
True

See Also
========

sympy.matrices.dense.DenseMatrix.lower_triangular_solve
sympy.matrices.dense.DenseMatrix.upper_triangular_solve
gauss_jordan_solve
cholesky_solve
LDLsolve
LUsolve
QRsolve
pinv_solve
cramer_solve
zMatrix should be diagonalzSize mismatchc                 ó   >• TX4   TX 4   -  $ ©N© )ÚiÚjÚMÚrhss     €€ÚS/home/mande/repo/quber/.venv/lib/python3.13/site-packages/sympy/matrices/solvers.pyÚ<lambda>Ú!_diagonal_solve.<locals>.<lambda>+   s   ø€ ¨¨Q¨T©°Q°q°t±WÒ)<ó    )Úis_diagonalÚ	TypeErrorÚrowsÚ_newÚcols)r   r   s   ``r   Ú_diagonal_solver    
   sX   ù€ ð6 �=‰=�?‰?ÜÐ3Ó4Ð4Ø
‡x�x�1—6‘6ÓÜ˜Ó(Ð(à�6‰6Ø�‰�#—(‘(Õ<ó>ð >r   c                 óf  ^ ^^^• SSK Jn  T R                  (       d  [        S5      eUR                  T R                  :w  a  [        S5      eT R                  (       d  [        S5      e[        5       nUR                  T R                  UR                  5      m[        UR                  5       Hq  m[        T R                  5       HU  mT TT4   S:X  a  [        S5      eU" UTT4   [        U UUU4S j[        T5       5       5      -
  T TT4   -  5      TTT4'   MW     Ms     T R                  T5      $ )	úÆSolves ``Ax = B``, where A is a lower triangular matrix.

See Also
========

upper_triangular_solve
gauss_jordan_solve
cholesky_solve
diagonal_solve
LDLsolve
LUsolve
QRsolve
pinv_solve
cramer_solve
r   ©ÚMutableDenseMatrixúMatrix must be square.úMatrices size mismatch.ú Matrix must be lower triangular.r   úMatrix must be non-singular.c              3   óB   >#   • U  H  nTTU4   TUT4   -  v •  M     g 7fr   r   ©Ú.0Úkr   ÚXr   r   s     €€€€r   Ú	<genexpr>Ú*_lower_triangular_solve.<locals>.<genexpr>P   s,   øé € ð +;Ú19¨Að ,-¨Q°¨T©7°1°Q¸°T±7®?Ú19ùó   ƒ)Údenser$   Ú	is_squarer
   r   r	   Úis_lowerÚ
ValueErrorr   Úzerosr   Úranger   Úsumr   ©r   r   r$   Údpsr-   r   r   s   `   @@@r   Ú_lower_triangular_solver:   .   s  û€ õ" *à�;�;Ü"Ð#;Ó<Ð<Ø
‡x�x�1—6‘6ÓÜÐ2Ó3Ð3Ø�:�:ÜÐ;Ó<Ð<ä
 Ó
"€CØ
×
"Ñ
" 1§6¡6¨3¯8©8Ó
4€Aä�3—8‘8Ž_ˆÜ�q—v‘v–ˆAØ��A�‰w˜!‹|ÜÐ >Ó?Ð?á˜3˜q !˜t™9¤s÷ +;Ü16°q´ó+;ó (;ñ ;Ø>?ÀÀ1À¹gñFó GˆAˆa�ˆd‹Gó	 ñ ð �6‰6�!‹9Ðr   c           
      ó°  • U R                   (       d  [        S5      eUR                  U R                  :w  a  [        S5      eU R                  (       d  [        S5      e[        5       n[        U R                  5       Vs/ s H  n/ PM     nnU R                  5        H!  u  p5nX5:”  d  M  XC   R                  XV45        M#     UR                  5       n[        UR                  5       HW  n[        UR                  5       H;  nXC    H  u  p†XsU4==   XgX…4   -  -  ss'   M     U" XsU4   XU4   -  5      XsU4'   M=     MY     U R                  U5      $ s  snf )r"   r%   r&   r'   )r2   r
   r   r	   r3   r4   r   r6   Úrow_listÚappendÚ
as_mutabler   r   ©	r   r   r9   r   r   r   Úvr-   Úus	            r   Ú_lower_triangular_solve_sparserB   U   s#  € ð" �;�;Ü"Ð#;Ó<Ð<Ø
‡x�x�1—6‘6ÓÜÐ2Ó3Ð3Ø�:�:ÜÐ;Ó<Ð<ä!Ó#€CÜ˜aŸf™fœÓ&š�1‹B™€DÐ&à—:‘:–<‰ˆˆaØ�5Ø‰G�N‰N˜A˜6Ö"ñ  ð 	�‰Ó€Aä�3—8‘8Ž_ˆÜ�s—x‘x–ˆAØœ‘�Ø�Q�$“˜1˜q˜t™W™9Ñ$•ñ  ñ ˜!˜q˜D™' A¨ d¡GÑ+Ó,ˆA�ˆd‹Gó	 !ñ ð �6‰6�!‹9Ðùò 's   Á?Ec                 ó”  ^ ^^^• SSK Jn  T R                  (       d  [        S5      eUR                  T R                  :w  a  [        S5      eT R                  (       d  [        S5      e[        5       nUR                  T R                  UR                  5      m[        UR                  5       Hˆ  m[        [        T R                  5      5       Hc  mT TT4   S:X  a  [        S5      eU" UTT4   [        U UUU4S j[        TS-   T R                  5       5       5      -
  T TT4   -  5      TTT4'   Me     MŠ     T R                  T5      $ )	úÇSolves ``Ax = B``, where A is an upper triangular matrix.

See Also
========

lower_triangular_solve
gauss_jordan_solve
cholesky_solve
diagonal_solve
LDLsolve
LUsolve
QRsolve
pinv_solve
cramer_solve
r   r#   r%   úMatrix size mismatch.úMatrix is not upper triangular.r   r(   c              3   óB   >#   • U  H  nTTU4   TUT4   -  v •  M     g 7fr   r   r*   s     €€€€r   r.   Ú*_upper_triangular_solve.<locals>.<genexpr>¢   s-   øé € ð +GÚ1E¨Að ,-¨Q°¨T©7°1°Q¸°T±7®?Ú1Eùr0   )r1   r$   r2   r
   r   r	   Úis_upperr   r   r5   r   r6   Úreversedr4   r7   r   r8   s   `   @@@r   Ú_upper_triangular_solverK   €   s  û€ õ" *à�;�;Ü"Ð#;Ó<Ð<Ø
‡x�x�1—6‘6ÓÜÐ0Ó1Ð1Ø�:�:ÜÐ9Ó:Ð:ä
 Ó
"€CØ
×
"Ñ
" 1§6¡6¨3¯8©8Ó
4€Aä�3—8‘8Ž_ˆÜœ% §¡›-Ö(ˆAØ��A�‰w˜!‹|Ü Ð!?Ó@Ð@á˜3˜q !˜t™9¤s÷ +GÜ16°q¸1±u¸a¿f¹fÔ1Eó+Gó (Gñ GØJKÈAÈqÈDÉ'ñRó SˆAˆa�ˆd‹Gó	 )ñ ð �6‰6�!‹9Ðr   c           
      óÔ  • U R                   (       d  [        S5      eUR                  U R                  :w  a  [        S5      eU R                  (       d  [        S5      e[        5       n[        U R                  5       Vs/ s H  n/ PM     nnU R                  5        H!  u  p5nX5:  d  M  XC   R                  XV45        M#     UR                  5       n[        UR                  5       Hi  n[        [        UR                  5      5       HD  n[        XC   5       H  u  p†XsU4==   XgX…4   -  -  ss'   M     U" XsU4   XU4   -  5      XsU4'   MF     Mk     U R                  U5      $ s  snf )rD   r%   rE   rF   )r2   r
   r   r	   rI   r   r   r6   r<   r=   r>   r   rJ   r   r?   s	            r   Ú_upper_triangular_solve_sparserM   §   s-  € ð" �;�;Ü"Ð#;Ó<Ð<Ø
‡x�x�1—6‘6ÓÜÐ0Ó1Ð1Ø�:�:ÜÐ9Ó:Ð:ä!Ó#€CÜ˜aŸf™fœÓ&š�1‹B™€DÐ&à—:‘:–<‰ˆˆaØ�5Ø‰G�N‰N˜A˜6Ö"ñ  ð 	�‰Ó€Aä�3—8‘8Ž_ˆÜœ% §¡›/Ö*ˆAÜ  ¡Ö)‘�Ø�Q�$“˜1˜q˜t™W™9Ñ$•ñ *ñ ˜!˜q˜D™' A¨ d¡GÑ+Ó,ˆA�ˆd‹Gó	 +ñ ð �6‰6�!‹9Ðùò 's   Á?E%c                 ó  • U R                   U R                  :  a  [        S5      eSnSnU R                  5       (       a  SnOU R                  (       d  SnU(       d  [        U 5      SL aC  U R                  nUR                  U 5      n UR                  U5      nU R                  5       (       + nU R                  US9nUR                  U5      nU(       a  UR                  R                  U5      $ UR                  R                  U5      $ )aƒ  Solves ``Ax = B`` using Cholesky decomposition,
for a general square non-singular matrix.
For a non-square matrix with rows > cols,
the least squares solution is returned.

See Also
========

sympy.matrices.dense.DenseMatrix.lower_triangular_solve
sympy.matrices.dense.DenseMatrix.upper_triangular_solve
gauss_jordan_solve
diagonal_solve
LDLsolve
LUsolve
QRsolve
pinv_solve
cramer_solve
ú6Under-determined System. Try M.gauss_jordan_solve(rhs)TF©Ú	hermitian)r   r   ÚNotImplementedErrorÚis_symmetricÚis_hermitianr   ÚHÚmultiplyÚcholeskyÚlower_triangular_solveÚupper_triangular_solveÚT)r   r   rQ   ÚreformrU   ÚLÚYs          r   Ú_cholesky_solver^   Ò   sÞ   € ð( 	‡v�v�—‘ƒÜ!ØDóFð 	Fð €IØ€Fà‡~�~×ÑØ‰	Ø�^�^ØˆæÔ)¨!Ó,°Ò5Ø—C‘CˆØ—J‘J˜q“MˆØ—J‘J˜s“OˆØŸ™Ó(Ô(ˆ	à	�
‰
˜Yˆ
Ð'€AØ	× Ñ  Ó%€AæØ—‘×+Ñ+¨AÓ.Ð.à—‘×+Ñ+¨AÓ.Ð.r   c                 ó:  • U R                   U R                  :  a  [        S5      eSnSnU R                  5       (       a  SnOU R                  (       d  SnU(       d  [        U 5      SL aC  U R                  nUR                  U 5      n UR                  U5      nU R                  5       (       + nU R                  US9u  pVUR                  U5      nUR                  U5      nU(       a  UR                  R                  U5      $ UR                  R                  U5      $ )aA  Solves ``Ax = B`` using LDL decomposition,
for a general square and non-singular matrix.

For a non-square matrix with rows > cols,
the least squares solution is returned.

Examples
========

>>> from sympy import Matrix, eye
>>> A = eye(2)*2
>>> B = Matrix([[1, 2], [3, 4]])
>>> A.LDLsolve(B) == B/2
True

See Also
========

sympy.matrices.dense.DenseMatrix.LDLdecomposition
sympy.matrices.dense.DenseMatrix.lower_triangular_solve
sympy.matrices.dense.DenseMatrix.upper_triangular_solve
gauss_jordan_solve
cholesky_solve
diagonal_solve
LUsolve
QRsolve
pinv_solve
cramer_solve
rO   TFrP   )r   r   rR   rS   rT   r   rU   rV   ÚLDLdecompositionrX   Údiagonal_solverY   rZ   )	r   r   rQ   r[   rU   r\   ÚDr]   ÚZs	            r   Ú	_LDLsolverd     só   € ð> 	‡v�v�—‘ƒÜ!ØDóFð 	Fð €IØ€Fà‡~�~×ÑØ‰	Ø�^�^ØˆæÔ)¨!Ó,°Ò5Ø—C‘CˆØ—J‘J˜q“MˆØ—J‘J˜s“OˆØŸ™Ó(Ô(ˆ	à×Ñ¨	ÐÐ2�D€AØ×#Ñ# CÓ(€AØ×Ñ˜AÓ€AæØ—‘×+Ñ+¨AÓ.Ð.à—‘×+Ñ+¨AÓ.Ð.r   c                 ó‚  ^
^• UR                   U R                   :w  a  [        S5      eU R                   nU R                  nX4:  a  [        S5      e U R	                  USS9u  pV[        5       m
UR                  U5      R                  5       n[        U5       H;  n[        [        X„5      5       H   n	XXU	4   mUR                  X‰U
U4S j5        M"     M=     X4:”  aU  [        XC5       H;  n[        UR                  5       H  n	U" XxU	4   5      (       a  M  [        S5      e   M=     USU2S	S	24   n[        US
-
  SS5       HS  n[        US
-   U5       H   n	XXU	4   mUR                  X‰U
U4S j5        M"     XXU4   mUR                  UU
U4S j5        MU     UR                  U5      $ ! [
         a    [        S5      ef = f)a�  Solve the linear system ``Ax = rhs`` for ``x`` where ``A = M``.

This is for symbolic matrices, for real or complex ones use
mpmath.lu_solve or mpmath.qr_solve.

See Also
========

sympy.matrices.dense.DenseMatrix.lower_triangular_solve
sympy.matrices.dense.DenseMatrix.upper_triangular_solve
gauss_jordan_solve
cholesky_solve
diagonal_solve
LDLsolve
QRsolve
pinv_solve
LUdecomposition
cramer_solve
z4``M`` and ``rhs`` must have the same number of rows.z&Underdetermined systems not supported.T)Ú
iszerofuncÚ	rankcheckú Matrix det == 0; not invertible.c                 ó    >• T" U TU-  -
  5      $ r   r   ©ÚxÚyr9   Úscales     €€r   r   Ú_LUsolve.<locals>.<lambda>h  ó   ø€ ©C°°E¸A±I±Ô,>r   zThe system is inconsistent.r   Nr   éÿÿÿÿc                 ó    >• T" U TU-  -
  5      $ r   r   rj   s     €€r   r   rn   w  ro   r   c                 ó    >• T" TS-  U -  5      $ )Nrp   r   )rk   Ú_r9   rm   s     €€r   r   rn   z  s   ø€ ¡ U¨B¡Y°¡]Ô!3r   )r   r	   r   rR   ÚLUdecomposition_Simpler4   r   r   Úpermute_rowsr>   r6   ÚminÚ
zip_row_opÚrow_opÚ	__class__)r   r   rf   ÚmÚnÚAÚpermÚbr   r   r9   rm   s             @@r   Ú_LUsolver   <  s¸  ù€ ð* ‡x�x�1—6‘6ÓÜØBóDð 	Dð 	
�‰€AØ	�‰€AàƒuÜ!Ð"JÓKÐKðKØ×*Ñ*Ø!¨Tð +ð 3‰ˆô
 !Ó
"€CØ
×
Ñ
˜4Ó
 ×
+Ñ
+Ó
-€Aô �1ŽXˆÜ”s˜1“yÖ!ˆAØ˜�d‘GˆEØ�L‰L˜Õ>Ö?ó "ñ ð 	ƒuÜ�q–ˆAÜ˜1Ÿ6™6–]�Ù! ! q D¡'×*Ó*Ü$Ð%BÓCÐCó #ñ ð
 ˆa�ˆc’1ˆf‰Iˆô �1�q‘5˜"˜bÖ!ˆÜ�q˜1‘u˜a–ˆAØ˜�d‘GˆEØ�L‰L˜Õ>Ö?ñ !ð �Q�$‘ˆØ	�‰�Õ3Ö4ñ "ð �=‰=˜ÓÐøô= ó KÜ&Ð'IÓJÐJðKús   ÁF( Æ(F>c                 ó€  • [        [        [        5      nU R                  5       u  p4UR                  U-  n/ nUR                  n[        US-
  SS5       HS  nXXSS24   n	[        US-   U5       H  n
X”XŠ4   XgS-
  U
-
     -  -  n	M     U" U	5      n	UR                  X”Xˆ4   -  5        MU     U R                  " USSS2   6 $ )aQ  Solve the linear system ``Ax = b``.

``M`` is the matrix ``A``, the method argument is the vector
``b``.  The method returns the solution vector ``x``.  If ``b`` is a
matrix, the system is solved for each column of ``b`` and the
return value is a matrix of the same shape as ``b``.

This method is slower (approximately by a factor of 2) but
more stable for floating-point arithmetic than the LUsolve method.
However, LUsolve usually uses an exact arithmetic, so you do not need
to use QRsolve.

This is mainly for educational purposes and symbolic matrices, for real
(or complex) matrices use mpmath.qr_solve.

See Also
========

sympy.matrices.dense.DenseMatrix.lower_triangular_solve
sympy.matrices.dense.DenseMatrix.upper_triangular_solve
gauss_jordan_solve
cholesky_solve
diagonal_solve
LDLsolve
LUsolve
pinv_solve
QRdecomposition
cramer_solve
r   rp   N)r   r   ÚQRdecompositionrZ   r   r6   r=   Úvstack)r   r~   r9   ÚQÚRrl   rk   r{   r   Útmpr,   s              r   Ú_QRsolver†     sÈ   € ô> "¤*¬jÓ9€CØ×ÑÓ�D€AØ�3‰3�‰7€Að
 	€AØ	�‰€Aä�1�q‘5˜"˜bÖ!ˆØ’1�‰gˆä�q˜1‘u˜a–ˆAØ�Q�T‘7˜Q 1™u q™y™\Ñ)Ñ)ŠCñ !ñ �#‹hˆà	�‰�˜˜‘w‘Öñ "ð �8Š8�Q‘t˜�t‘WÐÐr   c                 ó
  ^• SSK JnJn  U R                  nU R	                  U R                  5       UR                  5       5      nUR                  nUSS2SU* 24   R                  u  nmUR                  SS9u  pšU	SS2SU* 24   U	SS2U* S24   p¹[        [        U4S jU
5      5      n
[        U
5      n[        U	R                  5       Vs/ s H  oÝU
;  d  M
  UPM     nnU" X®-   5      R                  nX¼S2SS24   R                  (       d  [        S5      e[!        SU/S	 S
 S9R"                  n[%        U5      nU" [        TU-
  U-  5       Vs/ s H  n['        U5      PM     sn5      R)                  TU-
  U5      nU	SU2U4   nUSU2SS24   nUR+                  UUU-  -
  U5      nU" TU5      n[        T5       H  nUUSS24   UUU   SS24'   M     U" U5      U" U5      nnU(       a  UUU4$ UU4$ s  snf s  snf )a}  
Solves ``Ax = B`` using Gauss Jordan elimination.

There may be zero, one, or infinite solutions.  If one solution
exists, it will be returned. If infinite solutions exist, it will
be returned parametrically. If no solutions exist, It will throw
ValueError.

Parameters
==========

B : Matrix
    The right hand side of the equation to be solved for.  Must have
    the same number of rows as matrix A.

freevar : boolean, optional
    Flag, when set to `True` will return the indices of the free
    variables in the solutions (column Matrix), for a system that is
    undetermined (e.g. A has more columns than rows), for which
    infinite solutions are possible, in terms of arbitrary
    values of free variables. Default `False`.

Returns
=======

x : Matrix
    The matrix that will satisfy ``Ax = B``.  Will have as many rows as
    matrix A has columns, and as many columns as matrix B.

params : Matrix
    If the system is underdetermined (e.g. A has more columns than
    rows), infinite solutions are possible, in terms of arbitrary
    parameters. These arbitrary parameters are returned as params
    Matrix.

free_var_index : List, optional
    If the system is underdetermined (e.g. A has more columns than
    rows), infinite solutions are possible, in terms of arbitrary
    values of free variables. Then the indices of the free variables
    in the solutions (column Matrix) are returned by free_var_index,
    if the flag `freevar` is set to `True`.

Examples
========

>>> from sympy import Matrix
>>> A = Matrix([[1, 2, 1, 1], [1, 2, 2, -1], [2, 4, 0, 6]])
>>> B = Matrix([7, 12, 4])
>>> sol, params = A.gauss_jordan_solve(B)
>>> sol
Matrix([
[-2*tau0 - 3*tau1 + 2],
[                 tau0],
[           2*tau1 + 5],
[                 tau1]])
>>> params
Matrix([
[tau0],
[tau1]])
>>> taus_zeroes = { tau:0 for tau in params }
>>> sol_unique = sol.xreplace(taus_zeroes)
>>> sol_unique
    Matrix([
[2],
[0],
[5],
[0]])


>>> A = Matrix([[1, 2, 3], [4, 5, 6], [7, 8, 10]])
>>> B = Matrix([3, 6, 9])
>>> sol, params = A.gauss_jordan_solve(B)
>>> sol
Matrix([
[-1],
[ 2],
[ 0]])
>>> params
Matrix(0, 1, [])

>>> A = Matrix([[2, -7], [-1, 4]])
>>> B = Matrix([[-21, 3], [12, -2]])
>>> sol, params = A.gauss_jordan_solve(B)
>>> sol
Matrix([
[0, -2],
[3, -1]])
>>> params
Matrix(0, 2, [])


>>> from sympy import Matrix
>>> A = Matrix([[1, 2, 1, 1], [1, 2, 2, -1], [2, 4, 0, 6]])
>>> B = Matrix([7, 12, 4])
>>> sol, params, freevars = A.gauss_jordan_solve(B, freevar=True)
>>> sol
Matrix([
[-2*tau0 - 3*tau1 + 2],
[                 tau0],
[           2*tau1 + 5],
[                 tau1]])
>>> params
Matrix([
[tau0],
[tau1]])
>>> freevars
[1, 3]


See Also
========

sympy.matrices.dense.DenseMatrix.lower_triangular_solve
sympy.matrices.dense.DenseMatrix.upper_triangular_solve
cholesky_solve
diagonal_solve
LDLsolve
LUsolve
QRsolve
pinv

References
==========

.. [1] https://en.wikipedia.org/wiki/Gaussian_elimination

r   )ÚMatrixr5   NT)Úsimplifyc                 ó   >• U T:  $ r   r   )ÚpÚcols    €r   r   Ú%_gauss_jordan_solve.<locals>.<lambda>@  s	   ø€  a¨#¢gr   zLinear system has no solutionÚtauc                 ó6   • [        U 5      R                  S5      $ )NÚ
1234567890)ÚstrÚrstrip)r   s    r   r   r�   R  s   € œc !›fŸm™m¨LÔ9r   c                 ó   • SU -   $ )Nrs   r   )Úss    r   r   r�   S  s   € ˜S 1šWr   )ÚcompareÚmodify)Úsympy.matricesrˆ   r5   ry   ÚhstackÚcopyr   ÚshapeÚrrefÚlistÚfilterÚlenr6   rZ   Úis_zero_matrixr4   r   Únamer   ÚnextÚreshaper‚   )r   ÚBÚfreevarrˆ   r5   ÚclsÚaugÚB_colsÚrowr|   Úpivotsr@   ÚrankÚcÚfree_var_indexÚpermutationr    Úgenr,   rŽ   ÚVÚvtÚfree_solÚsolrŒ   s                           @r   Ú_gauss_jordan_solver³   µ  s  ø€ ÷B -à�{‰{€CØ�x‰x˜Ÿ™› !§&¡&£(Ó+€CØ�v‰v€FØ’1�h˜�w�h�;Ñ×%Ñ%�H€Cˆð —‘ $�Ð'�I€AØ’!�X�v�g�X�+‘ ¢! f W¡X +¡€qÜ”VÔ-¨vÓ6Ó7€FÜ�F“€Dô "' q§v¡v¤ÓB¢˜A¸6±/—a¡€NÐBñ ˜Ñ0Ó1×3Ñ3€Kð ‰U’AˆX‰;×%×%ÜÐ8Ó9Ð9ô ! ¨¨Ù9Ù$ñ&ç&*¡dð 	ô ˜DÓ!€CÙ¤e¨S°4©Z¸Ñ,?Ô&@ÓAÒ&@ ”4˜–9Ñ&@ÑAÓB×JÑJØ�$‰J˜ó €Cð ��$�˜Ð&Ñ'€AØ��$�š�‰{€BØ�z‰z˜"˜q 3™w™,¨Ó,€Hñ ��VÓ
€Cä�3ŽZˆØ!)¨!ªA¨#¡ˆˆK˜‰NšAÐÓñ ñ �3‹x™˜S›ˆ€CæØ�C˜Ð'Ð'à�CˆxˆùòG Cùò  Bs   Ã	G;ÃG;ÅH Nc                 ób  • SSK Jn  U nU R                  5       nUcP  UR                  UR                  pv[	        SR                  Xg5      [        S9nU R                  XvU5      R                  nUR                  U5      U" UR                  5      UR                  U5      -
  R                  U5      -   $ )a�  Solve ``Ax = B`` using the Moore-Penrose pseudoinverse.

There may be zero, one, or infinite solutions.  If one solution
exists, it will be returned.  If infinite solutions exist, one will
be returned based on the value of arbitrary_matrix.  If no solutions
exist, the least-squares solution is returned.

Parameters
==========

B : Matrix
    The right hand side of the equation to be solved for.  Must have
    the same number of rows as matrix A.
arbitrary_matrix : Matrix
    If the system is underdetermined (e.g. A has more columns than
    rows), infinite solutions are possible, in terms of an arbitrary
    matrix.  This parameter may be set to a specific matrix to use
    for that purpose; if so, it must be the same shape as x, with as
    many rows as matrix A has columns, and as many columns as matrix
    B.  If left as None, an appropriate matrix containing dummy
    symbols in the form of ``wn_m`` will be used, with n and m being
    row and column position of each symbol.

Returns
=======

x : Matrix
    The matrix that will satisfy ``Ax = B``.  Will have as many rows as
    matrix A has columns, and as many columns as matrix B.

Examples
========

>>> from sympy import Matrix
>>> A = Matrix([[1, 2, 3], [4, 5, 6]])
>>> B = Matrix([7, 8])
>>> A.pinv_solve(B)
Matrix([
[ _w0_0/6 - _w1_0/3 + _w2_0/6 - 55/18],
[-_w0_0/3 + 2*_w1_0/3 - _w2_0/3 + 1/9],
[ _w0_0/6 - _w1_0/3 + _w2_0/6 + 59/18]])
>>> A.pinv_solve(B, arbitrary_matrix=Matrix([0, 0, 0]))
Matrix([
[-55/18],
[   1/9],
[ 59/18]])

See Also
========

sympy.matrices.dense.DenseMatrix.lower_triangular_solve
sympy.matrices.dense.DenseMatrix.upper_triangular_solve
gauss_jordan_solve
cholesky_solve
diagonal_solve
LDLsolve
LUsolve
QRsolve
pinv

Notes
=====

This may return either exact solutions or least squares solutions.
To determine which, check ``A * A.pinv() * B == B``.  It will be
True if exact solutions exist, and False if only a least-squares
solution exists.  Be aware that the left hand side of that equation
may need to be simplified to correctly compare to the right hand
side.

References
==========

.. [1] https://en.wikipedia.org/wiki/Moore-Penrose_pseudoinverse#Obtaining_all_solutions_of_a_linear_system

r   )Úeyezw:{}_:{})r¥   )
r—   rµ   Úpinvr   r   Úformatr   ry   rZ   rV   )	r   r£   Úarbitrary_matrixrµ   r|   ÚA_pinvr   r   Úws	            r   Ú_pinv_solver»   k  s—   € õ\ #à€AØ�V‰V‹X€FàÑØŸ6™6 1§6¡6ˆdÜ" :×#4Ñ#4°TÓ#@ÄeÑLˆØŸ;™; t°1Ó5×7Ñ7Ðà�?‰?˜1Ó¡ Q§V¡V£Ø�O‰O˜AÓñ"ß (¡Ð)9Ó :ñ;ð ;r   c                 óÆ  ^ ^^^
^• SSK Jn  U U
UU4S jnTS:X  a	  SSKJn  UnO-TS:X  a	  SSKJn  UnO[        T[        5      (       a  U4S jnOTnU" T 5      nU" TR                  6 n	[        TR                  S   5       HN  m[        TR                  S	   5       H/  m
U" T R                  " / T R                  QUP76 5      U-  U	T
T4'   M1     MP     T R                  U	5      $ )
aÝ  Solves system of linear equations using Cramer's rule.

This method is relatively inefficient compared to other methods.
However it only uses a single division, assuming a division-free determinant
method is provided. This is helpful to minimize the chance of divide-by-zero
cases in symbolic solutions to linear systems.

Parameters
==========
M : Matrix
    The matrix representing the left hand side of the equation.
rhs : Matrix
    The matrix representing the right hand side of the equation.
det_method : str or callable
    The method to use to calculate the determinant of the matrix.
    The default is ``'laplace'``.  If a callable is passed, it should take a
    single argument, the matrix, and return the determinant of the matrix.

Returns
=======
x : Matrix
    The matrix that will satisfy ``Ax = B``.  Will have as many rows as
    matrix A has columns, and as many columns as matrix B.

Examples
========

>>> from sympy import Matrix
>>> A = Matrix([[0, -6, 1], [0, -6, -1], [-5, -2, 3]])
>>> B = Matrix([[-30, -9], [-18, -27], [-26, 46]])
>>> x = A.cramer_solve(B)
>>> x
Matrix([
[ 0, -5],
[ 4,  3],
[-6,  9]])

References
==========

.. [1] https://en.wikipedia.org/wiki/Cramer%27s_rule#Explicit_formulas_for_small_systems

r   )r5   c                 ó*   >• UT:X  a  TU T4   $ TX4   $ r   r   )r   r   r   rŒ   r   r²   s     €€€€r   ÚentryÚ_cramer_solve.<locals>.entryõ  s"   ø€ Ø 3›hˆs�1�c�6‰{Ð3¨A¨a¨d©GÐ3r   Úbird)Ú	_det_birdÚlaplace)Ú_det_laplacec                 ó"   >• U R                  TS9$ )N©Úmethod)Údet)ÚmatrixÚ
det_methods    €r   r   Ú_cramer_solve.<locals>.<lambda>ÿ  s   ø€ ˜VŸZ™Z¨z˜ZÑ:r   r   )
r1   r5   ÚdeterminantrÁ   rÃ   Ú
isinstancer‘   rš   r6   ry   )r   r   rÉ   r5   r¾   rÁ   rÇ   rÃ   Údet_Mrk   rŒ   r²   s   ```       @@r   Ú_cramer_solverÎ   Ç  sÍ   ü€ õX ÷4ð 4ð �VÓÝ*Ø‰Ø	�yÓ	 Ý-Ø‰Ü	�J¤×	$Ñ	$Ü:‰àˆÙ�‹F€EÙˆs�y‰yÐ€AÜ�S—Y‘Y˜q‘\Ö"ˆÜ˜Ÿ™ 1™Ö&ˆCÙ˜aŸkškÐ:¨1¯7©7Ð:°EÒ:Ó;¸eÑCˆAˆc�3ˆh‹Kó 'ñ #ð �;‰;�q‹>Ðr   c                 óâ  • US;   a)   U R                  U5      u  p4U(       a  [        S5      e U$ US:X  a  U R                  U5      $ US:X  a  U R	                  U5      $ US:X  a  U R                  U5      $ US:X  a  U R                  U5      $ US:X  a  U R                  U5      $ US	:X  a  U R                  U5      $ U R                  US
9R                  U5      $ ! [         a    [        S5      ef = f)aØ  Solves linear equation where the unique solution exists.

Parameters
==========

rhs : Matrix
    Vector representing the right hand side of the linear equation.

method : string, optional
    If set to ``'GJ'`` or ``'GE'``, the Gauss-Jordan elimination will be
    used, which is implemented in the routine ``gauss_jordan_solve``.

    If set to ``'LU'``, ``LUsolve`` routine will be used.

    If set to ``'QR'``, ``QRsolve`` routine will be used.

    If set to ``'PINV'``, ``pinv_solve`` routine will be used.

    If set to ``'CRAMER'``, ``cramer_solve`` routine will be used.

    It also supports the methods available for special linear systems

    For positive definite systems:

    If set to ``'CH'``, ``cholesky_solve`` routine will be used.

    If set to ``'LDL'``, ``LDLsolve`` routine will be used.

    To use a different method and to compute the solution via the
    inverse, use a method defined in the .inv() docstring.

Returns
=======

solutions : Matrix
    Vector representing the solution.

Raises
======

ValueError
    If there is not a unique solution then a ``ValueError`` will be
    raised.

    If ``M`` is not square, a ``ValueError`` and a different routine
    for solving the system will be suggested.
)ÚGJÚGEzcMatrix det == 0; not invertible. Try ``M.gauss_jordan_solve(rhs)`` to obtain a parametric solution.rh   ÚLUÚCHÚQRÚLDLÚPINVÚCRAMERrÅ   )Úgauss_jordan_solver   r4   ÚLUsolveÚcholesky_solveÚQRsolveÚLDLsolveÚ
pinv_solveÚcramer_solveÚinvrV   )r   r   rÆ   ÚsolnÚparams        r   Ú_solverâ   
  s	  € ðb �Óð	OØ×.Ñ.¨sÓ3‰KˆDæÜ.ð 0Uó Vð Vð ð ˆà	�4‹Ø�y‰y˜‹~ÐØ	�4‹Ø×Ñ Ó$Ð$Ø	�4‹Ø�y‰y˜‹~ÐØ	�5‹Ø�z‰z˜#‹ÐØ	�6Ó	Ø�|‰|˜CÓ Ð Ø	�8Ó	Ø�~‰~˜cÓ"Ð"à�u‰u˜FˆuÐ#×,Ñ,¨SÓ1Ð1øô% ó 	OÜ*Ð+MÓNÐNð	Oús   ˆ%C ÃC.c                 óú   • US:X  a  U R                  U5      $ US:X  a  U R                  U5      $ US:X  a  U R                  U5      $ US:X  a  U R                  U5      $ U R                  nX0-  R                  X1-  US9$ )a`  Return the least-square fit to the data.

Parameters
==========

rhs : Matrix
    Vector representing the right hand side of the linear equation.

method : string or boolean, optional
    If set to ``'CH'``, ``cholesky_solve`` routine will be used.

    If set to ``'LDL'``, ``LDLsolve`` routine will be used.

    If set to ``'QR'``, ``QRsolve`` routine will be used.

    If set to ``'PINV'``, ``pinv_solve`` routine will be used.

    Otherwise, the conjugate of ``M`` will be used to create a system
    of equations that is passed to ``solve`` along with the hint
    defined by ``method``.

Returns
=======

solutions : Matrix
    Vector representing the solution.

Examples
========

>>> from sympy import Matrix, ones
>>> A = Matrix([1, 2, 3])
>>> B = Matrix([2, 3, 4])
>>> S = Matrix(A.row_join(B))
>>> S
Matrix([
[1, 2],
[2, 3],
[3, 4]])

If each line of S represent coefficients of Ax + By
and x and y are [2, 3] then S*xy is:

>>> r = S*Matrix([2, 3]); r
Matrix([
[ 8],
[13],
[18]])

But let's add 1 to the middle value and then solve for the
least-squares value of xy:

>>> xy = S.solve_least_squares(Matrix([8, 14, 18])); xy
Matrix([
[ 5/3],
[10/3]])

The error is given by S*xy - r:

>>> S*xy - r
Matrix([
[1/3],
[1/3],
[1/3]])
>>> _.norm().n(2)
0.58

If a different xy is used, the norm will be higher:

>>> xy += ones(2, 1)/10
>>> (S*xy - r).norm().n(2)
1.5

rÓ   rÔ   rÕ   rÖ   rÅ   )rÚ   rÛ   rÜ   rÝ   rU   Úsolve)r   r   rÆ   Úts       r   Ú_solve_least_squaresræ   X  s~   € ðX �ƒ~Ø×Ñ Ó$Ð$Ø	�4‹Ø�y‰y˜‹~ÐØ	�5‹Ø�z‰z˜#‹ÐØ	�6Ó	Ø�|‰|˜CÓ Ð à�C‰CˆØ‘�}‰}˜Q™W¨Vˆ}Ð4Ð4r   )Fr   )rÂ   )rÐ   )rÓ   )Úsympy.core.functionr   Úsympy.core.symbolr   r   r   Úsympy.utilities.iterablesr   Ú
exceptionsr	   r
   r   Úeigenr   Ú	utilitiesr   r   r    r:   rB   rK   rM   r^   rd   r   r†   r³   r»   rÎ   râ   ræ   r   r   r   Ú<module>rí      s{   ðÝ *ß CÑ CÝ 6ç RÑ RÝ +ß 6ò!>òH%òN(òV%òN(òV,/ò^8/ðv !(ô @òF3ôlsôlY;ôx@ôFK2õ\V5r   