Switch to debruijn indices, genericize sub/lub/glb

More refactoring in support of HRTB. There should be no change in functionality from these changes.

r? @pnkfelix 
You're right, I've been annoyed several times at having that big comment in the file. i'll make a proper directory.