The Stone-Weierstrass Theorem

Can every continuous function on a closed interval be approximated by a polynomial? The approximation can be as close as one likes. This question was first answered affirmatively by Weierstrass in 1885. It seems almost too good to be true. Polynomials are algebraically rigid objects. They are built from finitely many additions and multiplications. Continuous functions, by contrast, can be wild. They may be nowhere differentiable and defined by no formula at all. Yet the answer is yes, uniformly, on any compact interval. The Stone–Weierstrass theorem was proved by Marshall Stone in 1937. It explains why this works. It does so by isolating the exact algebraic and topological structure responsible for it. It also generalizes the result in two ways. It extends from intervals to arbitrary compact Hausdorff spaces. It extends from polynomials to any suitably rich family of functions. The idea matters for a key reason. It converts a soft topological problem into a checkable algebraic one. The soft question is: is a set of functions dense? The algebraic question is: is this set closed under sums and products? Does it also distinguish points? This shift is the engine behind an enormous swath of analysis. It certifies that trigonometric polynomials are dense in the continuous periodic functions. These form the analytic backbone of Fourier series. It also shows that polynomials in several variables approximate continuous functions on compact sets. Many function bases used in numerical analysis and approximation theory are complete in the uniform norm. The big picture is this. Fix a compact Hausdorff space KK and consider C(K,R)C(K,\mathbb{R}). This is the set of continuous real-valued functions on KK. It is equipped with the sup norm ∥f∥∞=sup⁡x∈K∣f(x)∣\|f\|_\infty = \sup_{x\in K}|f(x)|. A subalgebra A⊆C(K,R)A \subseteq C(K,\mathbb{R}) is a linear subspace closed under pointwise multiplication. The theorem states the following. Suppose AA contains the constants and separates points. That means: for every x≠yx\ne y in KK, there is f∈Af\in A with f(x)≠f(y)f(x)\ne f(y). Then AA is dense in C(K,R)C(K,\mathbb{R}) with respect to ∥⋅∥∞\|\cdot\|_\infty. Everything else follows as a corollary of this. This includes Weierstrass's original polynomial theorem. It includes density of trigonometric polynomials. It also includes density of polynomials in several real variables. Each case is obtained by checking these two hypotheses for a specific algebra. This article states and proves the theorem in full rigor. It builds the classical approximation-of-∣x∣|x| lemma. This lemma makes the lattice argument work. It derives the original Weierstrass approximation theorem as a clean corollary. It works two nontrivial examples. These show the machinery in action on genuinely asymmetric functions. It closes by connecting the theorem to its most important descendant. That descendant is the rigorous theory of Fourier Series: Rigorous Foundations.

Key takeaways
  • The theorem gives a purely algebraic criterion — subalgebra, contains constants, separates points — that forces uniform density in C(K,R)C(K,\mathbb{R}).
  • It generalizes Weierstrass's 1885 polynomial approximation theorem from compact intervals to arbitrary compact Hausdorff spaces.
  • The proof hinges on approximating ∣t∣|t| uniformly by polynomials, which shows the closure of AA is a lattice (closed under max⁡,min⁡\max,\min).
  • Point separation plus a two-point interpolation lemma lets any continuous function be sandwiched arbitrarily well by lattice elements of AA.
  • The complex version needs an extra hypothesis, closure under conjugation, or it can fail (holomorphic functions on the disk are a genuine counterexample).
  • Key idea: an algebra of functions that tells points apart and contains constants already contains, in its closure, every continuous function.

Where this lives today

The theorem underwrites the entire theory of uniform approximation and its descendants. In Fourier Series: Rigorous Foundations, density of trigonometric polynomials in C(T)C(\mathbb T) (proved above) is the crucial density lemma used to show that Fourier partial sums, suitably averaged (Fejér means), converge uniformly to any continuous periodic function — a foundational step before tackling pointwise or L2L^2 convergence of Fourier series themselves. In numerical analysis, Stone–Weierstrass justifies that polynomial and spline interpolation schemes can, in principle, approximate any continuous signal to arbitrary accuracy, motivating quantitative refinements like the Bernstein and Jackson theorems that supply explicit convergence rates. In machine learning theory, the "universal approximation theorem" for neural networks with a single hidden layer is proved by an analogous strategy: showing that the relevant class of network functions forms (or generates) a dense subalgebra or subring of C(K)C(K) on compact domains. In operator algebra and C∗C^*-algebra theory, the commutative Gelfand–Naimark theorem identifies every commutative C∗C^*-algebra with C(K)C(K) for some compact Hausdorff KK, and the complex Stone–Weierstrass theorem (with conjugation-closure) is a working tool for identifying dense self-adjoint subalgebras, directly informing quantum mechanics' operator formalism. In algebraic and complex geometry, polynomial density on compact sets bears on questions of when holomorphic or rational functions can approximate continuous data (Mergelyan's theorem sharpens this in the complex-analytic setting), and in probability theory, density of polynomials or exponentials in C(K)C(K) underlies moment-problem uniqueness arguments — if two measures agree on all polynomial (or exponential) test functions on a compact set, Stone–Weierstrass forces them to agree as measures.

:::quiz[A student claims: "Since polynomials are dense in C([0,1])C([0,1]), every continuous function is differentiable, being a limit of differentiable polynomials." What is wrong?]

  • Nothing; the claim is correct
  • Uniform limits of differentiable functions need not be differentiable; differentiability is not preserved under uniform (only under stronger, e.g. C1C^1-uniform) convergence ✓
  • Polynomials are not actually dense in C([0,1])C([0,1])
  • Weierstrass's theorem only applies to analytic functions

Ask the tutor: Why does the complex Stone–Weierstrass theorem require closure under complex conjugation, and what exactly goes wrong on the closed unit disk without it?

DefinitionSubalgebra of C(K,R)C(K,\mathbb{R}), separating points, uniform density

