def rules_2prereq(rules):
 prereq = defaultdict(set)
 for ((a, _), impl) in rules.items():
  if isinstance(a, Not):
   a = a.args[0]
  for (i, _) in impl:
   if isinstance(i, Not):
    i = i.args[0]
   prereq[i].add(a)
 return prereq

def rules_2prereq ( rules ) : prereq = defaultdict ( set ) for ( ( a , _ ) , impl ) in rules . items ( ) : if isinstance ( a , Not ) : a = a . args [ 0 ] for ( i , _ ) in impl : if isinstance ( i , Not ) : i = i . args [ 0 ] prereq [ i ] . add ( a ) return prereq
build prerequisites table from rules description by example given set of logic rules: a -> b .