Solution (source code)

= Solution

The <closest point theorem in a Hilbert space> says that, for every nonempty closed <convex set> $C\subset H$ and $x\in H$, there is exactly one $p\in C$ minimizing $\|x-p\|$.

Put $d=\inf_{y\in C}\|x-y\|$ and choose $y_n\in C$ with $\|x-y_n\|\to d$. The midpoint belongs to $C$ because it is a <convex set>. The <parallelogram law> gives
$$
\|y_n-y_m\|^2
=2\|x-y_n\|^2+2\|x-y_m\|^2-4\left\|x-\frac{y_n+y_m}{2}\right\|^2
\leq2\|x-y_n\|^2+2\|x-y_m\|^2-4d^2\longrightarrow0.
$$
Thus $(y_n)$ is a <Cauchy sequence>. Completeness of the <Hilbert space> and closedness of $C$ give a limit $p\in C$, with $\|x-p\|=d$. Applying the same identity to two minimizers gives their squared distance at most zero, proving uniqueness.

The resulting projection is characterized by
$$
\boxed{\operatorname{Re}\langle x-p,z-p\rangle\leq0\quad(z\in C).}
$$
Indeed, differentiate $\|x-p-t(z-p)\|^2$ at $t=0^+$; the minimum there gives the inequality. Conversely, expanding $\|x-z\|^2$ proves minimality from this inequality. For a closed linear subspace, both signs of each direction are allowed, so $x-p$ is <orthogonal> to that subspace: this recovers the <orthogonal projection>.