TITLE: When is $V=U\oplus U^{\perp}$?
QUESTION [8 upvotes]: Let $V$ be a (infinite dimensional) vector space with inner product $(,)$ and $V$ may not be complete with the metric induced from the norm. Let $U$ be a subspace of $V$. What is the necessary and sufficient condition that can guarantee
$$
U\oplus U^{\perp}=V?
$$
Is the hypothesis $U$ has finite codimension enough?
Update:
As others pointed out, $U$ is closed or $U$ has finite codimension is not enough. I `know' that the following condition is enough: If there exist a finite dimensional subspace $W\subseteq V$ such that $W^{\perp}\subseteq U$, then $V=U\oplus U^{\perp}$. But neither can I prove it, nor do I know a better condition to replace it or show the criterion is wrong. So I ask at here.

REPLY [3 votes]: I'm adding another answer, now that you've changed the question.
Assume that $W$ is finite-dimensional with $W^{\perp} \subseteq U$. The goal is to show that $U\oplus U^{\perp} = V$. All '$\oplus$' decompositions are orthogonal in what follows.
Because $W$ is finite-dimensional then $V=W\oplus W^{\perp}$ which can be seen by choosing any basis of $W$ and using Gram-Schmidt to find an orthonormal basis $\{ e_{1},\cdots,e_{n}\}$ of $W$. Then every $v\in V$ can be written as
$$
            v = \left(v-\sum_{j=1}^{n}(v,e_{j})e_{j}\right)+\sum_{j=1}^{n}(v,e_{j})e_{j}.
$$
So $W^{\perp}\oplus W=V$. Assuming that $W^{\perp}\subseteq U$, it follows that every $u \in U$ can be written as $u=w_{\perp}+w$ where $w_{\perp}\in W^{\perp}$ and $w\in W$. Because $w_{\perp} \in W^{\perp}\subseteq U$, then $u-w_{\perp}=w \in U$, which gives the decomposition
$$
                    U = W^{\perp}\oplus(U\cap W).
$$
Because $U\cap W$ is a finite-dimensional subspace of $W$, then it follows that there exists a finite-dimensional subspace $U'$ such that $(U\cap W)\oplus U'=W$; $U'$ is found by completing an orthonormal basis of $U\cap W$ to one for $W$. Therefore $(U\cap W)\oplus U'=W$. Finally,
$$
\begin{align}
       U\oplus U' & = (W^{\perp}\oplus (U\cap W))\oplus U' \\
                  & = W^{\perp}\oplus((U\cap W)\oplus U') \\
                  & = W^{\perp}\oplus W = V.
\end{align}
$$
This is enough to give $U'=U^{\perp}$ and $U\oplus U^{\perp}=V$.