[Math] Intuitive explanation of the Dirichlet function and rationality

functionsirrational-numbersrational numbers

The Dirichlet function is defined by $f(x)=\begin{cases} c &\text{ if } x\in \mathbb{Q}\\d &\text{ if } x\notin \mathbb{Q}.\end{cases}, c\neq d$

See MathWorld's page for the full definition.

One of the properties of the Dirichlet function is that it is discontinuous everywhere, which means that its graph would look like this:
enter image description here

If I understand correctly, then it would imply the following:

If $x$ is rational, then $\lim_{h\to0} x+h$ would be irrational. And conversely, if $x$ is irrational, then $\lim_{h\to0} x+h$ would be rational.

I'm having an extremely hard time grasping this concept.

For example, if $x$ cannot be written as $\frac{a}{b}$, then why can $\lim_{h\to0} x+h$ be written as $\frac{a}{b}$ ?

If someone could intuitively explain this, then it would be much appreciated.
Also, if I do not understand the Dirichlet function correctly, then please also explain why.

EDIT
Another example:
If there are two rational numbers arbitrarily close together, wouldn't there be another rational number in between them? And if so, wouldn't it make the Dirichlet function continuous at that point?

Best Answer

$\mathbb{Q}$ is dense in $\mathbb{R}$, which means in this case that:

$$ \forall x,y \in \mathbb{R} \hspace{2mm} \text{with} \hspace{2mm} x < y \hspace{2mm} \exists r \in \mathbb{Q}: x < r < y $$

So, for two real (particularly irrational) numbers, there is always a rational number in between, no matter how close the two reals are to each other. So the Dirichlet function jumps from $c$ to $d$ and vice versa for every (arbitrarily small) iteration of $x$.

Here you can see a plot for $c=1$ and $d=0$: German Wikipedia

EDIT: Changes made, thanks to comment of LJL.