How to merge 2 or more expressions
example: 3x + 2y – 2 and 2x + 3y -1 (3x + 2y -2 = 2x + 3y -1)
which gives x-y-1
>Solution :
from sympy import *
# declare symbols
var("x, y")
# write the two expressions
expr1 = 3*x + 2*y - 2
expr2 = 2*x + 3*y - 1
# subtract them
result = expr1 - expr2
result
# out: x - y - 1
EDIT: Alternatively, we can also create an Equality object and later rewrite it as an addition:
eqaulity = Eq(expr1, expr2)
# out: 3*x + 2*y - 2 = 2*x + 3*y - 1
eqaulity.rewrite(Add)
# out: x - y - 1