Title: Dag representation and optimization of rewriting