
    MZd-                       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 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.m/Z/m0Z0m1Z1 ddl2m3Z3m4Z4 dAdZ5 G d de      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>d' Z? G d( d)e      Z@ G d* d+e      ZA G d, d-e      ZB G d. d/eB      ZC G d0 d1eB      ZD G d2 d3eB      ZE G d4 d5eB      ZF G d6 d7e      ZG G d8 d9eG      ZH G d: d;eG      ZI G d< d=e      ZJ G d> d?e      ZKy@)Bz 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)Symbol)sympify)	factorial
factorial2RisingFactorial)
polar_liftre
unpolarify)ceilingfloor)sqrtroot)explog	exp_polar)coshsinh)cossinsinc)hypermeijergc                 R   | j                   d   j                  r<|r(d|d<    | j                  |fi |t        j                  fS | t        j                  fS |r2 | j                   d   j                  |fi |j                         \  }}n | j                   d   j                         \  }}| j                  |t        |z  z         | j                  |t        |z  z
        z   dz  }| j                  |t        |z  z         | j                  |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          I/usr/lib/python3/dist-packages/sympy/functions/special/error_functions.pyreal_to_real_as_real_imagr5      s   yy|$$$E)DKK..77!&&>!"tyy|""4151>>@1yy|((*1
))A!G
tyyQqS1
11	4B
))A!G
tyyQqS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

    Tc                     |dk(  r/dt        | j                  d   dz         z  t        t              z  S t	        | |      N   r'   r   r   r(   r   r
   r   r.   argindexs     r4   fdiffz	erf.fdiff   s>    q=S$))A,/)**4833$T844r6   c                     t         S z8
        Returns the inverse of this function.

        erfinvr=   s     r4   inversezerf.inverse   s	    
 r6   c                    |j                   r|t        j                  u rt        j                  S |t        j                  u rt        j                  S |t        j
                  u rt        j                  S |j                  rt        j                  S t        |t              r|j                  d   S t        |t              r t        j                  |j                  d   z
  S |j                  rt        j                  S t        |t              r(|j                  d   j                  r|j                  d   S |j                  t              }|t        j                  t        j
                  fv r|S |j!                         r
 | |        S y Nr   r;   )	is_Numberr   NaNInfinityOneNegativeInfinityNegativeOneis_zeror+   
isinstancerC   r(   erfcinverf2invextract_multiplicativelyr	   could_extract_minus_signclsargts      r4   evalzerf.eval   s   ==aee|uu

"uu***}}$vvc6"HHQKc7#55388A;&&;;66M c7#(;(;88A; ((+Q//00J '')I: *r6   c                 H   | dk  s| dz  dk(  rt         j                  S t        |      }t        | dz
  t        d      z        }t	        |      dkD  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   lenrL   r   r   r
   nr1   previous_termsks       r4   taylor_termzerf.taylor_term   s     q5AEQJ66M
Aq1uadl#A>"Q&&r**QT1QU;QqSAA))AqD0!IaL.b2IJJr6   c                 Z    | j                  | j                  d   j                               S Nr   r-   r(   	conjugater.   s    r4   _eval_conjugatezerf._eval_conjugate   "    yy1//122r6   c                 4    | j                   d   j                  S rb   r(   r)   re   s    r4   _eval_is_realzerf._eval_is_real       yy|,,,r6   c                 h    | j                   d   j                  ry| j                   d   j                  S Nr   T)r(   	is_finiter)   re   s    r4   _eval_is_finitezerf._eval_is_finite   s*    99Q<!!99Q<000r6   c                 4    | j                   d   j                  S rb   r(   rM   re   s    r4   _eval_is_zerozerf._eval_is_zero       yy|###r6   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_functionsrw   r   r   rJ   Halfr
   r.   zkwargsrw   s       r4   _eval_rewrite_as_uppergammazerf._eval_rewrite_as_uppergamma   s=    FAqDz!|QUUZ1%=d2h%FFGGr6   c                     t         j                  t        z
  |z  t        t              z  }t         j                  t        z   t        |      t        t        |      z  z
  z  S Nr   rJ   r	   r   r
   fresnelcfresnelsr.   r|   r}   rU   s       r4   _eval_rewrite_as_fresnelszerf._eval_rewrite_as_fresnels   @    uuqy!mDH$	HSMAhsmO;<<r6   c                     t         j                  t        z
  |z  t        t              z  }t         j                  t        z   t        |      t        t        |      z  z
  z  S r   r   r   s       r4   _eval_rewrite_as_fresnelczerf._eval_rewrite_as_fresnelc   r   r6   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   rz   r   r.   r|   r}   s      r4   _eval_rewrite_as_meijergzerf._eval_rewrite_as_meijerg   s7    bz'166(Bhr1o5F1MMMr6   c                     d|z  t        t              z  t        t        j                  gdt        j                  z  g|dz         z  S Nr'      r   r
   r#   r   rz   r   s      r4   _eval_rewrite_as_hyperzerf._eval_rewrite_as_hyper   s8    s48|E166(QqvvXJA>>>r6   c                     t        |dz        |z  |t        t        j                  |dz        z  t        t              z  z
  S Nr'   r   expintr   rz   r
   r   s      r4   _eval_rewrite_as_expintzerf._eval_rewrite_as_expint   s6    AqDz!|aqvvq!t 44T"X===r6   c                    ddl m} |rW |||t        j                        }|t        j                  u r-t        j
                  t        |       t        |dz         z  z   S t        j                  t        |      t        |dz         z  z
  S )Nr   )limitr'   )	sympy.series.limitsr   r   rI   rK   rL   _erfsr   rJ   )r.   r|   limitvarr}   r   lims         r4   _eval_rewrite_as_tractablezerf._eval_rewrite_as_tractable   sn    -8QZZ0Ca(((}}uaRyadU';;;uuuQxQTE
***r6   c                 :    t         j                  t        |      z
  S r   )r   rJ   erfcr   s      r4   _eval_rewrite_as_erfczerf._eval_rewrite_as_erfc   s    uutAwr6   c                 6    t          t        t         |z        z  S r   r	   erfir   s      r4   _eval_rewrite_as_erfizerf._eval_rewrite_as_erfi   s    r$qs)|r6   c                 B   | j                   d   j                  |||      }|j                  |d      }|t        j                  u r|j                  |d|dk(  rdnd      }||j                  v r!|j                  rd|z  t        t              z  S | j                  |      S )Nr   logxcdirr   -+dirr'   )r(   as_leading_termsubsr   ComplexInfinityr   free_symbolsrM   r   r
   r-   r.   r1   r   r   rU   arg0s         r4   _eval_as_leading_termzerf._eval_as_leading_term   s    iil**14d*Cxx1~1$$$99Qdbjsc9BD   T\\S5b>!99T?"r6   c                 t   ddl m} |d   }|t        j                  t        j                  fv r| j
                  d   }	 |j                  |      \  }}	|	 }	|	j                  rt        ||	z        }
t        |
      D cg c]9  }t        j                  |z  t        d|z  dz
        z  |d|z  dz   z  d|z  z  z  ; c} |d||
z  z  |      gz   }t        j                  t        |dz         t!        t"              z  t%        | z  z
  S t&        t(        | W  ||||      S # t        t        f$ r | cY S w xY wc c}w Nr   Orderr'   r;   )sympy.series.orderr   r   rI   rK   r(   leadterm
ValueErrorNotImplementedErroris_positiver   rangerL   r   rJ   r   r   r
   r   superr8   _eval_aseries)r.   r]   args0r1   r   r   pointr|   _exnewnr_   s	__class__s                r4   r   zerf._eval_aseries   s6   ,aQZZ!3!344		!A

