---
title: The Riemann integral
heading: Squeezing the area between upper and lower sums
eyebrow: A14 · Lesson 17 · The Riemann integral
xp: 40
---

::: hook
Calculus defines the integral as "area under the curve," and A13 approximated it with sums. Analysis asks when the area is well defined at all. The Riemann integral traps it between two staircase sums: an **upper sum** using the largest value of f on each strip, and a **lower sum** using the smallest. If you can make the two as close as you like by using finer strips, the function is integrable, and the integral is the number squeezed between them. The gap $U - L$ is also a guaranteed error bound for any Riemann-sum approximation, so this is quadrature with a certificate.
:::

::: play
- The function is $x^2$ on [0, 1], split into n equal strips. The solid staircase uses each strip's largest value (upper sum), the dashed one its smallest (lower sum).
- The true integral, $\frac13$, is always between them. The readouts show $U = \frac{(n + 1)(2n + 1)}{6n^2}$, $L = \frac{(n - 1)(2n - 1)}{6n^2}$, and their gap, exactly $\frac1n$.
- Raise n: the staircases close in from both sides.
:::
:::

```sim plot
view: graph
x: x = 0..1
y: y = 0..1.05
slider: n = 2..40 step 1 = 6
plot: x^2 | label: x²
plot: (ceil(x*n)/n)^2 | samples: 1600 | color: ch2 | label: upper staircase
plot: (floor(x*n)/n)^2 | samples: 1600 | dashed | color: ch3 | label: lower staircase
readout: upper sum U = (n + 1)*(2*n + 1)/(6*n^2)
readout: lower sum L = (n - 1)*(2*n - 1)/(6*n^2)
readout: U − L = 1/n
```

::: predict
## f is increasing on [0, 2], with f(0) = 1 and f(2) = 5. With n equal strips, how far apart can the upper and lower sums be?

- [ ] $\frac4n$
- [x] $\frac8n$
- [ ] $\frac2n$
- [ ] It depends on f

::: reveal
$\frac8n$, exactly. For an increasing function each strip's max is its right end and its min its left end, so $U - L = \frac{b - a}{n}\sum(f(x_k) - f(x_{k-1})) = \frac{b - a}{n}(f(b) - f(a)) = \frac{2 \times 4}{n}$: the sum telescopes.
:::
:::

::: nameit
## Upper and lower sums

For a bounded f on [a, b] and a partition $a = x_0 < x_1 < \cdots < x_n = b$, with $M_k = \sup f$ and $m_k = \inf f$ on $[x_{k-1}, x_k]$:

$$U = \sum M_k\Delta x_k, \qquad L = \sum m_k\Delta x_k, \qquad L \le U$$

Refining the partition can only lower U and raise L, so every lower sum is below every upper sum.

## Integrability

f is **Riemann integrable** if for every ε > 0 some partition has $U - L < \varepsilon$. Then $\int_a^bf$ is the one number between all lower and all upper sums, and any Riemann sum $\sum f(t_k)\Delta x_k$ (with $t_k$ anywhere in its strip) is within $U - L$ of it.

## Which functions are integrable

- **Monotone** functions: with n equal strips, $U - L = \frac{(b - a)\lvert f(b) - f(a)\rvert}{n}$.
- **Continuous** functions on [a, b]: uniform continuity (lesson 13) makes $M_k - m_k < \varepsilon$ on fine enough strips.
- **Lipschitz** with constant K: $U - L \le \frac{K(b - a)^2}{n}$.
- Bounded functions with finitely many jumps.
- Not the indicator of the rationals: every strip contains rationals and irrationals, so U = b − a and L = 0 always. (The Lebesgue integral of lesson 46 handles it.)
:::

::: example
## Compute U and L for $x^2$ on [0, 1] with n = 4.

::: solution
1. **Upper sum.**
   $$\begin{aligned} U &= \frac14 \cdot \frac{1 + 4 + 9 + 16}{16} \\ &= \frac{30}{64} \\ &= 0.46875 \end{aligned}$$
2. **Lower sum.**
   $$\begin{aligned} L &= \frac14 \cdot \frac{0 + 1 + 4 + 9}{16} \\ &= \frac{14}{64} \\ &= 0.21875 \end{aligned}$$
3. **The gap.** The gap is $0.25 = \frac14$, and $\frac13$ lies between.

**Answer:** U = 0.46875 and L = 0.21875, with the integral $\frac13$ between them.
:::
:::

::: example
## How many equal strips guarantee a Riemann sum of $e^x$ on [0, 1] within $10^{-3}$ of the integral?

::: solution
1. **The gap for an increasing function.** $e^x$ is increasing, so
   $$U - L = \frac{(e - 1)\cdot 1}{n}$$
2. **Solve for n.** That's below $10^{-3}$ when
   $$n > 1718.3$$
   so 1719 strips.
3. **Compare with the trapezoid rule.** The trapezoid rule needs far fewer, because it averages U and L instead of bounding by either.

**Answer:** 1719 strips.
:::
:::

::: example
## Compute the upper and lower sums for $e^{-x}$ on [0, 1] with 10 equal strips.

::: solution
1. **Where the extremes are.** $e^{-x}$ decreases, so on each strip its largest value is at the left end and its smallest at the right.
2. **Upper sum.**
   $$\begin{aligned} U &= \frac{1}{10}\sum_{k=0}^{9}e^{-k/10} \\ &= \frac{1}{10}\cdot\frac{1 - e^{-1}}{1 - e^{-0.1}} \\ &= 0.66425 \end{aligned}$$
3. **Lower sum.** L drops the first term and adds the last:
   $$\begin{aligned} L &= U - \frac{1 - e^{-1}}{10} \\ &= 0.60104 \end{aligned}$$
