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.Tue, 26 Oct 2010 18:22:24 +0200Is the expression (pi > 0) lazy evaluated?https://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 16:31:39 +0200https://ask.sagemath.org/question/7743/is-the-expression-pi-0-lazy-evaluated/Answer 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>
https://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 18:20:11 +0200https://ask.sagemath.org/question/7743/is-the-expression-pi-0-lazy-evaluated/?answer=11757#post-id-11757Answer 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>
https://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 18:22:24 +0200https://ask.sagemath.org/question/7743/is-the-expression-pi-0-lazy-evaluated/?answer=11758#post-id-11758