o
    GZh6                    @   s  d Z ddlmZ ddlmZ ddlmZ ddlmZm	Z	m
Z
 ddlmZ ddlmZmZ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m Z  ddl!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,m-Z-m.Z. ddl/m0Z0m1Z1 ddl2m3Z3m4Z4m5Z5 ddl6m7Z7m8Z8 dEddZ9G dd de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>G d"d# d#eZ?G d$d% d%eZ@G d&d' d'eZAG d(d) d)eZBd*d+ ZCG d,d- d-eZDG d.d/ d/eZEG d0d1 d1eZFG d2d3 d3eFZGG d4d5 d5eFZHG d6d7 d7eFZIG d8d9 d9eFZJG d:d; d;eZKG d<d= d=eKZLG d>d? d?eKZMG d@dA dAeZNG dBdC dCeZOdDS )Fz This module contains various functions that are special cases
    of incomplete gamma functions. It should probably be renamed.     )
EulerGamma)Add)cacheit)DefinedFunctionArgumentIndexError
expand_mul)fuzzy_or)IpiRationalInteger)is_eq)Pow)S)Dummyuniquely_named_symbol)sympify)	factorial
factorial2RisingFactorial)
polar_liftre
unpolarify)ceilingfloor)sqrtroot)explog	exp_polar)coshsinh)cossinsinc)hypermeijergTc                 K   s   | j d jr|rd|d< | j|fi |tjfS | tjfS |r0| j d j|fi | \}}n	| j d  \}}| |t|  | |t|   d }| |t|  | |t|   dt  }||fS )Nr   Fcomplex   )argsis_extended_realexpandr   Zeroas_real_imagfuncr	   )selfdeephintsxyr   Zim r4   V/var/www/auris/lib/python3.10/site-packages/sympy/functions/special/error_functions.pyreal_to_real_as_real_imag   s   
"(,r6   c                       s   e Zd ZdZdZd1ddZd1ddZedd	 Ze	e
d
d Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd2d'd(Zd)d* Zd+d, Zd-d. Z fd/d0ZeZ  Z S )3erfa.  
    The Gauss error function.

    Explanation
    ===========

    This function is defined as:

    .. math ::
        \mathrm{erf}(x) = \frac{2}{\sqrt{\pi}} \int_0^x e^{-t^2} \mathrm{d}t.

    Examples
    ========

    >>> from sympy import I, oo, erf
    >>> from sympy.abc import z

    Several special values are known:

    >>> erf(0)
    0
    >>> erf(oo)
    1
    >>> erf(-oo)
    -1
    >>> erf(I*oo)
    oo*I
    >>> erf(-I*oo)
    -oo*I

    In general one can pull out factors of -1 and $I$ from the argument:

    >>> erf(-z)
    -erf(z)

    The error function obeys the mirror symmetry:

    >>> from sympy import conjugate
    >>> conjugate(erf(z))
    erf(conjugate(z))

    Differentiation with respect to $z$ is supported:

    >>> from sympy import diff
    >>> diff(erf(z), z)
    2*exp(-z**2)/sqrt(pi)

    We can numerically evaluate the error function to arbitrary precision
    on the whole complex plane:

    >>> erf(4).evalf(30)
    0.999999984582742099719981147840

    >>> erf(-4*I).evalf(30)
    -1296959.73071763923152794095062*I

    See Also
    ========

    erfc: Complementary error function.
    erfi: Imaginary error function.
    erf2: Two-argument error function.
    erfinv: Inverse error function.
    erfcinv: Inverse Complementary error function.
    erf2inv: Inverse two-argument error function.

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Error_function
    .. [2] https://dlmf.nist.gov/7
    .. [3] https://mathworld.wolfram.com/Erf.html
    .. [4] https://functions.wolfram.com/GammaBetaErf/Erf

    T   c                 C   s2   |dkrdt | jd d   tt S t| |Nr8   r(   r   r   r)   r   r
   r   r/   argindexr4   r4   r5   fdiff       
z	erf.fdiffc                 C      t S z8
        Returns the inverse of this function.

        erfinvr;   r4   r4   r5   inverse      zerf.inversec                 C   s   |j r!|tju rtjS |tju rtjS |tju rtjS |jr!tjS t	|t
r+|jd S t	|tr8tj|jd  S |jr>tjS t	|trN|jd jrN|jd S |t}|tjtjfv r]|S | rg| |  S d S Nr   r8   )	is_Numberr   NaNInfinityOneNegativeInfinityNegativeOneis_zeror,   
isinstancerB   r)   erfcinverf2invextract_multiplicativelyr	   could_extract_minus_signclsargtr4   r4   r5   eval   s.   







zerf.evalc                 G   s   | dk s
| d dkrt jS t|}t| d t d }t|dkr2|d  |d  | d  | |  S dt j|  ||   | t| tt  S Nr   r(   r8   )	r   r,   r   r   lenrK   r   r   r
   nr2   previous_termskr4   r4   r5   taylor_term   s   "*zerf.taylor_termc                 C      |  | jd  S Nr   r.   r)   	conjugater/   r4   r4   r5   _eval_conjugate      zerf._eval_conjugatec                 C      | j d jdu r
dS d S Nr   Tr)   r*   rc   r4   r4   r5   _eval_is_real      zerf._eval_is_realc                 C   rf   rg   )r)   is_imaginaryrc   r4   r4   r5   _eval_is_imaginary   rj   zerf._eval_is_imaginaryc                 C   s   | j d }t|j|jgS r`   )r)   r   	is_finiter*   r/   zr4   r4   r5   _eval_is_finite   s   
zerf._eval_is_finitec                 C       | j d jdu r| j d jS d S rg   )r)   r*   rL   rc   r4   r4   r5   _eval_is_zero      zerf._eval_is_zeroc                 C   rq   rg   )r)   r*   Zis_extended_positiverc   r4   r4   r5   _eval_is_positive   rs   zerf._eval_is_positivec                 C   rq   rg   )r)   r*   is_extended_negativerc   r4   r4   r5   _eval_is_negative   rs   zerf._eval_is_negativec                 K   s:   ddl m} t|d | tj|tj|d tt   S Nr   
uppergammar(   'sympy.functions.special.gamma_functionsry   r   r   rI   Halfr
   r/   ro   kwargsry   r4   r4   r5   _eval_rewrite_as_uppergamma   s   .zerf._eval_rewrite_as_uppergammac                 K   4   t jt | tt }t jt t|tt|   S Nr   rI   r	   r   r
   fresnelcfresnelsr/   ro   r~   rT   r4   r4   r5   _eval_rewrite_as_fresnels      zerf._eval_rewrite_as_fresnelsc                 K   r   r   r   r   r4   r4   r5   _eval_rewrite_as_fresnelc   r   zerf._eval_rewrite_as_fresnelcc                 K   s.   |t t ttjgg dgtddg|d  S Nr   r(   r   r
   r&   r   r|   r   r/   ro   r~   r4   r4   r5   _eval_rewrite_as_meijerg      .zerf._eval_rewrite_as_meijergc                 K   s.   d| t t ttjgdtj g|d   S Nr(      r   r
   r%   r   r|   r   r4   r4   r5   _eval_rewrite_as_hyper   r   zerf._eval_rewrite_as_hyperc                 K   s,   t |d | |ttj|d  t t  S Nr(   r   expintr   r|   r
   r   r4   r4   r5   _eval_rewrite_as_expint      ,zerf._eval_rewrite_as_expintNc                 K   sb   ddl m} |r#|||tj}|tju r#tjt| t|d    S tjt|t|d    S )Nr   )limitr(   )	Zsympy.series.limitsr   r   rH   rJ   rK   _erfsr   rI   )r/   ro   limitvarr~   r   Zlimr4   r4   r5   _eval_rewrite_as_tractable   s   
zerf._eval_rewrite_as_tractablec                 K      t jt| S r   )r   rI   erfcr   r4   r4   r5   _eval_rewrite_as_erfc      zerf._eval_rewrite_as_erfcc                 K      t  tt |  S r   r	   erfir   r4   r4   r5   _eval_rewrite_as_erfi      zerf._eval_rewrite_as_erfic                 C   sr   | j d j|||d}||d}|tju r$|j|d|dkr dndd}||jv r4|jr4d| tt	 S | 
|S )Nr   logxcdirr   -+dirr(   )r)   as_leading_termsubsr   ComplexInfinityr   free_symbolsrL   r   r
   r.   r/   r2   r   r   rT   arg0r4   r4   r5   _eval_as_leading_term   s   

zerf._eval_as_leading_termc              	      s   ddl m} |d }|tjtjfv ra| jd  z	 |\}}W n ttfy-   |  Y S w | }|j	rat
|| }	 fddt|	D |d |	  |g }
tjt d  tt t|
   S tt| ||||S )Nr   Orderc                    s>   g | ]}t j| td | d   d | d  d |   qS r(   r8   )r   rK   r   .0r]   ro   r4   r5   
<listcomp>  s    6z%erf._eval_aseries.<locals>.<listcomp>r8   r(   )sympy.series.orderr   r   rH   rJ   r)   Zleadterm
ValueErrorNotImplementedErroris_positiver   rangerI   r   r   r
   r   superr7   _eval_aseries)r/   r[   args0r2   r   r   point_exZnewns	__class__r   r5   r     s&   

$zerf._eval_aseriesr8   r   )!__name__
__module____qualname____doc__
unbranchedr=   rC   classmethodrV   staticmethodr   r^   rd   ri   rl   rp   rr   rt   rv   r   r   r   r   r   r   r   r   r   r   r   r6   r-   __classcell__r4   r4   r   r5   r7   1   s:    L


!
r7   c                   @   s   e Zd ZdZdZd)ddZd)ddZedd	 Ze	e
d
d Zdd Zdd Zd*ddZdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& ZeZd'd( ZdS )+r   a&  
    Complementary Error Function.

    Explanation
    ===========

    The function is defined as:

    .. math ::
        \mathrm{erfc}(x) = \frac{2}{\sqrt{\pi}} \int_x^\infty e^{-t^2} \mathrm{d}t

    Examples
    ========

    >>> from sympy import I, oo, erfc
    >>> from sympy.abc import z

    Several special values are known:

    >>> erfc(0)
    1
    >>> erfc(oo)
    0
    >>> erfc(-oo)
    2
    >>> erfc(I*oo)
    -oo*I
    >>> erfc(-I*oo)
    oo*I

    The error function obeys the mirror symmetry:

    >>> from sympy import conjugate
    >>> conjugate(erfc(z))
    erfc(conjugate(z))

    Differentiation with respect to $z$ is supported:

    >>> from sympy import diff
    >>> diff(erfc(z), z)
    -2*exp(-z**2)/sqrt(pi)

    It also follows

    >>> erfc(-z)
    2 - erfc(z)

    We can numerically evaluate the complementary error function to arbitrary
    precision on the whole complex plane:

    >>> erfc(4).evalf(30)
    0.0000000154172579002800188521596734869

    >>> erfc(4*I).evalf(30)
    1.0 - 1296959.73071763923152794095062*I

    See Also
    ========

    erf: Gaussian error function.
    erfi: Imaginary error function.
    erf2: Two-argument error function.
    erfinv: Inverse error function.
    erfcinv: Inverse Complementary error function.
    erf2inv: Inverse two-argument error function.

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Error_function
    .. [2] https://dlmf.nist.gov/7
    .. [3] https://mathworld.wolfram.com/Erfc.html
    .. [4] https://functions.wolfram.com/GammaBetaErf/Erfc

    Tr8   c                 C   s2   |dkrdt | jd d   tt S t| |)Nr8   rX   r   r(   r:   r;   r4   r4   r5   r=   o  r>   z
erfc.fdiffc                 C   r?   r@   rN   r;   r4   r4   r5   rC   u  rD   zerfc.inversec                 C   s   |j r|tju rtjS |tju rtjS |jrtjS t|tr&tj|j	d  S t|t
r0|j	d S |jr6tjS |t}|tjtjfv rF| S | rQd| |  S d S Nr   r(   )rF   r   rG   rH   r,   rL   rI   rM   rB   r)   rN   rP   r	   rJ   rQ   rR   r4   r4   r5   rV   |  s&   





z	erfc.evalc                 G   s   | dkrt jS | dk s| d dkrt jS t|}t| d t d }t|dkr9|d  |d  | d  | |  S dt j|  ||   | t| tt	  S rW   )
r   rI   r,   r   r   rY   rK   r   r   r
   rZ   r4   r4   r5   r^     s   "*zerfc.taylor_termc                 C   r_   r`   ra   rc   r4   r4   r5   rd     re   zerfc._eval_conjugatec                 C   s,   | j d jdu r
