Generalize and refactor simpl
Common subexpression elimination