ó
    ‰*£h®-  ã                   óÄ   • S r SSKJr  SSK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  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJrJrJr  S rS rSS jrS rS rS r g)zAThis module implements tools for integrating rational functions. é    )ÚLambda)ÚI)ÚS)ÚDummyÚSymbolÚsymbols)Úlog)Úatan)ÚDomainError)Úroots)Úcancel)ÚRootSum)ÚPolyÚ	resultantÚZZc                 ó†  • [        U [        5      (       a  U u  p4OU R                  5       u  p4[        X1SSS9[        XASSS9pCUR	                  U5      u  pSnUR                  U5      u  pcUR                  U5      R                  5       nUR                  (       a  XW-  $ [        X4U5      u  p‰U	R                  5       u  p«[        X¡5      n
[        X±5      nU
R                  U5      u  pLXxUR                  U5      R                  5       -   -  nUR                  (       Gd£  UR                  SS5      n[        U[        5      (       d  [        U5      nOUR                  5       n[        XËX5      nUR                  S5      nUco  [        U [        5      (       a&  U u  p4UR                  5       UR                  5       -  nOU R                  5       nUU1-
   H  nUR                   (       a  M  Sn  O   Sn["        R$                  nU(       dP  U HI  u  p”U	R'                  5       u  nn	U[)        U[+        Xî[-        U	R                  5       5      -  5      SS9-  nMK     OeU H_  u  p”U	R'                  5       u  nn	[/        X”X5      nUb  UU-  nM.  U[)        U[+        Xî[-        U	R                  5       5      -  5      SS9-  nMa     UU-  nXW-  $ )a	  
Performs indefinite integration of rational functions.

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

Given a field :math:`K` and a rational function :math:`f = p/q`,
where :math:`p` and :math:`q` are polynomials in :math:`K[x]`,
returns a function :math:`g` such that :math:`f = g'`.

Examples
========

>>> from sympy.integrals.rationaltools import ratint
>>> from sympy.abc import x

>>> ratint(36/(x**5 - 2*x**4 - 2*x**3 + 4*x**2 + x - 2), x)
(12*x + 6)/(x**2 - 1) + 4*log(x - 2) - 4*log(x + 1)

References
==========

.. [1] M. Bronstein, Symbolic Integration I: Transcendental
   Functions, Second Edition, Springer-Verlag, 2005, pp. 35-70

See Also
========

sympy.integrals.integrals.Integral.doit
sympy.integrals.rationaltools.ratint_logpart
sympy.integrals.rationaltools.ratint_ratpart

FT)Ú	compositeÚfieldÚsymbolÚtÚreal)Ú	quadratic)Ú
isinstanceÚtupleÚas_numer_denomr   r   ÚdivÚ	integrateÚas_exprÚis_zeroÚratint_ratpartÚgetr   r   Úas_dummyÚratint_logpartÚatomsÚis_extended_realr   ÚZeroÚ	primitiver   r   r	   Úlog_to_real)ÚfÚxÚflagsÚpÚqÚcoeffÚpolyÚresultÚgÚhÚPÚQÚrr   r   ÚLr   r$   ÚeltÚepsÚ_ÚRs                         ÚZ/home/mande/repo/quber/.venv/lib/python3.13/site-packages/sympy/integrals/rationaltools.pyÚratintr<      sq  € ôD �!”U×ÑØ‰ˆˆ1à×ÑÓ!‰ˆä� ¨TÑ2´D¸ÈÐVZÑ4[€qà—(‘(˜1“+�K€EˆaØ�e‰e�A‹h�G€Dà�^‰^˜AÓ×&Ñ&Ó(€Fà‡y‡yØ‰|Ðä˜! Ó"�D€Aà×ÑÓ�D€AäˆQ‹
€AÜˆQ‹
€Aà�5‰5�‹8�D€Aà
�!—+‘+˜a“.×(Ñ(Ó*Ñ*Ñ*€Fà�9�9ˆ9Ø—‘˜8 SÓ)ˆä˜&¤&×)Ñ)Ü�f“‰Aà—‘Ó!ˆAä˜1 Ó&ˆà�y‰y˜Ó ˆà‰<Ü˜!œU×#Ñ#Ø‘�ØŸ™›	 A§G¡G£IÑ-‘àŸ™›	�à ˜s”{�Ø×+×+Ñ+Ø �DÙñ #ð
 �ä�f‰fˆæÛ‘�Ø—{‘{“}‘��1Ø”wØ”v˜a¤3 q§y¡y£{Ó#3Ñ!3Ó4ÀñFñ F’ò ó
 ‘�Ø—{‘{“}‘��1Ü  aÓ+�à‘=Ø˜1‘H’Càœ7Øœ6 !¤s¨1¯9©9«;Ó'7Ñ%7Ó8ÀDñJñ J’Cñ ð 	�#‰ˆà‰<Ðó    c           
      óŠ  • SSK Jn  [        X5      n [        X5      nUR                  UR	                  5       5      u  pEnUR                  5       nUR                  5       n[        SU5       V	s/ s H  n	[        S[        Xy-
  5      -   5      PM     n
n	[        SU5       V	s/ s H  n	[        S[        X‰-
  5      -   5      PM     nn	X«-   n[        X¢[        U   S9n[        X²[        U   S9nXR	                  5       U-  -
  XÔR	                  5       U-  R                  U5      -  -   Xä-  -
  nU" UR                  5       U5      nUR                  5       R                  U5      nUR                  5       R                  U5      n[        XÔR                  5       -  U5      n[        XåR                  5       -  U5      nUU4$ s  sn	f s  sn	f )aK  
Horowitz-Ostrogradsky algorithm.

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

Given a field K and polynomials f and g in K[x], such that f and g
are coprime and deg(f) < deg(g), returns fractions A and B in K(x),
such that f/g = A' + B and B has square-free denominator.

Examples
========

    >>> from sympy.integrals.rationaltools import ratint_ratpart
    >>> from sympy.abc import x, y
    >>> from sympy import Poly
    >>> ratint_ratpart(Poly(1, x, domain='ZZ'),
    ... Poly(x + 1, x, domain='ZZ'), x)
    (0, 1/(x + 1))
    >>> ratint_ratpart(Poly(1, x, domain='EX'),
    ... Poly(x**2 + y**2, x, domain='EX'), x)
    (0, 1/(x**2 + y**2))
    >>> ratint_ratpart(Poly(36, x, domain='ZZ'),
    ... Poly(x**5 - 2*x**4 - 2*x**3 + 4*x**2 + x - 2, x, domain='ZZ'), x)
    ((12*x + 6)/(x**2 - 1), 12/(x**2 - x - 2))

See Also
========

ratint, ratint_logpart
r   )ÚsolveÚaÚb)Údomain)Úsympy.solvers.solversr?   r   Ú	cofactorsÚdiffÚdegreeÚranger   Ústrr   ÚquoÚcoeffsr   Úsubsr   )r)   r1   r*   r?   ÚuÚvr9   ÚnÚmÚiÚA_coeffsÚB_coeffsÚC_coeffsÚAÚBÚHr0   Úrat_partÚlog_parts                      r;   r    r    }   ss  € õ@ ,äˆQ‹
€AÜˆQ‹
€Aà�k‰k˜!Ÿ&™&›(Ó#�G€Aˆ!à	�‰‹
€AØ	�‰‹
€Aä27¸¸1´+Ó?²+¨Q”�sœS ¡›ZÑ'Ö(±+€HÐ?Ü27¸¸1´+Ó?²+¨Q”�sœS ¡›ZÑ'Ö(±+€HÐ?àÑ"€HäˆX¤ H¡Ñ.€AÜˆX¤ H¡Ñ.€Aà	�F‰F‹H�Q‰J‰˜ŸF™F›H Q™J×+Ñ+¨AÓ.Ñ.Ñ.°±Ñ4€Aá�1—8‘8“:˜xÓ(€Fà	�	‰	‹×Ñ˜Ó €AØ	�	‰	‹×Ñ˜Ó €Aä�aŸ	™	›‘m QÓ'€HÜ�aŸ	™	›‘m QÓ'€Hà�XÐÐùò% @ùÚ?s   Á-#F;Â #G Nc                 ó~  • [        X5      [        X5      pU=(       d    [        S5      nXUR                  5       [        X25      -  -
  pT[        XESS9u  pg[        XcSS9nU(       d   SU< SU< S35       e0 / p˜U H  n
X¨U
R	                  5       '   M     S	 nUR                  5       u  pÍU" XÍ5        U GH…  u  pïUR                  5       u  nnUR	                  5       U:X  a  U	R                  X45        MA  X�   n[        UR                  5       USS
9nUR                  SS9u  nnU" UU5        U H3  u  nnUR                  [        UR                  U5      U-  U5      5      nM5     UR                  U5      [        R                  /nnUR                  5       SS  HQ  nUR                  UR                   5      nUU-  R#                  U5      nUR                  UR%                  5       5        MS     [        ['        [)        [+        UR-                  5       U5      5      5      U5      nU	R                  UU45        GMˆ     U	$ )aú  
Lazard-Rioboo-Trager algorithm.

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

Given a field K and polynomials f and g in K[x], such that f and g
are coprime, deg(f) < deg(g) and g is square-free, returns a list
of tuples (s_i, q_i) of polynomials, for i = 1..n, such that s_i
in K[t, x] and q_i in K[t], and::

                       ___    ___
             d  f   d  \  `   \  `
             -- - = --  )      )   a log(s_i(a, x))
             dx g   dx /__,   /__,
                      i=1..n a | q_i(a) = 0

Examples
========

>>> from sympy.integrals.rationaltools import ratint_logpart
>>> from sympy.abc import x
>>> from sympy import Poly
>>> ratint_logpart(Poly(1, x, domain='ZZ'),
... Poly(x**2 + x + 1, x, domain='ZZ'), x)
[(Poly(x + 3*_t/2 + 1/2, x, domain='QQ[_t]'),
...Poly(3*_t**2 + 1, _t, domain='ZZ'))]
>>> ratint_logpart(Poly(12, x, domain='ZZ'),
... Poly(x**2 - x - 2, x, domain='ZZ'), x)
[(Poly(x - 3*_t/8 - 1/2, x, domain='QQ[_t]'),
...Poly(-_t**2 + 16, _t, domain='ZZ'))]

See Also
========

ratint, ratint_ratpart
r   T)Ú
includePRSF)r   zBUG: resultant(z, z) cannot be zeroc                 ó’   • U R                   (       a6  U S:  S:X  a,  US   u  p#U R                  UR                  5      nX$-  U4US'   g g g )Nr   T)r%   Úas_polyÚgens)ÚcÚsqfr2   ÚkÚc_polys        r;   Ú_include_signÚ%ratint_logpart.<locals>._include_signñ   sI   € Ø×× 1 q¡5¨T£/Ø�q‘6‰DˆAØ—Y‘Y˜qŸv™vÓ&ˆFØ‘X˜q�[ˆC�ŠFð #2Ðr=   )r   )Úallé   N)r   r   rE   r   rF   Úsqf_listr'   ÚappendÚLCrI   ÚgcdÚinvertr   ÚOnerJ   r\   r]   Úremr   ÚdictÚlistÚzipÚmonoms)r)   r1   r*   r   r@   rA   Úresr:   ÚR_maprV   r5   rb   ÚCÚres_sqfr-   rP   r9   r2   Úh_lcr^   Úh_lc_sqfÚjÚinvrJ   r.   ÚTs                             r;   r#   r#   ¼   sà  € ôL �‹:”t˜A“z€qà	�ŒU�3‹Z€AØ�!—&‘&“(œ4 ›:Ñ%Ñ%€qä�q¨Ñ-�F€CÜ
ˆs Ñ
'€CæÑ@»1»aÐ@Ó@ˆ3à�2ˆ1ãˆØˆa�h‰h‹jÓñ ò!ð —‘“�J€AÙ�!Ôä‰ˆØ�{‰{‹}‰ˆˆ1à�8‰8‹:˜‹?Ø�H‰H�a�VÖà‘ˆAÜ˜Ÿ™› ¨Ñ.ˆDàŸ-™-¨D˜-Ð1‰KˆAˆxÙ˜!˜XÔ&ã ‘��1Ø—E‘Eœ$˜qŸu™u Q›x¨™{¨AÓ.Ó/’ñ !ð Ÿ+™+ a›.¬1¯5©5¨'�ˆCàŸ™› A B›�ØŸ™ c§h¡hÓ/�Ø˜‘Y—O‘O AÓ&�Ø—‘˜aŸi™i›kÖ*ñ (ô
 ”Tœ$œs 1§8¡8£:¨vÓ6Ó7Ó8¸!Ó<ˆAà�H‰H�a˜�V×ñ1 ð4 €Hr=   c                 ó¼  • U R                  5       UR                  5       :  a  U* U pU R                  5       n UR                  5       nU R                  U5      u  p#UR                  (       a  S[	        UR                  5       5      -  $ UR                  U * 5      u  pEnX-  X-  -   R                  U5      nS[	        UR                  5       5      -  nU[        XE5      -   $ )aØ  
Convert complex logarithms to real arctangents.

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

Given a real field K and polynomials f and g in K[x], with g != 0,
returns a sum h of arctangents of polynomials in K[x], such that:

               dh   d         f + I g
               -- = -- I log( ------- )
               dx   dx        f - I g

Examples
========

    >>> from sympy.integrals.rationaltools import log_to_atan
    >>> from sympy.abc import x
    >>> from sympy import Poly, sqrt, S
    >>> log_to_atan(Poly(x, x, domain='ZZ'), Poly(1, x, domain='ZZ'))
    2*atan(x)
    >>> log_to_atan(Poly(x + S(1)/2, x, domain='QQ'),
    ... Poly(sqrt(3)/2, x, domain='EX'))
    2*atan(2*sqrt(3)*x/3 + sqrt(3)/3)

See Also
========

log_to_real
é   )	rF   Úto_fieldr   r   r
   r   ÚgcdexrI   Úlog_to_atan)	r)   r1   r,   r-   Úsr   r2   rL   rT   s	            r;   r~   r~     s±   € ð> 	‡x�xƒz�A—H‘H“JÓØˆr�1ˆ1à	�
‰
‹€AØ	�
‰
‹€Aà�5‰5�‹8�D€Aà‡y‡yØ”�a—i‘i“kÓ"Ñ"Ð"à—'‘'˜1˜"“+‰ˆˆaØ‰S�1‘3‰Y�O‰O˜AÓˆØŒd�1—9‘9“;ÓÑˆà”;˜qÓ$Ñ$Ð$r=   c                 ó€   • [        U SS9n U R                  5       n[        U5      U:X  a  U$ g! [         a    Us $ f = f)zget real roots of f if possibler:   )ÚfilterN)r   Úcount_rootsÚlenr   )r)   r*   ÚrsÚ	num_rootss       r;   Ú_get_real_rootsr†   H  sJ   € ä	ˆq˜Ñ	€BðØ—M‘M“Oˆ	ô ˆr‹7�iÓØˆIàøô ó ØŠ	ðús   Œ. ®=¼=c           
      óÚ  • SSK Jn  [        S[        S9u  pVU R	                  5       R                  X5[        U-  -   05      R                  5       nUR	                  5       R                  X5[        U-  -   05      R                  5       nU" U[        SS9n	U" U[        SS9n
U	R                  [        R                  [        R                  5      U	R                  [        [        R                  5      pËU
R                  [        R                  [        R                  5      U
R                  [        [        R                  5      pí[        [        XÞU5      U5      n[        Xõ5      nUc  g[        R                  nUR                  5        GH‹  n[        UR                  UU05      U5      nU(       d-  [        UR                  UU05      U5      n[        R                  n[        UU5      nUc    g/ nU Hr  nUU;  d  M  U* U;  d  M  UR                   (       d  UR#                  5       (       a  UR%                  U* 5        MN  UR&                  (       a  Ma  UR%                  U5        Mt     U H¥  nUR                  UUUU05      nUR)                  SS	9S:w  a  M-  [        UR                  UUUU05      U5      n[        UR                  UUUU05      U5      nUS
-  US
-  -   R	                  5       nUU[+        U5      -  U[-        UU5      -  -   -  nM§     GMŽ     [        X5      nUc  gUR                  5        H2  nUU[+        U R	                  5       R/                  UU5      5      -  -  nM4     U$ )a  
Convert complex logarithms to real functions.

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

Given real field K and polynomials h in K[t,x] and q in K[t],
returns real function f such that:
                      ___
              df   d  \  `
              -- = --  )  a log(h(a, x))
              dx   dx /__,
                     a | q(a) = 0

Examples
========

    >>> from sympy.integrals.rationaltools import log_to_real
    >>> from sympy.abc import x, y
    >>> from sympy import Poly, S
    >>> log_to_real(Poly(x + 3*y/2 + S(1)/2, x, domain='QQ[y]'),
    ... Poly(3*y**2 + 1, y, domain='ZZ'), x, y)
    2*sqrt(3)*atan(2*sqrt(3)*x/3 + sqrt(3)/3)/3
    >>> log_to_real(Poly(x**2 - 1, x, domain='ZZ'),
    ... Poly(-2*y + 1, y, domain='ZZ'), x, y)
    log(x**2 - 1)/2

See Also
========

log_to_atan
r   )Úcollectzu,v)ÚclsF)ÚevaluateNT)Úchopr{   )Úsympy.simplify.radsimprˆ   r   r   r   Úxreplacer   Úexpandr!   r   rk   r&   r   r   r†   ÚkeysÚis_negativeÚcould_extract_minus_signrg   r   Úevalfr	   r~   rK   )r2   r-   r*   r   rˆ   rL   rM   rV   r4   ÚH_mapÚQ_mapr@   rA   r^   Údr:   ÚR_ur0   Úr_urs   ÚR_vÚ
R_v_pairedÚr_vÚDrT   rU   ÚABÚR_qr5   s                                r;   r(   r(   W  sË  € õB /Ü�5œeÑ$�D€Aà	�	‰	‹×Ñ˜a¤Q q¡S¡˜\Ó*×1Ñ1Ó3€AØ	�	‰	‹×Ñ˜a¤Q q¡S¡˜\Ó*×1Ñ1Ó3€Aá�A”q 5Ñ)€EÙ�A”q 5Ñ)€Eà�9‰9”Q—U‘UœAŸF™FÓ# U§Y¡Y¬q´!·&±&Ó%9€qØ�9‰9”Q—U‘UœAŸF™FÓ# U§Y¡Y¬q´!·&±&Ó%9€qäŒY�q˜QÓ Ó#€Aä
˜!Ó
€Cà
�{Øä�V‰V€Fà�x‰x�zˆÜ�—‘˜Q ˜HÓ% qÓ)ˆÞô �Q—Z‘Z  C Ó)¨1Ó-ˆAô
 —‘ˆAä˜a Ó#ˆà‰;Ùàˆ
ÛˆCØ˜*Õ$¨#¨°ZÕ)?Ø—?—? c×&BÑ&B×&DÑ&DØ×%Ñ% s dÖ+ØŸŸ™Ø×%Ñ% cÖ*ñ ó ˆCà—
‘
˜A˜s A sÐ+Ó,ˆAà�w‰w˜DˆwÐ! QÓ&Ùä�Q—Z‘Z  C¨¨CÐ 0Ó1°1Ó5ˆAÜ�Q—Z‘Z  C¨¨CÐ 0Ó1°1Ó5ˆAà�Q‘$˜˜A™‘+×&Ñ&Ó(ˆBà�cœ#˜b›'‘k C¬°A°qÓ(9Ñ$9Ñ9Ñ9ŠFô ñ5 ôP ˜!Ó
€Cà
�{Øà�X‰XŽZˆØ�!”C˜Ÿ	™	›×(Ñ(¨¨AÓ.Ó/Ñ/Ñ/Šñ ð €Mr=   )N)!Ú__doc__Úsympy.core.functionr   Úsympy.core.numbersr   Úsympy.core.singletonr   Úsympy.core.symbolr   r   r   Ú&sympy.functions.elementary.exponentialr	   Ú(sympy.functions.elementary.trigonometricr
   Úsympy.polys.polyerrorsr   Úsympy.polys.polyrootsr   Úsympy.polys.polytoolsr   Úsympy.polys.rootoftoolsr   Úsympy.polysr   r   r   r<   r    r#   r~   r†   r(   © r=   r;   Ú<module>r«      sT   ðÙ Gå &Ý  Ý "ß 6Ñ 6Ý 6Ý 9Ý .Ý 'Ý (Ý +ß +Ñ +òjòZ<ô~Xòv.%òbófr=   