What number follows immediately after a rational number? I recently came across a confusing question on limits and was having trouble solving it.
$$f(x) =
\begin{cases}
x^2  & \text{if $x$ is rational} \\[1ex]
0 & \text{if $x$ is irrational}
\end{cases}$$
What would be the limit of this function as it approaches any Rational number?

Let's see what happens when $x$ approaches any real number $a$.
We will see that the function has no limit because we cannot satisfy the definition of a limit
(unless $a = 0$ of course, there we have a limit).
That's because both rationals and irrationals are dense in the set of the real numbers $\mathbb{R}$.
What does that mean? If you take any real number $r$ you can get as close as you wish to it by "stepping" only on rational numbers. That's what it means that rationals are dense in $\mathbb{R}$.
The same applies for irrationals.
So now... you take any number $a \ne 0$. Let's assume that $f$ has a limit (when $x$ goes to $a$), and that limit is $L$. Take any $\epsilon \gt 0$. No matter what $\delta \gt 0$ you choose in $(a-\delta, a+\delta)$ you will always find both rational and irrational numbers. So you cannot satisfy the inequality
$$|f(x) - L| \lt \epsilon$$ for every $x \in (a-\delta, a+\delta)$
Why? Well, for irrationals this inequality will be equivalent to $$|L| < \epsilon$$ which would imply $L=0$ (because we can pick $\epsilon$ to be arbitrary small). So from here you can conclude that if you the function has a limit (as $x$ goes to $a$) that limit must be zero.
But on the other hand for rational values of $x$, the function approaches $a^2 \ne 0$. So... the two "limits" don't coincide.
Which two "limits" do I mean here?

*

*the limit when $x$ approaches $a$ with rational values

*the limit when $x$ approaches $a$ with irrational values

Try to visualize this in your head. Think e.g. of rationals as blue and irrationals as red points on the real axis. You are walking on these points and you're heading towards the point $a$. Both the red and blue points get closer and closer to $a$ (as close as we want... because of rationals and irrationals being dense in $\mathbb{R}$).
But when you (i.e. the variable $x$) approach $a$ while only stepping on blue points the function approaches $a^2$, while if you approach $a$ only stepping on red points the function approaches $0$.
In a way... visually this is similar to left and right limit. It's just that here we approach the point $a$ not from left and right, but by stepping only on blue/red points.
