+
    ‹°³j  ã                   ó–   € ^ RI Ht ^ RIHtHtHt ^ RIHt ^ RIH	t	H
t
HtHtHt ^ RIHtHt ^ RIHtHt ^ RIHtHt R tR	R
RR/R ltR# )é    )Úcombinations_with_replacement)ÚsymbolsÚAddÚDummy)ÚRational)ÚcancelÚComputationFailedÚparallel_poly_from_exprÚreducedÚPoly)ÚMonomialÚmonomial_div)ÚDomainErrorÚPolificationFailed)ÚdebugÚdebugfc                óÌ   € \        V 4      P                  4       w  r \        W.RRR7      w  r4\	        T!  \        YB,          4      ,           #   \         d    Y,          u # i ; i)z·
Put an expression over a common denominator, cancel and reduce.

Examples
========

>>> from sympy import ratsimp
>>> from sympy.abc import x, y
>>> ratsimp(1/x + 1/y)
(x + y)/(x*y)
TF)ÚfieldÚexpand)r   Úas_numer_denomr   r	   r   )ÚexprÚfÚgÚQÚrs   &    ÚW/home/luca/screen-checking/.venv/lib/python3.14/site-packages/sympy/simplify/ratsimp.pyÚratsimpr   	   s^   € ô �$‹<×&Ñ&Ó(�D€AðÜ�q˜# T°%Ô8‰ˆô �‰7”V˜A�C“[Õ Ð øô ô Ø�sŠ
ðús   �A ÁA#Á"A#ÚquickTÚ
polynomialFc          	     ó€  aaaaaaaa€ ^ RI Ho \        RV 4       \        V 4      P	                  4       w  rg \        Wg.S,           .VO5/ VB w  poSP                  p	T	P                  '       d   T	P                  4       Sn        M\        RT	,          4      hTR,           U
u. uF  qªP                  SP                  4      NK  	  up
o\        4       oTTT3R loRTTTTTTT3R llo\        TSSP                  SP                  R7      ^,          p\        TSSP                  SP                  R7      ^,          pT'       d   Yg,          P                  4       # S! \!        TSP                  SP                  R7      \!        TSP                  SP                  R7      . 4      w  r¼pS'       g{   T'       ds   \#        R	\%        T4      4       . pT FE  w  ppppS! TTR
RR7      pTP'                  TP)                  T4      TP)                  T4      34       KG  	  \+        TR R7      w  r¼T	P,                  '       g8   TP/                  R
R7      w  ppTP/                  R
R7      w  pp\1        TT4      pM\1        ^4      pTTP2                  ,          TTP4                  ,          ,          #   \         d    T u # i ; iu up
i )a‚  
Simplifies a rational expression ``expr`` modulo the prime ideal
generated by ``G``.  ``G`` should be a Groebner basis of the
ideal.

Examples
========

>>> from sympy.simplify.ratsimp import ratsimpmodprime
>>> from sympy.abc import x, y
>>> eq = (x + y**5 + y)/(x - y)
>>> ratsimpmodprime(eq, [x*y**5 - x - y], x, y, order='lex')
(-x**2 - x*y - x - y)/(-x**2 + x*y)

If ``polynomial`` is ``False``, the algorithm computes a rational
simplification which minimizes the sum of the total degrees of
the numerator and the denominator.

If ``polynomial`` is ``True``, this function just brings numerator and
denominator into a canonical form. This is much faster, but has
potentially worse results.

References
==========

.. [1] M. Monagan, R. Pearce, Rational Simplification Modulo a Polynomial
    Ideal, https://dl.acm.org/doi/pdf/10.1145/1145768.1145809
    (specifically, the second algorithm)
)ÚsolveÚratsimpmodprimez.Cannot compute rational simplification over %s:é   NNc                ó0  <a€ V ^ 8X  d   ^.# . p\        \        \        SP                  4      4      V 4       F‘  p^ .\        SP                  4      ,          oV F  pSV;;,          ^,          uu&   K  	  \        ;QJ d    V3R lS 4       F  '       d   K   RM	  RM! V3R lS 4       4      '       g   K€  VP                  S4       K“  	  V Uu. uF&  p\        V4      P                  ! SP                  !  NK(  	  upS! V ^,
          4      ,           # u upi )zs
