Is there a way to prove the following result using connectedness?


Let $J=\mathbb{R} \setminus \mathbb{Q}$ denote the set of irrational numbers. There is no continuous map $f: \mathbb{R} \rightarrow \mathbb{R}$ such that $f(\mathbb{Q}) \subseteq J$ and $f(J) \subseteq \mathbb{Q}$.


Nick Peterson
  • 31,127
  • 2
  • 52
  • 72
  • 5,518
  • 1
  • 27
  • 46
  • 1
    Please make your post self-contained by incorporating the statement. It takes forever for planetmath to render for me. Maintaining the link is fine, so one can see how it is proved there. – Ross Millikan Aug 04 '11 at 18:18
  • @Ross Millikan: just edited it. – user10 Aug 04 '11 at 18:22
  • 1
    @user10 actually the link is down. – Gabriel Romon Feb 21 '14 at 23:56
  • I searched planetmath to find the original linked argument; I think it is [here](http://planetmath.org/sites/default/files/texpdf/36692.pdf) and [here](http://planetmath.org/nocontinuousfunctionswitchestherationalandtheirrationalnumbers) If it moves again but stays on the site, a Google search such as `site:planetmath.org switch rational irrational baire` will find it. – Jonas Meyer Jul 07 '16 at 14:42
  • [Linked](https://math.stackexchange.com/questions/576708/does-there-exist-a-continuous-function-such-that-fx-is-rational-for-every-irra). – Alex Ravsky Sep 23 '17 at 01:05
  • I have answered with proof by contraction here https://math.stackexchange.com/q/2877563 – Multigrid Aug 09 '18 at 18:36

4 Answers4


Here's a way to use connectedness, really amounting to using the intermediate value theorem.

If $f(\mathbb{Q})\subseteq \mathbb R\setminus\mathbb Q$ and $f(\mathbb R\setminus \mathbb Q)\subseteq\mathbb Q$, then $f(0)\neq f(\sqrt 2)$. Because intervals are connected in $\mathbb R$ and $f$ is continuous, $f[0,\sqrt 2]$ is connected. Because connected subsets of $\mathbb R$ are intervals, $f[0,\sqrt 2]$ contains the interval $\left[\min\{f(0),f(\sqrt 2)\},\max\{f(0),f(\sqrt 2)\}\right]$. The set of irrational numbers in this interval is uncountable, yet contained in the countable set $f(\mathbb Q)$, a contradiction.

A slightly briefer outline: The hypothesis implies that $f$ is nonconstant with range contained in the countable set $\mathbb Q\cup f(\mathbb Q)$, whereas the intermediate value theorem and uncountability of $\mathbb R$ imply that a nonconstant continuous function $f:\mathbb R\to\mathbb R$ has uncountable range.

Jonas Meyer
  • 50,123
  • 8
  • 190
  • 292

Suppose there is such a mapping $f$. Consider $g:[0,1]\to \mathbb{R}$ defined by $$g(x)=f(x)-x.$$ Suppose that $g(x)\in \mathbb{Q}$ for some $x\in [0,1]$. Then:

  • if $x\in J$, then $g(x)-f(x)\in \mathbb{Q}$, i.e. $x\in \mathbb{Q}$.
  • if $x\in \mathbb{Q}$, then $g(x)+x\in \mathbb{Q}$, i.e. $f(x)\in \mathbb{Q}$, but $f(x)\in J$.

Both produce contradictions. Thus $g([0,1])\subseteq J$. Since $f$ is continuous, $g$ is continuous, and then $g([0,1])=[\min g,\max g]$. If $g$ is not constant then there exists $r$ a rational in $[\min g,\max g]$. By the intermediate value theorem, there exists $z\in[0,1]$ such that $g(z)=r$, but this is impossible because $g([0,1])\subseteq J$. Therefore, $g$ must be constant and then $$f(x)=c+x$$ with $c\in J$. Particularly, $f(c)=2c\not\in \mathbb Q$ which, as Jonas pointed, is contradictory to the hypothesis. Therefore such an $f$ can not exist.

  • 9,743
  • 6
  • 47
  • 118
  • 1
    A quicker way to finish once you have $f(x)=c+x$ is to note that $f(c)=2c$ is irrational, contradicting the hypothesis. +1: This is a nice alternative that can handle a more general situation. Note that cardinality need not be considered, and in fact $\mathbb Q$ can be replaced by any subgroup of $\mathbb R$. – Jonas Meyer Aug 04 '11 at 19:43
  • yes, that's true and thank you @Jonas, I will correct for the sake of simplicity. – leo Aug 04 '11 at 19:48
  • 1
    To clarify my previous comment, I should have said that this argument applies verbatim if $\mathbb Q$ is replaced by any *dense* subgroup of $\mathbb R$ containing $2$. The last restriction could be handled by rescaling if necessary. – Jonas Meyer Aug 04 '11 at 20:06
  • Yes, I had some doubts after I wrote my comment. – leo Aug 04 '11 at 20:39
  • Hey Leo, how do you conclude that $g([0,1]) \subset $\mathbb{I}$ from the two contradictions above? – Kamil Jul 07 '16 at 09:24
  • @Kamil what's proveen is that if a point in $g([0,1])$ is rational then there are contradictions. So no point in $g([0,1])$ can be rational. Real numbers are either rational or irrational, therefore all points in the image of $g$ are irrational. – leo Jul 08 '16 at 15:56

Another simple proof:

Because $f$ is continuous and by connectedness, $f([0,1])=[a,b]$ for some $a<b$. Now define $$g : x \mapsto \frac{1}{p} \left(f(x)-q \right), \ \text{where} \ p,q \in \mathbb{Q}.$$

In particular, $g(x)$ is rational iff $f(x)$ is rational, i.e. $g$ has the same property that $f$.

Notice that $g([0,1])= \left[ \frac{a-q}{p}, \frac{b-q}{p} \right]$. Therefore, if $b-1 \leq q \leq a$ and $p \geq b-q$ then $g : [0,1] \to [0,1]$ and classically $g$ has a fixed point $x_0 \in [0,1]$.

Finally we deduce that $x_0 \in \mathbb{Q}$ iff $x_0 = g(x_0) \notin \mathbb{Q}$, a contradiction.

  • 31,571
  • 5
  • 66
  • 131
  • 1
    This uses compactness as well as connectedness of $[0,1]$ to conclude that $f([0,1])$ is a closed, bounded interval. – Jonas Meyer Jul 23 '13 at 15:10
  • Very nice proof. – leo Dec 30 '13 at 01:51
  • If $f([0,1])=[-1,1]$, then you are suggesting to consider $g(x)=f(x)$ in order to find a function $[0,1] \to [0,1]$, so it doesn't seem to work. – Seirios Aug 12 '15 at 05:49
  • Yes, you are right. Define $g(x)=\left\lvert\dfrac{f(x)}{\left\lceil \max(\left\lvert a \right\rvert,\left\lvert b\right\rvert)\right\rceil}\right\rvert$. I think that it will work. –  Aug 13 '15 at 13:48
  • I think so. But now, your solution does not seem to be really simpler than the original. – Seirios Aug 14 '15 at 06:46

Suppose such a continuous function exists. $f(\Bbb R)$ is connected, and hence uncountable. Then, $f(\Bbb Q)$ is countable because $\Bbb Q$ is so. Moreover, $f(\Bbb R\setminus\Bbb Q)$ is countable since it is contained in $\Bbb Q$. This is a contradiction.

  • 10,393
  • 3
  • 15
  • 41