Exercise 2.17
Solution for exercise 2.18