Simulating hamiltonian dynamics