I have a code that gives me the Christoffel symbols of a metric. How do I take the covariant derivative of a vector?

It does not necessarily have to build upon my code, but this is what I have used so far that gives me the affine connactions:

n = 4 
coord = {T, R, \[Theta], \[Phi]}

metric = {{-1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, R^2, 0}, {0, 0, 0, R^2 Sin[\[Theta]]^2}}

inversemetric = Simplify[Inverse[metric]]

affine := 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[\[CapitalGamma][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}]```

  • $\begingroup$ If you're going to be doing a lot of this sort of thing, you might want to look into the xAct package, and in particular the xCoba sub-package included with it. $\endgroup$ Jul 12, 2021 at 17:12
  • $\begingroup$ As a corollary to that, to the best of my knowledge this is not something that Mathematica can do "natively". You would have to either write your own code or use an add-on package, such as xAct. $\endgroup$ Jul 12, 2021 at 17:15
  • $\begingroup$ Related: mathematica.stackexchange.com/questions/2620/… $\endgroup$
    – Michael E2
    Jul 14, 2021 at 0:26

1 Answer 1


If you google something like "covariant derivative mathematica" you will get some hits that lead to mathematica.stackexchange.com where similar questions are answered. One example is Covariant derivative given Christoffel symbols which I think gives you the answer you are looking for. Be aware that the covariant derivative of a "vector" depends on whether you mean a covariant or contravariant vector - see e.g. https://mathworld.wolfram.com/CovariantDerivative.html for the difference.


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