# How to define a divergence-free vector or a traceless tensor in xAct?

I'm trying to implement a Friedmann-Lemaître-Robertson-Walker metric + a perturbation in a scalar-vector-tensor split in mathematica, using xAct. The S-V-T decomposition comes with some rules for the vector and tensor parts, i.e. the vector is transverse and divergence-free and the tensor is transverse and traceless. How can I implement this?

Divergence-free Vector

Can I make a rule, before I set a metric and have the corresponding covariant derivative? I need to set it before, because it is part of the metric...

Doing it later gives me

DFBRule =   MakeRule[{cd[a][Bv[-a]], 0}, PatternIndices -> All,
MetricOn -> All];
** MakeRule: Potential problems moving indices on the LHS.
Rules {1,1} have been declared as UpValues for Bv.


Traceless Tensor

DefTensor[Ct[a, b], M] knows only the argument symmetric, but not traceless. I thought, maybe, I could redefine it like

Ct[a,b]=MakeTraceless[Ct[a,b]]


But this only throws a couple of errors:

First::nofirst: {} has zero length and no first element.
ToCanonical::noident: Unknown expression not canonicalized: First[{}][-a,-b] .
ToCanonical::noident: Unknown expression not canonicalized: First[{}][-a,-b] .
ChangeFreeIndices::error: Inconsistent number of free indices.
Throw::nocatch: Uncaught Throw[Null] returned to top level.


TFRule = MakeRule[{Ct[a, -a], 0}, PatternIndices -> All,