Contact systems Hamiltonian and Lagrangian systems mathematics