# Tensor contraction for two antisymmetric tensors [duplicate]

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?

• Try TensorContract[TensorProduct[A, B], {{3,7}, {4, 8}}]] Aug 26, 2017 at 4:44

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;
B := LeviCivitaTensor;
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.