# Why doesn't simplify() simplify symbolic equations?

Consider the following sage code:

a,b,c = var('a b c')

simplify(a + b == a + c)


I would expect the result of this code to be b == c, but sage gives me a + b == a + c. The only way to actually simplify the equation is to use add_to_both_sides(-a). For more complicated equations this seems to be hardly applicable. Why doesn't simplify() (or full_simplify()) take care of this properly?

edit retag close merge delete

Sort by » oldest newest most voted

I think the analysis of @kcrisman is the right one (i.e. full_simplify() works on each side of the equality). Along those lines, it is possible to transform the equation back to an equation as follows:

sage: eq_simplify = lambda eq : ((eq.rhs() - eq.lhs()).full_simplify() == 0)
sage: eq_simplify(a + b == a + c)
-b + c == 0

sage: simplify(cos(a)^2 == b - sin(a)^2)
cos(a)^2 == -sin(a)^2 + b
sage: eq_simplify(cos(a)^2 == b - sin(a)^2)
b - 1 == 0


Or, if we do not want to deal with equalities separately:

sage: new_simplify = lambda expr : ((expr.rhs() - expr.lhs()).full_simplify() == 0) if expr.operator() == operator.eq else expr.full_simplify()
sage: new_simplify(cos(a)^2 == b - sin(a)^2)
b - 1 == 0
sage: new_simplify(cos(a)^2 + sin(a)^2)
1

more

I very much like your approach. I noticed the problem when I wanted to simplify an inequality though... In this case you would have to know the kind of relation as well...

( 2014-01-21 21:36:13 -0500 )edit

simplify is a very weak thing - it only sends things to Maxima and back. full_simplify does indeed do some reasonable powerful things, of course. As far as I know, these both would just "simplify" each side separately.

To "simplify" automatically along the lines you are suggesting might be quite hard in general. If there is only one term in common among fifty on each side of the equation, and we asked Sage (or anything else) to look for that in every symbolic equation that was simplified in the "do each side" sense, one might see massive inefficiency. If there even was something to find, like how deciding whether an expression is zero is a quite hard problem.

One way to get around this is

var('a,b,c')
Eq = a+b == a+c
(Eq.lhs() - Eq.rhs()).simplify()


though of course this gives b-c which isn't exactly what you're looking for.

more