Foundations of the theory of algebraic invariants