Hamiltonian systems as selfdual equations