ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 17 Nov 2014 09:20:34 -0600How to simplify with Sage?https://ask.sagemath.org/question/24866/how-to-simplify-with-sage/Does Sage have a function to simplify symbolic expressions in a similar way to how the other major CAS do it? I.e. use heuristics to try to come up with a form which is likely to seem simpler to humans, which is certainly subjective and cannot be done perfectly, but it's also certainly very useful.
`simplify` doesn't do this, and the documentation is a bit confusing: it says that `f = I + x - x; simplify(f)` gives `I`, but so does just printing `f`. So what's the point of `simplify`?
I'm sure there must be a function that does this, as I beieve Sage includes several good CAS, I just can't find it.
Some examples to try:
(sqrt(2) - 1)*(sqrt(2)+1)
1/(3*(1 + x)) - (2*x - 1)/(6*(x^2 - x + 1)) + 2/(3*(1 + ((2*x - 1)^2)/3))
(Second one taken from Mathematica documentation.)
I know I can play with `expand` and `factor` but is there a less manual way?Fri, 14 Nov 2014 14:00:32 -0600https://ask.sagemath.org/question/24866/how-to-simplify-with-sage/Answer by tmonteil for <p>Does Sage have a function to simplify symbolic expressions in a similar way to how the other major CAS do it? I.e. use heuristics to try to come up with a form which is likely to seem simpler to humans, which is certainly subjective and cannot be done perfectly, but it's also certainly very useful.</p>
<p><code>simplify</code> doesn't do this, and the documentation is a bit confusing: it says that <code>f = I + x - x; simplify(f)</code> gives <code>I</code>, but so does just printing <code>f</code>. So what's the point of <code>simplify</code>?</p>
<p>I'm sure there must be a function that does this, as I beieve Sage includes several good CAS, I just can't find it.</p>
<p>Some examples to try:</p>
<pre><code>(sqrt(2) - 1)*(sqrt(2)+1)
1/(3*(1 + x)) - (2*x - 1)/(6*(x^2 - x + 1)) + 2/(3*(1 + ((2*x - 1)^2)/3))
</code></pre>
<p>(Second one taken from Mathematica documentation.)</p>
<p>I know I can play with <code>expand</code> and <code>factor</code> but is there a less manual way?</p>
https://ask.sagemath.org/question/24866/how-to-simplify-with-sage/?answer=24875#post-id-24875To complement @ndomes answer, a good way to know what can be done with an object is to give it a name:
sage: a = (sqrt(2) - 1)*(sqrt(2)+1)
then, you can access all possible methods that available for this particular object by typing ``a.`` and then the ``TAB`` key:
sage: a.<TAB>
You will see a lot of things, in particular the ``.full_simplify()`` is pretty self explanatory:
sage: a.full_simplify()
1
This will also work for the the other expression:
sage: b = 1/(3*(1 + x)) - (2*x - 1)/(6*(x^2 - x + 1)) + 2/(3*(1 + ((2*x - 1)^2)/3))
sage: b.full_simplify()
1/(x^3 + 1)
Sat, 15 Nov 2014 09:19:31 -0600https://ask.sagemath.org/question/24866/how-to-simplify-with-sage/?answer=24875#post-id-24875Answer by kcrisman for <p>Does Sage have a function to simplify symbolic expressions in a similar way to how the other major CAS do it? I.e. use heuristics to try to come up with a form which is likely to seem simpler to humans, which is certainly subjective and cannot be done perfectly, but it's also certainly very useful.</p>
<p><code>simplify</code> doesn't do this, and the documentation is a bit confusing: it says that <code>f = I + x - x; simplify(f)</code> gives <code>I</code>, but so does just printing <code>f</code>. So what's the point of <code>simplify</code>?</p>
<p>I'm sure there must be a function that does this, as I beieve Sage includes several good CAS, I just can't find it.</p>
<p>Some examples to try:</p>
<pre><code>(sqrt(2) - 1)*(sqrt(2)+1)
1/(3*(1 + x)) - (2*x - 1)/(6*(x^2 - x + 1)) + 2/(3*(1 + ((2*x - 1)^2)/3))
</code></pre>
<p>(Second one taken from Mathematica documentation.)</p>
<p>I know I can play with <code>expand</code> and <code>factor</code> but is there a less manual way?</p>
https://ask.sagemath.org/question/24866/how-to-simplify-with-sage/?answer=24893#post-id-24893Two useful resources are http://www.sagemath.org/doc/reference/calculus/sage/symbolic/expression.html and http://sagemath.org/doc/prep/Symbolics-and-Basic-Plotting.html#symbolic-expressionsMon, 17 Nov 2014 09:20:34 -0600https://ask.sagemath.org/question/24866/how-to-simplify-with-sage/?answer=24893#post-id-24893Answer by ndomes for <p>Does Sage have a function to simplify symbolic expressions in a similar way to how the other major CAS do it? I.e. use heuristics to try to come up with a form which is likely to seem simpler to humans, which is certainly subjective and cannot be done perfectly, but it's also certainly very useful.</p>
<p><code>simplify</code> doesn't do this, and the documentation is a bit confusing: it says that <code>f = I + x - x; simplify(f)</code> gives <code>I</code>, but so does just printing <code>f</code>. So what's the point of <code>simplify</code>?</p>
<p>I'm sure there must be a function that does this, as I beieve Sage includes several good CAS, I just can't find it.</p>
<p>Some examples to try:</p>
<pre><code>(sqrt(2) - 1)*(sqrt(2)+1)
1/(3*(1 + x)) - (2*x - 1)/(6*(x^2 - x + 1)) + 2/(3*(1 + ((2*x - 1)^2)/3))
</code></pre>
<p>(Second one taken from Mathematica documentation.)</p>
<p>I know I can play with <code>expand</code> and <code>factor</code> but is there a less manual way?</p>
https://ask.sagemath.org/question/24866/how-to-simplify-with-sage/?answer=24868#post-id-24868
sage: a = (sqrt(2) - 1)*(sqrt(2)+1)
sage: a.simplify_full()
1Fri, 14 Nov 2014 16:01:37 -0600https://ask.sagemath.org/question/24866/how-to-simplify-with-sage/?answer=24868#post-id-24868