# HW 3

## 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 1


```python
M = Manifold('M', dim=3)
P = Patch('origin', M)
rho, z, phi = sympy.symbols('rho z phi', nonnegative=True)

psi = sympy.Function('psi')(rho, z, phi)
q = sympy.Function('q')(rho, z)
cs = coords.CoordSystem('cylindrical', P, [rho, z, phi])
drho, dz, dphi = cs.base_oneforms()


ds2 =  (sympy.exp(q) * (tpow(drho, 2) + tpow(dz, 2)) 
                  + rho ** 2 * tpow(dphi, 2))
gamma = metric.Metric(twoform=ds2)

gamma
```




$\displaystyle \rho^{2} \operatorname{d}\phi \otimes \operatorname{d}\phi + e^{q{\left(\rho,z \right)}} \left(\operatorname{d}\rho \otimes \operatorname{d}\rho + \operatorname{d}z \otimes \operatorname{d}z\right)$




```python
ricci = curvature.ricci_scalar(gamma).doit()
ricci = full_simplify(ricci)
ricci
```




$\displaystyle - \left(\frac{\partial^{2}}{\partial \rho^{2}} q{\left(\rho,z \right)} + \frac{\partial^{2}}{\partial z^{2}} q{\left(\rho,z \right)}\right) e^{- q{\left(\rho,z \right)}}$




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


```python
curvature.display_components(christoffels)
```


$\begin{split} (\mu=0, \nu=0, \rho=0) &: \frac{\frac{\partial}{\partial \rho} q{\left(\rho,z \right)}}{2} \\ (\mu=0, \nu=0, \rho=1) &: - \frac{\frac{\partial}{\partial z} q{\left(\rho,z \right)}}{2} \\ (\mu=0, \nu=0, \rho=2) &: 0 \\ (\mu=1, \nu=1, \rho=0) &: - \frac{\frac{\partial}{\partial \rho} q{\left(\rho,z \right)}}{2} \\ (\mu=1, \nu=1, \rho=1) &: \frac{\frac{\partial}{\partial z} q{\left(\rho,z \right)}}{2} \\ (\mu=1, \nu=1, \rho=2) &: 0 \\ (\mu=2, \nu=2, \rho=0) &: - \rho e^{- q{\left(\rho,z \right)}} \\ (\mu=2, \nu=2, \rho=1) &: 0 \\ (\mu=2, \nu=2, \rho=2) &: 0 \end{split}$


LHS


```python
one_form = [sympy.Derivative(psi, cs.base_symbols()[k]) for k in range(3)]
```


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

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


```python
def Dbar2(i, j, conformal_func, g):
    one_form = [sympy.Derivative(psi, g.coord_system.base_symbols()[k]) for k in range(3)]
    raw = cov_deriv_one_form(i, j, one_form, g)
    return full_simplify(raw.doit())
```


```python
DiDjPsi = sympy.Matrix([[Dbar2(0, j, psi, gamma) for j in range(3)],
                            [Dbar2(1, j, psi, gamma) for j in range(3)],
                            [Dbar2(2, j, psi, gamma) for j in range(3)]])
```


```python
Dbar2Psi = sum([gamma.matrix.inverse()[i, j] * DiDjPsi[i, j] 
                for i, j in itertools.product(range(3), range(3))])
```


```python
LHS = full_simplify(Dbar2Psi)
RHS = psi / 8 * ricci
```


```python
notation_subs = [
    (psi, sympy.symbols('psi'))
]
```


```python
LHS.subs(notation_subs)
```




$\displaystyle \frac{\left(\rho^{2} \left(\frac{d^{2}}{d \rho^{2}} \psi + \frac{d^{2}}{d z^{2}} \psi\right) + \rho \frac{d}{d \rho} \psi + e^{q{\left(\rho,z \right)}} \frac{d^{2}}{d \phi^{2}} \psi\right) e^{- q{\left(\rho,z \right)}}}{\rho^{2}}$




```python
RHS.subs(notation_subs)
```




$\displaystyle - \frac{\psi \left(\frac{\partial^{2}}{\partial \rho^{2}} q{\left(\rho,z \right)} + \frac{\partial^{2}}{\partial z^{2}} q{\left(\rho,z \right)}\right) e^{- q{\left(\rho,z \right)}}}{8}$




```python
def flat_laplacian(func):
    return ((1 / rho) * sympy.Derivative((rho * sympy.Derivative(func, rho)), rho)
             + (1 / rho) ** 2 * sympy.Derivative(sympy.Derivative(func, phi), phi)
             + sympy.Derivative(sympy.Derivative(func, z), z))
```


```python
flat_laplacian(psi).doit().subs(notation_subs)
```




$\displaystyle \frac{d^{2}}{d z^{2}} \psi + \frac{\rho \frac{d^{2}}{d \rho^{2}} \psi + \frac{d}{d \rho} \psi}{\rho} + \frac{\frac{d^{2}}{d \phi^{2}} \psi}{\rho^{2}}$




```python
gamma.matrix.inverse()
```




$\displaystyle \left[\begin{matrix}e^{- q{\left(\rho,z \right)}} & 0 & 0\\0 & e^{- q{\left(\rho,z \right)}} & 0\\0 & 0 & \frac{1}{\rho^{2}}\end{matrix}\right]$




```python

```


```python

```


```python
cov_deriv_one_form()
```


```python

```

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