I'm trying to use the xAct Mathematica package for manipulating tensors, and I'd like to plug in a metric into the perturbation equations to first order in general relativity, and have everything explicitly written out, but I'm having trouble with this. I do the usual, defining my metric, manifold, etc. The perturbation to first order of the Ricci tensor is given by:

ExpandPerturbation@Perturbed[RicciCD[-a, -b], 1]

enter image description here

Now, I'd actually like to 'plug in' what my actual metric is, and have xAct compute all those covariant derivatives of the perturbation. To simplify them, I'd then plug in an ansatz for h.

I have looked through the documentation, and I haven't found how I can do this. It's easy to define a metric, just write,

DefMetric[-1,metric[-a,-b],CD, PrintAs -> "g"]

but I don't know how I'm suppose to specify what g is and have xAct 'execute' the computation.

Note: the xPert package is also required.

  • $\begingroup$ I don't have it installed at the moment, but MetricCompute command used to work for getting geometric quantities from the metric. $\endgroup$ Dec 6, 2014 at 17:00
  • $\begingroup$ @AlexeyBobrick: Are you sure? MetricCompute doesn't come up with any suggestions in Mathematica. $\endgroup$ Dec 6, 2014 at 17:04
  • $\begingroup$ @AlexeyBobrick: Nevermind, it does exist, but you need to also load xCoba :) $\endgroup$ Dec 6, 2014 at 17:06
  • $\begingroup$ @AlexeyBobrick: Do you know how I can actually set my metric equal to some explicit matrix? And how I can get it to compute the Ricci tensor in the perturbation equation and carry out the index summation? I can then use Collect[] to sort out the mess. $\endgroup$ Dec 6, 2014 at 17:08
  • $\begingroup$ Yes, I can show you an example, but with another metric, should also work for you. $\endgroup$ Dec 6, 2014 at 17:15

2 Answers 2


Here is an example of how to do it.

We need xTensor and xCoba packages. First is made to work with abstract objects, whilst the second is for operations with explicitly specified metric and basis:

<< xAct`xTensor`
<< xAct`xCoba`(*Package*)

Then comes an example of how to define and get all the quantities for Kerr metric. In your case you will need to input other expressions into the metric.

In summary, we define the manifold, a chart and specify explicitly the metric:

$PrePrint = ScreenDollarIndices; (*Was needed for nice printouts*)
    $CVVerbose = False;
DefManifold[M4, 4,  {b, d, f, h, i, j, k, l, m, p, q, s}]; 
(*4d manifold called M4, indices to be used*)

  M4, {1, 2, 3, 4}, {r[], θ[], φ[], t[]}, 
  BasisColor -> Green]; (*Chart called kerr, coordinate names*)

DefScalarFunction /@ {Δ, ρ};(*Auxiliary functions for metric*)
DefConstantSymbol /@ {M, a};

Δ = (r[])^2 - 2 M r[] + a^2;
ρ = ((r[])^2 + a^2 (Cos[θ[]])^2)^(1/2);
(*Explicit form for the auxiliary functions*)

DefMetric[-1, metricg[-i, -j], CD, PrintAs -> "g", 
 SymbolOfCovD -> {";","D"}](*Definition of the metric*)

MetricInBasis[metricg, -kerr, ( {
   {ρ^2/Δ, 0, 0, 0},
   {0, ρ^2, 0, 0},
   {0, 0, (((r[])^2 + a^2) + 
       2 a^2 M r[] ((Sin[θ[]])^2)/(ρ^2)) \
(Sin[θ[]])^2, -(2 a M r[] (Sin[θ[]])^2)/ρ^2},
   {0, 0, -(2 a M r[] (Sin[θ[]])^2)/ρ^2, -(1 - (2 M r[])/\
  } )]
(*Explicit form for the metric*)

MetricCompute[metricg, kerr, All]
(*Get all the quantities in kerr basis*)

After all this is done, you can use ToValues to get the explicit values of the quantities. For example: ToValues[metricg[{4, -kerr}, {4, -kerr}]. A good summary on how to access and manipulate the computed quantities is contained in xCoba documentation.

Hope this helps!

Edit 1: Here is a short summary of some relevant things which can be done with xCoba:

1) Metric compute prints out lots of lines, some of which state, which new quantities have been defined. For example, the above code prints:

** DefTensor: Defining symmetric Christoffel tensor ChristoffelPDkerr[b,-d,-f]. `

Now we can use the quantity ChristoffelCDPDkerr[{i, kerr}, {-k, -kerr}, {-j, -kerr}], which stands for Christoffel symbol in the natural basis (called kerr here) for natural covariant derivative.

2) Any geometric quantities can be contracted with each other, e.g. one can introduce a new vector field and contract it with $\Gamma^i_{kj}$:

DefTensor[Xg[i], {M4}];(*Define new tensor*)
Exp = ChristoffelCDPDkerr[{i,kerr}, {-k, -kerr}, {-j, -kerr}]Xg[{k, kerr}] Xg[{j, kerr}]] (*Make a new expression, which involves contractions, but has free indices too*)

3) And further it is possible manipulate, how one would like Exp to be, for example:


will replace abstract indices to explicit ones, as in $a^\mu a_\mu=a^1a_1+a^2a_2 + ...$

Or, a free index can become a list of explicit ones:


will change $a^\mu$ into $(a^1,a^2,...)$.

Or, finally, explicit quantities like $a^1$, if they were computed before (index position matters), can be replaced by their computed values:


4) New quantities may explicitly be defined as functions of coordinates for further use in 1-3) with AllComponentValues, e.g.AllComponentValues[Xg[{i,kerr}],{r[],(t[])^2,(r[])^(1/2),(r[])^(-1)}]

5) More things can generally be done with basis changes, but it is not very relevant here.

  • $\begingroup$ Thanks, I've used my metric with your code, and it's computed all the curvature tensors (after some time, though I am working in 26 dimensions). Do you know how I can 'plug' it into the perturbation equations, and execute the summation over the indices? $\endgroup$ Dec 7, 2014 at 22:30
  • $\begingroup$ @user1997744: Yes, it is exactly in xCoba documentation. I will check if I have relevant example for the above metric (still don't have xAct). May I ask, what is the application, which requires working in 26 curved dimensions? $\endgroup$ Dec 9, 2014 at 13:09
  • $\begingroup$ I'm doing perturbation theory in low energy effective string theory, and I need $D=26$ on grounds of consistency to ensure the central charge $c=0$ such that the trace anomaly vanishes. $\endgroup$ Dec 9, 2014 at 13:11
  • $\begingroup$ @user1997744: Interesting to know, thanks! I used to think that people most commonly do low energy string theory for holography, but in somewhat smaller number of dimensions. $\endgroup$ Dec 9, 2014 at 13:24
  • $\begingroup$ Well, now you know why I absolutely need xAct; doing it by hand is prohibitively tedious. (Though, I was brave and computed the curvature tensors by hand using differential forms.) $\endgroup$ Dec 9, 2014 at 13:54

My suggestion would be to use xPert to generate the expressions in abstract indices. Once you have those then use xCoba to establish your metric in a particular chart, then you can expand your perturbative expression in the chosen coordinate basis according to the operations under the xCoba documentation. I have a slide show on how to do this sort of thing (not perturbations exactly, but once you have the expression for the tensors, it is easy to apply it) at the web site: http://www.madscitech.org/tensors.html, look for GR Calculations in Specific Bases using Mathematica.

  • 2
    $\begingroup$ I recommend providing more detailed answer since other users might find it slightly ambiguous. $\endgroup$
    – Artes
    Nov 6, 2015 at 14:48

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.