refactor IntegerExp

Eliminates duplicate code, and some dead code. Simplifies the logic. Makes assumptions explicit with assert. Steps towards making IntegerExp copy-on-write. No semantic changes.