# Is there a continuous function from $[0,1]$ to $\mathbb R$ that satisfies

Is there a continuous function $f:[0,1] \to \mathbb R$ such that $f(x) = 0$ uncountably often and, for every $x$ such that $f(x) = 0$, in any neighbourhood of $x$ there are $a$ and $b$ such that $f(a) > 0$ and $f(b) < 0$?

Let $K$ be the Cantor set; recall that $K$ is uncountable. Then the function $x\to d(x,K),$ where $d(x,K)$ denotes the distance from $x$ to $K,$ is continuous on $[0,1].$ Define

$$f(x) = \begin{cases} 0, x \in K\\ d(x,K)\sin (1/d(x,K)), x \in [0,1]\setminus K. \end{cases}$$

Let $I_1, I_2, \dots$ be the open intervals thrown out in the construction of $K.$ In each $I_n,$ $f$ is continuous. Hence $f$ is continuous on $[0,1]\setminus K.$ If $x_n \to x \in K,$ then $d(x_n,K)\to 0,$ hence so does $f(x_n),$ which implies $f$ is continuous at $x.$ Thus $f$ is continuous on $[0,1].$

Now in any neighborhood of a point in $K,$ one of the $I_n$ will be contained in that neighborhood, hence $f$ will be both positive and negative in that neighborhood because of the $\sin (1/d(x,K))$ term.

Added: I just noticed that I omitted discussing points in $[0,1]\setminus K$ where $f=0.$ That happens at an $x$ such that $d(x,K)=1/(m\pi)$ for some $m\in \mathbb {N}.$ Because each $I_n$ has length $1/3^k$ for some $k,$ such an $x$ could not be the midpoint of any $I_n.$ So then $x$ is to the right or left of the midpoint of whatever $I_n$ it belongs to, and thus $d(\cdot,K)$ will be strictly increasing or decreasing in a neighborhood of $x,$ which implies a change in the sign of $f$ at that $x$ as desired.

• Very clever! How'd you come up with that?
– Moya
Aug 30, 2015 at 23:24
• $x\sin(1/x)$ and its relatives are the gift that keeps on giving.
– zhw.
Aug 30, 2015 at 23:28

In addition to the carefully constructed examples others have given, I just want to note that with probability $1$ one-dimensional Brownian motion starting at $0$ has these properties.

Absolutely. For example, we can proceed in a similar fashion to the definition of the Cantor function, using the "middle third construction of the Cantor set. In the first stage, we remove the "middle third" $(\frac13,\frac23)$ of $[0,1],$ and on this interval, we define $f(x)=(x-\frac12)^2+c_1$, where $c_1$ is the unique number such that $f(x)\to 0$ as $x\searrow\frac13$ and $x\nearrow\frac23.$ (I leave its determination to you.)

In the second stage, we remove the two "middle thirds" $(\frac19,\frac29)$ and $(\frac79,\frac89)$. On the first of these, we define $f(x)=-(x-\frac16)^2+c_2,$ where $c_2$ is the unique number so that $f(x)\to 0$ as $x\searrow\frac19$ and $x\nearrow\frac29.$ on the second, we define it by $f(x)=-(x-\frac56)^2+c_2,$ and we can show that $f(x)\to 0$ as $x\searrow\frac79$ and $x\nearrow\frac89.$ (I leave it to you to find $c_2$ and verify this.

We proceed in much the same manner. At the $n$th stage, we remove $2^{n-1}$ open intervals of the form $\left(m-\frac1{2\cdot3^n},m+\frac1{2\cdot3^n}\right),$ and there is some $c_n$ such that for any such "middle third" interval, we define the function on that interval by $f(x)=(-1)^{n-1}(x-m)^2+c_n,$ and we have the property that $f(x)\to0$ as $x\searrow m-\frac1{2\cdot3^n}$ and $x\nearrow m+\frac1{2\cdot3^n}.$

Finally, we define $f(x)=0$ on the Cantor set, itself. Then $f$ has exactly the properties you need, and is in fact differentiable everywhere but at the endpoints of the "middle third" intervals, I believe.

Yes.

Our function will be $0$ on the Cantor set and nowhere else. For convenience we define a spike function $S(a, b)(x) = \mathbb{1}_{[a, b]}(x) \cdot \min\{|a-x|, |b-x|\}$ which is a continuous, positive, compact support function on the interval $[a, b]$. The idea will be to add a countable collection of spike functions to eventually satisfy your conditions.

So, lets approximate our function in a series of countable steps. Firstly, let $f_1 = S(1/3, 2/3)$. The greatest distance from a point with positive function value is now $1/3 = \delta_1$. Let $f_2 = f_1 - (S(1/9, 2/9) + S(7/9, 8/9))$. Now, the greatest distance from a point in $x\in [0, 1]$ with $f_2(x) = 0$ to a point with $y\in [0, 1]$ with $f_2(y)<0$ is now $1/9 = \delta_2$. Proceeding in this way, we would next add $4$ spikes to get $f_3 = f_2 + \sum_{i = 1, 7, 19, 25} S(i/27, (i+1)/27)$, and $\delta_3 = 1/27$, subtract $8$ spikes to get $f_4$

I claim that the limit of the $\{f_n\}$ exists, is well defined, and satisfies your conditions because the $\delta_n\to 0$.

Completed as a pennance for not reading the question properly.

• The question doesn't ask for the function to be surjective, just that it takes real values. Aug 30, 2015 at 22:50
• +1: Nice fix. That's pretty much the direction I was considering, initially, but I decided to try for more differentiability (for no particular reason). Aug 30, 2015 at 23:41
• Its the natural solution, though Robert Israel has a nice example/class of examples too. Aug 31, 2015 at 5:49