TITLE: Is there a differentiable function such that $f(\mathbb Q) \subseteq \mathbb Q$ but $f'(\mathbb Q) \not \subseteq \mathbb Q$?
QUESTION [50 upvotes]: Is there a differentiable function $f:\mathbb R \rightarrow \mathbb R$ such that $f(\mathbb Q) \subseteq \mathbb Q$, but $f'(\mathbb Q) \not \subseteq \mathbb Q$? A friend of mine asserted this without giving any examples. I seriously doubt it, but I had hard time trying to disprove it since analysis isn't really my thing. I can't even think of any class of differentiable functions with $f(\mathbb Q) \subseteq \mathbb Q$ other than the rational functions.

REPLY [6 votes]: Here is another answer. Define $h:[0,+\infty)\to \mathbb{R}$ as follows:
$$h(x):= \frac{1}{(n+1)!}(n+1-n(x-n)) \quad \text{for } x\in [n,n+1)$$
The function $h$ is continuous and satisfies $h(k)=1/k!$ for every $k$ integer in its domain. Moreover:
$$ \int _0^{q}h(t)dt \in \mathbb{Q} \quad \forall q \in \mathbb{Q}$$
since on every interval of the type $[n,n+1)$ the function $h$ is  an affine function with rational coefficients. A direct computation shows:
$$ \int _0^{\infty}h(t)dt = \sum_{k=0}^{+\infty} \frac{1}{2}\big( \frac{1}{k!} + \frac{1}{(k+1)!}\big) = e - \frac{1}{2}$$
Define now $f:\mathbb{R}\to \mathbb{R}$ as follows:
$$f(x):=
\begin{cases}
0 & x=0\\
x \int _0^{1/|x|}h(t)dt & x\neq 0
\end{cases}
$$
Then $f$ satisfies $f(\mathbb{Q})\subseteq \mathbb{Q}$ and it is differentiable in $x\neq 0$ for the fundamental theorem of integral calculus. What about $x=0$? We have:
$$\lim_{x\to 0}\frac{f(x)-f(0)}{x-0} = \lim_{x\to 0}\frac{x \int _0^{1/|x|}h(t)dt}{x}= \int _0^{+\infty}h(t)dt = e - \frac{1}{2}$$
Hence $f$ is differentiable on the whole real line and $f'(0)= e-1/2 \notin \mathbb{Q}$