Let KK be a nonempty compact Hausdorff topological space, and let C(K,R)C(K,\mathbb{R}) denote the vector space of continuous functions f:K→Rf:K\to\mathbb{R}, normed by

∥f∥∞:=sup⁡x∈K∣f(x)∣.\|f\|_\infty := \sup_{x \in K} |f(x)|.

This is a norm because KK is compact and ff continuous, so ∣f∣|f| attains its supremum and ∥f∥∞<∞\|f\|_\infty < \infty. A subset A⊆C(K,R)A \subseteq C(K,\mathbb{R}) is a subalgebra if it is a linear subspace (closed under addition and scalar multiplication) and is closed under pointwise multiplication: f,g∈A  ⟹  fg∈Af,g \in A \implies fg \in A. AA contains the constants if the constant function 1\mathbf{1} (and hence every real multiple of it) lies in AA. AA separates points if for every pair x≠yx \neq y in KK there exists f∈Af \in A with f(x)≠f(y)f(x) \neq f(y). AA is dense in C(K,R)C(K,\mathbb{R}) (in the uniform/sup-norm topology) if for every g∈C(K,R)g \in C(K,\mathbb{R}) and every ε>0\varepsilon > 0 there exists f∈Af \in A with ∥f−g∥∞<ε\|f - g\|_\infty < \varepsilon.

Intuition

Think first about why point separation is necessary. If some algebra AA could not distinguish two points x≠yx \ne y — every f∈Af \in A satisfies f(x)=f(y)f(x) = f(y) — then every function in the closure of AA also satisfies this (closure preserves the equality, since uniform limits of functions agreeing at two points still agree there). So no algebra failing to separate points can be dense: there will always be continuous functions with g(x)≠g(y)g(x) \ne g(y) that lie outside its closure. Point separation is therefore forced by the conclusion, not an artificial technical convenience. Now think about why containing constants matters. Without constants, AA might consist only of functions vanishing at a fixed point x0x_0 (e.g. A={f∈C[0,1]:f(0)=0}A = \{f \in C[0,1] : f(0) = 0\}, which is a subalgebra separating points). Its closure is exactly the functions vanishing at x0x_0 — still not all of C(K,R)C(K,\mathbb{R}). Constants patch this hole. The heart of the proof is a completely different idea: convert the algebraic hypothesis into an order-theoretic one. The key technical fact is that t↦∣t∣t \mapsto |t| can be uniformly approximated by polynomials on any bounded interval, with no constant term needed beyond what algebra already supplies. This means the closure A‾\overline{A} of a subalgebra is automatically a lattice: closed under f∨g=max⁡(f,g)f \vee g = \max(f,g) and f∧g=min⁡(f,g)f \wedge g = \min(f,g), because

max⁡(f,g)=f+g+∣f−g∣2,min⁡(f,g)=f+g−∣f−g∣2,\max(f,g) = \frac{f+g+|f-g|}{2}, \qquad \min(f,g) = \frac{f+g-|f-g|}{2},

and ∣f−g∣|f-g| can be approximated using the polynomial-in-∣t∣|t| trick applied to f−gf - g. Once A‾\overline A is a lattice containing constants and separating points, an elementary two-point interpolation argument (find h∈A‾h \in \overline A agreeing with a target gg approximately at any two prescribed points) combined with compactness (finite subcovers glue local approximations into a global one) forces A‾=C(K,R)\overline A = C(K,\mathbb{R}).

:::svg[Polynomials pnp_n closing in on ∣t∣|t| uniformly on [−1,1][-1,1]] t y 0 -1 1 y = |t| p₂(t) p₅(t) closer still p₀=0, p_{n+1}(t) = p_n(t) + (t² − p_n(t)²)/2, iterated on t²

TheoremStone–Weierstrass Theorem, real version

Let KK be a nonempty compact Hausdorff space and let A⊆C(K,R)A \subseteq C(K,\mathbb{R}) be a subalgebra of C(K,R)C(K,\mathbb{R}) such that: 1. AA contains all constant functions; 2. AA separates points of KK. Then AA is dense in C(K,R)C(K,\mathbb{R}) with respect to the uniform norm ∥⋅∥∞\|\cdot\|_\infty; that is, A‾=C(K,R)\overline{A} = C(K,\mathbb{R}).

LemmaUniform polynomial approximation of ∣t∣|t|

For every ε>0\varepsilon > 0 there is a real polynomial pp with p(0)=0p(0) = 0 such that

∣∣t∣−p(t)∣<εfor all t∈[−1,1].\big| |t| - p(t) \big| < \varepsilon \quad \text{for all } t \in [-1,1].
Proof

Technique: explicit recursive construction plus a monotone convergence / Dini-type estimate. It suffices to approximate s↦ss \mapsto \sqrt{s} uniformly on [0,1][0,1] by polynomials vanishing at 00, since then p(t):=q(t2)p(t) := q(t^2) approximates ∣t∣=t2|t| = \sqrt{t^2} uniformly on [−1,1][-1,1], and p(0)=q(0)=0p(0) = q(0) = 0. Define a sequence of polynomials on [0,1][0,1] recursively:

q0:=0,qn+1(s):=qn(s)+12(s−qn(s)2).q_0 := 0, \qquad q_{n+1}(s) := q_n(s) + \tfrac12\big(s - q_n(s)^2\big).

Each qnq_n is a polynomial in ss with qn(0)=0q_n(0) = 0 (immediate induction: q0(0)=0q_0(0)=0, and if qn(0)=0q_n(0)=0 then qn+1(0)=0+12(0−0)=0q_{n+1}(0) = 0 + \tfrac12(0-0)=0).

Claim: for all n≥0n \ge 0 and all s∈[0,1]s \in [0,1], 0≤qn(s)≤s0 \le q_n(s) \le \sqrt{s}. Proof by induction. Base case n=0n=0: 0=q0(s)≤s0 = q_0(s) \le \sqrt s holds since s≥0s \ge 0. Inductive step: assume 0≤qn(s)≤s0 \le q_n(s) \le \sqrt s for all s∈[0,1]s\in[0,1]. Then

