TITLE: Is there a real valued function whose limit exists only on irrational numbers?
QUESTION [8 upvotes]: I have been trying to find a function $f : \mathbb R \to \mathbb R$  such that $\lim_{x \to c} f(x)$ exists when $c$ is irrational and the limit doesn't exist when $c$ is rational.
I tried variations of the Dirichlet function and Thomae's function, but I couldn't get anywhere.
I also tried proving that such a function cannot exist, using the fact that both the rationals and the irrationals are dense in real numbers. But I couldn't get a satisfying proof that way either.

REPLY [9 votes]: Arrange rationals in a sequence $q_n$, and set
$$f(x) = \sum_{n = 1}^\infty 2^{-n} \mathbb{1}_{[q_n,\infty)}(x),$$
where
$$\mathbb{1}_{[q_n,\infty)}(x) = \begin{cases} 1 & \text{if $x \geqslant q_n$,} \\ 0 & \text{if $x < q_n$.} \end{cases} $$
In other words,
$$f(x) = \sum_{n : q_n \leqslant x} 2^{-n} .$$
By the dominated convergence theorem, we have
$$\lim_{x \to a^-} f(x) = \sum_{n : q_n < a} 2^{-n}$$
and
$$\lim_{x \to a^+} f(x) = \sum_{n : q_n \leqslant a} 2^{-n} = f(a) .$$
It follows that
$$\lim_{x \to q_n^+} f(x) = 2^{-n} + \lim_{x \to q_n^-} f(x)$$
and hence $f$ has no limit at each $q_n$, but $f$ is continuous at every irrational point.