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.Sat, 07 Oct 2017 11:19:26 +0200symbolic ring comparisons return strange resultshttps://ask.sagemath.org/question/39031/symbolic-ring-comparisons-return-strange-results/ Greetings,
bool(abs(-1+sqrt(2)) != abs(1-sqrt(2)))
erroneously returns True (I'm running SageMath-8.0 on a mac laptop, for what it's worth).
Is this a bug?
ThanksWed, 04 Oct 2017 16:34:08 +0200https://ask.sagemath.org/question/39031/symbolic-ring-comparisons-return-strange-results/Comment by mforets for <p>Greetings,</p>
<p>bool(abs(-1+sqrt(2)) != abs(1-sqrt(2)))</p>
<p>erroneously returns True (I'm running SageMath-8.0 on a mac laptop, for what it's worth).</p>
<p>Is this a bug?</p>
<p>Thanks</p>
https://ask.sagemath.org/question/39031/symbolic-ring-comparisons-return-strange-results/?comment=39041#post-id-39041it looks like a bug to me, and also why it does this:
sage: x = SR.var('x')
sage: bool(abs(1-x) == abs(x-1))
True
sage: bool(abs(1-x) != abs(x-1))
TrueFri, 06 Oct 2017 05:41:00 +0200https://ask.sagemath.org/question/39031/symbolic-ring-comparisons-return-strange-results/?comment=39041#post-id-39041Answer by dan_fulea for <p>Greetings,</p>
<p>bool(abs(-1+sqrt(2)) != abs(1-sqrt(2)))</p>
<p>erroneously returns True (I'm running SageMath-8.0 on a mac laptop, for what it's worth).</p>
<p>Is this a bug?</p>
<p>Thanks</p>
https://ask.sagemath.org/question/39031/symbolic-ring-comparisons-return-strange-results/?answer=39033#post-id-39033In order to establish if two expressions are equal, sage performs a "default wash machine program" and in case there is a **proof** for the `True` value, it returns this True. Else it returns False.
In such cases, one should help sage to find the truth.
In our case:
sage: expression = abs(-1+sqrt(2)) != abs(1-sqrt(2))
sage: bool(expression)
True
sage: bool(expression.simplify_full())
False
Just tell `sage` to perfom a simplification of the expression!
Note: One can find many "bugs" like the posted one, just try for instance:
sage: bool( abs(-1+sqrt(2)) != abs(1-sqrt(2)) )
True
sage: bool( abs(-1+sqrt(2)) == abs(1-sqrt(2)) )
True
Wed, 04 Oct 2017 19:54:07 +0200https://ask.sagemath.org/question/39031/symbolic-ring-comparisons-return-strange-results/?answer=39033#post-id-39033Comment by DrNick for <p>In order to establish if two expressions are equal, sage performs a "default wash machine program" and in case there is a <strong>proof</strong> for the <code>True</code> value, it returns this True. Else it returns False. </p>
<p>In such cases, one should help sage to find the truth.</p>
<p>In our case:</p>
<pre><code>sage: expression = abs(-1+sqrt(2)) != abs(1-sqrt(2))
sage: bool(expression)
True
sage: bool(expression.simplify_full())
False
</code></pre>
<p>Just tell <code>sage</code> to perfom a simplification of the expression!</p>
<p>Note: One can find many "bugs" like the posted one, just try for instance:</p>
<pre><code>sage: bool( abs(-1+sqrt(2)) != abs(1-sqrt(2)) )
True
sage: bool( abs(-1+sqrt(2)) == abs(1-sqrt(2)) )
True
</code></pre>
https://ask.sagemath.org/question/39031/symbolic-ring-comparisons-return-strange-results/?comment=39035#post-id-39035Yeah, I sort of understood the issue of returning False in case it can't really verify truth. But this is returning True when the statement is in fact False.Wed, 04 Oct 2017 22:29:16 +0200https://ask.sagemath.org/question/39031/symbolic-ring-comparisons-return-strange-results/?comment=39035#post-id-39035Comment by eric_g for <p>In order to establish if two expressions are equal, sage performs a "default wash machine program" and in case there is a <strong>proof</strong> for the <code>True</code> value, it returns this True. Else it returns False. </p>
<p>In such cases, one should help sage to find the truth.</p>
<p>In our case:</p>
<pre><code>sage: expression = abs(-1+sqrt(2)) != abs(1-sqrt(2))
sage: bool(expression)
True
sage: bool(expression.simplify_full())
False
</code></pre>
<p>Just tell <code>sage</code> to perfom a simplification of the expression!</p>
<p>Note: One can find many "bugs" like the posted one, just try for instance:</p>
<pre><code>sage: bool( abs(-1+sqrt(2)) != abs(1-sqrt(2)) )
True
sage: bool( abs(-1+sqrt(2)) == abs(1-sqrt(2)) )
True
</code></pre>
https://ask.sagemath.org/question/39031/symbolic-ring-comparisons-return-strange-results/?comment=39059#post-id-39059Most probably this is because `a != b` is first converted to `not (a == b)` before evaluation.Sat, 07 Oct 2017 11:19:26 +0200https://ask.sagemath.org/question/39031/symbolic-ring-comparisons-return-strange-results/?comment=39059#post-id-39059