本文整理汇总了Python中sympy.polygamma函数的典型用法代码示例。如果您正苦于以下问题:Python polygamma函数的具体用法?Python polygamma怎么用?Python polygamma使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了polygamma函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_factorial_simplify_fail
def test_factorial_simplify_fail():
# simplify(factorial(x + 1).diff(x) - ((x + 1)*factorial(x)).diff(x))) == 0
from sympy.abc import x
assert (
simplify(x * polygamma(0, x + 1) - x * polygamma(0, x + 2) + polygamma(0, x + 1) - polygamma(0, x + 2) + 1) == 0
)
示例2: test_polygamma_expansion
def test_polygamma_expansion():
# A. & S., pa. 259 and 260
assert polygamma(0, 1 / x).nseries(x, n=3) == -log(x) - x / 2 - x ** 2 / 12 + O(x ** 4)
assert polygamma(1, 1 / x).series(x, n=5) == x + x ** 2 / 2 + x ** 3 / 6 + O(x ** 5)
assert polygamma(3, 1 / x).nseries(x, n=11) == 2 * x ** 3 + 3 * x ** 4 + 2 * x ** 5 - x ** 7 + 4 * x ** 9 / 3 + O(
x ** 11
)
示例3: test_factorial_diff
def test_factorial_diff():
n = Symbol('n', integer=True)
assert factorial(n).diff(n) == \
gamma(1 + n)*polygamma(0, 1 + n)
assert factorial(n**2).diff(n) == \
2*n*gamma(1 + n**2)*polygamma(0, 1 + n**2)
示例4: test_loggamma
def test_loggamma():
raises(TypeError, lambda: loggamma(2, 3))
raises(ArgumentIndexError, lambda: loggamma(x).fdiff(2))
assert loggamma(x).diff(x) == polygamma(0, x)
s1 = loggamma(1/(x + sin(x)) + cos(x)).nseries(x, n=4)
s2 = (-log(2*x) - 1)/(2*x) - log(x/pi)/2 + (4 - log(2*x))*x/24 + O(x**2) + \
log(x)*x**2/2
assert (s1 - s2).expand(force=True).removeO() == 0
s1 = loggamma(1/x).series(x)
s2 = (1/x - S(1)/2)*log(1/x) - 1/x + log(2*pi)/2 + \
x/12 - x**3/360 + x**5/1260 + O(x**7)
assert ((s1 - s2).expand(force=True)).removeO() == 0
assert loggamma(x).rewrite('intractable') == log(gamma(x))
s1 = loggamma(x).series(x)
assert s1 == -log(x) - EulerGamma*x + pi**2*x**2/12 + x**3*polygamma(2, 1)/6 + \
pi**4*x**4/360 + x**5*polygamma(4, 1)/120 + O(x**6)
assert s1 == loggamma(x).rewrite('intractable').series(x)
assert loggamma(x).is_real is None
y, z = Symbol('y', real=True), Symbol('z', imaginary=True)
assert loggamma(y).is_real
assert loggamma(z).is_real is False
def tN(N, M):
assert loggamma(1/x)._eval_nseries(x, n=N, logx=None).getn() == M
tN(0, 0)
tN(1, 1)
tN(2, 3)
tN(3, 3)
tN(4, 5)
tN(5, 5)
示例5: test_function__eval_nseries
def test_function__eval_nseries():
n = Symbol("n")
assert sin(x)._eval_nseries(x, 2, None) == x + O(x ** 2)
assert sin(x + 1)._eval_nseries(x, 2, None) == x * cos(1) + sin(1) + O(x ** 2)
assert sin(pi * (1 - x))._eval_nseries(x, 2, None) == pi * x + O(x ** 2)
assert acos(1 - x ** 2)._eval_nseries(x, 2, None) == sqrt(2) * x + O(x ** 2)
assert polygamma(n, x + 1)._eval_nseries(x, 2, None) == polygamma(n, 1) + polygamma(n + 1, 1) * x + O(x ** 2)
raises(PoleError, "sin(1/x)._eval_nseries(x,2,None)")
raises(PoleError, "acos(1-x)._eval_nseries(x,2,None)")
raises(PoleError, "acos(1+x)._eval_nseries(x,2,None)")
assert loggamma(1 / x)._eval_nseries(x, 0, None) == log(x) / 2 - log(x) / x - 1 / x + O(1, x)
assert loggamma(log(1 / x)).nseries(x, n=1, logx=y) == loggamma(-y)
示例6: fdiff
def fdiff(self, argindex=1):
from sympy import polygamma
if argindex == 1:
# http://functions.wolfram.com/GammaBetaErf/Binomial/20/01/01/
n, k = self.args
return binomial(n, k) * (polygamma(0, n + 1) - polygamma(0, n - k + 1))
elif argindex == 2:
# http://functions.wolfram.com/GammaBetaErf/Binomial/20/01/02/
n, k = self.args
return binomial(n, k) * (polygamma(0, n - k + 1) - polygamma(0, k + 1))
else:
raise ArgumentIndexError(self, argindex)
示例7: test_catalan
def test_catalan():
assert catalan(1) == 1
assert catalan(2) == 2
assert catalan(3) == 5
assert catalan(4) == 14
assert catalan(x) == catalan(x)
assert catalan(2*x).rewrite(binomial) == binomial(4*x, 2*x)/(2*x + 1)
assert catalan(Rational(1,2)).rewrite(gamma) == 8/(3*pi)
assert catalan(3*x).rewrite(gamma) == 4**(3*x)*gamma(3*x + Rational(1,2))/(sqrt(pi)*gamma(3*x + 2))
assert catalan(x).rewrite(hyper) == hyper((-x + 1, -x), (2,), 1)
assert diff(catalan(x),x) == (polygamma(0, x + Rational(1,2)) - polygamma(0, x + 2) + 2*log(2))*catalan(x)
c = catalan(0.5).evalf()
assert str(c) == '0.848826363156775'
示例8: test_FunctionWrapper
def test_FunctionWrapper():
import sympy
n, m, theta, phi = sympy.symbols("n, m, theta, phi")
r = sympy.Ynm(n, m, theta, phi)
s = Integer(2)*r
assert isinstance(s, Mul)
assert isinstance(s.args[1]._sympy_(), sympy.Ynm)
x = symbols("x")
e = x + sympy.loggamma(x)
assert str(e) == "x + loggamma(x)"
assert isinstance(e, Add)
assert e + sympy.loggamma(x) == x + 2*sympy.loggamma(x)
f = e.subs({x : 10})
assert f == 10 + log(362880)
f = e.subs({x : 2})
assert f == 2
f = e.subs({x : 100});
v = f.n(53, real=True);
assert abs(float(v) - 459.13420537) < 1e-7
f = e.diff(x)
assert f == 1 + sympy.polygamma(0, x)
示例9: test_gamma_series
def test_gamma_series():
assert gamma(x + 1).series(x, 0, 3) == \
1 - EulerGamma*x + x**2*(EulerGamma**2/2 + pi**2/12) + O(x**3)
assert gamma(x).series(x, -1, 3) == \
-1/(x + 1) + EulerGamma - 1 + (x + 1)*(-1 - pi**2/12 - EulerGamma**2/2 + \
EulerGamma) + (x + 1)**2*(-1 - pi**2/12 - EulerGamma**2/2 + EulerGamma**3/6 - \
polygamma(2, 1)/6 + EulerGamma*pi**2/12 + EulerGamma) + O((x + 1)**3, (x, -1))
示例10: test_gamma
def test_gamma():
assert gamma(nan) == nan
assert gamma(oo) == oo
assert gamma(-100) == zoo
assert gamma(0) == zoo
assert gamma(1) == 1
assert gamma(2) == 1
assert gamma(3) == 2
assert gamma(102) == factorial(101)
assert gamma(Rational(1,2)) == sqrt(pi)
assert gamma(Rational(3, 2)) == Rational(1, 2)*sqrt(pi)
assert gamma(Rational(5, 2)) == Rational(3, 4)*sqrt(pi)
assert gamma(Rational(7, 2)) == Rational(15, 8)*sqrt(pi)
assert gamma(Rational(-1, 2)) == -2*sqrt(pi)
assert gamma(Rational(-3, 2)) == Rational(4, 3)*sqrt(pi)
assert gamma(Rational(-5, 2)) == -Rational(8, 15)*sqrt(pi)
assert gamma(Rational(-15, 2)) == Rational(256, 2027025)*sqrt(pi)
assert gamma(x).diff(x) == gamma(x)*polygamma(0, x)
assert gamma(x - 1).expand(func=True) == gamma(x)/(x-1)
assert gamma(x + 2).expand(func=True, mul=False) == x*(x+1)*gamma(x)
assert expand_func(gamma(x + Rational(3, 2))) ==\
(x + Rational(1, 2))*gamma(x + Rational(1, 2))
示例11: test_lowergamma
def test_lowergamma():
from sympy import meijerg, exp_polar, I, expint
assert lowergamma(x, y).diff(y) == y**(x-1)*exp(-y)
assert td(lowergamma(randcplx(), y), y)
assert lowergamma(x, y).diff(x) == \
gamma(x)*polygamma(0, x) - uppergamma(x, y)*log(y) \
+ meijerg([], [1, 1], [0, 0, x], [], y)
assert lowergamma(S.Half, x) == sqrt(pi)*erf(sqrt(x))
assert not lowergamma(S.Half - 3, x).has(lowergamma)
assert not lowergamma(S.Half + 3, x).has(lowergamma)
assert lowergamma(S.Half, x, evaluate=False).has(lowergamma)
assert tn(lowergamma(S.Half + 3, x, evaluate=False),
lowergamma(S.Half + 3, x), x)
assert tn(lowergamma(S.Half - 3, x, evaluate=False),
lowergamma(S.Half - 3, x), x)
assert lowergamma(x, y).rewrite(uppergamma) == gamma(x) - uppergamma(x, y)
assert tn_branch(-3, lowergamma)
assert tn_branch(-4, lowergamma)
assert tn_branch(S(1)/3, lowergamma)
assert tn_branch(pi, lowergamma)
assert lowergamma(3, exp_polar(4*pi*I)*x) == lowergamma(3, x)
assert lowergamma(y, exp_polar(5*pi*I)*x) == \
exp(4*I*pi*y)*lowergamma(y, x*exp_polar(pi*I))
assert lowergamma(-2, exp_polar(5*pi*I)*x) == \
lowergamma(-2, x*exp_polar(I*pi)) + 2*pi*I
assert lowergamma(x, y).rewrite(expint) == -y**x*expint(-x + 1, y) + gamma(x)
k = Symbol('k', integer=True)
assert lowergamma(k, y).rewrite(expint) == -y**k*expint(-k + 1, y) + gamma(k)
k = Symbol('k', integer=True, positive=False)
assert lowergamma(k, y).rewrite(expint) == lowergamma(k, y)
示例12: test_gamma_series
def test_gamma_series():
assert gamma(x + 1).series(x, 0, 3) == \
1 - EulerGamma*x + x**2*(EulerGamma**2/2 + pi**2/12) + O(x**3)
assert gamma(x).series(x, -1, 3) == \
-1/x + EulerGamma - 1 + x*(-1 - pi**2/12 - EulerGamma**2/2 + EulerGamma) \
+ x**2*(-1 - pi**2/12 - EulerGamma**2/2 + EulerGamma**3/6 -
polygamma(2, 1)/6 + EulerGamma*pi**2/12 + EulerGamma) + O(x**3)
示例13: test_gamma
def test_gamma():
assert gamma(nan) == nan
assert gamma(oo) == oo
assert gamma(-100) == zoo
assert gamma(0) == zoo
assert gamma(1) == 1
assert gamma(2) == 1
assert gamma(3) == 2
assert gamma(102) == factorial(101)
assert gamma(Rational(1, 2)) == sqrt(pi)
assert gamma(Rational(3, 2)) == Rational(1, 2)*sqrt(pi)
assert gamma(Rational(5, 2)) == Rational(3, 4)*sqrt(pi)
assert gamma(Rational(7, 2)) == Rational(15, 8)*sqrt(pi)
assert gamma(Rational(-1, 2)) == -2*sqrt(pi)
assert gamma(Rational(-3, 2)) == Rational(4, 3)*sqrt(pi)
assert gamma(Rational(-5, 2)) == -Rational(8, 15)*sqrt(pi)
assert gamma(Rational(-15, 2)) == Rational(256, 2027025)*sqrt(pi)
assert gamma(Rational(
-11, 8)).expand(func=True) == Rational(64, 33)*gamma(Rational(5, 8))
assert gamma(Rational(
-10, 3)).expand(func=True) == Rational(81, 280)*gamma(Rational(2, 3))
assert gamma(Rational(
14, 3)).expand(func=True) == Rational(880, 81)*gamma(Rational(2, 3))
assert gamma(Rational(
17, 7)).expand(func=True) == Rational(30, 49)*gamma(Rational(3, 7))
assert gamma(Rational(
19, 8)).expand(func=True) == Rational(33, 64)*gamma(Rational(3, 8))
assert gamma(x).diff(x) == gamma(x)*polygamma(0, x)
assert gamma(x - 1).expand(func=True) == gamma(x)/(x - 1)
assert gamma(x + 2).expand(func=True, mul=False) == x*(x + 1)*gamma(x)
assert conjugate(gamma(x)) == gamma(conjugate(x))
assert expand_func(gamma(x + Rational(3, 2))) == \
(x + Rational(1, 2))*gamma(x + Rational(1, 2))
assert expand_func(gamma(x - Rational(1, 2))) == \
gamma(Rational(1, 2) + x)/(x - Rational(1, 2))
# Test a bug:
assert expand_func(gamma(x + Rational(3, 4))) == gamma(x + Rational(3, 4))
assert gamma(3*exp_polar(I*pi)/4).is_nonnegative is False
assert gamma(3*exp_polar(I*pi)/4).is_nonpositive is True
# Issue 8526
k = Symbol('k', integer=True, nonnegative=True)
assert isinstance(gamma(k), gamma)
assert gamma(-k) == zoo
示例14: test_evalf_default
def test_evalf_default():
from sympy.functions.special.gamma_functions import polygamma
assert type(sin(4.0)) == Real
assert type(re(sin(I + 1.0))) == Real
assert type(im(sin(I + 1.0))) == Real
assert type(sin(4)) == sin
assert type(polygamma(2,4.0)) == Real
assert type(sin(Rational(1,4))) == sin
示例15: test_gamma_series
def test_gamma_series():
assert gamma(x + 1).series(x, 0, 3) == \
1 - x*EulerGamma + x**2*EulerGamma**2/2 + pi**2*x**2/12 + O(x**3)
assert gamma(x).series(x, -1, 3) == \
-1/x + EulerGamma - 1 + EulerGamma*x - EulerGamma**2*x/2 - pi**2*x/12 \
- x + EulerGamma*x**2 + EulerGamma*pi**2*x**2/12 - \
x**2*polygamma(2, 1)/6 + EulerGamma**3*x**2/6 - EulerGamma**2*x**2/2 \
- pi**2*x**2/12 - x**2 + O(x**3)