-1

Though I've managed to multiply two third-rank tensors, I can't figure out how to compute this expression in Mathematica: $$D_{ijk} = O_{il} O_{jm} O_{kn} D_{lmn}$$ where $i, j, k, l, m, n = 1, 2, 3$. Any explanation and help with the TensorContract methods would be appreciated here.

1 Answers1

1

Use TensorProduct + TensorContract. In the following I use o and d because O and D are protected symbols that you shouldn't use:

res = TensorContract[
    TensorProduct[o, o, o, d],
    {{2,7}, {4,8}, {6,9}}
] //FullForm

TensorContract[TensorProduct[o,o,o,d],List[List[2,7],List[4,8],List[6,9]]]

Here o and d don't have explicit values, and so the result is symbolic. If we assign values to o and d:

o = RandomInteger[1, {3, 3}];
d = RandomInteger[1, {3, 3, 3}];

then the tensor contraction will become explicit:

res

{{{5, 5, 0}, {5, 6, 0}, {0, 0, 0}}, {{1, 2, 0}, {2, 3, 0}, {0, 0, 0}}, {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}}

Carl Woll
  • 130,679
  • 6
  • 243
  • 355
  • Just wanted to add that from my experience this procedure can be quite resource-greedy, especially for big tensors, as TensorProduct seems to allocate the memory for the resulting tensor first, which can be huge. There've been some workarounds with Hold, and using Dot and Transpose seemed to be faster still. I'm not sure if this has been fixed in newer versions of Mathematica. – Stan Jul 18 '17 at 16:31