+
    ‹°³jÔ0  ã                   ó®   € ^ RI Ht ^ RIHt ^ RIHtHt ^RIHtH	t	H
t
Ht ^RIHt RR ltRR lt]	3R	 lt]	R
R
3R lt]	R
3R ltR tR t]	R
RR3R ltR# )é    )ÚFunctionType)ÚCoercionFailed)ÚZZÚQQ)Ú_get_intermediate_simpÚ_iszeroÚ_dotprodsimpÚ	_simplify)Ú_find_reasonable_pivotTc	                ó°  a aa€ VV 3R lp	VV 3R lp
VVV 3R lp\        \        4      o^ ^ rÜ. p. pVS8  Edp   WÁ8  Edi   \        V	! V4      VR WE4      w  ppppV F"  w  ppVV,          pVS VS,          V,           &   K$  	  Vf   V^,          pK`  VP                  V4       V^ 8w  d+   V
! VVV,           4       VP                  VVV,           34       VRJ dh   YÍppVS VS,          V,           &   \	        VS,          V,           ^,           V^,           S,          4       F  pS! S V,          V,          4      S V&   K  	  Tp\	        V4       FM  pVV8X  d   K  VRJ d
   VV8  d   K  S VS,          V,           ,          pV! V4      '       d   KB  V! VVVV4       KO  	  V^,          pEKw  VRJ d•   VRJ d�   \        V4       F  w  ppS VS,          V,           ,          pVS VS,          V,           &   \	        VS,          V,           ^,           V^,           S,          4       F  pS! S V,          V,          4      S V&   K  	  K�  	  S \        V4      \        V4      3# )a{  Row reduce a flat list representation of a matrix and return a tuple
(rref_matrix, pivot_cols, swaps) where ``rref_matrix`` is a flat list,
``pivot_cols`` are the pivot columns and ``swaps`` are any row swaps that
were used in the process of row reduction.

Parameters
==========

mat : list
    list of matrix elements, must be ``rows`` * ``cols`` in length

rows, cols : integer
    number of rows and columns in flat list representation

one : SymPy object
    represents the value one, from ``Matrix.one``

iszerofunc : determines if an entry can be used as a pivot

simpfunc : used to simplify elements and test if they are
    zero if ``iszerofunc`` returns `None`

normalize_last : indicates where all row reduction should
    happen in a fraction-free manner and then the rows are
    normalized (so that the pivots are 1), or whether
    rows should be normalized along the way (like the naive
    row reduction algorithm)

normalize : whether pivot rows should be normalized so that
    the pivot value is 1

zero_above : whether entries above the pivot should be zeroed.
    If ``zero_above=False``, an echelon matrix will be returned.
c                 ó   <€ SV R S1,          # ©N© )ÚiÚcolsÚmats   &€€ÚZ/home/luca/screen-checking/.venv/lib/python3.14/site-packages/sympy/matrices/reductions.pyÚget_colÚ!_row_reduce_list.<locals>.get_col/   s   ø€ Ø�1�7�d�7�|Ðó    c                 óÒ   <€ SVS,          V^,           S,           SV S,          V ^,           S,           uSV S,          V ^,           S,          % SVS,          V^,           S,          % R# )é   Nr   )r   Újr   r   s   &&€€r   Úrow_swapÚ"_row_reduce_list.<locals>.row_swap2   s]   ø€ à��$•˜˜A�˜t•|Ð$ c¨!¨D­&°!°aµ%¸µÐ&>ð 	;ˆˆAˆd�F�A˜•E˜4•<Ð  # a¨¥f¨a°!­e°T­\Ò":r   c                óÞ   <€ W1,
          S,          p\        VS,          V^,           S,          4       F7  pS! V SV,          ,          VSWT,           ,          ,          ,
          4      SV&   K9  	  R# )z,Does the row op row[i] = a*row[i] - b*row[j]N)Úrange)	Úar   Úbr   ÚqÚpr   Úisimpr   s	   &&&&  €€€r   Úcross_cancelÚ&_row_reduce_list.<locals>.cross_cancel6   sP   ø€ à�U�D�LˆÜ�q˜•v  A¥ t�|Ö,ˆAÙ˜1˜S �V�8 a¨¨A­E­
