Curvature and the Einstein Equation

This is the Mathematica notebook Curvature and the Einstein Equation available from the book website.  From a given metric (Subscript[g, αβ]) , it computes the components of the following: the inverse metric, (g^(λσ)), the Christoffel symbols or affine connection,

(Subscript[(Γ^λ), μν])=(1/2)(g^(λσ))((∂_μ)(Subscript[g, σν])+(∂_ν)(Subscript[g, σμ])-(∂_σ)(Subscript[g, μν])),

( (∂_(α  ))stands for the partial derivative ∂/∂(x^α)), the Riemann tensor,

(Subscript[(R^λ), μνσ])=(∂_ν) (Subscript[(Γ^λ), μσ])-(∂_σ) (Subscript[(Γ^λ), μν])+(Subscript[(Γ^η), μσ])(Subscript[(Γ^λ), ην])-(Subscript[(Γ^η), μν])(Subscript[(Γ^λ), ησ]),

the Ricci tensor

(Subscript[R, μν])=(Subscript[(R^λ), μλν]),

the scalar curvature,

R=(g^(μν))(Subscript[R, μν]),

and the Einstein tensor,

(Subscript[G, μν])=(Subscript[R, μν])-(1/2)(Subscript[g, μν])R.

You must input the covariant components of the metric tensor (Subscript[g, μν]) by editing the relevant input line in this Mathematica notebook. You may also wish to change the names of the coordinates. Only the nonzero components of the above quantities are displayed as the output. All the components computed are in the coordinate basis in which the metric was specified.

Clearing the values of symbols:

First clear any values that may already have been assigned to the names of the various objects to be calculated. The names of the coordinates that you will use are also cleared.

Clear[coord, metric,inversemetric, affine, riemann, ricci,scalar, einstein,z,t,x1,x2,x3]

Setting the dimension:

The dimension n of the spacetime (or space) must be set:

n=4

Defining a list of coordinates:

The example given here is the Schwarzschild metric. The coordinate choice of Schwarzschild is appropriate for this spherically symmetric spacetime.

coord = {t,r,θ,ϕ}

You can change the names of the coordinates by simply editing the definition of coord, for example, to coord = {x, y, z, t}, when another set of coordinate names is more appropriate. In this program indices range over 1 to n.  Thus for spacetime they range from 1 to 4 and (x^4) is the same as (x^0) used in the text.

Defining the metric:

Input the metric as a list of lists, i.e., as a matrix. You can input the components of any metric here, but you must specify them as explicit functions of the coordinates.

metric={{-(1 - 2 G M/r),0,0,0},{0,(1 - 2 G M/r)^(-1),0,0},{0,0,r^2, 0},{0,0,0,r^2 Sin[θ]^2}}

You can also display this in matrix form.

metric//MatrixForm

Note:

It is important not to use the symbols, i, j, k, l, s, or n as constants or coordinates in the metric that you specify above. The reason is that the first five of  those symbols are used as summation or table indices in the calculations done below, and n is the dimension of the space. For example, if m were used as a summation or table index below, then you would get the wrong answer for the present metric because the m in the metric would be treated as an index, rather than as the mass.

Calculating the inverse metric:

The inverse metric is obtained through matrix inversion.

inversemetric=Simplify[Inverse[metric]]

This can also be displayed in matrix form:

inversemetric//MatrixForm

Calculating the Christoffel symbols:

The calculation of the components of the Christoffel symbols is done by transcribing the definition given earlier into the notation of Mathematica and using the Mathematica functions D for taking partial derivatives, Sum for summing over repeated indices, Table for forming a list of components, and Simplify for simplifying the result.

affine:=affine=Simplify[Table[(1/2)*Sum[(inversemetric[[i,s]])*
(D[metric[[s,j]],coord[[k]] ]+
D[metric[[s,k]],coord[[j]] ]-D[metric[[j,k]],coord[[s]] ]),{s,1,n}],
{i,1,n},{j,1,n},{k,1,n}] ]

Displaying the Christoffel symbols:

The nonzero Christoffel symbols are displayed below. You need not follow the details of constructing the functions that we use for that purpose.  In the output the symbol Γ[1,2,3] stands for (Subscript[(Γ^1), 23]). Because the Christoffel symbols are symmetric under interchange of the last two indices, only the independent components are displayed.

