Essence of Weierstrass approximation theorem. Weierstrass approximation theorem is a quite strong theorem,even stronger than the Taylor's theorem because:
Statement:Suppose $f:[a,b]\to \mathbb R$ is a continuous function then $\exists$ a sequence of polynomials $\{P_n\}$ converging uniformly to $f$.
1.It is an approximation supported by uniform convergence.
2.It can approximate any continuous function not necessarily differentiable/smooth one.
So,I want to understand its essence properly.In most of the books like Kumaresan and Rudin,a very mechanical proof is given;the proof obviously will not occur in mind naturally(unless he is a genius).Is there any proof that will come in mind naturally and quite intuitive and brings out the essence of that theorem?[Please note that I do not know Riemann Integrals,so the proof should not involve these things.]
       Also I want to understand why the domain set must be a compact interval in $\mathbb R$,i.e of the form $[a,b]$.Why is the assumption essential?Give me an example where we cannot approximate a function because domain is not compact.
 A: No bounded continuous function from $\mathbb R$ into itself (other than a constant) can be approximated uniformly on $\mathbb R$ by polynomials. This is because any non-constant polynomial $p$ has the property $|p(x)| \to \infty$ as $x \to \infty$. In particular $\sin\, x$ can  be approximated by polynomials uniformly on any interval of the type $[-N,N]$ but not on the whole real line. 
A: Let $\ f:(0;1] \rightarrow \mathbb R\ $ be such that
$$ \forall_{x\in(0;1]}\quad f(x)\ :=\ \cos\left(\frac \pi x\right) $$
Then
$$ \forall_{n=1}^\infty\quad f\left(\frac 1n\right)\ =\ (-1)^n $$
Let $\ g:(0;1]\rightarrow\infty\ $ be continuous and such that
$$ \forall_{n=1}^\infty\quad \left|g\left(\frac 1n\right)-(-1)^n\right| < \frac 12 $$
hence
$$ \forall_{n=1}^\infty\quad g\left(\frac 1{2\cdot n-1}\right) < -\frac 12
        \qquad\mbox{and}\qquad g\left(\frac 1{2\cdot n}\right) > \frac 12    $$
It follows that
$$ \forall_{n=1}^\infty\,\ \exists_
      {x_n\in\left[\frac 1{n+1};\frac 1n\right]}
              \,\ g(x_n)\ =\ 0 $$
Thus, function $\ g\ $ has infinitely many roots hence it cannot be a polynomial.
We see that there does not exist a polynomial $g$ which approximates $\ f\ $
within $\ \frac 12,\ $, the uniform distance is $\ |g-f|\ \ge \frac 12.$
