Nexus Learn

Lecture 8: Inference and Resolution for Problem Solving

Lecture Notes CS-511 Artificial Intelligence 10 min read Updated 8 Nov 2026

↓ Download notes (Word)

On this page
  1. Learning Outcomes
  2. 1. Inference
  3. 2. The Resolution Rule
  4. 3. Proof by Resolution (Refutation)
  5. 4. Resolution in First-Order Logic
  6. 5. Common Mistakes
  7. Word Bank
  8. Summary
  9. Self-Check Questions

Learning Outcomes

SLO

After this lecture you will be able to...

CLO

Bloom

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

1. Inference

§1.1 Derivation, soundness and completeness

Slide L08-S06

Inference means deriving new sentences from the knowledge base (KB) with rules. KB ⊢ α means 'α can be derived from the KB'. In Lecture 6 we used KB ⊨ α - 'α is true in every model of the KB' - and checked it with a truth table. Truth tables need 2ⁿ rows (50 atoms give about 10¹⁵ rows), so for real problems we use rules instead.

Word

Meaning

Sound

Every derived sentence is really entailed: the method never proves something false.

Complete

Every entailed sentence can be derived.

Refutation-complete

If the KB is contradictory, the method will find the contradiction (resolution has this property).

§1.2 Rules of inference

Slide L08-S07

Rule

From

Conclude

Example

Modus ponens

P → Q, P

Q

If it rains the match is off; it rains → the match is off.

Modus tollens

P → Q, ¬Q

¬P

If attendance ≥ 75% then eligible; not eligible → attendance < 75% (L06 HW 3).

AND-elimination

P ∧ Q

P

Ali is a student and lives in Burewala → Ali is a student.

AND-introduction

P, Q

P ∧ Q

Fever; body ache → fever and body ache.

Disjunctive syllogism

P ∨ Q, ¬P

Q

Fuse or wiring; not the fuse → the wiring.

Hypothetical syllogism

P → Q, Q → R

P → R

Load-shedding → UPS on; UPS on → fan runs; so load-shedding → fan runs.

Invalid! From P → Q and Q we may NOT conclude P (affirming the consequent - the converse trap of Lecture 6).

§1.3 A proof with rules

Slide L08-S08

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 infection possible, S dengue season, T test for dengue, L low platelets, D dengue suspected).

Step

Sentence

Reason

1

F ∧ B

AND-introduction

2

V

Modus ponens R1, 1

3

V ∧ S

AND-introduction

4

T

Modus ponens R2, 3

5

T ∧ L

AND-introduction

6

D

Modus ponens R3, 5

This is forward chaining (Lecture 5), and every step uses a sound rule. The difficulty for a computer is choosing which rule to apply next - resolution solves this with ONE rule.

2. The Resolution Rule

§2.1 Literals, clauses and resolvents

Slide L08-S10

A literal is an atom or its negation (P, ¬P). A clause is literals joined by ∨ (¬F ∨ ¬B ∨ V). If one clause has a literal and another has its negation (a complementary pair), they can be resolved: remove the pair and join what is left with ∨.

Resolution: from A ∨ P and ¬P ∨ C conclude A ∨ C.

Clause 1

Clause 2

Resolvent

Note

Rain ∨ Canal

¬Rain ∨ Wet

Canal ∨ Wet

General case

¬P ∨ Q

P

Q

= modus ponens

¬P ∨ Q

¬Q

¬P

= modus tollens

P

¬P

□ (empty clause)

Contradiction

Why it is sound: P is either true or false. If P is true, ¬P ∨ C makes C true; if P is false, A ∨ P makes A true. Either way A ∨ C is true. Resolve on ONE complementary pair at a time.

§2.2 Conjunctive normal form (CNF)

Slide L08-S11

Resolution works on clauses, so the KB must be in CNF: an AND of clauses. Four steps:

Step

Rule

Example: W ↔ (C ∧ ¬R)

1. Remove ↔

A ↔ B ≡ (A → B) ∧ (B → A)

(W → (C ∧ ¬R)) ∧ ((C ∧ ¬R) → W)

2. Remove →

A → B ≡ ¬A ∨ B

(¬W ∨ (C ∧ ¬R)) ∧ (¬(C ∧ ¬R) ∨ W)