¥lÕ2Ó3ˆC�‹Fó -r   NFT)r   r	   r   Úappendr   Ú	enumerateÚtuple)r   Úrowsr   ÚoneÚ
iszerofuncÚsimpfuncÚnormalize_lastÚ	normalizeÚ
zero_abover   r   r#   Úpiv_rowÚpiv_colÚ
pivot_colsÚswapsÚpivot_offsetÚ	pivot_valÚassumed_nonzeroÚnewly_determinedÚoffsetÚvalr   r   r!   ÚrowÚpiv_iÚpiv_jr"   s   f&f&&&&&&                   @r   Ú_row_reduce_listr<   
   sL  ú€ öJö?÷4ô #¤<Ó0€EØ˜!ˆWØ€JØ€Eð �D�.˜W�^ä,BÙ˜Ó   Ð*¨Jó-Bñ	*ˆ�iØÐ)ó
 .‰MˆV�SØ�gÕˆFØ),ˆC��t•˜gÕ%Ó&ñ .ð ÒØ�q�LˆGÙà×Ñ˜'Ô"Ø˜1ÔÙ�W˜l¨WÕ4Ô5Ø�L‰L˜' <°'Õ#9Ð:Ô;ð ˜UÓ"ØˆqˆAØ!ˆC��$•˜•
