+
    i<                         ^ RI Ht ^ RIHtHtHt ^ RIHt ^ RIH	t	H
t
 RR/R ltRR	RR/R
 ltR tR tR tR tR tR tR tRR/R ltRR/R ltRR/R ltR tR tR tR tR# )    )ZZ)SDM	sdm_irrefsdm_rref_den)DDM)	ddm_irrefddm_irref_denmethodautoc               ~   \        WRR7      w  r\        W4      w  rVR8X  d   \        V 4      p\        V4      w  rVMrVR8X  d"   \	        V 4      w  rxp\        V4      V,          pMJVR8X  d6   V P                  RR7      w  r\	        V
4      w  rxp\        V4      V,          pM\        RV 24      h\        WS4      w  rYWV3# )	aZ  
Compute the reduced row echelon form of a ``DomainMatrix``.

This function is the implementation of :meth:`DomainMatrix.rref`.

Chooses the best algorithm depending on the domain, shape, and sparsity of
the matrix as well as things like the bit count in the case of :ref:`ZZ` or
:ref:`QQ`. The result is returned over the field associated with the domain
of the Matrix.

See Also
========

sympy.polys.matrices.domainmatrix.DomainMatrix.rref
    The ``DomainMatrix`` method that calls this function.
sympy.polys.matrices.rref._dm_rref_den
    Alternative function for computing RREF with denominator.
FdenominatorGJFFCDTconvertUnknown method for rref: )_dm_rref_choose_method
_dm_to_fmt	_to_field_dm_rref_GJ_dm_rref_den_FFclear_denoms_rowwise
ValueError)Mr
   use_fmtold_fmtMfM_rrefpivotsM_rref_fden_Mrs   &$         y/Users/tonyclaw/.openclaw/workspace/skills/math-calculator/venv/lib/python3.14/site-packages/sympy/polys/matrices/rref.py_dm_rrefr'   %   s    & -QEJOFA'JA~q\$R	4 / 2v8$s*	4&&t&4 / 3v8$s* 4VH=>>6+IF >    keep_domainTc               ^   \        WRR7      w  r#\        W4      w  rVR8X  d   \        V 4      w  rVpEMjVR8X  d   \        \	        V 4      4      w  rV'       dl   VP
                  V P
                  8w  dQ   VP                  RR7      w  rV'       d   V^ V^ ,          3,          P                  pMVP
                  P                  pMTpVP
                  P                  pMVR8X  d   V P                  RR7      w  r\        V
4      w  rpV'       dE   VP
                  V P
                  8w  d*   \	        V4      V,          pV P
                  P                  pMLTpV'       d   V^ V^ ,          3,          P                  pM%VP
                  P                  pM\        RV 24      h\        WT4      w  rYWVV3# )a  
Compute the reduced row echelon form of a ``DomainMatrix`` with denominator.

This function is the implementation of :meth:`DomainMatrix.rref_den`.

Chooses the best algorithm depending on the domain, shape, and sparsity of
the matrix as well as things like the bit count in the case of :ref:`ZZ` or
:ref:`QQ`. The result is returned over the same domain as the input matrix
unless ``keep_domain=False`` in which case the result might be over an
associated ring or field domain.

See Also
========

sympy.polys.matrices.domainmatrix.DomainMatrix.rref_den
    The ``DomainMatrix`` method that calls this function.
sympy.polys.matrices.rref._dm_rref
    Alternative function for computing RREF without denominator.
Tr   r   r   r   r   r   )r   r   r   r   r   domainclear_denomselementoner   r   )r   r)   r
   r   r   r    r#   r!   r"   r$   r%   M_rref_rs   &$$         r&   _dm_rref_denr0   Y   sk   ( -QDIOFA'JA~-a0V	4&y|4 8??ahh6 --d-;IAQq	\*22mm'' F--##C	4&&t&4 / 3v8??ahh6x(3.F((,,C FQq	\*22mm''4VH=>>6+IF r(   c                    V P                   P                  pW!8X  d    W3# VR8X  d   V P                  4       p W3# VR8X  d   V P                  4       p W3# \	        RV 24      h)z?Convert a matrix to the given format and return the old format.densesparsezUnknown format: )repfmtto_dense	to_sparser   )r   r5   r   s   && r&   r   r      sr    eeiiG~ : 
JJL
 :	 
