# Approximating a continuous function by one with zero derivative

Let $f : \mathbb R \rightarrow \mathbb R$ be a continuous function. I am trying to prove that for each $\epsilon > 0$, there is a continuous function $g$ whose derivative exists and equals 0 almost everywhere such that $|f(x) - g(x)| < \epsilon$ for each $x \in \mathbb R$. So far, I've considered trying to use linear combinations of the cantor-lebesgue function (which is continuous and has zero derivative a.e.), but have not met with much success.

-

## 2 Answers

This cries out loud for the Stone-Weierstrass theorem.

The singular functions are a subalgebra of $C[a,b]$, they contain the constant functions and they separate points, hence every continuous function on $[a,b]$ can be uniformly approximated by singular functions.

Now we can paraphrase Robert Israel's answer here:

Approximate by [singular functions] $p_k(x)$ on each interval $[k,k+2]$, and put them together using a smooth partition of unity: if $\phi(x)$ is a smooth function with $\phi(x) = 0$ for $x \le 0$, $\phi(x) = 1$ for $x \ge 1$, and $0 \le \phi(x) \le 1$ for $0 \le x \le 1$, take $g(x) = \phi(x-k) p_k(x) + (1 - \phi(x-k)) p_{k-1}(x)$ for $k \le x \le k+1$.

-

Here is how to do this on $I=[0,1]$. $f$ is uniformly continuous on $I$, so find the $n$ so that if $|x-y|<1/n\;$, $|f(x)-f(y)|<\epsilon\;$. For $x\in[k/n,(k+1)/n]$ define $$g(x)=f(k/n)+C(nx-k)(f((k+1)/n)-f(k/n))$$ Where $C$ is the Cantor-Lebesgue function. This can then be repeated for other compact intervals.

-
+1: I prefer your solution to applying Stone-Weierstrass! –  commenter Sep 25 '11 at 3:11
@commenter: thanks. While an answer using S-W is nice in its generality, I prefer a constructive answer, too. –  robjohn Sep 25 '11 at 3:33