Tensor contraction computation

contraction-operatortensor-productstensors

I am currently trying to implement tensors as multidimensional arrays in C++, which is why i am asking this with regards to algorithmic computability.

I would like to implement the contraction of two tensors A = Aabc…n and B = Bn…xyz and C = AB such that a through z represent the dimensions of A and B. A and B can have arbitrary dimension and a through z can be arbitrarily large.

It is extremely difficult to find actual sources on this, without having to first take a few online courses about this topic. If you have some sources regarding this topic, i would greatly appreciate it.

EDIT: Sort of like this: https://www.youtube.com/watch?v=FbsJ6urR4x0 Which indices with which and where do they go.

Best Answer

Calculating the component values of a tensor contraction simply involves pairing one contravariant (upper) index of one tensor with a covariant (lower) index of the other tensor and then summing over both indices.

So the component values of the contracted tensor $C^{abc\dots}_{\dots xyz}$ are given in terms of the component values $A^{abc \dots n}$ and $B_{n \dots xyz}$ by

$C^{abc\dots}_{\dots xyz} = \sum_{n=1}^{k}A^{abc\dots n}B_{n\dots xyz}$

where $k$ is the dimension of the underlying vector space. Using the convention of the Einstein summation convention the sum operator is omitted (and understood to be implied by the repeated index label $n$) so the same expression is written as

$C^{abc\dots}_{\dots xyz} = A^{abc\dots n}B_{n\dots xyz}$