# How to define a traceless tensor with xAct

I would like to define a tensor $$A_i^j$$ which is traceless ($$A_i^i = 0$$) and to obtain $$A_i^j \delta^i_j = 0$$ with xAct / xTensor / xCoba.

I first tried defining an antisymmetric tensor, since they are automatically traceless, but the final answer of the following code is not zero, but still $$A_i^j \delta^i_j$$.

<< xActxTensor
<< xActxCoba

dim = 3;

DefManifold[M, dim, {i, j, k, l, a, b, c, d}]

DefChart[ch, M, {1, 2, 3}, {x[], y[], z[]}, ChartColor -> Red]

metric = CTensor[DiagonalMatrix[{1, 1, 1}], {-ch, -ch}]

SetCMetric[metric, ch, SignatureOfMetric -> {2, 0, 0}]

DefTensor[A[-i, -j], M, Antisymmetric[{-i, -j}]]

A[-i, -j] metric[i, j]

1. How can I obtain the answer 0 for the above code?

2. And how can I define a general traceless tensor, not necessarily antisymmetric?

• I ask questions about xact on the xact google group. I searched for traceless in the conversation and found this discussion. I did not check if it could help you but maybe you could look at the other questions in the conversation (first link). Commented Oct 19, 2022 at 18:34

You just need to be careful when combining the abstract tensor in $$xTensor$$ defined by the DefTensor function and you coordinate chart defined in $$xCoba$$ you can use the following code to attain the right result

A[{a, ch}, {b, ch}] // ComponentArray // ComponentValue // Flatten
A[{a, ch}, {b, ch}] metric[{-a, -ch}, {-b, -ch}] // ContractBasis // ToValues


Which results in the expected $$0$$.

To make a traceless tensor you can define the tensor as normal and then add a rule

DefTensor[ T[-a,-b], M ];
TFRule = MakeRule[ { T[a,-a], 0 }, PatternIndices->All, MetricOn->All ];


Which can be used as any other rule, i.e.

T[a, -a] /. TFRule


results in $$0$$.

One can also define the rule

TFchRule = Sum[T[{i, ch}, {i, ch}], {i, dim}] -> 0


which works with explicit coordinates in a specific chart, as with A above

T[{a, ch}, {b, ch}] // ComponentArray // ComponentValue // Flatten
T[{a, ch}, {b, ch}] metric[{-a, -ch}, {-b, -ch}] // ContractBasis // ToValues
% /. TFchRule


which returns $$0$$ as well