Show that there are $(\alpha_m)_{m\in\mathbb{N}}$ and $(A_m)_{m\in\mathbb{N}}$ such that $f(x) = \sum_{m=1}^\infty\alpha_m\chi_{A_m}(x)$ Assignment:

Let $f: \mathbb{R}^n \rightarrow [0,\infty]$ be measurable. Show that, there is non-negative sequence $(\alpha_m)_{m\in\mathbb{N}} \subset [0,\infty)$ and a sequence $(A_m)_{m\in\mathbb{N}}$ of measurable subsets $A_m \subset \mathbb{R}^n$ such that
  $$f(x) = \sum_{m=1}^\infty\alpha_m\chi_{A_m}(x)$$

I understand the idea behind the simple functions but I am unsure on how to begin.
I'd appeciate any help.
 A: This can be done in a rather elegant way. The primary thing to note is this means that the set of $A_m$ such that $x\in A_m$ must entirely determine the value of $f(x)$. Suppose we wrote out a sequence, $(k_m)_{m\in\mathbb N}$ defined by
$$k_m=\chi_{A_m}(x)$$
which basically just lists what sets $x$ is a part of. We would then have that $\sum_m \alpha_mk_m=f(x)$. So we are trying to, from a sequence of bits, determine a number. So, letting the sum run over all of $\mathbb{Z}$ instead of just $\mathbb{N}$ (which is easily justified), we could set $\alpha_m=2^m$ and then we have
$$\sum_{m\in\mathbb Z}2^mk_m=f(x)$$
meaning that $k_m$ would be exactly the binary representation of $f(x)$. Thus, if we define $A_m$ to be the set of $x$ such that $f(x)$ has a $1$ at the $m^{th}$ digit of its binary expansion, we have put $f$ in the desired form. Moreover, we can write
$$A_m=f^{-1}\left[\bigcup_{i=0}^{\infty}[2^{m}(2i+1),2^{m}(2i+2))\right]$$
where the inner set is measurable, implying so is the preimage $A_m$.
