We have introduced the structure of σ-algebras. As part of understanding the structure, we should understand which functions on sets respect this structure. These are the measurable functions, and they play a role in measure theory analogous to the role played by continuous functions in topology. Their main importance to us is that they are the functions we will be able to integrate.
Let $X$ and $Y$ be sets. Suppose $\mathscr{B}$ is a σ-algebra on $X$ and $\mathscr{C}$ is a σ-algebra of subsets of $Y$. A function $f : X \to Y$ is $(\mathscr{B},\mathscr{C})$ measurable if $f^{-1}(C) \in \mathscr{B}$ for every $C \in \mathscr{C}$.
Fortunately, in order to check that a function is measurable, it suffices to verify that $f^{-1}(C)$ belongs to $\B$ for all sets $C$ in a generating set for the σ-algebra.
Let $\mathscr{B}$ and $\mathscr{C}$ be σ-algebras on sets $X$ and $Y$ respectively. If $\mathscr{C}$ is generated by a collection $\mathcal{F} \subset \P(Y)$ and $f^{-1}(F) \in \mathscr{B}$ for every $F \in \mathcal{F}$ then $f$ is $(\mathscr{B},\mathscr{C})$ measurable.
Consider the collection \[ \mathscr{G} = \{ E \subset Y : f^{-1}(E) \in \B \} \] and note that, by hypothesis, it contains $\mathcal{F}$. It suffices to verify that $\mathscr{G}$ contains $\mathscr{C}$. We are going to check that $\mathscr{G}$ is a σ-algebra on $Y$. It will then immediately contain $\mathscr{C}$ because $\mathscr{C}$ is the smallest σ-algebra that contains $\mathcal{F}$. We will check the defining properties of a σ-algebra.
It is immediate that $Y \in \mathscr{G}$ because $f^{-1}(Y) = X \in \B$. Also, if $E \in \mathscr{G}$ then \[ f^{-1}(Y \setminus E) = f^{-1}(Y) \setminus f^{-1}(E) = X \setminus f^{-1}(E) \] belongs to $\B$ because complements of sets from $\B$ belong to $\B$. Finally, if $E_1,E_2,\dots$ all belong to $\mathscr{G}$ then \[ f^{-1} \left( \, \bigcup_{n=1}^\infty E_n \right) = \bigcup_{n=1}^\infty f^{-1}(E_n) \] belongs to $\B$ because $\B$ is a σ-algebra.▮
We are most interested in functions from a given set $X$ into the real line, partly because we wish to integrate such functions. The real line has a distinguished σ-algebra $\borel(\R)$. Given a measurable space $(X,\B)$ we would therefore like to be able to determine whether a function $f : X \to \R$ is $(\B,\borel(\R))$ measurable.
Fix a measurable space $(X,\B)$ and a function $f : X \to \R$. If $f^{-1}(U) \in \B$ for every open set $U \subset \R$ then $f$ is $(\B,\borel(\R))$ measurable.
The Borel σ-algebra is generated by the open sets. By the previous theorem $f$ is therefore $(\B,\borel(\R))$ measurable if $f^{-1}(U)$ belongs to $\B$ for every open set $U \subset \R$. But this is precisely what is hypothesized. ▮
From our understanding of open sets we can give more explicit criteria for $(\B,\borel(\R))$ measurability.
Fix a measurable space $(X,\B)$. A function $f : X \to \R$ is $(\B,\borel(\R))$ measurable whenever any of the following is true.
By the previous proposition it suffices in each case to deduce that $f^{-1}(U)$ belongs to $\B$ whenever $U \subset \R$ is open. Since every open set is a countable union \[ U = \bigcup_{n=1}^\infty J_n \] of open intervals and \[ f^{-1}(U) = \bigcup_{n=1}^\infty f^{-1}(J_n) \] it suffices to prove that $f^{-1}(J) \in \B$ whenever $J \subset \R$ is an open interval.
The first condition tells $f^{-1}(J) \in \B$ for finite open intervals. As \[ (a,\infty) = \bigcup_{n=1}^\infty (a,a+n) \] and \[ (-\infty,a) = \bigcup_{n=1}^\infty (a-n,a) \] we get what we want by taking inverse images.
The second condition says $f^{-1}(J) \in \B$ whenever $J$ is a half-infinite open interval. Writing \[ (a,b) = \bigcap_{n=1}^\infty (a,\infty) \cap \R \setminus (b+\tfrac{1}{n},\infty) \] so that \[ f^{-1}(a,b) = \bigcap_{n=1}^\infty f^{-1}(a,\infty) \cap (X \setminus f^{-1}(b+\tfrac{1}{n},\infty)) \] gives $f^{-1}(J) \in \B$ for every finite open interval, and we can appeal to the first criterion.▮
Fix a set $X$ and $A \subset X$. The indicator function of $A$ is the function \[ 1_A(x) = \begin{cases} 1 & x \in A \\ 0 & x \notin A \end{cases} \] from $X$ to $\R$.
Fix a measurable space $(X,\B)$. For every $B \in \mathscr{B}$ the function $1_B : X \to \R$ is $(\B,\P(\R))$ measurable.
Fix $E \subset \R$. The set $(1_B)^{-1}(E)$ can only be $\emptyset$, $B$, $X \setminus B$ or $X$ according to which of $0,1$ belong to $E$. All four sets belong to $\mathscr{B}$ because $B \in \mathscr{B}$. Therefore $1_B$ is $(\B,\P(\R))$ measurable.▮
Fix a measurable space $(X,\B)$. A function $f : X \to \R$ is simple if there are sets $B(1),\dots,B(k)$ in $\B$ and numbers $a_1,\dots,a_k$ such that $f = a_1 1_{B(1)} + \cdots + a_k 1_{B(k)}$.
The expression \[ a_1 1_{B(1)} + \cdots + a_k 1_{B(k)} \] is not unique. Indeed, when $B(1)$ and $B(2)$ are disjoint we can write \[ 1_{B(1)} + 1_{B(2)} = 1_{B(1) \cup B(2)} \] and when $B(1) \cap B(2)$ is non-empty we can write \[ a_1 1_{B(1)} + a_2 1_{B(2)} = a_1 1_{B(1) \setminus B(2)} + (a_1 + a_2) 1_{B(1) \cap B(2)} + a_2 1_{B(2) \setminus B(1)} \] however, it is always possible to write a simple function in the form \[ a_1 1_{B(1)} + \cdots + a_k 1_{B(k)} \] where the sets $B(1),\dots,B(k)$ are disjoint.
A function $f : X \to \R$ is simple if and only if its range is finite.
If $f$ can be written as \[ a_1 1_{B(1)} + a_2 1_{B(2)} + \cdots + a_k 1_{B(k)} \] then its range is finite, as $f$ can only take values obtained from adding together at most $k$ of the terms $a_1,\dots,a_k$. On the other hand, if the only values $f$ takes are $c_1,\dots,c_k$ then \[ f = c_1 1_{f^{-1}(\{c_1\})} + \cdots + c_k 1_{f^{-1}(\{c_k\})} \] expresses $f$ as a simple function.▮