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.
\(\displaystyle{}\text{Property Coordinate attached to }\left[r, t, \phi, \theta\right].\)
\(\displaystyle{}\text{Property Indices(position=fixed) attached to }\left[\mu, \nu, \rho, \sigma, \lambda, \kappa, \chi, \gamma\right].\)
\(\displaystyle{}\text{Property PartialDerivative attached to }\backslash\texttt{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}$);
\(\displaystyle{}\left[g_{t t} = -1 +2M {r}^{-1}, g_{r r} = {\left(1 -2M {r}^{-1}\right)}^{-1}, g_{\theta \theta} = {r}^{2}, g_{\phi \phi} = {r}^{2} {\left(\sin{\theta}\right)}^{2}, g^{t t} = {\left(2M {r}^{-1} -1\right)}^{-1}, g^{r r} = -2M {r}^{-1} +1, g^{\phi \phi} = {\left({r}^{2} {\left(\sin{\theta}\right)}^{2}\right)}^{-1}, g^{\theta \theta} = {r}^{-2}\right]\)
{g_{t t} = -1 + 2M (r)**(-1), g_{r r} = (1-2M (r)**(-1))**(-1), g_{\theta \theta} = (r)**2, g_{\phi \phi} = (r)**2 (\sin(\theta))**2, g^{t t} = (2M (r)**(-1)-1)**(-1), g^{r r} = -2M (r)**(-1) + 1, g^{\phi \phi} = ((r)**2 (\sin(\theta))**2)**(-1), g^{\theta \theta} = (r)**(-2)}
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);
\(\displaystyle{}\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} = 1/2 g^{\mu \sigma} (\partial_{\rho}(g_{\nu \sigma}) + \partial_{\nu}(g_{\rho \sigma})-\partial_{\sigma}(g_{\nu \rho}))
\(\displaystyle{}\Gamma^{\mu}\,_{\nu \rho} = \square{}_{\nu}{}_{\rho}{}^{\mu}\left\{\begin{aligned}\square{}_{\phi}{}_{r}{}^{\phi}& = {r}^{-1}\\[-.5ex] \square{}_{\phi}{}_{\theta}{}^{\phi}& = {\left(\tan{\theta}\right)}^{-1}\\[-.5ex] \square{}_{\theta}{}_{r}{}^{\theta}& = {r}^{-1}\\[-.5ex] \square{}_{r}{}_{r}{}^{r}& = M {\left(r \left(2M -r\right)\right)}^{-1}\\[-.5ex] \square{}_{t}{}_{r}{}^{t}& = M {\left(r \left(-2M +r\right)\right)}^{-1}\\[-.5ex] \square{}_{r}{}_{\phi}{}^{\phi}& = {r}^{-1}\\[-.5ex] \square{}_{\theta}{}_{\phi}{}^{\phi}& = {\left(\tan{\theta}\right)}^{-1}\\[-.5ex] \square{}_{r}{}_{\theta}{}^{\theta}& = {r}^{-1}\\[-.5ex] \square{}_{r}{}_{t}{}^{t}& = M {\left(r \left(-2M +r\right)\right)}^{-1}\\[-.5ex] \square{}_{\phi}{}_{\phi}{}^{r}& = \left(2M -r\right) {\left(\sin{\theta}\right)}^{2}\\[-.5ex] \square{}_{\phi}{}_{\phi}{}^{\theta}& = - \frac{1}{2}\sin\left(2\theta\right)\\[-.5ex] \square{}_{\theta}{}_{\theta}{}^{r}& = 2M -r\\[-.5ex] \square{}_{t}{}_{t}{}^{r}& = M \left(-2M +r\right) {r}^{-3}\\[-.5ex] \end{aligned}\right. \)
\Gamma^{\mu}_{\nu \rho} = \components_{\nu \rho}^{\mu}({{\phi, r, \phi} = (r)**(-1), {\phi, \theta, \phi} = (\tan(\theta))**(-1), {\theta, r, \theta} = (r)**(-1), {r, r, r} = M (r (2M-r))**(-1), {t, r, t} = M (r (-2M + r))**(-1), {r, \phi, \phi} = (r)**(-1), {\theta, \phi, \phi} = (\tan(\theta))**(-1), {r, \theta, \theta} = (r)**(-1), {r, t, t} = M (r (-2M + r))**(-1), {\phi, \phi, r} = (2M-r) (\sin(\theta))**2, {\phi, \phi, \theta} = - 1/2 \sin(2\theta), {\theta, \theta, r} = 2M-r, {t, t, r} = M (-2M + r) (r)**(-3)})
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};
\(\displaystyle{}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);
\(\displaystyle{}R^{\rho}\,_{\sigma \mu \nu} = \square{}_{\nu}{}_{\sigma}{}^{\rho}{}_{\mu}\left\{\begin{aligned}\square{}_{t}{}_{t}{}^{r}{}_{r}& = 2M \left(2M -r\right) {r}^{-4}\\[-.5ex] \square{}_{\theta}{}_{\theta}{}^{r}{}_{r}& = -M {r}^{-1}\\[-.5ex] \square{}_{\phi}{}_{\phi}{}^{\theta}{}_{\theta}& = 2M {\left(\sin{\theta}\right)}^{2} {r}^{-1}\\[-.5ex] \square{}_{\phi}{}_{\phi}{}^{r}{}_{r}& = -M {\left(\sin{\theta}\right)}^{2} {r}^{-1}\\[-.5ex] \square{}_{t}{}_{r}{}^{t}{}_{r}& = 2M {\left({r}^{2} \left(2M -r\right)\right)}^{-1}\\[-.5ex] \square{}_{\phi}{}_{\theta}{}^{\phi}{}_{\theta}& = -2M {r}^{-1}\\[-.5ex] \square{}_{r}{}_{t}{}^{r}{}_{t}& = 2M \left(-2M +r\right) {r}^{-4}\\[-.5ex] \square{}_{r}{}_{\theta}{}^{r}{}_{\theta}& = M {r}^{-1}\\[-.5ex] \square{}_{\theta}{}_{\phi}{}^{\theta}{}_{\phi}& = -2M {\left(\sin{\theta}\right)}^{2} {r}^{-1}\\[-.5ex] \square{}_{r}{}_{\phi}{}^{r}{}_{\phi}& = M {\left(\sin{\theta}\right)}^{2} {r}^{-1}\\[-.5ex] \square{}_{r}{}_{r}{}^{t}{}_{t}& = 2M {\left({r}^{2} \left(-2M +r\right)\right)}^{-1}\\[-.5ex] \square{}_{r}{}_{r}{}^{\theta}{}_{\theta}& = M {\left({r}^{2} \left(2M -r\right)\right)}^{-1}\\[-.5ex] \square{}_{\theta}{}_{\theta}{}^{\phi}{}_{\phi}& = 2M {r}^{-1}\\[-.5ex] \square{}_{r}{}_{r}{}^{\phi}{}_{\phi}& = M {\left({r}^{2} \left(2M -r\right)\right)}^{-1}\\[-.5ex] \square{}_{t}{}_{t}{}^{\phi}{}_{\phi}& = M \left(-2M +r\right) {r}^{-4}\\[-.5ex] \square{}_{t}{}_{t}{}^{\theta}{}_{\theta}& = M \left(-2M +r\right) {r}^{-4}\\[-.5ex] \square{}_{\phi}{}_{\phi}{}^{t}{}_{t}& = -M {\left(\sin{\theta}\right)}^{2} {r}^{-1}\\[-.5ex] \square{}_{\theta}{}_{\theta}{}^{t}{}_{t}& = -M {r}^{-1}\\[-.5ex] \square{}_{\phi}{}_{r}{}^{\phi}{}_{r}& = M {\left({r}^{2} \left(-2M +r\right)\right)}^{-1}\\[-.5ex] \square{}_{\phi}{}_{t}{}^{\phi}{}_{t}& = M \left(2M -r\right) {r}^{-4}\\[-.5ex] \square{}_{\theta}{}_{r}{}^{\theta}{}_{r}& = M {\left({r}^{2} \left(-2M +r\right)\right)}^{-1}\\[-.5ex] \square{}_{\theta}{}_{t}{}^{\theta}{}_{t}& = M \left(2M -r\right) {r}^{-4}\\[-.5ex] \square{}_{t}{}_{\phi}{}^{t}{}_{\phi}& = M {\left(\sin{\theta}\right)}^{2} {r}^{-1}\\[-.5ex] \square{}_{t}{}_{\theta}{}^{t}{}_{\theta}& = M {r}^{-1}\\[-.5ex] \end{aligned}\right. \)
R^{\rho}_{\sigma \mu \nu} = \components_{\nu \sigma}^{\rho}_{\mu}({{t, t, r, r} = 2M (2M-r) (r)**(-4), {\theta, \theta, r, r} = -M (r)**(-1), {\phi, \phi, \theta, \theta} = 2M (\sin(\theta))**2 (r)**(-1), {\phi, \phi, r, r} = -M (\sin(\theta))**2 (r)**(-1), {t, r, t, r} = 2M ((r)**2 (2M-r))**(-1), {\phi, \theta, \phi, \theta} = -2M (r)**(-1), {r, t, r, t} = 2M (-2M + r) (r)**(-4), {r, \theta, r, \theta} = M (r)**(-1), {\theta, \phi, \theta, \phi} = -2M (\sin(\theta))**2 (r)**(-1), {r, \phi, r, \phi} = M (\sin(\theta))**2 (r)**(-1), {r, r, t, t} = 2M ((r)**2 (-2M + r))**(-1), {r, r, \theta, \theta} = M ((r)**2 (2M-r))**(-1), {\theta, \theta, \phi, \phi} = 2M (r)**(-1), {r, r, \phi, \phi} = M ((r)**2 (2M-r))**(-1), {t, t, \phi, \phi} = M (-2M + r) (r)**(-4), {t, t, \theta, \theta} = M (-2M + r) (r)**(-4), {\phi, \phi, t, t} = -M (\sin(\theta))**2 (r)**(-1), {\theta, \theta, t, t} = -M (r)**(-1), {\phi, r, \phi, r} = M ((r)**2 (-2M + r))**(-1), {\phi, t, \phi, t} = M (2M-r) (r)**(-4), {\theta, r, \theta, r} = M ((r)**2 (-2M + r))**(-1), {\theta, t, \theta, t} = M (2M-r) (r)**(-4), {t, \phi, t, \phi} = M (\sin(\theta))**2 (r)**(-1), {t, \theta, t, \theta} = M (r)**(-1)})
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);
\(\displaystyle{}R_{\sigma \nu} = R^{\rho}\,_{\sigma \rho \nu}\)
R_{\sigma \nu} = R^{\rho}_{\sigma \rho \nu}
\(\displaystyle{}R_{\sigma \nu} = 0\)
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};
\(\displaystyle{}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);
\(\displaystyle{}K = 48{M}^{2} {r}^{-6}\)
K = 48(M)**2 (r)**(-6)
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};
\(\displaystyle{}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}
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}} );
\(\displaystyle{}\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} = 1/2 g^{\mu \sigma} (\partial_{\rho}(g_{\nu \sigma}) + \partial_{\nu}(g_{\rho \sigma})-\partial_{\sigma}(g_{\nu \rho}))
substitute(rm, ch);
\(\displaystyle{}R^{\rho}\,_{\sigma \mu \nu} = \frac{1}{2}\partial_{\mu}\left(g^{\rho \lambda} \left(\partial_{\sigma}{g_{\nu \lambda}} +\partial_{\nu}{g_{\sigma \lambda}} -\partial_{\lambda}{g_{\nu \sigma}}\right)\right) - \frac{1}{2}\partial_{\nu}\left(g^{\rho \lambda} \left(\partial_{\sigma}{g_{\mu \lambda}} +\partial_{\mu}{g_{\sigma \lambda}} -\partial_{\lambda}{g_{\mu \sigma}}\right)\right) +\frac{1}{4}g^{\rho \kappa} \left(\partial_{\lambda}{g_{\mu \kappa}} +\partial_{\mu}{g_{\lambda \kappa}} -\partial_{\kappa}{g_{\mu \lambda}}\right) g^{\lambda \chi} \left(\partial_{\sigma}{g_{\nu \chi}} +\partial_{\nu}{g_{\sigma \chi}} -\partial_{\chi}{g_{\nu \sigma}}\right) - \frac{1}{4}g^{\rho \kappa} \left(\partial_{\lambda}{g_{\nu \kappa}} +\partial_{\nu}{g_{\lambda \kappa}} -\partial_{\kappa}{g_{\nu \lambda}}\right) g^{\lambda \chi} \left(\partial_{\sigma}{g_{\mu \chi}} +\partial_{\mu}{g_{\sigma \chi}} -\partial_{\chi}{g_{\mu \sigma}}\right)\)
R^{\rho}_{\sigma \mu \nu} = 1/2 \partial_{\mu}(g^{\rho \lambda} (\partial_{\sigma}(g_{\nu \lambda}) + \partial_{\nu}(g_{\sigma \lambda})-\partial_{\lambda}(g_{\nu \sigma}))) - 1/2 \partial_{\nu}(g^{\rho \lambda} (\partial_{\sigma}(g_{\mu \lambda}) + \partial_{\mu}(g_{\sigma \lambda})-\partial_{\lambda}(g_{\mu \sigma}))) + 1/4 g^{\rho \kappa} (\partial_{\lambda}(g_{\mu \kappa}) + \partial_{\mu}(g_{\lambda \kappa})-\partial_{\kappa}(g_{\mu \lambda})) g^{\lambda \chi} (\partial_{\sigma}(g_{\nu \chi}) + \partial_{\nu}(g_{\sigma \chi})-\partial_{\chi}(g_{\nu \sigma})) - 1/4 g^{\rho \kappa} (\partial_{\lambda}(g_{\nu \kappa}) + \partial_{\nu}(g_{\lambda \kappa})-\partial_{\kappa}(g_{\nu \lambda})) g^{\lambda \chi} (\partial_{\sigma}(g_{\mu \chi}) + \partial_{\mu}(g_{\sigma \chi})-\partial_{\chi}(g_{\mu \sigma}))
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};
\(\displaystyle{}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);
\(\displaystyle{}K = 48{M}^{2} {r}^{-6}\)
K = 48(M)**2 (r)**(-6)
Copyright © 2001-2024 Kasper Peeters
Questions? info@cadabra.science