Solution (source code)

= Solution

Write $\iota_C$ for the <indicator functional of a constraint set> $C$ and $q(u)=\|u\|^2/2$. Then
$$
d_C=\iota_C\mathbin\square q.
$$
Both terms are <convex>, hence their <infimal convolution> is the <convex> <squared distance to a convex set>. The <closest point theorem in a Hilbert space> supplies the unique <metric projection onto a closed convex set> $P_Cu$ and gives $d_C(u)=\|u-P_Cu\|^2/2$.

Identify the <Hilbert space> with its <dual space> using the <Riesz representation theorem>. Completing the square yields $q^*(p)=\|p\|^2/2$, while $\iota_C^*(p)=\sup_{v\in C}\langle p,v\rangle=\sigma_C(p)$ is the <support function>. The <conjugate of the squared distance to a convex set> is therefore
$$
\boxed{d_C^*(p)=\frac12\|p\|^2+\sigma_C(p).}
$$
For the closed unit ball, the <metric projection onto a closed convex set> is $P_Cu=u$ if $\|u\|\leq1$, and $P_Cu=u/\|u\|$ otherwise. Therefore
$$
\boxed{d_C(u)=\frac12\bigl(\max\{\|u\|-1,0\}\bigr)^2,\qquad
d_C^*(p)=\frac12\|p\|^2+\|p\|.}
$$
The last equality uses the <Cauchy-Schwarz inequality> to compute the unit ball's <support function>, attained in the direction of $p$ when $p\neq0$.