Cadabra

expand_dummies

Expand contracted dummy index pairs
Expand contracted dummy index as a sum over coordinate values optionally taking a list of component values to be applied. The behaviour is similar to evaluate but free indices are not split into components. The minimal information needed for this to work is a declaration of the indices used, and a declaration of the values that those indices use:
{r,t}::Coordinate. {\mu, \rho, \lambda}::Indices(values={t,r}). ex:= x_{\mu} g_{\rho \lambda} k^{\rho} k^{\lambda};
\(\displaystyle{}x_{\mu} g_{\rho \lambda} k^{\rho} k^{\lambda}\)
The list of component values should be given just like the list of rules for the substitute algorithm, that is, as equalities. If values are defined for some components of an object, then any missing components are assumed to be 0.
rl:= [ g_{t t} = -1, g_{r r} = 1, k^{t} = t, k^{r} = 1]; expand_dummies(ex, rl);
\(\displaystyle{}\left[g_{t t} = -1, g_{r r} = 1, k^{t} = t, k^{r} = 1\right]\)
\(\displaystyle{}-x_{\mu} t t+x_{\mu}\)
If no components are given it returns the full expanded sum over coordinates:
ex:= r_{\mu} g_{\rho \lambda} k^{\rho} k^{\lambda}. expand_dummies(ex);
\(\displaystyle{}r_{\mu} g_{t t} k^{t} k^{t}+r_{\mu} g_{t r} k^{t} k^{r}+r_{\mu} g_{r t} k^{r} k^{t}+r_{\mu} g_{r r} k^{r} k^{r}\)