ó
¡¼™\c           @  sÄ  d  d l  m Z m Z d  d l m Z m Z m Z m Z m Z m	 Z	 m
 Z
 d  d l m Z d  d l m Z m Z d  d l m Z d  d l m Z d d l m Z d d	 l m Z m Z d  d
 l m Z m Z d  d l m Z m Z d  d l m  Z  d  d l! m" Z" m# Z# m$ Z$ d  d l% m& Z& m' Z' d  d l( m) Z) m* Z* m+ Z+ d e f d „  ƒ  YZ, d e f d „  ƒ  YZ- d e f d „  ƒ  YZ. d e f d „  ƒ  YZ/ d e f d „  ƒ  YZ0 d „  Z1 d „  Z2 d S(   iÿÿÿÿ(   t   print_functiont   division(   t   Addt   St   sympifyt   oot   pit   Dummyt   expand_func(   t   range(   t   Functiont   ArgumentIndexError(   t   Rational(   t   Powi   (   t   zeta(   t   erft   erfc(   t   expt   log(   t   ceilingt   floor(   t   sqrt(   t   sint   cost   cot(   t	   bernoullit   harmonic(   t	   factorialt   rft   RisingFactorialt   gammac           B  sw   e  Z d  Z e Z d d „ Z e d „  ƒ Z d „  Z d „  Z	 d „  Z
 d „  Z d „  Z d	 „  Z d
 „  Z d „  Z RS(   sÊ  
    The gamma function

    .. math::
        \Gamma(x) := \int^{\infty}_{0} t^{x-1} e^{-t} \mathrm{d}t.

    The ``gamma`` function implements the function which passes through the
    values of the factorial function, i.e. `\Gamma(n) = (n - 1)!` when n is
    an integer. More general, `\Gamma(z)` is defined in the whole complex
    plane except at the negative integers where there are simple poles.

    Examples
    ========

    >>> from sympy import S, I, pi, oo, gamma
    >>> from sympy.abc import x

    Several special values are known:

    >>> gamma(1)
    1
    >>> gamma(4)
    6
    >>> gamma(S(3)/2)
    sqrt(pi)/2

    The Gamma function obeys the mirror symmetry:

    >>> from sympy import conjugate
    >>> conjugate(gamma(x))
    gamma(conjugate(x))

    Differentiation with respect to x is supported:

    >>> from sympy import diff
    >>> diff(gamma(x), x)
    gamma(x)*polygamma(0, x)

    Series expansion is also supported:

    >>> from sympy import series
    >>> series(gamma(x), x, 0, 3)
    1/x - EulerGamma + x*(EulerGamma**2/2 + pi**2/12) + x**2*(-EulerGamma*pi**2/12 + polygamma(2, 1)/6 - EulerGamma**3/6) + O(x**3)

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

    >>> gamma(pi).evalf(40)
    2.288037795340032417959588909060233922890
    >>> gamma(1+I).evalf(20)
    0.49801566811835604271 - 0.15494982830181068512*I

    See Also
    ========

    lowergamma: Lower incomplete gamma function.
    uppergamma: Upper incomplete gamma function.
    polygamma: Polygamma function.
    loggamma: Log Gamma function.
    digamma: Digamma function.
    trigamma: Trigamma function.
    sympy.functions.special.beta_functions.beta: Euler Beta function.

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Gamma_function
    .. [2] http://dlmf.nist.gov/5
    .. [3] http://mathworld.wolfram.com/GammaFunction.html
    .. [4] http://functions.wolfram.com/GammaBetaErf/Gamma/
    i   c         C  sG   | d k r4 |  j  |  j d ƒ t d |  j d ƒ St |  | ƒ ‚ d  S(   Ni   i    (   t   funct   argst	   polygammaR   (   t   selft   argindex(    (    sF   lib/python2.7/site-packages/sympy/functions/special/gamma_functions.pyt   fdiffa   s    (c         C  sO  | j  rK| t j k r t j S| t j k r5 t j S| j r_ | j rU t | d ƒ St j SqK| j rK| j	 d k rHt
 | j ƒ | j	 } | j r© | t j } } n3 | d } } | d @d k rÓ t j } n	 t j } x( t d d | d ƒ D] } | | 9} qó W| j r)| t t j ƒ d | Sd | t t j ƒ | SqHqKn  d  S(   Ni   i   i    i   (   t	   is_NumberR   t   NaNt   Infinityt
   is_Integert   is_positiveR   t   ComplexInfinityt   is_Rationalt   qt   abst   pt   Onet   NegativeOneR	   R   t   Pi(   t   clst   argt   nt   kt   coefft   i(    (    sF   lib/python2.7/site-packages/sympy/functions/special/gamma_functions.pyt   evalg   s.    			
				c   	      K  s%  |  j  d } | j r t | j ƒ | j k r t d ƒ } | j | j } | j | | j } |  j | | ƒ j ƒ  j | t	 | | j ƒ ƒ Sn  | j
 r| j ƒ  \ } } | ræ | j d k ræ t | ƒ } | | f | } | } n  | j d t | Œ } |  j | ƒ t | | ƒ S|  j |  j  Œ  S(   Ni    t   xi   t   reeval(   R    R+   R-   R.   R,   R   R   t   _eval_expand_funct   subsR   t   is_Addt   as_coeff_addR   t   _new_rawargst   FalseR   (	   R"   t   hintsR3   R9   R4   R.   R6   t   tailt   intpart(    (    sF   lib/python2.7/site-packages/sympy/functions/special/gamma_functions.pyR;   ‰   s     	2		c         C  s   |  j  |  j d j ƒ  ƒ S(   Ni    (   R   R    t	   conjugate(   R"   (    (    sF   lib/python2.7/site-packages/sympy/functions/special/gamma_functions.pyt   _eval_conjugate   s    c         C  s'   |  j  d } | j s | j r# t Sd  S(   Ni    (   R    R)   t   is_nonintegert   True(   R"   R9   (    (    sF   lib/python2.7/site-packages/sympy/functions/special/gamma_functions.pyt   _eval_is_real    s    c         C  s4   |  j  d } | j r t S| j r0 t | ƒ j Sd  S(   Ni    (   R    R)   RG   RF   R   t   is_even(   R"   R9   (    (    sF   lib/python2.7/site-packages/sympy/functions/special/gamma_functions.pyt   _eval_is_positive¥   s
    		c         K  s   t  t | ƒ ƒ S(   N(   R   t   loggamma(   R"   t   zt   kwargs(    (    sF   lib/python2.7/site-packages/sympy/functions/special/gamma_functions.pyt   _eval_rewrite_as_tractable¬   s    c         K  s   t  | d ƒ S(   Ni   (   R   (   R"   RL   RM   (    (    sF   lib/python2.7/site-packages/sympy/functions/special/gamma_functions.pyt   _eval_rewrite_as_factorial¯   s    c         C  s”   |  j  d j | d ƒ } | j o+ | d k sJ t t |  ƒ j | | | ƒ S|  j  d | } |  j | d ƒ t |  j  d | d ƒ j | | | ƒ S(   Ni    i   (   R    t   limitR(   t   superR   t   _eval_nseriesR   R   (   R"   R9   R4   t   logxt   x0t   t(    (    sF   lib/python2.7/site-packages/sympy/functions/special/gamma_functions.pyRR   ²   s
    c         C  s)   d d  l  j } | j |  j d j ƒ  ƒ S(   Niÿÿÿÿi    (   t   sage.allt   allR   R    t   _sage_(   R"   t   sage(    (    sF   lib/python2.7/site-packages/sympy/functions/special/gamma_functions.pyRX   ¹   s    (   t   __name__t
   __module__t   __doc__RG   t
   unbranchedR$   t   classmethodR8   R;   RE   RH   RJ   RN   RO   RR   RX   (    (    (    sF   lib/python2.7/site-packages/sympy/functions/special/gamma_functions.pyR      s   G"							t
   lowergammac           B  sM   e  Z d  Z d d „ Z e d „  ƒ Z d „  Z d „  Z d „  Z d „  Z	 RS(   sÇ  
    The lower incomplete gamma function.

    It can be defined as the meromorphic continuation of

    .. math::
        \gamma(s, x) := \int_0^x t^{s-1} e^{-t} \mathrm{d}t = \Gamma(s) - \Gamma(s, x).

    This can be shown to be the same as

    .. math::
        \gamma(s, x) = \frac{x^s}{s} {}_1F_1\left({s \atop s+1} \middle| -x\right),

    where :math:`{}_1F_1` is the (confluent) hypergeometric function.

    Examples
    ========

    >>> from sympy import lowergamma, S
    >>> from sympy.abc import s, x
    >>> lowergamma(s, x)
    lowergamma(s, x)
    >>> lowergamma(3, x)
    -2*(x**2/2 + x + 1)*exp(-x) + 2
    >>> lowergamma(-S(1)/2, x)
    -2*sqrt(pi)*erf(sqrt(x)) - 2*exp(-x)/sqrt(x)

    See Also
    ========

    gamma: Gamma function.
    uppergamma: Upper incomplete gamma function.
    polygamma: Polygamma function.
    loggamma: Log Gamma function.
    digamma: Digamma function.
    trigamma: Trigamma function.
    sympy.functions.special.beta_functions.beta: Euler Beta function.

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Incomplete_gamma_function#Lower_incomplete_Gamma_function
    .. [2] Abramowitz, Milton; Stegun, Irene A., eds. (1965), Chapter 6, Section 5,
           Handbook of Mathematical Functions with Formulas, Graphs, and Mathematical Tables
    .. [3] http://dlmf.nist.gov/8
    .. [4] http://functions.wolfram.com/GammaBetaErf/Gamma2/
    .. [5] http://functions.wolfram.com/GammaBetaErf/Gamma3/
    i   c         C  sÌ   d d l  m } m } | d k rN |  j \ } } t | | ƒ ƒ | | d S| d k r¹ |  j \ } } t | ƒ t | ƒ t | ƒ t | | ƒ | g  d d g d d | g g  | ƒ St	 |  | ƒ ‚ d  S(   Niÿÿÿÿ(   t   meijergt
   unpolarifyi   i   i    (
   t   sympyR`   Ra   R    R   R   t   digammaR   t
   uppergammaR   (   R"   R#   R`   Ra   t   aRL   (    (    sF   lib/python2.7/site-packages/sympy/functions/special/gamma_functions.pyR$   õ   s    Pc   	   
   C  sñ  d d l  m } m } | d k r) t j S| j ƒ  \ } } | j ru | j ru | | ƒ } | | k rú t | | ƒ Sn… | j rÇ | j	 rÇ | d k rú d t
 | | d | t | ƒ t | | ƒ Sn3 | d k rú t d t
 | | | ƒ t | | ƒ S| j rí| t j k r$t j t | ƒ S| t j k rMt t
 ƒ t t | ƒ ƒ S| j scd | j rí| d } | j rJ| j rÏt | ƒ t | ƒ t | ƒ t g  t | ƒ D] } | | t | ƒ ^ q¬Œ  St | ƒ t t j | ƒ t t
 ƒ t | ƒ t g  t d | t j ƒ D]( } | | t j t t j | ƒ ^ qŒ  Sn  | j sêd t j | t
 t t | ƒ ƒ t d | ƒ t | ƒ t g  t d t d ƒ d | ƒ D]0 } | | | d t | ƒ t | | ƒ ^ q®Œ  Sqín  d  S(   Niÿÿÿÿ(   Ra   t   Ii    i   i   i   (   Rb   Ra   Rf   R   t   Zerot   extract_branch_factort
   is_integerR)   R_   t   is_nonpositiveR   R   R   R%   R/   t   HalfR   R   R(   R   R	   R   (	   R2   Re   R9   Ra   Rf   t   nxR4   t   bR5   (    (    sF   lib/python2.7/site-packages/sympy/functions/special/gamma_functions.pyR8     s4    4'	
		P{	c         C  s«   d d l  m } m } d d l m } t d „  |  j Dƒ ƒ r£ |  j d j | ƒ } |  j d j | ƒ } | | ƒ  | j | d | ƒ } Wd  QX| j	 | | ƒ S|  Sd  S(   Niÿÿÿÿ(   t   mpt   workprec(   t   Exprc         s  s   |  ] } | j  Vq d  S(   N(   t	   is_number(   t   .0R9   (    (    sF   lib/python2.7/site-packages/sympy/functions/special/gamma_functions.pys	   <genexpr>5  s    i    i   (
   t   mpmathRn   Ro   Rb   Rp   RW   R    t
   _to_mpmatht   gammainct   _from_mpmath(   R"   t   precRn   Ro   Rp   Re   RL   t   res(    (    sF   lib/python2.7/site-packages/sympy/functions/special/gamma_functions.pyt   _eval_evalf2  s    c         C  sL   |  j  d } | t j t j f k rH |  j |  j  d j ƒ  | j ƒ  ƒ Sd  S(   Ni   i    (   R    R   Rg   t   NegativeInfinityR   RD   (   R"   RL   (    (    sF   lib/python2.7/site-packages/sympy/functions/special/gamma_functions.pyRE   >  s    c         K  s   t  | ƒ t | | ƒ S(   N(   R   Rd   (   R"   t   sR9   RM   (    (    sF   lib/python2.7/site-packages/sympy/functions/special/gamma_functions.pyt   _eval_rewrite_as_uppergammaC  s    c         K  s<   d d l  m } | j r& | j r& |  S|  j t ƒ j | ƒ S(   Niÿÿÿÿ(   t   expint(   Rb   R}   Ri   Rj   t   rewriteRd   (   R"   R{   R9   RM   R}   (    (    sF   lib/python2.7/site-packages/sympy/functions/special/gamma_functions.pyt   _eval_rewrite_as_expintF  s    (
   RZ   R[   R\   R$   R^   R8   Ry   RE   R|   R   (    (    (    sF   lib/python2.7/site-packages/sympy/functions/special/gamma_functions.pyR_   Â   s   00			Rd   c           B  sV   e  Z d  Z d d „ Z d „  Z e d „  ƒ Z d „  Z d „  Z d „  Z	 d „  Z
 RS(	   s¡  
    The upper incomplete gamma function.

    It can be defined as the meromorphic continuation of

    .. math::
        \Gamma(s, x) := \int_x^\infty t^{s-1} e^{-t} \mathrm{d}t = \Gamma(s) - \gamma(s, x).

    where `\gamma(s, x)` is the lower incomplete gamma function,
    :class:`lowergamma`. This can be shown to be the same as

    .. math::
        \Gamma(s, x) = \Gamma(s) - \frac{x^s}{s} {}_1F_1\left({s \atop s+1} \middle| -x\right),

    where :math:`{}_1F_1` is the (confluent) hypergeometric function.

    The upper incomplete gamma function is also essentially equivalent to the
    generalized exponential integral:

    .. math::
        \operatorname{E}_{n}(x) = \int_{1}^{\infty}{\frac{e^{-xt}}{t^n} \, dt} = x^{n-1}\Gamma(1-n,x).

    Examples
    ========

    >>> from sympy import uppergamma, S
    >>> from sympy.abc import s, x
    >>> uppergamma(s, x)
    uppergamma(s, x)
    >>> uppergamma(3, x)
    2*(x**2/2 + x + 1)*exp(-x)
    >>> uppergamma(-S(1)/2, x)
    -2*sqrt(pi)*erfc(sqrt(x)) + 2*exp(-x)/sqrt(x)
    >>> uppergamma(-2, x)
    expint(3, x)/x**2

    See Also
    ========

    gamma: Gamma function.
    lowergamma: Lower incomplete gamma function.
    polygamma: Polygamma function.
    loggamma: Log Gamma function.
    digamma: Digamma function.
    trigamma: Trigamma function.
    sympy.functions.special.beta_functions.beta: Euler Beta function.

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Incomplete_gamma_function#Upper_incomplete_Gamma_function
    .. [2] Abramowitz, Milton; Stegun, Irene A., eds. (1965), Chapter 6, Section 5,
           Handbook of Mathematical Functions with Formulas, Graphs, and Mathematical Tables
    .. [3] http://dlmf.nist.gov/8
    .. [4] http://functions.wolfram.com/GammaBetaErf/Gamma2/
    .. [5] http://functions.wolfram.com/GammaBetaErf/Gamma3/
    .. [6] https://en.wikipedia.org/wiki/Exponential_integral#Relation_with_other_functions
    i   c         C  s¹   d d l  m } m } | d k rO |  j \ } } t | | ƒ ƒ | | d S| d k r¦ |  j \ } } t | | ƒ t | ƒ | g  d d g d d | g g  | ƒ St |  | ƒ ‚ d  S(   Niÿÿÿÿ(   R`   Ra   i   i   i    (   Rb   R`   Ra   R    R   Rd   R   R   (   R"   R#   R`   Ra   Re   RL   (    (    sF   lib/python2.7/site-packages/sympy/functions/special/gamma_functions.pyR$   Š  s    <c         C  sª   d d l  m } m } d d l m } t d „  |  j Dƒ ƒ r¦ |  j d j | ƒ } |  j d j | ƒ } | | ƒ  | j | | | j	 ƒ } Wd  QX| j
 | | ƒ S|  S(   Niÿÿÿÿ(   Rn   Ro   (   Rp   c         s  s   |  ] } | j  Vq d  S(   N(   Rq   (   Rr   R9   (    (    sF   lib/python2.7/site-packages/sympy/functions/special/gamma_functions.pys	   <genexpr>˜  s    i    i   (   Rs   Rn   Ro   Rb   Rp   RW   R    Rt   Ru   t   infRv   (   R"   Rw   Rn   Ro   Rp   Re   RL   Rx   (    (    sF   lib/python2.7/site-packages/sympy/functions/special/gamma_functions.pyRy   •  s    c   
   	   C  s  d d l  m } m } m } | j rm | t j k r; t j S| t j k rQ t j S| t j k rm t	 | ƒ Sn  | j
 ƒ  \ } } | j rÂ | d k t k rÂ | | ƒ } | | k rxt | | ƒ Sn¶ | j r| d k t k r| d k rxd t | | d | t | ƒ t | | ƒ Sn[ | d k rxt	 | ƒ d t d t | | | ƒ t d t | | | ƒ t | | ƒ S| j r™| t j k r›t | ƒ S| t j k rÄt t ƒ t t | ƒ ƒ S| j sÚd | j r™| d } | j rÓ| j r<t | ƒ t | ƒ t g  t | ƒ D] }	 | |	 t |	 ƒ ^ qŒ  St	 | ƒ t t | ƒ ƒ d | t d ƒ d t | ƒ t | ƒ t g  t | t j ƒ D]1 }	 t	 t j |	 ƒ | |	 t	 d | ƒ ^ q–Œ  Sn) | j rü| | | ƒ | | ƒ | d S| j s–d t j | t t t | ƒ ƒ t	 d | ƒ | | t | ƒ t g  t t j | ƒ D], }	 | |	 t	 | ƒ t	 | |	 d ƒ ^ q^Œ  Sq™n  d  S(   Niÿÿÿÿ(   Ra   Rf   R}   i    iþÿÿÿi   i   i   (   Rb   Ra   Rf   R}   R%   R   R&   R'   Rg   R   Rh   Ri   RG   Rd   R   R   R   R/   Rk   R   R   R(   R)   R   R	   (
   R2   Re   RL   Ra   Rf   R}   Rl   R4   Rm   R5   (    (    sF   lib/python2.7/site-packages/sympy/functions/special/gamma_functions.pyR8      sB    	4O	
		F—	 	c         C  sL   |  j  d } | t j t j f k rH |  j |  j  d j ƒ  | j ƒ  ƒ Sd  S(   Ni   i    (   R    R   Rg   Rz   R   RD   (   R"   RL   (    (    sF   lib/python2.7/site-packages/sympy/functions/special/gamma_functions.pyRE   Ë  s    c         K  s   t  | ƒ t | | ƒ S(   N(   R   R_   (   R"   R{   R9   RM   (    (    sF   lib/python2.7/site-packages/sympy/functions/special/gamma_functions.pyt   _eval_rewrite_as_lowergammaÐ  s    c         K  s)   d d l  m } | d | | ƒ | | S(   Niÿÿÿÿ(   R}   i   (   Rb   R}   (   R"   R{   R9   RM   R}   (    (    sF   lib/python2.7/site-packages/sympy/functions/special/gamma_functions.pyR   Ó  s    c         C  s9   d d  l  j } | j |  j d j ƒ  |  j d j ƒ  ƒ S(   Niÿÿÿÿi    i   (   RV   RW   R   R    RX   (   R"   RY   (    (    sF   lib/python2.7/site-packages/sympy/functions/special/gamma_functions.pyRX   ×  s    (   RZ   R[   R\   R$   Ry   R^   R8   RE   R   R   RX   (    (    (    sF   lib/python2.7/site-packages/sympy/functions/special/gamma_functions.pyRd   M  s   :	+			R!   c           B  sq   e  Z d  Z d d „ Z d „  Z d „  Z d „  Z d „  Z e d „  ƒ Z	 d „  Z
 d	 „  Z d
 „  Z d „  Z RS(   s'
  
    The function ``polygamma(n, z)`` returns ``log(gamma(z)).diff(n + 1)``.

    It is a meromorphic function on `\mathbb{C}` and defined as the (n+1)-th
    derivative of the logarithm of the gamma function:

    .. math::
        \psi^{(n)} (z) := \frac{\mathrm{d}^{n+1}}{\mathrm{d} z^{n+1}} \log\Gamma(z).

    Examples
    ========

    Several special values are known:

    >>> from sympy import S, polygamma
    >>> polygamma(0, 1)
    -EulerGamma
    >>> polygamma(0, 1/S(2))
    -2*log(2) - EulerGamma
    >>> polygamma(0, 1/S(3))
    -log(3) - sqrt(3)*pi/6 - EulerGamma - log(sqrt(3))
    >>> polygamma(0, 1/S(4))
    -pi/2 - log(4) - log(2) - EulerGamma
    >>> polygamma(0, 2)
    1 - EulerGamma
    >>> polygamma(0, 23)
    19093197/5173168 - EulerGamma

    >>> from sympy import oo, I
    >>> polygamma(0, oo)
    oo
    >>> polygamma(0, -oo)
    oo
    >>> polygamma(0, I*oo)
    oo
    >>> polygamma(0, -I*oo)
    oo

    Differentiation with respect to x is supported:

    >>> from sympy import Symbol, diff
    >>> x = Symbol("x")
    >>> diff(polygamma(0, x), x)
    polygamma(1, x)
    >>> diff(polygamma(0, x), x, 2)
    polygamma(2, x)
    >>> diff(polygamma(0, x), x, 3)
    polygamma(3, x)
    >>> diff(polygamma(1, x), x)
    polygamma(2, x)
    >>> diff(polygamma(1, x), x, 2)
    polygamma(3, x)
    >>> diff(polygamma(2, x), x)
    polygamma(3, x)
    >>> diff(polygamma(2, x), x, 2)
    polygamma(4, x)

    >>> n = Symbol("n")
    >>> diff(polygamma(n, x), x)
    polygamma(n + 1, x)
    >>> diff(polygamma(n, x), x, 2)
    polygamma(n + 2, x)

    We can rewrite polygamma functions in terms of harmonic numbers:

    >>> from sympy import harmonic
    >>> polygamma(0, x).rewrite(harmonic)
    harmonic(x - 1) - EulerGamma
    >>> polygamma(2, x).rewrite(harmonic)
    2*harmonic(x - 1, 3) - 2*zeta(3)
    >>> ni = Symbol("n", integer=True)
    >>> polygamma(ni, x).rewrite(harmonic)
    (-1)**(n + 1)*(-harmonic(x - 1, n + 1) + zeta(n + 1))*factorial(n)

    See Also
    ========

    gamma: Gamma function.
    lowergamma: Lower incomplete gamma function.
    uppergamma: Upper incomplete gamma function.
    loggamma: Log Gamma function.
    digamma: Digamma function.
    trigamma: Trigamma function.
    sympy.functions.special.beta_functions.beta: Euler Beta function.

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Polygamma_function
    .. [2] http://mathworld.wolfram.com/PolygammaFunction.html
    .. [3] http://functions.wolfram.com/GammaBetaErf/PolyGamma/
    .. [4] http://functions.wolfram.com/GammaBetaErf/PolyGamma2/
    i   c         C  sC   | d k r0 |  j  d  \ } } t | d | ƒ St |  | ƒ ‚ d  S(   Ni   i   (   R    R!   R   (   R"   R#   R4   RL   (    (    sF   lib/python2.7/site-packages/sympy/functions/special/gamma_functions.pyR$   @  s    c         C  s;   |  j  d j r7 |  j  d d k t k r7 |  j  d j Sd  S(   Ni   i    (   R    R)   RG   t   is_odd(   R"   (    (    sF   lib/python2.7/site-packages/sympy/functions/special/gamma_functions.pyRJ   G  s    )c         C  s;   |  j  d j r7 |  j  d d k t k r7 |  j  d j Sd  S(   Ni   i    (   R    R)   RG   RI   (   R"   (    (    sF   lib/python2.7/site-packages/sympy/functions/special/gamma_functions.pyt   _eval_is_negativeK  s    )c         C  s   |  j  d j S(   Ni    (   R    t   is_real(   R"   (    (    sF   lib/python2.7/site-packages/sympy/functions/special/gamma_functions.pyRH   O  s    c         C  s­  d d l  m } | d t k sA |  j d j o= |  j d j r` t t |  ƒ j | | | | ƒ S|  j d } |  j d } | d k r\t	 | ƒ d d | } d  }	 | d k  rÆ | d | | ƒ }	 n t | d d ƒ }
 g  t d |
 ƒ D]* } t d | ƒ d | | d | ^ qê } | t | Œ  8} | d | d |
 | ƒ }	 | j | | | ƒ |	 St | ƒ } | | | d | } t | d d ƒ }
 xu t d |
 ƒ D]d } | d | | d d | | d d | d | d } | t d | ƒ | | d | 7} q¢W| d | d |
 | ƒ }	 | d k rG| d | | ƒ }	 n& | d k rm| d | d | ƒ }	 n  | j | | | ƒ |	 } d d | | | j | | | ƒ Sd  S(   Niÿÿÿÿ(   t   Orderi   i    i   (   Rb   R…   R   R    R(   t   is_nonnegativeRQ   R!   t   _eval_aseriesR   t   NoneR   R	   R   R   RR   R   (   R"   R4   t   args0R9   RS   R…   RL   t   Nt   rt   ot   mR5   t   lt   fact   e0(    (    sF   lib/python2.7/site-packages/sympy/functions/special/gamma_functions.pyR‡   R  s:    !@:(c         C  s  t  t t | | f ƒ ƒ \ } } d d l m } | j rU| j rk | | ƒ } | | k rk t | | ƒ Sn  | d k r t | ƒ S| j	 rU| t
 j k r  t
 j S| t
 j k rÛ | j	 rO| t
 j k rÎ t
 j St
 j SqOqR| j rR| j rô t
 j S| t
 j k rt
 j t | d d ƒ S| j rOd | d t | ƒ t | d | ƒ SqRqUn  | d k r| t
 j k rwt
 j S| j rº| j ƒ  \ } } | d k r
t t | | d t ƒƒ Sq| t
 j t
 j f k rÙt
 j S| j t
 j ƒ } | t
 j t
 j f k rt
 j Sn  d  S(   Niÿÿÿÿ(   Ra   i   i    i   t   evaluate(   t   listt   mapR   Rb   Ra   Ri   R†   R!   RK   R%   R   R&   R'   Rg   R(   Rj   R*   t
   EulerGammaR   R‚   R   R   R+   t   as_numer_denomR   R@   Rz   t   extract_multiplicativelyt   ImaginaryUnit(   R2   R4   RL   Ra   t   nzR.   R,   RU   (    (    sF   lib/python2.7/site-packages/sympy/functions/special/gamma_functions.pyR8   {  sH    !		
					0	c      
   K  s  |  j  \ } } | j r¸| j r¸| j r | j  d } | j rµ| d } | d k r™ t g  t d t | ƒ d ƒ D] } t | | | ƒ ^ qt Œ  } n= t g  t d t | ƒ ƒ D] } t | | | ƒ ^ q³ Œ  } t | | | ƒ d | t	 | ƒ | Sq¸| j
 r¸| j ƒ  \ } } | j r¨| j r¨g  t d t | ƒ ƒ D]" } t | | t | | ƒ ƒ ^ qC} | d k rt | Œ  | t | ƒ St | Œ  | | d Sn  | | 9} q¸n  | d k r| j r| j ƒ  \ } }	 t j t t | t |	 ƒ d t |	 ƒ t g  t d |	 ƒ D]> }
 t d |
 t | |	 ƒ t d t |
 t |	 ƒ ƒ ^ qŒ  } | d k r¶t | ƒ } | | } | t g  t | ƒ D] }
 d | |
 ^ qšŒ  S| d k  rt d | ƒ } | | } | t g  t | ƒ D] }
 d | d |
 ^ qïŒ  Sn  t | | ƒ S(   Ni    i   iÿÿÿÿi   (   R    R(   R†   R=   R   R	   t   intR   R!   R   t   is_Mult   as_two_termsR)   R   R   R+   R•   R   R”   R   R   R   R   R   (   R"   RA   R4   RL   R6   t   eR7   RB   R.   R,   R5   t   part_1t   z0(    (    sF   lib/python2.7/site-packages/sympy/functions/special/gamma_functions.pyR;   ¯  sD    		<7*	;.X
/
6c         K  s>   | t  j k r6 d | d t | ƒ t | d | ƒ S|  Sd  S(   Niÿÿÿÿi   (   R   R/   R   R   (   R"   R4   RL   RM   (    (    sF   lib/python2.7/site-packages/sympy/functions/special/gamma_functions.pyt   _eval_rewrite_as_zetaÝ  s    'c         K  sp   | j  rl | t j k r- t | d ƒ t j St j | d t | ƒ t | d ƒ t | d | d ƒ Sn  d  S(   Ni   (   Ri   R   Rg   R   R”   R0   R   R   (   R"   R4   RL   RM   (    (    sF   lib/python2.7/site-packages/sympy/functions/special/gamma_functions.pyt   _eval_rewrite_as_harmonicã  s    	c         C  s‘   d d l  m } g  |  j D] } | j | ƒ ^ q \ } } | | | ƒ } | d k r} | j d | ƒ r} | j ƒ  t | ƒ S|  j | | ƒ Sd  S(   Niÿÿÿÿ(   R…   i    i   (   Rb   R…   R    t   as_leading_termt   containst   getnR   R   (   R"   R9   R…   Re   R4   RL   RŒ   (    (    sF   lib/python2.7/site-packages/sympy/functions/special/gamma_functions.pyt   _eval_as_leading_termê  s    +(   RZ   R[   R\   R$   RJ   Rƒ   RH   R‡   R^   R8   R;   RŸ   R    R¤   (    (    (    sF   lib/python2.7/site-packages/sympy/functions/special/gamma_functions.pyR!   à  s   ]				)4	.		RK   c           B  sk   e  Z d  Z e d „  ƒ Z d „  Z d d „ Z d „  Z d „  Z	 d „  Z
 d „  Z d d	 „ Z d
 „  Z RS(   sà
  
    The ``loggamma`` function implements the logarithm of the
    gamma function i.e, `\log\Gamma(x)`.

    Examples
    ========

    Several special values are known. For numerical integral
    arguments we have:

    >>> from sympy import loggamma
    >>> loggamma(-2)
    oo
    >>> loggamma(0)
    oo
    >>> loggamma(1)
    0
    >>> loggamma(2)
    0
    >>> loggamma(3)
    log(2)

    and for symbolic values:

    >>> from sympy import Symbol
    >>> n = Symbol("n", integer=True, positive=True)
    >>> loggamma(n)
    log(gamma(n))
    >>> loggamma(-n)
    oo

    for half-integral values:

    >>> from sympy import S, pi
    >>> loggamma(S(5)/2)
    log(3*sqrt(pi)/4)
    >>> loggamma(n/2)
    log(2**(1 - n)*sqrt(pi)*gamma(n)/gamma(n/2 + 1/2))

    and general rational arguments:

    >>> from sympy import expand_func
    >>> L = loggamma(S(16)/3)
    >>> expand_func(L).doit()
    -5*log(3) + loggamma(1/3) + log(4) + log(7) + log(10) + log(13)
    >>> L = loggamma(S(19)/4)
    >>> expand_func(L).doit()
    -4*log(4) + loggamma(3/4) + log(3) + log(7) + log(11) + log(15)
    >>> L = loggamma(S(23)/7)
    >>> expand_func(L).doit()
    -3*log(7) + log(2) + loggamma(2/7) + log(9) + log(16)

    The loggamma function has the following limits towards infinity:

    >>> from sympy import oo
    >>> loggamma(oo)
    oo
    >>> loggamma(-oo)
    zoo

    The loggamma function obeys the mirror symmetry
    if `x \in \mathbb{C} \setminus \{-\infty, 0\}`:

    >>> from sympy.abc import x
    >>> from sympy import conjugate
    >>> conjugate(loggamma(x))
    loggamma(conjugate(x))

    Differentiation with respect to x is supported:

    >>> from sympy import diff
    >>> diff(loggamma(x), x)
    polygamma(0, x)

    Series expansion is also supported:

    >>> from sympy import series
    >>> series(loggamma(x), x, 0, 4)
    -log(x) - EulerGamma*x + pi**2*x**2/12 + x**3*polygamma(2, 1)/6 + O(x**4)

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

    >>> from sympy import I
    >>> loggamma(5).evalf(30)
    3.17805383034794561964694160130
    >>> loggamma(I).evalf(20)
    -0.65092319930185633889 - 1.8724366472624298171*I

    See Also
    ========

    gamma: Gamma function.
    lowergamma: Lower incomplete gamma function.
    uppergamma: Upper incomplete gamma function.
    polygamma: Polygamma function.
    digamma: Digamma function.
    trigamma: Trigamma function.
    sympy.functions.special.beta_functions.beta: Euler Beta function.

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Gamma_function
    .. [2] http://dlmf.nist.gov/5
    .. [3] http://mathworld.wolfram.com/LogGammaFunction.html
    .. [4] http://functions.wolfram.com/GammaBetaErf/LogGamma/
    c         C  sþ   t  | ƒ } | j rA | j r% t j S| j r² t t | ƒ ƒ Snq | j r² | j	 ƒ  \ } } | j r² | d k r² t t
 t j ƒ d d | t | ƒ t | d t j ƒ ƒ Sn  | t j k rÈ t j St | ƒ t j k rä t j S| t j k rú t j Sd  S(   Ni   i   (   R   Ri   Rj   R   R'   R)   R   R   t   is_rationalR•   R   R1   Rk   R-   R*   R&   (   R2   RL   R.   R,   (    (    sF   lib/python2.7/site-packages/sympy/functions/special/gamma_functions.pyR8   a  s     				Ac         K  sD  d d l  m } |  j d } | j r@| j ƒ  \ } } | | } | | | } | j r@| j r@| | k  r@t d ƒ } | j rÇ t | | ƒ | t | ƒ | t | d | | ƒ | d | f ƒ S| j	 r#t | | ƒ | t | ƒ t
 j t
 j | | t | | | ƒ | d | f ƒ S| j r=t | | ƒ Sq@n  |  S(   Niÿÿÿÿ(   t   Sumi    R5   i   (   Rb   R¦   R    R+   R•   R)   R   RK   R   t   is_negativeR   R1   R—   t   is_zero(   R"   RA   R¦   RL   R.   R,   R4   R5   (    (    sF   lib/python2.7/site-packages/sympy/functions/special/gamma_functions.pyR;   w  s    	
	D	S	c         C  si   |  j  d j | d ƒ } | t j k rM |  j |  j  Œ  } | j | | | ƒ St t |  ƒ j | | | ƒ S(   Ni    (   R    RP   R   Rg   t   _eval_rewrite_as_intractableRR   RQ   RK   (   R"   R9   R4   RS   RT   t   f(    (    sF   lib/python2.7/site-packages/sympy/functions/special/gamma_functions.pyRR   Œ  s
    c         C  sW  d d l  m } | d t k r? t t |  ƒ j | | | | ƒ S|  j d } t | t | t	 d ƒ d ƒ ƒ } t
 | ƒ | t	 d ƒ d | t
 d t ƒ d } g  t d | ƒ D]: }	 t d |	 ƒ d |	 d |	 d | d |	 d ^ q³ }
 d  } | d k r| d | ƒ } n | d | d | d | ƒ } | t |
 Œ  j | | | ƒ | S(   Niÿÿÿÿ(   R…   i    i   i   (   Rb   R…   R   RQ   RK   R‡   R    t   minR   R   R   R   R	   R   Rˆ   R   RR   (   R"   R4   R‰   R9   RS   R…   RL   R   R‹   R5   RŽ   RŒ   (    (    sF   lib/python2.7/site-packages/sympy/functions/special/gamma_functions.pyR‡   “  s    #4Pc         K  s   t  t | ƒ ƒ S(   N(   R   R   (   R"   RL   RM   (    (    sF   lib/python2.7/site-packages/sympy/functions/special/gamma_functions.pyR©   £  s    c         C  s   |  j  d j S(   Ni    (   R    R„   (   R"   (    (    sF   lib/python2.7/site-packages/sympy/functions/special/gamma_functions.pyRH   ¦  s    c         C  s<   |  j  d } | t j t j f k r8 |  j | j ƒ  ƒ Sd  S(   Ni    (   R    R   Rg   Rz   R   RD   (   R"   RL   (    (    sF   lib/python2.7/site-packages/sympy/functions/special/gamma_functions.pyRE   ©  s    i   c         C  s3   | d k r  t  d |  j d ƒ St |  | ƒ ‚ d  S(   Ni   i    (   R!   R    R   (   R"   R#   (    (    sF   lib/python2.7/site-packages/sympy/functions/special/gamma_functions.pyR$   ®  s    c         C  s)   d d  l  j } | j |  j d j ƒ  ƒ S(   Niÿÿÿÿi    (   RV   RW   t	   log_gammaR    RX   (   R"   RY   (    (    sF   lib/python2.7/site-packages/sympy/functions/special/gamma_functions.pyRX   ´  s    N(   RZ   R[   R\   R^   R8   R;   Rˆ   RR   R‡   R©   RH   RE   R$   RX   (    (    (    sF   lib/python2.7/site-packages/sympy/functions/special/gamma_functions.pyRK   ô  s   l					c         C  s   t  d |  ƒ S(   s&  
    The digamma function is the first derivative of the loggamma function i.e,

    .. math::
        \psi(x) := \frac{\mathrm{d}}{\mathrm{d} z} \log\Gamma(z)
                = \frac{\Gamma'(z)}{\Gamma(z) }

    In this case, ``digamma(z) = polygamma(0, z)``.

    See Also
    ========

    gamma: Gamma function.
    lowergamma: Lower incomplete gamma function.
    uppergamma: Upper incomplete gamma function.
    polygamma: Polygamma function.
    loggamma: Log Gamma function.
    trigamma: Trigamma function.
    sympy.functions.special.beta_functions.beta: Euler Beta function.

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Digamma_function
    .. [2] http://mathworld.wolfram.com/DigammaFunction.html
    .. [3] http://functions.wolfram.com/GammaBetaErf/PolyGamma2/
    i    (   R!   (   R9   (    (    sF   lib/python2.7/site-packages/sympy/functions/special/gamma_functions.pyRc   ¹  s    c         C  s   t  d |  ƒ S(   s  
    The trigamma function is the second derivative of the loggamma function i.e,

    .. math::
        \psi^{(1)}(z) := \frac{\mathrm{d}^{2}}{\mathrm{d} z^{2}} \log\Gamma(z).

    In this case, ``trigamma(z) = polygamma(1, z)``.

    See Also
    ========

    gamma: Gamma function.
    lowergamma: Lower incomplete gamma function.
    uppergamma: Upper incomplete gamma function.
    polygamma: Polygamma function.
    loggamma: Log Gamma function.
    digamma: Digamma function.
    sympy.functions.special.beta_functions.beta: Euler Beta function.

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Trigamma_function
    .. [2] http://mathworld.wolfram.com/TrigammaFunction.html
    .. [3] http://functions.wolfram.com/GammaBetaErf/PolyGamma2/
    i   (   R!   (   R9   (    (    sF   lib/python2.7/site-packages/sympy/functions/special/gamma_functions.pyt   trigammaØ  s    N(3   t
   __future__R    R   t
   sympy.coreR   R   R   R   R   R   R   t   sympy.core.compatibilityR	   t   sympy.core.functionR
   R   t   sympy.core.numbersR   t   sympy.core.powerR   t   zeta_functionsR   t   error_functionsR   R   t&   sympy.functions.elementary.exponentialR   R   t#   sympy.functions.elementary.integersR   R   t(   sympy.functions.elementary.miscellaneousR   t(   sympy.functions.elementary.trigonometricR   R   R   t%   sympy.functions.combinatorial.numbersR   R   t(   sympy.functions.combinatorial.factorialsR   R   R   R   R_   Rd   R!   RK   Rc   R­   (    (    (    sF   lib/python2.7/site-packages/sympy/functions/special/gamma_functions.pyt   <module>   s*   4¬‹“ÿ Å	