functions from Q to itself with derivative zero

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.

-
I have a feeling that f(x)=1/q^2 when x=p/q in lowest terms will be a guiding example, if not a counterexample. Gerhard "Ask Me About System Design" Paseman, 2012.07.10 –  Gerhard Paseman Jul 11 '12 at 1:53
Gerhard, I don't think that works. In the neighborhood of any $x$ your function will take values arbitrarily close to $0$. –  Nik Weaver Jul 11 '12 at 4:30

No, $f$ does not have to be locally constant. Let $a_n$ be a sequence of irrationals that decreases to zero, define $f(x) = 0$ for $x \leq 0$, and let $f(x)$ be a (single) rational number in $(e^{-1/{a_{n+1}}}, e^{-1/{a_n}})$ for $a_n < x < a_{n-1}$. Voila!

-
On second thought, a rational number less than $1/a_n^2$ in absolute value would be good enough ... –  Nik Weaver Jul 11 '12 at 5:00
-
There seems to be some problem with the link in your post. en.wikipedia.org/wiki/Minkowski's_question_mark_function –  user11000 Jul 11 '12 at 3:28
I think it is fixed –  Aaron Meyerowitz Jul 11 '12 at 5:07
Waow! Fascinating! –  Denis Serre Jul 11 '12 at 6:45

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}$.

-
I think you meant in the second sentence to write "function" instead of "homeomorphism": if you assume that $f$ is the restriction to $\mathbb{Q}$ of a homeomorphism $\mathbb{R} \to \mathbb{R}$ then you are in fact assuming that $f$ isn't constant. –  Mark Meckes Jul 13 '12 at 17:56
thank you! fixed. –  Pietro Majer Jul 13 '12 at 21:03
(Curiously it still made sense. If there were no such homeomorphism, we actully could deduce that any element in that empty class of homeomorphisms is a constant map. So, as I wrote, it was a kind of baroque way of stating that such homeo does exist!) –  Pietro Majer Jul 14 '12 at 0:45