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.
\[{}\text{Attached property Coordinate to }\left\{r, \mmlToken{mo}[linebreak="goodbreak"]{} t, \mmlToken{mo}[linebreak="goodbreak"]{} \phi, \mmlToken{mo}[linebreak="goodbreak"]{} \theta\right\}.\]
\[{}\text{Attached property Indices(position=fixed) to }\left\{\mu, \mmlToken{mo}[linebreak="goodbreak"]{} \nu, \mmlToken{mo}[linebreak="goodbreak"]{} \rho, \mmlToken{mo}[linebreak="goodbreak"]{} \sigma, \mmlToken{mo}[linebreak="goodbreak"]{} \lambda, \mmlToken{mo}[linebreak="goodbreak"]{} \kappa, \mmlToken{mo}[linebreak="goodbreak"]{} \chi, \mmlToken{mo}[linebreak="goodbreak"]{} \gamma\right\}.\]
\[{}\text{Attached property PartialDerivative 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}$);
\[{}\left\{g_{t t} = -1+\frac{2M}{r}, \mmlToken{mo}[linebreak="goodbreak"]{} g_{r r} = \frac{1}{1 - \frac{2M}{r}}, \mmlToken{mo}[linebreak="goodbreak"]{} g_{\theta \theta} = r^{2}, \mmlToken{mo}[linebreak="goodbreak"]{} g_{\phi \phi} = r^{2} \sin{\theta}^{2}, \mmlToken{mo}[linebreak="goodbreak"]{} g^{t t} = \frac{r}{2M-r}, \mmlToken{mo}[linebreak="goodbreak"]{} g^{r r} = \frac{-2M+r}{r}, \mmlToken{mo}[linebreak="goodbreak"]{} g^{\phi \phi} = \frac{1}{r^{2} \sin{\theta}^{2}}, \mmlToken{mo}[linebreak="goodbreak"]{} g^{\theta \theta} = r^{-2}\right\}\]
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);
\[{}\Gamma^{\mu}\,_{\nu \rho} = \frac{1}{2}g^{\mu \sigma} \left(\partial_{\rho}{g_{\nu \sigma}}+\partial_{\nu}{g_{\rho \sigma}}-\partial_{\sigma}{g_{\nu \rho}}\right)\]
\[{}\Gamma^{\mu}\,_{\nu \rho} = \left\{\begin{aligned}\square{}_{\phi}{}_{r}{}^{\phi}= & \frac{1}{r}\\[-.5ex] \square{}_{\phi}{}_{\theta}{}^{\phi}= & \frac{1}{\tan{\theta}}\\[-.5ex] \square{}_{\theta}{}_{r}{}^{\theta}= & \frac{1}{r}\\[-.5ex] \square{}_{r}{}_{r}{}^{r}= & \frac{M}{r \left(2M-r\right)}\\[-.5ex] \square{}_{t}{}_{r}{}^{t}= & \frac{M}{r \left(-2M+r\right)}\\[-.5ex] \square{}_{r}{}_{\phi}{}^{\phi}= & \frac{1}{r}\\[-.5ex] \square{}_{\theta}{}_{\phi}{}^{\phi}= & \frac{1}{\tan{\theta}}\\[-.5ex] \square{}_{r}{}_{\theta}{}^{\theta}= & \frac{1}{r}\\[-.5ex] \square{}_{r}{}_{t}{}^{t}= & \frac{M}{r \left(-2M+r\right)}\\[-.5ex] \square{}_{\phi}{}_{\phi}{}^{r}= & \left(2M-r\right) \sin{\theta}^{2}\\[-.5ex] \square{}_{\phi}{}_{\phi}{}^{\theta}= & - \frac{1}{2}\sin{2\theta}\\[-.5ex] \square{}_{\theta}{}_{\theta}{}^{r}= & 2M-r\\[-.5ex] \square{}_{t}{}_{t}{}^{r}= & M \frac{-2M+r}{r^{3}}\\[-.5ex] \end{aligned}\right. \]
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^{\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}\]
substitute(rm, ch) evaluate(rm, ss, rhsonly=True);
\[{}R^{\rho}\,_{\sigma \mu \nu} = \left\{\begin{aligned}\square{}_{t}{}_{t}{}^{r}{}_{r}= & 2M \frac{2M-r}{r^{4}}\\[-.5ex] \square{}_{\theta}{}_{\theta}{}^{r}{}_{r}= & - \frac{M}{r}\\[-.5ex] \square{}_{\phi}{}_{\phi}{}^{\theta}{}_{\theta}= & 2M \frac{\sin{\theta}^{2}}{r}\\[-.5ex] \square{}_{\phi}{}_{\phi}{}^{r}{}_{r}= & -M \frac{\sin{\theta}^{2}}{r}\\[-.5ex] \square{}_{t}{}_{r}{}^{t}{}_{r}= & \frac{2M}{r^{2} \left(2M-r\right)}\\[-.5ex] \square{}_{\phi}{}_{\theta}{}^{\phi}{}_{\theta}= & - \frac{2M}{r}\\[-.5ex] \square{}_{r}{}_{t}{}^{r}{}_{t}= & 2M \frac{-2M+r}{r^{4}}\\[-.5ex] \square{}_{r}{}_{\theta}{}^{r}{}_{\theta}= & \frac{M}{r}\\[-.5ex] \square{}_{\theta}{}_{\phi}{}^{\theta}{}_{\phi}= & -2M \frac{\sin{\theta}^{2}}{r}\\[-.5ex] \square{}_{r}{}_{\phi}{}^{r}{}_{\phi}= & M \frac{\sin{\theta}^{2}}{r}\\[-.5ex] \square{}_{r}{}_{r}{}^{t}{}_{t}= & \frac{2M}{r^{2} \left(-2M+r\right)}\\[-.5ex] \square{}_{r}{}_{r}{}^{\theta}{}_{\theta}= & \frac{M}{r^{2} \left(2M-r\right)}\\[-.5ex] \square{}_{\theta}{}_{\theta}{}^{\phi}{}_{\phi}= & \frac{2M}{r}\\[-.5ex] \square{}_{r}{}_{r}{}^{\phi}{}_{\phi}= & \frac{M}{r^{2} \left(2M-r\right)}\\[-.5ex] \square{}_{t}{}_{t}{}^{\phi}{}_{\phi}= & M \frac{-2M+r}{r^{4}}\\[-.5ex] \square{}_{t}{}_{t}{}^{\theta}{}_{\theta}= & M \frac{-2M+r}{r^{4}}\\[-.5ex] \square{}_{\phi}{}_{\phi}{}^{t}{}_{t}= & -M \frac{\sin{\theta}^{2}}{r}\\[-.5ex] \square{}_{\theta}{}_{\theta}{}^{t}{}_{t}= & - \frac{M}{r}\\[-.5ex] \square{}_{\phi}{}_{r}{}^{\phi}{}_{r}= & \frac{M}{r^{2} \left(-2M+r\right)}\\[-.5ex] \square{}_{\phi}{}_{t}{}^{\phi}{}_{t}= & M \frac{2M-r}{r^{4}}\\[-.5ex] \square{}_{\theta}{}_{r}{}^{\theta}{}_{r}= & \frac{M}{r^{2} \left(-2M+r\right)}\\[-.5ex] \square{}_{\theta}{}_{t}{}^{\theta}{}_{t}= & M \frac{2M-r}{r^{4}}\\[-.5ex] \square{}_{t}{}_{\phi}{}^{t}{}_{\phi}= & M \frac{\sin{\theta}^{2}}{r}\\[-.5ex] \square{}_{t}{}_{\theta}{}^{t}{}_{\theta}= & \frac{M}{r}\\[-.5ex] \end{aligned}\right. \]
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_{\sigma \nu} = R^{\rho}\,_{\sigma \rho \nu}\]
\[{}R_{\sigma \nu} = 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^{\mu}\,_{\nu \rho \sigma} R^{\lambda}\,_{\kappa \gamma \chi} g_{\mu \lambda} g^{\nu \kappa} g^{\rho \gamma} g^{\sigma \chi}\]
substitute(K, rm) evaluate(K, ss, rhsonly=True);
\[{}K = \frac{48M^{2}}{r^{6}}\]
This shows that $r=0$ is a true singularity.
Copyright © 2001-2017 Kasper Peeters
Questions? info@cadabra.science