K iI:dZddlmZmZmZmZddlmZmZddl m Z m Z ddl m Z ddlmZddlmZddlmZmZdd lmZdd lmZmZGd d eZGd deZGddeZGddeZy)z Elliptic Integrals. )SpiIRational)DefinedFunctionArgumentIndexError)Dummyuniquely_named_symbol)sign)atanh)sqrt)sintan)gamma)hypermeijergcNeZdZdZedZd dZdZd dZdZ dZ dZ d Z y ) elliptic_kaN The complete elliptic integral of the first kind, defined by .. math:: K(m) = F\left(\tfrac{\pi}{2}\middle| m\right) where $F\left(z\middle| m\right)$ is the Legendre incomplete elliptic integral of the first kind. Explanation =========== The function $K(m)$ is a single-valued function on the complex plane with branch cut along the interval $(1, \infty)$. Note that our notation defines the incomplete elliptic integral in terms of the parameter $m$ instead of the elliptic modulus (eccentricity) $k$. In this case, the parameter $m$ is defined as $m=k^2$. Examples ======== >>> from sympy import elliptic_k, I >>> from sympy.abc import m >>> elliptic_k(0) pi/2 >>> elliptic_k(1.0 + I) 1.50923695405127 + 0.625146415202697*I >>> elliptic_k(m).series(n=3) pi/2 + pi*m/8 + 9*pi*m**2/128 + O(m**3) See Also ======== elliptic_f References ========== .. [1] https://en.wikipedia.org/wiki/Elliptic_integrals .. [2] https://functions.wolfram.com/EllipticIntegrals/EllipticK cj|jrttjzS|tjur/dtt ddzzt t dddzz S|tj urtjS|tjur.t t dddzdtdtzzz S|tjtjttjzttjztjfvrtjSy)N)is_zerorrHalfrrOneComplexInfinity NegativeOner InfinityNegativeInfinityrZero)clsms p/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/functions/special/elliptic_integrals.pyevalzelliptic_k.eval:s 99aff9  !&&[R!Q''hr1o(>(AA A !%%Z$$ $ !-- !Q(!+QtAbDz\: : 1::q111QZZ<Q'''):):<<66M<cr|jd}t|d|z t|zz d|zd|z zz S)Nrrr)args elliptic_er)selfargindexr%s r&fdiffzelliptic_k.fdiffHs< IIaL1 Q 1 55!QU DDr(c|jd}|jxr|dz jdur|j|j Sy)NrrFr*is_real is_positivefunc conjugater,r%s r&_eval_conjugatezelliptic_k._eval_conjugateLsD IIaL II -1q5--% 799Q[[]+ + 8r(chddlm}||jtj |||S)Nr hyperexpandnlogx)sympy.simplifyr9rewriter _eval_nseries)r,xr;r<cdirr9s r&r?zelliptic_k._eval_nseriesQs+.4<<.<>r(Nrr) __name__ __module__ __qualname____doc__ classmethodr'r.r6r?rFrIrLrTr(r&rr sB*X  E, Q>M ?r(rc:eZdZdZedZddZdZdZdZ y) elliptic_fa The Legendre incomplete elliptic integral of the first kind, defined by .. math:: F\left(z\middle| m\right) = \int_0^z \frac{dt}{\sqrt{1 - m \sin^2 t}} Explanation =========== This function reduces to a complete elliptic integral of the first kind, $K(m)$, when $z = \pi/2$. Note that our notation defines the incomplete elliptic integral in terms of the parameter $m$ instead of the elliptic modulus (eccentricity) $k$. In this case, the parameter $m$ is defined as $m=k^2$. Examples ======== >>> from sympy import elliptic_f, I >>> from sympy.abc import z, m >>> elliptic_f(z, m).series(z) z + z**5*(3*m**2/40 - m/30) + m*z**3/6 + O(z**6) >>> elliptic_f(3.0 + I/2, 1.0 + I) 2.909449841483 + 1.74720545502474*I See Also ======== elliptic_k References ========== .. [1] https://en.wikipedia.org/wiki/Elliptic_integrals .. [2] https://functions.wolfram.com/EllipticIntegrals/EllipticF cD|jrtjS|jr|Sd|ztz }|jr|t |zS|tj tjfvrtjS|jrt| | SyrH) rrr#r is_integerrr!r"could_extract_minus_signr^)r$zr%ks r&r'zelliptic_f.evals 9966M 99H aCF <<Z]? " 1::q112 266M  ' ' )r1%% %*r(c|j\}}td|t|dzzz }|dk(rd|z S|dk(rFt||d|zd|z zz t ||d|zz z td|zdd|z z|zz z St ||)Nrrr)r*r rr+r^r)r,r-rbr%fms r&r.zelliptic_f.fdiffsyy1 !aA k/ " q=R4K ]q!$ac1q5k2Z15Eqs5KK!HaQil+, - x00r(c|j\}}|jxr|dz jdur.|j|j |j Sy)NrFr0r,rbr%s r&r6zelliptic_f._eval_conjugatesLyy1 II -1q5--% 799Q[[]AKKM: : 8r(c ddlm}ttd|j}|j d|j d}}|dt d|t|dzzz z |d|fSrN)rRrPr r rSr*r r)r,r*rErPrQrbr%s r&rTz$elliptic_f._eval_rewrite_as_Integralsc6 'T277 8yy|TYYq\14Ac!faiK01Aq!9==r(cp|j\}}|jry|jr|jryyy)NT)r*ris_extended_realrKrgs r&rLzelliptic_f._eval_is_zeros3yy1 99  !--#0 r(NrU) rWrXrYrZr[r'r.r6rTrLr\r(r&r^r^gs0'R & &1; > r(r^cVeZdZdZed dZd dZdZd fd ZdZ dZ dZ xZ S) r+a Called with two arguments $z$ and $m$, evaluates the incomplete elliptic integral of the second kind, defined by .. math:: E\left(z\middle| m\right) = \int_0^z \sqrt{1 - m \sin^2 t} dt Called with a single argument $m$, evaluates the Legendre complete elliptic integral of the second kind .. math:: E(m) = E\left(\tfrac{\pi}{2}\middle| m\right) Explanation =========== The function $E(m)$ is a single-valued function on the complex plane with branch cut along the interval $(1, \infty)$. Note that our notation defines the incomplete elliptic integral in terms of the parameter $m$ instead of the elliptic modulus (eccentricity) $k$. In this case, the parameter $m$ is defined as $m=k^2$. Examples ======== >>> from sympy import elliptic_e, I >>> from sympy.abc import z, m >>> elliptic_e(z, m).series(z) z + z**5*(-m**2/40 + m/30) - m*z**3/6 + O(z**6) >>> elliptic_e(m).series(n=4) pi/2 - pi*m/8 - 3*pi*m**2/128 - 5*pi*m**3/512 + O(m**4) >>> elliptic_e(1 + I, 2 - I/2).n() 1.55203744279187 + 0.290764986058437*I >>> elliptic_e(0) pi/2 >>> elliptic_e(2.0 - I) 0.991052601328069 + 0.81879421395609*I References ========== .. [1] https://en.wikipedia.org/wiki/Elliptic_integrals .. [2] https://functions.wolfram.com/EllipticIntegrals/EllipticE2 .. [3] https://functions.wolfram.com/EllipticIntegrals/EllipticE c|||}}d|ztz }|jr|S|jrtjS|jr|t |zS|tj tjfvrtjS|jrt | | Sy|jr tdz S|tjurtjS|tj urttj zS|tjurtj S|tjurtjSyrH) rrrr#r`r+r!r"rrarr)r$r%rbrcs r&r'zelliptic_e.evals  =aqA!BAyyyyvv A&qzz1#5#566(((++-"A2q))).yy!t aeeuu ajj|#a(((zz!a'''((((r(cVt|jdk(rU|j\}}|dk(rtd|t|dzzz S|dk(rPt ||t ||z d|zz S|jd}|dk(rt |t |z d|zz St||)Nrrr)lenr*r rr+r^rr)r,r-rbr%s r&r.zelliptic_e.fdiffs tyy>Q 99DAq1}A#a&!) O,,Q"1a(:a+;;acBB ! A1}"1 1 5!<< x00r(ct|jdk(r]|j\}}|jxr|dz jdur.|j |j |j Sy|jd}|jxr|dz jdur|j |j Sy)NrrFrrnr*r1r2r3r4rgs r&r6zelliptic_e._eval_conjugates tyy>Q 99DAq 1q1u11e;yy >>< ! A 1q1u11e;yy//rr?super)r,r@r;r<rAr9 __class__s r&r?zelliptic_e._eval_nseriessS. tyy>Q t||E2@@ad@ST Tw$Q!$$77r(ct|dk(rE|d}tdz ttddtj ftj f|zSy)Nrrrr)rnrrrrrrr,r*rEr%s r&rFz!elliptic_e._eval_rewrite_as_hyper$sH t9>QAqD%"a!&& 9AEE8QGG G r(ct|dk(rS|d}ttjt ddfgftj ftj ff|  dz Sy)Nrrrrr)rnrrrrr#rus r&rIz#elliptic_e._eval_rewrite_as_meijerg)sc t9>QAaffhq!n5r:ffY 2QB8889: : r(c ddlm}t|jdk(rtdz |jdfn |j\}}t t d|j}|td|t|dzzz |d|fS)NrrOrrrQ) rRrPrnr*rr r rSr r)r,r*rErPrbr%rQs r&rTz$elliptic_e._eval_rewrite_as_Integral/st6'*499~':1diil# 1 'T277 8Q3q619_-1ay99r(rCrUrV) rWrXrYrZr[r'r.r6r?rFrIrT __classcell__)rss@r&r+r+s<-^))4 108 H : :r(r+c6eZdZdZeddZdZddZdZy) elliptic_piaO Called with three arguments $n$, $z$ and $m$, evaluates the Legendre incomplete elliptic integral of the third kind, defined by .. math:: \Pi\left(n; z\middle| m\right) = \int_0^z \frac{dt} {\left(1 - n \sin^2 t\right) \sqrt{1 - m \sin^2 t}} Called with two arguments $n$ and $m$, evaluates the complete elliptic integral of the third kind: .. math:: \Pi\left(n\middle| m\right) = \Pi\left(n; \tfrac{\pi}{2}\middle| m\right) Explanation =========== Note that our notation defines the incomplete elliptic integral in terms of the parameter $m$ instead of the elliptic modulus (eccentricity) $k$. In this case, the parameter $m$ is defined as $m=k^2$. Examples ======== >>> from sympy import elliptic_pi, I >>> from sympy.abc import z, n, m >>> elliptic_pi(n, z, m).series(z, n=4) z + z**3*(m/6 + n/3) + O(z**4) >>> elliptic_pi(0.5 + I, 1.0 - I, 1.2) 2.50232379629182 - 0.760939574180767*I >>> elliptic_pi(0, 0) pi/2 >>> elliptic_pi(1.0 - I/3, 2.0 + I) 3.29136443417283 + 0.32555634906645*I References ========== .. [1] https://en.wikipedia.org/wiki/Elliptic_integrals .. [2] https://functions.wolfram.com/EllipticIntegrals/EllipticPi3 .. [3] https://functions.wolfram.com/EllipticIntegrals/EllipticPi Nc |||}}|jr t||S|tjurIt||t d|t |dzzz t |zt||z d|z z zSd|ztz }|jr|t||zS|jr2tt |dz t |zt |dz z S||k(rDt||td||z t |t d|t |dzzz z zS|tjtjfvrtjS|tjtjfvrtjS|jrt|| | S|jr t||S|j r |j"s|j r|j"rtjSyy|jr t%|S|tjurtj&S|jrtdt d|z zz S|tjk(rtjt)|dz z S||k(rt|d|z z S|tjtjfvrtjS|tjtjfvrtjS|jr t%|S|j r |j"s|j r|j"rtjSyy)Nrr)rr^rrr rrr+rr`rzr r!r"r#rarjrKrrr )r$r;r%rbrcs r&r'zelliptic_pi.evalcs =aqAyy!!Q''aee"1a(a!CFAI+o.s1v5#Aq)*,-E334!BA||Q***T!a%[Q/0a!e<<a"1a(;q!Q+??AtA#a&!) O4456qzz1#5#566vv qzz1#5#566vv ++-#Ar1---yy!!Q''!!amm&&1==vv ,9&yy!!}$aee(((1T!a%[=))aee))$q1u+55a!!}a!e,,qzz1#5#566vv qzz1#5#566vv yy!!}$!!amm&&1==vv ,9&r(ct|jdk(r|j\}}}|jxr|dz jdur]|jxr|dz jdur=|j |j |j |j Syy|j\}}|j |j |j S)NrrFrp)r,r;rbr%s r&r6zelliptic_pi._eval_conjugates tyy>Q iiGAq! 1q1u11e; 1q1u11e;yy q{{}MM<<99DAq99Q[[]AKKM: :r(cft|jdk(r|j\}}}td|t|dzzz d|t|dzzz }}|dk(rft ||||z t ||z|z z|dz|z t |||z|z z||ztd|zzd|zz z d||z z|dz zz S|dk(rd||zz S|dk(rt |||dz z t |||z|td|zzd|dz z|zz z d||z zz S|j\}}|dk(rHt |||z t|z|z z|dz|z t ||z|z zd||z z|dz zz S|dk(r't ||dz z t ||zd||z zz St||)Nrrr) rnr*r rr+r^rzrr)r,r-r;rbr%refns r&r.zelliptic_pi.fdiffs tyy>Q iiGAq!!aA k/*A#a&!) OB1}"1a(AE:a3C+CA+EEA;q!Q#779:"S1X qt,-/0!a%y!a%/@BBQ"R%y Q"1a(!a%0#Aq!,-#ac( Aq1uIbL1245q1uI??99DAq1}"1 Q 1 (=a(??A;q!#44Q679:AEAE9JLLQ"1 q1u- Aq0AAAq1uINN x00r(c jddlm}t|jdk(r(|jd|jdtdz }}}n|j\}}}t t d|j}|dd|t|dzzz td|t|dzzz zz |d|fS)NrrOrrrQ) rRrPrnr*rr r rSrr )r,r*rErPr;r%rbrQs r&rTz%elliptic_pi._eval_rewrite_as_Integrals6 tyy>Q iilDIIaL"Q$!qAiiGAq! 'T277 8A#a&!) OT!aA k/-BBCaAYOOr(rCrU) rWrXrYrZr[r'r6r.rTr\r(r&rzrz6s-*X//b;1.Pr(rzN)rZ sympy.corerrrrsympy.core.functionrrsympy.core.symbolr r $sympy.functions.elementary.complexesr %sympy.functions.elementary.hyperbolicr (sympy.functions.elementary.miscellaneousr (sympy.functions.elementary.trigonometricrr'sympy.functions.special.gamma_functionsrsympy.functions.special.hyperrrrr^r+rzr\r(r&rsc))C9579=98W?W?tRRjw:w:tGP/GPr(