code for building and manipulating tree IPMs (or IBMs)