Solution (source code)

= Solution

<Hamilton's equations> give $\dot X=P/m+O(\lambda^2)$ and $\dot P=-m\omega^2X+O(\lambda^2)$. Hence, with constants $A\geq0$ and $\delta$ fixed by transformed <initial data>,
$$
\boxed{X(t)=A\cos\vartheta+O(\lambda^2),\qquad
P(t)=-m\omega A\sin\vartheta+O(\lambda^2),\qquad
\vartheta=\omega t+\delta.}
$$
An equivalent form uses $X(0)\cos\omega t+[P(0)/(m\omega)]\sin\omega t$ for $X(t)$. The indicated errors are a fixed-time perturbative statement; a higher-order <frequency> correction can accumulate <phase> on longer times.