TITLE: Polynomials are dense in $L^2$
QUESTION [7 upvotes]: I know that the function $e^{inx}$ can be uniformly approximated on $[-\pi,\pi]$ by polynomials in $x$. I want to use this to show that polynomials are dense in $L^2([-\pi,\pi])$.
Suppose that $f\in L^2([-\pi,\pi])$. I want to show that for any $\epsilon>0$, there is a polynomial $p$ such that $|\int_{-\pi}^\pi (f(x)-p(x))^2dx|<\epsilon$. I was thinking about writing $f$ in terms of its coefficients, i.e. $$f(x)=\sum_{n=-\infty}^\infty \hat{f}(n)e^{inx}$$ But I'm still not sure how this can lead to the polynomial $p$.

REPLY [7 votes]: Let $\epsilon >0$. Then, there exists some $N$ so that
$$\|f(x)- \sum_{n=-N}^N \hat{f}(n)e^{inx} \|_2 < \frac{\epsilon}{2}$$
Now for each $-N \le n \le N$ you can find some polynomial $P_n$ so that
$$\| \hat{f}(n) e^{inx} - \hat{f}(n)P_n \|_2 < \frac{\epsilon}{2(2N+1)}$$
Now prove that
$$P= \sum_{n=-N}^N \hat{f}(n) P_n$$
works.