Solution (source code)

= Solution

Take upward <velocity> as positive, and consider the closed material system consisting of the rocket and the fuel it ejects during a short interval $dt$. Initially its mass and <momentum> are $m$ and $mv$. Let $\delta m>0$ be the ejected mass, so the rocket's mass change is $dm=-\delta m$. At the end its <velocity> is $v+dv$, while the ejected gas has inertial <velocity> $v-u$ to first order; its downward relative <velocity> need not be downward in the inertial frame.

The final total <momentum>, to first order, is
$$
(m-\delta m)(v+dv)+\delta m(v-u)=mv+m\,dv-u\,\delta m.
$$
Neglect air resistance and take the gravitational <acceleration> $g$ constant. The external gravitational impulse on this material system is $-mg\,dt$ to first order. <Newton's second law> therefore gives $m\,dv-u\,\delta m=-mg\,dt$, or
$$
\boxed{m\frac{dv}{dt}=-u\frac{dm}{dt}-gm.}
$$
The positive thrust is $-u\dot m$ because fuel loss makes $\dot m<0$. Applying $d(mv)/dt$ to the rocket alone without accounting for the escaping <momentum> would give the wrong equation.

For constant $u$ and positive mass, divide by $m$ and integrate from release at $t=0$:
$$
v(t)=-u\ln\frac{m(t)}{m_0}-gt.
$$
Thus the gravity-corrected <rocket equation> is equivalent to
$$
\boxed{m(t)=m_0\exp\left[-\frac{gt+v(t)}u\right].}
$$