add implementation of example 4.1 in Ziheng Yang's 2014 book