On this page
A double integral over a rectangle can be worked out as two single integrals, one inside the other. These are called iterated integrals, and you can nest them in two orders: integrate in y first and then x, or x first and then y. Fubini's theorem tells you when the order does not matter. For most integrals in a calculus course, it does not. But one short example changes its answer when you swap the order, and seeing why turns a rule into understanding.
What does Fubini's theorem say?
The condition is absolute integrability: if the integral of |f(x, y)| over the region is finite, both iterated integrals exist and equal the double integral, as stated in Wikipedia's article on Fubini's theorem. The same article records that Guido Fubini proved the general result in 1907, and that Leonida Tonelli gave a variation in 1909 for non-negative functions. Tonelli's version needs no finiteness check: if a (measurable) f is never negative, the two orders always agree, even when the common value is infinite.
For class work, the article notes a simpler version: the formula holds for the ordinary (Riemann) integral when the function is continuous on the rectangle. A continuous function on a closed, bounded rectangle is bounded, so the integral of |f| is automatically finite.
How do you integrate over a rectangle in either order?
Take f(x, y) = xy² on the rectangle 0 ≤ x ≤ 2, 0 ≤ y ≤ 3.
Order 1, y first:
Inner integral: integrate xy² in y from 0 to 3. Treat x as a constant: x · [y³/3] from 0 to 3 = 9x.
Outer integral: integrate 9x in x from 0 to 2: 9 · [x²/2] from 0 to 2 = 18.
Order 2, x first:
Inner integral: integrate xy² in x from 0 to 2. Treat y as a constant: y² · [x²/2] from 0 to 2 = 2y².
Outer integral: integrate 2y² in y from 0 to 3: 2 · [y³/3] from 0 to 3 = 18.
Both orders give 18, as the theorem promises, because xy² is continuous on a closed rectangle. The integrand also splits into a function of x times a function of y, so the double integral is (integral of x from 0 to 2) × (integral of y² from 0 to 3) = 2 × 9 = 18.
When does swapping the order of integration give a different answer?
The classic example is f(x, y) = (x² − y²)/(x² + y²)² on the unit square 0 ≤ x ≤ 1, 0 ≤ y ≤ 1. The Wikipedia article gives its two iterated integrals as π/4 and −π/4. Here is how to check both.
y first. The derivative of y/(x² + y²) with respect to y is exactly (x² − y²)/(x² + y²)². So for a fixed x > 0, the inner integral from y = 0 to 1 is 1/(1 + x²). Then the integral of 1/(1 + x²) from 0 to 1 is arctan 1 = π/4.
x first. The derivative of −x/(x² + y²) with respect to x is the same f. So the inner integral from x = 0 to 1 is −1/(1 + y²), and the outer integral is −π/4.
Same function, same square, two answers, and no algebra mistake.
Why does the counterexample break Fubini's theorem?
The function is not continuous at the origin; it blows up there. In polar coordinates it becomes cos(2θ)/r², and the area element is r dr dθ. So |f| times the area element is |cos 2θ|/r dr dθ, and the integral of 1/r from 0 diverges. The integral of |f| over the square is infinite, which is the step the Wikipedia article uses to show the hypothesis fails.
Below the diagonal (x > y) the function is positive; above it, negative. Each part on its own holds an infinite amount near the corner, so the double integral is a disguised infinity minus infinity, and the order of integration decides how it resolves.
A three-question check before you swap
Is f continuous on a closed, bounded rectangle? Then swap freely.
Is f never negative (or never positive) on the region? Then Tonelli's version applies and the orders agree, though the answer may be infinite.
Otherwise, is the integral of |f| finite? Look hardest where f blows up; polar coordinates often settle a single bad point. If it is finite, swap. If not, trust neither order.
If double and iterated integrals still feel like a recipe rather than an idea, the Fermi Concept Library covers every concept in physics, chemistry, biology, mathematics and computing. To practise setting up limits in either order, the Fermi Problem Library has a step-by-step solver that explains the reasoning.
Next time an integral looks easier the other way round, run the three questions first.



