# Homework 2

## Imports


```python
import nbtools
nbtools.setup_nb()
```


```python
import itertools
import sympy
from sympy.diffgeom import Manifold, Patch
from pystein import coords, metric, curvature
from pystein.utilities import tensor_pow as tpow, full_simplify
```

## Problem 2


```python

```


```python
M = Manifold('M', dim=3)
P = Patch('origin', M)
r, theta, phi = sympy.symbols('r theta phi', nonnegative=True)
cs = coords.CoordSystem('spherical-polar', P, [r, theta, phi])
dr, dtheta, dphi = cs.base_oneforms()


ds2 = tpow(dr, 2) + r ** 2 * tpow(dtheta, 2) + r ** 2 * sympy.sin(theta) ** 2 * tpow(dphi, 2)
gamma = metric.Metric(twoform=ds2)

gamma
```




$\displaystyle r^{2} \sin^{2}{\left(\theta \right)} \operatorname{d}\phi \otimes \operatorname{d}\phi + r^{2} \operatorname{d}\theta \otimes \operatorname{d}\theta + \operatorname{d}r \otimes \operatorname{d}r$




```python
christoffels = [((i, j, k), full_simplify(curvature.christoffel_symbol_component(i, j, k, gamma))) 
                for i, j, k in itertools.product(range(3), range(3), range(3))]
```


```python
curvature.display_components([c for c in christoffels if c[1]])
```


$\begin{split} (\mu=0, \nu=1, \rho=1) &: - r \\ (\mu=0, \nu=2, \rho=2) &: - r \sin^{2}{\left(\theta \right)} \\ (\mu=1, \nu=0, \rho=1) &: \frac{1}{r} \\ (\mu=1, \nu=1, \rho=0) &: \frac{1}{r} \\ (\mu=1, \nu=2, \rho=2) &: - \frac{\sin{\left(2 \theta \right)}}{2} \\ (\mu=2, \nu=0, \rho=2) &: \frac{1}{r} \\ (\mu=2, \nu=1, \rho=2) &: \frac{1}{\tan{\left(\theta \right)}} \\ (\mu=2, \nu=2, \rho=0) &: \frac{1}{r} \\ (\mu=2, \nu=2, \rho=1) &: \frac{1}{\tan{\left(\theta \right)}} \end{split}$



```python
riccis = [((i, j), full_simplify(curvature.ricci_tensor_component(i, j, gamma).doit())) 
          for i, j in itertools.product(range(3), range(3))]
```


```python
curvature.display_components(riccis)
```


$\begin{split} (\mu=0, \nu=0) &: 0 \\ (\mu=0, \nu=1) &: 0 \\ (\mu=0, \nu=2) &: 0 \\ (\mu=1, \nu=0) &: 0 \\ (\mu=1, \nu=1) &: 0 \\ (\mu=1, \nu=2) &: 0 \\ (\mu=2, \nu=0) &: 0 \\ (\mu=2, \nu=1) &: 0 \\ (\mu=2, \nu=2) &: 0 \end{split}$


 Computing $\beta_j$


```python
M = sympy.symbols('M')
```


```python
beta_j = sympy.Matrix([sympy.sqrt(2 * M / r), 0, 0])
beta_j
```




$\displaystyle \left[\begin{matrix}\sqrt{2} \sqrt{\frac{M}{r}}\\0\\0\end{matrix}\right]$




```python
(gamma.matrix * beta_j).T
```




$\displaystyle \left[\begin{matrix}\sqrt{2} \sqrt{\frac{M}{r}} & 0 & 0\end{matrix}\right]$




```python
def cov_deriv_one_form(i, j, form, g):
    coord_syms = g.coord_system.base_symbols()
    v = sympy.Derivative(form[j], coord_syms[i])
    
    for k in range(len(coord_syms)):
        v -= curvature.christoffel_symbol_component(k, i, j, g) * form[k]

    return full_simplify(v.doit())
```


```python
def k_ij(i, j, beta_j, g, alpha = 1):
    d_i_beta_j = cov_deriv_one_form(i, j, beta_j, g)
    d_j_beta_i = cov_deriv_one_form(j, i, beta_j, g)
    return - sympy.Rational(1, 2) / alpha * (d_i_beta_j + d_j_beta_i)
```


```python
K_ij = sympy.Matrix([[k_ij(0, j, beta_j, gamma) for j in range(3)],
                     [k_ij(1, j, beta_j, gamma) for j in range(3)],
                     [k_ij(2, j, beta_j, gamma) for j in range(3)]])
```


```python
K_ij = - (d_i_beta_j + d_j_beta_i) / 2
K_ij #/ beta_j[0]
```




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



$$K_{ij} \approx \frac{1}{r} \beta^r \gamma_{ij}$$


```python
sympy.trace(gamma.matrix.inv() * K_ij)
```




$\displaystyle - \frac{3 \sqrt{2} \sqrt{\frac{M}{r}}}{2 r}$




```python

```


```python

```


```python

```


```python

```


```python

```


```python

```


```python

```


```python

```

d10f7dc4347daa260c9772d90590d26fe1d5451e
ipynb
Jupyter Notebook
notebooks/homework-2.ipynb
JWKennington/CourseNR
c0f62c0e129fd44c3b1c006fce62e4528e59cd8b
MIT
notebooks/homework-2.ipynb
JWKennington/CourseNR
c0f62c0e129fd44c3b1c006fce62e4528e59cd8b
MIT
notebooks/homework-2.ipynb
JWKennington/CourseNR
c0f62c0e129fd44c3b1c006fce62e4528e59cd8b
MIT
Qwen/Qwen-72B
1. YES
2. YES