Compute all monomials with degree less than ``n`` that are
not divisible by any element of ``leading_monomials``.
c              3   ó@   <"  € T F  p\        SV4      R J x € K  	  R # 5i©N)r   )Ú.0ÚlmgÚms   & €r   Ú	<genexpr>Ú5ratsimpmodprime.<locals>.staircase.<locals>.<genexpr>b   s$   øé € ð &Ù$ð 58”<  3Ó'¨4Õ/Û$ùs   ƒFT)r   ÚrangeÚlenÚgensÚallÚappendr   Úas_expr)	ÚnÚSÚmiÚiÚsr)   Úleading_monomialsÚoptÚ	staircases	   &    @€€€r   r9   Ú"ratsimpmodprime.<locals>.staircaseV   s×   ù€ ð
 �Œ6Ø�3ˆJØˆÜ/´´c¸#¿(¹(³mÓ0DÀaÖHˆBØ�”C˜Ÿ™“MÕ!ˆAÛ�Ø�!—˜•	•ñ ç‹sô &Ù$ó&�s�sŠsô &Ù$ó&÷ &ô &à—‘˜–ñ Iñ 9:Ó:¹°1”˜“×#Ò# S§X¡XÔ.¹Ñ:¹YÀqÈ1ÅuÓ=MÕMÐMùÒ:s   Ã,Dc                óŽ  <aaaa€ Yre^ pV P                  4       VP                  4       ,           pS'       d   V^,
          p	MTp	W4,           V	8:  EdE   W43S9   d   EM:SP                  W434       S! V4      oS! V4      o\        RW4SS34       \        R\	        S4      ,          \
        R7      o\        R\	        S4      ,          \
        R7      oSS,           p
\        \        VV3R l\        \	        S4      4       4       4      SP                  V
,           4      p\        \        VV3R l\        \	        S4      4       4       4      SP                  V
,           4      p\        W,          W,          ,
          SSP                  V
,           SP                  RR7      ^,          p\        VSP                  R	7      P                  4       pS! VSS,           RRR
7      pV'       Ed•   \        ;QJ d*    R VP                  4        4       F  '       d   K   RM	  RM! R VP                  4        4       4      '       Eg>   VP                  V4      pVP                  V4      pVP                  \!        \#        \%        SS,           ^.\	        S4      \	        S4      ,           ,          4      4      4      4      pVP                  \!        \#        \%        SS,           ^.\	        S4      \	        S4      ,           ,          4      4      4      4      p\        VSP                  4      p\        VSP                  4      pV^ 8X  d   \'        R4      hVP)                  W¼VSS,           34       W4,           V8w  d   VR,          .pMV^,          pV^,          pV^,          pEKR  V^ 8”  d(   S! WVW#WG,
          4      w  rVpS! WVW#V,
          V4      w  rVpWVV3# )a«  
Computes a rational simplification of ``a/b`` which minimizes
the sum of the total degrees of the numerator and the denominator.

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

The algorithm proceeds by looking at ``a * d - b * c`` modulo
the ideal generated by ``G`` for some ``c`` and ``d`` with degree
less than ``a`` and ``b`` respectively.
The coefficients of ``c`` and ``d`` are indeterminates and thus
the coefficients of the normalform of ``a * d - b * c`` are
linear polynomials in these indeterminates.
If these linear polynomials, considered as system of
equations, have a nontrivial solution, then `\frac{a}{b}
\equiv \frac{c}{d}` modulo the ideal generated by ``G``. So,
by construction, the degree of ``c`` and ``d`` is less than
the degree of ``a`` and ``b``, so a simpler representation
has been found.
After a simpler representation has been found, the algorithm
tries to reduce the degree of the numerator and denominator
and returns the result afterwards.

