Processing math: 100%
Cadabra
a field-theory motivated approach to computer algebra

The Schwarzschild spacetime

This notebook shows how you can do component computations in Cadabra. It illustrates this by computing properties of the Schwarzschild spacetime. The first thing we always need to do is to declare the coordinates used, and the names of the indices.
{r,t,\phi,\theta}::Coordinate; {\mu,\nu,\rho,\sigma,\lambda,\kappa,\chi,\gamma}::Indices(values={t,r,\phi,\theta}, position=fixed); \partial{#}::PartialDerivative; g_{\mu\nu}::Metric. g^{\mu\nu}::InverseMetric.
Property Coordinate attached to [r,t,ϕ,θ].
Property Indices(position=fixed) attached to [μ,ν,ρ,σ,λ,κ,χ,γ].
Property PartialDerivative attached to partial{#}.
Below is the Schwarzschild metric in standard coordinates. Note how the components are given in terms of substitution rules, and how the inverse metric is computed. The complete algorithm adds the rules for the inverse metric to the rules for the metric.
ss:= { g_{t t} = -(1-2 M/r), g_{r r} = 1/(1-2 M/r), g_{\theta\theta} = r**2, g_{\phi\phi}=r**2 \sin(\theta)**2 }. complete(ss, $g^{\mu\nu}$);
[gtt=1+2Mr1,grr=(12Mr1)1,gθθ=r2,gϕϕ=r2(sinθ)2,gtt=(2Mr11)1,grr=2Mr1+1,gϕϕ=(r2(sinθ)2)1,gθθ=r2]
We can now compute the Christoffel symbols. We give Cadabra the expression for the Christoffel symbols in terms of the metric, and then evaluate the components of the metric using the evaluate algorithm.
ch:= \Gamma^{\mu}_{\nu\rho} = 1/2 g^{\mu\sigma} ( \partial_{\rho}{g_{\nu\sigma}} +\partial_{\nu}{g_{\rho\sigma}} -\partial_{\sigma}{g_{\nu\rho}} ): evaluate(ch, ss, rhsonly=True);
Γμνρ=12gμσ(ρgνσ+νgρσσgνρ)
Γμνρ=νρμ{ϕrϕ=r1ϕθϕ=(tanθ)1θrθ=r1rrr=M(r(2Mr))1trt=M(r(2M+r))1rϕϕ=r1θϕϕ=(tanθ)1rθθ=r1rtt=M(r(2M+r))1ϕϕr=(2Mr)(sinθ)2ϕϕθ=12sin(2θ)θθr=2Mrttr=M(2M+r)r3
Continuing from here we can compute the Riemann tensor components. Again, we start by giving this tensor in terms of the Christoffel symbols. We then subsitute the Christoffel symbols just found, and work out any remaining component substitions using evaluate (the computation takes a few seconds, essentially because of the round trips through Sympy).
rm:= R^{\rho}_{\sigma\mu\nu} = \partial_{\mu}{\Gamma^{\rho}_{\nu\sigma}} -\partial_{\nu}{\Gamma^{\rho}_{\mu\sigma}} +\Gamma^{\rho}_{\mu\lambda} \Gamma^{\lambda}_{\nu\sigma} -\Gamma^{\rho}_{\nu\lambda} \Gamma^{\lambda}_{\mu\sigma};
Rρσμν=μΓρνσνΓρμσ+ΓρμλΓλνσΓρνλΓλμσ
substitute(rm, ch) evaluate(rm, ss, rhsonly=True);
Rρσμν=νσρμ{ttrr=2M(2Mr)r4θθrr=Mr1ϕϕθθ=2M(sinθ)2r1ϕϕrr=M(sinθ)2r1trtr=2M(r2(2Mr))1ϕθϕθ=2Mr1rtrt=2M(2M+r)r4rθrθ=Mr1θϕθϕ=2M(sinθ)2r1rϕrϕ=M(sinθ)2r1rrtt=2M(r2(2M+r))1rrθθ=M(r2(2Mr))1θθϕϕ=2Mr1rrϕϕ=M(r2(2Mr))1ttϕϕ=M(2M+r)r4ttθθ=M(2M+r)r4ϕϕtt=M(sinθ)2r1θθtt=Mr1ϕrϕr=M(r2(2M+r))1ϕtϕt=M(2Mr)r4θrθr=M(r2(2M+r))1θtθt=M(2Mr)r4tϕtϕ=M(sinθ)2r1tθtθ=Mr1
The Ricci tensor should of course vanish as the Schwarzschild solution is a vacuum solution. Following the same logic as above, this is easily verified:
rc:= R_{\sigma\nu} = R^{\rho}_{\sigma\rho\nu}; substitute(rc, rm) evaluate(rc, ss, rhsonly=True);
Rσν=Rρσρν
Rσν=0
More interesting is the Kretschmann scalar.
K:= K = R^{\mu}_{\nu\rho\sigma} R^{\lambda}_{\kappa\gamma\chi} g_{\mu\lambda} g^{\nu\kappa} g^{\rho\gamma} g^{\sigma\chi};
K=RμνρσRλκγχgμλgνκgργgσχ
substitute(K, rm) evaluate(K, ss, rhsonly=True);
K=48M2r6
This shows that r=0 is a true singularity.
You could have computed the Riemann tensor in a different way, first expanding it fully in terms of the metric tensor, and then substituting the components. This is a bit more wasteful on resources, but of course gives the same result:
rm:= R^{\rho}_{\sigma\mu\nu} = \partial_{\mu}{\Gamma^{\rho}_{\nu\sigma}} -\partial_{\nu}{\Gamma^{\rho}_{\mu\sigma}} +\Gamma^{\rho}_{\mu\lambda} \Gamma^{\lambda}_{\nu\sigma} -\Gamma^{\rho}_{\nu\lambda} \Gamma^{\lambda}_{\mu\sigma};
Rρσμν=μΓρνσνΓρμσ+ΓρμλΓλνσΓρνλΓλμσ
ch:= \Gamma^{\mu}_{\nu\rho} = 1/2 g^{\mu\sigma} ( \partial_{\rho}{g_{\nu\sigma}} +\partial_{\nu}{g_{\rho\sigma}} -\partial_{\sigma}{g_{\nu\rho}} );
Γμνρ=12gμσ(ρgνσ+νgρσσgνρ)
substitute(rm, ch);
Rρσμν=12μ(gρλ(σgνλ+νgσλλgνσ))12ν(gρλ(σgμλ+μgσλλgμσ))+14gρκ(λgμκ+μgλκκgμλ)gλχ(σgνχ+νgσχχgνσ)14gρκ(λgνκ+νgλκκgνλ)gλχ(σgμχ+μgσχχgμσ)
evaluate(rm, ss, rhsonly=True)
K:= K = R^{\mu}_{\nu\rho\sigma} R^{\lambda}_{\kappa\gamma\chi} g_{\mu\lambda} g^{\nu\kappa} g^{\rho\gamma} g^{\sigma\chi};
K=RμνρσRλκγχgμλgνκgργgσχ
substitute(K, rm) evaluate(K, ss);
K=48M2r6
Copyright © 2001-2025 Kasper Peeters
Questions? info@cadabra.science