本文整理汇总了Python中sympy.holonomic.HolonomicFunction.to_expr方法的典型用法代码示例。如果您正苦于以下问题:Python HolonomicFunction.to_expr方法的具体用法?Python HolonomicFunction.to_expr怎么用?Python HolonomicFunction.to_expr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sympy.holonomic.HolonomicFunction
的用法示例。
在下文中一共展示了HolonomicFunction.to_expr方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_to_expr
# 需要导入模块: from sympy.holonomic import HolonomicFunction [as 别名]
# 或者: from sympy.holonomic.HolonomicFunction import to_expr [as 别名]
def test_to_expr():
x = symbols('x')
R, Dx = DifferentialOperators(ZZ.old_poly_ring(x), 'Dx')
p = HolonomicFunction(Dx - 1, x, 0, [1]).to_expr()
q = exp(x)
assert p == q
p = HolonomicFunction(Dx**2 + 1, x, 0, [1, 0]).to_expr()
q = cos(x)
assert p == q
p = HolonomicFunction(Dx**2 - 1, x, 0, [1, 0]).to_expr()
q = cosh(x)
assert p == q
p = HolonomicFunction(2 + (4*x - 1)*Dx + \
(x**2 - x)*Dx**2, x, 0, [1, 2]).to_expr().expand()
q = 1/(x**2 - 2*x + 1)
assert p == q
p = expr_to_holonomic(sin(x)**2/x).integrate((x, 0, x)).to_expr()
q = (sin(x)**2/x).integrate((x, 0, x))
assert p == q
C_0, C_1, C_2, C_3 = symbols('C_0, C_1, C_2, C_3')
p = expr_to_holonomic(log(1+x**2)).to_expr()
q = C_2*log(x**2 + 1)
assert p == q
p = expr_to_holonomic(log(1+x**2)).diff().to_expr()
q = C_0*x/(x**2 + 1)
assert p == q
p = expr_to_holonomic(erf(x) + x).to_expr()
q = 3*C_3*x - 3*sqrt(pi)*C_3*erf(x)/2 + x + 2*x/sqrt(pi)
assert p == q
p = expr_to_holonomic(sqrt(x), x0=1).to_expr()
assert p == sqrt(x)
assert expr_to_holonomic(sqrt(x)).to_expr() == sqrt(x)
p = expr_to_holonomic(sqrt(1 + x**2)).to_expr()
assert p == sqrt(1+x**2)
p = expr_to_holonomic((2*x**2 + 1)**(S(2)/3)).to_expr()
assert p == (2*x**2 + 1)**(S(2)/3)
p = expr_to_holonomic(sqrt(-x**2+2*x)).to_expr()
assert p == sqrt(x)*sqrt(-x + 2)
p = expr_to_holonomic((-2*x**3+7*x)**(S(2)/3)).to_expr()
q = x**(S(2)/3)*(-2*x**2 + 7)**(S(2)/3)
assert p == q
p = from_hyper(hyper((-2, -3), (S(1)/2, ), x))
s = hyperexpand(hyper((-2, -3), (S(1)/2, ), x))
D_0 = Symbol('D_0')
C_0 = Symbol('C_0')
assert (p.to_expr().subs({C_0:1, D_0:0}) - s).simplify() == 0
p.y0 = {0: [1], S(1)/2: [0]}
assert p.to_expr() == s
assert expr_to_holonomic(x**5).to_expr() == x**5
assert expr_to_holonomic(2*x**3-3*x**2).to_expr().expand() == \
2*x**3-3*x**2
a = symbols("a")
p = (expr_to_holonomic(1.4*x)*expr_to_holonomic(a*x, x)).to_expr()
q = 1.4*a*x**2
assert p == q
p = (expr_to_holonomic(1.4*x)+expr_to_holonomic(a*x, x)).to_expr()
q = x*(a + 1.4)
assert p == q
p = (expr_to_holonomic(1.4*x)+expr_to_holonomic(x)).to_expr()
assert p == 2.4*x
示例2: test_diff
# 需要导入模块: from sympy.holonomic import HolonomicFunction [as 别名]
# 或者: from sympy.holonomic.HolonomicFunction import to_expr [as 别名]
def test_diff():
x, y = symbols('x, y')
R, Dx = DifferentialOperators(ZZ.old_poly_ring(x), 'Dx')
p = HolonomicFunction(x*Dx**2 + 1, x, 0, [0, 1])
assert p.diff().to_expr() == p.to_expr().diff().simplify()
p = HolonomicFunction(Dx**2 - 1, x, 0, [1, 0])
assert p.diff(x, 2).to_expr() == p.to_expr()
p = expr_to_holonomic(Si(x))
assert p.diff().to_expr() == sin(x)/x
assert p.diff(y) == 0
C_0, C_1, C_2, C_3 = symbols('C_0, C_1, C_2, C_3')
q = Si(x)
assert p.diff(x).to_expr() == q.diff()
assert p.diff(x, 2).to_expr().subs(C_0, -S(1)/3) == q.diff(x, 2).simplify()
assert p.diff(x, 3).series().subs({C_3:-S(1)/3, C_0:0}) == q.diff(x, 3).series()