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