Measurability of one Random Variable with respect to Another After several hours of struggling, I've been unable to solve the following problem

Let $X,Y: (\Omega, \mathcal{S}) \rightarrow (\mathbb{R}, \mathcal{R})$ where $\mathcal{R}$ are the Borel Sets for the Reals.  Show that $Y$ is measurable with respect to $\sigma(X) = \{ X^{-1}(B) : B \in \mathcal{R} \}$ if and only if there exists a function $f: \mathbb{R} \rightarrow \mathbb{R}$ such that $Y(\omega) =
f(X(\omega))$ for all $\omega \in \Omega$.

Firstly, I am assuming that for $Y$ to be measurable with respect to $\sigma(X)$ means that $\forall B \in \mathcal{R} \quad Y^{-1}(B) \in \sigma(X)$.  The text (Probability: Theory and Examples) failed to define the phrase.
The problem following it begins describing a constructive proof where we split $Y$'s range into segments of increasingly fine granularity ( i.e. $\left [\frac{m}{2^{n}}, \frac{m+1}{2^{n}}\right)$ for each $m \in \mathbb{N}$ ) and define a function between $X$'s range and $Y$'s for each level of granularity ( i.e. by noting that $Y^{-1}\left(\left[\frac{m}{2^{n}}, \frac{m+1}{2^{n}}\right)\right)$ = $X^{-1}(B_{n,m})$ for some $B_{n,m} \in \mathcal{R}$ and defining $f_{n}(x) = \frac{m}{2^{n}}$ when $x \in B_{n,m}$ ), then need to show that $Y$ is equal to this function in the limit.
Unfortunately I can't even make sense of how each of these functions are defined, much less use them.  In particular, I don't see how each $x \in \mathbb{R}$ maps to a single $B_{n,m}$, which would mean we would need to define $f_{n}$ via the infimum of all available values.  Take the example that $X(\omega) = 0$ for all $\omega$.
As this constructive proof is a separate problem, there must then exist a non-constructive one as well which is perhaps more concise.  I have been unable to make any headway in that respect.
 A: An abstract approach works in the opposite direction.
Start with all bounded, measurable functions of $X$, that is, let 
 ${\cal K}={\cal H}=\{f(X): f\in b{\mathcal{R}}\}$ where
$b{\mathcal{R}}$ refers to all bounded, Borel-measurable 
$f: (\mathbb{R},\mathcal{R}) \rightarrow (\mathbb{R},\mathcal{R}).$ 
Clearly ${\cal K}$ is multiplicative, and ${\cal H}$ is a vector space
that contains the constant function $1_\Omega$. To show that ${\cal H}$ is 
a monotone vector space, suppose $0\leq f_n(X)\uparrow Y\leq M$ for
some constant $M$. Replace $f_n$ by $g_n:=(f_n)_+\wedge M$ and we still 
have $0\leq g_n(X)\uparrow Y\leq M$. Set $g=\limsup_n g_n$ so that $g\in b{\mathcal{R}}$
and $$Y(\omega)=\limsup_n\ g_n(X(\omega))=g(X(\omega)).$$
This shows that ${\cal H}$ is a monotone vector space so we can invoke the 
functional Monotone Class Theorem and conclude that ${\cal H}$ contains
every bounded function measurable with respect to $\sigma({\cal K})=\sigma(X)$.
That is, every bounded $Y$ that is measurable with respect to $\sigma(X)$ can 
be expressed as a measurable function of $X$. 
It is now easy to extend this to non-bounded $Y$. 
A: Here is my favorite proof.
You probably know the following fact:

If $(\Omega, \mathcal{F})$ is a measurable space and $Y : \Omega \to \mathbb{R}$ is a measurable function, then there exist measurable simple functions $Y_n : \Omega \to \mathbb{R}$ with $Y_n \to Y$ pointwise.

Recall that a simple function (or simple random variable) is one of the form $Z = \sum_{i=1}^m a_i 1_{A_i}$, where $A_i \in \mathcal{F}$.
Now apply this fact to the measurable space $(\Omega, \sigma(X))$.  We get that $Y = \lim Y_n$, where $Y_n = \sum_{i=1}^{m_n} a_{i,n} 1_{A_{i,n}}$.  But $A_{i,n} \in \sigma(X)$, which means $A_{i,n} = X^{-1}(B_{i,n})$ for some Borel sets $B_{i,n}$.  So if we set $f_n = \sum a_{i,n} 1_{B_{i,n}}$, we actually have $Y_n = f_n(X)$.
We'd like to just say: let $f = \lim f_n$ and then $Y = f(X)$.  There's a slight problem in that each $f_n$ could do something bizarre with values that are not in the range of $X$, and they need not converge on those values.  But there's a simple workaround: set $f = \limsup f_n$.  Of course $f$ is measurable, and we have $f(X) = \limsup f_n(X) = \limsup Y_n = Y$.

To explain the "something bizarre" comment: the issue is that the sets $B_{i,n}$ are not uniquely determined.  Let's take a trivial example: suppose $\Omega = \{\omega_0\}$ contains only one outcome, so all the random variables are constants.  Let's say $Y_n = Y = 17$ for all $n$, and $X = 42$.  So for all $n$ we have $m_n = 1$, $a_{1,n} = 17$, and $A_{i,n} = \Omega = \{\omega_0\}$.  We will then have $A_{1,n} = X^{-1}(B_{1,n})$ for any Borel set $B_{1,n} \subset \mathbb{R}$ that contains $42$.  To be perverse, take $B_{1,n} = \{42\}$ when $n$ is odd, and $B_{1,n} = \mathbb{R}$ when $n$ is even.  This leads to
$$f_{n}(x) = \begin{cases} 17, & x = 42 \\ 0, & x \ne 42 \end{cases}, \quad \text{$n$ odd}$$
and $f_{n}(x) \equiv 17$ when $n$ is even.  For any $x \ne 42$, the sequence $f_{n}(x)$ oscillates between 0 and 17, and so $\lim f_n(x)$ does not exist for such $x$.  So it does not make sense to say "let $f(x) = \lim f_n(x)$ for all $x$".
But $\limsup f_n(x) = 17$ does exist for all $n$, and setting $f(x) = \limsup f_n(x)$ yields $f(x) \equiv 17$.  The desired conclusion $f(X) = Y$ still holds.
Taking $f(x) = \liminf f_n(x)$ would also work, and would give $f(42) = 17$, $f(x)=0$ otherwise.  We would still have $f(X) = Y$.  Here, we frankly don't care what $f(x)$ is for any $x \ne 42$; we just need to make sure it is something that results in $f$ being everywhere defined and measurable.
