
    sg,:                         d Z ddlmZmZmZmZ ddlmZmZ ddl	m
Z
mZ ddlmZ ddlmZ ddlmZ ddlmZmZ dd	lmZ dd
lmZmZ  G d de      Z G d de      Z G d de      Z G d de      Zy)z Elliptic Integrals.     )SpiIRational)FunctionArgumentIndexError)Dummyuniquely_named_symbol)sign)atanh)sqrt)sintan)gamma)hypermeijergc                   N    e Zd ZdZed        ZddZd ZddZd Z	d Z
d Z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

    c                 j   |j                   rt        t        j                  z  S |t        j                  u r/dt        t	        dd      z  z  t        t	        dd            dz  z  S |t        j                  u rt        j                  S |t        j                  u r.t        t	        dd            dz  dt        dt        z        z  z  S |t        j                  t        j                  t        t        j                  z  t        t        j                  z  t        j                  fv rt        j                  S y )N               )is_zeror   r   Halfr   r   OneComplexInfinityNegativeOner   InfinityNegativeInfinityr   Zero)clsms     ]/var/www/html/venv/lib/python3.12/site-packages/sympy/functions/special/elliptic_integrals.pyevalzelliptic_k.eval:   s    99aff9!&&[R!Q''hr1o(>(AAA!%%Z$$$!--!Q(!+QtAbDz\::1::q111QZZ<Q'''):):< <66M<    c                 r    | j                   d   }t        |      d|z
  t        |      z  z
  d|z  d|z
  z  z  S )Nr   r   r   )args
elliptic_er   )selfargindexr%   s      r&   fdiffzelliptic_k.fdiffH   s<    IIaL1Q
1 55!QUDDr(   c                     | j                   d   }|j                  xr |dz
  j                  du r| j                  |j	                               S y )Nr   r   Fr*   is_realis_positivefunc	conjugater,   r%   s     r&   _eval_conjugatezelliptic_k._eval_conjugateL   sD    IIaLII-1q5--%799Q[[]++ 8r(   c                 h    ddl m}  || j                  t              j	                  |||            S )Nr   hyperexpandnlogx)sympy.simplifyr9   rewriter   _eval_nseries)r,   xr;   r<   cdirr9   s         r&   r?   zelliptic_k._eval_nseriesQ   s+    .4<<.<<Q!$<OPPr(   c                     t         t        j                  z  t        t        j                  t        j                  ft        j                  f|      z  S N)r   r   r   r   r   r,   r%   kwargss      r&   _eval_rewrite_as_hyperz!elliptic_k._eval_rewrite_as_hyperU   s1    !&&y/!%%1===r(   c                     t        t        j                  t        j                  fg ft        j                  ft        j                  ff|       dz  S Nr   )r   r   r   r#   rD   s      r&   _eval_rewrite_as_meijergz#elliptic_k._eval_rewrite_as_meijergX   s;    ("-	AFF9/ErJ1LLr(   c                 <    | j                   d   }|j                  ryy )Nr   T)r*   is_infiniter5   s     r&   _eval_is_zerozelliptic_k._eval_is_zero[   s    IIaL== r(   c           
          ddl m} t        t        d|      j                        }| j
                  d   } |dt        d|t        |      dz  z  z
        z  |dt        dz  f      S Nr   Integraltr   r   )	sympy.integrals.integralsrP   r	   r
   namer*   r   r   r   )r,   r*   rE   rP   rQ   r%   s         r&   _eval_rewrite_as_Integralz$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____doc__classmethodr'   r.   r6   r?   rF   rI   rL   rT    r(   r&   r   r      sB    *X  E,
Q>M
?r(   r   c                   :    e Zd ZdZed        ZddZd Zd Zd Z	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

    c                 D   |j                   rt        j                  S |j                   r|S d|z  t        z  }|j                  r|t        |      z  S |t        j                  t        j                  fv rt        j                  S |j                         rt        | |       S y rH   )
r   r   r#   r   
is_integerr   r!   r"   could_extract_minus_signr^   )r$   zr%   ks       r&   r'   zelliptic_f.eval   s    9966M99HaCF<<Z]?"1::q112266M'')r1%%% *r(   c                    | j                   \  }}t        d|t        |      dz  z  z
        }|dk(  rd|z  S |dk(  rFt        ||      d|z  d|z
  z  z  t	        ||      d|z  z  z
  t        d|z        dd|z
  z  |z  z  z
  S t        | |      )Nr   r   r   )r*   r   r   r+   r^   r   )r,   r-   rb   r%   fms        r&   r.   zelliptic_f.fdiff   s    yy1!aA	k/"q=R4K]q!$ac1q5k2Z15Eqs5KK!HaQil+, - x00r(   c                     | j                   \  }}|j                  xr |dz
  j                  du r.| j                  |j	                         |j	                               S y )Nr   Fr0   r,   rb   r%   s      r&   r6   zelliptic_f._eval_conjugate   sL    yy1II-1q5--%799Q[[]AKKM:: 8r(   c           
          ddl m} t        t        d|      j                        }| j
                  d   | j
                  d   }} |dt        d|t        |      dz  z  z
        z  |d|f      S rN   )rR   rP   r	   r
   rS   r*   r   r   )r,   r*   rE   rP   rQ   rb   r%   s          r&   rT   z$elliptic_f._eval_rewrite_as_Integral   sc    6'T2778yy|TYYq\14Ac!faiK01Aq!9==r(   c                 p    | j                   \  }}|j                  ry|j                  r|j                  ryy y )NT)r*   r   is_extended_realrK   rg   s      r&   rL   zelliptic_f._eval_is_zero   s3    yy199!-- #0r(   NrU   )
rW   rX   rY   rZ   r[   r'   r.   r6   rT   rL   r\   r(   r&   r^   r^   g   s0    'R & &1;
>r(   r^   c                   V     e Zd ZdZed	d       Zd
dZd Zd fd	Zd Z	d Z
d Z xZ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|z  t         z  }|j                  r|S |j                  rt        j                  S |j                  r|t        |      z  S |t        j                  t        j                  fv rt        j                  S |j                         rt        | |       S y |j                  r	t         dz  S |t        j                  u rt        j                  S |t        j                  u rt        t        j                  z  S |t        j                  u rt        j                  S |t        j                  u rt        j                  S y rH   )r   r   r   r#   r`   r+   r!   r"   r   ra   r   r   )r$   r%   rb   rc   s       r&   r'   zelliptic_e.eval   s
   =aqA!BAyyyyvvA&qzz1#5#566(((++-"A2q))) . yy!taeeuuajj|#a(((zz!a'''((( (r(   c                 V   t        | j                        dk(  rU| j                  \  }}|dk(  rt        d|t        |      dz  z  z
        S |dk(  rPt	        ||      t        ||      z
  d|z  z  S | j                  d   }|dk(  rt	        |      t        |      z
  d|z  z  S t        | |      )Nr   r   r   )lenr*   r   r   r+   r^   r   r   )r,   r-   rb   r%   s       r&   r.   zelliptic_e.fdiff  s    tyy>Q99DAq1}A#a&!)O,,Q"1a(:a+;;acBB		!A1}"1
15!<< x00r(   c                    t        | j                        dk(  r]| j                  \  }}|j                  xr |dz
  j                  du r.| j	                  |j                         |j                               S y | j                  d   }|j                  xr |dz
  j                  du r| j	                  |j                               S y )Nr   r   Fr   rn   r*   r1   r2   r3   r4   rg   s      r&   r6   zelliptic_e._eval_conjugate  s    tyy>Q99DAq		1q1u11e;yy>> < 		!A		1q1u11e;yy// <r(   c                     ddl m} t        | j                        dk(  r- || j	                  t
              j                  |||            S t        |   |||      S )Nr   r8   r   r:   )r=   r9   rn   r*   r>   r   r?   super)r,   r@   r;   r<   rA   r9   	__class__s         r&   r?   zelliptic_e._eval_nseries  sS    .tyy>Qt||E2@@ad@STTw$Q!$$77r(   c                     t        |      dk(  rE|d   }t        dz  t        t        dd      t        j
                  ft        j                  f|      z  S y )Nr   r   r   r   )rn   r   r   r   r   r   r   r,   r*   rE   r%   s       r&   rF   z!elliptic_e._eval_rewrite_as_hyper$  sH    t9>QAqD%"a!&& 9AEE8QGGG r(   c                     t        |      dk(  rS|d   }t        t        j                  t	        dd      fg ft        j
                  ft        j
                  ff|        dz  S y )Nr   r   r   r   r   )rn   r   r   r   r   r#   ru   s       r&   rI   z#elliptic_e._eval_rewrite_as_meijerg)  sc    t9>QAaffhq!n5r:ffY	2QB8 889: : r(   c           	         ddl m} t        | j                        dk(  rt        dz  | j                  d   fn| j                  \  }}t        t        d|      j                        } |t        d|t        |      dz  z  z
        |d|f      S )Nr   rO   r   r   rQ   )
