The Riemann integral is defined by squeezing a function between upper and lower sums over partitions. When the upper and lower integrals agree, the function is integrable. The fundamental theorem of calculus links integration to differentiation: integration undoes differentiation.
Partitions and upper/lower sums
A partition P of [a, b] is a finite set of points a = x_0 < x_1 < ... < x_n = b. The lower sum L(P, f) uses the infimum of f on each subinterval; the upper sum U(P, f) uses the supremum. Always L(P, f) ≤ U(P, f). Refining the partition tightens the squeeze.
Scheme
; Upper and lower Riemann sums for f(x) = x^2 on [0, 1]
(define (f x) (* x x))
(define (riemann-sums n)
(let* ((dx (/ 1.0 n)))
(let loop ((i 0) (lower 0.0) (upper 0.0))
(if (>= i n)
(begin
(display " n=") (display n)
(display ": L=") (display lower)
(display ", U=") (display upper)
(display ", gap=") (display (- upper lower))
(newline))
(let* ((x-left (* i dx))
(x-right (* (+ i 1) dx))
; f is increasing on [0,1], so inf=f(left), sup=f(right)
(inf-val (f x-left))
(sup-val (f x-right)))
(loop (+ i 1)
(+ lower (* inf-val dx))
(+ upper (* sup-val dx))))))))
(display "Riemann sums for x^2 on [0,1]:") (newline)
(for-each riemann-sums (list 4101001000))
(display "Exact integral = 1/3 = ")
(display (/ 1.03))
Python
# Riemann sums for x^2 on [0,1]
f = lambda x: x**2for n in [4, 10, 100, 1000]:
dx = 1/n
lower = sum(f(i*dx) * dx for i inrange(n))
upper = sum(f((i+1)*dx) * dx for i inrange(n))
print(f"n={n:4d}: L={lower:.6f}, U={upper:.6f}, gap={upper-lower:.6f}")
print(f"Exact: {1/3:.6f}")
Integrability
f is Riemann integrable on [a, b] if the supremum of all lower sums equals the infimum of all upper sums. Every continuous function on [a, b] is integrable. Every monotone function on [a, b] is integrable. Functions with finitely many discontinuities are integrable.
Scheme
; A function with a single discontinuity is still integrable; f(x) = 1 if x != 0.5, f(0.5) = 100; Integral on [0,1] should be 1 (the spike has measure zero)
(define (f x)
(if (and (> x 0.499999) (< x 0.500001)) 1001))
(define (riemann-sum f n)
(let ((dx (/ 1.0 n)))
(let loop ((i 0) (s 0.0))
(if (>= i n) s
(let ((x (+ (* i dx) (/ dx 2.0)))) ; midpoint
(loop (+ i 1) (+ s (* (f x) dx))))))))
(display "Midpoint sums (spike at 0.5):") (newline)
(for-each (lambda (n)
(display " n=") (display n)
(display ": ") (display (riemann-sum f n)) (newline))
(list 10100100010000))
(display "As partition refines, sum -> 1 (spike is negligible)")
Python
# Python equivalentdef f(x):
return100if0.499999 < x < 0.500001else1print("Midpoint sums (spike at 0.5):")
for n in [10, 100, 1000, 10000]:
dx = 1.0 / n
s = sum(f(i * dx + dx / 2) * dx for i inrange(n))
print(" n=" + str(n) + ":", s)
print("As partition refines, sum -> 1 (spike is negligible)")
Fundamental theorem of calculus
FTC Part 1: if f is continuous on [a, b], then F(x) = ∫_a^x f(t) dt is differentiable and F'(x) = f(x). FTC Part 2: if F is any antiderivative of f, then ∫_a^b f(t) dt = F(b) - F(a). Integration and differentiation are inverse operations.
Scheme
; FTC: integral of f'(x) = f(b) - f(a); f(x) = x^3, f'(x) = 3x^2; integral of 3x^2 from 1 to 3 should = 3^3 - 1^3 = 26
(define (numerical-integral f a b n)
(let ((dx (/ (- b a) n)))
(let loop ((i 0) (s 0.0))
(if (>= i n) s
(let ((x (+ a (* i dx) (/ dx 2.0))))
(loop (+ i 1) (+ s (* (f x) dx))))))))
(define (fprime x) (* 3 x x))
(define result (numerical-integral fprime 1.03.010000))
(display "Integral of 3x^2 from 1 to 3: ")
(display result) (newline)
(display "F(3) - F(1) = 27 - 1 = 26") (newline)
; FTC Part 1: F(x) = integral from 0 to x of sin(t) dt; F'(x) should equal sin(x)
(define (F x) (numerical-integral sin 0 x 1000))
(define (F-prime x)
(let ((h 0.001))
(/ (- (F (+ x h)) (F x)) h)))
(display "F'(pi/4) = ") (display (F-prime 0.785398)) (newline)
(display "sin(pi/4) = ") (display (sin 0.785398))
Python
# Python equivalentimportmathdef integrate(f, a, b, n=10000):
dx = (b - a) / n
returnsum(f(a + i * dx + dx / 2) * dx for i inrange(n))
fprime = lambda x: 3 * x * x
result = integrate(fprime, 1.0, 3.0)
print("Integral of 3x^2 from 1 to 3:", result)
print("F(3) - F(1) = 27 - 1 = 26")
# FTC Part 1: F(x) = integral of sin from 0 to x
F = lambda x: integrate(math.sin, 0, x, 1000)
h = 0.001
x0 = math.pi / 4
F_prime = (F(x0 + h) - F(x0)) / h
print("F'(pi/4) =", F_prime)
print("sin(pi/4) =", math.sin(x0))
📐 Calculus Ch.7 — integration techniques: the computational toolkit built on the Riemann integral
🎰 Probability Ch.2 — continuous probability distributions are Riemann integrals of density functions
⚛ Physics Ch.8 — work and energy: line integrals are the physical application of the Riemann integral
Translation notes
Numerical integration (midpoint rule) converges at rate O(1/n^2). The upper/lower sum approach converges at O(1/n) for monotone functions. Neither is the Riemann integral itself: that is the common value they converge to. The FTC proof requires the mean value theorem, not computation.