Is there a bijection between $(0,1)$ and $\mathbb{R}$ that preserves rationality?

While reading about cardinality, I've seen a few examples of bijections from the open unit interval $(0,1)$ to $\mathbb{R}$, one example being the function defined by $f(x)=\tan\pi(2x-1)/2$. Another geometric example is found by bending the unit interval into a semicircle with center $P$, and mapping a point to its projection from $P$ onto the real line.

My question is, is there a bijection between the open unit interval $(0,1)$ and $\mathbb{R}$ such that rationals are mapped to rationals and irrationals are mapped to irrationals?

I played around with mappings similar to $x\mapsto 1/x$, but found that this never really had the right range, and using google didn't yield any examples, at least none which I could find. Any examples would be most appreciated, thanks!

• For "explicit" examples mathoverflow.net/questions/48910/… is relevant – Colin McQuillan Jan 15 '11 at 10:18
• Just to make it clear: if you are asking for a bijection with no further properties (e.g. no continuity etc. conditions) then this is true simply for cardinality reasons: $\mathbb Q$ and $\mathbb Q\cap (0,1)$ are both countably infinite, and so we can find a bijection $\phi$ from the first to the second. Also $\mathbb R\setminus \mathbb Q$ and $(0,1) \setminus \mathbb Q$ both have the cardinality of the continuum, so we can find a bijection $\psi$ from the first to the second. Gluing $\phi$ and $\psi$ gives a bijection from $\mathbb R$ to $(0,1)$ that takes (ir)rationals to (ir)rationals. ... – Matt E Jan 15 '11 at 21:42
• ... This is discussed more carefully in Asaf Karagila's answer, and the accompanying comments. – Matt E Jan 15 '11 at 21:42

$(1/x)-2$ on $(0,1/2]$ and $2-(1/(x-1/2))$ on $(1/2,1)$.

• Modify this to $2-1/(1-x)$ on $({1\over2},1)$, and it is even continuous. – Christian Blatter Jan 15 '11 at 12:55
• @ Christian. You can find a $C^k$ function composing by a well chosen polynomial. But I don't know if it is possible to find a smooth function. – Nabyl Bod Jan 15 '11 at 18:11
• Thanks Nabyl Bod, this was nice and clear and easy for me to verify for myself. – yunone Jan 15 '11 at 19:40
• @Nabyl: Can could please tell me what kind of polynomial you think of? I can't figure it out. – Hendrik Vogt Jan 16 '11 at 14:22
• @Hendrik. I think of composing by a rational polynomial (taking non negative coefficients to make it one-to-one) with a degree greater than the constraints at point $1/2$ BUT this construction does not preserve irrationality. Thanks for your comment ;) But you can find a $C^1$ function: $1/(4x)-1/2$ on $(0,1/2)$ and $1/2-1/(4(1-x))$ on $[1/2,1)$ that answers the question. – Nabyl Bod Jan 16 '11 at 16:50

$$f(x) = \frac{2x - 1}{1 - |2x - 1|}.$$

• Thanks for your response also, mjqxxxx. – yunone Jan 15 '11 at 19:42
• How do you make sure that if $x$ is irrational then so is $f(x)$? irrational divided by an irrational could be rational.. – Fawzy Hegab Jan 26 '15 at 0:02
• Solve for $x$ as a function of $f(x)$. You will find that if $f(x)$ is rational, then so is $x$. – mjqxxxx Jan 26 '15 at 3:35

With the axiom of choice we can find well orderings of $\mathbb{R}$ and of $(0,1)$ such that the first $\omega$ elements are all the rationals of the set, then we can define our map to go from one well ordering to another by preserving the index (that is $a_\alpha\mapsto b_\alpha$, for $\alpha<2^{\aleph_0}$)

As discussed in the comments below by Colin and Jason (and myself), one does not need the axiom of choice for that. Using the Cantor-Schroeder-Bernstein theorem one can have two bijections, one from $(0,1)\setminus\mathbb{Q}$ to $\mathbb{R}\setminus\mathbb{Q}$ and one from $(0,1)\cap\mathbb{Q}$ to $\mathbb{Q}$, and define a bijection as needed without the use of the axiom of choice.

• One can use the en.wikipedia.org/wiki/… to avoid using the axiom of choice – Colin McQuillan Jan 15 '11 at 10:21
• Colin: How can you ensure that the map you have from CSB preserves rationals? – Asaf Karagila Jan 15 '11 at 10:25
• @Asaf: Apply CBS theorem to injections between $(0,1) \setminus \mathbb{Q}$ and $\mathbb{R} \setminus \mathbb{Q}$ to get a bijection between the two sets and then extend by the identity function. – Jason Jan 15 '11 at 10:37
• @Jason: The identity function is not a bijection from $(0,1)\cap\mathbb{Q}$ to $\mathbb{Q}$. However you can in fact well order the rationals without AC, and then you can create the bijection. – Asaf Karagila Jan 15 '11 at 10:44
• True, that was a lazy answer by me. – Jason Jan 15 '11 at 10:50

Consider the function $f: (0,1) \rightarrow \mathbb{R}$.

\

