def to_cnf(expr, simplify=False):
 expr = sympify(expr)
 if (not isinstance(expr, BooleanFunction)):
  return expr
 if simplify:
  return simplify_logic(expr, 'cnf', True)
 if is_cnf(expr):
  return expr
 expr = eliminate_implications(expr)
 return distribute_and_over_or(expr)

def to_cnf ( expr , simplify = False ) : expr = sympify ( expr ) if ( not isinstance ( expr , BooleanFunction ) ) : return expr if simplify : return simplify_logic ( expr , 'cnf' , True ) if is_cnf ( expr ) : return expr expr = eliminate_implications ( expr ) return distribute_and_over_or ( expr )
convert a propositional logical sentence s to conjunctive normal form .