Solution (source code)

= Solution

For a real image, $u>f$ and $v=fu/(u-f)>0$. The object-to-image separation is
$$
D=u+v=\frac{u^2}{u-f}.
$$
Its excess above $4f$ factors into a nonnegative expression:
$$
D-4f=\frac{u^2-4f(u-f)}{u-f}=\frac{(u-2f)^2}{u-f}\ge0.
$$
Therefore
$$
\boxed{D_{\min}=4f,\qquad u=v=2f}.
$$
At this minimum the image is inverted and has unit absolute <magnification>. The restriction to a real object and a real image matters: the positive separation used here is not the same quantity as a signed distance to a virtual image.