\chapter{Lebesgue integration}
\label{ch:lebesgue_integration}
On any measure space $(\Omega, \SA, \mu)$ we can then,
for a function $f \colon \Omega \to [0,\infty]$
define an integral
\[ \int_\Omega f \; d\mu. \]
This integral may be $+\infty$ (even if $f$ is finite).
As the details of the construction won't matter for us later on,
we will state the relevant definitions,
skip all the proofs,
and also state all the properties that we actually care about.
Consequently, this chapter will be quite short.

\section{The definition}
The construction is done in four steps.
\begin{definition}
	If $A$ is a measurable set of $\Omega$,
	then the \vocab{indicator function}
	$\mathbf{1}_A \colon \Omega \to \RR$ is defined by
	\[ \mathbf{1}_A(\omega) = \begin{cases}
			1 & \omega \in A \\
			0 & \omega \notin A.
		\end{cases} \]
\end{definition}

\begin{step}
	[Indicator functions]
	For an indicator function, we require
	\[ \int_\Omega \mathbf{1}_A \; d\mu \defeq \mu(A) \]
	(which may be infinite).
\end{step}
We extend this linearly now for nonnegative functions
which are sums of indicators:
these functions are called \vocab{simple functions}.
\begin{step}
	[Simple functions]
	Let $A_1$, \dots, $A_n$ be a finite collection of measurable sets.
	Let $c_1$, \dots, $c_n$ be either nonnegative real numbers or $+\infty$.
	Then we define
	\[ \int_\Omega \left( \sum_{i=1}^n c_i \mathbf{1}_{A_i} \right) \; d\mu
		\defeq \sum_{i=1}^n c_i \mu(A_i). \]
	If $c_i = \infty$ and $\mu(A_i) = 0$, we treat $c_i \mu(A_i) = 0$.
\end{step}
One can check the resulting sum does not depend
on the representation of the simple function as $\sum c_i \mathbf{1}_{A_i}$.
In particular, it is compatible with the previous step.

Conveniently, this is already enough to define the integral
for $f \colon \Omega \to [0, +\infty]$.
Note that $[0,+\infty]$ can be thought of as a topological space
where we add new open sets $(a,+\infty]$ %chktex 9
for each real number $a$ to our usual basis of open intervals.
Thus we can equip it with the Borel $\sigma$-algebra.\footnote{We
	\emph{could} also try to define a measure on it,
	but we will not: it is good enough for us
	that it is a measurable space.}
\begin{step}
	[Nonnegative functions]
	For each measurable function $f \colon \Omega \to [0, +\infty]$, let
	\[ \int_\Omega f \; d\mu \defeq
		\sup_{0 \le s \le f} \left( \int_\Omega s \; d\mu \right) \]
	where the supremum is taken over all \emph{simple} $s$
	such that $0 \le s \le f$.
	As before, this integral may be $+\infty$.
\end{step}

That is,
\begin{moral}
	We define the integral $\int_\Omega f \; d\mu$ by approximating it from below with simple functions,
	for which we know how to integrate.
\end{moral}

One can check this is compatible with the previous definitions.
At this point, we introduce an important term.
\begin{definition}
	A measurable (nonnegative) function $f \colon \Omega \to [0, +\infty]$
	is \vocab{absolutely integrable}
	or just \vocab{integrable} if $\int_\Omega f \; d\mu < \infty$.
\end{definition}
Warning: I find ``integrable'' to be \emph{really} confusing terminology.
Indeed, \emph{every} measurable function from $\Omega$ to $[0,+\infty]$
can be assigned a Lebesgue integral, it's just that
this integral may be $+\infty$.
So the definition is far more stringent than the name suggests.
Even constant functions can fail to be integrable:
\begin{example}
	[We really should call it ``finitely integrable'']
	The constant function $1$ is \emph{not} integrable on $\RR$,
	since $\int_\RR 1 \; d\mu = \mu(\RR) = +\infty$.
