22. Adv: the Riemann integral — definition and criteria for integrability

📖 Reading · 12 min
💡 Every code box below is live — edit it and hit Run.

§4.2 defined the definite integral as a limit of Riemann sums, using sample points chosen anywhere within each subinterval. This lesson makes that definition airtight, using §15.0's supremum and infimum to remove all ambiguity about which sample points are chosen — and states exactly when a function fails to be integrable at all, something §4.2 never had to confront because every function used since then was safely continuous.

Upper and lower sums

Partition [a,b] into subintervals [x_0,x_1],[x_1,x_2],\ldots,[x_{n-1},x_n] (not necessarily equal width). On each subinterval, define

M_i=\sup_{x\in[x_{i-1},x_i]}f(x)\qquad m_i=\inf_{x\in[x_{i-1},x_i]}f(x)

using §15.0's supremum and infimum — guaranteed to exist for any bounded f, with no assumption that f actually attains these values on the subinterval. The upper sum and lower sum for this partition P:

U(f,P)=\sum_{i=1}^nM_i\,\Delta x_i\qquad L(f,P)=\sum_{i=1}^nm_i\,\Delta x_i

Every ordinary Riemann sum from §4.1 (using any sample point in each subinterval) lies between L(f,P) and U(f,P), since the sample point's f-value can be no larger than M_i and no smaller than m_i. The upper and lower sums are the two extreme cases — the largest and smallest possible Riemann sums for that partition.

The upper and lower integrals, and integrability

Define the upper integral as the infimum of U(f,P) over every possible partition, and the lower integral as the supremum of L(f,P) over every partition. f is Riemann integrable on [a,b] exactly when these two agree:

\underline{\int_a^b}f=\overline{\int_a^b}f\qquad\Longrightarrow\qquad\int_a^bf(x)\,dx:=\text{their common value}

Riemann's criterion restates this in a form that's actually usable for proofs:

f is integrable on [a,b] if and only if, for every \varepsilon>0, there exists a partition P with U(f,P)-L(f,P)<\varepsilon.

This is exactly the Cauchy-criterion spirit from §15.1: instead of computing the exact integral directly, integrability is certified by showing the upper and lower sums can be squeezed arbitrarily close together.

Continuous functions are integrable

Every function continuous on [a,b] is Riemann integrable there.

Why: continuity on the closed, bounded interval [a,b] is automatically uniform continuity, by §15.3's theorem. Given \varepsilon>0, uniform continuity supplies a single \delta making |f(x)-f(y)| small whenever |x-y|<\delta, anywhere in [a,b]. Choosing a partition fine enough that every subinterval has width less than \delta forces M_i-m_i (the function's oscillation on that piece) to be small everywhere at once — not just on some subintervals — which drives U(f,P)-L(f,P)=\sum(M_i-m_i)\Delta x_i below any target \varepsilon. This is precisely why §15.3's uniform continuity theorem exists in this course: it's the exact tool needed to make Riemann's criterion work for continuous functions, which is every function this course has integrated since Module 4.

A function that is not integrable

The Dirichlet function, f(x)=1 if x is rational and f(x)=0 if x is irrational, fails Riemann's criterion on every partition of any interval, however fine: since both rationals and irrationals are dense (every subinterval, no matter how small, contains both), every subinterval has M_i=1 (some rational point sits there) and m_i=0 (some irrational point sits there too). So U(f,P)=1\cdot(b-a) and L(f,P)=0 for every partition P — the gap U(f,P)-L(f,P)=b-a never shrinks, no matter how the partition is refined.

\boxed{\text{the Dirichlet function is not Riemann integrable on any interval}}

Doing it in Python

Computing upper and lower sums for f(x)=x^2 on [0,1] with equal partitions of increasing fineness, watching U-L\to0 — Riemann's criterion confirmed numerically:

def f(x):
    return x**2

def upper_lower(n):
    dx = 1 / n
    U = L = 0
    for i in range(n):
        left, right = i*dx, (i+1)*dx
        U += f(right) * dx   # f is increasing on [0,1], so max is at the right endpoint
        L += f(left) * dx    # and min is at the left endpoint
    return U, L

print(f"{'n':>6} {'U':>10} {'L':>10} {'U-L':>10}")
for n in (4, 10, 100, 1000):
    U, L = upper_lower(n)
    print(f"{n:>6} {U:>10.6f} {L:>10.6f} {U-L:>10.6f}")
print(f"\nboth U and L converge toward 1/3 = {1/3:.6f}, and U-L -> 0")

Confirming the Dirichlet function's upper and lower sums never converge, regardless of partition fineness — a direct contrast:

from fractions import Fraction

def dirichlet_upper_lower(n):
    # on ANY subinterval, both a rational and an irrational point exist,
    # so M_i=1 and m_i=0 always, regardless of how fine the partition is
    dx = Fraction(1, n)
    U = sum(1 * dx for _ in range(n))
    L = sum(0 * dx for _ in range(n))
    return U, L

for n in (4, 100, 10000):
    U, L = dirichlet_upper_lower(n)
    print(f"n={n}: U={float(U)}, L={float(L)}, U-L={float(U-L)}")
print("\nU-L stays exactly 1 forever -- Riemann's criterion never succeeds")

