xAct: An Efficient Tensor Computer Algebra

Sitender Kashyap, Chennai Mathematical Institute

Numerical and Analytical Relativity
Department of Applied Sciences, 
Indian Institute of Information Technology, 
Allahabad.

Plan of the talk

Introduce xAct

Sample abstract index computations using xTensor

Sample component computations using xCoba

Sample computations using xPert and xTras

Aim of this lecture

As we can see xAct is a huge collection of many packages that can do a variety of problems.

This is by no means provides any justification to the vast amount of things that can be coded in xAct.

The aim of this talk is to give a flavour of various things that xAct can do that relate to problems in general relativity.

The idea is to introduce people very new to xAct to see what it can do and possibly use it to fasten their research activities.

Aim of the next lecture

Give the methodology of how do we use xAct to code the Bondi-Sachs formalism.

The basic hurdle as was pointed out in Prof. Amitabh’s lecture is covariance. There is covariance only with respect to the “sphere” metric and not the full 4 dimensional metric. Challenge is how to make xAct deal with this partial covariance.

1.1. Main

xAct is a collection of hierarchical mathematica (Wolfrom language) packages (24 currently)

The purpose of this talk is to show its utility for performing a variety of general relativity problems.

It performs both abstract computations and component computations, possibly mixed.

Here we shall assume the very basic familiarity with Mathematica.

Its utility however goes well beyond general relativity even  field theory calculations can be performed e.g. FieldsX

Successfully used in 1000+ publications (47% gr-qc,  40% hep-th,  8% astro-ph,  5% other).

1100+ different authors have used it.

1.2. Resources