$f(n) =\left\{ \begin{array}{ll} \dfrac{1}{x} - 2 & \text{if}\ 0 < x \leq \dfrac{1}{2}\\ \dfrac{1}{x-1} + 2 & \text{if} \ \dfrac{1}{2} < x < 1 \end{array} \right.$

\

We claim that $f$ is a bijective function between the open unit interval $(0,1)$ and $\mathbb{R}$ that takes rationals to rationals and irrationals to irrationals.

\

First, we notice that $f$ is piece-wise defined in such a way that $dom \ f$ partitions the open unit interval into two sets $S$ and $R$ defined by $S = \left \{ x \in \mathbb{R} \ | \ x \in (0,\dfrac{1}{2}] \right\}$ and $R = \left \{ x \in \mathbb{R} \ | \ x \in (\dfrac{1}{2},1) \right\}$.

\

Second, we show that $f$ takes rationals only to rationals and irrationals only to irrationals. There are a total of four cases to consider.

$\bf{Case \ \#1}$: Say $x \in S \cap \mathbb{Q}$. Then, by the definition of our function $f$, $\exists a,b \in \mathbb{Z}$ such that $x = \dfrac{a}{b}$ and $f(x) = \dfrac{b}{a} - 2$ and $b \neq 0$ because every rational $x$ can be represented as a ratio of two integers, with the denominator non-zero. Since rationals are closed under division and subtraction, we know that $\dfrac{b}{a} - 2$ is rational.

$\bf{Case \ \#2}$: Say $x \in R \cap \mathbb{Q}$. Then, by the definition of our function $f$, $\exists a,b \in \mathbb{Z}$ such that $x = \dfrac{a}{b}$ and $f(x) = \dfrac{1}{\dfrac{a}{b}-1} + 2$. Since rationals are closed under division, subtraction, and addition, we know that $\dfrac{1}{x-1} + 2$ is rational.

This shows that $\forall x \in (0,1) \cap \mathbb{Q}, f(x) \in \mathbb{Q} \subseteq \mathbb{R}$. So every rational in the open interval is mapped to a rational.

$\bf{Case \ \#3}$: Say $x \in S \cap (\mathbb{R} - \mathbb{Q}$). Then, by the definition of $f$, $\sim \exists a,b \in \mathbb{Z}$ such that $f(x) = \dfrac{b}{a} - 2$. Since both the subtraction and division of an irrational number by a rational number still produces an irrational number, we know that $\dfrac{b}{a} - 2$ is irrational.

$\bf{Case \ \#4}$: Say $x \in R \cap (\mathbb{R} - \mathbb{Q}$). Then, by the definition of $f$, $\sim \exists a,b \in \mathbb{Z}$ such that $f(x) = \dfrac{1}{\dfrac{a}{b}-1} + 2$. Since the subtraction, division, and addition of an irrational number with a rational number produces an irrational number, we know that $\dfrac{1}{\dfrac{a}{b}-1} + 2$ is irrational.

Therefore, $f$ maps irrationals only to irrationals.

\

Thirdly, we must show that $f$ is a bijective function.

\

To prove injectivity, there are two cases:

\

$\bf{Case \ \#1}$: Let $f(x) = f(y)$, where $x,y \in S \cap \mathbb{Q}$. Then, $\exists a,b,c,d \in \mathbb{Z}$, where $b,d \neq 0$, and $x = \dfrac{a}{b}$ and $y = \dfrac{c}{d}$ such that $\dfrac{b}{a} - 2 = \dfrac{d}{c} -2$. Adding both sides by two, we get $\dfrac{b}{a} = \dfrac{d}{c}$ which implies that $\dfrac{a}{b} = \dfrac{c}{d}$. So $x = y$ and $f$ is injective.

$\bf{Case \ \#2}$: Let $f(x) = f(y)$, where $x,y \in R \cap \mathbb{Q}$. Then, $\exists a,b,c,d \in \mathbb{Z}$, where $b,d \neq 0$, and $x = \dfrac{a}{b}$ and $y = \dfrac{c}{d}$ such that $\dfrac{1}{\dfrac{a}{b}-1} + 2 = \dfrac{1}{\dfrac{c}{d}-1} + 2$. Subtracting both sides by 2 we get $\dfrac{1}{\dfrac{a}{b}-1} = \dfrac{1}{\dfrac{c}{d}-1}$. This implies that $\dfrac{c}{d} - 1 = \dfrac{a}{b} -1$. Adding both sides by 1, we get $y = x$ so $f$ is injective.

\

To prove surjectivity, there are four cases:

\

$\bf{Case \ \#1}$: We show that $\forall y \in \mathbb{Q}$, $y = f(x)$ for some $x \in S \cap \mathbb{Q}$. Let $f(x) = y$; so $y = \dfrac{1}{x} - 2$. Then, $x = \dfrac{1}{y+ 2}$ and we are done.

$\bf{Case \ \#2}$: We show that $\forall y \in \mathbb{Q}$, $y = f(x)$ for some $x \in R \cap \mathbb{Q}$. Let $f(x) = y$; so $y = \dfrac{1}{x-1} + 2$. Then, $x = \dfrac{1}{y-2} + 1$ and we are done.

$\bf{Case \ \#3}$: We show that $\forall y \in (\mathbb{R} - \mathbb{Q})$, $y = f(x)$ for some $x \in S \cap (\mathbb{R} - \mathbb{Q})$. Let $f(x) = y$; so $y = \dfrac{1}{x} - 2$. Then, $x = \dfrac{1}{y+ 2}$ and we are done.

$\bf{Case \ \#4}$: We show that $\forall y \in (\mathbb{R} - \mathbb{Q})$, $y = f(x)$ for some $x \in R \cap (\mathbb{R} - \mathbb{Q})$. Let $f(x) = y$; so $y = \dfrac{1}{x-1} + 2$. Then, $x = \dfrac{1}{y-2} + 1$ and we are done.

\

This completes our proof that $f$ is a bijective function between the open unit interval $(0,1)$ and $\mathbb{R}$ that takes rationals to rationals and irrationals to irrationals.