dS | j d jdu rdS d S )Nr   TF)r)   r*   rk   rc   r4   r4   r5   ri     s
   zerfc._eval_is_realNc                 K      |  tj dd|dS N	tractableT)r0   r   rewriter7   r/   ro   r   r~   r4   r4   r5   r        zerfc._eval_rewrite_as_tractablec                 K   r   r   )r   rI   r7   r   r4   r4   r5   _eval_rewrite_as_erf  r   zerfc._eval_rewrite_as_erfc                 K   s   t jttt|   S r   )r   rI   r	   r   r   r4   r4   r5   r     r   zerfc._eval_rewrite_as_erfic                 K   :   t jt | tt }t jt jt t|tt|    S r   r   r   r4   r4   r5   r        $zerfc._eval_rewrite_as_fresnelsc                 K   r   r   r   r   r4   r4   r5   r     r   zerfc._eval_rewrite_as_fresnelcc              	   K   s4   t j|tt tt jgg dgtddg|d   S r   )r   rI   r   r
   r&   r|   r   r   r4   r4   r5   r        4zerfc._eval_rewrite_as_meijergc                 K   s4   t jd| tt tt jgdt j g|d    S r   )r   rI   r   r
   r%   r|   r   r4   r4   r5   r     r   zerfc._eval_rewrite_as_hyperc                 K   s@   ddl m} tjt|d | tj|tj|d tt    S rw   )r{   ry   r   rI   r   r|   r
   r}   r4   r4   r5   r     s   4z erfc._eval_rewrite_as_uppergammac                 K   s2   t jt|d |  |tt j|d  tt  S r   )r   rI   r   r   r|   r
   r   r4   r4   r5   r     s   2zerfc._eval_rewrite_as_expintc                 K   
   |  tS r   r   r/   r1   r4   r4   r5   _eval_expand_func     
zerfc._eval_expand_funcc                 C   s^   | j d j|||d}||d}|tju r$|j|d|dkr dndd}|jr*tjS | |S )Nr   r   r   r   r   r   )	r)   r   r   r   r   r   rL   rI   r.   r   r4   r4   r5   r     s   

zerfc._eval_as_leading_termc                 C   s   t jt| j |||| S r   )r   rI   r7   r)   r   )r/   r[   r   r2   r   r4   r4   r5   r        zerfc._eval_aseriesr   r   )r   r   r   r   r   r=   rC   r   rV   r   r   r^   rd   ri   r   r   r   r   r   r   r   r   r   r   r   r6   r-   r   r4   r4   r4   r5   r      s2    L



r   c                       s   e Zd ZdZdZd)ddZedd Zee	dd	 Z
d
d Zdd Zdd Zd*ddZdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ ZeZd%d& Z fd'd(Z  ZS )+r   a  
    Imaginary error function.

    Explanation
    ===========

    The function erfi is defined as:

    .. math ::
        \mathrm{erfi}(x) = \frac{2}{\sqrt{\pi}} \int_0^x e^{t^2} \mathrm{d}t

    Examples
    ========

    >>> from sympy import I, oo, erfi
    >>> from sympy.abc import z

    Several special values are known:

    >>> erfi(0)
    0
    >>> erfi(oo)
    oo
    >>> erfi(-oo)
    -oo
    >>> erfi(I*oo)
    I
    >>> erfi(-I*oo)
    -I

    In general one can pull out factors of -1 and $I$ from the argument:

    >>> erfi(-z)
    -erfi(z)

    >>> from sympy import conjugate
    >>> conjugate(erfi(z))
    erfi(conjugate(z))

    Differentiation with respect to $z$ is supported:

    >>> from sympy import diff
    >>> diff(erfi(z), z)
    2*exp(z**2)/sqrt(pi)

    We can numerically evaluate the imaginary error function to arbitrary
    precision on the whole complex plane:

    >>> erfi(2).evalf(30)
    18.5648024145755525987042919132

    >>> erfi(-2*I).evalf(30)
    -0.995322265018952734162069256367*I

    See Also
    ========

    erf: Gaussian error function.
    erfc: Complementary error function.
    erf2: Two-argument error function.
    erfinv: Inverse error function.
    erfcinv: Inverse Complementary error function.
    erf2inv: Inverse two-argument error function.

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Error_function
    .. [2] https://mathworld.wolfram.com/Erfi.html
    .. [3] https://functions.wolfram.com/GammaBetaErf/Erfi

    Tr8   c                 C   s0   |dkrdt | jd d  tt S t| |r9   r:   r;   r4   r4   r5   r=   .     
z
erfi.fdiffc                 C   s   |j r|tju rtjS |jrtjS |tju rtjS |jrtjS | r)| |  S |t}|d urf|tju r9tS t	|t
rEt|jd  S t	|trTttj|jd   S t	|trh|jd jrjt|jd  S d S d S d S rE   )rF   r   rG   rL   r,   rH   rQ   rP   r	   rM   rB   r)   rN   rI   rO   rS   ro   nzr4   r4   r5   rV   4  s.   





