Thomae's function, named after Carl Johannes Thomae, has many names: the popcorn function, the raindrop function, the countable cloud function, the modified Dirichlet function, the ruler function, the Riemann function, or the Stars over Babylon (John Horton Conway's name). This real-valued function f(x) of the real variable x is defined as:
It is a modification of the Dirichlet function, which is 1 at rational numbers and 0 elsewhere.
The popcorn function has a complicated set of discontinuities: f is continuous at all irrational numbers and discontinuous at all rational numbers.
The popcorn function also has a strict local maximum at each rational number.
Informal proof of discontinuities
Clearly, f is discontinuous at all rational numbers: since the irrationals are dense in the reals, for any rational x, no matter what ε we select, there is an irrational a even nearer to our x where f(a) = 0 (while f(x) is positive). In other words, f can never "get close" and "stay close" to any positive number because its domain is dense with zeroes.
To show continuity at the irrationals, assume without loss of generality that our ε is rational (for any irrational ε′, we can choose a smaller rational ε″ and the proof is transitive). Since ε is rational, it can be expressed in lowest terms as a/b. We want to show that f(x) is continuous when x is irrational.
Note that f takes a maximum value of 1 at each whole integer, so we may limit our examination to the space between and . Since ε has a finite denominator of b, the only values for which f may return a value greater than ε are those with a reduced denominator no larger than b. There exist only a finite number of values between two integers with denominator no larger than b, so these can be exhaustively listed. Setting δ to be smaller than the nearest distance from x to one of these values guarantees every value within δ of x has f(x) < ε.
The Lebesgue criterion for integrability states that a bounded function is Riemann integrable if and only if the set of all discontinuities has measure zero. Since the set of all discontinuities is the rational numbers, and the rational numbers are countable, the set has measure zero. As well, the function is bounded on the interval [0, 1], so by the Lebesgue criterion, the function is Riemann integrable on [0, 1]. Its integral is equal to 0 over [0,1].
A natural follow-up question one might ask is if there is a function which is continuous on the rational numbers and discontinuous on the irrational numbers. This turns out to be impossible; the set of discontinuities of any function must be an Fσ set. If such a function existed, then the irrationals would be an Fσ set and hence, as they don't contain an interval, would also be a meager set. It would follow that the real numbers, being a union of the irrationals and the rationals (which is evidently meager), would also be a meager set. This would contradict the Baire category theorem.
Related probability distributions
Empirical probability distributions related to Thomae's function appear in DNA sequencing. The human genome is diploid, having two strands per chromosome. When sequenced, small pieces ("reads") are generated: for each spot on the genome, an integer number of reads overlap with it. Their ratio is a rational number, and typically distributed similar to Thomae's function.
If pairs of positive integers are sampled from a distribution and used to generate ratios , this gives rise to a distribution on the rational numbers. If the integers are independent the distribution can be viewed as a convolution over the rational numbers, . Closed form solutions exist for power-law distributions with a cut-off. If (where is the polylogarithm function) then . In the case of uniform distributions on the set , which is very similar to Thomae's function. Both their graphs have fractal dimension 3/2.
- Euclid's orchard – Thomae's function can be interpreted as a perspective drawing of Euclid's orchard
- "…the so-called ruler function, a simple but provocative example that appeared in a work of Johannes Karl Thomae … The graph suggests the vertical markings on a ruler—hence the name." William Dunham, The Calculus Gallery, chapter 10
- Spivak, M. (p. 53, Theorem 3-8)
- Vladimir Trifonov, Laura Pasqualucci, Riccardo Dalla-Favera & Raul Rabadan. Fractal-like Distributions over the Rational Numbers in High-throughput Biological and Clinical Data. Scientific Reports 1:191 DOI: 10.1038/srep00191
- Robert G. Bartle and Donald R. Sherbert (1999), Introduction to Real Analysis, 3rd Edition (Example 5.1.6 (h)). Wiley. ISBN 978-0-471-32148-4
- Spivak, M. Calculus on manifolds. 1965. Perseus Books. ISBN 0-8053-9021-9
- Abbot, Stephen. Understanding Analysis. Berlin: Springer, 2001. ISBN 0-387-95060-5