Ask Your Question
0

equating formal functions

asked 2012-12-01 13:04:56 +0100

Mark gravatar image

Why does the following not result in 'True'?

var('x')
f=function('f',nargs=1)
f(x)==f(x)

or, speaking differently, can I define formal functions such that the preceding will result in 'True'?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2012-12-01 13:55:53 +0100

DSM gravatar image

It seems to work fine for me:

sage: var('x')
x
sage: f=function('f',nargs=1)
sage: f
f
sage: f == f
True
sage: f(x) == f(x)
f(x) == f(x)
sage: bool(f(x) == f(x))
True
sage: if f(x) == f(x):
....:     print 'equal!'
....:     
equal!

Do you mean that you want f(x) == f(x) to be automatically simplified to True, instead of returning an equation? That can't work in general, because in Sage, an equation is False if Sage can't prove that it's true. So if you had an equation like

sage: x^2 - 4 == 0
x^2 - 4 == 0

it would instead give you False rather than the equation, because it's possible that x is something other than 2 or -2..

Long story short, if you want the truth value, call bool. You might be able to construct a subclass which gives you the behaviour you want but ISTM it'll only lead to headaches.

edit flag offensive delete link more

Comments

Yes, I was expecting f(x)==f(x) to automatically simplify to True. (Mathematica will actually do so.) The bool()-typing workaround you suggest is kind of ok for me, yet, as I read your answer, it seems really strange that x-x==0 does not result in True but rather in 0==0 ... and moreover, if you type 0==0 at the sage prompt you will obviously get True ...

Mark gravatar imageMark ( 2012-12-01 17:45:50 +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-12-01 13:04:56 +0100

Seen: 604 times

Last updated: Dec 01 '12