% =================================================================
%  Lecture 5
%  Primary source: handwritten notes (Mathpix mmd, lines 1-62)
%  Fallback: kashlak.pdf §2.1-2.2 (only for OCR/notation/curriculum clarity)
% =================================================================
\section[Lecture 5 -- Simple and Measurable Functions]{Lecture 5 \textemdash{} Simple and Measurable Functions}
\label{sec:lec05}

With Lebesgue measure in hand, we now begin populating the measure
space with \emph{functions}. The strategy is the one of Lecture~3
recycled: start with the simplest possible class of functions
(finite-step indicators), define everything we want for them, and
later extend by limits to a much wider class. Two parallel languages
will run side by side throughout: a probability space
\((\Omega,\Fcal,\P)\) hosts \emph{simple random variables}, while a
generic measure space \((\Omega,\Fcal,\mu)\) hosts \emph{simple
functions}. The structural content is identical.

\subsection{Simple random variables}

\begin{definition}{Simple random variable}{simple-rv}
Let \((\Omega,\Fcal,\P)\) be a probability space (\(\P(\Omega)=1\)). A
\emph{simple random variable} is a map \(X\colon\Omega\to\R\) such
that
\begin{itemize}
  \item \(X(\omega)\) takes only finitely many values
        \(\{x_1,\dots,x_p\}\subseteq\R\);
  \item for each \(i\), the level set
        \(\{\omega\in\Omega : X(\omega)=x_i\}\) lies in \(\Fcal\).
\end{itemize}
Equivalently, given a finite \(\Fcal\)-measurable partition
\(\{A_i\}_{i=1}^{p}\) of \(\Omega\) (so
\(\bigsqcup_{i=1}^{p}A_i=\Omega\) and \(A_i\cap A_j=\emptyset\) for
\(i\neq j\)),
\[
X(\omega) \;=\; \sum_{i=1}^{p} x_i\,\indic[\omega\in A_i].
\]
\end{definition}

The probability that \(X\) hits a particular value reads off the
partition directly:
\[
\P(X=x_i) \;=\; \P\bigl(\{\omega\in\Omega : X(\omega)=x_i\}\bigr)
          \;=\; \P(A_i),
\]
and the \emph{expectation} is
\[
\E X \;=\; \sum_{i=1}^{p} x_i\,\P(X=x_i).
\]

\begin{example}[{Staircase approximation of the identity on $(0,1]$}]
Take \(\Omega=(0,1]\) with Lebesgue measure, partition by
\(A_1=(0,\tfrac14]\), \(A_2=(\tfrac14,\tfrac12]\),
\(A_3=(\tfrac12,\tfrac34]\), \(A_4=(\tfrac34,1]\), and set
\(x_i=(i-1)/4\). Each cell has \(\lambda(A_i)=\tfrac14\), so the
simple random variable
\[
X^{(4)}(\omega) \;=\; \sum_{i=1}^{4} \tfrac{i-1}{4}\,\indic[\omega\in A_i]
\]
takes the values \(0,\tfrac14,\tfrac12,\tfrac34\) each with
probability \(\tfrac14\), and
\(\E X^{(4)} = (0+\tfrac14+\tfrac12+\tfrac34)/4 = 0.375\).
Refining the partition into \(2^m\) equal pieces produces a sequence
of simple random variables \(X^{(2^m)}\) that approximates the
identity \(\omega\mapsto\omega\) on \((0,1]\) ever more closely.

