# Contravariant & Covariant indices in Tensors (Symbolic)


```python
import sympy
from einsteinpy.symbolic import ChristoffelSymbols, RiemannCurvatureTensor
from einsteinpy.symbolic.predefined import Schwarzschild

sympy.init_printing()
```

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


```python
sch = Schwarzschild()
sch.tensor()
```




$\displaystyle \left[\begin{matrix}1 - \frac{r_{s}}{r} & 0 & 0 & 0\\0 & - \frac{1}{c^{2} \left(1 - \frac{r_{s}}{r}\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]$




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




$\displaystyle \left[\begin{matrix}\frac{r}{r - r_{s}} & 0 & 0 & 0\\0 & \frac{c^{2} \left(- r + r_{s}\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]$




```python
sch.order
```


```python
sch.config
```




    'll'



### Obtaining Christoffel Symbols from Metric Tensor


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




$\displaystyle \left[\begin{matrix}\left[\begin{matrix}0 & \frac{r_{s}}{2 r^{2} \left(1 - \frac{r_{s}}{r}\right)} & 0 & 0\\\frac{r_{s}}{2 r^{2} \left(1 - \frac{r_{s}}{r}\right)} & 0 & 0 & 0\\0 & 0 & 0 & 0\\0 & 0 & 0 & 0\end{matrix}\right] & \left[\begin{matrix}- \frac{r_{s} \left(- \frac{c^{2}}{2} + \frac{r_{s} c^{2}}{2 r}\right)}{r^{2}} & 0 & 0 & 0\\0 & \frac{r_{s} \left(- \frac{c^{2}}{2} + \frac{r_{s} c^{2}}{2 r}\right)}{r^{2} c^{2} \left(1 - \frac{r_{s}}{r}\right)^{2}} & 0 & 0\\0 & 0 & \frac{2 r \left(- \frac{c^{2}}{2} + \frac{r_{s} c^{2}}{2 r}\right)}{c^{2}} & 0\\0 & 0 & 0 & \frac{2 r \left(- \frac{c^{2}}{2} + \frac{r_{s} c^{2}}{2 r}\right) \sin^{2}{\left(\theta \right)}}{c^{2}}\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]$




```python
chr.config
```




    'ull'



### Changing the first index to covariant


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




$\displaystyle \left[\begin{matrix}\left[\begin{matrix}0 & \frac{r_{s}}{2 r^{2}} & 0 & 0\\\frac{r_{s}}{2 r^{2}} & 0 & 0 & 0\\0 & 0 & 0 & 0\\0 & 0 & 0 & 0\end{matrix}\right] & \left[\begin{matrix}- \frac{r_{s}}{2 r^{2}} & 0 & 0 & 0\\0 & \frac{r_{s}}{2 c^{2} \left(r - r_{s}\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]$




```python
new_chr.config
```




    'lll'



### Any arbitary index configuration would also work!


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




$\displaystyle \left[\begin{matrix}\left[\begin{matrix}0 & \frac{r_{s}}{2 r \left(r - r_{s}\right)} & 0 & 0\\\frac{r_{s} c^{2} \left(- r + r_{s}\right)}{2 r^{3}} & 0 & 0 & 0\\0 & 0 & 0 & 0\\0 & 0 & 0 & 0\end{matrix}\right] & \left[\begin{matrix}- \frac{r_{s}}{2 r \left(r - r_{s}\right)} & 0 & 0 & 0\\0 & - \frac{r_{s}}{2 r \left(r - r_{s}\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 & r - r_{s} & 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(r - r_{s}\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


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




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




```python
rm.config
```




    'ulll'




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




$\displaystyle \left[\begin{matrix}0 & 0 & 0 & 0\\0 & - \frac{r_{s} c^{4}}{r^{3}} & 0 & 0\\0 & 0 & \frac{r_{s} c^{4}}{2 r^{4} \left(r - r_{s}\right)} & 0\\0 & 0 & 0 & \frac{r_{s} c^{4}}{2 r^{4} \left(r - r_{s}\right) \sin^{2}{\left(\theta \right)}}\end{matrix}\right]$




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




$\displaystyle \left[\begin{matrix}0 & 0 & 0 & 0\\0 & \frac{r_{s} c^{2}}{r^{3}} & 0 & 0\\0 & 0 & - \frac{r_{s} c^{2}}{2 r^{3}} & 0\\0 & 0 & 0 & - \frac{r_{s} c^{2}}{2 r^{3}}\end{matrix}\right]$




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




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



#### It is seen that `rm` and `rm4` are same as they have the same configuration

16af43a55a370f15c07b7a8c085d223104886fab
ipynb
Jupyter Notebook
docs/source/examples/Symbolic Module - Tensor Indexing.ipynb
QMrpy/einsteinpy
f95ff6840e0648dd96ec11006fad958f67a18520
MIT
2021-04-24T22:38:38.000Z
2021-10-17T18:27:13.000Z
docs/source/examples/Symbolic Module - Tensor Indexing.ipynb
prakashaditya369/einsteinpy
acfba21eecb5a5805042592d8e9ac5c96979f8af
MIT
docs/source/examples/Symbolic Module - Tensor Indexing.ipynb
prakashaditya369/einsteinpy
acfba21eecb5a5805042592d8e9ac5c96979f8af
MIT
Qwen/Qwen-72B
1. YES
2. YES