# Continuous functions that preserve rationality

I am not sure whether I stated to title correctly, but here is the problem that came up while studying.

For a continuous function $f: \mathbb{R} \rightarrow \mathbb{R}$, find all functions $f$ such that if $x$ is a rational number, then $f(x)$ is also a rational number. Also, if $x$ is irrational, then $f(x)$ is also irrational.

I could think of $f(x)=ax+b, f(x)=1/x$. Could there be any other functions?

I haven't studied real analysis, so I think this may be out of my knowledge.

• – Math Lover Mar 31 '17 at 8:11
• This question is too wide. Anyway, $1/x$ is not defined on the whole real line, so it does not satisfy your condition. There is $|x|$ which satisfies it. Moreover, you can use composition to make new ones, like $$||2x+3|-5|x-6|+4|+|2x-1|$$ – Crostul Mar 31 '17 at 8:12