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.Tue, 19 Apr 2011 04:07:12 -0500simply_full for expressions with exponentshttps://ask.sagemath.org/question/8083/simply_full-for-expressions-with-exponents/Hello,
I am new to sage and I am trying to simplify some expression.
If I try:
var('a');
h = 2^(a - 2) * 3^(a + 3) / 6^a;
h.simplify_full();
I get 27 / 4 which is right. However if I try
var('a');
h = (2^(a - 2) * 3^(a + 3) / 6^a == 27 / 4);
h.simplify_full();
I get (27/4) == (27/4). I don't understand why I do not get
the answer True in this case.
Tue, 19 Apr 2011 02:06:09 -0500https://ask.sagemath.org/question/8083/simply_full-for-expressions-with-exponents/Answer by DSM for <p>Hello,</p>
<p>I am new to sage and I am trying to simplify some expression.
If I try:</p>
<p>var('a');
h = 2^(a - 2) * 3^(a + 3) / 6^a;
h.simplify_full();</p>
<p>I get 27 / 4 which is right. However if I try</p>
<p>var('a');
h = (2^(a - 2) * 3^(a + 3) / 6^a == 27 / 4);
h.simplify_full();</p>
<p>I get (27/4) == (27/4). I don't understand why I do not get
the answer True in this case.</p>
https://ask.sagemath.org/question/8083/simply_full-for-expressions-with-exponents/?answer=12290#post-id-12290This is because of the way the Sage type system works. When you ask Sage to simplify an equation, it tries to do just that: it tries to find a simpler expression. It doesn't change an equation into a boolean truth value. In this case, the fact you're using the symbol "h" for both a (non-relational) expression and a relation is confusing things a bit, I think.
You have the variable a, which is an Expression:
sage: a = var("a")
sage: type(a)
<type 'sage.symbolic.expression.Expression'>
h, which is also an Expression:
sage: h = 2^(a - 2) * 3^(a + 3) / 6^a
sage: type(h)
<type 'sage.symbolic.expression.Expression'>
but isn't an equation or inequality:
sage: h.is_relational()
False
and which simplifies as you note.
sage: h.simplify_full()
27/4
Now we write the equation:
sage: eq = h == 27/4
sage: type(eq)
<type 'sage.symbolic.expression.Expression'>
This is also an Expression, but now it's a little different:
sage: eq.is_relational()
True
If you want to find out if the equation is true, you convert the equation to a boolean value:
sage: bool(eq)
True
In this case you don't even need to simplify it. Does that make sense? Expressions can get simplified, but in general they don't simplify to truth values. You have to ask for that explicitly if that's what you want.
**Warning: bool(eq) doesn't mean what you think it might!**
Sage inherits the convention that while bool(eq)==True means that the expression is true (subject to whatever assumptions are in effect), **bool(eq) == False doesn't mean the expression is (necessarily) false!** It only means it couldn't figure out how to prove it.
Tue, 19 Apr 2011 03:44:01 -0500https://ask.sagemath.org/question/8083/simply_full-for-expressions-with-exponents/?answer=12290#post-id-12290Comment by viorel preoteasa for <p>This is because of the way the Sage type system works. When you ask Sage to simplify an equation, it tries to do just that: it tries to find a simpler expression. It doesn't change an equation into a boolean truth value. In this case, the fact you're using the symbol "h" for both a (non-relational) expression and a relation is confusing things a bit, I think.</p>
<p>You have the variable a, which is an Expression:</p>
<pre><code>sage: a = var("a")
sage: type(a)
<type 'sage.symbolic.expression.Expression'>
</code></pre>
<p>h, which is also an Expression:</p>
<pre><code>sage: h = 2^(a - 2) * 3^(a + 3) / 6^a
sage: type(h)
<type 'sage.symbolic.expression.Expression'>
</code></pre>
<p>but isn't an equation or inequality:</p>
<pre><code>sage: h.is_relational()
False
</code></pre>
<p>and which simplifies as you note.</p>
<pre><code>sage: h.simplify_full()
27/4
</code></pre>
<p>Now we write the equation:</p>
<pre><code>sage: eq = h == 27/4
sage: type(eq)
<type 'sage.symbolic.expression.Expression'>
</code></pre>
<p>This is also an Expression, but now it's a little different:</p>
<pre><code>sage: eq.is_relational()
True
</code></pre>
<p>If you want to find out if the equation is true, you convert the equation to a boolean value:</p>
<pre><code>sage: bool(eq)
True
</code></pre>
<p>In this case you don't even need to simplify it. Does that make sense? Expressions can get simplified, but in general they don't simplify to truth values. You have to ask for that explicitly if that's what you want.</p>
<p><strong>Warning: bool(eq) doesn't mean what you think it might!</strong></p>
<p>Sage inherits the convention that while bool(eq)==True means that the expression is true (subject to whatever assumptions are in effect), <strong>bool(eq) == False doesn't mean the expression is (necessarily) false!</strong> It only means it couldn't figure out how to prove it.</p>
https://ask.sagemath.org/question/8083/simply_full-for-expressions-with-exponents/?comment=21823#post-id-21823Here it is another example: ((2^(a - 2) * 3^(a + 3) / 6^a == 27 / 4) and a == a).simplify_full() this is simplified to a == a. Why here not 27/4 == 27 / 4 and a == a? The expression (a == a and (2^(a - 2) * 3^(a + 3) / 6^a == 27 / 4)).simplify_full() returns 27/4 == 27/4. Why terms in a conjunction are simplified away if they are true, except the last term?Tue, 19 Apr 2011 04:07:12 -0500https://ask.sagemath.org/question/8083/simply_full-for-expressions-with-exponents/?comment=21823#post-id-21823Comment by viorel preoteasa for <p>This is because of the way the Sage type system works. When you ask Sage to simplify an equation, it tries to do just that: it tries to find a simpler expression. It doesn't change an equation into a boolean truth value. In this case, the fact you're using the symbol "h" for both a (non-relational) expression and a relation is confusing things a bit, I think.</p>
<p>You have the variable a, which is an Expression:</p>
<pre><code>sage: a = var("a")
sage: type(a)
<type 'sage.symbolic.expression.Expression'>
</code></pre>
<p>h, which is also an Expression:</p>
<pre><code>sage: h = 2^(a - 2) * 3^(a + 3) / 6^a
sage: type(h)
<type 'sage.symbolic.expression.Expression'>
</code></pre>
<p>but isn't an equation or inequality:</p>
<pre><code>sage: h.is_relational()
False
</code></pre>
<p>and which simplifies as you note.</p>
<pre><code>sage: h.simplify_full()
27/4
</code></pre>
<p>Now we write the equation:</p>
<pre><code>sage: eq = h == 27/4
sage: type(eq)
<type 'sage.symbolic.expression.Expression'>
</code></pre>
<p>This is also an Expression, but now it's a little different:</p>
<pre><code>sage: eq.is_relational()
True
</code></pre>
<p>If you want to find out if the equation is true, you convert the equation to a boolean value:</p>
<pre><code>sage: bool(eq)
True
</code></pre>
<p>In this case you don't even need to simplify it. Does that make sense? Expressions can get simplified, but in general they don't simplify to truth values. You have to ask for that explicitly if that's what you want.</p>
<p><strong>Warning: bool(eq) doesn't mean what you think it might!</strong></p>
<p>Sage inherits the convention that while bool(eq)==True means that the expression is true (subject to whatever assumptions are in effect), <strong>bool(eq) == False doesn't mean the expression is (necessarily) false!</strong> It only means it couldn't figure out how to prove it.</p>
https://ask.sagemath.org/question/8083/simply_full-for-expressions-with-exponents/?comment=21824#post-id-21824Thank you for your answer. It was certainly useful. I have expected that my second expression, which is an equation (var('a'); h = (2^(a - 2) * 3^(a + 3) / 6^a == 27 / 4)) to be simplified directly to true. But I can use bool(h.simplify_full()) to check if the relation is true. However it still feels strange because if you just type the expression 27/4 == 27/4 then the system returns true and h.simplify_full() is just 27/4 == 27/4. The problem seems more acute when something is not necessarily true. If you test bool(a == b) for a, b variables you get false and not a == b as you would get when using simplification. On the other hand you would not be able to simplify an expression h as before to true, just using simplify_full.Tue, 19 Apr 2011 04:00:28 -0500https://ask.sagemath.org/question/8083/simply_full-for-expressions-with-exponents/?comment=21824#post-id-21824