I'm struggling with a problem that seems very straightforward, so I apologize in advance if the answer is trivial. I'm trying to prove that:
$$f(x) = \begin{cases} x+x^2 & x \in \mathbb{Q} \\ x-x^2 & x \not\in \mathbb{Q} \\ \end{cases} $$ is not monotone on $[0, M)$ for any $M>0$.
My thoughts: Considering only the irrational portion of the function, it is clear that
$$ \sup \{f(x) : x \not\in \mathbb{Q} \} = \frac{1}{4}.$$ So, taking $M > \frac{-1 + \sqrt{2}}{2}$, by the density of the rational's and irrational's, we can find some rational $x_1 \in (\frac{-1 + \sqrt{2}}{2},M)$, some rational $x_2 \in (x_1,M)$, and some irrational $x_3 \in (x_1,x_2)$. Then, since $x_1$ and $x_2$ are rational and greater than $\frac{-1 + \sqrt{2}}{2}$, it follows that
$$\frac{1}{4} < f(x_1) < f(x_2)$$
but $f(x_3) < \frac{1}{4}$, and $x_3 \in (x_1,x_2)$, so $f$ is not monotone on $[0,M)$.
Considering the case when $M \leq \frac{-1 + \sqrt{2}}{2}$ is what is giving me trouble. I understand intuitively that the function "bounces" back and forth between the two parabola's, and $x+x^2 \geq x - x^2$ on $[0,M)$, so clearly it can't be monotone, but I can't seem to prove it formally.
What am I missing here? Do I even need to consider $M$'s case-by-case?
Let $a\in[0,M)\cap\mathbb{Q}$, we can do this because the rationals are dense in $\mathbb{R}$.
Choose $\epsilon$ such that $a^2+b^2>\epsilon>0$ for all $b>a$, i.e. take $0<\epsilon < \inf\limits_{b>a}a^2+b^2$.
Then, choose $b\in[a,a+\epsilon)\cap(\mathbb{R}\backslash\mathbb{Q})\cap[0,M)$, we can do this because the irrationals are dense in $\mathbb{R}$. Then we have $a<b$ but
\begin{align} f(a)-f(b) &= a+a^2-b+b^2\\ &> b-\epsilon+a^2-b+b^2\quad\quad\quad b\in[a,a+\epsilon)\\ &=-\epsilon + a^2 + b^2 \\ &> 0\quad\quad\quad\quad\quad\quad\quad\quad\quad\quad\ \ \epsilon<a^2+b^2\\ \implies f(a)&>f(b) \end{align}
So $f$ is not monotone.