# How do I speed up the symbolic calculation of Riemann tensor?

I've been trying to use sagemath for a derivation in general relativity. For a particular step I need to calculate the riemann tensor of a perturbation metric (This metric has no particular form) and the cell did not execute for even after 16 hours of run time. Here's the snippet of my code. can someone help me in defining a metric in some other way, probably indicial notation or something else so that the process can speed up?

here's a minimal code:

h=M.metric('h') for i in range(4): for j in range(4): h[i, j] = function(f'h{i}{j}')(t, x, y, z) h[i, j] = h[j, i]

h[:] riemann=h.riemann() riemann.display()

edit retag close merge delete

1

please provide a minimal code example

( 2024-08-17 08:23:54 +0200 )edit

Try to give the metric in a closed form as much as you can: For example, use a function f(t,x) instead of $t^3+xt+x^2$.

( 2024-08-17 08:31:59 +0200 )edit
1

You could try to use a simplification chain lighter than the default one, since this is where most of the CPU time is spent. See https://doc.sagemath.org/html/en/refe...

( 2024-08-21 11:04:52 +0200 )edit

here's a minimal code:

h=M.metric('h')
for i in range(4):
for j in range(4):
h[i, j] = function(f'h{i}{j}')(t, x, y, z)
h[i, j] = h[j, i]

h[:]
riemann=h.riemann()
riemann.display()

( 2024-08-26 12:28:24 +0200 )edit

If all of the elements of your metric are nonzero and strictly depend on each coordinate, then the Riemann tensor calculation should take a serious amount of time. A lighter simplification suggestion of @eric_g seems like the only way to have a result (useful or not). However, I would first think about the restrictions I could put on the metric (e.g. no time dependence, no g_{tr} terms, etc.).

( 2024-08-26 19:48:54 +0200 )edit