o
    §ƒðjI:  ã                   @   sÐ   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„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZdS )z Elliptic Integrals. é    )ÚSÚpiÚIÚRational)ÚDefinedFunctionÚArgumentIndexError)ÚDummyÚuniquely_named_symbol)Úsign)Úatanh)Úsqrt)ÚsinÚtan)Úgamma)ÚhyperÚmeijergc                   @   sX   e Zd ZdZedd„ ƒZddd„Zdd„ Zdd
d„Zdd„ Z	dd„ Z
dd„ Zdd„ ZdS )Ú
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                 C   s¨   |j rttj S |tju rdttddƒ  ttddƒƒd  S |tju r'tjS |tju r=ttddƒƒd dt	dt ƒ  S |tj
tjttj
 ttj tjfv rRtjS d S )Né   é   é   éÿÿÿÿé   é   )Úis_zeror   r   ÚHalfr   r   ÚOneÚComplexInfinityÚNegativeOner   ÚInfinityÚNegativeInfinityr   ÚZero)ÚclsÚm© r#   ú¬/tmp/claude-1000/-var-www-html-academy/3f42efd1-c2b7-4d08-9b05-30d86bb35479/scratchpad/piper/venv/lib/python3.10/site-packages/sympy/functions/special/elliptic_integrals.pyÚeval:   s   

$

"ÿþzelliptic_k.evalr   c                 C   s2   | j d }t|ƒd| t|ƒ  d| d|   S )Nr   r   r   )ÚargsÚ
elliptic_er   )ÚselfÚargindexr"   r#   r#   r$   ÚfdiffH   s   
(zelliptic_k.fdiffc                 C   s0   | j d }|jo|d jdu r|  | ¡ ¡S d S )Nr   r   F©r&   Úis_realÚis_positiveÚfuncÚ	conjugate©r(   r"   r#   r#   r$   Ú_eval_conjugateL   s   
ÿzelliptic_k._eval_conjugater   c                 C   s&   ddl m} ||  t¡j|||d�ƒS )Nr   ©Úhyperexpand©ÚnÚlogx)Úsympy.simplifyr3   Úrewriter   Ú_eval_nseries©r(   Úxr5   r6   Úcdirr3   r#   r#   r$   r9   Q   s   zelliptic_k._eval_nseriesc                 K   s"   t tj ttjtjftjf|ƒ S ©N)r   r   r   r   r   ©r(   r"   Úkwargsr#   r#   r$   Ú_eval_rewrite_as_hyperU   s   "z!elliptic_k._eval_rewrite_as_hyperc                 K   s*   t tjtjfg ftjftjff| ƒd S ©Nr   )r   r   r   r    r>   r#   r#   r$   Ú_eval_rewrite_as_meijergX   s   *z#elliptic_k._eval_rewrite_as_meijergc                 C   s   | j d }|jr
dS d S )Nr   T)r&   Úis_infiniter0   r#   r#   r$   Ú_eval_is_zero[   s   
ÿzelliptic_k._eval_is_zeroc                 O   sR   ddl m} ttd|ƒjƒ}| jd }|dtd|t|ƒd   ƒ |dtd fƒS ©Nr   ©ÚIntegralÚtr   r   )	Úsympy.integrals.integralsrG   r   r	   Únamer&   r   r   r   )r(   r&   r?   rG   rH   r"   r#   r#   r$   Ú_eval_rewrite_as_Integral`   s   
,z$elliptic_k._eval_rewrite_as_IntegralN©r   ©r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úclassmethodr%   r*   r1   r9   r@   rB   rD   rK   r#   r#   r#   r$   r      s    ,


r   c                   @   s>   e Zd ZdZedd„ ƒZddd„Zdd„ Zd	d
„ Zdd„ Z	dS )Ú
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                 C   sd   |j rtjS |j r|S d| t }|jr|t|ƒ S |tjtjfv r%tjS | ¡ r0t	| |ƒ S d S rA   )
r   r   r    r   Ú
is_integerr   r   r   Úcould_extract_minus_signrS   )r!   Úzr"   Úkr#   r#   r$   r%   ‘   s   ÿzelliptic_f.evalr   c                 C   sŒ   | j \}}td|t|ƒd   ƒ}|dkrd| S |dkrAt||ƒd| d|   t||ƒd|   td| ƒdd|  |   S t| |ƒ‚)Nr   r   r   )r&   r   r   r'   rS   r   )r(   r)   rV   r"   Úfmr#   r#   r$   r*   Ÿ   s   
*ÿ
zelliptic_f.fdiffc                 C   s6   | j \}}|jo|d jdu r|  | ¡ | ¡ ¡S d S )Nr   Fr+   ©r(   rV   r"   r#   r#   r$   r1   ©   s   
ÿzelliptic_f._eval_conjugatec                 O   sZ   ddl m} ttd|ƒjƒ}| jd | jd }}|dtd|t|ƒd   ƒ |d|fƒS rE   )rI   rG   r   r	   rJ   r&   r   r   )r(   r&   r?   rG   rH   rV   r"   r#   r#   r$   rK   ®   s   (z$elliptic_f._eval_rewrite_as_Integralc                 C   s,   | j \}}|jr
dS |jr|jrdS d S d S )NT)r&   r   Úis_extended_realrC   rY   r#   r#   r$   rD   ´   s   
ÿzelliptic_f._eval_is_zeroNrL   )
rN   rO   rP   rQ   rR   r%   r*   r1   rK   rD   r#   r#   r#   r$   rS   g   s    )


