See lecture notes in the assignment page.