With the help of sympy.simplify() method, we can simplify any mathematical expression.
Syntax: simplify(expression)
Parameters:
expression – It is the mathematical expression which needs to be simplified.Returns: Returns a simplified mathematical expression corresponding to the input expression.
Example #1: In this example we can see that by using sympy.simplify() method, we can simplify any mathematical expression.
Python3
# import sympy from sympy import * x = symbols( 'x' ) expr = sin(x) * * 2 + cos(x) * * 2 print ("Before Simplification : {}". format (expr)) # Use sympy.simplify() method smpl = simplify(expr) print ("After Simplification : {}". format (smpl)) |
Output:
Before Simplification : sin(x)**2 + cos(x)**2 After Simplification: 1
Example #2:
Python3
# import sympy from sympy import * x = symbols( 'x' ) expr = (x * * 3 + x * * 2 - x - 1 ) / (x * * 2 + 2 * x + 1 ) print ("Before Simplification : {}". format (expr)) # Use sympy.simplify() method smpl = simplify(expr) print ("After Simplification : {}". format (smpl)) |
Output:
Before Simplification : (x**3 + x**2 - x - 1)/(x**2 + 2*x + 1) After Simplification : After Simplification : x - 1