Ë
    7^(h¬<  ã                   óÀ   — d dl mZ d dlmZmZmZ d dlmZ d dlm	Z	m
Z
 ddœd„Zddd	œd
„Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zddœd„Zddœd„Zddœd„Zd„ Zd„ Zd„ Zd„ Zy)é    )ÚZZ)ÚSDMÚ	sdm_irrefÚsdm_rref_den)ÚDDM)Ú	ddm_irrefÚddm_irref_denÚauto)Úmethodc                óx  — t        | |d¬«      \  }}t        | |«      \  } }|dk(  rt        | «      }t        |«      \  }}ni|dk(  rt	        | «      \  }}}t        |«      |z  }nF|dk(  r3| j                  d¬«      \  }	}
t	        |
«      \  }}}t        |«      |z  }nt        d|› �«      ‚t        ||«      \  }}	||fS )	aŽ  
    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              úW/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/sympy/polys/matrices/rref.pyÚ_dm_rrefr'   %   sÙ   € ô& -¨Q°ÀEÔJ�O€FˆGä˜A˜wÓ'�J€A€wà�‚~ä�q‹\ˆÜ$ R›‰ˆ‘à	�4Šä /°Ó 2Ñˆ�#�vÜ˜8Ó$ sÑ*‰à	�4Šà×&Ñ&¨tÐ&Ó4‰ˆˆ2Ü /°Ó 3Ñˆ�#�vÜ˜8Ó$ sÑ*‰ô Ð4°V°HÐ=Ó>Ð>ä˜6 7Ó+�I€FˆAð �6ˆ>Ðó    T)Úkeep_domainr   c                ó
  — t        | |d¬«      \  }}t        | |«      \  } }|dk(  rt        | «      \  }}}�n:|dk(  rŽt        t	        | «      «      \  }}|r\|j
                  | j
                  k7  rC|j                  d¬«      \  }	}|r|d|d   f   j                  }n×|j
                  j                  }nÀ|}|j
                  j                  }n§|dk(  r”| j                  d¬«      \  }	}
t        |
«      \  }}}|r>|j
                  | j
                  k7  r%t	        |«      |z  }| j
                  j                  }n>|}|r|d|d   f   j                  }n%|j
                  j                  }nt        d|› �«      ‚t        ||«      \  }}	|||fS )	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   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   sƒ  € ô( -¨Q°ÀDÔI�O€FˆGä˜A˜wÓ'�J€A€wà�‚~ä-¨aÓ0Ñˆ�’Và	�4Šä&¤y°£|Ó4Ñˆ�&ñ ˜8Ÿ?™?¨a¯h©hÒ6Ø ×-Ñ-°dÐ-Ó;‰IˆAˆváØ˜Q  q¡	˜\Ñ*×2Ñ2‘à—m‘m×'Ñ'‘ð ˆFØ—-‘-×#Ñ#‰Cà	�4Šà×&Ñ&¨tÐ&Ó4‰ˆˆ2ä /°Ó 3Ñˆ�#�vá˜8Ÿ?™?¨a¯h©hÒ6ä˜xÓ(¨3Ñ.ˆFØ—(‘(—,‘,‰Cð ˆFáØ˜Q  q¡	˜\Ñ*×2Ñ2‘à—m‘m×'Ñ'‘äÐ4°V°HÐ=Ó>Ð>ä˜6 7Ó+�I€FˆAð �3˜ÐÐr(   c                 óÂ   — | j                   j                  }||k(  r	 | |fS |dk(  r| j                  «       } | |fS |dk(  r| j                  «       } | |fS t	        d|› �«      ‚)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   §   sz   € à�e‰e�i‰i€GØ�#‚~Øð ˆgˆ:Ðð 
�ŠØ�J‰J‹Lˆð
 ˆgˆ:Ðð	 
�ŠØ�K‰K‹Mˆð ˆgˆ:Ðô Ð+¨C¨5Ð1Ó2Ð2r(   c                 ó`   — | j                   j                  dk(  rt        | «      S t        | «      S )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(   € à‡u�u‡y�y�HÒÜ! !Ó$Ð$ä  Ó#Ð#r(   c                 ó`   — | j                   j                  dk(  rt        | «      S t        | «      S )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(   € à‡u�u‡y�y�HÒÜ% aÓ(Ð(ä$ QÓ'Ð'r(   c                 ó²   — t        | j                  «      \  }}}t        || j                  | j                  «      }t        |«      }| j                  |«      |fS )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   È   sJ   € ä# A§E¡EÓ*Ñ€Hˆf�aÜ�X˜qŸw™w¨¯©Ó1€JÜ�6‹]€FØ�:‰:�jÓ! 6Ð)Ð)r(   c                 ób  — | j                   j                  xs | j                   j                  }| j                  j	                  «       j                  «       }t        ||¬«      }t        || j                  | j                   «      }t        |«      }| j                  |j                  «       «      |fS )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|   € à—H‘H—N‘NÒ4 a§h¡h§n¡n€MØ
�%‰%�,‰,‹.×
Ñ
Ó
€CÜ�s¨=Ô9€FÜ�S˜!Ÿ'™' 1§8¡8Ó,€JÜ�6‹]€FØ�:‰:�j×.Ñ.Ó0Ó1°6Ð9Ð9r(   c                 óÊ   — t        | j                  | j                  «      \  }}}t        || j                  | j                  «      }t        |«      }| j                  |«      ||fS ©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=   Ú   sR   € ä(¨¯©°·±Ó9Ñ€Hˆc�6Ü�X˜qŸw™w¨¯©Ó1€JÜ�6‹]€FØ�:‰:�jÓ! 3¨Ð.Ð.r(   c                 ó   — | j                   j                  «       j                  «       }t        || j                  «      \  }}t        || j                  | j                  «      }t        |«      }| j                  |j                  «       «      ||fS rP   )
r4   rI   rJ   r	   r+   r   r@   rA   rB   rK   )r   rM   r#   r!   rN   s        r&   r>   r>   â   sl   € à
�%‰%�,‰,‹.×
Ñ
Ó
€CÜ  Q§X¡XÓ.�K€CˆÜ�S˜!Ÿ'™' 1§8¡8Ó,€JÜ�6‹]€FØ�:‰:�j×.Ñ.Ó0Ó1°3¸Ð>Ð>r(   Fr   c                ó®  — |dk7  r,|j                  d«      r|dt        d«        }d}||fS d}||fS d}| j                  }|j                  rt	        | |¬«      }||fS |j
                  rt        | |¬«      }||fS |j                  s|j                  rd}d}||fS |j                  r#| j                  j                  dk(  r
