o
    oh,:                     @   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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#   ~/var/www/html/construction_image-detection-poc/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   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   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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   )	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