E ExamMaster

Artificial Intelligence · AI Foundations

Forward, Backward and Resolution

In AI because a first-order sentence is only useful if a machine can derive what follows — and the three classical procedures, forward chaining, backward chaining and resolution,…

Last lesson gave the library a language: objects, quantifiers, unification. This lesson is how a machine uses that language. Three procedures cover the classical syllabus. Forward chaining starts from facts and fires every rule whose premises are already known. Backward chaining starts from a query and asks what would have to be true. Resolution is the one-rule refutation engine that works on any clause, not only the definite ones. The campus KB is tiny and stays tiny: two facts and two rules, so every firing can be written down.

  • Artificial Intelligence
  • Medium level
  • 5 concepts

1Definite clauses

A definite clause has exactly one positive atom, implied by a (possibly empty) conjunction of atoms: (P_1 \wedge \cdots \wedge P_n) \rightarrow Q. In campus clothes: \mathrm{Student}(x) \rightarrow \mathrm{Person}(x), and (\mathrm{Person}(x) \wedge \mathrm{Borrowed}(x, y)) \rightarrow \mathrm{Responsible}(x, y). A fact is the n = 0 case: \mathrm{Student}(\mathrm{Priya}) is a definite clause with an empty body.

The one-positive-atom restriction is what lets a chainer treat Q as 'the thing this rule concludes' and the P_i as 'the things it needs'. A sentence with two conclusions, or a bare negation, is still first-order logic — it is just not a definite clause, and the two chainers in this lesson will not fire it. Resolution, later, drops the restriction.

Library KB, as definite clauses
ClauseKindReads as
Student(Priya)factPriya is a student
Borrowed(Priya, Dune)factPriya borrowed Dune
Student(x) → Person(x)ruleevery student is a person
Person(x) ∧ Borrowed(x, y) → Responsible(x, y)rulea person who borrowed a book is responsible for it

2Forward chaining

Forward chaining is data-driven. Start with the facts. Whenever a rule's premises all unify with known atoms, add the head (after applying the unifier) as a new fact. Repeat until a pass adds nothing. The library KB starts with Student(Priya) and Borrowed(Priya, Dune). The first rule fires and adds Person(Priya). The second rule then fires and adds Responsible(Priya, Dune). A third pass finds nothing new, and the procedure stops.

The procedure is sound: every added atom is entailed. On a finite set of definite clauses with no function symbols it also terminates, because only finitely many ground atoms can appear. Functions reopen an infinite term world — advisor(advisor(Priya)) and so on — and a careless forward chainer can run forever even when the query is already sitting in the KB. That is a design constraint, not a footnote.

Forward loop

  1. MatchFind a rule whose every premise unifies with a known fact.
  2. AddApply the unifier to the head and insert that atom, if it is new.
  3. RepeatStop when a full pass adds nothing — or when a asked query appears.

Three passes on the library KB

Facts: Student(Priya), Borrowed(Priya, Dune). Rules: Student(x) → Person(x), and Person(x) ∧ Borrowed(x, y) → Responsible(x, y).

  • Pass 1: Student(x) matches Student(Priya)add Person(Priya)
  • Pass 2: Person(Priya) and Borrowed(Priya, Dune)add Responsible(Priya, Dune)
  • Pass 3: no remaining unfired matchstop
  • Known atomsStudent, Borrowed, Person, Responsible

Pro tip. Person(Priya) was not written down. It was derived. A later query 'is Priya a person?' is answered by looking in the closed fact set, not by walking the rule again.

3Backward chaining

Backward chaining is goal-driven. Start with a query atom. If it unifies with a fact, you are done. Otherwise, find a rule whose head unifies with the query, and replace the query by that rule's premises — new subgoals. The library query Responsible(Priya, Dune) does not match a fact, so the second rule opens two subgoals: Person(Priya) and Borrowed(Priya, Dune). The second is a fact. The first is not, so the first rule opens Student(Priya), which is a fact. The query succeeds.

Nothing about Person(Omar) is ever derived, because no subgoal asked for it. That is the point on a large KB: backward chaining touches only the rules that could support this query. The cost is recursion and branching — two rules with the same head mean two alternative proofs, and a recursive rule can loop. Prolog is this procedure with a fixed search order.

Figure. The query tree, not the firing order. Responsible needs Person and Borrowed; Person needs Student. Sage nodes match facts. Topology of subgoals; not a proof animation.

One query, three subgoals

Same KB. Query: Responsible(Priya, Dune).

  • Responsible(Priya, Dune) vs factsno match
  • Head of rule 2 unifies; subgoalsPerson(Priya), Borrowed(Priya, Dune)
  • Borrowed(Priya, Dune) vs factsmatch
  • Person(Priya) opens rule 1subgoal Student(Priya) — match

Pro tip. The same four atoms are involved as in forward chaining, but Omar's personhood was never considered. Forward would have derived every entailed ground atom; backward derived only what this query needed.

4Resolution as refutation

