Clear[coord,metric,inversemetric,affine,riemann,ricci,scalar,r,θ,ϕ]
n = 3
coord = {r,θ,ϕ}
metric = {{(1 - ((r^2)/3) - ((2 m)/r))^(-1), 0, 0}, {0, r^2, 0},
{0, 0, r^2*(sin[θ])^2}}
MatrixForm[metric]
inversemetric = Simplify[Inverse[metric]]
MatrixForm[inversemetric]
affine = Simplify[
Table[(1/2)*
Sum[(inversemetric[[i, s]])*(D[metric[[s, j]], 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}]]
listaffine :=
Table[If[UnsameQ[affine[[i, j, k]],
0], {ToString[Γ[i, j, k]], affine[[i, j, k]]}], {i,
1, n}, {j, 1, n}, {k, 1, j}]
TableForm[Partition[DeleteCases[Flatten[listaffine], Null], 2],
TableSpacing -> {2, 2}]
riemann = Simplify[Table[
D[affine[[ i,j,l]],coord[[k]]]-
D[affine[[ i,j,k]],coord[[l]]]+Sum[affine[[ s,j,l]]affine[[i,k,s]]-
affine[[s,j,k]]affine[[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,j,k,l]],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}]
Output:
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,l]],ricci[[j,l]]}],{j,1,n},{l, 1, j}]
TableForm[Partition [DeleteCases[ Flatten[ listricci], Null],2],TableSpacing
-> {2, 2}]
Output:
scalar = Simplify[
Sum[inversemetric [[i, j]] ricci [[i, j]], {i, 1, n}, {j, 1, n}]]
Output:
By using these results, I found that the metric is not Einstein, but someone said to me that my calculation was wrong, and the metric was supposed to be Einstein. So I think maybe there's something wrong with my code, but I just can't find any. Please someone help me to figure it out, thanks!



Sininstead ofsin, the former being the sine function, the latter being undefined. Basic differential geometry operations are defined in Compute covariant derivative in Mathematica. In particular, I used that code when I said to you, on physics.SE, that your metric is not Einstein. Please do check it for yourself. – AccidentalFourierTransform Aug 05 '18 at 13:47Sin[]instead of a sin, but it is not necessary. And so everything is clear. – Alex Trounev Aug 05 '18 at 14:11