algebrica-org-pages/dirichlet-function.md

# Dirichlet Function

Source: algebrica.org - CC BY-NC 4.0
https://algebrica.org/dirichlet-function/
Fetched from algebrica.org post 25215; source modified 2026-03-20T18:18:50.

Concept

The structure of the entry is shown in the conceptual map, where each branch represents a core component and the sub-nodes highlight the specific notions discussed.

Advanced

4

Requires

0

Enables

The following concepts, [Discontinuities of Real Functions](../discontinuities-of-real-functions.md), [Functions](../functions.md), [Limits](../limits.md), [Riemann Integrability Criteria](../riemann-integrability-criteria.md), are required as prerequisites for this entry.

## Definition

The Dirichlet function is defined on \\(\\mathbb{R}\\) by the following rule:

\\[
D(x) = \\begin{cases} 1 & \\text{if } x \\in \\mathbb{Q} \\[6pt] 0 & \\text{if } x \\in \\mathbb{R} \\setminus \\mathbb{Q} \\end{cases}
\\]

At first glance this appears to be an almost trivial definition, a simple distinction between rationals and irrationals. Yet precisely this simplicity conceals an extremely irregular analytic behaviour, which has made this function a key reference object in [integration](../definite-integrals.md) theory and real analysis.

* * *

A notable property of \\(D\\) is its [discontinuity](../discontinuities-of-real-functions.md) at every point of \\(\\mathbb{R}\\). This result follows from the mutual density of \\(\\mathbb{Q}\\) and \\(\\mathbb{R} \\setminus \\mathbb{Q}\\) in the real line.

For any fixed point \\(x\_0 \\in \\mathbb{R}\\) and any \\(\\varepsilon > 0\\), the [interval](../intervals.md) \\((x\_0 - \\varepsilon, x\_0 + \\varepsilon)\\) contains both rational and irrational numbers. Therefore, there is no neighborhood of \\(x\_0\\) on which \\(D\\) is constant, and any sequence converging to \\(x\_0\\) can be constructed so that the values of \\(D\\) alternate indefinitely between \\(0\\) and \\(1\\). As a result, the following [limit](../limits.md):

\\[
\\lim\_{x \\to x\_0} D(x)
\\]

does not exist for any \\(x\_0\\), establishing discontinuity at every point. Since a function that is discontinuous everywhere cannot be [Riemann integrable](../riemann-integrability-criteria.md) on any non-degenerate interval, this can be confirmed by noting that the upper and lower Darboux sums remain fixed at \\(1\\) and \\(0\\), respectively, for every partition of the interval.

###### Darboux sums are sums obtained by multiplying the maximum or minimum value of a function on each subinterval of a partition by the width of that subinterval. These sums are used to approximate the integral from above and below.

## Non-integrability in the Riemann sense

Consider an interval \\(\[a, b\]\\) with \\(a < b\\) and any partition \\(\\mathcal{P}\\) such that:

\\[
\\mathcal{P} = {a = x\_0 < x\_1 < \\cdots < x\_n = b}
\\]

On each subinterval \\(\[x\_{i-1}, x\_i\]\\), the supremum of \\(D\\) is \\(1\\) due to the density of the rationals, while the infimum is \\(0\\) due to the density of the irrationals. Therefore:

\\[
U(D, \\mathcal{P}) = \\sum\_{i=1}^{n} 1 \\cdot (x\_i - x\_{i-1}) = b - a
\\]



\\[
L(D, \\mathcal{P}) = \\sum\_{i=1}^{n} 0 \\cdot (x\_i - x\_{i-1}) = 0
\\]

Because \\(U(D, \\mathcal{P}) - L(D, \\mathcal{P}) = b - a > 0\\) for every partition \\(\\mathcal{P}\\), the Riemann criterion is not satisfied. Consequently, the function is not integrable in the classical sense on any non-trivial interval.

* * *

Lebesgue’s integration theory introduces a significant shift in perspective. The set \\(\\mathbb{Q}\\) is countable and therefore has Lebesgue measure zero: \\(\\lambda(\\mathbb{Q}) = 0\\). It follows that \\(D(x) = 0\\) almost everywhere with respect to the Lebesgue measure, and since a function that equals zero almost everywhere has integral zero, one obtains

\\[
\\int\_{a}^{b} D(x) \\, d\\lambda = 0
\\]

