The direct sum of two closed subspace is closed? (Hilbert space)

In the sequence space $\ell^2$, let $X_1$ be the subspace of sequences $x = (x_0,x_1,x_2, \ldots)$ such that $x_{2n} = 0$ for all natural numbers $n$, and $X_2$ the subspace of sequences $x$ such that $x_{2n+1} = n x_{2n}$ for all $n$. It is easy to see that $X_1 \cap X_2 = \{0\}$, and that $X_1 + X_2$ is dense (e.g. it contains all sequences with finite support). However, $X_1 + X_2$ is not all of $\ell^2$, e.g. it can't contain the sequence $x_n = 1/(n+1)$: if this was $u + v$ with $u \in X_1$ and $v \in X_2$, we'd need $v_{2n} = x_{2n} = 1/(2n+1)$ and $v_{2n+1} = n/(2n+1)$, but then $\sum_n |v_n|^2 = \infty$.

When $X_1 \oplus X_2$ is not closed, the projection $P$ of $X_1 \oplus X_2$ onto $X_1$ must be unbounded: otherwise it would extend to a bounded linear operator $Q$ from $\overline{X_1 \oplus X_2}$ onto $X_1$; since $(I - P)x \in X_2$ for $x \in X_1 \oplus X_2$, we'd also have $(I-Q) x \in X_2$ for $x \in \overline{X_1 \oplus X_2}$. But then $x = Qx + (I-Q)x \in X_1 \oplus X_2$ for $x \in \overline{X_1 \oplus X_2}$, contradiction.


Let $X = H_{0}^1(0,1) \mathbin{\oplus_2} L^2(0,1)$ be the Hilbert space direct sum of the Sobolev space $H_{0}^1(0,1)$ (the completion of $C_{c}^\infty(0,1)$ with respect to the norm $\|f\|_{H^1} = (\|f\|_{L^2}^2 +\|f'\|_{L^2}^2)^{1/2}$) and the usual Hilbert space $L^2(0,1)$. Then $X$ is a Hilbert space with respect to the norm $\|(f,g)\| = (\|f\|_{H^1}^2 + \|g\|_{L^2}^2)^{1/2}$.

Let $i: H^1(0,1) \to L^2(0,1)$ be the natural inclusion. The graph $\Gamma = \{ (f,f)\,:\,f \in H_{0}^1\} \subset X$ of the function $i: H_{0}^1 \to L^2$ is closed because $i$ is bounded: $\|i(f)\|_{L^2} = \|f\|_{L^2} \leq \|f\|_{H^{1}}$. The subspace $U = H_{0}^{1}(0,1) \mathbin{\oplus_2} \{0\}$ is also closed in $X$. I claim that $\Gamma + U$ is not closed in $X$.

The image $i(H_{0}^1) \subset L^2$ is dense because $H_{0}^1(0,1)$ contains $C_{c}^\infty(0,1)$, and $i$ is not onto because functions in $H_{0}^1$ have absolutely continuous representatives. Therefore there is $g \in L^2 \smallsetminus H_{0}^1$ and there are $f_n \in H_{0}^1$ such that $\|g - f_n\|_{L^2} \to 0$. Now note that $(0,f_n) = (f_n,f_n) + (-f_n,0) \in \Gamma + U$, so $(0,g)$ is in the closure of $\Gamma + U$ but not in $\Gamma + U$ itself.

This is a special case of my answer here adapted to the Hilbert space setting.