本文整理汇总了Python中sympy.combsimp函数的典型用法代码示例。如果您正苦于以下问题:Python combsimp函数的具体用法?Python combsimp怎么用?Python combsimp使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了combsimp函数的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_issue_9699
def test_issue_9699():
n, k = symbols('n k', real=True)
x, y = symbols('x, y')
assert combsimp((n + 1)*factorial(n)) == factorial(n + 1)
assert combsimp((x + 1)*factorial(x)/gamma(y)) == gamma(x + 2)/gamma(y)
assert combsimp(factorial(n)/n) == factorial(n - 1)
assert combsimp(rf(x + n, k)*binomial(n, k)) == binomial(n, k)*gamma(k + n + x)/gamma(n + x)
开发者ID:A-turing-machine,项目名称:sympy,代码行数:7,代码来源:test_combsimp.py
示例2: test_meijerg_expand
def test_meijerg_expand():
from sympy import combsimp, simplify
# from mpmath docs
assert hyperexpand(meijerg([[], []], [[0], []], -z)) == exp(z)
assert hyperexpand(meijerg([[1, 1], []], [[1], [0]], z)) == \
log(z + 1)
assert hyperexpand(meijerg([[1, 1], []], [[1], [1]], z)) == \
z/(z + 1)
assert hyperexpand(meijerg([[], []], [[S(1)/2], [0]], (z/2)**2)) \
== sin(z)/sqrt(pi)
assert hyperexpand(meijerg([[], []], [[0], [S(1)/2]], (z/2)**2)) \
== cos(z)/sqrt(pi)
assert can_do_meijer([], [a], [a - 1, a - S.Half], [])
assert can_do_meijer([], [], [a/2], [-a/2], False) # branches...
assert can_do_meijer([a], [b], [a], [b, a - 1])
# wikipedia
assert hyperexpand(meijerg([1], [], [], [0], z)) == \
Piecewise((0, abs(z) < 1), (1, abs(1/z) < 1),
(meijerg([1], [], [], [0], z), True))
assert hyperexpand(meijerg([], [1], [0], [], z)) == \
Piecewise((1, abs(z) < 1), (0, abs(1/z) < 1),
(meijerg([], [1], [0], [], z), True))
# The Special Functions and their Approximations
assert can_do_meijer([], [], [a + b/2], [a, a - b/2, a + S.Half])
assert can_do_meijer(
[], [], [a], [b], False) # branches only agree for small z
assert can_do_meijer([], [S.Half], [a], [-a])
assert can_do_meijer([], [], [a, b], [])
assert can_do_meijer([], [], [a, b], [])
assert can_do_meijer([], [], [a, a + S.Half], [b, b + S.Half])
assert can_do_meijer([], [], [a, -a], [0, S.Half], False) # dito
assert can_do_meijer([], [], [a, a + S.Half, b, b + S.Half], [])
assert can_do_meijer([S.Half], [], [0], [a, -a])
assert can_do_meijer([S.Half], [], [a], [0, -a], False) # dito
assert can_do_meijer([], [a - S.Half], [a, b], [a - S.Half], False)
assert can_do_meijer([], [a + S.Half], [a + b, a - b, a], [], False)
assert can_do_meijer([a + S.Half], [], [b, 2*a - b, a], [], False)
# This for example is actually zero.
assert can_do_meijer([], [], [], [a, b])
# Testing a bug:
assert hyperexpand(meijerg([0, 2], [], [], [-1, 1], z)) == \
Piecewise((0, abs(z) < 1),
(z*(1 - 1/z**2)/2, abs(1/z) < 1),
(meijerg([0, 2], [], [], [-1, 1], z), True))
# Test that the simplest possible answer is returned:
assert combsimp(
simplify(hyperexpand(meijerg([1], [1 - a], [-a/2, -a/2 + S(1)/2],
[], 1/z)))) == \
-2*sqrt(pi)*(sqrt(z + 1) + 1)**a/a
# Test that hyper is returned
assert hyperexpand(meijerg([1], [], [a], [0, 0], z)) == \
z**a*gamma(a)*hyper(
(a,), (a + 1, a + 1), z*exp_polar(I*pi))/gamma(a + 1)**2
开发者ID:jenshnielsen,项目名称:sympy,代码行数:60,代码来源:test_hyperexpand.py
示例3: test_lerchphi
def test_lerchphi():
from sympy import combsimp, exp_polar, polylog, log, lerchphi
assert hyperexpand(hyper([1, a], [a + 1], z)/a) == lerchphi(z, 1, a)
assert hyperexpand(
hyper([1, a, a], [a + 1, a + 1], z)/a**2) == lerchphi(z, 2, a)
assert hyperexpand(hyper([1, a, a, a], [a + 1, a + 1, a + 1], z)/a**3) == \
lerchphi(z, 3, a)
assert hyperexpand(hyper([1] + [a]*10, [a + 1]*10, z)/a**10) \
== lerchphi(z, 10, a)
assert combsimp(hyperexpand(meijerg([0, 1 - a], [], [0], [-a],
exp_polar(-I*pi)*z))) == \
lerchphi(z, 1, a)
assert combsimp(hyperexpand(meijerg([0, 1 - a, 1 - a], [], [0], [-a, -a],
exp_polar(-I*pi)*z))) == \
lerchphi(z, 2, a)
assert combsimp(
hyperexpand(meijerg([0, 1 - a, 1 - a, 1 - a], [], [0], [-a, -a, -a],
exp_polar(-I*pi)*z))) == \
lerchphi(z, 3, a)
assert hyperexpand(z*hyper([1, 1], [2], z)) == -log(1 + -z)
assert hyperexpand(z*hyper([1, 1, 1], [2, 2], z)) == polylog(2, z)
assert hyperexpand(z*hyper([1, 1, 1, 1], [2, 2, 2], z)) == polylog(3, z)
assert hyperexpand(hyper([1, a, 1 + S(1)/2], [a + 1, S(1)/2], z)) == \
-2*a/(z - 1) + (-2*a**2 + a)*lerchphi(z, 1, a)
# Now numerical tests. These make sure reductions etc are carried out
# correctly
# a rational function (polylog at negative integer order)
assert can_do([2, 2, 2], [1, 1])
# NOTE these contain log(1-x) etc ... better make sure we have |z| < 1
# reduction of order for polylog
assert can_do([1, 1, 1, b + 5], [2, 2, b], div=10)
# reduction of order for lerchphi
# XXX lerchphi in mpmath is flaky
assert can_do(
[1, a, a, a, b + 5], [a + 1, a + 1, a + 1, b], numerical=False)
# test a bug
from sympy import Abs
assert hyperexpand(hyper([S(1)/2, S(1)/2, S(1)/2, 1],
[S(3)/2, S(3)/2, S(3)/2], S(1)/4)) == \
Abs(-polylog(3, exp_polar(I*pi)/2) + polylog(3, S(1)/2))
开发者ID:jenshnielsen,项目名称:sympy,代码行数:47,代码来源:test_hyperexpand.py
示例4: test_combsimp
def test_combsimp():
from sympy.abc import n, k
assert combsimp(factorial(n)) == factorial(n)
assert combsimp(binomial(n, k)) == binomial(n, k)
assert combsimp(factorial(n)/factorial(n - 3)) == n*(-1 + n)*(-2 + n)
assert combsimp(binomial(n + 1, k + 1)/binomial(n, k)) == (1 + n)/(1 + k)
assert combsimp(binomial(3*n + 4, n + 1)/binomial(3*n + 1, n)) == \
S(3)/2*((3*n + 2)*(3*n + 4)/((n + 1)*(2*n + 3)))
assert combsimp(factorial(n)**2/factorial(n - 3)) == factorial(n)*n*(-1 + n)*(-2 + n)
assert combsimp(factorial(n)*binomial(n+1, k+1)/binomial(n, k)) == factorial(n)*(1 + n)/(1 + k)
assert combsimp(binomial(n - 1, k)) == -((-n + k)*binomial(n, k))/n
assert combsimp(binomial(n + 2, k + S(1)/2)) == \
4*((n + 1)*(n + 2)*binomial(n, k + S(1)/2))/((2*k - 2*n - 1)*(2*k - 2*n - 3))
assert combsimp(binomial(n + 2, k + 2.0)) == \
-((1.0*n + 2.0)*binomial(n + 1.0, k + 2.0))/(k - n)
开发者ID:ness01,项目名称:sympy,代码行数:21,代码来源:test_simplify.py
示例5: test_action_verbs
def test_action_verbs():
assert nsimplify((1/(exp(3*pi*x/5)+1))) == (1/(exp(3*pi*x/5)+1)).nsimplify()
assert ratsimp(1/x + 1/y) == (1/x + 1/y).ratsimp()
assert trigsimp(log(x), deep=True) == (log(x)).trigsimp(deep = True)
assert radsimp(1/(2+sqrt(2))) == (1/(2+sqrt(2))).radsimp()
assert powsimp(x**y*x**z*y**z, combine='all') == (x**y*x**z*y**z).powsimp(combine='all')
assert simplify(x**y*x**z*y**z) == (x**y*x**z*y**z).simplify()
assert together(1/x + 1/y) == (1/x + 1/y).together()
assert separate((x*(y*z)**3)**2) == ((x*(y*z)**3)**2).separate()
assert collect(a*x**2 + b*x**2 + a*x - b*x + c, x) == (a*x**2 + b*x**2 + a*x - b*x + c).collect(x)
assert apart(y/(y+2)/(y+1), y) == (y/(y+2)/(y+1)).apart(y)
assert combsimp(y/(x+2)/(x+1)) == (y/(x+2)/(x+1)).combsimp()
assert factor(x**2+5*x+6) == (x**2+5*x+6).factor()
assert refine(sqrt(x**2)) == sqrt(x**2).refine()
assert cancel((x**2+5*x+6)/(x+2)) == ((x**2+5*x+6)/(x+2)).cancel()
开发者ID:goodok,项目名称:sympy,代码行数:15,代码来源:test_expr.py
示例6: test_mellin_transform_bessel
def test_mellin_transform_bessel():
from sympy import Max, Min, hyper, meijerg
MT = mellin_transform
# 8.4.19
assert MT(besselj(a, 2*sqrt(x)), x, s) == \
(gamma(a/2 + s)/gamma(a/2 - s + 1), (-re(a)/2, S(3)/4), True)
assert MT(sin(sqrt(x))*besselj(a, sqrt(x)), x, s) == \
(2**a*gamma(-2*s + S(1)/2)*gamma(a/2 + s + S(1)/2)/(
gamma(-a/2 - s + 1)*gamma(a - 2*s + 1)), (
-re(a)/2 - S(1)/2, S(1)/4), True)
assert MT(cos(sqrt(x))*besselj(a, sqrt(x)), x, s) == \
(2**a*gamma(a/2 + s)*gamma(-2*s + S(1)/2)/(
gamma(-a/2 - s + S(1)/2)*gamma(a - 2*s + 1)), (
-re(a)/2, S(1)/4), True)
assert MT(besselj(a, sqrt(x))**2, x, s) == \
(gamma(a + s)*gamma(S(1)/2 - s)
/ (sqrt(pi)*gamma(1 - s)*gamma(1 + a - s)),
(-re(a), S(1)/2), True)
assert MT(besselj(a, sqrt(x))*besselj(-a, sqrt(x)), x, s) == \
(gamma(s)*gamma(S(1)/2 - s)
/ (sqrt(pi)*gamma(1 - a - s)*gamma(1 + a - s)),
(0, S(1)/2), True)
# NOTE: prudnikov gives the strip below as (1/2 - re(a), 1). As far as
# I can see this is wrong (since besselj(z) ~ 1/sqrt(z) for z large)
assert MT(besselj(a - 1, sqrt(x))*besselj(a, sqrt(x)), x, s) == \
(gamma(1 - s)*gamma(a + s - S(1)/2)
/ (sqrt(pi)*gamma(S(3)/2 - s)*gamma(a - s + S(1)/2)),
(S(1)/2 - re(a), S(1)/2), True)
assert MT(besselj(a, sqrt(x))*besselj(b, sqrt(x)), x, s) == \
(4**s*gamma(1 - 2*s)*gamma((a + b)/2 + s)
/ (gamma(1 - s + (b - a)/2)*gamma(1 - s + (a - b)/2)
*gamma( 1 - s + (a + b)/2)),
(-(re(a) + re(b))/2, S(1)/2), True)
assert MT(besselj(a, sqrt(x))**2 + besselj(-a, sqrt(x))**2, x, s)[1:] == \
((Max(re(a), -re(a)), S(1)/2), True)
# Section 8.4.20
assert MT(bessely(a, 2*sqrt(x)), x, s) == \
(-cos(pi*(a/2 - s))*gamma(s - a/2)*gamma(s + a/2)/pi,
(Max(-re(a)/2, re(a)/2), S(3)/4), True)
assert MT(sin(sqrt(x))*bessely(a, sqrt(x)), x, s) == \
(-4**s*sin(pi*(a/2 - s))*gamma(S(1)/2 - 2*s)
* gamma((1 - a)/2 + s)*gamma((1 + a)/2 + s)
/ (sqrt(pi)*gamma(1 - s - a/2)*gamma(1 - s + a/2)),
(Max(-(re(a) + 1)/2, (re(a) - 1)/2), S(1)/4), True)
assert MT(cos(sqrt(x))*bessely(a, sqrt(x)), x, s) == \
(-4**s*cos(pi*(a/2 - s))*gamma(s - a/2)*gamma(s + a/2)*gamma(S(1)/2 - 2*s)
/ (sqrt(pi)*gamma(S(1)/2 - s - a/2)*gamma(S(1)/2 - s + a/2)),
(Max(-re(a)/2, re(a)/2), S(1)/4), True)
assert MT(besselj(a, sqrt(x))*bessely(a, sqrt(x)), x, s) == \
(-cos(pi*s)*gamma(s)*gamma(a + s)*gamma(S(1)/2 - s)
/ (pi**S('3/2')*gamma(1 + a - s)),
(Max(-re(a), 0), S(1)/2), True)
assert MT(besselj(a, sqrt(x))*bessely(b, sqrt(x)), x, s) == \
(-4**s*cos(pi*(a/2 - b/2 + s))*gamma(1 - 2*s)
* gamma(a/2 - b/2 + s)*gamma(a/2 + b/2 + s)
/ (pi*gamma(a/2 - b/2 - s + 1)*gamma(a/2 + b/2 - s + 1)),
(Max((-re(a) + re(b))/2, (-re(a) - re(b))/2), S(1)/2), True)
# NOTE bessely(a, sqrt(x))**2 and bessely(a, sqrt(x))*bessely(b, sqrt(x))
# are a mess (no matter what way you look at it ...)
assert MT(bessely(a, sqrt(x))**2, x, s)[1:] == \
((Max(-re(a), 0, re(a)), S(1)/2), True)
# Section 8.4.22
# TODO we can't do any of these (delicate cancellation)
# Section 8.4.23
assert MT(besselk(a, 2*sqrt(x)), x, s) == \
(gamma(
s - a/2)*gamma(s + a/2)/2, (Max(-re(a)/2, re(a)/2), oo), True)
assert MT(besselj(a, 2*sqrt(2*sqrt(x)))*besselk(
a, 2*sqrt(2*sqrt(x))), x, s) == (4**(-s)*gamma(2*s)*
gamma(a/2 + s)/(2*gamma(a/2 - s + 1)), (Max(0, -re(a)/2), oo), True)
# TODO bessely(a, x)*besselk(a, x) is a mess
assert MT(besseli(a, sqrt(x))*besselk(a, sqrt(x)), x, s) == \
(gamma(s)*gamma(
a + s)*gamma(-s + S(1)/2)/(2*sqrt(pi)*gamma(a - s + 1)),
(Max(-re(a), 0), S(1)/2), True)
assert MT(besseli(b, sqrt(x))*besselk(a, sqrt(x)), x, s) == \
(2**(2*s - 1)*gamma(-2*s + 1)*gamma(-a/2 + b/2 + s)* \
gamma(a/2 + b/2 + s)/(gamma(-a/2 + b/2 - s + 1)* \
gamma(a/2 + b/2 - s + 1)), (Max(-re(a)/2 - re(b)/2, \
re(a)/2 - re(b)/2), S(1)/2), True)
# TODO products of besselk are a mess
mt = MT(exp(-x/2)*besselk(a, x/2), x, s)
mt0 = combsimp((trigsimp(combsimp(mt[0].expand(func=True)))))
assert mt0 == 2*pi**(S(3)/2)*cos(pi*s)*gamma(-s + S(1)/2)/(
(cos(2*pi*a) - cos(2*pi*s))*gamma(-a - s + 1)*gamma(a - s + 1))
assert mt[1:] == ((Max(-re(a), re(a)), oo), True)
开发者ID:FedericoV,项目名称:sympy,代码行数:92,代码来源:test_transforms.py
示例7: test_combsimp
def test_combsimp():
assert combsimp(A*B - B*A) == A*B - B*A
开发者ID:BDGLunde,项目名称:sympy,代码行数:2,代码来源:test_noncommutative.py
示例8: test_probability
def test_probability():
# various integrals from probability theory
from sympy.abc import x, y
from sympy import symbols, Symbol, Abs, expand_mul, combsimp, powsimp, sin
mu1, mu2 = symbols("mu1 mu2", real=True, nonzero=True, finite=True)
sigma1, sigma2 = symbols("sigma1 sigma2", real=True, nonzero=True, finite=True, positive=True)
rate = Symbol("lambda", real=True, positive=True, finite=True)
def normal(x, mu, sigma):
return 1 / sqrt(2 * pi * sigma ** 2) * exp(-(x - mu) ** 2 / 2 / sigma ** 2)
def exponential(x, rate):
return rate * exp(-rate * x)
assert integrate(normal(x, mu1, sigma1), (x, -oo, oo), meijerg=True) == 1
assert integrate(x * normal(x, mu1, sigma1), (x, -oo, oo), meijerg=True) == mu1
assert integrate(x ** 2 * normal(x, mu1, sigma1), (x, -oo, oo), meijerg=True) == mu1 ** 2 + sigma1 ** 2
assert integrate(x ** 3 * normal(x, mu1, sigma1), (x, -oo, oo), meijerg=True) == mu1 ** 3 + 3 * mu1 * sigma1 ** 2
assert integrate(normal(x, mu1, sigma1) * normal(y, mu2, sigma2), (x, -oo, oo), (y, -oo, oo), meijerg=True) == 1
assert (
integrate(x * normal(x, mu1, sigma1) * normal(y, mu2, sigma2), (x, -oo, oo), (y, -oo, oo), meijerg=True) == mu1
)
assert (
integrate(y * normal(x, mu1, sigma1) * normal(y, mu2, sigma2), (x, -oo, oo), (y, -oo, oo), meijerg=True) == mu2
)
assert (
integrate(x * y * normal(x, mu1, sigma1) * normal(y, mu2, sigma2), (x, -oo, oo), (y, -oo, oo), meijerg=True)
== mu1 * mu2
)
assert (
integrate(
(x + y + 1) * normal(x, mu1, sigma1) * normal(y, mu2, sigma2), (x, -oo, oo), (y, -oo, oo), meijerg=True
)
== 1 + mu1 + mu2
)
assert (
integrate(
(x + y - 1) * normal(x, mu1, sigma1) * normal(y, mu2, sigma2), (x, -oo, oo), (y, -oo, oo), meijerg=True
)
== -1 + mu1 + mu2
)
i = integrate(x ** 2 * normal(x, mu1, sigma1) * normal(y, mu2, sigma2), (x, -oo, oo), (y, -oo, oo), meijerg=True)
assert not i.has(Abs)
assert simplify(i) == mu1 ** 2 + sigma1 ** 2
assert (
integrate(y ** 2 * normal(x, mu1, sigma1) * normal(y, mu2, sigma2), (x, -oo, oo), (y, -oo, oo), meijerg=True)
== sigma2 ** 2 + mu2 ** 2
)
assert integrate(exponential(x, rate), (x, 0, oo), meijerg=True) == 1
assert integrate(x * exponential(x, rate), (x, 0, oo), meijerg=True) == 1 / rate
assert integrate(x ** 2 * exponential(x, rate), (x, 0, oo), meijerg=True) == 2 / rate ** 2
def E(expr):
res1 = integrate(expr * exponential(x, rate) * normal(y, mu1, sigma1), (x, 0, oo), (y, -oo, oo), meijerg=True)
res2 = integrate(expr * exponential(x, rate) * normal(y, mu1, sigma1), (y, -oo, oo), (x, 0, oo), meijerg=True)
assert expand_mul(res1) == expand_mul(res2)
return res1
assert E(1) == 1
assert E(x * y) == mu1 / rate
assert E(x * y ** 2) == mu1 ** 2 / rate + sigma1 ** 2 / rate
ans = sigma1 ** 2 + 1 / rate ** 2
assert simplify(E((x + y + 1) ** 2) - E(x + y + 1) ** 2) == ans
assert simplify(E((x + y - 1) ** 2) - E(x + y - 1) ** 2) == ans
assert simplify(E((x + y) ** 2) - E(x + y) ** 2) == ans
# Beta' distribution
alpha, beta = symbols("alpha beta", positive=True)
betadist = x ** (alpha - 1) * (1 + x) ** (-alpha - beta) * gamma(alpha + beta) / gamma(alpha) / gamma(beta)
assert integrate(betadist, (x, 0, oo), meijerg=True) == 1
i = integrate(x * betadist, (x, 0, oo), meijerg=True, conds="separate")
assert (combsimp(i[0]), i[1]) == (alpha / (beta - 1), 1 < beta)
j = integrate(x ** 2 * betadist, (x, 0, oo), meijerg=True, conds="separate")
assert j[1] == (1 < beta - 1)
assert combsimp(j[0] - i[0] ** 2) == (alpha + beta - 1) * alpha / (beta - 2) / (beta - 1) ** 2
# Beta distribution
# NOTE: this is evaluated using antiderivatives. It also tests that
# meijerint_indefinite returns the simplest possible answer.
a, b = symbols("a b", positive=True)
betadist = x ** (a - 1) * (-x + 1) ** (b - 1) * gamma(a + b) / (gamma(a) * gamma(b))
assert simplify(integrate(betadist, (x, 0, 1), meijerg=True)) == 1
assert simplify(integrate(x * betadist, (x, 0, 1), meijerg=True)) == a / (a + b)
assert simplify(integrate(x ** 2 * betadist, (x, 0, 1), meijerg=True)) == a * (a + 1) / (a + b) / (a + b + 1)
assert simplify(integrate(x ** y * betadist, (x, 0, 1), meijerg=True)) == gamma(a + b) * gamma(a + y) / gamma(
a
) / gamma(a + b + y)
# Chi distribution
k = Symbol("k", integer=True, positive=True)
chi = 2 ** (1 - k / 2) * x ** (k - 1) * exp(-x ** 2 / 2) / gamma(k / 2)
assert powsimp(integrate(chi, (x, 0, oo), meijerg=True)) == 1
assert simplify(integrate(x * chi, (x, 0, oo), meijerg=True)) == sqrt(2) * gamma((k + 1) / 2) / gamma(k / 2)
assert simplify(integrate(x ** 2 * chi, (x, 0, oo), meijerg=True)) == k
# Chi^2 distribution
chisquared = 2 ** (-k / 2) / gamma(k / 2) * x ** (k / 2 - 1) * exp(-x / 2)
#.........这里部分代码省略.........
开发者ID:Carreau,项目名称:sympy,代码行数:101,代码来源:test_meijerint.py
示例9: test_combsimp
def test_combsimp():
from sympy.abc import n, k
assert combsimp(factorial(n)) == factorial(n)
assert combsimp(binomial(n, k)) == binomial(n, k)
assert combsimp(factorial(n)/factorial(n - 3)) == n*(-1 + n)*(-2 + n)
assert combsimp(binomial(n + 1, k + 1)/binomial(n, k)) == (1 + n)/(1 + k)
assert combsimp(binomial(3*n + 4, n + 1)/binomial(3*n + 1, n)) == \
S(3)/2*((3*n + 2)*(3*n + 4)/((n + 1)*(2*n + 3)))
assert combsimp(factorial(n)**2/factorial(n - 3)) == \
factorial(n)*n*(-1 + n)*(-2 + n)
assert combsimp(factorial(n)*binomial(n + 1, k + 1)/binomial(n, k)) == \
factorial(n + 1)/(1 + k)
assert combsimp(binomial(n - 1, k)) == -((-n + k)*binomial(n, k))/n
assert combsimp(binomial(n + 2, k + S(1)/2)) == 4*((n + 1)*(n + 2) *
binomial(n, k + S(1)/2))/((2*k - 2*n - 1)*(2*k - 2*n - 3))
assert combsimp(binomial(n + 2, k + 2.0)) == \
-((1.0*n + 2.0)*binomial(n + 1.0, k + 2.0))/(k - n)
# coverage tests
assert combsimp(factorial(n*(1 + n) - n**2 - n)) == 1
assert combsimp(binomial(n + k - 2, n)) == \
k*(k - 1)*binomial(n + k, n)/((n + k)*(n + k - 1))
i = Symbol('i', integer=True)
e = gamma(i + 3)
assert combsimp(e) == e
e = gamma(exp(i))
assert combsimp(e) == e
e = gamma(n + S(1)/3)*gamma(n + S(2)/3)
assert combsimp(e) == e
assert combsimp(gamma(4*n + S(1)/2)/gamma(2*n - S(3)/4)) == \
2**(4*n - S(5)/2)*(8*n - 3)*gamma(2*n + S(3)/4)/sqrt(pi)
assert combsimp(6*FallingFactorial(-4, n)/factorial(n)) == \
(-1)**n*(n + 1)*(n + 2)*(n + 3)
assert combsimp(6*FallingFactorial(-4, n - 1)/factorial(n - 1)) == \
(-1)**(n - 1)*n*(n + 1)*(n + 2)
assert combsimp(6*FallingFactorial(-4, n - 3)/factorial(n - 3)) == \
(-1)**(n - 3)*n*(n - 1)*(n - 2)
assert combsimp(6*FallingFactorial(-4, -n - 1)/factorial(-n - 1)) == \
-(-1)**(-n - 1)*n*(n - 1)*(n - 2)
assert combsimp(6*RisingFactorial(4, n)/factorial(n)) == \
(n + 1)*(n + 2)*(n + 3)
assert combsimp(6*RisingFactorial(4, n - 1)/factorial(n - 1)) == \
n*(n + 1)*(n + 2)
assert combsimp(6*RisingFactorial(4, n - 3)/factorial(n - 3)) == \
n*(n - 1)*(n - 2)
assert combsimp(6*RisingFactorial(4, -n - 1)/factorial(-n - 1)) == \
-n*(n - 1)*(n - 2)
开发者ID:A-turing-machine,项目名称:sympy,代码行数:55,代码来源:test_combsimp.py
示例10: test_combsimp_gamma
def test_combsimp_gamma():
from sympy.abc import x, y
R = Rational
assert combsimp(gamma(x)) == gamma(x)
assert combsimp(gamma(x + 1)/x) == gamma(x)
assert combsimp(gamma(x)/(x - 1)) == gamma(x - 1)
assert combsimp(x*gamma(x)) == gamma(x + 1)
assert combsimp((x + 1)*gamma(x + 1)) == gamma(x + 2)
assert combsimp(gamma(x + y)*(x + y)) == gamma(x + y + 1)
assert combsimp(x/gamma(x + 1)) == 1/gamma(x)
assert combsimp((x + 1)**2/gamma(x + 2)) == (x + 1)/gamma(x + 1)
assert combsimp(x*gamma(x) + gamma(x + 3)/(x + 2)) == \
(x + 2)*gamma(x + 1)
assert combsimp(gamma(2*x)*x) == gamma(2*x + 1)/2
assert combsimp(gamma(2*x)/(x - S(1)/2)) == 2*gamma(2*x - 1)
assert combsimp(gamma(x)*gamma(1 - x)) == pi/sin(pi*x)
assert combsimp(gamma(x)*gamma(-x)) == -pi/(x*sin(pi*x))
assert combsimp(1/gamma(x + 3)/gamma(1 - x)) == \
sin(pi*x)/(pi*x*(x + 1)*(x + 2))
assert powsimp(combsimp(
gamma(x)*gamma(x + S(1)/2)*gamma(y)/gamma(x + y))) == \
2**(-2*x + 1)*sqrt(pi)*gamma(2*x)*gamma(y)/gamma(x + y)
assert combsimp(1/gamma(x)/gamma(x - S(1)/3)/gamma(x + S(1)/3)) == \
3**(3*x - S(3)/2)/(2*pi*gamma(3*x - 1))
assert simplify(
gamma(S(1)/2 + x/2)*gamma(1 + x/2)/gamma(1 + x)/sqrt(pi)*2**x) == 1
assert combsimp(gamma(S(-1)/4)*gamma(S(-3)/4)) == 16*sqrt(2)*pi/3
assert powsimp(combsimp(gamma(2*x)/gamma(x))) == \
2**(2*x - 1)*gamma(x + S(1)/2)/sqrt(pi)
# issue 6792
e = (-gamma(k)*gamma(k + 2) + gamma(k + 1)**2)/gamma(k)**2
assert combsimp(e) == -k
assert combsimp(1/e) == -1/k
e = (gamma(x) + gamma(x + 1))/gamma(x)
assert combsimp(e) == x + 1
assert combsimp(1/e) == 1/(x + 1)
e = (gamma(x) + gamma(x + 2))*(gamma(x - 1) + gamma(x))/gamma(x)
assert combsimp(e) == (x**2 + x + 1)*gamma(x + 1)/(x - 1)
e = (-gamma(k)*gamma(k + 2) + gamma(k + 1)**2)/gamma(k)**2
assert combsimp(e**2) == k**2
assert combsimp(e**2/gamma(k + 1)) == k/gamma(k)
a = R(1, 2) + R(1, 3)
b = a + R(1, 3)
assert combsimp(gamma(2*k)/gamma(k)*gamma(k + a)*gamma(k + b))
3*2**(2*k + 1)*3**(-3*k - 2)*sqrt(pi)*gamma(3*k + R(3, 2))/2
A, B = symbols('A B', commutative=False)
assert combsimp(e*B*A) == combsimp(e)*B*A
# check iteration
assert combsimp(gamma(2*k)/gamma(k)*gamma(-k - R(1, 2))) == (
-2**(2*k + 1)*sqrt(pi)/(2*((2*k + 1)*cos(pi*k))))
assert combsimp(
gamma(k)*gamma(k + R(1, 3))*gamma(k + R(2, 3))/gamma(3*k/2)) == (
3*2**(3*k + 1)*3**(-3*k - S.Half)*sqrt(pi)*gamma(3*k/2 + S.Half)/2)
开发者ID:A-turing-machine,项目名称:sympy,代码行数:61,代码来源:test_combsimp.py
示例11: simplify_density_matrix
def simplify_density_matrix(density_matrix):
for row in xrange(4):
for col in xrange(4):
density_matrix[row, col] = subsitute(combsimp(density_matrix[row, col]))
return density_matrix
开发者ID:luviiit,项目名称:research,代码行数:5,代码来源:utils.py
示例12: test_combsimp
def test_combsimp():
k, m, n = symbols('k m n', integer = True)
assert combsimp(factorial(n)) == factorial(n)
assert combsimp(binomial(n, k)) == binomial(n, k)
assert combsimp(factorial(n)/factorial(n - 3)) == n*(-1 + n)*(-2 + n)
assert combsimp(binomial(n + 1, k + 1)/binomial(n, k)) == (1 + n)/(1 + k)
assert combsimp(binomial(3*n + 4, n + 1)/binomial(3*n + 1, n)) == \
S(3)/2*((3*n + 2)*(3*n + 4)/((n + 1)*(2*n + 3)))
assert combsimp(factorial(n)**2/factorial(n - 3)) == \
factorial(n)*n*(-1 + n)*(-2 + n)
assert combsimp(factorial(n)*binomial(n + 1, k + 1)/binomial(n, k)) == \
factorial(n + 1)/(1 + k)
assert combsimp(gamma(n + 3)) == factorial(n + 2)
assert combsimp(factorial(x)) == gamma(x + 1)
# issue 9699
assert combsimp((n + 1)*factorial(n)) == factorial(n + 1)
assert combsimp(factorial(n)/n) == factorial(n-1)
# issue 6658
assert combsimp(binomial(n, n - k)) == binomial(n, k)
# issue 6341, 7135
assert combsimp(factorial(n)/(factorial(k)*factorial(n - k))) == \
binomial(n, k)
assert combsimp(factorial(k)*factorial(n - k)/factorial(n)) == \
1/binomial(n, k)
assert combsimp(factorial(2*n)/factorial(n)**2) == binomial(2*n, n)
assert combsimp(factorial(2*n)*factorial(k)*factorial(n - k)/
factorial(n)**3) == binomial(2*n, n)/binomial(n, k)
assert combsimp(factorial(n*(1 + n) - n**2 - n)) == 1
assert combsimp(6*FallingFactorial(-4, n)/factorial(n)) == \
(-1)**n*(n + 1)*(n + 2)*(n + 3)
assert combsimp(6*FallingFactorial(-4, n - 1)/factorial(n - 1)) == \
(-1)**(n - 1)*n*(n + 1)*(n + 2)
assert combsimp(6*FallingFactorial(-4, n - 3)/factorial(n - 3)) == \
(-1)**(n - 3)*n*(n - 1)*(n - 2)
assert combsimp(6*FallingFactorial(-4, -n - 1)/factorial(-n - 1)) == \
-(-1)**(-n - 1)*n*(n - 1)*(n - 2)
assert combsimp(6*RisingFactorial(4, n)/factorial(n)) == \
(n + 1)*(n + 2)*(n + 3)
assert combsimp(6*RisingFactorial(4, n - 1)/factorial(n - 1)) == \
n*(n + 1)*(n + 2)
assert combsimp(6*RisingFactorial(4, n - 3)/factorial(n - 3)) == \
n*(n - 1)*(n - 2)
assert combsimp(6*RisingFactorial(4, -n - 1)/factorial(-n - 1)) == \
-n*(n - 1)*(n - 2)
开发者ID:baoqchau,项目名称:sympy,代码行数:56,代码来源:test_combsimp.py
示例13: mysimp
def mysimp(expr):
return powsimp(powdenest(expand(unpolarify(simplify(expand(combsimp(expand_func(expr.rewrite(besselj))))))), polar=True))
开发者ID:goodok,项目名称:sympy,代码行数:2,代码来源:test_transforms.py
示例14: test_F4
def test_F4():
assert combsimp((2**n * factorial(n) * product(2*k - 1, (k, 1, n)))) == factorial(2*n)
开发者ID:batya239,项目名称:sympy,代码行数:2,代码来源:test_wester.py
示例15: test_F3
def test_F3():
assert combsimp(2**n * factorial(n) * factorial2(2*n - 1)) == factorial(2*n)
开发者ID:batya239,项目名称:sympy,代码行数:2,代码来源:test_wester.py
示例16: test_probability
def test_probability():
# various integrals from probability theory
from sympy.abc import x, y, z
from sympy import symbols, Symbol, Abs, expand_mul, combsimp, powsimp
mu1, mu2 = symbols('mu1 mu2', real=True, finite=True, bounded=True)
sigma1, sigma2 = symbols('sigma1 sigma2', real=True, finite=True,
bounded=True, positive=True)
rate = Symbol('lambda', real=True, positive=True, bounded=True)
def normal(x, mu, sigma):
return 1/sqrt(2*pi*sigma**2)*exp(-(x-mu)**2/2/sigma**2)
def exponential(x, rate):
return rate*exp(-rate*x)
assert integrate(normal(x, mu1, sigma1), (x, -oo, oo), meijerg=True) == 1
assert integrate(x*normal(x, mu1, sigma1), (x, -oo, oo), meijerg=True) == mu1
assert integrate(x**2*normal(x, mu1, sigma1), (x, -oo, oo), meijerg=True) \
== mu1**2 + sigma1**2
assert integrate(x**3*normal(x, mu1, sigma1), (x, -oo, oo), meijerg=True) \
== mu1**3 + 3*mu1*sigma1**2
assert integrate(normal(x, mu1, sigma1)*normal(y, mu2, sigma2),
(x, -oo, oo), (y, -oo, oo), meijerg=True) == 1
assert integrate(x*normal(x, mu1, sigma1)*normal(y, mu2, sigma2),
(x, -oo, oo), (y, -oo, oo), meijerg=True) == mu1
assert integrate(y*normal(x, mu1, sigma1)*normal(y, mu2, sigma2),
(x, -oo, oo), (y, -oo, oo), meijerg=True) == mu2
assert integrate(x*y*normal(x, mu1, sigma1)*normal(y, mu2, sigma2),
(x, -oo, oo), (y, -oo, oo), meijerg=True) == mu1*mu2
assert integrate((x+y+1)*normal(x, mu1, sigma1)*normal(y, mu2, sigma2),
(x, -oo, oo), (y, -oo, oo), meijerg=True) == 1 + mu1 + mu2
assert integrate((x+y-1)*normal(x, mu1, sigma1)*normal(y, mu2, sigma2),
(x, -oo, oo), (y, -oo, oo), meijerg=True) == -1 + mu1 + mu2
i = integrate(x**2*normal(x, mu1, sigma1)*normal(y, mu2, sigma2),
(x, -oo, oo), (y, -oo, oo), meijerg=True)
assert not i.has(Abs)
assert simplify(i) == mu1**2 + sigma1**2
assert integrate(y**2*normal(x, mu1, sigma1)*normal(y, mu2, sigma2),
(x, -oo, oo), (y, -oo, oo), meijerg=True) == \
sigma2**2 + mu2**2
assert integrate(exponential(x, rate), (x, 0, oo), meijerg=True) == 1
assert integrate(x*exponential(x, rate), (x, 0, oo), meijerg=True) == 1/rate
assert integrate(x**2*exponential(x, rate), (x, 0, oo), meijerg=True) \
== 2/rate**2
def E(expr):
res1 = integrate(expr*exponential(x, rate)*normal(y, mu1, sigma1),
(x, 0, oo), (y, -oo, oo), meijerg=True)
res2 = integrate(expr*exponential(x, rate)*normal(y, mu1, sigma1),
(y, -oo, oo), (x, 0, oo), meijerg=True)
assert expand_mul(res1) == expand_mul(res2)
return res1
assert E(1) == 1
assert E(x*y) == mu1/rate
assert E(x*y**2) == mu1**2/rate + sigma1**2/rate
assert simplify(E((x+y+1)**2) - E(x+y+1)**2) == (rate**2*sigma1**2 + 1)/rate**2
assert simplify(E((x+y-1)**2) - E(x+y-1)**2) == (rate**2*sigma1**2 + 1)/rate**2
assert simplify(E((x+y)**2) - E(x+y)**2) == (rate**2*sigma1**2 + 1)/rate**2
# Beta' distribution
alpha, beta = symbols('alpha beta', positive=True)
betadist = x**(alpha-1)*(1+x)**(-alpha - beta)*gamma(alpha+beta) \
/gamma(alpha)/gamma(beta)
assert integrate(betadist, (x, 0, oo), meijerg=True) == 1
i = integrate(x*betadist, (x, 0, oo), meijerg=True, conds='separate')
assert (combsimp(i[0]), i[1]) == (alpha/(beta - 1), 1 < beta)
j = integrate(x**2*betadist, (x, 0, oo), meijerg=True, conds='separate')
assert j[1] == (1 < beta - 1)
assert combsimp(j[0] - i[0]**2) == (alpha + beta - 1)*alpha \
/(beta - 2)/(beta - 1)**2
# Chi distribution
k = Symbol('k', integer=True, positive=True)
chi = 2**(1-k/2)*x**(k-1)*exp(-x**2/2)/gamma(k/2)
assert powsimp(integrate(chi, (x, 0, oo), meijerg=True)) == 1
assert simplify(integrate(x*chi, (x, 0, oo), meijerg=True)) == \
sqrt(2)*gamma((k + 1)/2)/gamma(k/2)
assert simplify(integrate(x**2*chi, (x, 0, oo), meijerg=True)) == k
# Chi^2 distribution
chisquared = 2**(-k/2)/gamma(k/2)*x**(k/2-1)*exp(-x/2)
assert powsimp(integrate(chisquared, (x, 0, oo), meijerg=True)) == 1
assert simplify(integrate(x*chisquared, (x, 0, oo), meijerg=True)) == k
assert simplify(integrate(x**2*chisquared, (x, 0, oo), meijerg=True)) == \
k*(k + 2)
assert combsimp(integrate(((x-k)/sqrt(2*k))**3*chisquared, (x, 0, oo),
meijerg=True)) == 2*sqrt(2)/sqrt(k)
# Dagum distribution
a, b, p = symbols('a b p', positive=True)
# XXX (x/b)**a does not work
dagum = a*p/x*(x/b)**(a*p)/(1 + x**a/b**a)**(p+1)
assert simplify(integrate(dagum, (x, 0, oo), meijerg=True)) == 1
# XXX conditions are a mess
assert simplify(integrate(x*dagum, (x, 0, oo), meijerg=True, conds='none')) \
== b*gamma(1 - 1/a)*gamma(p + 1/a)/gamma(p)
assert simplify(integrate(x**2*dagum, (x, 0, oo), meijerg=True, conds='none')) \
== b**2*gamma(1 - 2/a)*gamma(p + 2/a)/gamma(p)
#.........这里部分代码省略.........
开发者ID:benglard,项目名称:sympy,代码行数:101,代码来源:test_meijerint.py
示例17: test_combsimp_gamma
def test_combsimp_gamma():
from sympy.abc import x, y
assert combsimp(gamma(x)) == gamma(x)
assert combsimp(gamma(x+1)/x) == gamma(x)
assert combsimp(gamma(x)/(x-1)) == gamma(x-1)
assert combsimp(x*gamma(x)) == gamma(x + 1)
assert combsimp((x+1)*gamma(x+1)) == gamma(x + 2)
assert combsimp(gamma(x+y)*(x+y)) == gamma(x + y + 1)
assert combsimp(x/gamma(x+1)) == 1/gamma(x)
assert combsimp((x+1)**2/gamma(x+2)) == (x + 1)/gamma(x + 1)
assert combsimp(x*gamma(x) + gamma(x+3)/(x+2)) == gamma(x+1) + gamma(x+2)
assert combsimp(gamma(2*x)*x) == gamma(2*x + 1)/2
assert combsimp(gamma(2*x)/(x - S(1)/2)) == 2*gamma(2*x - 1)
assert combsimp(gamma(x)*gamma(1-x)) == pi/sin(pi*x)
assert combsimp(gamma(x)*gamma(-x)) == -pi/(x*sin(pi*x))
assert combsimp(1/gamma(x+3)/gamma(1-x)) == sin(pi*x)/(pi*x*(x+1)*(x+2))
assert simplify(combsimp(gamma(x)*gamma(x+S(1)/2)*gamma(y)/gamma(x+y))) \
== 2**(-2*x + 1)*sqrt(pi)*gamma(2*x)*gamma(y)/gamma(x + y)
assert combsimp(1/gamma(x)/gamma(x-S(1)/3)/gamma(x+S(1)/3)) == \
3**(3*x + S(1)/2)/(18*pi*gamma(3*x - 1))
assert simplify(gamma(S(1)/2 + x/2)*gamma(1 + x/2)/gamma(1+x)/sqrt(pi)*2**x) \
== 1
assert combsimp(gamma(S(-1)/4)*gamma(S(-3)/4)) == 16*sqrt(2)*pi/3
assert simplify(combsimp(gamma(2*x)/gamma(x))) == \
2**(2*x - 1)*gamma(x + S(1)/2)/sqrt(pi)
开发者ID:ness01,项目名称:sympy,代码行数:29,代码来源:test_simplify.py
示例18: test_issue_14528
def test_issue_14528():
p = symbols("p", integer=True, positive=True)
assert combsimp(binomial(1,p)) == 1/(factorial(p)*factorial(1-p))
assert combsimp(factorial(2-p)) == factorial(2-p)
开发者ID:KonstantinTogoi,项目名称:sympy,代码行数:4,代码来源:test_combsimp.py
注:本文中的sympy.combsimp函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论