# A nontrivial everywhere continuous function with uncountably many roots?

This is my first post on SE, forgive any blunders.

I am looking for an example of a function $f:\mathbb{R} \to \mathbb{R}$ which is continuous everywhere but has uncountably many roots ($x$ such that $f(x) = 0$). I am not looking for trivial examples such as $f = 0$ for all $x$. This is not a homework problem. I'd prefer a nudge in the right direction rather than an explicit example.

Thanks!

Edit: Thanks all! I've constructed my example with your help.

## 7 Answers

The roots of a continuous function is always a closed subset of $\mathbb{R}$ : $\{0\}$ is closed, thus $f^{-1}(\{0\})$ is closed too.

If you have a closed set $S$, you can define a function $f : x \mapsto d(x,S)$, which is continuous and whose set of roots is exactly $S$ : you can make a continuous function have any closed set as its set of roots.

Therefore you only have to look for closed sets that are uncountable.

• This is the best answer, since it says exactly which sets appear as zero sets of continuous functions (with an explicit construction). Thus although the OP did not specify what "nontrivial" means -- but it must mean something: e.g. it is probably not very exciting to have a function which is constantly zero on some nontrivial interval -- with this answer in hand it doesn't really matter: one knows the general case. – Pete L. Clark May 22 '11 at 17:49
• @Pete: By nontrivial, I meant exactly what you said. If a function is constantly zero on some continuous interval of $\mathbb{R}$, of course it has uncountably many roots, but this is not interesting (I thought I had made this clear by stating I was not interested in, eg, $f(x) = 0$ for all $x$). Thanks for the great answer, chandok! – barf May 22 '11 at 21:47
• I guess the Cantor set would do as an uncountable closed set. – gary Jun 30 '11 at 21:12

This could be interesting for you.

• Andre Henriques's answer has an impressive 86 upvotes! – Cheerful Parsnip May 22 '11 at 1:56

Even though you seem to be happy with the given answers, I can't resist pointing out the following construction which I already mentioned in this thread. If this example is already contained in one of the links provided in the other answer, I apologize for the duplication:

Choose a space-filling curve $c: \mathbb{R} \to \mathbb{R}^2$ and compose it with the projection $p$ to one of the coordinate axes. This gives you an example of a continuous and surjective function $f = p \circ c: \mathbb{R} \to \mathbb{R}$ all of whose pre-images are uncountable.

If $f(x)$ is the function then $E = \{ x \colon f(x) = 0 \}$ is a closed set. Do you know of a nontrivial, by your standards, closed set with uncountable many points? The complement of $E$ is open. Is there a way to describe the complement of $E$ so that it would be easy to construct the remainder of the function in such a way that the function was never $0$ on the complement of $E$.

Why not $f(x)=x+|x|$? Looks quite nontrivial to me.

• I think he is looking for an example that is not 0 on a dense interval, otherwise the problem is pretty boring. – Listing May 22 '11 at 8:49
• OK, but I only wanted to notice, that he should specify what kind of a "nontrivial" example he is looking for. – t22 May 22 '11 at 9:00

I just thought I'd mention that a Brownian motion has this property (almost surely).

If you just want a continuous function, then let $f(x) = 0$ over an interval say $[a,b]$ where $a<b$ and over the rest of the real line find functions $g(x)$ and $h(x)$ such that $g(a) = 0$ and $h(b) = 0$ and define $f(x) = g(x), \forall x \leq a$ and $f(x) = h(x), \forall x \geq b$.

You could also have infinitely smooth functions with zero on an uncountable set as for instance $$f(x)=\begin{cases}e^{-1/x}&x>0\newline 0&x\leq 0\end{cases}$$

And if you want an infinitely smooth function with a compact support

$$f(x) = \begin{cases} \exp(- \frac{1}{1 - x^2}), \quad |x| < 1 \\ 0 , \quad |x| \geq 1 \end{cases}$$