3
$\begingroup$

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?

$\endgroup$
1
  • 2
    $\begingroup$ Try TensorContract[TensorProduct[A, B], {{3,7}, {4, 8}}]] $\endgroup$
    – Carl Woll
    Commented Aug 26, 2017 at 4:44

1 Answer 1

1
$\begingroup$

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.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.