Is there an analytic non-linear function that maps rational numbers to rational numbers and it maps irrational numbers to irrational numbers? Consider a function $h$ defined on real numbers, which is not of the form $kx+b$ i.e. a linear function. If $h$ maps rational numbers to rational numbers and it maps irrational numbers to irrational numbers, could $h$ be analytic? If so, how to give an example?
 A: Answering a question of Erdos, Barth and Schneider proved that for every countable dense sets $A$ and $B$
in the complex plane, there exists an entire function such that $f(z)\in B$ if and only if $z\in A$.
K. Barth and W. Schneider, Entire functions mapping arbitrary countable dense sets and their complements to each other,
J. London Math. Soc., 4 (1971/72) 482-488.
Another paper of the same authors concerns the case
when $A$ and $B$ are on the real line. They prove
that for every two such countable dense sets, there is a transcendental entire function that maps $A$ into $B$ monotonically.
MR0269834
Barth, K. F.; Schneider, W. J.
Entire functions mapping countable dense subsets of the reals onto each other monotonically.
J. London Math. Soc. (2) 2 (1970), 620–626.
A: Let $q_n$ be a numbering of the rationals, with $q_1=0$. We can define a non linear, analytic function $F:\mathbb{R}\to\mathbb{R}$ which is strictly increasing and that maps $\mathbb{Q}$ surjectively to $\mathbb{Q}$, so it is as you want.
The function $F$ can be defined as $\sum_{n=1}^\infty p_n(x)$, where $p_i$ are certain polynomials that satisfy the following conditions:

*

*$F_n(x):=\sum_{i=1}^np_n(x)$ is strictly increasing, in fact, $F_n'(x)\geq\frac{1}{2}+\frac{1}{2^n}$. This implies in particular that $F_n:\mathbb{R}\to\mathbb{R}$ is bijective.


*$F_n(q_i)\in\mathbb{Q}$ for all $i\leq n$ and $F_n^{-1}(q_i)\in\mathbb{Q}$ for all $i\leq n$. Moreover, letting $A_n=\{q_1,\dots,q_n,F_n^{-1}(q_1),\dots,F_n^{-1}(q_n)\}$, we will have $F_{n+1}|_{A_n}=F_n|_{A_n}$. This ensures that $F|_{A_n}=F_n|_{A_n}$, so $F$ maps $\mathbb{Q}$ bijectively into $\mathbb{Q}$.


*$p_n\in\mathbb{R}[x]$ $\forall n$, and seeing $p_n$ as elements of $\mathbb{C}[x]$, we have that $|p_n(z)|<\frac{1}{2^n}$ for all $z\in B(0,n)\subseteq\mathbb{C}$. This ensures that $\sum_np_n$ converges locally uniformly in all $\mathbb{C}$, so $F$ is analytic.
Let's try to create such a sequence $F_n$ of polynomials: let $F_1(x)=x$ and suppose we are given $F_{n-1}$ satisfying the hypotheses above.
To construct $F_n$ first consider the polynomial $f_n(x)=\prod_{a\in A_{n-1}}(x-a)$. If necessary multiply $f_n$ by $x$ to ensure that it has odd degree: this implies that $f_n'$ has a lower bound. Let $G_n=F_{n-1}+\varepsilon f_n$, where $\varepsilon\geq0$ is small and such that $G_n^{-1}(q_n)$ is rational. Now let $g_n=\prod_{a\in A_{n-1}\cup\{G_n^{-1}(q_n)\}}(x-a)$, multiply it by $x$ if necessary as before, and let $F_n=G_n+\delta g_n$, where $\delta\geq0$ is small and ensures that $F_n(q_n)$ is rational.
We can make $\varepsilon,\delta$ so small that $|\varepsilon f_n+\delta g_n|<\frac{1}{2^n}$ for all $z\in B(0,n)$ and $(\varepsilon f_n+\delta g_n)'(x)\geq\frac{-1}{2^{n}}$ for all $x\in\mathbb{R}$, so that $F_n'(x)\geq\frac{1}{2}+\frac{1}{2^n}$ by induction hypothesis.
To make sure that $F$ is not linear, you can first take $\delta\neq0$ at some step so that $F_n$ is non linear and then make the $p_k$, with $k>n$, have very small norm in some disk so that $F=F_n+\sum_{k>n}p_k$ cannot be linear.