As an extension, if quick=False, we look at all possible degrees such
that the total degree is less than *or equal to* the best current
solution. We retain a list of all solutions of minimal degree, and try
to find the best one at the end.
z%s / %s: %s, %szc:%d)Úclszd:%dc              3   óR   <"  € T F  pSV,          SV,          ,          x € K  	  R # 5ir&   © )r'   r5   ÚCsÚM1s   & €€r   r*   Ú<ratsimpmodprime.<locals>._ratsimpmodprime.<locals>.<genexpr>›   ó   øé € Ð:©> a�B�q•E˜B˜q�E—M’M«>ùó   ƒ$'c              3   óR   <"  € T F  pSV,          SV,          ,          x € K  	  R # 5ir&   r>   )r'   r5   ÚDsÚM2s   & €€r   r*   rA   �   rB   rC   T)ÚorderÚpolys)r.   ©Ú
particularr   c              3   ó*   "  € T F	  q^ 8H  x € K  	  R# 5i)r   Nr>   )r'   r6   s   & r   r*   rA   ¥   s   é € Ð<©|¨! Ažv«|ùs   ‚FzIdeal not prime?éÿÿÿÿ)Útotal_degreeÚaddr   r   r-   r   r   Úsumr,   r.   r   rG   Úcoeffsr/   ÚvaluesÚsubsÚdictÚlistÚzipÚ
ValueErrorr0   )ÚaÚbÚallsolÚNÚDÚcÚdÚstepsÚmaxdegÚboundÚngÚc_hatÚd_hatr   r3   Úsolr?   rE   r@   rF   ÚGÚ_ratsimpmodprimer8   r   r!   r9   Útesteds   &&&&&           @@@@€€€€€€€r   rf   Ú)ratsimpmodprime.<locals>._ratsimpmodprimeh   sÝ  ü€ ð: ˆ1Øˆà—‘Ó! A§N¡NÓ$4Õ4ˆßØ˜Q•J‰EàˆEØ�e�u�nØˆv˜ÔÙØ�J‰J˜�vÔá˜1“ˆBÙ˜1“ˆBÜÐ$ q¨R° nÔ5ä˜¤# b£'Õ)¬uÔ5ˆBÜ˜¤# b£'Õ)¬uÔ5ˆBØ�b•ˆBäÜÕ:¬5´°R³¬>Ó:Ó:¸C¿H¹HÀr½MóKˆEäÜÕ:¬5´°R³¬>Ó:Ó:¸C¿H¹HÀr½MóKˆEô ˜�	 A¥IÕ-¨q°#·(±(¸Rµ-Ø!Ÿi™i¨tô5Ø56õ8ˆAô �Q˜SŸX™XÔ&×-Ñ-Ó/ˆAÙ˜˜2 �7¨t¸4Ô@ˆCçˆsŸ3›3Ñ<¨s¯z©z¬|Ó<Ÿ3Ÿ3š3Ñ<¨s¯z©z¬|Ó<×<Ó<Ø—J‘J˜s“O�Ø—J‘J˜s“O�ð
 —F‘Fœ4¤¤S¨¨b­°1°#¼¸R»Ä3ÀrÃ7Õ9JÕ2KÓ%LÓ MÓNÓO�Ø—F‘Fœ4¤¤S¨¨b­°1°#¼¸R»Ä3ÀrÃ7Õ9JÕ2KÓ%LÓ MÓNÓO�ä˜˜CŸH™HÓ%�Ü˜˜CŸH™HÓ%�Ø˜”6Ü$Ð%7Ó8Ð8à—‘˜u¨Q°°RµÐ8Ô9Ø•5˜F”?Ø$ R�j˜\�Fàà�Q�JˆEØ��FˆAØ��F‹Aà�1Œ9Ù+¨A°&¸Q½YÓG‰LˆA�&Ù+¨A°&¸e½)ÀQÓG‰LˆA�&à�Vˆ|Ðó    )rG   )Údomainz*Looking for best minimal solution. Got: %sTFrI   c                 óŒ   € \        V ^ ,          P                  4       4      \        V ^,          P                  4       4      ,           # )r   )r-   Úterms)Úxs   &r   Ú<lambda>Ú!ratsimpmodprime.<locals>.<lambda>Õ   s'   € ¬¨Q¨q­T¯Z©Z«\Ó):¼SÀÀ1ÅÇÁÃÓ=NÖ)Nri   )Úkey)Úconvert)r   r   )Úsympy.solvers.solversr!   r   r   r   r
   r   rj   Úhas_assoc_FieldÚ	get_fieldr   ÚLMrG   Úsetr   r.   r   r   r-   r0   rR   ÚminÚis_FieldÚclear_denomsr   ÚqÚp)r   re   r   r   r.   ÚargsÚnumÚdenomrH   rj   r   r\   r]   rY   Únewsolrb   rc   r3   ra   rd   ÚcnÚdnr   rf   r7   r8   r!   r9   rg   s   &fd$*,                 @@@@@@r   r"   r"      s<  ÿ€ õ< ,ä	Ð
˜TÔ"ô ˜“×,Ñ,Ó.�J€CðÜ,¨c¨\¸AÕ-=ÐMÀÒMÈÑM‰
ˆˆsð �Z‰Z€Fà××ÐØ×%Ñ%Ó'ˆ�
äØ<¸vÕEóGð 	Gð 38¸¶)Ó<±)¨QŸ™˜cŸi™iž±)Ñ<ÐÜ‹U€F÷N÷$Zõ Zô| �#�q˜#Ÿ(™(¨#¯)©)Ô
4°QÕ
7€CÜ�E˜1˜cŸh™h¨c¯i©iÔ8¸Õ;€EçØ•	×!Ñ!Ó#Ð#á#ÜˆS�#—(‘( 3§:¡:Ô.´°U¸C¿H¹HÈSÏZÉZÔ0XÐZ\ó^�L€Aˆ&ç—VÜÐ;¼SÀ»[ÔIØˆÛ#)ÑˆE�5˜!˜RÙ˜˜2¨$°eÔ<ˆCà�M‰M˜5Ÿ:™: c›?¨E¯J©J°s«OÐ<Ö=ñ $*ô �6ÑNÔO‰ˆà�?�?ˆ?Ø—‘ t�Ó,‰ˆˆAØ—‘ t�Ó,‰ˆˆAÜ�R˜Ó‰ä�Q‹Kˆàˆa�c‰c�E�A�a—c‘c•E�?Ðøôo ô ØŠðüò =s   ·J( Â"#J;Ê(J8Ê7J8N)Ú	itertoolsr   Ú
sympy.corer   r   r   Úsympy.core.numbersr   Úsympy.polysr   r	   r
   r   r   Úsympy.polys.monomialsr   r   Úsympy.polys.polyerrorsr   r   Úsympy.utilities.miscr   r   r   r"   r>   ri   r   Ú<module>r‰      s;   ðÝ 3ß *Ñ *Ý 'ß YÕ Yß 8ß Bß .ò!ð,¨$ð ¸5ö ri   