Some more optimizations in the logic module

- Don't recompute the total on a slice (this may be a bad idea, "special cases
are not special enough to break the rules")
- Cache the hash. This makes a big difference in the non-recursive BDD
algorithm.