z	erfi.evalc                 G   s   | dk s
| d dkrt jS t|}t| d t d }t|dkr1|d |d  | d  | |  S d||   | t| tt  S rW   )r   r,   r   r   rY   r   r   r
   rZ   r4   r4   r5   r^   R  s     zerfi.taylor_termc                 C   r_   r`   ra   rc   r4   r4   r5   rd   _  re   zerfi._eval_conjugatec                 C      | j d jS r`   rh   rc   r4   r4   r5   _eval_is_extended_realb     zerfi._eval_is_extended_realc                 C   r   r`   r)   rL   rc   r4   r4   r5   rr   e  r   zerfi._eval_is_zeroNc                 K   r   r   r   r   r4   r4   r5   r   h  r   zerfi._eval_rewrite_as_tractablec                 K   r   r   )r	   r7   r   r4   r4   r5   r   k  r   zerfi._eval_rewrite_as_erfc                 K   s   t tt |  t  S r   )r	   r   r   r4   r4   r5   r   n  re   zerfi._eval_rewrite_as_erfcc                 K   4   t jt | tt }t jt t|tt|   S r   r   r   r4   r4   r5   r   q  r   zerfi._eval_rewrite_as_fresnelsc                 K   r   r   r   r   r4   r4   r5   r   u  r   zerfi._eval_rewrite_as_fresnelcc                 K   s0   |t t ttjgg dgtddg|d   S r   r   r   r4   r4   r5   r   y     0zerfi._eval_rewrite_as_meijergc                 K   s,   d| t t ttjgdtj g|d  S r   r   r   r4   r4   r5   r   |  r   zerfi._eval_rewrite_as_hyperc                 K   s>   ddl m} t|d  | |tj|d  tt tj  S rw   )r{   ry   r   r   r|   r
   rI   r}   r4   r4   r5   r     s   2z erfi._eval_rewrite_as_uppergammac                 K   s0   t |d  | |ttj|d   t t  S r   r   r   r4   r4   r5   r     r   zerfi._eval_rewrite_as_expintc                 K   r   r   r   r   r4   r4   r5   r     r   zerfi._eval_expand_funcc                 C   s\   | j d j|||d}||d}||jv r!|jr!d| tt S |jr)| |S | |S )Nr   r   r(   )	r)   r   r   r   rL   r   r
   rm   r.   r   r4   r4   r5   r     s   

zerfi._eval_as_leading_termc                    s   ddl m} |d }|tju r:| jd   fddt|D |d |  |g }t t d tt	 t
|   S tt| ||||S )Nr   r   c                    s4   g | ]}t d | d d |  d | d    qS r   )r   r   r   r4   r5   r     s    ,z&erfi._eval_aseries.<locals>.<listcomp>r8   r(   )r   r   r   rH   r)   r   r	   r   r   r
   r   r   r   r   r/   r[   r   r2   r   r   r   r   r   r   r5   r     s   


"zerfi._eval_aseriesr   r   )r   r   r   r   r   r=   r   rV   r   r   r^   rd   r   rr   r   r   r   r   r   r   r   r   r   r   r6   r-   r   r   r   r4   r4   r   r5   r     s2    I



r   c                   @   s   e Zd ZdZdd Zedd Zdd Zdd	 Zd
d Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd S )!erf2a?  
    Two-argument error function.

    Explanation
    ===========

    This function is defined as:

    .. math ::
        \mathrm{erf2}(x, y) = \frac{2}{\sqrt{\pi}} \int_x^y e^{-t^2} \mathrm{d}t

    Examples
    ========

    >>> from sympy import oo, erf2
    >>> from sympy.abc import x, y

    Several special values are known:

    >>> erf2(0, 0)
    0
    >>> erf2(x, x)
    0
    >>> erf2(x, oo)
    1 - erf(x)
    >>> erf2(x, -oo)
    -erf(x) - 1
    >>> erf2(oo, y)
    erf(y) - 1
    >>> erf2(-oo, y)
    erf(y) + 1

    In general one can pull out factors of -1:

    >>> erf2(-x, -y)
    -erf2(x, y)

    The error function obeys the mirror symmetry:

    >>> from sympy import conjugate
    >>> conjugate(erf2(x, y))
    erf2(conjugate(x), conjugate(y))

    Differentiation with respect to $x$, $y$ is supported:

    >>> from sympy import diff
    >>> diff(erf2(x, y), x)
    -2*exp(-x**2)/sqrt(pi)
    >>> diff(erf2(x, y), y)
    2*exp(-y**2)/sqrt(pi)

    See Also
    ========

    erf: Gaussian error function.
    erfc: Complementary error function.
    erfi: Imaginary error function.
    erfinv: Inverse error function.
    erfcinv: Inverse Complementary error function.
    erf2inv: Inverse two-argument error function.

    References
    ==========

    .. [1] https://functions.wolfram.com/GammaBetaErf/Erf2/

    c                 C   sX   | j \}}|dkrdt|d   tt S |dkr'dt|d   tt S t| |)Nr8   rX   r(   )r)   r   r   r
   r   r/   r<   r2   r3   r4   r4   r5   r=     s   

z
erf2.fdiffc                 C   s   t jt jt jf}|t ju s|t ju rt jS ||krt jS ||v s$||v r,t|t| S t|tr=|jd |kr=|jd S |j	sO|j	sO|j
rI|jsO|j
rW|jrWt|t| S | }| }|rk|rk| | |  S |so|rwt|t| S d S rE   )r   rH   rJ   r,   rG   r7   rM   rO   r)   rL   r*   is_infiniterQ   )rS   r2   r3   ZchkZsign_xZsign_yr4   r4   r5   rV     s,   
z	erf2.evalc                 C   s    |  | jd  | jd  S rE   ra   rc   r4   r4   r5   rd   
  s    zerf2._eval_conjugatec                 C   s   | j d jo| j d jS rE   rh   rc   r4   r4   r5   r        zerf2._eval_is_extended_realc                 K   s   t |t | S r   r7   r/   r2   r3   r~   r4   r4   r5   r        zerf2._eval_rewrite_as_erfc                 K   s   t |t | S r   r   r   r4   r4   r5   r     r   zerf2._eval_rewrite_as_erfcc                 K   s   t tt | tt |   S r   r   r   r4   r4   r5   r     r   zerf2._eval_rewrite_as_erfic                 K      t |tt |t S r   )r7   r   r   r   r4   r4   r5   r     r   zerf2._eval_rewrite_as_fresnelsc                 K   r   r   )r7   r   r   r   r4   r4   r5   r     r   zerf2._eval_rewrite_as_fresnelcc                 K   r   r   )r7   r   r&   r   r4   r4   r5   r     r   zerf2._eval_rewrite_as_meijergc                 K   r   r   )r7   r   r%   r   r4   r4   r5   r   "  r   zerf2._eval_rewrite_as_hyperc                 K   sh   ddl m} t|d | tj|tj|d tt   t|d | tj|tj|d tt    S rw   rz   )r/   r2   r3   r~   ry   r4   r4   r5   r   %  s   ,,z erf2._eval_rewrite_as_uppergammac                 K   r   r   )r7   r   r   r   r4   r4   r5   r   *  r   zerf2._eval_rewrite_as_expintc                 K   r   r   r   r   r4   r4   r5   r   -  r   zerf2._eval_expand_funcc                 C   s
   t | j S r   )r   r)   rc   r4   r4   r5   rr   0  r   zerf2._eval_is_zeroN)r   r   r   r   r=   r   rV   rd   r   r   r   r   r   r   r   r   r   r   r   rr   r4   r4   r4   r5   r     s$    E	
r   c                   @   s@   e Zd ZdZdddZdddZedd Zd	d
 Zdd Z	dS )rB   aR  
    Inverse Error Function. The erfinv function is defined as:

    .. math ::
        \mathrm{erf}(x) = y \quad \Rightarrow \quad \mathrm{erfinv}(y) = x

    Examples
    ========

    >>> from sympy import erfinv
    >>> from sympy.abc import x

    Several special values are known:

    >>> erfinv(0)
    0
    >>> erfinv(1)
    oo

    Differentiation with respect to $x$ is supported:

    >>> from sympy import diff
    >>> diff(erfinv(x), x)
    sqrt(pi)*exp(erfinv(x)**2)/2

    We can numerically evaluate the inverse error function to arbitrary
    precision on [-1, 1]:

    >>> erfinv(0.2).evalf(30)
    0.179143454621291692285822705344

    See Also
    ========

    erf: Gaussian error function.
    erfc: Complementary error function.
    erfi: Imaginary error function.
    erf2: Two-argument error function.
    erfcinv: Inverse Complementary error function.
    erf2inv: Inverse two-argument error function.

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Error_function#Inverse_functions
    .. [2] https://functions.wolfram.com/GammaBetaErf/InverseErf/

    r8   c                 C   s8   |dkrt tt| | jd d  tj S t| |Nr8   r   r(   r   r
   r   r.   r)   r   r|   r   r;   r4   r4   r5   r=   f  s   &
zerfinv.fdiffc                 C   r?   r@   r   r;   r4   r4   r5   rC   l  rD   zerfinv.inversec                 C   s   |t ju rt jS |t ju rt jS |jrt jS |t ju rt jS t|t	r.|j
d jr.|j
d S |jr4t jS |d}|d urNt|t	rP|j
d jrR|j
d  S d S d S d S Nr   r   )r   rG   rK   rJ   rL   r,   rI   rH   rM   r7   r)   r*   rP   r   r4   r4   r5   rV   s  s    




zerfinv.evalc                 K      t d| S Nr8   r   r   r4   r4   r5   _eval_rewrite_as_erfcinv  r   zerfinv._eval_rewrite_as_erfcinvc                 C   r   r`   r   rc   r4   r4   r5   rr     r   zerfinv._eval_is_zeroNr   )
r   r   r   r   r=   rC   r   rV   r   rr   r4   r4   r4   r5   rB   3  s    
2

rB   c                   @   sH   e Zd ZdZdddZdddZedd Zd	d
 Zdd Z	dd Z
dS )rN   a  
    Inverse Complementary Error Function. The erfcinv function is defined as:

    .. math ::
        \mathrm{erfc}(x) = y \quad \Rightarrow \quad \mathrm{erfcinv}(y) = x

    Examples
    ========

    >>> from sympy import erfcinv
    >>> from sympy.abc import x

    Several special values are known:

    >>> erfcinv(1)
    0
    >>> erfcinv(0)
    oo

    Differentiation with respect to $x$ is supported:

    >>> from sympy import diff
    >>> diff(erfcinv(x), x)
    -sqrt(pi)*exp(erfcinv(x)**2)/2

    See Also
    ========

    erf: Gaussian error function.
    erfc: Complementary error function.
    erfi: Imaginary error function.
    erf2: Two-argument error function.
    erfinv: Inverse error function.
    erf2inv: Inverse two-argument error function.

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Error_function#Inverse_functions
    .. [2] https://functions.wolfram.com/GammaBetaErf/InverseErfc/

    r8   c                 C   s:   |dkrt t t| | jd d  tj S t| |r   r   r;   r4   r4   r5   r=     s   (
zerfcinv.fdiffc                 C   r?   r@   r   r;   r4   r4   r5   rC     rD   zerfcinv.inversec                 C   sJ   |t ju rt jS |jrt jS |t ju rt jS |dkrt jS |jr#t jS d S r   )r   rG   rL   rH   rI   r,   rJ   rS   ro   r4   r4   r5   rV     s   

zerfcinv.evalc                 K   r   r   rA   r   r4   r4   r5   _eval_rewrite_as_erfinv  r   zerfcinv._eval_rewrite_as_erfinvc                 C   s   | j d d jS rE   r   rc   r4   r4   r5   rr     r   zerfcinv._eval_is_zeroc                 C   s"   | j d }t|jt|tdgS r   )r)   r   rL   r   r   rn   r4   r4   r5   _eval_is_infinite  s   
zerfcinv._eval_is_infiniteNr   )r   r   r   r   r=   rC   r   rV   r   rr   r   r4   r4   r4   r5   rN     s    
,

rN   c                   @   s,   e Zd ZdZdd Zedd Zdd ZdS )	rO   a2  
    Two-argument Inverse error function. The erf2inv function is defined as:

    .. math ::
        \mathrm{erf2}(x, w) = y \quad \Rightarrow \quad \mathrm{erf2inv}(x, y) = w

    Examples
    ========

    >>> from sympy import erf2inv, oo
    >>> from sympy.abc import x, y

    Several special values are known:

    >>> erf2inv(0, 0)
    0
    >>> erf2inv(1, 0)
    1
    >>> erf2inv(0, 1)
    oo
    >>> erf2inv(0, y)
    erfinv(y)
    >>> erf2inv(oo, y)
    erfcinv(-y)

    Differentiation with respect to $x$ and $y$ is supported:

    >>> from sympy import diff
    >>> diff(erf2inv(x, y), x)
    exp(-x**2 + erf2inv(x, y)**2)
    >>> diff(erf2inv(x, y), y)
    sqrt(pi)*exp(erf2inv(x, y)**2)/2

    See Also
    ========

    erf: Gaussian error function.
    erfc: Complementary error function.
    erfi: Imaginary error function.
    erf2: Two-argument error function.
    erfinv: Inverse error function.
    erfcinv: Inverse complementary error function.

    References
    ==========

    .. [1] https://functions.wolfram.com/GammaBetaErf/InverseErf2/

    c                 C   sb   | j \}}|dkrt| ||d |d  S |dkr,tttj t| ||d  S t| |)Nr8   r(   )r)   r   r.   r   r
   r   r|   r   r   r4   r4   r5   r=     s   
"
zerf2inv.fdiffc                 C   s   |t ju s
|t ju rt jS |jr|jrt jS |jr!|t ju r!t jS |t ju r,|jr,t jS |jr3t|S |t ju r=t| S |jrB|S |t ju rKt|S |jrX|jrTt jS t|S |jr]|S d S r   )r   rG   rL   r,   rI   rH   rB   rN   )rS   r2   r3   r4   r4   r5   rV      s.   


zerf2inv.evalc                 C   s"   | j \}}|jr|jrdS d S d S )NTr   )r/   r2   r3   r4   r4   r5   rr   ;  s   
zerf2inv._eval_is_zeroN)r   r   r   r   r=   r   rV   rr   r4   r4   r4   r5   rO     s    3	
rO   c                       s   e Zd ZdZedd ZdddZ fddZd	d
 Zdd Z	dd Z
