How to fix this argument that the periodic functions on $[-L/2,L/2]$ generate a dense subspace of $L^2[-L/2,L/2]$? In V. Moretti's "Spectral Theory and Quantum Mechanics," example 3.32 (1), he attempts to show that the functions
$$f_n(x)=\frac{1}{\sqrt{L}}e^{i\frac{2\pi n}{L}x},$$
where $n\in\mathbb Z,x\in[-L/2,L/2]$ for fixed $L>0$, generate a dense subspace of $L^2[-L/2,L/2]$. But I think his argument is wrong, as confirmed by this post and discussed by me below. My question is, how can we most easily correct this proof, preferably without resorting to an entirely different method?
Let $S=\operatorname{span}\{f_n\}_{n\in\mathbb N}$. Moretti's approach is to show that $S$ is dense in $C[-L/2,L/2]$ (the continuous functions from $[-L/2,L/2]$ to $\mathbb C$), and then that $C[-L/2,L/2]$ is dense in $L^2[-L/2,L/2]$. But to show that $S$ is dense in $C[-L/2,L/2]$, he invokes the Stone-Weierstrass theorem, which requires that $S$ separates points in $[-L/2,L/2].$ From what I can tell (and as is similarly claimed in the above-linked post), $S$ does not separate the endpoints $-L/2$ and $L/2$. Can this approach still be salvaged, and if so, how?
 A: The proof is essentially correct. The fix is to prove the density instead on the torus, ie. $[-L/2,L/2]$ with the endpoints quotiented together. Then they are the same point, so there’s nothing to separate! (Note that S-W still works on a compact Hausdorff space.) Then since null sets don’t matter, $L^2$ on the torus is naturally identified with $L^2$ on this interval.
A: You salvage the approach by showing that the continuous functions such that $f(-L/2)=f(L/2)$ are dense in $L^2$. This is easy to show as you can always consider a small interval around a point where you don't need to approximate your function.
That is, given $f\in L^2$ and $\varepsilon>0$, find $g$ continuous with $\|f-g\|<\varepsilon/2$. Then define $h$ to be continuous, equal to $g$ on $[-L/2,L/2-\varepsilon^2/(2\|g\|_\infty)^2]$, with $\|h\|_\infty=\|g\|_\infty$, and with $h(-L/2)=h(L/2)$. Then
$$
\|f-h\|_2\leq \|f-g\|_2+\|g-h\|_2<\frac\varepsilon2+\frac{\varepsilon}2=\varepsilon.
$$
A: Write $C_0[-L/2,L/2]$ for the subspace of $C[-L/2,L/2]$ consisting of the $f$
with $f(-L/2)=f(L/2)$. Then by Stone-Weierstrass, the $f_n$ generate an $L^2$-dense
subspace of $C_0[-L/2,L/2]$ and we know $C[-L/2,L/2]$ is $L^2$-dense in $L^2[-L/2,L/2]$.
To complete the proof we need that
$C_0[-L/2,L/2]$ is $L^2$ dense in $C[-L/2,L/2]$.
But $C_0[-L/2,L/2]$ has codimension $1$ in $C[-L/2,L/2]$, so we only need
to show that there's one function $h\in C[-L/2,L/2]$ but not in $C_0[-L/2,L/2]$
that can be $L^2$-approximated by functions in $C_0[-L/2,L/2]$. We can take $h(x)=x$
and write down a sequence in $C[-L/2,L/2]$ converging to $h$ in the $L^2$-norm.
