Notes and code for Chapter 6