solution for Exercise 3.1