# Unable to simplify tensor expressions with xAct

Using xAct package in Mathematica, I am trying to obtain expansions of Ricci scalar upto second order in metric perturbations. Although I am able to obtain the perturbed expressions, Mathematica/xAct does not seem to simplify some tensor expressions. For example, there are terms like:

    p2[a, -a] p2[b, -b] - (p2[a, -a])^2


where p2[a,b] is a second rank tensor. I would like such expressions to be automatically simplified; in the above case, expected result is 0. However, when I use the command //Simplification, I get the same expression. For instance, this is what I get for the above expression:

    In:= p2[a, -a] * p2[b, -b] - (p2[a, -a])^2 // Simplification

Out= p2[a, -a]   p2[b, -b] - xActxTensorScalar[p2[a, -a]]^2


Why is xAct/Mathematica not recognizing the two terms as equal?

What is xActxTensorScalar[] object?

A prescription to simplify such expressions in general would be appreciated.

• I'm not familiar with the xact notation, but are you sure the first term is contracted and the second one is not implicitly multiplyied by the identity tensor. So it could be a non zero tensor of second order. Jul 11, 2018 at 15:28
• Welcome! To make the most of Mma.SE start by taking the tour now. It will help us to help you if you write an excellent question. Edit your question each time you find it can be improved to show due diligence, give more context. As you receive give back, vote and answer questions, keep the site useful, be kind, correct mistakes and share what you have learned. Jul 11, 2018 at 16:00
• @Gluoncito I am not an expert in xAct, but from what I understand it does take care of contractions of repeated indices. Using the command //ScalarQ returns True , implying that this expression is a scalar. Jul 11, 2018 at 17:06

An expression like p[a, -a]^2 is strictly incorrect in xTensor, because in WL this is p[a, -a]*p[a, -a], which has repeated indices. The way to avoid this problem is to hide internal scalar indices inside the Scalar head. That is, the expression Scalar[p[a, -a]]^2 is the correct way to express that object in xTensor.
Your Simplification call finds an improper expression and tries to fix it by returning an unambiguous expression (this doesn't always work, because ambiguous input may be incorrectly interpreted sometimes). Use then the command NoScalar, which will rename indices to avoid collisions, and finally use Simplification or ToCanonical again. You'll get the expected zero output.
Alternative, the command PutScalar (internally used by Simplification) adds the Scalar heads, and then you can call Simplification:
In:= p[a, -a] p[b, -b] - p[a, -a]^2 // PutScalar // Simplification