Applications of xAct in GR and beyond

General Relativity - Refresher Course

Apratim Ganguly, IUCAA

23 June - 5 July, 2025

Chapter 1 - xAct`xTensor`

xTensor extends Mathematica capabilities in abstract tensor calculus, focusing on General Relativity.
	
	Read the documentation:
	Full documentation:  xTensorDoc.nb
	The reference notebook is also useful:  xTensorRefGuide.nb

Loading the package

<<xAct`xTensor`

$PrePrint=ScreenDollarIndices;

Check packages are read in the correct order

$ContextPath

xCore: generic programming tools for the rest of the system  (full documentation: xCoreDoc.nb)
	xPerm: computations with large groups of permutations (full documentation:  xPermDoc.nb)

Search for documentation

?xAct`xTensor`*

Hierarchy of objects

1. Manifolds: Let us define a 4D manifold

? DefManifold

DefManifold[M4l,4,{a,b,c,d}]

You can put as many and whatever indices you want.

DefManifold[M4g,4,{α,β,γ,δ}]

? M4l

$Manifolds

2. Vector Bundle (VBundle)
		
		For example, a tangent bundle is associated with the manifold. xAct defines objects by creating Heads that have names related to the definition of the names of the Manifold, the metric, the covariant derivative, etc.

? TangentM4l

3. Abstract Indices

? a

$AbstractIndices

4. Tensor: 
		
		Define (1,0) and (0,1) tensors:

DefTensor[v[a],M4l]
DefTensor[u[-a], M4l]

? v

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

Define (0,2) and (2,0) tensors, we can specify certain symmetries of their indices:

DefTensor[F[a,b],M4l,Antisymmetric[{a,b}]]; (* antisymmetric in a,b *)
DefTensor[S[-a,-b],M4l,         Symmetric[{-a,-b}]];   (* symmetric in a,b *)
{F[a,b],S[-a,-b]}

?F

Let’s try more:

DefTensor[𝒮[a,-b, -c],M4l,Symmetric[{-b,-c}]];  (* can also use PrintAs -> "..."*)
𝒮[a,-b,-c]

If you don’t need a tensor anymore, or you need to redefine it, you have to “undefine” it first, using UndefTensor:

UndefTensor[𝒮]

You can define a scalar field, a constant scalar field (defined with a manifold and its derivative is 0) and a constant

DefTensor[ϕ[],M4l];DefTensor[𝒞[],{}] ; DefConstantSymbol[ℏ];
{ϕ[],𝒞[],ℏ}

5. Metric: define a metric (Subscript[g, ab]) and a metric compatible, torsion free covariant derivative CD.  A lot of things gets defined, read the output.  -1 (first argument) determines the signature.

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

Repeated indices are contracted

F[-a,-b]v[a]v[b]//ToCanonical

F[-a,-b]S[a,b]//ToCanonical

F[a,b]F[-b,-a]//ToCanonical

F[a,b]F[-b,-c]F[c,-a]//ToCanonical   (*odd number of tensors*)

Validate tensorial expressions

