Cool question!

Thanks to user lionelbrits for his answer that prompted me to pull out my mechanics books and check the definitions of "canonical transformation" given by different authors.

If you look in Goldstein's classical mechanics texts in the section on canonical transformations, then you'll find that canonical transformations are essentially defined as follows (I paraphrase)

**Goldstein Definition:** A transformation $f:\mathcal P\to\mathcal P$ on phase space $\mathcal P$ is canonical provided there exists a phase space function $K$ such that if $(q(t), p(t))$ is a solution to Hamilton's equations generated by $H$, then $(Q(t), P(t)) = f(q(t), p(t))$ is a solution to Hamilton's equations generated by $K$.

This is essentially the definition given by lionelbrits in his answer.

On the other hand, if you look, for example, in Spivak's mechanics text, then you'll find the following definition:

**Spivak's Definition:** A transformation $f:\mathcal P \to \mathcal P$ on phase space is canonical provided it preserves the symplectic form.

In more concrete terms (namely in canonical coordinates), Spivak's definition can be stated as follows:

The transformation $f(q,p) = (f^q(q,p), f^p(q,p))$ is canonical if and only if its Jacobian (derivative) matrix preserves the symplectic matrix $J$, namely
\begin{align}
f'(p,q)\,J\,f'(p,q)^t = J
\end{align}
where
\begin{align}
J=\begin{pmatrix}
0 & I_n \\
-I_n & 0 \\
\end{pmatrix},\qquad
f' = \begin{pmatrix}
\frac{\partial f^q}{\partial q} & \frac{\partial f^q}{\partial p} \\
\frac{\partial f^p}{\partial q} & \frac{\partial f^p}{\partial p} \\
\end{pmatrix}
\end{align}
where $2n$ is the dimension of phase space and $I_n$ is the $n\times n$ identity matrix.

It also turns out that

If a transformation is canonical in the sense defined by Spivak, then it is canonical is the sense of Goldstein with $K = H\circ f^{-1}$

but the converse is not true. In fact, this example you brink up is a counterexample to the converse! What lionelbrit showed in his answer is that the example you have written is a canonical transformation in the sense of Goldstein, but, as you should try to convince yourself (I did), the function $K = H\circ f^{-1}$ that you wrote down by inverting the transformation and plugging back into $H$ leads to Hamilton's equations that are not satisfied by $(Q(t), P(t)) = f(q(t), p(t))$. You can show this directly by writing down the equations of motion. You can also show this by computing the Jacobian of the transformation and showing that it does not preserve the symplectic matrix. In fact, you should find that the Jacobian is given by
\begin{align}
f'(q,p)=\begin{pmatrix}
1 & 0 \\
-\frac{1}{2\sqrt{q}} & \frac{1}{2\sqrt{p}} \\
\end{pmatrix}
\end{align}
and that
\begin{align}
f'(q,p) J f'(q,p)^t = \frac{1}{2\sqrt{p}} J
\end{align}
In other words, the Jacobian of the transformation preserves the symplectic matrix up to a multiplicative factor.

**Speculation.** I'm going to go out on a limb and guess that your professor calls Goldstein's definition a "local canonical transformation" and Spivak's definition a "canonical transformation." If we adopt this terminology, then it's clear from our remarks that the $K$ he gives shows that your example is a *local* canonical transformation, but that the transformation is not canonical.

## Best Answer

See What's the point of Hamiltonian mechanics? for a closely related question. The answers in that thread mention various benefits with the Hamiltonian formulation, among other things:

Analysis of structural patterns, symmetries & conservation laws, separability & integrability, Liouville theorem, Hamilton-Jacobi theory, etc, without solving the EOMs.

Contact to (mainly non-relativistic) quantum mechanics and statistical physics.

If we are only interested in solving the EOMs, then the Lagrangian formulation is usually easier.

In this answer, we assume that by a canonical transformation$^1$ (CT) OP means a symplectomorphism $f:M\to M$ on a symplectic manifold $(M,\omega)$ with Hamiltonian function $H:M\to\mathbb{R}$. Symplectomorphism are diffeomorphisms that respect the Poisson bracket $\{\cdot,\cdot\}$.

Darboux Theorem guarantees the existence of local Darboux/canonical coordinate charts. A symplectomorphism takes local Darboux/canonical coordinates into local Darboux/canonical coordinates.

Note that from a geometric point of view the important construct is the Poisson bracket itself. In contrast, the local Darboux/canonical coordinates are in principle dispensable.

Example:Let us here assume no explicit time dependence for simplicity. Then under a symplectomorphism $f$ a constant of motion $Q:M\to\mathbb{R}$ with $\{Q,H\} =0$ turn into a constant of motion $f^{\ast}Q:=Q\circ f$ with $\{f^{\ast}Q,f^{\ast}H\} =0$.--

$^1$ For various definitions of a CT, see this Phys.SE post.