Define a couple of arbitrary spacetime tensors for exploration purposes
Enter, for example, this tensorial expression, with a contravariant free index
To check the repeated and free indices in an expression use Check
So (3) has and the contravariant as free indices. Substitute now : the standard subs command will only substitute the covariant
Consequently, the resulting expression is not equivalent to (3): it now has four free indices
To substitute both covariant and contravariant repeated indices obtaining an expression equivalent to original one use
Substitute now the contravariant by ; the standard subs command will fail because contravariant indices are prefixed by ~, so this returns (3) as given
To make it work with subs you would need to substitute ~rho = ~beta instead. Using SubstituteTensorIndices you get the desired result regardless of this subtlety
To substitute several indices at once, enclose the substitution equations in a set or a list
After substituting, tensors are re-evaluated; in this example, becomes 1 and the normalized form of g_ is presented with it in the first place, so switching places with
To avoid this re-evaluation of tensors in the result use evaluatetensor = false