for every interval \\(\[a, b\]\\). This is one of the more immediate illustrations of the greater reach of Lebesgue’s theory relative to Riemann’s: by construction, it assigns no weight to sets of measure zero, even when those sets are dense in the real line.

## Differentiability

The question of whether \\(D\\) possesses a [derivative](../derivatives.md) at any point has a definitive answer: \\(D\\) is nowhere differentiable. The derivative of \\(D\\) at a point \\(x\_0\\) is defined as the limit:

\\[
D’(x\_0) = \\lim\_{h \\to 0} \\frac{D(x\_0 + h) - D(x\_0)}{h}
\\]

provided this limit exists. Since differentiability implies [continuity](../continuous-functions.md) and \\(D\\) is discontinuous at every point of \\(\\mathbb{R}\\), it follows immediately that \\(D\\) cannot be differentiable anywhere.

This conclusion can also be seen directly through [difference quotients](../difference-quotient.md). Fix any \\(x\_0\\) and consider two sequences \\((r\_n)\\) and \\((s\_n)\\) converging to \\(x\_0\\), with \\(r\_n \\in \\mathbb{Q}\\) and \\(s\_n \\in \\mathbb{R} \\setminus \\mathbb{Q}\\) for all \\(n\\). If \\(x\_0 \\in \\mathbb{Q}\\), then:

\\[
\\frac{D(r\_n) - D(x\_0)}{r\_n - x\_0} = \\frac{1 - 1}{r\_n - x\_0} = 0
\\]



\\[
\\frac{D(s\_n) - D(x\_0)}{s\_n - x\_0} = \\frac{0 - 1}{s\_n - x\_0} = \\frac{-1}{s\_n - x\_0}
\\]

The second expression is unbounded as \\(s\_n \\to x\_0\\). If instead \\(x\_0 \\in \\mathbb{R} \\setminus \\mathbb{Q}\\), then:

\\[
\\frac{D(r\_n) - D(x\_0)}{r\_n - x\_0} = \\frac{1 - 0}{r\_n - x\_0} = \\frac{1}{r\_n - x\_0}
\\]



\\[
\\frac{D(s\_n) - D(x\_0)}{s\_n - x\_0} = \\frac{0 - 0}{s\_n - x\_0} = 0
\\]

It is now the first expression that grows without bound as \\(r\_n \\to x\_0\\). In either case, the difference quotient admits no finite limit, confirming that \\(D’(x\_0)\\) does not exist.

## The Thomae function

A function closely related to the Dirichlet function, known as the Thomae function or the popcorn function, is defined as follows:

\\[
T(x) = \\begin{cases} \\dfrac{1}{q} & \\text{if } x = \\dfrac{p}{q} \\[6pt] 0 & \\text{if } x \\in \\mathbb{R} \\setminus \\mathbb{Q} \\end{cases}
\\]

We have \\(p \\in \\mathbb{Z}\\), \\(q \\in \\mathbb{N}\_{>0}\\), and \\(\\gcd(|p|, q) = 1\\), that is, the fraction \\(p/q\\) is in lowest terms.

In contrast to the Dirichlet function, the Thomae function is continuous at every irrational point and discontinuous at every rational point. This behaviour exemplifies the boundary case allowed by the Lebesgue criterion for Riemann integrability: a Riemann-integrable function may be discontinuous on a set of measure zero, and the rationals, though dense, constitute precisely such a set.

Consequently, the Thomae function is Riemann integrable, with integral equal to zero on every interval, and serves as a well-behaved counterpart to the Dirichlet function.

## Selected resources

-   **Harvard University, C. T. McMullen**. [Math 55b Course Notes](https://people.math.harvard.edu/~ctm/home/text/class/harvard/55b/10/html/home/course/course.pdf)

-   **Harvard University, A. Varilly**. [Thomae Function and Riemann Integrability](https://people.math.harvard.edu/~ctm/home/text/class/harvard/112/02/html/home/solns/sol11.pdf)

-   **MIT, R. B. Melrose**. [Dirichlet Function and Darboux Sums](https://math.mit.edu/~rbm/18.100B/HW8-solved.pdf)

-   **Princeton University, J. Shapiro**. [Lebesgue’s Theorem and the Dirichlet Function](https://web.math.princeton.edu/~js129/PDFs/teaching/MAT425_spring_2025/MAT425_Lecture_Notes.pdf)

-   **UC Davis J. K. Hunter**. [The Riemann Integral](https://www.math.ucdavis.edu/~hunter/m125b/ch1.pdf)