Expectation of a function of a random variable