Symbolic Tensors

The Wolfram System offers a large number of functions to efficiently manipulate lists, matrices, and arrays of any depth and dimension. Among them there are functions to perform algebraic operations, like sums, products, inner or outer products, transpositions, etc. The Wolfram System also has powerful algorithms to manipulate algebraic combinations of expressions representing those arrays. These expressions are called symbolic arrays or symbolic tensors. By assuming given properties about those symbolic arrays (mainly rank, dimension, and symmetry), you can construct and prove results which are valid for arbitrary members of large domains of arrays obeying those properties.

Matrices are rank 2 arrays and can be symmetric, antisymmetric, or not have any symmetry at all. Higher-rank tensors can be fully symmetric or fully antisymmetric, but they can also have many other types of symmetries under transposition of their levels or slots. Relevant tensors in physics and mathematics usually have symmetry: the symmetric inertia tensors, the antisymmetric electromagnetic field, the rank 4 stiffness tensor in elasticity, the rank 4 Riemann curvature tensor of a manifold, the fully antisymmetric volume forms, etc. Even when you work with elementary objects without symmetry, like vectors, the repeated use of them leads to the appearance of symmetry. The Wolfram System introduces a general language to describe arbitrary transposition symmetries of arrays of any depth and dimension, both for ordinary arrays and for symbolic arrays. See "Tensor Symmetries" for a description of the language of symmetries.

Symbolic Array Domains

A given symbolic expression expr will be taken to belong to a given domain adom of arrays by using an assumption of the form (RefLink[Element, paclet:ref/Element])[expr,adom], where adom specifies the properties shared by all arrays of that domain.

Domains of symbolic arrays.

Extract properties of a real symmetric matrix:

$Assumptions=m∈Matrices[{4,4},Reals,Symmetric[{1,2}]]

TensorRank[m]

TensorDimensions[m]

TensorSymmetry[m]

You can compute properties of combinations of tensors, like tensor products:

$Assumptions={m∈Matrices[{4,4},Complexes,Symmetric[{1,2}]],
v∈Vectors[4,Complexes]};

TensorRank[m⊗v]

TensorDimensions[v⊗m⊗v]

TensorSymmetry[v⊗v⊗v]

The symmetry must be compatible with the dimensions of the array:

m∈Matrices[{3,4},Reals,Antisymmetric[{1,2}]]

m∈Matrices[{3,3},Reals,Antisymmetric[{1,2,3}]]

A general symbolic tensor expression can be understood as a linear combination of terms formed by combining the symbolic tensors using three basic operations: tensor products, transpositions, and contractions. Other basic algebra operations can be decomposed in terms of these.

Basic tensor operations.

Declare new symbolic tensor objects:

$Assumptions={a∈Arrays[{4,4,4},Reals,Antisymmetric[{1,2,3}]],
b∈Arrays[{2,3,4},Reals],v∈Vectors[4,Reals]};

This is a transposition of the array b:

TensorTranspose[b,{2,3,1}]

TensorDimensions[%]

Compare with:

Transpose[Array[x,{2,3,4}],{2,3,1}]//Dimensions

This is a contraction of levels 1 and 3 of the array a:

TensorContract[a,{{1,3}}]

%//TensorDimensions

Contractions must be dimensionally consistent:

TensorContract[b,{{1,3}}]

All terms in a sum must have the same rank and dimensions, but not necessarily the same symmetry:

3a-2v⊗v⊗v//TensorDimensions

3a-2b//TensorDimensions

Tensor Canonicalization

As usual in computer algebra, one of the most important computational steps is converting general expressions into a canonical form, if possible. When only transposition symmetries are involved, it is always possible to bring symbolic tensor polynomials to such canonical form, using specialized group theory algorithms. However, for complicated cases involving large ranks, it could consume considerable time and memory.

Tensor canonicalization.

Declare the properties of various real tensors:

$Assumptions={T∈Arrays[{3,3,4,4},Reals,Symmetric[{1,2}]],A∈Matrices[{3,3},Reals,Antisymmetric[{1,2}]],M∈Matrices[{4,4},Reals,Antisymmetric[{1,2}]],
P∈Matrices[{4,4},Reals]};

