Thomae's function
Function that is discontinuous at rationals and continuous at irrationals

Thomae's function is a real-valued function of a real variable that can be defined as:
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) and
, the function is well-defined. Note that
is the only number in
that is coprime to
It is a modification of the Dirichlet function, which is 1 at rational numbers and 0 elsewhere.
01Properties
- Thomae's function
is bounded and maps all real numbers to the unit interval:
is periodic with period
for all integers n and all real x.
Proof of periodicity For all
we also have
and hence
For all
there exist
and
such that
and
Consider
. If
divides
and
, it divides
and
. Conversely, if
divides
and
, it divides
and
. So
, and
.
is discontinuous at every rational number, so its points of discontinuity are dense within the real numbers.
Proof of discontinuity at rational numbers Let
be an arbitrary rational number, with
and
and
coprime.
This establishes
Let
be any irrational number and define
for all
These
are all irrational, and so
for all
This implies
and
Let
, and given
let
For the corresponding
we have
and
which is exactly the definition of discontinuity of
at
.
is continuous at every irrational number, so its points of continuity are dense within the real numbers.
Proof of continuity at irrational arguments Since
is periodic with period
and
it suffices to check all irrational points in
Assume now
and
According to the Archimedean property of the reals, there exists
with
and there exist
such that
for
we have
The minimal distance of
to its i-th lower and upper bounds equals
We define
as the minimum of all the finitely many
so that for all
and
This is to say, all these rational numbers
are outside the
-neighborhood of
Now let
with the unique representation
where
are coprime. Then, necessarily,
and therefore,
Likewise, for all irrational
and thus, if
then any choice of (sufficiently small)
gives
Therefore,
is continuous on
is nowhere differentiable.
Proof of being nowhere differentiable - For rational numbers, this follows from non-continuity.
- For irrational numbers:
- For any sequence of irrational numbers
with
for all
that converges to the irrational point
, the sequence
is identically
, and so
.
- On the other hand, consider the sequence of rational numbers
with
, where
denotes the floor of
. Since
, the sequence
converges to
using the Squeeze theorem. Also,
for all
.
- Thus for all
,
. Therefore we obtain
and so
is not differentiable at any irrational number
.
- For any sequence of irrational numbers
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, wherehas maxima.
is Riemann integrable on any interval and the integral evaluates to
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 toover any set because the function is equal to zero almost everywhere.
- If
is the graph of the restriction of
to
, then the box-counting dimension of
is
.
03The ruler function
For integers, the exponent of the highest power of 2 dividing gives 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, ... (sequence A007814 in the OEIS). 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, ... (sequence A001511 in the OEIS). 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.
Sources and credits
This article is adapted from the Wikipedia article “Thomae's function”, written by its contributors and licensed under CC BY-SA 4.0. Fathomly has changed the layout, removed citation markers, navigation and maintenance notices, and adjusted punctuation. This adapted version is shared under the same license. For references, see the original article.
Images, from Wikimedia Commons:
- Thomae function (0,1).svg by Smithers888, Public domain
Fathomly is not affiliated with or endorsed by the Wikimedia Foundation. Spotted a problem? Tell us.