The xAct project

Tensor analysis is the essential language in very important branches of Mathematics & Physics:

Field theory.

General relativity.

Continuum mechanics.

Differential Geometry.

The xAct project

xAct is a suite of packages written in the WL with the purpose of doing tensor analysis by computer:

14+ years of development.

500+ different commands and 35000 lines of Wolfram language code.

340+ scientific papers using xAct. See http://www.xact.es/articles.html

2100+ posts in the xAct forum. See https://groups.google.com/forum/?hl=en#!forum/xAct

Full information about the xAct system in www.xact.es

Syllabus

The xAct system: efficient tensor computer algebra for the Wolfram Language.

Introduction to the Wolfram Language.

xTensor: coordinate-free tensor analysis.

xTensor and its data types: working with tensors and covariant derivatives. Canonicalization of plain tensorial expressions.

Working with a single and multiple metric tensors. Canonicalization of expressions with a metric tensor.

Canonicalization of expressions with covariant derivatives.

Pattern indices. Implementation of general tensorial rules.

Constant symbols, inert heads, parameters and scalar functions. Lie brackets and vector contraction of tensor slots.

The variational derivative. Working examples with the Einstein-Hilbert action (Palatini formalism), f(R) theory and Lovelock gravity.

xCoba: tensor analysis in coordinates.

Component computations with xCoba. Storage of components: the tensor values framework and the CTensor container.

The containers CTensor and CCovD and their converters. The xCoba cache system.

Application: curvature computations with xCoba.

xTerior: exterior calculus in the Wolfram Language and its applications.

The exterior algebra. Differential forms. Changes of coordinates.

Basic operations with differential forms: the exterior derivative, the inner contraction and the Lie derivative.

Cartan structure equations.

Hodge duality. The co-differential. The Hodge Laplacian.

Tensor valued differential forms. The exterior covariant derivative.

Application: formulation of the Einstein’s equations with differential forms.

Bibliography

A. García-Parrado, J.M.Martín-García:  Spinors: A Mathematica package for doing spinor calculus in General Relativity. https://doi.org/10.1016/j.cpc.2012.04.024

R. Maeder: Computer Science with Mathematica, Cambridge University Press, Cambridge (2000).

J. M. Martín-García: xAct: Efficient tensor computer algebra for the Wolfram Language http://www.xact.es

A. García-Parrado: A course about the xAct system  http://xact.es/xActCourse_Prague/

J.M.Martín-García:  xPerm: fast index canonicalization for tensor computer algebra. https://doi.org/10.1016/j.cpc.2008.05.009

Sample session in xTensor

We load xTensor. All necessary xAct packages are automatically loaded.

Exit

<<xAct`xTensor`

Some initial set-up:

$PrePrint=ScreenDollarIndices;

We declare a 4-dimensional manifold and define a tensor:

DefManifold[M4,4,{a,b,c,d,f,g}]

DefTensor[T[a,-b],M4]

Canonicalization of arbitrary tensor expressions taking into account tensor symmetries and dummy index manipulations:

expr=T[a,-b]T[b,-c]-T[a,-d]T[d,-c]

%//ToCanonical

ToCanonical is the most important command of the xAct system:

?ToCanonical

Full support for covariant derivatives:

DefCovD[cd[-a],{"|","D"}]

Canonicalization of tensorial expressions involving covariant derivatives:

cd[-a]@expr

%//ToCanonical

Introducing a metric tensor:

DefMetric[-1,metricg[-a,-b],CD,{"|","∇"},PrintAs->"g"]

A number of tensorial quantities are automatically defined. The Einstein tensor:

EinsteinCD[-a,-b]

Write Einstein tensor in terms of the Ricci tensor:

%//EinsteinToRicci

Explicit expansion into generic coordinates:

NoScalar@ChangeCurvature[%]

ChristoffelToGradMetric[%]

ToCanonical@ContractMetric@%

Ricci identities for arbitrary covariant derivatives:

CD[-a]@CD[-b]@T[c,-d]-CD[-b]@CD[-a]@T[c,-d]

%//SortCovDs

cd[-a]@cd[-b]@T[c,-d]-cd[-b]@cd[-a]@T[c,-d]

%//SortCovDs

Exit

Working with coordinates

Kerr in Boyer-Lindquist coordinates

Needs["xAct`xCoba`"]

<<xAct`ShowTime1`

$DefInfoQ=$UndefInfoQ=False;

Define manifold & coordinates:

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

