Algebraic treatment of nonrelativistic and relativistic quantum equations and its relation to the theory of differential equations