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, 26 Oct 2010 11:22:24 -0500Is the expression (pi > 0) lazy evaluated?http://ask.sagemath.org/question/7743/is-the-expression-pi-0-lazy-evaluated/[Absolute beginner here.]
The expression $pi > 0$ has the type `sage.symbolic.expression.Expression`. How can I force the evaluation and get the result `True`.
Also, as per the question title, can you please point me to a reference on the evaluation model in Sage?Tue, 26 Oct 2010 09:31:39 -0500http://ask.sagemath.org/question/7743/is-the-expression-pi-0-lazy-evaluated/Answer by Mike Hansen for <p>[Absolute beginner here.]</p>
<p>The expression $pi > 0$ has the type <code>sage.symbolic.expression.Expression</code>. How can I force the evaluation and get the result <code>True</code>.</p>
<p>Also, as per the question title, can you please point me to a reference on the evaluation model in Sage?</p>
http://ask.sagemath.org/question/7743/is-the-expression-pi-0-lazy-evaluated/?answer=11758#post-id-11758You can use `bool()` :
sage: bool(pi > 0)
True
Sage's evaluation model is the same as Python's. The above example is not actually lazily evaluated, when you evaluate `pi > 0`, it immediately makes a call like the following:
sage: pi.__gt__(0)
pi > 0
Instead of returning `True` or `False` it instead returns symbolic expression representing the inequality. This is done for symbolic expressions to be consistent with things like
sage: x > 2
x > 2
Also, notice that it is specific to symbolic expressions:
sage: SR(2) == 2
2 == 2
sage: 2 == 2
True
Tue, 26 Oct 2010 11:22:24 -0500http://ask.sagemath.org/question/7743/is-the-expression-pi-0-lazy-evaluated/?answer=11758#post-id-11758Answer by DSM for <p>[Absolute beginner here.]</p>
<p>The expression $pi > 0$ has the type <code>sage.symbolic.expression.Expression</code>. How can I force the evaluation and get the result <code>True</code>.</p>
<p>Also, as per the question title, can you please point me to a reference on the evaluation model in Sage?</p>
http://ask.sagemath.org/question/7743/is-the-expression-pi-0-lazy-evaluated/?answer=11757#post-id-11757bool(pi > 0) returns True; bool(pi > 3.15) returns False.
Tue, 26 Oct 2010 11:20:11 -0500http://ask.sagemath.org/question/7743/is-the-expression-pi-0-lazy-evaluated/?answer=11757#post-id-11757