# Why is this function nowhere continuous?

I was introduced in class to this function, described here in a post from a few years ago: https://math.stackexchange.com/a/44285/429158

This function has the intermediate value property, i.e. its image is an interval, but it is nowhere continuous.

I do get why it has the intermediate value property, but I can't wrap my head around why is it nowhere continuous. Any insights?

• The very short answer is that it takes every value in $[0,1]$ within any interval with a nonempty interior. This simple point is perhaps easily overlooked in the mass of detail in that post. – Harald Hanche-Olsen May 31 '17 at 12:14
• Sorry, I feel like a dummy but I still don't quite get it. Would you mind to elaborate a little? – Noa May 31 '17 at 12:20

To quote the question from the linked post:

Question: Recall that every $x \in (0,1)$ can be represented by a binary fraction $0.a_{1}a_{2}a_{3}\cdots$, where $a_{i} \in \{0,1\}$ and $i=1,2, \cdots$. Let $f: (0,1) \to [0,1]$ be defined by $$f(x) = \overline{\lim_{n \to \infty}} \ \frac{1}{n} \sum\limits_{i=1}^{n}a_{i}$$ Prove that $f$ is discontinuous at each $x \in (0,1)$ but nevertheless has the intermediate value property.

Before continuing, I should mention a minor point: The function $f$ is not well defined, since any dyadic rational $x$ has two binary expansions, one ending in all zeros and one ending in all ones. So you get both $f(x)=0$ and $f(x)=1$ from the definition. This is easily repaired, though: Just choose one or the other. From a quick reading of the linked answer, I guess the choice is $f(x)=1$ for dyadic rationals $x$.

Now the point is this: To describe $x$ to great accuracy, you need to fix the first $k$ bits $a_i$, for some $k$. But once that is done, you can make $f(x)$ be whatever you want, just by adjusting the frequency of the following bits. It quickly follows that $f$ takes all values in $[0,1]$ in any open subinterval of $(0,1)$.

If $f$ is continuous at $x$, then there is some $\delta>0$ so that $|f(y)-f(x)|<\frac14$ whenever $|y-x|<\delta$. That is, $f(y)\in\bigl(f(x)-\frac14,f(x)+\frac14\bigr)$. But that interval has length $\frac12$, so it does not cover $[0,1]$. That is a contradiction, so $f$ is discontinuous.

The intermediate value property should be quite obvious.

Edit: On second thought, I think the argument in the linked answer is more simply done as follows: Given $y\in[0,1)$, and assuming $a_i$ is selected for $i<n$, pick $a_n=1$ if that makes $n^{-1}\sum_{i=1}^n a_i<y$. Otherwise, pick $a_n=0$. Now the average $n^{-1}\sum_{i=1}^n a_i$ will grow with $n$ until it exceeds $y$, then it will shrink until it is less than $y$, and so forth, moving up and down in increasingly smaller excursions around $y$, and therefore converging to $y$. (Writing a formal proof is left to the reader.)