K i^dZddlmZddlmZddlmZmZmZddl m Z ddl m Z m Z mZddlmZddlmZdd lmZdd lmZdd lmZmZmZmZdd lmZmZmZm Z dd l!m"Z"m#Z#m$Z$ddl%m&Z&m'Z'ddl(m)Z)ddl*m+Z+ddl,m-Z-GddeZ.GddeZ/GddeZ0GddeZ1GddeZ2GddeZ3edZ4y) z$ Riemann zeta and related function. )Add)cacheit)ArgumentIndexError expand_mulDefinedFunction) fuzzy_not)piIInteger)Eq)S)Dummy)sympify) bernoulli factorialgenocchiharmonic)re unpolarifyAbs polar_lift)log exp_polarexp)ceilingfloor)sqrt) Piecewise)Polyc0eZdZdZdZddZdZdZdZy) 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] https://dlmf.nist.gov/25.14 .. [3] https://en.wikipedia.org/wiki/Lerch_transcendent c @|j\}}}|dk(r t||S|jr|dkrtd}t ||z| z|}dd|z z }t j }t|jD]} || |zz }||j|z} |j||S|jrt j } t j} |dkDrPt|} | |k(r| dz} || z}|| z} tt| D cgc]} || | z z || z|zz c} } nR|dkrMt| dz} || z }|| z} tt| D cgc]} || dz | z z|| z dz |zz c} } t |j |j"g\}} t%dt&zt(z| z }|d| z z}t+|}g}t| D]S} t-||| z|z}t/|t,r|j0di|}|j3||| z|z|zz U| | | |dz zzt|zzSt/|t4r'|jdt&t(zz js|dt(t( fvr|dk(rt ddg\}}ny|t(k(rt ddg\}}n_|t( k(rt ddg\}}nD|jddt&zt(zz }t |j |j"g\}}tt|D cgc]=} t5dt&zt(z| z|z|z ||zz t|| |z|z z?c} St7|||Scc} wcc} wcc} w)Nrt)argszeta is_Integerrrr Zeroreversed all_coeffsdiffsubs is_RationalOnerrrangepqrr r rpolylog isinstance_eval_expand_funcappendrr!)selfhintszsar$r4startrescaddmulnkmzetrootup_zetaddargsr5args l/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/functions/special/zeta_functions.pyr8zlerchphi._eval_expand_funcs))1a 61:  < ! == &&C%%C1u!H6FAQ1"gE!HEqQQZKQ 2EFa1"IMQd58LaAA NAEAI>9LMacc133Z=DAqAbDF1H%Cqs8D_FG1X 6AsAvd{+a)+++4e4Aq&!)D.1!445  6 QQZW 55 5 a 166!9bd#3"@"@A"aRSQSDTBw!Qy1a!Qy1qb"az1ffQi2a(#%%(1"'(,QrT!VAXaZ\*1a4/QQ 0BB,- -1a  EF M4,sN'N>ANc|j\}}}|dk(r| t||dz|zS|dk(r$t||dz ||t|||zz |z St)Nr#)r)r!r)r:argindexr<r=r>s rLfdiffzlerchphi.fdiffsj))1a q=2hq!a%++ + ]QAq)Ahq!Q.?,??B B$ $cL|j}|j|r|S|SN)r8has)r:targetr@s rL_eval_rewrite_helperzlerchphi._eval_rewrite_helpers%$$& 776?JKrQc ,|jtSrS)rVr*r:r<r=r>kwargss rL_eval_rewrite_as_zetazlerchphi._eval_rewrite_as_zetas((..rQc ,|jtSrS)rVr6rXs rL_eval_rewrite_as_polylogz!lerchphi._eval_rewrite_as_polylogs((11rQNr#) __name__ __module__ __qualname____doc__r8rPrVrZr\r(rQrLr!r!s#gR?!B%/2rQr!cNeZdZdZedZddZdZdZdZ d fd Z xZ S) r6a 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|jru|tjur t|S|tjur t | S|tj urtj S|dk(rt}||vr||S|jrtj S|jtj}|r t|S|durK|tj ur|d|z z S|tjur |d|z dzz S|jr|d|z z S|jttr4|st|tjkdk(r||t|Syy)Nr%Fr#T) is_numberr r2r* NegativeOne dirichlet_etar, _dilogtableis_zeroequalsrTrrrr)clsr=r< dilogtablezones rLevalz polylog.eval%s- ;;AEEzAwamm#%a(((affvv a(]  ?%a=( 9966Mxx 7N U] AFF{!a%y amm#!a%!|#yy!a%y  55J 'Tc!fo$5Nq*Q-( (6O 'rQcZ|j\}}|dk(rt|dz ||z St)Nr%r#)r)r6r)r:rOr=r<s rLrPz polylog.fdiffLs2yy1 q=1q5!$Q& &  rQc "|t||dzSNr#r!)r:r=r<rYs rL_eval_rewrite_as_lerchphiz!polylog._eval_rewrite_as_lerchphiRs!Q"""rQc (|j\}}|dk(rtd|z  S|jrX|dkrStd}|d|z z }t | D]}||j |z}t |j||St||S)Nr#ru) r)rr+rr3r/rr0r6)r:r;r=r<rtr?_s rLr8zpolylog._eval_expand_funcUsyy1 6AJ;  <*>3CHB :: A3qu~!Q$NOOAq$5==?;HFq$)AAIDHHT!R%Z()Aw{"Wd1!QdCC# 34   s3D66E  E r])r) r^r_r`ra classmethodrmrPrrr8rwr __classcell__rs@rLr6r6s?CJ$)$)L! #  DDrQr6c`eZdZdZed dZd dZd dZd dZdZ dZ d dZ fd Z xZ S) r*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$ not a nonpositive integer 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$. 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$ a default value of $a = 1$ is assumed, 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 nonnegative even and negative integer values is related to the Bernoulli numbers and polynomials: >>> zeta(2) pi**2/6 >>> zeta(4) pi**4/90 >>> zeta(0) -1/2 >>> zeta(-1) -1/12 >>> zeta(-4) 0 The specific formulae are: .. math:: \zeta(2n) = -\frac{(2\pi i)^{2n} B_{2n}}{2(2n)!} .. math:: \zeta(-n,a) = -\frac{B_{n+1}(a)}{n+1} 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] https://dlmf.nist.gov/25.11 .. [2] https://en.wikipedia.org/wiki/Hurwitz_zeta_function c|tjur||S|tjus|tjurtjS|tjurtjS|tjurtjS|tjurtj S|j }|tj}|r!|jrtd|z ||dz z S|tjur?|r<|jr/dtztz|z t|zdt|zz Syy|r0|j r$|jr||t|dz |z S|j r:|jr-|jdus|jdurtjSyyy)Nr#r%F)r r2r~ComplexInfinityInfinityr,r+is_nonpositiveris_evenr r rrr is_integer)rjr=r>sints rLrmz zeta.evals[ :q6M !%%Z1:55L !%%Z$$ $ !**_55L !**_66M|| 9A A$$QqS!$!, , !%%Z 2a! |il2a ! nEE"t allq}}q6HQqS!,, , \\a..&!*:*:e*C55L+D/\rQc |dk(rS|jrG|jr;|jr/dtztz|z t |zdt |zz St d|z ||dz z S)Nr#r%)ris_nonnegativerr r rrr:r=r>rYs rL_eval_rewrite_as_bernoullizzeta._eval_rewrite_as_bernoullisa 6allq'7'7AIIrT!VaK<)A,.!IaL.A A1a AaC((rQc \|dk7r|S|jd}t|ddd|z zz z S)Nr#rr%)r)rfrs rL_eval_rewrite_as_dirichlet_etaz#zeta._eval_rewrite_as_dirichlet_etas7 6K IIaLQQQZ00rQc td||Srprqrs rLrrzzeta._eval_rewrite_as_lerchphis1a  rQcLt|jddz jS)Nrr#)rr)rh)r:s rL_eval_is_finitezzeta._eval_is_finites $))A,*3344rQc h|jd}t|jdkDr|jdntj}|jr_|j rt |t|dz |z S|jr,|jdus|jdurtjS|S)Nrr#F) r)lenr r2rrr*rrr~)r:r;r=r>s rLr8zzeta._eval_expand_func"s IIaL NQ.DIIaLAEE <<}}Aw!A#q!111Q\\U%:$$-uu  rQct|jdk(r|j\}}n|jdz\}}|dk(r| t|dz|zSt)Nr%r]r#)rr)r*r)r:rOr=r>s rLrPz zeta.fdiff-sU tyy>Q 99DAq99t#DAq q=2d1q5!n$ $$ $rQcJt|jdk(r|j\}}n!|jtjfz\}} |j |\}}|j r|jst tt|+|||S#t $r|cYSwxYw)Nr%)rr) rr)r r2rrrrrr*_eval_as_leading_term) r:rrrr=r>rAers rLrzzeta._eval_as_leading_term7s tyy>Q 99DAq99x'DAq ::a=DAq ==% %T46qt$6OO # K s B B"!B"rSr])r^r_r`rarrmrrrrrr8rPrrrs@rLr*r*sHhT4) 1 !5 %PPrQr*cNeZdZdZeddZddZejfdZ dZ y) rfa Dirichlet eta function. Explanation =========== For $\operatorname{Re}(s) > 0$ and $0 < x \le 1$, this function is defined as .. math:: \eta(s, a) = \sum_{n=0}^\infty \frac{(-1)^n}{(n+a)^s}. It admits a unique analytic continuation to all of $\mathbb{C}$ for any fixed $a$ not a nonpositive integer. It is an entire, unbranched function. It can be expressed using the Hurwitz zeta function as .. math:: \eta(s, a) = \zeta(s,a) - 2^{1-s} \zeta\left(s, \frac{a+1}{2}\right) and using the generalized Genocchi function as .. math:: \eta(s, a) = \frac{G(1-s, a)}{2(s-1)}. In both cases the limiting value of $\log2 - \psi(a) + \psi\left(\frac{a+1}{2}\right)$ is used when $s = 1$. Examples ======== >>> from sympy import dirichlet_eta, zeta >>> from sympy.abc import s >>> dirichlet_eta(s).rewrite(zeta) Piecewise((log(2), Eq(s, 1)), ((1 - 2**(1 - s))*zeta(s), True)) See Also ======== zeta References ========== .. [1] https://en.wikipedia.org/wiki/Dirichlet_eta_function .. [2] Peter Luschny, "An introduction to the Bernoulli function", https://arxiv.org/abs/2009.06743 Nc|tjur||S|?|dk(r tdSt|}|j tsddd|z zz |zSy|dk(r)ddlm}td||z ||dzdz zSt||}t||dzdz }|j ts$|j ts|dd|z z|zz Syy)Nr#r%rdigamma)r r2rr*rT'sympy.functions.special.gamma_functionsr)rjr=r>r<rz1z2s rLrmzdirichlet_eta.evalws :q6M 9Av1v QA55;A!H ))  !V Gq6GAJ&!A#q)99 9 !QZ !ac1W vvd|BFF4LAaC2 % %%1|rQc Jddlm}|dk(r8ttdt |dfddd|z zz t |zdfSttd||z ||dzdz zt |dft ||dd|z zt ||dzdz zz dfS)Nrrr#r%T)rrrrr r*r:r=r>rYrs rLrZz#dirichlet_eta._eval_rewrite_as_zetasC 6c!fbAh/1q1Q3x<472JD1QR R#a&71:-1a0@@"Q(Kaa!A#ha!A#q)9994@B BrQc ddlm}ttd||z ||dzdz zt |dft d|z |d|dz zz dfS)Nrrr%r#T)rrrrr rrs rL_eval_rewrite_as_genocchiz'dirichlet_eta._eval_rewrite_as_genocchis^C#a&71:-1a0@@"Q(K!A#q!Q!A#Y/68 8rQctd|jDr$|jtj |Sy)Nc34K|]}|jywrS)rd).0is rL z,dirichlet_eta._eval_evalf..s.qq{{.s)allr)rewriter* _eval_evalf)r:precs rLrzdirichlet_eta._eval_evalfs3 .DII. .<<%11$7 7 /rQrSr]) r^r_r`rarrmrZr r2rrr(rQrLrfrfHs5,\&&$B./UU8 8rQrfc&eZdZdZedZdZy) 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 cddlm}t|}|tjtj fvrtj St|ts'||dz z||dz z|zdt|dz zzz SyNr)gammar#r%) rrr*r r,r2Halfr7r )rjr=rr<s rLrmzriemann_xi.evalskA G  66M!T"a!e9U1Q3Z')1R!A#Y;7 7#rQc nddlm}||dz z||dz zt|zdt|dz zzz Sr)rrr*r )r:r=rYrs rLrZz riemann_xi._eval_rewrite_as_zetas:A!a%yqs#DG+QrAaCy[99rQN)r^r_r`rarrmrZr(rQrLrrs .88:rQrc"eZdZdZeddZy) 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 Ncr|Ut|}|tjurtjS|jr|jrtj S|j ry|tjurtjS|dkrtj S|jstj S|tjur|dvrtjS|jrtj S|jr|dvrtjS|jdk(rtj Sy)NrrpF) rr r~r+rr is_Numberr, EulerGammais_extended_negativerhr)rjrDr>s rLrmzstieltjes.evals = AAEEzuu || 0 0((( ;;AEEzuu Q(((\\(((affi||# ! !$$ $ 99i<<  <<5 $$ $ !rQrS)r^r_r`rarrmr(rQrLrrs"H%%rQrctjtdzdz tddzdz z t dtdzdz t tztdzz t ddz dz tdz dz tt ddz dz dzdz zt ddz dz tdz dz tt ddzdz dzz dt dz dz tdzdz tt ddz dz dzz t ddz dz tdzdz tt ddz dz dzz t t tjztdzd z z t t tjztdzd z z dt z tdzd z t tjzz tt zdz tdzz dt ztdzd z t tjzztt zdz tdzzdt z dz tddz d z tt ztdzd z zdtdzzd z zt tjzz i S) Nr% r'r# rN0`)r rr rr r rCatalanr(rQrLrgrgs Ab3q619Q;& RU1WqtCF{* q'A+qBE6"9sDGAIq='91'> q'A+qBE6"9sDGAIq='91'<< T!Wa"a%(S$q'!)Q%7%:: a1a"a%(S$q'!)Q%7%:: AaiiK"a%( " aR \BE"H $ AAb1QYY;&AaA6 AAb1QYY;&AaA6 Q SVQYJqL2a4A;q=01RU72:=!)) K  rQN)5rasympy.core.addrsympy.core.cachersympy.core.functionrrrsympy.core.logicrsympy.core.numbersr r r sympy.core.relationalr sympy.core.singletonr sympy.core.symbolrsympy.core.sympifyr%sympy.functions.combinatorial.numbersrrrr$sympy.functions.elementary.complexesrrrr&sympy.functions.elementary.exponentialrrr#sympy.functions.elementary.integersrr(sympy.functions.elementary.miscellaneousr$sympy.functions.elementary.piecewisersympy.polys.polytoolsrr!r6r*rfrrrgr(rQrLrs*$OO&--$"#&ZZPPFF>9:&22LeDoeDXzP?zPzP8OP8f$:$:N?%?%D    rQ