# Fubini's Theorem
Fubini's theorem is one of the theorems whose formulation and proof is slightly more involved when learning it in analysis courses, in both the case when we are working with Darboux integrals and Lebesgue integrals. In this post, we will formalize all of the small details for both cases and prove Fubini's theorem.
The Darboux Case
Most of the presentation for Darboux integrals is based on the one given in Michael Spivak's Calculus on Manifolds.
First we clarify some definitions. Suppose that $A$ were a closed interval $[a, b]$. When we talk about Riemann/Darboux integrals in $\mathbb R$, we use a partition $\mathcal P$ of $A$ given by a sequence of increasing reals such that $$ a = t_1 < t_2 < \cdots < t_k = b. $$ We say that the subintervals of this partitions are $[t_1, t_2], \cdots [t_{k - 1}, t_k]$. Equivalently, we can characterize a partition by the subintervals $S_1, \dots, S_n$. Now more generally, suppose that $A = [a_1, b_1] \times [a_2, b_2] \times \cdots \times [a_n, b_n]$ is a closed rectangle in $\mathbb R^n$. We define a partition of $A$ to be a collection of partitions $\mathcal P_i$ of each interval $[a_i, b_i]$. The subrectangles of this partition $\{\mathcal P_i\}_{i = 1}^n = \{(S_{i1}, \dots, S_{ik_i})\}_{i = 1}^n$ are the cartesian products $S_{1j_1} \times S_{2j_2} \times \cdots \times S_{nj_n}$.
Now, given a partition $\mathcal P$ of some rectangle $A \subseteq \mathbb R^n$ and some function $f: A \to \mathbb R$, we can define the lower and upper Darboux sums as follows: $$ \mathcal L(f, \mathcal P) = \sum_{S \in \mathcal P} \left(\inf_{x \in S} f(x) \right) \mu(S) \quad \text{and} \quad \mathcal U(f, \mathcal P) = \sum_{S \in \mathcal P} \left(\sup_{x \in S} f(x) \right) \mu(S)$$ where by $S \in \mathcal P$, we mean the subrectangles of the partition and $\mu(S)$ is the volume of the subrectangle. Such a function $f$ is integrable if $$ \sup_{\mathcal P} \mathcal L(f, \mathcal P) = \inf_{\mathcal P} \mathcal U(f, \mathcal P), $$ and the integral of $f$ is this value, which we denote by $\int f$.
This clears up most of the terminology that we'll be using throughout this post. Now, recall that Fubini's theorem allows us to iteratively integrate. More specifically, for continuous functions $f: A \times B \to \mathbb R$ with rectangles $A, B$, it is true that $$ \int_{A \times B} f = \int_A \int_B (y \mapsto f(x, y)) = \int_A \left(\int_B f(x, y) \, dy\right) \, dx .$$ This precise statement is actually false in the case of integrable functions $f$. Recall that a function is Darboux integrable if and only if $f$ is discontinuous on a measure $0$ set. Such a function $f: A \times B \to \mathbb R$ may be discontinuous on a measure $0$ set, but this set of discontinuities may not be measure zero when we consider either $x \mapsto f(x, y)$ or $y \mapsto f(x, y)$, which suggests that some of the integral in Fubini's theorem may not even exist.
Fortunately, this state of affairs can be remedied by considering lower and upper integrals. Whether integrable or not, a bounded function $g$ on $A$ must have lower and upper integrals $$ \mathbf L \int_A g = \sup_{\mathcal P} \mathcal L(g, \mathcal P) \quad \text{and} \quad \mathbf U \int_A g = \inf_{\mathcal P} \mathcal U(g, \mathcal P). $$ All integrable functions are bounded (think about why!) which allows us to always use lower and upper integrals in Fubini's theorem.
Here is the most general (Darboux) statement of Fubini's theorem. Let $A \subseteq \mathbb R^n, B \subseteq \mathbb R^m$ be closed rectangles, and let $f : A \times B \to \mathbb R$ be integrable. Then the two lower and upper integrals $$ \mathbf L \int_B (y \mapsto f(x, y)) \quad\text{and}\quad \mathbf U \int_B(y \mapsto f(x, y)) $$ integrable over $x \in A$. Furthermore, $$ \begin{aligned} \int_{A \times B} f & = \int_A \left(x \mapsto \mathbf L\int_B(y \mapsto f(x, y))\right) = \int_A \left(\mathbf L \int_B f(x, y) \, dy\right) \, dx \\ \int_{A \times B} f & = \int_A \left(x \mapsto \mathbf U \int_B (y \mapsto f(x, y)) \right) = \int_A \left(\mathbf U \int_B f(x, y) \, dy\right) \, dx. \end{aligned}$$
The approach we're going to take is the following. Take some partition $\mathcal P$ of $A$ and $\mathcal Q$ of $B$. If we show that $$ \begin{aligned} \mathcal L(f, \mathcal P \times \mathcal Q) & \le \mathcal L\left(x \mapsto \mathbf L \int_B (y \mapsto f(x, y)), \mathcal P\right) \\ & \le \mathcal U \left(x \mapsto \mathbf L\int_B (y \mapsto f(x, y)), \mathcal P\right) \\ & \le \mathcal U \left(x \mapsto \mathbf U\int_B (y \mapsto f(x, y)), \mathcal P \right) \le \mathcal U (f, \mathcal P \times \mathcal Q). \end{aligned}$$ Since we know that $\sup_{\mathcal P, \mathcal Q} \mathcal L(f, \mathcal P \times \mathcal Q) = \inf_{\mathcal P, \mathcal Q} \mathcal U(f, \mathcal P \times \mathcal Q)$, this must hold for $x \mapsto \mathbf L \int_B( y \mapsto f(x, y))$ as well. We can then prove the same for $x \mapsto \mathbf U \int_B(y \mapsto f(x, y))$.
We'll approach each of the inequalities in the chain one at a time. First, note that for some fixed $x$, we must always have $$ \mathcal L(f, \mathcal P \times Q) = $$