With the version of Cadabra currently on github (2.3.1.5) you can write a small function which examines every term in the expression, counts the number of '5' indices, and flips the sign if there is an odd number of pairs. Starting from

```
{m,n,p}::Indices(space);
{\mu,\nu}::Indices(subspace, parent=space);
ex:=A^{m n} B_{m n};
split_index(ex, $m, \mu, 5$, repeat=True);
```

which produces $$A^{\mu \nu} B_{\mu \nu}+A^{\mu 5} B_{\mu 5}+A^{5 \mu} B_{5 \mu}+A^{5 5} B_{5 5},$$ you can define

```
def flip5(ex):
for node in ex:
for term in node.terms():
cnt=0
for index in term.indices():
if index.name=="1" and index.multiplier==5:
cnt+=1
term.multiplier *= (-1)**(cnt//2)
return ex
```

and then do

```
flip5(ex);
```

to get $$A^{\mu \nu} B_{\mu \nu}-A^{\mu 5} B_{\mu 5}-A^{5 \mu} B_{5 \mu}+A^{5 5} B_{5 5}$$