def pl_fc_entails(KB, q):
    """Use forward chaining to see if a PropDefiniteKB entails symbol q.
    [Fig. 7.15]
    >>> pl_fc_entails(Fig[7,15], expr('Q'))
    True
    """
    count = dict([(c, len(conjuncts(c.args[0]))) for c in KB.clauses
                                                 if c.op == '>>'])
    inferred = DefaultDict(False)
    agenda = [s for s in KB.clauses if is_prop_symbol(s.op)]
    while agenda:
        p = agenda.pop()
        if p == q: return True
        if not inferred[p]:
            inferred[p] = True
            for c in KB.clauses_with_premise(p):
                count[c] -= 1
                if count[c] == 0:
                    agenda.append(c.args[1])
    return False
def pl_fc_entails(KB, q):
    """Use forward chaining to see if a PropDefiniteKB entails symbol q.
    [Fig. 7.15]
    >>> pl_fc_entails(Fig[7,15], expr('Q'))
    True
    """
    count = dict([(c, len(conjuncts(c.args[0]))) for c in KB.clauses
                                                 if c.op == '>>'])
    inferred = DefaultDict(False)
    agenda = [s for s in KB.clauses if is_prop_symbol(s.op)]
    while agenda:
        p = agenda.pop()
        if p == q: return True
        if not inferred[p]:
            inferred[p] = True
            for c in KB.clauses_with_premise(p):
                count[c] -= 1
                if count[c] == 0:
                    agenda.append(c.args[1])
    return False
def pl_fc_entails ( KB , q ) : count = dict ( [ ( c , len ( conjuncts ( c . args [ 0 ] ) ) ) for c in KB . clauses if c . op == '>>' ] ) inferred = DefaultDict ( False ) agenda = [ s for s in KB . clauses if is_prop_symbol ( s . op ) ] while agenda : p = agenda . pop ( ) if p == q : return True if not inferred [ p ] : inferred [ p ] = True for c in KB . clauses_with_premise ( p ) : count [ c ] -= 1 if count [ c ] == 0 : agenda . append ( c . args [ 1 ] ) return False
Use forward chaining to see if a PropDefiniteKB entails symbol q.
    [Fig. 7.15]
    >>> pl_fc_entails(Fig[7,15], expr('Q'))
    True
Use forward chaining to see if a PropDefiniteKB entails symbol q . [ Fig . 7 . 15 ] >>> pl_fc_entails ( Fig [ 7 15 ] expr ( Q )) True