Ask Your Question
1

Is the expression (pi > 0) lazy evaluated?

asked 2010-10-26 16:31:39 +0100

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 18:22:24 +0100

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 18:20:11 +0100

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 16:31:39 +0100

Seen: 540 times

Last updated: Oct 26 '10