K i' UdZddlmZddlmZmZmZmZddlm Z m Z ddl m Z ddl mZddlmZddlmZdd lmZdd lmZdd lmZdd lmZdd lmZddlmZddlm Z m!Z!m"Z"ddl#m$Z$ddl%m&Z&m'Z'm(Z(ddl)m*Z*ddl+m,Z,m-Z-m.Z.ddl/m0Z0ddl1m2Z2m3Z3ddl4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;mZ>ddl?m@Z@ddlAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZLmMZMmNZNddlOmPZPmQZQddlRmSZSmTZTmUZUmVZVmWZWmXZXmYZYmZZZm[Z[m\Z\ddl]m^Z^ddl_m`Z`maZaddlbmcZcmdZdmeZemfZfmgZgmhZhmiZimjZjmkZkddllmmZmd d!lnmoZodd"lpmqZqdd#lrmsZsdd$ltmuZumvZvmwZwmxZxdd%lymzZzdd&l{m|Z|dd'l}m~Z~dd(lmZmZmZmZdd)lmZdd*lmZe Gd+d,e Ze Gd-d.ee Ze Gd/d0eZe Gd1d2eZe Gd3d4eZe Gd5d6eZe Gd7d8eZe Gd9d:eZe Gd;deZe Gd?d@ee Ze GdAdBeZe GdCdDeZe GdEdFeZe GdGdHeZe GdIdJeZe GdKdLeZe GdMdNee Ze GdOdPeZe GdQdReZe GdSdTeZe GdUdVeZe GdWdXeZe GdYdZeZe Gd[d\eZe Gd]d^eZe Gd_d`eZe GdadbeZe GdcddeZe GdedfeZe GdgdheZe GdidjeZe GdkdleZe GdmdneZe GdodpeZe GdqdreZe GdsdteZe Gdudvee Ze GdwdxeZe GdydzeZe Gd{d|eZe Gd}d~eZe GddeZe GddeZe GddeZe GddeZe Gddee Ze GddeZe GddeZe GddeZe GddeZe GddeZe GddeZe GddeZe GddeZe GddeZe GddeZe GddeZe GddeZe GddeZGddeZdZdZeKeJeIeLeMeNfZdZdZdZdZdZdZdZdZdZgZded<gZe,dZdZddZddZdddZdZddZddZdZdZddZdZddZdddZddZedZed„ZedÄZedĄZedńZdƄZdDŽZedȄZedɄZedʄZed˄Zed̄Zed̈́Zed΄ZedτZedЄZedфZed҄ZedӄZedԄZedՄZedքZedׄZd؄ZdلZdڄZdۄZd܄Zd݄ZdބZdd߄ZdZeddZeddZeddZeddZdZdZdZ iZ ded<ee Z ded<e,dZ dZdZy)a/Integration method that emulates by-hand techniques. This module also provides functionality to get the steps used to evaluate a particular integral, in the ``integral_steps`` function. This will return nested ``Rule`` s representing the integration rules used. Each ``Rule`` class represents a (maybe parametrized) integration rule, e.g. ``SinRule`` for integrating ``sin(x)`` and ``ReciprocalSqrtQuadraticRule`` for integrating ``1/sqrt(a+b*x+c*x**2)``. The ``eval`` method returns the integration result. The ``manualintegrate`` function computes the integral by calling ``eval`` on the rule returned by ``integral_steps``. The integrator can be extended with new heuristics and evaluation techniques. To do so, extend the ``Rule`` class, implement ``eval`` method, then write a function that accepts an ``IntegralInfo`` object and returns either a ``Rule`` instance or ``None``. If the new technique requires a new match, add the key and call to the antiderivative function to integral_steps. To enable simple substitutions, add the match to find_substitutions. ) annotations) NamedTupleTypeCallableSequence)ABCabstractmethod) dataclass) defaultdict)Mapping)Add)cacheit)Dict)Expr) Derivative) fuzzy_not)Mul)IntegerNumberE)Pow)EqNeBoolean)S)DummySymbolWild)Abs)explog)HyperbolicFunctioncschcoshcothsechsinhtanhasinh)sqrt) Piecewise) TrigonometricFunctioncossintancotcscsecacosasinatanacotacscasec) Heaviside DiracDelta) erferfifresnelcfresnelsCiChiSiShiEili) uppergamma) elliptic_e elliptic_f) chebyshevt chebyshevulegendrehermitelaguerreassoc_laguerre gegenbauerjacobiOrthogonalPolynomial)polylog)Integral)And) primefactors)degreelcm_listgcd_listPoly)fraction)simplify)solve)switchdo_one null_safe condition)iterable)debugcFeZdZUded<ded<eddZed dZy) Ruler integrandrvariablecyNselfs e/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/integrals/manualintegrate.pyevalz Rule.evalM cyrhrirjs rlcontains_dont_knowzRule.contains_dont_knowQrnroNreturnrrsbool)__name__ __module__ __qualname____annotations__r rmrqrirorlrdrdHs3O    rordceZdZdZddZy) AtomicRulez1A simple rule that does not depend on other rulescy)NFrirjs rlrqzAtomicRule.contains_dont_knowYsroNrt)rvrwrx__doc__rqrirorlr{r{Vs ;ror{ceZdZdZddZy) ConstantRulezintegrate(a, x) -> a*xc4|j|jzSrh)rerfrjs rlrmzConstantRule.eval`s~~ --roNrrrvrwrxr}rmrirorlrr]s ".rorc@eZdZUdZded<ded<ded<d dZd dZy ) ConstantTimesRulez.integrate(a*f(x), x) -> a*integrate(f(x), x)rconstantotherrdsubstepcP|j|jjzSrh)rrrmrjs rlrmzConstantTimesRule.evalks}}t||00222roc6|jjSrhrrqrjs rlrqz$ConstantTimesRule.contains_dont_known||..00roNrrrtrvrwrxr}ryrmrqrirorlrrds8N K M31rorc.eZdZUdZded<ded<ddZy) PowerRulezintegrate(x**a, x)rbaser ct|j|jdzz|jdzz t|jdft |jdfSNrRT)r+rr rr!rjs rlrmzPowerRule.evalxsPii$((Q,'$((Q, 7DHHb9I J ^T "  roNrrrvrwrxr}ryrmrirorlrrrs J I rorc.eZdZUdZded<ded<ddZy) NestedPowRulezintegrate((x**a)**b, x)rrr c|j|jz}t||jdzz t |jdf|t |jzdfSr)rrer+r rr!)rkms rlrmzNestedPowRule.evalsU II &!txx!|,b2.>?c$))n,d35 5roNrrrrirorlrrs! J I5rorc,eZdZUdZded<ddZddZy) AddRulezDintegrate(f(x) + g(x), x) -> integrate(f(x), x) + integrate(g(x), x) list[Rule]substepsc4td|jDS)Nc3<K|]}|jywrh)rm.0rs rl zAddRule.eval..sAW\\^A)r rrjs rlrmz AddRule.evalsA4==ABBroc:td|jDS)Nc3<K|]}|jywrhrqrs rlrz-AddRule.contains_dont_know..sMG7--/Mr)anyrrjs rlrqzAddRule.contains_dont_knowsMt}}MMMroNrrrtrrirorlrrsNCNrorc@eZdZUdZded<ded<ded<d dZd d Zy ) URulez;integrate(f(g(x))*g'(x), x) -> integrate(f(u), u), u = g(x)ru_varru_funcrdrcP|jj}|jjrQ|jj \}}|dk(r/|j t |jt | }|j |j|jS)Nr)rrmris_Pow as_base_expsubsr!r)rkresultrexp_s rlrmz URule.evalsu""$ ;;  002JD$rzS_s4yjA{{4::t{{33roc6|jjSrhrrjs rlrqzURule.contains_dont_knowrroNrrrtrrirorlrrsE M L M41rorcJeZdZUdZded<ded<ded<ded <d d Zdd Zy ) PartsRulez@integrate(u(x)*v'(x), x) -> u(x)*v(x) - integrate(u'(x)*v(x), x)rurdvrdv_step Rule | None second_stepc|jJ|jj}|j|z|jjz Srh)rrrmr)rkvs rlrmzPartsRule.evalsH+++ KK   vvzD,,11333roc|jjxs*|jduxr|jjSrh)rrqrrjs rlrqzPartsRule.contains_dont_knows@{{--/T   D ( RT-=-=-P-P-R TroNrrrtrrirorlrrs%J I H L4 Trorc6eZdZUdZded<ded<d dZd dZy) CyclicPartsRulez9Apply PartsRule multiple times to integrate exp(x)*sin(x)zlist[PartsRule] parts_rulesr coefficientcg}d}|jD]@}|j||jz|jj z|dz}Bt |d|j z z S)NrRr)rappendrrrmr r)rkrsignrules rlrmzCyclicPartsRule.evalsl$$ D MM$-$++*:*:*<< = BJD F|q4#3#3344roc:td|jDS)Nc3<K|]}|jywrhrrs rlrz5CyclicPartsRule.contains_dont_know..sPG7--/Pr)rrrjs rlrqz"CyclicPartsRule.contains_dont_knowsPt?O?OPPProNrrrtrrirorlrrsC  5Qrorc eZdZy)TrigRuleNrvrwrxrirorlrrrorceZdZdZddZy)SinRulezintegrate(sin(x), x) -> -cos(x)c.t|j Srh)r-rfrjs rlrmz SinRule.evalDMM"""roNrrrrirorlrrs )#rorceZdZdZddZy)CosRulezintegrate(cos(x), x) -> sin(x)c,t|jSrh)r.rfrjs rlrmz CosRule.eval4==!!roNrrrrirorlrrs ("rorceZdZdZddZy) SecTanRulez%integrate(sec(x)*tan(x), x) -> sec(x)c,t|jSrh)r2rfrjs rlrmzSecTanRule.evalrroNrrrrirorlrrs /"rorceZdZdZddZy) CscCotRulez&integrate(csc(x)*cot(x), x) -> -csc(x)c.t|j Srh)r1rfrjs rlrmzCscCotRule.evalrroNrrrrirorlrrs 0#rorceZdZdZddZy)Sec2Rulez!integrate(sec(x)**2, x) -> tan(x)c,t|jSrh)r/rfrjs rlrmz Sec2Rule.evalrroNrrrrirorlrrs +"rorceZdZdZddZy)Csc2Rulez"integrate(csc(x)**2, x) -> -cot(x)c.t|j Srh)r0rfrjs rlrmz Csc2Rule.evalrroNrrrrirorlrrs ,#rorc eZdZy)HyperbolicRuleNrrirorlrrrrorceZdZdZddZy)SinhRulez integrate(sinh(x), x) -> cosh(x)c,t|jSrh)r$rfrjs rlrmz SinhRule.evalDMM""roNrrrrirorlrrs *#rorceZdZdZdZy)CoshRulez integrate(cosh(x), x) -> sinh(x)c,t|jSrh)r'rfrjs rlrmz CoshRule.eval rroNrrirorlrr s *#rorc.eZdZUdZded<ded<ddZy)ExpRulez integrate(a**x, x) -> a**x/ln(a)rrr cF|jt|jz Srh)rer!rrjs rlrmz ExpRule.evals~~DII..roNrrrrirorlrrs* J I/rorc$eZdZUdZded<ddZy)ReciprocalRulezintegrate(1/x, x) -> ln(x)rrc,t|jSrh)r!rrjs rlrmzReciprocalRule.eval s499~roNrrrrirorlrrs$ JrorceZdZdZddZy) ArcsinRulez'integrate(1/sqrt(1-x**2), x) -> asin(x)c,t|jSrh)r4rfrjs rlrmzArcsinRule.eval'rroNrrrrirorlrr$s 1#rorceZdZdZddZy) ArcsinhRulez'integrate(1/sqrt(1+x**2), x) -> asin(x)c,t|jSrh)r)rfrjs rlrmzArcsinhRule.eval.sT]]##roNrrrrirorlrr+s 1$rorc8eZdZUdZded<ded<ded<ddZy) ReciprocalSqrtQuadraticRulezWintegrate(1/sqrt(a+b*x+c*x**2), x) -> log(2*sqrt(c)*sqrt(a+b*x+c*x**2)+b+2*c*x)/sqrt(c)rabcc |j|j|j|jf\}}}}t dt |zt |||zz||dzzzz|zd|z|zzt |z S)N)rrrrfr!r*rkrrrxs rlrmz ReciprocalSqrtQuadraticRule.eval9stVVTVVTVVT]]: 1a1T!W9T!AaC%!Q$,//1!A#a%78a@@roNrrrrirorlrr2sa G G GArorcBeZdZUdZded<ded<ded<ded<d dZy ) SqrtQuadraticDenomRulez(integrate(poly(x)/sqrt(a+b*x+c*x**2), x)rrrrz list[Expr]coeffsc  |j|j|j|jj |j f\}}} g j t t dz D]g}t dz |z } |||zz }j| |dzxxd|zdz |zdz |zzcc< |dzxx|dz |z|zzcc<i d d}}t||zz|dzzz} |||zd|zz z } | dk(rd} n-ttd| z d} | | jz} tg fdt tD||z | z| zS) NrrRrrF degeneratec3RK|]}|tdz |z zz yw)rN)len)rir result_coeffsrs rlrz.SqrtQuadraticDenomRule.eval..^s49#1%a#f+a-/&::9s$')rrrrcopyrfrangerrr*inverse_trig_rule IntegralInformr )rkrrrrncoeffdesrI0steprrrs @@@rlrmzSqrtQuadraticDenomRule.evalFs!VVTVVTVVT[[5E5E5GV1a s6{1}% )AF A aA1IqsOE   ' 1Q3KAaCE19Q;u, ,K 1Q3KAaC75= (K  ) bz6":1 1Q3qAv QqS!A#Y; q=B$\!A#q%9eLD$))+%B?9#C $679?:;A#??@ACEF FroNrrrrirorlrr>s 2 G G G Frorc8eZdZUdZded<ded<ded<ddZy) SqrtQuadraticRulez integrate(sqrt(a+b*x+c*x**2), x)rrrrcxtt|j|jd}|j S)NFr)sqrt_quadratic_rulerrerfrm)rkrs rlrmzSqrtQuadraticRule.evalis*"< #N[`ayy{roNrrrrirorlrrbs* G G Grorc,eZdZUdZded<ddZddZy) AlternativeRulez Multiple ways to do integration.r alternativesc<|jdjSNr)rrmrjs rlrmzAlternativeRule.evalss  #((**roc:td|jDS)Nc3<K|]}|jywrhrrs rlrz5AlternativeRule.contains_dont_know..wsQG7--/Qr)rrrjs rlrqz"AlternativeRule.contains_dont_knowvsQt?P?PQQQroNrrrtrrirorlrrns*+Rrorc eZdZdZddZddZy) DontKnowRulezLeave the integral as is.cBt|j|jSrh)rSrerfrjs rlrmzDontKnowRule.eval}s 66rocyNTrirjs rlrqzDontKnowRule.contains_dont_knowsroNrrrt)rvrwrxr}rmrqrirorlrrzs#7rorceZdZdZddZy)DerivativeRulezintegrate(f'(x), x) -> f(x)ct|jtsJt|jj}t |D]#\}\}}||j k(s||dz f||<nt|jjg|SNrR) isinstancererlistvariable_count enumeraterfexpr)rkr&rvarcounts rlrmzDerivativeRule.evals$..*555dnn;;<(8 OA|Udmm#%(%!)$4q! $..--???roNrrrrirorlr!r!s %@ror!c6eZdZUdZded<ded<d dZd dZy) RewriteRulez;Rewrite integrand to another form that is easier to handle.r rewrittenrdrc6|jjSrh)rrmrjs rlrmzRewriteRule.evals||  ""roc6|jjSrhrrjs rlrqzRewriteRule.contains_dont_knowrroNrrrtrrirorlr,r,sEO M#1ror,ceZdZdZy)CompleteSquareRulez7Rewrite a+b*x+c*x**2 to a-b**2/(4*c) + c*(x+b/(2*c))**2N)rvrwrxr}rirorlr1r1sAror1c(eZdZUded<ddZddZy) PiecewiseRulez%Sequence[tuple[Rule, bool | Boolean]] subfunctionscxt|jDcgc]\}}|j|fc}}Scc}}wrh)r+r4rm)rkrconds rlrmzPiecewiseRule.evalsD040A0AC,w$LLND1CD DCs6 c:td|jDS)Nc3BK|]\}}|jywrhr)rr_s rlrz3PiecewiseRule.contains_dont_know..sTJGQ7--/Ts)rr4rjs rlrqz PiecewiseRule.contains_dont_knowsT$BSBSTTTroNrrrtrvrwrxryrmrqrirorlr3r3s77DUror3c<eZdZUded<ded<ded<d dZd dZy) HeavisideRulerhargibndrdrc|jj}t|j||j |j |j z zSrh)rrmr9r=rrfr>)rkrs rlrmzHeavisideRule.evalsB ""$#v DMM4990U'UVVroc6|jjSrhrrjs rlrqz HeavisideRule.contains_dont_knowrroNrrrtr:rirorlr<r<s J J MW1ror<c4eZdZUded<ded<ded<ddZy)DiracDeltaRulerr rrc|j|j|j|jf\}}}}|dk(rt |||zz|z St |||zz|dz |z SNrrR)r rrrfr9r:rkr rrrs rlrmzDiracDeltaRule.evalseVVTVVTVVT]]: 1a 6QqsU#A% %!AaC%1%a''roNrrrvrwrxryrmrirorlrBrBs G G G(rorBcPeZdZUded<ded<ded<ded<ded<d d Zd d Zy )TrigSubstitutionRulerthetafuncr-rdrzbool | Boolean restrictionc|j|j|j}}}|jt |dt |z }|jt |dt|z }|jt|dt|z }t|jt}t|dk(sJ|d}t||z |}t|dk(sJt|d\}}t!|tr'|}|} t#|dz|dzz } t%|d} n]t!|t r'|} |} t#|dz|dzz }t'|d} n&|}|} t#|dz|dzz} t)|d} t||| z ft || | z ft||| z f|| fg} t+|j,j/j| j1|j2fS)NrRrr)rIrJrfrr2r-r1r.r0r/r%findr,rr\rZr$r*r4r3r5r+rrmtrigsimprK) rkrIrJr trig_functionrelationnumerdenomopposite hypotenuseadjacentinverse substitutions rlrmzTrigSubstitutionRule.evalsTYY QtyyUQs5z\2yyUQs5z\2yyUQs5z\2TYY'<=> =!Q&&&%a( T=18}!!! , u mS )HJE1Huax/0H8A;'G  s +HJE1Huax/0H8A;'GHHeQh12J8A;'GZ*, - Z*, - Z(* + G   ""$)),7@@BDDTDTU  roc6|jjSrhrrjs rlrqz'TrigSubstitutionRule.contains_dont_knowrroNrrrtr:rirorlrHrHs' K JO M% N1rorHc8eZdZUdZded<ded<ded<ddZy) ArctanRulezAintegrate(a/(b*x**2+c), x) -> a/b / sqrt(c/b) * atan(x/sqrt(c/b))rrrrc|j|j|j|jf\}}}}||z t ||z z t |t ||z z zSrh)rrrrfr*r5rs rlrmzArctanRule.eval sTVVTVVTVVT]]: 1asT!A#YaQqS k!222roNrrrrirorlrZrZsK G G G3rorZceZdZUded<y)OrthogonalPolyRulerr Nrvrwrxryrirorlr]r]s Gror]c*eZdZUded<ded<ddZy) JacobiRulerrrc N|j|j|j|jf\}}}}t dt |dz|dz |dz |z||z|zz t ||z|zdf|t|df||zdz|dzzdz ||z |zdz zt|dfS)NrrRr)r rrrfr+rOrrrEs rlrmzJacobiRule.evalsVVTVVTVVT]]: 1a va!eQUAE1- -q1uqy 92a!eai;K L 1aM!eaiA a 1q5!)A+ -r!Qx 8: :roNrrrFrirorlr`r`s G G:ror`c eZdZUded<ddZy)GegenbauerRulerrc|j|j|j}}}tt |dz|dz |d|dz zz t |dft |dz||dzz t |dftjdfS)NrRrrT) r rrfr+rNrrHrZero)rkr rrs rlrmzGegenbauerRule.eval$s&&$&&$--a1 Aq1ua (!QU) 4bAh ? Aq !1q5 )2a9 5 VVTN roNrrrFrirorlrdrd s  GrordceZdZddZy)ChebyshevTRulec|j|j}}tt|dz||dzz t|dz ||dz z z dz t t |df|dzdz dfS)NrRrT)r rfr+rHrrrkr rs rlrmzChebyshevTRule.eval.s|vvt}}1Q"AE*Q"AE*+,-./1#a&!} > T!VTN roNrrrvrwrxrmrirorlrhrh,srorhceZdZddZy)ChebyshevURulec|j|j}}tt|dz||dzz t |dft j dfSr)r rfr+rHrrrfrjs rlrmzChebyshevURule.eval8sMvvt}}1 Aq !1q5 )2a9 5 VVTN roNrrrkrirorlrmrm6srormceZdZddZy) LegendreRulec|j|j}}t|dz|t|dz |z d|zdzz SNrRr)r rfrJrjs rlrmzLegendreRule.evalAsAvvt}}1Aq!HQUA$661qAAroNrrrkrirorlrprp?sBrorpceZdZddZy) HermiteRulecb|j|j}}t|dz|d|dzzz Srr)r rfrKrjs rlrmzHermiteRule.evalHs1vvt}}1q1ua !QU),,roNrrrkrirorlrtrtFs-rortceZdZddZy) LaguerreRulecj|j|j}}t||t|dz|z Sr#)r rfrLrjs rlrmzLaguerreRule.evalOs/vvt}}11~Q 222roNrrrkrirorlrwrwM3rorwc eZdZUded<ddZy)AssocLaguerreRulerrcft|jdz|jdz |j Sr#)rMr rrfrjs rlrmzAssocLaguerreRule.evalXs(tvvz466A:t}}EEEroNrrrFrirorlr{r{Ts  GFror{c"eZdZUded<ded<y)IRulerrrNr^rirorlr~r~\s  G Gror~ceZdZddZy)CiRulec|j|j|j}}}t|t ||zzt |t ||zzz Srh)rrrfr-r?r.rArkrrrs rlrmz CiRule.evaldF&&$&&$--a11vb1g~Ar!A#w..roNrrrkrirorlrrb/rorceZdZddZy)ChiRulec|j|j|j}}}t|t ||zzt |t ||zzzSrh)rrrfr$r@r'rBrs rlrmz ChiRule.evalkH&&$&&$--a1Aws1Q3x$q'#ac("222roNrrrkrirorlrriryrorceZdZddZy)EiRulec~|j|j|j}}}t|t ||zzSrh)rrrfr rCrs rlrmz EiRule.evalrs1&&$&&$--a11vb1g~roNrrrkrirorlrrpsrorceZdZddZy)SiRulec|j|j|j}}}t|t ||zzt |t ||zzzSrh)rrrfr.r?r-rArs rlrmz SiRule.evalyrroNrrrkrirorlrrwrrorceZdZddZy)ShiRulec|j|j|j}}}t|t ||zzt |t ||zzzSrh)rrrfr'r@r$rBrs rlrmz ShiRule.evalrroNrrrkrirorlrr~ryrorceZdZddZy)LiRulecr|j|j|j}}}t||z|z|z Srh)rrrfrDrs rlrmz LiRule.evals1&&$&&$--a1!A#'{1}roNrrrkrirorlrrsrorc4eZdZUded<ded<ded<ddZy)ErfRulerrrrc |j|j|j|jf\}}}}|jrt t tjt | z dz t||dzd|zz z ztd|z|z|z dt | zz z|dkft tjt |z dz t||dzd|zz z ztd|z|z|zdt |zz zdfSt tjt |z dz t||dzd|zz z ztd|z|z|zdt |zz zS)NrrbrrT) rrrrfis_extended_realr+r*rPir r;r<rs rlrmz ErfRule.evalshVVTVVTVVT]]: 1a  addD!H$Q&QAqs^)<<Aa!aaRj12345E;addDG#A%A1ac N(;;!A#a%!)aQi012379: : ADDz$q'!!#c!adAaCj.&99ac!eai!DG),-. .roNrrrFrirorlrrs G G G .rorc4eZdZUded<ded<ded<ddZy) FresnelCRulerrrrc |j|j|j|jf\}}}}t t j t d|zz t|dzd|zz |z td|z|z|zt d|zt j zz zt|dzd|zz |z td|z|z|zt d|zt j zz zzzSNrrb) rrrrfr*rrr-r=r.r>rs rlrmzFresnelCRule.evalVVTVVTVVT]]: 1aADDz$qs)# 1ac Q !A#a%!)T!A#add(^)C D D 1ac Q !A#a%!)T!A#add(^)C D D EF FroNrrrFrirorlrr G G GFrorc4eZdZUded<ded<ded<ddZy) FresnelSRulerrrrc |j|j|j|jf\}}}}t t j t d|zz t|dzd|zz |z td|z|z|zt d|zt j zz zt|dzd|zz |z td|z|z|zt d|zt j zz zz zSr) rrrrfr*rrr-r>r.r=rs rlrmzFresnelSRule.evalrroNrrrFrirorlrrrrorc*eZdZUded<ded<ddZy) PolylogRulerrrcbt|jdz|j|jzSr#)rQrrrfrjs rlrmzPolylogRule.evals$tvvz466DMM#9::roNrrrFrirorlrrs G G;rorc*eZdZUded<ded<ddZy)UpperGammaRulerrr c|j|j|j}}}||z| |z| zzt|dz| |zz|z Sr#)rr rfrE)rkrr rs rlrmzUpperGammaRule.evalsQ&&$&&$--a1!tr!trl"ZAr!t%<>roNrrrFrirorlrrs G G?rorc*eZdZUded<ded<ddZy) EllipticFRulerrr ct|j|j|jz t |jz Srh)rGrfr rr*rjs rlrmzEllipticFRule.eval,$--7TVV DDroNrrrFrirorlrr G GErorc*eZdZUded<ded<ddZy) EllipticERulerrr ct|j|j|jz t |jzSrh)rFrfr rr*rjs rlrmzEllipticERule.evalrroNrrrFrirorlrrrrorc"eZdZUded<ded<y)rrrersymbolNr^rirorlrrs O Nrorc>|jr|jd}t|tr |jt |dzzSt|t r!|j t |dzzSt|tr)|jt |zt|zSt|t r*|j t |zt |zSt|trtfd|jDSt|tr^t|jdk(rFt|jdtr)|jdt|jdzS|jS)aDerivative of f in form expected by find_substitutions SymPy's derivatives for some trig functions (like cot) are not in a form that works well with finding substitutions; this replaces the derivatives for those particular forms with something that works better. rrc36K|]}t|ywrh) manual_diffrargrs rlrzmanual_diff..sBC{3/BrR) argsr$r/diffr2r0r1r sumrrrr)frrs ` rlrrs; vvffQi a 88F#c#hk1 1 3 HHV$$s3x{2 2 3 88F#c#h.S9 9 3 HHV$$s3x/#c(: : 3 B166BB B 3 166{aJqvvay&$Avvay;qvvay&#AAA 66&>roct|dk(rB|d}t|ttfr|j }n3t |s(t dt|dk(r|g}n t dg}|D]Y\}t|ts|jd|jfdfd}|jtf[|jt||zS)zn A wrapper for `expr.subs(*args)` with additional logic for substitution of invertible functions. rRrz(Expected an iterable of (old, new) pairsrz$subs accepts either 1 or 2 argumentsc>|jxr|jk(Srh)rr)rx0s rlzmanual_subs..s!((*Cqvv|roc4t|jzSrh)r )rnews rlrzmanual_subs..s#aeeCi.ro)rr$rr itemsra ValueErrorr!rreplacerr rr%)r(rsequencenew_subsoldrrs @@rl manual_subsrs  4yA~7 hw 0~~'H(#GH H Ta6?@@H ,S c3  !B<< C(*D OORSN + , 99T(^h. //rocH g}fd}dfd } fd ttj |zD]X}|k(r t|}|||}|dus#|\} }|j k(r>|| |f} | |vsH|j | Z|S)Nc|dk(ry|z }tdj||t||j}|j ryj r[|j rJt fdjD}t fd|jD}||kDry|jdS)NrFz!substituted: {}, u: {}, u_var: {}c36K|]}t|ywrhrV)rtrs rlrz;find_substitutions..test_subterm..-sS1VAv.Src36K|]}t|ywrhr)rrrs rlrz;find_substitutions..test_subterm...sSF1e,Sr)as_Add) rbformatrcancelhas_freeis_rational_functionmaxas_numer_denomas_independent)ru_diff substituted deg_before deg_afterrerrs rl test_subtermz(find_substitutions..test_subterm"s Q;&(  188aOP!+q%8??A    '  ) )& 1k6V6VW\6]S 8P8P8RSSJSk6P6P6RSSI:%))%)>>rocfg}g}tddg}|jtD]\}|jd}|jvr!|j |z}|r|j ||L|j |^|r&|j tt|z|S)Nr c|jSrh) is_Integerr s rlrz:find_substitutions..exp_subterms..6s ALLro propertiesr)rrMr r free_symbolsmatchrrX)term linear_coeffstermsr rrrrs rl exp_subtermsz(find_substitutions..exp_subterms3s  "8!9 :IIcN #D))A,CS---IIah'E$$U1X. T" #  LLXm4V;< = roc t|ttgttt t r|jdgSt|tttttfr|jdgSt|ttfr|jdgSt|tr|jdgSt|t r=g}|jD]*}|j#||j%|,|St|t&r|jDcgc]}|j)s|}}|jj*r|j%t-|jDcgc]5}d|cxkrt/|jdkrnn|j0|z7c}|j0j2r;|j%|j0Dcgc]}|j4r|c}|St|t6r=g}|jD]*}|j#||j%|,|SgScc}wcc}wcc}w)NrrRr)r$r,r"inverse_trig_functionsr r!r9rrHrIrJrKrLrNrMrOrrextendrhasrrUabsris_Addrr )rrrrr rpossible_subtermsrs rlrz-find_substitutions..possible_subtermsDs d24F242 2"%2'02 3IIaL> ! z: '856IIaL> ! z>: ;IIaL> ! f %IIaL> ! c "AYY / *1-. /H c " $ =SWWV_=A=xx"" TXX0F2110s499Q<00))Q,2399##HH):499)E%A88 %&H c "Ayy 1 *3/0 1H >2%s'I>I<:I$2I)F)rr)r%dictfromkeysrrr) rerrresultsrrrr new_integrandrrWrs ``` @rlfind_substitutionsrsG?""!F$-- 1) <|I?V VW X - ; Q'$Q/  %&3 #Hm vu ==x7L7*|, - Nrocfd}|S)z$Strategy that rewrites an integrand.c|\}}tdj|||r9|}||k7r.t||}t|ts|rt ||||Syyyy)Nz/Integral: {} is rewritten with {} on symbol: {})rbrintegral_stepsr$rr,)integralrerr-rr`rewrites rl _rewriterzrewriter.._rewriterxs}$ 6 ?FFyRY[abc h *II%(F;!'<8W&y&)WMM>E8& rori)r`rrs`` rlrewriterrvsN rocfd}|S)zAStrategy that rewrites an integrand based on some other criteria.c |\}}|\}}tdj||||t|z}|r#|}||k7rt|||t ||Syy)Nz@Integral: {} is rewritten with {} on symbol: {} and criteria: {})rbrr%r,r)criteriarrerrr-r`rs rl_proxy_rewriterz'proxy_rewriter.._proxy_rewriters%($ 6 PWWXacjlrt|}~$x.( d II%"9fiPY[aAbcc& rori)r`rrs`` rlproxy_rewriterrsd rocfd}|S)z4Apply the rule that matches the condition, else NonecZjD]\}}||s||cSyrh)r)r(keyr conditionss rlmultiplexer_rlz#multiplexer..multiplexer_rls0#))+ "IC4yDz! "rori)rrs` rl multiplexerrs" rocfd}|S)zHStrategy that makes an AlternativeRule out of multiple possible results.cg}d}tdD]Z}|dz}tdj||||}|s.t|tr?||k7sE||vsJ|j |\t |dk(r|dS|r<|Dcgc]}|j r|}}|r tg||Stg||Sycc}w)NrzList of Alternative RulesrR Rule {}: {})rbrr$rrrrqr)raltsr*rrdoableruless rl _alternativesz#alternatives.._alternativess )* $DAIE -&&ud3 4(^Fz&,?("vT'9 F# $ t9>7N '+Mt43J3J3LdMFM&99&99&77$77 Ms CCri)rrs` rlrrs8( roct|Srh)rrs rl constant_ruler  ""roc |\}}|j\}}||jvr Iv)..#V,y&!Y^^A->??-roctttttt t ttttttttti}tdtdtdi}|\}|D]p}t!||s|j#|d}|j$|us4t'fd|j$d|DrV|||g|j$d|cSy)NrrrRc3@K|]}|jywrhr)rrrs rlrz'orthogonal_poly_rule..sFaAEE&MF)rOr`rNrdrHrhrIrmrJrprKrtrLrwrMr{r$getrr)rorthogonal_poly_classesorthogonal_poly_var_indexreklass var_indexrs @rlorthogonal_poly_ruler$s NNN,,)   A!  !Iv(j i '155eQ?Iy)V3F9>>*9+EFF9259)Viinn]g^gNhii jroz/list[tuple[Type, Expr, Callable | None, tuple]]_special_function_patternsrc|\}}tsftdtgdg}tdtg}tdtg}tdtgdg}td tgd g}tj |||||f|tz|z}|td zz|tzz|z} tj t t |d tz dtft t|d tz dtft t|d tz dtft t|d tz dtft t|d tz dtft dt#|d z dt$ft t | d dt&ftt| d dt(ftt| d dt*ft t|zt |tzd zdt,ft t/||tzd tz dt0ft dt3||ttd d zzz z dt4ft t3||ttd d zzz dt6ff |j9|t} tD]S\} } } }t;| | s| j=| s)t?fdtD}| | |sI|||g|cSy)Nrc|j Srhrrs rlrz'special_function_rule.. 199}roexcluderrr,rr c|j Srhr(r)s rlrz'special_function_rule..r*ror c8|jxr |j Srh)is_nonnegative is_integerr)s rlrz'special_function_rule..s1++< =rorFevaluaterRc ||k7Srhrirr s rlrz'special_function_rule.. Q!Vroc ||k7Srhrir5s rlrz'special_function_rule.. r6roc3bK|]&}j|j|(ywrh)r)rwrs rlrz(special_function_rule..s."?1%*YYq\%=#())A,"?s,/) r%r_symbol_wildsrrr rr-rr$rr.rr'rrr!rrrrrrQrr*rrrr$rtuple)rrerrrrr r linear_patternquadratic_pattern _integrandtype_pattern constraintr wild_valsrs @rlspecial_function_rulerDs Iv % wi5L4M N wi ( wi ( wi5L4M N wi =5? @ q!Q1o&7QgqjL1W94q8")) #nu5g=tV L #nu5g=tV L $~6w>g N #nu5g=tV L $~6w>g N !C77v F #'%8$ H #'%8$ M #'%8$ M '1*S7U;;T> R '!QwY7?{ S !DQs7U;Q>>>??#] 4 $q1S591<<<=#] 4+  "0J,F?(w D j% ($$W-E!"?"?? %Y)? 6>I>>?roch||St|tr2|jDcgc]\}}|||zjf}}}n||fg}t|tr||jz }n!|j |t j ft|j|j|Scc}}wrh) r$r3r4r[rrtruererf) generic_cond generic_stepdegenerate_steprr6r4s rl_add_degenerate_steprJs, .-9-F-FH)GT!4,#6"@"@"BCH H&|45 /=1444 _aff56 //1F1F UUHsB.c |\} td gtd dg  zz tj Gddtd fd  |\}} tjurd}nt |j d }t | ||}t ||S#$rYywxYw) Nrr-rrc eZdZy) nested_pow_rule..NoMatchNrrirorlNoMatchrM/s rorNc|js tjtjfS|jr|j \}}|s tjtjfS|Dcgc] } | }}|Dchc]\}}| }}}|j tjt|dk(r|jtd|DfS |jr=|j|j}}|jr  |\}} || |zfS|j} | r0| | }} | |z z}t|d|tjfS cc}wcc}}w)NrRc3&K|] \}}| ywrhri)rr9r s rlrz9nested_pow_rule.._get_base_exp..=s)@1!)@sr)rrOnerfis_Mul as_coeff_muldiscardrpopr rrr rr)r(r9rrrrbasesr base_sub_exprrrN _get_base_expa_b_rGrArs rlrYz&nested_pow_rule.._get_base_exp2sT}}Q55!&&= ;;((*HAuuuaff}$7<=t}T*=G=#*+41aQ+E+ MM!%% 5zQyy{C)@)@$AAAM ;;99dhhqAzz!} *1-NE7'A+% % 7# 9eBiqA!GEa8L!%%<  '>+s 8E9 E>)r(rrsztuple[Expr, Expr])rrrF ExceptionrrrrJ) rrerrrIrHrNrYrZr[rGrArs @@@@@@@rlnested_pow_ruler]&sLIq cA3 B cAq6 "BAgG66L ) 8"9- dqvv'y~~a';Q? AtT:L  lO LL s B55B=<B=c|\j\}}tdg}tdg}tddg}|j||zz|dzzz}|syd fd }|||fD cgc]"} |j| tj $c} \}}}t |d} |r| tjurd} n:|jrt||z} ntt||zz|z} td|zd zdk(r| d|zz ||dzd |zz z } } t | d}d}|tjur4td t|| z dzzz | z tj}|tj ur|St#|||}t%|||}| j&r|j&rg}t(| d | d | ft+| dkD|dkft,| d |d | ft+| dkD|dkDffD]G\}}|tjur||cS|tj us2|j/|||fI|r;| j0s!|j/|tjft3|}n|}t%| || S|tj4k(rt7|||}t%| || Sycc} w) zm Set degenerate=False on recursive call where coefficient of quadratic term is assumed non-zero. rr-rrrrNcltd}dt||z||z|z dzzzz }t||z |z z}dt|z } d} |ur|} |}dt|||dzzzz } || |} | dk7rt| | z| | | } | t||| | } |dk7rt || } | S)NrrRrr)rr*rrr1) RuleClassrsign_arsign_chrr-quadratic_baserr standard_formrrers rlmake_inverse_trigz,inverse_trig_rule..make_inverse_trigjsc d6!8fQhq1}&<<== acF1H-T!W9  '#F"N$v~q/@(@@AA M>: q='(>R_ahiG  IvufgFG 6(FIwOGrorRrbr)rsrd)rrrrrrfrrFrrsqrt_linear_rulerr[rr* NegativeOnefalserrJis_realrrTrr is_positiver3Halfr)rrrr rrrrrfrrGrIrcknon_square_cond square_steprHrrrr6rers @@rlrr[s !Iv%%'ID# S6(#A S6(#A S61+&A JJq1V8|a k1 2E &/0AY7uyyAFF#7GAq!a8L / &qCx8*<QZC8OQW+XY# ar1Q3xQT1Q3Z1Q( !&& ('$q&(Q*?(?PQSTS`S`aK agg % 29faAN #O\;O 99EaQBA.AE1q50ABq!Q1-s1q5!a%/@A C d166>,d33qww&LL"3T":D!AB C}}LL,!78$Y>##L$HH aff} FAq!<#L$HHK8s7'Kc|\}}|jDcgc]}t||}}d|vrdSt|||Scc}wrh)as_ordered_termsrr)rrergrs rladd_rulerssX Iv 1135a(5G57?4K 67(KK5sAc||\}}|j|\}}|dk7rt||}|t|||||Syyr#)rrr)rrerr r next_steps rlmul_rulervsX Iv''/HE1 z"1f-  $Yq)L L !rocfd}d d}|t|t||tt|tg}t d}t |tgtr||z}t|D]\}}||}|s|\} } | jvr| j|sy| j|d} | j|d} ||k(r| jsyt | tr'd| z } | jrt| dk(ry||k(ry| js%| jtst | trHt!| } | j#ry| j%} | j'}| | || | fcSd}|dkrd}np||k(r+| j(rt+d| j(Drd}n@||dzdD]5}||}|s|d j|dj-| s3d}n|s| j%} t!t/| } | j#r| j'}| | || | fcSy) Nc"|jj}t|ts |jsgn+|j Dcgc]}|j s|c}}|rt|}||z j}||fSycc}wrh)rtogetherr$r+rRris_algebraic_exprr)rer algebraicrrrs rlpull_out_algebraicz'_parts_rule..pull_out_algebraics$$&//1 %i;9CSCSR!*Q#33H3H3P#Q  YAa-'')Bb5L Rs B #B cdfd }|S)NctfdDrAjDcgc]tfdDr}}|rt|}|z }||fSycc}w)Nc3@K|]}j|ywrhrrrres rlrzI_parts_rule..pull_out_u..pull_out_u_rl..s79==#7rc36K|]}t|ywrh)r$)rclsrs rlrzI_parts_rule..pull_out_u..pull_out_u_rl..sIz#s3Ir)rrr)rerrrr functionss`` rl pull_out_u_rlz6_parts_rule..pull_out_u..pull_out_u_rlsi7Y77'0~~KIyIIKKT A"QBb5L KsA)rerrsztuple[Expr, Expr] | Noneri)rrs` rl pull_out_uz_parts_rule..pull_out_us ro temporaryrRFrTc3RK|]}t|tttf!ywrh)r$r.r-r )rrs rlrz_parts_rule..s%"q3S/2"s%'r)rsz*Callable[[Expr], tuple[Expr, Expr] | None])r!rr.r-r rr$r'rrr is_polynomialrV is_Derivativer,rPrrqrrmrallequalsr[)rerr|r liate_rulesdummyindexrrrrrec_dvrduracceptlrulers ` rl _parts_rulers` c?J0F$G%z#s';c?$K + E)c;$:;<I%  -70 ti EArQ^^+AEE%Lua A"B))!//&2I!S!2((066*a/))##rvv.C'D"2';<+B7F002#VVF^"KKM "aV33Fqy,,"""!F(4Ei(AQqTYYua077;!%  VVF^' f=002 Ab!R//o70p rocZ|\}|j\}}t|}g}|r|\}}}}} tdj||||| |j |t |t ryt |tttttfr5|jti} t| dkDryt| xxdz cc<tdD]} tdj| |||||z|z j!} | dk(rn‰| j"vrdt%||D cgc]\}}}}} t'dd||| dc} }}}}dt)|z| z} |dk7r| rt+||z||| } | cS||zj\}}t|}|r)|\}}}}} ||z}||z}|j ||||| fnfd|rC|d\}}}}} t'|||| |dd||z} |dk7r| rt+||z||| } | Sycc} }}}}w) Nz,u : {}, dv : {}, v : {}, du : {}, v_step: {}rrRrbz7Cyclic integration {} with v: {}, du: {}, integrand: {}rc p|r(|d\}}}}}t|||||dd||zSt|SrD)rr) stepsrerrrrrmake_second_steprs rlrz$parts_rule..make_second_stepIsU #(8 Ar1b&Y2v?OPUVWVXPY[\_a[a?bc ci00ror) as_coeff_Mulrrbrrr$rSr.r-r r'r$xreplace _cache_dummy_parts_u_cacherrrrrrr)rrerrrrrrrrcachekeyr9rr next_constantnext_integrandrrs @@rl parts_rulers Iv#002Hi F +F E %2q"f <CCAr1bRXYZ V a "  a#sCt4 5zz6<"89Hh'!+ 8 $ ) $q A KRRSTVWY[]fg hFi/779Ka[555&y&38::/!RBtT1b&$?:CJ&46Mt,X -A68U^`deD ./V,A,A,C )M> 8F'-$2q"f]"m# aQF341 41  $Qx2q"fFAr6;KERSRTIWX[]W];^_ Mt$X %968YX\]D  3:s3H$c j|\}}|t|k(r t||S|t|k(r t||S|t |dzk(r t ||S|t |dzk(r t||St|tr&t|jt|jz }nt|tr&t|jt|jz }nt|trN|jd}t |dzt|t |zzt |t|zz }n_t|t rN|jd}t |dzt|t |zzt |t|zz }nyt|||t||SNrr)r.rr-rr2rr1rr$r/rr0r,r)rrerr-rs rl trig_rulerWsy IvCKy&))CKy&))CKN" 6**CKN" 6**)S!(3 +?? Is #(3 +?? Is #nnQ#hkCHs3x$77#hS)+ Is #nnQ#hkCHs3x$77#hS)+   y&)^Iv5V WWroc|\}}|t|t|zk(r t||S|t|t |zk(r t ||Syrh)r2r/rr1r0rrs rltrig_product_rulerssU IvCK#f+--)V,,CK#f+--)V,,.roc |\}}td|g}td|g}td|g}|j|||dzz|zz }|r}||||||}}}t|||||}|jr |jr||z dkD}|tj ur|S|dt | zt |zz } t | |z } d|| z z } d|| zz } t| ||| z t| |d| t| ||| zg} | | z x}}t||| }| dk7rt| |d }t||| ||}t||||}|tjur|St||||f|tj fgSt|||d }|dk7rt||d|z |d z|}t|||t|df|d fgStd |g}|j|||dzz||zz|zz }|rf||||}}|j ryt#d}||d|zz z}|j%|||d|zz z }t'||}|rt)|||||Sytd|g}|j||z|z||dzz||zz|zz }|r||||||||||f\}}}}}|j ry||dzz||zz|z}|d|zz }d|z|z|z}| |z|z}t#d}t)||||t'|dz|}|dk7rt||z|z ||||z |}|j r|St'||z |}t||||g} ||z|z ||z z}!t|||!| Sy)Nrr-rrrrrRrFr2rTr rr )rrrZrrrFr*rrrrr,rir3rrrrrrr)"rrerrrrr general_rule positive_condr rr1r2 log_stepsr-sub negative_steppowerr match2rr integrand2rur match3 denominatorconstnumer1numer2step1step2rrewritens" rlquadratic_denom_ruler{s; Iv S6(#A S6(#A S6(#A OOAVq[1!45 6E (E!HeAha1!)VQ1=  !"4"4aC!GM&##qqbz$q')*EQBqDzHF8O$BF8O$B'FF8OD*B3BrSY[abj[j@klnI 2g %I#C;MzsU; 1)VUCQ^ _ ' 69mTM'$$ FlM5RUbdedjdjTk4lm m)VVR8 6%i1fbj%PEY,1a1IESW=0YZZ S6(#A __Q!fk/AJ">"BC DF q 6!91 99  #J!QqS'!^^FAQqS M: ":q1 VQ B B  S6(#A __ai!mFaK!f*0Lq0PQ RF q 6!9fQiF1IM 1aA 99 &!)ma&j014 AaCQ3v:a<Q #JinQWa&@B A:%eFl;&>&+VK-?HE >>Lvk16:9fuen=< +F;,>>9fhAA roc |\}}td|g}td|dg}dx}}ggg} }}|jtD]} | j| j} } | j s|| j vr6| jsy| j|||zz} | s^| || |}}||z||zk7s||z jsy|dk(s||z dkDtjur||}}|j| | j||j| j|dk(ryt|}|||zzd|z z}td}|j!t#|| |D cic]=\} }}| tj$|z z||z tj$|z z|||z zz?c}}} j!|||z|z |z }t'|||dz zz|z|z |}|j)st+|||||}t-|d}|tjurR|j!t.j1| d}t'||}t3||||f|tjfg}|Sycc}}} w)z* Substitute common (a+b*x)**(1/n) rr-rrNrRr)rrMrrr rr is_Rationalrr0rrFrqrWrrziprQrrqrrrrr3)rrerrra0b0rVqsbspow_rrra1b1q0u_xrrrrrrG simplifiedrIs rlrgrgsLIq S1#A S1a&!AKBBr2Es#YYd ??at'8'88   1QqS5! q58B b5BrE>"R%!7!7  7r"uqyQVV+B T "  $&&!" Qw2,B 19" C c A..47r24F"H"H&0dAq#'q/AbDAEE!G3DQAY3N"N"HIIMaRSUWRWXZRZ\^Q^I_[RT225b8!.s (Arorrc $tzzdzzz}|j}|dkr>|dk(r|jntj|j f\}}|dzz }||zz }dzzz|z }d} d} |dk7rit d} tdt| z | | tj } t|| zzdzzz| } |dk7rt||z||| } |dk7r4ttd|z d} |dk7rt||z |d|z | } | r3| r1t||z||z d} t|| t| | | g}|S| xs| }|S|j}t!||}|S)NrrRrrFrr2)r*rV all_coeffsrrfas_exprrrrlrrrrr r,rr) numer_polyrerRdegr r ABpre_substitute constant_step linear_steprpow_ruleaddrrrrrrs rlsqrt_quadratic_denom_rulez6sqrt_quadratic_rule..sqrt_quadratic_denom_rule sQqsU1QT6\"! !8.1Qh:((*QVVZEWEWEY#NAq!AaC%!Q$,Q 6"3An4DaN\g"hKAv 1,qw2JW\ ] 6$5agq!QuWm$\M}!N*AeGeD$/ 1c73PQT_anSoCp$q  #3m  **,F))Q1aHD rorRr)rrYrer)rrr*as_polyrrrFrrrgrrr,rJ)rrrerr rf_polyrGrIrrr-rrHrrrrs @@@@rlrrsLIq S1#A S1#A S1a&!A S A SABCA OOAd1QqS51a4<0!33 4E !HeAha%(E!HDMAq!Q YYq\F ~a8L / (47A:q9*<$q1u+q.8H!+LM@ 1uq1uQq!tV|!Qw77 &&(a!eAadFl);; +J B"9aGD b0C   lO LLroc|\}}t|tr|jd|k(r|jtk(r t ||S|jt k(r t||Std}|jtk(rIt |t |z }t|||t|||t |td|z ||S|jtk(rIt |t |z }t|||t|||t |td|z ||S|jt}|jtk(rbt|||t|||t|dz t!d|dzdzz |t#dt"j$t"j$S|jt&k(r5t|||t|||t|dz td|z ||Syyy)NrrrRr)r$r"rrJr'rr$rrr(r,rrr%rr&rZrrQr#)rrerrr-s rlhyperbolic_ruler7s Iv)/0Y^^A5F&5P >>T !Iv. . >>T !Iv. . #J >>T !V T&\1Iy&)FAtF|^AaCQRTU=VWY Y >>T !V T&\1Iy&)FAtF|^AaCQRTU=VWY Y"))$/I~~%"9fiY4q>!!QTAX,1Q4FHII~~%"9fiY4q>%ac1a0233&)6Q0roctd|g}td|g}td|gdg}td|gdg}||||fS) Nrr-rrc"t|tSrhr$rrs rlrzmake_wilds..V *Q:Pror+r c"t|tSrhrrs rlrzmake_wilds..Wrro)r)rrrrr s rl make_wildsrRsT S6(#A S6(#A S6(0P/QRA S6(0P/QRA aA:rocvt|\}}}}t||z|zt||z|zz}|||||fSrh)rr.r-rrrrr rAs rlsincos_patternr[IF#JAq!Q!F(mQQvX!11G Aq!Q rocvt|\}}}}t||z|zt||z|zz}|||||fSrh)rr/r2rs rltansec_patternrbrrocvt|\}}}}t||z|zt||z|zz}|||||fSrh)rr0r1rs rlcotcsc_patternrirroctd|g}td|g}td}t||z|z|z}||||fS)Nrr-rrr)rr9)rrrrrrAs rlheaviside_patternrpsM S6(#A S6(#A S A&1 %)G Aq! rocfd}|S)Nc|Srhri)rrJs rl uncurry_rlzuncurry..uncurry_rlzs T{rori)rJrs` rluncurryrys rocfd}|S)Nc l|\}}}}}}||||||}||k7rt|||t||Syrh)r,r) rrrrr rerr-rs rltrig_rewriter_rlz'trig_rewriter..trig_rewriter_rlsO(,%1aIvAq!Q 6:  !y&)^IW]=^_ _ "rori)rrs` rl trig_rewriterr~s` rocn|jxr(|jxr|jxr |jSrh)is_evenr0rrrr rr s rlrrs4QYY*199**))rocxdtd|z|zz dz |dz zdtd|z|zzdz |dz zzSrr)r-rrrr rrs rlrrsMq3qs6z?':a&?QU%K'(3qs6z?':a&?QU%K%Mroc(|jxr|dk\SNrrrs rlrr188;NQroc~dt||zdzz |dz dz zt||zzt||z|zzSrr)r-r.rs rlrrJQQvX)9%9a!eq[$I$'&M%2$'&MQ$6%7roc(|jxr|dk\Srrrs rlrrrroc~dt||zdzz |dz dz zt||zzt||z|zzSrr)r.r-rs rlrrrroc(|jxr|dk\SNrbrrs rlrrAII. 09==  0r)rr.r-rrrsincos_botheven_conditionsincos_bothevensincos_sinodd_condition sincos_sinoddsincos_cosodd_condition sincos_cosoddr<rrrf rrrArrrr rrres @rltrig_sincos_rulers Iv 0c3Z 00,V4Aq!(  { % #] #]   ,-q!Q< 8aUYYq!&& ! 8    ! " " 1 9s'B8 c  |\ } jdt|z t|i t fdttfDrt |\}}}}} j |}|sytttttttit||||fDcgc]"}|j|t j"$c} |gzSycc}w)NrRc3@K|]}j|ywrhrrs rlrz#trig_tansec_rule..rr)rr-r2rr/rrrtansec_tanodd_condition tansec_tanoddtansec_seceven_conditiontansec_seceventan_tansquared_conditiontan_tansquaredr<rrrfrs @rltrig_tansec_ruler#s Iv CKV I 0c3Z 00,V4Aq!(  { #] $n $n   ,-q!Q< 8aUYYq!&& ! 8    ! " " 1 9s('C c $ |\ } jdt|z t|dt|z t |t |t|z t |i t fdttfDrt|\}}}}} j|}|sytttttit||||fDcgc]"}|j|t j"$c} |gzSycc}w)NrRc3@K|]}j|ywrhrrs rlrz#trig_cotcsc_rule..rr)rr.r1r/r0r-rrrrcotcsc_cotodd_condition cotcsc_cotoddcotcsc_csceven_conditioncotcsc_cscevenr<rrrfrs @rltrig_cotcsc_ruler*s Iv CKV CKV F c&k!3v; I  0c3Z 00,V4Aq!(  { #] $n   ,-q!Q< 8aUYYq!&& ! 8    !" " 1 9s'D c|\}}tdtd|zg}|jtd|z|z}|r8dt|zt|ztd|zz }t ||z|Sy)Nrrr-)rr.rr-r)rrerrr sin_doubles rltrig_sindouble_ruler-sy Iv S3qx=/*A OOC&M!O ,E s6{]3v;.s1V8}< i*4f== roc ttttttttt |Srh)r^r_rr#r*r-rs rltrig_powers_products_ruler/s@ 26),-,-,-/0 23; <* IIa  IIa {{,q1u> {{,q1u> {{,q1u> {{,q1u>  *1gd1goU3FK JAwtQBx'HE *Ffy0&82CDK JQBxQ'HE *Ffy0&82CDK M33% A34U8 d1U8Q;/067%j d1U8b>23 A !~~ff5>>@H"8];H<<'K66#,,."--#e* 5'00#e* c%j2 H)59113/ 6vx+GGc2Groc|\}}t|\}}}}|j|}|r;d||k7r2t|||}||||}}t||||z|z| |z |Syyr)rrrr<) rrerrArrrrrrs rlheaviside_ruler?=s Iv(0GQ1 OOG $E eAh q62Qxq1Y&1 qbdGLL uroc|\}}t|jdk(rtj}n|jd}|jr|dkryt d|gt d|dg}}|jdj |||zz}|sy||||}}t|d}|tjurd}ntt|||}t|||||} t|| |S)NrRrrr-r) rrrrfrrrrrFrr:rBrJ) rrerr rrrrGrIrHs rldirac_delta_rulerAHsLIq 9>>a FF NN1  <<1q5 aS !4aV#roc$|j|Srh)apartrIs rlrrsioof5rocyrrirIs rlrrsroc"|jSrh)rrIs rlrri..0rocpt|ttfxstfd|jDS)Nc3\K|]#}|jxs|j%ywrh)rrrs rlrz..s*0s]`1Xs?P?PQW?X1X0ss),)r$rrrrrIs `rlrrs-9sCj)sS0sdmdrdr0s-sroc"|jSrhexpandrIs rlrrrNroct|jtDchc]}|jdc}dkDScc}wrD)ratomsr,r)rerrs rlrrs4 0E F G1QVVAY GH1L Gs=c&|jdS)NT)trigrRrIs rlrrsi..D.9roc|d}|j}|j}|j}|j|vr,|j|vrt |St ||jSt |Sr) variablesr(rrr!rr)rrediff_variablesundifferentiated_functionintegrand_variabless rlderivative_ruler]sl I((N )3@@-- ??n ,!8, , 8??; ;X&&roc |\}}|jdt|z r?|jdt|z t|}t |||t ||Syr#)rr-rr2r,r)rrerr-s rl rewrites_ruler_sZ IvqV}%NN1S[=#f+> 9fi SY9Z[[&roct|Srh)rrs rl fallback_rulerarrozdict[Expr, Expr | None]_integral_cachezdict[Expr, int]rzc h|jti}|tvr4t| t|St|jtfSdt|<t |}fdfd}t t tt ttt t tt tt tt ttttt t"t$t&t t t(t t*t t,t tt tt t.t0t2t4t6t8t,t:t<t>t@tBtDi t t t6t tFt tItJtLtO|t&ttPtO|t&ttRtO|t&tTgtVtXtO|t&ttZt\t^t tO|t&tt`t tbtd|}t|=|S)aReturns the steps needed to compute an integral. Explanation =========== This function attempts to mirror what a student would do by hand as closely as possible. SymPy Gamma uses this to provide a step-by-step explanation of an integral. The code it uses to format the results of this function can be found at https://github.com/sympy/sympy_gamma/blob/master/app/logic/intsteps.py. Examples ======== >>> from sympy import exp, sin >>> from sympy.integrals.manualintegrate import integral_steps >>> from sympy.abc import x >>> print(repr(integral_steps(exp(x) / (1 + exp(2 * x)), x))) # doctest: +NORMALIZE_WHITESPACE URule(integrand=exp(x)/(exp(2*x) + 1), variable=x, u_var=_u, u_func=exp(x), substep=ArctanRule(integrand=1/(_u**2 + 1), variable=_u, a=1, b=1, c=1)) >>> print(repr(integral_steps(sin(x), x))) # doctest: +NORMALIZE_WHITESPACE SinRule(integrand=sin(x), variable=x) >>> print(repr(integral_steps((x**2 + 3)**2, x))) # doctest: +NORMALIZE_WHITESPACE RewriteRule(integrand=(x**2 + 3)**2, variable=x, rewritten=x**4 + 6*x**2 + 9, substep=AddRule(integrand=x**4 + 6*x**2 + 9, variable=x, substeps=[PowerRule(integrand=x**4, variable=x, base=x, exp=4), ConstantTimesRule(integrand=6*x**2, variable=x, constant=6, other=x**2, substep=PowerRule(integrand=x**2, variable=x, base=x, exp=2)), ConstantRule(integrand=9, variable=x)])) Returns ======= rule : Rule The first step; most rules have substeps that must also be considered. These substeps can be evaluated using ``manualintegrate`` to obtain a result. Nc|j}|jvrtSttt fD]}t ||s|cSt|Srh)rerrrr,rPr$type)rrerrs rlrzintegral_steps..keysT&& // /M13GH C)S)  Irocfd}|S)Nc4|}|xr t|Srh) issubclass)rrmrklassess rl_integral_is_subclasszKintegral_steps..integral_is_subclass.._integral_is_subclass sH A/Aw/ /rori)rjrkrs` rlintegral_is_subclassz,integral_steps..integral_is_subclass s 0%$ro)3rrrbrrr^r_rDr]rrrrgrrr rr rsrrvrr?rrr]r,rr9r:rArPr$rrrrr_rGr`partial_fractions_rule cancel_ruler!rrdistribute_expand_ruler/trig_expand_ruler]r=ra)reroptionsrrrlrrs ` @rlrrs&Z!!6<"89H?" 8 $ , 62 2$H-66|VL %)!Iv.H% -V'(&  *-y9J/K!"23!"679 J    (+Y7H-I!.19=Q3R!"23!"568  !9 ~ ( "6 M!   $  i o & l!(c2*,(c2!(c-+- (c2*,* # & i 4S# >P Q , -/ 2 [-Z [-!F\ ! Mroct||j}tjt |t rt |jdk(r}|jdd}t |tr[|jdddk(rF|j|jddt|jf|jdddf}|S)a$manualintegrate(f, var) Explanation =========== Compute indefinite integral of a single variable using an algorithm that resembles what a student would do by hand. Unlike :func:`~.integrate`, var can only be a single symbol. Examples ======== >>> from sympy import sin, cos, tan, exp, log, integrate >>> from sympy.integrals.manualintegrate import manualintegrate >>> from sympy.abc import x >>> manualintegrate(1 / x, x) log(x) >>> integrate(1/x) log(x) >>> manualintegrate(log(x), x) x*log(x) - x >>> integrate(log(x)) x*log(x) - x >>> manualintegrate(exp(x) / (1 + exp(2 * x)), x) atan(exp(x)) >>> integrate(exp(x) / (1 + exp(2 * x))) RootSum(4*_z**2 + 1, Lambda(_i, _i*log(2*_i + exp(x)))) >>> manualintegrate(cos(x)**4 * sin(x), x) -cos(x)**5/5 >>> integrate(cos(x)**4 * sin(x), x) -cos(x)**5/5 >>> manualintegrate(cos(x)**4 * sin(x)**3, x) cos(x)**7/7 - cos(x)**5/5 >>> integrate(cos(x)**4 * sin(x)**3, x) cos(x)**7/7 - cos(x)**5/5 >>> manualintegrate(tan(x), x) -log(cos(x)) >>> integrate(tan(x), x) -log(cos(x)) See Also ======== sympy.integrals.integrals.integrate sympy.integrals.integrals.Integral.doit sympy.integrals.integrals.Integral rrrRT) rrmrclearr$r+rrrrJr)rr)rr6s rlmanualintegratertCsbAs # ( ( *F&)$V[[)9Q)>{{1~a  dB FKKN1$5$=[[Q"B N3Q"D)+F MroN)rHrdrIrrsrd)rr)T)rsz*tuple[Expr, Expr, Expr, Expr, Rule] | None)rztuple[Expr, Symbol](r} __future__rtypingrrrrabcrr dataclassesr collectionsr collections.abcr sympy.core.addr sympy.core.cachersympy.core.containersrsympy.core.exprrsympy.core.functionrsympy.core.logicrsympy.core.mulrsympy.core.numbersrrrsympy.core.powerrsympy.core.relationalrrrsympy.core.singletonrsympy.core.symbolrrr$sympy.functions.elementary.complexesr&sympy.functions.elementary.exponentialr r!%sympy.functions.elementary.hyperbolicr"r#r$r%r&r'r(r)(sympy.functions.elementary.miscellaneousr*$sympy.functions.elementary.piecewiser+(sympy.functions.elementary.trigonometricr,r-r.r/r0r1r2r3r4r5r6r7r8'sympy.functions.special.delta_functionsr9r:'sympy.functions.special.error_functionsr;r<r=r>r?r@rArBrCrD'sympy.functions.special.gamma_functionsrE*sympy.functions.special.elliptic_integralsrFrG#sympy.functions.special.polynomialsrHrIrJrKrLrMrNrOrP&sympy.functions.special.zeta_functionsrQ integralsrSsympy.logic.boolalgrTsympy.ntheory.factor_rUsympy.polys.polytoolsrVrWrXrYsympy.simplify.radsimprZsympy.simplify.simplifyr[sympy.solvers.solversr\sympy.strategies.corer]r^r_r`sympy.utilities.iterablesrasympy.utilities.miscrbrdr{rrrrrrrrrrrrrrrrrrrrrrrrrrrr!r,r1r3r<rBrHrZr]r`rdrhrmrprtrwr{r~rrrrrrrrrrrrrrrrrrrrrrrrrr$r%ryr;r:rDrJr]rrsrvrrrrrrgrrrrrrrrrrrrrrrrr rrr!r"r(r)r&r'rr#r*r-r/r=r?rArGrmrnrorpr]r_rarbintrrrrtrirorlrsY .#77#!##$& *&11 11"114;)))9:FFFFI(((>M;#.BB+,'FF.&   3      s   .:. .   1 1  1        5J5 5 NdN N 1D1 1& TT T" QdQ Q"  z3    #h# #  "h" "  "" "  ## #  "x" "  #x# #   Z    #~# #  #~# #  /j/ / Z  ## #  $*$ $  A*A A  FZ F  FF    RdR R 4   @Z @  @  1$ 1  1      UDU U 1D1 1"  (Z (  ( /14/1 /1d 33 3  S     :# :  : '  '  '  B%B B  -$- -  3%3 3  F*F F  J    /U/ /  3e3 3  U   /U/ /  3e3 3  U   .j. ."  F: F  F  F: F  F ;*; ; ?Z? ? EJE E EJE E: 20BdD$=Un  0# *@ j2OQKP  *(?V V2MjIIXLM\~<~X8-J Z)X@MF36              $*+ OP""NO89 ""NO89 ##PQ9: ""CD:; ##MN9;##PQ9: ""CD9: """*"*>< :GxMM,0f">57#0 2 "u02 N9 ; '\# ,.(-"-c"22Sz {|;ro