TITLE: Continuous function taking rationals to rationals
QUESTION [7 upvotes]: 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.

REPLY [3 votes]: 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.