Confirming that every ordinary Riemann sum (with sample points anywhere in each subinterval, §4.1's original construction) is trapped between the lower and upper sums:

import random

def f(x):
    return x**2

n = 10
dx = 1/n
random.seed(3)

U = sum(f((i+1)*dx) * dx for i in range(n))
L = sum(f(i*dx) * dx for i in range(n))

# an ordinary Riemann sum with random sample points
riemann_sum = sum(f(i*dx + random.random()*dx) * dx for i in range(n))

print(f"L = {L:.6f}")
print(f"Riemann sum (random samples) = {riemann_sum:.6f}")
print(f"U = {U:.6f}")
print(f"trapped between L and U: {L <= riemann_sum <= U}")

Worked example

Compute the upper and lower sums for f(x)=x^2 on [0,1] using 4 equal subintervals, and confirm they bracket the true integral \int_0^1x^2dx=\frac13.

Subintervals: [0,\frac14],[\frac14,\frac12],[\frac12,\frac34],[\frac34,1], each of width \frac14. Since f(x)=x^2 is increasing on [0,1], M_i occurs at each subinterval's right endpoint and m_i at its left endpoint.

U=\frac14\left[\left(\frac14\right)^2+\left(\frac12\right)^2+\left(\frac34\right)^2+1^2\right]=\frac14\left[\frac1{16}+\frac14+\frac9{16}+1\right]=\frac14\cdot\frac{30}{16}=\frac{30}{64}=\boxed{\frac{15}{32}}

L=\frac14\left[0^2+\left(\frac14\right)^2+\left(\frac12\right)^2+\left(\frac34\right)^2\right]=\frac14\left[0+\frac1{16}+\frac14+\frac9{16}\right]=\frac14\cdot\frac{14}{16}=\frac{14}{64}=\boxed{\frac7{32}}

Sanity check. L=\frac7{32}=0.21875 and U=\frac{15}{32}=0.46875, and indeed L<\frac13\approx0.333<U — the true integral sits strictly between the lower and upper sums, exactly as it must (every ordinary Riemann sum, and the true integral itself, is squeezed between these two extremes). The gap U-L=\frac{15}{32}-\frac7{32}=\frac8{32}=0.25 is substantial with only 4 subintervals; the "Doing it in Python" section confirmed this gap keeps shrinking as the partition refines — with 1000 subintervals, U-L drops to just 0.001, exactly the behavior Riemann's criterion demands for integrability. ✓

Your turn

1. Compute the upper and lower sums for f(x)=x on [0,2] using 2 equal subintervals, and compare to the exact integral \int_0^2x\,dx=2.

2. Explain, in one sentence, why the Dirichlet function's upper sum is always exactly b-a and its lower sum is always exactly 0, no matter how the partition is chosen.

3. True or false: a function can be Riemann integrable on [a,b] even if it is discontinuous at some points in [a,b].

Solutions

1. Subintervals [0,1] and [1,2], each width 1. f(x)=x is increasing.

U=1\cdot f(1)+1\cdot f(2)=1+2=3,\qquad L=1\cdot f(0)+1\cdot f(1)=0+1=1

\boxed{U=3,\ L=1}

— and indeed 1<2<3, with the true integral 2 sitting between them.

2. Every subinterval, however small, contains both rational and irrational numbers (both sets are dense in \mathbb R), so M_i=\sup=1 (achieved by some rational point in the subinterval) and m_i=\inf=0 (achieved by some irrational point) on every subinterval of every partition — forcing U(f,P)=1\cdot(b-a) and L(f,P)=0 regardless of how the partition is refined.

3. True. Riemann's criterion only requires U(f,P)-L(f,P) to be made arbitrarily small by some partition — a function can have a finite number of discontinuities (or even certain infinite but "small enough" sets of them) and still satisfy this, as long as those discontinuities don't create the persistent, everywhere-dense oscillation the Dirichlet function has. (The precise general criterion — a bounded function is Riemann integrable exactly when its set of discontinuities has "measure zero" — belongs to a course in measure theory, beyond this bridge's scope, but the Dirichlet function's failure and a finitely-discontinuous function's success are both explainable directly from Riemann's criterion alone.)

Check yourself in code

Compute the upper and lower sums for f(x)=x^2 on [0,1] with n=4 equal subintervals.

Print exactly this:

U = 0.46875
L = 0.21875
U - L = 0.25
def f(x):
    return x**2

n = 4
dx = 1 / n
U = sum(f((i+1)*dx) * dx for i in range(n))
L = sum(f(i*dx) * dx for i in range(n))

print("U = ...")
print("L = ...")
print("U - L = ...")
def f(x):
    return x**2

n = 4
dx = 1 / n
U = sum(f((i+1)*dx) * dx for i in range(n))
L = sum(f(i*dx) * dx for i in range(n))

print(f"U = {U}")
print(f"L = {L}")
print(f"U - L = {U - L}")

The Riemann integral is rigorously defined via upper and lower sums built from §15.0's supremum and infimum on each subinterval, with f declared integrable exactly when these two can be squeezed together — Riemann's criterion — arbitrarily closely. Continuity on [a,b] guarantees this squeeze is always achievable, precisely because §15.3's uniform continuity theorem makes the function's oscillation small everywhere at once once the partition is fine enough, while the Dirichlet function shows a bounded function can fail integrability entirely, with the upper and lower sums locked a fixed distance apart no matter how fine the partition gets.

Next: revisiting §8.4's pointwise-versus-uniform-convergence distinction with the full rigor this module has been building — including the exact proof of why uniform convergence licenses swapping a limit with an integral.