K iRhUddlmZddlmZddlmZddlmZddlm Z ddl m Z ddl m Z ddlmZmZmZdd l mZdd lmZmZmZdd lmZmZdd lmZdd lmZddlmZddl m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'ddl m(Z(m)Z)m*Z*m+Z+m,Z,m-Z-ddl m.Z.m/Z/m0Z0m1Z1m2Z2ddl m3Z3m4Z4m5Z5m6Z6ddl m7Z7m8Z8m9Z9m:Z:ddl;mZ>m?Z?m@Z@ddlAmBZBddlCmDZDmEZEddlFmGZGddlHmIZImJZJddlKmLZLddlMmNZNmOZOddlPmQZQddlRmSZSmTZTmUZUmVZVmWZWmXZXddlYmZZZddl[m\Z\ddl]m^Z^dd l_m`Z`dd!lambZbdd"lcmdZdd#ZeiZfd$egd%<d&Zh d.d(ZiGd)d*Zjd'akGd+d,Zl d.d-Zmy')/) annotations) defaultdict)reduce) permutations)Add)Basic)Mul)WildDummySymbol)sympify)RationalpiI)EqNe)S)ordered) iterfreeargs)expsincostancotasinatan)logsinhcoshtanhcothasinh)sqrterferfiliEi)besseljbesselybesselibesselk)hankel1hankel2jnyn)Absreimsignarg)LambertW)floorceiling) Piecewise) Heaviside DiracDelta)collect)AndOr)uniq)quogcdlcm factor_listcancelPolynomialError) itermonomials) root_factors)PolyRing) solve_lin_sys)construct_domain) integratect}|j|rD|jr|jr|j ||S|j s |j r3|jD]}|t||z}|j ||S|jr|t|j|z}|jjsq|jjr>|j |jtd|jjz|S|t|j||hzz}|S|jD]}|t||z}|S)a Returns a set of all functional components of the given expression which includes symbols, function applications and compositions and non-integer powers. Fractional powers are collected with minimal, positive exponents. Examples ======== >>> from sympy import cos, sin >>> from sympy.abc import x >>> from sympy.integrals.heurisch import components >>> components(sin(x)*cos(x)**2, x) {x, sin(x), cos(x)} See Also ======== heurisch )sethas_free is_symbolis_commutativeadd is_Function is_Derivativeargs componentsis_Powbaser is_Integer is_Rationalrq)fxresultgs ^/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/integrals/heurisch.pyrUrU-s3,UFzz!} ;;1++ JJqM$ M#]]aooVV +*Q** + JJqM MXX j+ +F55##55$$JJqvvx15577';;< M j2aS88F MVV +*Q** + Mzdict[str, list[Dummy]]_symbols_cachec  t|}t||kr7|jt d|t|fzt||kr7|d|S#t$rg}|t|<Y`wxYw)z*get vector of symbols local to this modulez%s%iN)raKeyErrorlenappendr )namenlsymss r__symbolsri`sx%t$ e*q. eFdCJ%778: e*q. !9 %$t%s AA,+A,Nc ddlm} m} t|}|j |s||zSt ||||||||| } t | ts| Sg} t| | D]} | | | gd|fz } | s| Stt| } g}| |D]} || | gd|fz }| Dcgc] }||vs| } }| s| St| dkDrTg}| D]>}|j|jDcgc]\}}t||c}}@| |d|f| z} g}| D]}t |j!||||||||| }t#|jDcgc]\}}t||c}}}t%|jDcgc]\}}t'||c}}}|t)|j!||}|j+||ft|dk(r't ||||||||| f|dddfg}t-|S|j+t ||||||||| dft-|S#t$rYwxYw#t$rYwxYwcc}wcc}}wcc}}wcc}}w)a A wrapper around the heurisch integration algorithm. Explanation =========== This method takes the result from heurisch and checks for poles in the denominator. For each of these poles, the integral is reevaluated, and the final integration result is given in terms of a Piecewise. Examples ======== >>> from sympy import cos, symbols >>> from sympy.integrals.heurisch import heurisch, heurisch_wrapper >>> n, x = symbols('n x') >>> heurisch(cos(n*x), x) sin(n*x)/n >>> heurisch_wrapper(cos(n*x), x) Piecewise((sin(n*x)/n, Ne(n, 0)), (x, True)) See Also ======== heurisch r)solvedenomsT)dictexcluderL)sympy.solvers.solversrkrlr rNheurisch isinstancerrNotImplementedErrorlistr>rdextenditemsrsubsr<r=rrJrer8)r[r\rewritehintsmappingsretries degree_offsetunnecessary_permutations _try_heurischrkrlresslnsdslns0seqssub_dictkeyvaluepairsexprcondgenerics r_heurisch_wrapperrns:4 A ::a=s 1a%7M+] I,;I1 +I7 I= II I)(I)c(eZdZdZdZdZdZdZy) BesselTablez~ Derivatives of Bessel functions of orders n and n-1 in terms of each other. See the docstring of DiffCache. cri|_td|_td|_|j y)Nrgz)tabler rgr _create_table)selfs r___init__zBesselTable.__init__s+ ss r`c|j|j|j}}}ttt t fD]@}||dz |||||z|z z |dz ||dz |z|z |||z f||<Bt}||dz |||||z|z z |dz ||dz |z|z |||zf||<t}||dz | ||||z|z z |dz ||dz |z|z |||z f||<ttfD]C}||dz ||dz|||z|z z |dz ||dz |z|z |||z f||<Ey)NrL) rrgrr(r)r,r-r*r+r.r/)trrgrr[s r_rzBesselTable._create_tablesggqssACC!q7GW5 5A!A#q Aa1gIaK/1a!Qi)AaG35E!H 5 ac1I!Aq' ! +qS!AaC)OA%!Q/1a qsAYJ1Q71,qS!AaC)OA%!Q/1ab 5A!A#q QqS!Aq'M!O31a!Qi)AaG35E!H 5r`c||jvrP|j|\}}|j|f|j|fg}|j||j|fSyN)rrgrrv)rr[rgrdiff0diff1repls r_diffszBesselTable.diffssZ <771:LE5SS!HqssAh'DJJt$ejj&67 7 r`c||jvSr)r)rr[s r_haszBesselTable.hassAGG|r`N)__name__ __module__ __qualname____doc__rrrrr`r_rrs 5"8 r`rceZdZdZdZdZy) DiffCacheau Store for derivatives of expressions. Explanation =========== The standard form of the derivative of a Bessel function of order n contains two Bessel functions of orders n-1 and n+1, respectively. Such forms cannot be used in parallel Risch algorithm, because there is a linear recurrence relation between the three functions while the algorithm expects that functions and derivatives are represented in terms of algebraically independent transcendentals. The solution is to take two of the functions, e.g., those of orders n and n-1, and to express the derivatives in terms of the pair. To guarantee that the proper form is used the two derivatives are cached as soon as one is encountered. Derivatives of other functions are also cached at no extra cost. All derivatives are with respect to the same variable `x`. cBi|_||_ts tayyr)cacher\ _bessel_tabler)rr\s r_rzDiffCache.__init__s! 'MMr`c|j}||vr ||St|drtj|js,t |j |j||<||S|j\}}tj|j||\}}|j|}||z||<||z||j |dz |<||S)NfuncrL) rhasattrrrrrCdiffr\rTrget_diff)rr[rrgrd0d1dzs r_rzDiffCache.get_diffs  : Qx!V$!!!&&)affTVVn-E!HQx 66DAq"((A6FBq!B"uE!H$&rEE!&&1a. !Qxr`N)rrrrrrrr`r_rrs,*r`rc N789:;<=>?@ABCt|}|dur>|jtttt t tttt ry|j|s||zS|js|j|\} }ntj} t t"t$ft&t(t*t,ft.i} |r+| j1D]\} } |j3| | }n(| j5D]} |j| snd}t7||} t9|}||st;d|g}t;d|g}t;d|g}t=| D]}|j>rotA|tBr|jDdjG|||zz}|H| jI|tC|||||zz|||||zzd||z ztK||d ztM|||||zzz||z zz ztA|tNs|jDdjG||d zz}|c||jPr*| jItStU|||zn*| jItWtU|| |z|jDdjG||d zz||zz|z}|||jPr}| jItUtXd z || ztO||||d zd ||zz z ztStU|||z||d tU||zz zzn||jZr~| jItUtXd z || ztO||||d zd ||zz z ztWtU|| |z||d tU|| zz z z|jDdjG|tM|d zz}|||jPrG| jItStU||tM|zd d tU||zz z||jZs5| jItWtU|| tM|zd d tU|| zz z |j\s|jNj^s|jNj`d k(s|jbjG||d zz|z}|||jPr~||jPr0| jItetU||||z |zn?||jZr0| jItgtU|| ||z |z|jbjG||d zz|z }|||jPs||jPrd tU|||d zz||z z }tMd tU||ztU|||d zz||z zd ||z|zztU||z 7||jh7<| jI7K||jZs\| jI|| d z tU|| ztktU|| |ztU|||d zz||z z zn| t=|z} t=| D] }| t7|jm||z} "tod tq| 8tstutstwtytw| 8Dcgc]}|dj|d |fc}d >>Dcic]\}}|| }}}|w>dd|k(sJ>j{dg}t}tr}>D]$}|\}}|t|j|&|Dcgc]}|| c}>>fd }|}n|xsg}>fd}|D]>ts>>>|z>| Dcgc]}||jm|}}|Dcgc]}|jd }}t8fd|Dsl||j8st8fd|=n|st||d||} | | | zSy|Dcgc]}t=|zc}?8?fd:89:fd98:stA|"t&rd|!d ||"d zz<2tA|"t.rd|!d ||"z<d|!d ||"z <_tA|"tspd|!||"<|||77j\}#}$<=}%<|$}&t=ts|&|%dgzts|!j5z}'|%dt|!j1Dcgc] \}}|s | c}}z}(|(|#|$fD)cgc]})|)j8}*})d|*vry|*D)cgc]})|)jc})\}}}|(|&dz9|&d zjA;fd;;||t||z},}+|+d kDr-|,d kDr(ttyt8|+|,zd z |z}-n$ttyt8|+|,z|z}-todtq|-@tt|-D.cgc] \}}.@||.zc}.}Bt=Cty|'D]:}/t|/g8\}0}1CjI|0Cjd|1D<d78:=@ABCfd }2td8Dr7jt=8z }3nR7j}4|4jttw8d8Dj|4jz}3|3s|2d}5|5|2}5n|2}5|5O|5j|}6t|6j}6|6jr|6j|d }6| |6zS|dk\rt||||||d z |} | | | zSycc}wcc}}wcc}wcc}wcc}wcc}wcc}}wcc})wcc})wcc}.}w)a- Compute indefinite integral using heuristic Risch algorithm. Explanation =========== This is a heuristic approach to indefinite integration in finite terms using the extended heuristic (parallel) Risch algorithm, based on Manuel Bronstein's "Poor Man's Integrator". The algorithm supports various classes of functions including transcendental elementary or special functions like Airy, Bessel, Whittaker and Lambert. Note that this algorithm is not a decision procedure. If it isn't able to compute the antiderivative for a given function, then this is not a proof that such a functions does not exist. One should use recursive Risch algorithm in such case. It's an open question if this algorithm can be made a full decision procedure. This is an internal integrator procedure. You should use top level 'integrate' function in most cases, as this procedure needs some preprocessing steps and otherwise may fail. Specification ============= heurisch(f, x, rewrite=False, hints=None) where f : expression x : symbol rewrite -> force rewrite 'f' in terms of 'tan' and 'tanh' hints -> a list of functions that may appear in anti-derivate - hints = None --> no suggestions at all - hints = [ ] --> try to figure out - hints = [f1, ..., fn] --> we know better Examples ======== >>> from sympy import tan >>> from sympy.integrals.heurisch import heurisch >>> from sympy.abc import x, y >>> heurisch(y*tan(x), x) y*log(tan(x)**2 + 1)/2 See Manuel Bronstein's "Poor Man's Integrator": References ========== .. [1] https://www-sop.inria.fr/cafe/Manuel.Bronstein/pmint/index.html For more information on the implemented algorithm refer to: .. [2] K. Geddes, L. Stefanus, On the Risch-Norman Integration Method and its Implementation in Maple, Proceedings of ISSAC'89, ACM Press, 212-217. .. [3] J. H. Davenport, On the Parallel Risch Algorithm (I), Proceedings of EUROCAM'82, LNCS 144, Springer, 144-157. .. [4] J. H. Davenport, On the Parallel Risch Algorithm (III): Use of Tangents, SIGSAM Bulletin 16 (1982), 3-6. .. [5] J. H. Davenport, B. M. Trager, On the Parallel Risch Algorithm (II), ACM Transactions on Mathematical Software 11 (1985), 356-362. See Also ======== sympy.integrals.integrals.Integral.doit sympy.integrals.integrals.Integral sympy.integrals.heurisch.components TNa)rnbcrrLr\c3KtD]&}|Dcgc]}t|D]}|c}}(ycc}}wwr)rr)ijmappings r__iter_mappingsz heurisch.._iter_mappingss?!'* 9"#8QWQZ8q8q88 98s ?9?c&|jSr)rv)rrs r_ _substitutezheurisch.._substitute syy!!r`c3<K|]}|jywr) is_polynomial).0hVs r_ zheurisch..s3qq"3sct||gSr)rA)prZrs r_zheurisch..sAq 1 r`)rwrxr|c ~ttDcgc]\}}||j|zc}}Scc}}wr)rzipr)rrvrnumerss r_ _derivationzheurisch.._derivations2FA@1a!&&)m@AA@s9 cD]}|j|s|tjus.|j|j \}}|t ||j |jzcS|Sr)rrZeroas_poly primitiver@ras_expr)ryrrZr _deflationrs r_rzheurisch.._deflation!sz AA5581~QVV+yy|--/1!!}SAFF1I%6%>%>%@@@  Ar`c 4D]}|j|s |tjus/|j|j \}}|j }t | ||}t|t ||j|||} |}|j|jdk(r|d||dzfcS t||z }|d|dz|z|d|dzfcStj|fS)NrrL) rrrrrrr@r?rdegreerCOne) rrrrZrrc_splitq_splitrr _splitters r_rzheurisch.._splitter,s  HA5581~QVV+yy|--/1IIK;q>1-3q!&&)Q/3#A,99Q<&&(A-#AJGAJ77#F1q5M2 71:-a/GAJ1FGG' H*qzr`Fc|jr|jjr|jjdk7r|jjdkDr0|jj|jjzdz St |jj|jjzSy|j s*|jrtfd|jDSy)NrLrc3.K|] }|ywrr)rr _exponents r_rz.heurisch.._exponent..ns4y|4s) rVrrYrZrabsis_AtomrTmax)r^rs r_rzheurisch.._exponentds 88uu  QUUWW\5577Q;5577QUUWW,q00quuww011qvv4QVV44 4r`Ac3&K|] \}}| ywrr)rfactmuls r_rzheurisch..s894$8sc Ft}t}|dk(r t%}nit}t}t%D]F}|tt|z}t|D]}tt|||}||z}FHgg} } t|D]}t |t d} | j t tj} | s<| j tjtj} | jt s| jt r|j| | f|j||r|j\} } | | f|vr_|j| | f| jr| } |j| | z| | zz|jt| | z n|j| t | zz|rt!dt#|}t!dt#|}t%t't)t||D]C\}}|js"j+|| j+|t-|zEt%t't)t||D]:\}}|js"j+|| j+||z<$#z t/| zt/| z} |!z z }|j1d}t"tztfd |t3d \}}t7"|}t7|} |j9|}t=|j?|d }|y|jA|jAtCt)"tjgt#"zS#t4$rYywxYw#t:$rt4wxYw) NQ)filterF)evaluateBCrc|js |jry|vry|jsj|y|js|j s |j r tt|jytr) rXrYrNrQis_Addis_MulrVrsmaprTrD)r find_non_symsnon_symssymss r_rz3heurisch.._integrate..find_non_symssg$"2"2"T]]D) T" t{{S 23&%r`T)field)_raw)"rMrrrFr;rgetrrrrrQremovepopcould_extract_minus_signrrirdreversedrsrrerras_numer_denomrIrDrG from_expr ValueErrorrHcoeffsxreplacerm)&ratansr irreduciblessetVpolyzVrrlog_part atan_partmrr\rrrr candidater raw_numerground_ coeff_ringringnumersolutionrrrFrrdenom poly_coeffs poly_denom poly_part reducibless& @@@r_ _integratezheurisch.._integrates C<z?Lq6D5L + C T 233 ALq?@A A%L !")L) *Da%0Aa AEE!%%(558quuQx 1a&!##D) *99;DAqA2w% a!W%--/A  1qs+ $qs)$  QqS) S#l+ , S#e* % S)>%B CD /GD!txx|""1%CI . /  S%; <= +GD!txx|""1%  T* +j(3>9COK I&. .$$&q) ;#a&(5 & ? ) $)>IFAk62 :& "NN9-E!%H  %%h/88Sqvvhs;/?&?@AC C!   "! ! "sPP P  P P c3<K|]}t|tywr)rqr rrs r_rzheurisch..s ,Q:a ,sc30K|]}tywr)r rs r_rzheurisch..s,@UW,@sr)ryrwrxrzr|r)Yr rr0r1r2r3r9r:r6r7r4rNras_independentrrrrrrrrr!r rurwkeysrUrr rMrRrqr&rTmatchrQr'rr is_positiver%r#r$r is_negativerVrYrZrWr"rrrrrirdrsrrrrrtypererallis_rational_functionrrprCr5r r total_degreerrtuplerEr enumeraterBupdate free_symbolsas_dummyrrmrvexpand)Dr[r\rwrxryrzr{r|r}indep rewritables candidatesruletermsdcacherrrr^MdFkr rev_mappingtypesrerrrrrlr]specialtermPru_splitv_splitpolysrrpolifiedrrmonomsmonomialrcoefffactorsr more_freeFdr  antiderivr rrrrrr rrrrrrsD @@@@@@@@@@@@@r_rprp(s f  A D 55b"dIz5'3 O  ::a=s 88##A&q c3 tTDK  + 1 1 3 , J *d+A ,&**, Jquuj! G q! E q\F S1#&AS1#&AS1#&AZ: W==!!R(FF1IOOAadF3=!IIq"QqT!QqT'\*:ad1ad7lbQRSTQUg=VWY[\]^[_`a[acfghijgklmopqroslsgsctZtuvwxuyZyWz=z*z'{} $As+FF1IOOAadF3= t// % $tAaDz!|*< = % #dAaD5k!m*< =FF1IOOAadFQqSL1,<== t// % $r!tadU|*Q/Q*R+S!T!"1!1!1 % $r!tadU|*R.R*S+T!UFF1IOOAc!faiK8= t// % $tAaDz#a&/@1aQqT lCS/S*T U t// % #dAaD5k#a&.@1aaPQdU mCT.T*U VXXuu((QUUWW\FFLL1a4!4=QqT-=-= t// % %QqT!A$Y0A*B C!"1!1!1 % $tQqTE!A$J/?/A*B CFFLL1a4!4=QqT-=-= t//%&tAaDAI!,<'=%=$'$qt* T!A$q!t)ad:J5K(KaPQRSPTfUVh(V$WX\]^_`]aXb$b24 Q % ! !"1!1!1 % 1Q4%'$!u+*=+/adU A d1Q419qQRtCS>T0T+U+V!Ws: Wz SZ E Z3 FOOA.223 c%j!A8Dg14UA?A!A$  a  #Q '?'A"BCCDFGHG$+,DAq1a4,K,r{1~"""$+KKO#4 D! %ADAq $q'N ! !! $ %&++58+ 9"##;#Ar "w-44;@Ba+fooa01BB279Q1##%a(99 3F3 38[ A8[8[]^8_5v>E aD)ACF!V|#(- /1veAg /FB 0G2   $$49K-q001D$'16K--.16K--.D(+-1 D)*2 AA   DAqGlG W '!*.glln1EE FE S'--/@$!QQA@AAA)*Aq 31A3H3 x+34Q 4GAq!gaj.:gaj#99BBDJ  Q<SAYqA1uQw}QA M0IJKLw}QA 0EFGH3F ,K$V,/ Ax#1~h./0IJ9$T.A.wu8889 hChCT ,! ,,NNSV+ ZZ\KKS,@a,@%A BlR__- c?  !|H<MM+. 9%,,.   !003A6IY a<aXwe]dgh]hD\]F!V|#q @,,C90xA3 56/sB, s2( s7 s=t9t0t  t $t 6tt1t! )FNNrNN)n __future__r collectionsr functoolsr itertoolsrsympy.core.addrsympy.core.basicrsympy.core.mulr sympy.core.symbolr r r r sympy.core.numbersrrrsympy.core.relationalrrsympy.core.singletonrsympy.core.sortingrsympy.core.traversalrsympy.functionsrrrrrrrrrrr r!r"r#r$r%r&r'r(r)r*r+r,r-r.r/$sympy.functions.elementary.complexesr0r1r2r3r4&sympy.functions.elementary.exponentialr5#sympy.functions.elementary.integersr6r7$sympy.functions.elementary.piecewiser8'sympy.functions.special.delta_functionsr9r:sympy.simplify.radsimpr;sympy.logic.boolalgr<r=sympy.utilities.iterablesr> sympy.polysr?r@rArBrCrDsympy.polys.monomialsrEsympy.polys.polyrootsrFsympy.polys.ringsrGsympy.polys.solversrHsympy.polys.constructorrIsympy.integrals.integralsrJrUra__annotations__rirrrrrprr`r_r^s"#""11$..("&-???>>33>>44GG;>:I*'*KK/.&-4/,^*,&+ NO?C#'^@&&P ..`FG7;er`