\begin{center}
\begin{tikzpicture}[>=Stealth, scale=4]
  % axes
  \draw[->] (-0.05,0) -- (1.15,0) node[right] {\small \(\omega\)};
  \draw[->] (0,-0.05) -- (0,1.05) node[above] {\small \(X^{(4)}(\omega)\)};
  % y ticks
  \foreach \y/\lab in {0.25/{\(\tfrac14\)}, 0.5/{\(\tfrac12\)},
                        0.75/{\(\tfrac34\)}, 1/{\(1\)}} {
    \draw (-0.012,\y) -- (0.012,\y);
    \node[left] at (-0.015,\y) {\small \lab};
  }
  % x ticks / partition labels
  \foreach \x/\lab in {0.25/{\(\tfrac14\)}, 0.5/{\(\tfrac12\)},
                        0.75/{\(\tfrac34\)}, 1/{\(1\)}} {
    \draw (\x,-0.012) -- (\x,0.012);
    \node[below] at (\x,-0.015) {\small \lab};
  }
  \node[below] at (0.125,-0.05) {\small \(A_1\)};
  \node[below] at (0.375,-0.05) {\small \(A_2\)};
  \node[below] at (0.625,-0.05) {\small \(A_3\)};
  \node[below] at (0.875,-0.05) {\small \(A_4\)};
  % reference line y = x
  \draw[exampleblue, thin] (0,0) -- (1,1);
  % step function
  \draw[highlightgreen, very thick] (0,0)    -- (0.25,0);
  \draw[highlightgreen, very thick] (0.25,0.25) -- (0.5,0.25);
  \draw[highlightgreen, very thick] (0.5,0.5)  -- (0.75,0.5);
  \draw[highlightgreen, very thick] (0.75,0.75) -- (1,0.75);
  % open/closed dots
  \foreach \x/\y in {0/0, 0.25/0.25, 0.5/0.5, 0.75/0.75} {
    \fill[white] (\x,\y) circle (0.012);
    \draw[highlightgreen] (\x,\y) circle (0.012);
  }
  \foreach \x/\y in {0.25/0, 0.5/0.25, 0.75/0.5, 1/0.75} {
    \fill[highlightgreen] (\x,\y) circle (0.012);
  }
\end{tikzpicture}
\end{center}
\end{example}

\begin{remark}
Letting the number of partition pieces grow to infinity, the
simple random variables \(X^{(2^m)}\) converge to the uniform
distribution on \((0,1]\). The mode of convergence will be made
precise in a later lecture.
\end{remark}

\subsection{Simple functions on a measure space}

The same definition works verbatim with \(\P\) replaced by a general
measure \(\mu\); the only thing we lose is the probabilistic reading
\(\P(X=x_i)\).

\begin{definition}{Simple function}{simple-function}
Let \((\Omega,\Fcal,\mu)\) be a measure space. A function
\(f\colon\Omega\to\R\) is \emph{simple} if there exist real numbers
\(x_1,\dots,x_p\) and sets \(B_1,\dots,B_p\in\Fcal\) such that
\[
f(\omega) \;=\; \sum_{i=1}^{p} x_i\,\indic[\omega\in B_i].
\]
The sets \(B_i\) need not be disjoint, but a representation with
disjoint \(B_i\) always exists by refining the family.
\end{definition}

\begin{example}[{Indicator of an interval}]
For \(\Omega=(0,1]\) with Borel \(\sigma\)-field and Lebesgue
measure, the function \(f(\omega)=\indic[\omega\in(0,1]]\) is simple:
it takes the value \(1\) on \((0,1]\) and \(0\) elsewhere.

\begin{center}
\begin{tikzpicture}[>=Stealth, scale=3]
  \draw[->] (-0.15,0) -- (1.25,0) node[right] {\small \(\omega\)};
  \draw[->] (0,-0.15) -- (0,1.25) node[above] {\small \(f(\omega)\)};
  \draw (-0.012,1) -- (0.012,1);
  \node[left] at (-0.015,1) {\small \(1\)};
  \draw (1,-0.012) -- (1,0.012);
  \node[below] at (1,-0.015) {\small \(1\)};
  \node[below left] at (0,0) {\small \(0\)};
  % zero parts
  \draw[highlightgreen, very thick] (-0.15,0) -- (0,0);
  \draw[highlightgreen, very thick] (1,0) -- (1.25,0);
  % top of indicator on (0,1]
  \draw[highlightgreen, very thick] (0,1) -- (1,1);
  % open at 0, closed at 1
  \fill[white] (0,1) circle (0.014);
  \draw[highlightgreen] (0,1) circle (0.014);
  \fill[highlightgreen] (1,1) circle (0.014);
  \fill[highlightgreen] (0,0) circle (0.014);
  \fill[white] (1,0) circle (0.014);
  \draw[highlightgreen] (1,0) circle (0.014);
