# Lebesgue vs Riemann Integral: Interactive Lab

Compare the Riemann and Lebesgue integrals: slice the x-axis or the y-axis, add up the same area and see why an expectation sorts by value. Interactive lab.

## About this tool

The Riemann integral adds up height times width as you walk along the x-axis. The Lebesgue integral slices the y-axis instead: it adds each level times the length of the set where the function reaches that level. For nice functions the two agree. The Lebesgue version keeps working when a function jumps everywhere and needs no order of the points at all, which is why expectations are Lebesgue integrals. These pages compare the two ways on one area and compute an expected score by sorting.

## Frequently asked questions

### What is the difference between Riemann and Lebesgue integrals?

Riemann cuts the domain into thin strips and adds strip width times a height. Lebesgue cuts the range into levels and adds each level times the measure of the set where the function takes about that value. The Lebesgue sum only needs the size of such sets, not a left-to-right order, so it also works on boards, path spaces and any other measure space. On continuous functions both give the same number.

### Why does expectation sort by value?

The expected value of X is the sum over values of value times the probability of getting it. That is already a Lebesgue sum: you group outcomes by the value X takes and weigh each group by its probability. For a dart board, sort the board into regions that score 10, 5, 2, 1 and 0 and add score times area. No coordinates are needed, and the same recipe works for a random price path.

### What should I try on the pages?

On the first page choose an integrand and refine the Riemann strips and the Lebesgue levels: both sums approach the same area on a smooth function. Then pick the Dirichlet function, one on the rationals and zero elsewhere. Riemann strips never settle, while the Lebesgue sum is exactly 0. On the second page, switch the thrower from uniform to aimed: the scores stay put and only the measure changes.

### Is the Lebesgue integral just a fancier way to get the same number?

For functions both methods can handle, yes. The gain is reach and good behaviour: more functions are integrable, and limits of functions pass through the integral under clear conditions, the convergence theorems. That is what lets you swap a limit and an expectation in proofs and in Monte Carlo arguments. The Riemann integral cannot give that, which is why modern probability is stated in Lebesgue terms.

## Learn the theory

- [The Lebesgue integral](https://quantsandbox.dev/guide/probability/lebesgue-integration): Integrals built from simple functions by slicing the range: the layer-cake formula, integrable functions, sums as integrals, and Riemann versus Lebesgue.
- [Expectation, variance and inequalities](https://quantsandbox.dev/guide/probability/expectation-variance): Expectation as an integral, computed from the distribution or from tails; linearity, variance and moments; the Markov, Chebyshev and Jensen inequalities.
- [Probability spaces, σ-algebras and random variables](https://quantsandbox.dev/guide/stochastic/probability-spaces): Sample space, σ-algebra, probability measure, measurable maps and the σ-algebra generated by a variable.
- [Monte Carlo option pricing](https://quantsandbox.dev/guide/stochastic/monte-carlo-pricing): Estimating option prices by simulation: standard error, confidence intervals and convergence to Black–Scholes.

Open the interactive tool: https://quantsandbox.dev/lebesgue-integral
