Python| sympy.powsimp() 方法
在sympy.powsimp()方法的帮助下,我们可以使用涉及幂的索引定律来简化数学表达式。
特性 :
1) x**a**x**b = x**(a+b)
2) x**a*y**a = (xy)**a
Syntax: powsimp(expression)
Parameters:
expression – It is the mathematical expression which needs to be simplified.
Returns: Returns a simplified mathematical expression corresponding to the input expression.
示例 #1:
在这个例子中,我们可以看到通过使用sympy.powsimp()方法,我们可以使用涉及幂的索引定律来简化任何数学表达式。
# import sympy
from sympy import *
x, a, b = symbols('x a b')
expr = x**a * x**b
print("Before Simplification : {}".format(expr))
# Use sympy.powsimp() method
smpl = powsimp(expr)
print("After Simplification : {}".format(smpl))
输出:
Before Simplification : x**a*x**b
After Simplification : x**(a + b)
示例 #2:
# import sympy
from sympy import *
x, a, b = symbols('x a b')
expr = ((x**(2 * a + b))*(x**(-a + b)))
print("Before Simplification : {}".format(expr))
# Use sympy.powsimp() method
smpl = powsimp(expr)
print("After Simplification : {}".format(smpl))
输出:
Before Simplification : x**(-a + b)*x**(2*a + b)
After Simplification : x**(a + 2*b)