dd ZeZeZeZdddZdd Z fddZd fdd	Z fddZ  ZS ) Eia	  
    The classical exponential integral.

    Explanation
    ===========

    For use in SymPy, this function is defined as

    .. math:: \operatorname{Ei}(x) = \sum_{n=1}^\infty \frac{x^n}{n\, n!}
                                     + \log(x) + \gamma,

    where $\gamma$ is the Euler-Mascheroni constant.

    If $x$ is a polar number, this defines an analytic function on the
    Riemann surface of the logarithm. Otherwise this defines an analytic
    function in the cut plane $\mathbb{C} \setminus (-\infty, 0]$.

    **Background**

    The name exponential integral comes from the following statement:

    .. math:: \operatorname{Ei}(x) = \int_{-\infty}^x \frac{e^t}{t} \mathrm{d}t

    If the integral is interpreted as a Cauchy principal value, this statement
    holds for $x > 0$ and $\operatorname{Ei}(x)$ as defined above.

    Examples
    ========

    >>> from sympy import Ei, polar_lift, exp_polar, I, pi
    >>> from sympy.abc import x

    >>> Ei(-1)
    Ei(-1)

    This yields a real value:

    >>> Ei(-1).n(chop=True)
    -0.219383934395520

    On the other hand the analytic continuation is not real:

    >>> Ei(polar_lift(-1)).n(chop=True)
    -0.21938393439552 + 3.14159265358979*I

    The exponential integral has a logarithmic branch point at the origin:

    >>> Ei(x*exp_polar(2*I*pi))
    Ei(x) + 2*I*pi

    Differentiation is supported:

    >>> Ei(x).diff(x)
    exp(x)/x

    The exponential integral is related to many other special functions.
    For example:

    >>> from sympy import expint, Shi
    >>> Ei(x).rewrite(expint)
    -expint(1, x*exp_polar(I*pi)) - I*pi
    >>> Ei(x).rewrite(Shi)
    Chi(x) + Shi(x)

    See Also
    ========

    expint: Generalised exponential integral.
    E1: Special case of the generalised exponential integral.
    li: Logarithmic integral.
    Li: Offset logarithmic integral.
    Si: Sine integral.
    Ci: Cosine integral.
    Shi: Hyperbolic sine integral.
    Chi: Hyperbolic cosine integral.
    uppergamma: Upper incomplete gamma function.

    References
    ==========

    .. [1] https://dlmf.nist.gov/6.6
    .. [2] https://en.wikipedia.org/wiki/Exponential_integral
    .. [3] Abramowitz & Stegun, section 5: https://web.archive.org/web/20201128173312/http://people.math.sfu.ca/~cbm/aands/page_228.htm

    c                 C   sd   |j rtjS |tju rtjS |tju rtjS |j rtjS | \}}|r0t|dt t |  S d S r   )	rL   r   rJ   rH   r,   extract_branch_factorr   r	   r
   rS   ro   r   r[   r4   r4   r5   rV     s   

zEi.evalr8   c                 C   s,   t | jd }|dkrt|| S t| |rE   )r   r)   r   r   r/   r<   rT   r4   r4   r5   r=     s   
zEi.fdiffc                    s:   | j d td jrt |tt | S t |S r   )r)   r   r   r   _eval_evalfr	   r
   r/   precr   r4   r5   r    s   zEi._eval_evalfc                 K   s(   ddl m} |dtd|  tt  S )Nr   rx   r   )r{   ry   r   r	   r
   r}   r4   r4   r5   r     s   zEi._eval_rewrite_as_uppergammac                 K   s   t dtd|  tt  S )Nr8   r   )r   r   r	   r
   r   r4   r4   r5   r     r   zEi._eval_rewrite_as_expintc                 K   s$   t |trt|jd S tt|S r`   )rM   r   lir)   r   r   r4   r4   r5   _eval_rewrite_as_li  s   
zEi._eval_rewrite_as_lic                 K   s.   |j rt|t| tt  S t|t| S r   )is_negativeShiChir	   r
   r   r4   r4   r5   _eval_rewrite_as_Si  s   zEi._eval_rewrite_as_SiNc                 K   s   t |t| S r   )r   _eisr   r4   r4   r5   r     r   zEi._eval_rewrite_as_tractablec                 K   s:   ddl m} ttd|gj}|tj| | |tj|fS Nr   IntegralrU   )sympy.integrals.integralsr  r   r   namer   ZExp1rJ   r/   ro   r~   r  rU   r4   r4   r5   _eval_rewrite_as_Integral  s   zEi._eval_rewrite_as_Integralc           	         s   ddl m} | jd |d}| jd j||d}|||}|jrJ||\}}|d u r1t|n|}t|||  t	 ||j
rFtt  S tj S t j|||dS )Nr   )r   )r   r   )Zsympyr   r)   r   r   r   rL   as_coeff_exponentr   r   r  r	   r
   r   r,   r   r   )	r/   r2   r   r   r   x0rT   cer   r4   r5   r     s   zEi._eval_as_leading_termr   c                    B   | j d |d}|jr| j| j  }||||S t |||S r`   )r)   r   rL   r  _eval_nseriesr   r/   r2   r[   r   r   r  fr   r4   r5   r    
   zEi._eval_nseriesc                    s   ddl m} |d }|tjtjfv r6| jd   fddt|D |d |  |g }t   t|  S t	t
| ||||S )Nr   r   c                    s   g | ]
}t | |  qS r4   r   r   r   r4   r5   r         z$Ei._eval_aseries.<locals>.<listcomp>r8   )r   r   r   rH   rJ   r)   r   r   r   r   r   r   r   r   r   r5   r     s   
zEi._eval_aseriesr   r   r   )r   r   r   r   r   rV   r=   r  r   r   r  r  _eval_rewrite_as_Ci_eval_rewrite_as_Chi_eval_rewrite_as_Shir   r  r   r  r   r   r4   r4   r   r5   r   D  s$    W

	
r   c                       sv   e Zd ZdZedd Zdd Zdd Zdd	 Zd
d Z	dd Z
e
Ze
Ze
Zd fdd	Z fddZdd Z  ZS )r   a  
    Generalized exponential integral.

    Explanation
    ===========

    This function is defined as

    .. math:: \operatorname{E}_\nu(z) = z^{\nu - 1} \Gamma(1 - \nu, z),

    where $\Gamma(1 - \nu, z)$ is the upper incomplete gamma function
    (``uppergamma``).

    Hence for $z$ with positive real part we have

    .. math:: \operatorname{E}_\nu(z)
              =   \int_1^\infty \frac{e^{-zt}}{t^\nu} \mathrm{d}t,

    which explains the name.

    The representation as an incomplete gamma function provides an analytic
    continuation for $\operatorname{E}_\nu(z)$. If $\nu$ is a
    non-positive integer, the exponential integral is thus an unbranched
    function of $z$, otherwise there is a branch point at the origin.
    Refer to the incomplete gamma function documentation for details of the
    branching behavior.

    Examples
    ========

    >>> from sympy import expint, S
    >>> from sympy.abc import nu, z

    Differentiation is supported. Differentiation with respect to $z$ further
    explains the name: for integral orders, the exponential integral is an
    iterated integral of the exponential function.

    >>> expint(nu, z).diff(z)
    -expint(nu - 1, z)

    Differentiation with respect to $\nu$ has no classical expression:

    >>> expint(nu, z).diff(nu)
    -z**(nu - 1)*meijerg(((), (1, 1)), ((0, 0, 1 - nu), ()), z)

    At non-postive integer orders, the exponential integral reduces to the
    exponential function:

    >>> expint(0, z)
    exp(-z)/z
    >>> expint(-1, z)
    exp(-z)/z + exp(-z)/z**2

    At half-integers it reduces to error functions:

    >>> expint(S(1)/2, z)
    sqrt(pi)*erfc(sqrt(z))/sqrt(z)

    At positive integer orders it can be rewritten in terms of exponentials
    and ``expint(1, z)``. Use ``expand_func()`` to do this:

    >>> from sympy import expand_func
    >>> expand_func(expint(5, z))
    z**4*expint(1, z)/24 + (-z**3 + z**2 - 2*z + 6)*exp(-z)/24

    The generalised exponential integral is essentially equivalent to the
    incomplete gamma function:

    >>> from sympy import uppergamma
    >>> expint(nu, z).rewrite(uppergamma)
    z**(nu - 1)*uppergamma(1 - nu, z)

    As such it is branched at the origin:

    >>> from sympy import exp_polar, pi, I
    >>> expint(4, z*exp_polar(2*pi*I))
    I*pi*z**3/3 + expint(4, z)
    >>> expint(nu, z*exp_polar(2*pi*I))
    z**(nu - 1)*(exp(2*I*pi*nu) - 1)*gamma(1 - nu) + expint(nu, z)

    See Also
    ========

    Ei: Another related function called exponential integral.
    E1: The classical case, returns expint(1, z).
    li: Logarithmic integral.
    Li: Offset logarithmic integral.
    Si: Sine integral.
    Ci: Cosine integral.
    Shi: Hyperbolic sine integral.
    Chi: Hyperbolic cosine integral.
    uppergamma

    References
    ==========

    .. [1] https://dlmf.nist.gov/8.19
    .. [2] https://functions.wolfram.com/GammaBetaErf/ExpIntegralE/
    .. [3] https://en.wikipedia.org/wiki/Exponential_integral

    c                 C   s  ddl m}m} t|}||krt||S |jr|dks$|js5d| jr5tt||d  |d| | S | \}}|tj	u rBd S |j
rm|dksKd S t||dt t | tj|d   t|d  t||d    S tdt t | | d ||d   |d|  t|| S )Nr   )gammary   r(   r8   )r{   r#  ry   r   r   
is_Integerr   r   r   r,   
is_integerr
   r	   rK   r   r   )rS   nuro   r#  ry   Znu2r[   r4   r4   r5   rV   c  s    
