Solution (source code)

= Solution

Use the separation vector $\boldsymbol r$ from the <star> to the <comet>, and let $m_{\rm red}=mM_\star/(m+M_\star)$. The <two-body problem> separates into uniform <centre of mass> motion and
$$
\ddot{\boldsymbol r}=-\frac{\mu}{r^3}\boldsymbol r,\qquad \mu=G(M_\star+m).
$$
Taking a cross product with $\boldsymbol r$ proves <conservation of angular momentum>; taking the scalar product with $\dot{\boldsymbol r}$ proves <conservation of energy>. The relative constants are
$$
\boldsymbol h=\boldsymbol r\times\dot{\boldsymbol r},\qquad \varepsilon=\frac{v^2}{2}-\frac{\mu}{r}.
$$
The total relative <angular momentum> and <energy> are $m_{\rm red}\boldsymbol h$ and $m_{\rm red}\varepsilon$, respectively. The conserved <eccentricity vector> is $\boldsymbol e=\dot{\boldsymbol r}\times\boldsymbol h/\mu-\widehat{\boldsymbol r}$. Its scalar product with $\widehat{\boldsymbol r}$ gives $r=h^2/[\mu(1+e\cos f)]$, with $f$ the <true anomaly>. The <periapsis> and <apoapsis> distances are therefore $h^2/[\mu(1+e)]$ and $h^2/[\mu(1-e)]$. Their sum is twice the <semi-major axis>, so
$$
\boxed{h=\sqrt{\mu a(1-e^2)}}.
$$
At either apsis $v=h/r$; substituting an apsidal radius gives $\varepsilon=-\mu/(2a)$. Thus the <specific orbital energy> implies the <vis-viva equation>
$$
\boxed{v=\sqrt{\mu\left(\frac2r-\frac1a\right)}}.
$$
These are exact relative-coordinate formulas for an <elliptic orbit>, $0\leq e<1$. In the barycentric frame the <comet>'s speed is $M_\star/(M_\star+m)$ times the relative speed; the printed identification with the <comet>'s stellar orbital speed uses $M_\star\gg m$.