rS   c                       sZ   e Zd ZdZeddd„ƒZddd„Zdd	„ Zd‡ fdd„	Zdd„ Z	dd„ Z
dd„ Z‡  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

    Nc                 C   sÌ   |d ur;||}}d| t  }|jr|S |jrtjS |jr#|t|ƒ S |tjtjfv r.tjS | 	¡ r9t| |ƒ S d S |jrBt d S |tj
u rJtj
S |tju rTttj S |tju r\tjS |tju rdtjS d S rA   )r   r   r   r    rT   r'   r   r   r   rU   r   r   )r!   r"   rV   rW   r#   r#   r$   r%   ì   s2   
ÿ




ÿzelliptic_e.evalr   c                 C   s’   t | jƒdkr/| j\}}|dkrtd|t|ƒd   ƒS |dkr.t||ƒt||ƒ d|  S n| jd }|dkrDt|ƒt|ƒ d|  S t| |ƒ‚)Nr   r   r   )Úlenr&   r   r   r'   rS   r   r   )r(   r)   rV   r"   r#   r#   r$   r*     s   
ÿ

zelliptic_e.fdiffc                 C   st   t | jƒdkr"| j\}}|jo|d jdu r |  | ¡ | ¡ ¡S d S | jd }|jo.|d jdu r8|  | ¡ ¡S d S )Nr   r   Fr   ©r[   r&   r,   r-   r.   r/   rY   r#   r#   r$   r1     s   
ÿ
ÿzelliptic_e._eval_conjugater   c                    sF   ddl m} t| jƒdkr||  t¡j|||d�ƒS tƒ j|||d�S )Nr   r2   r   r4   )r7   r3   r[   r&   r8   r   r9   Úsuperr:   ©Ú	__class__r#   r$   r9     s   zelliptic_e._eval_nseriesc                 O   s<   t |ƒdkr|d }td ttddƒtjftjf|ƒ S d S )Nr   r   r   r   )r[   r   r   r   r   r   r   ©r(   r&   r?   r"   r#   r#   r$   r@   $  s   $þz!elliptic_e._eval_rewrite_as_hyperc                 O   sH   t |ƒdkr"|d }ttjtddƒfg ftjftjff| ƒ d S d S )Nr   r   r   r   r   )r[   r   r   r   r   r    r`   r#   r#   r$   rB   )  s   ÿÿþz#elliptic_e._eval_rewrite_as_meijergc                 O   sj   ddl m} t| jƒdkrtd | jd fn| j\}}ttd|ƒjƒ}|td|t	|ƒd   ƒ|d|fƒS )Nr   rF   r   r   rH   )
rI   rG   r[   r&   r   r   r	   rJ   r   r   )r(   r&   r?   rG   rV   r"   rH   r#   r#   r$   rK   /  s   *$z$elliptic_e._eval_rewrite_as_Integralr=   rL   rM   )rN   rO   rP   rQ   rR   r%   r*   r1   r9   r@   rB   rK   Ú__classcell__r#   r#   r^   r$   r'   ¼   s    /

r'   c                   @   s8   e Zd ZdZeddd„ƒZdd„ Zddd	„Zd
d„ ZdS )Ú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                 C   sB  |d urµ||}}|j rt||ƒS |tju r4t||ƒtd|t|ƒd   ƒt|ƒ t||ƒ d|   S d| t }|j	rD|t
||ƒ S |j rYtt|d ƒt|ƒ ƒt|d ƒ S ||krxt||ƒt
d||ƒ t|ƒtd|t|ƒd   ƒ  S |tjtjfv rƒtjS |tjtjfv rŽtjS | ¡ ršt
|| |ƒ S |j r¢t||ƒS |jr¨|js®|jr±|jr³tjS d S d S |j r¼t|ƒS |tju rÄtjS |j rÑtdtd| ƒ  S |tjkrßtjt|d ƒ S ||krët|ƒd|  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 d S d S )Nr   r   )r   rS   r   r   r   r   r   r'   r   rT   rb   r   r   r   r    rU   rZ   rC   r   r   r
   )r!   r5   r"   rV   rW   r#   r#   r$   r%   c  sv   


