I'm doing some GR calculations with xAct. I get an expression that is heavy. In order to simplify the results, I try to use the function ReplaceAll in simple cases. Here's an expression I want to simplify. The $R_{abcd}R^{abcd}$ is the one I want to replace. To make it simple, I put $1$:

enter image description here

 x_*RiemannCD[a, b, c, d] RiemannCD[-a, -b, -c, -d]*y_ -> 1]

where perturb is a variable containing the expression above. In its definition I used :

\[Delta]Sphi =  VarD[\[Phi][]][Lc + Lm] // ContractMetric;
perturb = Perturbation[\[Delta]Sphi, 0] // ExpandPerturbation // SortCovDs // ContractMetric

Here is the InputForm for perturb:

PD[-a][PD[a][\[Phi][]]] + PD[a][PD[-a][\[Phi][]]] - 
 4*\[Alpha]*RicciCD[-a, -b]*RicciCD[a, b]*
  Derivative[1][F][\[Phi][]] + \[Alpha]*RicciScalarCD[]^2*
  Derivative[1][F][\[Phi][]] + 
   \[Alpha]*RiemannCD[-a, -b, -c, -d]*RiemannCD[a, b, c, d]*
  Derivative[1][F][\[Phi][]] + 
 8*\[Beta]^3*RicciCD[-a, -b]*RicciCD[a, b]*\[Psi][]*
  Derivative[1][F][\[Phi][]] - 
  Derivative[1][F][\[Phi][]] - 
 2*\[Beta]^3*RiemannCD[-a, -b, -c, -d]*RiemannCD[a, b, c, d]*\[Psi][]*
  Derivative[1][F][\[Phi][]] + \[Beta]^3*\[Psi][]^2*

Here is the problem:

  • With perturb, the function gives me back the same expression, without any replacement.
  • If instead I directly put the expression above, it perfectly works !

Can you explain what's going on and how I can to not to place everytime the whole expression ?

Thanks !


  • 1
    $\begingroup$ Welcome to Mathematica StackExchange! Please edit the question and include the definition of perturb (copy and paste the InputForm from Mathematica) :) $\endgroup$
    – Domen
    Commented Mar 29 at 15:00
  • 1
    $\begingroup$ Hmm, I guess I wasn't really clear. Copy the output of the perturb, so that we can try the code ourself. perturb = -2β^3 RiemannCD[...] ... $\endgroup$
    – Domen
    Commented Mar 29 at 15:23

2 Answers 2


You have to explicitely specify the lengths of factors in products, eg. the number of factors fact may be 0 to $\infty$

-2 \[Beta]^3 riemann1["\[Del]", a, b, c, d] riemann2["\[Del]", a, b, 
c, d] \[Psi] F'[\[Phi]] + \[Beta]^3 \[Psi]^2 F'[\[Phi]] /. {fact___*
riemann1["\[Del]", a, b, c, d] riemann2["\[Del]", a, b, c, d] :>Times[ fact]}

$$\beta ^3 \psi ^2 F'(\phi )-2 \beta ^3 \psi F'(\phi )$$

Very important: Enclose fact in a Times, because the Pattern match yields a sequence of factors expanded in the outer Plus as a sum, not as a product.

  • $\begingroup$ Hey ! Thanks for your answer. When I try to execute ReplaceAll[perturb,{fact___* RiemannCD[-a, -b, -c, -d] RiemannCD[a, b, c, d] :>Times[ fact]} this still gives me the unchanged expression. Even with /. notation. $\endgroup$
    – TrodaroX
    Commented Mar 29 at 17:06

I solved the problem by using the MakeRule method of xAct

ruleG = MakeRule[{RiemannCD[a, b, c, d] RiemannCD[-a, -b, -c, -d], 
    G - RicciScalarCD[]^2 + 4* RicciCD[a, b] RicciCD[-a, -b]}];
RiemannCD[-a, -b, -c, -d]*RiemannCD[a, b, c, d] /. ruleG

it gives:

G + 4*RicciCD[-a, -b]*RicciCD[a, b] - RicciScalarCD[]^2

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.