"
8>zexpint.evalc                 C   s`   | j \}}|dkr||d   tg ddgddd| gg | S |dkr+t|d | S t| |r   )r)   r&   r   r   )r/   r<   r&  ro   r4   r4   r5   r=   y  s   
,
zexpint.fdiffc                 K   s&   ddl m} ||d  |d| | S )Nr   rx   r8   )r{   ry   )r/   r&  ro   r~   ry   r4   r4   r5   r     s   z"expint._eval_rewrite_as_uppergammac                    s    dkrt |tt t   tt  S  jrM dkrMt|  d  t d  t|t  t	t d  t
 fddt d D    S | S )Nr8   c                    s$   g | ]}t  | d  |  qS r(   r  r   r&  r2   r4   r5   r        $ z.expint._eval_rewrite_as_Ei.<locals>.<listcomp>)r   r   r	   r
   r$  r   r   E1r   r   r   r   r/   r&  ro   r~   r4   r(  r5   _eval_rewrite_as_Ei  s    
$zexpint._eval_rewrite_as_Eic                 K   s   |  tj tfi |S r   )r   r   r   r   r4   r4   r5   r     r   zexpint._eval_expand_funcc                 K   s   |dkr| S t |t| S r   )r	  r
  r+  r4   r4   r5   r    s   zexpint._eval_rewrite_as_Sir   c                    st   | j d |s2| j d }|dkr| j| j  }||||S |jr2|dkr2| j| j  }||||S t |||S rE   )r)   hasr  r  r$  r,  r   )r/   r2   r[   r   r   r&  r  r   r4   r5   r    s   
zexpint._eval_nseriesc                    s   ddl m} |d }| jd  |tju r:| jd  fddt|D |d|  |g }t  t|  S tt	| 
||||S )Nr   r   r8   c                    s(   g | ]}t j| t | |  qS r4   )r   rK   r   r   r&  ro   r4   r5   r     s   ( z(expint._eval_aseries.<locals>.<listcomp>)r   r   r)   r   rH   r   r   r   r   r   r   r   r   r.  r5   r     s   


,zexpint._eval_aseriesc                 O   sL   ddl m} | j\}}ttd|j}|||  t| |  |dtjfS Nr   r  rU   r8   )	r  r  r)   r   r   r  r   r   rH   )r/   r)   r~   r  r[   r2   rU   r4   r4   r5   r    s   
&z expint._eval_rewrite_as_Integralr  )r   r   r   r   r   rV   r=   r   r,  r   r  r   r!  r"  r  r   r  r   r4   r4   r   r5   r     s    g
	r   c                 C   s
   t d| S )a+  
    Classical case of the generalized exponential integral.

    Explanation
    ===========

    This is equivalent to ``expint(1, z)``.

    Examples
    ========

    >>> from sympy import E1
    >>> E1(0)
    expint(1, 0)

    >>> E1(5)
    expint(1, 5)

    See Also
    ========

    Ei: Exponential integral.
    expint: Generalised exponential integral.
    li: Logarithmic integral.
    Li: Offset logarithmic integral.
    Si: Sine integral.
    Ci: Cosine integral.
    Shi: Hyperbolic sine integral.
    Chi: Hyperbolic cosine integral.

    r8   )r   r   r4   r4   r5   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d Z
dd ZeZdd ZeZdd Zdd Zd ddZd!ddZdd ZdS )"r  a	  
    The classical logarithmic integral.

    Explanation
    ===========

    For use in SymPy, this function is defined as

    .. math:: \operatorname{li}(x) = \int_0^x \frac{1}{\log(t)} \mathrm{d}t \,.

    Examples
    ========

    >>> from sympy import I, oo, li
    >>> from sympy.abc import z

    Several special values are known:

    >>> li(0)
    0
    >>> li(1)
    -oo
    >>> li(oo)
    oo

    Differentiation with respect to $z$ is supported:

    >>> from sympy import diff
    >>> diff(li(z), z)
    1/log(z)

    Defining the ``li`` function via an integral:
    >>> from sympy import integrate
    >>> integrate(li(z))
    z*li(z) - Ei(2*log(z))

    >>> integrate(li(z),z)
    z*li(z) - Ei(2*log(z))


    The logarithmic integral can also be defined in terms of ``Ei``:

    >>> from sympy import Ei
    >>> li(z).rewrite(Ei)
    Ei(log(z))
    >>> diff(li(z).rewrite(Ei), z)
    1/log(z)

    We can numerically evaluate the logarithmic integral to arbitrary precision
    on the whole complex plane (except the singular points):

    >>> li(2).evalf(30)
    1.04516378011749278484458888919

    >>> li(2*I).evalf(30)
    1.0652795784357498247001125598 + 3.08346052231061726610939702133*I

    We can even compute Soldner's constant by the help of mpmath:

    >>> from mpmath import findroot
    >>> findroot(li, 2)
    1.45136923488338

    Further transformations include rewriting ``li`` in terms of
    the trigonometric integrals ``Si``, ``Ci``, ``Shi`` and ``Chi``:

    >>> from sympy import Si, Ci, Shi, Chi
    >>> li(z).rewrite(Si)
    -log(I*log(z)) - log(1/log(z))/2 + log(log(z))/2 + Ci(I*log(z)) + Shi(log(z))
    >>> li(z).rewrite(Ci)
    -log(I*log(z)) - log(1/log(z))/2 + log(log(z))/2 + Ci(I*log(z)) + Shi(log(z))
    >>> li(z).rewrite(Shi)
    -log(1/log(z))/2 + log(log(z))/2 + Chi(log(z)) - Shi(log(z))
    >>> li(z).rewrite(Chi)
    -log(1/log(z))/2 + log(log(z))/2 + Chi(log(z)) - Shi(log(z))

    See Also
    ========

    Li: Offset logarithmic integral.
    Ei: Exponential integral.
    expint: Generalised exponential integral.
    E1: Special case of the generalised exponential integral.
    Si: Sine integral.
    Ci: Cosine integral.
    Shi: Hyperbolic sine integral.
    Chi: Hyperbolic cosine integral.

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Logarithmic_integral
    .. [2] https://mathworld.wolfram.com/LogarithmicIntegral.html
    .. [3] https://dlmf.nist.gov/6
    .. [4] https://mathworld.wolfram.com/SoldnersConstant.html

    c                 C   s<   |j rtjS |tju rtjS |tju rtjS |j rtjS d S r   )rL   r   r,   rI   rJ   rH   r   r4   r4   r5   rV   B  s   

zli.evalr8   c                 C   *   | j d }|dkrtjt| S t| |rE   r)   r   rI   r   r   r  r4   r4   r5   r=   M     

zli.fdiffc                 C   s"   | j d }|js| | S d S r`   )r)   ru   r.   rb   rn   r4   r4   r5   rd   T  s   
zli._eval_conjugatec                 K   s   t |td S r   )Lir  r   r4   r4   r5   _eval_rewrite_as_LiZ  r   zli._eval_rewrite_as_Lic                 K   s   t t|S r   )r   r   r   r4   r4   r5   r,  ]  r   zli._eval_rewrite_as_Eic                 K   sP   ddl m} |dt|  tjtt|ttjt|    tt|  S Nr   rx   )r{   ry   r   r   r|   rI   r}   r4   r4   r5   r   `  s   "zli._eval_rewrite_as_uppergammac                 K   sX   t tt| tttt|   tjttjt| tt|   ttt|  S r   )Cir	   r   Sir   r|   rI   r   r4   r4   r5   r  e  s
   ""zli._eval_rewrite_as_Sic                 K   s<   t t|tt| tjttjt| tt|   S r   )r
  r   r	  r   r|   rI   r   r4   r4   r5   r"  k  s   <zli._eval_rewrite_as_Shic                 K   s@   t |tddt | tjt t |t tjt |    t S )N)r8   r8   )r(   r(   )r   r%   r   r|   rI   r   r   r4   r4   r5   r   p  s
   "zli._eval_rewrite_as_hyperc                 K   sF   t t |  tjt tjt | t t |   tddt |  S )N)r4   r   ))r   r   r4   )r   r   r|   rI   r&   r   r4   r4   r5   r   t  s   2zli._eval_rewrite_as_meijergNc                 K   s   |t t| S r   )r  r   r   r4   r4   r5   r   x  r   zli._eval_rewrite_as_tractabler   c                    s:   | j d   fddtd|D }ttt  t|  S )Nr   c                    s$   g | ]}t  | t||  qS r4   )r   r   r   r   r4   r5   r   }  r)  z$li._eval_nseries.<locals>.<listcomp>r8   )r)   r   r   r   r   )r/   r2   r[   r   r   r   r4   r   r5   r  {  s   
zli._eval_nseriesc                 C      | j d }|jr
dS d S rg   r   rn   r4   r4   r5   rr        
zli._eval_is_zeror   r   r  )r   r   r   r   r   rV   r=   rd   r4  r,  r   r  r   r"  r!  r   r   r   r  rr   r4   r4   r4   r5   r    s$    c




r  c                   @   sJ   e Zd ZdZedd ZdddZdd Zd	d
 ZdddZ	dddZ
dS )r3  ab  
    The offset logarithmic integral.

    Explanation
    ===========

    For use in SymPy, this function is defined as

    .. math:: \operatorname{Li}(x) = \operatorname{li}(x) - \operatorname{li}(2)

    Examples
    ========

    >>> from sympy import Li
    >>> from sympy.abc import z

    The following special value is known:

    >>> Li(2)
    0

    Differentiation with respect to $z$ is supported:

    >>> from sympy import diff
    >>> diff(Li(z), z)
    1/log(z)

    The shifted logarithmic integral can be written in terms of $li(z)$:

    >>> from sympy import li
    >>> Li(z).rewrite(li)
    li(z) - li(2)

    We can numerically evaluate the logarithmic integral to arbitrary precision
    on the whole complex plane (except the singular points):

    >>> Li(2).evalf(30)
    0

    >>> Li(4).evalf(30)
    1.92242131492155809316615998938

    See Also
    ========

    li: Logarithmic integral.
    Ei: Exponential integral.
    expint: Generalised exponential integral.
    E1: Special case of the generalised exponential integral.
    Si: Sine integral.
    Ci: Cosine integral.
    Shi: Hyperbolic sine integral.
    Chi: Hyperbolic cosine integral.

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Logarithmic_integral
    .. [2] https://mathworld.wolfram.com/LogarithmicIntegral.html
    .. [3] https://dlmf.nist.gov/6

    c                 C   s&   |t ju rt jS |t dkrt jS d S r   )r   rH   r,   r   r4   r4   r5   rV     s
   
zLi.evalr8   c                 C   r0  rE   r1  r  r4   r4   r5   r=     r2  zLi.fdiffc                 C   s   |  t|S r   )r   r  Zevalfr  r4   r4   r5   r    r   zLi._eval_evalfc                 K   s   t |t d S r   )r  r   r4   r4   r5   r    r   zLi._eval_rewrite_as_liNc                 K   s   |  tj dddS )Nr   T)r0   )r   r  r   r4   r4   r5   r     re   zLi._eval_rewrite_as_tractabler   c                 C   s   | j | j }||||S r   )r  r)   r  )r/   r2   r[   r   r   r  r4   r4   r5   r    s   zLi._eval_nseriesr   r   r  )r   r   r   r   r   rV   r=   r  r  r   r  r4   r4   r4   r5   r3    s    @


r3  c                       sH   e Zd ZdZedd ZdddZdd Zd	d
 Zd fdd	Z	  Z
S )TrigonometricIntegralz) Base class for trigonometric integrals. c                 C   s(  |t ju r| jS |t ju r|  S |t ju r|  S |jr | jS |t	t
}|d u r7| ddkr7|t
}|d urA| |dS |t	t
 }|d urS| |dS |t	d}|d u rj| ddkrj|d}|d urs| |S | \}}|dkr||krd S dt t
 | | d | | S )Nr   r8   r   r(   )r   r,   _atzerorH   _atinfrJ   	_atneginfrL   rP   r   r	   	_trigfunc_Ifactor_minusfactorr   r
   r  r4   r4   r5   rV     s2   





"zTrigonometricIntegral.evalr8   c                 C   s.   t | jd }|dkr| || S t| |rE   )r   r)   r>  r   r  r4   r4   r5   r=   	  s   
zTrigonometricIntegral.fdiffc                 K   s   |  |tS r   )r   r   r   r   r4   r4   r5   r,    r   z)TrigonometricIntegral._eval_rewrite_as_Eic                 K   s   ddl m} | ||S r5  )r{   ry   r   r   r}   r4   r4   r5   r     s   z1TrigonometricIntegral._eval_rewrite_as_uppergammar   c                    s   | j d |ddkrt |||S | ||||}| ddkr(|d8 }|jtdd dd}| ddkrA|tt| 7 }||| j d |||S )Nr   r8   c                 S   s   | | | S r   r4   )rU   r[   r4   r4   r5   <lambda>  s    z5TrigonometricIntegral._eval_nseries.<locals>.<lambda>F)Zsimultaneous)	r)   r   r   r  r>  replacer   r   r   )r/   r2   r[   r   r   Z
baseseriesr   r4   r5   r    s   z#TrigonometricIntegral._eval_nseriesr   r  )r   r   r   r   r   rV   r=   r,  r   r  r   r4   r4   r   r5   r:    s    

r:  c                       s~   e Zd ZdZeZejZe	dd Z
e	dd Ze	dd Ze	dd	 Zd
d Zdd ZeZdd Z fddZdd Z  ZS )r7  a  
    Sine integral.

    Explanation
    ===========

    This function is defined by

    .. math:: \operatorname{Si}(z) = \int_0^z \frac{\sin{t}}{t} \mathrm{d}t.

    It is an entire function.

    Examples
    ========

    >>> from sympy import Si
    >>> from sympy.abc import z

    The sine integral is an antiderivative of $sin(z)/z$:

    >>> Si(z).diff(z)
    sin(z)/z

    It is unbranched:

    >>> from sympy import exp_polar, I, pi
    >>> Si(z*exp_polar(2*I*pi))
    Si(z)

    Sine integral behaves much like ordinary sine under multiplication by ``I``:

    >>> Si(I*z)
    I*Shi(z)
    >>> Si(-z)
    -Si(z)

    It can also be expressed in terms of exponential integrals, but beware
    that the latter is branched:

    >>> from sympy import expint
    >>> Si(z).rewrite(expint)
    -I*(-expint(1, z*exp_polar(-I*pi/2))/2 +
         expint(1, z*exp_polar(I*pi/2))/2) + pi/2

    It can be rewritten in the form of sinc function (by definition):

    >>> from sympy import sinc
    >>> Si(z).rewrite(sinc)
    Integral(sinc(_t), (_t, 0, z))

    See Also
    ========

    Ci: Cosine integral.
    Shi: Hyperbolic sine integral.
    Chi: Hyperbolic cosine integral.
    Ei: Exponential integral.
    expint: Generalised exponential integral.
    sinc: unnormalized sinc function
    E1: Special case of the generalised exponential integral.
    li: Logarithmic integral.
    Li: Offset logarithmic integral.

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Trigonometric_integral

    c                 C   s
   t tj S r   r
   r   r|   rS   r4   r4   r5   r<  n     
z	Si._atinfc                 C   s   t  tj S r   rC  rD  r4   r4   r5   r=  r  s   zSi._atneginfc                 C   
   t | S r   )r7  r   r4   r4   r5   r@  v  rE  zSi._minusfactorc                 C      t t| | S r   )r	   r	  rS   ro   signr4   r4   r5   r?  z     zSi._Ifactorc                 K   s2   t d ttt| ttt |  d t  S r   )r
   r*  r   r	   r   r4   r4   r5   r   ~  s   2zSi._eval_rewrite_as_expintc                 K   s2   ddl m} ttd|gj}|t||d|fS r  )r  r  r   r   r  r$   r  r4   r4   r5   r    s   zSi._eval_rewrite_as_Integralc                 C   sh   | j d j|||d}||d}|tju r%|j|dt|jr!dndd}|jr*|S |j	s2| 
|S | S Nr   r   r   r   r   r)   r   r   r   rG   r   r   r  rL   r   r.   r   r4   r4   r5   r     s   

zSi._eval_as_leading_termc           	         s   ddl m} |d }|tju rX| jd   fddt|d d D |d |  |g } fddt|d D |d |  |g }td t t|   t	 t|   S t
t| ||||S )Nr   r   c                    2   g | ]}t j| td |   d | d   qS r   r   rK   r   r   r   r4   r5   r         *z$Si._eval_aseries.<locals>.<listcomp>r(   r8   c                    6   g | ]}t j| td | d   d |d    qS r   rN  r   r   r4   r5   r         .)r   r   r   rH   r)   r   r
   r"   r   r#   r   r7  r   )	r/   r[   r   r2   r   r   r   pqr   r   r5   r     s    




(zSi._eval_aseriesc                 C   r8  rg   r   rn   r4   r4   r5   rr     r9  zSi._eval_is_zero)r   r   r   r   r#   r>  r   r,   r;  r   r<  r=  r@  r?  r   r  Z_eval_rewrite_as_sincr   r   rr   r   r4   r4   r   r5   r7  $  s$    F



r7  c                       sr   e Zd ZdZeZejZe	dd Z
e	dd Ze	dd Ze	dd	 Zd
d Zdd Zdd Z fddZ  ZS )r6  a  
    Cosine integral.

    Explanation
    ===========

    This function is defined for positive $x$ by

    .. math:: \operatorname{Ci}(x) = \gamma + \log{x}
                         + \int_0^x \frac{\cos{t} - 1}{t} \mathrm{d}t
           = -\int_x^\infty \frac{\cos{t}}{t} \mathrm{d}t,

    where $\gamma$ is the Euler-Mascheroni constant.

    We have

    .. math:: \operatorname{Ci}(z) =
        -\frac{\operatorname{E}_1\left(e^{i\pi/2} z\right)
               + \operatorname{E}_1\left(e^{-i \pi/2} z\right)}{2}

    which holds for all polar $z$ and thus provides an analytic
    continuation to the Riemann surface of the logarithm.

    The formula also holds as stated
    for $z \in \mathbb{C}$ with $\Re(z) > 0$.
    By lifting to the principal branch, we obtain an analytic function on the
    cut complex plane.

    Examples
    ========

    >>> from sympy import Ci
    >>> from sympy.abc import z

    The cosine integral is a primitive of $\cos(z)/z$:

    >>> Ci(z).diff(z)
    cos(z)/z

    It has a logarithmic branch point at the origin:

    >>> from sympy import exp_polar, I, pi
    >>> Ci(z*exp_polar(2*I*pi))
    Ci(z) + 2*I*pi

    The cosine integral behaves somewhat like ordinary $\cos$ under
    multiplication by $i$:

    >>> from sympy import polar_lift
    >>> Ci(polar_lift(I)*z)
    Chi(z) + I*pi/2
    >>> Ci(polar_lift(-1)*z)
    Ci(z) + I*pi

    It can also be expressed in terms of exponential integrals:

    >>> from sympy import expint
    >>> Ci(z).rewrite(expint)
    -expint(1, z*exp_polar(-I*pi/2))/2 - expint(1, z*exp_polar(I*pi/2))/2

    See Also
    ========

    Si: Sine integral.
    Shi: Hyperbolic sine integral.
    Chi: Hyperbolic cosine integral.
    Ei: Exponential integral.
    expint: Generalised exponential integral.
    E1: Special case of the generalised exponential integral.
    li: Logarithmic integral.
    Li: Offset logarithmic integral.

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Trigonometric_integral

    c                 C      t jS r   )r   r,   rD  r4   r4   r5   r<       z	Ci._atinfc                 C   s   t t S r   )r	   r
   rD  r4   r4   r5   r=    s   zCi._atneginfc                 C      t |tt  S r   r6  r	   r
   r   r4   r4   r5   r@    rJ  zCi._minusfactorc                 C      t |tt d |  S r   r
  r	   r
   rH  r4   r4   r5   r?       zCi._Ifactorc                 K   s(   t tt| t tt |   d S r   )r*  r   r	   r   r4   r4   r5   r     s   (zCi._eval_rewrite_as_expintc                 K   sH   ddl m} ttd|gj}tjt| |dt| | |d|f S r/  )	r  r  r   r   r  r   r   r   r"   r  r4   r4   r5   r    s   *zCi._eval_rewrite_as_Integralc                 C      | j d j|||d}||d}|tju r%|j|dt|jr!dndd}|jrC|	|\}}|d u r7t
|n|}t
|||  t S |jrK| |S | S rK  r)   r   r   r   rG   r   r   r  rL   r  r   r   rm   r.   r/   r2   r   r   rT   r   r  r  r4   r4   r5   r        

zCi._eval_as_leading_termc           
         s   ddl m} |d }|tjtjfv rd| jd   fddt|d d D |d |  |g } fddt|d D |d |  |g }t t|  t	 t|   }	|tju rb|	t
t 7 }	|	S tt| ||||S )Nr   r   c                    rM  r   rN  r   r   r4   r5   r   ,  rO  z$Ci._eval_aseries.<locals>.<listcomp>r(   r8   c                    rP  r   rN  r   r   r4   r5   r   .  rQ  )r   r   r   rH   rJ   r)   r   r#   r   r"   r	   r
   r   r6  r   )
r/   r[   r   r2   r   r   r   rR  rS  resultr   r   r5   r   &  s&   



 
zCi._eval_aseries)r   r   r   r   r"   r>  r   r   r;  r   r<  r=  r@  r?  r   r  r   r   r   r4   r4   r   r5   r6    s     O



r6  c                   @   sb   e Zd ZdZeZejZe	dd Z
e	dd Ze	dd Ze	dd	 Zd
d Zdd Zdd ZdS )r	  a  
    Sinh integral.

    Explanation
    ===========

    This function is defined by

    .. math:: \operatorname{Shi}(z) = \int_0^z \frac{\sinh{t}}{t} \mathrm{d}t.

    It is an entire function.

    Examples
    ========

    >>> from sympy import Shi
    >>> from sympy.abc import z

    The Sinh integral is a primitive of $\sinh(z)/z$:

    >>> Shi(z).diff(z)
    sinh(z)/z

    It is unbranched:

    >>> from sympy import exp_polar, I, pi
    >>> Shi(z*exp_polar(2*I*pi))
    Shi(z)

    The $\sinh$ integral behaves much like ordinary $\sinh$ under
    multiplication by $i$:

    >>> Shi(I*z)
    I*Si(z)
    >>> Shi(-z)
    -Shi(z)

    It can also be expressed in terms of exponential integrals, but beware
    that the latter is branched:

    >>> from sympy import expint
    >>> Shi(z).rewrite(expint)
    expint(1, z)/2 - expint(1, z*exp_polar(I*pi))/2 - I*pi/2

    See Also
    ========

    Si: Sine integral.
    Ci: Cosine integral.
    Chi: Hyperbolic cosine integral.
    Ei: Exponential integral.
    expint: Generalised exponential integral.
    E1: Special case of the generalised exponential integral.
    li: Logarithmic integral.
    Li: Offset logarithmic integral.

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Trigonometric_integral

    c                 C   rT  r   r   rH   rD  r4   r4   r5   r<  {  rU  z
Shi._atinfc                 C   rT  r   )r   rJ   rD  r4   r4   r5   r=    rU  zShi._atneginfc                 C   rF  r   )r	  r   r4   r4   r5   r@    rE  zShi._minusfactorc                 C   rG  r   )r	   r7  rH  r4   r4   r5   r?    rJ  zShi._Ifactorc                 K   s,   t |t ttt |  d tt d  S r   )r*  r   r	   r
   r   r4   r4   r5   r     s   ,zShi._eval_rewrite_as_expintc                 C   r8  rg   r   rn   r4   r4   r5   rr     r9  zShi._eval_is_zeroc                 C   sb   | j d |}||d}|tju r"|j|dt|jrdndd}|jr'|S |j	s/| 
|S | S )Nr   r   r   r   rL  r   r4   r4   r5   r     s   

zShi._eval_as_leading_termN)r   r   r   r   r!   r>  r   r,   r;  r   r<  r=  r@  r?  r   rr   r   r4   r4   r4   r5   r	  8  s    ?



r	  c                   @   sZ   e Zd ZdZeZejZe	dd Z
e	dd Ze	dd Ze	dd	 Zd
d Zdd ZdS )r
  a   
    Cosh integral.

    Explanation
    ===========

    This function is defined for positive $x$ by

    .. math:: \operatorname{Chi}(x) = \gamma + \log{x}
                         + \int_0^x \frac{\cosh{t} - 1}{t} \mathrm{d}t,

    where $\gamma$ is the Euler-Mascheroni constant.

    We have

    .. math:: \operatorname{Chi}(z) = \operatorname{Ci}\left(e^{i \pi/2}z\right)
                         - i\frac{\pi}{2},

    which holds for all polar $z$ and thus provides an analytic
    continuation to the Riemann surface of the logarithm.
    By lifting to the principal branch we obtain an analytic function on the
    cut complex plane.

    Examples
    ========

    >>> from sympy import Chi
    >>> from sympy.abc import z

    The $\cosh$ integral is a primitive of $\cosh(z)/z$:

    >>> Chi(z).diff(z)
    cosh(z)/z

    It has a logarithmic branch point at the origin:

    >>> from sympy import exp_polar, I, pi
    >>> Chi(z*exp_polar(2*I*pi))
    Chi(z) + 2*I*pi

    The $\cosh$ integral behaves somewhat like ordinary $\cosh$ under
    multiplication by $i$:

    >>> from sympy import polar_lift
    >>> Chi(polar_lift(I)*z)
    Ci(z) + I*pi/2
    >>> Chi(polar_lift(-1)*z)
    Chi(z) + I*pi

    It can also be expressed in terms of exponential integrals:

    >>> from sympy import expint
    >>> Chi(z).rewrite(expint)
    -expint(1, z)/2 - expint(1, z*exp_polar(I*pi))/2 - I*pi/2

    See Also
    ========

    Si: Sine integral.
    Ci: Cosine integral.
    Shi: Hyperbolic sine integral.
    Ei: Exponential integral.
    expint: Generalised exponential integral.
    E1: Special case of the generalised exponential integral.
    li: Logarithmic integral.
    Li: Offset logarithmic integral.

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Trigonometric_integral

    c                 C   rT  r   r`  rD  r4   r4   r5   r<    rU  z