4. **Check.** The integral, $1 - e^{-1} = 0.63212$, lies between them.
5. **Monotone functions in general.** For any monotone function
   $$U - L = \frac{\lvert f(b) - f(a)\rvert(b - a)}{n}$$
   so monotone functions are always integrable, and the gap shrinks as $\frac1n$.

**Answer:** U = 0.66425 and L = 0.60104, with the integral 0.63212 between them.
:::
:::

::: check
given: n = 4 | 10 | 50
answer: (n + 1)*(2*n + 1)/(6*n^2)
tolerance: 0.01%

## What's the upper sum for $x^2$ on [0, 1] with {n} equal strips?

::: right
Right. $\frac{(n + 1)(2n + 1)}{6n^2}$ = {answer}.
:::

::: misses
- [(n - 1)*(2*n - 1)/(6*n^2)] That's the lower sum, using left ends.
- [1/3] That's the integral, which lies between the sums.
- [any] Not yet. $\frac1n\sum_{k=1}^n(k/n)^2$.
:::
:::

::: check
given: a = 0 | 1; b = 3 | 4; fa = 1 | 3; fb = 7 | 10; n = 10 | 100
answer: (b - a)*(fb - fa)/n
tolerance: 0.1%

## f increases from {fa} at x = {a} to {fb} at x = {b}. What's U − L with {n} equal strips?

::: right
Right. $\frac{(b - a)(f(b) - f(a))}{n}$ = {answer}.
:::

::: misses
- [(fb - fa)/n] Each strip has width $\frac{b - a}{n}$.
- [any] Not yet. The differences telescope.
:::
:::

::: check
given: d = 1.718 | 2.5; e = 0.003 | 0.00013
answer: floor(d/e) + 1
tolerance: 0

## An increasing function on [0, 1] rises by {d}. How many equal strips make $U - L < \given{e}$?

::: right
Right. Need $\frac{d}{n} < \varepsilon$: n = {answer}.
:::

::: misses
- [floor(d/e)] That n gives $U - L \ge \varepsilon$; take the next.
- [any] Not yet. $U - L = \frac{d}{n}$.
:::
:::

::: check
given: K = 2 | 5; L = 2 | 3; n = 20 | 1000
answer: K*L^2/n
tolerance: 0.1%

## A Lipschitz function (constant {K}) on an interval of length {L}: what's the bound on U − L with {n} equal strips?

::: right
Right. $\frac{K(b - a)^2}{n}$ = {answer}.
:::

::: misses
- [K*L/n] Each strip contributes at most $K\cdot\frac{L}{n}$ in height times $\frac Ln$ in width.
- [any] Not yet. $M_k - m_k \le K\frac Ln$ on each strip.
:::
:::

::: check
kind: choice

## For the indicator of the rationals on [0, 1], what are every upper sum and every lower sum?

- [ ] Both 0
- [x] Upper 1, lower 0
- [ ] Both ½
- [ ] Upper ½, lower 0

::: misses
- [1] Every strip contains a rational, where the function is 1.
- [3] They never meet: that's why it isn't Riemann integrable.
- [4] Every strip's supremum is 1.
:::
:::

::: check
kind: parts
given: n = 4 | 10 | 50

## Upper and lower sums for $e^{-x}$ on [0, 1] with {n} equal strips.

::: part
answer: (1/n)*(1 - exp(-1))/(1 - exp(-1/n))
tolerance: 0.1%

### What is the upper sum?

::: misses
- [any] Left endpoints: $\frac1n\sum_{k=0}^{n-1}e^{-k/n}$, a geometric sum.
:::
:::

::: part
answer: (1 - exp(-1))/n
tolerance: 0.5%

### What is U − L?

::: misses
- [any] $\frac{f(0) - f(1)}{n}$ for a decreasing function.
:::
:::
:::

::: check
kind: derivation
vars: n = 2..100

## Riemann sums of f(x) = x on [0, 1] with n equal strips.

::: step
answer: (n + 1)/(2*n)

### What is the upper sum?
:::

::: step
answer: (n - 1)/(2*n)

### What is the lower sum?
:::

::: right
Right. They differ by $\frac1n$ and squeeze the integral ½.
:::
:::

::: explain
## Why is every continuous function on [a, b] Riemann integrable?

::: model
On a closed, bounded interval a continuous function is uniformly continuous: for any η > 0 there's a δ such that points closer than δ have values closer than η. Split [a, b] into strips narrower than δ; on each strip the largest and smallest values then differ by less than η, so $U - L < \eta(b - a)$. Choosing $\eta = \varepsilon/(b - a)$ makes the gap less than ε, which is the definition of integrability. Uniform continuity matters: a δ that changed from strip to strip couldn't guarantee all the strips at once.
:::
:::

::: practice

::: check
given: n = 4..40 int
answer: (n - 1)*(2*n - 1)/(6*n^2)
tolerance: 0.01%

## Lower sum for $x^2$ on [0, 1], n = {n}?

::: misses
- [any] $\frac{(n - 1)(2n - 1)}{6n^2}$.
:::
:::

::: check
given: a = 2 | 0; b = 5 | 3; fa = 0 | 2; fb = 9 | 6; n = 30 | 300
answer: (b - a)*(fb - fa)/n
tolerance: 0.1%

## U − L for an increasing f from {fa} to {fb} on [{a}, {b}], n = {n}?

::: misses
- [any] $\frac{(b - a)(f(b) - f(a))}{n}$.
:::
:::

::: check
given: K = 3 | 0.5; L = 2 | 4; n = 50 | 400
answer: K*L^2/n
tolerance: 0.1%

## Lipschitz bound on U − L, K = {K}, length {L}, n = {n}?

::: misses
- [any] $\frac{KL^2}{n}$.
:::
:::
:::