listaffine:=Table[If[UnsameQ[affine[[i,j,k]],0],{ToString[Γ[i,j,k]],affine[[i,j,k]]}] ,{i,1,n},{j,1,n},{k,1,j}]

TableForm[Partition[DeleteCases[Flatten[FullSimplify[listaffine]],Null],2],TableSpacing->{2,2}]

Calculating and displaying the Riemann tensor:

The components of the Riemann tensor, (Subscript[(R^λ), μνσ]), are calculated using the definition given above.

riemann:=riemann=Simplify[Table[
D[affine[[i,j,l]],coord[[k]] ]-D[affine[[i,j,k]],coord[[l]] ]+
Sum[affine[[s,j,l]] affine[[i,k,s]]-affine[[s,j,k]] affine[[i,l,s]],
{s,1,n}],
{i,1,n},{j,1,n},{k,1,n},{l,1,n}] ]

The nonzero components are displayed by the following functions. In the output, the symbol R[1, 2, 1, 3] stands for (Subscript[(R^1), 213]), and similarly for the other components. You can obtain R[1, 2, 3, 1] from R[1, 2, 1, 3] using the antisymmetry of the Riemann tensor under exchange of the last two indices. The antisymmetry under exchange of the first two indices of (Subscript[R, λμνσ]) is not evident in the output because the components of (Subscript[(R^λ), μνσ]) are displayed.

listriemann:=Table[If[UnsameQ[riemann[[i,j,k,l]],0],{ToString[R[i,j,k,l]],riemann[[i,j,k,l]]}] ,{i,1,n},{j,1,n},{k,1,n},{l,1,k-1}]

TableForm[Partition[DeleteCases[Flatten[listriemann],Null],2],TableSpacing->{2,2}]

Calculating and displaying the Ricci tensor:

The Ricci tensor (Subscript[R, μν]) was defined by summing the first and third indices of the Riemann tensor (which has the first index already raised).

ricci:=ricci=Simplify[Table[Sum[riemann[[i,j,i,l]],{i,1,n}],{j,1,n},{l,1,n}] ]

Next we display the nonzero components. In the output, R[1, 2] denotes (Subscript[R, 12]), and similarly for the other components.

listricci:=Table[If[UnsameQ[ricci[[j,l]],0],{ToString[R[j,l]],ricci[[j,l]]}] ,{j,1,n},{l,1,j}]

TableForm[Partition[DeleteCases[Flatten[listricci],Null],2],TableSpacing->{2,2}]

A vanishing table (as with the Schwarzschild metric example)  means that the vacuum Einstein equation is satisfied.

Calculating the scalar curvature:

The scalar curvature R is calculated using the inverse metric and the Ricci tensor. The result is displayed in the output line.

scalar=Simplify[Sum[inversemetric[[i,j]]ricci[[i,j]],{i,1,n},{j,1,n}] ]

Calculating the Einstein tensor:

The Einstein tensor,  (Subscript[G, μν])=(Subscript[R, μν])-(1/2)(Subscript[g, μν])R, is found from the tensors already calculated.

einstein:=einstein=Simplify[ricci-(1/2)scalar*metric]

The results are displayed in the same way as for the Ricci tensor earlier.

listeinstein:=Table[If[UnsameQ[einstein[[j,l]],0],{ToString[G[j,l]],einstein[[j,l]]}] ,{j,1,n},{l,1,j}]

TableForm[Partition[DeleteCases[Flatten[listeinstein],Null],2],TableSpacing->{2,2}]

A vanishing table means that the vacuum Einstein equation is satisfied!

Calculating the Square of the Riemann Tensor

riemmsq = Sum[metric[[α, i]] inversemetric[[β, j]] inversemetric[[γ, j]]inversemetric[[δ, k]] riemann[[i,j,k,l]]riemann[[α,β,γ,δ]], {i, 1, n}, {j, 1, n}, {k, 1, n}, {l, 1, n}, {α, 1, n}, {β, 1, n}, {γ, 1, n}, {δ, 1, n}]//Simplify

Acknowledgment

This program was kindly written by Leonard Parker, University of Wisconsin, Milwaukee especially  for this text.