The Theory of Substitutions and Its Applications to Algebra