Q:

Proving that a Dirichlet type function doesn't have IVP

Let $f:\mathbb{R}\to \mathbb{R}$, $f(x)=\begin{cases}x,& x\in\mathbb Q \\ x^2&x\in\mathbb R\setminus\mathbb Q\end{cases}$. Prove that $f$ doesn't have the intermediate value property.      
I know that there exists a general result for this, but I want to prove this particular one doesn't have IVP by using its particularities (i.e. not going for the more complicated proof of the general statement).      
Let us note that $f([2,3]\cap \mathbb{Q})\subset [2,3]$ and $f([2,3]\cap \mathbb R\setminus\mathbb Q)\subset [4,9]$. As a result, $f([2,3])\subset [2,3] \cup  [4,9]$, so $f$ doesn't map $[2,3]$ to another interval, hence it doesn't have IVP.     
I think that this is correct, but I haven't seen a proof like this anywhere for this type of questions. All the solutions I have seen to such problems use the basic definition of the IVP, not the equivalent one that a function which has the IVP maps any interval included in its domain to another interval. So, I would like to see your feedback on this solution.

A:

The IVP property for $f$ and interval $[2,3]$ would mean that For all real numbers $y$ between $f(2)=2$ and $f(3)=3$, there exists $x\in[2,3]$ with $f(x)=y$. However, this is not the case for $y=\sqrt 5$: Assume $f(x)=\sqrt 5$. Then $x\notin\Bbb Q$ as that would imply $\sqrt 5=f(x)=x\in\Bbb Q$. But if $x\notin \Bbb Q$, then $x\ge 2$  implies $f(x)=x^2\ge 4>\sqrt 5$.
The observation that $f([2,3])\subseteq [2,3]\cup[4,9]$ by itself does not show the failure of IVP, though only a tiny detail is missing: That $f([2,3])$ actually contains values from both $[2,3]$ and $[4,9]$, e.g. $f(2)=2\in[2,3]$ and $f(2\sqrt 2)=8\in[4,9]$.

