Calculation of Hamiltonian normal form