An initial (unproven) implementation of rewrite.