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.Sun, 29 Jan 2012 09:49:47 -0600Sage is refusing to simplify an element of the symbolic ring to an integerhttp://ask.sagemath.org/question/8551/sage-is-refusing-to-simplify-an-element-of-the-symbolic-ring-to-an-integer/For example: How can I get sage to simplify ( sqrt(2) + sqrt(3) ) * ( sqrt(2) - sqrt(3) ) to -1? I've tried simplify() but it wont do it. Thanks.Sun, 29 Jan 2012 09:03:06 -0600http://ask.sagemath.org/question/8551/sage-is-refusing-to-simplify-an-element-of-the-symbolic-ring-to-an-integer/Answer by DSM for <p>For example: How can I get sage to simplify ( sqrt(2) + sqrt(3) ) * ( sqrt(2) - sqrt(3) ) to -1? I've tried simplify() but it wont do it. Thanks.</p>
http://ask.sagemath.org/question/8551/sage-is-refusing-to-simplify-an-element-of-the-symbolic-ring-to-an-integer/?answer=13211#post-id-13211Not every method -- i.e. a function which lives inside an object -- has a function form. What I mean is that sometimes you can write sqrt(2), because sqrt is a function, but you could also write 2.sqrt(), but not everything is exactly the same.
This holds for simplify too. There *is* a simplify function, but you can get much tighter control by calling the simplify *methods*. You can usually look inside an object by hitting TAB. For example:
sage: q = ( sqrt(2) + sqrt(3) ) * ( sqrt(2) - sqrt(3) )
sage: q.[HERE I HIT TAB]
q.N q.exp_simplify q.leading_coeff q.reduce_trig
q.Order q.expand q.leading_coefficient q.rename
q.abs q.expand_log q.left q.reset_name
q.add q.expand_rational q.left_hand_side q.rhs
q.add_to_both_sides q.expand_trig q.lgamma q.right
q.additive_order q.factor q.lhs q.right_hand_side
[etc..]
In sage, lots of functionality lives objects like this. If you type
Sun, 29 Jan 2012 09:09:57 -0600http://ask.sagemath.org/question/8551/sage-is-refusing-to-simplify-an-element-of-the-symbolic-ring-to-an-integer/?answer=13211#post-id-13211Answer by DSM for <p>For example: How can I get sage to simplify ( sqrt(2) + sqrt(3) ) * ( sqrt(2) - sqrt(3) ) to -1? I've tried simplify() but it wont do it. Thanks.</p>
http://ask.sagemath.org/question/8551/sage-is-refusing-to-simplify-an-element-of-the-symbolic-ring-to-an-integer/?answer=13212#post-id-13212Not every method -- i.e. a function which lives inside an object -- has a function form. What I mean is that you can write sqrt(2), because sqrt is a function, and you could also write 2.sqrt(), but not everything is paired up like that.
This holds for simplify too. There *is* a simplify function, but you can get much tighter control by calling the simplify *methods*. You can usually look inside an object by hitting TAB. For example:
sage: q = ( sqrt(2) + sqrt(3) ) * ( sqrt(2) - sqrt(3) )
sage: q.[HERE I HIT TAB]
q.N q.exp_simplify q.leading_coeff q.reduce_trig
q.Order q.expand q.leading_coefficient q.rename
q.abs q.expand_log q.left q.reset_name
q.add q.expand_rational q.left_hand_side q.rhs
q.add_to_both_sides q.expand_trig q.lgamma q.right
q.additive_order q.factor q.lhs q.right_hand_side
[etc..]
In sage, lots of functionality lives inside objects like this. If you type
sage: q.simp[TAB]
q.simplify q.simplify_factorial q.simplify_log q.simplify_rational
q.simplify_exp q.simplify_full q.simplify_radical q.simplify_trig
you'll see a bunch of possibilities. If you type
sage: q.simplify_radical?
you can see the docs for it (and two ?? show the code.)
All of that is a long-winded way to bring us here:
sage: q = ( sqrt(2) + sqrt(3) ) * ( sqrt(2) - sqrt(3) )
sage: q.simplify_radical()
-1
sage: q.simplify_full()
-1
Sun, 29 Jan 2012 09:11:44 -0600http://ask.sagemath.org/question/8551/sage-is-refusing-to-simplify-an-element-of-the-symbolic-ring-to-an-integer/?answer=13212#post-id-13212Comment by Zaubertrank for <p>Not every method -- i.e. a function which lives inside an object -- has a function form. What I mean is that you can write sqrt(2), because sqrt is a function, and you could also write 2.sqrt(), but not everything is paired up like that.</p>
<p>This holds for simplify too. There <em>is</em> a simplify function, but you can get much tighter control by calling the simplify <em>methods</em>. You can usually look inside an object by hitting TAB. For example:</p>
<pre><code>sage: q = ( sqrt(2) + sqrt(3) ) * ( sqrt(2) - sqrt(3) )
sage: q.[HERE I HIT TAB]
q.N q.exp_simplify q.leading_coeff q.reduce_trig
q.Order q.expand q.leading_coefficient q.rename
q.abs q.expand_log q.left q.reset_name
q.add q.expand_rational q.left_hand_side q.rhs
q.add_to_both_sides q.expand_trig q.lgamma q.right
q.additive_order q.factor q.lhs q.right_hand_side
[etc..]
</code></pre>
<p>In sage, lots of functionality lives inside objects like this. If you type</p>
<pre><code>sage: q.simp[TAB]
q.simplify q.simplify_factorial q.simplify_log q.simplify_rational
q.simplify_exp q.simplify_full q.simplify_radical q.simplify_trig
</code></pre>
<p>you'll see a bunch of possibilities. If you type</p>
<pre><code>sage: q.simplify_radical?
</code></pre>
<p>you can see the docs for it (and two ?? show the code.)</p>
<p>All of that is a long-winded way to bring us here:</p>
<pre><code>sage: q = ( sqrt(2) + sqrt(3) ) * ( sqrt(2) - sqrt(3) )
sage: q.simplify_radical()
-1
sage: q.simplify_full()
-1
</code></pre>
http://ask.sagemath.org/question/8551/sage-is-refusing-to-simplify-an-element-of-the-symbolic-ring-to-an-integer/?comment=20391#post-id-20391oh man great answer, I didn't even know about all that functionality, thanks.Sun, 29 Jan 2012 09:49:47 -0600http://ask.sagemath.org/question/8551/sage-is-refusing-to-simplify-an-element-of-the-symbolic-ring-to-an-integer/?comment=20391#post-id-20391