\end{tikzpicture}
\end{center}
\end{example}

\begin{proposition}{Algebra of simple functions}{simple-algebra}
If \(f,g\colon\Omega\to\R\) are simple functions, then so are
\[
f+g,\qquad f\cdot g,\qquad \max\{f,g\},\qquad \min\{f,g\}.
\]
\end{proposition}

The integral of a simple function is what one would write down by
hand: value \(\times\) size of the level set, summed.

\begin{definition}{Integral of a simple function}{simple-integral}
For a simple function
\(f=\sum_{i=1}^{p} x_i\,\indic[\,\cdot\in B_i\,]\) on
\((\Omega,\Fcal,\mu)\) with disjoint \(B_i\), the \emph{integral} of
\(f\) with respect to \(\mu\) is
\[
\int f\,d\mu \;:=\; \sum_{i=1}^{p} x_i\,\mu(B_i).
\]
\end{definition}

\begin{remark}
For non-negative simple \(f,g\) and a scalar \(c>0\) the integral is
linear:
\(\int(f+g)\,d\mu=\int f\,d\mu+\int g\,d\mu\) and
\(\int cf\,d\mu=c\int f\,d\mu\). This is the seed from which the
Lebesgue integral on a much wider class of functions will grow in
the next lectures.
\end{remark}

\subsection{Measurable functions}

To go beyond finite-valued functions, we drop the requirement that
\(f\) take only finitely many values and ask instead that the
\emph{preimages} of nice sets be measurable.

\begin{definition}{Measurable function}{measurable-function}
Let \((\Xset,\Xcal)\) and \((\Yset,\Ycal)\) be measurable
spaces. A function \(f\colon\Xset\to\Yset\) is
\emph{\(\Xcal/\Ycal\)-measurable} if
\[
f^{-1}(B) \;\in\; \Xcal \qquad \text{for every } B\in\Ycal,
\]
where \(f^{-1}(B)=\{x\in\Xset : f(x)\in B\}\).
\end{definition}

\begin{remark}
When \((\Yset,\Ycal)=(\R,\Bcal(\R))\) we call \(f\)
\emph{Borel measurable}. Replacing \(\Bcal(\R)\) by the Lebesgue
\(\sigma\)-field \(\Mcal_\lambda(\R)\) gives the strictly larger
class of \emph{Lebesgue measurable} functions. Measurable random
variables on a probability space are exactly measurable functions
\(X\colon\Omega\to\R\).
\end{remark}

\begin{remark}
Inverse images preserve set operations:
\[
f^{-1}\!\Bigl(\,\bigcup_i A_i\Bigr) \;=\; \bigcup_i f^{-1}(A_i),
\qquad
f^{-1}(\Yset\setminus A) \;=\; \Xset\setminus f^{-1}(A).
\]
A useful corollary: \(\{f^{-1}(B):B\in\Ycal\}\) is itself a
\(\sigma\)-field on \(\Xset\), and \(f\) is measurable iff this
\(\sigma\)-field is contained in \(\Xcal\). To prove two
\(\sigma\)-fields are equal, it suffices (as always) to verify both
inclusions \(A\subseteq B\) and \(B\subseteq A\).
\end{remark}

\subsection{Useful facts about measurability}

The following stability properties are the working toolkit. They say,
roughly, that measurability survives every reasonable operation one
might want to perform.

