I want to compute the Christoffel-symbol for a given metric. I am using the code here, but I am missing something.

The Chrisfoffel-symbol formula is

$\Gamma^{\mu}_{\phantom{\mu}\nu\sigma}=\frac{1}{2}g^{\mu\alpha}\left\{\frac{\partial g_{\alpha\nu}}{\partial x^{\sigma}}+\frac{\partial g_{\alpha\sigma}}{\partial x^{\nu}}-\frac{\partial g_{\nu\sigma}}{\partial x^{\alpha}}\right\}\quad$

The metric is given to be

$g_{\mu \nu} = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & r^2+b^2 & 0 & 0 \\ 0 & 0 & (r^2+b^2)\sin^2(\theta) & 0 \\ 0 & 0 & 0 & -1 \end{pmatrix} $

The provided solution is:







The code I'm using is

xx = {t, x, \[Theta], \[Phi]};

g  = { {1,0,0,0},

inversemetric = Simplify[Inverse[metric]];

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]

But I do not get the desired answer.

What am I missing? Besides, I'd like to learn how could I display the answer once I know how to actually get it.

Note I also checked Artes' solution here but I do not get how to run the code either.


After playing around a bit with the Christoffel symbols (which is much more fun when you use Mathematica ;)) I've realized of several features:

  1. If the metric is diagonal then the only way to get a non-zero Christoffel symbol is when any of the indices appears at least twice.

  2. If the metric is diagonal we cannot have any index appearing three times yielding a non-trivial Christoffel symbol. The reason is because $g_{rr}$ is independent of $r$, $g_{\theta \theta}$ is independent of $\theta$, $g_{\phi \phi}$ is independent of $\phi$ and $g_{tt}$ is independent of $t$, which implies $\partial_{\mu} g_{\nu \rho}=0$ when $\mu=\nu=\rho$

  3. Based on 1. and 2. we conclude that (when the metric is diagonal) all non-trivial Christoffel symbols must show repeated indices exactly twice.

  • 1
    $\begingroup$ Many statements in this code seem incosistent: for instance, there is an expression inversemetric that involves an expression metric, but metric is undefined and should probably be g, just above. Further, in the body of ChristoffelSymbol there is reference to a function called InverseMetric (note the capitalization and the arguments in hard brackets) but this function is also undefined. It should maybe just be inversemetric...? $\endgroup$ – Marius Ladegård Meyer Jun 19 at 12:47
  • 1
    $\begingroup$ It seems you haven't checked this answer carefully. There is no metric defined, g stands for the metric. $\endgroup$ – Artes Jun 19 at 15:16
  • 5
    $\begingroup$ This question is based on a basic misunderstanding of the code here: How to calculate scalar curvature Ricci tensor and Christoffel symbols in Mathematica? $\endgroup$ – Artes Jun 19 at 15:20
  • $\begingroup$ @Artes absolutely, that's a typo of mine. Actually in my first try I used the code in your answer (which is a gem), labelling the metric g. My issue was in how to call out the function once defined (sorry, my programming skills are really really basic XD). Now I learned how; we first label the function sol = ChristoffelSymbol[g, xx] and then call out a specific solution, for instance sol[[1, 2, 2]]. $\endgroup$ – JD_PM Jun 19 at 16:23

The code you provided is a definition for a function to compute the Christoffel symbol (and Inverse to compute the inverse metric, I do not know "InverseMetric")

ChristoffelSymbol[g_, xx_] := 
 Block[{n, ig, res}, n = Length[xx]; ig = Inverse[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}];

Then you have to define coordinates xx and the compontents metric with respect to the coordinate basis.

(* The coordinates *)
xx = {r, \[Theta], \[Phi], t};

(* The metric *)
g = {{1, 0, 0, 0}, {0, r^2 + b^2, 0, 0}, {0, 
    0, (r^2 + b^2) Sin[\[Theta]]^2, 0}, {0, 0, 0, -1}};

(* The Christoffel *)
sol = ChristoffelSymbol[g, xx] (* This calls the function! *);

sol[[1, 2, 2]]
(* -r *)

sol[[1, 3, 3]]
(* -r Sin[\[Theta]]^2 *)

sol[[2, 2, 1]]
(* r/(b^2 + r^2) *)

sol[[2, 3, 3]]
(* -Cos[\[Theta]] Sin[\[Theta]] *)

sol[[3, 3, 1]]
(* r/(b^2 + r^2) *)

sol[[3, 3, 2]]
(* Cot[\[Theta]] *)

Edited the answer with the correct coordinates.

Note that you get some coefficients "twice" since the Christoffel symbols are symmetric.

Union@Flatten@With[{n = Length[xx]}, Table[sol[[i, j, k]] == sol[[i, k, j]], {i, n}, {j, n}, {k, n}]]
(* {True} *)
| improve this answer | |
  • $\begingroup$ Thanks for your answer! Note there's something missing in your code. Please see the provided solution above; you do not get 4 of the 6 Christoffel symbols and you get $\cot(\theta)$ twice. $\endgroup$ – JD_PM Jun 19 at 13:04
  • $\begingroup$ Natas I got it thanks! Just one last question: does the code Union@Flatten@With[{n = Length[xx]}, Table[sol[[i, j, k]] == sol[[i, k, j]], {i, n}, {j, n}, {k, n}]] (* {True} *) simply verify that the Christoffel symbols are symmetric in their lower indices? If yes, how does it work? I've tried sol[[3,3,1]]==sol[3,1,3] expecting a true as an output but did not work. $\endgroup$ – JD_PM Jun 19 at 16:09
  • 1
    $\begingroup$ Indeed it does simply verify that the Christoffel symbols are symmetric in the lower indices. sol[[3,3,1]]==sol[[3,1,3]] should work (double brackets are used for indexing in Mathematica). The @ is simply is shorthand for Prefix and f[x] == f@x. In the code you quoted I check this (inefficiently) for all indices which gives a nested list of True which is flattened with Flatten and then the duplicates are removed with Union. Had there been a case in which the symmetry condition had been violated it would give {False, True}. $\endgroup$ – Natas Jun 19 at 17:07

Not the answer you're looking for? Browse other questions tagged or ask your own question.