Problem about Weierstrass Approximation Let f be a continuous function on [0, 1].The moments of f can refer to the quantities $\int_0^1x^nf(x)dx$
for n = 0,1,2...    . Prove that two continuous functions defined on [0, 1] are identical if they have the same sequence of moments.
I know we have to use Weierstrass Approximation Theorem. But I don't know use it on this problem.
 A: As a lemma, suppose that $f$ is continuous and that
$$\int_0^1 x^nf(x)\,dx = 0$$
for all $n\in\mathbb N$. We'll show that 
$$\int_0^1 f(x)^2\,dx = 0$$
which, of course, implies that $f$ is identically zero on $[0,1]$ since, otherwise, the above integral would be positive.
Then, given two functions $f$ and $g$ with identical moments, we can apply the above lemma to $f-g$ to see that $f$ and $g$ are equal.
To prove the lemma, let $\varepsilon>0$, let $M$ denote the maximum of $f$ on $[0,1]$, and, by the Weierstrass Approximation Theorem, choose a polynomial $p(x)$ such that $|f(x)-p(x)|<\varepsilon/M$ for every $x\in[0,1]$. Then, by linearity of the integral,
$$\int_0^1 f(x)p(x)\,dx = 0.$$
Thus,
\begin{align}
  \left|\int_0^1 f(x)^2\,dx\right| &= 
    \left|\int_0^1 \left(f(x)^2-f(x)p(x)\right)\,dx\right| \\
  &\leq \int_0^1 \left|f(x)^2-f(x)p(x)\right|\,dx \\
  &= \int_0^1 |f(x)|\left|f(x)-p(x)\right|\,dx \leq M\frac{\varepsilon}{M}=\varepsilon
\end{align}
Since $\varepsilon>0$ was arbitrary, it follows that 
$$\int_0^1 f(x)^2\,dx = 0.$$
A: From a Hilbert space theory point of view:
Denote the set of polynomials in $[0,1]$ by $\mathcal P$. The idea is to consider $\mathcal P$ as a dense linear subspace of $L^2([0,1])$, the Hilbert space of square-integrable functions defined in $[0,1]$ with inner product
$$
\left<f,g\right>=\int_0^1 f(x)\overline{g(x)}\ dx.
$$
The Weierstrass approximation theorem tells us that $\mathcal P$ is dense in 
$C([0,1])$ with respect to the sup norm. It is straightforward from this that it will be also dense with respect to the $L^2$ norm. Since it is well known that $C([0,1])$ is dense in $L^2([0,1])$, we obtain that $\mathcal P$ is in turn dense in $L^2([0,1])$. 
Hence, since $\mathcal P$ is the linear span of $\{1,x,x^2,\dots\}$, if $f$ and $g$ are such that their moments are equal then
$$
\left<f-g,x^n\right>=0,\qquad \forall n=0,1,2,\dots
$$
And we can conclude that $f=g$ in $L^2$. 
