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.Tue, 21 Jun 2011 00:54:44 -0500bool returns true to an incorrect function call?http://ask.sagemath.org/question/8173/bool-returns-true-to-an-incorrect-function-call/This happened to me by mistake.
sage: var('x1,t1,x2,t2,u,c',domain=RR);assume(u>0);assume(c>u);assume(x2>x1);assume(t2>t1);
(x1, t1, x2, t2, u, c)
sage: T1 = (t1-((u*x1)/(c^2)))/sqrt(1-((u^2)/(c^2)))
sage: T2 = (t2-((u*x2)/(c^2)))/sqrt(1-((u^2)/(c^2)))
sage: dT = T2-T1
sage: bool(dT.full_simplify >= 0)
True
sage: bool(dT.full_simplify() >= 0)
False
When I made the incorrect function call dT.full_simplify , bool returned true. When I made the correct function call dT.full_simplify() , bool returned false. Is this a bug?
ThanksMon, 20 Jun 2011 13:18:07 -0500http://ask.sagemath.org/question/8173/bool-returns-true-to-an-incorrect-function-call/Answer by parzan for <p>This happened to me by mistake.</p>
<pre><code>sage: var('x1,t1,x2,t2,u,c',domain=RR);assume(u>0);assume(c>u);assume(x2>x1);assume(t2>t1);
(x1, t1, x2, t2, u, c)
sage: T1 = (t1-((u*x1)/(c^2)))/sqrt(1-((u^2)/(c^2)))
sage: T2 = (t2-((u*x2)/(c^2)))/sqrt(1-((u^2)/(c^2)))
sage: dT = T2-T1
sage: bool(dT.full_simplify >= 0)
True
sage: bool(dT.full_simplify() >= 0)
False
</code></pre>
<p>When I made the incorrect function call dT.full_simplify , bool returned true. When I made the correct function call dT.full_simplify() , bool returned false. Is this a bug?</p>
<p>Thanks</p>
http://ask.sagemath.org/question/8173/bool-returns-true-to-an-incorrect-function-call/?answer=12448#post-id-12448Observe that:
sage: dT.full_simplify
<built-in method simplify_full of sage.symbolic.expression.Expression object at 0xb1ddb0c>
Which means "dT.full_simplify" is **not** a function call but the "simplify_full" function itself, and comparing it to zero has no mathematical meaning.
I think the reason sage (actually python) allows comparing very general object is to allow creation of sorted lists containing elements of assorted types. If you sort the list [1,2,dT.full_simplify,3] the result will not be "sorted mathematically" but it will allow binary search nonetheless!
In fact notice that you don't even have to call bool:
sage: dT.full_simplify >= 0
True
whereas for the mathematical comparison you do have to, since doing symbolic computations we don't want every EXPR1 >= EXPR2 expression to evaluate immediately to boolean:
sage: dT.full_simplify() >= 0
-sqrt(c - u)*sqrt(c + u)*(c^2*t1 - c^2*t2 - u*x1 + u*x2)/(c^3 - c*u^2) >= 0
sage: bool(_)
False
Tue, 21 Jun 2011 00:54:44 -0500http://ask.sagemath.org/question/8173/bool-returns-true-to-an-incorrect-function-call/?answer=12448#post-id-12448