Thomae's Function

This scene shows Thomae's function, a popcorn of dots. Dots jump up at rationals and stick to the floor at irrationals.

Tall dots are rare. Fix any height: only finitely many dots reach it. So near an irrational you can choose a window avoiding tall dots. That is why it is continuous at irrationals only.

For example, picture a jar of 🍬 candies. Only a few are big, and you can count them. A corner with only tiny candies is nearly flat. Neighborhoods of irrationals look like that: no big jumps, so the function stays quiet.

f(x)={1/qx=p/q in lowest terms0x∉Qf(x) = \begin{cases} 1/q & x = p/q \text{ in lowest terms} \\ 0 & x \notin \mathbb{Q} \end{cases}
{x:f(x)≥ε}={p/q:q≤1/ε} finite\{x : f(x) \ge \varepsilon\} = \{p/q : q \le 1/\varepsilon\} \text{ finite}

Examples & Exercises

Prove completely that Thomae's function ff (f(p/q)=1/qf(p/q) = 1/q in lowest terms, f=0f = 0 at irrationals) is discontinuous at every rational x0x_0.

x0=pq (lowest terms)⇒f(x0)=1q>0,ε=12qx_0 = \frac{p}{q}\ \text{(lowest terms)} \Rightarrow f(x_0) = \frac{1}{q} > 0, \quad \varepsilon = \frac{1}{2q}
View centered at the rational x0=1/2x_0 = 1/2: f(1/2)=1/2f(1/2) = 1/2, yet irrationals with f=0f = 0 sit arbitrarily close, so no δ\delta works for ε=1/4\varepsilon = 1/4.
Show proof
  1. Write x0=p/qx_0 = p/q in lowest terms, so f(x0)=1/q>0f(x_0) = 1/q > 0. Set ε=1/(2q)>0\varepsilon = 1/(2q) > 0.

    By density of the irrationals, for every δ>0\delta > 0 the interval (x0−δ,x0+δ)(x_0 - \delta, x_0 + \delta) contains an irrational xx.

  2. At an irrational xx, f(x)=0f(x) = 0, so ∣f(x)−f(x0)∣=1/q>1/(2q)=ε|f(x) - f(x_0)| = 1/q > 1/(2q) = \varepsilon. That is, for every δ>0\delta > 0 there is an xx with ∣x−x0∣<δ|x - x_0| < \delta but ∣f(x)−f(x0)∣≥ε|f(x) - f(x_0)| \ge \varepsilon; by the ε\varepsilon-δ\delta definition, ff is not continuous at x0x_0.

  3. Since x0x_0 was an arbitrary rational, Thomae's function is discontinuous at every rational. In the scene, centering on a rational (e.g. 1/21/2) gives δ=0\delta = 0, exhibiting this argument directly.

Prove completely, by an ε\varepsilon-δ\delta argument, that Thomae's function is continuous at every irrational x0x_0.

Sε={x∈[0,1]:f(x)≥ε}={pq:q≤1ε} finiteS_\varepsilon = \left\{x \in [0,1] : f(x) \ge \varepsilon\right\} = \left\{\frac{p}{q} : q \le \frac{1}{\varepsilon}\right\}\ \text{finite}
View centered at the irrational x0≈0.618x_0 \approx 0.618: only finitely many dots (those with q≤10q \le 10) reach height ε=0.1\varepsilon = 0.1, and δ\delta is the distance to the nearest one.
Show proof
  1. Let x0x_0 be irrational and ε>0\varepsilon > 0 arbitrary. Consider Sε={x∈[0,1]:f(x)≥ε}S_\varepsilon = \{x \in [0,1] : f(x) \ge \varepsilon\}.

    By the definition of ff, members of SεS_\varepsilon are only lowest-terms fractions p/qp/q with 1/q≥ε1/q \ge \varepsilon, i.e. q≤1/εq \le 1/\varepsilon; hence SεS_\varepsilon is a finite set.

  2. Degenerate case: if Sε=∅S_\varepsilon = \varnothing (this happens when ε>1\varepsilon > 1, since f(x)≤1<εf(x) \le 1 < \varepsilon for every xx), any δ>0\delta > 0 works (e.g. δ=1\delta = 1). Assume henceforth Sε≠∅S_\varepsilon \ne \varnothing. Since x0x_0 is irrational, x0∉Sεx_0 \notin S_\varepsilon.

    Thus δ=min⁡x∈Sε∣x−x0∣\delta = \min_{x \in S_\varepsilon} |x - x_0|, the minimum of finitely many positive numbers, is strictly positive. Argue by contrapositive: if x∈Sεx \in S_\varepsilon then ∣x−x0∣≥δ|x - x_0| \ge \delta by definition of the minimum. Hence ∣x−x0∣<δ|x - x_0| < \delta implies x∉Sεx \notin S_\varepsilon — i.e. f(x)<εf(x) < \varepsilon (for x=x0x = x_0 this is trivial since f(x0)=0<εf(x_0) = 0 < \varepsilon).

  3. Since ∣f(x)−f(x0)∣=∣f(x)−0∣=f(x)<ε|f(x) - f(x_0)| = |f(x) - 0| = f(x) < \varepsilon, ff is continuous at x0x_0. As x0x_0 was an arbitrary irrational, Thomae's function is continuous at every irrational — the δ\delta shown in the scene is exactly this minimum.

On [0,1][0,1], show that Thomae's function is a pointwise limit of continuous functions — i.e. prove completely that it is of Baire class 1.

fn(x)=max⁡p/q∈[0,1] lowest terms, q≤nmax⁡(0,1q−n∣x−pq∣)→f(x) ∀x∈[0,1]f_n(x) = \max_{\substack{p/q \in [0,1]\ \text{lowest terms},\ q \le n}} \max\left(0, \frac{1}{q} - n\left|x - \frac{p}{q}\right|\right) \to f(x)\ \forall x \in [0,1]
Q=30Q = 30, ε=0.05\varepsilon = 0.05: a pointwise limit of continuous tent functions draws these popcorn dots — a Baire-1 function must have a dense set of continuity points, and Thomae's is the irrationals (a dense GδG_\delta).
Show proof
  1. Restrict the domain to [0,1][0,1] (without this restriction the finiteness below fails). For each n≥1n \ge 1 let Sn={p/q∈[0,1]:1≤q≤n, gcd⁡(p,q)=1}S_n = \{p/q \in [0,1] : 1 \le q \le n,\ \gcd(p,q) = 1\}. This is a finite set: there are only finitely many pairs (p,q)(p, q) with 0≤p≤q≤n0 \le p \le q \le n.

    Define fn(x)=max⁡r∈Snmax⁡(0,1/q(r)−n∣x−r∣)f_n(x) = \max_{r \in S_n} \max(0, 1/q(r) - n|x - r|) on [0,1][0,1], where q(r)q(r) is the denominator of r=p/qr = p/q. Each tent x↦max⁡(0,1/q−n∣x−r∣)x \mapsto \max(0, 1/q - n|x - r|) is continuous, and a finite maximum of continuous functions is continuous, so each fnf_n is continuous.

  2. Let x=a/b∈[0,1]x = a/b \in [0,1] in lowest terms. For n≥bn \ge b, the tent at r=x∈Snr = x \in S_n itself gives the value 1/b1/b, while for any other r′=p/q∈Snr' = p/q \in S_n with r′≠xr' \ne x and q≤nq \le n we have ∣x−r′∣≥1/(bq)|x - r'| \ge 1/(bq) (distinct rationals with denominators b,qb, q differ by at least 1/(bq)1/(bq)), so n∣x−r′∣≥n/(bq)≥1/qn|x - r'| \ge n/(bq) \ge 1/q — the tent value is 0. Hence fn(x)=1/b=f(x)f_n(x) = 1/b = f(x) for n≥bn \ge b.

  3. If x∈[0,1]x \in [0,1] is irrational, f(x)=0f(x) = 0. Fix M≥1M \ge 1: tents with denominator q≤Mq \le M all vanish for large nn (there are only finitely many rationals in [0,1][0,1] with denominator ≤M\le M, each at positive distance from the irrational xx), and tents with q>Mq > M are worth at most 1/q<1/M1/q < 1/M.

    Hence lim sup⁡n→∞fn(x)≤1/M\limsup_{n \to \infty} f_n(x) \le 1/M; since MM is arbitrary, fn(x)→0=f(x)f_n(x) \to 0 = f(x). So fn→ff_n \to f at every x∈[0,1]x \in [0,1]: Thomae's function is Baire class 1 on [0,1][0,1].

4. Continuity