def distribute_not(domain):
 result = []
 stack = [False]
 for token in domain:
  negate = stack.pop()
  if is_leaf(token):
   if negate:
    (left, operator, right) = token
    if (operator in TERM_OPERATORS_NEGATION):
     result.append((left, TERM_OPERATORS_NEGATION[operator], right))
    else:
     result.append(NOT_OPERATOR)
     result.append(token)
   else:
    result.append(token)
  elif (token == NOT_OPERATOR):
   stack.append((not negate))
  elif (token in DOMAIN_OPERATORS_NEGATION):
   result.append((DOMAIN_OPERATORS_NEGATION[token] if negate else token))
   stack.append(negate)
   stack.append(negate)
  else:
   result.append(token)
 return result

def distribute_not ( domain ) : result = [ ] stack = [ False ] for token in domain : negate = stack . pop ( ) if is_leaf ( token ) : if negate : ( left , operator , right ) = token if ( operator in TERM_OPERATORS_NEGATION ) : result . append ( ( left , TERM_OPERATORS_NEGATION [ operator ] , right ) ) else : result . append ( NOT_OPERATOR ) result . append ( token ) else : result . append ( token ) elif ( token == NOT_OPERATOR ) : stack . append ( ( not negate ) ) elif ( token in DOMAIN_OPERATORS_NEGATION ) : result . append ( ( DOMAIN_OPERATORS_NEGATION [ token ] if negate else token ) ) stack . append ( negate ) stack . append ( negate ) else : result . append ( token ) return result
distribute any ! domain operators found inside a normalized domain .