12 B~~qt}#Dk+ ]]A%
1Q37(;;q1Q37|aQRd?RS +.3AagIq.A-BCuuQTE
48 3sAw>>>S$-a4@@  34 +s   D =>D5D21D2r;   r   rb   )__name__
__module____qualname____doc__
unbranchedr?   rD   classmethodrW   staticmethodr   r`   rf   rj   ro   rr   r~   r   r   r   r   r   r   r   r   r   r   r5   r,   __classcell__r   s   @r4   r8   r8   0   s    JX J5  B 	K  	K3-1$H==N?>+	#A* -Lr6   r8   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y	)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

    Tc                     |dk(  r/dt        | j                  d   dz         z  t        t              z  S t	        | |      )Nr;   rZ   r   r'   r<   r=   s     r4   r?   z
erfc.fdiff`  s>    q=c499Q<?*++DH44$T844r6   c                     t         S rA   rO   r=   s     r4   rD   zerfc.inversef  s	    
 r6   c                 ^   |j                   r`|t        j                  u rt        j                  S |t        j                  u rt        j                  S |j
                  rt        j                  S t        |t              r t        j                  |j                  d   z
  S t        |t              r|j                  d   S |j
                  rt        j                  S |j                  t              }|t        j                  t        j                  fv r| S |j                         rd | |       z
  S y )Nr   r'   )rG   r   rH   rI   r+   rM   rJ   rN   rC   r(   rO   rQ   r	   rK   rR   rS   s      r4   rW   z	erfc.evalm  s    ==aee|uu

"vvuuc6"55388A;&&c7#88A;;;55L ((+Q//004K '')sC4y=  *r6   c                 r   | 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kD  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 rY   )
r   rJ   r+   r   r   r[   rL   r   r   r
   r\   s       r4   r`   zerfc.taylor_term  s     655LUa!eqj66M
Aq1uadl#A>"Q&&r**QT1QU;QqSAA!--**QT11Yq\>$r(3JKKr6   c                 Z    | j                  | j                  d   j                               S rb   rc   re   s    r4   rf   zerfc._eval_conjugate  rg   r6   c                 4    | j                   d   j                  S rb   ri   re   s    r4   rj   zerfc._eval_is_real  rk   r6   Nc                 P    | j                  t              j                  dd|      S N	tractableT)r/   r   rewriter8   r.   r|   r   r}   s       r4   r   zerfc._eval_rewrite_as_tractable  #    ||C ((4((SSr6   c                 :    t         j                  t        |      z
  S r   )r   rJ   r8   r   s      r4   _eval_rewrite_as_erfzerfc._eval_rewrite_as_erf  s    uus1v~r6   c                 V    t         j                  t        t        t        |z        z  z   S r   )r   rJ   r	   r   r   s      r4   r   zerfc._eval_rewrite_as_erfi  s    uuqac{""r6   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       r4   r   zerfc._eval_rewrite_as_fresnels  sI    uuqy!mDH$uu	HSMAhsmO$CDDDr6   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       r4   r   zerfc._eval_rewrite_as_fresnelc  sI    uuQwk$r("uu	HSMAhsmO$CDDDr6   c                     t         j                  |t        t              z  t	        t         j
                  gg dgt        dd      g|dz        z  z
  S r   )r   rJ   r   r
   r$   rz   r   r   s      r4   r   zerfc._eval_rewrite_as_meijerg  sC    uuqbz'166(Bhr1o=NPQSTPT"UUUUr6   c                     t         j                  d|z  t        t              z  t	        t         j
                  gdt         j
                  z  g|dz         z  z
  S r   )r   rJ   r   r
   r#   rz   r   s      r4   r   zerfc._eval_rewrite_as_hyper  sA    uuqs48|E166(QqvvXJA$FFFFr6   c                     ddl m} t        j                  t	        |dz        |z  t        j                   |t        j
                  |dz        t	        t              z  z
  z  z
  S ru   )ry   rw   r   rJ   r   rz   r
   r{   s       r4   r~   z erfc._eval_rewrite_as_uppergamma  sF    FuutAqDz!|QUUZ1-Ed2h-N%NOOOr6   c                     t         j                  t        |dz        |z  z
  |t        t         j                  |dz        z  t        t
              z  z   S r   )r   rJ   r   r   rz   r
   r   s      r4   r   zerfc._eval_rewrite_as_expint  s?    uutAqDz!|#aqvvq!t(<&<T"X&EEEr6   c                 ,    | j                  t              S r   r   r.   r0   s     r4   _eval_expand_funczerfc._eval_expand_func      ||C  r6   c                    | j                   d   j                  |||      }|j                  |d      }|t        j                  u r|j                  |d|dk(  rdnd      }|j                  rt        j                  S | j                  |      S )Nr   r   r   r   r   r   )	r(   r   r   r   r   r   rM   rJ   r-   r   s         r4   r   zerfc._eval_as_leading_term  sx    iil**14d*Cxx1~1$$$99Qdbjsc9BD<<55L99T?"r6   c                 l    t         j                  t        | j                   j	                  ||||      z
  S r   )r   rJ   r8   r(   r   )r.   r]   r   r1   r   s        r4   r   zerfc._eval_aseries  s*    uusDII44Qq$GGGr6   r   r   rb   )r   r   r   r   r   r?   rD   r   rW   r   r   r`   rf   rj   r   r   r   r   r   r   r   r~   r   r   r   r5   r,   r    r6   r4   r   r     s    JX J5 ! !6 L  L3-T#EEVGPF!	# -LHr6   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

    Tc                     |dk(  r.dt        | j                  d   dz        z  t        t              z  S t	        | |      r:   r<   r=   s     r4   r?   z
erfi.fdiff  s;    q=S1q))$r(22$T844r6   c                    |j                   r`|t        j                  u rt        j                  S |j                  rt        j                  S |t        j
                  u rt        j
                  S |j                  rt        j                  S |j                         r
 | |        S |j                  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              r0|j                  d   j                  rt        |j                  d   z  S y y y rF   )rG   r   rH   rM   r+   rI   rR   rQ   r	   rN   rC   r(   rO   rJ   rP   rT   r|   nzs      r4   rW   z	erfi.eval"  s   ;;AEEzuuvvajjzz!9966M %%'G8O ''*>QZZ"f%|#"g&!%%"''!*,--"g&2771:+=+=|# ,>& r6   c                    | dk  s| dz  dk(  rt         j                  S t        |      }t        | dz
  t        d      z        }t	        |      dkD  r|d   |dz  z  | dz
  z  | |z  z  S d|| z  z  | t        |      z  t        t              z  z  S rY   )r   r+   r   r   r[   r   r   r
   r\   s       r4   r`   zerfi.taylor_term@  s     q5AEQJ66M
Aq1uadl#A>"Q&%b)AqD0AE:AaC@@1a4x9Q<R!899r6   c                 Z    | j                  | j                  d   j                               S rb   rc   re   s    r4   rf   zerfi._eval_conjugateM  rg   r6   c                 4    | j                   d   j                  S rb   ri   re   s    r4   _eval_is_extended_realzerfi._eval_is_extended_realP  rk   r6   c                 4    | j                   d   j                  S rb   rq   re   s    r4   rr   zerfi._eval_is_zeroS  rs   r6   c                 P    | j                  t              j                  dd|      S r   r   r   s       r4   r   zerfi._eval_rewrite_as_tractableV  r   r6   c                 6    t          t        t         |z        z  S r   )r	   r8   r   s      r4   r   zerfi._eval_rewrite_as_erfY  s    r#ac({r6   c                 B    t         t        t         |z        z  t         z
  S r   )r	   r   r   s      r4   r   zerfi._eval_rewrite_as_erfc\  s    ac{Qr6   c                     t         j                  t        z   |z  t        t              z  }t         j                  t        z
  t        |      t        t        |      z  z
  z  S r   r   r   s       r4   r   zerfi._eval_rewrite_as_fresnels_  r   r6   c                     t         j                  t        z   |z  t        t              z  }t         j                  t        z
  t        |      t        t        |      z  z
  z  S r   r   r   s       r4   r   zerfi._eval_rewrite_as_fresnelcc  r   r6   c           
          |t        t              z  t        t        j                  gg dgt        dd      g|dz         z  S r   r   r   s      r4   r   zerfi._eval_rewrite_as_meijergg  s9    bz'166(Bhr1o5FANNNr6   c                     d|z  t        t              z  t        t        j                  gdt        j                  z  g|dz        z  S r   r   r   s      r4   r   zerfi._eval_rewrite_as_hyperj  s6    s48|E166(QqvvXJ1===r6   c                     ddl m} t        |dz         |z   |t        j                  |dz         t        t
              z  t        j                  z
  z  S ru   )ry   rw   r   r   rz   r
   rJ   r{   s       r4   r~   z erfi._eval_rewrite_as_uppergammam  sA    FQTE{1}j!Q$7R@155HIIr6   c                     t        |dz         |z  |t        t        j                  |dz         z  t        t              z  z
  S r   r   r   s      r4   r   zerfi._eval_rewrite_as_expintq  s:    QTE{1}qA!66tBx???r6   c                 ,    | j                  t              S r   r   r   s     r4   r   zerfi._eval_expand_funct  r   r6   c                 "   | j                   d   j                  |||      }|j                  |d      }||j                  v r!|j                  rd|z  t        t              z  S |j                  r| j                  |      S | j                  |      S )Nr   r   r'   )	r(   r   r   r   rM   r   r
   rn   r-   r   s         r4   r   zerfi._eval_as_leading_termy  sy    iil**14d*Cxx1~   T\\S5b>!^^99T?"yy~r6   c                    ddl m} |d   }|t        j                  u r| j                  d   }t        |      D cg c]%  }t        d|z  dz
        d|z  |d|z  dz   z  z  z  ' c} |d||z  z  |      gz   }	t         t        |dz        t        t              z  t        |	 z  z   S t        t        | ;  ||||      S c c}w r   )r   r   r   rI   r(   r   r   r	   r   r   r
   r   r   r   r   r.   r]   r   r1   r   r   r   r|   r_   r   r   s             r4   r   zerfi._eval_aseries  s    ,aAJJ		!A"1X' AaC!G$1q1Q37|(;< '*/!Q$*:);<A2QT48+sAw666T4.q%DAA	's   *B>r   r   rb   )r   r   r   r   r   r?   r   rW   r   r   r`   rf   r   rr   r   r   r   r   r   r   r   r~   r   r   r5   r,   r   r   r   r   s   @r4   r   r     s    GR J5 $ $: 	:  	:3-$T==O>J@! -L
B 
Br6   r   c                   t    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y)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;   rZ   r'   )r(   r   r   r
   r   r.   r>   r1   r2   s       r4   r?   z
