a
    RG5dbS                     @   s  d Z ddlmZ ddlmZmZmZ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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 ddl m!Z! G dd deZ"G dd deZ#G dd deZ$G dd deZ%G dd deZ&G dd deZ'dS )z$ Riemann zeta and related function.     )Add)FunctionSsympifypiI)ArgumentIndexError
expand_mul)Dummy)	bernoulli	factorialharmonic)re
unpolarifyAbs
polar_lift)log	exp_polarexp)ceilingfloor)sqrt)Polyc                   @   s:   e Zd ZdZdd ZdddZdd Zd	d
 Zdd ZdS )lerchphia]  
    Lerch transcendent (Lerch phi function).

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

    For $\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 $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 $\mathbb{C} - [1, \infty)$.
    Finally, for $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 $\log{x}$ and
    $\log{\log{x}}$ (a branch of $\log{\log{x}}$ is needed to
    evaluate $\log{x}^{s-1}$).
    This concludes the analytic continuation. The Lerch transcendent is thus
    branched at $z \in \{0, 1, \infty\}$ and
    $a \in \mathbb{Z}_{\le 0}$. For fixed $z, a$ outside these
    branch points, it is an entire function of $s$.

    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 $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 $z$ is a root of unity, the Lerch transcendent
    reduces to a sum of Hurwitz zeta functions:

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

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

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

    More generally, if $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 $z$ and $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)

    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

    c           	         s  | j \ dkrt S jrdkrtd}t|    |dd|  }tj}t D ]}||| 7 }||	| }qf|
|S  jrtj}tj} dkrt  krƈd8  8    }t fddtD  }nH dkrBt  d  7   }t fddtD  }t j jg\tdt t  	d  ||d   t	fddtD    S ttrΈj d tt  jsd	tt fv rd	krtddg\ndtkrtdd
g\nHt kr6td	d
g\n*j d dt t  }t|j|jg\t fddtD  S t S )N   r   tc                    s&   g | ]}|    |   qS  r   .0kanszr   b/var/www/html/django/DPS/env/lib/python3.9/site-packages/sympy/functions/special/zeta_functions.py
<listcomp>       z.lerchphi._eval_expand_func.<locals>.<listcomp>c                    s,   g | ]$}d  |   | d    qS r   r   r   r    r   r%   r&      r'      c                    s>   g | ]6}t |  jf i  t|    qS r   )polylog_eval_expand_funcr   r   )hintsmrootr#   zetr   r%   r&      s      c                    sB   g | ]:}t d t t |     t|    qS )r)   )r   r   r   zetar   )r!   pqr#   r   r%   r&      s   )argsr2   
is_Integerr
   r   r   Zeroreversed
all_coeffsdiffsubsis_RationalOner   r   ranger3   r4   r   r   r   
isinstancer   r   )	selfr,   r   startrescaddmulargr   )
r!   r,   r-   r"   r3   r4   r.   r#   r$   r/   r%   r+   }   s`    

"
 4

zlerchphi._eval_expand_funcr   c                 C   s^   | j \}}}|dkr*| t||d | S |dkrVt||d ||t|||  | S td S )N   r   )r5   r   r   )r@   argindexr$   r#   r!   r   r   r%   fdiff   s    $zlerchphi.fdiffc                 C   s   |   }||r|S | S d S N)r+   has)r@   r$   r#   r!   targetrB   r   r   r%   _eval_rewrite_helper   s    
zlerchphi._eval_rewrite_helperc                 K   s   |  |||tS rJ   )rM   r2   r@   r$   r#   r!   kwargsr   r   r%   _eval_rewrite_as_zeta   s    zlerchphi._eval_rewrite_as_zetac                 K   s   |  |||tS rJ   )rM   r*   rN   r   r   r%   _eval_rewrite_as_polylog   s    z!lerchphi._eval_rewrite_as_polylogN)r   )	__name__
__module____qualname____doc__r+   rI   rM   rP   rQ   r   r   r   r%   r      s   i<
	r   c                       sP   e Zd ZdZedd ZdddZdd Zd	d
 Zdd Z	d fdd	Z
  ZS )r*   a  
    Polylogarithm function.

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

    For $|z| < 1$ and $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 $n$. It admits
    an analytic continuation which is branched at $z=1$ (notably not on the
    sheet of initial definition), $z=0$ and $z=\infty$.

    The name polylogarithm comes from the fact that for $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).

    Examples
    ========

    For $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 $s$ is a negative integer, $0$ or $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 $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)

    See Also
    ========

    zeta, lerchphi

    c                 C   s0  |t ju rt|S |t ju r&t| S |t ju r6t jS |dkr||t jkrftd d tdd d  S |dkrtd d t	t td  S |t
