use rewriting to see if expr becomes simpler

This isn't used unconditionally since the user probably doesn't want
the result rewritten in terms of exp. The result is only taken if all
the exp that were introduced are removed after factoring.