Removing the pattern test, i.e.Because Mathematica prioritizes specific function definitions over general ones, simply making the definition f[x_] := -f[-x], or adding a corresponding definition with ?Positive
M[i_, j_] := -M[j, i] will work as long as you only try to evaluate fM with values for xi forand j for which either f[x]M[i, j] or f[-x]M[j, i] have been explicitly defined. Otherwise you get infinite recursion:
f[x_]M[1, 2] := -f[-x]a f[-1]M[4, 3] := 2;b f[2] M[1, =2] (* 4;a *) f[1]M[2, 1] (* -2a *) f[-2]M[3, 4] (* -4b *) f[3]M[1, 3] (* $RecursionLimit::reclim2: Recursion depth of 1024 exceeded during evaluation of f[-3]M[3,1]. *) (* Hold[-f[-3]]M[3, 1]] *) Clear[f]Clear[M] To avoid this, we can make a definition for fM that only allows itself to be recursed twice, like so:
Module[{in = 0}, f[x_]M[i_, j_] /; in < 2 := Block[{in = in + 1}, -f[-x]];M[j, i]] ] The variable in counts the number of times that thethis definition of f[x]M has been called recursively. If in is less than two, the definition applies, and the sign of xi is flippedand j are swapped. When in is equal to two, the definition doesn't apply, and evaluation terminates. Since at this point the definition has been applied twice, the original expression is returned.
Now we have
f[-1] =M[1, 2; f[2]2] := 4; a M[4, 3] := b f[1]M[1, 2] (* -2a *) f[-2]M[2, 1] (* -4a *) f[3]M[3, 4] (* f[3]-b *) f[f[f[1]]]M[1, 3] (* f[-4]M[1, 3] *) (Side note: Mathematica colors the n in the Block expression red, because it thinks that we've created a naming conflict between the Module and the Block, but in fact it works just how we want.)