dd  d krtd  d tt
dd d d d  S |t
dd  d krtd  d tt
dd d d  S |dt
d d krBtd d tt
dd d d  S |t
dd d kr|td d tt
dd d d  S |jrt jS |t j}|rt|S |d	u r|t ju r|d|  S |t ju r|d| d  S |jr|d|  S |ttr,|st|t jkd
kr,| |t|S d S )Nr)      r1      r      
   rG   FT)r   r=   r2   NegativeOnedirichlet_etar7   Halfr   r   r   r   is_zeroequalsrK   r   r   r   r   )clsr#   r$   zoner   r   r%   eval  sB    





*&$$
(zpolylog.evalr   c                 C   s,   | j \}}|dkr$t|d || S td S )Nr)   r   )r5   r*   r   )r@   rH   r#   r$   r   r   r%   rI   I  s    
zpolylog.fdiffc                 K   s   |t ||d S Nr   r   )r@   r#   r$   rO   r   r   r%   _eval_rewrite_as_lerchphiO  s    z!polylog._eval_rewrite_as_lerchphic                 K   sz   | j \}}|dkr td|  S |jrp|dkrptd}|d|  }t| D ]}||| }qLt|||S t||S )Nr   r   u)	r5   r   r6   r
   r>   r:   r	   r;   r*   )r@   r,   r#   r$   re   rA   _r   r   r%   r+   R  s    
zpolylog._eval_expand_funcc                 C   s   | j d }|jrdS d S )Nr   Tr5   r]   )r@   r$   r   r   r%   _eval_is_zero^  s    
zpolylog._eval_is_zeror   c              	      s  ddl m} | j\}}||d}|tju rJ|j|dt|jrBdndd}|j	rz|
|\}	}
W n ttfy~   |  Y S 0 |
jrt||
 }||| |}||||| }|tju r|S |}|g}td|D ]}||9 }||||   qt| | S tt| ||||S )Nr   )Order-+)dirr)   )sympy.series.orderri   r5   r;   r   NaNlimitr   is_negativer]   leadterm
ValueErrorNotImplementedErroris_positiver   _eval_nseriesremoveOr7   r>   appendr   superr*   )r@   xr"   logxcdirri   nur$   z0rf   r   newnortermr#   r   	__class__r   r%   ru   c  s.    



zpolylog._eval_nseries)r   )r   )rR   rS   rT   rU   classmethodra   rI   rd   r+   rh   ru   __classcell__r   r   r   r%   r*      s   E
.
r*   c                   @   sD   e Zd ZdZedddZdddZddd	Zd
d ZdddZ	dS )r2   a  
    Hurwitz zeta function (or Riemann zeta function).

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

    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 $n + a$ is used. For fixed
    $a$ with $\operatorname{Re}(a) > 0$ the Hurwitz zeta function admits a
    meromorphic continuation to all of $\mathbb{C}$, it is an unbranched
    function with a simple pole at $s = 1$.

    Analytic continuation to other $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
    $s$ and $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 $a$, by this function assumes a default value
    of $a = 1$, yielding the Riemann zeta function.

    Examples
    ========

    For $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 $\zeta(s, a)$ with respect to $a$ can be computed:

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

    However the derivative with respect to $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:`~.lerchphi`:

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

    See Also
    ========

    dirichlet_eta, lerchphi, polylog

    References
    ==========

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

    Nc                 C   s~  |d u r t tt|df\}}nt tt||f\}}|jrf|tju rLtjS |tju rf|d urf| |S |jr|tju r|tjS |tju rtjS |jrtj	| S |tju rtj
S |jrh|jrh|jrtj| t| d  | d  }nV|jr8|jr8t|t| }}tj|d d  d|d   | t|  | }nd S |jrV|tt|| S |t|d | S |jrztj	| S d S Nr   r)   )listmapr   	is_Numberr   rn   r=   Infinityr]   r\   ComplexInfinity
is_integerr6   rp   rZ   r   is_evenrt   r   r   r   abs)r_   r$   Za_r!   r2   BFr   r   r%   ra     s<    




