I'd like to define a function CDOrder[k] to compute the k-th order covariant derivative of a vector A[mu] (or, more generally: a one-by-one growing chain of covariant derivatives starting from some "initial" index to a "final" one specified by me as arguments of that function).

I was thinking about using a Do loop to evaluate iteratively the covariant derivatives of the vector until I get the desired order, however, it doesn't seem to work nice, mainly because, in each iteration I'd need to redefine the tensor taking into account the extra dimension added by the actual covariant derivative in order to avoid the next one to be calculated the wrong way (I suppose).

This is all I've managed to do until now:

Some initialization stuff:

Block[{Print}, << xAct`xTensor`]
Block[{Print}, << xAct`xPert`]
Block[{Print}, << xAct`xPand`]
Block[{Print}, << xAct`xCoba`]
Block[{Print}, << xAct`xTras`]

DefManifold[M, 4, {α, β, γ, μ, ν, ρ, σ, τ, λ, χ, η, κ, ζ}]
DefMetric[-1, g[-α, -β], CD, {";", "∇"}, PrintAs -> "ḡ"];
DefTensor[A[-μ], M]
PrintAs[A] ^= "A";

A first trial of a function:

CD[initial_, final_, μ_] :=
  {list = {}},
  If[initial <= final,
   Do[AppendTo[list, -μ[i]], {i, final, initial, -1}],
   Do[AppendTo[list, -μ[i]], {i, final, initial, 1}]
  DefTensor[ans[α], M];
  ans[α] = A[α];
  Do[ ans[α] = CD[index][ans[α]], {index, list}];

Some tests: (The first 3 work well and the others don't) - I could conclude that, inside the loop, I'm assigning the value of the new tensor to a single component of the tensor aux, i.e. to aux[alpha] which is interpreted as different from aux[mu]. - I'd have to fix this in order to make things go fine but I don't how to do it yet.

CD[1, 6, α]
CD[6, 1, α]
CD[, , α]

CD[1, 6, μ]
CD[6, 1, μ]
CD[, , μ]

I'd appreciate some tips of you, guys. If you can suggest some changes.

  • $\begingroup$ Welcome to Mma.SE. Start by taking the tour now and learning about asking and what's on-topic. Always edit if improvable, show due diligence, give brief context, include minimal working example of your code and data in formatted form. By doing all this you help us to help you and likely you will inspire great answers. The site depends on participation, as you receive give back: vote and answer questions, keep the site useful, be kind, correct mistakes and share what you have learned. $\endgroup$
    – rhermans
    Commented Aug 22, 2018 at 13:16
  • $\begingroup$ What is M1? I guess the index b belongs to the tangent bundle of M1? Note that you have defined the tensor A with two indices, but then you use it with one index only in the covariant derivative. $\endgroup$
    – jose
    Commented Aug 22, 2018 at 21:47
  • $\begingroup$ Ahhhh, you're right Jose, but, for my purposes I just need one index with the vector A so I will edit the original post and let's focus on that scenario. (the b index that you mentioned was supposed to belong to a second metric that's not necessary to consider at this point). The problem is still there. $\endgroup$
    – JuanC97
    Commented Aug 22, 2018 at 21:57
  • $\begingroup$ OK. Then I've edited my answer to use A with only one index. $\endgroup$
    – jose
    Commented Aug 22, 2018 at 22:42
  • $\begingroup$ Note also that a tensor called A will print as "A" by default, so you don't need the PrintAs definition above. $\endgroup$
    – jose
    Commented Aug 22, 2018 at 22:47

1 Answer 1


CD is the Levi-Civita covariant derivative associated with the metric g. You cannot add new definitions to it as you did. On the other hand, you have declared that the indices for M are {α, β, γ, μ, ν, ...}. You cannot use α[1] as an index. It must be α itself.

Given the tensor A[-α], the first derivative, with index -β, is CD[-β][A[-α]]. The second derivative, with index -γ, is CD[-γ][CD[-β][A[-α]]], etc. So imagine you want to create a function that gives you high order derivatives of A. You could do this:

CDA[aind_, dinds_] := Construct[RightComposition @@ Map[CD, dinds], A[aind]]

Then try (note how the indices are inserted in the order they are specified, and hence they appear sorted in reverse order):

CDA[-α, {-μ}]
(* CD[-μ][A[-α]] *)

CDA[-α, {-μ, -ν}]
(* CD[-ν][CD[-μ][A[-α]]] *)

CDA[-α, {-μ, -ν, -λ}]
(* CD[-λ][CD[-ν][CD[-μ][A[-α]]]] *)

CDA[-α, {-μ, -ν, -λ, -σ}]
(* CD[-σ][CD[-λ][CD[-ν][CD[-μ][A[-α]]]]] *)
  • $\begingroup$ Thanks jose, this is exactly what I was looking for. Btw, do you know how to implement the alphanumeric style of indices? $\endgroup$
    – JuanC97
    Commented Aug 23, 2018 at 7:17
  • $\begingroup$ What do you mean by the "alphanumeric style"? Are you referring to using indices like a1, a2, a3, etc? You can use any symbol as index, and then you can define any PrintAs definition for each index. For example declare DefManifold[M, 4, {a1, a2, a3}] and then do PrintAs[a1] ^= SubscriptBox["a", 1], etc. $\endgroup$
    – jose
    Commented Aug 23, 2018 at 13:39
  • $\begingroup$ Again, thanks. That's all I need. Awesome! $\endgroup$
    – JuanC97
    Commented Aug 24, 2018 at 16:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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