Conditional expectation and measurable functions I have  one example here with solution, but I don't understand it: 
Suppose that we have $\Omega=[0,1], \mathscr F= \mathscr B_{[0,1]}$ ( $\sigma$ -algebra of Borel-measurable subsets of [0,1] ) and $P$ is Lebesgue measure on $\mathscr F$. Random variable $Y$ is defined as follows: 
$Y(\omega)=
\begin{cases}
    2, &    0 \leq \omega < \frac{1}{3} \\
    5, &   \frac{1}{3} \leq \omega \leq 1
  \end{cases} $
 . Then  $ \mathscr{D}= \sigma\{Y\}=\{\emptyset, \Omega, [0,\frac{1}{3}),[\frac{1}{3},1]\}$.  The only $\mathscr D $-measurable functions are step-functions with one step in  $\frac{1}{3}$. Let $ X(\omega)=\omega $, for all $\omega \in \Omega$.  It is easy to show that:
$ E(X|Y)(\omega)=  \begin{cases}
    \frac{1}{6}, &    0 \leq \omega < \frac{1}{3} \\
   \frac{2}{3},  &   \frac{1}{3} \leq \omega \leq 1
  \end{cases} $
My questions are:
1) How do we calculate this conditional expectation? 
2) Why are the only $\mathscr D $-measurable functions step-functions with one step in  $\frac{1}{3}$? Can someone give me an example of one such function? 
3) How do we know what $\sigma \{Y\}$ is?
 A: By definition $E[X\mid\mathscr B]$ is measurable wrt. $\mathscr B$ and for any $A\in \mathscr B$: $\int_{A}E[X\mid Y]\ dP=\int_AXdP.$

We have  $ \mathscr{D}= \sigma\{Y\}=\left\{\emptyset, \Omega, [0,\frac{1}{3}),[\frac{1}{3},1]\right\}$. For the two interesting sets 
$$\int_{[\frac{1}{3},1]}E[X\mid Y]\ dP=\int_{[\frac{1}{3},1]}\omega\ dP=\frac12\left[\omega^2\right]_{\frac13}^{1}=\frac49$$
and
$$\ \int_{[0,\frac{1}{3})}E[X\mid Y]\ dP=\int_{[0,\frac{1}{3})}\omega\ dP=\frac12\left[\omega^2\right]_{0}^{\frac13}=\frac1{18}.$$
Since $E[X\mid Y](\omega)$ is $\mathscr D$ measurable it has to be constant over the two sets. 
So, $$\int_{0}^{\frac13}E [X\mid Y]\ dP=c_{[0,\frac13)}\frac13=\frac1 {18}$$
Thus
$$c_{[0,\frac13)}=\frac3 {18}=\frac16. $$
One can compute the value for the other set.

How do we know that the $\sigma$-algebra generated by  $Y$ is $\mathscr D$? We use the definition of the measurability of  a function: $X$ is $\mathscr D$ measurable if for any $x\in[0,1]$ the set 
$$A_x=\left\{\omega \mid Y(\omega)<x\right\}\in\mathscr D.$$
If $x<2$ then $A_x=\emptyset$, if $2< x\le5$, then $A_x=[0,\frac13)$, if $x> 5$ then $A_x=\Omega=[0,1].$ Since $\mathscr D$ is a $\sigma$-algebra $[0,\frac13]^c=(\frac13,1]$ has to be in $\mathscr D$.

Why are the $\mathscr D$ measurable function step functions? Take a look at the previous paragraph again and ask the question again.

Note to the comment
The density sought is a function whose integral over an interval gives the probability of $X$'s falling in that interval. So, we have
$$f_X(x)=1$$
over $[0,1]$, $0$ otherwise. But this $[0,1]$ is not $\Omega$, this $[0,1]$ is the range of $X(\omega)$ whose domain is $\Omega=[0,1]$.
$$P(X\in [a,b])=P(\{\omega\mid a\le X(\omega)\le b\})=b-a=\int_a^b 1 \ dx=b-a.$$
