Loading [MathJax]/jax/output/HTML-CSS/jax.js

First time here? Check out the FAQ!

Ask Your Question
1

Is the expression (pi > 0) lazy evaluated?

asked 14 years ago

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?

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
2

answered 14 years ago

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
Preview: (hide)
link
2

answered 14 years ago

DSM gravatar image

bool(pi > 0) returns True; bool(pi > 3.15) returns False.

Preview: (hide)
link

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: 14 years ago

Seen: 544 times

Last updated: Oct 26 '10