Hypothesis of Stone-Weierstrass Theorem Why do we need compactness in the space as hypothesis in Stone-Weierstrass Theorem?


  Theorem:
  Let $A \subset C(K)$ such that
  
  
  $A$ is a subalgebra that vanishes nowhere.
  For each $x, y \in K $ with $x \neq  y $, there exists $f \in A$ such that $f(x)\neq f(y)$.
  
  
  Then $ \overline A = C(K)$, where $C(K)$ is the space of continuous functions over the compact space $K$.
The Stone-Weierstrass theorem can be generalized in various ways, as discussed below (mostly based on General Topology by Willard, section 44). But presenting things in the greatest possible generality usually goes counter to the purpose of writing a textbook. Textbook authors are more concerned with presenting an insightful, digestible proof, and with proving the results that are actually used later. 

Functions vanishing at infinity

The easiest generalization is to consider the algebra $C_0(X)$ of functions "vanishing at infinity" on a locally compact space $X$. This is the form that  Wikipedia presents. It's not really much of a generalization, since one can consider the one-point compactification of $X$, denoted $\widehat {X}=X\cup\{\infty\}$, and extend functions to $\infty$ by zero. By including the constant function in subalgebra $A$ one gets to the point where the compact case of Stone-Weierstrass can be used. Then one observes that to approximate a function that vanishes at $\infty$,  one does not need the constant functions after all. 

Bounded functions

The space of all bounded real-valued continuous functions $C_b(X)$ still has the uniform norm, so one can hope to generalize the Stone-Weierstrass theorem verbatim. This does not actually work, though: let $X=[0,\infty)$ and denote by $A$ the algebra of all continuous functions $f\colon X\to\mathbb R$ such that $\lim_{x\to\infty} f(x)$ exists. This is a closed subalgebra which vanishes nowhere and separates points, but it does not coincide with $C_b(X)$; for example $\sin x\notin A$. 

To state a version of Stone-Weierstrass theorem for this case, let's say that $Z\subset X$ is a zero set if there exists a continuous function $f:X\to\mathbb{R}$ such that $Z=f^{-1}(0)$. An algebra $A$ separates zero sets if for any two disjoint zero sets $Z_1$ and $Z_1$ there is $f\in A$ such that $\overline{f(Z_1)}\cap \overline{f(Z_2)}$ is empty. 

Theorem. Suppose $X$ is a Tychonoff space (also known as $T_{3\frac12}$ space). If an algebra $A\subset C_b(X)$ separates zero sets, contains constant functions, and is closed in the uniform norm, then $A=C_b(X)$. 

The proof still involves compactification of $X$, but this time one needs the Stone–Čech compactification.

Compact-open topology

If one considers $C(X)$, the set of all continuous functions on a non-compact space $X$, then that's no longer a normed space. While uniform convergence still makes sense, one can't hope to have uniform approximation here: for example, $f(x)=e^x$ cannot be uniformly approximated by polynomials on $\mathbb{R}$. A natural decision is to equip $C(X)$ with the compact-open topology; i.e., it's a locally convex space with topology generated by seminorms $\|f\|_K = \sup_K|f|$, for all compact subsets $K\subset X$. 

Theorem. Suppose $X$ is a Tychonoff space. If $A\subset C(X)$ is an algebra that is closed in the compact-open topology, separates the points of $X$, and contains the constant functions, then $A=C(X)$. 

For example, this implies that for every continuous function $f:\mathbb{R}\to\mathbb{R}$ there is a sequence of polynomials $p_n$ such that 
$$
\forall M\ \lim_{n\to\infty}\sup_{|x|\le M}|f(x)-p_n(x)| =0
$$

Topology of uniform convergence

Willard presents two more forms of the Stone-Weierstrass theorem, using the topology of uniform convergence on $C(X)$ (which makes it a very disconnected topological space). They impose strong additional assumptions on the algebras of functions and are too involved to be stated here.
We need  the compactness of M because we are gonna cover it with a finite subcover of neightboors of a given point q arbitrary.

What a simple reasoning..