
    \hI:                         S r SSKJrJrJrJr  SSKJrJr  SSK	J
r
Jr  SSKJr  SSKJr  SSKJr  SSKJrJr  SS	KJr  SS
KJrJr   " S S\5      r " S S\5      r " S S\5      r " S S\5      rg)zElliptic Integrals.     )SpiIRational)DefinedFunctionArgumentIndexError)Dummyuniquely_named_symbol)sign)atanh)sqrt)sintan)gamma)hypermeijergc                   Z    \ rS rSrSr\S 5       rSS jrS rSS jr	S r
S rS	 rS
 rSrg)
elliptic_k   a  
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

c                 ~   UR                   (       a  [        [        R                  -  $ U[        R                  L a/  S[        [	        SS5      -  -  [        [	        SS5      5      S-  -  $ U[        R                  L a  [        R                  $ U[        R                  L a.  [        [	        SS5      5      S-  S[        S[        -  5      -  -  $ U[        R                  [        R                  [        [        R                  -  [        [        R                  -  [        R                  4;   a  [        R                  $ g )N               )is_zeror   r   Halfr   r   OneComplexInfinityNegativeOner   InfinityNegativeInfinityr   Zero)clsms     b/var/www/auris/envauris/lib/python3.13/site-packages/sympy/functions/special/elliptic_integrals.pyevalelliptic_k.eval:   s    99aff9!&&[R!Q''hr1o(>(AAA!%%Z$$$!--!Q(!+QtAbDz\::1::q111QZZ<Q'''):):< <66M<    c                 r    U R                   S   n[        U5      SU-
  [        U5      -  -
  SU-  SU-
  -  -  $ )Nr   r   r   )args
elliptic_er   )selfargindexr&   s      r'   fdiffelliptic_k.fdiffH   s<    IIaL1Q
1 55!QUDDr*   c                     U R                   S   nUR                  =(       a    US-
  R                  SL a  U R                  UR	                  5       5      $ g )Nr   r   Fr,   is_realis_positivefunc	conjugater.   r&   s     r'   _eval_conjugateelliptic_k._eval_conjugateL   sD    IIaLII-1q5--%799Q[[]++ 8r*   c                 `    SSK Jn  U" U R                  [        5      R	                  XUS95      $ )Nr   hyperexpandnlogx)sympy.simplifyr=   rewriter   _eval_nseries)r.   xr?   r@   cdirr=   s         r'   rC   elliptic_k._eval_nseriesQ   s)    .4<<.<<Q$<OPPr*   c                     [         [        R                  -  [        [        R                  [        R                  4[        R                  4U5      -  $ N)r   r   r   r   r   r.   r&   kwargss      r'   _eval_rewrite_as_hyper!elliptic_k._eval_rewrite_as_hyperU   s1    !&&y/!%%1===r*   c                     [        [        R                  [        R                  4/ 4[        R                  4[        R                  44U* 5      S-  $ Nr   )r   r   r   r$   rI   s      r'   _eval_rewrite_as_meijerg#elliptic_k._eval_rewrite_as_meijergX   s;    ("-	AFF9/ErJ1LLr*   c                 F    U R                   S   nUR                  (       a  gg )Nr   T)r,   is_infiniter8   s     r'   _eval_is_zeroelliptic_k._eval_is_zero[   s    IIaL== r*   c           
          SSK Jn  [        [        SU5      R                  5      nU R
                  S   nU" S[        SU[        U5      S-  -  -
  5      -  US[        S-  45      $ Nr   Integraltr   r   )	sympy.integrals.integralsrX   r	   r
   namer,   r   r   r   )r.   r,   rJ   rX   rY   r&   s         r'   _eval_rewrite_as_Integral$elliptic_k._eval_rewrite_as_Integral`   s[    6'T2778IIaL$q1SVQY;//!Q1>>r*    Nr   r   )__name__
__module____qualname____firstlineno____doc__classmethodr(   r0   r9   rC   rK   rO   rS   r\   __static_attributes__r^   r*   r'   r   r      sB    *X  E,
Q>M
?r*   r   c                   D    \ rS rSrSr\S 5       rS
S jrS rS r	S r
Srg	)
elliptic_fg   a  
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

c                 p   UR                   (       a  [        R                  $ UR                   (       a  U$ SU-  [        -  nUR                  (       a  U[        U5      -  $ U[        R                  [        R                  4;   a  [        R                  $ UR                  5       (       a  [        U* U5      * $ g rN   )
r   r   r$   r   
is_integerr   r"   r#   could_extract_minus_signri   )r%   zr&   ks       r'   r(   elliptic_f.eval   s    9966M99HaCF<<Z]?"1::q112266M''))r1%%% *r*   c                    U R                   u  p#[        SU[        U5      S-  -  -
  5      nUS:X  a  SU-  $ US:X  aD  [        X#5      SU-  SU-
  -  -  [	        X#5      SU-  -  -
  [        SU-  5      SSU-
  -  U-  -  -
  $ [        X5      e)Nr   r   r   )r,   r   r   r-   ri   r   )r.   r/   rn   r&   fms        r'   r0   elliptic_f.fdiff   s    yy!aA	k/"q=R4K]q$ac1q5k2Z5Eqs5KK!HaQil+, - 00r*   c                     U R                   u  pUR                  =(       a    US-
  R                  SL a.  U R                  UR	                  5       UR	                  5       5      $ g )Nr   Fr3   r.   rn   r&   s      r'   r9   elliptic_f._eval_conjugate   sJ    yyII-1q5--%799Q[[]AKKM:: 8r*   c           
          SSK Jn  [        [        SU5      R                  5      nU R
                  S   U R
                  S   peU" S[        SU[        U5      S-  -  -
  5      -  USU45      $ rV   )rZ   rX   r	   r
   r[   r,   r   r   )r.   r,   rJ   rX   rY   rn   r&   s          r'   r\   $elliptic_f._eval_rewrite_as_Integral   sa    6'T2778yy|TYYq\14Ac!faiK01Aq!9==r*   c                     U R                   u  pUR                  (       a  gUR                  (       a  UR                  (       a  gg g )NT)r,   r   is_extended_realrR   ru   s      r'   rS   elliptic_f._eval_is_zero   s1    yy99!-- #0r*   r^   Nr_   )ra   rb   rc   rd   re   rf   r(   r0   r9   r\   rS   rg   r^   r*   r'   ri   ri   g   s0    'R & &1;
>r*   ri   c                   f   ^  \ rS rSrSr\SS j5       rSS jrS rSU 4S jjr	S r
S rS	 rS
rU =r$ )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                    Ub  XpSU-  [         -  nUR                  (       a  U$ UR                  (       a  [        R                  $ UR                  (       a  U[        U5      -  $ U[        R                  [        R                  4;   a  [        R                  $ UR                  5       (       a  [        U* U5      * $ g UR                  (       a	  [         S-  $ U[        R                  L a  [        R                  $ U[        R                  L a  [        [        R                  -  $ U[        R                  L a  [        R                  $ U[        R                  L a  [        R                  $ g rN   )r   r   r   r$   rl   r-   r"   r#   r    rm   r   r   )r%   r&   rn   ro   s       r'   r(   elliptic_e.eval   s	   =q!BAyyyyvvA&qzz1#5#566(((++--"A2q))) . yy!taeeuuajj|#a(((zz!a'''((( (r*   c                 X   [        U R                  5      S:X  aU  U R                  u  p#US:X  a  [        SU[        U5      S-  -  -
  5      $ US:X  a  [	        X#5      [        X#5      -
  SU-  -  $ O2U R                  S   nUS:X  a  [	        U5      [        U5      -
  SU-  -  $ [        X5      e)Nr   r   r   )lenr,   r   r   r-   ri   r   r   )r.   r/   rn   r&   s       r'   r0   elliptic_e.fdiff  s    tyy>Q99DA1}A#a&!)O,,Q"1(:a+;;acBB  		!A1}"1
15!<< 00r*   c                    [        U R                  5      S:X  ab  U R                  u  pUR                  =(       a    US-
  R                  SL a.  U R	                  UR                  5       UR                  5       5      $ g U R                  S   nUR                  =(       a    US-
  R                  SL a  U R	                  UR                  5       5      $ g )Nr   r   Fr   r   r,   r4   r5   r6   r7   ru   s      r'   r9   elliptic_e._eval_conjugate  s    tyy>Q99DA		1q1u11e;yy>> < 		!A		1q1u11e;yy// <r*   c                    > SSK Jn  [        U R                  5      S:X  a)  U" U R	                  [
        5      R                  XUS95      $ [        TU ]  XUS9$ )Nr   r<   r   r>   )rA   r=   r   r,   rB   r   rC   super)r.   rD   r?   r@   rE   r=   	__class__s         r'   rC   elliptic_e._eval_nseries  sO    .tyy>Qt||E2@@d@STTw$Q$$77r*   c                     [        U5      S:X  aE  US   n[        S-  [        [        SS5      [        R
                  4[        R                  4U5      -  $ g )Nr   r   r   r   )r   r   r   r   r   r   r   r.   r,   rJ   r&   s       r'   rK   !elliptic_e._eval_rewrite_as_hyper$  sH    t9>QAqD%"a!&& 9AEE8QGGG r*   c                     [        U5      S:X  aS  US   n[        [        R                  [	        SS5      4/ 4[        R
                  4[        R
                  44U* 5      * S-  $ g )Nr   r   r   r   r   )r   r   r   r   r   r$   r   s       r'   rO   #elliptic_e._eval_rewrite_as_meijerg)  sc    t9>QAaffhq!n5r:ffY	2QB8 889: : r*   c           	         SSK Jn  [        U R                  5      S:X  a  [        S-  U R                  S   4OU R                  u  pE[        [        SU5      R                  5      nU" [        SU[        U5      S-  -  -
  5      USU45      $ )Nr   rW   r   r   rY   )
rZ   rX   r   r,   r   r	   r
   r[   r   r   )r.   r,   rJ   rX   rn   r&   rY   s          r'   r\   $elliptic_e._eval_rewrite_as_Integral/  sr    6'*499~':1diil#		'T2778Q3q619_-1ay99r*   r^   rH   r_   r`   )ra   rb   rc   rd   re   rf   r(   r0   r9   rC   rK   rO   r\   rg   __classcell__)r   s   @r'   r-   r-      sA    -^ ) )4108H
:: :r*   r-   c                   B    \ rS rSrSr\S	S j5       rS rS
S jrS r	Sr
g)elliptic_pii6  a  
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           	      t   UGb*  X#p#UR                   (       a  [        X25      $ U[        R                  L aG  [        X25      [	        SU[        U5      S-  -  -
  5      [        U5      -  [        X25      -
  SU-
  -  -   $ SU-  [        -  nUR                  (       a  U[        X5      -  $ UR                   (       a2  [        [	        US-
  5      [        U5      -  5      [	        US-
  5      -  $ X:X  aB  [        X15      [        SX15      -
  [        U5      [	        SU[        U5      S-  -  -
  5      -  -   $ U[        R                  [        R                  4;   a  [        R                  $ U[        R                  [        R                  4;   a  [        R                  $ UR                  5       (       a  [        X* U5      * $ UR                   (       a  [        X25      $ UR                   (       a  UR"                  (       d"  UR                   (       a"  UR"                  (       a  [        R                  $ g g UR                   (       a  [%        U5      $ U[        R                  L a  [        R&                  $ UR                   (       a  [        S[	        SU-
  5      -  -  $ U[        R                  :X  a  [        R                  [)        US-
  5      -  $ X:X  a  [        U5      SU-
  -  $ U[        R                  [        R                  4;   a  [        R                  $ U[        R                  [        R                  4;   a  [        R                  $ UR                   (       a  [%        U5      $ UR                   (       a  UR"                  (       d"  UR                   (       a"  UR"                  (       a  [        R                  $ g g )Nr   r   )r   ri   r   r   r   r   r   r-   r   rl   r   r   r"   r#   r$   rm   rz   rR   r   r    r   )r%   r?   r&   rn   ro   s        r'   r(   elliptic_pi.evalc  s   =qyy!!''aee"1(a!CFAI+o.s1v5#A)*,-E33 4 !BA||Q***T!a%[Q/0a!e<<"1(;q!+??AtA#a&!)O445 6qzz1#5#566vvqzz1#5#566vv++--#Ar1---yy!!''!!amm&&1==vv ,9& yy!!}$aee(((1T!a%[=))aee))$q1u+55!!}a!e,,qzz1#5#566vvqzz1#5#566vvyy!!}$!!amm&&1==vv ,9&r*   c                    [        U R                  5      S:X  a  U R                  u  pnUR                  =(       a    US-
  R                  SL ac  UR                  =(       a    US-
  R                  SL a=  U R	                  UR                  5       UR                  5       UR                  5       5      $ g g U R                  u  pU R	                  UR                  5       UR                  5       5      $ )Nr   r   Fr   )r.   r?   rn   r&   s       r'   r9   elliptic_pi._eval_conjugate  s    tyy>QiiGA!		1q1u11e;		1q1u11e;yyq{{}MM < < 99DA99Q[[]AKKM::r*   c                 L   [        U R                  5      S:X  a  U R                  u  p#n[        SU[        U5      S-  -  -
  5      SU[        U5      S-  -  -
  peUS:X  a`  [	        X45      XB-
  [        X45      -  U-  -   US-  U-
  [        X#U5      -  U-  -   X%-  [        SU-  5      -  SU-  -  -
  SXB-
  -  US-
  -  -  $ US:X  a  SXV-  -  $ US:X  aD  [	        X45      US-
  -  [        X#U5      -   U[        SU-  5      -  SUS-
  -  U-  -  -
  SX$-
  -  -  $ OU R                  u  p$US:X  aE  [	        U5      XB-
  [        U5      -  U-  -   US-  U-
  [        X$5      -  U-  -   SXB-
  -  US-
  -  -  $ US:X  a%  [	        U5      US-
  -  [        X$5      -   SX$-
  -  -  $ [        X5      e)Nr   r   r   )	r   r,   r   r   r-   ri   r   r   r   )r.   r/   r?   rn   r&   rr   fns          r'   r0   elliptic_pi.fdiff  s   tyy>QiiGA!!aA	k/*A#a&!)O1}"1(AE:a3C+CA+EEA;qQ#779:S1Xqt,-/0!%y!a%/@B B Q"%y Q"1(!a%0#A!,-#ac(
Aq1uIbL1245quI? ? 
 99DA1}"1
1(=a(??A;q#44Q679:AEAE9JL LQ"1q1u-A0AAAquINN 00r*   c                 h   SSK Jn  [        U R                  5      S:X  a'  U R                  S   U R                  S   [        S-  penOU R                  u  pFn[        [        SU5      R                  5      nU" SSU[        U5      S-  -  -
  [        SU[        U5      S-  -  -
  5      -  -  USU45      $ )Nr   rW   r   r   rY   )
rZ   rX   r   r,   r   r	   r
   r[   r   r   )r.   r,   rJ   rX   r?   r&   rn   rY   s           r'   r\   %elliptic_pi._eval_rewrite_as_Integral  s    6tyy>QiilDIIaL"Q$!A!iiGA!'T2778A#a&!)OT!aA	k/-BBCaAYOOr*   r^   rH   r_   )ra   rb   rc   rd   re   rf   r(   r9   r0   r\   rg   r^   r*   r'   r   r   6  s-    *X / /b;1.Pr*   r   N)re   
sympy.corer   r   r   r   sympy.core.functionr   r   sympy.core.symbolr	   r
   $sympy.functions.elementary.complexesr   %sympy.functions.elementary.hyperbolicr   (sympy.functions.elementary.miscellaneousr   (sympy.functions.elementary.trigonometricr   r   'sympy.functions.special.gamma_functionsr   sympy.functions.special.hyperr   r   r   ri   r-   r   r^   r*   r'   <module>r      sc     ) ) C 9 5 7 9 = 9 8W? W?tR Rjw: w:tGP/ GPr*   