{v[a]v[b]//Validate,v[a]v[-a]//Validate, v[a]v[a]//Validate,v[-a] v[-a]//Validate}

{S[a,-b]//Validate, S[a,-a]//Validate, S[-a,-a]//Validate}

Riemann Tensor, defined as an antisymmetric tensor by default

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

DefTensor[x[a],M4l];DefTensor[y[-a], M4l];

RiemannCD[-a,-b,-c,d] v[a] u[b] x[c] y[-d]

{RiemannCD[-a,-b,-c,d] v[a] v[b] x[c] y[-d], RiemannCD[-a,-b,-c,d] v[a] v[b] x[c] y[-d]//ToCanonical}

{RiemannCD[-a,-b,-c,-d] v[a] v[b] x[c] y[d], RiemannCD[-a,-b,-c,-d] v[a] v[b] x[c] y[d]//ToCanonical}

Challenge: (Subscript[R, abcd ])(F^ac) (u^b)(u^d)=(Subscript[R, cdab])(F^ac) (u^b)(u^d)=-(Subscript[R, cdab])(F^ca) (u^b)(u^d)=-(Subscript[R, adcb])(F^ac) (u^b)(u^d)=-(Subscript[R, abcd])(F^ac) (u^d)(u^b)=0

Kronecker delta

Defined as: ((Subscript[δ, a])^b)

delta[-a,b]

delta[-a,a]

delta[-a,b]x[-b]

Generalised delta: ((Subscript[δ, a1 a2 ... an ])^(b1 b2 ... bn))=n!((Subscript[δ, [a1])^b1)((Subscript[δ, a2])^b2)...((Subscript[δ, an]])^bn)

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

ExpandGdelta[Gdelta[-a,-b,c,d]]

Levi-Civita tensor

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

epsilong[-a,-b,-c,-d]g[a,b]//ToCanonical

Challenge: (Subscript[ϵ, abcd]) (ϵ^mncd)=?, (Subscript[ϵ, abcd]) (ϵ^mbcd)=?, (Subscript[ϵ, abcd]) (ϵ^abcd)=?

Metric contractions

g[-a,-b]g[b,c]

g[-a,a]

{g[-a,-b]v[b],g[-a,-b]v[b]//ContractMetric, g[a,b]v[-b]//ContractMetric}

{g[a,b]F[-b,-c], g[a,b]F[-b,-c]//ContractMetric}

{g[a,b]F[-c,-a]v[-b], g[a,b]F[-c,-a]v[-b]//ContractMetric}

{g[a,b]g[c,d]F[-b,-d], g[a,b]g[c,d]F[-b,-d]//ContractMetric}

{RiemannCD[-a,-b,-c,-d]g[b,c], RiemannCD[-a,-b,-c,-d]g[b,c]//ContractMetric}

RicciCD[-a,-b]g[a,b]

Predefined ordinary, flat, partial derivative, with zero torsion and curvature. This is only defined locally

PD[-a][ F[b,-c] ]

PD[-a][ PD[-b][ F[c,-d] ] ]

{PD[-a][ϕ[]],PD[-a][v[b]], PD[-a][ϕ[]v[b]], PD[-a][u[b]v[c]]}

{PD[-a][PD[-b][u[c]]]-PD[-b][PD[-a][u[c]]], PD[-a][PD[-b][u[c]]]-PD[-b][PD[-a][u[c]]]//ToCanonical} (*partial derivatives are commutative*)

Christoffel Connection

{ChristoffelCD[a,-b,-c],ChristoffelCD[-a,-b,-c]}

{ChristoffelCD[a,-b,-c], ChristoffelCD[-a,-b,-c]}//ChristoffelToGradMetric

Covariant Derivative

{CD[-a][ϕ[]],CD[-a][v[b]],CD[-a][u[-b]], CD[-a][ϕ[]v[b]],CD[-a][u[-b]v[c]]}

CD[-a][ϕ[]]//CovDToChristoffel

{CD[-a][v[b]], CD[-a][u[-b]]}//CovDToChristoffel

{CD[-a][v[b]], CD[-a][u[-b]]}//CovDToChristoffel//ChristoffelToGradMetric

{CD[-a][ℏ],CD[-a][ℏ ϕ[]],CD[-a][ℏ v[b]]}

{CD[-a][F[-b,-c]],CD[-a][v[b]F[-c,-d]]}

CD[-a][F[-b,-c]]//CovDToChristoffel

CD[-a][F[-b,-c]]//CovDToChristoffel//ChristoffelToGradMetric

Another equivalent notation (using @)

CD[-a]@v[b]

CD[-a]@CD[-b]@CD[-c]@v[d]

CD[-a]@CD[-b]@CD[-c]@v[d]//CovDToChristoffel//ChristoffelToGradMetric

Lie Derivative

{LieD[v[a]][u[b]],LieD[v[a]][F[b,c]],LieD[v[a]][u[b]F[c,d]]}

{LieD[v[a]][u[b]],LieD[v[a]][F[b,c]],LieD[v[a]][u[b]F[c,d]]}//LieDToCovD

LieDToCovD[LieD[v[a]][u[b]],CD] (*demand the expression in terms of CD*)

LieDToCovD[LieD[v[a]][F[b,c]],CD]

Compute the Lie bracket

Bracket[u[a],v[b]][c]

Bracket[u[a],v[b]][c]//BracketToCovD

BracketToCovD[Bracket[u[a],v[b]][c],CD]

Challenge: Prove that (Subscript[ℒ, [a,b]])ξ=[(Subscript[ℒ, a]),(Subscript[ℒ, b])]ξ

Disclaimer: The tutorials presented in this course are not the original work of the instructor. Most of the material are adapted from resources available at https://xact.es/.