
    g3                       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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,m-Z-m.Z. ddl/m0Z0m1Z1m2Z2 ddl3m4Z4m5Z5 dBdZ6 G d de          Z7 G d de          Z8 G d de          Z9 G d de          Z: G d de          Z; G d  d!e          Z< G d" d#e          Z= G d$ d%e          Z> G d& d'e          Z?d( Z@ G d) d*e          ZA G d+ d,e          ZB G d- d.e          ZC G d/ d0eC          ZD G d1 d2eC          ZE G d3 d4eC          ZF G d5 d6eC          ZG G d7 d8e          ZH G d9 d:eH          ZI G d; d<eH          ZJ G d= d>e          ZK G d? d@e          ZLdAS )Cz This module contains various functions that are special cases
    of incomplete gamma functions. It should probably be renamed.     )
EulerGamma)Add)cacheit)FunctionArgumentIndexError
expand_mul)IpiRational)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                 R   | j         d         j        r/|rd|d<    | j        |fi |t          j        fS | t          j        fS |r/ | j         d         j        |fi |                                \  }}n"| j         d                                         \  }}|                     |t          |z  z             |                     |t          |z  z
            z   dz  }|                     |t          |z  z             |                     |t          |z  z
            z
  dt          z  z  }||fS )Nr   Fcomplex   )argsis_extended_realexpandr   Zeroas_real_imagfuncr	   )selfdeephintsxyr   ims          c/var/www/html/ai-engine/env/lib/python3.11/site-packages/sympy/functions/special/error_functions.pyreal_to_real_as_real_imagr6      s"   y|$ " 	"$E)DK....77!&>! +"ty|"411511>>@@11y|((**1
))A!G

tyyQqS11
11	4B
))A!G

tyyQqS11
1AaC	8B8O    c                        e Zd ZdZdZddZddZed             Ze	e
d                         Zd Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zd ZddZd Zd ZddZ fdZeZ xZS )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                     |dk    r6dt          | j        d         dz             z  t          t                    z  S t	          | |          Nr:   r(   r   r   r)   r   r
   r   r/   argindexs     r5   fdiffz	erf.fdiff   sF    q==S$)A,/)***48833$T8444r7   c                     t           S z8
        Returns the inverse of this function.

        erfinvr>   s     r5   inversezerf.inverse   s	    
 r7   c                    |j         ra|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                    rt          j        |j        d         z
  S |j        rt          j        S t          |t                    r|j        d         j        r|j        d         S |                    t                    }|t          j        t          j        fv r|S |                                r | |            S d S Nr   r:   )	is_Numberr   NaNInfinityOneNegativeInfinityNegativeOneis_zeror,   
isinstancerD   r)   erfcinverf2invextract_multiplicativelyr	   could_extract_minus_signclsargts      r5   evalzerf.eval   s>   = 	ae||u
""u***}$ vc6"" 	 HQKc7## 	'538A;&&; 	6M c7## 	(; 	8A; ((++Q/000J '')) 	CII:	 	r7   c                 v   | dk     s	| dz  dk    rt           j        S t          |          }t          | dz
  t          d          z            }t	          |          dk    r|d          |dz  z  | dz
  z  | |z  z  S dt           j        |z  z  || z  z  | t          |          z  t          t                    z  z  S Nr   r(   r:   )	r   r,   r   r   lenrM   r   r   r
   nr2   previous_termsks       r5   taylor_termzerf.taylor_term   s     q55AEQJJ6M

Aq1uaddl##A>""Q&&&r**QT1QU;QqSAA))AqD0!IaLL.b2IJJr7   c                 f    |                      | j        d                                                   S Nr   r.   r)   	conjugater/   s    r5   _eval_conjugatezerf._eval_conjugate   &    yy1//11222r7   c                 &    | j         d         j        S rc   r)   r*   rf   s    r5   _eval_is_realzerf._eval_is_real       y|,,r7   c                 N    | j         d         j        rdS | j         d         j        S Nr   T)r)   	is_finiter*   rf   s    r5   _eval_is_finitezerf._eval_is_finite   s'    9Q<! 	149Q<00r7   c                 &    | j         d         j        S rc   r)   rN   rf   s    r5   _eval_is_zerozerf._eval_is_zero       y|##r7   c                     ddl m} t          |dz            |z  t          j         |t          j        |dz            t          t                    z  z
  z  S Nr   
uppergammar(   'sympy.functions.special.gamma_functionsrx   r   r   rK   Halfr
   r/   zkwargsrx   s       r5   _eval_rewrite_as_uppergammazerf._eval_rewrite_as_uppergamma   sQ    FFFFFFAqDzz!|QUZZ1%=%=d2hh%FFGGr7   c                     t           j        t          z
  |z  t          t                    z  }t           j        t          z   t          |          t          t          |          z  z
  z  S Nr   rK   r	   r   r
   fresnelcfresnelsr/   r}   r~   rV   s       r5   _eval_rewrite_as_fresnelszerf._eval_rewrite_as_fresnels   B    uqy!mDHH$	HSMMAhsmmO;<<r7   c                     t           j        t          z
  |z  t          t                    z  }t           j        t          z   t          |          t          t          |          z  z
  z  S r   r   r   s       r5   _eval_rewrite_as_fresnelczerf._eval_rewrite_as_fresnelc   r   r7   c           
          |t          t                    z  t          t          j        gg dgt          dd          g|dz            z  S Nr   r(   r   r
   r%   r   r{   r   r/   r}   r~   s      r5   _eval_rewrite_as_meijergzerf._eval_rewrite_as_meijerg   s<    bz'16(Bhr1oo5F1MMMMr7   c                     d|z  t          t                    z  t          t          j        gdt          j        z  g|dz             z  S Nr(      r   r
   r$   r   r{   r   s      r5   _eval_rewrite_as_hyperzerf._eval_rewrite_as_hyper   s9    s488|E16(QqvXJA>>>>r7   c                     t          |dz            |z  |t          t          j        |dz            z  t          t                    z  z
  S Nr(   r   expintr   r{   r
   r   s      r5   _eval_rewrite_as_expintzerf._eval_rewrite_as_expint   s;    AqDzz!|aqvq!t 4 44T"XX===r7   Nc                    ddl m} |rV |||t          j                  }|t          j        u r1t          j        t          |           t          |dz             z  z   S t          j        t          |          t          |dz             z  z
  S )Nr   )limitr(   )	sympy.series.limitsr   r   rJ   rL   rM   _erfsr   rK   )r/   r}   limitvarr~   r   lims         r5   _eval_rewrite_as_tractablezerf._eval_rewrite_as_tractable   s    ------ 	<%8QZ00Ca(((}uaRyyadU';;;uuQxxQTE

***r7   c                 :    t           j        t          |          z
  S r   )r   rK   erfcr   s      r5   _eval_rewrite_as_erfczerf._eval_rewrite_as_erfc   s    utAwwr7   c                 B    t            t          t           |z            z  S r   r	   erfir   s      r5   _eval_rewrite_as_erfizerf._eval_rewrite_as_erfi   s    r$qs))|r7   r   c                 N   | j         d                             |||          }|                    |d          }|t          j        u r |                    |d|dk    rdnd          }||j        v r!|j        rd|z  t          t                    z  S | 
                    |          S )Nr   logxcdirr   -+dirr(   )r)   as_leading_termsubsr   ComplexInfinityr   free_symbolsrN   r   r
   r.   r/   r2   r   r   rV   arg0s         r5   _eval_as_leading_termzerf._eval_as_leading_term   s    il**14d*CCxx1~~1$$$99Qdbjjssc9BBD   T\ S5b>!99T??"r7   c                 @   ddl m} |d         }|t          j        t          j        fv r| j        d         	                     |          \  }}n# t          t          f$ r | cY S w xY w| }|j	        rt          ||z            }	fdt          |	          D              |d|	z  z  |          gz   }
t          j        t          dz             t          t                    z  t!          |
 z  z
  S t#          t$          |                               ||||          S )Nr   Orderc                 ~    g | ]9}t           j        |z  t          d |z  dz
            z  d |z  dz   z  d |z  z  z  :S r(   r:   )r   rM   r   .0r`   r}   s     r5   
<listcomp>z%erf._eval_aseries.<locals>.<listcomp>  s`     + + + ]A%
1Q37(;(;;q1Q37|aQRd?RS + + +r7   r:   r(   )sympy.series.orderr   r   rJ   rL   r)   leadterm
ValueErrorNotImplementedErroris_positiver   rangerK   r   r   r
   r   superr9   _eval_aseries)r/   r^   args0r2   r   r   point_exnewnsr}   	__class__s              @r5   r   zerf._eval_aseries   sD   ,,,,,,aQZ!3444	!A

122 34    B~ ?qt}}+ + + +#Dkk+ + +.3eAagIq.A.A-BCuQTE

