Thomae's function
(0,1). The topmost point in the middle shows f(1/2) = 1/2. Thomae's function is a real-valued function of a real variable that can be defined as: f(x) = \begin{cases} \frac{1}{q} &\text{if }x = \tfrac{p}{q}\quad (x \text{ is rational), with } p \in \mathbb Z \text{ and } q \in \mathbb N \text{ coprime}\\ 0 &\text{if }x \text{ is irrational.} \end{cases} It is named after Carl Johannes Thomae, but has many other names: the popcorn function, the raindrop function, the countable cloud function, the modified Dirichlet function, the ruler function (not to be confused with the integer ruler function), the Riemann function, or the Stars over Babylon (John Horton Conway's name). Thomae mentioned it as an example for an integrable function with infinitely many discontinuities in an early textbook on Riemann's notion of integration. Since every rational number has a unique representation with coprime (also termed relatively prime) p \in \mathbb Z and q \in \mathbb N , the function is well-defined. Note that q = +1 is the only number in \mathbb N that is coprime to p = 0. It is a modification of the Dirichlet function, which is 1 at rational numbers and 0 elsewhere.
(0,1). The topmost point in the middle shows f(1/2) = 1/2. Thomae's function is a real-valued function of a real variable that can be defined as: f(x) = \begin{cases} \frac{1}{q} &\text{if }x = \tfrac{p}{q}\quad (x \text{ is rational), with } p \in \mathbb Z \text{ and } q \in \mathbb N \text{ coprime}\\ 0 &\text{if }x \text{ is irrational.} \end{cases} It is named after Carl Johannes Thomae, but has many other names: the popcorn function, the raindrop function, the countable cloud function, the modified Dirichlet function, the ruler function (not to be confused with the integer ruler function), the Riemann function, or the Stars over Babylon (John Horton Conway's name). Thomae mentioned it as an example for an integrable function with infinitely many discontinuities in an early textbook on Riemann's notion of integration. Since every rational number has a unique representation with coprime (also termed relatively prime) p \in \mathbb Z and q \in \mathbb N , the function is well-defined. Note that q = +1 is the only number in \mathbb N that is coprime to p = 0. It is a modification of the Dirichlet function, which is 1 at rational numbers and 0 elsewhere. ==Properties== {{unordered list |Thomae's function f is bounded and maps all real numbers to the unit interval: f : \mathbb R \to [0, 1]. | f is periodic with period 1:\; f(x + n) = f(x) for all integers and all real . For all x \in \mathbb R \setminus \mathbb Q, we also have x+n \in \mathbb R \setminus \mathbb Q and hence f(x+n) = f(x)= 0, For all x \in \mathbb Q,\; there exist p \in \mathbb Z and q \in \mathbb N such that \;x = p/q,\; and \gcd(p,\;q) = 1. Consider x + n = (p + nq) / q . If d divides p and q , it divides p + nq and q . Conversely, if d divides p + nq and q , it divides (p + nq) - nq = p and q . So \gcd(p + nq, q) = \gcd(p, q) = 1 , and f(x + n) = 1/q = f(x) . | f is discontinuous at every rational number, so its points of discontinuity are dense within the real numbers. Let x_0 = p/q be an arbitrary rational number, with \;p \in \mathbb Z,\; q \in \mathbb N, and p and q coprime. This establishes f(x_0) = 1/q. Let \;\alpha \in \mathbb R \setminus \mathbb Q\; be any irrational number and define x_n = x_0 + \frac{\alpha}{n} for all n \in \mathbb N. These x_n are all irrational, and so f(x_n) = 0 for all n \in \mathbb N. This implies |x_0 - x_n| = \frac{\alpha}{n}, and |f(x_0) - f(x_n)| = \frac{1}{q}. Let \;\varepsilon = 1/q\; , and given \delta > 0 let n = 1 + \left\lceil\frac{\alpha}{\delta }\right\rceil. For the corresponding \;x_n we have |f(x_0) - f(x_n)|= 1/q \ge \varepsilon and |x_0 - x_n| = \frac{\alpha}{n} = \frac{\alpha}{1 + \left\lceil\frac{\alpha}{\delta}\right\rceil} which is exactly the definition of discontinuity of f at x_0 . | f is continuous at every irrational number, so its points of continuity are dense within the real numbers. Since f is periodic with period 1 and 0 \in \Q, it suffices to check all irrational points in I=(0,1).\; Assume now \varepsilon > 0,\; i \in \N and x_0 \in I \setminus \Q. According to the Archimedean property of the reals, there exists r \in \N with 1/r and there exist \; k_i \in \N, such that for i = 1, \ldots, r we have 0 \le \frac{k_i}{i} The minimal distance of x_0 to its i-th lower and upper bounds equals d_i := \min\left\{\left|x_0 - \frac{k_i}{i}\right|,\; \left|x_0 - \frac{k_i + 1}{i}\right| \right\}. We define \delta as the minimum of all the finitely many d_i. \delta := \min_{1\le i\le r}\{d_i\},\; so that for all i = 1, \dots, r, |x_0 - k_i/i| \ge \delta and |x_0 - (k_i+1)/i| \ge \delta. This is to say, all these rational numbers k_i/i,\;(k_i + 1)/i,\; are outside the Now let x \in \mathbb{Q} \cap (x_0 - \delta, x_0 + \delta) with the unique representation x = p/q where p, q \in \mathbb N are coprime. Then, necessarily, q > r,\; and therefore, f(x)=1/q Likewise, for all irrational x \in I, \; f(x) = 0 = f(x_0),\; and thus, if \varepsilon > 0 then any choice of (sufficiently small) \delta > 0 gives |x - x_0| Therefore, f is continuous on \mathbb R \setminus \mathbb Q. | f is nowhere differentiable. For rational numbers, this follows from non-continuity. For irrational numbers: For any sequence of irrational numbers (a_n)_{n=1}^\infty with a_n \ne x_0 for all n \in \mathbb{N}_{+} that converges to the irrational point x_0 , the sequence (f(a_n))_{n=1}^\infty is identically 0 , and so \lim_{n \to \infty}\left|\frac{f(a_n)-f(x_0)}{a_n - x_0}\right| = 0 . On the other hand, consider the sequence of rational numbers (b_n)_{n=1}^{\infty} with b_n = \lfloor nx_0\rfloor/n , where \lfloor nx_0\rfloor denotes the floor of nx_0 . Since nx_0-1 , the sequence (b_n)_{n=1}^{\infty} converges to x_0 using the Squeeze theorem. Also, |b_n-x_0| = |\lfloor nx_0\rfloor/n - x_0| = |\lfloor nx_0\rfloor - nx_0|/n \le 1/n for all n . Thus for all n , \left| \frac{f(b_n)-f(x_0)}{b_n-x_0} \right| \ge \frac{1/n - 0}{1/n} = 1 . Therefore we obtain \liminf_{n\to\infty} \left| \frac{f(b_n)-f(x_0)}{b_n-x_0} \right| \ge 1 \ne 0 and so at any irrational number x_0 . | f has a proper local maximum at each rational number, providing an example of a function with a dense set of proper local maxima. See the proofs for continuity and discontinuity above for the construction of appropriate neighbourhoods, maxima. | f is Riemann integrable on any interval and the integral evaluates to 0 over any set. 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. Every countable subset of the real numbers - such as the rational numbers - has measure zero, so the above discussion shows that Thomae's function is Riemann integrable on any interval. The function's integral is equal to 0 over any set because the function is equal to zero almost everywhere. |If G = \{ \, (x,f(x)) : x \in (0,1) \, \} \subset \mathbb{R}^2 is the graph of the restriction of f to (0,1) , then the box-counting dimension of G is 4/3 . }} ==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 similarly to Thomae's function. If pairs of positive integers m, n are sampled from a distribution f(n,m) and used to generate ratios q=n/(n+m) , this gives rise to a distribution g(q) on the rational numbers. If the integers are independent the distribution can be viewed as a convolution over the rational numbers, g(a/(a+b)) = \sum_{t=1}^\infty f(ta)f(tb) . Closed form solutions exist for power-law distributions with a cut-off. If f(k) =k^{-\alpha} e^{-\beta k}/\mathrm{Li}_\alpha(e^{-\beta}) (where \mathrm{Li}_\alpha is the polylogarithm function) then g(a/(a+b)) = (ab)^{-\alpha} \mathrm{Li}_{2\alpha}(e^{-(a+b)\beta})/\mathrm{Li}^2_{\alpha}(e^{-\beta}) . In the case of uniform distributions on the set \{1,2,\ldots , L\} g(a/(a+b)) = (1/L^2) \lfloor L/\max(a,b) \rfloor , which is very similar to Thomae's function. ==The ruler function== For integers, the exponent of the highest power of 2 dividing n gives 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, ... . If 1 is added, or if the 0s are removed, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1, ... . The values resemble tick-marks on a 1/16th graduated ruler, hence the name. These values correspond to the restriction of the Thomae function to the dyadic rationals: those rational numbers whose denominators are powers of 2. ==Related functions== 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 set. If such a function existed, then the irrationals would be an set. The irrationals would then be the countable union of closed sets \bigcup_{i = 0}^\infty C_i , but since the irrationals do not contain an interval, neither can any of the C_i . Therefore, each of the C_i would be nowhere dense, and the irrationals would be a meager set. It would follow that the real numbers, being the union of the irrationals and the rationals (which, as a countable set, is evidently meager), would also be a meager set. This would contradict the Baire category theorem: because the reals form a complete metric space, they form a Baire space, which cannot be meager in itself. A variant of Thomae's function can be used to show that any subset of the real numbers can be the set of discontinuities of a function. If A = \bigcup_{n=1}^{\infty} F_n is a countable union of closed sets F_n , define f_A(x) = \begin{cases} \frac{1}{n} & \text{if } x \text{ is rational and } n \text{ is minimal so that } x \in F_n\\ -\frac{1}{n} & \text{if } x \text{ is irrational and } n \text{ is minimal so that } x \in F_n\\ 0 & \text{if } x \notin A \end{cases} Then a similar argument as for Thomae's function shows that f_A has A as its set of discontinuities. ==See also== Blumberg theorem Cantor function Dirichlet function Euclid's orchard – Thomae's function can be interpreted as a perspective drawing of Euclid's orchard Volterra's function ==References== ==Further reading== (Example 5.1.6 (h)) ==External links==
References
No reference rows published for this article.
Cite this article
MLA
"Thomae's function." encyclopegia.org, 2026, https://encyclopegia.org/wiki/thomae-s-function. Accessed 24 November 2026.
Chicago
"Thomae's function." encyclopegia.org. Accessed November 24, 2026. https://encyclopegia.org/wiki/thomae-s-function.
APA
encyclopegia.org. (2026). Thomae's function. Retrieved November 24, 2026, from https://encyclopegia.org/wiki/thomae-s-function
Accessed November 24, 2026 · CC BY-SA 4.0 · citation page · JSON