Chi._atinfc                 C   rT  r   r`  rD  r4   r4   r5   r=    rU  zChi._atneginfc                 C   rV  r   rY  r   r4   r4   r5   r@    rJ  zChi._minusfactorc                 C   rX  r   rW  rH  r4   r4   r5   r?    rZ  zChi._Ifactorc                 K   s.   t  t d t|ttt t |  d  S r   )r	   r
   r*  r   r   r4   r4   r5   r    	  r   zChi._eval_rewrite_as_expintc                 C   r[  rK  r\  r]  r4   r4   r5   r   	  r^  zChi._eval_as_leading_termN)r   r   r   r   r    r>  r   r   r;  r   r<  r=  r@  r?  r   r   r4   r4   r4   r5   r
    s    J



r
  c                   @   sJ   e Zd ZdZdZedd ZdddZdd	 ZeZ	d
d Z
dd ZeZdS )FresnelIntegralz& Base class for the Fresnel integrals.Tc                 C   s   |t ju rt jS |jrt jS t j}|}d}|d}|d ur%| }|}d}|t}|d ur9| jt | }|}d}|rA|| | S d S )NFr   T)	r   rH   r|   rL   r,   rI   rP   r	   _sign)rS   ro   ZprefactZnewargchangedr   r4   r4   r5   rV   	  s(   


zFresnelIntegral.evalr8   c                 C   s0   |dkr|  tjt | jd d  S t| |r   )r>  r   r|   r
   r)   r   r;   r4   r4   r5   r=   ;	  r   zFresnelIntegral.fdiffc                 C   r   r`   rh   rc   r4   r4   r5   r   A	  r   z&FresnelIntegral._eval_is_extended_realc                 C   r   r`   r   rc   r4   r4   r5   rr   F	  r   zFresnelIntegral._eval_is_zeroc                 C   r_   r`   ra   rc   r4   r4   r5   rd   I	  re   zFresnelIntegral._eval_conjugateNr   )r   r   r   r   r   r   rV   r=   r   rp   rr   rd   r6   r-   r4   r4   r4   r5   ra  	  s    

