This is a follow-up question to a previous question of mine. The previous one was answered (in fact it was a duplicate), but I still didn't feel like my inquiry was over.
The original question was about the mean value theorem on a space which is not complete, in this case $\mathbb{Q}$. We can easily find a function $f\colon\mathbb{Q}\to\mathbb{R}$ which doesn't satisfy the mean value theorem by choosing a function with $f(a)=f(b),a,b\in\mathbb{Q}$ and the only maximum or minimum $x_m\in (a,b)\cap (\mathbb{R}\setminus\mathbb{Q})$.
My question now was: Is there a function $f\colon\mathbb{Q}\to\mathbb{R}$, differentiable everywhere (on $\mathbb{Q}$) with a nonnegative derivative $f'(x)\ge 0$ for every $x\in\mathbb{Q}$, but which is not monotone increasing.
It turns out that finding a such a function is a bit more difficult, but conceptually not much different - we simply take a function $f\colon\mathbb{R}\to\mathbb{R}$ that has a jump discontinuity at some irrational point but is constant everywhere else, then take its restriction $f\mid_{\mathbb{Q}}$.
At this point I wasn't satisfied, because it felt pathological to force a function into discontinuity in its (mostly continuous) extension to the reals. I started wondering whether I could construct a function that could be continuously extended to the reals and maybe even be differentiable everywhere.
Here I figured that, if it was differentiable everywhere, the derivative could not be continuous, since the derivative was nonnegative on a dense subset, so would have to be nonnegative everywhere. I also noticed that as soon as $f'(x)<0$ for some irrational $x\not\in\mathbb{Q}$, the derivative would have to take every value between $f'(x)$ and $0$ between $x$ and any rational point $p/q$ by the theorem of Darboux, which states that even non continuous derivatives satisfy the intermediate value theorem.
This feels impossible, but I don't know. So I approached the idea from a different angle. How about constructing the derivative and then taking its primitive?
My question now became: Is there a function $f\colon\mathbb{R}\to\mathbb{R}$, such that $f(p/q)=0$ for every rational $p/q$ but $f(x)<0$ for some irrational $x$? This in itself can easily be constructed, but is it still possible if we force the regularity condition that $f$ is integrable and the continuous $F\colon\mathbb{R}\to\mathbb{R}, x\mapsto\int_0^x f(t)\mathrm{d}t$ is differentiable everywhere with derivative $F'=f$ or at least $F'(y)=f(y)<0$ for some irrational $y$? Or maybe that $f$ satisfies the intermediate value theorem?
If you have input or an answer to any of my question, I'd much appreciate the ideas. I myself am stuck here. The idea seems impossible, but I am still missing the argument as to why. Maybe someone here can help. Cheers!
Edit: José Carlos Santos reply showed that my previous conditions on $f$ would not be enough to give a primitive that is not monotone increasing. So I needed to impose more conditions.
Take$$\begin{array}{rccc}f\colon&\Bbb R&\longrightarrow&\Bbb R\\&x&\mapsto&\begin{cases}0&\text{ if }x\ne\sqrt2\\-1&\text{ otherwise.}\end{cases}\end{array}$$If you define $F\colon\Bbb R\longrightarrow\Bbb R$ by $F(x)=\int_0^xf(t)\,\mathrm dt$, then $F$ is differentiable everywhere, since it is the null function.