erf2.fdiff  sd    yy1q=c1a4%j=b))]S!Q$Z<R(($T844r6   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                  s0|j                  r|j                  s|j                  r#|j                  rt        |      t        |      z
  S |j                         }|j                         }|r|r | | |        S |s|rt        |      t        |      z
  S y rF   )r   rI   rK   r+   rH   r8   rN   rP   r(   rM   r)   is_infiniterR   )rT   r1   r2   chksign_xsign_ys         r4   rW   z	erf2.eval  s   zz1--qvv6:aee55L!V66M#Xcq6CF?"a!affQi1n66!999		Q%7%7AMM""q}}q6CF?" ++-++-vQBK<q6#a&=  r6   c                     | j                  | j                  d   j                         | j                  d   j                               S rF   rc   re   s    r4   rf   zerf2._eval_conjugate  s5    yy1//1499Q<3I3I3KLLr6   c                 j    | j                   d   j                  xr | j                   d   j                  S rF   ri   re   s    r4   r   zerf2._eval_is_extended_real  s)    yy|,,N11N1NNr6   c                 0    t        |      t        |      z
  S r   r8   r.   r1   r2   r}   s       r4   r   zerf2._eval_rewrite_as_erf  s    1vAr6   c                 0    t        |      t        |      z
  S r   r   r  s       r4   r   zerf2._eval_rewrite_as_erfc  s    Awa  r6   c                 Z    t         t        t         |z        t        t         |z        z
  z  S r   r   r  s       r4   r   zerf2._eval_rewrite_as_erfi  s"    $qs)D1I%&&r6   c                 |    t        |      j                  t              t        |      j                  t              z
  S r   )r8   r   r   r  s       r4   r   zerf2._eval_rewrite_as_fresnels  '    1v~~h'#a&..*BBBr6   c                 |    t        |      j                  t              t        |      j                  t              z
  S r   )r8   r   r   r  s       r4   r   zerf2._eval_rewrite_as_fresnelc
  r  r6   c                 |    t        |      j                  t              t        |      j                  t              z
  S r   )r8   r   r$   r  s       r4   r   zerf2._eval_rewrite_as_meijerg  s'    1v~~g&Q)@@@r6   c                 |    t        |      j                  t              t        |      j                  t              z
  S r   )r8   r   r#   r  s       r4   r   zerf2._eval_rewrite_as_hyper  s'    1v~~e$s1v~~e'<<<r6   c                 D   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 ru   rx   )r.   r1   r2   r}   rw   s        r4   r~   z erf2._eval_rewrite_as_uppergamma  s{    FQT
1aeejA&>tBx&GGHAJqL!%%*QVVQT":48"CCDE 	Fr6   c                 |    t        |      j                  t              t        |      j                  t              z
  S r   )r8   r   r   r  s       r4   r   zerf2._eval_rewrite_as_expint  s'    1v~~f%Av(>>>r6   c                 ,    | j                  t              S r   r   r   s     r4   r   zerf2._eval_expand_func  r   r6   c                 &    t        | j                   S r   )r   r(   re   s    r4   rr   zerf2._eval_is_zero  s    dii  r6   N)r   r   r   r   r?   r   rW   rf   r   r   r   r   r   r   r   r   r~   r   r   rr   r   r6   r4   r
  r
    si    BJ5 ! !0MO!'CCA=F
?!!r6   r
  c                   <    e Zd ZdZddZddZed        Zd Zd Z	y)	rC   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/

    c                     |dk(  rKt        t              t        | j                  | j                  d         dz        z  t
        j                  z  S t        | |      Nr;   r   r'   r   r
   r   r-   r(   r   rz   r   r=   s     r4   r?   zerfinv.fdiffT  sI    q=8C		$))A, 7 :;;AFFBB$T844r6   c                     t         S rA   r  r=   s     r4   rD   zerfinv.inverseZ  s	    
 
r6   c                 L   |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 |j                  d      }|;t        |t              r*|j                  d   j                  r|j                  d    S y y y Nr   r   )r   rH   rL   rK   rM   r+   rJ   rI   rN   r8   r(   r)   rQ   r   s      r4   rW   zerfinv.evala  s    :55L!--%%%YY66M!%%Z::a!&&)"<"<66!99966M ''+>z"c2
7T7TGGAJ; 8U2>r6   c                     t        d|z
        S Nr;   r   r   s      r4   _eval_rewrite_as_erfcinvzerfinv._eval_rewrite_as_erfcinvw  s    aclr6   c                 4    | j                   d   j                  S rb   rq   re   s    r4   rr   zerfinv._eval_is_zeroz  rs   r6   Nr   )
