Is the distance of two affine subspaces in Hilbert space always attainable? I have two affine subspaces $C$ and $D$ in Hilbert space $\mathcal{H}$. Define the distance between the two subspaces as $d(C, D) := \inf_{x\in C, y\in D} d(x, y)$, where $d(x, y)$ is the metric induced by the inner product defined in the Hilbert space. My question is whether this infimum is always attainable. I don't known how to prove either case.
Edit: I've removed the diagonal part since it is not related to this question.
 A: This is not true, even for closed affine subspaces.  For instance, let $\mathcal{H}$ have an orthonormal basis $(e_n)_{n\in\mathbb{N}}$.  Let $f_n=e_{2n}+2^ne_{2n+1}$ and let $F$ be the closed span of all the $f_n$.  Let $C$ be the closed span of the $e_{2n+1}$, and let $D$ be the affine subspace $v+F$ where $v=\sum 2^{-n}e_{2n}$.  Then for any $x\in\mathcal{H}$, $d(x,C)=\|Px\|$ where $P$ is the orthogonal projection onto $C^\perp$.  Since $v\in C^\perp$, your question is then whether there exists $x\in F$ which minimizes $\|P(v-x)\|=d(v,Px)$.
Now note that $Pf_n=e_{2n}$ so if we let $x_N=\sum_{n=0}^N 2^{-n}f_n$ then $x_N\in F$ for each $N$ and $Px_N\to v$.  So, if there exists $x\in F$ which minimizes $d(v,Px)$, then we must have $Px=v$.  Since the $f_n$ are an orthogonal basis for $F$, we can write such an $x$ as $\sum c_n f_n$ for scalars $c_n$, and then $\langle x,e_{2n}\rangle=c_n$.  So if $Px=v$, we must have $c_n=2^{-n}$ for each $n$.  But the sum $\sum 2^{-n}f_n$ does not converge since $\|f_n\|>2^n$, so no such $x$ exists.
I don't know what you mean by "the diagonal of $\mathcal{H}$", but by applying a translation and a unitary operator to everything in this example, you can get a similar example where $D$ is an arbitrary closed affine subspace of $\mathcal{H}$ whose dimension and codimension are both infinite.
