Cadabra
a field-theory motivated approach to computer algebra

Two-sphere

This notebook computes the curvature of a 2-sphere by computing connection coefficients and the Riemann tensor components.
{\theta, \varphi}::Coordinate; {\alpha, \beta, \gamma, \delta, \rho, \sigma, \mu, \nu, \lambda}::Indices(values={\varphi, \theta}, position=fixed); \partial{#}::PartialDerivative; g_{\alpha\beta}::Metric. g^{\alpha\beta}::InverseMetric.
\(\displaystyle{}\text{Attached property Coordinate to }\left[\theta, \varphi\right].\)
\(\displaystyle{}\text{Attached property Indices(position=fixed) to }\left[\alpha, \beta, \gamma, \delta, \rho, \sigma, \mu, \nu, \lambda\right].\)
\(\displaystyle{}\text{Attached property PartialDerivative to }\partial{\#}.\)
sphe:={ g_{\theta\theta} = r**2, g_{\varphi\varphi} = r**2 \sin(\theta)**2 }. complete(sphe, $g^{\alpha\beta}$);
\(\displaystyle{}\left[g_{\theta \theta} = {r}^{2}, g_{\varphi \varphi} = {r}^{2} {\left(\sin{\theta}\right)}^{2}, g^{\varphi \varphi} = {\left({r}^{2} {\left(\sin{\theta}\right)}^{2}\right)}^{-1}, g^{\theta \theta} = {r}^{-2}\right]\)
{g_{\theta \theta} = (r)**2, g_{\varphi \varphi} = (r)**2 (\sin(\theta))**2, g^{\varphi \varphi} = ((r)**2 (\sin(\theta))**2)**-1, g^{\theta \theta} = (r)**-2}
The Christoffel symbols are given in terms of the metric by the following expression.
ch:= \Gamma^{\alpha}_{\mu\nu} = 1/2 g^{\alpha\beta} ( \partial_{\nu}{g_{\beta\mu}} +\partial_{\mu}{g_{\beta\nu}} -\partial_{\beta}{g_{\mu\nu}} );
\(\displaystyle{}\Gamma^{\alpha}\,_{\mu \nu} = \frac{1}{2}g^{\alpha \beta} \left(\partial_{\nu}{g_{\beta \mu}}+\partial_{\mu}{g_{\beta \nu}}-\partial_{\beta}{g_{\mu \nu}}\right)\)
\Gamma^{\alpha}_{\mu \nu} = 1/2 g^{\alpha \beta} (\partial_{\nu}(g_{\beta \mu}) + \partial_{\mu}(g_{\beta \nu})-\partial_{\beta}(g_{\mu \nu}))
We evaluate the components using evaluate and then massage them a bit further using sympy.
evaluate(ch, sphe, rhsonly=True) map_sympy(ch, "expand_trig");
\(\displaystyle{}\Gamma^{\alpha}\,_{\mu \nu} = \square{}_{\mu}{}_{\nu}{}^{\alpha}\left\{\begin{aligned}\square{}_{\varphi}{}_{\theta}{}^{\varphi}= & {\left(\tan{\theta}\right)}^{-1}\\[-.5ex] \square{}_{\theta}{}_{\varphi}{}^{\varphi}= & {\left(\tan{\theta}\right)}^{-1}\\[-.5ex] \square{}_{\varphi}{}_{\varphi}{}^{\theta}= & -\sin{\theta} \cos{\theta}\\[-.5ex] \end{aligned}\right. \)
\Gamma^{\alpha}_{\mu \nu} = \components_{\mu \nu}^{\alpha}({{\varphi, \theta, \varphi} = (\tan(\theta))**-1, {\theta, \varphi, \varphi} = (\tan(\theta))**-1, {\varphi, \varphi, \theta} = -\sin(\theta) \cos(\theta)})
The Riemann tensor is given in terms of the Christoffel symbols by the expression below.
rm:= R^{\rho}_{\sigma\mu\nu} = +\partial_{\mu}{\Gamma^{\rho}_{\sigma\nu}} -\partial_{\nu}{\Gamma^{\rho}_{\sigma\mu}} +\Gamma^{\rho}_{\beta\mu} \Gamma^{\beta}_{\sigma\nu} -\Gamma^{\rho}_{\beta\nu} \Gamma^{\beta}_{\sigma\mu}; substitute(rm, ch) evaluate(rm, sphe, rhsonly=True);
\(\displaystyle{}R^{\rho}\,_{\sigma \mu \nu} = \partial_{\mu}{\Gamma^{\rho}\,_{\sigma \nu}}-\partial_{\nu}{\Gamma^{\rho}\,_{\sigma \mu}}+\Gamma^{\rho}\,_{\beta \mu} \Gamma^{\beta}\,_{\sigma \nu}-\Gamma^{\rho}\,_{\beta \nu} \Gamma^{\beta}\,_{\sigma \mu}\)
R^{\rho}_{\sigma \mu \nu} = \partial_{\mu}(\Gamma^{\rho}_{\sigma \nu})-\partial_{\nu}(\Gamma^{\rho}_{\sigma \mu}) + \Gamma^{\rho}_{\beta \mu} \Gamma^{\beta}_{\sigma \nu}-\Gamma^{\rho}_{\beta \nu} \Gamma^{\beta}_{\sigma \mu}
\(\displaystyle{}R^{\rho}\,_{\sigma \mu \nu} = \square{}_{\sigma}{}_{\nu}{}^{\rho}{}_{\mu}\left\{\begin{aligned}\square{}_{\varphi}{}_{\varphi}{}^{\theta}{}_{\theta}= & {\left(\sin{\theta}\right)}^{2}\\[-.5ex] \square{}_{\theta}{}_{\varphi}{}^{\varphi}{}_{\theta}= & -1\\[-.5ex] \square{}_{\varphi}{}_{\theta}{}^{\theta}{}_{\varphi}= & -{\left(\sin{\theta}\right)}^{2}\\[-.5ex] \square{}_{\theta}{}_{\theta}{}^{\varphi}{}_{\varphi}= & 1\\[-.5ex] \end{aligned}\right. \)
R^{\rho}_{\sigma \mu \nu} = \components_{\sigma \nu}^{\rho}_{\mu}({{\varphi, \varphi, \theta, \theta} = (\sin(\theta))**2, {\theta, \varphi, \varphi, \theta} = -1, {\varphi, \theta, \theta, \varphi} = -(\sin(\theta))**2, {\theta, \theta, \varphi, \varphi} = 1})
These are not in the simplest form possible yet, but this is a sympy simplification issue; for the time being we will continue and compute the Ricci tensor and scalar.
ricci:= R_{\sigma\nu} = R^{\rho}_{\sigma\rho\nu}; substitute(ricci, rm) evaluate(ricci, sphe, rhsonly=True);
\(\displaystyle{}R_{\sigma \nu} = R^{\rho}\,_{\sigma \rho \nu}\)
R_{\sigma \nu} = R^{\rho}_{\sigma \rho \nu}
\(\displaystyle{}R_{\sigma \nu} = \square{}_{\sigma}{}_{\nu}\left\{\begin{aligned}\square{}_{\varphi}{}_{\varphi}= & {\left(\sin{\theta}\right)}^{2}\\[-.5ex] \square{}_{\theta}{}_{\theta}= & 1\\[-.5ex] \end{aligned}\right. \)
R_{\sigma \nu} = \components_{\sigma \nu}({{\varphi, \varphi} = (\sin(\theta))**2, {\theta, \theta} = 1})
R:= R = R_{\sigma\nu} g^{\sigma\nu}; substitute(R, ricci) evaluate(R, sphe, rhsonly=True);
\(\displaystyle{}R = R_{\sigma \nu} g^{\sigma \nu}\)
R = R_{\sigma \nu} g^{\sigma \nu}
\(\displaystyle{}R = 2{r}^{-2}\)
R = 2(r)**-2
The main time computing this is spent in the rather inefficient sympy bridge. You can see timing information by querying the server object for the totals list.
server.totals();
{}$\big[$cadabra::collect_terms: 21 calls, 0 steps, 0 ms, cadabra::complete: 1 calls, 0 steps, 268 ms, cadabra::evaluate: 4 calls, 0 steps, 2212 ms, cadabra::map_sympy: 1 calls, 0 steps, 20 ms, cadabra::simplify: 49 calls, 0 steps, 2209 ms, cadabra::substitute: 3 calls, 0 steps, 5 ms, scalar_backend: 49 calls, 0 steps, 2209 ms, sympy: 49 calls, 0 steps, 2209 ms$\big]$
Copyright © 2001-2018 Kasper Peeters
Questions? info@cadabra.science