r   r   r   r   r?   rD   r   rW   r,  rr   r   r6   r4   rC   rC   !  s0    /d5  *$r6   rC   c                   B    e Zd ZdZd	dZd	dZed        Zd Zd Z	d Z
y)
rO   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/

    c                     |dk(  rLt        t               t        | j                  | j                  d         dz        z  t
        j                  z  S t        | |      r%  r&  r=   s     r4   r?   zerfcinv.fdiff  sK    q=H9S499Q<!8!!;<<QVVCC$T844r6   c                     t         S rA   r  r=   s     r4   rD   zerfcinv.inverse  s	    
 r6   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 y r   )r   rH   rM   rI   rJ   r+   rK   rT   r|   s     r4   rW   zerfcinv.eval  sd    :55LYY::!%%Z66M!V%%%99:: r6   c                     t        d|z
        S r+  rB   r   s      r4   _eval_rewrite_as_erfinvzerfcinv._eval_rewrite_as_erfinv  s    ac{r6   c                 :    | j                   d   dz
  j                  S rF   rq   re   s    r4   rr   zerfcinv._eval_is_zero  s    		!q )))r6   c                 4    | j                   d   j                  S rb   rq   re   s    r4   _eval_is_infinitezerfcinv._eval_is_infinite  rs   r6   Nr   )r   r   r   r   r?   rD   r   rW   r4  rr   r7  r   r6   r4   rO   rO   ~  s5    )X5  *$r6   rO   c                   ,    e Zd ZdZd Zed        Zd Zy)rP   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                    | j                   \  }}|dk(  r$t        | j                  ||      dz  |dz  z
        S |dk(  r?t        t              t
        j                  z  t        | j                  ||      dz        z  S t        | |      Nr;   r'   )r(   r   r-   r   r
   r   rz   r   r  s       r4   r?   zerf2inv.fdiff  sx    yy1q=tyy1~q(A-..]8AFF?3tyy1~q'8#999$T844r6   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 y r   )r   rH   rM   r+   rJ   rI   rC   rO   )rT   r1   r2   s      r4   rW   zerf2inv.eval  s    :aee55LYY19966MYY1:::!%%ZAII55LYY!9!**_A2;YYH!**_!999yyvvay 99H r6   c                 V    | j                   \  }}|j                  r|j                  ryy y )NTrq   )r.   r1   r2   s      r4   rr   zerf2inv._eval_is_zero(  s&    yy199 #9r6   N)r   r   r   r   r?   r   rW   rr   r   r6   r4   rP   rP     s&    0f5  4r6   rP   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 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                 d   |j                   rt        j                  S |t        j                  u rt        j                  S |t        j                  u rt        j                  S |j                   rt        j                  S |j                         \  }}|rt        |      dt        z  t        z  |z  z   S y r   )	rM   r   rK   rI   r+   extract_branch_factorr>  r	   r
   rT   r|   r   r]   s       r4   rW   zEi.eval  s    99%%%!**_::!$$$66M99%%%'')Ab6AaCF1H$$ r6   c                 p    t        | j                  d         }|dk(  rt        |      |z  S t        | |      rF   )r   r(   r   r   r.   r>   rU   s      r4   r?   zEi.fdiff  s6    1&q=s8C<$T844r6   c                     | j                   d   t        d      z  j                  r3t        j                  | |      t
        t        z  j	                  |      z   S t        j                  | |      S r)  )r(   r   r   r   _eval_evalfr	   r
   r.   precs     r4   rE  zEi._eval_evalf  sV    IIaLB'44''d3qt6H6H6NNN##D$//r6   c                 V    ddl m}  |dt        d      |z         t        t        z  z
  S )Nr   rv   r   )ry   rw   r   r	   r
   r{   s       r4   r~   zEi._eval_rewrite_as_uppergamma  s)    F 1jnQ.//!B$66r6   c                 P    t        dt        d      |z         t        t        z  z
  S )Nr;   r   )r   r   r	   r
   r   s      r4   r   zEi._eval_rewrite_as_expint  s$    q*R.*++ad22r6   c                 z    t        |t              rt        |j                  d         S t        t	        |            S rb   )rN   r   lir(   r   r   s      r4   _eval_rewrite_as_lizEi._eval_rewrite_as_li  s.    aaffQi= 
 #a&zr6   c                     |j                   r%t        |      t        |      z   t        t        z  z
  S t        |      t        |      z   S r   )is_negativeShiChir	   r
   r   s      r4   _eval_rewrite_as_SizEi._eval_rewrite_as_Si  s6    ==q6CF?QrT))q6CF?"r6   c                 0    t        |      t        |      z  S r   )r   _eisr   s       r4   r   zEi._eval_rewrite_as_tractable  s    1vQr6   c                    ddl m} | j                  d   j                  |d      }| j                  d   j	                  ||      }|j                  ||      }|j                  rm|j                  |      \  }}|t        |      n|}t        |      ||z  z   t        z    ||      j                  rt        t        z  z
  S t        j                  z
  S t        	| A  |||      S )Nr   )r   )r   r   )sympyr   r(   r   r   r   rM   as_coeff_exponentr   r   rN  r	   r
   r   r+   r   r   )
r.   r1   r   r   r   x0rU   cer   s
            r4   r   zEi._eval_as_leading_term  s    YYq\1%iil**14*8wwq$::((+DAq!\3q6tDq6AdF?Z/4,,": :23&&: :w,QT,EEr6   c                     | j                   d   j                  |d      }|j                  r, | j                  | j                    }|j	                  |||      S t
        |   |||      S rb   )r(   r   rM   rQ  _eval_nseriesr   r.   r1   r]   r   r   rW  fr   s          r4   r[  zEi._eval_nseries  sa    YYq\1%::((($))4A??1a..w$Q400r6   c                 2   ddl m} |d   }|t        j                  u r_| j                  d   }t        |      D cg c]  }t        |      ||z  z   c} |d||z  z  |      gz   }	t        |      |z  t        |	 z  S t        t        | /  ||||      S c c}w Nr   r   r;   )r   r   r   rI   r(   r   r   r   r   r   r>  r   r  s             r4   r   zEi._eval_aseries  s    ,aAJJ		!A05a911Q&91QT61%&'AF1HQ''R,Qq$??	 :s   Br   r   rb   r   )r   r   r   r   r   rW   r?   rE  r~   r   rL  rQ  _eval_rewrite_as_Ci_eval_rewrite_as_Chi_eval_rewrite_as_Shir   r   r[  r   r   r   s   @r4   r>  r>  1  sl    Tn % %50
73#
 ... 
F1
@ 
@r6   r>  c                   h     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 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        |      }||k7  rt	        ||      S |j
                  r|dk  s|j
                  s6d|z  j
                  r't        t        ||dz
  z   |d|z
  |      z              S |j                         \  }}|t        j                  u ry |j                  r^|dkD  sy 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   )gammarw   r'   r;   )ry   rf  rw   r   r   