488 3sAw>>>S$--a4@@@s   A A('A(r:   r   rc   )__name__
__module____qualname____doc__
unbranchedr@   rE   classmethodrX   staticmethodr   ra   rg   rk   rp   rs   r   r   r   r   r   r   r   r   r   r   r   r6   r-   __classcell__r   s   @r5   r9   r9   0   s       J JX J5 5 5 5      [B 	K 	K W \	K3 3 3- - -1 1 1$ $ $H H H= = == = =N N N? ? ?> > >+ + + +    	# 	# 	# 	#A A A A A* -LLLLLr7   r9   c                       e Zd ZdZdZddZddZed             Ze	e
d                         Zd Zd	 ZddZd Zd Zd Zd Zd Zd Zd Zd Zd ZddZeZ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

    Tr:   c                     |dk    r6dt          | j        d         dz             z  t          t                    z  S t	          | |          )Nr:   r[   r   r(   r=   r>   s     r5   r@   z
erfc.fdiff`  sF    q==c49Q<?*+++DHH44$T8444r7   c                     t           S rB   rP   r>   s     r5   rE   zerfc.inversef  s	    
 r7   c                    |j         rG|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         z
  S t          |t                    r|j	        d         S |j        rt          j        S |                    t                    }|t          j        t          j        fv r| S |                                rd | |           z
  S d S )Nr   r(   )rH   r   rI   rJ   r,   rN   rK   rO   rD   r)   rP   rR   r	   rL   rS   rT   s      r5   rX   z	erfc.evalm  s    = 	ae||u
""v uc6"" 	'538A;&&c7## 	8A;; 	5L ((++Q/0004K '')) 	!ssC4yy= 	! 	!r7   c                    | dk    rt           j        S | dk     s	| dz  dk    rt           j        S t          |          }t	          | dz
  t          d          z            }t          |          dk    r|d          |dz  z  | dz
  z  | |z  z  S dt           j        |z  z  || z  z  | t          |          z  t          t                    z  z  S rZ   )
r   rK   r,   r   r   r\   rM   r   r   r
   r]   s       r5   ra   zerfc.taylor_term  s     665LUUa!eqjj6M

Aq1uaddl##A>""Q&&&r**QT1QU;QqSAA!-**QT11Yq\\>$r((3JKKr7   c                 f    |                      | j        d                                                   S rc   rd   rf   s    r5   rg   zerfc._eval_conjugate  rh   r7   c                 &    | j         d         j        S rc   rj   rf   s    r5   rk   zerfc._eval_is_real  rl   r7   Nc                 b    |                      t                                         dd|          S N	tractableT)r0   r   rewriter9   r/   r}   r   r~   s       r5   r   zerfc._eval_rewrite_as_tractable  )    ||C  ((4((SSSr7   c                 :    t           j        t          |          z
  S r   )r   rK   r9   r   s      r5   _eval_rewrite_as_erfzerfc._eval_rewrite_as_erf  s    us1vv~r7   c                 Z    t           j        t          t          t          |z            z  z   S r   )r   rK   r	   r   r   s      r5   r   zerfc._eval_rewrite_as_erfi  s    uqac{""r7   c                     t           j        t          z
  |z  t          t                    z  }t           j        t           j        t          z   t          |          t          t          |          z  z
  z  z
  S r   r   r   s       r5   r   zerfc._eval_rewrite_as_fresnels  sI    uqy!mDHH$u	HSMMAhsmmO$CDDDr7   c                     t           j        t          z
  |z  t          t                    z  }t           j        t           j        t          z   t          |          t          t          |          z  z
  z  z
  S r   r   r   s       r5   r   zerfc._eval_rewrite_as_fresnelc  sI    uQwk$r(("u	HSMMAhsmmO$CDDDr7   c                     t           j        |t          t                    z  t	          t           j        gg dgt          dd          g|dz            z  z
  S r   )r   rK   r   r
   r%   r{   r   r   s      r5   r   zerfc._eval_rewrite_as_meijerg  sF    uqbz'16(Bhr1oo=NPQSTPT"U"UUUUr7   c                     t           j        d|z  t          t                    z  t	          t           j        gdt           j        z  g|dz             z  z
  S r   )r   rK   r   r
   r$   r{   r   s      r5   r   zerfc._eval_rewrite_as_hyper  s@    uqs488|E16(QqvXJA$F$FFFFr7   c                     ddl m} t          j        t	          |dz            |z  t          j         |t          j        |dz            t	          t                    z  z
  z  z
  S rv   )rz   rx   r   rK   r   r{   r
   r|   s       r5   r   z erfc._eval_rewrite_as_uppergamma  sX    FFFFFFutAqDzz!|QUZZ1-E-Ed2hh-N%NOOOr7   c                     t           j        t          |dz            |z  z
  |t          t           j        |dz            z  t          t
                    z  z   S r   )r   rK   r   r   r{   r
   r   s      r5   r   zerfc._eval_rewrite_as_expint  sB    utAqDzz!|#aqvq!t(<(<&<T"XX&EEEr7   c                 6    |                      t                    S r   r   r/   r1   s     r5   _eval_expand_funczerfc._eval_expand_func      ||C   r7   r   c                     | j         d                             |||          }|                    |d          }|t          j        u r |                    |d|dk    rdnd          }|j        rt          j        S |                     |          S )Nr   r   r   r   r   r   )	r)   r   r   r   r   r   rN   rK   r.   r   s         r5   r   zerfc._eval_as_leading_term  s    il**14d*CCxx1~~1$$$99Qdbjjssc9BBD< 	#5L99T??"r7   c                 d    t           j        t          | j                             ||||          z
  S r   )r   rK   r9   r)   r   )r/   r^   r   r2   r   s        r5   r   zerfc._eval_aseries  s)    usDI44Qq$GGGGr7   r   r   rc   )r   r   r   r   r   r@   rE   r   rX   r   r   ra   rg   rk   r   r   r   r   r   r   r   r   r   r   r   r6   r-   r    r7   r5   r   r     s       J JX J5 5 5 5    ! ! [!6 L L W \L3 3 3- - -T T T T  # # #E E EE E EV V VG G GP P PF F F! ! !	# 	# 	# 	# -LH H H H Hr7   r   c                        e Zd ZdZdZddZed             Zee	d                         Z
d Zd Zd	 ZddZd Zd Zd Zd Zd Zd Zd Zd Zd ZeZddZ fdZ x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

    Tr:   c                     |dk    r5dt          | j        d         dz            z  t          t                    z  S t	          | |          r<   r=   r>   s     r5   r@   z
erfi.fdiff  sC    q==S1q)))$r((22$T8444r7   c                    |j         rG|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                    }||t          j        u rt          S t          |t                    rt          |j        d         z  S t          |t                    r"t          t          j        |j        d         z
  z  S t          |t                    r)|j        d         j        rt          |j        d         z  S d S d S d S rG   )rH   r   rI   rN   r,   rJ   rS   rR   r	   rO   rD   r)   rP   rK   rQ   rU   r}   nzs      r5   rX   z	erfi.eval"  s?   ; 	"AEzzu "vajz!9 	6M %%'' 	CGG8O ''**>QZ"f%% $|#"g&& .!%"'!*,--"g&& $271:+= $|# >$ $ $ $r7   c                 T   | dk     s	| dz  dk    rt           j        S t          |          }t          | dz
  t          d          z            }t	          |          dk    r|d         |dz  z  | dz
  z  | |z  z  S d|| z  z  | t          |          z  t          t                    z  z  S rZ   )r   r,   r   r   r\   r   r   r
   r]   s       r5   ra   zerfi.taylor_term@  s     q55AEQJJ6M

Aq1uaddl##A>""Q&&%b)AqD0AE:AaC@@1a4x9Q<<R!899r7   c                 f    |                      | j        d                                                   S rc   rd   rf   s    r5   rg   zerfi._eval_conjugateM  rh   r7   c                 &    | j         d         j        S rc   rj   rf   s    r5   _eval_is_extended_realzerfi._eval_is_extended_realP  rl   r7   c                 &    | j         d         j        S rc   rr   rf   s    r5   rs   zerfi._eval_is_zeroS  rt   r7   Nc                 b    |                      t                                         dd|          S r   r   r   s       r5   r   zerfi._eval_rewrite_as_tractableV  r   r7   c                 B    t            t          t           |z            z  S r   )r	   r9   r   s      r5   r   zerfi._eval_rewrite_as_erfY  s    r#ac(({r7   c                 P    t           t          t           |z            z  t           z
  S r   )r	   r   r   s      r5   r   zerfi._eval_rewrite_as_erfc\  s    ac{Qr7   c                     t           j        t          z   |z  t          t                    z  }t           j        t          z
  t          |          t          t          |          z  z
  z  S r   r   r   s       r5   r   zerfi._eval_rewrite_as_fresnels_  r   r7   c                     t           j        t          z   |z  t          t                    z  }t           j        t          z
  t          |          t          t          |          z  z
  z  S r   r   r   s       r5   r   zerfi._eval_rewrite_as_fresnelcc  r   r7   c           
          |t          t                    z  t          t          j        gg dgt          dd          g|dz             z  S r   r   r   s      r5   r   zerfi._eval_rewrite_as_meijergg  s>    bz'16(Bhr1oo5FANNNNr7   c                     d|z  t          t                    z  t          t          j        gdt          j        z  g|dz            z  S r   r   r   s      r5   r   zerfi._eval_rewrite_as_hyperj  s7    s488|E16(QqvXJ1====r7   c                     ddl m} t          |dz             |z   |t          j        |dz             t          t
                    z  t          j        z
  z  S rv   )rz   rx   r   r   r{   r
   rK   r|   s       r5   r   z erfi._eval_rewrite_as_uppergammam  sU    FFFFFFQTE{{1}jj!Q$77R@15HIIr7   c                     t          |dz             |z  |t          t          j        |dz             z  t          t                    z  z
  S r   r   r   s      r5   r   zerfi._eval_rewrite_as_expintq  s?    QTE{{1}qA!6!66tBxx???r7   c                 6    |                      t                    S r   r   r   s     r5   r   zerfi._eval_expand_funct  r   r7   r   c                 *   | j         d                             |||          }|                    |d          }||j        v r!|j        rd|z  t          t                    z  S |j        r|                     |          S |                     |          S )Nr   r   r(   )	r)   r   r   r   rN   r   r
   ro   r.   r   s         r5   r   zerfi._eval_as_leading_termy  s    il**14d*CCxx1~~   T\ S5b>!^ 	#99T??"yy~~r7   c                    ddl m} |d         }|t          j        u rv| j        d         fdt          |          D              |d|z  z  |          gz   }t           t          dz            t          t                    z  t          | z  z   S t          t          |                               ||||          S )Nr   r   c                 ^    g | ])}t          d |z  dz
            d |z  d |z  dz   z  z  z  *S r   )r   r   s     r5   r   z&erfi._eval_aseries.<locals>.<listcomp>  sS     ' ' ' AaC!G$$1q1Q37|(;< ' ' 'r7   r:   r(   )r   r   r   rJ   r)   r   r	   r   r   r
   r   r   r   r   
r/   r^   r   r2   r   r   r   r   r}   r   s
           @r5   r   zerfi._eval_aseries  s    ,,,,,,aAJ	!A' ' ' '"1XX' ' '*/%!Q$*:*:);<A2QT488+sAw666T4  ..q%DAAAr7   r   r   rc   )r   r   r   r   r   r@   r   rX   r   r   ra   rg   r   rs   r   r   r   r   r   r   r   r   r   r   r6   r-   r   r   r   r   s   @r5   r   r     s       G GR J5 5 5 5 $ $ [$: 	: 	: W \	:3 3 3- - -$ $ $T T T T    = = == = =O O O> > >J J J@ @ @! ! ! -L   
B 
B 
B 
B 
B 
B 
B 
B 
Br7   r   c                   |    e Zd ZdZd Zed             Zd Zd Zd Z	d Z
d Zd	 Zd
 Zd Zd Zd Zd Zd Z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                     | j         \  }}|dk    r+dt          |dz             z  t          t                    z  S |dk    r+dt          |dz             z  t          t                    z  S t	          | |          )Nr:   r[   r(   )r)   r   r   r
   r   r/   r?   r2   r3   s       r5   r@   z
erf2.fdiff  sq    y1q==c1a4%jj=b))]]S!Q$ZZ<R(($T8444r7   c                    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          |          z
  S t          |t                    r|j        d         |k    r|j        d         S |j	        s#|j	        s|j
        r|j        s|j
        r&|j        rt          |          t          |          z
  S |                                }|                                }|r|r | | |            S |s|rt          |          t          |          z
  S d S rG   )r   rJ   rL   r,   rI   r9   rO   rQ   r)   rN   r*   is_infiniterS   )rU   r2   r3   chksign_xsign_ys         r5   rX   z	erf2.eval  s]   z1-qv6::ae5L!VV6M#XXcq66CFF?"a!! 	afQi1nn6!99 	#	 	#Q%7 	#AM 	#"	#'(}	#q66CFF?" ++--++-- 	!v 	!CQBKK< 	! 	!q66#a&&= 	! 	!r7   c                     |                      | j        d                                         | j        d                                                   S rG   rd   rf   s    r5   rg   zerf2._eval_conjugate  s:    yy1//1149Q<3I3I3K3KLLLr7   c                 J    | j         d         j        o| j         d         j        S rG   rj   rf   s    r5   r   zerf2._eval_is_extended_real  s    y|,N11NNr7   c                 @    t          |          t          |          z
  S r   r9   r/   r2   r3   r~   s       r5   r   zerf2._eval_rewrite_as_erf  s    1vvAr7   c                 @    t          |          t          |          z
  S r   r   r  s       r5   r   zerf2._eval_rewrite_as_erfc  s    Awwa  r7   c                 p    t           t          t           |z            t          t           |z            z
  z  S r   r   r  s       r5   r   zerf2._eval_rewrite_as_erfi  s&    $qs))D1II%&&r7   c                     t          |                              t                    t          |                              t                    z
  S r   )r9   r   r   r  s       r5   r   zerf2._eval_rewrite_as_fresnels  1    1vv~~h''#a&&..*B*BBBr7   c                     t          |                              t                    t          |                              t                    z
  S r   )r9   r   r   r  s       r5   r   zerf2._eval_rewrite_as_fresnelc
  r!  r7   c                     t          |                              t                    t          |                              t                    z
  S r   )r9   r   r%   r  s       r5   r   zerf2._eval_rewrite_as_meijerg  s1    1vv~~g&&Q)@)@@@r7   c                     t          |                              t                    t          |                              t                    z
  S r   )r9   r   r$   r  s       r5   r   zerf2._eval_rewrite_as_hyper  s1    1vv~~e$$s1vv~~e'<'<<<r7   c                 T   ddl m} t          |dz            |z  t          j         |t          j        |dz            t          t                    z  z
  z  t          |dz            |z  t          j         |t          j        |dz            t          t                    z  z
  z  z
  S rv   ry   )r/   r2   r3   r~   rx   s        r5   r   z erf2._eval_rewrite_as_uppergamma  s    FFFFFFQT

1aejjA&>&>tBxx&GGHAJJqL!%**QVQT":":488"CCDE 	Fr7   c                     t          |                              t                    t          |                              t                    z
  S r   )r9   r   r   r  s       r5   r   zerf2._eval_rewrite_as_expint  s1    1vv~~f%%Av(>(>>>r7   c                 6    |                      t                    S r   r   r   s     r5   r   zerf2._eval_expand_func  r   r7   c                     t          | j         S r   )r   r)   rf   s    r5   rs   zerf2._eval_is_zero  s    di  r7   N)r   r   r   r   r@   r   rX   rg   r   r   r   r   r   r   r   r   r   r   r   rs   r   r7   r5   r  r    s        B BJ5 5 5 ! ! [!0M M MO O O  ! ! !' ' 'C C CC C CA A A= = =F F F
? ? ?! ! !! ! ! ! !r7   r  c                   D    e Zd ZdZd	dZd	dZed             Zd Zd Z	dS )
rD   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/

    r:   c                     |dk    rRt          t                    t          |                     | j        d                   dz            z  t
          j        z  S t          | |          Nr:   r   r(   r   r
   r   r.   r)   r   r{   r   r>   s     r5   r@   zerfinv.fdiffT  sR    q==88C		$)A, 7 7 :;;;AFBB$T8444r7   c                     t           S rB   r  r>   s     r5   rE   zerfinv.inverseZ  s	    
 
r7   c                    |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        rt           j        S |                    d          }|5t          |t                    r"|j
        d         j        r|j
        d          S d S d S d S Nr   r   )r   rI   rM   rL   rN   r,   rK   rJ   rO   r9   r)   r*   rR   r   s      r5   rX   zerfinv.evala  s    ::5L!-%%Y 	6M!%ZZ:a 	!&)"< 	6!99 	6M ''++>z"c22>
7T>GAJ; >>>>>r7   c                 &    t          d|z
            S Nr:   r   r   s      r5   _eval_rewrite_as_erfcinvzerfinv._eval_rewrite_as_erfcinvw  s    acllr7   c                 &    | j         d         j        S rc   rr   rf   s    r5   rs   zerfinv._eval_is_zeroz  rt   r7   Nr   )
r   r   r   r   r@   rE   r   rX   r2  rs   r   r7   r5   rD   rD   !  s        / /d5 5 5 5      [*  $ $ $ $ $r7   rD   c                   J    e Zd ZdZd
dZd
dZed             Zd Zd Z	d Z
d	S )rP   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/

    r:   c                     |dk    rSt          t                     t          |                     | j        d                   dz            z  t
          j        z  S t          | |          r+  r,  r>   s     r5   r@   zerfcinv.fdiff  sT    q==HH9S49Q<!8!8!!;<<<QVCC$T8444r7   c                     t           S rB   r  r>   s     r5   rE   zerfcinv.inverse  s	    
 r7   c                     |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   rI   rN   rJ   rK   r,   rL   rU   r}   s     r5   rX   zerfcinv.eval  sf    ::5LY 	&:!%ZZ6M!VV%%9 	:	 	r7   c                 &    t          d|z
            S r1  rC   r   s      r5   _eval_rewrite_as_erfinvzerfcinv._eval_rewrite_as_erfinv  s    ac{{r7   c                 ,    | j         d         dz
  j        S rG   rr   rf   s    r5   rs   zerfcinv._eval_is_zero  s    	!q ))r7   c                 &    | j         d         j        S rc   rr   rf   s    r5   _eval_is_infinitezerfcinv._eval_is_infinite  rt   r7   Nr   )r   r   r   r   r@   rE   r   rX   r:  rs   r=  r   r7   r5   rP   rP   ~  s        ) )X5 5 5 5      [  * * *$ $ $ $ $r7   rP   c                   4    e Zd ZdZd Zed             Zd ZdS )rQ   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                 6   | j         \  }}|dk    r,t          |                     ||          dz  |dz  z
            S |dk    rHt          t                    t
          j        z  t          |                     ||          dz            z  S t          | |          )Nr:   r(   )r)   r   r.   r   r
   r   r{   r   r  s       r5   r@   zerf2inv.fdiff  s    y1q==tyy1~~q(A-...]]88AF?3tyy1~~q'8#9#999$T8444r7   c                 &   |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        rt          |          S |t           j        u rt          |           S |j        r|S |t           j        u rt          |          S |j        r"|j        rt           j        S t          |          S |j        r|S d S r   )r   rI   rN   r,   rK   rJ   rD   rP   )rU   r2   r3   s      r5   rX   zerf2inv.eval  s   ::ae5LY 	19 	6MY 	1:::!%ZZAIZ5LY 	!99!*__A2;;Y 	H!*__!999 	!y !vayy 9 	H	 	r7   c                 >    | j         \  }}|j        r	|j        rdS d S d S )NTrr   )r/   r2   r3   s      r5   rs   zerf2inv._eval_is_zero(  s9    y19 	 	4	 	 	 	r7   N)r   r   r   r   r@   r   rX   rs   r   r7   r5   rQ   rQ     sX        0 0f5 5 5   [4    r7   rQ   c                        e Zd ZdZed             ZddZd Zd Zd Z	d Z
d	 ZeZeZeZddZd Zd fd	Zd fd	Z fdZ x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                 6   |j         rt          j        S |t          j        u rt          j        S |t          j        u rt          j        S |j         rt          j        S |                                \  }}|r%t          |          dt          z  t          z  |z  z   S d S r   )	rN   r   rL   rJ   r,   extract_branch_factorrC  r	   r
   rU   r}   r   r^   s       r5   rX   zEi.eval  s    9 	%%!*__:!$$$6M9 	&%%''))A 	%b66AaCF1H$$	% 	%r7   r:   c                     t          | j        d                   }|dk    rt          |          |z  S t          | |          rG   )r   r)   r   r   r/   r?   rV   s      r5   r@   zEi.fdiff  s>    1&&q==s88C<$T8444r7   c                     | j         d         t          d          z  j        r8t          j        | |          t
          t          z                      |          z   S t          j        | |          S r/  )r)   r   r   r   _eval_evalfr	   r
   r/   precs     r5   rJ  zEi._eval_evalf  s\    IaLB'4 	O'd33qt6H6H6N6NNN#D$///r7   c                 h    ddl m}  |dt          d          |z             t          t          z  z
  S )Nr   rw   r   )rz   rx   r   r	   r
   r|   s       r5   r   zEi._eval_rewrite_as_uppergamma  s?    FFFFFF 
1jnnQ.///!B$66r7   c                 d    t          dt          d          |z             t          t          z  z
  S )Nr:   r   )r   r   r	   r
   r   s      r5   r   zEi._eval_rewrite_as_expint  s)    q*R..*+++ad22r7   c                     t          |t                    rt          |j        d                   S t          t	          |                    S rc   )rO   r   lir)   r   r   s      r5   _eval_rewrite_as_lizEi._eval_rewrite_as_li  s:    a 	!afQi== 
 #a&&zzr7   c                     |j         r/t          |          t          |          z   t          t          z  z
  S t          |          t          |          z   S r   )is_negativeShiChir	   r
   r   s      r5   _eval_rewrite_as_SizEi._eval_rewrite_as_Si  sA    = 	#q66CFF?QrT))q66CFF?"r7   Nc                 @    t          |          t          |          z  S r   )r   _eisr   s       r5   r   zEi._eval_rewrite_as_tractable  s    1vvQr7   c                     ddl m} t          t          d|g          j                  } |t
          j        |z  |z  |t
          j        |f          S Nr   IntegralrW   )sympy.integrals.integralsr\  r   r   namer   Exp1rL   r/   r}   r~   r\  rW   s        r5   _eval_rewrite_as_IntegralzEi._eval_rewrite_as_Integral  sW    666666'aS11677x	!a);Q%?@@@r7   r   c                     ddl m} | j        d                             |d          }| j        d                             ||          }|                    ||          }|j        rt|                    |          \  }}|t          |          n|}t          |          ||z  z   t          z    ||          j
        rt          t          z  nt          j        z
  S t                                          |||          S )Nr   )r   )r   r   )sympyr   r)   r   r   r   rN   as_coeff_exponentr   r   rS  r	   r
   r   r,   r   r   )
r/   r2   r   r   r   x0rV   cer   s
            r5   r   zEi._eval_as_leading_term  s    Yq\1%%il**14*88wwq$: 	:((++DAq!\3q666tDq66AdF?Z/4,8"!&: :ww,,QT,EEEr7   c                     | j         d                             |d          }|j        r& | j        | j          }|                    |||          S t                                          |||          S rc   )r)   r   rN   rV  _eval_nseriesr   r/   r2   r^   r   r   re  fr   s          r5   ri  zEi._eval_nseries  sk    Yq\1%%: 	/(($)4A??1a...ww$$Q4000r7   c                 D   ddl m} |d         }|t          j        u rX| j        d         fdt          |          D              |d|z  z  |          gz   }t                    z  t          | z  S t          t          |           
                    ||||          S )Nr   r   c                 :    g | ]}t          |          |z  z  S r   r   r   s     r5   r   z$Ei._eval_aseries.<locals>.<listcomp>  s(    99911Q&999r7   r:   )r   r   r   rJ   r)   r   r   r   r   rC  r   r  s
           @r5   r   zEi._eval_aseries  s    ,,,,,,aAJ	!A9999a999U1QT61%%&'AFF1HQ''R,,Qq$???r7   r   r   rc   r   )r   r   r   r   r   rX   r@   rJ  r   r   rQ  rV  _eval_rewrite_as_Ci_eval_rewrite_as_Chi_eval_rewrite_as_Shir   ra  r   ri  r   r   r   s   @r5   rC  rC  1  sD       T Tn % % [%5 5 5 50 0 0
7 7 73 3 3  # # #
 ...       A A A

F 
F 
F 
F 
F 
F1 1 1 1 1 1
@ 
@ 
@ 
@ 
@ 
@ 
@ 
@ 
@r7   rC  c                   t     e Zd ZdZed             Zd Zd Zd Zd Z	d Z
e
Ze
Ze
Zd fd		Z fd
Zd Z x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           	         ddl m}m} t          |          }||k    rt	          ||          S |j        r|dk    s|j        s<d|z  j        r2t          t          ||dz
  z   |d|z
  |          z                      S |                                \  }}|t          j	        u rd S |j
        rj|dk    sd S t	          ||          dt          z  t          z  |z  t          j        |dz
  z  z  t          |dz
            z  t          |          |dz
  z  z  z
  S t          dt          z  t          z  |z  |z            dz
  ||dz
  z  z   |d|z
            z  t	          ||          z   S )Nr   )gammarx   r(   r:   )rz   ru  rx   r   r   
is_Integerr   rE  r   r,   
is_integerr
   r	   rM   r   r   )rU   nur}   ru  rx   nu2r^   s          r5   rX   zexpint.evalP  s   OOOOOOOOnn99#q>>!= 	MR1WWR]W"?PWjR!VZZB5J5J)JKKLLL &&((1;;F= 	T66"a==B$q&(1=26229R!V3D3DDZPQ]]UWZ[U[E\\] ] !Br	!$$q(!b1f+5eeAFmmCfRQRmmSSr7   c           	          | j         \  }}|dk    r%||dz
  z   t          g ddgddd|z
  gg |          z  S |dk    rt          |dz
  |           S t          | |          r+  )r)   r%   r   r   )r/   r?   rx  r}   s       r5   r@   zexpint.fdifff  sy    	Aq==QK<QFQ1r6NB J JJJ]]261%%%%$T8444r7   c                 >    ddl m} ||dz
  z   |d|z
  |          z  S )Nr   rw   r:   )rz   rx   )r/   rx  r}   r~   rx   s        r5   r   z"expint._eval_rewrite_as_uppergammao  s7    FFFFFF26{::a"fa0000r7   c           	         dk    r>t          |t          t           t          z            z             t          t          z  z
  S j        rdk    rt          |           dz
  z  t          dz
            z  t          |                              t                     z  t                    t          dz
            z  t          fdt          dz
            D              z  z   S | S )Nr:   c                 F    g | ]}t          |z
  d z
            |z  z  S r(   rn  )r   r`   rx  r2   s     r5   r   z.expint._eval_rewrite_as_Ei.<locals>.<listcomp>{  s2    HHHQiQ
++AqD0HHHr7   )rC  r   r	   r
   rv  r   r   E1r   r   r   r   )r/   rx  r}   r~   r2   s    `  @r5   _eval_rewrite_as_Eizexpint._eval_rewrite_as_Eis  s    77qA2b5)))***QrT11] 	rAvvAArAv;ya000Ar1B1BBAya(((HHHHH%Q--HHHIJJ J Kr7   c                 X     |                      t                    j         t          fi |S r   )r   rC  r   r   s     r5   r   zexpint._eval_expand_func  s)    't||B'88%888r7   c                 P    |dk    r| S t          |          t          |          z
  S r1  )rT  rU  )r/   rx  r}   r~   s       r5   rV  zexpint._eval_rewrite_as_Si  s&    77K1vvAr7   r   c                 b   | j         d                             |          sl| j         d         }|dk    r& | j        | j          }|                    |||          S |j        r,|dk    r& | j        | j          }|                    |||          S t                                          |||          S rG   )r)   hasrV  ri  rv  r  r   )r/   r2   r^   r   r   rx  rk  r   s          r5   ri  zexpint._eval_nseries  s    y|"" 	31BQww,D,di8q!T222 3266,D,di8q!T222ww$$Q4000r7   c                 d  	 ddl m} |d         }| j        d         |t          j        u rZ| j        d         		fdt          |          D              |d	|z  z  |          gz   }t          	           	z  t          | z  S t          t          |           
                    ||||          S )Nr   r   r:   c                 \    g | ](}t           j        |z  t          |          z  |z  z  )S r   )r   rM   r   )r   r`   rx  r}   s     r5   r   z(expint._eval_aseries.<locals>.<listcomp>  s8    TTTa!OB$:$::QTATTTr7   )r   r   r)   r   rJ   r   r   r   r   r   r   )r/   r^   r   r2   r   r   r   r   rx  r}   r   s           @@r5   r   zexpint._eval_aseries  s    ,,,,,,aYq\AJ	!ATTTTT5QR88TTTX]X]^_`acd`d^dfgXhXhWiiAGGAIa((VT""00E1dCCCr7   c                     ddl m} | j        \  }}t          t	          d|          j                  } ||| z  t          | |z            z  |dt          j        f          S Nr   r[  rW   r:   )	r]  r\  r)   r   r   r^  r   r   rJ   )r/   r)   r~   r\  r^   r2   rW   s          r5   ra  z expint._eval_rewrite_as_Integral  sl    666666y1'T22788xA2QBqD		)Aq!*+=>>>r7   ro  )r   r   r   r   r   rX   r@   r   r  r   rV  rp  rq  rr  ri  r   ra  r   r   s   @r5   r   r     s        d dN T T [T*5 5 51 1 1
 
 
