Skip to content

Latest commit

 

History

History
22 lines (19 loc) · 1.93 KB

PL-FC-Entails.md

File metadata and controls

22 lines (19 loc) · 1.93 KB

PL-FC-ENTAILS?

AIMA3e

function PL-FC-ENTAILS?(KB, q) returns true or false
inputs: KB, the knowledge base, a set of propositional definite clauses
     q, the query, a proposition symbol
count ← a table, where count[c] is the number of symbols in c's premise
inferred ← a table, where inferred[s] is initially false for all symbols
agenda ← a queue of symbols, initially symbols known to be true in KB

while agenda is not empty do
   p ← POP(agenda)
   if p = q then return true
   if inferred[p] = false then
     inferred[p] ← true
     for each clause c in KB where p is in c.PREMISE do
       decrement count[c]
       if count[c] = 0 then add c.CONCLUSION to agenda
return false


Figure ?? The forward-chaining algorithm for propositional logic. The agenda keeps track of symbols known to be true but not yet "processed". The count table keeps track of how many premises of each implication are as yet unknown. Whenever a new symbol p from the agenda is processed, the count is reduced by one for each implication in whose premise p appears (easily identified in constant time with appropriate indexing.) If a count reaches zero, all the premises of the implication are known, so its conclusion can be added to the agenda. Finally, we need to keep track of which symbols have been processed; a symbol that is already in the set of inferred symbols need not be added to the agenda again. This avoids redundant work and prevents loops caused by implications such as PQ and QP.