$0z	zeta.evalr   c                 K   s.   |dkr| S | j d }t|ddd|    S )Nr   r   r)   )r5   r[   r@   r#   r!   rO   r   r   r%   _eval_rewrite_as_dirichlet_eta  s    
z#zeta._eval_rewrite_as_dirichlet_etac                 K   s   t d||S rb   rc   r   r   r   r%   rd   %  s    zzeta._eval_rewrite_as_lerchphic                 C   s"   | j d d j}|d ur| S d S )Nr   r   rg   )r@   Z
arg_is_oner   r   r%   _eval_is_finite(  s    zzeta._eval_is_finitec                 C   sL   t | jdkr| j\}}n| jd \}}|dkrD| t|d | S td S )Nr)   r(   r   )lenr5   r2   r   )r@   rH   r#   r!   r   r   r%   rI   -  s    z
zeta.fdiff)N)r   )r   )r   )
rR   rS   rT   rU   r   ra   r   rd   r   rI   r   r   r   r%   r2     s   n'

r2   c                   @   s$   e Zd ZdZedd Zdd ZdS )r[   a  
    Dirichlet eta function.

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

    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 $\mathbb{C}$.
    It is an entire, unbranched 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)

    See Also
    ========

    zeta

    References
    ==========

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

    c                 C   s:   |dkrt dS t|}|ts6ddd|   | S d S r   )r   r2   rK   )r_   r#   r$   r   r   r%   ra   \  s
    
zdirichlet_eta.evalc                 K   s   ddd|   t | S r   )r2   )r@   r#   rO   r   r   r%   rP   d  s    z#dirichlet_eta._eval_rewrite_as_zetaNrR   rS   rT   rU   r   ra   rP   r   r   r   r%   r[   8  s   #
r[   c                   @   s$   e Zd ZdZedd Zdd ZdS )
riemann_xia  
    Riemann Xi function.

    Examples
    ========

    The Riemann Xi function is closely related to the Riemann zeta function.
    The zeros of Riemann Xi function are precisely the non-trivial zeros
    of the zeta function.

    >>> from sympy import riemann_xi, zeta
    >>> from sympy.abc import s
    >>> riemann_xi(s).rewrite(zeta)
    s*(s - 1)*gamma(s/2)*zeta(s)/(2*pi**(s/2))

    References
    ==========

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

    c                 C   sd   ddl m} t|}|tjtjfv r*tjS t|ts`||d  ||d  | dt|d    S d S Nr   )gammar   r)   )	'sympy.functions.special.gamma_functionsr   r2   r   r7   r=   r\   r?   r   )r_   r#   r   r$   r   r   r%   ra     s    
zriemann_xi.evalc                 K   s<   ddl m} ||d  ||d  t| dt|d    S r   )r   r   r2   r   )r@   r#   rO   r   r   r   r%   rP     s    z riemann_xi._eval_rewrite_as_zetaNr   r   r   r   r%   r   h  s   
	r   c                   @   s   e Zd ZdZedddZdS )	stieltjesa  
    Represents Stieltjes constants, $\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)

    The 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

    Nc                 C   s   |d ur2t |}|tju r tjS |jr2|jr2tjS |jrz|tju rHtjS |dk rVtjS |jsbtjS |tju rz|dv rztjS |j	rtjS |j
r|dv rtjS |jdkrtjS d S )Nr   rb   F)r   r   rn   r6   is_nonpositiver   r   r7   
EulerGammais_extended_negativer]   r   )r_   r"   r!   r   r   r%   ra     s*    


zstieltjes.eval)N)rR   rS   rT   rU   r   ra   r   r   r   r%   r     s   $r   N)(rU   Zsympy.core.addr   
sympy.corer   r   r   r   r   sympy.core.functionr   r	   sympy.core.symbolr
   %sympy.functions.combinatorial.numbersr   r   r   $sympy.functions.elementary.complexesr   r   r   r   &sympy.functions.elementary.exponentialr   r   r   #sympy.functions.elementary.integersr   r   (sympy.functions.elementary.miscellaneousr   sympy.polys.polytoolsr   r   r*   r2   r[   r   r   r   r   r   r%   <module>   s&    B 5 10&