# Are there any continuous “totally rational” functions besides piecewise first-order polynomial or rational functions?

Let $I \subseteq \mathbb{R}$ be an interval and $f: I \to \mathbb{R}$ a continuous function. We’ll say that $f$ is totally rational if the following propositions are true for any $x\in I$:

1. If $x \in \mathbb{Q}$ then $f(x) \in \mathbb{Q}$

2. If $f(x) \in \mathbb{Q}$ then $x \in \mathbb{Q}$

A simple example of such a function is the identity function $f(x)=x$. More generally any function of the form $f(x)=ax + b$ with $a,b\in \mathbb{Q}$ will do. Another class of functions that are totally rational are those of the form $$f(x)=\frac{ax + b}{cx + d}\qquad \text{with}\ a,b,c,d\in \mathbb{Q} \ \text{and}\ x\neq-\frac{d}{c}.$$

Besides functions of these kinds (and piecewise combinations thereof) I cannot find any other examples of such functions. It is easy to see, for instance, that any higher-order polynomial or rational function will fail condition (2).

But do other totally rational functions exist?

• Hm. Is, for example, the blancmange function one of these? – Chappers Apr 14 '17 at 19:54
• Your examples are not functions $\mathbb{R}\to\mathbb{R}$ unless $c=0$. – Eric Wofsey Apr 14 '17 at 19:55
• – Dave L. Renfro Apr 14 '17 at 20:06
• Here's a paper I came across this morning (entirely by accident) that is not one of papers in my previously posted list: Walter Kurt Hayman, Some examples of functions mapping rationals on rationals, Results in Mathematics 10 #1-2 (August 1986), 82-92. – Dave L. Renfro Apr 20 '17 at 16:23

$f(n + 0.a_1 a_2 a_3 \dots) = 0.0 a_1 0 a_2 0 a_3 \dots$
$f(n + \sum_{i \ge 1}{a_i \cdot 10^{-i}}) = \sum_{i \ge 1}{a_i \cdot 100^{-i}}$
In other words, the function takes the decimal expansion of the fractional part and inserts a $0$ between every digit. Or it writes it in base $10$ and reads it again in base $100$.