Suppose that the function $p(x)$ is defined on an open subset $U$ of $\mathbb{R}$ by a power series with real coefficients. Suppose, further, that $p$ maps rationals to rationals. Must $p$ be defined on $U$ by a rational function?

4$\begingroup$ A more realistic question: is it true that if $p(x)$ maps all rationals to rationals, then all coefficients of $p$ are rational numbers? $\endgroup$– user6976Commented Oct 17, 2010 at 6:57

2$\begingroup$ I'd say no. The $f(x)$ that I wrote below may have (by rearrangement) only irrational coefficients in its power series expansion, the reason being that we just have a smallness constraint in choosing the rationals $\epsilon _n$, while the coefficient of the power series expansion are given by certain series in which all the $\epsilon_n$ enter (so we can easily make them all trascendent). $\endgroup$– Pietro MajerCommented Oct 17, 2010 at 8:12
2 Answers
No. In fact, $p(x)$ can be a complex analytic function with rational coefficients that takes any algebraic number $\alpha$ in an element of $\mathbb{Q}(\alpha)$. (And everywhere analytic functions are not rational unless they are polynomials).
The algebraic numbers are countable, so one can find a countable sequence of polynomials $q_1(x), q_2(x), \ldots \in \mathbb{Q}[x]$ such that every algebraic number is a root of $q_n(x)$ for some $n$. Suppose that the degree of $q_i(x)$ is $a_i$, and choose integers $b_i$ such that $$b_{n+1} > b_{n} + a_1 + a_2 + \ldots + a_n.$$
Then consider the formal power series:
$$p(x) = \sum_{n=0}^{\infty} c_n x^{b_n} \left( \prod_{i=0}^{n} q_i(x) \right),$$
By the construction of $b_n$, the coefficient of $x^k$ for $k = b_n$ to $b_{n+1} 1$ in $p(x)$ is the coefficient of $x^k$ in $c_n x^{b_n} \prod_{i=1}^{n} q_i(x)$. Hence, choosing the $c_n$ to be appropriately small rational numbers, one can ensure that the coefficients of $p(x)$ decrease sufficiently rapidly and thus guarantee that $p(x)$ is analytic.
On the other hand, clearly $p(\alpha) \in \mathbb{Q}[\alpha]$ for every (algebraic) $\alpha$, because then the sum above will be a finite sum.
With a slight modification one can even guarantee that the same property holds for all derivatives of $p(x)$.
I learnt this fun argument from the always entertaining Alf van der Poorten (who sadly died recently).

6$\begingroup$ Tribute to Alf by Jeff Shallit at recursed.blogspot.com/2010/10/… $\endgroup$ Commented Oct 17, 2010 at 7:18

$\begingroup$ What is that "slight modification" to have derivatives with same property? $\endgroup$– SomniumCommented Sep 28, 2022 at 16:15
You can map $\mathbb{Q}$ in itself by plenty of entire functions that are not rational functions. Let fix an enumeration of the rationals, $\mathbb{Q}=\{q _ j\ : j=1,2,\dots \} $. Consider a series $$f(x):=\sum_{n=1}^\infty\ \epsilon _n \ \prod _{j=1}^n (xq _j)$$ If $\epsilon _n$ is a sequence of rationals converging to 0 with sufficient velocity, the series converges uniformly on bounded sets to an entire function.
(edit) rmk. of course with some more small care we can even make an entire function $f(x)=\sum_{n=0}^\infty p _n(x)$ invertible over $\mathbb{R}$, and a bijection between two assigned countably infinite dense subsets $A$ and $B$. Start the series with the identity $p_0(x)=x$, then add inductively only odd degree polynomials $p _n$, that vanish on the (finitely many) already settled points, and do not destroy the invertibility on $\mathbb{R}$ (say, keeping all partial sums of the series with derivative greater than $1/2$). The bijectivity between $A$ and $B$ is to be ensured by a standard pingpong argument.