ra  c                       sd   e Zd ZdZeZej Ze	e
dd Zdd Zdd Zdd	 Zd
d Zdd Z fddZ  ZS )r   ay  
    Fresnel integral S.

    Explanation
    ===========

    This function is defined by

    .. math:: \operatorname{S}(z) = \int_0^z \sin{\frac{\pi}{2} t^2} \mathrm{d}t.

    It is an entire function.

    Examples
    ========

    >>> from sympy import I, oo, fresnels
    >>> from sympy.abc import z

    Several special values are known:

    >>> fresnels(0)
    0
    >>> fresnels(oo)
    1/2
    >>> fresnels(-oo)
    -1/2
    >>> fresnels(I*oo)
    -I/2
    >>> fresnels(-I*oo)
    I/2

    In general one can pull out factors of -1 and $i$ from the argument:

    >>> fresnels(-z)
    -fresnels(z)
    >>> fresnels(I*z)
    -I*fresnels(z)

    The Fresnel S integral obeys the mirror symmetry
    $\overline{S(z)} = S(\bar{z})$:

    >>> from sympy import conjugate
    >>> conjugate(fresnels(z))
    fresnels(conjugate(z))

    Differentiation with respect to $z$ is supported:

    >>> from sympy import diff
    >>> diff(fresnels(z), z)
    sin(pi*z**2/2)

    Defining the Fresnel functions via an integral:

    >>> from sympy import integrate, pi, sin, expand_func
    >>> integrate(sin(pi*z**2/2), z)
    3*fresnels(z)*gamma(3/4)/(4*gamma(7/4))
    >>> expand_func(integrate(sin(pi*z**2/2), z))
    fresnels(z)

    We can numerically evaluate the Fresnel integral to arbitrary precision
    on the whole complex plane:

    >>> fresnels(2).evalf(30)
    0.343415678363698242195300815958

    >>> fresnels(-2*I).evalf(30)
    0.343415678363698242195300815958*I

    See Also
    ========

    fresnelc: Fresnel cosine integral.

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Fresnel_integral
    .. [2] https://dlmf.nist.gov/7
    .. [3] https://mathworld.wolfram.com/FresnelIntegrals.html
    .. [4] https://functions.wolfram.com/GammaBetaErf/FresnelS
    .. [5] The converging factors for the fresnel integrals
            by John W. Wrench Jr. and Vicki Alley

    c                 G   s   | dk rt jS t|}t|dkr6|d }td  |d  d|  d  d|  d|  d  d|  d   | S |d |d  |   t dd|  d  td|  d    d|  d td|  d   S )	Nr   r8   r   r(         r   rX   r   r,   r   rY   r
   r   r[   r2   r\   rR  r4   r4   r5   r^   	  s   BVzfresnels.taylor_termc                 K   sN   t jt d tt jt d tt | ttt jt d tt |    S Nrd  r(   r   rI   r	   r7   r   r
   r   r4   r4   r5   r   	     Nzfresnels._eval_rewrite_as_erfc                 K   sF   t |d  d ttddgtddtddgt d  |d  d  S )Nr      rd  r(         )r
   r%   r   r   r4   r4   r5   r   	  s   Fzfresnels._eval_rewrite_as_hyperc              	   K   sr   t |tdd  td|d tdd  | tdd   tg dgtddgtdddgt d  |d  d  S )N	   rd  r(   r   r8   r   rm  )r
   r   r   r&   r   r4   r4   r5   r   	  s   :4z!fresnels._eval_rewrite_as_meijergc                 K   >   ddl m} ttd|gj}|tt|d  d |d|fS Nr   r  rU   r(   )r  r  r   r   r  r#   r
   r  r4   r4   r5   r  	      z"fresnels._eval_rewrite_as_Integralc                 C   s   ddl m} | jd j|||d}||d}|tju r+|j|dt|j	r'dndd}|j
r6t|d  d S |tjtjfv rQ|tju rEd	nd
}|tj ||| S | |S )Nr   r   r   r   r   r   r   rk  r8   r   )r   r   r)   r   r   r   r   r   r   r  rL   r
   rH   rJ   r|   r.   r/   r2   r   r   r   rT   r   r   r4   r4   r5   r   	  s   

