Find E[e^x] by finding cdf and differentiating I am trying to understand the solution in my textbook for the following exercise:
The density function of X is given by
\begin{equation}
f(x) = 
\left\{
    \begin{array}{lr}
        1 & \text{if } 0 \leq x \leq 1\\
        0 & \text{otherwise}
    \end{array}
\right\}
\end{equation}
Find E[e^X]
Solution:
Let $Y = e^X$. We start by determining $F_Y$, the cdf of Y.
Now for $ 1 \leq x \leq e$,
$F_Y(x) = P\{Y \leq x\} = P\{e^X \leq x\} = P\{X \leq log(x)\} = (\int_{0}^{log(x)} f(y) \,dy)$ = log(x)$
By differentiating $F_Y$ we get the pdf of Y:
$f_Y(x) = 1/x$
Hence,
$E[e^X] = E\{Y\} = \int_{- \infty}^{\infty} xf_Y(x) dx) = \int_{1}^{e}\,dx)$
I don't fully understand why we have to determine the cdf and then differentiate the cdf in order to get $E[e^X]$. Why don't we just use the rule
$E[g(x)] = \int_{- \infty}^{\infty} g(y)f(y)\mathrm dy$
I have a suspicion that the exercise is still solveable that way, but I still want to know why the book's solution works also.
 A: 
I don't fully understand why we have to determine the cdf

You don't have to do so.  You may do so.
You have established that
$$\begin{align} f_Y(y) &=\dfrac{\mathrm d~~}{\mathrm d y}\mathsf P(X\leq \ln y)\\ &= \dfrac{\mathrm d ~~}{\mathrm d y}\int_{0}^{\ln y} f_X(x)\,\mathrm d x\\&= \dfrac 1y f_X(\ln y)\\[2ex] &= \dfrac 1y\mathbf 1_{(1\leq y\leq \mathrm e)}\end{align}$$
So... by a change of variables: $$\begin{align} \mathsf E(\mathrm e^X) &= \int_\Bbb R \mathrm e^xf_X(x)\mathrm d x \\&= \int_\Bbb R 
 \mathrm e^{\ln y}~f_X(\ln y)\cdot\dfrac{\mathrm d \ln y}{\mathrm d y}\,\mathrm d y\\&=\int_\Bbb R y~f_Y(y)\,\mathrm d y \\&= \mathsf E(Y)\\[2ex] &=\int_1^\mathrm e 1\,\mathrm dy\\&=(\mathrm e-1)\end{align}$$

I agree it would be simpler to use the Law of Unconscious Statistician to evaluate $$\begin{align}\mathsf E(\mathrm e^X) &=\int_\Bbb R \mathrm e^x f_X(x)\,\mathrm d x\\ &=\int_0^1 \mathrm e^x\,\mathrm d x \\&=(\mathrm e^1-\mathrm e^0)\end{align}$$
But the LoUS is basically proven by change of variable theorems.
