Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I define a abstract odd function in mathematica?

How can I define a abstract odd function, say f[x].

Whenever f[x]+f[-x] appears, mathematica simplifies it to zero.

like image 568
pengfei_guo Avatar asked Jan 15 '23 01:01

pengfei_guo


1 Answers

This can be done easily using upvalues

f[x_] + f[y_] /; x == -y ^:= 0

Normally Mathematica would try to assign the above rule to Plus, which of course does not work since that's protected. By using ^:= instead of := you can assign the rule to f. A quick check yields:

In[2]:=   f[3]+f[-3]
Out[2]:=  0

Edit: This, however, only works for Plus. It's probably better to use something more general, like:

f[x_?Negative] := -f[-x]

Now this also works with things like

In[4]:=  -f[3] - f[-3]
Out[4]:= 0

If you also want the function to work symbolically, you could add something like:

f[-a_] := -f[a]
like image 103
einbandi Avatar answered Jan 17 '23 14:01

einbandi