Simplification of logical functions with application to circuits