I have SparseArray for two rank 4 antisymmetric tensors A and B, I want to compute $T_{abef}=\sum_{cd}A_{abcd}B_{efcd}$. How should I do it?
1 Answer
$\begingroup$
$\endgroup$
I think a code of this sort should help you. I have defined A and B to be levi-civita tensors for demonstration purposes. You can also opt to have the display as MatrixForm for a quick demo:
n = 4;
A := LeviCivitaTensor[4];
B := LeviCivitaTensor[4];
Compute := Compute = Simplify[Table[Sum[
A[[a, b, c, d]]*B[[e, f, c, d]]
, {c, 1, n}, {d, 1, n}]
, {a, 1, n}, {b, 1, n}, {e, 1, n}, {f, 1, n}]]
Compute // MatrixForm
listCompute :=
Table[If[UnsameQ[Compute[[a, b, e, f]], 0], {ToString[T[a, b, e, f]],
Compute[[a, b, e, f]]}] , {a, 1, n}, {b, 1, n}, {e, 1, n}, {f, 1,
n}]
TableForm[Partition[DeleteCases[Flatten[listCompute], Null], 2],
TableSpacing -> {2, 2}]
You may also opt to read about "TensorProduct" however like this I feel I have more control over the code itself.
TensorContract[TensorProduct[A, B], {{3,7}, {4, 8}}]]
$\endgroup$