Understanding Hamiltonian mechanics: (1) The math