TensorContract

TensorContract[tensor,{{s11,s12},{s21,s22},}]

yields the contraction of tensor in the pairs {si1,si2} of slots.

Details

  • The first argument of TensorContract[tensor,pairs] can be any tensorial object, in particular explicit or symbolic arrays, or combinations like tensor products, transpositions, etc.
  • The slots sij must all be different positive integers, not larger than the rank of the contracted tensor.
  • The slots contracted in each pair must all have the same dimensions, but different pairs might be associated to different dimensions.
  • For a symbolic tensor in the first argument of TensorContract, the contractions in the second argument are sorted, after sorting the slots in each contraction.
  • TensorContract[tensor,{}] returns tensor.

Examples

open allclose all

Basic Examples  (3)

Contract slots 2 and 3 of a rank-3 array:

Perform several contractions in an array:

A symbolic array of rank 3:

Slots 1 and 3 can be contracted:

Slots 1 and 2 cannot be contracted:

Scope  (3)

Contractions of arrays:

Contraction of symbolic arrays:

Report invalid contractions for symbolic arrays:

Combining successive contractions:

Generalizations & Extensions  (1)

With arrays it is possible to use contractions of more than two slots, using the function SymbolicTensors`ArrayContract:

It is also possible to specify an arbitrary head, generalizing the role of Plus:

The contraction can be performed in such a way that levels stay inside the contraction head g:

Properties & Relations  (8)

Contraction of the first levels of an array is equivalent to Tr:

Contraction of a tensor product of arrays is equivalent to Dot and Inner:

Inner performs one contraction between two arrays:

Dot with arguments performs contractions among them:

Arbitrary contractions can be also performed with a combination of Transpose and Apply:

Contraction of antisymmetric pairs of array levels gives zero:

Since levels one and three are not an antisymmetric pair, the result is not zero:

Contraction of antisymmetric symbolic arrays gives zero:

In other cases, the expression is canonicalized, moving contractions to the last possible slots:

TensorContract[tensor,{}] returns tensor, irrespectively of what tensor is:

TensorContract, in combination with TensorProduct, can be used to implement Dot:

Possible Issues  (1)

Invalid contractions are reported:

The expression becomes inert then:

Wolfram Research (2012), TensorContract, Wolfram Language function, https://reference.wolfram.com/language/ref/TensorContract.html.

Text

Wolfram Research (2012), TensorContract, Wolfram Language function, https://reference.wolfram.com/language/ref/TensorContract.html.

CMS

Wolfram Language. 2012. "TensorContract." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/TensorContract.html.

APA

Wolfram Language. (2012). TensorContract. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/TensorContract.html

BibTeX

@misc{reference.wolfram_2024_tensorcontract, author="Wolfram Research", title="{TensorContract}", year="2012", howpublished="\url{https://reference.wolfram.com/language/ref/TensorContract.html}", note=[Accessed: 18-December-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_tensorcontract, organization={Wolfram Research}, title={TensorContract}, year={2012}, url={https://reference.wolfram.com/language/ref/TensorContract.html}, note=[Accessed: 18-December-2024 ]}