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.Sat, 21 Dec 2019 04:37:23 -0600Evaluation of triangle inequalityhttps://ask.sagemath.org/question/49101/evaluation-of-triangle-inequality/I wrote the following code:
x = var('x')
assume(x,'real')
y = var('y')
assume(y,'real')
z = var('z')
assume(z,'real')
expr = abs(x-y)+abs(y-z) >= abs(x-z)
Then I run it:
sage: bool(expr)
False
The expression is obviously mathematically correct. How come Sage returns "False"?Fri, 20 Dec 2019 12:27:45 -0600https://ask.sagemath.org/question/49101/evaluation-of-triangle-inequality/Answer by Emmanuel Charpentier for <p>I wrote the following code:</p>
<pre><code>x = var('x')
assume(x,'real')
y = var('y')
assume(y,'real')
z = var('z')
assume(z,'real')
expr = abs(x-y)+abs(y-z) >= abs(x-z)
</code></pre>
<p>Then I run it:</p>
<pre><code>sage: bool(expr)
False
</code></pre>
<p>The expression is obviously mathematically correct. How come Sage returns "False"?</p>
https://ask.sagemath.org/question/49101/evaluation-of-triangle-inequality/?answer=49111#post-id-49111Sage implements booleans,and answers to a"logical" query either by `True`, which means that Sage can compute an equality, or `False`, meaning that Sage cannot compute this equality. This *does not* mean that the result is false, only that Sage cannot prove it.
Mathematica does the same:
sage: %%mathematica
....: P = Abs[x - y] + Abs[y - z] >= Abs[x - z]
....: Assuming[x \[Element] Reals && y \[Element] Reals && z \[Element] Reals, Re
....: duce[P]]
....:
Abs[x - y] + Abs[y - z] >= Abs[x - z]
Out[3]= Abs[y - z] >= -Abs[x - y] + Abs[x - z]
Contrast this with Maxima:
sage: %%maxima
....: declare(x,real,y,real,z,real);
....: is(abs(x-y)+abs(y-z)>=abs(x-z));
....:
done
unknown
Maxima implements "trinary logicals", i. e. a logical value can be `true` (i. e. the result can be computed true), `false`(the result can be cimputed false) or `unknown` (the result cannot be computed).
HTH,Sat, 21 Dec 2019 04:37:23 -0600https://ask.sagemath.org/question/49101/evaluation-of-triangle-inequality/?answer=49111#post-id-49111