9 9 9   ...	1 	1 	1 	1 	1 	1
D 
D 
D 
D 
D? ? ? ? ? ? ?r7   r   c                 "    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.

    r:   )r   )r}   s    r5   r  r    s    @ !Q<<r7   c                   ~    e Zd ZdZed             ZddZd Zd Zd Z	d Z
d	 ZeZd
 ZeZd Zd ZddZddZd ZdS )rP  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                     |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   )rN   r   r,   rK   rL   rJ   r8  s     r5   rX   zli.eval/  sU    9 	6M!%ZZ%%!*__:9 	6M	 	r7   r:   c                     | j         d         }|dk    rt          j        t          |          z  S t	          | |          rG   r)   r   rK   r   r   rH  s      r5   r@   zli.fdiff:  9    ilq==53s88##$T8444r7   c                 |    | j         d         }|j        s'|                     |                                          S d S rc   )r)   is_extended_negativer.   re   r/   r}   s     r5   rg   zli._eval_conjugateA  s<    IaL% 	,99Q[[]]+++	, 	,r7   c                 @    t          |          t          d          z   S r   )LirP  r   s      r5   _eval_rewrite_as_Lizli._eval_rewrite_as_LiG      !uur!uu}r7   c                 :    t          t          |                    S r   )rC  r   r   s      r5   r  zli._eval_rewrite_as_EiJ  s    #a&&zzr7   c           	      (   ddl m}  |dt          |                      t          j        t          t          |                    t          t          j        t          |          z            z
  z  z   t          t          |                     z
  S Nr   rw   )rz   rx   r   r   r{   rK   r|   s       r5   r   zli._eval_rewrite_as_uppergammaM  s    FFFFFFAAw'''CFFc!%A,&7&7789;>Aw<<H 	Ir7   c                    t          t          t          |          z            t          t          t          t          |          z            z  z
  t          j        t          t          j        t          |          z            t          t          |                    z
  z  z
  t          t          t          |          z            z
  S r   )Cir	   r   Sir   r{   rK   r   s      r5   rV  zli._eval_rewrite_as_SiR  s    1SVV8qAc!ffH~-AE#a&&L))CAKK789;>qQx==I 	Jr7   c                    t          t          |                    t          t          |                    z
  t          j        t          t          j        t          |          z            t          t          |                    z
  z  z
  S r   )rU  r   rT  r   r{   rK   r   s      r5   rr  zli._eval_rewrite_as_ShiX  sW    CFFc#a&&kk)AFCc!ff4E4ECPQFF4S,TTUr7   c           	         t          |          t          ddt          |                    z  t          j        t          t          |                    t          t          j        t          |          z            z
  z  z   t
          z   S )N)r:   r:   )r(   r(   )r   r$   r   r{   rK   r   r   s      r5   r   zli._eval_rewrite_as_hyper]  se    AuVVSVV444CFFc!%A,&7&7789;EF 	Gr7   c                 &   t          t          |                      t          j        t          t          j        t          |          z            t          t          |                    z
  z  z
  t	          ddt          |                     z
  S )N)r   r   ))r   r   r   )r   r   r{   rK   r%   r   s      r5   r   zli._eval_rewrite_as_meijerga  sg    c!ffWAE#a&&L(9(9CAKK(G HH*lSVVG<<= 	>r7   Nc                 @    |t          t          |                    z  S r   )rX  r   r   s       r5   r   zli._eval_rewrite_as_tractablee  s    4A<<r7   r   c                     | j         d         fdt          d|          D             }t          t          t                              z   t	          | z   S )Nr   c                 Z    g | ]'}t                    |z  t          |          |z  z  (S r   )r   r   r   s     r5   r   z$li._eval_nseries.<locals>.<listcomp>j  s3    CCC!c!ffq[IaLL1,-CCCr7   r:   )r)   r   r   r   r   )r/   r2   r^   r   r   r   r}   s         @r5   ri  zli._eval_nseriesh  sO    IaLCCCCuQ{{CCCCAKK'#q'11r7   c                 2    | j         d         }|j        rdS d S rn   rr   r  s     r5   rs   zli._eval_is_zerom  &    IaL9 	4	 	r7   r   r   ro  )r   r   r   r   r   rX   r@   rg   r  r  r   rV  rp  rr  rq  r   r   r   ri  rs   r   r7   r5   rP  rP    s       ` `F   [5 5 5 5, , ,    I I I
J J J .V V V 0G G G> > >       2 2 2 2
    r7   rP  c                   L    e Zd ZdZed             ZddZd Zd ZddZ	dd
Z
dS )r  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                 x    |t           j        u rt           j        S |t          d          k    rt           j        S d S r   )r   rJ   r,   r8  s     r5   rX   zLi.eval  s2    
??:!A$$YY6M Yr7   r:   c                     | j         d         }|dk    rt          j        t          |          z  S t	          | |          rG   r  rH  s      r5   r@   zLi.fdiff  r  r7   c                 \    |                      t                                        |          S r   )r   rP  evalfrK  s     r5   rJ  zLi._eval_evalf  s"    ||B%%d+++r7   c                 @    t          |          t          d          z
  S r   )rP  r   s      r5   rQ  zLi._eval_rewrite_as_li  r  r7   Nc                 `    |                      t                                         dd          S )Nr   T)r0   )r   rP  r   s       r5   r   zLi._eval_rewrite_as_tractable  s'    ||B''$'???r7   r   c                 N     | j         | j         }|                    |||          S r   )rQ  r)   ri  )r/   r2   r^   r   r   rk  s         r5   ri  zLi._eval_nseries  s)    $D$di0q!T***r7   r   r   ro  )r   r   r   r   r   rX   r@   rJ  rQ  r   ri  r   r7   r5   r  r  r  s        = =@   [5 5 5 5, , ,  @ @ @ @+ + + + + +r7   r  c                   N     e Zd ZdZed             Zd	dZd Zd Zd
 fd	Z	 xZ
S )TrigonometricIntegralz) Base class for trigonometric integrals. c                    |t           j        u r| j        S |t           j        u r|                                 S |t           j        u r|                                 S |j        r| j        S |                    t          t                              }|3|                     d          dk    r|                    t                    }||                     |d          S |                    t          t                               }||                     |d          S |                    t          d                    }|.|                     d          dk    r|                    d          }||                     |          S |                                \  }}|dk    r||k    rd S dt          z  t          z  |z  |                     d          z   | |          z   S )Nr   r:   r   r(   )r   r,   _atzerorJ   _atinfrL   	_atneginfrN   rR   r   r	   	_trigfunc_Ifactor_minusfactorrE  r
   rF  s       r5   rX   zTrigonometricIntegral.eval  s   ;;;!*__::<<!$$$==??"9 	;''
166:#--**a//++A..B><<A&&&''
A277><<B'''''
277:#--**a//++B//B>##B'''''))A66bAggFtAvaxa(((33r7722r7   r:   c                     t          | j        d                   }|dk    r|                     |          |z  S t          | |          rG   )r   r)   r  r   rH  s      r5   r@   zTrigonometricIntegral.fdiff  sE    1&&q==>>#&&s**$T8444r7   c                 \    |                      |                              t                    S r   )r   r   rC  r   s      r5   r  z)TrigonometricIntegral._eval_rewrite_as_Ei  s$    ++A..66r:::r7   c                 ^    ddl m} |                     |                              |          S r  )rz   rx   r   r   r|   s       r5   r   z1TrigonometricIntegral._eval_rewrite_as_uppergamma   s6    FFFFFF++A..66zBBBr7   r   c                 2   | j         d                             |d          dk    r#t                                          |||          S |                     |                              |||          }|                     d          dk    r|dz  }|                    t          d d          }|                     d          dk    r|t          t          |          z   z  }|                    || j         d                                       |||          S )Nr   r:   c                     | |z  |z  S r   r   )rW   r^   s     r5   <lambda>z5TrigonometricIntegral._eval_nseries.<locals>.<lambda>  s    !Q$q& r7   F)simultaneous)	r)   r   r   ri  r  replacer   r   r   )r/   r2   r^   r   r   
baseseriesr   s         r5   ri  z#TrigonometricIntegral._eval_nseries  s    9Q<Q""a''77((At444^^A&&44Q4@@
>>!!!!OJ''-@-@u'UU
>>!!!*s1vv--Jq$)A,//==aDIIIr7   r   ro  )r   r   r   r   r   rX   r@   r  r   ri  r   r   s   @r5   r  r    s        33 3 3 [3>5 5 5 5; ; ;C C C
J 
J 
J 
J 
J 
J 
J 
J 
J 
Jr7   r  c                        e Zd ZdZeZej        Ze	d             Z
e	d             Ze	d             Ze	d             Zd Zd ZeZdd
Z fdZd Z xZS )r  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                 *    t           t          j        z  S r   r
   r   r{   rU   s    r5   r  z	Si._atinf[  s    !&yr7   c                 ,    t            t          j        z  S r   r  r  s    r5   r  zSi._atneginf_  s    s16zr7   c                 "    t          |           S r   )r  r8  s     r5   r  zSi._minusfactorc  s    1vr7   c                 6    t           t          |          z  |z  S r   )r	   rT  rU   r}   signs      r5   r  zSi._Ifactorg  s    Qx}r7   c                     t           dz  t          t          t                    |z            t          t          t                     |z            z
  dz  t          z  z   S r   )r
   r  r   r	   r   s      r5   r   zSi._eval_rewrite_as_expintk  sG    !tr*Q--/**R
A2q0@-A-AA1DQFFFr7   c                     ddl m} t          t          d|g          j                  } |t          |          |d|f          S rZ  )r]  r\  r   r   r^  r#   r`  s        r5   ra  zSi._eval_rewrite_as_Integralo  sO    666666'aS11677xQ!Q+++r7   Nr   c                 :   | j         d                             |||          }|                    |d          }|t          j        u r.|                    |dt          |          j        rdnd          }|j        r|S |j	        s| 
                    |          S | S Nr   r   r   r   r   r)   r   r   r   rI   r   r   rS  rN   r  r.   r   s         r5   r   zSi._eval_as_leading_termv  s    il**14d*CCxx1~~15==99Qbhh.B'Kss9LLD< 	J! 	99T??"Kr7   c                   	 ddl m} |d         }|t          j        u r| j        d         		fdt          |dz  dz             D              |d	|z  z  |          gz   }	fdt          |dz            D              |d	|z  z  |          gz   }t          dz  t          	          t          | z  z
  t          	          t          | z  z
  S t          t          |                               ||||          S )Nr   r   c                 l    g | ]0}t           j        |z  t          d |z            z  d |z  dz   z  z  1S r   r   rM   r   r   s     r5   r   z$Si._eval_aseries.<locals>.<listcomp>  P     . . . !IacNN2Q1q\A . . .r7   r(   r:   c                 r    g | ]3}t           j        |z  t          d |z  dz             z  d |dz   z  z  z  4S r   r  r   s     r5   r   z$Si._eval_aseries.<locals>.<listcomp>  V     * * * !IacAg$6$66QAYG * * *r7   )r   r   r   rJ   r)   r   r
   r!   r   r"   r   r  r   )r/   r^   r   r2   r   r   r   pqr}   r   s            @r5   r   zSi._eval_aseries  s4   ,,,,,,a AJ	!A. . . ."1a4!8__. . .16qAvq1A1A0BCA* * * *"1a4[[* * *-2U1QT61-=-=,>?Aa4#a&&a.(3q66#q'>99 R,,Qq$???r7   c                 2    | j         d         }|j        rdS d S rn   rr   r  s     r5   rs   zSi._eval_is_zero  r  r7   rc   )r   r   r   r   r"   r  r   r,   r  r   r  r  r  r  r   ra  _eval_rewrite_as_sincr   r   rs   r   r   s   @r5   r  r    s       D DL IfG  [   [   [   [G G G, , ,
 7   @ @ @ @ @       r7   r  c                        e Zd ZdZeZej        Ze	d             Z
e	d             Ze	d             Ze	d             Zd Zd Zdd
Z fdZ xZS )r  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                     t           j        S r   )r   r,   r  s    r5   r  z	Ci._atinf  s	    vr7   c                      t           t          z  S r   )r	   r
   r  s    r5   r  zCi._atneginf  s    tr7   c                 @    t          |          t          t          z  z   S r   r  r	   r
   r8  s     r5   r  zCi._minusfactor  s    !uuqt|r7   c                 L    t          |          t          t          z  dz  |z  z   S r   rU  r	   r
   r  s      r5   r  zCi._Ifactor  s    1vv"Qt##r7   c                     t          t          t                    |z            t          t          t                     |z            z    dz  S r   )r  r   r	   r   s      r5   r   zCi._eval_rewrite_as_expint  s<    JqMM!O$$r*aR..*:';';;<Q>>r7   c                     ddl m} t          t          d|g          j                  }t
          j        t          |          z    |dt          |          z
  |z  |d|f          z
  S r  )	r]  r\  r   r   r^  r   r   r   r!   r`  s        r5   ra  zCi._eval_rewrite_as_Integral  si    666666'aS11677|c!ff$xx3q661q!Qi'H'HHHr7   Nr   c                    | j         d                             |||          }|                    |d          }|t          j        u r.|                    |dt          |          j        rdnd          }|j        rH|	                    |          \  }}|t          |          n|}t          |          ||z  z   t          z   S |j        r|                     |          S | S r  r)   r   r   r   rI   r   r   rS  rN   rd  r   r   ro   r.   r/   r2   r   r   rV   r   rf  rg  s           r5   r   zCi._eval_as_leading_term      il**14d*CCxx1~~15==99Qbhh.B'Kss9LLD< 	((++DAq!\3q666tDq66AdF?Z//^ 	99T??"Kr7   c                 >  
 ddl m} |d         }|t          j        t          j        fv r| j        d         

fdt          |dz  dz             D              |d
|z  z  |          gz   }
fdt          |dz            D              |d
|z  z  |          gz   }t          
          t          | z  t          
          t          | z  z
  }	|t          j        u r|	t          t          z  z  }	|	S t          t          |                               ||||          S )Nr   r   c                 l    g | ]0}t           j        |z  t          d |z            z  d |z  dz   z  z  1S r   r  r   s     r5   r   z$Ci._eval_aseries.<locals>.<listcomp>  r  r7   r(   r:   c                 r    g | ]3}t           j        |z  t          d |z  dz             z  d |dz   z  z  z  4S r   r  r   s     r5   r   z$Ci._eval_aseries.<locals>.<listcomp>  r  r7   )r   r   r   rJ   rL   r)   r   r"   r   r!   r	   r
   r   r  r   )r/   r^   r   r2   r   r   r   r  r  resultr}   r   s             @r5   r   zCi._eval_aseries  sP   ,,,,,,aQZ!3444	!A. . . ."1a4!8__. . .16qAvq1A1A0BCA* * * *"1a4[[* * *-2U1QT61-=-=,>?AVVS!W%AQ(88F***!B$MR,,Qq$???r7   rc   )r   r   r   r   r!   r  r   r   r  r   r  r  r  r  r   ra  r   r   r   r   s   @r5   r  r    s        M M^ IG  [   [   [ $ $ [$? ? ?I I I
   @ @ @ @ @ @ @ @ @r7   r  c                       e Zd ZdZeZej        Ze	d             Z
e	d             Ze	d             Ze	d             Zd Zd Zdd
ZdS )rT  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                     t           j        S r   r   rJ   r  s    r5   r  z
Shi._atinfh  
    zr7   c                     t           j        S r   )r   rL   r  s    r5   r  zShi._atneginfl  s    !!r7   c                 "    t          |           S r   )rT  r8  s     r5   r  zShi._minusfactorp  s    Awr7   c                 6    t           t          |          z  |z  S r   )r	   r  r  s      r5   r  zShi._Ifactort  s    Awt|r7   c                     t          |          t          t          t          t          z            |z            z
  dz  t          t          z  dz  z
  S r   )r  r   r	   r
   r   s      r5   r   zShi._eval_rewrite_as_expintx  s<    19QrT??1,---q01R4699r7   c                 2    | j         d         }|j        rdS d S rn   rr   r  s     r5   rs   zShi._eval_is_zero|  r  r7   Nr   c                 4   | j         d                             |          }|                    |d          }|t          j        u r.|                    |dt          |          j        rdnd          }|j        r|S |j	        s| 
                    |          S | S )Nr   r   r   r   r  r   s         r5   r   zShi._eval_as_leading_term  s    il**1--xx1~~15==99Qbhh.B'Kss9LLD< 	J! 	99T??"Kr7   rc   )r   r   r   r   r    r  r   r,   r  r   r  r  r  r  r   rs   r   r   r7   r5   rT  rT  %  s        = =~ IfG  [ " " ["   [   [: : :  
     r7   rT  c                       e Zd ZdZeZej        Ze	d             Z
e	d             Ze	d             Ze	d             Zd Zd
d	ZdS )rU  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                     t           j        S r   r  r  s    r5   r  z
Chi._atinf  r  r7   c                     t           j        S r   r  r  s    r5   r  zChi._atneginf  r  r7   c                 @    t          |          t          t          z  z   S r   r  r8  s     r5   r  zChi._minusfactor  s    1vv"}r7   c                 L    t          |          t          t          z  dz  |z  z   S r   r  r  s      r5   r  zChi._Ifactor  s    !uuqtAvd{""r7   c                     t            t          z  dz  t          |          t          t          t           t          z            |z            z   dz  z
  S r   )r	   r
   r  r   r   s      r5   r   zChi._eval_rewrite_as_expint  s>    r"uQw"Q%%"Yqt__Q%6"7"77:::r7   Nr   c                    | j         d                             |||          }|                    |d          }|t          j        u r.|                    |dt          |          j        rdnd          }|j        rH|	                    |          \  }}|t          |          n|}t          |          ||z  z   t          z   S |j        r|                     |          S | S r  r  r  s           r5   r   zChi._eval_as_leading_term  r  r7   rc   )r   r   r   r   r   r  r   r   r  r   r  r  r  r  r   r   r   r7   r5   rU  rU    s        H HT IG  [   [   [ # # [#; ; ;     r7   rU  c                   N    e Zd ZdZdZed             Zd
dZd ZeZ	d Z
d ZeZd	S )FresnelIntegralz& Base class for the Fresnel integrals.Tc                 @   |t           j        u rt           j        S |j        rt           j        S t           j        }|}d}|                    d          }|| }|}d}|                    t                    }|| j        t          z  |z  }|}d}|r| | |          z  S d S )NFr   T)	r   rJ   r{   rN   r,   rK   rR   r	   _sign)rU   r}   prefactnewargchangedr   s         r5   rX   zFresnelIntegral.eval		  s     
??6M 9 	6M %,,R00>hGFG,,Q//>ik')GFG 	'33v;;&&	' 	'r7   r:   c                     |dk    r8|                      t          j        t          z  | j        d         dz  z            S t          | |          r+  )r  r   r{   r
   r)   r   r>   s     r5   r@   zFresnelIntegral.fdiff(	  sB    q==>>!&)DIaL!O";<<<$T8444r7   c                 &    | j         d         j        S rc   rj   rf   s    r5   r   z&FresnelIntegral._eval_is_extended_real.	  rl   r7   c                 &    | j         d         j        S rc   rr   rf   s    r5   rs   zFresnelIntegral._eval_is_zero3	  rt   r7   c                 f    |                      | j        d                                                   S rc   rd   rf   s    r5   rg   zFresnelIntegral._eval_conjugate6	  rh   r7   Nr   )r   r   r   r   r   r   rX   r@   r   rp   rs   rg   r6   r-   r   r7   r5   r  r  	  s        00J' ' ['<5 5 5 5- - - -O$ $ $3 3 3 -LLLr7   r  c                   |     e Zd ZdZeZej         Ze	e
d                         Zd Zd Zd Zd Zdd	Z fd
Z x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                    | dk     rt           j        S t          |          }t          |          dk    r=|d         }t          dz   |dz  z  d| z  dz
  z  d| z  d| z  dz   z  d| z  dz   z  z  |z  S |dz  |dz   | z  z  t          d          d| z  dz
  z  t          d| z  dz   z  z  z  d| z  dz   t          d| z  dz             z  z  S )	Nr   r:   r   r(         r   r[   r   r,   r   r\   r
   r   r^   r2   r_   r  s       r5   ra   zfresnels.taylor_term	  s     q556M

A>""Q&&"2&Qq!tQqS1W-qsAaC!G}acAg/FG1LL!t1uqj(AaDD2a4!8,<R!A#'],JKPQRSPSVWPWYbcdefcfijcjYkYkOkllr7   c           	      4   t           j        t          z   dz  t          t           j        t          z   dz  t	          t
                    z  |z            t          t          t           j        t          z
  dz  t	          t
                    z  |z            z  z
  z  S Nr  r(   r   rK   r	   r9   r   r
   r   s      r5   r   zfresnels._eval_rewrite_as_erf	  k    	1}QUQYM$r(($:1$< = =#quqyRSmTXY[T\T\F\]^F^B_B_@_ _``r7   c           	          t           |dz  z  dz  t          t          dd          gt          dd          t          dd          gt           dz   |dz  z  dz            z  S )Nr      r  r(         )r
   r$   r   r   s      r5   r   zfresnels._eval_rewrite_as_hyper	  sb    !Q$wqy5(1a..!1HQNNHQPQNN3SVXZ[V[U[\]_`\`U`acUcddddr7   c           
      <   t           |t          dd          z  z  t          d          |dz  t          dd          z  z  | t          dd          z  z  z  t          g dgt          dd          gt          dd          dgt           dz   |dz  z  dz            z  S )N	   r  r(   r   r:   r   r  )r
   r   r   r%   r   s      r5   r   z!fresnels._eval_rewrite_as_meijerg	  s    1hq!nn$$QAA0F(FXVWYZ^^G[([\"qcHQNN#3hq!nna5H2q5&QRTUQU+VX.YYZ 	[r7   c                     ddl m} t          t          d|g          j                  } |t          t          |dz  z  dz            |d|f          S Nr   r[  rW   r(   )r]  r\  r   r   r^  r"   r
   r`  s        r5   ra  z"fresnels._eval_rewrite_as_Integral	  [    666666'aS11677xBq!tGAIAq	222r7   Nr   c                    ddl m} | j        d                             |||          }|                    |d          }|t
          j        u r.|                    |dt          |          j	        rdnd          }|j
        rt          |dz  z  dz  S |t
          j        t
          j        fv r.|t
          j        u rd	nd
}|t
          j        z   |||          z   S |                     |          S )Nr   r   r   r   r   r   r   r  r:   r   )r   r   r)   r   r   r   r   r   r   rS  rN   r
   rJ   rL   r{   r.   r/   r2   r   r   r   rV   r   r   s           r5   r   zfresnels._eval_as_leading_term	  s    ,,,,,,il**14d*CCxx1~~1$$$99Qbhh.B'Kss9LLD< 	#c1f9Q;aj!"4555QZ''RAQV8eeAqkk))99T??"r7   c                   
 ddl m} |d         }|t          j        t          j         fv r| j        d         

fdt          d          D             }dd
z  z  g
fdt          d          D             z   }d |D             }d |D             }|t          j        u rdnd	}	|	t          j        z  t          
dz            t          | z  t          
dz            t          | z  z   
                    |t          dt          z            |z            z    |d
z  z  |          z   S t                                          |||          S )
Nr   r   c                     g | ]g}d |z  dz   k     t           j        |z  t          d |z  dz             z  dd|z  dz   z  d |z  dz   z  z  dd|z  z  z  t          d|z            z  z  hS r  r   r:   r(   r  r   r`   r^   r}   s     r5   r   z*fresnels._eval_aseries.<locals>.<listcomp>	  s     6 6 61q1 !IacAg$6$66acAg,QqS1W-AaC81Q3GI)4r7   r:   r(   c                     g | ]m}d |z  dz   k     t           j        |z  t          d |z  dz
            z  dd|z  dz   z  d |z  dz   z  z  dd|z  dz
  z  z  t          d|z  dz
            z  z  nS r  r:   r(   r  r  s     r5   r   z*fresnels._eval_aseries.<locals>.<listcomp>	       6 6 61q1 ]A-	!A#'0B0BBacAg,QqS1W-AaC!G<YqsQw=O=OOQ)4r7   c                 D    g | ]}t          d t          z             |z  S r~  r   r
   r   rW   s     r5   r   z*fresnels._eval_aseries.<locals>.<listcomp>	  (    ***1$qt**Q***r7   c                 D    g | ]}t          d t          z             |z  S r~  r   r!  s     r5   r   z*fresnels._eval_aseries.<locals>.<listcomp>	  r"  r7   r   )r   r   r   rJ   r)   r   r{   r"   r   r!   r   r   r
   r   r   r/   r^   r   r2   r   r   r   r  r  r   r}   r   s    `        @r5   r   zfresnels._eval_aseries	  s   ,,,,,,a QZ!*---	!A6 6 6 6 61++6 6 6A AaC	 6 6 6 6 61++6 6 6 6A +****A*****Aaj((bA QV8s1a4yya03q!t99S!W3DD$q$qt**Q,''(*/%!Q$*:*:; ; ww$$Qq$777r7   rc   )r   r   r   r   r"   r  r   rK   r  r   r   ra   r   r   r   ra  r   r   r   r   s   @r5   r   r   <	  s        S Sh IUFE	m 	m W \	ma a ae e e[ [ [3 3 3