3. Move ¬ inwards

De Morgan; ¬¬A ≡ A

(¬W ∨ (C ∧ ¬R)) ∧ (¬C ∨ R ∨ W)

4. Distribute ∨ over ∧

A ∨ (B ∧ C) ≡ (A ∨ B) ∧ (A ∨ C)

(¬W ∨ C) ∧ (¬W ∨ ¬R) ∧ (¬C ∨ R ∨ W)

Shortcut for rules: (A ∧ B) → C becomes the single clause ¬A ∨ ¬B ∨ C. Each conversion below was checked against the original sentence in every row of the truth table (real output of l08/cnf.py):

(R ∧ C) → W vs ¬R ∨ ¬C ∨ W EQUIVALENT

W ↔ (C ∧ ¬R) vs (¬W ∨ C) ∧ (¬W ∨ ¬R) ∧ (¬C ∨ R ∨ W) EQUIVALENT

P → (Q ∨ R) vs ¬P ∨ Q ∨ R EQUIVALENT

¬(A ∧ B) → C vs (A ∨ C) ∧ (B ∨ C) EQUIVALENT

(L ∧ ¬U) → ¬F vs ¬L ∨ U ∨ ¬F EQUIVALENT

S ↔ E vs (¬S ∨ E) ∧ (S ∨ ¬E) EQUIVALENT

Wrong: ¬(A ∧ B) vs ¬A ∧ ¬B NOT equivalent at {'A': True, 'B': False}

3. Proof by Resolution (Refutation)

§3.1 The method

Slide L08-S13

  1. Write the KB as CNF clauses.
  2. Add the NEGATION of the query (to prove α, add ¬α).
  3. Resolve pairs of clauses and add each new resolvent.
  4. If the empty clause □ appears, KB ∧ ¬α is impossible, so KB ⊨ α (PROVED). If no new clause can be made, α does not follow.

§3.2 A resolution prover in Python

Slide L08-S13, S14

The program below (plain Python) uses the set-of-support strategy: every step uses the negated query or a clause made from it. It prints only the clauses used in the proof.

"""L08 demo: a small resolution prover for propositional logic (plain Python).

A clause is a set of literals; '~A' means not A. To prove a query we add its negation and look for the empty clause.

Set-of-support strategy: every step uses at least one clause that comes from the negated query."""

from itertools import count

def neg(l):

return l[1:] if l.startswith("~") else "~" + l

def show(c):

return "□ (empty clause)" if not c else " ∨ ".join(("¬" + l[1:]) if l.startswith("~") else l for l in sorted(c, key=lambda x: x.lstrip("~")))

def resolve(a, b):

out = []

for l in a:

if neg(l) in b:

out.append(frozenset((a - {l}) | (b - {neg(l)})))

return out

def prove(kb, query, title):

print(title)

clauses = [frozenset(c) for c in kb]

goal = frozenset([neg(query)])

info = {c: ("KB", None) for c in clauses}

info[goal] = ("negated query", None)

support, done = [goal], set()

allc = clauses + [goal]

while support:

c = support.pop(0)

for d in list(allc):

if (c, d) in done: continue

done.add((c, d)); done.add((d, c))

for r in resolve(c, d):

if r in info: continue

info[r] = ("resolve", (c, d))

if not r:

return trace(r, info)

support.append(r); allc.append(r)

print(" no proof: the query does not follow\n")

return False

def trace(empty, info):

order, seen = [], set()

def visit(c):

if c in seen: return

seen.add(c)

kind, par = info[c]

if par:

visit(par[0]); visit(par[1])

order.append(c)

visit(empty)

num = {}

for i, c in zip(count(1), order):

num[c] = i

kind, par = info[c]

why = kind if not par else f"resolve {num[par[0]]} + {num[par[1]]}"

print(f" {i:>2}. {show(c):<22} {why}")

print(" The empty clause was reached, so the query is PROVED.\n")

return True

if __name__ == "__main__":

# Example 1: L06 homework Task 3 - attendance (modus tollens)

prove([{"~A", "E"}, {"~E"}], "~A", "Example 1: KB = {A → E, ¬E}. Query: ¬A")

# Example 2: dengue rules (L05 style) in clause form

