The complexity and applications of circuit minimization