Coding Riemann (0,4) Equation in Python - Help Needed!

In summary: 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: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):
  • #1
Vick
105
11
TL;DR 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
 
Technology news on Phys.org
  • #2
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?
 
  • #3
Ibix said:
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!
 
  • #4
##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.
 
  • Like
Likes vanhees71 and Vick
  • #5
Ibix said:
##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!
 
  • #6
Vick said:
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}##?
 
  • Like
Likes Vick
  • #7
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.
 
  • #8
pervect said:
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
 
  • Like
Likes vanhees71
  • #9
pedro the swift said:
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.
 
  • #10
pedro the swift said:
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.
 
  • Like
Likes vanhees71 and Vick
  • #11
Vick said:
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
 
  • Like
Likes Vick
  • #12
pervect said:
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.
 

1. What is the Riemann (0,4) equation?

The Riemann (0,4) equation is a mathematical formula that describes the curvature of a four-dimensional space. It is used in the field of differential geometry to analyze the properties of curved spaces.

2. Why is it important to code the Riemann (0,4) equation in Python?

Coding the Riemann (0,4) equation in Python allows for efficient and accurate computation of the equation's values. It also allows for easier manipulation and visualization of the data, making it a valuable tool for mathematicians and scientists.

3. What are the challenges of coding the Riemann (0,4) equation in Python?

One of the main challenges is handling the complex mathematical calculations involved in the equation. Another challenge is ensuring the code is written accurately and efficiently to avoid errors and optimize performance.

4. Are there any existing resources or libraries for coding the Riemann (0,4) equation in Python?

Yes, there are several libraries available for coding the Riemann (0,4) equation in Python, such as SymPy, SciPy, and SageMath. These libraries provide pre-written functions and tools for working with the equation, making it easier to implement in your code.

5. How can I get help with coding the Riemann (0,4) equation in Python?

You can seek help from online communities and forums dedicated to Python programming and mathematics. You can also consult with experienced programmers or mathematicians for guidance and assistance. Additionally, there are many online tutorials and resources available for learning how to code the Riemann (0,4) equation in Python.

Similar threads

  • Programming and Computer Science
Replies
3
Views
267
  • Programming and Computer Science
Replies
6
Views
3K
  • Programming and Computer Science
Replies
1
Views
2K
  • Special and General Relativity
Replies
5
Views
4K
  • Programming and Computer Science
Replies
1
Views
1K
  • Special and General Relativity
Replies
4
Views
1K
Replies
14
Views
973
  • Programming and Computer Science
Replies
1
Views
3K
  • Special and General Relativity
Replies
5
Views
1K
  • Advanced Physics Homework Help
Replies
3
Views
2K
Back
Top