rR   rP   rn   r*   r   r	   r
   rS   r   r   )r,   r*   rE   rP   rb   r%   rQ   s          r&   rT   z$elliptic_e._eval_rewrite_as_Integral/  st    6'*499~':1diil#		1'T2778Q3q619_-1ay99r(   rC   rU   rV   )rW   rX   rY   rZ   r[   r'   r.   r6   r?   rF   rI   rT   __classcell__)rs   s   @r&   r+   r+      s<    -^ ) )4108H
::r(   r+   c                   6    e Zd ZdZedd       Zd ZddZd Zy)	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           	         ||||}}}|j                   rt        ||      S |t        j                  u rIt        ||      t	        d|t        |      dz  z  z
        t        |      z  t        ||      z
  d|z
  z  z   S d|z  t        z  }|j                  r|t        ||      z  S |j                   r2t        t	        |dz
        t        |      z        t	        |dz
        z  S ||k(  rDt        ||      t        d||      z
  t        |      t	        d|t        |      dz  z  z
        z  z   S |t        j                  t        j                  fv rt        j                  S |t        j                  t        j                  fv rt        j                  S |j                         rt        || |       S |j                   rt        ||      S |j                   r|j"                  s|j                   r|j"                  rt        j                  S y y |j                   rt%        |      S |t        j                  u rt        j&                  S |j                   rt        dt	        d|z
        z  z  S |t        j                  k(  rt        j                  t)        |dz
        z  S ||k(  rt        |      d|z
  z  S |t        j                  t        j                  fv rt        j                  S |t        j                  t        j                  fv rt        j                  S |j                   rt%        |      S |j                   r|j"                  s|j                   r|j"                  rt        j                  S y y )Nr   r   )r   r^   r   r   r   r   r   r+   r   r`   rz   r   r!   r"   r#   ra   rj   rK   r   r   r   )r$   r;   r%   rb   rc   s        r&   r'   zelliptic_pi.evalc  s   =A!qAyy!!Q''aee"1a(a!CFAI+o.s1v5#Aq)*,-E33 4 !BA||Q***T!a%[Q/0a!e<<a"1a(;q!Q+??AtA#a&!)O445 6qzz1#5#566vvqzz1#5#566vv++-#Ar1---yy!!Q''!!amm&&1==vv ,9& yy!!}$aee(((1T!a%[=))aee))$q1u+55a!!}a!e,,qzz1#5#566vvqzz1#5#566vvyy!!}$!!amm&&1==vv ,9&r(   c                    t        | j                        dk(  r| j                  \  }}}|j                  xr |dz
  j                  du r]|j                  xr |dz
  j                  du r=| j	                  |j                         |j                         |j                               S y y | j                  \  }}| j	                  |j                         |j                               S )Nr   r   Frp   )r,   r;   rb   r%   s       r&   r6   zelliptic_pi._eval_conjugate  s    tyy>QiiGAq!		1q1u11e;		1q1u11e;yyq{{}MM < < 99DAq99Q[[]AKKM::r(   c                 f   t        | j                        dk(  r| j                  \  }}}t        d|t        |      dz  z  z
        d|t        |      dz  z  z
  }}|dk(  rft	        ||      ||z
  t        ||      z  |z  z   |dz  |z
  t        |||      z  |z  z   ||z  t        d|z        z  d|z  z  z
  d||z
  z  |dz
  z  z  S |dk(  rd||z  z  S |dk(  rt	        ||      |dz
  z  t        |||      z   |t        d|z        z  d|dz
  z  |z  z  z
  d||z
  z  z  S | j                  \  }}|dk(  rHt	        |      ||z
  t        |      z  |z  z   |dz  |z
  t        ||      z  |z  z   d||z
  z  |dz
  z  z  S |dk(  r't	        |      |dz
  z  t        ||      z   d||z
  z  z  S t        | |      )Nr   r   r   )	rn   r*   r   r   r+   r^   rz   r   r   )r,   r-   r;   rb   r%   re   fns          r&   r.   zelliptic_pi.fdiff  s   tyy>QiiGAq!!aA	k/*A#a&!)OB1}"1a(AE:a3C+CA+EEA;q!Q#779:"S1Xqt,-/0!a%y!a%/@B B Q"R%y Q"1a(!a%0#Aq!,-#ac(
Aq1uIbL1245q1uI? ? 99DAq1}"1Q
1(=a(??A;q!#44Q679:AEAE9JL LQ"1q1u-Aq0AAAq1uINN x00r(   c                 j   ddl m} t        | j                        dk(  r(| j                  d   | j                  d   t        dz  }}}n| j                  \  }}}t        t        d|      j                        } |dd|t        |      dz  z  z
  t        d|t        |      dz  z  z
        z  z  |d|f      S )Nr   rO   r   r   rQ   )
rR   rP   rn   r*   r   r	   r
   rS   r   r   )r,   r*   rE   rP   r;   r%   rb   rQ   s           r&   rT   z%elliptic_pi._eval_rewrite_as_Integral  s    6tyy>QiilDIIaL"Q$!qAiiGAq!'T2778A#a&!)OT!aA	k/-BBCaAYOOr(   rC   rU   )	rW   rX   rY   rZ   r[   r'   r6   r.   rT   r\   r(   r&   rz   rz   6  s-    *X / /b;1.Pr(   rz   N)rZ   
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   r^   r+   rz   r\   r(   r&   <module>r      sc     ) ) < 9 5 7 9 = 9 8W? W?tR Rjw: w:tGP( GPr(   