s−qn+1(s)=s−qn(s)−12(s−qn(s)2)=(s−qn(s))(1−12(s+qn(s))).\sqrt{s} - q_{n+1}(s) = \sqrt s - q_n(s) - \tfrac12\big(s - q_n(s)^2\big) = \big(\sqrt s - q_n(s)\big)\Big(1 - \tfrac12\big(\sqrt s + q_n(s)\big)\Big).

By the inductive hypothesis s−qn(s)≥0\sqrt s - q_n(s) \ge 0. Also s≤1\sqrt s \le 1 and qn(s)≤s≤1q_n(s) \le \sqrt s \le 1, so s+qn(s)≤2\sqrt s + q_n(s) \le 2, hence 1−12(s+qn(s))≥01 - \tfrac12(\sqrt s + q_n(s)) \ge 0. Therefore s−qn+1(s)≥0\sqrt s - q_{n+1}(s) \ge 0, i.e. qn+1(s)≤sq_{n+1}(s) \le \sqrt s. Combined with qn+1(s)−qn(s)=12(s−qn(s)2)=12(s−qn(s))(s+qn(s))≥0q_{n+1}(s) - q_n(s) = \tfrac12(s - q_n(s)^2) = \tfrac12(\sqrt s - q_n(s))(\sqrt s + q_n(s)) \ge 0 (both factors nonnegative by the inductive hypothesis), we get qn+1(s)≥qn(s)≥0q_{n+1}(s) \ge q_n(s) \ge 0. This closes the induction, and simultaneously shows (qn(s))n(q_n(s))_n is nondecreasing and bounded above by s≤1\sqrt s \le 1 for each fixed ss. By monotone convergence of a bounded increasing real sequence, qn(s)→L(s)q_n(s) \to L(s) for some L(s)∈[0,s]L(s) \in [0,\sqrt s], for every s∈[0,1]s \in [0,1]. Passing to the limit in the recursion qn+1(s)=qn(s)+12(s−qn(s)2)q_{n+1}(s) = q_n(s) + \tfrac12(s - q_n(s)^2) gives L(s)=L(s)+12(s−L(s)2)L(s) = L(s) + \tfrac12(s - L(s)^2), so L(s)2=sL(s)^2 = s, and since L(s)≥0L(s)\ge 0, L(s)=sL(s) = \sqrt s. Now we upgrade pointwise convergence to uniform convergence using Dini's theorem: [0,1][0,1] is compact, each qnq_n is continuous, the sequence (qn)(q_n) is monotonically nondecreasing in nn at each point, and the pointwise limit s\sqrt{s} is continuous. Dini's theorem (a consequence of compactness: for ε>0\varepsilon>0 the sets Un={s:s−qn(s)<ε}U_n = \{s : \sqrt s - q_n(s) < \varepsilon\} are open, increasing in nn, and cover [0,1][0,1] by pointwise convergence, so finitely many suffice, and monotonicity gives UN=[0,1]U_N = [0,1] for the largest index NN among that finite subcover) yields

sup⁡s∈[0,1]∣s−qn(s)∣→0as n→∞.\sup_{s\in[0,1]} \big|\sqrt s - q_n(s)\big| \to 0 \quad \text{as } n\to\infty.

Given ε>0\varepsilon>0, choose nn with sup⁡s∈[0,1]∣s−qn(s)∣<ε\sup_{s\in[0,1]}|\sqrt s - q_n(s)| < \varepsilon and set q:=qnq := q_n, p(t):=q(t2)p(t) := q(t^2). Then for t∈[−1,1]t \in [-1,1], s:=t2∈[0,1]s := t^2 \in [0,1] and ∣∣t∣−p(t)∣=∣s−qn(s)∣<ε|{|t|} - p(t)| = |\sqrt s - q_n(s)| < \varepsilon. ■\blacksquare

∎
CorollaryClosure of a subalgebra is a lattice

If A⊆C(K,R)A \subseteq C(K,\mathbb{R}) is a subalgebra, then its uniform closure A‾\overline{A} is closed under f,g↦max⁡(f,g)f,g \mapsto \max(f,g) and f,g↦min⁡(f,g)f,g\mapsto \min(f,g).

Proof

Technique: rescaling the previous lemma and using that A‾\overline A is itself a closed subalgebra. First note A‾\overline A is again a subalgebra: if fn→ff_n \to f and gn→gg_n \to g uniformly with fn,gn∈Af_n, g_n \in A, then fn+gn→f+gf_n + g_n \to f+g uniformly (triangle inequality) and fngn→fgf_ng_n \to fg uniformly, since

∥fngn−fg∥∞≤∥fn∥∞∥gn−g∥∞+∥g∥∞∥fn−f∥∞→0,\|f_ng_n - fg\|_\infty \le \|f_n\|_\infty\|g_n - g\|_\infty + \|g\|_\infty\|f_n-f\|_\infty \to 0,

using that ∥fn∥∞\|f_n\|_\infty is bounded (convergent sequences are bounded). Also A‾\overline A is closed by definition of closure. Fix f∈A‾f \in \overline A, f≠0f \ne 0, and let M:=∥f∥∞>0M := \|f\|_\infty > 0. Given ε>0\varepsilon > 0, by the Lemma choose a polynomial pp with p(0)=0p(0)=0 and ∣∣t/M∣−p(t/M)∣<ε/M\big||t/M| - p(t/M)\big| < \varepsilon / M for all t∈[−M,M]t \in [-M,M] — equivalently apply the Lemma to t/M∈[−1,1]t/M \in [-1,1]. Write p(u)=∑k=1nckukp(u) = \sum_{k=1}^n c_k u^k (no constant term since p(0)=0p(0)=0). Define

