circuit rewriting