Can we construct a function $f:\mathbb{R} \rightarrow \mathbb{R}$ such that it has intermediate value property and discontinuous everywhere?

Sure. The class of functions satisfying the conclusion of the Intermediate Value Theorem is actually vast and well-studied: such functions are called Darboux functions in honor of Jean Gaston Darboux, who showed that any derivative is such a function (the point being that not every derivative is continuous).

A standard example of an everywhere discontinuous Darboux function is Conway's base 13 function.

(Perhaps it is worth noting that the existence of such functions is not due to Conway: his is just a particularly nice, elementary example. I believe such functions were already well known to Rene Baire, and indeed possibly to Darboux himself.)


Please look at the problem $1.3.29$ in Problems in Mathematical Analysis Vol II, Continuity and Differentiation, by Kaczor and Nowak (page 18 and page 159).

They have provided solutions also. Anyhow since one can't view it in Google books, I am Texing out the solution here.

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.

Solution. We show that if $I$ is a subinterval of $(0,1)$ with non-empty interior then, $f(I)=[0,1]$. To this end, note that such an $I$ contains a sub-interval $\bigl(\frac{k}{2^{n_0}}, \frac{k+1}{2^{n_0}}\bigr)$. So it is enough to show that, $$f\biggl(\biggl(\frac{k}{2^{n_0}},\frac{k+1}{2^{n_0}}\biggr)\biggr)= [0,1]$$

Now observe that if $x \in (0,1)$ then either $x-\frac{m}{2^{n_0}}$ with some $m$ and $n_0$ or $x \in \bigl(\frac{j}{2^{n_0}},\frac{j+1}{2^{n_0}}\bigr)$ with some $j=0,1, \cdots, 2^{n_0}-1.$ If $x = \frac{m}{2^{n_0}}$, then $f(x)=1$, and the value of $f$, at the middle point of $\bigl(\frac{k}{2^{n_0}}, \frac{k+1}{2^{n_0}}\bigr)$ is also $1$. Next if $x \in \bigl(\frac{j}{2^{n_0}}, \frac{j+1}{2^{n_0}}\bigr)$ then there is $x' \in \bigl(\frac{k}{2^{n_0}}, \frac{k+1}{2^{n_0}}\bigr)$, such that $f(x)=f(x')$. Indeed, all numbers in $\bigl(\frac{k}{2^{n_0}}, \frac{k+1}{2^{n_0}}\bigr)$ have the same first $n_0$ digits, and we can find $x'$ in this interval for which all the remaining digits are as in the binary expansion of $x$. Since $$\overline{\lim_{n\to\infty}} \ \frac{\sum\limits_{i=1}^{n} a_{i}}{n} = \overline{\lim_{n\to\infty}} \ \frac{\sum\limits_{i=n_{0}+1}^{n} a_{i}}{n}$$ we get $f(x)=f(x')$.

Consequently it is enough to show that $f((0,1))=[0,1]$, or in other words, for each $y \in [0,1]$ there is $x \in (0,1)$ such that $f(x)=y$. It follows from the above that $1$ is attained, for example at $x =\frac{1}{2}$. To show that $0$ is also attained, take $x = 0.a_{1}a_{2}\cdots,$ where $$ a_{i}=\biggl\{\begin{array}{cc} 1 & \text{if} \ i=2^{k}, \ k=1,2, \cdots, \\\ 0 & \text{otherwise.}\end{array}$$

Then $$f(x) = \lim_{k \to \infty} \frac{k}{2^{k}}=0$$

To obtain $y=\frac{p}{q}$, where $p$ and $q$ are Co-prime positive integers, take $$ x = \underbrace{.00\cdots 0}_{q-p} \: \underbrace{11\cdots 1}_{p} \: \underbrace{00\cdots 0}_{q-p} \cdots,$$ where blocks of $q-p$ zeros alternate with blocks of $p$ ones. Then $f(x) = \lim_{k\to\infty} \frac{kp}{kq}=\frac{p}{q}$. Now our task is to show that every irrational $y \in [0,1]$ is also attained. We know that there is a sequence of rationals $\frac{p_n}{q_n}$, where each pair of $p_n$ and $q_n$ are co-prime converging to an irrational $y$. Let $$x = \underbrace{.00 \cdots 0}_{q_{1}-p_{1}} \: \underbrace{11\cdots 1}_{p_{1}} \: \underbrace{00 \cdots 0}_{q_{2}-p_{2}} \cdots,$$

Then $f(x) = \lim_{n \to \infty} \frac{p_{1} + p_{2} + \cdots + p_{n}}{q_{1} + q_{2} + \cdots + q_{n}} = \lim_{n \to \infty} \frac{p_{n}}{q_{n}} = y$.

Since $\displaystyle\lim_{n \to \infty} q_{n} = +\infty$, the second equality follows from the Stolz theorem.


Any function that give all the reals numbers on any open interval is an example. You can find other examples of this in the answers to this question on MathOverflow.


Not only such functions exists, but it turns out there are lots of such functions.

There is actually a Theorem, I think by Sierpinski, that any real valued function is the sum of two Darboux functions...