Maths WorkshopMaths problems with full solutions
Exercise 2080Calculus › Single-variable calculus › Continuity › Continuous and discontinuous functionsL2Added 2 Nov 2026

The popcorn function

#continuity#rationals#density#pathological functions

Statement

Define f:R→Rf:\mathbb{R}\to\mathbb{R} by f(x)=0f(x)=0 if xx is irrational, f(0)=1f(0)=1, and f ⁣(pq)=1qf\!\left(\dfrac pq\right)=\dfrac1q if pq\frac pq is a non-zero rational written in lowest terms with q≥1q\ge1. Prove that ff is continuous at every irrational number and discontinuous at every rational number.

Hint

At an irrational aa and for a given ε\varepsilon, only finitely many rationals near aa have denominator at most 1ε\frac1\varepsilon. Shrink the neighbourhood to avoid all of them.

Show solutionHide solution

Solution

Rational points. Let a=pqa=\frac pq be rational. Then f(a)=1q>0f(a)=\frac1q>0. Every neighbourhood of aa contains irrational numbers, where f=0f=0, so ff cannot tend to f(a)>0f(a)>0. Hence ff is discontinuous at aa.

Irrational points. Let aa be irrational and ε>0\varepsilon>0. Choose an integer N>1εN>\frac1\varepsilon.

*Finitely many bad rationals.* Consider the rationals in [a−1,a+1][a-1,a+1] whose denominator (in lowest terms) is at most NN. For each fixed denominator q≤Nq\le N there are only finitely many such fractions pq\frac pq in a bounded interval, so the set BB of all of them is finite. Since aa is irrational, a∉Ba\notin B, so
δ=min⁡(1, min⁡b∈B∣a−b∣)>0.\delta=\min\Bigl(1,\ \min_{b\in B}|a-b|\Bigr)>0.

*Checking.* Let ∣x−a∣<δ|x-a|<\delta. If xx is irrational, f(x)=0f(x)=0. If x=pqx=\frac pq is rational, then x∉Bx\notin B, so q>Nq>N and f(x)=1q<1N<εf(x)=\frac1q<\frac1N<\varepsilon. In both cases ∣f(x)−f(a)∣=f(x)<ε|f(x)-f(a)|=f(x)<\varepsilon.

Conclusion. ff is continuous exactly at the irrational numbers.

Remark. A function can be continuous at infinitely many points and discontinuous at infinitely many others, with both sets dense. The graph looks like popcorn: tall kernels 12,13,…\frac12,\frac13,\dots above each rational, flattening toward 00. The reverse is impossible: there is no function continuous exactly at the rationals.