Recap of Lecture 7 and Homework Check
LAST LECTURE · 5 MIN
Today: the six-step proof from L07 (S16) done by a machine - with ONE rule called resolution.
Today's Plan (50 minutes)
ROADMAP
0-5
Recap of Lecture 7 and homework check
S02
5-8
Plan and learning outcomes
S03-S04
8-16
Module 1: Inference rules and proofs
S05-S08
16-27
Module 2: The resolution rule and CNF
S09-S11
27-35
Module 3: Proof by resolution; unification
S12-S15
35-43
Class activity: prove it
S16
43-48
Common mistakes and recap quiz
S17-S18
48-50
Homework and next lecture
S19
Learning Outcomes (SLOs)
BY THE END OF THIS LECTURE YOU WILL BE ABLE TO
SLO 8.1
Apply inference rules (modus ponens, modus tollens and others) to derive a conclusion
→ CLO2 · C3 Apply
SLO 8.2
Convert a propositional sentence into conjunctive normal form (CNF)
→ CLO2 · C3 Apply
SLO 8.3
Prove a query by resolution refutation and unify simple first-order atoms
→ CLO2 · C3 Apply
- Course Learning Outcome(s) served
- CLO2: Demonstrate first-order predicate calculus, logical reasoning and problem-solving using Prolog language.
Slide 5
MODULE 1
Inference Rules
Proving new sentences from old ones - without a truth table
What Is Inference?
MODULE 1 · INFERENCE
Truth tables
Inference rules
Sure, but 2ⁿ rows: 50 atoms give about 10¹⁵ rows.
Work on the sentences: a proof of 10-20 steps, whatever the number of atoms.
The Main Rules of Inference
MODULE 1 · RULES
Why sound: each rule is a tautology (L06) - it can never lead from true premises to a false conclusion.
A Proof with Inference Rules
MODULE 1 · PROOF
The KB
- R1: F ∧ B → V
- R2: V ∧ S → T
- R3: T ∧ L → D
- Facts: F, B, S, L
- F fever, B body ache, V viral, S dengue season, T test, L low platelets, D dengue suspected
Problem: which rule to try next? A computer needs ONE simple rule it can always apply. That rule is resolution.
Slide 9
MODULE 2
Resolution and CNF
One rule that does the work of all the others
The Resolution Rule
MODULE 2 · RESOLUTION
From A ∨ P and ¬P ∨ C conclude A ∨ C
Words: literal = P or ¬P; clause = literals joined by ∨; resolvent = the new clause; □ = empty clause (contradiction).
Converting to Conjunctive Normal Form (CNF)
MODULE 2 · CNF
REAL OUTPUT: L08/CNF.PY (CHECKED IN ALL 8 ROWS)
W ↔ (C ∧ ¬R) vs (¬W ∨ C) ∧ (¬W ∨ ¬R) ∧ (¬C ∨ R ∨ W) EQUIVALENT
Result: 3 clauses: ¬W ∨ C, ¬W ∨ ¬R, ¬C ∨ R ∨ W. An implication A ∧ B → C becomes one clause ¬A ∨ ¬B ∨ C.
Slide 12
MODULE 3
Proof by Resolution
To prove α, assume NOT α and reach a contradiction
Resolution Refutation: The Method
MODULE 3 · REFUTATION
- 1. Write the KB in CNF (a list of clauses).
- 2. Add the NEGATION of the query: to prove α, add ¬α.
- 3. Resolve pairs of clauses and add each new resolvent.
- 4. Empty clause □ found → contradiction → the query is PROVED.
- No new clauses possible → the query does NOT follow.
REAL OUTPUT: L08/RESOLUTION.PY
- Example 1: KB = {A → E, ¬E}. Query: ¬A
- 1. A negated query
- 2. ¬A ∨ E KB
- 3. E resolve 1 + 2
- 4. ¬E KB
- 5. □ (empty clause) resolve 3 + 4
- The empty clause was reached, so the query is PROVED.
Example: L06 homework Task 3 (attendance) - modus tollens, now done by resolution.
Demo: A Resolution Prover in Python
MODULE 3 · REFUTATION
REAL OUTPUT: EXAMPLE 2 - DENGUE KB
REAL OUTPUT: EXAMPLE 3
- Example 2: dengue KB (3 rules, 4 facts). Query: D (dengue suspected)
- 1. ¬D negated query
- 2. D ∨ ¬L ∨ ¬T KB
- 3. ¬L ∨ ¬T resolve 1 + 2
- 4. ¬S ∨ T ∨ ¬V KB
- 5. ¬L ∨ ¬S ∨ ¬V resolve 3 + 4
- 6. ¬B ∨ ¬F ∨ V KB
- 7. ¬B ∨ ¬F ∨ ¬L ∨ ¬S resolve 5 + 6
- 8. F KB
- 9. ¬B ∨ ¬L ∨ ¬S resolve 7 + 8
- 10. B KB
- 11. ¬L ∨ ¬S resolve 9 + 10
- 12. S KB
- 13. ¬L resolve 11 + 12
- 14. L KB
- 15. □ (empty clause) resolve 13 + 14
- The empty clause was reached, so the query is PROVED.
- Example 3: KB = {R → W, W}. Query: R (converse trap)
- no proof: the query does not follow
Clauses in
- ¬F ∨ ¬B ∨ V, ¬V ∨ ¬S ∨ T, ¬T ∨ ¬L ∨ D, F, B, S, L and the negated query ¬D.
- Strategy: set of support - every step uses the negated query or a clause made from it.
Resolution in First-Order Logic: Unification
MODULE 3 · FIRST-ORDER LOGIC
REAL OUTPUT: L08/UNIFY.PY
- UNIFY(Eligible(x), Eligible(Hira)) = {x/Hira}
- UNIFY(Knows(Ali, y), Knows(x, Sana)) = {x/Ali, y/Sana}
- UNIFY(Advises(Waqas, x), Advises(y, fatherOf(Ali))) = {y/Waqas, x/fatherOf(Ali)}
- UNIFY(Knows(Ali, y), Knows(y, Sana)) = FAIL (no substitution)
- UNIFY(Student(Ali), Teacher(Ali)) = FAIL (no substitution)
Prolog (L09): eligible(X) :- student(X), att75(X). ?- eligible(ali). Prolog unifies X = ali and resolves.
Activity: Prove It
CLASS ACTIVITY · PAIRS · 8 MIN
Pairs, 6 minutes + 2 minutes check. Write the answer and the rule you used.
Name the rule: 'If it rains the match is cancelled. It rains. So the match is cancelled.'
Convert ¬(A ∧ B) → C to CNF.
Name the rule: from R → C and ¬C conclude ¬R.
Resolve the clauses A ∨ B and ¬B ∨ C.
Convert P → (Q ∨ R) to CNF.
Prove R by resolution from KB = {P → Q, Q → R, P}.
Common Mistakes
WATCH OUT
WRONG IDEA
CORRECT IDEA
✗ To prove α, add α to the KB.
✓ Add ¬α (the NEGATION) and look for the empty clause.
✗ From P → Q and Q, conclude P.
✓ Invalid (converse trap). Only modus ponens (P) and modus tollens (¬Q) are valid.
✗ Resolve two pairs at once: (P ∨ Q), (¬P ∨ ¬Q) gives □.
✓ Resolve ONE pair: the result is Q ∨ ¬Q (a tautology), not □.
✗ A → B becomes A ∨ ¬B in CNF.
✓ A → B ≡ ¬A ∨ B (negate the left side).
✗ Knows(Ali, y) unifies with Knows(y, Sana).
✓ It fails: y cannot be Ali and Sana. Rename variables apart first.
Recap Quiz
CHECK YOUR UNDERSTANDING · 3 MIN
- Q1. From P → Q and ¬Q we conclude ¬P. This is:
- (a) Modus ponens (b) Modus tollens (c) AND-elimination (d) Resolution only
- Q2. Resolving (A ∨ B) with (¬B ∨ C) gives:
- (a) A ∨ C (b) A ∧ C (c) B ∨ C (d) □
- Q3. In CNF, A → B becomes:
- (a) A ∨ ¬B (b) ¬A ∧ B (c) ¬A ∨ B (d) A ∧ ¬B
- Q4. To prove α by refutation we add:
- (a) α (b) ¬α (c) α ∨ ¬α (d) Nothing
Homework and Next Lecture
BEFORE THE NEXT CLASS
- Task 1: Convert to CNF: (a) (L ∧ ¬U) → ¬F (b) S ↔ E.
- Task 2: D = soil dry, R = rain forecast, I = irrigation needed, L = load-shedding, G = start diesel engine. KB = {(D ∧ ¬R) → I, (I ∧ L) → G, D, ¬R, L}. Prove G by resolution (number every step).
- Task 3: Find the unifier or say FAIL: (a) Teaches(Waqas, x) and Teaches(y, CS511) (b) Older(x, x) and Older(Ali, Sana).
- Read: Russell & Norvig 7.5 and 9.2; Luger 14.1. Install SWI-Prolog (swi-prolog.org) for Lecture 9.
NEXT LECTURE
- Lecture 9:
- Logic Programming with Prolog