Functions – Is There a Bijection Between $(0,1)$ and $\mathbb{R}$ That Preserves Rationality?

elementary-set-theoryfunctions

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!

Best Answer

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

Related Question