TITLE: functions from Q to itself with derivative zero
QUESTION [19 upvotes]: Let $f: {\bf Q} \rightarrow {\bf Q}$ be a "${\bf Q}$-differentiable" function whose "${\bf Q}$-derivative" is constantly zero; that is, for all $x \in {\bf Q}$ and all $\epsilon > 0$ in ${\bf Q}$, there exists $\delta > 0$ in ${\bf Q}$ such that for all $y \in {\bf Q}$ with $0 < |x-y| < \delta$, $|(f(y)-f(x))/(y-x)| < \epsilon$.
An example of such a function is the 2-valued function on ${\bf Q}$ that takes the value 0 or 1 according to whether $x<\pi$ or $x>\pi$.
Must $f$ be locally constant, in the sense that for all $x \in {\bf Q}$, there exists $\delta > 0$ in ${\bf Q}$ such that for all $y \in {\bf Q}$ with $|x-y| < \delta$, $f(y)=f(x)$?
I have a feeling that this is not a hard problem (and I am even afraid some of you will think that it is a homework problem!), but it actually arose from my research (see http://jamespropp.org/reverse.pdf), and after an hour of thought I still don't see the answer.  In an ideal world I'd mull it over longer before posting, but since the journal to which I have submitted the paper has given me a deadline for making revisions, and the deadline is approaching, I am swallowing my pride and seeking help.

REPLY [12 votes]: Of course you can't deduce that $f$ is constant. It is worth remarking that  such  $ 
f$ is not necessarily constant even in the quite stronger assumption that it is the restriction to $\mathbb{Q}$ of an  everywhere differentiable function $\mathbb{R}\to\mathbb{R}$.
Indeed, there are everywhere differentiable homeomorphisms $g:\mathbb{R}\to\mathbb{R}$ whose derivative vanishes on a dense set. Moreover, you can put in bijection any pair of countable dense subsets of $\mathbb{R}$ by means of an analytic diffeomorphism (see the linked paper in this answer, or the construction sketched in this other answer). So, composing the above function  $g$ with diffeos $\phi$ and $\psi$ produces an everywhere differentiable map $f:=\phi\circ g\circ\psi$ whose derivative vanishes on $\mathbb{Q}$ and such that $f(\mathbb{Q})=\mathbb{Q}$:  just take $\psi(\mathbb{Q})\subset\{g'=0\}$ and 
$\phi (g(\psi (\mathbb{Q})))=\mathbb{Q}$.