is_Integerr   r@  r   r+   
is_integerr
   r	   rL   r   r   )rT   nur|   rf  rw   nu2r]   s          r4   rW   zexpint.evalK  s=   On9#q>!==R1WR]]"?P?PjR!VZB5J)JKLL &&(1;==6"a=B$q&(1==26229R!V3DDZPQ]UWZ[U[E\\] ] !Br	!$q(!b1f+5eAFmCfRQRmSSr6   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>   ri  r|   s       r4   r?   zexpint.fdiffa  sn    		Aq=QK<QFQ1r6NB JJJ]261%%%$T844r6   c                 8    ddl m} ||dz
  z   |d|z
  |      z  S )Nr   rv   r;   )ry   rw   )r.   ri  r|   r}   rw   s        r4   r~   z"expint._eval_rewrite_as_uppergammaj  s#    F26{:a"fa000r6   c                    |dk(  r2t        |t        t         t        z        z         t        t        z  z
  S |j                  r|dkD  rt        |       }||dz
  z  t        |dz
        z  t        |      j                  t               z  t        |      t        |dz
        z  t        t        |dz
        D cg c]  }t        ||z
  dz
        ||z  z   c} z  z   S | S c c}w r:  )r>  r   r	   r
   rg  r   r   E1r   r   r   r   )r.   ri  r|   r}   r1   r_   s         r4   _eval_rewrite_as_Eizexpint._eval_rewrite_as_Ein  s    7qA2b5))**QrT11]]rAvAArAv;ya00Ar1BBAya((%Q-HQiQ
+AqD0HIJJ J K Is   8C c                 V     | j                  t              j                   t        fi |S r   )r   r>  r   r   s     r4   r   zexpint._eval_expand_funcz  s#    't||B''8%88r6   c                 >    |dk7  r| S t        |      t        |      z
  S r+  )rO  rP  )r.   ri  r|   r}   s       r4   rQ  zexpint._eval_rewrite_as_Si}  s     7K1vAr6   c                 \   | j                   d   j                  |      s}| j                   d   }|dk(  r, | j                  | j                    }|j                  |||      S |j                  r1|dkD  r, | j
                  | j                    }|j                  |||      S t        |   |||      S rF   )r(   hasrQ  r[  rg  ro  r   )r.   r1   r]   r   r   ri  r]  r   s          r4   r[  zexpint._eval_nseries  s    yy|"1BQw,D,,dii8q!T2226,D,,dii8q!T22w$Q400r6   c                 |   ddl m} |d   }| j                  d   }|t        j                  u ru| j                  d   }t        |      D 	cg c](  }	t        j                  |	z  t        ||	      z  ||	z  z  * c}	 |d||z  z  |      gz   }
t        |       |z  t        |
 z  S t        t        | 3  ||||      S c c}	w r_  )r   r   r(   r   rI   r   rL   r   r   r   r   r   r   )r.   r]   r   r1   r   r   r   ri  r|   r_   r   r   s              r4   r   zexpint._eval_aseries  s    ,aYYq\AJJ		!AKPQR8Ta!OB$::QTATX]^_`acd`d^dfgXhWiiAGAIa((VT0E1dCC Us   
-B9r`  )r   r   r   r   r   rW   r?   r~   ro  r   rQ  ra  rb  rc  r[  r   r   r   s   @r4   r   r     s^    dN T T*51
9 ...	1
D 
Dr6   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    r4   rn  rn    s    @ !Q<r6   c                   v    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y)rK  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 y r   )rM   r   r+   rJ   rK   rI   r2  s     r4   rW   zli.eval$  sS    9966M!%%Z%%%!**_::9966M r6   c                 z    | j                   d   }|dk(  rt        j                  t        |      z  S t	        | |      rF   r(   r   rJ   r   r   rC  s      r4   r?   zli.fdiff/  6    iilq=553s8##$T844r6   c                 x    | j                   d   }|j                  s| j                  |j                               S y rb   )r(   is_extended_negativer-   rd   r.   r|   s     r4   rf   zli._eval_conjugate6  s2    IIaL%%99Q[[]++ &r6   c                 0    t        |      t        d      z   S r   )LirK  r   s      r4   _eval_rewrite_as_Lizli._eval_rewrite_as_Li<      !ur!u}r6   c                 *    t        t        |            S r   )r>  r   r   s      r4   ro  zli._eval_rewrite_as_Ei?  s    #a&zr6   c           	          ddl m}  |dt        |              t        j                  t        t        |            t        t        j
                  t        |      z        z
  z  z   t        t        |             z
  S Nr   rv   )ry   rw   r   r   rz   rJ   r{   s       r4   r~   zli._eval_rewrite_as_uppergammaB  s`    FAAw''CFc!%%A,&7789;>Aw<H 	Ir6   c                 N   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   rz   rJ   r   s      r4   rQ  zli._eval_rewrite_as_SiG  sp    1SV8qAc!fH~-AEE#a&L)CAK789;>qQx=I 	Jr6   c                     t        t        |            t        t        |            z
  t        j                  t        t        j
                  t        |      z        t        t        |            z
  z  z
  S r   )rP  r   rO  r   rz   rJ   r   s      r4   rc  zli._eval_rewrite_as_ShiM  sJ    CFc#a&k)AFFCc!f4ECPQF4S,TTUr6   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   rz   rJ   r   r   s      r4   r   zli._eval_rewrite_as_hyperR  sY    AuVVSV44CFc!%%A,&7789;EF 	Gr6   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   rz   rJ   r$   r   s      r4   r   zli._eval_rewrite_as_meijergV  sY    c!fWAEE#a&L(9CAK(G HH*lSVG<= 	>r6   Nc                 0    |t        t        |            z  S r   )rS  r   r   s       r4   r   zli._eval_rewrite_as_tractableZ  s    4A<r6   c                     | j                   d   }t        d|      D cg c]  }t        |      |z  t        |      |z  z  ! }}t        t        t        |            z   t        | z   S c c}w rF   )r(   r   r   r   r   r   )r.   r1   r]   r   r   r|   r_   r   s           r4   r[  zli._eval_nseries]  s`    IIaL7<Q{C!c!fq[IaL1,-CCCAK'#q'11 Ds   $A(c                 <    | j                   d   }|j                  ryy rm   rq   r}  s     r4   rr   zli._eval_is_zerob      IIaL99 r6   r   r   r`  )r   r   r   r   r   rW   r?   rf   r  ro  r~   rQ  ra  rc  rb  r   r   r   r[  rr   r   r6   r4   rK  rK    sm    `F  5,I
J .V 0G> 2
r6   rK  c                   D    e Zd ZdZed        Zd	dZd Zd Zd
dZ	ddZ
y)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                     |t         j                  u rt         j                  S |t        d      k(  rt         j                  S y r   )r   rI   r+   r2  s     r4   rW   zLi.eval  s0    