P(f):=∑k=1nck fkMk−1∈A(since A is an algebra, closed under sums and products).P(f) := \sum_{k=1}^n c_k \, \frac{f^k}{M^{k-1}} \in A \quad (\text{since } A \text{ is an algebra, closed under sums and products}).

Then P(f)(x)=M p(f(x)/M)P(f)(x) = M\, p(f(x)/M) for each x∈Kx\in K, so

∣∣f(x)∣−P(f)(x)∣=M∣∣f(x)/M∣−p(f(x)/M)∣<M⋅εM=ε\big| |f(x)| - P(f)(x)\big| = M\Big|\big|f(x)/M\big| - p(f(x)/M)\Big| < M \cdot \frac{\varepsilon}{M} = \varepsilon

for all x∈Kx \in K (using ∣f(x)/M∣≤1|f(x)/M| \le 1 since ∣f(x)∣≤M|f(x)|\le M). Hence ∥ ∣f∣−P(f) ∥∞≤ε\|\,|f| - P(f)\,\|_\infty \le \varepsilon with P(f)∈AP(f) \in A. Since ε>0\varepsilon>0 was arbitrary, ∣f∣∈A‾|f| \in \overline A. (If f=0f = 0 then ∣f∣=0∈A⊆A‾|f| = 0 \in A \subseteq \overline A trivially.) Since A⊆A‾A \subseteq \overline A, this shows: f∈A‾  ⟹  ∣f∣∈A‾f \in \overline A \implies |f| \in \overline A. Now for f,g∈A‾f, g \in \overline A, we have f−g∈A‾f - g \in \overline A (linear subspace), hence ∣f−g∣∈A‾|f-g| \in \overline A by the above, hence

max⁡(f,g)=(f+g)+∣f−g∣2∈A‾,min⁡(f,g)=(f+g)−∣f−g∣2∈A‾,\max(f,g) = \frac{(f+g) + |f-g|}{2} \in \overline A, \qquad \min(f,g) = \frac{(f+g) - |f-g|}{2} \in \overline A,

as both are algebraic combinations (sums, scalar multiples) of elements of the linear subspace A‾\overline A. ■\blacksquare

∎
Proof

Proof of the Stone–Weierstrass Theorem. Technique: two-point interpolation + lattice property + compactness (finite subcover gluing). Let g∈C(K,R)g \in C(K,\mathbb{R}) and ε>0\varepsilon > 0 be given; we must find f∈Af \in A with ∥f−g∥∞<ε\|f - g\|_\infty < \varepsilon. Since A⊆A‾A \subseteq \overline A and it suffices to find such ff in A‾\overline A and then approximate that ff within ε/2\varepsilon/2 by an element of AA (definition of closure) and adjust constants, we may work in A‾\overline A; we show A‾=C(K,R)\overline A = C(K,\mathbb{R}) directly, which gives the result since A‾‾=A‾\overline{\overline A} = \overline A. By the Corollary, A‾\overline A is a lattice; it is also a subalgebra containing constants (since AA does and A‾⊇A\overline A \supseteq A) and separating points (since AA does, and A⊆A‾A \subseteq \overline A).

Step 1: Two-point interpolation. Fix distinct x,y∈Kx, y \in K and target values α:=g(x)\alpha := g(x), β:=g(y)∈R\beta := g(y) \in \mathbb{R}. We construct hx,y∈A‾h_{x,y} \in \overline A with hx,y(x)=αh_{x,y}(x) = \alpha and hx,y(y)=βh_{x,y}(y) = \beta exactly. Since AA separates points, choose ϕ∈A\phi \in A with ϕ(x)≠ϕ(y)\phi(x) \ne \phi(y). Set

hx,y:=α⋅1+(β−α)⋅ϕ−ϕ(x)1ϕ(y)−ϕ(x).h_{x,y} := \alpha \cdot \mathbf 1 + (\beta - \alpha) \cdot \frac{\phi - \phi(x)\mathbf 1}{\phi(y) - \phi(x)}.

This is a linear combination of 1\mathbf 1 and ϕ\phi with real coefficients (the denominator ϕ(y)−ϕ(x)\phi(y)-\phi(x) is a nonzero real number), so hx,y∈Ah_{x,y} \in A since AA is a linear subspace containing 1\mathbf{1} and ϕ\phi. Direct substitution gives hx,y(x)=α+0=αh_{x,y}(x) = \alpha + 0 = \alpha and hx,y(y)=α+(β−α)⋅1=βh_{x,y}(y) = \alpha + (\beta-\alpha)\cdot 1 = \beta, as required. (If x=yx=y this step is vacuous/unnecessary; we only invoke it for x≠yx \ne y, and separately every constant function trivially handles the case where we only need one point.)

Step 2: Fix x∈Kx \in K; build fx∈A‾f_x \in \overline A with fx(x)=g(x)f_x(x) = g(x) and fx<g+εf_x < g + \varepsilon everywhere. For each y∈Ky \in K, y≠xy \ne x, let hx,y∈Ah_{x,y} \in A be as in Step 1 (with α=g(x)\alpha = g(x), β=g(y)\beta = g(y)), so hx,y(x)=g(x)h_{x,y}(x) = g(x), hx,y(y)=g(y)h_{x,y}(y) = g(y). For y=xy = x set hx,x:=g(x)⋅1∈Ah_{x,x} := g(x)\cdot \mathbf 1 \in A. Define, for each y∈Ky \in K, the open set

Uy:={z∈K:hx,y(z)<g(z)+ε}.U_y := \{ z \in K : h_{x,y}(z) < g(z) + \varepsilon \}.

