def is_nnf(expr, simplified=True):
 expr = sympify(expr)
 if is_literal(expr):
  return True
 stack = [expr]
 while stack:
  expr = stack.pop()
  if (expr.func in (And, Or)):
   if simplified:
    args = expr.args
    for arg in args:
     if (Not(arg) in args):
      return False
   stack.extend(expr.args)
  elif (not is_literal(expr)):
   return False
 return True

def is_nnf ( expr , simplified = True ) : expr = sympify ( expr ) if is_literal ( expr ) : return True stack = [ expr ] while stack : expr = stack . pop ( ) if ( expr . func in ( And , Or ) ) : if simplified : args = expr . args for arg in args : if ( Not ( arg ) in args ) : return False stack . extend ( expr . args ) elif ( not is_literal ( expr ) ) : return False return True
checks if expr is in negation normal form .