# Construct an increasing function $f$ on $\mathbb{R}$ that is continuous at every irrational number and is discontinuous at every rational number.

Construct an increasing function f on R that is continuous at every irrational number and is discontinuous at every rational number.

Solution: Let ($$r_n$$) be a sequence with distinct terms whose range is $$\mathbb{Q}$$. Let $$f: \mathbb{R} \rightarrow \mathbb{R}$$ be given by $$f(x)= \sum_{r_n

If $$x_1 < x_2$$, then the series yielding $$f(x_2)$$ has additional positive terms than the series whose sum is $$f(x_1)$$. Thus f is increasing.

I don't understand this function at all. Can anyone tell me about the construction of function?

• It means that you have to consider those indices for $n$ for which $r_n\lt x$. For example: suppose $r_1,r_3,r_5 \lt x$ and for all other $r_n$ we have $r_n\ge x$ then $f(x)=\frac 12+\frac 1{2^3}+\frac 1{2^5}$. Also refer this: math.stackexchange.com/questions/4126663/…
– Koro
Jun 15, 2021 at 12:08
• Are you sure that it's $\frac1{2n}$? I think that it should be $\frac1{2^n}$. Jun 15, 2021 at 12:08
• The function is a sum of step functions of decreasing amplitude $2^{-n}$, with a discontinuity at $r_n$. Hence by construction, the sum converges everywhere, but has a discontinuity at every rational.
– user65203
Jun 15, 2021 at 12:15
• One special thing about this function is: it is discontinuous only at $r_n$'s and continuous elsewhere. $r_n$ is a rational no. Note that set of rationals is countable so can be indexed (enumerated).
– Koro
Jun 15, 2021 at 12:15
• $r_n$ is any enumeration of the rationals (they are countable).
– user65203
Jun 15, 2021 at 12:15

Let$$f_0(x)=\begin{cases}0&\text{ if }r_0\geqslant x\\1&\text{ if }r_0It's increasing, right!? Besides, it is discontinuous at $$r_0$$ and only at $$r_0$$.

Now, let$$f_1(x)=\begin{cases}0&\text{ if }r_1\geqslant x\\\frac12&\text{ if }r_1It's increasing and it is discontinuous at $$r_1$$ and only at $$r_1$$. So, $$f_0+f_1$$ is increasing and it is discontinuous at $$r_0$$ and at $$r_1$$ and only at those points.

More generally, for each $$n\in\Bbb Z_+$$, let$$f_n(x)=\begin{cases}0&\text{ if }r_n\geqslant x\\\frac1{2^n}&\text{ if }r_nThen $$f$$ is increasing, since it is equal to $$\sum_{n=0}^\infty f_n$$. And it is not hard to see that it is discontinuous at $$x$$ if and only if $$x\in\{q_n\mid n\in\Bbb Z_+\}=\Bbb Q$$ (this follows from the fact that the convergence of the series $$\sum_{n=0}^\infty f_n$$ is uniform, by the Weierstrass $$M$$-test). The reason why I told you in the comments that it should be $$\frac1{2^n}$$ rather than $$\frac1{2n}$$ was so that the expression $$\sum_{n=0}^\infty f_n$$ makes sense, that is, so that it converges, for every $$x\in\Bbb R$$.

• One missing comment: the sum is always convergent.
– user65203
Jun 15, 2021 at 12:19
• Fantastic! Thank you for this :-) I would also like to add that instead of $\sum \frac 1{2^n}$, any convergent series of positive terms will also work :)
– Koro
Jun 15, 2021 at 12:21
• @YvesDaoust Thank you. I've added that to my answer. Jun 15, 2021 at 12:22
• @Koro Indeed.${}$ Jun 15, 2021 at 12:22
• In fact it seems worth mentioning that the sum converges uniformly (hence it's continuous at every point where all the terms are continuous). Jun 15, 2021 at 13:05

First you need a sequence covering all the rational numbers, such as $$0,-1,1,-2,-\frac12, \frac12, 2, -3, -\frac13, \frac13, 3, -4, -\frac32, -\frac23, -\frac14,\frac14, \ldots$$ and then a corresponding sequence of powers of $$\frac12$$ $$\tfrac12,\tfrac14,\tfrac18,\tfrac1{16},\tfrac1{32},\tfrac1{64},\tfrac1{128},\tfrac1{256},\tfrac1{512},\tfrac1{1024},\tfrac1{2048},\tfrac1{4096},\tfrac1{8192},\tfrac1{16384},\tfrac1{32768}, \tfrac1{65536},\ldots$$

So if you want to find for example $$f(-1)$$ you would take those powers of $$\frac12$$ corresponding to less than $$-1$$ in the sequence of rationals (to $$-2,-3,-4,-\frac32,\ldots$$), and add them up, i.e. $$f(-1)=\frac1{16}+\frac1{256}+\frac1{4096}+\frac1{8192}+\cdots \approx 0.006678$$

This is clearly discontinuous at $$x=-1$$ as any $$x> -1$$ has $$f(x)$$ at least $$\frac14$$ larger. Similarly with any rational.

• What the properties of this sequence? Any sequence whose terms are distinct and every element is rational? I am stuck by how to confirm such a sequence. But many thanks for your concrete example. This is very helpful. Jun 15, 2021 at 13:23
• The properties are that this is a strictly increasing sequence, taking values on $(0,1)$, discontinuous (though left-continuous) on the rationals and continuous (and differentiable with derivative $0$) on the irrationals. With a slight adjustment to make it right-continuous, e.g. using $1-f(x)$, it could be a cumulative distribution function for a discrete random variable on the rationals Jun 15, 2021 at 13:32
• no, I was asking the sequence $r_n$. Jun 15, 2021 at 13:35
• $r_n$ takes each rational number as $\frac{a}{b}$ with $b$ a positive integer coprime to integer $a$, then orders the rationals by $|a|+|b|$ and within those by $\frac{a}{b}$. So $\frac{-3}{1}, \frac{-1}{3}, \frac{1}{3}, \frac{3}{1}$ are those where $|a|+|b|=4$, and we can ignore $\frac{2}{2}$ because $2$ is not coprime to $2$ (in fact we already listed that as $\frac11$) Jun 15, 2021 at 13:40
• Any complete list of the rationals is fine. If you leave a rational out, your $f(x)$ will be continuous there Jun 15, 2021 at 13:53