Now you can have a symbolic tensor expression like the following:

texpr=2M⊗P-P⊗(M+P)+P⊗TensorContract[T⊗A,{{1,5},{2,6}}]

(RefLink[TensorExpand, paclet:ref/TensorExpand]) expands sums in products and applies basic identities:

TensorExpand[texpr]

(RefLink[TensorReduce, paclet:ref/TensorReduce]) applies the same operations, sorts the tensors lexicographically, and uses the symmetry information. In this example, the contraction term disappears because it involves the contraction of a symmetric and an antisymmetric tensor:

TensorReduce[texpr]

(RefLink[TensorReduce, paclet:ref/TensorReduce]) always moves (RefLink[TensorProduct, paclet:ref/TensorProduct]) inside (RefLink[TensorContract, paclet:ref/TensorContract]) or (RefLink[TensorTranspose, paclet:ref/TensorTranspose]):

TensorContract[T,{{1,2}}]⊗TensorContract[P⊗M,{{1,3}}]//TensorReduce

TensorTranspose[A⊗M,{2,3,1}]⊗T//TensorReduce

(RefLink[TensorReduce, paclet:ref/TensorReduce]) always moves (RefLink[TensorContract, paclet:ref/TensorContract]) inside (RefLink[TensorTranspose, paclet:ref/TensorTranspose]):

TensorContract[TensorTranspose[P⊗P,{2,3,4,1}],{{3,4}}]//TensorReduce

Scalar factors (in this case a contraction of P) are separated if possible:

TensorContract[M⊗P⊗P,{{3,4}}]//TensorReduce

The next example explores the trace of powers of an antisymmetric matrix. For such a matrix A in any dimension, (RefLink[Tr, paclet:ref/Tr])[(RefLink[MatrixPower, paclet:ref/MatrixPower])[A,n]] vanishes for odd n but not for even n. This is illustrated by constructing the power and trace in terms of (RefLink[TensorProduct, paclet:ref/TensorProduct]) and (RefLink[TensorContract, paclet:ref/TensorContract]) and then canonicalizing the expression using (RefLink[TensorReduce, paclet:ref/TensorReduce]).

Declare A to be an antisymmetric matrix in arbitrary dimension:

$Assumptions=A∈Matrices[{d,d},Reals,Antisymmetric[{1,2}]];

Construct a representation using (RefLink[TensorContract, paclet:ref/TensorContract]) and (RefLink[TensorProduct, paclet:ref/TensorProduct]):

contract[mat_,n_]:=TensorContract[TensorProduct@@ConstantArray[mat,n],Partition[RotateLeft[Range[2n]],2]]

contract[A,1]

TensorReduce[%]

contract[A,2]

TensorReduce[%]

contract[A,3]

TensorReduce[%]

These are the results for low values of n:

Table[n->TensorReduce[contract[A,n]]===0,{n,20}]

A more complicated example is given by the canonicalization of scalar polynomials in the Riemann tensor. Here, only its transposition symmetries are used (also known as permutation symmetries or monoterm symmetries), and not the Riemann cyclic symmetries.

This is a specification of the Riemann transposition symmetry:

Rsym={{{2,1,3,4},-1},{{3,4,1,2},1}};

$Assumptions=R∈Arrays[{d,d,d,d},Reals,Rsym]

There are 24 possible transpositions:

TensorTranspose[R,#]&/@Permutations[{1,2,3,4}]

But only three (up to sign) are canonical:

TensorReduce/@%//Union

This gives random contraction of m pairs of slots in the tensor product of n Riemann tensors:

randomRprod[n_,m_]:=TensorContract[TensorProduct@@ConstantArray[R,n],Partition[RandomSample[Range[4n]][[Range[2m]]],2]]/;m≤2n

These are three contractions with two Riemann tensors:

SeedRandom[17];
randomRprod[2,3]

%//TensorReduce//Timing

A bigger case, involving 25 tensors (100 slots) and 40 contraction pairs:

randomRprod[25,40]

%//TensorReduce//Timing