Assume I'm trying to naively define an antisymmetric functionf[x_, y_] := -f[y, x]
and assign it a value at some point f[1, 2] = 1;
. After this, calling {f[1, 2], f[2, 1]}
gives {1,-1}
as desired. However, evaluating f[1,3]
leads to an infinite recursion with result Hold[f[1, 3]]
.
My goal is to write a definition of f[x,y]
in such a way that it tries both variants f[x,y]
and -f[y,x]
to see if a value is assigned for any of them. If it is, the function should evaluate to this value. If it isn't, then it should stay unevaluated but avoid the infinite loop.
Condition
in your definition to avoid the infinite loop:f[x_, y_] /; (!OrderedQ[{x,y}]) := -f[y, x]
$\endgroup$f[2,1]=-1
thenf[1,2]
will stay unevaluated. My whole purpose is to not care whether I should definef[x,y]
orf[y,x]
. $\endgroup$DownValues
. $\endgroup$f[1,1] = 1
??? $\endgroup$