How do we know the complex exponentials "span" the set of all real functions?
Solution 1:
Here is one explanation (I will gloss over many technical details, but it should give an idea at least):
Fix some $N$, and consider the subset $S_N$ of $[0,2\pi]$ consisting of the points $0, 2\pi/N, 4\pi/N, \ldots, (N-1)2\pi/N$.
Straightforward linear algebra shows that a function on the finite set $S_N$ can be written uniquely as a linear combination of the exponentials $e^{i n x}$, for $0 \leq n \leq N-1$.
Precisely, if $\phi$ is a function on $S_N$, then $\phi(x) = \sum_{n=0}^{N-1} a_n e^{2\pi i n/N},$ where $$a_n = \dfrac{1}{N}\sum_{n = 0}^{N-1} \phi(x) e^{-2\pi i n/N}.$$
This is finite Fourier theory. We will now show that Fourier theory for functions on $[0,2\pi]$ is a kind of limit of the finite theory.
Suppose now that a continuous function $f$ is orthogonal to every complex exponential, i.e. such that all the $c_n$ vanish. Let $\phi$ be the restriction of $f$ to $S_N$. Since $f$ is continuous, if we take $N$ very large, then it will be nearly constant between the various points of $S_N$, and so the sum computing the $a_n$ for $\phi$ will be very nearly equal to the integral computing the $c_n$ for $f$. But these $c_n = 0$ by assumption, so the $a_n$ for $\phi$ will be very small. Hence $f$ will be very small in value on $S_N$.
Letting $N \to \infty$, the approximation will get better and better, and so, since the union of the $S_N$ is dense in $[0,2\pi]$, we will conclude that in fact $f$ vanishes on $[0,2\pi]$.
Now an interpolation argument, using the fact that continuous functiosn are dense in $L^2$, will show that in fact any $L^2$ function orthogonal to all the $e^{i n x}$ must vanish. Thus the span of the $e^{i n x}$ has zero orthogonal complement in $L^2$, and hence this span must be dense in $L^2$, as required.