dengue = [{"~F", "~B", "V"}, # fever ∧ body_ache → viral

{"~V", "~S", "T"}, # viral ∧ dengue_season → test

{"~T", "~L", "D"}, # test ∧ low_platelets → dengue_suspected

{"F"}, {"B"}, {"S"}, {"L"}]

prove(dengue, "D", "Example 2: dengue KB (3 rules, 4 facts). Query: D (dengue suspected)")

# Example 3: a query that does NOT follow

prove([{"~R", "W"}, {"W"}], "R", "Example 3: KB = {R → W, W}. Query: R (converse trap)")

Real output:

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 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

Example 1 is modus tollens done by resolution. Example 3 shows soundness: the converse R does not follow from R → W and W, and the prover correctly finds no proof.

4. Resolution in First-Order Logic

§4.1 Unification

Slide L08-S15

In FOL, P(x) and ¬P(Ali) are complementary only after we substitute x = Ali. Unification finds a substitution (unifier) that makes two atoms identical. Variables are lower case; constants start with a capital letter.

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)

Knows(Ali, y) and Knows(y, Sana) fail because y cannot be both Ali and Sana; if the two sentences came from different rules we first rename variables apart (y → y1). Different predicates never unify.

Clause 1

Clause 2

Unifier

Resolvent

¬Student(x) ∨ ¬Att75(x) ∨ Eligible(x)

Student(Ali)

{x/Ali}

¬Att75(Ali) ∨ Eligible(Ali)

¬Att75(Ali) ∨ Eligible(Ali)

Att75(Ali)

{ }

Eligible(Ali)

In Prolog (Lecture 9) the same rule is written eligible(X) :- student(X), att75(X). and the query ?- eligible(ali). is answered by unification and resolution.

5. Common Mistakes

Wrong idea

Correct idea

To prove α, add α to the KB.

Add ¬α and look for the empty clause.

From P → Q and Q, conclude P.

Invalid; only modus ponens (from P) and modus tollens (from ¬Q) are valid.

(P ∨ Q) and (¬P ∨ ¬Q) resolve to □.

Resolve ONE pair: the result is Q ∨ ¬Q (a tautology).

A → B becomes A ∨ ¬B.

A → B ≡ ¬A ∨ B.

Knows(Ali, y) unifies with Knows(y, Sana).

It fails; rename variables apart first.

Word Bank

Word

Simple meaning

Example

Inference

Deriving new sentences from old ones

From R → W and R derive W

Sound

Never proves a false conclusion

Every rule of S07

Literal

An atom or its negation

P, ¬P

Clause

Literals joined by OR

¬F ∨ ¬B ∨ V

CNF

An AND of clauses

(¬W ∨ C) ∧ (¬W ∨ ¬R)

Resolvent

The clause made by resolution

A ∨ C

Refutation

Proof by contradiction

Add ¬α, reach □

Empty clause □

A clause with no literals = contradiction

P resolved with ¬P

Unifier

Substitution that makes two atoms the same

{x/Ali}

Summary

  • Inference rules (modus ponens, modus tollens, ...) derive conclusions without truth tables; they are sound.
  • Resolution: from A ∨ P and ¬P ∨ C conclude A ∨ C. It needs the KB in CNF.
  • CNF in four steps: remove ↔, remove →, move ¬ inwards, distribute ∨ over ∧.
  • Refutation: add the negated query; the empty clause proves the query.
  • In FOL, unification makes literals match; this is how Prolog works.

Self-Check Questions

  1. Differentiate KB ⊨ α and KB ⊢ α. What is a sound procedure? (see §1.1)
  2. State modus ponens and modus tollens with a local example each. (see §1.2)
  3. Why is 'from P → Q and Q conclude P' not valid? (see §1.2)
  4. Resolve (Rain ∨ Canal) with (¬Rain ∨ Wet). (see §2.1)
  5. Convert (L ∧ ¬U) → ¬F to CNF. (see §2.2)
  6. Prove ¬A from {A → E, ¬E} by resolution. (see §3)
  7. Find the unifier of Knows(Ali, y) and Knows(x, Sana). (see §4.1)

Reading: Russell & Norvig (4e) 7.5 and 9.2; Luger (6e) 14.1.

← All CS-511 material