Resolution is one inference rule. Written on clauses — disjunctions of literals — it says: from A \vee B and \neg A \vee C, after unifying the complementary pair, derive B \vee C. A fact P is the unit clause P. A query Q is proved by refutation: add \neg Q to the KB and try to derive the empty clause, the clause with no literals, which is unsatisfiable. If you do, the KB plus \neg Q cannot be true, so the KB entails Q.

On the library, to prove Person(Priya) you add \neg \mathrm{Person}(\mathrm{Priya}). The rule \mathrm{Student}(x) \rightarrow \mathrm{Person}(x) is the clause \neg \mathrm{Student}(x) \vee \mathrm{Person}(x). Resolving that with \neg \mathrm{Person}(\mathrm{Priya}) produces \neg \mathrm{Student}(\mathrm{Priya}). Resolving with the fact \mathrm{Student}(\mathrm{Priya}) produces the empty clause. The query is proved. The same rule works on clauses that are not definite — that is the expressiveness the chainers gave up.

Figure. Add ¬Person(Priya) and resolve with ¬Student(x) ∨ Person(x) to get ¬Student(Priya) under {x/Priya}. Resolve that with the fact Student(Priya) to the empty clause. KB ∪ {¬Person(Priya)} is unsatisfiable, so the KB entails Person(Priya).

Refute ¬Person(Priya)

Clauses: Student(Priya); ¬Student(x) ∨ Person(x). Add ¬Person(Priya) and resolve.

  • ¬Person(Priya) with ¬Student(x) ∨ Person(x)¬Student(Priya) [x/Priya]
  • ¬Student(Priya) with Student(Priya)empty clause
  • KB ∪ {¬Person(Priya)} is unsatisfiableKB entails Person(Priya)

Pro tip. The empty clause is not a missing answer. It is the proof: a contradiction was derived from the KB plus the negated query, so the query must follow.

5Complete, and not a decision procedure

Resolution is sound and, with a fair search and the occur-check, complete for FOL: if the KB entails Q, a refutation will eventually appear. Church and Turing showed the converse fails as a halt: if the KB does not entail Q, the search may run forever. That is the semi-decidability the Knowledge Engineering glimpse already stated, now attached to a procedure you have seen fire.

Production systems and databases stay inside fragments where the search does halt — definite clauses without functions, or description logics with a restricted quantifier. The habit is the same as in search: pick the procedure whose object and whose halt story match the job. Forward when new facts should wake rules. Backward when one query should wake rules. Resolution when the KB is not definite. And do not read a long silence as a proof of \neg Q.

Figure. If the KB entails Q, a fair resolution search with the occur-check will eventually produce a refutation. If it does not, Church and Turing: the search may run forever. Do not read a long silence as a proof of ¬Q.

Forward chaining on the library KB has just added Person(Priya). A classmate now asks Responsible(Omar, Dune) and, after a quiet second, concludes ¬Responsible(Omar, Dune). What is wrong?
  1. Silence is not a proof of the negation — Omar was never a fact, so the second rule never fired for him, and even a finished chainer on a richer KB cannot treat 'not yet derived' as ¬Q in full FOL
  2. They should have used unification on Omar and Priya
  3. Responsible is not a definite clause
  4. Resolution forbids queries about Omar

On this tiny function-free KB the chainer did finish and Omar is simply absent. The deeper mistake the option names is the one that survives on a richer KB: failing to derive Q is not deriving ¬Q, and full FOL may never tell you which case you are in.

Notes

  • A definite clause is one positive atom implied by a conjunction of atoms — the shape forward and backward chaining require.
  • Forward chaining fires applicable rules until no new fact appears; backward chaining starts from a query and works toward known facts.
  • Resolution is a single refutation rule on clauses; it is complete for FOL and only semi-decidable in the general case.

Formulas

  • Definite clause: (P_1 \wedge \cdots \wedge P_n) \rightarrow Q, written Q \leftarrow P_1, \ldots, P_n
  • Resolution: from A \vee B and \neg A \vee C, derive B \vee C (after unifying the complementary literals)
  • Refutation: KB entails Q iff KB ∪ {¬Q} is unsatisfiable

Exam traps & shortcuts

  • Forward chaining is data-driven: a new fact is what wakes a rule. Backward chaining is goal-driven: a query is what wakes a rule.
  • A rule that is not a definite clause — two positive atoms, or a bare negation — is outside both chainers; resolution can still take it.
  • Failing to prove Q is not proving ¬Q. FOL entailment may run forever on a non-consequence — the bill the knowledge-systems glimpse already named.

Recap

Next: knowledge engineering.

Definite clause
One positive head, a conjunction of atoms as the body. Facts are the empty-body case. Chainers require this shape.
Forward
Facts wake rules. The library adds Person(Priya), then Responsible(Priya, Dune), then stops.
Backward
A query wakes rules. Responsible(Priya, Dune) opens Person and Borrowed; Omar is never touched.
Resolution
Add ¬Q, resolve to the empty clause. Complete for FOL; a non-consequence may never halt.

Practise Forward, Backward and Resolution

Reading is free and needs no account. Practice, mocks and progress live in the app.

  • 1 quick check with worked explanations
  • Timed mocks scored with the real marking scheme
  • Readiness tracked per topic, kept on your device
Continue with Google — freeNo card, no trial. Works offline once installed.