forward chaining
propositional logic chaining
the forward-chaining algorithm (which stands for "propositional logic forward chaining entails" and is shown in forward_chaining.html) determines if a single proposition symbol
--the query--is entailed by a knowledge base of definite clauses. it begins from known facts (positive literals) in the knowledge base. if all the premises of an implication are known, then its conclusion is added to the set of known facts. for example, if
and
are known and
is in the knowledge base, then
can be added. this process continues until the query
is added or until no further inferences can be made. it is important to remember that this algorithm runs in linear time.
the best way to understand the algorithm is through an example and a picture. broken link: blk:fig-forward-chaining-1 shows a simple knowledge base of horn clauses with and
as known facts and the knowledge base drawn as an
graph.
in graphs, multiple edges joined by an arc indicate a conjunction-—every edge must be proved—-while multiple edges without an arc indicate a disjunction—-any edge can be proved. it is easy to see how forward chaining works in the graph. the known leaves (here,
and
) are set, and inference propagates up the graph as far as possible. wherever a conjunction appears, the propagation waits until all the conjuncts are known before proceeding.
broken link: attachment:fig1.png
first-order logic chaining
forward_chaining.html shows a simple forward chaining inference algorithm for first-order logic. starting from the known facts, it triggers all the rules whose premises are satisfied, adding their conclusions to the known facts. the process repeats until the query is answered (assuming that just one answer is required) or no new facts are added. notice that a fact is not "new" if it is just a renaming of a known fact—-a sentence is a renaming of another if they are identical except for the names of the variables. for example, and
are renamings of each other. they both mean the same thing: "everyone likes ice cream."
"...it is a crime for an American to sell weapons to hostile nations":
- on the first iteration, rule forward_chaining.html has unsatisfied premises.
- rule forward_chaining.html is satisfied with
, and
is added.
- rule forward_chaining.html is satisfied with
, and
is added.
- rule forward_chaining.html is satisfied with
, and
is added.
- rule forward_chaining.html is satisfied with
- on the second iteration, rule forward_chaining.html is satisfied with
, and the inference
is added.
first, which values are eligible for the variable
for each combination of variables we need to generate all variations of constants such that repetition is allowed and order matters, repetition should be allowed because different variables shuold be able to hold the same constant value, and order should matter because it matters which variable gets substituted by which constant value. the total number of variations for a combination of variables of length
the candidates for the expression
\textsc{FOL-BC-Or} works by fetching all clauses that might unify with the goal, standardizing the variables in the clause to be brand new variables, and then, if the
backward chaining, as we have written it, is clearly a depth-first search algorithm. this means that its space requirements are linear in the size of the proof. it also means that backward chaining (unlike forward chaining) suffers from problems with repeated states and incompleteness. despite these limitations, backward chaining has proven to be popular and effective in logic programming languages.