ÿÿÿ$ÿ
ÿÿþ

ÿÿþzelliptic_pi.evalc                 C   s‚   t | jƒdkr2| j\}}}|jo|d jdu r.|jo|d jdu r0|  | ¡ | ¡ | ¡ ¡S d S d S | j\}}|  | ¡ | ¡ ¡S )Nr   r   Fr\   )r(   r5   rV   r"   r#   r#   r$   r1   •  s   þ
zelliptic_pi._eval_conjugater   c                 C   s¸  t | jƒdkr’| j\}}}td|t|ƒd   ƒd|t|ƒd   }}|dkr^t||ƒ|| t||ƒ |  |d | t|||ƒ |  || td| ƒ d|   d||  |d   S |dkrhd||  S |dkr‘t||ƒ|d  t|||ƒ |td| ƒ d|d  |   d||   S nE| j\}}|dkrÀt|ƒ|| t|ƒ |  |d | t||ƒ |  d||  |d   S |dkr×t|ƒ|d  t||ƒ d||   S t| |ƒ‚)Nr   r   r   )	r[   r&   r   r   r'   rS   rb   r   r   )r(   r)   r5   rV   r"   rX   Úfnr#   r#   r$   r*   Ÿ  s@   .ÿþþ
ÿþ
þÿ
ÿÿ&
zelliptic_pi.fdiffc                 O   s”   ddl m} t| jƒdkr| jd | jd td }}}n| j\}}}ttd|ƒjƒ}|dd|t|ƒd   t	d|t|ƒd   ƒ  |d|fƒS )Nr   rF   r   r   rH   )
rI   rG   r[   r&   r   r   r	   rJ   r   r   )r(   r&   r?   rG   r5   r"   rV   rH   r#   r#   r$   rK   ¶  s   "<z%elliptic_pi._eval_rewrite_as_Integralr=   rL   )	rN   rO   rP   rQ   rR   r%   r1   r*   rK   r#   r#   r#   r$   rb   6  s    ,1

rb   N)rQ   Ú
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   rS   r'   rb   r#   r#   r#   r$   Ú<module>   s    ZUz