# A Riemann Tensor

#### Vick

Summary
Riemann Tensor for coding in Python
Hi,

I've coded Riemann tensor in python successfully. However, I recently stumbled onto another Riemann equation for the valence (0,4) as shown in the following link: Riemann (0,4)

I'm having troubled coding the last part after the partial derivatives and the plus sign. Can anyone help me? Thanks

Related Special and General Relativity News on Phys.org

#### Ibix

Science Advisor
What do you mean by coding the Riemann tensor in python? Is this numerical work? Is there a specific spacetime you are interested in? Can you post your code (in code tags)? What don't you understand about Christoffel symbols?

#### Vick

What do you mean by coding the Riemann tensor in python? Is this numerical work? Is there a specific spacetime you are interested in? Can you post your code (in code tags)? What don't you understand about Christoffel symbols?
Hi, I do understand Christoffel symbols. I was just having troubled putting it in code as the metric tensor has n and p which R doesn't have but instead has i,k,l,m. But I finally succeeded in placing a double sum of n and then p as per following code:
Riemann Tensor:
chi = [[[[[]for n in range(d)] for a in range(d)] for b in range(d)] for c in range(d)]

for i in range(d):
for k in range(d):
for l in range(d):
for m in range(d):
parti = (diff(g[i][m],x[k],x[l])+diff(g[k][l],x[i],x[m])-diff(g[i][l],x[k],x[m])-diff(g[k][m],x[i],x[l]))
summation = 0
for n in range(d):
for p in range(d):
summation=summation +(g[n][p]*(christoffel[n][k][l]*christoffel[p][i][m]-christoffel[n][k][m]*christoffel[p][i][l]))
chi[i][k][l][m]=0.5 * parti + summation
print(i,k,l,m)
print(simplify(chi[i][k][l][m]))
print(' ')
Thanks anyway!

#### Ibix

Science Advisor
$n$ and $p$ are dummy indices and are summed over. Any repeated index (one must be lower and one upper) is treated like this. So $g_{ab}V^a$ is to be read as $\sum_ag_{ab}V^a$ and gives a single lower index tensor. At a quick glance, your code appears to be implementing this correctly.

Note that there are symmetries in the Christoffel symbols ($\Gamma^i_{jk}=\Gamma^i_{kj}$), and you can probably implement it more efficiently than you have done.

• vanhees71 and Vick

#### Vick

$n$ and $p$ are dummy indices and are summed over. Any repeated index (one must be lower and one upper) is treated like this. So $g_{ab}V^a$ is to be read as $\sum_ag_{ab}V^a$ and gives a single lower index tensor. At a quick glance, your code appears to be implementing this correctly.

Note that there are symmetries in the Christoffel symbols ($\Gamma^i_{jk}=\Gamma^i_{kj}$), and you can probably implement it more efficiently than you have done.
Thanks, I had already coded the Riemann Tensor from the partial derivatives of the Christoffel symbols as per the first equation in that section of wiki article. However, as i'm trying to implement it in another program for numerical calculations, I wanted to compute it using only the derivatives of the metric tensor and not the christoffel symbols. So after several attempts, I succeeded, but i had already posted this query in physicsforum!

#### pervect

Staff Emeritus
Science Advisor
Summary: Riemann Tensor for coding in Python

Hi,

I've coded Riemann tensor in python successfully. However, I recently stumbled onto another Riemann equation for the valence (0,4) as shown in the following link: Riemann (0,4)

I'm having troubled coding the last part after the partial derivatives and the plus sign. Can anyone help me? Thanks
"Coding the Riemann tensor" needs some more context to make sense.

I can follow enough of the code to guess that you're computing the Riemann tensor from the metric tensor. More specifically, you appear to be calculating the components of the Riemann tensor in a coordinate basis from the components of the metric tensor.

Are you using some sort of symbolic algebra package, or are functions like "diff", which I assume is taking a partial derivative, built into whatever Python version you are using? It looks a bit like a Maple function I"m familiar with. I've seen a bit of python, but I wasn't aware of any version of it that had a "diff" function such as Maple has. I would think that would need a symbolic algebra package to drive it, but it's unclear. However, I'd be interested to find out more about what you're doing.

As far as your question goes - "valence(0,4)" isn't standard terminology, I'm not sure what you're asking or why. The wiki link doesn't really help me with what you are asking - at a guess maybe you're interested in calculating $R_{ijkl}$ rather than $R^{i}{}_{jkl}$?

• Vick

#### pedro the swift