# # # #8 8 8 8 8 8 8 8 8r7   r   c                   z     e Zd ZdZeZej        Ze	e
d                         Zd Zd Zd Zd Zdd	Z fd
Z x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                 |   | dk     rt           j        S t          |          }t          |          dk    r=|d         }t          dz   |dz  z  d| z  dz
  z  d| z  d| z  dz
  z  d| z  dz   z  z  |z  S ||dz   | z  z  t          d          d| z  z  t          d| z  z  z  z  d| z  dz   t          d| z            z  z  S )	Nr   r:   r   r(   r  r   r  r[   r  r  s       r5   ra   zfresnelc.taylor_term5
  s     q556M

A>""Q&&"2&Qq!tQqS1W-qsAaC!G}acAg/FG1LLQTEA:~11b1Q3i)?@QqS1WiXYZ[X[nnD\]]r7   c           	      4   t           j        t          z
  dz  t          t           j        t          z   dz  t	          t
                    z  |z            t          t          t           j        t          z
  dz  t	          t
                    z  |z            z  z   z  S r
  r  r   s      r5   r   zfresnelc._eval_rewrite_as_erfB
  r  r7   c           	          |t          t          dd          gt          j        t          dd          gt          dz   |dz  z  dz            z  S )Nr:   r     r(   r  )r$   r   r   r{   r
   r   s      r5   r   zfresnelc._eval_rewrite_as_hyperE
  sF    5(1a..)AFHQNN+Cb!eVAqD[QS^TTTTr7   c           
      0   t           |t          dd          z  z  t          d          t          |dz  d          z  t          | d          z  z  t	          g dgt          dd          gt          dd          dgt           dz   |dz  z  dz            z  S )Nr   r  r(   r:   r   r  )r
   r   r   r   r%   r   s      r5   r   z!fresnelc._eval_rewrite_as_meijergH
  s    1hq!nn$$QQT1(=dA2qkk(IJ"qcHQNN#3hq!nna5H2q5&QRTUQU+VX.YYZ 	[r7   c                     ddl m} t          t          d|g          j                  } |t          t          |dz  z  dz            |d|f          S r  )r]  r\  r   r   r^  r!   r
   r`  s        r5   ra  z"fresnelc._eval_rewrite_as_IntegralL
  r  r7   Nr   c                    ddl m} | j        d                             |||          }|                    |d          }|t
          j        u r.|                    |dt          |          j	        rdnd          }|j
        r|S |t
          j        t
          j        fv r.|t
          j        u rdnd}|t
          j        z   |||          z   S |                     |          S )	Nr   r   r   r   r   r   r:   r   )r   r   r)   r   r   r   r   r   r   rS  rN   rJ   rL   r{   r.   r  s           r5   r   zfresnelc._eval_as_leading_termQ
  s    ,,,,,,il**14d*CCxx1~~1$$$99Qbhh.B'Kss9LLD< 	#Jaj!"4555QZ''RAQV8eeAqkk))99T??"r7   c                   
 ddl m} |d         }|t          j        t          j         fv r| j        d         

fdt                    D             }dd
z  z  g
fdt          d          D             z   }d |D             }d |D             }|t          j        u rdnd	}	|	t          j        z  t          
dz            t          | z  t          
dz            t          | z  z   
                    |t          dt          z            |z            z    |d
z  z  |          z   S t                                          |||          S )
Nr   r   c                     g | ]g}d |z  dz   k     t           j        |z  t          d |z  dz             z  dd|z  dz   z  d |z  dz   z  z  dd|z  z  z  t          d|z            z  z  hS r  r  r  s     r5   r   z*fresnelc._eval_aseries.<locals>.<listcomp>j
  s     3 3 3acAgkk !IacAg$6$66acAg,QqS1W-AaC81Q3GI&1kkr7   r:   r(   c                     g | ]m}d |z  dz   k     t           j        |z  t          d |z  dz
            z  dd|z  dz   z  d |z  dz   z  z  dd|z  dz
  z  z  t          d|z  dz
            z  z  nS r  r  r  s     r5   r   z*fresnelc._eval_aseries.<locals>.<listcomp>m
  r  r7   c                 D    g | ]}t          d t          z             |z  S r~  r   r!  s     r5   r   z*fresnelc._eval_aseries.<locals>.<listcomp>q
  r"  r7   c                 B    g | ]}t          d t          z            |z  S r~  r   r!  s     r5   r   z*fresnelc._eval_aseries.<locals>.<listcomp>r
  s&    ***1$qt**Q,***r7   r   )r   r   r   rJ   r)   r   r{   r!   r   r"   r   r   r
   r   r   r$  s    `        @r5   r   zfresnelc._eval_aseries`
  s   ,,,,,,a QZ!*---	!A3 3 3 3 3((3 3 3A AaC	 6 6 6 6 61++6 6 6 6A +****A*****Aaj((bA QV8s1a4yya03q!t99S!W3DD$q$qt**Q,''(*/%!Q$*:*:; ; ww$$Qq$777r7   rc   )r   r   r   r   r!   r  r   rK   r  r   r   ra   r   r   r   ra  r   r   r   r   s   @r5   r   r   	  s        S Sh IEE	^ 	^ W \	^a a aU U U[ [ [3 3 3
# # # #8 8 8 8 8 8 8 8 8r7   r   c                   F     e Zd ZdZed             Z fdZddZd Z xZ	S )r   zi
    Helper function to make the $\mathrm{erf}(z)$ function
    tractable for the Gruntz algorithm.

    c                 ,    |j         rt          j        S d S r   )rN   r   rK   )rU   rV   s     r5   rX   z
_erfs.eval
  s    ; 	5L	 	r7   c                 Z  
 ddl m} |d         }|t          j        u ra| j        d         

fdt          |          D             } |d
d|z  dz   z  z  |          }t          |                     |||          |z   S |                    t                    }	|	t          j        u ra| j        d         

fdt          |          D             } |d
d|z  dz   z  z  |          }t          |                     |||          |z   S t                                          ||||          S )Nr   r   c                     g | ]`}d t          t                    z  t          d|z            z  t          d           | z  z  t          |          z  d z  d|z  d z   z  z  aS r:   r(   r  r   r
   r   r   r   s     r5   r   z'_erfs._eval_aseries.<locals>.<listcomp>
       N N N?@ 488i!nn,q0 0 /r. $Q<<(+,Q3!A#'*:; N N Nr7   r:   r(   c                     g | ]`}d t          t                    z  t          d|z            z  t          d           | z  z  t          |          z  d z  d|z  d z   z  z  aS r6  r7  r   s     r5   r   z'_erfs._eval_aseries.<locals>.<listcomp>
  r8  r7   )r   r   r   rJ   r)   r   r   ri  rR   r	   r   r   )r/   r^   r   r2   r   r   r   lorW   r}   r   s             @r5   r   z_erfs._eval_aseries
  sr   ,,,,,,a AJ	!AN N N NDI!HHN N NAaAaC!Gna((AG**1a66:: **1--
??	!AN N N NDI!HHN N NAaAaC!Gna((AG**1a66:: ww$$Qq$777r7   r:   c                     |dk    r:| j         d         }dt          t                    z  d|z  t          |          z  z   S t	          | |          )Nr:   r   r[   r(   )r)   r   r
   r   r   r/   r?   r}   s      r5   r@   z_erfs.fdiff
  sI    q==	!Ad2hh;1U1XX--$T8444r7   c                 `    t           j        t          |          z
  t          |dz            z  S r   )r   rK   r9   r   r   s      r5   _eval_rewrite_as_intractablez"_erfs._eval_rewrite_as_intractable
  s#    AAqD		))r7   r   )
r   r   r   r   r   rX   r   r@   r?  r   r   s   @r5   r   r   
  s         
   [8 8 8 8 865 5 5 5* * * * * * *r7   r   c                   H     e Zd ZdZ fdZd
dZd Zd fd	Zd fd		Z xZ	S )rX  z~
    Helper function to make the $\mathrm{Ei}(z)$ and $\mathrm{li}(z)$
    functions tractable for the Gruntz algorithm.

    c                 P   ddl m} |d         t          j        k    r+t	          t
          |                               ||||          S | j        d         fdt          |          D             } |d|dz   z  z  |          }t          | 
                    |||          |z   S )Nr   r   c                 F    g | ]}t          |          d z  |d z   z  z  S r   rn  r   s     r5   r   z&_eis._eval_aseries.<locals>.<listcomp>
  s0    ===qYq\\QqSAEN*===r7   r:   )r   r   r   rJ   r   r   r   r)   r   r   ri  )
r/   r^   r   r2   r   r   r:  r;  r}   r   s
           @r5   r   z_eis._eval_aseries
  s    ,,,,,,8qz!!%%33AuaFFFIaL====E!HH===E!AAJ,""Q&&q!T22Q66r7   r:   c                     |dk    r,| j         d         }t          j        |z  t          |          z
  S t	          | |          )Nr:   r   )r)   r   rK   rX  r   r=  s      r5   r@   z
_eis.fdiff
  s=    q==	!A519tAww&&$T8444r7   c                 B    t          |           t          |          z  S r   )r   rC  r   s      r5   r?  z!_eis._eval_rewrite_as_intractable
  s    A2wwr!uu}r7   Nr   c                     | j         d                             |d          }|j        r' | j        | j          }|                    |||          S t                                          |||          S )Nr   r   )r)   r   rN   r?  r   r   )r/   r2   r   r   re  rk  r   s         r5   r   z_eis._eval_as_leading_term
  st    Yq\1%%: 	D1149=A**14d*CCCww,,QT,EEEr7   c                     | j         d                             |d          }|j        r& | j        | j          }|                    |||          S t                                          |||          S rc   )r)   r   rN   r?  ri  r   rj  s          r5   ri  z_eis._eval_nseries
  sk    Yq\1%%: 	/1149=A??1a...ww$$Q4000r7   r   rc   ro  )
r   r   r   r   r   r@   r?  r   ri  r   r   s   @r5   rX  rX  
  s         	7 	7 	7 	7 	75 5 5 5  F F F F F F1 1 1 1 1 1 1 1 1 1r7   rX  N)T)Mr   
sympy.corer   sympy.core.addr   sympy.core.cacher   sympy.core.functionr   r   r   sympy.core.numbersr	   r
   r   sympy.core.relationalr   sympy.core.powerr   sympy.core.singletonr   sympy.core.symbolr   r   sympy.core.sympifyr   (sympy.functions.combinatorial.factorialsr   r   r   $sympy.functions.elementary.complexesr   r   r   #sympy.functions.elementary.integersr   r   (sympy.functions.elementary.miscellaneousr   r   &sympy.functions.elementary.exponentialr   r   r   %sympy.functions.elementary.hyperbolicr   r    (sympy.functions.elementary.trigonometricr!   r"   r#   sympy.functions.special.hyperr$   r%   r6   r9   r   r   r  rD   rP   rQ   rC  r   r  rP  r  r  r  r  rT  rU  r  r   r   r   rX  r   r7   r5   <module>rY     s%  F F " ! ! ! ! !       $ $ $ $ $ $ H H H H H H H H H H . . . . . . . . . . ' ' ' ' ' '             " " " " " " : : : : : : : : & & & & & & [ [ [ [ [ [ [ [ [ [ L L L L L L L L L L > > > > > > > > ? ? ? ? ? ? ? ? F F F F F F F F F F < < < < < < < < C C C C C C C C C C 8 8 8 8 8 8 8 8   *^- ^- ^- ^- ^-( ^- ^- ^-B|H |H |H |H |H8 |H |H |H~}B }B }B }B }B8 }B }B }B@O! O! O! O! O!8 O! O! O!bZ$ Z$ Z$ Z$ Z$X Z$ Z$ Z$zO$ O$ O$ O$ O$x O$ O$ O$d[ [ [ [ [h [ [ [Bt@ t@ t@ t@ t@ t@ t@ t@n}? }? }? }? }?X }? }? }?@     Fe e e e e e e eNZ+ Z+ Z+ Z+ Z+ Z+ Z+ Z+@<J <J <J <J <JH <J <J <J~E E E E E	 E E EPJ@ J@ J@ J@ J@	 J@ J@ J@Xg g g g g
 g g gTn n n n n
 n n nj5- 5- 5- 5- 5-h 5- 5- 5-p^8 ^8 ^8 ^8 ^8 ^8 ^8 ^8B^8 ^8 ^8 ^8 ^8 ^8 ^8 ^8L.* .* .* .* .*H .* .* .*b*1 *1 *1 *1 *18 *1 *1 *1 *1 *1r7   