real analysis30 min

Riemann Integration

The rigorous construction of the Riemann integral via upper and lower Darboux sums, integrability criteria, and the fundamental theorem of calculus

0/9Not Started

Why This Matters

In calculus, you computed integrals using the antiderivative and the fundamental theorem. But what does the Riemann integral actually mean, rigorously? It is defined through upper and lower Darboux sums: partition the interval into subintervals, take the supremum and infimum of f on each piece, and form weighted sums. If the upper and lower sums converge to the same value as the partition gets finer, the function is Riemann integrable.

This framework answers fundamental questions: which functions can be integrated? (All continuous functions, and many more.) Why does the antiderivative trick work? (The fundamental theorem of calculus, proven rigorously.) What goes wrong for pathological functions like the Dirichlet function? (The upper and lower sums never agree.) Understanding Riemann integration is essential before moving to the Lebesgue integral, which handles even more functions.

Define Terms

Visual Model

Partition Pa = x0, x1, ..., xn = b
Upper Sum U(f,P)Sum of sup(f) * width
Lower Sum L(f,P)Sum of inf(f) * width
RefinementMore points => closer sums
Upper Integralinf over all U(f,P)
IntegrableUpper int = Lower int
Fund. Theorem of CalculusLinks integral and derivative

The full process at a glance. Click Start tour to walk through each step.

The Riemann integral is defined by squeezing upper and lower sums together through partition refinement.

Code Example

Code
// Darboux upper and lower sums
function darbouxSums(f, a, b, n) {
  const dx = (b - a) / n;
  let upper = 0, lower = 0;
  const samples = 100; // samples per subinterval to approximate sup/inf
  for (let i = 0; i < n; i++) {
    const left = a + i * dx;
    const right = a + (i + 1) * dx;
    let sup = -Infinity, inf = Infinity;
    for (let j = 0; j <= samples; j++) {
      const x = left + (j / samples) * (right - left);
      const val = f(x);
      if (val > sup) sup = val;
      if (val < inf) inf = val;
    }
    upper += sup * dx;
    lower += inf * dx;
  }
  return { upper, lower, gap: upper - lower };
}

// f(x) = x^2 on [0, 1], integral = 1/3
console.log("f(x) = x^2 on [0, 1]:");
for (const n of [4, 10, 50, 200]) {
  const { upper, lower, gap } = darbouxSums(x => x*x, 0, 1, n);
  console.log(`  n=${n}: L=${lower.toFixed(6)}, U=${upper.toFixed(6)}, gap=${gap.toFixed(6)}`);
}
console.log(`  Exact integral = ${(1/3).toFixed(6)}`);

// f(x) = sin(x) on [0, pi], integral = 2
console.log("\nf(x) = sin(x) on [0, pi]:");
for (const n of [4, 10, 50, 200]) {
  const { upper, lower, gap } = darbouxSums(Math.sin, 0, Math.PI, n);
  console.log(`  n=${n}: L=${lower.toFixed(6)}, U=${upper.toFixed(6)}, gap=${gap.toFixed(6)}`);
}
console.log(`  Exact integral = 2.000000`);

// Non-integrable function: Dirichlet function (1 if rational, 0 if irrational)
// On any subinterval, sup = 1 and inf = 0
console.log("\nDirichlet function on [0, 1]:");
console.log("  Every partition: U = 1, L = 0");
console.log("  Gap never shrinks => not Riemann integrable");

// Convergence rate: gap decreases as O(1/n) for Lipschitz functions
console.log("\nConvergence rate for x^2:");
let prevGap = null;
for (const n of [10, 20, 40, 80, 160]) {
  const { gap } = darbouxSums(x => x*x, 0, 1, n);
  const ratio = prevGap ? (prevGap / gap).toFixed(2) : "-";
  console.log(`  n=${n}: gap=${gap.toFixed(6)}, ratio=${ratio}`);
  prevGap = gap;
}

Interactive Experiment

Try these exercises:

  • Compute upper and lower sums for f(x) = 1/x on [1, 2] with n = 10, 100, 1000. The integral is ln(2). How fast do the sums converge?
  • For the step function f(x) = 0 for x below 0.5, f(x) = 1 for x at least 0.5 on [0, 1], compute Darboux sums. Is this function integrable? What happens at the jump?
  • Try f(x) = x * sin(1/x) on [0.001, 1]. Is it integrable? The function oscillates rapidly near 0, but is bounded.
  • Compare the upper-lower gap for f(x) = x^2 versus f(x) = sqrt(x) on [0, 1]. Which converges faster? Relate this to the Lipschitz constant.
  • Verify the fundamental theorem: let F(x) = integral of t^2 from 0 to x. Compute F(0.5) numerically using Darboux sums, then verify that F prime(0.5) is approximately 0.25.

Quick Quiz

Coding Challenge

Compute Darboux Sums

Write a function called `darbouxSums` that takes a function f, interval endpoints a and b, and a number of subintervals n. It should return an array [lowerSum, upperSum] where lowerSum is the lower Darboux sum and upperSum is the upper Darboux sum. To approximate the supremum and infimum on each subinterval, sample f at 50 evenly spaced points within each subinterval and take the max and min.

Loading editor...

Real-World Usage

Riemann integration and its theory appear throughout science and engineering:

  • Numerical quadrature: Simpson rule, Gaussian quadrature, and adaptive integration methods all approximate Darboux sums with guaranteed error bounds derived from integrability theory.
  • Probability: Expected values and distributions are defined as integrals. The rigorous framework ensures these quantities exist for well-behaved probability distributions.
  • Physics: Work, energy, and flux are all defined as integrals. The fundamental theorem of calculus connects conservative force fields to potential energy functions.
  • Signal processing: The energy of a signal is the integral of its squared amplitude. Parseval theorem relates this to the Fourier coefficients.
  • Machine learning: Loss functions are often integrals (or expectations). Understanding integrability ensures these loss functions are well-defined and can be minimized.

Connections