How to show that the set of all Lipschitz functions on a compact set X is dense in C(X)?

Im reading Chapter12 of Carothers’ Real Analysis, 1ed. Here is a reading material of Lip(X) which denotes the set of all Lipschitz functions on a compact set X,
enter image description here

How to show that the set of all Lipschitz functions on a compact set X is dense in C(X)?

I want to show $Ball_ε$(g) ∩ Lip(X) ≠ empty for every continuous function g ∈ $C$(X) and every ε>0. But I got stuck here cos I need to find a function f in Lip(X) such that $||f – g||_∞$<ε.

Solutions Collecting From Web of "How to show that the set of all Lipschitz functions on a compact set X is dense in C(X)?"

As Chris Janjigian said, the passage you quoted is a proof that Lipschitz functions are dense; perhaps one should say at the end

Thus, if $X$ is compact, then $\operatorname{Lip}X$ is dense in $C(X)$ by the Stone-Weierstrass theorem.

But to directly answer the question posed in the title: a constructive self-contained proof (without Stone-Weierstrass) goes as follows. Given a continuous function $g$ and a number $\epsilon>0$, pick $\delta>0$ such that $|g(x)-g(y)|<\epsilon$ whenever $d(x,y)<\delta$ — this is possible by uniform continuity of $g$. Also let $M=\sup_X |g|$. Define
$$f(x) = \sup_{y\in X} \left(g(y)- 2M \delta^{-1}d(x,y)\right)\tag{1}$$
I claim that $f$ is Lipschitz and $\sup_X |f-g|\le \epsilon$.

  1. $f(x_1)-f(x_2)\le 2M \delta^{-1}d(x_1,x_2)$ by the triangle inequality. Reversing the roles of $x_1,x_2$, we see that $f$ is Lipschitz with constant $2M \delta^{-1}$.
  2. We have $f(x)\ge g(x)$, because the expression under the supremum in (1) turns to $f(x)$ when $y=x$.
  3. If $d(x,y)\ge \delta$, then the expression under the supremum in (1) is at most $-M$, which is less than $g(x)$.
  4. If $d(x,y)< \delta$, then the expression under the supremum in (1) is at most $g(x)+\epsilon$, by the choice of $\delta$.
  5. Combine the items 2-3-4 to obtain $g(x)\le f(x)\le g(x)+\epsilon$.