Solution (source code)

= Solution

On a locally right-moving branch with $\bar k,\bar\omega>0$, a spatial phase increase of $2\pi$ counts one wave. The local number of waves per unit length and the number passing a fixed point per unit time are
$$
\boxed{n_w=\frac{\bar k}{2\pi},\qquad j_w=\frac{\bar\omega}{2\pi}.}
$$
The physical unsigned counts use absolute values on other branches; the signed phase convention is useful for the conservation law. A phase change around a small spacetime rectangle must close. Equivalently, $\bar k_t=\Theta_{xt}$ and $\bar\omega_x=-\Theta_{tx}$, so
$$
\boxed{\frac{\partial\bar k}{\partial t}+\frac{\partial\bar\omega}{\partial x}=0,\qquad\frac{\partial n_w}{\partial t}+\frac{\partial j_w}{\partial x}=0.}
$$
This <wave conservation equation> states that the wave count in an interval changes by the crest flux through its ends, provided the smooth phase description has no defects or creation of crests inside. It is phase compatibility, distinct from energy conservation or wave-action conservation.