K i-dZddlmZddlmZddlmZddlmZm Z m Z ddl m Z ddl mZddlmZdd lmZdd lmZdd lmZdd lmZmZmZd ZdZddZdZdZdZ y)zAThis module implements tools for integrating rational functions. )Lambda)I)S)DummySymbolsymbols)log)atan) DomainError)roots)cancel)RootSum)Poly resultantZZc xt|tr|\}}n|j\}}t||ddt||dd}}|j |\}}}|j |\}}|j |j}|jr||zSt|||\}} | j\} } t| |} t| |} | j | \}} |||j |jzz }| js|jdd} t| ts t| }n| j}t| | ||}|jd}|dt|tr'|\}}|j|jz}n|j}||hz D]}|j rd}nd}t"j$}|sS|D]M\} }| j'\}} |t)|t+||t-| jzdz }Onh|D]c\} }| j'\}} t/| |||}|||z }/|t)|t+||t-| jzdz }e||z }||zS)aa 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) compositefieldsymboltreal) quadratic) isinstancetupleas_numer_denomrr div integrateas_expris_zeroratint_ratpartgetrras_dummyratint_logpartatomsis_extended_realrZero primitiverrr log_to_real)fxflagspqcoeffpolyresultghPQrrrLrr$elteps_Rs c/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/integrals/rationaltools.pyratintr<sD!U1!1 1T 2DAVZ4[qA((1+KE1aeeAhGD! ^^A  & & (FyyV| !Q "DAq   DAq Q A Q A 558DAq a!++a.((***F 998S)&&)f A!A 1aA &yy  <!U#1 AGGI- s{ ++ D  ff F1{{}1wva3qyy{#3!34FF F  J1{{}11a+=1HC76!Qs199;'7%78DJJC J #  <c ddlm}t||}t||}|j|j \}}}|j }|j }t d|D cgc]} tdt|| z z} } t d|D cgc]} tdt|| z z} } | | z} t| |t| } t| |t| }|| j |zz | |j |zj|zz||zz }||j| }| jj|} |jj|}t| |jz |}t||jz |}||fScc} wcc} w)a 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)solveab)domain)sympy.solvers.solversr?r cofactorsdiffdegreerangerstrrquocoeffsrsubsr )r)r1r*r?uvr9nmiA_coeffsB_coeffsC_coeffsABHr0rat_partlog_parts r;r r }s@, Q A Q Akk!&&(#GAq!  A  A271+?QsSQZ'(?H?271+?QsSQZ'(?H?("H XqH.A XqH.A AFFHQJAFFHQJ++A...14A 188:x (F  A  Aa mQ'Ha mQ'H X %@?s 0!G!!G Nc t||t||}}|xs td}|||jt||zz }}t||d\}}t||d}|sJd|d|dig} }|D]} | || j <d } |j \} } | | | | D]\}}|j \}}|j |k(r| j||fA||}t|j|d }|j d \}}| |||D]2\}}|jt|j||z|}4|j|tjg}}|jd d D]P}|j|j }||zj#|}|j|j%Rtt't)t+|j-||}| j||f| S)an 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 rT) includePRSF)rzBUG: resultant(z, z) cannot be zeroc|jr7|dkdk(r.|d\}}|j|j}||z|f|d<yyy)NrT)r%as_polygens)csqfr2kc_polys r; _include_signz%ratint_logpart.._include_signsM  1q5T/q6DAqYYqvv&FvXq[CF#2 r=)r)allN)rrrErrFsqf_listr'appendLCrIgcdinvertrOnerJr\r]remrdictlistzipmonoms)r)r1r*rr@rAresr:R_maprVr5rbCres_sqfr-rPr9r2h_lcr^h_lc_sqfjinvrJr.Ts r;r#r#sL 1:tAqzqA U3ZA a!&&(41:%%qA q! -FC sA 'C @1a@@321E ahhj! JAw!W1{{}1 88:? HHaV aA.D--D-1KAx !X &  01EE$quuQx{A./ 0++a.155'CAB + chh/YOOA& aiik* + T$s188:v678!>> 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 ) rFto_fieldrrr rgcdexrI log_to_atan) r)r1r,r-srr2rLrTs r;r}r}s> xxzAHHJr11 A A 558DAqyyaiik"""''1"+1a qS1Q3YOOA  d199; ;q!$$$r=ct|d} |j}t||k(r|Sy#t$r|cYSwxYw)zget real roots of f if possibler:)filterN)r count_rootslenr )r)r*rs num_rootss r;_get_real_rootsrHsJ q BMMO  r7i I  s 0 >>c ddlm}tdt\}}|j j ||t |zzij}|j j ||t |zzij}||t d} ||t d} | jtjtj| jt tj} } | jtjtj| jt tj}} tt| |||}t||}|ytj}|jD]j}t| j ||i|}|s-t|j ||i|}tj}t||}|yg}|D]Z}||vs| |vs|j s|j#r|j%| =|j&rJ|j%|\|D]}|j ||||i}|j)d dk7r.t| j ||||i|}t| j ||||i|}|d z|d zzj }||t+|z|t-||zzz }mt||}|y|jD]1}||t+|j j/||zz }3|S) aw 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)collectzu,v)clsF)evaluateNT)choprz)sympy.simplify.radsimprrrrxreplacerexpandr!rrjr&rrrkeys is_negativecould_extract_minus_signrfrevalfr r}rK)r2r-r*rrrLrMrVr4H_mapQ_mapr@rAr^dr:R_ur0r_urrR_v R_v_pairedr_vDrTrUABR_qr5s r;r(r(WsB/ 5e $DAq aQqS\*113A aQqS\*113A Aq5 )E Aq5 )E 99QUUAFF #UYYq!&&%9qA 99QUUAFF #UYYq!&&%9qA Yq!Q #A !Q C { VVFxxz&: QH%q )QZZC)1-A Aa# ;  +C*$#Z)???c&B&B&D%%sd+%%c*  + :C AsAs+,AwwDw!Q&QZZCC 0115AQZZCC 0115AQ$A+&&(B c#b'kC Aq(9$99 9F :5&:P !Q C { XXZ0!C ((A.///0 Mr=)N)!__doc__sympy.core.functionrsympy.core.numbersrsympy.core.singletonrsympy.core.symbolrrr&sympy.functions.elementary.exponentialr (sympy.functions.elementary.trigonometricr sympy.polys.polyerrorsr sympy.polys.polyrootsr sympy.polys.polytoolsr sympy.polys.rootoftoolsr sympy.polysrrrr<r r#r}rr(r=r;rsTG& "6669.'(+++jZ<~X v.%b fr=