HDI function from the book
new