U
    ZÊ¹j,:  ã                   @   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)ÚFunctionÚ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kr>dttddƒ  ttddƒƒd  S |tjkrNtjS |tjkrzttddƒƒd dt	dt ƒ  S |tj
tjttj
 ttj tjfkr¤tjS d S )Né   é   é   éÿÿÿÿé   é   )Úis_zeror   r   ÚHalfr   r   ÚOneÚComplexInfinityZNegativeOner   ÚInfinityÚNegativeInfinityr   ÚZero)ÚclsÚm© r"   úi/var/www/html/bwave/python/venv/lib/python3.8/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k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.simplifyr2   Úrewriter   Ú_eval_nseries©r'   Úxr4   r5   Úcdirr2   r"   r"   r#   r8   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_infiniter/   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.integralsrE   r   r	   Únamer%   r   r   r   )r'   r%   r=   rE   rF   r!   r"   r"   r#   Ú_eval_rewrite_as_Integral`   s    
z$elliptic_k._eval_rewrite_as_IntegralN)r   )r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úclassmethodr$   r)   r0   r8   r>   r@   rB   rI   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r4|t|ƒ S |tjtjfkrJtjS | ¡ r`t	| |ƒ S d S r?   )
r   r   r   r   Ú
is_integerr   r   r   Úcould_extract_minus_signrO   )r    Úzr!   Úkr"   r"   r#   r$   ‘   s    zelliptic_f.evalr   c                 C   s�   | j \}}td|t|ƒd   ƒ}|dkr2d| S |dkr‚t||ƒd| d|   t||ƒd|   td| ƒdd|  |   S t| |ƒ‚d S )Nr   r   r   )r%   r   r   r&   rO   r   )r'   r(   rR   r!   Úfmr"   r"   r#   r)   Ÿ   s    
*ÿzelliptic_f.fdiffc                 C   s6   | j \}}|jo|d jdkr2|  | ¡ | ¡ ¡S d S )Nr   Fr*   ©r'   rR   r!   r"   r"   r#   r0   ©   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 rC   )rG   rE   r   r	   rH   r%   r   r   )r'   r%   r=   rE   rF   rR   r!   r"   r"   r#   rI   ®   s    z$elliptic_f._eval_rewrite_as_Integralc                 C   s(   | j \}}|jrdS |jr$|jr$dS d S )NT)r%   r   Úis_extended_realrA   rU   r"   r"   r#   rB   ´   s
    
zelliptic_f._eval_is_zeroN)r   )
rJ   rK   rL   rM   rN   r$   r)   r0   rI   rB   r"   r"   r"   r#   rO   g   s   )


rO   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 k	rt|| }}d| t  }|jr(|S |jr4tjS |jrF|t|ƒ S |tjtjfkr\tjS | 	¡ rÆt| |ƒ S nR|jr‚t d S |tj
kr’tj
S |tjkr¦ttj S |tjkr¶tjS |tjkrÆtjS d S r?   )r   r   r   r   rP   r&   r   r   r   rQ   r   r   )r    r!   rR   rS   r"   r"   r#   r$   ì   s.    





zelliptic_e.evalr   c                 C   s–   t | jƒdkr^| j\}}|dkr8td|t|ƒd   ƒS |dkrˆt||ƒt||ƒ d|  S n*| jd }|dkrˆt|ƒt|ƒ d|  S t| |ƒ‚d S )Nr   r   r   )Úlenr%   r   r   r&   rO   r   r   )r'   r(   rR   r!   r"   r"   r#   r)     s    

zelliptic_e.fdiffc                 C   sr   t | jƒdkrB| j\}}|jo&|d jdkrn|  | ¡ | ¡ ¡S n,| jd }|joZ|d jdkrn|  | ¡ ¡S d S )Nr   r   Fr   ©rW   r%   r+   r,   r-   r.   rU   r"   r"   r#   r0     s    

zelliptic_e._eval_conjugater   c                    sF   ddl m} t| jƒdkr4||  t¡j|||d�ƒS tƒ j|||d�S )Nr   r1   r   r3   )r6   r2   rW   r%   r7   r   r8   Úsuperr9   ©Ú	__class__r"   r#   r8     s    zelliptic_e._eval_nseriesc                 O   s<   t |ƒdkr8|d }td ttddƒtjftjf|ƒ S d S )Nr   r   r   r   )rW   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rD|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   )rW   r   r   r   r   r   r\   r"   r"   r#   r@   )  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   rD   r   r   rF   )
rG   rE   rW   r%   r   r   r	   rH   r   r   )r'   r%   r=   rE   rR   r!   rF   r"   r"   r#   rI   /  s    *z$elliptic_e._eval_rewrite_as_Integral)N)r   )r   )rJ   rK   rL   rM   rN   r$   r)   r0   r8   r>   r@   rI   Ú__classcell__r"   r"   rZ   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   s^  |d k	�r~|||  }}}|j r*t||ƒS |tjkrpt||ƒtd|t|ƒd   ƒt|ƒ t||ƒ d|   S d| t }|j	r�|t
||ƒ S |j rºtt|d ƒt|ƒ ƒt|d ƒ S ||k� rút||ƒt
d||ƒ t|ƒtd|t|ƒd   ƒ  S |tjtjfk�rtjS |tjtjfk�r*tjS | ¡ �rDt
|| |ƒ S |j �rVt||ƒS |j�rf|j�sv|j�rZ|j�rZtjS nÜ|j �rŽt|ƒS |tjk�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k�rtjS |tjtjfk�r$tjS |j �r4t|ƒS |j�rD|j�sT|j�rZ|j�rZtjS d S )Nr   r   )r   rO   r   r   r   r   r   r&   r   rP   r^   r   r   r   r   rQ   rV   rA   r   r   r
   )r    r4   r!   rR   rS   r"   r"   r#   r$   c  sr    


ÿÿÿ$
ÿ

ÿÿ
ÿÿzelliptic_pi.evalc                 C   s€   t | jƒdkr^| j\}}}|jo(|d jdkr||jo<|d jdkr||  | ¡ | ¡ | ¡ ¡S n| j\}}|  | ¡ | ¡ ¡S d S )Nr   r   FrX   )r'   r4   rR   r!   r"   r"   r#   r0   •  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rÒd||  S |dk�r¶t||ƒ|d  t|||ƒ |td| ƒ d|d  |   d||   S nŽ| j\}}|dk�r†t|ƒ|| t|ƒ |  |d | t||ƒ |  d||  |d   S |dk�r¶t|ƒ|d  t||ƒ d||   S t| |ƒ‚d S )Nr   r   r   )	rW   r%   r   r   r&   rO   r^   r   r   )r'   r(   r4   rR   r!   rT   Ú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   rD   r   r   rF   )
rG   rE   rW   r%   r   r   r	   rH   r   r   )r'   r%   r=   rE   r4   r!   rR   rF   r"   r"   r#   rI   ¶  s    "z%elliptic_pi._eval_rewrite_as_Integral)N)r   )	rJ   rK   rL   rM   rN   r$   r0   r)   rI   r"   r"   r"   r#   r^   6  s   ,1

r^   N)rM   Z
sympy.corer   r   r   r   Zsympy.core.functionr   r   Zsympy.core.symbolr   r	   Z$sympy.functions.elementary.complexesr
   Z%sympy.functions.elementary.hyperbolicr   Z(sympy.functions.elementary.miscellaneousr   Z(sympy.functions.elementary.trigonometricr   r   Z'sympy.functions.special.gamma_functionsr   Zsympy.functions.special.hyperr   r   r   rO   r&   r^   r"   r"   r"   r#   Ú<module>   s   ZUz