# Finding the Riemann tensor for the surface of a sphere with sympy.diffgeom

I have implemented a SymPy program that can calculate the Riemann curvature tensor for a given curve element. However, I am encountering problems solving for the case when the curve element is the surface of a sphere

\begin{align} ds^2 = r^2d\theta^2 + r^2 \sin^2\theta d\phi^2 \end{align}

This is obviously a 2D curve element, so the non-zero elements of the metric become \begin{align} g_{11} = r^2, \qquad g_{22} = r^2 \sin^2\theta. \end{align} The entries of metric are clearly a function of two variables $r$ and $\theta$. But the way I have created the program it treats them according to their differentials $d\theta$ and $d\phi$. Since $dr$ is 'zero', my metric is computed as \begin{align} \begin{bmatrix} 0 &0 &0\\ 0 &r^2 &0\\ 0 &0 &r^2 \sin^2\theta \end{bmatrix}. \end{align} The way I have coded my implementation is by asking the user for the metric defined as a matrix. If the matrix is 2D, then I use $u$,$v$ to represent the coordinates. Which in the 2D case assign $r$ as $u$ and $\theta$ as $v$. For 3D (with metric above), the additional value $\phi$ is assigned $w$.

Does anyone see my dilemma here? For 3D, I am basically trying to calculate the Riemann tensor for a metric with the determinant equal to zero. And for 2D, the $\phi$ component does not even exist.

This element is important for me to test my code as this generates a non-zero Riemann curvature tensor. I would really appreciate any suggestions how I can handle this case and thereby improve my code....which fails completely for this case.

(I was not sure if this was appropiate to post here or on stackoverflow. My logic was that basically only phisicists are using SymPy; "then I better go the source instead".)

• Sympy has its own discussion group – garyp Oct 14 '15 at 16:00
• Note also that we don't really do debugging on Physics.SE, you might be able to get some pointers at Computational Science, but not entirely sure on that either. – Kyle Kanos Oct 14 '15 at 16:03
• Thats good be aware of! – imranal Oct 14 '15 at 16:05
• @garyp : I posted this thread on the SymPy discussion group as well. I also gave them a link to the code : pastebin.com/DPxW38L0 . Thanks for the tip! – imranal Oct 14 '15 at 16:16

If you look up the definition of pseudo-Riemannian geometry on Wikipedia: https://en.wikipedia.org/wiki/Pseudo-Riemannian_manifold

You'll notice for the metric:

Instead a weaker condition of nondegeneracy is imposed on the metric tensor.

Your metric is degenerate, so you cannot use algorithms for pseudo-Riemannian geometries with that.

The algorithm implemented in SymPy tries to invert the metric to calculate the Riemann tensor components, which obviously does not work.

If you are studying a 2D manifold, use a $2 \times 2$ matrix.

It is not very clear from your question what your aim is, but maybe you should have a look at the induced metric, to map a 3D metric into a 2D submanifold: https://en.wikipedia.org/wiki/Induced_metric

• Thanks for your help. I managed to solve it now and posted the code on pastebin : pastebin.com/k7UZ4PYy . The entries were none-zero! Which is great. But the results printed out for the Riemann tensor, are not exactly as I thought they would be : physicspages.com/2014/04/08/… – imranal Oct 17 '15 at 15:46
• Turns out that the values generated from the code are correct. The linked blog calculates the covariant form of the Riemann tensor. – imranal Oct 23 '15 at 11:58