\begin{proposition}{Generators suffice}{generators-suffice}
If \(\Ycal=\sigma(\Acal)\) for some collection \(\Acal\), then
\(f\) is \(\Xcal/\Ycal\)-measurable iff
\(f^{-1}(A)\in\Xcal\) for every \(A\in\Acal\). In particular,
since \(\Bcal(\R)\) is generated by the half-lines
\(A_t=(-\infty,t]\) for \(t\in\R\), a function
\(f\colon\Xset\to\R\) is Borel measurable iff
\[
\{x\in\Xset : f(x)\le t\} \;\in\; \Xcal \qquad \text{for every } t\in\R.
\]
\end{proposition}

\begin{proposition}{Indicator functions}{indicator-measurable}
For any \(A\in\Xcal\), the indicator
\(f(x)=\indic[x\in A]\) is measurable. The \(\sigma\)-field
generated by \(f^{-1}\) is simply
\(\{\emptyset,A,A^c,\Xset\}\subseteq\Xcal\).
\end{proposition}

\begin{proposition}{Algebra of measurable functions}{measurable-algebra}
For measurable \(f,g\colon\Xset\to\R\), the functions \(f+g\) and
\(fg\) are measurable.
\end{proposition}

\begin{proposition}{Pointwise limits of measurable functions}{measurable-limits}
For a sequence \(\{f_i\}_{i=1}^{\infty}\) of measurable functions
from \(\Xset\) to \(\R\), each of
\[
\sup_i f_i,\quad \inf_i f_i,\quad \limsup_i f_i,\quad \liminf_i f_i
\]
is measurable, and \(\lim_i f_i\) is measurable wherever it exists.
The key identity is
\[
\{x : \sup_i f_i(x) \le t\} \;=\; \bigcap_i \{x : f_i(x)\le t\},
\]
a countable intersection of measurable sets.
\end{proposition}

\begin{proposition}{Continuous functions are Borel measurable}{continuous-measurable}
Every continuous \(f\colon\R\to\R\) (or, more generally, between
topological spaces equipped with their Borel \(\sigma\)-fields) is
Borel measurable. The reason: preimages of open sets under
continuous maps are open, and open sets generate the Borel
\(\sigma\)-field.
\end{proposition}

\begin{remark}
Given any collection \(\{f_i\}_{i\in I}\) of functions
\(f_i\colon\Xset\to\Yset\), one can always equip \(\Xset\) with the
smallest \(\sigma\)-field that makes every \(f_i\) measurable,
namely \(\sigma(\{f_i^{-1}(B):i\in I,\,B\in\Ycal\})\). This is
the canonical way to \emph{manufacture} measurability rather than
verify it.
\end{remark}

\subsection{Almost everywhere}

A function-level analogue of ``measure-zero exception'' lets us
identify functions that disagree only on a negligible set.

\begin{definition}{Almost everywhere / almost surely}{ae}
Let \((\Omega,\Fcal,\mu)\) be a measure space and
\(f,g\colon\Omega\to\R\). We say \(f=g\) \emph{almost everywhere}
(written \(f=g\) a.e.) if
\[
\mu\bigl(\{\omega\in\Omega : f(\omega)\neq g(\omega)\}\bigr) \;=\; 0.
\]
On a probability space the same notion is called \emph{almost
surely} (a.s.), or equivalently \emph{with probability one} (wp1).
\end{definition}

\begin{example}[{Dirichlet-style equality}]
On \(\bigl((0,1],\Bcal((0,1]),\lambda\bigr)\), set \(f(t)=0\) for
all \(t\in(0,1]\), and
\[
g(t) \;=\; \begin{cases}
0 & t\in(0,1]\setminus\Q,\\
1 & t\in(0,1]\cap\Q.
\end{cases}
\]
Then \(f=g\) almost everywhere: the disagreement set is
\((0,1]\cap\Q\), which is countable. Enumerate it as
\(\{q_1,q_2,\dots\}\) and cover \(q_m\) by the half-open interval
\((q_m-2^{-m},\,q_m+2^{-m+1}]\); the union of these intervals has
Lebesgue measure at most \(\sum_m 3\cdot 2^{-m}<\infty\), and a
sharper argument gives \(\lambda\bigl((0,1]\cap\Q\bigr)=0\).
\end{example}