|sd}d}||fS |rd}||fS d}||fS )	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Ô$Ø˜Oœc (›m˜^Ð,ˆFØˆGðJ �7ˆ?ÐðG ˆGðF �7ˆ?Ðð? ˆà�H‰Hˆà�7Š7Ü.¨q¸kÔJˆFð4 �7ˆ?Ðð3 �WŠWÜ.¨q¸kÔJˆFð0 �7ˆ?Ðð/ �WŠW˜ŸšàˆFØˆGð( �7ˆ?Ðð' �WŠW˜Ÿ™Ÿ™ gÒ-±kð ˆFØˆGð �7ˆ?Ðñ Ø�ð �7ˆ?Ðð �à�7ˆ?Ðr(   c                ór  — t        | «      \  }}}|t        d|dz  «      k  ryt        | «      \  }}t        |D �cg c]  }|j	                  «       ‘Œ c}d¬«      }t
        j                  }	|D ]0  }
t        j                  |	|
«      }	|	j	                  «       d|z  kD  sŒ0 y |	j	                  «       dk  ryyc c}w )	z5Choose the fastest method for computing RREF over QQ.é   é   r   é   ©Údefaulté2   r   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�ð ”�Q˜˜a™“Ò Øô *¨!Ó,�N€FˆFÜ¨fÖ5¨�a—l‘l•nÒ5¸qÔA€Jä—‘€IØò ˆÜ—F‘F˜9 aÓ(ˆ	Ø×ÑÓ! A j¡LÓ0Ùðð ×ÑÓ Ò"Øàùò) 6s   ºB4c                ó,  — d}t        | «      \  }}}|dk  r
||dz  k  ryy|dk  ry|d||z  z   kD  ryt        | «      }t        |D �cg c]  }|j                  «       ‘Œ c}d¬«      }t        dd	|z  |z  «      }	d|||dz  z  z  z   |	z  }
||
k  ryyc c}w )
z5Choose the fastest method for computing RREF over ZZ.i'  é
   r^   r   r   r]   r_   r`   gUUUUUUå?)rc   Ú_dm_elementsrf   rg   )r   r   ÚPARAMri   Únrows_nzrj   ÚelementsÚeÚbitsÚwidenessÚmax_densitys              r&   rW   rW   F  sÆ   € ð$ €Eô
  /¨qÓ1Ñ€GˆX�uð �"‚}Ø�U˜1‘WÒØàð �‚{ØØ	�1�u˜X‘~Ñ%Ò	%Øô ˜A‹€HÜ¨Ö1 1�—‘•Ò1¸1Ô=€Dô �1�c˜%‘i Ñ(Ó)€Hà�u˜h t¨Q¡wÑ.Ñ/Ñ/°8Ñ;€Kà�ÒØàùò 2s   ÁBc                 óÖ   — | j                   d   }| j                  j                  «       j                  «       }|sdd|fS t	        |«      }t        t        t        |«      «      |z  }|||fS )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_   r   )r@   r4   Úto_sdmÚvaluesrU   ÚsumÚmap)r   rj   Úrows_nzru   ri   s        r&   rc   rc   |  sd   € ð �G‰G�A‰J€EØ�e‰e�l‰l‹n×#Ñ#Ó%€GÙØ�!�Uˆ{Ðä�w“<ˆÜ”cœ#˜wÓ'Ó(¨8Ñ3ˆØ˜ %Ð'Ð'r(   c                 ó,   — | j                  «       \  }}|S )z*Return nonzero elements of a DomainMatrix.)Ú
to_flat_nz)r   rv   r$   s      r&   rs   rs   ’  s   € à—,‘,“.�K€HˆaØ€Or(   c                 ó˜   — t        | «      }|D �cg c]  }|j                  ‘Œ }}|D �cg c]  }|j                  ‘Œ }}||fS c c}w c c}w )zBReturns the numerators and denominators of a DomainMatrix over QQ.)rs   Ú	numeratorr   )ÚMqrv   rw   rk   rl   s        r&   re   re   ˜  sL   € ä˜BÓ€HØ#+Ö,˜aˆa�k‹kÐ,€FÐ,Ø%-Ö. ˆa�m‹mÐ.€FÐ.Ø�6ˆ>Ðùò -ùÚ.s
   �A©Ac                 óV   — | j                   }|j                  r| j                  «       S | S )z.Convert a DomainMatrix to a field if possible.)r+   Úhas_assoc_FieldÚto_field)r   r[   s     r&   r   r      s%   € à	�‰€AØ×ÒØ�z‰z‹|Ðàˆ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   rc   rs   re   r   © r(   r&   ú<module>rŽ      s‡   ðõ< #ç AÑ AÝ (ß ?ð !ô 1ðh $(°ô Kò\ò"$ò(ò*ò:ò/ò?ð 6;ô +ð\ 16ô *ðZ 16ô 3òl(ò,òór(   