Existence of non-constant continuous functions with infinitely many zeros

[!!! There is an error in the following argument !!! ]

Since this answer has been accepted, I can no longer delete it, however. The comments below may be useful for anyone interested.

In fact every closed subset of $\mathbb R$ is the zero set of a smooth function:

First, suppose we are given an open interval $I = (a,b) \subset \mathbb R$. We will construct a smooth function $f: \mathbb R\to [0,1]$ satisfying $f(x)>0 \iff x \in I$.

Then, if we are given a closed set $K \subset \mathbb R$, the complement $U = \mathbb R\setminus K$ can be written as the disjoint union of countably many open intervals $I_n$ for $n\in \mathbb N$, i.e.

$$ U = \bigcup_{n=1}^\infty I_n, \quad \text{with } \; I_n \cap I_m = \varnothing \; \text{ for $m\ne n$}$$

Assuming the first part, we can find smooth functions $f_n: \mathbb R\to [0,1]$ such that $f_n(x) > 0$ if and only if $x \in I_n$. Now define

$$g(x) := \sum_{n=1}^\infty f_n(x)$$

Then $g$ is well-defined and smooth, because for any point $x\in \mathbb R$ there is a neighborhood $V$ such that only finitely many $f_n$ are nonzero on $V$ (in fact we can choose $V$ sufficiently small such that it intersects two intervals $I_m$ and $I_n$ at most).

Let us prove the first assertion: So, we are given $I=(a,b)\subset \mathbb R$ and want to construct $f: \mathbb R\to [0,1]$ such that $f(x) >0\iff x \in I$.

First, let

$$ h(x) = \begin{cases} e^{-1/x} & x>0 \\ 0 & x\le 0\end{cases}$$

I think, it is a standard exercise in Analysis to prove that $h$ is smooth, so I won't bother doing this here. Now define

$$f(x) = h(x-a)h(b-x)$$

This function is smooth and maps into $[0,1]$ ($h\le 1$). Furthermore $$f(x) \ne 0 \iff x-a >0 \text{ and } b-x>0 \iff a < x < b$$

This concludes our observation.


You can take $$f(x) = \left\{\begin{array}{ll} (x-a)\sin\left(\frac{1}{x-a}\right)&\text{if }x\neq a\\ 0 &\text{if }x=a. \end{array}\right.$$

You can even make it differentiable on $[a,b]$ by replacing the $(x-a)$ factor with $(x-a)^2$. This function is not constant on any subinterval.


It is well known that, with probability $1$, the zero set of Brownian motion is an uncountable closed set with no isolated points.