# Continuous function taking rationals to rationals

Is there a continuous increasing function $f : [0, \pi] \to [0, e]$ such that $f(0) = 0, f(\pi) = e$ and $f (q ) \in \mathbb{Q}$ for $q \in \mathbb{Q}$ and $f (q ) \in \mathbb{Q}^c$ for $q \in \mathbb{Q}^c$? I think there should be, but I am unable to construct one.

-
I found a more straightforward solution: pick two increasing sequences of positive rational numbers $\{a_n : n \geq 1 \}$ and $\{b_n : n \geq 1 \}$ with $a_n \uparrow \pi$ and $b_n \uparrow e$ as $n \to \infty$. Set $a_0 = b_0 = 0$. Now define, $$f (x) = \begin{cases} b_n + \frac{(b_{n+1} - b_{n} ) (x - a_n) }{ (a_{n+1} - a_{n} ) } & \text{ if } a_n \leq x < a_{n+1}, n \geq 0 \\ e & \text{ if } x = \pi. \end{cases}$$ Easy to see that $f$ defined above will satisfy the properties. –  Rana Nov 8 '12 at 6:25

The back-and-forth method that shows the isomorphism of dense countable linear orders gets you there. Let $a_i$ be an enumeration of the rationals in $(0,\pi)$ and $b_j$ be an enumeration of the rationals in $(0,e)$. Set $f(a_1)$ to the first $b_j$ that has not been used and is not prohibited by the order. In this case it will be $b_1$. Then set $f^{-1}(b_2)$ to the lowest $a_i$ that is not used yet and acceptable. Alternate back and forth, assigning $f(a_i)$'s on the odd steps and $f^{-1}(b_j)$'s on the even steps. As the rationals are dense, there will always be one available. As they are countable, each has only finitely many predecessors and we will always get to it. Now for the irrationals, use continuity.

-

Find a suitable strictly ascending sequence $(c_n)_n$ of rationals and define $f(c_1)=0$ and recursively for $x\in[c_{n-1},c_n]$ by $f(c_n)=f(c_{n-1})+\frac12 (x-c_{n-1})$ if $n$ is even and $f(c_n)=f(c_{n-1})+c_n-c_{n-1}$ if $n$ is odd. Let $d_n=c_{n+1}-c_n$. In order to make this an example you are looking for, we have to make sure

• that $c_1=0$ and $c_n\to \pi$ (so that $f$ is defined on all of $[0,\pi]$)
• that $\sum_n d_n = \pi$ (which implies $c_n\to c_0+\pi)$
• that $\sum_{n\text{ even}}d_n+\frac12\sum_{n\text{ odd}}d_n$ = e

This can be accomplished by selecting positive rational numbers $d_{2n-1}$ such that their sum converges to $2(\pi-e)$ and positive rational numbers $d_{2n}$ such that theri sum converges to $2e-\pi$.

That $f$ maps rational to rational and irrational to irrational follows from the fact that each segemnt is of the form $f(x)=ax+b$ with positive rational $a$ and rational $b$.

-
Your map will only map the rationals that appear in this sequence to rationals. –  Lukas Geyer Oct 7 '12 at 17:14