?::!A$Y66M r6   c                 z    | j                   d   }|dk(  rt        j                  t        |      z  S t	        | |      rF   ry  rC  s      r4   r?   zLi.fdiff  rz  r6   c                 J    | j                  t              j                  |      S r   )r   rK  evalfrF  s     r4   rE  zLi._eval_evalf  s    ||B%%d++r6   c                 0    t        |      t        d      z
  S r   )rK  r   s      r4   rL  zLi._eval_rewrite_as_li  r  r6   Nc                 N    | j                  t              j                  dd      S )Nr   T)r/   )r   rK  r   s       r4   r   zLi._eval_rewrite_as_tractable  s!    ||B''$'??r6   c                 Z     | j                   | j                   }|j                  |||      S r   )rL  r(   r[  )r.   r1   r]   r   r   r]  s         r4   r[  zLi._eval_nseries  s+    $D$$dii0q!T**r6   r   r   r`  )r   r   r   r   r   rW   r?   rE  rL  r   r[  r   r6   r4   r  r  g  s6    =@  5,@+r6   r  c                   H     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                 V   |t         j                  u r| j                  S |t         j                  u r| j	                         S |t         j
                  u r| j                         S |j                  r| j                  S |j                  t        t                    }|)| j                  d      dk(  r|j                  t              }|| j                  |d      S |j                  t        t                     }|| j                  |d      S |j                  t        d            }|%| j                  d      dk(  r|j                  d      }|| j                  |      S |j                         \  }}|dk(  r||k(  ry dt        z  t        z  |z  | j                  d      z   | |      z   S )Nr   r;   r   r'   )r   r+   _atzerorI   _atinfrK   	_atneginfrM   rQ   r   r	   	_trigfunc_Ifactor_minusfactorr@  r
   rA  s       r4   rW   zTrigonometricIntegral.eval  sn   ;;;!**_::<!$$$==?"99;;''
16:#--*a/++A.B><<A&&''
A27><<B''''
27:#--*a/++B/B>##B'''')A6bAgtAvaxa((3r722r6   c                 |    t        | j                  d         }|dk(  r| j                  |      |z  S t        | |      rF   )r   r(   r  r   rC  s      r4   r?   zTrigonometricIntegral.fdiff  s<    1&q=>>#&s**$T844r6   c                 J    | j                  |      j                  t              S r   )r   r   r>  r   s      r4   ro  z)TrigonometricIntegral._eval_rewrite_as_Ei  s    ++A.66r::r6   c                 N    ddl m} | j                  |      j                  |      S r  )ry   rw   r   r   r{   s       r4   r~   z1TrigonometricIntegral._eval_rewrite_as_uppergamma  s!    F++A.66zBBr6   c                    |dz  }| j                   d   j                  |d      dk7  rt        |   |||      S | j	                  |      j                  |||      }| j	                  d      dk7  r|dz  }|j                  t        d d      }| j	                  d      dk7  r|t        t        |      z   z  }|j                  || j                   d         j                  |||      S )Nr;   r   c                     | |z  |z  S r   r   )rV   r]   s     r4   <lambda>z5TrigonometricIntegral._eval_nseries.<locals>.<lambda>  s    !Q$q& r6   F)simultaneous)	r(   r   r   r[  r  replacer   r   r   )r.   r1   r]   r   r   
baseseriesr   s         r4   r[  z#TrigonometricIntegral._eval_nseries  s    	Q99Q<Q"a'7(At44^^A&44Q4@
>>!!!OJ''-@u'U
>>!!*s1v--Jq$))A,/==aDIIr6   r   r`  )r   r   r   r   r   rW   r?   ro  r~   r[  r   r   s   @r4   r  r    s6    3 3 3>5;CJ Jr6   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 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                 0    t         t        j                  z  S r   r
   r   rz   rT   s    r4   r  z	Si._atinfQ  s    !&&yr6   c                 2    t          t        j                  z  S r   r  r  s    r4   r  zSi._atneginfU  s    s166zr6   c                     t        |       S r   )r  r2  s     r4   r  zSi._minusfactorY  s    1vr6   c                 ,    t         t        |      z  |z  S r   )r	   rO  rT   r|   signs      r4   r  zSi._Ifactor]  s    Qx}r6   c                     t         dz  t        t        t              |z        t        t        t               |z        z
  dz  t        z  z   S r   )r
   rn  r   r	   r   s      r4   r   zSi._eval_rewrite_as_expinta  s=    !tr*Q-/*R
A2q0@-AA1DQFFFr6   c                 R    ddl m} t        dd      } |t        |      |d|f      S )Nr   )IntegralrV   T)Dummy)sympy.integrals.integralsr  r   r"   )r.   r|   r}   r  rV   s        r4   _eval_rewrite_as_sinczSi._eval_rewrite_as_since  s(    63d#Q!Q++r6   c                    ddl m} |d   }|t        j                  u r| j                  d   }t        t        |dz
  dz              D cg c]-  }t        j                  |z  t        d|z        z  |d|z  z  z  / c} |d||z  z  |      gz   }	t        t        |dz        dz
        D cg c]3  }t        j                  |z  t        d|z  dz         z  |d|z  dz   z  z  5 c} |d||z  z  |      gz   }
t        dz  t        |      |z  t        |	 z  z
  t        |      |z  t        |
 z  z
  S t        t        | ?  ||||      S c c}w c c}w Nr   r   r;   r'   )r   r   r   rI   r(   r   intrL   r   r
   r    r   r!   r   r  r   r.   r]   r   r1   r   r   r   r|   r_   pqr   s              r4   r   zSi._eval_aseriesj  s]   ,a AJJ		!A"3Aqy>24 !IacN2Q1X= 47<Qq!tVQ7G6HIA #3qs8a<02 !IacAg$66QqS1WE 25:1QT615E4FGAa43q6!8S!W,,Aq#q'/AAA R,Qq$??42s   2E-8Ec                 <    | j                   d   }|j                  ryy rm   rq   r}  s     r4   rr   zSi._eval_is_zeroz  r  r6   )r   r   r   r   r!   r  r   r+   r  r   r  r  r  r  r   r  r   rr   r   r   s   @r4   r  r    s~    DL IffG       G,
@ r6   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	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    r4   r  z	Ci._atinf  s    vvr6   c                     t         t        z  S r   )r	   r
   r  s    r4   r  zCi._atneginf  s    tr6   c                 4    t        |      t        t        z  z   S r   r  r	   r
   r2  s     r4   r  zCi._minusfactor  s    !uqt|r6   c                 @    t        |      t        t        z  dz  |z  z   S r   rP  r	   r
   r  s      r4   r  zCi._Ifactor  s    1v"Qt##r6   c                 z    t        t        t              |z        t        t        t               |z        z    dz  S r   )rn  r   r	   r   s      r4   r   zCi._eval_rewrite_as_expint  s2    JqM!O$r*aR.*:';;<Q>>r6   c                    | j                   d   j                  |||      }|j                  |d      }|t        j                  u r+|j                  |dt        |      j                  rdnd      }|j                  r;|j                  |      \  }}|t        |      n|}t        |      ||z  z   t        z   S |j                  r| j                  |      S | S Nr   r   r   r   r   r(   r   r   r   rH   r   r   rN  rM   rV  r   r   rn   r-   r.   r1   r   r   rU   r   rX  rY  s           r4   r   zCi._eval_as_leading_term      iil**14d*Cxx1~155=99Qbh.B.Bs9LD<<((+DAq!\3q6tDq6AdF?Z//^^99T?"Kr6   c                    ddl m} |d   }|t        j                  u r| j                  d   }t        t        |dz
  dz              D cg c]-  }t        j                  |z  t        d|z        z  |d|z  z  z  / c} |d||z  z  |      gz   }	t        t        |dz        dz
        D cg c]3  }t        j                  |z  t        d|z  dz         z  |d|z  dz   z  z  5 c} |d||z  z  |      gz   }
t        |      |z  t        |	 z  t        |      |z  t        |
 z  z
  S t        t        | ;  ||||      S c c}w c c}w r  )r   r   r   rI   r(   r   r  rL   r   r!   r   r    r   r  r   r  s              r4   r   zCi._eval_aseries  sT   ,a AJJ		!A"3Aqy>24 !IacN2Q1X= 47<Qq!tVQ7G6HIA #3qs8a<02 !IacAg$66QqS1WE 25:1QT615E4FGAF1Hc1g%Q37(::: R,Qq$??42s   2D>-8Erb   )r   r   r   r   r    r  r   r   r  r   r  r  r  r  r   r   r   r   r   s   @r4   r  r    s    M^ IG      $ $?@ @r6   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y)rO  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   rI   r  s    r4   r  z
Shi._atinfI      zzr6   c                 "    t         j                  S r   )r   rK   r  s    r4   r  zShi._atneginfM  s    !!!r6   c                     t        |       S r   )rO  r2  s     r4   r  zShi._minusfactorQ  s    Awr6   c                 ,    t         t        |      z  |z  S r   )r	   r  r  s      r4   r  zShi._IfactorU  s    Awt|r6   c                     t        |      t        t        t        t        z        |z        z
  dz  t        t        z  dz  z
  S r   )rn  r   r	   r
   r   s      r4   r   zShi._eval_rewrite_as_expintY  s5    19QrT?1,--q01R4699r6   c                 <    | j                   d   }|j                  ryy rm   rq   r}  s     r4   rr   zShi._eval_is_zero]  r  r6   Nc                 6   | j                   d   j                  |      }|j                  |d      }|t        j                  u r+|j                  |dt        |      j                  rdnd      }|j                  r|S |j                  s| j                  |      S | S )Nr   r   r   r   )r(   r   r   r   rH   r   r   rN  rM   r  r-   r   s         r4   r   zShi._eval_as_leading_termb  s~    iil**1-xx1~155=99Qbh.B.Bs9LD<<J!!99T?"Kr6   rb   )r   r   r   r   r   r  r   r+   r  r   r  r  r  r  r   rr   r   r   r6   r4   rO  rO    su    =~ IffG  " "    :
r6   rO  c                   z    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y)
rP  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    r4   r  z
Chi._atinf  r  r6   c                 "    t         j                  S r   r  r  s    r4   r  zChi._atneginf  r  r6   c                 4    t        |      t        t        z  z   S r   r  r2  s     r4   r  zChi._minusfactor  s    1v"}r6   c                 @    t        |      t        t        z  dz  |z  z   S r   r  r  s      r4   r  zChi._Ifactor  s    !uqtAvd{""r6   c                     t          t        z  dz  t        |      t        t        t         t        z        |z        z   dz  z
  S r   )r	   r
   rn  r   r   s      r4   r   zChi._eval_rewrite_as_expint  s7    r"uQw"Q%"Yqt_Q%6"77:::r6   Nc                    | j                   d   j                  |||      }|j                  |d      }|t        j                  u r+|j                  |dt        |      j                  rdnd      }|j                  r;|j                  |      \  }}|t        |      n|}t        |      ||z  z   t        z   S |j                  r| j                  |      S | S r  r  r  s           r4   r   zChi._eval_as_leading_term  r  r6   rb   )r   r   r   r   r   r  r   r   r  r   r  r  r  r  r   r   r   r6   r4   rP  rP  p  ss    HT IG      # #;r6   rP  c                   F    e Zd ZdZdZed        Zd	dZd ZeZ	d Z
d ZeZy)
FresnelIntegralz& Base class for the Fresnel integrals.Tc                 X   |t         j                  u rt         j                  S |j                  rt         j                  S t         j
                  }|}d}|j                  d      }|| }|}d}|j                  t              }|| j                  t        z  |z  }|}d}|r| | |      z  S y )NFr   T)	r   rI   rz   rM   r+   rJ   rQ   r	   _sign)rT   r|   prefactnewargchangedr   s         r4   rW   zFresnelIntegral.eval  s     

?66M 9966M %%,,R0>hGFG,,Q/>iik')GFG3v;&& r6   c                     |dk(  r9| j                  t        j                  t        z  | j                  d   dz  z        S t        | |      r%  )r  r   rz   r
   r(   r   r=   s     r4   r?   zFresnelIntegral.fdiff		  s>    q=>>!&&)DIIaL!O";<<$T844r6   c                 4    | j                   d   j                  S rb   ri   re   s    r4   r   z&FresnelIntegral._eval_is_extended_real	  rk   r6   c                 4    | j                   d   j                  S rb   rq   re   s    r4   rr   zFresnelIntegral._eval_is_zero	  rs   r6   c                 Z    | j                  | j                  d   j                               S rb   rc   re   s    r4   rf   zFresnelIntegral._eval_conjugate	  rg   r6   Nr   )r   r   r   r   r   r   rW   r?   r   ro   rr   rf   r5   r,   r   r6   r4   r  r    s>    0J' '<5- -O$3 -Lr6   r  c                   t     e Zd ZdZeZej                   Ze	e
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                 n   | dk  rt         j                  S t        |      }t        |      dkD  r9|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   rZ   r   r+   r   r[   r
   r   r]   r1   r^   r  s       r4   r`   zfresnels.taylor_termu	  s     q566M
