K iddlmZddlmZmZmZmZddlmZddl m Z m Z m Z ddl mZmZddlmZmZmZmZddlmZddlmZdd lmZmZmZdd lmZmZdd l m!Z!m"Z"dd l#m$Z$m%Z%dd l&m'Z'ddl(m)Z)m*Z*m+Z+ddl,m-Z-m.Z.ddl/m0Z0m1Z1m2Z2ddl3m4Z4ddl5m6Z6m7Z7ddl8m9Z9dZ:Gdde Z;Gdde Z<Gdde Z=Gdde Z>Gdde Z?Gdd e Z@Gd!d"e ZAGd#d$e ZBy%)&)prod)AddSDummy expand_func)Expr)DefinedFunctionArgumentIndexError PoleError) fuzzy_and fuzzy_not)RationalpiooI)Powzeta)erferfcEi)re unpolarify)explog)ceilingfloor)sqrt)sincoscot) bernoulliharmonic) factorialrfRisingFactorial)as_int)mpworkprec) prec_to_dpsc> t|dy#t$rYywxYw)NF)strictT)r' ValueErrorns m/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/functions/special/gamma_functions.pyintliker1s&q s  ceZdZdZdZej fZd dZe dZ dZ dZ dZ dZdd Zd Zdfd Zd ZxZS)gammaa The gamma function .. math:: \Gamma(x) := \int^{\infty}_{0} t^{x-1} e^{-t} \mathrm{d}t. Explanation =========== 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 generally, $\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, 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 - zeta(3)/3 - 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] https://dlmf.nist.gov/5 .. [3] https://mathworld.wolfram.com/GammaFunction.html .. [4] https://functions.wolfram.com/GammaBetaErf/Gamma/ Tc|dk(r8|j|jdtd|jdzSt||Nr)funcargs polygammar selfargindexs r0fdiffz gamma.fdiffrsA q=99TYYq\*9Q ! +EE E$T84 4c|jrK|tjurtjS|turtSt |r*|j rt |dz StjS|jr|jdk(rt|j|jz}|j r|tj}}n0|dzx}}|dzdk(rtj}ntj}|ttdd|zdz}|j r|t!t"zd|zz Sd|zt!t"z|z Syyy)Nr6r) is_NumberrNaNrr1 is_positiver$ComplexInfinity is_RationalqabspOne NegativeOnerrangerr)clsargr/kcoeffs r0evalz gamma.evalxs ==aee|uu  ??$S1W--,,,55A:CEE cee+A#$aee5 !A Aq5A:$%EEE$%MMET%1Q3"233E$T"X~144 !tDH}u44%! r>c |jd}|jrt|j|jkDrt d}|j|jz}|j||jzz }|j ||zjj|t||jS|jrj|j\}}|r%|jdk7rt|}||z f|z}|}|j|ddi}|j |t||zS|j |jS)Nrxr6reevalF)r8rFrHrIrGrr7_eval_expand_funcsubsris_Add as_coeff_addr _new_rawargsr&) r;hintsrNrSr/rIrPtailintparts r0rUzgamma._eval_expand_funcsiil ??355zCEE!#JEESUUNEEAceeGOyyQ'99;@@HQPSPUPUDVWW ::**,KE4A,)D0#3##T8%8D99T??4#?? ?tyy$))$$r>cZ|j|jdjSNr)r7r8 conjugater;s r0_eval_conjugatezgamma._eval_conjugates"yy1//122r>c|jd}|jr |jryt|r|dkry|js |j ryy)NrFT)r8is_nonpositive is_integerr1rD is_nonintegerr;rSs r0 _eval_is_realzgamma._eval_is_realsF IIaL    1:!q& ==AOO,r>c~|jd}|jry|jrt|jSy)NrT)r8rDreris_evenrfs r0_eval_is_positivezgamma._eval_is_positives5 IIaL == __8## #r>c *tt|SN)rloggamma)r;zlimitvarkwargss r0_eval_rewrite_as_tractablez gamma._eval_rewrite_as_tractables8A;r>c t|dz SNr6)r$r;rnrps r0_eval_rewrite_as_factorialz gamma._eval_rewrite_as_factorialsQr>c0|jdj|d}|jr|dkst||||S|jd|z }|j |dzt |jd| dzz j |||SNrr6)r8limit is_Integersuper _eval_nseriesr7r%)r;rSr/logxcdirx0t __class__s r0r{zgamma._eval_nseriess YYq\  1 % "'7(At4 4 IIaL2  !a% DIIaL2#'!::II!QPTUUr>cF|jd}|j|d}|jrN|jrB| }tj |z|j |dzz }|||zj|z S|js|j |Strw) r8rVrdrcrrKr7as_leading_term is_infiniter )r;rSr|r}rNr~r/ress r0_eval_as_leading_termzgamma._eval_as_leading_termsiil XXa^ ==R..A--"499QU#33Ca0033 399R= kr>r6rl)r)__name__ __module__ __qualname____doc__ unbranchedrrE_singularitiesr= classmethodrQrUrargrjrqrur{r __classcell__rs@r0r3r3"sbJXJ'')N5 55@%(3$  V r>r3c^eZdZdZd dZedZdZdZdZ fdZ dZ d Z d Z xZS) lowergammaa The lower incomplete gamma function. Explanation =========== 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 ${}_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] https://dlmf.nist.gov/8 .. [4] https://functions.wolfram.com/GammaBetaErf/Gamma2/ .. [5] https://functions.wolfram.com/GammaBetaErf/Gamma3/ c6ddlm}|dk(r-|j\}}tt | ||dz zzS|dk(rQ|j\}}t |t |zt|t||zz |gddgdd|gg|z St||Nr)meijergr@r6) sympy.functions.special.hyperrr8rrr3digammar uppergammar r;r<rarns r0r=zlowergamma.fdiffs9 q=99DAq 1 ~&q1q5z1 1 ]99DAq8GAJ&Q 1a0@)@@"q!fq!QiQ78 8%T84 4r>c  |tjurtjS|j\}}|jr(|jrt |}||k7rt ||S|jrS|jrG|dk7rsdtztz|ztj| zzt| z t ||zS|dk7r,tdtztz|z|zt ||zS|jrR|tjurtjt| z S|tjur$t!tt#t!|zS|j$sd|zj$r|dz }|jr|jrSt|t| t|zt't)|Dcgc]}||zt|z c}zz St+|t tj|t!tz t| t't)d|tjzDcgc]5}||tjz zt+tj|zz 7c}zz zS|j$stjtj|z ztzt#t!|zt+d|z z t| t't)dt-dd|z Dcgc](}|||zdz zt+|zt+||zz *c}zzS|j.rtjSycc}wcc}wcc}w)Nrr@r6rA)rZeroextract_branch_factorrdrDrrrcrrrKr$rrBrJHalfrrryrrLr3ris_zero)rMrrSnxr/brOs r0rQzlowergamma.eval#s~" ;66M'')A <tBx)G#qb'RUDIJKMNQRQWQWMWDXXY~XY\]`a`f`f\fXghmnontntwxnxhyXyXYSZKZ*Z [[||==166A:6r9#d1g,FuQQRU|SVY[\Z\V]^aSXYZ\defhi\jmn\nSodpNOdehilmhmpqhqdrsxyzs{d{}BCDGHCH}IeIdp_qWqqq 9966M MvXYdpsM6 :M;$-N cPtd|jDr}|jdj|}|jdj|}t|5t j |d|}dddt j|S|S#1swY!xYw)Nc34K|]}|jywrl is_number.0rSs r0 z)lowergamma._eval_evalf..V.qq{{.rr6)allr8 _to_mpmathr)r(gammaincr _from_mpmathr;precrrnrs r0 _eval_evalfzlowergamma._eval_evalfUs .DII. . ! ''-A ! ''-A$ +kk!Q* +$$S$/ /K  + +s $BB%c|jd}|tjtjfvr;|j |jdj |j Syr5r8rrNegativeInfinityr7r_rfs r0razlowergamma._eval_conjugate_S IIaL QVVQ//0 099TYYq\335q{{}E E 1r>c|j\}}t|j|||j||g}|s|S|j||}|jr!t|j |j gS|j||}t|j |j t|jgSrl) r8r _eval_is_meromorphicrVrdrD is_finiter r)r;rSrsrn args_meromz0s0s r0rzlowergamma._eval_is_meromorphicds yy1 6 6q! < " "1a ( *+   VVAq\ <<ammR\\:; ; VVAq\",, i 6KLMMr>c( ddlm}|j\ |dtur^ j |sM zt z}t fdt|dz D}| z | zz}||z|zSt |%||||S)Nr)Oc3HK|]}|zt|dzz yw)r6N)r%)rrOrrns r0rz+lowergamma._eval_aseries..zs$C1a41a!e ,Cs"r6) sympy.series.orderrr8rhasrsumrLrz _eval_aseries) r;r/args0rSr|rrPsum_exprorrnrs @@r0rzlowergamma._eval_aseriesus(yy1 8r>!%%(qDaRLECeAElCCH!Q$qA2w,A>A% %w$Qq$77r>c 2t|t||z Srl)r3rr;rrSrps r0_eval_rewrite_as_uppergammaz&lowergamma._eval_rewrite_as_uppergammaQx*Q***r>c ddlm}|jr|jr|S|j t j |S)Nrexpint)'sympy.functions.special.error_functionsrrdrcrewriterr;rrSrprs r0_eval_rewrite_as_expintz"lowergamma._eval_rewrite_as_expints3B <c<|jd}|jryy)Nr6T)r8rrfs r0 _eval_is_zerozlowergamma._eval_is_zeros IIaL 99 r>r@)rrrrr=rrQrrarrrrrrrs@r0rrsH4n 5//bF N"8+8 r>rcLeZdZdZd dZdZedZdZdZ dZ dZ d Z y ) ra The upper incomplete gamma function. Explanation =========== 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 ${}_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] https://dlmf.nist.gov/8 .. [4] https://functions.wolfram.com/GammaBetaErf/Gamma2/ .. [5] https://functions.wolfram.com/GammaBetaErf/Gamma3/ .. [6] https://en.wikipedia.org/wiki/Exponential_integral#Relation_with_other_functions cddlm}|dk(r.|j\}}tt |  ||dz zzS|dk(r9|j\}}t ||t |z|gddgdd|gg|zSt||r)rrr8rrrrr rs r0r=zuppergamma.fdiffs9 q=99DAqA''AE 2 2 ]99DAqa#CF*WR!Q!QBPQ-RR R$T84 4r>cltd|jDr|jdj|}|jdj|}t|5t j ||tj }dddtj|S|S#1swY!xYw)Nc34K|]}|jywrlrrs r0rz)uppergamma._eval_evalf..rrrr6) rr8rr)r(rinfrrrs r0rzuppergamma._eval_evalfs .DII. . ! ''-A ! ''-A$ 0kk!Q/ 0$$S$/ /  0 0s $&B**B3c ( ddlm}|jrf|tjurtjS|t urtj S|jr t|jr t|S|j\}}|jr(|jrt|}||k7rt||S|jrS|jrG|dk7rdt zt"z|ztj$| zzt'| z t||zS|dk7r[t|dt)dt zt"z|z|zz zt)dt zt"z|z|zt||zzS|jr|tj ur|jr t+|  S|tj,ur t)| S|tj.ur$t1t t3t1|zS|j4sd|zj4r |dz }|jr|jrGt)| t'|zt7t9|Dcgc]}||zt'|z c}zSt|t3t1|ztj$|tddz z zt)| zt1|zt7t9|tj.z Dcgc]5}ttj. |z | |zztd|z z 7c}zzS|j4r|| |t||dzzzS|j4stj$tj.|z zt zt3t1|ztd|z z ||zt)| zt7t9tj.|z Dcgc]%}||zt|zt||zdzz 'c}zz S|jr|jr t+|  S|jr!t|jr t|Syycc}wcc}wcc}w)Nrrr6r@rA)rrrBrrCrrrrrDr3rrdrrrcrrrKr$rrrJrrrryrrL)rMrrnrrr/rrOs r0rQzuppergamma.evalsB ;;AEEzuu bvv a5$$ 8O'')A <QBC?@dYq\>Q>Q9R RR!&a4Q= 8 ! AaDF ;c1"g EQ O"%16q166z1B(D,-).qvvgk(:qb1W(DuQqSz(Q(D#E!E!EF\\!1"a=AQ)???||MMAFFQJ7"CAFFQJ>O5Q9:67TE!H_uQqSQRU|5S5Q0RRRS 99rF7N 99A**8O+9%>Q (D5Qs.R :R *R c|jd}|tjtjfvr;|j |jdj |j Syr5rr;rns r0razuppergamma._eval_conjugaterr>c0tj|||Srl)rr)r;rSrs r0rzuppergamma._eval_is_meromorphic"s..tQ::r>c 2t|t||z Srl)r3rrs r0_eval_rewrite_as_lowergammaz&uppergamma._eval_rewrite_as_lowergamma%rr>c Dtt|t||z Srl)rrmrrs r0rqz%uppergamma._eval_rewrite_as_tractable(s8A;*Q"222r>c 2ddlm}|d|z |||zzS)Nrrr6)rrrs r0rz"uppergamma._eval_rewrite_as_expint+sBa!eQ1$$r>Nr) rrrrr=rrrQrarrrqrr>r0rrsA>B 566pF ;+3%r>rcpeZdZdZedZdZdZdZdZ dZ dZ d Z d Z dd Zfd Zd ZxZS)r9a The function ``polygamma(n, z)`` returns ``log(gamma(z)).diff(n + 1)``. Explanation =========== 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). For `n` not a nonnegative integer the generalization by Espinosa and Moll [5]_ is used: .. math:: \psi(s,z) = \frac{\zeta'(s+1, z) + (\gamma + \psi(-s)) \zeta(s+1, z)} {\Gamma(-s)} 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] https://mathworld.wolfram.com/PolygammaFunction.html .. [3] https://functions.wolfram.com/GammaBetaErf/PolyGamma/ .. [4] https://functions.wolfram.com/GammaBetaErf/PolyGamma2/ .. [5] O. Espinosa and V. Moll, "A generalized polygamma function", *Integral Transforms and Special Functions* (2004), 101-115. cb|tjus|tjurtjS|tur"|jrtStjS|j r|j rtjS|tjur!t|tdtzdz z S|jr|t us"|jttt fvrtS|j rt|dz tjz S|j r>|j#\}}|dkr%t%t'tj|dSyy|j(r|j*rt-|}||k7r t'||S|j r2tj|dzzt/|zt1|dz|zS|tj2ur=tj|dzzt/|zd|dzzdz zt1|dzzSyyy)Nr@r6F)evaluate)rrCrrrryrcrErKrmrrextract_multiplicativelyrr# EulerGammarFas_numer_denomrr9rdis_nonnegativerr$rr)rMr/rnrIrGnzs r0rQzpolygamma.evals :aee55L "W2 . . \\a..$$ $ !-- A;QrTQ. . YYRCx155a8R"IE !}q||33'')16&yU'KLL  \\a..ABBw B''||}}qs+il:T!A#q\IIaff}}qs+il:a!A#hqjIDQRSTQTIUU /\r>cl|jdjr|jdjryyy)Nrr6T)r8rDr`s r0rgzpolygamma._eval_is_reals/ 99Q< # # ! (@(@)A #r>c|jd}t|j|jg}t|jt |gSrs)r8r is_negativerd is_complexr )r;rnis_negative_integers r0_eval_is_complexzpolygamma._eval_is_complexsA IIaL' (EF!,, 2E(FGHHr>c|j\}}|jr4|jr |jry|jr|jryyyyNTF)r8rDis_oddis_realrir;r/rns r0rjzpolygamma._eval_is_positivesByy1 ==xxAIIyyQ]]+y r>c|j\}}|jr4|jr |jry|jr|jryyyyr)r8rDrirrrs r0_eval_is_negativezpolygamma._eval_is_negativesByy1 ==yyQ]]xxAII&x r>c |j\}}|jr|jrw|jr|jd}|jrO|dz }|dkDr:t t dt |dzDcgc]}t||z |c}}n7t t t | Dcgc]}t||z|c} }t|||z tj|zt|z|zzS|jr|j\}}|jrq|jret t |Dcgc]}t||t||z}}|dk(rt ||z t!|zSt |||dzzz S||z}|dk(r9|j"r,|j%\}} tj& t(t+|t(z| z zdz z t!| z t t d| D cgc]?} t-d| zt(z|z| z t!dt/| t(z| z zzAc} z} |dkDr8t1|}||z } | t t |D cgc] } d| | zz  c} zS|dkr>t1d|z }||z} | t t |D cgc] } d| dz | z z c} z S|dk(r!t3|t!dt(zdz z S|j4dus|jdurvt7d} t9| |j;| j=| |dz}|tj&t?| zt9|dz|zztA| z St||Scc}wcc}wcc}wcc} wcc} wcc} w)Nrr6r@Fr)!r8ryrrWrrLintrr9rrKr$is_Mul as_two_termsrDrrrFrrrr!r rrrmrdrrdiffrVrr3)r;rZr/rnrPeir[rIrGrOpart_1rrdzts r0rUzpolygamma._eval_expand_funcsyy1 <>+q##(9(9,1#e*,=?'(&aX5."*"#?D?Av"Dz%/#e*<<"Dz%!a%.88U  6amm##%DAqll]R#a"fqj/%9A%==AFNSTUWXkZ#a!ebj1nq()CCB O0C,DDZJ\\F1u!HUE!H%Eqa26l%E FFFQ!a%LUa%I1a26A:&6%I JJJ 7A;QrTQ. . <<5 A$4$4$=c Aq!*//!$))!QqS1C1<<'1"+5ac1EEPQrR RAU%I&C?[ &F&Js%<N$3N) N.AN3 N8 N= c |jr?|jr2tj|dzzt |zt |dz|zSyyrs)rdrDrrKr$rr;r/rnrps r0_eval_rewrite_as_zetazpolygamma._eval_rewrite_as_zeta sA <c |jro|jrt|dz tjz Stj |dzzt |zt|dzt|dz |dzz zSyrs)rdrr#rrrKr$rrs r0_eval_rewrite_as_harmonicz#polygamma._eval_rewrite_as_harmonicso <<yyA55}}qs+il:d1Q3i(STUVSVXYZ[X[J\>\]] r>cddlm}|jDcgc]}|j|c}\}}|||}|dk(r6|j d|z r"| t |n|}|j |zS|j||Scc}w)NrOrderr6)rr r8rcontainsrgetnr7) r;rSr|r}r rr/rnrs r0rzpolygamma._eval_as_leading_terms|,.2ii8!!!$81 !QK 6ajj1o!\3q6tD668d? "99Q? " 9sB cf|dk(r!|jdd\}}t|dz|St||Nr@r6)r8r9r )r;r<r/rns r0r=zpolygamma.fdiff s: q=99Ra=DAqQUA& &$T84 4r>cddlm}|dtk7s2|jdjr|jdj st |||||S|jd}|jd}|dk(rt|dd|zz z }d} |dkr |d|z |} n_t|dzdz} td| D cgc]} td| zd| z|d| zzzz !} } |t| z}|d||zz |} |j|||| zSt|} | || zd|zz z}t|dzdz} td| D]H} | d| z|zdz zd| z|zdz zd| zd| zdz zz } |td| z| z|d| zzz z }J|d|d| zzz |} |dk(r |d|z |} n|dk(r|d|dzz |} |j|||| z}dd|z |zz|zj|||Scc} w)Nrr r6r@r)rr rr8ryrrzrrrrLr"rr{r3)r;r/rrSr|r rnNrrmrOlface0rs r0rzpolygamma._eval_aseries'sU, 8r>1((TYYq\-H-H7(E1d; ; IIaL IIaL 6AAaC AA1u!A#qMQUQJ'>CAqkJYqs^qs1qs8|4JJS!W !AqD&!$??1a.2 2(Cquac{"BQ #A1a[ 21Q37Q;'1q15!A#!aIi!nS(QqS11 2aAaCj!$AAv!A#qMa!AqD&!$  At,q0A"Q$NQ&55aDA A-Ks$Hctd|jDsy|jdj|dz}|jdj|dz}tj|r|dkrt j St|dz5tj|r|dk\rtj||}nwtj|dz|}tj|dz|d}|tjtj| z|zztj| z}dddtj|S#1swYxYw)Nc34K|]}|jywrlr)rrs r0rz(polygamma._eval_evalf..Qs211;;2rr r6)rr8rr(isintrrEr)r9reulerrrgammarr)r;rrrnrztrs r0rzpolygamma._eval_evalfPs!2 22  IIaL # #DG , IIaL # #DG , 88A;16$$ $ d2g  Oxx{qAvll1a(WWQqS!_ggac1a(bhhQB72==A2N  O  d++ O Os B)EE(r)rrrrrrQrgrrjrrUrrrr=rrrrs@r0r9r94s]hTVV:I 3jF^#5'BR,r>r9c^eZdZdZedZdZd fd ZfdZdZ dZ dZ d d Z xZ S) rma 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 >>> 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).cancel() -log(x) - EulerGamma*x + pi**2*x**2/12 - x**3*zeta(3)/3 + O(x**4) We can numerically evaluate the ``loggamma`` 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] https://dlmf.nist.gov/5 .. [3] https://mathworld.wolfram.com/LogGammaFunction.html .. [4] https://functions.wolfram.com/GammaBetaErf/LogGamma/ c|jr2|jrtS|jrt t |S|j rq|j\}}|jrR|dk(rMt ttdd|z zzt |zt |dztjzz S|turtSt|turtjS|tjurtjSyr)rdrcrrDrr3 is_rationalrrrrrrHrErC)rMrnrIrGs r0rQz loggamma.evals << 58}$ ]]##%DAq}}a48a!a%j058;eQUAFFN>SSTT 7I Vr\$$ $ :55L r>c Lddlm}|jd}|jr|j \}}||z}|||zz }|j r|j r||krt d}|j rS1q\TUWX[\Z\S]A^^^YY#AE?* r>c|jdj|d}|jr,|j|j}|j |||St ||||Sr^)r8rxr_eval_rewrite_as_intractabler{rz)r;rSr/r|r}r~frs r0r{zloggamma._eval_nseriessa YYq\  1 % ::111499=A??1a. .w$Q400r>cddlm}|dtk7rt |||||S|j d}t ||tjz z|z t dtzdz z}td|Dcgc]+}td|zd|zd|zdz z|d|zdz zzz -} }d} |dk(r |d|} n|d||zz |} |t| zj|||| zScc}w)Nrr r@r6)rr rrzrr8rrrrrLr"rr{) r;r/rrSr|r rnrrOrrrs r0rzloggamma._eval_aseriess, 8r>7(E1d; ; IIaL FAJ ! #c!B$ik 1DI!QK PqYqs^qsAaC!G}Q1q\9 : P P  6a Aa1fa ACG **1a6:: Qs;0C,c *tt|Srl)rr3rts r0r%z%loggamma._eval_rewrite_as_intractables58}r>cV|jd}|jry|jryy)NrTF)r8rDrcrs r0rgzloggamma._eval_is_reals* IIaL ==   r>c|jd}|tjtjfvr|j |j Syr^rrs r0razloggamma._eval_conjugates@ IIaL QVVQ//0 099Q[[]+ + 1r>cV|dk(rtd|jdSt||r5)r9r8r r:s r0r=zloggamma.fdiffs+ q=Q ! - -$T84 4r>r^r)rrrrrrQrUr{rr%rgrar=rrs@r0rmrmasAlZ&*1 ;, 5r>rmc^eZdZdZdZddZdZdZdZdZ e dZ d Z d Z d Zd Zy )rat The ``digamma`` function is the first derivative of the ``loggamma`` function .. 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)``. Examples ======== >>> from sympy import digamma >>> digamma(0) zoo >>> from sympy import Symbol >>> z = Symbol('z') >>> digamma(z) polygamma(0, z) To retain ``digamma`` as it is: >>> digamma(0, evaluate=False) digamma(0) >>> digamma(z, evaluate=False) digamma(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] https://mathworld.wolfram.com/DigammaFunction.html .. [3] https://functions.wolfram.com/GammaBetaErf/PolyGamma2/ cn|jd}t|}td|j|S)Nrr.r8r*r9evalfr;rrnnprecs r0rzdigamma._eval_evalfT3 IIaLD!A$$u$--r>cT|jd}td|jSr^r8r9r=r;r<rns r0r=z digamma.fdiffY$ IIaLA$$&&r>cL|jd}td|jSr^r8r9rrs r0rgzdigamma._eval_is_real]! IIaLA&&&r>cL|jd}td|jSr^r8r9rDrs r0rjzdigamma._eval_is_positivea! IIaLA***r>cL|jd}td|jSr^r8r9rrs r0rzdigamma._eval_is_negativeer<r>c||jt}tjg|z}|j ||||Srl)rr9rrrr;r/rrSr| as_polygammas r0rzdigamma._eval_aseriesis7||I.  E!))!UAt<ctd|Sr^r9rMrns r0rQz digamma.evalnAr>c X|jd}td|jdS)NrTr7r8r9expandr;rZrns r0rUzdigamma._eval_expand_funcr) IIaLA%%4%00r>c @t|dz tjz Srs)r#rrrts r0rz!digamma._eval_rewrite_as_harmonicvsA--r>c td|Sr^rCrts r0_eval_rewrite_as_polygammaz"digamma._eval_rewrite_as_polygammayAr>cV|jd}td|j|Sr^r8r9rr;rSr|r}rns r0rzdigamma._eval_as_leading_term|& IIaLA..q11r>Nr)rrrrrr=rgrjrrrrQrUrrNrrr>r0rr$sN.^. ''++= 1.2r>rcdeZdZdZdZddZdZdZdZdZ e dZ d Z d Z d Zd Zd Zy)trigammaa^ The ``trigamma`` function is the second derivative of the ``loggamma`` function .. math:: \psi^{(1)}(z) := \frac{\mathrm{d}^{2}}{\mathrm{d} z^{2}} \log\Gamma(z). In this case, ``trigamma(z) = polygamma(1, z)``. Examples ======== >>> from sympy import trigamma >>> trigamma(0) zoo >>> from sympy import Symbol >>> z = Symbol('z') >>> trigamma(z) polygamma(1, z) To retain ``trigamma`` as it is: >>> trigamma(0, evaluate=False) trigamma(0) >>> trigamma(z, evaluate=False) trigamma(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] https://mathworld.wolfram.com/TrigammaFunction.html .. [3] https://functions.wolfram.com/GammaBetaErf/PolyGamma2/ cn|jd}t|}td|j|S)Nrr6r.r.r0s r0rztrigamma._eval_evalfr2r>cT|jd}td|jSrwr4r5s r0r=ztrigamma.fdiffr6r>cL|jd}td|jSrwr8rs r0rgztrigamma._eval_is_realr9r>cL|jd}td|jSrwr;rs r0rjztrigamma._eval_is_positiver<r>cL|jd}td|jSrwr>rs r0rztrigamma._eval_is_negativer<r>c||jt}tjg|z}|j ||||Srl)rr9rrJrr@s r0rztrigamma._eval_aseriess7||I. 5 ))!UAt<ctd|SrsrCrDs r0rQz trigamma.evalrEr>c X|jd}td|jdS)Nrr6TrGrHrJs r0rUztrigamma._eval_expand_funcrKr>c td|S)Nr@rrts r0rztrigamma._eval_rewrite_as_zetasAqzr>c td|SrsrCrts r0rNz#trigamma._eval_rewrite_as_polygammarOr>c <t|dz d tdzdz zS)Nr6r@r)r#rrts r0rz"trigamma._eval_rewrite_as_harmonics#Q""RUQY..r>cV|jd}td|j|SrwrQrRs r0rztrigamma._eval_as_leading_termrSr>Nr)rrrrrr=rgrjrrrrQrUrrNrrrr>r0rUrUsS.^. ''++= 1/2r>rUc8eZdZdZdZddZedZdZdZ y) multigammaa The multivariate gamma function is a generalization of the gamma function .. math:: \Gamma_p(z) = \pi^{p(p-1)/4}\prod_{k=1}^p \Gamma[z + (1 - k)/2]. In a special case, ``multigamma(x, 1) = gamma(x)``. Examples ======== >>> from sympy import S, multigamma >>> from sympy import Symbol >>> x = Symbol('x') >>> p = Symbol('p', positive=True, integer=True) >>> multigamma(x, p) pi**(p*(p - 1)/4)*Product(gamma(-_k/2 + x + 1/2), (_k, 1, p)) Several special values are known: >>> multigamma(1, 1) 1 >>> multigamma(4, 1) 6 >>> multigamma(S(3)/2, 1) sqrt(pi)/2 Writing ``multigamma`` in terms of the ``gamma`` function: >>> multigamma(x, 1) gamma(x) >>> multigamma(x, 2) sqrt(pi)*gamma(x)*gamma(x - 1/2) >>> multigamma(x, 3) pi**(3/2)*gamma(x)*gamma(x - 1)*gamma(x - 1/2) Parameters ========== p : order or dimension of the multivariate gamma function See Also ======== gamma, lowergamma, uppergamma, polygamma, loggamma, digamma, trigamma, sympy.functions.special.beta_functions.beta References ========== .. [1] https://en.wikipedia.org/wiki/Multivariate_gamma_function Tc ddlm}|dk(rL|j\}}td}|j |||t d|d|z dz z|d|fzSt ||)Nrr!r@rOr6)r#r"r8rr7r9r )r;r<r"rSrIrOs r0r=zmultigamma.fdiff"sd1 q=99DAqc A99Q?3yAQ M'BQ1I#NN N$T84 4r>cddlm}|jdus|jdur t dt d}t ||dz zdz z|t|d|z dz z|d|fzjS) Nr)ProductFz+Order parameter p must be positive integer.rOr6r@) sympy.concrete.productsrfrDrdr-rrr3doit)rMrSrIrfrOs r0rQzmultigamma.eval+sy3 ==E !Q\\U%:JK K #JQAYq[!'%QUAI *>+,a)#556:df =r>c`|j\}}|j|j|Srl)r8r7r_)r;rSrIs r0razmultigamma._eval_conjugate4s&yy1yy**r>c|j\}}d|z}|jr ||dz kduryt|r ||dz kry||dz kDs |jryy)Nr@r6TF)r8rdr1re)r;rSrIys r0rgzmultigamma._eval_is_real8s^yy1 aC <Nr) rrrrrr=rrQrargrr>r0rcrcs27pJ5==+r>rcN)Cmathr sympy.corerrrrsympy.core.exprrsympy.core.functionr r r sympy.core.logicr r sympy.core.numbersrrrrsympy.core.powerr&sympy.functions.special.zeta_functionsrrrrr$sympy.functions.elementary.complexesrr&sympy.functions.elementary.exponentialrr#sympy.functions.elementary.integersrr(sympy.functions.elementary.miscellaneousr(sympy.functions.elementary.trigonometricrr r!%sympy.functions.combinatorial.numbersr"r#(sympy.functions.combinatorial.factorialsr$r%r&sympy.utilities.miscr'mpmathr(r)mpmath.libmp.libmpfr*r1r3rrr9rmrrUrcrr>r0rs11 NN122 7AA?;>9BBESS'+uOuxmm`_%_%Lj,j,Z @5@5FZ2oZ2|]2]2JYYr>