DefChart[BL,M,{0,1,2,3},{t[],r[],θ[],ϕ[]}]

BL/:CIndexForm[0,BL]="t";BL/:CIndexForm[1,BL]="r";BL/:CIndexForm[2,BL]="θ";BL/:CIndexForm[3,BL]="φ";

Define metric parameters:

DefConstantSymbol[Mass,PrintAs->"M"]
DefConstantSymbol[Rotation,PrintAs->"a"]

Define metric functions:

Deltar=(r[]^2+Rotation^2)-2 Mass r[];
Sigma=r[]^2+Rotation^2Cos[θ[]]^2;

Introduce metric:

ds2=(Sigma/Deltar)dr^2+Sigma dθ^2+((Sin[θ[]]^2)/Sigma)(Rotation dt-(r[]^2+Rotation^2)dϕ)^2-(Deltar/Sigma)(dt-Rotation Sin[θ[]]^2dϕ)^2;

MatrixForm[KMatrix=CoefficientArrays[ds2,{dt,dr,dθ,dϕ},"Symmetric"->True][[3]]//Normal//Simplify]

Do computations with the metric. Use the CTensor container:

metricg=CTensor[KMatrix,{-BL,-BL}];

metricg[-a,-b]

Choose simplification algorithm:

$CVSimplify=Simplify;

SetCMetric[metricg,BL,SignatureOfMetric->{3,1,0}]

Compute Riemann tensor:

MetricCompute[metricg,BL,"Riemann"[-1,-1,-1,1],Verbose->True]

CTensor representation of the Riemann tensor:

cd=CovDOfMetric[metricg];

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

Try different index configurations:

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

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

Check vacuum condition:

Ricci[cd]

Compute Kretschmann

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

%//Simplify

Separation of variables for the Hamilton-Jacobi equation in a Kerr background

Hamilton-Jacobi equation for photon particles and its separation.

Hamilton-Jacobi function:

DefTensor[S[],M]

Canonical momenta:

DefTensor[#,M]&/@{pt[],pr[],pθ[],pφ[]};

PrintAs@pt^="(Subscript[p, t])";
PrintAs@pr^="(Subscript[p, r])";
PrintAs@pθ^="(Subscript[p, θ])";
PrintAs@pφ^="(Subscript[p, φ])";

Variable separation functions:

DefScalarFunction[Ft,PrintAs->"(Subscript[F, t])"]

DefScalarFunction[Fθ,PrintAs->"(Subscript[F, θ])"]

DefScalarFunction[Fφ,PrintAs->"(Subscript[F, φ])"]

DefScalarFunction[Fr,PrintAs->"(Subscript[F, r])"]

Hamilton-Jacobi equation for a photon:

metricg[a,b]PDBL[-a]@S[]PDBL[-b]@S[]==0

TraceBasisDummy/@(ToBasis[BL]/@%)

Collect[#,PDBL[_]@_,FullSimplify]&/@%

HamiltonJacobiBLNull=%;

HamiltonJacobiBLNull

We implement the separation variable ansatz:

SAnsatz=S[]==Ft[t[]]+Fr[r[]]+Fθ[θ[]]+Fφ[ϕ[]]

Compute the momenta in terms of the separation variables functions

{PDBL[{0,-BL}]@S[]==pt[],PDBL[{3,-BL}]@S[]==pφ[],PDBL[{2,-BL}]@S[]==pθ[],PDBL[{1,-BL}]@S[]==pr[]}

%/.(SAnsatz/.Equal->Rule)

SeparationFunctionsToMomenta=%;

HamiltonJacobiBLNull/.(SAnsatz/.Equal->Rule)

HamiltonJacobi1=%;

Variable separation constants:

DefConstantSymbol/@{k1,k2,k3,k4};

PrintAs@k1^="(Subscript[k, 1])";

PrintAs@k2^="(Subscript[k, 2])";

PrintAs@k3^="(Subscript[k, 3])";

PrintAs@k4^="(Subscript[k, 4])";

The momenta (Subscript[p, φ]) and (Subscript[p, t]) correspond to variable separation constants:

SeparationOfVariables={Derivative[1][Fφ][ϕ[]]->pφ[],Derivative[1][Ft][t[]]->pt[]}

HamiltonJacobi1/.SeparationOfVariables

%/.Rotation^2 Cos[θ[]]^2+r[]^2->Hold[Rotation^2 Cos[θ[]]^2+r[]^2]/.Rotation^2-2Mass r[]+r[]^2->Hold[Rotation^2-2Mass r[]+r[]^2]/.(Rotation^2+r[](r[]-2Mass))->Hold[Rotation^2-2Mass r[]+r[]^2]

Times[#,Hold[Rotation^2 Cos[θ[]]^2+r[]^2]]&/@%

Simplify/@Expand/@%

Expand/@%

%//ReleaseHold

MapAt[Expand,%,{1,2}]

Actual separation of variables:

{%[[1,1]]+%[[1,2]]+%[[1,-1]]==k3,%[[1,3]]+%[[1,4]]+%[[1,5]]+%[[1,6]]+%[[1,7]]+%[[1,8]]==k4}

Map[Simplify,%,{2}]

HamiltonJacobiSeparated=%;

The functions  (Subscript[F, θ])'[θ]and  (Subscript[F, r])'[r] can be obtained through quadratures.

Clearing data

UnsetCMetric@metricg

Remove[metricg,ds2,Deltar,Sigma,KMatrix]

UndefConstantSymbol[{Mass,Rotation}]

UndefTensor@JacobianBL

UndefChart[BL]

UndefMapping@iBL

UndefCovD@PDBL

UndefTensor/@$Tensors;

UndefManifold[M]

ClearxCobaCache[All]

cd=.

Working with exterior calculus

Exit

We load xTerior. All necessary xAct packages are automatically loaded.

<<xAct`xTerior`

We remove unnecessary info messages:

$DefInfoQ=False;
$UndefInfoQ=False;

$CVVerbose=False;

We declare a 3-dimensional coordinate system, with coordinates {x, y, z}. For that we use xAct Def commands to declare a manifold and a coordinate chart.

DefManifold[M3,3,{a,b,c,d,f,g}]
DefChart[Ec,M3,{1,2,3},{x[],y[],z[]}]

We are now able to work with arbitrary differential forms written in these coordinates. They are all combinations of the wedge product of coordinate differentials:

Diff[x[]]⋀Diff[y[]]

Wedge product is the Wolfram language built-in symbol Wedge, entered with Esc ^ Esc. All differential forms in these coordinates can be written as combinations of elements in the following list.

{Diff[x[]],Diff[y[]],Diff[z[]],Diff[x[]]⋀Diff[y[]],Diff[x[]]⋀Diff[z[]],Diff[y[]]⋀Diff[z[]],Diff[x[]]⋀Diff[y[]]⋀Diff[z[]]}

Basic operations

We can represent any differential form, and do operations on it.

ω=(x[]^2+y[]^2)Diff[z[]]⋀Diff[x[]]-1/(x[]^2+y[]^2)Diff[x[]]⋀Diff[y[]]

ω⋀Diff[z[]]

The Simplification command takes into account the wedge product and its special properties.

?Simplification

Simplification@%%

The degree of  a differential form is obtained with Deg:

Deg@%

The exterior derivative and its properties are implemented by means of the action of  Diff.

Diff@ω

Simplification@%

We can also work with general differential forms written in the coordinates {x,y,z}. For example, let us declare a set of scalar functions:

DefScalarFunction/@{Fx,Fy,Fz};
PrintAs@Fx^="(Subscript[F, x])";PrintAs@Fy^="(Subscript[F, y])";PrintAs@Fz^="(Subscript[F, z])";

A scalar function is a head that can take as its arguments any number of coordinates:

{Fx[x[]],Fx[x[],x[]],Fx[x[],y[],z[]]}

We can use the scalar functions to represent a generic 2-form and do operations on it:

ψ=Fx[x[],y[],z[]]Diff[y[]]⋀Diff[z[]]-Fy[x[],y[],z[]]Diff[x[]]⋀Diff[z[]]+Fz[x[],y[],z[]]Diff[x[]]⋀Diff[y[]]

Diff@ψ//Simplification

As is well-known the double exterior derivative is zero. Hence the double action of Diff yields zero

Diff@%//Simplification

More examples:

φ=Fx[x[],y[],z[]]Diff@x[]+Fy[x[],y[],z[]]Diff@y[]+Fz[x[],y[],z[]]Diff@z[]

dφ=Diff@φ//Simplification

We check that the previous expression is essentially the curl of the vector field {Fx,Fy,Fz} when regarded as a field in the Euclidean 3-space:

Curl[{Fx[x[],y[],z[]],Fy[x[],y[],z[]],Fz[x[],y[],z[]]},{x[],y[],z[]}]

And this is the divergence:

ψ

Coefficient[Diff@ψ//Simplification,Diff[x[]]⋀Diff[y[]]⋀Diff[z[]]]

Div[{Fx[x[],y[],z[]],Fy[x[],y[],z[]],Fz[x[],y[],z[]]},{x[],y[],z[]}]

UndefChart@Ec

UndefManifold@M3

Cartan structure equations

Define a manifold of symbolic dimension:

DefConstantSymbol@dim

DefManifold[M,dim,{a,b,c,d,e,f,g,h}]

We introduce a covariant derivative in our manifold using the xTensor DefCovD:

DefCovD[CD[-a],{";","D"},Torsion->True]

Once we have introduced a covariant derivative we can work with its connection 1- form and the curvature 2-form. These are tensor valued forms.

ChristoffelForm[CD][a,-b]

%//Deg

RiemannForm[CD][a,-b]

%//Deg

These elements are related by the Cartan structure equations. We can easily obtain the Cartan structure equations for a given connection by means of UseCartan.

CartanStructureEqs={Diff@Coframe[M][a]==UseCartan[Diff[Coframe[M][a]],CD],Diff@ChristoffelForm[CD][a,-b]==UseCartan[Diff[ChristoffelForm[CD][a,-b]],CD],Diff@TorsionForm[CD][a]==UseCartan[Diff[TorsionForm[CD][a]],CD],Diff@RiemannForm[CD][a,-b]==UseCartan[Diff[RiemannForm[CD][a,-b]],CD]}

We can also check the complete integrability conditions of the Cartan system.

Diff@%

UseCartan[%,CD]

ToCanonical[%]

Some of the Cartan equations can be formulated in any vector bundle. For example take a real vector bundle over the manifold M with 3 - dimensional fibres and define a covariant derivative on it:

DefVBundle[VB,M,3,{A,B,L,S,J,H}]

DefCovD[cdv[-a],VB,{"|","𝒟"}]

For a covariant derivative defined in a general vector bundle, the notation for the connection 1 - form and the curvature 2 - form is slightly different; in addition to the symbol of the covariant derivative it also contains the symbol representing the vector bundle upon which the covariant derivative is defined:

ConnectionForm[cdv,VB][A,-B]

%//Deg

CurvatureForm[cdv,VB][A,-B]

%//Deg

In this case, the Cartan equations adopt the form:

{Diff@ConnectionForm[cdv,VB][A,-B]==UseCartan[Diff@ConnectionForm[cdv,VB][A,-B],cdv],Diff@CurvatureForm[cdv,VB][A,-B]==UseCartan[Diff@CurvatureForm[cdv,VB][A,-B],cdv]}

We compute the integrability conditions of the Cartan system in this case.

Diff@%

UseCartan[%,cdv]

ToCanonical@%

Example: Hodge Laplacian in the Schwarzschild metric.

DefManifold[M4,4,{α,β,γ,δ,ν}]
DefChart[Sch,M4,{0,1,2,3},{t[],R[],Θ[],λ[]}]

DefConstantSymbol[mass,PrintAs->"M"]

Metric tensor in Matrix form:

Smet={{-1+mass/R[],0,0,0},{0,(1-mass/R[])^(-1),0,0},{0,0,R[]^2,0},{0,0,0,R[]^2 Sin[Θ[]]^2}}

We declare this as a metric tensor.

Smet=CTensor[Smet,{-Sch,-Sch}]

SetCMetric[Smet,Sch,SignatureOfMetric->{3,1,0}]

We use the command UseDimensionStart to get rid of forms whose degree is higher than the dimension of the manifold.

UseDimensionStart[]

Computation of the Hodge Laplacian (dδ+δd)ϕ of the scalar ϕ

DefScalarFunction[Φ]

Diff@Codiff[Smet][Φ@@ScalarsOfChart@Sch]+Codiff[Smet]@Diff[Φ@@ScalarsOfChart@Sch]

We express the co-differential in terms of exterior derivatives and Hodge duals and next we work out the Hodge duals:

CodiffToDiff@%

ExpandHodgeDual[%,dx[M4],Smet];

ExpandHodgeDual[%,dx[M4],Smet]

Simplify//@%

We clear all the symbols used so far:

UnsetCMetric/@$Metrics;

UseDimensionStop[]

UndefChart/@$Charts;

UndefBasis/@$Bases;

UndefCovD/@Rest@$CovDs;

UndefTensor/@$Tensors;

VisitorsOf@M

UndefVBundle@VB;

UndefManifold/@$Manifolds;

ω=.