A>"Q&"2&Qq!tQqS1W-qsAaC!G}acAg/FG1LL!t1uqj(AaD2a4!8,<R!A#'],JKPQRSPSVWPWYbcdefcfijcjYkOkllr6   c           	          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   rJ   r	   r8   r   r
   r   s      r4   r   zfresnels._eval_rewrite_as_erf	  f    	1}QUUQYM$r($:1$< =#quuqyRSmTXY[T\F\]^F^B_@_ _``r6   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      r4   r   zfresnels._eval_rewrite_as_hyper	  sY    !Q$wqy5(1a.!1HQNHQPQN3SVXZ[V[U[\]_`\`U`acUcdddr6   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      r4   r   z!fresnels._eval_rewrite_as_meijerg	  s    1hq!n$$QAA0F(FXVWYZ^G[([\"qcHQN#3hq!na5H2q5&QRTUQU+VX.YZ 	[r6   c                    ddl m} | j                  d   j                  |||      }|j	                  |d      }|t
        j                  u r+|j                  |dt        |      j                  rdnd      }|j                  rt        |dz  z  dz  S |t
        j                  t
        j                  fv r3|t
        j                  u rd	nd
}|t
        j                  z   |||      z   S | j                  |      S )Nr   r   r   r   r   r   r   r  r;   r   )r   r   r(   r   r   r   r   r   r   rN  rM   r
   rI   rK   rz   r-   r.   r1   r   r   r   rU   r   r   s           r4   r   zfresnels._eval_as_leading_term	  s    ,iil**14d*Cxx1~1$$$99Qbh.B.Bs9LD<<c1f9Q;ajj!"4"455QZZ'RAQVV8eAqk))99T?"r6   c           
      n   ddl m} |d   }|t        j                  t        j                   fv r| j                  d   }t        d|      D cg c]b  }d|z  dz   |k  rUt        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  d }	}dd|z  z  gt        d|      D cg c]h  }d|z  dz   |k  r[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  j c}z   }
