TITLE: The limit of a function with derivative at least $1_\mathbb{Q}$
QUESTION [8 upvotes]: Let $f:\mathbb{R}\to \mathbb{R}$ be differentiable, such that $f'(x) \ge 1_{\mathbb{Q}}(x)$. Is it true that $\lim_{x\to\infty}f(x) = \infty$?

REPLY [6 votes]: The answer is "no", and here is how one can adapt Pietro Majer's construction from the other answer to work with the set of rational numbers.

Step 1. We begin with the original construction of Pompeiu function. Let $q_n$ be an enumeration of rational numbers in $(0, 1)$, and define, as in the original construction,
$$ u(x) = a + b \sum_{n = 1}^\infty \frac{\sqrt[3]{x - q_n}}{2^n} \, , $$
where $a$ and $b > 0$ are chosen in such a way that $u(0) = 0$ and $u(1) = 1$. Then $u$ is increasing and differentiable in an extended sense: $u'(x) \in (0, \infty]$ exists for every $x \in [0, 1]$, and $u'(x) = \infty$ for every rational $x \in (0, 1)$.

Step 2. We now define
$$ v(x) = u\biggl(\frac{1}{2} + \frac{x}{1 + 2 |x|}\biggr) . $$
Observe that $x \mapsto 1/2 + x / (1 + 2 |x|)$ is differtentiable with everywhere positive derivative, and it maps rational numbers to rational numbers. Thus, $v : \mathbb{R} \to (0, 1)$ is an increasing homeomorphism, $v$ is everywhere differentiable in the extended sense, $v'(x) \in (0, \infty]$ for every $x$, and $v'(x) = \infty$ whenever $x$ is rational.

Step 3. We now find an increasing homeomorphism $\phi : (0, 1) \to (0, 1)$ which is differentiable with everywhere positive derivative, and which has the following property: for every $s \in \mathbb{Q}$ there is $x \in \mathbb{Q}$ such that $$x + \phi(v(x)) = x.$$ Such a function $\phi$ can be constructed recursively, as follows.
We begin with $\phi_0(x) = s$. Let $r_n$ be an enumeration of all rational numbers. In step $n$ we suppose that we have already constructed a function $\phi_{n-1}$ with the following properties: $$|\phi_{n-1}' - 1| < 3^{-1} + \ldots + 3^{-(n-1)},$$ and there are rational numbers $x_1, \ldots, x_{n-1}$ such that $$x_j + \phi_{n-1}(v(x_j)) = r_j$$ for $j = 1, \ldots, n-1$. We now define $\phi_n$ to be an appropriate "tiny" modification of $\phi_{n-1}$.
Since $\phi_{n-1}' > 0$, there is a unique number $\tilde{x}_n$ such that $$\tilde{x}_n + \phi_{n-1}(v(\tilde{x}_n)) = r_n.$$ We choose a non-negative, compactly supported, smooth function $\psi_n$ on $(0, 1)$ such that $\psi_n(v(x_j)) = 0$ for $j = 1, \ldots, n - 1$, $\psi_n(v(\tilde{x}_n)) > 0$, and $\|\psi_n'\|_\infty < 3^{-n}$. For every $\epsilon \in [0, 1)$ we have
$$\phi_{n-1}' + \epsilon \psi_n' \ge 1 - (3^{-1} + \ldots + 3^{-(n-1)} + \epsilon 3^{-n}) > 0 ,$$
and hence there is a unique solution $x$ of $$x + \phi_{n-1}(v(x)) + \epsilon \psi_n(v(x)) = r_n .$$ This solution depends continuously on $\epsilon$, and since $\psi_n(v(\tilde{x}_n)) \ne 0$, it indeed changes with $\epsilon$. By the intermediate value property, there is an $\epsilon$ such that the corresponding solution $x$ is a rational number. For this $\epsilon$ and $x$, we set
$$ \phi_n = \phi_{n-1} + \epsilon \psi_n $$
and $x_n = x$. This way, we have constructed $\phi_n$ with all the desired properties.
By construction, $\psi_n$ converges in $C^1$ to an increasing homeomorphism $\psi : (0, 1) \to (0, 1)$ with the desired properties; namely, $|\psi' - 1| < 1/2$, and $x_n + \psi(v(x_n)) = r_n$.

Step 4. We set $w(x) = \psi(v(x))$. Then $w : \mathbb{R} \to (0, 1)$ is differentiable everywhere in the extended sense, $w'(x) = \psi'(v(x)) v'(x) \in (0, \infty]$, $w'(x) = \infty$ for every rational $x$, and $$x_n + w(x_n) = r_n.$$ Now we follow Pietro Majer's argument: we set $g : (0, 1) \to \mathbb{R}$ to be the inverse function of $w$, $h(x) = g(x) + x$, and $f : \mathbb{R} \to (0, 1)$ to be the inverse function of $h$.
Clearly, $g$, $h$ and $f$ are everywhere differentiable, with $g' \geqslant 0$, $h' \geqslant 1$ and $0 < f' \leqslant 1$, respectively.
Observe that $h(w(x_n)) = g(w(x_n)) + w(x_n) = x_n + w(x_n) = r_n$. Since $w'(x_n) = \infty$ for every $n$, we have $g'(w(x_n)) = 0$, and hence $h'(w(x_n)) = 1$. Thus, $f'(r_n) = f'(h(w(x_n)) = 1 / h'(w(x_n)) = 1$. Since $r_n$ exhaust all rational numbers, $f'(x) = 1$ for every rational $x$.