'Compile rules into internal lookup tables'

def __init__(self, rules):

    if isinstance(rules, string_types):
        rules = rules.splitlines()
    P = Prover()
    for rule in rules:
        (a, op, b) = rule.split(None, 2)
        a = Logic.fromstring(a)
        b = Logic.fromstring(b)
        if (op == '->'):
            P.process_rule(a, b)
        elif (op == '=='):
            P.process_rule(a, b)
            P.process_rule(b, a)
        else:
            raise ValueError(('unknown    op    %r' % op))
    self.beta_rules = []
    for (bcond, bimpl) in P.rules_beta:
        self.beta_rules.append((set((_as_pair(a) for a in bcond.args)), _as_pair(bimpl)))
    impl_a = deduce_alpha_implications(P.rules_alpha)
    impl_ab = apply_beta_to_alpha_route(impl_a, P.rules_beta)
    self.defined_facts = set((_base_fact(k) for k in impl_ab.keys()))
    full_implications = defaultdict(set)
    beta_triggers = defaultdict(set)
    for (k, (impl, betaidxs)) in impl_ab.items():
        full_implications[_as_pair(k)] = set((_as_pair(i) for i in impl))
        beta_triggers[_as_pair(k)] = betaidxs
    self.full_implications = full_implications
    self.beta_triggers = beta_triggers
    prereq = defaultdict(set)
    rel_prereq = rules_2prereq(full_implications)
    for (k, pitems) in rel_prereq.items():
        prereq[k] |= pitems
    self.prereq = prereq
