How can I define a abstract odd function, say f[x].
Whenever f[x]+f[-x] appears, mathematica simplifies it to zero.
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]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With