Can Cantor set be the zero set of a continuous function?

The continuous function is very easy to construct: it's the distance to the closed set.


Here's a semi-explicit construction for a smooth function f that is zero precisely on the classical Cantor set. By this set I mean the one that is obtained from $I_0 = [0,1]$ by repeatedly removing the middle third of any ensuing interval. So let's denote by $I_n$ the $n$-th set in this process.

Now let's make a smooth function $f_n$ on $[0,1]$ such that its zero set is exactly $I_n$. Starting with $f_0 = 0$ we obtain $f_{n+1}$ from $f_n$ as follows:

Set $f_{n+1} = f_n$ on $I_{n+1}$ and on an interval that is removed from $I_n$ make $f_{n+1}$ equal to a bump function that is 0 only at the boundary of the interval. We can choose the bump function to be of height $2^{-2^n}$.

This choice of heights of the bump functions will ensure that the derivatives of $f$ all converge uniformly to their pointwise limits. Hence the limit function $f_n$ is again smooth. By construction its zero set is exactly the Cantor set.


It is a standard result that each closed subset of $\mathbb{R}^n$ is a zero set of some smooth function on $\mathbb{R}^n$. One proves this using smooth bump functions and partitions of unity.