This is open because hx,y−gh_{x,y} - g is continuous (gg is continuous by hypothesis, hx,yh_{x,y} is continuous as it's a specific continuous function built algebraically from continuous functions) and UyU_y is the preimage of the open set (−∞,ε)(-\infty,\varepsilon) under z↦hx,y(z)−g(z)z \mapsto h_{x,y}(z) - g(z). Also y∈Uyy \in U_y since hx,y(y)=g(y)<g(y)+εh_{x,y}(y) = g(y) < g(y) + \varepsilon. Hence {Uy}y∈K\{U_y\}_{y \in K} is an open cover of KK. Since KK is compact, extract a finite subcover Uy1,…,UymU_{y_1}, \dots, U_{y_m} covering KK. Define

fx:=min⁡(hx,y1,…,hx,ym)∈A‾,f_x := \min(h_{x,y_1}, \dots, h_{x,y_m}) \in \overline A,

using the Corollary's lattice closure repeatedly (min⁡\min of finitely many elements of A‾\overline A is obtained by iterating the binary min⁡\min, which stays in A‾\overline A). For any z∈Kz \in K, zz lies in some UyiU_{y_i}, so hx,yi(z)<g(z)+εh_{x,y_i}(z) < g(z) + \varepsilon, and since fx(z)≤hx,yi(z)f_x(z) \le h_{x,y_i}(z) (minimum is ≤\le any one term), we get

fx(z)<g(z)+εfor all z∈K.f_x(z) < g(z) + \varepsilon \quad \text{for all } z \in K.

Moreover fx(x)=min⁡ihx,yi(x)=min⁡ig(x)=g(x)f_x(x) = \min_i h_{x,y_i}(x) = \min_i g(x) = g(x), since every hx,yi(x)=g(x)h_{x,y_i}(x) = g(x) by construction (Step 1 gives hx,y(x)=α=g(x)h_{x,y}(x) = \alpha = g(x) for every yy).

Step 3: Glue over xx. For each x∈Kx \in K we now have fx∈A‾f_x \in \overline A with fx(x)=g(x)f_x(x) = g(x) and fx(z)<g(z)+εf_x(z) < g(z) + \varepsilon for all z∈Kz \in K. Define

Vx:={z∈K:fx(z)>g(z)−ε}.V_x := \{ z \in K : f_x(z) > g(z) - \varepsilon \}.

This is open (preimage of (−ε,∞)(-\varepsilon,\infty) under the continuous fx−gf_x - g), and x∈Vxx \in V_x since fx(x)−g(x)=0>−εf_x(x) - g(x) = 0 > -\varepsilon. So {Vx}x∈K\{V_x\}_{x\in K} is an open cover of the compact space KK; extract a finite subcover Vx1,…,VxnV_{x_1},\dots,V_{x_n}. Define

f:=max⁡(fx1,…,fxn)∈A‾,f := \max(f_{x_1}, \dots, f_{x_n}) \in \overline A,

again using iterated binary max⁡\max from the Corollary. For any z∈Kz \in K: since z∈Vxjz \in V_{x_j} for some jj, fxj(z)>g(z)−εf_{x_j}(z) > g(z) - \varepsilon, and f(z)≥fxj(z)f(z) \ge f_{x_j}(z), so f(z)>g(z)−εf(z) > g(z) - \varepsilon. On the other hand, every fxif_{x_i} satisfies fxi(z)<g(z)+εf_{x_i}(z) < g(z) + \varepsilon for all zz (Step 2, valid for all ii since it held for every z∈Kz \in K), so f(z)=max⁡ifxi(z)<g(z)+εf(z) = \max_i f_{x_i}(z) < g(z) + \varepsilon. Combining: for every z∈Kz \in K,

g(z)−ε<f(z)<g(z)+ε,i.e.∣f(z)−g(z)∣<ε.g(z) - \varepsilon < f(z) < g(z) + \varepsilon, \quad \text{i.e.} \quad |f(z) - g(z)| < \varepsilon.

Hence ∥f−g∥∞≤ε\|f - g\|_\infty \le \varepsilon with f∈A‾f \in \overline A (in fact one can rerun the argument with ε/2\varepsilon/2 to get strict inequality if desired). Since ε>0\varepsilon > 0 and g∈C(K,R)g \in C(K,\mathbb{R}) were arbitrary, A‾=C(K,R)\overline A = C(K,\mathbb{R}). ■\blacksquare

∎
CorollaryClassical Weierstrass Approximation Theorem

Let [a,b]⊂R[a,b] \subset \mathbb{R} be a compact interval, a<ba<b. For every g∈C([a,b],R)g \in C([a,b],\mathbb{R}) and ε>0\varepsilon>0, there is a polynomial pp with real coefficients such that sup⁡x∈[a,b]∣g(x)−p(x)∣<ε\sup_{x\in[a,b]}|g(x)-p(x)| < \varepsilon. That is, polynomials are dense in C([a,b],R)C([a,b],\mathbb{R}) under the uniform norm.

Proof

Technique: verify the two hypotheses of the theorem for K=[a,b]K=[a,b] and A=A = polynomials. K=[a,b]K = [a,b] is compact (Heine–Borel) and Hausdorff (it is a metric space). Let AA be the set of all polynomial functions p:[a,b]→Rp: [a,b] \to \mathbb{R} with real coefficients. AA is a subalgebra: sums and scalar multiples of polynomials are polynomials (linear subspace), and products of polynomials are polynomials (closed under pointwise multiplication). AA contains the constants: the constant function cc is the (degree 00) polynomial p(x)=cp(x) = c. AA separates points: for x≠yx \ne y in [a,b][a,b], take f(x)=xf(x) = x (the identity polynomial, i.e. p(t)=tp(t)=t); then f(x)=x≠y=f(y)f(x) = x \ne y = f(y). All hypotheses of the Stone-Weierstrass Theorem hold, so AA is dense in C([a,b],R)C([a,b],\mathbb{R}): for every g∈C([a,b])g\in C([a,b]) and ε>0\varepsilon>0 there is a polynomial p∈Ap\in A with ∥g−p∥∞<ε\|g-p\|_\infty<\varepsilon. ■\blacksquare

∎

Worked examples

Example 1: Approximating g(x)=exsin⁡(3x)g(x) = e^{x}\sin(3x) on [−1,2][-1,2] to accuracy 10−210^{-2} — verifying the hypothesis chain and exhibiting an explicit approximant. Take K=[−1,2]K = [-1,2], compact and Hausdorff, and A=A = polynomials on KK, as in the Corollary above. The function g(x)=exsin⁡(3x)g(x) = e^x \sin(3x) is continuous on [−1,2][-1,2] (product and composition of continuous functions: exe^x, sin⁡\sin, and 3x3x are all continuous, and pointwise products/compositions of continuous functions are continuous). By the classical Weierstrass corollary, for ε=10−2\varepsilon = 10^{-2} there exists a polynomial pp with sup⁡x∈[−1,2]∣g(x)−p(x)∣<10−2\sup_{x\in[-1,2]}|g(x)-p(x)| < 10^{-2}; the theorem guarantees existence but let us also see how to produce one concretely, illustrating that the abstract theorem matches concrete practice. Use the degree-NN Taylor polynomial of gg about x0=0.5x_0 = 0.5 (the midpoint of [−1,2][-1,2], a reasonable centering choice). We have g(x)=exsin⁡(3x)g(x) = e^x\sin(3x), an entire function (both factors are entire, and finite products/compositions of entire functions with polynomials are entire), so its Taylor series converges to gg on all of R\mathbb R; on the compact set [−1,2][-1,2], since ∣x−0.5∣≤1.5|x - 0.5|\le 1.5, Taylor's theorem with Lagrange remainder gives

∣g(x)−TN(x)∣≤max⁡ξ∈[−1,2]∣g(N+1)(ξ)∣(N+1)! (1.5)N+1.|g(x) - T_N(x)| \le \frac{\max_{\xi\in[-1,2]}|g^{(N+1)}(\xi)|}{(N+1)!}\,(1.5)^{N+1}.

Because gg is a product of exe^x (bounded by e2e^2 on [−1,2][-1,2]) and sin⁡(3x)\sin(3x) and its derivatives (bounded by 3k3^k in absolute value after kk derivatives via the product/chain rule and boundedness of sine/cosine by 11), one can bound ∣g(N+1)(ξ)∣|g^{(N+1)}(\xi)| by, say, e2∑j=0N+1(N+1j)3je^2 \sum_{j=0}^{N+1}\binom{N+1}{j}3^{j} — crudely, ∣g(N+1)(ξ)∣≤e2⋅4N+1|g^{(N+1)}(\xi)| \le e^2 \cdot 4^{N+1} works (Leibniz rule: each of the N+2N+2 terms is bounded by e2⋅3N+1e^2 \cdot 3^{N+1}, giving a bound e2(N+2)3N+1e^2(N+2)3^{N+1}, which for N=8N=8 is about 7.39×10×6561≈4.85×1057.39 \times 10 \times 6561 \approx 4.85\times10^5; more carefully one finds that N=8N=8 already gives remainder well under 10−210^{-2} once divided by 9!=3628809! = 362880 and multiplied by 1.59≈38.441.5^9 \approx 38.44):

4.85×105×38.44362880≈51.4.\frac{4.85\times 10^5 \times 38.44}{362880} \approx 51.4.

This crude bound is not yet small enough at N=8N=8, showing that centered Taylor polynomials can converge slowly on wide intervals — exactly the kind of subtlety the abstract theorem sidesteps (it guarantees existence of some polynomial of possibly much higher, unspecified degree, without giving an efficient one). Taking N=16N=16 drives 1.517/17!1.5^{17}/17! down by a factor of roughly (1.5/17)9≈8×10−9(1.5/17)^{9}\approx 8\times10^{-9} relative to the N=8N=8 term (each extra pair of degrees multiplies the ratio by 1.52/((N+1)(N+2))1.5^2/((N+1)(N+2)), rapidly shrinking once NN exceeds 1.51.5), so the remainder at N=16N=16 is of order 10−810^{-8}, comfortably below 10−210^{-2}. So the explicit polynomial

p(x)=T16(x)=∑k=016g(k)(0.5)k!(x−0.5)kp(x) = T_{16}(x) = \sum_{k=0}^{16} \frac{g^{(k)}(0.5)}{k!}(x-0.5)^k

satisfies sup⁡[−1,2]∣g−p∣<10−2\sup_{[-1,2]}|g - p| < 10^{-2} (in fact far smaller), consistent with — and concretely instantiating — the existence claim of the theorem. This illustrates the crucial point: Stone–Weierstrass guarantees existence and density, but says nothing about the degree needed; that is a separate, quantitative question (addressed by results such as Jackson's theorem in approximation theory).

Example 2: Trigonometric polynomials are dense in C(T,R)C(\mathbb T, \mathbb{R}), T=R/2πZ\mathbb T = \mathbb R / 2\pi\mathbb Z — a non-interval compact space. Let K=TK = \mathbb T, the circle, realized as [−π,π][-\pi,\pi] with endpoints identified, a compact Hausdorff space (compact quotient of a compact interval by a closed equivalence relation; Hausdorff because it is homeomorphic to the unit circle in R2\mathbb{R}^2 via θ↦(cos⁡θ,sin⁡θ)\theta \mapsto (\cos\theta,\sin\theta)). A continuous function on T\mathbb T is the same thing as a continuous 2π2\pi-periodic function on R\mathbb R. Let AA be the set of real trigonometric polynomials:

A={θ↦a0+∑k=1n(akcos⁡kθ+bksin⁡kθ)  :  n∈N, ak,bk∈R}.A = \Big\{ \theta \mapsto a_0 + \sum_{k=1}^n \big(a_k\cos k\theta + b_k \sin k\theta\big) \;:\; n\in\mathbb N,\ a_k,b_k \in \mathbb R \Big\}.

Check subalgebra: AA is visibly a linear subspace (closed under addition, scalar multiplication of the coefficients). For products, use the product-to-sum identities

cos⁡(jθ)cos⁡(kθ)=12[cos⁡((j+k)θ)+cos⁡((j−k)θ)],similarly for cos⁡⋅sin⁡, sin⁡⋅sin⁡,\cos(j\theta)\cos(k\theta) = \tfrac12[\cos((j+k)\theta) + \cos((j-k)\theta)], \quad \text{similarly for } \cos\cdot\sin,\ \sin\cdot\sin,

so the product of any two terms cos⁡(jθ),sin⁡(jθ)\cos(j\theta), \sin(j\theta) from one factor with cos⁡(kθ),sin⁡(kθ)\cos(k\theta),\sin(k\theta) from the other is again a real-linear combination of cos⁡(mθ),sin⁡(mθ)\cos(m\theta), \sin(m\theta) for various integers mm, hence lies back in the span defining AA. Since a general product of trigonometric polynomials is a finite sum of such term-by-term products (distributivity), the product of two elements of AA is again in AA. So AA is a subalgebra. Check constants: a0a_0 alone (all other coefficients zero) gives every constant function, so A⊇R⋅1A \supseteq \mathbb R \cdot \mathbf 1. Check separation of points: Let θ1≠θ2\theta_1 \ne \theta_2 in T\mathbb T, i.e. θ1≢θ2(mod2π)\theta_1 \not\equiv \theta_2 \pmod {2\pi}. Consider f(θ)=cos⁡θf(\theta) = \cos\theta and h(θ)=sin⁡θh(\theta)=\sin\theta, both in AA. If cos⁡θ1=cos⁡θ2\cos\theta_1 = \cos\theta_2 and sin⁡θ1=sin⁡θ2\sin\theta_1=\sin\theta_2, then (cos⁡θ1,sin⁡θ1)=(cos⁡θ2,sin⁡θ2)(\cos\theta_1,\sin\theta_1)=(\cos\theta_2,\sin\theta_2) as points on the unit circle, forcing θ1≡θ2(mod2π)\theta_1\equiv\theta_2\pmod{2\pi}, a contradiction. So at least one of f,hf,h separates θ1,θ2\theta_1,\theta_2; hence AA separates points of T\mathbb T. All hypotheses hold, so by the Stone–Weierstrass theorem AA is dense in C(T,R)C(\mathbb T,\mathbb R): every continuous 2π2\pi-periodic function is a uniform limit of real trigonometric polynomials. This single fact — proved here purely from the abstract theorem, with no Fourier coefficient computation whatsoever — is the analytic bedrock beneath the rigorous theory of Fourier Series: Rigorous Foundations: it guarantees, before any convergence theorem for Fourier series per se is proved, that trigonometric polynomials are rich enough to approximate any continuous periodic signal uniformly.

CounterexampleDropping point separation breaks density

Let K=[−1,1]K = [-1,1] and let

A={p∈C([−1,1],R):p is a polynomial in x2}=span⁡{1,x2,x4,x6,… }.A = \{ p \in C([-1,1],\mathbb R) : p \text{ is a polynomial in } x^2 \} = \operatorname{span}\{1, x^2, x^4, x^6, \dots\}.

This AA is a subalgebra (sums, scalar multiples, and products of even polynomials in xx are even polynomials in xx) and contains the constants (1=x01 = x^0 is included). However AA does not separate points: for x0=1/2x_0 = 1/2 and y0=−1/2y_0 = -1/2, every f∈Af \in A is an even function, so f(x0)=f(−x0)=f(y0)f(x_0) = f(-x_0) = f(y_0); no element of AA distinguishes 1/21/2 from −1/2-1/2. Consequently the conclusion of the theorem fails: AA is not dense in C([−1,1],R)C([-1,1],\mathbb R). Indeed take g(x)=xg(x) = x, a perfectly ordinary continuous function. For any f∈Af \in A (even), f(1/2)=f(−1/2)f(1/2) = f(-1/2), so

∣f(1/2)−g(1/2)∣+∣f(−1/2)−g(−1/2)∣=∣f(1/2)−12∣+∣f(1/2)+12∣≥∣(f(1/2)+12)−(f(1/2)−12)∣=1|f(1/2) - g(1/2)| + |f(-1/2) - g(-1/2)| = |f(1/2) - \tfrac12| + |f(1/2) + \tfrac12| \ge \big|(f(1/2)+\tfrac12) - (f(1/2)-\tfrac12)\big| = 1

(triangle inequality: ∣A∣+∣B∣≥∣A−B∣|A|+|B|\ge|A-B|), so at least one of these two absolute values is ≥1/2\ge 1/2, forcing ∥f−g∥∞≥1/2\|f-g\|_\infty \ge 1/2 for every f∈Af \in A. Hence gg lies at uniform distance at least 1/21/2 from all of AA, and no sequence in AA converges uniformly to gg. This shows point separation is not a technical nicety but a genuinely necessary hypothesis: without it, A‾\overline A can be a proper, closed, "thin" subalgebra (here, exactly the even continuous functions on [−1,1][-1,1]) rather than all of C(K,R)C(K,\mathbb R).

Scope, edge cases & common traps

SituationWhat happensWhy
AA complex-valued, no conjugation closureDensity can failHolomorphic polynomials in zz on the closed unit disk separate points and contain constants, but their uniform closure is the disk algebra, not all of C(D‾,C)C(\overline{\mathbb D},\mathbb C) — missing zˉ\bar z
AA complex-valued, closed under conjugationDensity holdsApply real version to real and imaginary parts (the "complex Stone–Weierstrass" corollary)
KK not compactTheorem does not apply as statedSup norm may be infinite; need weighted or compact-open topologies instead
AA misses constants but separates pointsDensity can still faile.g. {f:f(x0)=0}\{f: f(x_0)=0\} on [0,1][0,1]; closure is exactly functions vanishing at x0x_0
AA a vector subspace but not closed under multiplicationDensity can fail even with constants + separatione.g. span of {1,x}\{1,x\} in C[0,1]C[0,1]: only affine functions, not dense

The mathematician behind it

Origins · 1 minMarshall Harvey Stone and how this was discovered
MH
Marshall Harvey Stone
1903–1989 · Harvard and University of Chicago, functional analysis and lattice theory

Stone worked at the intersection of topology, algebra, and analysis, best known for the Stone representation theorem for Boolean algebras and the Stone–Čech compactification. His 1937 paper generalized Weierstrass's 52-year-old polynomial approximation theorem to arbitrary compact Hausdorff spaces, replacing an analytic, interval-specific argument with a clean algebraic-order-theoretic one that applies everywhere from finite sets to infinite-dimensional function spaces.

History
- 1885: Karl Weierstrass proves that continuous functions on a closed bounded interval are uniform limits of polynomials.
- 1904/1908: Lebesgue and Fejér give alternative proofs of Weierstrass's theorem via convolution with approximate identities (e.g. Bernstein-type or Fejér kernels).
- 1912: Sergei Bernstein gives a probabilistic proof using Bernstein polynomials, with an explicit rate of convergence.
- 1937: Marshall Stone publishes the general theorem for algebras of continuous functions on compact Hausdorff spaces, subsuming Weierstrass's theorem as a special case.
- 1948: Stone republishes a streamlined, widely cited version of the proof, cementing the modern "Stone–Weierstrass" name and lattice-based argument used in this article.
Does Stone–Weierstrass tell us how large a degree polynomial is needed for a given accuracy?

No. The theorem is purely an existence and density statement: for every ε>0\varepsilon>0 some polynomial (or algebra element) achieves uniform error less than ε\varepsilon, but the proof gives no explicit bound on the required degree in terms of ε\varepsilon and properties of gg (like its modulus of continuity). Quantitative versions exist separately: Jackson's theorem bounds the best-approximation error by a polynomial of degree nn in terms of the modulus of continuity of gg, and Bernstein's explicit polynomials give concrete, if often suboptimal, convergence rates. In practice, when an explicit approximant is needed, one turns to these quantitative theorems or to numerical methods (Chebyshev interpolation, least-squares fitting) rather than to Stone–Weierstrass itself.

Why is closure under pointwise multiplication so essential, beyond linear-subspace structure?

Multiplication closure is what lets the proof manufacture ∣f∣|f|, and hence max⁡\max and min⁡\min, from elements of AA: the polynomial approximating ∣t∣|t| has degree greater than one, so evaluating it at ff requires forming powers f2,f3,…f^2, f^3,\dots, which requires the algebra to be closed under products. Without this, AA might only be a linear subspace (like span⁡{1,x}\operatorname{span}\{1,x\}), whose closure is still just a low-dimensional space of functions, since no new functions can be algebraically generated. The lattice property is the linchpin of the entire two-point interpolation argument; without it, Steps 2 and 3 of the proof (which rely on taking finite min⁡\min's and max⁡\max's) have no foothold.

Is the Stone–Weierstrass theorem true for non-compact spaces, like R\mathbb R?

Not in the same form. On R\mathbb R, the sup norm of a general continuous function can be infinite, so C(R,R)C(\mathbb R,\mathbb R) with ∥⋅∥∞\|\cdot\|_\infty is not even meaningfully normed for unbounded functions, and uniform density on all of R\mathbb R is generally false (polynomials cannot uniformly approximate a bounded, non-polynomial continuous function like sin⁡x\sin x across all of R\mathbb R, since a nonconstant polynomial is unbounded). The usual fixes are to work on compact subsets, use the compact-open topology (uniform convergence on compacts), or pass to one-point/Stone–Čech compactifications and consider functions vanishing at infinity, which is the setting of the locally compact version of the theorem.

How does this theorem relate to Fourier series?

It supplies the key density fact — trigonometric polynomials are uniformly dense in C(T,R)C(\mathbb T,\mathbb R) — worked out explicitly in the second example above, purely from the abstract algebra/point-separation criterion, without needing to compute a single Fourier coefficient. This density is the analytic backbone used, for instance, in proving that Fejér's Cesàro-averaged partial sums of a Fourier series converge uniformly to any continuous periodic function: one shows the Fejér kernel behaves like an approximate identity acting on the dense subspace of trigonometric polynomials, then extends by a uniform continuity/density argument to all of C(T)C(\mathbb T). This is precisely the strategy developed rigorously in Fourier Series: Rigorous Foundations.

Can Stone–Weierstrass fail if KK is compact but not Hausdorff?

The theorem as classically stated assumes Hausdorff, and this is not merely cosmetic: much of point-set topology (existence of enough continuous functions, Urysohn-type separation) that make C(K)C(K) well-behaved relies on the Hausdorff property, and pathological compact non-Hausdorff spaces can have too few continuous real-valued functions for the separation hypothesis to even be checkable meaningfully. In practice essentially every space of interest in analysis (metric spaces, compact subsets of Rn\mathbb R^n, compact groups) is Hausdorff, so this hypothesis is rarely a binding restriction, but it is not dropped for free in the general topological statement.

What is the simplest possible nontrivial example of the theorem in action?

Take K={1,2,…,n}K = \{1,2,\dots,n\}, a finite discrete space (trivially compact Hausdorff). Here C(K,R)≅RnC(K,\mathbb R) \cong \mathbb R^n (every function on a finite discrete space is automatically continuous), and any subalgebra containing constants and separating points must, by a short direct argument, already equal all of Rn\mathbb R^n — so the "approximation" is exact, not just arbitrarily close. This finite case strips away the analytic subtlety and shows the theorem's algebraic heart: separating points plus algebra closure plus constants forces you to capture every degree of freedom in the space of functions.

Before this

Where this leads