“Smart” substitution of subexpressions