xTras Tutorial|Functions »

Introduction to xAct

xAct is a suite of free packages for tensor computer algebra in Mathematica. xAct implements state-of-the-art algorithms for fast manipulations of indices and has been modelled on the current geometric approach to General Relativity. It is highly programmable and configurable. Since its first public release in March 2004, xAct has been intensively tested and has solved a number of hard problems in GR.
xAct consists of the following packages:
xCoregeneric programming tools
xPermmanipulation of large groups of permutations
xTensorabstract tensor computations
xCobacomponent tensor computations

xAct kernel packages

xPerthigh-order perturbation theory in GR
Harmonicstensor spherical harmonics
Invarpolynomial invariants of the Riemann tensor
Spinorsspinor computations in GR

xAct application packages

xPrintformatted input
SymManipulatorsymmetrized expressions
xTrasfield theory inspired additions
TexActTAdjustmentBox[E, BoxBaselineShift -> 0.5, BoxMargins -> {{-0.3, 0}, {0, 0}}]X code formatting
xPandcosmological perturbation theory
xTeriordifferential forms

Contributed xAct packages

Setting up a session

Let's start by getting a simple xAct session up and running, and define a manifold and tensors on that manifold.
DefManifold[M,dim,inds]defines a manifold M with dimension dim and a tangent bundle with indices inds.
DefMetric[sign,g[-a,-b],cd]defines a metric g of signature sign on the manifold of which a and b are indices, a covariant derivative cd, and all curvature tensors of g.
DefTensor[T[inds],M,sym]defines a tensor T with indices inds and symmetry sym on the manifold M.

Commands for defining manifolds, metrics, and tensors.

First, load the xTensor package.
This loaded not only the xTensor package, but also the xPerm package which handles the group theoretical computations needed for canonicalizing tensors.
Let's define a four-dimensiona manifold:
You'll notice that besides defining a manifold, this also defined a vector bundle TangentM where our tensors will live. In fact, xAct is build around the notion of 'defining' geometric quantities and tensors, and has quite some commands to do so. We can get a list of them with the Information command:
The two most important ones (next to DefManifold) are DefMetric, which defines the metric, and DefTensor, which defines a tensor. Let's first define a metric on our manifold M.
We don't need to specify the manifold, because xTensor determines that from the indices of the metric. But we do need to specify a symbol for the associated covariant derivative. We'll name it CD, and we'll let the metric be Lorentzian (hence the -1). The option CurvatureRelations is to ensure that contractions of Riemann tensors are automatically converted to Ricci's.
This did a whole lot of things. It first defined a metric, and then a number of curvature tensors (the Christoffel tensors, Riemann, Ricci's, the Weyl tensor, etc).
For instance, we now have a Riemann tensor. It has the same structure as every tensor in xAct, namely the name of the tensor followed by its indices. Because we named our covariant derivative CD, this Riemann tensor is called RiemannCD (it's the Riemann tensor of the covariant derivative CD). We can enter it as follows:
In[4]:=
Click for copyable input
Out[4]=
Note that it prints much nicer than how it's put in: xAct formats the indices properly and shortens the name of the tensor to something readable. But underneath it still has the same structure:
In[5]:=
Click for copyable input
Out[5]//InputForm=
The minus signs in front of the indices indicate that they're (covariant) lower indices. If we want to put in (contravariant) upper indices, we just forgo the minus sign:
In[6]:=
Click for copyable input
Out[6]=
We can define other tensors with the DefTensor command:
It's very important to not forget the bracket [], even though scalars don't have indices! Thus
Click for copyable input
is a valid xAct expression, even though it doesn't print its indices.
More complicated tensors can be defined by just specifying their index structure. We can also specify if it's (anti)symmetric as follows:
xAct does not automatically enforce the symmetries of the tensor. For instance, this should be zero:
In[9]:=
Click for copyable input
Out[9]=

Canonicalizing and contracting indices

ToCanonical[expr]gives a canonical reorganization of the indices of expr according to the symmetries of tensors and positions of dummies and repeated indices
ContractMetric[expr]contracts all metrics in expr

Arguably two of the most important functions in xAct.

ToCanonical canonicalizes expressions, which roughly means 'sorting the indices and introduce minus signs where necessary':
In[10]:=
Click for copyable input
Out[10]=
Out[11]=
This introduced a minus sign, because the tensor F is antisymmetric.
In[12]:=
Click for copyable input
Out[12]=
Out[13]=
This didn't do anything, because the expression was already canonical (it's indices were already sorted).
The symmetrization of F does reduce to zero if we use ToCanonical:
In[14]:=
Click for copyable input
Out[14]=
Out[15]=
ToCanonical also works on more general expressions and symmetries. Here is its action on a permutation of the Riemann tensor:
In[16]:=
Click for copyable input
Out[16]=
Out[17]=
We can contract indices with the metric:
In[18]:=
Click for copyable input
Out[18]=
This is not automatically contracted. We have to use the function ContractMetric if we want to do so:
In[8]:=
Click for copyable input
Out[8]=
Out[9]=
This is automatically converted to the Ricci tensor:
In[10]:=
Click for copyable input
Out[10]//InputForm=
Contracting again gives, as expected, the Ricci scalar:
In[11]:=
Click for copyable input
Out[11]=
Out[12]//InputForm=
Contracting a pair of antisymmetric indices results in zero, but only after using ToCanonical:
In[17]:=
Click for copyable input
Out[17]=
Out[18]=
Out[19]=