Symbolic Tensors

Mathematica 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. Mathematica 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. Mathematica 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 Element[expr, adom], where adom specifies the properties shared by all arrays of that domain.

Arrays[{d1,...,dr},dom,sym]arrays of given dimensions, component type, and symmetry
Matrices[{d1,d2},dom,sym]matrices of given dimensions, component type, and symmetry
Vectors[d1,dom]vectors of given dimension and component type

Domains of symbolic arrays.

Extract properties of a real symmetric matrix.
In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=
In[3]:=
Click for copyable input
Out[3]=
In[4]:=
Click for copyable input
Out[4]=
You can compute properties of combinations of tensors, like tensor products.
In[5]:=
Click for copyable input
In[6]:=
Click for copyable input
Out[6]=
In[7]:=
Click for copyable input
Out[7]=
In[8]:=
Click for copyable input
Out[8]=
The symmetry must be compatible with the dimensions of the array.
In[9]:=
Click for copyable input
Out[9]=
In[10]:=
Click for copyable input
Out[10]=

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.

TensorProduct[t1,t2,...]tensor product of tensors
TensorTranspose[t,perm]transposition of tensor t by permutation perm
TensorContract[t,pairs]contraction of the pairs of slots in the tensor t

Basic tensor operations.

Declare new symbolic tensor objects.
In[11]:=
Click for copyable input
This is a transposition of the array b.
In[12]:=
Click for copyable input
Out[12]=
In[13]:=
Click for copyable input
Out[13]=
Compare with:
In[14]:=
Click for copyable input
Out[14]=
This is a contraction of levels 1 and 3 of the array a.
In[15]:=
Click for copyable input
Out[15]=
In[16]:=
Click for copyable input
Out[16]=
Contractions must be dimensionally consistent.
In[17]:=
Click for copyable input
Out[17]=
All terms in a sum must have the same rank and dimensions, but not necessarily the same symmetry.
In[18]:=
Click for copyable input
Out[18]=
In[19]:=
Click for copyable input
Out[19]=

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.

TensorExpand[texpr]expand tensor sums and products
TensorReduce[texpr]canonicalize terms with respect to symmetry

Tensor canonicalization.

Declare the properties of various real tensors.
In[20]:=
Click for copyable input
Now you can have a symbolic tensor expression like the following.
In[21]:=
Click for copyable input
Out[21]=
TensorExpand expands sums in products and applies basic identities.
In[22]:=
Click for copyable input
Out[22]=
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.
In[23]:=
Click for copyable input
Out[23]=
In[24]:=
Click for copyable input
Out[24]=
In[25]:=
Click for copyable input
Out[25]=
In[26]:=
Click for copyable input
Out[26]=
Scalar factors (in this case a contraction of ) are separated if possible.
In[27]:=
Click for copyable input
Out[27]=

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

Declare to be an antisymmetric matrix in arbitrary dimension.
In[28]:=
Click for copyable input
Construct a representation using TensorContract and TensorProduct.
In[29]:=
Click for copyable input
In[30]:=
Click for copyable input
Out[30]=
In[31]:=
Click for copyable input
Out[31]=
In[32]:=
Click for copyable input
Out[32]=
In[33]:=
Click for copyable input
Out[33]=
In[34]:=
Click for copyable input
Out[34]=
In[35]:=
Click for copyable input
Out[35]=
These are the results for low values of n.
In[36]:=
Click for copyable input
Out[36]=

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.
In[37]:=
Click for copyable input
In[38]:=
Click for copyable input
Out[38]=
There are 24 possible transpositions.
In[39]:=
Click for copyable input
Out[39]=
But only three (up to sign) are canonical.
In[40]:=
Click for copyable input
Out[40]=
This gives random contraction of m pairs of slots in the tensor product of n Riemann tensors.
In[41]:=
Click for copyable input
These are three contractions with two Riemann tensors.
In[42]:=
Click for copyable input
Out[43]=
In[44]:=
Click for copyable input
Out[44]=
A bigger case, involving 25 tensors (100 slots) and 40 contraction pairs.
In[45]:=
Click for copyable input
Out[45]=
In[46]:=
Click for copyable input
Out[46]=
New to Mathematica? Find your learning path »
Have a question? Ask support »