zfresnels._eval_as_leading_termc           
         s
  ddl m} |d }|tjtj fv r|| jd  fddtd D }dd  g fddtd D  }dd |D }d	d |D }|tju rNdnd
}	|	tj td t|  t	d t|   
|tdt |  |d   | S t  |||S )Nr   r   c                    n   g | ]3}d | d  k rt j| td | d  dd| d  d | d   dd|   td|   qS rd  r   r8   r(   rN  r   r[   ro   r4   r5   r   	      6z*fresnels._eval_aseries.<locals>.<listcomp>r8   r(   c                    v   g | ]7}d | d  k rt j| td | d  dd| d  d | d   dd| d   td| d   qS rd  r8   r(   rN  r   ru  r4   r5   r   	      >c                 S      g | ]}t d t  | qS r'  r   r
   r   rU   r4   r4   r5   r   	      c                 S   rz  r'  r{  r|  r4   r4   r5   r   	  r}  r   )r   r   r   rH   r)   r   r|   r#   r   r"   r   r   r
   r   r   
r/   r[   r   r2   r   r   r   rR  rS  r   r   ru  r5   r   	  s&   
.zfresnels._eval_aseries)r   r   r   r   r#   r>  r   rI   rb  r   r   r^   r   r   r   r  r   r   r   r4   r4   r   r5   r   O	  s    Tr   c                       sb   e Zd ZdZeZejZe	e
dd Zdd Zdd Zdd	 Zd
d Zdd Z fddZ  ZS )r   au  
    Fresnel integral C.

    Explanation
    ===========

    This function is defined by

    .. math:: \operatorname{C}(z) = \int_0^z \cos{\frac{\pi}{2} t^2} \mathrm{d}t.

    It is an entire function.

    Examples
    ========

    >>> from sympy import I, oo, fresnelc
    >>> from sympy.abc import z

    Several special values are known:

    >>> fresnelc(0)
    0
    >>> fresnelc(oo)
    1/2
    >>> fresnelc(-oo)
    -1/2
    >>> fresnelc(I*oo)
    I/2
    >>> fresnelc(-I*oo)
    -I/2

    In general one can pull out factors of -1 and $i$ from the argument:

    >>> fresnelc(-z)
    -fresnelc(z)
    >>> fresnelc(I*z)
    I*fresnelc(z)

    The Fresnel C integral obeys the mirror symmetry
    $\overline{C(z)} = C(\bar{z})$:

    >>> from sympy import conjugate
    >>> conjugate(fresnelc(z))
    fresnelc(conjugate(z))

    Differentiation with respect to $z$ is supported:

    >>> from sympy import diff
    >>> diff(fresnelc(z), z)
    cos(pi*z**2/2)

    Defining the Fresnel functions via an integral:

    >>> from sympy import integrate, pi, cos, expand_func
    >>> integrate(cos(pi*z**2/2), z)
    fresnelc(z)*gamma(1/4)/(4*gamma(5/4))
    >>> expand_func(integrate(cos(pi*z**2/2), z))
    fresnelc(z)

    We can numerically evaluate the Fresnel integral to arbitrary precision
    on the whole complex plane:

    >>> fresnelc(2).evalf(30)
    0.488253406075340754500223503357

    >>> fresnelc(-2*I).evalf(30)
    -0.488253406075340754500223503357*I

    See Also
    ========

    fresnels: Fresnel sine integral.

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Fresnel_integral
    .. [2] https://dlmf.nist.gov/7
    .. [3] https://mathworld.wolfram.com/FresnelIntegrals.html
    .. [4] https://functions.wolfram.com/GammaBetaErf/FresnelC
    .. [5] The converging factors for the fresnel integrals
            by John W. Wrench Jr. and Vicki Alley

    c                 G   s   | dk rt jS t|}t|dkr6|d }td  |d  d|  d  d|  d|  d  d|  d   | S ||d  |   t dd|   td|     d|  d td|    S )	Nr   r8   r   r(   rd  r   re  rX   rf  rg  r4   r4   r5   r^   H
  s   BFzfresnelc.taylor_termc                 K   sN   t jt d tt jt d tt | ttt jt d tt |    S rh  ri  r   r4   r4   r5   r   U
  rj  zfresnelc._eval_rewrite_as_erfc                 K   s6   |t tddgtjtddgtd  |d  d  S )Nr8   rd     r(   rm  )r%   r   r   r|   r
   r   r4   r4   r5   r   X
  s   6zfresnelc._eval_rewrite_as_hyperc              	   K   sj   t |tdd  tdt|d d t| d  tg dgtddgtdddgt d  |d  d  S )Nr   rd  r(   r8   r   rm  )r
   r   r   r   r&   r   r4   r4   r5   r   [
  s   24z!fresnelc._eval_rewrite_as_meijergc                 K   ro  rp  )r  r  r   r   r  r"   r
   r  r4   r4   r5   r  _
  rq  z"fresnelc._eval_rewrite_as_Integralc                 C   s   ddl m} | jd j|||d}||d}|tju r+|j|dt|j	r'dndd}|j
r0|S |tjtjfv rK|tju r?dnd}|tj ||| S | |S )	Nr   r   r   r   r   r   r8   r   )r   r   r)   r   r   r   r   r   r   r  rL   rH   rJ   r|   r.   rr  r4   r4   r5   r   d
  s   

zfresnelc._eval_as_leading_termc           
         s  ddl m} |d }|tjtj fv r{| jd  fddt D }dd  g fddtd D  }dd |D }d	d |D }|tju rMdnd
}	|	tj td t|  t	d t|   
|tdt |  |d   | S t  |||S )Nr   r   c                    rs  rt  rN  r   ru  r4   r5   r   }
  rv  z*fresnelc._eval_aseries.<locals>.<listcomp>r8   r(   c                    rw  rx  rN  r   ru  r4   r5   r   
  ry  c                 S   rz  r'  r{  r|  r4   r4   r5   r   
  r}  c                 S   s   g | ]
}t d t | qS r'  r{  r|  r4   r4   r5   r   
  r  r   )r   r   r   rH   r)   r   r|   r"   r   r#   r   r   r
   r   r   r~  r   ru  r5   r   s
  s&   
.zfresnelc._eval_aseries)r   r   r   r   r"   r>  r   rI   rb  r   r   r^   r   r   r   r  r   r   r   r4   r4   r   r5   r   	  s    Tr   c                       s>   e Zd ZdZedd Z fddZdddZd	d
 Z  Z	S )r   zi
    Helper function to make the $\mathrm{erf}(z)$ function
    tractable for the Gruntz algorithm.

    c                 C   s   |j rtjS d S r   )rL   r   rI   )rS   rT   r4   r4   r5   rV   
  s   z
_erfs.evalc           
         s   ddl m} |d }|tju r7| jd   fddt|D }|d d| d   |}t| |||| S |t	}	|	tju ri| jd   fddt|D }|d d| d   |}t| |||| S t
 ||||S )Nr   r   c                    P   g | ]$}d t t td|  td |   t| d   d| d    qS r8   r(   rd  r   r
   r   r   r   r   r4   r5   r   
      z'_erfs._eval_aseries.<locals>.<listcomp>r8   r(   c                    r  r  r  r   r   r4   r5   r   
  r  )r   r   r   rH   r)   r   r   r  rP   r	   r   r   )
r/   r[   r   r2   r   r   r   lorU   r   r   r5   r   
  s$   






z_erfs._eval_aseriesr8   c                 C   s8   |dkr| j d }dtt d| t|  S t| |)Nr8   r   rX   r(   )r)   r   r
   r   r   r/   r<   ro   r4   r4   r5   r=   
  s   

z_erfs.fdiffc                 K   s   t jt| t|d  S r   )r   rI   r7   r   r   r4   r4   r5   _eval_rewrite_as_intractable
  s   z"_erfs._eval_rewrite_as_intractabler   )
r   r   r   r   r   rV   r   r=   r  r   r4   r4   r   r5   r   
  s    

r   c                       sL   e Zd ZdZ fddZdddZdd Z fd	d
Zd fdd	Z  Z	S )r  z~
    Helper function to make the $\mathrm{Ei}(z)$ and $\mathrm{li}(z)$
    functions tractable for the Gruntz algorithm.

    c                    s~   ddl m} |d tjtjfvrt ||||S | jd   fddt|D }|d |d   |}t	| 
|||| S )Nr   r   c                    s$   g | ]}t |d   |d    qS r   r  r   r   r4   r5   r   
  r)  z&_eis._eval_aseries.<locals>.<listcomp>r8   )r   r   r   rH   rJ   r   r   r)   r   r   r  )r/   r[   r   r2   r   r   r  r  r   r   r5   r   
  s   
z_eis._eval_aseriesr8   c                 C   s.   |dkr| j d }tj| t| S t| |)Nr8   r   )r)   r   rI   r  r   r  r4   r4   r5   r=   
  s   

z
_eis.fdiffc                 K   s   t | t| S r   )r   r   r   r4   r4   r5   r  
  r   z!_eis._eval_rewrite_as_intractablec                    sF   | j d |d}|jr| j| j  }|j|||dS t j|||dS )Nr   r   )r)   r   rL   r  r   r   )r/   r2   r   r   r  r  r   r4   r5   r   
  s
   z_eis._eval_as_leading_termr   c                    r  r`   )r)   r   rL   r  r  r   r  r   r4   r5   r  
  r  z_eis._eval_nseriesr   r  )
r   r   r   r   r   r=   r  r   r  r   r4   r4   r   r5   r  
  s    
r  N)T)Pr   Z
sympy.corer   Zsympy.core.addr   Zsympy.core.cacher   Zsympy.core.functionr   r   r   Zsympy.core.logicr   Zsympy.core.numbersr	   r
   r   r   Zsympy.core.relationalr   Zsympy.core.powerr   Zsympy.core.singletonr   Zsympy.core.symbolr   r   Zsympy.core.sympifyr   Z(sympy.functions.combinatorial.factorialsr   r   r   Z$sympy.functions.elementary.complexesr   r   r   Z#sympy.functions.elementary.integersr   r   Z(sympy.functions.elementary.miscellaneousr   r   Z&sympy.functions.elementary.exponentialr   r   r   Z%sympy.functions.elementary.hyperbolicr    r!   Z(sympy.functions.elementary.trigonometricr"   r#   r$   Zsympy.functions.special.hyperr%   r&   r6   r7   r   r   r   rB   rN   rO   r   r   r*  r  r3  r:  r7  r6  r	  r
  ra  r   r   r   r  r4   r4   r4   r5   <module>   sl    
 p C A ]Sa 8 A# (`? 	 ju8 " '1