Solution (source code)

= Solution

Use the <standard symplectic form> $\omega_0=\sum_{j=1}^n dq_j\wedge dp_j$. A <canonical transformation> is a <diffeomorphism> $f$ preserving this <symplectic form>:
$$
\boxed{f^*\omega_0=\omega_0.}
$$
Thus, writing $f(q,p)=(Q,P)$, the defining identity is $\sum_jdQ_j\wedge dP_j=\sum_jdq_j\wedge dp_j$. For a local <canonical transformation>, require this on its open domain. In particular preservation of the <symplectic form>, rather than just of <phase-space volume>, is the condition in dimensions greater than two.

Throughout these solutions choose the <Hamiltonian vector field> convention $\iota_{X_F}\omega=dF$. It gives $\dot q=F_p$, $\dot p=-F_q$ and agrees with the positive coordinate <Poisson bracket> used below. The opposite convention for <Hamiltonian vector fields> changes signs in the <Lie bracket of vector fields> identity but none of the commuting or integrability conclusions.