Find all polynomials that fix $\mathbb Q$ and the irrationals [duplicate]
Take a polynomial $f=a_nx^n+a_{n-1}x^{n-1}+...+a_1x+a_0$, and assume $f$ satisfies the problem conditions.
Since $f(1),f(2),f(3),...,f(n)$ are all rationals, we can use them to get $n$ independent equations in the variables $a_i$. Then, we can solve for all the $a_i$ with linear algebra. Linear algebra tells us that this equation-solving uses only +,-,*, and /, so all coefficients $a_i$ of the polynomial must be rational.
Now, multiply $f$ by all the denominators of all the $a_i$ to get a new polynomial $g=b_nx^n+b_{n-1}x^{n-1}+...+b_1x+b_0$ with integer coefficients. Clearly $g$ satisfies the problem conditions as well.
Consider all values $x$ for which $g(x)$ is an integer. By the Rational Root Theorem, any such $x$ can be expressed as $\frac{k}{b_n}$ for some integer $k$. From this we deduce that any two values $x$ for which $g(x)$ is an integer are spaced at least $\frac{1}{b_n}$ apart.
But if the polynomial $g(x)$ has degree at least $2$, it attains arbitrarily large slope as $x$ goes to $\infty$. In particular, we can pick $x$ so large that $g(x+\frac{1}{b_n})>g(x)+100$. But then $g$ attains many integer values between $x$ and $x+\frac{1}{b_n}$, violating the deduction in the previous paragraph. Therefore, $g$ has degree at most $1$.
After proving this, we are done: the only polynomials $f$ that work are the ones in the form $a_1x+a_0$, where both $a_1$ and $a_0$ are rational.
Answer: $f(x) = ax+b$, where $a, b\in \mathbb{Q}$ and $a\neq 0$.
It's obvious that functions $f(x) = ax+b$ satisfy the condition. It's also easy to see that no other linear functions satisfy the condition. So we will only prove that no polynomials of degree greater than one satisfy the condition.
Definition. Let $\cal F$ be the family of polynomials that send $\mathbb Q$ to $\mathbb Q$.
Claim 1. $\cal F$ is a linear space over $\mathbb Q$.
Proof: We need to prove that $f+g\in \cal F$ if $f,g\in \cal F$ and $\alpha f\in \cal F$ when $\alpha\in {\mathbb Q}$ and $f\in \cal F$. Both statements are obvious. QED
Lemma 2. Suppose that $p(x) \in \cal F$ then the leading coefficient of $p(x)$ is a rational number.
Sketch of a proof: Let $k = \deg p$. Let $p(x) = c x^k + \dots $ . It is known that there exist rational numbers $\alpha_i$ ($1\leq i \leq k+1$) s.t. $\sum_{i=1}^{k+1} \alpha_i i^t = 0$ for $t\in \{0,\dots, k-1\}$ but $\sum_{i=1}^{k+1} \alpha_i i^{k} \neq 0$ (in particular, that follows from the Vandermonde determinant formula).
We have $\sum_{i=1}^{k+1} \alpha_i p(i) = \sum_{i=1}^{k+1} \alpha_i c i^k = c(\sum_{i=1}^{k+1} \alpha_i i^k)$. Note that $\sum_{i=1}^{k+1} \alpha_i p(i)\in \mathbb Q$ since $p(x)\in \cal F$, and $\sum_{i=1}^{k+1} \alpha_i i^k\in \mathbb Q$. Therefore, $c\in \mathbb Q$. QED
Corollary 3. Suppose that $p(x) \in \cal F$ then all coefficients of $p$ are rational.
Proof: We prove this by induction. The leading coefficient $c$ of $p(x)$ is rational by Lemma 2. Now $p(x) - c x^k\in \cal F$ by Claim 1. The polynomial $p(x) - c x^k\in \cal F$ has degree at most $k-1$. By the induction hypothesis all its coefficients are rational. Thus all coefficients of $p(x)$ are also rational. QED
Now suppose that $p(x)$ satisfies the condition of the question but $\deg p(x) > 1$. We proved that $p(x) = \sum_{i=0}^k a_i x^i$ where all $a_i\in \mathbb Q$. Without loss of generality we may assume that all coefficients $a_i$ are integer and coprime, $a_k > 0$, and that $a_0 = 0$.
Let $r$ be a sufficiently large prime number (we will let $r$ “go to infinity”). Note that $p(x) - r$ has a real root since $p(0) < 0$ but $p(x) \to +\infty$ as $x\to +\infty$. The root $\rho$ of $p(x) - r$ must be a rational number as otherwise $p(x)$ would send an irrational number $\rho$ to $0$ and thus violate the condition. Denote the root by $u/v$ where $u$ and $v$ are coprime integers. Note that if $r$ is sufficiently large, it is coprime with $a_k$. Thus $u$ divides $r$ and $v$ divides $a_k$. If $r > \max_{t\in[-1,1]} p(t)$ then $|u/v| > 1$ thus $u > 1$. So $u=r$ or $u=-r$. We get $|u/v| \geq r/a_k$. We get, $$a_k |u/v| \geq r = p(u/v) = (1+o(1)) \cdot a_k (u/v)^k,$$ which is impossible for $r\to \infty$ if $k > 1$. We conclude that $k=1$.