I'm trying to calculate the Kretschmann scalar in mathematica, it is given by:
$c = R^{abcd} R_{abcd}$
Where $R^{abcd}$ is the Riemann tensor. I'm following this MSE post so I modified it to get the corresponding $R^{abcd}$ in the following manner:
RiemannTensorarriba[g_, xx_] := Block[{n, Rie, ig, res}, n = 4;
Rie = RiemannTensor[g, xx];
ig = InverseMetric[g];
res = Table[
Sum[ig[[i, a]]*ig[[j, b]]*ig[[k, c]]*Rie[l, a, b, c], {a, 1,
n}, {b, 1, n}, {c, 1, n}], {i, 1, n}, {j, 1, n}, {k, 1, n}, {l,
1, n}];
Simplify[res]]
And I'm raising the first index in the Riemann Tensor of the MSE:
Riemannabajo[g_, xx_] := Block[{n, rie, res}, n = 4;
rie = RiemannTensor[g, xx];
res = Table[
Sum[g[[i, j]]*rie[[j, a, b, c]], {j, 1, n}], {i, 1, n}, {a, 1,
n}, {b, 1, n}, {c, 1, n}];
Simplify[res]]
Now if I have the both tensors that I need, so to contract the indices I'm trying both:
Riemannabajo[g,xx].RiemannTensorArriba[g,xx]
And programing it via a summation like:
Kreztchman[g_, xx_] := Block[{n, Rie, Riea, res}, n = 4;
Rie = Riemannabajo[g, xx];
Riea = RiemannTensorarriba[g, xx];
res = Sum[
Riea[[i, k, l, m]]*Rie[[i, k, l, m]], {i, 1, n}, {k, 1, n}, {l, 1,
n}, {m, 1, n}];
Simplify[res]]
But both answers don't give me a scalar, instead I get some kind of tensor. Where I'm missing the point?
Edit: In order to be consistent, Im using the solution of the MSE as proposed by @Arte, ie:
InverseMetric[g_]:=Simplify[Inverse[g]]
ChristoffelSymbol[g_,xx_]:=Block[{n,ig,res},n=4;ig=InverseMetric[g];
res=Table[(1/2)*Sum[ig[[i,s]]*(-
D[g[[j,k]],xx[[s]]]+D[g[[j,s]],xx[[k]]]+D[g[[s,k]],xx[[j]]]),{s,1,n}],{i,1,n},{j,1,n},{k,1,n}];
Simplify[res]]
RiemannTensor[g_,xx_]:=Block[{n,Chr,res},n=4;Chr=ChristoffelSymbol[g,xx];
res=Table[D[Chr[[i,k,m]],xx[[l]]]-D[Chr[[i,k,l]],xx[[m]]]+Sum[Chr[[i,s,l]]*Chr[[s,k,m]],{s,1,n}]-Sum[Chr[[i,s,m]]*Chr[[s,k,l]],{s,1,n}],{i,1,n},{k,1,n},{l,1,n},{m,1,n}];
Simplify[res]]
RicciTensor[g_,xx_]:=Block[{Rie,res,n},n=4;Rie=RiemannTensor[g,xx];
res=Table[Sum[Rie[[s,i,s,j]],{s,1,n}],{i,1,n},{j,1,n}];
Simplify[res]]
RicciScalar[g_,xx_]:=Block[{Ricc,ig,res,n},n=4;Ricc=RicciTensor[g,xx];ig=InverseMetric[g];
res=Sum[ig[[s,i]] Ricc[[s,i]],{s,1,n},{i,1,n}];
Simplify[res]]
RiemannTensorarriba[g_,xx_]:=Block[{n,Rie,ig,res},n=4;
Rie=RiemannTensor[g,xx];
ig=InverseMetric[g];
res=Table[Sum[ig[[i,a]]*ig[[j,b]]*ig[[k,c]]*Rie[l,a,b,c],{a,1,n},{b,1,n},{c,1,n}],{i,1,n},{j,1,n},{k,1,n},{l,1,n}];
Simplify[res]]
Riemannabajo[g_,xx_]:=Block[{n,rie,res},n=4;
rie=RiemannTensor[g,xx];
res=Table[Sum[g[[i,j]]*rie[[j,a,b,c]],{j,1,n}],{i,1,n},{a,1,n},{b,1,n},{c,1,n}];
Simplify[res]]
And I'm trying to calculete the Kretschmann invariant to the following metric:
xx = {t, x, \[Theta], \[Phi]};
g = {{-(1 - x^2/a^2), 0, 0, 0}, {0, 1/(1 - x^2/a^2), 0, 0}, {0, 0,
x^2, 0}, {0, 0, 0, x^2 Sin[\[Theta]]^2}};
Dot
contracts the last index in its first arguments with the first index in its second argument; for your tensors, this will result in a tensor of rank 6, and not a scalar, so this can't possibly work. Perhaps you want to look atInner
orTensorContract
. $\endgroup$RiemannTensorarriba
vsRiemannTensorArriba
). Pleass make sure that you don't have stray definitions by restarting the kernel. It might be helpful to English speakers to replacearriba
andabajo
byUp
andDown
. Your approach withSum[...,{i,1,n},{j,1,n},{k,1,n},{l,1,n}]
seems reasonable, but it seems thatRiemannabajo[[i,j,k,l]]
should beRiemannabajo[g,xx][[i,j,k,l]]
if I read the code correctly. The order of indices inRiemannTensorarriba
seems wrong (should bel
,i
,j
,k
). $\endgroup$Rie[l,a,b,c]
should have double brackets. Perhaps that mistake occurs elsewhere: you can check the dimension of various parts byDimensions[Riemannabajo[g,xx]]
etc. As for order of indices, if I readSum[ig[[i, a]]*ig[[j, b]]*ig[[k, c]]*Rie[l, a, b, c], {a, 1, n}, {b, 1, n}, {c, 1, n}]
correctly it computes $g^{ia}g^{jb}g^{kc}R^l{}_{abc} = R^{lijk}$ not $R^{ijkl}$. But maybeRie[[l, a, b, c]]
means $R_{abc}{}^l$. $\endgroup$