‰OÜ˜1˜T�6 A�:¨�>¨A°­E°4­<Ö8�Ù˜s 1�v¨	Õ1Ó2��A“ñ 9ð ˆIô ˜–;ˆCà�gŒ~Ùà˜UÓ" s¨W¤}Ùà�c˜$•h Õ(Õ)ˆCÙ˜#�ŠÙá˜ C¨¨gÖ6ñ ð 	�1�‹ð ˜Ó )¨tÓ"3Ü% jÖ1‰LˆE�5Ø˜E $�J¨Õ.Õ/ˆIØ&)ˆC��d•
˜UÕ"Ñ#Ü˜5 �:¨Õ-°Õ1°E¸AµI¸tÕ3CÖD�Ù˜s 1�v¨	Õ1Ó2��A“ó Eñ 2ð ”�jÓ!¤5¨£<Ð/Ð/r   c                 óÌ   € \        \        V 4      V P                  V P                  V P                  WVWER 7	      w  rgpV P                  V P                  V P                  V4      Wx3# )©r,   r-   r.   )r<   Úlistr(   r   r)   Ú_new)	ÚMr*   r+   r,   r-   r.   r   r1   r2   s	   &&&&&&   r   Ú_row_reducerB   |   sU   € ô .¬d°1«g°q·v±v¸q¿v¹vÀqÇuÁuØ°Øô8Ñ€C�Uð �6‰6�!—&‘&˜!Ÿ&™& #Ó&¨
Ð9Ð9r   c                óz  a€ V P                   ^ 8:  g   V P                  ^ 8:  d   R# \        ;QJ d&    V3R lV R,           4       F  '       d   K   RM	  RM! V3R lV R,           4       4      pS! V R,          4      '       d   T;'       d    \        V R,          S4      # T;'       d    \        V R,          S4      # )zžReturns `True` if the matrix is in echelon form. That is, all rows of
zeros are at the bottom, and below each leading non-zero in a row are
exclusively zeros.Tc              3   ó4   <"  € T F  pS! V4      x € K  	  R # 5ir   r   )Ú.0Útr*   s   & €r   Ú	<genexpr>Ú_is_echelon.<locals>.<genexpr>Ž   s   øé € Ð6©X¨‘j —m�m«Xùs   ƒF)ºr   NNr   )r   r   )ºNNNrI   )rI   rI   )r(   r   ÚallÚ_is_echelon)rA   r*   Úzeros_belows   &f r   rL   rL   †   s†   ø€ ð
 	‡v�v�„{�a—f‘f ”kÙç“#Ô6¨Q¨u®XÓ6—#—#’#Ô6¨Q¨u®XÓ6Ó6€Ká�!�D•'×ÒØ×@Ð@œ{¨1¨U­8°ZÓ@Ð@à×=Ð=œ; q¨¥y°*Ó=Ð=r   Fc           	     ó~   € \        V\        4      '       d   TM\        p\        WVRRRR7      w  rVpV'       d   WV3# V# )aB  Returns a matrix row-equivalent to ``M`` that is in echelon form. Note
that echelon form of a matrix is *not* unique, however, properties like the
row space and the null space are preserved.

Examples
========

>>> from sympy import Matrix
>>> M = Matrix([[1, 2], [3, 4]])
>>> M.echelon_form()
Matrix([
[1,  2],
[0, -2]])
TFr>   )Ú
isinstancer   r
   rB   )rA   r*   ÚsimplifyÚwith_pivotsr+   r   ÚpivotsÚ_s   &&&&    r   Ú_echelon_formrT   –   sC   € ô  & h´×=Ò=‰xÄ9€Hä  °Ø¨5¸UôD�N€C�÷ Øˆ{Ðà€Jr   c           	     ón  € R p\        V\        4      '       d   TM\        pV P                  ^ 8:  g   V P                  ^ 8:  d   ^ # V P                  ^8:  g   V P                  ^8:  d    V  Uu. uF
  qQ! V4      NK  	  ppRV9   d   ^# V P                  ^8X  dm   V P                  ^8X  d\   V  Uu. uF
  qQ! V4      NK  	  ppRV9  d
   RV9  d   ^ # V P                  4       pV! V4      '       d
   RV9   d   ^# V! V4      RJ d   ^# V! WR7      w  r‰\        W�VRRRR7      w  ršp	\        V
4      # u upi u upi )zÓReturns the rank of a matrix.

Examples
========

>>> from sympy import Matrix
>>> from sympy.abc import x
>>> m = Matrix([[1, 2], [x, 1 - 1/x]])
>>> m.rank()
2
>>> n = Matrix(3, 3, range(1, 10))
>>> n.rank()
2
c                óæ   a a€ V V3R lp\        S P                  4       Uu. uF  q2! V4      V3NK  	  pp\        V4       UUu. uF  w  r5VNK	  	  pppS P                  VRR7      V3# u upi u uppi )aP  Permute columns with complicated elements as
far right as they can go.  Since the ``sympy`` row reduction
algorithms start on the left, having complexity right-shifted
speeds things up.

Returns a tuple (mat, perm) where perm is a permutation
of the columns to perform to shift the complex columns right, and mat
is the permuted matrix.c                 ó@   <€ \        V3R  lSRV 3,           4       4      # )c              3   ó@   <"  € T F  pS! V4      f   ^M^ x € K  	  R # 5ir   r   )rE   Úer*   s   & €r   rG   ÚO_rank.<locals>._permute_complexity_right.<locals>.complexity.<locals>.<genexpr>Ï   s   øé € ÐJÁ'¸Q™J q›MÒ1‘q°qÔ8Ã'ùs   ƒrJ   )Úsum)r   rA   r*   s   &€€r   Ú
complexityÚ<_rank.<locals>._permute_complexity_right.<locals>.complexityÌ   s   ø€ ô ÔJÀ!ÀAÀqÀDÆ'ÓJÓJÐJr   r   )Úorientation)r   r   ÚsortedÚpermute)rA   r*   r\   r   Úcomplexr   Úperms   ff     r   Ú_permute_complexity_rightÚ(_rank.<locals>._permute_complexity_rightÂ   sj   ù€ ö	Kô
 05°Q·V±V¬}Ó=©}¨!�J˜q“M 1Ó%©}ˆÐ=Ü#)¨'¤?Ô3¡?™˜!“1¡?ˆÑ3à—	‘	˜$¨F�	Ó3°TÐ:Ð:ùò >ùÛ3s   ¡A(ÁA-FN)r*   Tr>   )rO   r   r
   r(   r   ÚdetrB   Úlen)rA   r*   rP   rc   r+   ÚxÚzerosÚdr   rS   rR   s   &&&        r   Ú_rankrj   ²   s  € ò ;ô( & h´×=Ò=‰xÄ9€Hð
 	‡v�v�„{�a—f‘f ”kÙà‡v�v�„{�a—f‘f ”kÙ()Ó*© 1�˜A–©ˆÐ*à�EŒ>Ùà‡v�v�„{�q—v‘v ”{Ù()Ó*© 1�˜A–©ˆÐ*à˜Ô $¨eÔ"3Ùà�E‰E‹Gˆá�a�=Š=˜U eœ^ÙÙ�a‹=˜EÓ!Ùá,¨QÔF�F€CÜ˜s°ÈØ¨ô/�L€Aˆqô ˆv‹;Ðùò- +ùò +s   Á,D-Â-D2c                 óè  € \        V R 4      '       g   R# V P                  pVP                  pVP                  '       d   V# VP                  '       d    VP                  \        4      # \        ;QJ d    R V  4       F  '       d   K   RM	  RM! R V  4       4      '       g   R#  VP                  \        4      #   \         d    Tu # i ; i  \         d    TP                  \        4      u # i ; i)Ú_repNc              3   ó8   "  € T F  qP                   x € K  	  R # 5ir   )Úis_Rational)rE   rY   s   & r   rG   Ú_to_DM_ZZ_QQ.<locals>.<genexpr>  s   é € Ð,©! Q—=–=«!ùs   ‚FT)
Úhasattrrl   ÚdomainÚis_ZZÚis_QQÚ
convert_tor   r   rK   r   )rA   ÚrepÚKs   &  r   Ú_to_DM_ZZ_QQrw   ø   sÀ   € ô �1�f×ÒÙà
�&‰&€CØ�
‰
€Aà‡w‡w€wØˆ
Ø	
��ˆð	Ø—>‘>¤"Ó%Ð%÷ ‹sÑ,©!Ó,�s�sŠsÑ,©!Ó,×,Ò,Ùð	&Ø—>‘>¤"Ó%Ð%øô ô 	ØŠJð	ûô ô 	&Ø—>‘>¤"Ó%Ò%ð	&ús$   ÁB; Â&C Â;CÃ
CÃ C1Ã0C1c                ó  € V P                   pVP                  '       d.   V P                  RR7      w  r#pVP                  4       V,          pM'VP                  '       d   V P                  4       w  r$MQ hVP                  4       pWT3# )z7Compute the reduced row echelon form of a DomainMatrix.F)Úkeep_domain)rq   rr   Úrref_denÚto_fieldrs   ÚrrefÚ	to_Matrix)ÚdMrv   ÚdM_rrefÚdenrR   ÚM_rrefs   &     r   Ú_rref_dmr‚     so   € à
�	‰	€Aà‡w‡w€wØ!Ÿ{™{°u˜{Ó=Ñˆ�fØ×"Ñ"Ó$ sÕ*‰Ø	
��ˆØŸ'™'›)‰ˆ�àˆuà×ÑÓ €Fàˆ>Ðr   c           	     óº   € \        V 4      pVe   \        V4      w  rgM2\        V\        4      '       d   TpM\        p\        WVVRRR7      w  rgp	V'       d   Wg3# V# )aA  Return reduced row-echelon form of matrix and indices
of pivot vars.

Parameters
==========

iszerofunc : Function
    A function used for detecting whether an element can
    act as a pivot.  ``lambda x: x.is_zero`` is used by default.

simplify : Function
    A function used to simplify elements when looking for a pivot.
    By default SymPy's ``simplify`` is used.

pivots : True or False
    If ``True``, a tuple containing the row-reduced matrix and a tuple
    of pivot columns is returned.  If ``False`` just the row-reduced
    matrix is returned.

normalize_last : True or False
    If ``True``, no pivots are normalized to `1` until after all
    entries above and below each pivot are zeroed.  This means the row
    reduction algorithm is fraction free until the very last step.
    If ``False``, the naive row reduction procedure is used where
    each pivot is normalized to be `1` before row operations are
    used to zero above and below the pivot.

Examples
========

>>> from sympy import Matrix
>>> from sympy.abc import x
>>> m = Matrix([[1, 2], [x, 1 - 1/x]])
>>> m.rref()
(Matrix([
[1, 0],
[0, 1]]), (0, 1))
>>> rref_matrix, rref_pivots = m.rref()
>>> rref_matrix
Matrix([
[1, 0],
[0, 1]])
>>> rref_pivots
(0, 1)

``iszerofunc`` can correct rounding errors in matrices with float
values. In the following example, calling ``rref()`` leads to
floating point errors, incorrectly row reducing the matrix.
``iszerofunc= lambda x: abs(x) < 1e-9`` sets sufficiently small numbers
to zero, avoiding this error.

>>> m = Matrix([[0.9, -0.1, -0.2, 0], [-0.8, 0.9, -0.4, 0], [-0.1, -0.8, 0.6, 0]])
>>> m.rref()
(Matrix([
[1, 0, 0, 0],
[0, 1, 0, 0],
[0, 0, 1, 0]]), (0, 1, 2))
>>> m.rref(iszerofunc=lambda x:abs(x)<1e-9)
(Matrix([
[1, 0, -0.301369863013699, 0],
[0, 1, -0.712328767123288, 0],
[0, 0,         0,          0]]), (0, 1))

Notes
=====

The default value of ``normalize_last=True`` can provide significant
speedup to row reduction, especially on matrices with symbols.  However,
if you depend on the form row reduction algorithm leaves entries
of the matrix, set ``normalize_last=False``
T)r-   r.   )rw   r‚   rO   r   r
   rB   )
rA   r*   rP   rR   r,   r~   r   r1   r+   rS   s
   &&&&&     r   Ú_rrefr„   '  sf   € ôT 
�a‹€Bà	‚~ä" 2›,‰ˆˆZô �h¤×-Ò-Ø‰Hä ˆHä(¨¸Ø¨$¸4ôAÑˆ˜÷ ØˆÐàˆ
r   N)TTT)Útypesr   Úsympy.polys.polyerrorsr   Úsympy.polys.domainsr   r   Ú	utilitiesr   r   r	   r
   Údeterminantr   r<   rB   rL   rT   rj   rw   r‚   r„   r   r   r   Ú<module>rŠ      se   ðÝ å 1ß &ç OÓ OÝ /ôn0ôd:ð &ô >ð  !(°%ÀUô ð8  ¨%ô CòL&ò<ð"  ¨%¸Øö\r   