As someone with a limited knowledge of this but a interest(having viewed a number of videos on Einstein field equations and Susskind's lectures on relativity) I am interested to see someone actually using the equations with I assume real numbers to generate some sort of out put.
The videos I have seen go to great lengths to give the general equations but never seem to have any real world numerical examples or solutions shown. I guess that this higher level of maths is mainly done with esoteric symbols but Ifind it difficult to relate to real world outcomes.

#### Vick

Are you using some sort of symbolic algebra package, or are functions like "diff", which I assume is taking a partial derivative, built into whatever Python version you are using? It looks a bit like a Maple function I"m familiar with.
I am using Python with Sympy module, which is a Python library for symbolic computation. I was trying to calculate Rijkl = 1/2( ....

The first part with the mixed partial derivatives was what I already did without a problem. I was having difficulty with the last part after the plus sign: gnp (..... as n and p is not found in Rijkl.

But I finally succeeded by having a double sum of n and p over and above the i,j,k and l as shown in the above code.

I wanted to compute the Riemann Tensor from the metric tensor as I'm actually trying to convert the calculations into a numeric one in another program.

What I meant by the valence(0,4) is Tensor field of type (0,4) on the 4-dimensional Lorentzian manifold. You can see the word "valence" being used here: Valence

• vanhees71

#### Vick

I guess that this higher level of maths is mainly done with esoteric symbols but I find it difficult to relate to real world outcomes.
You can use the Einstein field equations to compute the Friedmann metric symbolically. At the end you will end up with Friedmann equations. The latter equation is what cosmologists use to calculate the co-moving distance and size of the universe, however in a parametrized form.

#### Ibix

Science Advisor
The videos I have seen go to great lengths to give the general equations but never seem to have any real world numerical examples or solutions shown. I guess that this higher level of maths is mainly done with esoteric symbols but Ifind it difficult to relate to real world outcomes.
There are plenty of known solutions. The Schwarzschild and Kerr metrics, describing non-rotating and rotating black holes (and a decent approximation to the field near the Earth), and the Friedmann-Lemaitre-Robertson-Walker (FLRW) metric describing the large scale structure of the universe, are probably the best known and should be easy to Google. I solved the equations for the interior of a solid sphere of constant density here if you want to see a slightly ham-fisted example of the process.

Unfortunately, solving the equations analytically is really difficult in general, since you need to satisfy sixteen simultaneous differential equations. Only highly symmetric solutions are known. Numerical solutions are the way we deal with cases like merging black holes, but people tend not to make videos about how to do such numerical work because it's one of those topics that is more or less nothing but detail.

• vanhees71 and Vick

#### pervect

Staff Emeritus
Science Advisor
I am using Python with Sympy module, which is a Python library for symbolic computation. I was trying to calculate Rijkl = 1/2( ....

The first part with the mixed partial derivatives was what I already did without a problem. I was having difficulty with the last part after the plus sign: gnp (..... as n and p is not found in Rijkl.

But I finally succeeded by having a double sum of n and p over and above the i,j,k and l as shown in the above code.

I wanted to compute the Riemann Tensor from the metric tensor as I'm actually trying to convert the calculations into a numeric one in another program.

What I meant by the valence(0,4) is Tensor field of type (0,4) on the 4-dimensional Lorentzian manifold. You can see the word "valence" being used here: Valence
I wasn't familiar with the term valence, but I can see it being used now that you point it out. Thanks!

Sums are implied by repeated index, this is called the Einstein summation convention. See for instance thw wiki on the Einstein summation convetion <<link>>. With two repeated indices in those expressions, a double sum is implied, as you wrote.

The operation of summing over repeated indexes, where one index is an upper index and the other is a lower index, is also called contracting a tensor. There's a wiki article on tensor contraction, but I didn't think it was very illuminating.

If you know either $R^i{}_{jkl}$ or $R_{ijkl}$ you can easily compute the other using the metric tensor, this is called "raising and lowering indices". See for instance the wiki on raising and lowering indices <<link>>.

So we can write

$$R^i{}_{jkl} = g^{mi} R_{mjkl}$$
$$R_{ijkl} = g_{mi} R^m{}_{jkl}$$

Both of these are written using the Einstein convention, so the sum over the repeated index, in this case m, is implied.

$g_{mi}$ is the metric tensor. It's symmetric, so $g_{mi} = g_{im}$. It's used for many things, in this case it is used to lower indices. The inverse of the metric tensor, $g^{mi}$, is used to raise indices. The inverse metric can be calculated from the metric, it's essentially a process of matrix inversion.

https://en.wikipedia.org/w/index.php?title=Kronecker_delta&oldid=891594308

• Vick

#### Vick

this is called "raising and lowering indices".
Hi i am aware of these stuffs and thanks for the summary, I was just having troubled coding it this way, because all the other times i've done this, the sums to be performed, are also the indices on the tensor being computed. But this time the metric tensor had indices which the Riemann tensor of valence (0,4) didn't have. But thanks anyway for the free summary.

"Riemann Tensor"

### Physics Forums Values

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving