General remarks
In General Relativity we work in a 4-dimentional Lorentzian manifold i.e. there is a metric tensor $g$ of signature $(+,-,-,-)$ or $(-,+,+,+)$. Theses signatures are mathematically equivalent and we choose the latter because of certain quite formal aspects even though there are some physically relevant reasons for choosing the former one. In a neighbourhood of any point we choose a local chart $xx = (x^{1},x^{2},x^{3},x^{4})$ where the metric tensor is represented by real functions $g_{\alpha\beta}(x^{\mu})$ i.e. $g = g_{\alpha\beta}(x^{\mu}) dx^{\alpha}\otimes dx^{\beta}$ (We enumerate indices by $1,2,3,4$ unlike traditionally $0,1,2,3$ for representing tensors in Mathematica
by Table
s and accessing their entries by Part
e.g. [[1,1]]
). Now assuming the Einstein notation we need the following objects :
- inverse metric $g^{\mu \nu}$ : (i.e. $g^{\mu \nu} g_{\nu\alpha} = \delta^{\mu}_{\alpha} )\quad$ (
InverseMetric[g][[μ, ν]]
)
- Christoffel symbols (of the second kind) $\Gamma^{\mu}_{\phantom{\mu}\nu\sigma}=\frac{1}{2}g^{\mu\alpha}\left\{\frac{\partial g_{\alpha\nu}}{\partial x^{\sigma}}+\frac{\partial g_{\alpha\sigma}}{\partial x^{\nu}}-\frac{\partial g_{\nu\sigma}}{\partial x^{\alpha}}\right\}\quad$ (
ChristoffelSymbol[g, xx][[μ, ν, σ]]
)
Riemann tensor $R^{\mu}_{\phantom{\mu}\nu\lambda\sigma}=\partial_{\lambda}\Gamma^{\mu}_{\phantom{\mu}\nu\sigma}-\partial_{\sigma}
\Gamma^{\mu}_{\phantom{\mu}\nu\lambda}+\Gamma^{\mu}_{\phantom{\mu}\rho\lambda}\Gamma^{\rho}_{\phantom{\mu}\nu\sigma}-\Gamma^{\mu}_{\phantom{\mu}\rho\sigma}\Gamma^{\rho}_{\phantom{\mu}\nu\lambda}\quad$
( RiemannTensor[g, xx][[μ, ν, λ, σ]]
)
Ricci tensor $R_{\mu\nu}=R^{\lambda}_{\phantom{\lambda}\mu\lambda\nu}\quad$ ( RicciTensor[g, xx][[μ, ν]]
)
- Ricci scalar $R = R^{\mu}_{\phantom{\lambda}\mu}\quad$ (
RicciScalar[g, xx]
)
A straightforward implementation
It will be convenient to define geometrical objects in the following order (this may become a frame for developing a package):
InverseMetric[ g_] := Simplify[ Inverse[g] ]
ChristoffelSymbol[g_, xx_] :=
Block[{n, ig, res},
n = 4; ig = InverseMetric[ g];
res = Table[(1/2)*Sum[ ig[[i,s]]*(-D[ g[[j,k]], xx[[s]]] +
D[ g[[j,s]], xx[[k]]]
+ D[ g[[s,k]], xx[[j]]]),
{s, 1, n}],
{i, 1, n}, {j, 1, n}, {k, 1, n}];
Simplify[ res]
]
RiemannTensor[g_, xx_] :=
Block[{n, Chr, res},
n = 4; Chr = ChristoffelSymbol[ g, xx];
res = Table[ D[ Chr[[i,k,m]], xx[[l]]]
- D[ Chr[[i,k,l]], xx[[m]]]
+ Sum[ Chr[[i,s,l]]*Chr[[s,k,m]], {s, 1, n}]
- Sum[ Chr[[i,s,m]]*Chr[[s,k,l]], {s, 1, n}],
{i, 1, n}, {k, 1, n}, {l, 1, n}, {m, 1, n}];
Simplify[ res]
]
RicciTensor[g_, xx_] :=
Block[{Rie, res, n},
n = 4; Rie = RiemannTensor[ g, xx];
res = Table[ Sum[ Rie[[ s,i,s,j]],
{s, 1, n}], {i, 1, n}, {j, 1, n}];
Simplify[ res]
]
RicciScalar[g_, xx_] :=
Block[{Ricc,ig, res, n},
n = 4; Ricc = RicciTensor[ g, xx]; ig = InverseMetric[ g];
res = Sum[ ig[[s,i]] Ricc[[s,i]], {s, 1, n}, {i, 1, n}];
Simplify[res]
]
Following this way one could define another interesting geometrical objects e.g. the Weyl tensor $
C_{\mu\nu\lambda\sigma}=R_{\mu\nu\lambda\sigma}-\left(g_{\mu[\lambda}R_{\nu]\sigma}-g_{\nu[\lambda}R_{\sigma]\mu}\right)+\frac{1}{3}R g_{\mu[\lambda}g_{\nu]\sigma}$
Schwarzschild-like ansatz for a static spherically symmetric spacetime
In order to start with a concrete example let's define coordinates and a metric tensor of 4-dimensional static spherically symmetric Lorentzian spacetime :
xx = {t, x, θ, ϕ};
g = { {-E^(2 ν[x]), 0 , 0, 0},
{ 0, E^(2 λ[x]), 0, 0},
{ 0, 0, x^2, 0},
{ 0, 0, 0, x^2 Sin[θ]^2}};
Now let's compute RicciScalar
:
RicciScalar[g, xx]
If you want to solve Einstein
equations of a vacuum spacetime (e.g. the Schwarzschild spacetime) you should solve equations : RicciTensor[g, xx] == 0
.
RicciTensor[g, xx]
Now you have to choose two independent equations, e.g.
eqs={ λ'[x] ( 2 + x ν'[x]) -x ( ν'[x]^2+ ν''[x]), -1 + E^(2 λ[x]) + x ( λ'[x] - ν'[x])};
and solve this system of ordinary differential equations :
eqs[[1]] == 0;
eqs[[2]] == 0;
with appropriate boundary conditions. In case of the Schwarzschild solution that should be g -> g0
at infinity, where g0
is the Minkowski metric.
de-Sitter spacetime
Let's find e.g. scalar curvature of de-Sitter spacetime (a
is a constant):
Clear[g]
g = {{-(1 - x^2/a^2), 0, 0, 0},
{ 0, 1/(1 - x^2/a^2), 0, 0},
{ 0, 0, x^2, 0},
{ 0, 0, 0, x^2 Sin[θ]^2}};
RicciScalar[g, xx]
12/a^2
Thus we have shown that de-Sitter spacetime has a constant scalar curvature.