a
    RG5d`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 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)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 rNtjS |tju rzttddd dt	dt   S |tj
tjttj
 ttj tjfv rtjS d S )N               )is_zeror   r   Halfr   r   OneComplexInfinityNegativeOner   InfinityNegativeInfinityr   Zero)clsm r"   f/var/www/html/django/DPS/env/lib/python3.9/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.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                 G   sJ   ddl m} td}| jd }|dtd|t|d    |dtd fS Nr   Integraltr   r   )sympy.integrals.integralsrE   r   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   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r4|t| S |tjtjfv rJtjS | r`t	| | S d S r?   )
r   r   r   r   
is_integerr   r   r   could_extract_minus_signrN   )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rt||d| d|   t||d|   td| dd|  |   S t| |d S )Nr   r   r   )r%   r   r   r&   rN   r   )r'   r(   rQ   r!   fmr"   r"   r#   r)      s    
*zelliptic_f.fdiffc                 C   s6   | j \}}|jo|d jdu r2| | | S d S )Nr   Fr*   r'   rQ   r!   r"   r"   r#   r0      s    
zelliptic_f._eval_conjugatec                 G   sR   ddl m} td}| jd | jd  }}|dtd|t|d    |d|fS rC   )rG   rE   r   r%   r   r   )r'   r%   rE   rF   rQ   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 )NT)r%   r   is_extended_realrA   rT   r"   r"   r#   rB      s
    
zelliptic_f._eval_is_zeroN)r   )
rI   rJ   rK   rL   rM   r$   r)   r0   rH   rB   r"   r"   r"   r#   rN   g   s   )


rN   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rt|| }}d| t  }|jr(|S |jr4tjS |jrF|t| S |tjtjfv r\tjS |	 rt| | S nR|jrt d S |tj
u rtj
S |tju rttj S |tju rtjS |tju rtjS d S r?   )r   r   r   r   rO   r&   r   r   r   rP   r   r   )r    r!   rQ   rR   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rt||t|| d|  S n*| jd }|dkrt|t| d|  S t| |d S )Nr   r   r   )lenr%   r   r   r&   rN   r   r   )r'   r(   rQ   r!   r"   r"   r#   r)     s    

zelliptic_e.fdiffc                 C   sr   t | jdkrB| j\}}|jo&|d jdu rn| | | S n,| jd }|joZ|d jdu rn| | S d S )Nr   r   Fr   rV   r%   r+   r,   r-   r.   rT   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   rV   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   )rV   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   )rV   r   r   r   r   r   r[   r"   r"   r#   r@   )  s    z#elliptic_e._eval_rewrite_as_meijergc                 G   sb   ddl m} t| jdkr,td | jd fn| j\}}td}|td|t|d   |d|fS )Nr   rD   r   r   rF   )rG   rE   rV   r%   r   r   r   r   )r'   r%   rE   rQ   r!   rF   r"   r"   r#   rH   /  s    *z$elliptic_e._eval_rewrite_as_Integral)N)r   )r   )rI   rJ   rK   rL   rM   r$   r)   r0   r8   r>   r@   rH   __classcell__r"   r"   rY   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   s^  |d ur~|||  }}}|j r*t||S |tju rpt||td|t|d   t| t|| d|   S d| t }|j	r|t
|| S |j rtt|d t| t|d  S ||k rt||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 | rDt
|| | S |j rVt||S |jrf|jsv|jrZ|jrZtjS n|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 rtjS |tjtjfv r$tjS |j r4t|S |jrD|jsT|jrZ|jrZtjS d S )Nr   r   )r   rN   r   r   r   r   r   r&   r   rO   r]   r
   r   r   r   rP   rU   rA   r   r   r	   )r    r4   r!   rQ   rR   r"   r"   r#   r$   c  sr    


$



zelliptic_pi.evalc                 C   s   t | jdkr^| j\}}}|jo(|d jdu r||jo<|d jdu r|| | | | S n| j\}}| | | S d S )Nr   r   FrW   )r'   r4   rQ   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rt|||| t|| |  |d | t||| |  || td|  d|   d||  |d   S |dkrd||  S |dkrt|||d  t||| |td|  d|d  |   d||   S n| j\}}|dkrt||| t| |  |d | t|| |  d||  |d   S |dkrt||d  t|| d||   S t| |d S )Nr   r   r   )	rV   r%   r   r   r&   rN   r]   r   r   )r'   r(   r4   rQ   r!   rS   fnr"   r"   r#   r)     s>    .





&zelliptic_pi.fdiffc                 G   s   ddl m} t| jdkr<| jd | jd td   }}}n| j\}}}td}|dd|t|d   td|t|d     |d|fS )Nr   rD   r   r   rF   )rG   rE   rV   r%   r   r   r   r   )r'   r%   rE   r4   r!   rQ   rF   r"   r"   r#   rH     s    "z%elliptic_pi._eval_rewrite_as_Integral)N)r   )	rI   rJ   rK   rL   rM   r$   r0   r)   rH   r"   r"   r"   r#   r]   6  s   ,1

r]   N)rL   
sympy.corer   r   r   r   sympy.core.functionr   r   sympy.core.symbolr   $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   rN   r&   r]   r"   r"   r"   r#   <module>   s   ZUz