I do have some multi-indexed variable, e.g. like this
\begin{align*}f_{123} &= 1\\f_{345} &= 1/2\end{align*}
where $f$ is antisymmetric under permutation of any pair of indices, i.e. e.g. $f_{132}=-1$ and so on. Also, $f_{ijk}=0$ for $(ijk)$ not being a permutation of either $(123)$ or $(345)$. I am wondering what the right "Mathematica way" is to set up such a scenario.
My current attempt:
Define all values depending on the indices
ClearAll[f, f2];
f[{1, 2, 3}] = 1;
f[{3, 4, 5}] = 1/2;
Explicitly set all f
to zero if their argument is not {1,2,3}
or {3,4,5}
.
f[list_ /; list != {1, 2, 3} || {3, 4, 5}] := 0;
Then define an f2
which takes a 3dim list
as argument, evaluates the Signature[list]
and multiplies with f
called with Sort
ed list
:
f2[list_?(VectorQ[#, NumericQ] &) /; Length[list] == 3] := Signature[list]*f[Sort@list];
This works as I want it to work. However, I feel like there must be another way to accomplish this - and I actually think that my attempt is not the best one (I have a gut feeling that it might miss certain cases and lead to errors at some point).
P.S.: If you do have better suggestions for Tags, I would much appreciate an edit/suggestion.
f[idx_ /; ! MatchQ[Sort[idx], {1, 2, 3} | {4, 5, 6}]] := 0
myself. $\endgroup$f[_]=0
, not thinking straight there :) $\endgroup$f["stuff"]
orf[{1, 2, 3, 4, 5}]
to return 0 as well? $\endgroup$f[_]:=0
or the explicitly stated "zero cases". However, it is true that this might cause issues if the code develops. So I will probably stick to explicitly stating whenf
should be zero and when it should stay unevaluated. $\endgroup$