ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 21 Jan 2014 21:36:13 -0600Why doesn't simplify() simplify symbolic equations?http://ask.sagemath.org/question/10950/why-doesnt-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?Tue, 21 Jan 2014 04:44:09 -0600http://ask.sagemath.org/question/10950/why-doesnt-simplify-simplify-symbolic-equations/Answer by tmonteil for <p>Consider the following sage code:</p>
<pre><code>a,b,c = var('a b c')
simplify(a + b == a + c)
</code></pre>
<p>I would expect the result of this code to be <code>b == c</code>, but sage gives me <code>a + b == a + c</code>. The only way to actually simplify the equation is to use <code>add_to_both_sides(-a)</code>. For more complicated equations this seems to be hardly applicable. Why doesn't <code>simplify()</code> (or <code>full_simplify()</code>) take care of this properly?</p>
http://ask.sagemath.org/question/10950/why-doesnt-simplify-simplify-symbolic-equations/?answer=15951#post-id-15951I 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
Tue, 21 Jan 2014 07:23:33 -0600http://ask.sagemath.org/question/10950/why-doesnt-simplify-simplify-symbolic-equations/?answer=15951#post-id-15951Comment by Mathmon for <p>I think the analysis of <a href="/users/41/kcrisman/">@kcrisman</a> is the right one (i.e. <code>full_simplify()</code> works on each side of the equality). Along those lines, it is possible to transform the equation back to an equation as follows:</p>
<pre><code>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
</code></pre>
<p>Or, if we do not want to deal with equalities separately:</p>
<pre><code>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
</code></pre>
http://ask.sagemath.org/question/10950/why-doesnt-simplify-simplify-symbolic-equations/?comment=16407#post-id-16407I 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...Tue, 21 Jan 2014 21:36:13 -0600http://ask.sagemath.org/question/10950/why-doesnt-simplify-simplify-symbolic-equations/?comment=16407#post-id-16407Answer by kcrisman for <p>Consider the following sage code:</p>
<pre><code>a,b,c = var('a b c')
simplify(a + b == a + c)
</code></pre>
<p>I would expect the result of this code to be <code>b == c</code>, but sage gives me <code>a + b == a + c</code>. The only way to actually simplify the equation is to use <code>add_to_both_sides(-a)</code>. For more complicated equations this seems to be hardly applicable. Why doesn't <code>simplify()</code> (or <code>full_simplify()</code>) take care of this properly?</p>
http://ask.sagemath.org/question/10950/why-doesnt-simplify-simplify-symbolic-equations/?answer=15950#post-id-15950`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.Tue, 21 Jan 2014 06:14:13 -0600http://ask.sagemath.org/question/10950/why-doesnt-simplify-simplify-symbolic-equations/?answer=15950#post-id-15950