# 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()

please provide a minimal code example

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$.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...

here's a minimal code:

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.).