graph rewrite