comparing Expressions in python

Hi,

I have an Expression I want to compare:

var('x,y')
x+y == x+y


But this does not return True. Why?

edit retag close merge delete

Sort by » oldest newest most voted

It works for me:

sage: var("x, y")
(x, y)
sage: x+y == x+y
x + y == x + y
sage: bool(x+y == x+y)
True
sage: if (x+y == x+y):
....:     print 'yep!'
....:
yep!


Unless you mean that you want bool to be automatically applied to every equation? Since Sage follows the convention that "False" means "I couldn't see how to prove this was true", this would mean that pretty much every equation would automatically be False from the get-go and so you couldn't do anything with it. For example, (x-2)*(x+3) == 0 would be False (x could be 9, after all).

more

Thanks! I didn't know about bool(). What is the advantage of not automatically applying it?

( 2012-10-28 16:52:23 -0600 )edit

@SLOtoSF: apparently I didn't explain well enough -- that's what my last paragraph was trying to explain. If you automatically applied it, you could never manipulate an equation because it'd be a bool instantly. No substitutions, no simplifications, nothing.

( 2012-10-29 09:01:22 -0600 )edit

I see. Totally makes sense. Thanks.

( 2012-10-29 09:09:26 -0600 )edit