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.



Is there a real valued function whose limit exists only on irrational numbers?
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.


