Clear[coord, metric, inversemetric, christoffel, reimann, ricci, einstein, r, φ, θ, t, x, y, z]
n = 4
coord = {t, r, θ, φ}
(* Enter your metric here - functions must be denoted with [] as in Φ[r] *)
metric = {{g_tt, 0, 0, 0}, {0, g_rr, 0, 0}, {0, 0, g_theta theta, 0}, {0, 0, 0, r^2 Sin[θ]^2}}
metric // MatrixForm
inversemetric = Simplify[Inverse[metric]]
inversemetric // MatrixForm
christoffel := Simplify[ Table[(1/2) * Sum[inversemetric[[s, i]] * ( D[metric[[j, s]], coord[[k]] ] + D[metric[[s, k]], coord[[j]] ] - D[metric[[j, k]], coord[[s]] ] ), {s, 1, n}], {i, 1, n}, {j, 1, n}, {k, 1, n} ] ]
listchristoffel := Table[If[UnsameQ[christoffel[[i, j, k]], 0], {ToString[Γ[i - 1, j - 1, k - 1]], christoffel[[i, j, k]]}], {i, 1, n}, {j, 1, n}, {k, 1, j}]
TableForm[Partition[DeleteCases[Flatten[listchristoffel], Null], 2], TableSpacing → {2, 2}]
riemann := riemann = Simplify[Table[D[ christoffel[[i, j, l]], coord[[k]] ] - D[ christoffel[[i, j, k]], coord[[l]] ] + Sum[christoffel[[s, j, l]] christoffel[[i, k, s]] - christoffel[[s, j, k]] christoffel[[i, l, s]], {s, 1, n}], {i, 1, n}, {j, 1, n}, {k, 1, n}, {l, 1, n}]]
listriemann := Table[If[UnsameQ[riemann[[i, j, k, l]], 0], {ToString[R[i - 1, j - 1, k - 1, l - 1]], riemann[[i, j, k, l]]}], {i, 1, n}, {j, 1, n}, {k, 1, n}, {l, 1, k - 1}]
TableForm[Partition[DeleteCases[Flatten[listriemann], Null], 2], TableSpacing → {2, 2}]
ricci := ricci = Simplify[Table[Sum[riemann[[i, j, i, l]], {i, 1, n}], {j, 1, n}, {l, 1, n}]]
listricci := Table[If[UnsameQ[ricci[[j, l]], 0], {ToString[R[j - 1, l - 1]], ricci[[j, l]]}], {j, 1, n}, {l, 1, n}]
TableForm[Partition[DeleteCases[Flatten[listricci], Null], 2], TableSpacing → {2, 2}]
scalar = Simplify[Sum[inversemetric[[i, j]] ricci[[i, j]], {i, 1, n}, {j, 1, n}]]
einstein := einstein = Simplify[ricci - (1/2) scalar * metric]
listeinstein := Table[If[UnsameQ[einstein[[j, l]], 0], {ToString[G[j - 1, l - 1]], einstein[[j, l]]}], {j, 1, n}, {l, 1, j}]
TableForm[Partition[DeleteCases[Flatten[listeinstein], Null], 2], TableSpacing → {2, 2}]