# Contravariant & Covariant indices in Tensors (Symbolic)¶

[1]:

from einsteinpy.symbolic import SchwarzschildMetric, MetricTensor, ChristoffelSymbols, RiemannCurvatureTensor
import sympy
sympy.init_printing()


## Analysing the schwarzschild metric along with performing various operations¶

[2]:

sch = SchwarzschildMetric()
sch.tensor()

[2]:

$$\left[\begin{matrix}- \frac{a}{r} + 1 & 0 & 0 & 0\\0 & - \frac{1}{c^{2} \left(- \frac{a}{r} + 1\right)} & 0 & 0\\0 & 0 & - \frac{r^{2}}{c^{2}} & 0\\0 & 0 & 0 & - \frac{r^{2} \sin^{2}{\left (\theta \right )}}{c^{2}}\end{matrix}\right]$$
[3]:

sch_inv = sch.inv()
sch_inv.tensor()

[3]:

$$\left[\begin{matrix}\frac{r}{- a + r} & 0 & 0 & 0\\0 & \frac{c^{2} \left(a - r\right)}{r} & 0 & 0\\0 & 0 & - \frac{c^{2}}{r^{2}} & 0\\0 & 0 & 0 & - \frac{c^{2}}{r^{2} \sin^{2}{\left (\theta \right )}}\end{matrix}\right]$$
[4]:

sch.order

[4]:

$$2$$
[5]:

sch.config

[5]:

'll'


## Obtaining Christoffel Symbols from Metric Tensor¶

[6]:

chr = ChristoffelSymbols.from_metric(sch_inv) # can be initialized from sch also
chr.tensor()

[6]:

$$\left[\begin{matrix}\left[\begin{matrix}0 & \frac{a}{2 r^{2} \left(- \frac{a}{r} + 1\right)} & 0 & 0\\\frac{a}{2 r^{2} \left(- \frac{a}{r} + 1\right)} & 0 & 0 & 0\\0 & 0 & 0 & 0\\0 & 0 & 0 & 0\end{matrix}\right] & \left[\begin{matrix}\frac{a c^{2} \left(- \frac{a}{r} + 1\right)}{2 r^{2}} & 0 & 0 & 0\\0 & - \frac{a}{2 r^{2} \left(- \frac{a}{r} + 1\right)} & 0 & 0\\0 & 0 & - r \left(- \frac{a}{r} + 1\right) & 0\\0 & 0 & 0 & - r \left(- \frac{a}{r} + 1\right) \sin^{2}{\left (\theta \right )}\end{matrix}\right] & \left[\begin{matrix}0 & 0 & 0 & 0\\0 & 0 & \frac{1}{r} & 0\\0 & \frac{1}{r} & 0 & 0\\0 & 0 & 0 & - \sin{\left (\theta \right )} \cos{\left (\theta \right )}\end{matrix}\right] & \left[\begin{matrix}0 & 0 & 0 & 0\\0 & 0 & 0 & \frac{1}{r}\\0 & 0 & 0 & \frac{\cos{\left (\theta \right )}}{\sin{\left (\theta \right )}}\\0 & \frac{1}{r} & \frac{\cos{\left (\theta \right )}}{\sin{\left (\theta \right )}} & 0\end{matrix}\right]\end{matrix}\right]$$
[7]:

chr.config

[7]:

'ull'


## Changing the first index to covariant¶

[8]:

new_chr = chr.change_config('lll') # changing the configuration to (covariant, covariant, covariant)
new_chr.tensor()

[8]:

$$\left[\begin{matrix}\left[\begin{matrix}0 & \frac{a}{2 r^{2}} & 0 & 0\\\frac{a}{2 r^{2}} & 0 & 0 & 0\\0 & 0 & 0 & 0\\0 & 0 & 0 & 0\end{matrix}\right] & \left[\begin{matrix}- \frac{a}{2 r^{2}} & 0 & 0 & 0\\0 & \frac{a}{2 c^{2} \left(a - r\right)^{2}} & 0 & 0\\0 & 0 & \frac{r}{c^{2}} & 0\\0 & 0 & 0 & \frac{r \sin^{2}{\left (\theta \right )}}{c^{2}}\end{matrix}\right] & \left[\begin{matrix}0 & 0 & 0 & 0\\0 & 0 & - \frac{r}{c^{2}} & 0\\0 & - \frac{r}{c^{2}} & 0 & 0\\0 & 0 & 0 & \frac{r^{2} \sin{\left (2 \theta \right )}}{2 c^{2}}\end{matrix}\right] & \left[\begin{matrix}0 & 0 & 0 & 0\\0 & 0 & 0 & - \frac{r \sin^{2}{\left (\theta \right )}}{c^{2}}\\0 & 0 & 0 & - \frac{r^{2} \sin{\left (2 \theta \right )}}{2 c^{2}}\\0 & - \frac{r \sin^{2}{\left (\theta \right )}}{c^{2}} & - \frac{r^{2} \sin{\left (2 \theta \right )}}{2 c^{2}} & 0\end{matrix}\right]\end{matrix}\right]$$
[9]:

