# equating formal functions

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

Sort by » oldest newest most voted 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.

more

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