
    \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  pU	R                  5       u  p[        X5      n
[        X5      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[        XX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  pU	R'                  5       u  nn	U[)        U[+        X[-        U	R                  5       5      -  5      SS9-  nMK     OeU H_  u  pU	R'                  5       u  nn	[/        XX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                         U/var/www/auris/envauris/lib/python3.13/site-packages/sympy/integrals/rationaltools.pyratintr<      sq   D !U1!T2DVZ4[q((1+KEaeeAhGD^^A&&(Fyy|!"DADAQ
AQ
A558DA
!++a.((***F9998S)&&))fA!A1&yy <!U##	AGGI-	s{+++ D #
 ff{{}1wva3qyy{#3!34F F 
 {{}1a+=1HC76!s199;'7%78D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-  -
  XR	                  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[        XR                  5       -  U5      n[        XR                  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kk!&&(#GA!	
A	
A271+?+QsSZ'(+H?271+?+QsSZ'(+H?"HXH.AXH.A	FFHQJFFHQJ++A...4A188:x(F			 A			 Aa		mQ'Ha		mQ'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 / pU H  n
XU
R	                  5       '   M     S	 nUR                  5       u  pU" X5        U GH  u  pU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    1q5T/q6DAYYqvv&FXq[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 :tAzq	U3ZA!&&(4:%%qq-FC
s
'C@1a@@321ahhj ! JA!{{}188:?HHaVA.D--D-1KAx!X& 1EE$quuQx{A./ ! ++a.155'CABchh/YOOA&aiik* (
 T$s188:v678!<AHHa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    > 	xxzAHHJr11	

A	

A558DAyyaiik"""''1"+aS13YOOAd199;;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MMO	 r7i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      pU
R                  [        R                  [        R                  5      U
R                  [        [        R                  5      p[        [        XU5      U5      n[        X5      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 /5e$DA			aQqS\*113A			aQqS\*113AAq5)EAq5)E99QUUAFF#UYYq!&&%9q99QUUAFF#UYYq!&&%9qYqQ#A
!
C
{VVFxxzQH%q) QZZC)1-A
 Aa#;
C*$#Z)???c&B&B&D&D%%sd+%%c*  C

AsAs+,AwwDw!Q&QZZCC 0115AQZZCC 0115AQ$A+&&(Bc#b'kCAq(9$999F 5 P !
C
{XXZ!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=   