The xAct webpage: (HyperlinkTemplate[www.xact.es, http://www.xact.esNone, http://www.xact.es, HyperlinkActionRecycled, HyperlinkActive, , ]). Here we can find all the resources and information related to downloads, installation, documentation - providing various tutorials etc, citations, frequently asked questions.

The xAct forum: (HyperlinkTemplate[groups.google.com/g/xact, https://groups.google.com/g/xactNone, https://groups.google.com/g/xact, HyperlinkActionRecycled, HyperlinkActive, , ]). If one is stuck, they can post their questions and recieve replies from experts.

There are also questions in (HyperlinkTemplate[mathematica.stackexchange.com, https://mathematica.stackexchange.com/search?q=xActNone, https://mathematica.stackexchange.com/search?q=xAct, HyperlinkActionRecycled, HyperlinkActive, , ])

1.3. Installation

From the xact wepage, goto the download section and download the compressed xAct file.

Uncompress the file and the place it in the directory where your Mathematica is installed.

For example,  for this system on windows: “C:\Program Files\Wolfram Research\Mathematica\12.0\AddOns\Applications\xAct_1.2.0”

To run xAct, open Mathematica and first run the following command.

SetDirectory["your directory....\xAct_1.2.0"]

For example for this system

SetDirectory["C:\Program Files\Wolfram Research\Mathematica\12.0\AddOns\Applications\xAct_1.2.0"]

To run an xAct package, it is done as usual <<xAct`xTensor`.  Here we load the package xTensor.

We will see the example soon.

1.3. The structure of xAct

xAct , as mentioned earlier is a collection of Mathematica packages that are organized hierarchically.

When a package is loaded, all packages it requires are automatically loaded too.

In all there are about 1500 xAct symbols, 450 of them are just in xTensor alone.

xTensor is a very major package and this is what we shall mostly use.

Packages

Core Pacakges

xCore:  Tools for rest of the system- admin

xPerm: permutations - group theory

xTensor:  main abstract tensor computations

xCoba:  component computations.

Application Pacakages

xPert : Metric perturbation theory

Harmonics: Tensor spherical harmonics

Spinors: Spinor calculus

xTras: Field theory

FieldsX: Fermions, gauge fields and BRST cohomology

etc....

Input/Output packages

TexAct :Tex formatting of tensor expressions

xPrint: graphical interface to xACT

Dependency graph

• Loops are not allowed. All dependencies must point downwards:

Graph[,VertexLabels->Automatic,GraphLayout->"LayeredDigraphEmbedding",VertexLabelStyle->Bold]

1.4. Tutorial session : Abstract vs component computations

Abstract computations

Here we deal with tensor expressions and identities that are frames and/or coordinate independet.

First we set the directory where xAct folder is placed.

SetDirectory["~/Documents/Wolfram Mathematica/xAct_1.2.0"]

Then we begin by loading xTensor.

<<xAct`xTensor`

Notice how xPerm, a package on which xTensor depends,  is automatically loaded .

In xACT we need to predefine everything.

The first thing we define is the manifold itself.

DefManifold[M,4,{a,b,c,d,e,f}]

M is the manifold, which is 4 dimensional, and the tensors here will have indices denoted by a, b, c, d, e, f

Next we see how to define a scalar, a vector field and an antisymmetric second rank tensor

DefTensor[Φ[],M]

DefTensor[v[a],M]

DefTensor[F[-a,-b],M,Antisymmetric[{-a,-b}]]

v[a]

v[-a]

F[-a,-b]

Note that [a] means a contravariant (uppper) index, while [-a] means a covariant (lower) index.

Next we define a metric on the above 4 dimensional manifold.

DefMetric[-1,g[-a,-b],CD]

(-1) denotes that the determinant of the metric is -1. CD is the covariant derivative associated with the metric.

Contractions with the kronecker delta tensor as automatic:

delta[-a,b]

v[a]delta[-a,b]

The Leibnitz rule is automatic:

ex=F[-b,-c]v[c]

CD[-a][ex]

Canonicalize a product: ToCanonical, the most imporant of the commands

ex1=ex v[b]

ex1//ToCanonical

ToCanonical is one of the most useful command for simplifying the expressions. It puts the indices in order based on the symmetry properties and rearranges the terms and indices in a suitable order.

xACT also remembers how an object was defined originally. Have a look at

ex1a=v[-a]//SeparateMetric[]

First let us remove the dollar indices - this is done by command ScreenDollarIndices

ex1a//ScreenDollarIndices

See how SeparateMetrci remembers that v[] was defined as a contravariant tensor.

xAct follows Wald’s conventions for signs, Riemann indices order, etc.

For Spinors xACT follows “Spinors and space-time” by Penrose & Rindler.

The sign configuration variables are kept as in Wald’s book by default. They may be changed at the beginning of a session.

{$AccelerationSign,$epsilonSign,$ExtrinsicKSign,$RicciSign,$RiemannSign,$TorsionSign}

Component computations

When tensors are to be written in a given basis we use xCoba

Here each component is treated as a scalar function of some coordinate fields.

Let us load xCoba

<<xAct`xCoba`

Next we define a basis on the Tangent of M

DefBasis[B,TangentM,{0,1,2,3}]

We define tensors by entering numeric components in the basis B

A=CTensor[{{0,1,2,3},{-1,0,4,5},{-2,-4,0,6},{-3,-5,-6,0}},{-B,-B}];
w=CTensor[{7,8,9,10},{B}];

w[b]

A[-a,-b]

ex2=A[-a,-b]w[b]

ex3=ex2 w[a]

Notice how the indices are placed up or down to denote whether they are contravariant or covariant

Component computations always keep track bases we are using.

Both together

The abstract and the component computations are very different.

Traditionally they were done separately.

xAct combines both types in a coherent framework:

• Let us see an example of contracting an abstract and a component tensor:

ex4=F[a,b]A[-a,-b]

ex5=ex4//ToCanonical

We see nothing happens as both are anti-symmetric tensor.

Let us define a symmetric tensor

DefTensor[G[a,b],M,Symmetric[{a,b}]]

ex6=G[a,b]A[-a,-b]

ex6//ToCanonical

The metric is Automatically used for contractions (recall that w was defined contravariant):

ex7=w[-a]w[a]//Expand

We can switch to an actual metric in a basis by

ex7/.g->CTensor[DiagonalMatrix[{-1,1,1,1}],{-B,-B}]

Cleanup the definitions

Remove[ex,ex1,ex1a,ex2,ex3,ex4,ex5,ex6,ex7]

UndefTensor/@{Φ,g,F,v,G}

• Undefine bases:

UndefBasis[B]

• Undefine manifolds:

UndefManifold[M]

• Remove other variables:

Remove[A,w]

?Global`*

• There are no symbols left in the user workspace:

2. Abstract computations with xTensor

2.1. Setup

Let us define again a 4D manifold with a metric field:

DefManifold[M,4,{a,b,c,d,e,f,g,i,j,k,l}]

DefMetric[-1,met[-a,-b],CD,PrintAs->"g"];

Note that the result is typeset as g, even though internally mathematica uses symbol met:

met[-a,-b]

%//InputForm

met[a,b]

met[-a,b]

CD is the covariant derivative of the metric:

CD[-a][met[-b,-c]]

The curvature tensors of CD:

RiemannCD[-a,-b,-c,d]

RicciCD[-a,-b]

RicciScalarCD[]

RiemannCD[-a,-b,-c,b]

RicciCD[-a,a]

Let us verify the symmetries of the Reimann tensor under index permutations:

RiemannCD[-a,-b,-c,d]+RiemannCD[-b,-a,-c,d]

%//ToCanonical

RiemannCD[-a,-b,-c,-d]-RiemannCD[-d,-c,-b,-a]

%//ToCanonical

The torsion associated with covariant derivatives are zero by default:

TorsionCD[-a,-b,c]

2.2. Partial derivatives and Christoffels

Let us expand the Riemann tensor as partial derivatives of Christoffel tensors:

RiemannCD[-a,-b,-c,d]

New dummies are always unique:

%//RiemannToChristoffel

Notice the strange dollar symbols given to the indices. This is how Mathematica handles the indices internally.

We can get hide these by  ScreeenDollarIndices

%//ScreenDollarIndices

We can also this globally by following command and we do not have to use this command everytime

$PrePrint=ScreenDollarIndices;

RiemannCD[-a,-b,-c,d]//RiemannToChristoffel

However, interanlly though internally they are still there!

%//InputForm

Let us now expand Christoffels into derivatives of the metric tensor:

RiemannCD[-a,-b,-c,d]//RiemannToChristoffel//ChristoffelToMetric

This  brute-force expansion is very useful in proving various identities. Take for example the First Bianchi identity:

Bianchi1=RiemannCD[-a,-b,-c,d]+RiemannCD[-b,-c,-a,d]+RiemannCD[-c,-a,-b,d]

Bianchi1//RiemannToChristoffel//ChristoffelToMetric

%//ToCanonical

Second Bianchi identity:

Bianchi2 =Antisymmetrize[CD[-a][RiemannCD[-b,-c,-d,e]],{-a,-b,-c}]

%//CovDToChristoffel

%//RiemannToChristoffel

%//ChristoffelToMetric

%//ToCanonical

2.3. Working with torsion tensor

We can define multiple covariant derivatives.

Let us define another covariant derivative, but this time with torsion:

DefCovD[Cdt[-a],Torsion->True,SymbolOfCovD->{":","𝒟"}]

Below are the tensors associated with this covariant derivative.

{TorsionCdt[a,-b,-c],ChristoffelCdt[a,-b,-c],RiemannCdt[-a,-b,-c,d],RicciCdt[-a,-b]}

The fact that there is torsion means that commutation of covariant derivatives now gives an additional term:

DefTensor[v[a],M]

CD[-a]@CD[-b]@v[c]//SortCovDs

Cdt[-a]@Cdt[-b]@v[c]//SortCovDs

Cdt[-a]@Cdt[-b]@v[c]

CommuteCovDs[%,Cdt,{-b,-a}]

• This is now the second Bianchi identity:

Cdt[-a][ RiemannCdt[-b,-c,-d,e] ]-TorsionCdt[f,-a,-b]RiemannCdt[-c,-f,-d,e]

6Antisymmetrize[%,{-a,-b,-c}]

%//CovDToChristoffel
%//RiemannToChristoffel
%//TorsionToChristoffel
%//ToCanonical

• First Bianchi identity for a connection with torsion:

RiemannCdt[-a,-b,-c,d]+Cdt[-a][ TorsionCdt[d,-b,-c] ]-TorsionCdt[e,-a,-b]TorsionCdt[d,-c,-e]

6Antisymmetrize[%,{-a,-b,-c}]

%//CovDToChristoffel
%//RiemannToChristoffel
%//TorsionToChristoffel
%//ToCanonical

• Undefine the metric field and the covariant derivative with torsion:

UndefMetric[met]

UndefCovD[Cdt]

UndefTensor[v]

2.4. Other things to do with xTensor

We can work with different metrics at the same time. However, it’s only the first metric raises and lowers the indices.

It is possible to work with conformally related metrics.

Take Lie derivatives.

• Take variational derivatives.

We can work with “product metrics”, defined by diagonal blocks.

Work with the Einstein and Weyl tensors. Work with epsilon tensors.

Many more applications

3. Component computations with xCoba

3.1. Load the package

<<xAct`xCoba`

3.2. Charts and metric fields: Schwarzschild

Define a coordinate system called schw, with scalar fields t, r, θ, ϕ corresponding to components 0, 1, 2, 3:

DefChart[schw,M,{0,1,2,3},{t[],r[],θ[],ϕ[]},ChartColor->Blue,FormatBasis->{"Partials","Differentials"}]

• Now define a metric field, the Schwarzschild metric:

DefConstantSymbol[mass,PrintAs->"M"]

met=CTensor[DiagonalMatrix[{-1+2mass/r[],1/(1-2mass/r[]),r[]^2,r[]^2Sin[θ[]]^2}],{-schw,-schw}];

met[-a,-b]

BasisExpand[%,{schw}]

• That tensor does not have any information about being a metric. In particular we cannot yet use it to raise and lower indices:

met[a,b]//Catch

We can compute the inverse metric manually:

Inv[met][a,b]

Let us define now a contravariant vector

v=CTensor[{0,r[],0,0},{schw}]

v[a]

The above is contravariante because we used schw rather than -schw

Note that since we have not defined a metric yet, we cannot directly lower the indices and if we do, we get an error.

v[-a]//Catch

We can manually use the metric to lower indices:

met[-a,-b]v[b]

We now declare that met[] is the metric on the vbundle of the coordinate frame of schw

This is roughly the equivalent of DefMetric in xTensor

In some cases SetCMetric can unambiguously compute the signature from the matrix of components, but in general it cannot, so we need to specify the signature as a triple {number of +1s, number of -1s, number of 0s}:

SetCMetric[met,schw,SignatureOfMetric->{3,1,0}]

Now that we have a metric, raising and lowering indices automatically produces the expected result:

{v[a],v[-a]}

This is a contraction:

v[a]v[-a]

If we raise one index of the metric we get the identity:

met[-a,b]

This is the inverse metric:

met[a,b]

3.3. Levi-Civita connection and curvature

cd=CovDOfMetric[met];

cd[-a][v[b]]

We can readily see that the covariant derivative of the metric field is zero:

cd[-a][met[-b,-c]]

The Christoffel connections with respect to the partial derivative of the chart are

Christoffel[cd,PDschw]

In the table form these look like

%[a,-b,-c]

ToBasisExpand[%]

• Commuting covariant derivatives:

comm=cd[-b]@cd[-a]@v[c]-cd[-a]@cd[-b]@v[c]//Simplify

• We can check that the result coincides with the expected contraction with the Riemann tensor of the connection:

comm==Riemann[cd][-a,-b,-d,c]v[d]

%//Simplify

• Being a Levi-Civita connection, it has zero torsion:

Torsion[cd][a,-b,-c]

As expected the Schwarzschild metric is indeed Ricci-flat:

Ricci[cd][-a,-b]

Riemann[cd][-a,-b,-c,d]

We now unset the metric, so that we can use other metrics on the same manifold.

UnsetCMetric[met]

4. Perturbation examples with xPert and xTras

4.1. Load the xPert package

Exit

SetDirectory["~/Documents/Wolfram Mathematica/xAct_1.2.0"]

<<xAct`xPert`

Let us define a set of perturbations (of arbitrary order) around the background metric g, with perturbative parameter ϵ:

DefManifold[M,4,{a,b,c,d,e,f,i,j,k,l}]

DefMetric[-1,g[-a,-b],cd]

DefMetricPerturbation[g,h,ϵ]

We can obtain the perturbations of the metric to any other:

Perturbed[g[-a,-b],3]

Perturbation[g[-a,-b],3]

It helps to color the “perturbation label indices”:

Unprotect[IndexForm];
IndexForm[LI[x_]]:=ColorString[ToString[x],Blue]

Perturbation[g[-a,-b],3]

4.3. Perturb the inverse metric

• Perturb the inverse metric:

Perturbed[g[a,b],3]

%//ExpandPerturbation

• Perturb at a specific order:

Perturbation[g[a,b],2]

%//ExpandPerturbation

• Check inversion relations:

Perturbed[g[-a,-b],3]

Perturbed[g[b,c],3]//ExpandPerturbation

% %%//Expand

%//ContractMetric//ToCanonical

Collect[%,ϵ]

4.4. Perturb the curvature tensors

We change the typesetting of Riemann, since here we are working with only one metric:

PrintAs[Riemanncd]^="R";

The first-order perturbation of Riemann is given by :

riempert1=Perturbation[Riemanncd[-a,-b,-c,d],1]

ExpandPerturbation[riempert1]

SortCovDs[%]//ToCanonical

•To get the result around flat spacetime we set the Riemann tensor to zero

%/._Riemanncd->0

• This can be imitated for higher perturbation orders:

order=2;

Perturbation[Riemanncd[-a,-b,-c,d],order]

(ExpandPerturbation[%]//Expand//SortCovDs//ToCanonical)/._Riemanncd->0

We know that the first order terms must be here somewhere, but with perturbation order 3 instead of 1:

%//ScreenDollarIndices//ColorPositions[Position[%,LI[order]][[All,{1}]]]

Now we do the clean up:

UndefTensor[h]

UndefParameter[ϵ]

UndefMetric[g]

Remove[order]

4.5. Using xPert and xTras to perform variational problems

Exit

SetDirectory["~/Documents/Wolfram Mathematica/xAct_1.2.0"]
<<xAct`xTras`

Let us start by defining the metric again.

Internally a perturbation structure is defined for it by xTras:

DefManifold[M,4,{a,b,c,d,e,f,i,j,k,l}]

DefMetric[-1,g[-a,-b],cd,CurvatureRelations->True]

PrintAs[Riemanncd]^="R";
PrintAs[Riccicd]^="R";
PrintAs[RicciScalarcd]^="R";
PrintAs[Einsteincd]^="G";

Now we can use the extended VarD command of xTras. Integrations by parts performed with the given connection:

VarD[g[-a,-b],cd][RicciScalarcd[]]

?VarD

?VarL

There is also a version that takes care of the determinants of the metric:

VarL[g[-a,-b]][RicciScalarcd[]]

%//RicciToEinstein//ToCanonical

Thus, setting this varation to zero gives the vacuum Einstein equations.

We can use this command to obtaint the e.o.m for more complicated terms in the action.

Let us give a couple of examples. Consider the variation of Ricci square:

s1=Riccicd[-a,-b]Riccicd[a,b]

VarL[g[-a,-b]][s1]

%//ContractMetric//ToCanonical

Now consider the Riemann square:

s2=Riemanncd[-a,-b,-c,-d]Riemanncd[a,b,c,d]

VarL[g[-a,-b]][s2]

%//ContractMetric//ToCanonical

The above shows the usefullness of this to study the equations of motion of theories based on Langrangians other than the Einstein-Hilbert Lagrangian.

Thank You