The following code should be useful:
{M,N,O,P,Q,R,S}::Indices(full, position=independent);
{\alpha,\beta,\mu,\nu,\sigma,\gamma,\lambda}::Indices(subspace1, position=independent, parent=full);
{\alpha,\beta,\mu,\nu,\sigma,\gamma,\lambda}::Integer(0..d-1).
w::Coordinate;
g_{\mu\nu}::Metric.
g^{\mu\nu}::InverseMetric.
g_{\mu\nu}::Symmetric.
g^{\mu\nu}::Symmetric.
g^{\mu}_{\nu}::KroneckerDelta.
g_{\mu}^{\nu}::KroneckerDelta.
from cdb.utils.indices import *
ex:=g_{M N} g^{M O} P^N;
replace_index(_,r"g",r'O',r'\mu');
split_index(_, $M,\mu,w$,repeat=True);
eliminate_metric(_);
eliminate_kronecker(_);
substitute(_,$P^w->A$);