|	D cg c]  }t        dt        z         |z   }	}|
D cg c]  }t        dt        z         |z   }
}|t        j                  u rdnd}|t        j                  z  t        |dz        t        |	 z  t        |dz        t        |
 z  z   j                  |t        dt        z        |z        z    |d||z  z  |      z   S t        | A  ||||      S c c}w c c}w c c}w c c}w Nr   r   r  r   r;   r'   r   )r   r   r   rI   r(   r   rL   r   r   r
   rz   r!   r   r    r   r   r   r.   r]   r   r1   r   r   r   r|   r_   r  r  rV   r   r   s                r4   r   zfresnels._eval_aseries	  sV   ,a QZZ!**--		!A  1+61q1 !IacAg$66acAg,QqS1W-AaC81Q3GI 6A 6 AaC	1+61q1 ]]A-	!A#'0BBacAg,QqS1W-AaC!G<YqsQw=OOQ 6 6A )**1$qt*Q*A*()*1$qt*Q*A*ajj(bA QVV8s1a4ya03q!t9S!W3DD$q$qt*Q,'(*/!Q$*:; ; w$Qq$77#66 +*s   A'H#A-H(H-&H2rb   )r   r   r   r   r!   r  r   rJ   r  r   r   r`   r   r   r   r   r   r   r   s   @r4   r   r   	  sY    Sh IUUFE	m  	mae[#8 8r6   r   c                   r     e Zd ZdZeZej                  Ze	e
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                 V   | dk  rt         j                  S t        |      }t        |      dkD  r9|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  rZ   r  r  s       r4   r`   zfresnelc.taylor_term
  s     q566M
A>"Q&"2&Qq!tQqS1W-qsAaC!G}acAg/FG1LLQTEA:~11b1Q3i)?@QqS1WiXYZ[X[nD\]]r6   c           	          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      r4   r   zfresnelc._eval_rewrite_as_erf
  r  r6   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   rz   r
   r   s      r4   r   zfresnelc._eval_rewrite_as_hyper!
  sA    5(1a.)AFFHQN+Cb!eVAqD[QS^TTTr6   c           
          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      r4   r   z!fresnelc._eval_rewrite_as_meijerg$
  s    1hq!n$$QQT1(=dA2qk(IJ"qcHQN#3hq!na5H2q5&QRTUQU+VX.YZ 	[r6   c                    ddl m} | j                  d   j                  |||      }|j	                  |d      }|t
        j                  u r+|j                  |dt        |      j                  rdnd      }|j                  r|S |t
        j                  t
        j                  fv r3|t
        j                  u rdnd}|t
        j                  z   |||      z   S | j                  |      S )	Nr   r   r   r   r   r   r;   r   )r   r   r(   r   r   r   r   r   r   rN  rM   rI   rK   rz   r-   r  s           r4   r   zfresnelc._eval_as_leading_term(
  s    ,iil**14d*Cxx1~1$$$99Qbh.B.Bs9LD<<Jajj!"4"455QZZ'RAQVV8eAqk))99T?"r6   c           
      j   ddl m} |d   }|t        j                  t        j                   fv r| j                  d   }t        |      D cg c]b  }d|z  dz   |k  rUt        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  d }	}dd|z  z  gt        d|      D cg c]h  }d|z  dz   |k  r[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  j c}z   }
|	D cg c]  }t        dt        z         |z   }	}|
D cg c]  }t        dt        z        |z   }
}|t        j                  u rdnd}|t        j                  z  t        |dz        t        |	 z  t        |dz        t        |
 z  z   j                  |t        dt        z        |z        z    |d||z  z  |      z   S t        | A  ||||      S c c}w c c}w c c}w c c}w r  )r   r   r   rI   r(   r   rL   r   r   r
   rz   r    r   r!   r   r   r   r  s                r4   r   zfresnelc._eval_aseries7
  sR   ,a QZZ!**--		!A  (3acAgk !IacAg$66acAg,QqS1W-AaC81Q3GI 3A 3 AaC	1+61q1 ]]A-	!A#'0BBacAg,QqS1W-AaC!G<YqsQw=OOQ 6 6A )**1$qt*Q*A*()*1$qt*Q,*A*ajj(bA QVV8s1a4ya03q!t9S!W3DD$q$qt*Q,'(*/!Q$*:; ; w$Qq$77#36 +*s   A'H!A-H&H+%H0rb   )r   r   r   r   r    r  r   rJ   r  r   r   r`   r   r   r   r   r   r   r   s   @r4   r   r   	  sW    Sh IEEE	^  	^aU[#8 8r6   r   c                   @     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 y r   )rM   r   rJ   )rT   rU   s     r4   rW   z
_erfs.eval`
  s    ;;55L r6   c                 P   ddl m} |d   }|t        j                  u r| j                  d   }t        |      D cg c]O  }dt        t              z  t        d|z        z  t        d       | z  z  t        |      z  d|z  d|z  dz   z  z  Q }	} |d|d|z  dz   z  z  |      }
t        |	 j                  |||      |
z   S |j                  t              }|t        j                  u r| j                  d   }t        |      D cg c]O  }dt        t              z  t        d|z        z  t        d       | z  z  t        |      z  d|z  d|z  dz   z  z  Q }	} |d|d|z  dz   z  z  |      }
t        |	 j                  |||      |
z   S t        | 9  ||||      S c c}w c c}w )Nr   r   r;   r'   r  )r   r   r   rI   r(   r   r   r
   r   r   r[  rQ   r	   r   r   )r.   r]   r   r1   r   r   r   r|   r_   lorV   r   s               r4   r   z_erfs._eval_aseriese
  s   ,a AJJ		!ADI!HN?@ 48i!n,q0 /r. $Q<(+,Q3!A#'*:; NA NaAaC!Gna(AG**1a6:: **1-

?		!A EJ!HN?@ 48i!n,q0 /r. $Q<(+,Q3!A#'*:; NA NaAaC!Gna(AG**1a6:: w$Qq$77%NNs   AFAF#c                     |dk(  r3| j                   d   }dt        t              z  d|z  t        |      z  z   S t	        | |      )Nr;   r   rZ   r'   )r(   r   r
   r   r   r.   r>   r|   s      r4   r?   z_erfs.fdiff
  sB    q=		!Ad2h;1U1X--$T844r6   c                 X    t         j                  t        |      z
  t        |dz        z  S r   )r   rJ   r8   r   r   s      r4   _eval_rewrite_as_intractablez"_erfs._eval_rewrite_as_intractable
  s!    AAqD	))r6   r   )
r   r   r   r   r   rW   r   r?   r  r   r   s   @r4   r   r   Z
  s+    
  865*r6   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 )
rS  z~
    Helper function to make the $\mathrm{Ei}(z)$ and $\mathrm{li}(z)$
    functions tractable for the Gruntz algorithm.

    c                 F   ddl m} |d   t        j                  k7  rt        t
        |   ||||      S | j                  d   }t        |      D cg c]  }t        |      d|z  |dz   z  z   }} |d||dz   z  z  |      }	t        | j                  |||      |	z   S c c}w r_  )r   r   r   rI   r   r   r   r(   r   r   r   r[  )r.   r]   r   r1   r   r   r|   r_   r	  r
  r   s             r4   r   z_eis._eval_aseries
  s    ,8qzz!3AuaFFIIaL49!H=qYq\QqSAEN*==!AAJ,"Q&&q!T2Q66 >s   Bc                     |dk(  r.| j                   d   }t        j                  |z  t        |      z
  S t	        | |      )Nr;   r   )r(   r   rJ   rS  r   r  s      r4   r?   z
_eis.fdiff
  s:    q=		!A5519tAw&&$T844r6   c                 2    t        |       t        |      z  S r   )r   r>  r   s      r4   r  z!_eis._eval_rewrite_as_intractable
  s    A2wr!u}r6   c                     | j                   d   j                  |d      }|j                  r- | j                  | j                    }|j	                  |||      S t
        |   |||      S )Nr   r   )r(   r   rM   r  r   r   )r.   r1   r   r   rW  r]  r   s         r4   r   z_eis._eval_as_leading_term
  si    YYq\1%::111499=A**14d*CCw,QT,EEr6   c                     | j                   d   j                  |d      }|j                  r, | j                  | j                    }|j	                  |||      S t
        |   |||      S rb   )r(   r   rM   r  r[  r   r\  s          r4   r[  z_eis._eval_nseries
  sa    YYq\1%::111499=A??1a..w$Q400r6   r   rb   r`  )
r   r   r   r   r   r?   r  r   r[  r   r   s   @r4   rS  rS  
  s'    	75F1 1r6   rS  N)T)Lr   
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   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$   r5   r8   r   r   r
  rC   rO   rP   r>  r   rn  rK  r  r  r  r  rO  rP  r  r   r   r   rS  r   r6   r4   <module>r'     s  F "  $ H H . . '   " $ & [ [ L L > ? F F < C C 8*^-( ^-B|H8 |H~}B8 }B@O!8 O!bZ$X Z$zO$x O$d[h [Bo@ o@dwDX wDt Fe eNZ+ Z+@=JH =J@v	 vrC@	 C@Lg
 gTn
 nj5-h 5-pY8 Y8xY8 Y8B.*H .*b*18 *1r6   