ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 29 Oct 2012 15:09:26 +0100comparing Expressions in pythonhttps://ask.sagemath.org/question/9394/comparing-expressions-in-python/Hi,
I have an Expression I want to compare:
> var('x,y')
> x+y == x+y
But this does not return `True`. Why?
Sun, 28 Oct 2012 17:12:00 +0100https://ask.sagemath.org/question/9394/comparing-expressions-in-python/Answer by DSM for <p>Hi,</p>
<p>I have an Expression I want to compare:</p>
<blockquote>
<pre><code>var('x,y')
x+y == x+y
</code></pre>
</blockquote>
<p>But this does not return <code>True</code>. Why?</p>
https://ask.sagemath.org/question/9394/comparing-expressions-in-python/?answer=14204#post-id-14204It works for me:
sage: var("x, y")
(x, y)
sage: x+y == x+y
x + y == x + y
sage: bool(x+y == x+y)
True
sage: if (x+y == x+y):
....: print 'yep!'
....:
yep!
Unless you mean that you want `bool` to be automatically applied to every equation? Since Sage follows the convention that "False" means "I couldn't see how to prove this was true", this would mean that pretty much every equation would automatically be False from the get-go and so you couldn't do anything with it. For example, `(x-2)*(x+3) == 0` would be False (`x` could be 9, after all).
Sun, 28 Oct 2012 20:20:43 +0100https://ask.sagemath.org/question/9394/comparing-expressions-in-python/?answer=14204#post-id-14204Comment by SLOtoSF for <p>It works for me:</p>
<pre><code>sage: var("x, y")
(x, y)
sage: x+y == x+y
x + y == x + y
sage: bool(x+y == x+y)
True
sage: if (x+y == x+y):
....: print 'yep!'
....:
yep!
</code></pre>
<p>Unless you mean that you want <code>bool</code> to be automatically applied to every equation? Since Sage follows the convention that "False" means "I couldn't see how to prove this was true", this would mean that pretty much every equation would automatically be False from the get-go and so you couldn't do anything with it. For example, <code>(x-2)*(x+3) == 0</code> would be False (<code>x</code> could be 9, after all). </p>
https://ask.sagemath.org/question/9394/comparing-expressions-in-python/?comment=18785#post-id-18785I see. Totally makes sense. Thanks.Mon, 29 Oct 2012 15:09:26 +0100https://ask.sagemath.org/question/9394/comparing-expressions-in-python/?comment=18785#post-id-18785Comment by SLOtoSF for <p>It works for me:</p>
<pre><code>sage: var("x, y")
(x, y)
sage: x+y == x+y
x + y == x + y
sage: bool(x+y == x+y)
True
sage: if (x+y == x+y):
....: print 'yep!'
....:
yep!
</code></pre>
<p>Unless you mean that you want <code>bool</code> to be automatically applied to every equation? Since Sage follows the convention that "False" means "I couldn't see how to prove this was true", this would mean that pretty much every equation would automatically be False from the get-go and so you couldn't do anything with it. For example, <code>(x-2)*(x+3) == 0</code> would be False (<code>x</code> could be 9, after all). </p>
https://ask.sagemath.org/question/9394/comparing-expressions-in-python/?comment=18790#post-id-18790Thanks! I didn't know about bool(). What is the advantage of not automatically applying it?Sun, 28 Oct 2012 22:52:23 +0100https://ask.sagemath.org/question/9394/comparing-expressions-in-python/?comment=18790#post-id-18790Comment by DSM for <p>It works for me:</p>
<pre><code>sage: var("x, y")
(x, y)
sage: x+y == x+y
x + y == x + y
sage: bool(x+y == x+y)
True
sage: if (x+y == x+y):
....: print 'yep!'
....:
yep!
</code></pre>
<p>Unless you mean that you want <code>bool</code> to be automatically applied to every equation? Since Sage follows the convention that "False" means "I couldn't see how to prove this was true", this would mean that pretty much every equation would automatically be False from the get-go and so you couldn't do anything with it. For example, <code>(x-2)*(x+3) == 0</code> would be False (<code>x</code> could be 9, after all). </p>
https://ask.sagemath.org/question/9394/comparing-expressions-in-python/?comment=18786#post-id-18786@SLotoSF: apparently I didn't explain well enough -- that's what my last paragraph was trying to explain. If you automatically applied it, you could never manipulate an equation because it'd be a bool instantly. No substitutions, no simplifications, nothing.Mon, 29 Oct 2012 15:01:22 +0100https://ask.sagemath.org/question/9394/comparing-expressions-in-python/?comment=18786#post-id-18786