TITLE: A question of rationality
QUESTION [8 upvotes]: This problem was asked to me by a friend and I simply have no idea about it. So I have not progressed a single bit. The problem is this: 
If $f :\mathbb{R}\to \mathbb{R}$ is an infinitely differentiable function and $f(x)\in\mathbb{Q} \;\forall x\in\mathbb{Q}$ then must $f'(x)$ be rational for all rational $x$ ?

REPLY [3 votes]: Let's first construct a function $f \,:\, \mathbb{R} \to \mathbb{R}$ with $f(\mathbb{Q}) \subset \mathbb{Q}$ which is derivable at a single point $x_0$ with $f'(x_0) \notin \mathbb{Q}$.
Let $q_n$ be some rational approximation of an irrational number $a$, i.e. for example let $q_n \in \mathbb{Q}$ with $\lim_{n\to\infty} q_n = \sqrt{2}$. Then take the piecwise constant function $f \,:\, \mathbb{R} \to \mathbb{Q}$ defined by $$
  f(x) = \begin{cases}
    \frac{q_n}{n} &\text{if $x \in \left[\tfrac{1}{n},\tfrac{1}{n-1}\right)$ for some $n\in\mathbb{N}$,} \\
    \frac{-q_n}{n} &\text{if $x \in \left(\tfrac{-1}{n+1},\tfrac{-1}{n}\right]$ for some $n\in\mathbb{N}$,} \\
    0 &\text{if $x = 0$}
  \end{cases}
$$
(For $x \geq 1$, this is to be read as $x \in [1,\infty)$, i.e. $n=1$ in this case). Since we even have $f(\mathbb{R}) \subset \mathbb{Q}$, obviously also $f(\mathbb{Q}) \subset \mathbb{Q})$, thus fullfilling our requirement.
Being a step function, $f$ is of course not differentiable on $\frac{1}{n}$ in general. However, at $0$, we have $$
  f'(0) = \lim_{x \to 0} \frac{f(x) - f(-x)}{2x} = \lim_{n\to\infty} \frac{f(\tfrac{1}{n}) - f(\tfrac{-1}{n})}{\tfrac{2}{n}} = \lim_{n\to\infty} \frac{\tfrac{q_n}{n} - \tfrac{-q_n}{n}}{\tfrac{2}{n}} = \lim_{n\to\infty} q_n = \sqrt{2} \notin \mathbb{Q}\text{,}
$$
meaning that $f'(0)$ does indeed exist, yet doesn't take a rational value. (Note that to force the limit to exists for all sequences $x_n \to 0$, not just $x_n = \left(\tfrac{1}{n}\right)$, it might be necessary to require $q_n$ to converge sufficiently fast)

To make $f$ differentiable everywhere, we're going to have to get rid of the steps, i.e. somehow smoothen the $f$ constructed above. For that, we can use polynomial interpolation. Let's assume $q_n \to \sqrt{2}$ monotonically from above. If we can find polynomials $p_n$, $n \in \mathbb{N}$, with $$\begin{eqnarray}
  p_n\left(\tfrac{1}{n}\right) &=& \frac{q_n}{n} \\
  p_n\left(\tfrac{1}{n-1}\right) &=& \frac{q_{n-1}}{n-1} \\
  p'_n\left(\tfrac{1}{n}\right) &=& q_{n} \\
  p'_n\left(\tfrac{1}{n-1}\right) &=& q_{n-1} \\
  p'_n\left(\left[\tfrac{1}{n}, \tfrac{1}{n-1}\right]\right) &\subset& [q_{n}, q_{n-1}]
\end{eqnarray}$$
then we can simply set $$
  f(x) = \begin{cases}
    p_n(x) &\text{if $x \in \left[\tfrac{1}{n},\tfrac{1}{n-1}\right)$ for some $n\in\mathbb{N}$,} \\
    -p_n(-x) &\text{if $x \in \left(\tfrac{-1}{n+1},\tfrac{-1}{n}\right]$ for some $n\in\mathbb{N}$,} \\
    0 &\text{if $x = 0$.}
  \end{cases}
$$
Again, $\lim_{x\to a}\frac{f(x) - f(-x)}{2x} = \lim_{n\to\infty} q_n$ if the first limit exists at all. The conditions imposed on $p'_n$ ought to ensure that it does.
Unfortunately, though, this idea still only yields a function that is differentiable once, and it's not clear whether it can be extended to yield an $f \in C^\infty$. Piecewise polynomial functions won't work for that, I fear.