ó
¡¼™\c           @  s  d  Z  d d l m Z m Z d d l m Z m Z m Z m Z 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 d d l 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 „  ƒ  YZ d S(   s$    Riemann zeta and related function. iÿÿÿÿ(   t   print_functiont   division(   t   Functiont   St   sympifyt   pit   I(   t   range(   t   ArgumentIndexError(   t	   bernoullit	   factorialt   harmonic(   t   logt	   exp_polar(   t   sqrtt   lerchphic           B  s>   e  Z d  Z d „  Z d d „ Z d „  Z d „  Z d „  Z RS(   s©  
    Lerch transcendent (Lerch phi function).

    For :math:`\operatorname{Re}(a) > 0`, `|z| < 1` and `s \in \mathbb{C}`, the
    Lerch transcendent is defined as

    .. math :: \Phi(z, s, a) = \sum_{n=0}^\infty \frac{z^n}{(n + a)^s},

    where the standard branch of the argument is used for :math:`n + a`,
    and by analytic continuation for other values of the parameters.

    A commonly used related function is the Lerch zeta function, defined by

    .. math:: L(q, s, a) = \Phi(e^{2\pi i q}, s, a).

    **Analytic Continuation and Branching Behavior**

    It can be shown that

    .. math:: \Phi(z, s, a) = z\Phi(z, s, a+1) + a^{-s}.

    This provides the analytic continuation to `\operatorname{Re}(a) \le 0`.

    Assume now `\operatorname{Re}(a) > 0`. The integral representation

    .. math:: \Phi_0(z, s, a) = \int_0^\infty \frac{t^{s-1} e^{-at}}{1 - ze^{-t}}
                                \frac{\mathrm{d}t}{\Gamma(s)}

    provides an analytic continuation to :math:`\mathbb{C} - [1, \infty)`.
    Finally, for :math:`x \in (1, \infty)` we find

    .. math:: \lim_{\epsilon \to 0^+} \Phi_0(x + i\epsilon, s, a)
             -\lim_{\epsilon \to 0^+} \Phi_0(x - i\epsilon, s, a)
             = \frac{2\pi i \log^{s-1}{x}}{x^a \Gamma(s)},

    using the standard branch for both :math:`\log{x}` and
    :math:`\log{\log{x}}` (a branch of :math:`\log{\log{x}}` is needed to
    evaluate :math:`\log{x}^{s-1}`).
    This concludes the analytic continuation. The Lerch transcendent is thus
    branched at :math:`z \in \{0, 1, \infty\}` and
    :math:`a \in \mathbb{Z}_{\le 0}`. For fixed :math:`z, a` outside these
    branch points, it is an entire function of :math:`s`.

    See Also
    ========

    polylog, zeta

    References
    ==========

    .. [1] Bateman, H.; Erdelyi, A. (1953), Higher Transcendental Functions,
           Vol. I, New York: McGraw-Hill. Section 1.11.
    .. [2] http://dlmf.nist.gov/25.14
    .. [3] https://en.wikipedia.org/wiki/Lerch_transcendent

    Examples
    ========

    The Lerch transcendent is a fairly general function, for this reason it does
    not automatically evaluate to simpler functions. Use expand_func() to
    achieve this.

    If :math:`z=1`, the Lerch transcendent reduces to the Hurwitz zeta function:

    >>> from sympy import lerchphi, expand_func
    >>> from sympy.abc import z, s, a
    >>> expand_func(lerchphi(1, s, a))
    zeta(s, a)

    More generally, if :math:`z` is a root of unity, the Lerch transcendent
    reduces to a sum of Hurwitz zeta functions:

    >>> expand_func(lerchphi(-1, s, a))
    2**(-s)*zeta(s, a/2) - 2**(-s)*zeta(s, a/2 + 1/2)

    If :math:`a=1`, the Lerch transcendent reduces to the polylogarithm:

    >>> expand_func(lerchphi(z, s, 1))
    polylog(s, z)/z

    More generally, if :math:`a` is rational, the Lerch transcendent reduces
    to a sum of polylogarithms:

    >>> from sympy import S
    >>> expand_func(lerchphi(z, s, S(1)/2))
    2**(s - 1)*(polylog(s, sqrt(z))/sqrt(z) -
                polylog(s, sqrt(z)*exp_polar(I*pi))/sqrt(z))
    >>> expand_func(lerchphi(z, s, S(3)/2))
    -2**s/z + 2**(s - 1)*(polylog(s, sqrt(z))/sqrt(z) -
                          polylog(s, sqrt(z)*exp_polar(I*pi))/sqrt(z))/z

    The derivatives with respect to :math:`z` and :math:`a` can be computed in
    closed form:

    >>> lerchphi(z, s, a).diff(z)
    (-a*lerchphi(z, s, a) + lerchphi(z, s - 1, a))/z
    >>> lerchphi(z, s, a).diff(a)
    -s*lerchphi(z, s + 1, a)
    c      	   K  s  d d l  m } m } m } m } m } m } m } m }	 |  j	 \ }
 } } |
 d k re t
 | | ƒ S| j r| d k r| d ƒ } | | | | | ƒ } d d | } t d ƒ } x; t | j ƒ  ƒ D]' } | | | 7} | | j | ƒ } qË W| j | |
 ƒ S| j rÊt d ƒ } t d ƒ } | d k rª| | ƒ } | | k rX| d 8} n  | | 8} |
 | } | g  t | ƒ D]! } |
 | | | | | ^ q}Œ  } nu | d k r| | ƒ d } | | 7} |
 | } | g  t | ƒ D]( } |
 | d | | | d | ^ qëŒ  } n  t | j | j g ƒ \ } } | d t | | ƒ } |
 d | } | | | | d | g  t | ƒ D]< } t | | | | ƒ j |   |	 | ƒ | | | ^ q…Œ  St |
 | ƒ rñ|
 j	 d t | j s|
 d | | g k r|
 d k r.t d d g ƒ \ } } n† |
 | k rUt d d g ƒ \ } } n_ |
 | k r}t d d g ƒ \ } } n7 |
 j	 d d t | } t | j | j g ƒ \ } } | g  t | ƒ D]C } | d t | | | | ƒ | | t
 | | | | ƒ ^ qÄŒ  St |
 | | ƒ S(   Niÿÿÿÿ(   t   expR   t   floort   Addt   Polyt   DummyR   t
   unpolarifyi   i    t   ti   i   (   t   sympyR   R   R   R   R   R   R   R   t   argst   zetat
   is_IntegerR   t   reversedt
   all_coeffst   difft   subst   is_RationalR   t   pt   qR   t   polylogt   _eval_expand_funct
   isinstanceR   (   t   selft   hintsR   R   R   R   R   R   R   R   t   zt   st   aR   R    t   startt   rest   ct   addt   mult   nt   kt   mt   zett   rootR!   t   arg(    (    sE   lib/python2.7/site-packages/sympy/functions/special/zeta_functions.pyR#   v   s\    :	
=

DO=Ti   c         C  sy   |  j  \ } } } | d k r7 | t | | d | ƒ S| d k ro t | | d | ƒ | t | | | ƒ | St ‚ d  S(   Ni   i   (   R   R   R   (   R%   t   argindexR'   R(   R)   (    (    sE   lib/python2.7/site-packages/sympy/functions/special/zeta_functions.pyt   fdiff³   s    ,c         C  s'   |  j  ƒ  } | j | ƒ r | S|  Sd  S(   N(   R#   t   has(   R%   R'   R(   R)   t   targetR+   (    (    sE   lib/python2.7/site-packages/sympy/functions/special/zeta_functions.pyt   _eval_rewrite_helper¼   s    c         K  s   |  j  | | | t ƒ S(   N(   R9   R   (   R%   R'   R(   R)   t   kwargs(    (    sE   lib/python2.7/site-packages/sympy/functions/special/zeta_functions.pyt   _eval_rewrite_as_zetaÃ   s    c         K  s   |  j  | | | t ƒ S(   N(   R9   R"   (   R%   R'   R(   R)   R:   (    (    sE   lib/python2.7/site-packages/sympy/functions/special/zeta_functions.pyt   _eval_rewrite_as_polylogÆ   s    (   t   __name__t
   __module__t   __doc__R#   R6   R9   R;   R<   (    (    (    sE   lib/python2.7/site-packages/sympy/functions/special/zeta_functions.pyR      s   d	=			R"   c           B  s;   e  Z d  Z e d „  ƒ Z d d „ Z d „  Z d „  Z RS(   s/  
    Polylogarithm function.

    For :math:`|z| < 1` and :math:`s \in \mathbb{C}`, the polylogarithm is
    defined by

    .. math:: \operatorname{Li}_s(z) = \sum_{n=1}^\infty \frac{z^n}{n^s},

    where the standard branch of the argument is used for :math:`n`. It admits
    an analytic continuation which is branched at :math:`z=1` (notably not on the
    sheet of initial definition), :math:`z=0` and :math:`z=\infty`.

    The name polylogarithm comes from the fact that for :math:`s=1`, the
    polylogarithm is related to the ordinary logarithm (see examples), and that

    .. math:: \operatorname{Li}_{s+1}(z) =
                    \int_0^z \frac{\operatorname{Li}_s(t)}{t} \mathrm{d}t.

    The polylogarithm is a special case of the Lerch transcendent:

    .. math:: \operatorname{Li}_{s}(z) = z \Phi(z, s, 1)

    See Also
    ========

    zeta, lerchphi

    Examples
    ========

    For :math:`z \in \{0, 1, -1\}`, the polylogarithm is automatically expressed
    using other functions:

    >>> from sympy import polylog
    >>> from sympy.abc import s
    >>> polylog(s, 0)
    0
    >>> polylog(s, 1)
    zeta(s)
    >>> polylog(s, -1)
    -dirichlet_eta(s)

    If :math:`s` is a negative integer, :math:`0` or :math:`1`, the
    polylogarithm can be expressed using elementary functions. This can be
    done using expand_func():

    >>> from sympy import expand_func
    >>> from sympy.abc import z
    >>> expand_func(polylog(1, z))
    -log(1 - z)
    >>> expand_func(polylog(0, z))
    z/(1 - z)

    The derivative with respect to :math:`z` can be computed in closed form:

    >>> polylog(s, z).diff(z)
    polylog(s - 1, z)/z

    The polylogarithm can be expressed in terms of the lerch transcendent:

    >>> from sympy import lerchphi
    >>> polylog(s, z).rewrite(lerchphi)
    z*lerchphi(z, s, 1)
    c         C  sb  t  | | f ƒ \ } } | d k r. t | ƒ S| d k rE t | ƒ S| d k rX t j S| d k rÎ| t j k r‘ t d d t d ƒ d d S| d k r» t d d t t t d ƒ S| t	 d ƒ d d k rt d d t t	 d ƒ d d ƒ d d S| t	 d ƒ d d k rGt d d	 t t	 d ƒ d d ƒ d S| d
 t	 d ƒ d k r‰t d d t t	 d ƒ d d ƒ d S| t	 d ƒ d d k rt d d	 t t	 d ƒ d d ƒ d Sn4 | d k ræ| d | S| d k r| d | d Sd d l
 m } m } m } | j t | ƒ r^| | ƒ t j k t k r^|  | | | ƒ ƒ Sd  S(   Ni   iÿÿÿÿi    i   i   i   i   i   i
   i   (   t   AbsR   t
   polar_lift(   R   R   t   dirichlet_etaR   t   Zerot   HalfR   R   R   R   t$   sympy.functions.elementary.complexesR@   R   RA   R7   R   t   Onet   True(   t   clsR(   R'   R@   R   RA   (    (    sE   lib/python2.7/site-packages/sympy/functions/special/zeta_functions.pyt   eval  s6    
-)(+-i   c         C  s:   |  j  \ } } | d k r0 t | d | ƒ | St ‚ d  S(   Ni   i   (   R   R"   R   (   R%   R5   R(   R'   (    (    sE   lib/python2.7/site-packages/sympy/functions/special/zeta_functions.pyR6   3  s    c         K  s   | t  | | d ƒ S(   Ni   (   R   (   R%   R(   R'   R:   (    (    sE   lib/python2.7/site-packages/sympy/functions/special/zeta_functions.pyt   _eval_rewrite_as_lerchphi9  s    c   
      K  sÃ   d d l  m } m } m } |  j \ } } | d k rF | d | ƒ S| j r¶ | d k r¶ | d ƒ } | d | } x( t | ƒ D] }	 | | j | ƒ } qƒ W| | ƒ j | | ƒ St	 | | ƒ S(   Niÿÿÿÿ(   R   t
   expand_mulR   i   i    t   u(
   R   R   RK   R   R   R   R   R   R   R"   (
   R%   R&   R   RK   R   R(   R'   RL   R*   t   _(    (    sE   lib/python2.7/site-packages/sympy/functions/special/zeta_functions.pyR#   <  s    (   R=   R>   R?   t   classmethodRI   R6   RJ   R#   (    (    (    sE   lib/python2.7/site-packages/sympy/functions/special/zeta_functions.pyR"   Î   s
   @#	R   c           B  sM   e  Z d  Z e d d „ ƒ Z d d „ Z d d „ Z d „  Z d d „ Z	 RS(   sÊ  
    Hurwitz zeta function (or Riemann zeta function).

    For `\operatorname{Re}(a) > 0` and `\operatorname{Re}(s) > 1`, this function is defined as

    .. math:: \zeta(s, a) = \sum_{n=0}^\infty \frac{1}{(n + a)^s},

    where the standard choice of argument for :math:`n + a` is used. For fixed
    :math:`a` with `\operatorname{Re}(a) > 0` the Hurwitz zeta function admits a
    meromorphic continuation to all of :math:`\mathbb{C}`, it is an unbranched
    function with a simple pole at :math:`s = 1`.

    Analytic continuation to other :math:`a` is possible under some circumstances,
    but this is not typically done.

    The Hurwitz zeta function is a special case of the Lerch transcendent:

    .. math:: \zeta(s, a) = \Phi(1, s, a).

    This formula defines an analytic continuation for all possible values of
    :math:`s` and :math:`a` (also `\operatorname{Re}(a) < 0`), see the documentation of
    :class:`lerchphi` for a description of the branching behavior.

    If no value is passed for :math:`a`, by this function assumes a default value
    of :math:`a = 1`, yielding the Riemann zeta function.

    See Also
    ========

    dirichlet_eta, lerchphi, polylog

    References
    ==========

    .. [1] http://dlmf.nist.gov/25.11
    .. [2] https://en.wikipedia.org/wiki/Hurwitz_zeta_function

    Examples
    ========

    For :math:`a = 1` the Hurwitz zeta function reduces to the famous Riemann
    zeta function:

    .. math:: \zeta(s, 1) = \zeta(s) = \sum_{n=1}^\infty \frac{1}{n^s}.

    >>> from sympy import zeta
    >>> from sympy.abc import s
    >>> zeta(s, 1)
    zeta(s)
    >>> zeta(s)
    zeta(s)

    The Riemann zeta function can also be expressed using the Dirichlet eta
    function:

    >>> from sympy import dirichlet_eta
    >>> zeta(s).rewrite(dirichlet_eta)
    dirichlet_eta(s)/(1 - 2**(1 - s))

    The Riemann zeta function at positive even integer and negative odd integer
    values is related to the Bernoulli numbers:

    >>> zeta(2)
    pi**2/6
    >>> zeta(4)
    pi**4/90
    >>> zeta(-1)
    -1/12

    The specific formulae are:

    .. math:: \zeta(2n) = (-1)^{n+1} \frac{B_{2n} (2\pi)^{2n}}{2(2n)!}
    .. math:: \zeta(-n) = -\frac{B_{n+1}}{n+1}

    At negative even integers the Riemann zeta function is zero:

    >>> zeta(-4)
    0

    No closed-form expressions are known at positive odd integers, but
    numerical evaluation is possible:

    >>> zeta(3).n()
    1.20205690315959

    The derivative of :math:`\zeta(s, a)` with respect to :math:`a` is easily
    computed:

    >>> from sympy.abc import a
    >>> zeta(s, a).diff(a)
    -s*zeta(s + 1, a)

    However the derivative with respect to :math:`s` has no useful closed form
    expression:

    >>> zeta(s, a).diff(s)
    Derivative(zeta(s, a), s)

    The Hurwitz zeta function can be expressed in terms of the Lerch transcendent,
    :class:`sympy.functions.special.lerchphi`:

    >>> from sympy import lerchphi
    >>> zeta(s, a).rewrite(lerchphi)
    lerchphi(1, s, a)

    c         C  sß  | d  k r0 t t t | d f ƒ ƒ \ } } n! t t t | | f ƒ ƒ \ } } | j r˜ | t j k rp t j S| t j k r˜ | d  k	 r˜ |  | ƒ Sn  | j r | t j k r· t j S| t j k rÍ t j S| t j	 k rç t j
 | S| t j k r t j Sn  | j rÛ| j rÛ| j r@d | t | d ƒ | d } n` | j rœ| j rœt | ƒ t | ƒ } } d | d d d | d | t | | } n d  S| j rÀ| t t | ƒ | ƒ S| t | d | ƒ SqÛn  d  S(   Ni   iÿÿÿÿi   (   t   Nonet   listt   mapR   t	   is_NumberR   t   NaNRF   t   InfinityRC   RD   t   ComplexInfinityt
   is_integerR   t   is_negativeR	   t   is_event   is_positiveR
   R   R   t   abs(   RH   R'   t   a_R)   R   t   Bt   F(    (    sE   lib/python2.7/site-packages/sympy/functions/special/zeta_functions.pyRI   º  s8    $!		
			%1	i   c         K  s7   | d k r |  S|  j  d } t | ƒ d d d | S(   Ni   i    i   (   R   RB   (   R%   R(   R)   R:   (    (    sE   lib/python2.7/site-packages/sympy/functions/special/zeta_functions.pyt   _eval_rewrite_as_dirichlet_etaá  s    c         K  s   t  d | | ƒ S(   Ni   (   R   (   R%   R(   R)   R:   (    (    sE   lib/python2.7/site-packages/sympy/functions/special/zeta_functions.pyRJ   ç  s    c         C  s)   |  j  d d j } | d  k	 r% | Sd  S(   Ni    i   (   R   t   is_zeroRO   (   R%   t
   arg_is_one(    (    sE   lib/python2.7/site-packages/sympy/functions/special/zeta_functions.pyt   _eval_is_finiteê  s    c         C  sf   t  |  j ƒ d k r' |  j \ } } n |  j d \ } } | d k r\ | t | d | ƒ St ‚ d  S(   Ni   i   (   i   (   t   lenR   R   R   (   R%   R5   R(   R)   (    (    sE   lib/python2.7/site-packages/sympy/functions/special/zeta_functions.pyR6   ï  s    N(
   R=   R>   R?   RN   RO   RI   R^   RJ   Ra   R6   (    (    (    sE   lib/python2.7/site-packages/sympy/functions/special/zeta_functions.pyR   N  s   j&	RB   c           B  s&   e  Z d  Z e d „  ƒ Z d „  Z RS(   s   
    Dirichlet eta function.

    For `\operatorname{Re}(s) > 0`, this function is defined as

    .. math:: \eta(s) = \sum_{n=1}^\infty \frac{(-1)^{n-1}}{n^s}.

    It admits a unique analytic continuation to all of :math:`\mathbb{C}`.
    It is an entire, unbranched function.

    See Also
    ========

    zeta

    References
    ==========

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

    Examples
    ========

    The Dirichlet eta function is closely related to the Riemann zeta function:

    >>> from sympy import dirichlet_eta, zeta
    >>> from sympy.abc import s
    >>> dirichlet_eta(s).rewrite(zeta)
    (1 - 2**(1 - s))*zeta(s)

    c         C  sI   | d k r t  d ƒ St | ƒ } | j t ƒ sE d d d | | Sd  S(   Ni   i   (   R   R   R7   (   RH   R(   R'   (    (    sE   lib/python2.7/site-packages/sympy/functions/special/zeta_functions.pyRI     s
    
c         K  s   d d d | t  | ƒ S(   Ni   i   (   R   (   R%   R(   R:   (    (    sE   lib/python2.7/site-packages/sympy/functions/special/zeta_functions.pyR;   #  s    (   R=   R>   R?   RN   RI   R;   (    (    (    sE   lib/python2.7/site-packages/sympy/functions/special/zeta_functions.pyRB   ú  s   t	   stieltjesc           B  s    e  Z d  Z e d d „ ƒ Z RS(   sy  Represents Stieltjes constants, :math:`\gamma_{k}` that occur in
    Laurent Series expansion of the Riemann zeta function.

    Examples
    ========

    >>> from sympy import stieltjes
    >>> from sympy.abc import n, m
    >>> stieltjes(n)
    stieltjes(n)

    zero'th stieltjes constant

    >>> stieltjes(0)
    EulerGamma
    >>> stieltjes(0, 1)
    EulerGamma

    For generalized stieltjes constants

    >>> stieltjes(n, m)
    stieltjes(n, m)

    Constants are only defined for integers >= 0

    >>> stieltjes(-1)
    zoo

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Stieltjes_constants
    c         C  s¾   t  | ƒ } | d  k	 rV t  | ƒ } | t j k r: t j S| j rV | j rV t j Sn  | j rº | t j k ru t j S| d k  rˆ t j S| j s˜ t j S| d k rº | d k rº t j Sn  d  S(   Ni    i   (   Ni   (	   R   RO   R   RS   R   t   is_nonpositiveRU   RR   t
   EulerGamma(   RH   R/   R)   (    (    sE   lib/python2.7/site-packages/sympy/functions/special/zeta_functions.pyRI   J  s     
		N(   R=   R>   R?   RN   RO   RI   (    (    (    sE   lib/python2.7/site-packages/sympy/functions/special/zeta_functions.pyRc   '  s   !N(   R?   t
   __future__R    R   t
   sympy.coreR   R   R   R   R   t   sympy.core.compatibilityR   t   sympy.core.functionR   t%   sympy.functions.combinatorial.numbersR	   R
   R   t&   sympy.functions.elementary.exponentialR   R   t(   sympy.functions.elementary.miscellaneousR   R   R"   R   RB   Rc   (    (    (    sE   lib/python2.7/site-packages/sympy/functions/special/zeta_functions.pyt   <module>   s   (¾€¬-