Ask Your Question
1

Why doesn't simplify() simplify symbolic equations?

asked 2014-01-21 11:44:09 +0100

Mathmon gravatar image

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 flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
4

answered 2014-01-21 14:23:33 +0100

tmonteil gravatar image

updated 2014-01-21 14:29:27 +0100

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
edit flag offensive delete link more

Comments

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...

Mathmon gravatar imageMathmon ( 2014-01-22 04:36:13 +0100 )edit
4

answered 2014-01-21 13:14:13 +0100

kcrisman gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2014-01-21 11:44:09 +0100

Seen: 2,285 times

Last updated: Jan 21 '14