<jupyter_start><jupyter_text>Spherical CoordinatesTransform Relation from $(r, \theta, \phi)$ to $(x, y, z)$:\begin{equation}\left\{\begin{matrix}x =& r \sin\theta & \cos\phi \\ y =& r \sin\theta & \sin\phi \\ z =& r \cos\theta &\end{matrix}\right.\end{equation}Transform Relation from $(x, y, z)$ to $(r, \theta, \phi)$:\begin{equation}\left\{\begin{matrix} & r^2 =& x^2+y^2+z^2 & \\ \tan & \phi  =& y/x & \\ & \theta =& \arccos (z/r) & = \arccos (\frac{z}{\sqrt{x^2+y^2+z^2}}) \end{matrix}\right.\end{equation}<jupyter_code>r, theta, phi = symbols('r theta phi', real=True)
x, y, z = [f(r,theta,phi) for f in symbols('x, y, z', real=True, cls=Function)]

eq_list = [
    Eq(x, r * sin(theta) * cos(phi)),
    Eq(y, r * sin(theta) * sin(phi)),
    Eq(z, r * cos(theta))]
for eq in eq_list: eq
diffed_eq_list = []
for eq in eq_list:
    for var in [r, theta, phi]:
        diffed_eq_list.append(
            Eq(eq.lhs.diff(var),
               eq.rhs.diff(var)))# .subs(x**2+y**2+z**2, r**2).simplify() )
for diffed_eq in diffed_eq_list: diffed_eq<jupyter_output><empty_output><jupyter_text>\begin{equation}\vec{e}_{1} = \frac{\partial \vec{r}}{\partial r} = \frac{\partial (x\hat{x}+y\hat{y}+z\hat{z})}{\partial r},\quad\vec{e}_{2} = \frac{\partial \vec{r}}{\partial \theta} = \frac{\partial (x\hat{x}+y\hat{y}+z\hat{z})}{\partial \theta},\quad\vec{e}_{3} = \frac{\partial \vec{r}}{\partial \phi} = \frac{\partial (x\hat{x}+y\hat{y}+z\hat{z})}{\partial \phi}\end{equation}<jupyter_code>from einsteinpy.symbolic.vector import GenericVector

e_i = [None, None, None] # The three components would be 
for i, var in enumerate([r, theta, phi]):
    e_i_temp = Array([x.diff(var), y.diff(var), z.diff(var)])
    for eq in diffed_eq_list:
        e_i_temp = e_i_temp.subs(eq.lhs, eq.rhs)
    e_i[i] = e_i_temp
from sympy import trigsimp
# define the metric for 3d spherical coordinates
metric = [[0 for i in range(3)] for i in range(3)]
for i in range(3):
    for j in range(3):
        metric[i][j] = (lambda vec1, vec2: 
                        vec1[0]*vec2[0] + vec1[1]*vec2[1] + vec1[2]*vec2[2])(e_i[i], e_i[j])
        metric[i][j] = trigsimp(metric[i][j])
        # metric[i][j]
metric
# define the metric for 3d spherical coordinates
metric = [[0 for i in range(3)] for i in range(3)]
metric[0][0] = 1
metric[1][1] = r**2
metric[2][2] = (r**2)*(sin(theta)**2)
# creating metric object
m_obj = MetricTensor(metric, (r, theta, phi), config='ll')
m_obj.tensor()
ch = ChristoffelSymbols.from_metric(m_obj)
ch.config
# Calculating Riemann Tensor from Christoffel Symbols
rm1 = RiemannCurvatureTensor.from_christoffels(ch)
rm1.tensor()
# Calculating Riemann Tensor from Metric Tensor
rm2 = RiemannCurvatureTensor.from_metric(m_obj)
rm2.tensor()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.20260021668472372, 'fraction_numerical': 0.018779342723004695, 'mean_word_length': 4.11070110701107, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '225757', 'license': 'MIT', 'n_tokens_mistral': 1140, 'n_tokens_neox': 1105, 'n_words': 243, 'path': 'nb/from_spherical_to_metric_Christoffel_Riemann_tensor.ipynb', 'repo_name': 'jiaxin1996/silkpy', 'size': '2769'}