Ask Your Question
0

comparing Expressions in python

asked 2012-10-28 17:12:00 +0100

SLOtoSF gravatar image

updated 2015-01-14 09:43:29 +0100

FrédéricC gravatar image

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 flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2012-10-28 20:20:43 +0100

DSM gravatar image

updated 2012-10-28 20:20:55 +0100

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).

edit flag offensive delete link more

Comments

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

SLOtoSF gravatar imageSLOtoSF ( 2012-10-28 22:52:23 +0100 )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.

DSM gravatar imageDSM ( 2012-10-29 15:01:22 +0100 )edit

I see. Totally makes sense. Thanks.

SLOtoSF gravatar imageSLOtoSF ( 2012-10-29 15:09:26 +0100 )edit

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: 2012-10-28 17:12:00 +0100

Seen: 708 times

Last updated: Oct 28 '12