Solution (source code)

= Solution

The <canonical momentum> of the <harmonic oscillator> is $p=\partial L_0/\partial\dot q=m\dot q$. Substituting $\dot q=p/m$ into the <Legendre transform in mechanics> gives
$$
\boxed{p=m\dot q,\qquad
H_0(q,p)=p\dot q-L_0=\frac{p^2}{2m}+\frac{m\omega^2q^2}{2}.}
$$