\end{example}
For this reason, I will usually prefer the term ``absolutely integrable''.
(If it were up to me, I would call it ``finitely integrable'',
and usually do so privately.)

\begin{remark}
	[Why don't we approximate the integral from above?]
	For bounded functions on measure spaces with $|\Omega| < \infty$, we can equivalently define
	\[ \int_\Omega f \; d\mu \defeq
		\inf_{0 \le f \le s} \left( \int_\Omega s \; d\mu \right) \]
	where the infimum is taken over all simple $s$ such that $f \leq s$.
	However, if the functions are unbounded or $|\Omega| = \infty$, the situation is not that
	simple:
	\begin{itemize}
		\ii The function $f(x) = x^{-2}$ defined over $\Omega = (1, \infty)$ is absolutely integrable,
		yet for all simple $s$ such that $f \leq s$ we have $\int_\Omega s \; d\mu = \infty$.
		\ii The function $f(x) = x^{-0.5}$ defined over $\Omega = (0, 1)$ is absolutely integrable,
		yet there's no simple $s$ such that $f \leq s$ and $s$ is finite almost everywhere.
	\end{itemize}
\end{remark}

Finally, this lets us integrate general functions.
\begin{definition}
	In general, a measurable function $f \colon \Omega \to [-\infty, \infty]$
	is \vocab{absolutely integrable} or just \vocab{integrable} if $|f|$ is.
\end{definition}
Since we'll be using the first word, this is easy to remember:
``absolutely integrable'' requires taking absolute values.

\begin{step}
	[Absolutely integrable functions]
	If $f \colon \Omega \to [-\infty, \infty]$ is absolutely integrable,
	then we define
	\begin{align*}
		f^+(x) &= \max\left\{ f(x), 0 \right\} \\
		f^-(x) &= \min\left\{ f(x), 0 \right\}
	\end{align*}
	and set
	\[ \int_\Omega f \; d\mu = \int_\Omega |f^+| \; d\mu
		- \int_\Omega |f^-| \; d\mu \]
	which in particular is finite.
\end{step}

That said, calling it ``finitely integrable'' here would also make it as easy to remember:
\begin{exercise}
	Show that $\int_\Omega |f| d\mu < \infty$ if and only if
	$\int_\Omega |f^+| d\mu < \infty$ and
	$\int_\Omega |f^-| d\mu < \infty$.
\end{exercise}

You may already start to see that we really like nonnegative functions:
with the theory of measures, it is possible to integrate them,
and it's even okay to throw in $+\infty$'s everywhere.
But once we start dealing with functions that can be either positive or negative,
we have to start adding finiteness restrictions ---
actually essentially what we're doing is splitting
the function into its positive and negative part,
requiring both are finite, and then integrating.


To finish this section, we state for completeness
some results that you probably could have guessed were true.
Fix $\Omega = (\Omega, \SA, \mu)$, and
let $f$ and $g$ be measurable real-valued functions.
\begin{itemize}
	\ii (Almost-everywhere preservation)
	If $f(x) = g(x)$ almost everywhere then
	$f$ is absolutely integrable if and only if $g$ is,
	and if so, their Lebesgue integrals match.
	\ii (Additivity)
	If $f$ and $g$ are absolutely integrable then
	\[ \int_\Omega f+g \; d\mu
		= \int_\Omega f \; d\mu
		+ \int_\Omega g \; d\mu. \]
	The ``absolutely integrable'' hypothesis can be dropped
	if $f$ and $g$ are nonnegative.
	\ii (Scaling) If $f$ is absolutely integrable and $c \in \RR$
	then $cf$ is absolutely integrable and
	\[ \int_\Omega cf \; d\mu = c \int_\Omega f \; d\mu. \]
	The ``absolutely integrable'' hypothesis can be dropped
	if $f$ is nonnegative and $c > 0$.
	\ii (Monotonicity)
	If $f$ and $g$ are absolutely integrable and $f \le g$, then
	\[ \int_\Omega f \; d\mu \le \int_\Omega g \; d\mu. \]
	The ``absolutely integrable'' hypothesis can be dropped
	if $f$ and $g$ are nonnegative.
\end{itemize}
There are more famous results like monotone/dominated convergence
that are also true, but we won't state them here
as we won't really have a use for them in the context of probability.
(They appear later on in a bonus chapter.)

\section{An equivalent definition}
\label{sec:lebesgue_int_equivalent_def}

The Lebesgue integral can also be defined as follows --- which should be more intuitive on the various
choices of the definitions we made in the steps.

In this definition,
\begin{moral}
	The integral $\int_\Omega f \; d\mu$ is just the volume of the region under the graph of $f$.
\end{moral}

Let us define it:
\setcounter{step}{0}
\begin{step}
	[The region under the graph]
	For a nonnegative function $f \colon \Omega \to \RR$, define the \vocab{region under the function}
	$f$, $R(f)$, to be $\{(x, y) \in \Omega \times \RR, 0 \leq y \leq f(x)\}$.
\end{step}

\begin{remark}
	It should be clear why we only define this for nonnegative function initially ---
	for general function $f$, the only way we could sensibly define the region would be something like
	the following:
	\begin{align*}
		R^+(f) &= \{(x, y) \in \Omega \times \RR, f(x) \geq 0, 0 \leq y \leq f(x)\}, \\
		R^-(f) &= \{(x, y) \in \Omega \times \RR, f(x) \leq 0, 0 \geq y \geq f(x)\}.
	\end{align*}
	Nevertheless, notice that $R^+(f)$ is simply the region under the function
	$f^+(x) = \max\{ f(x), 0 \}$, and $R^-(f)$ has the same measure as the region under the function
	$f^-(x) = \min\{ f(x), 0 \}$, so defining $\int_\Omega f \; d\mu$ for nonnegative functions first
	would actually simplify the definition.
\end{remark}

\begin{step}
	[Making $\Omega \times \RR$ into a measure space]
	We define a pre-measure on $\Omega \times \RR$ the obvious way:
	if $X \subseteq \Omega$ and $Y \subseteq \RR$ are measurable subsets respectively,
	then assign $|X \times Y| = |X| \times |Y|$.

	The pre-measure can be extended to a measure, as we have done in the previous chapter.
\end{step}

\begin{step}
	[Nonnegative functions]
	For each function $f \colon \Omega \to [0, +\infty]$, let
	\[ \int_\Omega f \; d\mu \defeq |R(f)|. \]
	The integral is well-defined whenever $R(f)$ is measurable.
\end{step}
As promised in \Cref{sec:measurable_functions}, the definition of measurable function satisfies:
\begin{moral}
	A nonnegative function $f$ is measurable if and only if we can ``measure'' the region below the graph
	of $f$.
\end{moral}

The last step is exactly the same as in the previous section.
\begin{step}
	[Absolutely integrable functions]
	If $f \colon \Omega \to [-\infty, \infty]$ is absolutely integrable,
	then we define
	\[ \int_\Omega f \; d\mu = \int_\Omega |f^+| \; d\mu
		- \int_\Omega |f^-| \; d\mu. \]
\end{step}

\section{Relation to Riemann integrals (or: actually computing Lebesgue integrals)}
For closed intervals, this actually just works out of the box.
\begin{theorem}
	[Lebesgue integral generalizes Riemann integral]
	Let $f \colon [a,b] \to \RR$ be a Riemann integrable function
	(where $[a,b]$ is equipped with the Borel measure).
	Then $f$ is also Lebesgue integrable and the integrals agree:
	\[ \int_a^b f(x) \; dx = \int_{[a,b]} f \; d\mu. \]
\end{theorem}

Note that a Riemann integrable function \emph{must be bounded},
which means if you try to construct a function $f \colon [0, 1] \to \RR$
in the same vein as \Cref{prob:sin_improper} by
\[
	f(x) = \begin{cases}
		\frac{\sin(1/x)}{x} & x > 0 \\
		0 & x = 0
	\end{cases}
\]
the function $f$ will in fact \emph{not} be Riemann integrable!
Although of course, the improper Riemann integral $\lim_{\eps \to 0^+} \int_\eps^1 f(x) \; dx$ exists.

Thus in practice, we do all theory with Lebesgue integrals (they're nicer),
but when we actually need to compute $\int_{[1,4]} x^2 \; d\mu$
we just revert back to our usual antics with the
Fundamental Theorem of Calculus.
\begin{example}
	[Integrating $x^2$ over {$[1,4]$}]
	Reprising our old example:
	\[ \int_{[1,4]} x^2 \; d\mu
		= \int_1^4 x^2 \; dx
		= \frac13 \cdot 4^3 - \frac13 \cdot 1^3 = 21.  \]
\end{example}

This even works for \emph{improper} integrals,
if the functions are nonnegative.
The statement is a bit cumbersome to write down, but here it is.
\begin{theorem}
	[Improper integrals are nice Lebesgue ones]
	Let $f \ge 0$ be a \emph{nonnegative}
	continuous function defined on $(a,b) \subseteq \RR$,
	possibly allowing $a = -\infty$ or $b = \infty$.
	Then
	\[ \int_{(a,b)} f \; d\mu
		= \lim_{\substack{a' \to a^+ \\ b' \to b^-}}
		\int_{a'}^{b'} f(x) \; dx \]
	where we allow both sides to be $+\infty$
	if $f$ is not absolutely integrable.
\end{theorem}
The right-hand side makes sense since $[a',b'] \subsetneq (a,b)$
is a compact interval on which $f$ is continuous.
This means that improper Riemann integrals of nonnegative
functions can just be regarded as Lebesgue ones
over the corresponding open intervals.

It's probably better to just look at an example though.
\begin{example}
	[Integrating $1/\sqrt{x}$ on $(0,1)$]
	For example, you might be familiar with improper integrals like
	\[ \int_0^1 \frac{1}{\sqrt x} \; dx
		\defeq \lim_{\eps \to 0^+}
		\int_\eps^1 \frac{1}{\sqrt x} \; dx
		= \lim_{\eps \to 0^+} \left( 2\sqrt{1} - 2\sqrt{\eps} \right) = 2.
	\]
	(Note this appeared before as \Cref{prob:improper}.)
	In the Riemann integration situation, we needed the limit as $\eps \to 0^+$
	since otherwise $\frac{1}{\sqrt x}$ is not defined as a function $[0,1] \to \RR$.
	However, it is a \emph{measurable nonnegative}
	function $(0,1) \to [0,+\infty]$, and hence
	\[ \int_{(0,1)} \frac{1}{\sqrt x} \; d\mu = 2. \]
\end{example}

If $f$ is not nonnegative, then all bets are off.
Indeed \Cref{prob:sin_improper} is the famous counterexample.

\section{\problemhead}

\begin{sproblem}
	[The indicator of the rationals]
	\label{prob:1QQ}
	Take the indicator function
	$\mathbf 1_{\QQ} \colon \RR \to \{0,1\} \subseteq \RR$
	for the rational numbers.
		\begin{enumerate}[(a)]
	   \ii Prove that $\mathbf{1}_\QQ$ is not Riemann integrable.
	   \ii Show that $\int_\RR \mathbf{1}_\QQ$ exists
	   and determine its value --- the one you expect!
   \end{enumerate}
\end{sproblem}

\begin{dproblem}
	[An improper Riemann integral with sign changes]
	\label{prob:sin_improper}
	Define $f \colon (1,\infty) \to \RR$ by $f(x) = \frac{\sin(x)}{x}$.
	Show that $f$ is not absolutely integrable,
	but that the improper Riemann integral
	\[ \int_1^\infty f(x) \; dx \defeq
		\lim_{b \to \infty}
		\int_1^b f(x) \; dx \]
	nonetheless exists.
\end{dproblem}
