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?



Is there an analytic non-linear function that maps rational numbers to rational numbers and it maps irrational numbers to irrational numbers?
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.


