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
from sympy import *
x = symbols('x')
expr = sin(x)**2 + cos(x)**2
print("Before Simplification : {}".format(expr))
smpl = simplify(expr)
print("After Simplification : {}".format(smpl))
|
Output:
Before Simplification : sin(x)**2 + cos(x)**2
After Simplification: 1
Example #2:
Python3
from sympy import *
x = symbols('x')
expr = (x**3 + x**2 - x - 1)/(x**2 + 2 * x + 1)
print("Before Simplification : {}".format(expr))
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
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!