KKM : +C5122r(   c                d    V P                   P                  R8X  d   \        V 4      # \        V 4      # )z:Compute RREF using Gauss-Jordan elimination with division.r3   )r4   r5   _dm_rref_GJ_sparse_dm_rref_GJ_denser   s   &r&   r   r      s(    uuyyH!!$$ ##r(   c                d    V P                   P                  R8X  d   \        V 4      # \        V 4      # )z:Compute RREF using fraction-free Gauss-Jordan elimination.r3   )r4   r5   _dm_rref_den_FF_sparse_dm_rref_den_FF_denser;   s   &r&   r   r      s(    uuyyH%a(($Q''r(   c                    \        V P                  4      w  rp\        WP                  V P                  4      p\        V4      pV P                  V4      V3# )zACompute RREF using sparse Gauss-Jordan elimination with division.)r   r4   r   shaper+   tuplefrom_rep)r   M_rref_dr!   r$   
M_rref_sdms   &    r&   r9   r9      sF    #AEE*HaXww1J6]F::j!6))r(   c                j   V P                   P                  ;'       g    V P                   P                  pV P                  P	                  4       P                  4       p\        W!R7      p\        W P                  V P                   4      p\        V4      pV P                  VP                  4       4      V3# )z@Compute RREF using dense Gauss-Jordan elimination with division.)_partial_pivot)r+   is_RRis_CCr4   to_ddmcopyr   r   r@   rA   rB   to_dfm_or_ddm)r   partial_pivotddmr!   
M_rref_ddms   &    r&   r:   r:      s{    HHNN44ahhnnM
%%,,.


Cs9FS''188,J6]F::j..01699r(   c                    \        V P                  V P                  4      w  rp\        WP                  V P                  4      p\        V4      pV P                  V4      W#3# zACompute RREF using sparse fraction-free Gauss-Jordan elimination.)r   r4   r+   r   r@   rA   rB   )r   rC   r#   r!   rD   s   &    r&   r=   r=      sL    (9H6Xww1J6]F::j!3..r(   c                   V P                   P                  4       P                  4       p\        WP                  4      w  r#\        WP                  V P                  4      p\        V4      pV P                  VP                  4       4      W#3# rP   )
r4   rI   rJ   r	   r+   r   r@   rA   rB   rK   )r   rM   r#   r!   rN   s   &    r&   r>   r>      sd    
%%,,.


CXX.KCS''188,J6]F::j..013>>r(   r   Fc                  VR8w  d2   VP                  R4      '       d   VR\        R4      )  pRpW3# Rp W3# RpV P                  pVP                  '       d   \	        WR7      pW3# VP
                  '       d   \        WR7      pW3# VP                  '       g   VP                  '       d   RpRpW3# VP                  '       d+   V P                  P                  R8X  d   V'       g   RpRpW3# V'       d   RpW3# RpW3# )	z3Choose the fastest method for computing RREF for M.r   _denseNr2   r3   r   r   r   )endswithlenr+   is_ZZ_dm_rref_choose_method_ZZis_QQ_dm_rref_choose_method_QQrG   rH   is_EXr4   r5   )r   r
   r   r   Ks   &&$  r&   r   r      s    ??8$$Oc(m^,FGJ ?G GF ?? HH777.qJF4 ?3 WWW.qJF0 ?/ WWWFG( ?' WWWg-k FG ?  ? ?r(   c                  \        V 4      w  r#pV\        ^V^,          4      8  d   R# \        V 4      w  rV\        V Uu. uF  qwP	                  4       NK  	  up^R7      p\
        P                  p	V F8  p
\
        P                  ! W4      p	V	P	                  4       ^V,          8  g   K7   R# 	  V	P	                  4       ^28  d   R# R# u upi )z5Choose the fastest method for computing RREF over QQ.r   defaultr   r   )_dm_row_densitymin_dm_QQ_numers_denomsmax
bit_lengthr   r.   lcm)r   r   densityr$   ncolsnumersdenomsn
numer_bits	denom_lcmds   &$         r&   rY   rY     s     (*G Qa  *!,NFf5fllnf5qAJIFF9(	!AjL0  ") 6s   Cc                  Rp\        V 4      w  r4pV^
8  d   W5^,          8  d   R# R# V^8  d   R# V^W$,          ,           8  d   R# \        V 4      p\        V Uu. uF  qwP                  4       NK  	  up^R7      p\        ^RV,          V,          4      p	^W$V^,          ,          ,          ,           V	,          p
W:8  d   R# R# u upi )z5Choose the fastest method for computing RREF over ZZ.i'  r   r   r]   gUUUUUU?)r_   _dm_elementsrb   rc   )r   r   PARAMre   nrows_nzrf   elementsebitswidenessmax_densitys   &$         r&   rW   rW   F  s    $ E
  /q1Gu "}1W {	1u~%	% AH1111=D 1c%i()HutQw.//8;K 2s   Cc                    V P                   ^,          pV P                  P                  4       P                  4       pV'       g   ^ ^ V3# \	        V4      p\        \        \        V4      4      V,          pWCV3# )a  Density measure for sparse matrices.

Defines the "density", ``d`` as the average number of non-zero entries per
row except ignoring rows that are fully zero. RREF can ignore fully zero
rows so they are excluded. By definition ``d >= 1`` except that we define
``d = 0`` for the zero matrix.

Returns ``(density, nrows_nz, ncols)`` where ``nrows_nz`` counts the number
of nonzero rows and ``ncols`` is the number of columns.
)r@   r4   to_sdmvaluesrU   summap)r   rf   rows_nzrp   re   s   &    r&   r_   r_   |  sb     GGAJEeelln##%G!U{w<c#w'(83%''r(   c                *    V P                  4       w  rV# )z*Return nonzero elements of a DomainMatrix.)
to_flat_nz)r   rq   r$   s   &  r&   rn   rn     s    ,,.KHOr(   c                    \        V 4      pV Uu. uF  q"P                  NK  	  ppV Uu. uF  q"P                  NK  	  ppW43# u upi u upi )zBReturns the numerators and denominators of a DomainMatrix over QQ.)rn   	numeratorr   )Mqrq   rr   rg   rh   s   &    r&   ra   ra     sH    BH#+,8akk8F,%-.XmmXF.> -.s
   AAc                b    V P                   pVP                  '       d   V P                  4       # V # )z.Convert a DomainMatrix to a field if possible.)r+   has_assoc_Fieldto_field)r   r[   s   & r&   r   r     s(    	Azz|r(   N)sympy.polys.domainsr   sympy.polys.matrices.sdmr   r   r   sympy.polys.matrices.ddmr   sympy.polys.matrices.denser   r	   r'   r0   r   r   r   r9   r:   r=   r>   r   rY   rW   r_   rn   ra   r    r(   r&   <module>r      s   < # A A ( ?1& 1hK4 K K\"$(*:/?+U +\* *Z3 3l(,r(   