o
    8Va9                     @   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
 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)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_kaM  
    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] http://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ComplexInfinityZNegativeOner
   InfinityNegativeInfinityr   Zero)clsm r    L/usr/lib/python3/dist-packages/sympy/functions/special/elliptic_integrals.pyeval9   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!   fdiffG   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_conjugateK   s   
zelliptic_k._eval_conjugater   c                 C   s&   ddl m} || tj|||dS )Nr   hyperexpandnlogx)sympy.simplifyr0   rewriter   _eval_nseriesr%   xr2   r3   cdirr0   r    r    r!   r6   P   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_hyperT   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_meijergW   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_zeroZ   s   
zelliptic_k._eval_is_zeroc                 G   sN   ddl m}m} |d}| jd }|dtd|t|d    |dtd fS Nr   IntegralDummytr   r   )sympyrD   rE   r#   r
   r   r   )r%   r#   rD   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'   r.   r6   r=   r?   rA   rH   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] http://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 r>   )
r   r   r   r   
is_integerr   r   r   could_extract_minus_signrP   )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$   rP   r   )r%   r&   rS   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%   rS   r   r    r    r!   r.      s   
zelliptic_f._eval_conjugatec                 G   sV   ddl m}m} |d}| jd | jd }}|dtd|t|d    |d|fS rB   )rG   rD   rE   r#   r
   r   )r%   r#   rD   rE   rF   rS   r   r    r    r!   rH      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_realr@   rV   r    r    r!   rA      s   
zelliptic_f._eval_is_zeroNrI   )
rK   rL   rM   rN   rO   r"   r'   r.   rH   rA   r    r    r    r!   rP   f   s    )


rP   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] http://functions.wolfram.com/EllipticIntegrals/EllipticE2
    .. [3] http://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 r>   )r   r   r   r   rQ   r$   r   r   r   rR   r   r   )r   r   rS   rT   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$   rP   r   r   )r%   r&   rS   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   rX   r#   r)   r*   r+   r,   rV   r    r    r!   r.     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   r/   r   r1   )r4   r0   rX   r#   r5   r   r6   superr7   	__class__r    r!   r6     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   )rX   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   )rX   r   r   r   r   r   r]   r    r    r!   r?   (  s   z#elliptic_e._eval_rewrite_as_meijergc                 G   sf   ddl m}m} t| jdkrtd | jd fn| j\}}|d}|td|t|d   |d|fS )Nr   rC   r   r   rF   )rG   rD   rE   rX   r#   r   r
   r   )r%   r#   rD   rE   rS   r   rF   r    r    r!   rH   .  s   *$z$elliptic_e._eval_rewrite_as_Integralr:   rI   rJ   )rK   rL   rM   rN   rO   r"   r'   r.   r6   r=   r?   rH   __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_piaM  
    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] http://functions.wolfram.com/EllipticIntegrals/EllipticPi3
    .. [3] http://functions.wolfram.com/EllipticIntegrals/EllipticPi

    Nc                 C   sH  |d ur|||}}}|j rt||S |tju r7t||td|t|d   t| t|| d|   S d| t }|j	rG|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v rtjS |tjtjfv rtjS | rt
|| | S |j rt||S |jr|js|jr|jrtjS d S d S |j rt|S |tju rtjS |j rtdtd|   S |tjkrtjt|d  S ||krt|d|  S |tjtjfv rt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   rP   r   r   r
   r   r   r$   r   rQ   r_   r	   r   r   r   rR   rW   r@   r   r   r   )r   r2   r   rS   rT   r    r    r!   r"   b  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   FrY   )r%   r2   rS   r   r    r    r!   r.     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rt|||d  t||| |td|  d|d  |   d||   S nE| j\}}|dkrt||| t| |  |d | t|| |  d||  |d   S |dkrt||d  t|| d||   S t| |)Nr   r   r   )	rX   r#   r
   r   r$   rP   r_   r   r   )r%   r&   r2   rS   r   rU   fnr    r    r!   r'     s@   .


&
zelliptic_pi.fdiffc                 G   s   ddl m}m} t| jdkr | jd | jd td }}}n| j\}}}|d}|dd|t|d   td|t|d     |d|fS )Nr   rC   r   r   rF   )rG   rD   rE   rX   r#   r   r   r
   )r%   r#   rD   rE   r2   r   rS   rF   r    r    r!   rH     s   "<z%elliptic_pi._eval_rewrite_as_Integralr:   rI   )	rK   rL   rM   rN   rO   r"   r.   r'   rH   r    r    r    r!   r_   5  s    ,1

r_   N)rN   Z
sympy.corer   r   r   r   Zsympy.core.functionr   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   rP   r$   r_   r    r    r    r!   <module>   s    ZUz