new_chr.config

[9]:

'lll'


## Any arbitary index configuration would also work!¶

[10]:

new_chr2 = new_chr.change_config('lul')
new_chr2.tensor()

[10]:

$$\left[\begin{matrix}\left[\begin{matrix}0 & \frac{a}{2 r \left(- a + r\right)} & 0 & 0\\\frac{a c^{2} \left(a - r\right)}{2 r^{3}} & 0 & 0 & 0\\0 & 0 & 0 & 0\\0 & 0 & 0 & 0\end{matrix}\right] & \left[\begin{matrix}\frac{a}{2 r \left(a - r\right)} & 0 & 0 & 0\\0 & \frac{a}{2 r \left(a - r\right)} & 0 & 0\\0 & 0 & - \frac{1}{r} & 0\\0 & 0 & 0 & - \frac{1}{r}\end{matrix}\right] & \left[\begin{matrix}0 & 0 & 0 & 0\\0 & 0 & - a + r & 0\\0 & \frac{1}{r} & 0 & 0\\0 & 0 & 0 & - \frac{1}{\tan{\left (\theta \right )}}\end{matrix}\right] & \left[\begin{matrix}0 & 0 & 0 & 0\\0 & 0 & 0 & \left(- a + r\right) \sin^{2}{\left (\theta \right )}\\0 & 0 & 0 & \frac{\sin{\left (2 \theta \right )}}{2}\\0 & \frac{1}{r} & \frac{1}{\tan{\left (\theta \right )}} & 0\end{matrix}\right]\end{matrix}\right]$$

## Obtaining Riemann Tensor from Christoffel Symbols and manipulating it’s indices¶

[11]:

rm = RiemannCurvatureTensor.from_christoffels(new_chr2)
rm[0,0,:,:]

[11]:

$$\left[\begin{matrix}0 & 0 & 0 & 0\\0 & \frac{a}{r^{2} \left(a - r\right)} & 0 & 0\\0 & 0 & \frac{a}{2 r} & 0\\0 & 0 & 0 & \frac{a \sin^{2}{\left (\theta \right )}}{2 r}\end{matrix}\right]$$
[12]:

rm.config

[12]:

'ulll'

[13]:

rm2 = rm.change_config("uuuu")
rm2[0,0,:,:]

[13]:

$$\left[\begin{matrix}0 & 0 & 0 & 0\\0 & - \frac{a c^{4}}{r^{3}} & 0 & 0\\0 & 0 & \frac{a c^{4}}{2 r^{4} \left(- a + r\right)} & 0\\0 & 0 & 0 & \frac{a c^{4}}{2 r^{4} \left(- a + r\right) \sin^{2}{\left (\theta \right )}}\end{matrix}\right]$$
[14]:

rm3 = rm2.change_config("lulu")
rm3[0,0,:,:]

[14]:

$$\left[\begin{matrix}0 & 0 & 0 & 0\\0 & \frac{a c^{2}}{r^{3}} & 0 & 0\\0 & 0 & - \frac{a c^{2}}{2 r^{3}} & 0\\0 & 0 & 0 & - \frac{a c^{2}}{2 r^{3}}\end{matrix}\right]$$
[15]:

rm4 = rm3.change_config("ulll")
rm4[0,0,:,:]

[15]:

$$\left[\begin{matrix}0 & 0 & 0 & 0\\0 & \frac{a}{r^{2} \left(a - r\right)} & 0 & 0\\0 & 0 & \frac{a}{2 r} & 0\\0 & 0 & 0 & \frac{a \sin^{2}{\left (\theta \right )}}{2 r}\end{matrix}\right]$$