2.1 HornDatabases ....................................... 2
2.2 BackwardChaining ..................................... 3
2.3 ForwardChaining ..................................... 3
3.1 NormalForm ........................................ 6
3.2 Proof-by-Refutation .................................... 7
3.3 ResolutionStrategies .................................... 9
Inthislecture, wedescribetwoproof-theoretic engines, onebased on modusponens(whichdates backtoAristotle), andthe other on resolution, whichdatesback to the work ofRobinson(aphilosopher, mathematician, and computer scientist) in 1965. Iterated modus ponens is closely related to iterated resolution, and hence the distinction is sometimes blurred. Following Ginsburg’s 1993 AI text, wepresent resolution as ageneralization of modusponens. More specifically, resolutionis applicable to knowledge bases in normal form, and all knowledge bases can be converted to normal form, whereas modusponensis applicable only toknowledgebases consisting ofHorn clauses. Horn databases, while natural, are not sufficient to express all sentences of propositional logic.
Modusponens, which captures one ofAristotle’s syllogisms,generalizes the(→ E)rule of natural deduction.
MODUS PONENS
A1 ∧... ∧Am → BAi
(MP)
A1 ∧... ∧Ai−1 ∧Ai+1 ∧... ∧Am → B
Exercise: Derive MP using ND.
Solution: (Sketch)
[A] C (∧I)
A ∧C → BA ∧C
(→ E)
B (→ I)
A → B
ITERATED MODUS PONENS
A1 ∧... ∧Am → BC1 ∧... ∧Cn → Ai
(IMP)
A1 ∧... ∧Ai−1 ∧C1 ∧... ∧Cn ∧Ai+1 ∧... ∧Am → B
Exercise: Derive IMP using ND. Solution: (Sketch)
[A1 ∧A2 ∧A3]
(∧E)
[A1 ∧A2 ∧A3] A2 ∧A3 A2 ∧A3 → C
(∧E) (→ E)
A1 C
(∧I)
(A1 ∧C)→ BA1 ∧C
(→ E) B (→ I)
A1 ∧A2 ∧A3 → B
Theorem: IMP is sound.
Proof: Suppose not: i.e., suppose that there exists aninterpretation which satisfies thepremises of IMPbutdoesnotsatisfy theconclusion. Insuch aninterpretation,theantecedent of theconclusion is satisfied, while the consequent is not; in particular, B is not satisfied. Since the antecedent is satisfied, however,(i) C1 ∧... ∧Cm is satisfied, and(ii) A1 ∧... ∧Ai−1 ∧Ai+1 ∧... ∧An is satisfied. Now,by(i) andthefactthatthe secondpremiseis satisfied, Ai must be satisfied. Together with (ii), this implies thatB is satisfied. Contradiction. Therefore, IMP is sound. ⋄
A Horn clause is a complex formula of the form A1 ∧... ∧An → B in which the Ai’s and B are atomic. Atomic formulas and their negations are called literals; thus, Horn clauses are equivalently defined asdisjunctions ofliterals with exactly onepositiveliteral(e.g., ¬A1 ∨... ∨¬An ∨B).
A Horn database is a knowledge base of Horn clauses. IMP is complete for Horn databases, but IMP is not complete for all knowledge bases. For example, KB |= R, but KB �⊢imp R, given KB = {C, C → T ∨H, H → R, T → R ∨S, S → R}.
Theorem provers that implement modus ponens proceed either by backward or forward chaining. Backward chaining involves reasoning backwards from the goal, while forward chaining is data-driven: new data drives new conclusions.
We demonstrate backward and forward chaining on the following Horn database: {P ∧Q ∧R → S, T ∧U → P, V → Q, R, T, U, V }. The complex formulas in this knowledge base are called Horn rules, and the literals are called facts.
Backward chaining is the repeated application of modus ponens to Horn databases. The inputs to backward chaining are a knowledge base KB of Horn clauses and set of goals Σ in some logical language(e.g., propositional logic). If KB |= Σ, then backward chaining terminates with true. If KB �|=Σ, then backward chaining terminates with false.
Thebackward chaining algorithmisinspiredby thefollowing observation:giventheHorndatabase KB with select rule A1 ∧... ∧An → A and given goal A ∈ Σ, if KB ⊢ A1,...,An, then KB ⊢ A, by modusponens. The mainidea ofbackward chaining, asits name suggests,isto reducethegoal A to n subgoals A1,...,An, and to proceed to further reduce these subgoals to facts.
A call to backward chaining, with goal S, would operate as follows on the sample Horn database given above:
Σ= {S} Σ= {P, Q, R} Σ= {T, U, Q, R} Σ= {U, Q, R} Σ= {Q, R} Σ= {V, R} Σ= {R} Σ= ∅, return true
If we were to add to our database the Horn rule O → S, then backward chaining might instead begin like this
Σ= {S} Σ= {O}, return false
beforeproceeding as above. Inother words,backward chaining is abacktracking depth-first search algorithm.
The implementation of backward chaining depicted in Table 1 relies on two mutually recursive subroutines. bc goals(KB, Σ) determinesif all of thegoalsinΣ areprovable. Todeterminethis, it calls bc rules on each such goal. bc rules(KB,A)determines if the goal A is provable. To determine this, it calls bc goals ontheantecedents of all rulesinKB with A as their consequent.
Given aknowledgebaseKB,forward chaining derives all the conclusionsimpliedby theknowledge base. This form of reasoning is useful in medical diagnosis, where it is important to consider all possible implications. But most often, forward chaining is less practical than backward chaining, since it derives many irrelevant conclusions.
The forward chaining algorithm is initialized with a knowledge base and a set of facts to which it repeatedly applies modusponensintheforwarddirection: i.e., if the rule B1 ∧... ∧Bn → C ∈ KB and the fact Bi ∈ KB, then the rule B1 ∧... ∧Bi−1 ∧Bi+1 ∧... ∧Bn → C is added to KB. The pseudocode for forward chaining in propositional logic appears in Table 2.
Forward chaining operates as follows on the sample Horn database given above:
bc goals(KB, Σ) Inputs a set of Horn rules KB a set of sub/goals Σ Outputs if KB ⊢ Σ(i.e., KB |=Σ), return true if KB �⊢ Σ(i.e., KB �|=Σ), return false
(a) x = x ∧bc rules(KB,A)
3. return x
bc rules(KB,A) Inputs a set of Horn rules KB a sub/goal A Outputs if KB ⊢ A (i.e., KB |= A), returntrue if KB �⊢ A (i.e., KB �|= A), returnfalse
3. return y
Table 1: Backward Chaining.
Pop R off Σ; replace P ∧Q ∧R → S with P ∧Q → S Pop T off Σ; replace T ∧U → P with U → P Pop U off Σ; delete U → P ; insert P intoΣ andΣ′ Pop V off Σ; delete V → Q; insert Q intoΣ andΣ′ Pop P off Σ; replace P ∧Q → S with Q → S Pop Q off Σ; delete Q → S; insert S intoΣ andΣ′ Pop S off Σ; return Σ′ = {R, T, U, V, P, Q, S}
The simplest case of resolution, unit resolution, can be understood as an application of modus ponens of the form: given premises ¬A → B and ¬A, conclude B. For example, let A be the proposition “it is raining” and let B be the proposition “the ground is dry”. Now ¬A → B is interpreted as “ifitisnotraining,thenthegroundisdry.” Equivalently, “eitheritisraining orthe ground is dry.” If ¬A holds(i.e., if it is not raining), then we conclude B (i.e., the ground is dry).
forward chaining(KB, Σ)
Inputs a set of Horn rules KB
an initial set of facts Σ
Output {A |KB∪Σ |= A}
Initialize =Σ
Σ′
while (Σ is not empty)do
return Σ′ Table 2: Forward Chaining.
UNIT RESOLUTION(1R)
A ∨B ¬B
(1R)
A
GROUND RESOLUTION(GR)
A1 ∨... ∨Am ∨CB1 ∨... ∨Bn ∨¬C
(GR)
A1 ∨... ∨Am ∨B1 ∨... ∨Bn
ITERATED GROUND RESOLUTION(IGR) If Dj = Ai, then
A1 ∧... ∧Am → B1 ∨... ∨Bn C1 ∧... ∧Ck → D1 ∨... ∨Dl
(IGR)
A1 ∧... ∧Ai−1 ∧Ai+1 ∧... ∧Am ∧C1 ∧... ∧Ck → B1 ∨... ∨Bn ∨D1 ∨... ∨Dj−1 ∨Dj+1 ∨... ∨Dl
Theorem: IGR is sound.
Proof: Supposenot:i.e., supposethatthereexistsaninterpretationwhich satisfiesthepremisesof IGRbutdoesnot satisfy theconclusion. Insuch aninterpretation,theantecedent of theconclusion is satisfied, whilethe consequentis not;inparticular, none ofB1,...,Bn,D1,...,Dj−1,Dj+1,...,Dl are satisfied. Since the antecedentis satisfied,however,(i) C1∧...∧Ck is satisfied, and(ii) A1∧...∧ Ai−1∧Ai+1∧...∧Am is satisfied. Now,by(i) andthefact that the secondpremiseis satisfied, one of D1,...,Dl is satisfied. Two cases arise. IfDj is notsatisfied, then one of D1,...,Dj−1,Dj+1,...,Dl is satisfied. Contradiction. Otherwise, if Dj = Ai is satisfied, together with(ii), thisimplies that one of B1,...,Bn is satisfied. Contradiction. Therefore, IGR is sound. ⋄
A formula is said to be in normal form iff it is of the form α1 ∧... ∧αn → β1 ∨... ∨βm where the αi’s and βj ’sare atomic. Allformulasofpropositionallogic(andindeed,predicate calculus) are convertible to normal form databases via the following procedure. 1
1. Eliminate implications.
• Rewrite A → B as ¬A ∨B.
2. Move negations inwards.
– Rewrite ¬¬A as A.
3. Distribute ∨ over ∧.
• Rewrite A ∨(B ∧C)as(A ∨B)∧(A ∨C).
• Rewrite(A ∧B)∨C as(A ∨C)∧(B ∨C). (Note: Theknowledgebaseis nowin conjuctive normalform(CNF).)
4. Split conjunctions: split up formulas like A ∧B into two separate entries in the knowledge base, namely A and B.
5. Flattennesteddisjunctions: flattenformulasof theform((A ∨B)∨C)into A ∨B ∨C. (This is often done along the way.)
6. Eliminate negations by reintroducing implications.
1 All formulas of first-order logic are also convertible to normal form databases, but that conversion procedure is a bit more complicated. See Lecture ??.
(As in Lecture 09, the connective ↔ is used as an abbreviation: in particular, A ↔ B means (A → B)∧(B → A).)
Example: [Ginsberg1993] If a house is big and old, then it is a lot of work to maintain, unless it comes with a housecleaner and doesn’t have a garden.
We express this sentence in propositional logic as B ∧ O → W ∨ (C ∧¬G), using the following propositions:
B: The house is big.
O: The house is old.
W: The house is a lot of work to maintain.
C: The house comes with a housecleaner.
G: The house has a garden.
Followingthe steps outlined above, we nowdemonstratehowto convert thisformula ofpropositional logic into a database in normal form:
¬B ∨(¬O ∨W ∨C)∧(¬O ∨W ∨¬G) (¬B ∨¬O ∨W ∨C)∧(¬B ∨¬O ∨W ∨¬G)
4. Split conjunctions:
¬B ∨¬O ∨W ∨C ¬B ∨¬O ∨W ∨¬G
B ∧O → W ∨C
B ∧O ∧G → W
Recall that a proof theory Π is said to be complete iff KB |= A implies KB ⊢Π A, for all formulas
A. A proof theory Π is refutation-complete iff KB |= ⊥ implies KB ⊢Π ⊥. The inference rule IGR is refutation-complete for knowledge bases in normal form. Therefore, since KB |= A iff KB∪{¬A}|= ⊥, by soundness and refutation-completeness, KB |= A iff KB, ¬A ⊢IGR ⊥.
This final observation motivates the solution to the logical entailment problem known as proof-by-refutation: (i) convert knowledge base KB ∪{¬A} to normalform;(ii) apply resolution until
⊤→ CC → T ∨H ⊤→ T ∨HH → R ⊤→ T ∨RT → R ∨S ⊤→ R ∨SS → R ⊤→ RR →⊥ ⊤→⊥
S → RR →⊥ S →⊥ T → R ∨S T → RC → T ∨H C → R ∨HH → R C → R ⊤→ C ⊤→ RR →⊥ ⊤→⊥
resolutionis nolonger applicable. Thefollowing aretwoproofs-by-refutationthatKB∪{¬R}⊢⊥, which implies that KB |= R, given KB = {⊤→C, C → T ∨H, H → R, T → R ∨S, S → R}.
Resolution pseudocode for propositional logic 2 appears in Table 3. All pairs of formulas in turn,
One way toimplementthispseudocode wouldbeto represent eachformula as apair of sets(e.g., φ = �{T }, {R, S}�). That way, resolvents that look like C → R ∨ R would automatically be simplified to C → R.
resolution(KB,A) Inputs a knowledge base KB in normal form a goal A Initialize Δ = ∅ Φ =KB∪{A →⊥} Outputs if KB,A →⊥⊢⊤→⊥ (i.e., KB |= A), returntrue
loop
1. for all pairs of formulas φ, ψ ∈ Φ
forever
Table 3: Resolution.
2 Adopted from Russell and Norvig, p. 216.
Resolution is sound and refutation-complete: i.e., KB |= A iff KB, ¬A ⊢IGR ⊥. In other words, the resolution inference rule guarantees the existence of a proof (by contradiction) whenever a knowledge base logically entails a fact, but it is not always straightforward to find such a proof.
Exercise: LetKB = {⊤ →A ∨B, A → C, B → C, C → P, P → Q, ⊤→ P }. Derive Q with and without explicitly deriving C.
There are a number of strategies that guide the application of resolution and aim to increase the efficiency of resolution theorem provers: (i) unit resolution: at least one of the formulas is a unit clause(i.e., consists of onepredicate symbol);(ii) input resolution: at least one of the formulas is in the knowledge base; (iii) linear resolution: one of the formulas is the most recent conclusion; (iv)set of support resolution: at least one of the formulas is in the set of support, which includes the negatedquery and allderivedformulas; and(v) ordered resolution: set of support resolution in which the first clause is always the resolvent.
A control strategy is complete if its preserves refutation-completeness. Neither unit nor input resolution is complete, but linear resolution, set of support, and ordered resolution are complete. For example, it is not possible to derive a contradiction from KB = {⊤ → P ∨Q, P → Q, Q → P, P ∧Q →⊥} using unit or input resolution, although the following reasoning is sound:
T → P ∨QQ → PP ∧Q →⊥ P → Q ⊤→ PP →⊥ ⊤→⊥
In addition, the following is a linear derivation of a contradiction, given KB:
| ⊤ → P ∨Q | P → Q | ||
|---|---|---|---|
| Q → P | ⊤ → Q | ||
| P ∧Q → ⊥ | ⊤ → P | ||
| ⊤ → Q | Q → ⊥ | ||
| ⊤ → ⊥ | |||