Ask Your Question
1

Is the expression (pi > 0) lazy evaluated?

asked 2010-10-26 09:31:39 -0500

Jennifer Dylan gravatar image

[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?

edit retag flag offensive close merge delete

2 answers

Sort by » oldest newest most voted
2

answered 2010-10-26 11:22:24 -0500

Mike Hansen gravatar image

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

answered 2010-10-26 11:20:11 -0500

DSM gravatar image

bool(pi > 0) returns True; bool(pi > 3.15) returns 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: 2010-10-26 09:31:39 -0500

Seen: 206 times

Last updated: Oct 26 '10