OPNF perf improvements and bug fixes

The correctness issues are for the removeUnreachableBasesAndInputs post-optimization. The performance improvements may be more widely applicable.

The changes have been thoroughly tested (unless I missed something in the move back from the Alloy codebase). The main question here is whether the Pair class is reasonable to add.