K ii^dZddlZddlmZddlmZddlmZmZm Z m Z m Z ddl m Z mZmZmZddlmZmZmZmZmZmZmZmZddlmZmZmZmZdd lm Z!dd l"m#Z#e!jHZ$e!jJZ%d Z&d Z'dd Z(dZ)dZ*dZ+dZ,dZ-dZ.dZ/dZ0dZ1dZ2dZ3ddZ4dZ5dZ6d dZ7d!dZ8y)"a Algorithms for solving Parametric Risch Differential Equations. The methods used for solving Parametric Risch Differential Equations parallel those for solving Risch Differential Equations. See the outline in the docstring of rde.py for more information. The Parametric Risch Differential Equation problem is, given f, g1, ..., gm in K(t), to determine if there exist y in K(t) and c1, ..., cm in Const(K) such that Dy + f*y == Sum(ci*gi, (i, 1, m)), and to find such y and ci if they exist. For the algorithms here G is a list of tuples of factions of the terms on the right hand side of the equation (i.e., gi in k(t)), and Q is a list of terms on the right hand side of the equation (i.e., qi in k[t]). See the docstring of each function for more information. N)reduce)ilcm)DummyAddMulPowS)order_at order_at_ooweak_normalizer bound_degree)gcdex_diophantinefrac_in derivationresidue_reduce splitfactorresidue_reduce_derivationDecrementLevelrecognize_log_derivative)Polylcmcancelsqf_list) PolyMatrix)solvecjt||\}}tt|\}}td|t d|j }t||\} } |j | } | j | j|j j| j | j|j } || z} | | z}| |z|t| |z|zz }|j|d\}}|Dcgc]\}}||zj|d}}}| ||f|| fScc}}w)a Parametric Risch Differential Equation - Normal part of the denominator. Explanation =========== Given a derivation D on k[t] and f, g1, ..., gm in k(t) with f weakly normalized with respect to t, return the tuple (a, b, G, h) such that a, h in k[t], b in k, G = [g1, ..., gm] in k(t)^m, and for any solution c1, ..., cm in Const(k) and y in k(t) of Dy + f*y == Sum(ci*gi, (i, 1, m)), q == y*h in k satisfies a*Dq + b*q == Sum(ci*Gi, (i, 1, m)). c$|j|SNrijs Z/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/integrals/prde.pyz#prde_normal_denom..2sQUU1XTinclude) rlistziprrtgcddiffquorr)fafdGDEdndsGasGdsgdenesphacbabdADs r#prde_normal_denomrB#sR FBCG}HC %sDBDDM :B R FB r A rwwrtt}!!!%%rtt "56A 1A !A 2:a$$R' 'B YYr4Y (FB34541a!A#a &5A5 BxA  6s D/c|j|j}|j|j}|jDcgc]"\}}|ddzdk(r|n|ddzdk(r| nd$}}}|jDcgc]"\}}|ddzdk(r|n|ddzdk(r| nd$}}}td|D}td|D}|jDcgc]"\}}|ddzdk(r|n|ddzdk(r| nd$} }}|jDcgc]"\}}|ddzdk(r|n|ddzdk(r| nd$} }}td| D} td | D} | |z| |zzj|| |z| |zz j|f}||z||zzj|}|d|d|fScc}}wcc}}wcc}}wcc}}w) a Helper function, to get the real and imaginary part of a rational function evaluated at sqrt(-1) without actually evaluating it at sqrt(-1). Explanation =========== Separates the even and odd power terms by checking the degree of terms wrt mod 4. Returns a tuple (ba[0], ba[1], bd) where ba[0] is real part of the numerator ba[1] is the imaginary part and bd is the denominator of the rational function. rr&c3 K|]}|ywr.0rs r# zreal_imag..S(!( c3 K|]}|ywrrHrIs r#rLzreal_imag..TrMrNc3 K|]}|ywrrHrIs r#rLzreal_imag..W&!&rNc3 K|]}|ywrrHrIs r#rLzreal_imag..XrQrN)as_polyas_dictitemssum) r>r?genkeyvalue denom_real denom_imagbd_realbd_imagnum_realnum_imagba_realba_imags r# real_imagrbBs C "B C "BceckckcmnU_UXZ_3q6A:?%#a&1*/qPnJnceckckcmnU_UXZ_3q6A:?%#a&1*/qPnJn(Z((G(Z((GacaiaiaklS]SVX]Q!qA aufQNlHlacaiaiaklS]SVX]Q!qA aufQNlHl&X&&G&X&&G 7?WW_ , 5 5c :WW_wW^=^, and g1, ..., gm in k(t) with Dt/t in k (resp. Dt/(t**2 + 1) in k, sqrt(-1) not in k), a != 0, and gcd(a, t) == 1 (resp. gcd(a, t**2 + 1) == 1), return the tuple (A, B, GG, h) such that A, B, h in k[t], GG = [gg1, ..., ggm] in k(t)^m, and for any solution c1, ..., cm in Const(k) and q in k of a*Dq + b*q == Sum(ci*gi, (i, 1, m)), r == q*h in k[t] satisfies A*Dr + B*r == Sum(ci*ggi, (i, 1, m)). For case == 'primitive', k == k[t], so it returns (a, b, G, 1) in this case. autoexptanrEr&) primitivebasez@case must be one of {'exp', 'tan', 'primitive', 'base'}, not %s.c3K|]6\}}t|jt|jz 8ywr)r r+)rJGaGdr2r:s r#rLz%prde_special_denom..s4 Kvr2Xb!RTT "Xb!RTT%: : Ksr?r1r2rlBnbncndcoeffalphaaalphadetaaetadr@QmzbetaabetadsNpNpnrjrkr;r:s ` @r#prde_special_denomr^sX* v~ww u} rtt   q1bdd # & & FF2J1aa''!%&' ' "a "a!6 6B K K KB ArC2JA 5=TTXXd244./F# &!("''!*RWWQZ)?q )I244!P$VRTT2 d(tRH=GAq!Av1I & &U]TTXXd2447Q;56F# ,)22r!tRTT)B%vv$VRTT2 d+DBDDM%,?K,VVT4LA,UE4rJA}"#1a6 #Aqs A , As A AB QBB "A 266": Q a 1b(9(=(=a(@@CCA;<=R"R%(  2t  ,=A= A q!Q<I & & , ,( >s BM23BM>#N 2M;>Nct|}tt|\}}td|}t |d}|D cgc](\}} ||j | zj |*c} }tdDs3tfdD} t| dz|fdj} ntd|gj} tt\} } | | fScc} }w) a Parametric Risch Differential Equation - Generate linear constraints on the constants. Explanation =========== Given a derivation D on k[t], a, b, in k[t] with gcd(a, b) == 1, and G = [g1, ..., gm] in k(t)^m, return Q = [q1, ..., qm] in k[t]^m and a matrix M with entries in k(t) such that for any solution c1, ..., cm in Const(k) and p in k[t] of a*Dp + b*p == Sum(ci*gi, (i, 1, m)), (c1, ..., cm) is a solution of Mx == 0, and p and the ci satisfy a*Dp + b*p == Sum(ci*qi, (i, 1, m)). Because M has entries in k(t), and because Matrix does not play well with Poly, M will be a Matrix of Basic expressions. c$|j|Srrr s r#r$z)prde_linear_constraints..AEE!Hr%Tfieldc3:K|]\}}|jywris_zero)rJ_ris r#rLz*prde_linear_constraints..s)earzz)sc3ZK|]"\}}|jj$ywrdegreer+)rJrrr2s r#rLz*prde_linear_constraints..s!/EAr "$$/s(+r&c2|dj|SNr&nthr!r"r|s r#r$z)prde_linear_constraints..s!A$q'++a.r%r) lenr)r*rrr.divallrrMatrixr+)r<br1r2r}Gnsr6rogar7rMqsrr|s ` @r#prde_linear_constraintsrs" AACG}HC$c*A QdA/01VR"aWWR[.  a 1A )q) ) /Q/ / 1q5!8"$$ ? 1aRTT " aMEB 7N 2s-C'c8t|}t|Dcgc]}|j|c}\}tdDs4t dD}t |dz|fd|j }||fSt d|g|j }||fScc}w)aB Given p = [p1, ..., pm] in k[t]^m and d in k[t], return q = [q1, ..., qm] in k[t]^m and a matrix M with entries in k such that Sum(ci*pi, (i, 1, m)), for c1, ..., cm in k, is divisible by d if and only if (c1, ..., cm) is a solution of Mx = 0, in which case the quotient is Sum(ci*qi, (i, 1, m)). c34K|]}|jywrrrJrs r#rLz*poly_linear_constraints..&brzz&c3<K|]}|jywr)rrs r#rLz*poly_linear_constraints..s( (sr&c,|j|Srr)r!r"rKs r#r$z)poly_linear_constraints..!A$((1+r%r)rr*rrrrrgens)r:ror}piqrvrrKs @r#poly_linear_constraintsrs AA Q'r' (DAq &A& & (a( ( 1q5!5qvv > a4K 1aQVV $ a4K(sBc |s||fS|j|}|j\}}|ddddf|dddf}}fd tjt |j t |j D]\}}|||fjjjs/||ddf} |||f |j fd} || z } |dd|f} || |zz }|| | zz }|j|}|jt| g|j}||fS)a Generate a system for the constant solutions. Explanation =========== Given a differential field (K, D) with constant field C = Const(K), a Matrix A, and a vector (Matrix) u with coefficients in K, returns the tuple (B, v, s), where B is a Matrix with coefficients in C and v is a vector (Matrix) such that either v has coefficients in C, in which case s is True and the solutions in C of Ax == u are exactly all the solutions of Bx == v, or v has a non-constant coefficient, in which case s is False Ax == u has no constant solution. This algorithm is used both in solving parametric problems and in determining if an element a of K is a derivative of an element of K or the logarithmic derivative of a K-radical using the structure theorem approach. Because Poly does not play well with Matrix yet, this algorithm assumes that all matrix entries are Basic expressions. Nc t|dS)NTbasic)r)xr2s r#r$z!constant_system..s*Q$/r%c|z SrrH)rrADAijs r#r$z!constant_system..s1r%)row_joinrref itertoolsproductrangecolsrowsexprhasT applyfunccol_joinrr) r@ur2Aurr"r!RiRm1um1AjrArs ` @@r#constant_systemrs9, !t AB GGIEB, a"f:r!R%yqA/A!!%-qvv?21 1QT7<<  RTT "1a4BQq!tW:D,,45CAaD'D.C1a4BBH ABH A 3A 63%01A2 q6Mr%c Jtt|Dcgc]}t|||c}\}}|}|t||z} t||D cgc]\} } | t| |z } } } t|}||j |j z } || | || fScc}wcc} } w)a( Special Polynomial Differential Equation algorithm: Parametric Version. Explanation =========== Given a derivation D on k[t], an integer n, and a, b, q1, ..., qm in k[t] with deg(a) > 0 and gcd(a, b) == 1, return (A, B, Q, R, n1), with Qq = [q1, ..., qm] and R = [r1, ..., rm], such that for any solution c1, ..., cm in Const(k) and q in k[t] of degree at most n of a*Dq + b*q == Sum(ci*gi, (i, 1, m)), p = (q - Sum(ci*ri, (i, 1, m)))/a has degree at most n1 and satisfies A*Dp + B*p == Sum(ci*qi, (i, 1, m)) )r)r*rrrr+)r<rr|rvr2qiRZr@rsrziQqn1s r# prde_spder)s A>b'1b1>? @DAq A Jq" A03Aq :fb""z"b! ! :B : QA QXXbdd^ B q"a ? ;s B Bc|jj}t}tdjg|z}t j t |ddt |D]y\}}|j||z|jz } t| j|zzj} ||| z||<|t| z || zz |<{tdDrd} ntfdD} t| dz|fdj} t| t| dzdj\} }t|j}| j!t| j"|jj%|j!| } || fS)aB Parametric Poly Risch Differential Equation - No cancellation: deg(b) large enough. Explanation =========== Given a derivation D on k[t], n in ZZ, and b, q1, ..., qm in k[t] with b != 0 and either D == d/dt or deg(b) > max(0, deg(D) - 1), returns h1, ..., hr in k[t] and a matrix A with coefficients in Const(k) such that if c1, ..., cm in Const(k) and q in k[t] satisfy deg(q) <= n and Dq + b*q == Sum(ci*qi, (i, 1, m)), then q = Sum(dj*hj, (j, 1, r)), where d1, ..., dr in Const(k) and A*Matrix([[c1, ..., cm, d1, ..., dr]]).T == 0. rrc34K|]}|jywrrrJrs r#rLz)prde_no_cancel_b_large..Zs ""2:: "rc3TK|]}|jj!ywrrrJrr2s r#rLz)prde_no_cancel_b_large..]s-R244-%(r&c,|j|Srrrs r#r$z(prde_no_cancel_b_large..^sqtxx{r%)rr+rrrrrrLCrrrrrrzeroseyerrr)rr|rvr2dbr}Hrr!sisitndcrr@rr=s ` ` r#prde_no_cancel_b_largerBs "$$B AA aA!!%2r"2E!H=41 qTXXa"f addf $BrttQwJ%td{!tjr**QtV3! 4  " ""  -1- -rAvq2BDD9A 1eBFArtt4b 9DAq Artt A 5BDD)*33AJJrNCA q6Mr%c X t}tdjg|z}tjt |ddt |D]\}}|j |jjjzdz |jjzz }t|j|zzj} ||| z||<|t| z || zz |<|jjdkDr`t |D]z}t|j |jj|jz j}|||z||<|t|z ||zz |<|tdDrd} ntfdD} t| dz|fdj} t| t| dzdj\} } t!|j}| j#t| j$|jj'|j#| } || fSj}j(dk7rt+5j}t-||d \}}Dcgc]}t-|j/|d  }}t1|||\}}d d d Dcgc]2\}}t|j3|j3z |d 4}}}tj4j7|}nTtd|d g}tDcgc]}|j/c}t8j:gzgj}tfd D}|dkDrAt||fd j} t| t|dj\} }ntd|gj} t|}t!|j}| j#t| j$||zj} |j#t|j$|j}|j#t||jj#| }||z| j'|j'|fScc}w#1swYxYwcc}}wcc}w) a= Parametric Poly Risch Differential Equation - No cancellation: deg(b) small enough. Explanation =========== Given a derivation D on k[t], n in ZZ, and b, q1, ..., qm in k[t] with deg(b) < deg(D) - 1 and either D == d/dt or deg(D) >= 2, returns h1, ..., hr in k[t] and a matrix A with coefficients in Const(k) such that if c1, ..., cm in Const(k) and q in k[t] satisfy deg(q) <= n and Dq + b*q == Sum(ci*qi, (i, 1, m)) then q = Sum(dj*hj, (j, 1, r)) where d1, ..., dr in Const(k) and A*Matrix([[c1, ..., cm, d1, ..., dr]]).T == 0. rrr&c34K|]}|jywrrrs r#rLz)prde_no_cancel_b_small..rrc3TK|]}|jj!ywrrrs r#rLz)prde_no_cancel_b_small..s1RYYrtt_1rc,|j|Srrrs r#r$z(prde_no_cancel_b_small..s1Q488A;r%rhTrNc3TK|]}|jj!ywrrrs r#rLz)prde_no_cancel_b_small..s (BIIbddO (rc2|j|dzSrrrs r#r$z(prde_no_cancel_b_small..sadhhq1uor%)rrr+rrrrrorrrrrrrrrrrrrrlrrTC param_rischDEas_expr from_Matrix to_Matrixr Zero)rr|rvr2r}rrr!rrrrr@rr=r+t0r>r?rQ0frsr/r0rorrKICs ` ` r#prde_no_cancel_b_smallrfsQ AA aA!!%1b/58<41 qTXXa"$$++bdd++a/ 0!BDDGGI+ >BrttQwJ%td{!tjr**QtV3! 4  xx~q 4Aadhhqxx~.qttv5rtt?r'"%%'2T2?B? RR0DAq  1$ R"**,rzz|+Qd ;     q{{}a 0!Qd # $ q)RUUW)QVVH45rtt < (a ((A1u 1a5rtt <q%1bdd"3R81 1aRTT " AA Artt A 5Q-.A 5BDD)*A 5Artt$%..r2A q5!**Q-((+ ++i@ 1 1" *s*&"T#T+T 7T!T'TTc g}|jdk(r/t|5t||jd\}}dddt |ddD]}|jdk(rot|5t||t |j||jz zj |jz|jd\}}dddt|5|Dcgc])}t|j||jd+} }t| |\} } ddd D cgc]<\} } t| j| jz |jd>} } }  j|j} t| }||k(r| }n?| jjt!|j"||j}dg|zdg|z}}t |D]N}| ||j|zj | |jz}|||<t ||||zz ||<P||z }||z}|fS#1swY!xYw#1swYxYwcc}w#1swYXxYwcc} } w)z Pg, 237. rgTrNrre)rlrrr+rrrSrrrrrset_gensrrrrr)rr|rvr2rr>r?r!rQyfiAir/r0rrFihir"hjis r#prde_cancel_liouvillianrsb A ww+ B  2QD1FB 21b"  77e # 2 aBDD")=bdd)B&C%L%LQVV%T!T "D2B 2B  3?@A!'!%%(BDD5ABA"2r2r2FB 3!"B2::< ,bdd$?"" [[  W 6A AJJuQVVR'>?@ATF2IBr 3AQ%2447++BqEJJ77CBqE b)AcE12BqE  3 R F?B q6MI 2 2  2 2B 3 3"s=I,AI%I7 .I2I7.AJI"%I/ 2I77J c t}|dkrtdDrgtd|jfSt fdD}t |dz|fdj}t |t|jdj\}} g|fS|jr|j}|jj|D cgc]!} | jj|#c} c}|jsUjdk(s8|jt djjdz kDrt!||S|js.|jjjdz kr:jdk(sjjdk\rt#||Sjjdk\r|jjjdz k(rV||j%j jj%jz kDr t'djd vrt)||St'd |j*|j,g|z} } |dk\rbt/|||\}}} }t1| | Dcgc] \}}|| |zz} }}| |z} |j3|}|jsn|dk\rbt5\}}t |t|jdj\}} |j7}|sgt9|jfSt |g}|Dcgc] }||zd } }t | g}|Dcgc] }||zd }}t;|j=||j=|| |\}}||Dcgc]}| |z c}z}t9|j }|D]}|j?|}|j?t|t|j}|jAt|j|jj?|}||fScc} wcc}}wcc}wcc}wcc}w) a5Polynomial solutions of a parametric Risch differential equation. Explanation =========== Given a derivation D in k[t], a, b in k[t] relatively prime, and q = [q1, ..., qm] in k[t]^m, return h = [h1, ..., hr] in k[t]^r and a matrix A with m + r columns and entries in Const(k) such that a*Dp + b*p = Sum(ci*qi, (i, 1, m)) has a solution p of degree <= n in k[t] with c1, ..., cm in Const(k) if and only if p = Sum(dj*hj, (j, 1, r)) where d1, ..., dr are in Const(k) and (c1, ..., cm, d1, ..., dr) is a solution of Ax == 0. rc34K|]}|jywrrrs r#rLz%param_poly_rischDE.. rrr&c3TK|]}|jj!ywrrrs r#rLz%param_poly_rischDE..s,B "$$,rc,|j|Srr)r!r"rs r#r$z$param_poly_rischDE..rr%rhrEz0prde_no_cancel_b_equal() is not yet implemented.)rgrez?non-linear and hypertangent cases have not yet been implemented)!rrrr+rrrrr is_groundrto_field exquo_groundrrlrrorrrSNotImplementedErrorronezerorr*r,r nullspacerparam_poly_rischDEr.rr)r<rrrvr2r}rrr@rralphabetarKbetairroqqVMqqvjMbetargrsgkr;s ` ` r#rrs5 AA1u &A& &uQ244(( ( ,!, , 1q5!5rtt <q%244"8"=11u {{ DDFzz|((+VW-XPRbkkm.H.H.K-X1yybgg/ SBDDKKMA$566)!Q26 6yyAHHJ)::WW&"$$++-1*<)!Q26 6ddkkmq hhjBDDKKMA--199;>>##BDDLLN$5$5$777%''( ( ww...q!Q;;)+>??%%!&&!4E q&!!Q1b1 1aA25dA,?YUBb ??   EE!H{{  q& $Aq )EB 1eAFFArtt4b 9DAq A 3q"$$< ",C !#b&!!A! D6NE!"#2%(A#A# aeeAha!Q ;DAq  ""U2X ""A Q A JJrN 5CFBDD)*A 5BDD)22156A a4KQ.Y>@R " $ #s"&R>/S%S S Sc Tt|}t|||\}\}}|}|Dcgc]\}}||zj|d}}}t||||\} \} } }} || z}t | | | ||\} }}}||z}| j |}| j ||j ||Dcgc]\}}|j||zd}}}}} t| |||\}}t|t|jd|j|\}}|j}|sgt||jfSt|g}|Dcgc] }||zd }} t| |||d}t#| ||||\}}t||j } |D]}| j%|} | j%t|t||j} | j't|j||jj%|} | j}t|}t|||zf}|Dcgc]}|d||| dz} }| D!"cgc] }!|!D]}"|" }#}!}"tg||#|j}|j}$t|$D%cgc]}%|%dd c}%|j}&|D'cgc]}'|'j|dc}'|&fScc}}wcc}}wcc}w#t $rd}YwxYwcc}wcc}"}!wcc}%wcc}'w)ad Solve a Parametric Risch Differential Equation: Dy + f*y == Sum(ci*Gi, (i, 1, m)). Explanation =========== Given a derivation D in k(t), f in k(t), and G = [G1, ..., Gm] in k(t)^m, return h = [h1, ..., hr] in k(t)^r and a matrix A with m + r columns and entries in Const(k) such that Dy + f*y = Sum(ci*Gi, (i, 1, m)) has a solution y in k(t) with c1, ..., cm in Const(k) if and only if y = Sum(dj*hj, (j, 1, r)) where d1, ..., dr are in Const(k) and (c1, ..., cm, d1, ..., dr) is a solution of Ax == 0. Elements of k(t) are tuples (a, d) with a and d in k[t]. Tr'r&r) parametricN)rr rrBrr,r.rrrrr+rrrr rrrr)(r/r0r1r2r}rgammarr7r<r>r?hnr@rshsrgiagidrrrr MqrrKrvr;WvshapewlelementsrowerUrnirhks( r#rrs;" AA!"b"-KAxB E789VR!B$r4 (9A9*2r1b9AxBB RKE$QB26KAq!R RKE aAeeAha#S$'::c!eT:#B#!#qA #1aB /DAq 1eAFFArtt4b 9DAq A 3q"$$< B "R% A  Aq" 6 aAq" -DAq Q A JJrN 5CFBDD)*A 5BDD)22156A A AA VQqSME+,-R2AQBC -H-" 03C 0qQ 0Q 0E 0 ##u#bdd#A A ""1"BDD)A56 7rBIIeTI * 7 ::_ :#J !   N. 0# 7s; K23 K8 K>$LL,L1 L L% LLct|\}}|Dcgc]\}}t|}}}tt|\} } td|f| z} | j | j j } | } t|  }d}jdvrtd|f| z}| |z} || t|zj|z}tt||j tfd|D}| jj |jj ztddjjj z |z z}nt|Dcgc]\}}| | z|zj!|d!}}}| || || | z|zj!|d|fScc}}wcc}}w) a Simpler version of step 1 & 2 for the limited integration problem. Explanation =========== Given a derivation D on k(t) and f, g1, ..., gn in k(t), return (a, b, h, N, g, V) such that a, b, h in k[t], N is a non-negative integer, g in k(t), V == [v1, ..., vm] in k(t)^m, and for any solution v in k(t), c1, ..., cm in C of f == Dv + Sum(ci*wi, (i, 1, m)), p = v*h is in k, and p and the ci satisfy a*Dp + b*p == g + Sum(ci*vi, (i, 1, m)). Furthermore, if S1irr == Sirr, then p is in k[t], and if t is nonlinear or Liouvillian over k, then deg(p) <= N. So that the special part is always computed, this function calls the more general prde_special_denom() automatically if it cannot determine that S1irr == Sirr. Furthermore, it will automatically call bound_degree() when t is linear and non-Liouvillian, which for the transcendental case, implies that Dt == a*t + b with for some a, b in k*. c$|j|Srrr s r#r$z*limited_integrate_reduce..#rr%r)rhrgrerfc$|j|Srrr s r#r$z*limited_integrate_reduce..,sqr%c3RK|]\}}t||j ywr)r r+)rJrr7r2s r#rLz+limited_integrate_reduce../s*0 B1>3 -0 >s G$G c|td|jz |jz|j}}td|j}td|j}||fg|z}t ||||\}|j }|Dcgc] }|ddk7s |}}|sy|dd} |d| z t } t | z dz tddz} tfdt| D } | j\} }t| |jt||j}}|td|jz |jz|jf}|| fScc}w)zQ Solves the limited integration problem: f = Dv + Sum(ci*wi, (i, 1, n)) r&rNc3K|]=}dz|z|djz|djz ?yw)r&rN)r)rJr!r;r}rs r#rLz$limited_integrate..TsM#1q519ad1goo//!Q0AA#sAA) rrr+monicrrrr)rVras_numer_denom)r/r0r1r2FaFdr@r rc0rKryy_numy_denYaYdYr;r}s ` @@r#limited_integrater:=stQruuwY% %rxxzB aB aB b QA RB 'DAq A#q1#A# qT!W aD2#J F FQJN 1a!e  #q## #'') ueRTT"D$5B tAbeegIrtt$ $bhhj 0!t ! $s  F %F c|xs td}|j|\}}|j|\}} tdt|j|j |jdz } t|j |j|j |j} |j |j| kDrt | dz| dzD cgc](} |j| ||j| zz *} } t| |}|r||jsy||j\}}|j|j}|j|j}||z|z||z|zz }||z}t|||d}|y|\}}|js |jry||z||z|fS|j |j| kDryt|j|jj!|j|jj!}|j#j|j#t%||jz}t'||\}}||j)|j+|jz}|j-|jsy||j/|zj|\}}||j/|zj|\}} t |j |jD cgc](} |j| || j| zz *} } t| |}|r||jsy||j\}}|j|j|z|z|j|j|z|zz }||z}t|||}|y|\}}|js |jry||z||z|fScc} wcc} w)aH Parametric logarithmic derivative heuristic. Explanation =========== Given a derivation D on k[t], f in k(t), and a hyperexponential monomial theta over k(t), raises either NotImplementedError, in which case the heuristic failed, or returns None, in which case it has proven that no solution exists, or returns a solution (n, m, v) of the equation n*f == Dv/v + m*Dtheta/theta, with v in k(t)* and n, m in ZZ with n != 0. If this heuristic fails, the structure theorem approach will need to be used. The argument w == Dtheta/theta c1rr&Nrd)rrrrrr+rrrr is_Rationalr0rSr!is_log_deriv_k_t_radical_in_fieldrrrr/rrr,r-rr.)!r/r0wawdr2r<r:r<rrrsrr!eqsrrrM_polyN_polynfmwanfmwdQvr|rr=llnlsr~u1r1u2r2s! r#parametric_log_deriv_heurN\s& uT{B 66":DAq 66":DAq Az"$$#**2440145A AHHRTTNAHHRTTN+Axx~/4QUAE/BC!quuQx"QUU1X+%CC #rN"))u##%1166"166"r " vby|+2 .ueR H :1 99 !QqS!}xx~ BJJrtt    !2::bdd#3#6#6#89A  rxxz"4244=0A B FB 266"''"$$-  A 55;rl   "FBrl   "FB-2188BDD>-B C266!9r"&&)| # CC C c2A AbE%% R5   !DAq IIbddOB r !AIIbddOB$6r$9 9E rEE *5% . I! 1b5==I"%Nc34K|]}|jywrr=rJr!s r#rLzis_deriv_k..#,Q1==,r8Cannot work with non-rational coefficients in this case.)rrrextsrAcasessetindicesrr.rrrrrrrrextargsr)r*rrr0rappendr)r/r0r2dfadfdr!E_partL_partdumlhsrhsr@rtermsansr"resultargtermsrGldroicoeffitermsrr!rwdtermsconsts ` r# is_deriv_krusz:b"%%:b"+=(==2Czz#tz,HC 277|s244y xx .!1:A .XX:k)9!:BJJu-./%'MN N"#)* *FHZZPUEV Wbdd1gkk$rttAwQ0199; WF W)+E): ;Abdd1goo ;F ; 'C &6/"C (C #++- -. 4C 3R (DAq A CIqII ,!,,%'-. ..0ZZ->?bjjm?&(jj&78RTT!W89Es5!}%C5A3q!956F*,**U*;qRZZ]>?HABHa( W1'')1!)!FA/62R41a3q!A#;2RRTU!)! #VQ 0F3SDAqC1Q3K3S SUV W2::< 4S!W3S3SsO5 PP P P+AP$P$*P)P.P3 =P9(P>Q.Q c|r7|t|z|t|zz j|dzd\}}n||}}tjtjk7rqj Dcgc] }|dk(s | c}s;j Dchc] }|dk(s | c}t jdz r tdtdjd Dcgc]R}j|jtj|j|jT}}jdDcgc]}j|j!}}t} t||zg| } t|j|jz g| } t| | \} } | j!} | rt#fd | Dsy t#d | Ds td t$j&t)t*| Dcgc]}|j-dc}z}| |z} jd Dcgc]}j|c}jdDcgc]}j.|c}z}t1t3|| }t5|Dcgc]\}}t7||c}}}jd Dcgc]}j.|c}jdDcgc]}j|c}z}t|j|jz t9t3|| Dcgc]\}}t5|||z c}}z }||||fScc}wcc}wcc}wcc}wcc}wcc}wcc}wcc}}wcc}wcc}wcc}}w)aE Checks if Df is the logarithmic derivative of a k(t)-radical. Explanation =========== b in k(t) can be written as the logarithmic derivative of a k(t) radical if there exist n in ZZ and u in k(t) with n, u != 0 such that n*b == Du/u. Either returns (ans, u, n, const) or None, which means that Df cannot be written as the logarithmic derivative of a k(t)-radical. ans is a list of tuples such that Mul(*[i**j for i, j in ans]) == u. This is useful for seeing exactly what elements of k(t) produce u. This function uses the structure theorem approach, which says that for any f in K, Df is the logarithmic derivative of a K-radical if and only if there are ri in QQ such that:: --- --- Dt \ r * Dt + \ r * i / i i / i --- = Df. --- --- t i in L i in E i K/C(x) K/C(x) Where C = Const(K), L_K/C(x) = { i in {1, ..., n} such that t_i is transcendental over C(x)(t_1, ..., t_i-1) and Dt_i = Da_i/a_i, for some a_i in C(x)(t_1, ..., t_i-1)* } (i.e., the set of all indices of logarithmic monomials of K over C(x)), and E_K/C(x) = { i in {1, ..., n} such that t_i is transcendental over C(x)(t_1, ..., t_i-1) and Dt_i/t_i = Da_i, for some a_i in C(x)(t_1, ..., t_i-1) } (i.e., the set of all indices of hyperexponential monomials of K over C(x)). If K is an elementary extension over C(x), then the cardinality of L_K/C(x) U E_K/C(x) is exactly the transcendence degree of K over C(x). Furthermore, because Const_D(K) == Const_D(C(x)) == C, deg(Dt_i) == 1 when t_i is in E_K/C(x) and deg(Dt_i) == 0 when t_i is in L_K/C(x), implying in particular that E_K/C(x) and L_K/C(x) are disjoint. The sets L_K/C(x) and E_K/C(x) must, by their nature, be computed recursively using this same function. Therefore, it is required to pass them as indices to D (or T). L_args are the arguments of the logarithms indexed by L_K (i.e., if i is in L_K, then T[i] == log(L_args[i])). This is needed to compute the final answer u such that n*f == Du/u. exp(f) will be the same as u up to a multiplicative constant. This is because they will both behave the same as monomials. For example, both exp(x) and exp(x + 1) == E*exp(x) satisfy Dt == t. Therefore, the term const is returned. const is such that exp(const)*f == u. This is calculated by subtracting the arguments of one exponential from the other. Therefore, it is necessary to pass the arguments of the exponential terms in E_args. To handle the case where we are given Df, not f, use is_log_deriv_k_t_radical_in_field(). See also ======== is_log_deriv_k_t_radical_in_field, is_deriv_k rETr'rfrgrQrRrSrec3NK|]}t|djywrUrVrWs r#rLz+is_log_deriv_k_t_radical..rXrYNc34K|]}|jywrr[r\s r#rLz+is_log_deriv_k_t_radical..r]rr^r&)rrrr_rAr`rarbrr.rrrrrrrrr Onerrr0rcr)r*rrr)r/r0r2Dfrerfr!rgrhrirjrkr@rrvrlrmr"rnrorts ` r#is_log_deriv_k_t_radicalr{=siz z"b))Bz"b/A,AAII"a%JSrS 277|s244y xx .!1:A .XX:k)9!:BJJu-./%'MN N"#)* *FHZZPUEV Wbdd1gkk$rttAwQ0199; WF W)+E): ;Abdd1goo ;F ; 'C &6/"C (C #++- -. 4C 3R (DAq A CIqII ,!,,&'-. .fT1#EaA$4$4$6q$9#EFFA FA')zz%'89!bdd1g9,.JJu,=>qRZZ]>?Es5!}%C5A3q!956F13 50AB1AB&(jj&78RTT!W89H2::< 4c(A.>?dac!QqSk?@ABEE* *g /:X ;4$F9>5C8?sO8 N.N. N3#N3.AN8$N=7O 2OO O O0OO!c  |j|d\}}t||\}}|js |xs td}t ||||\}}|sy|D cgc]\} } | | j f} } } t d| Dsytt| xsggg\} } tt|D cgc]&}| |D]} ||dj|| | f(}}} t|j|jz t|||z }|j|j}|y|j!|jt#d|j$j!|jk\ry|dk(r |j&}|d k(rt)|j|jt+|j|jd\}}t-|5t/||jd \}}t/||f|j\}}t1|||||}dddy|\}}}||j|zz}n|d k(rEt-|5t/||j\}}t3|||d }dddy|\}}n|d k(r|j4r!|j!|j!k\ryt6j8t;t<|D cgc]\} } | j?dc} } dz}tA|D cgc]\} }tC| ||zc}} }||fS|dk(r tEd|dvrtGd|ztGd|zt6j8t;t<|D cgc]\} }| c}} D cgc]} | j?dc} |gzdz}|D cgc] \} }| ||zf}} }||z}|||zk7r tGdt||ztA|D cgc]\} }tC| |c}} z}||fScc} } wcc} }w#1swYxYw#1swYxYwcc} } wcc}} wcc}} wcc} wcc}} wcc}} w)a Checks if f can be written as the logarithmic derivative of a k(t)-radical. Explanation =========== It differs from is_log_deriv_k_t_radical(fa, fd, DE, Df=False) for any given fa, fd, DE in that it finds the solution in the given field not in some (possibly unspecified extension) and "in_field" with the function name is used to indicate that. f in k(t) can be written as the logarithmic derivative of a k(t) radical if there exist n in ZZ and u in k(t) with n, u != 0 such that n*f == Du/u. Either returns (n, u) or None, which means that f cannot be written as the logarithmic derivative of a k(t)-radical. case is one of {'primitive', 'exp', 'tan', 'auto'} for the primitive, hyperexponential, and hypertangent cases, respectively. If case is 'auto', it will attempt to determine the type of the derivation automatically. See also ======== is_log_deriv_k_t_radical, is_deriv_k Tr'r~)r~Nc3K|]7\}}t||jk(xrtd|D9yw)c34K|]}|jywrr[)rJks r#rLz>is_log_deriv_k_t_radical_in_field...s+EaAMM+ErN)rrr)rJr!r"s r#rLz4is_log_deriv_k_t_radical_in_field..s>q!1v#E+E1+E(EEs=?r&rdre)rrg)rlrhrfzTThe hypertangent case is not yet implemented for is_log_deriv_k_t_radical_in_field()) other_linearother_nonlinearz.The %s case is not supported in this function.zGcase must be one of {'primitive', 'exp', 'tan', 'base', 'auto'}, not %szInexact division)$rris_onerr real_rootsrr)r*rrsubsrrrSr+rrrrorlrrrrrqr>is_sqfr ryrrr0rrrrm)r/r0r2rlr~rvrrrr!rrootsrespolysresiduesr" residuetermsr:r?r@papdr@r!r common_denomr}s r#r>r>s4YYr4Y (FB r2 DAq 88  U3ZA "b" *DAq -. /TQa /E /  c5k*6r2hHh6;3q6] a[ qT!W\\!Q'++L rzz|BJJL(+DQA+NNOA "$$Ayxx~Q BDD 122 v~ww u}BDD"%,,T"$$-=t,LB B  9QT2FBb"Xrtt,FB$RRR8A 9 91a RTT1W    B  KQ%FB1"b"6JA K 91 yyBIIK299;6 EE&,O$!Q 0 0 21 5OQRS S ,7$!Q#a1+7 81v !#FG G 4 4IDPQQ"$()* *55GTQPQqG'q'7'7'9!'<''!!L4@ADAqQ,'ALAaAqs+,,q!tC =1#a)=>>?A ! e 0( 9 9 K K P7G'A>sIQ?+Q 8AQ3)Q>Q)0Q/ Q52Q; RRQQ&)rdr)T)rdN)9__doc__r functoolsrsympy.core.intfuncr sympy.corerrrrr sympy.integrals.rder r r r sympy.integrals.rischrrrrrrrr sympy.polysrrrrsympy.polys.polymatrixrr sympy.solversrrrrBrbrrrrrrrrrrr,r:rNrqrur{r>rHr%r#rs #..437  jj>8NbB&CL2!Ha,H-`FRE;P/?d>Xv  w(tx+v}r%