(implications)
return res
deduce all implications

       Description by example
       ----------------------

       given set of logic rules:

         a -> b
         b -> c

       we deduce all possible rules:

         a -> b, c
         b -> c


       implications: [] of (a,b)
       return:       {} of a -> set([b, c, ...])
deduce all implications
deduce all implications
def deduce_alpha_implications(implications):
    """deduce all implications

       Description by example
       ----------------------

       given set of logic rules:

         a -> b
         b -> c

       we deduce all possible rules:

         a -> b, c
         b -> c


       implications: [] of (a,b)
       return:       {} of a -> set([b, c, ...])
    """
    res = defaultdict(set)
    for a, b in implications:
        if a == b:
            continue    # skip a->a cyclic input

        res[a].add(b)

        # (x >> a) & (a >> b) => x >> b
        for fact in res:
            implied = res[fact]
            if a in implied:
                implied.add(b)

        # (a >> b) & (b >> x) => a >> x
        if b in res:
            res[a] |= res[b]

    # Clean up tautologies and check consistency
    for a, impl in res.items():
        impl.discard(a)
        na = Not(a)
        if na in impl:
            raise ValueError(
                'implications are inconsistent: %s -> %s %s' % (a, na, impl))

    return res
def deduce_alpha_implications ( implications ) : res = defaultdict ( set ) for a , b in implications : if a == b : continue # skip a->a cyclic input res [ a ] . add ( b ) # (x >> a) & (a >> b) => x >> b for fact in res : implied = res [ fact ] if a in implied : implied . add ( b ) # (a >> b) & (b >> x) => a >> x if b in res : res [ a ] |= res [ b ] # Clean up tautologies and check consistency for a , impl in res . items ( ) : impl . discard ( a ) na = Not ( a ) if na in impl : raise ValueError ( 'implications are inconsistent: %s -> %s %s' % ( a , na , impl ) ) return res