📜  Python| sympy.expand_pow_exp() 方法

📅  最后修改于: 2022-05-13 01:55:01.005000             🧑  作者: Mango

Python| sympy.expand_pow_exp() 方法

借助sympy.expand_pow_exp()方法,我们可以使用以下恒等式展开数学表达式——

x(a+b) = xa.xb

示例 #1:
在这个例子中,我们可以看到通过使用sympy.expand_pow_exp()方法,我们可以在幂方面展开数学表达式。

Python3
# import sympy
from sympy import *
 
x, a, b = symbols('x a b')
expr = x**(a + b)
 
print("Before Expansion : {}".format(expr))
   
# Use sympy.expand_pow_exp() method
smpl = expand_pow_exp(expr)
   
print("After Expansion : {}".format(smpl))


Python3
# import sympy
from sympy import *
 
x, a, b = symbols('x a b')
expr = x**(2 * a + 3 * b)
 
print("Before Expansion : {}".format(expr))
   
# Use sympy.expand_pow_exp() method
smpl = expand_pow_exp(expr)
   
print("After Expansion : {}".format(smpl))


输出:

Before Expansion : x**(a + b)
After Expansion : x**a*x**b

示例 #2:

Python3

# import sympy
from sympy import *
 
x, a, b = symbols('x a b')
expr = x**(2 * a + 3 * b)
 
print("Before Expansion : {}".format(expr))
   
# Use sympy.expand_pow_exp() method
smpl = expand_pow_exp(expr)
   
print("After Expansion : {}".format(smpl))

输出:

Before Expansion : x**(2*a + 3*b)
After Expansion : x**(2*a)*x**(3*b)