First time here? Check out the FAQ!

Ask Your Question
1

Why doesn't simplify() simplify symbolic equations?

asked 11 years ago

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?

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
4

answered 11 years ago

tmonteil gravatar image

updated 11 years ago

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
Preview: (hide)
link

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 ( 11 years ago )
4

answered 11 years ago

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.

Preview: (hide)
link

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: 11 years ago

Seen: 2,432 times

Last updated: Jan 21 '14