# Tensor Canonicalization

Mathematica 9 includes a powerful tensor canonicalizer, which can bring expressions involving products, contractions, and transpositions of tensors with symmetries into a standard form. From these standard forms, computations can be optimized and new identities can be derived.

#### Declare T to be a rank-4 tensor in dimension with the transposition symmetries of the Riemann tensor. There are then 105 possible complete contractions of .

 In[1]:= X\$Assumptions = T \[Element] Arrays[{d, d, d, d}, Reals, {{{2, 1, 3, 4}, -1}, {{3, 4, 1, 2}, 1}}]; contractions = Map[Sort, Partition[#, 2] & /@ Permutations[Range[8]], {1, 2}] // DeleteDuplicates; Length[contractions]
 Out[1]=

#### However, due to symmetry, there are only nine possible results—five if sign is ignored. The following list gives the canonical form of each such contraction, and the table following it illustrates the possible nonzero contractions.

 In[2]:= XTensorReduce[TensorContract[T\[TensorProduct]T, #]] & /@ contractions // DeleteDuplicates
 Out[2]=

#### The canonicalizer uses state-of-the-art algorithms to return answers quickly. A tensor expression involving 50 contractions can be canonicalized in a fraction of a second.

 In[3]:= XTensorReduce[ TensorContract[TensorProduct @@ ConstantArray[T, 25], Partition[RandomSample[Range@100], 2]]] // Timing
 Out[3]=