Basic Examples (4)
Take an array of depth 4:
Contract levels 2 and 3:
Contract levels 2, 3 and 4:
Use head g for the contraction:
Scope (8)
Use arrays of any depth:
Perform contractions of any number of levels:
Perform any number of contractions simultaneously:
Use any head for contractions:
Heads with attribute Flat, like Plus, will then combine, eliminating nesting:
Take an array of depth 4:
Contract levels 1 and 3 into a single level with head g, which by default is placed where level 3 was, effectively considering that the original array had depth 3:
Move the contracted level one level deeper:
Listable heads automatically move as deep as possible in the array, ignoring the effective depth argument:
Arrays must be rectangular, at least up to the level given by the effective depth:
As a corner case, effective depth 0 is possible when there are no contractions:
Contract sparse arrays, quantity arrays or other types of structured arrays:
Properties and Relations (7)
Tr can contract only the higher levels of an array:
ArrayContract can contract any group of levels:
Performing this operation with Tr would require transpositions:
Empty contractions are ignored:
The presence of a contraction head is irrelevant if all contractions are empty:
TensorContract and ArrayContract can both perform several contractions:
TensorContract always uses Plus as a contraction head, but ArrayContract can use any head:
TensorContract can handle symbolic expressions, but ArrayContract only acts on explicit arrays:
ArrayContract can perform transpositions, using effectively the same notation as Flatten:
ArrayContract generalizes Apply on consecutive levels, with levels shifted by one:
Transpose can also perform simultaneous contractions with head List:
The order of contractions is relevant: