Ask Your Question
0

bool returns true to an incorrect function call?

asked 2011-06-20 20:18:07 +0100

omoplata gravatar image

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?

Thanks

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2011-06-21 07:54:44 +0100

parzan gravatar image

updated 2011-06-21 08:06:51 +0100

Observe 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
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2011-06-20 20:18:07 +0100

Seen: 299 times

Last updated: Jun 21 '11