CSE-41XX
CS-4101 AI

Lecture 09.2: CNF Conversion and Resolution

How to convert First-Order Logic into Conjunctive Normal Form (CNF) and use Resolution graphs to prove theorems.

To perform automated theorem proving, AI systems convert logical sentences into a standardized format called Conjunctive Normal Form (CNF). A sentence in CNF is a conjunction (\land) of clauses, where each clause is a disjunction (\lor) of literals (a literal is a predicate or its negation).


Why Use Normal Forms?

Converting complex logical sentences into normal forms (like CNF or DNF) provides several major advantages for AI reasoning systems:

  1. Common Language: Acts as a unified standard for logic-based AI systems, enabling consistent knowledge representation and exchange.
  2. Simplifies Reasoning: Standardized structural formats allow inference algorithms to operate systematically without needing custom logic for arbitrary sentence structures.
  3. Automated Theorem Proving: Advanced reasoning algorithms—most notably Resolution—require statements to be in CNF to function correctly and efficiently.
  4. Knowledge Base Management: Facts and rules in a Knowledge Base (KB) are easier to store, query, index, and update when maintained in a consistent normal form.
  5. Algorithm Compatibility & SAT Solvers: Specialized solvers (such as modern SAT and SMT solvers) operate directly on CNF clauses to perform satisfiability checking and inference efficiently.
  6. Universality: Every sentence in First-Order Logic can be converted into an inferentially equivalent CNF formula without losing logical meaning.

The Six Steps of CNF Conversion

Every First-Order Logic (FOL) sentence can be converted to CNF using a systematic six-step procedure.

We illustrate the procedure using the sentence: "Everyone who loves all animals is loved by someone."

x[y(Animal(y)Loves(x,y))yLoves(y,x)]\forall x \left[ \forall y (\text{Animal}(y) \Rightarrow \text{Loves}(x, y)) \Rightarrow \exists y \text{Loves}(y, x) \right]

Step 1: Eliminate Biconditionals and Implications

Replace all implications (\Rightarrow) and biconditionals (\Leftrightarrow) using equivalent disjunctions:

  • AB¬ABA \Rightarrow B \equiv \neg A \lor B
  • AB(¬AB)(¬BA)A \Leftrightarrow B \equiv (\neg A \lor B) \land (\neg B \lor A)

Applying this to our example sentence: x[¬y(¬Animal(y)Loves(x,y))yLoves(y,x)]\forall x \left[ \neg \forall y (\neg \text{Animal}(y) \lor \text{Loves}(x, y)) \lor \exists y \text{Loves}(y, x) \right]


Step 2: Move Negations Inward

Push negation symbols (¬\neg) inward until they apply only to individual predicates, using De Morgan's laws and quantifier negation rules:

  • ¬(AB)¬A¬B\neg (A \lor B) \equiv \neg A \land \neg B
  • ¬(AB)¬A¬B\neg (A \land B) \equiv \neg A \lor \neg B
  • ¬xP(x)x¬P(x)\neg \forall x P(x) \equiv \exists x \neg P(x)
  • ¬xP(x)x¬P(x)\neg \exists x P(x) \equiv \forall x \neg P(x)
  • ¬(¬A)A\neg (\neg A) \equiv A

Pushing ¬\neg inward: x[y¬(¬Animal(y)Loves(x,y))yLoves(y,x)]\forall x \left[ \exists y \neg(\neg \text{Animal}(y) \lor \text{Loves}(x, y)) \lor \exists y \text{Loves}(y, x) \right] x[y(Animal(y)¬Loves(x,y))yLoves(y,x)]\forall x \left[ \exists y (\text{Animal}(y) \land \neg \text{Loves}(x, y)) \lor \exists y \text{Loves}(y, x) \right]


Step 3: Standardize Variables

Ensure every quantifier uses a unique variable name to prevent scope overlaps: x[y(Animal(y)¬Loves(x,y))(zQ(z))]\forall x \left[ \exists y (\text{Animal}(y) \land \neg \text{Loves}(x, y)) \lor (\exists z \text{Q}(z)) \right]

Renaming the second yy to zz: x[y(Animal(y)¬Loves(x,y))zLoves(z,x)]\forall x \left[ \exists y (\text{Animal}(y) \land \neg \text{Loves}(x, y)) \lor \exists z \text{Loves}(z, x) \right]


Step 4: Skolemize Existential Quantifiers

Skolemization eliminates existential quantifiers (\exists) by replacing existential variables with Skolem constants or Skolem functions:

  • Skolem Constant: Used when an existential quantifier is not enclosed within any universal quantifier scope. Replace the existential variable with a new constant symbol (e.g., xRich(x)Rich(G1)\exists x \text{Rich}(x) \to \text{Rich}(G_1)).
  • Skolem Function: Used when an existential quantifier lies within the scope of a universal quantifier. The existential variable depends on the universally quantified variable, so it is replaced with a new function of that variable.

Skolemization Examples

  1. Example 1 (Skolem Function): "For every person xx, there exists a person yy that xx loves" (xyLoves(x,y)\forall x \exists y \text{Loves}(x, y)).
    • Replacing yy with Skolem function cc or f(x)f(x) yields: xLoves(x,f(x))\forall x \text{Loves}(x, f(x)). (The person loved depends on xx).
  2. Example 2 (Mother function): xy(Mother(x,y)Loves(y,x))\forall x \exists y (\text{Mother}(x, y) \land \text{Loves}(y, x)).
    • Replacing yy with Skolem function mother_of(x)\text{mother\_of}(x) yields: x(Mother(x,mother_of(x))Loves(mother_of(x),x))\forall x (\text{Mother}(x, \text{mother\_of}(x)) \land \text{Loves}(\text{mother\_of}(x), x)).
  3. Example 3 ("Everyone has a heart"): x(Person(x)y(Heart(y)Has(x,y)))\forall x (\text{Person}(x) \Rightarrow \exists y (\text{Heart}(y) \land \text{Has}(x, y))).
    • Skolemizing yH(x)y \to H(x) yields: x(Person(x)Heart(H(x))Has(x,H(x)))\forall x (\text{Person}(x) \Rightarrow \text{Heart}(H(x)) \land \text{Has}(x, H(x))).

In our sentence:

  • Existential variable yy is inside universal quantifier x    x \implies replace yy with F(x)F(x).
  • Existential variable zz is inside universal quantifier x    x \implies replace zz with G(x)G(x).

x[(Animal(F(x))¬Loves(x,F(x)))Loves(G(x),x)]\forall x \left[ (\text{Animal}(F(x)) \land \neg \text{Loves}(x, F(x))) \lor \text{Loves}(G(x), x) \right]


Step 5: Drop Universal Quantifiers

Since all remaining variables are universally quantified, we drop the explicit \forall symbols. All variables are implicitly assumed to be universally quantified: (Animal(F(x))¬Loves(x,F(x)))Loves(G(x),x)\left( \text{Animal}(F(x)) \land \neg \text{Loves}(x, F(x)) \right) \lor \text{Loves}(G(x), x)


Step 6: Distribute \lor over \land

Use the distributive law (AB)C(AC)(BC)(A \land B) \lor C \equiv (A \lor C) \land (B \lor C) to yield conjunctions of disjunctions: (Animal(F(x))Loves(G(x),x))(¬Loves(x,F(x))Loves(G(x),x))\left( \text{Animal}(F(x)) \lor \text{Loves}(G(x), x) \right) \land \left( \neg \text{Loves}(x, F(x)) \lor \text{Loves}(G(x), x) \right)

This gives two final CNF clauses:

  • Clause 1a: Animal(F(x))Loves(G(x),x)\text{Animal}(F(x)) \lor \text{Loves}(G(x), x)
  • Clause 1b: ¬Loves(x,F(x))Loves(G(x),x)\neg \text{Loves}(x, F(x)) \lor \text{Loves}(G(x), x)

Resolution and Resolution Rules

Resolution is a powerful inference rule for automated theorem proving in CNF formulas.

The Resolution Rule

Given two clauses containing complementary literals (e.g., AA and ¬A\neg A), resolution eliminates the complementary literals and combines the remaining literals into a new clause called the resolvent:

Clause 1: ABClause 2: ¬ACResolvent: BC\frac{\text{Clause 1: } A \lor B \quad \quad \text{Clause 2: } \neg A \lor C}{\text{Resolvent: } B \lor C}

Proof by Contradiction (Refutation Procedure)

To prove a query GG from a Knowledge Base KBKB:

  1. Negate the Goal: Assume ¬G\neg G.
  2. Convert to FOPL: Translate all facts, rules, and ¬G\neg G into First-Order Logic.
  3. Convert to CNF: Standardize all sentences into CNF clauses.
  4. Derive Contradiction: Repeatedly apply the resolution rule to derive the empty clause (\bot). Deriving \bot proves that KB¬GKB \land \neg G is unsatisfiable, thus proving GG is true.

Resolution Graphs

A Resolution Graph is a Directed Acyclic Graph (DAG) that visualizes the step-by-step resolution process:

  • Nodes: Represent individual clauses (either initial input clauses or derived resolvents).
  • Edges: Point from parent clauses to their derived resolvent clause.
  • Leaf Nodes: The original input clauses from the KB and negated goal.
  • Root Node: The empty clause (\bot), indicating contradiction and completing the proof.

Simple Resolution Graph Example

Given the CNF clauses:

  1. ABA \lor B
  2. ¬A\neg A
  3. ¬B\neg B
  • Step 1: Resolve Clause (1) ABA \lor B and Clause (2) ¬A\neg A by eliminating AA and ¬A    \neg A \implies Resolvent: BB.
  • Step 2: Resolve BB with Clause (3) ¬B    \neg B \implies Resolvent: \bot (Contradiction).

Resolution Example 1: Jack and Nature

Let's solve a complete resolution problem step by step:

Domain Facts:

  1. Everyone who loves all animals is a lover of nature.
  2. Jack loves all animals.
  3. Cats are animals.
  4. Jack does not love nature.

Step 1: Formalize in FOL and Convert to CNF

  1. Statement 1: x[(y(Animal(y)Loves(x,y)))LovesNature(x)]\forall x \left[ (\forall y (\text{Animal}(y) \Rightarrow \text{Loves}(x, y))) \Rightarrow \text{LovesNature}(x) \right]

    • Implication removal: x[¬(y(¬Animal(y)Loves(x,y)))LovesNature(x)]\forall x \left[ \neg (\forall y (\neg \text{Animal}(y) \lor \text{Loves}(x, y))) \lor \text{LovesNature}(x) \right]
    • Push negation inward: x[(y(Animal(y)¬Loves(x,y)))LovesNature(x)]\forall x \left[ (\exists y (\text{Animal}(y) \land \neg \text{Loves}(x, y))) \lor \text{LovesNature}(x) \right]
    • Skolemize (yf(x)y \to f(x)): x[(Animal(f(x))¬Loves(x,f(x)))LovesNature(x)]\forall x \left[ (\text{Animal}(f(x)) \land \neg \text{Loves}(x, f(x))) \lor \text{LovesNature}(x) \right]
    • Distribute \lor over \land:
      • Clause 1a (C1a): Animal(f(x))LovesNature(x)\text{Animal}(f(x)) \lor \text{LovesNature}(x)
      • Clause 1b (C1b): ¬Loves(x,f(x))LovesNature(x)\neg \text{Loves}(x, f(x)) \lor \text{LovesNature}(x)
  2. Statement 2: y(Animal(y)Loves(Jack,y))\forall y (\text{Animal}(y) \Rightarrow \text{Loves}(\text{Jack}, y))

    • Clause 2 (C2): ¬Animal(y)Loves(Jack,y)\neg \text{Animal}(y) \lor \text{Loves}(\text{Jack}, y)
  3. Statement 3: Cats are animals.

    • Clause 3 (C3): Animal(Cat)\text{Animal}(\text{Cat})
  4. Statement 4: Jack does not love nature.

    • Clause 4 (C4): ¬LovesNature(Jack)\neg \text{LovesNature}(\text{Jack})

Step 2: Resolution Derivations

  1. Resolve C2 and C3 with substitution {y/Cat}\{y / \text{Cat}\}:
    • Parent 1: ¬Animal(y)Loves(Jack,y)\neg \text{Animal}(y) \lor \text{Loves}(\text{Jack}, y)
    • Parent 2: Animal(Cat)\text{Animal}(\text{Cat})
    • Clause 5 (C5): Loves(Jack,Cat)\text{Loves}(\text{Jack}, \text{Cat})
  2. Resolve C1b and C5 with substitution {x/Jack,f(Jack)=Cat}\{x / \text{Jack}, f(\text{Jack}) = \text{Cat}\}:
    • Parent 1: ¬Loves(x,f(x))LovesNature(x)\neg \text{Loves}(x, f(x)) \lor \text{LovesNature}(x)
    • Parent 2: Loves(Jack,Cat)\text{Loves}(\text{Jack}, \text{Cat})
    • Clause 6 (C6): LovesNature(Jack)\text{LovesNature}(\text{Jack})
  3. Resolve C6 and C4:
    • Parent 1: LovesNature(Jack)\text{LovesNature}(\text{Jack})
    • Parent 2: ¬LovesNature(Jack)\neg \text{LovesNature}(\text{Jack})
    • Clause 7 (C7): \bot (Contradiction!)

Step 3: Resolution Graph (Jack and Nature)


Resolution Example 2: "Curiosity Killed the Cat"

Let's work through the classic theorem-proving puzzle:

Facts:

  1. Everyone who loves all animals is loved by someone.
  2. Anyone who kills an animal is loved by no one.
  3. Jack loves all animals.
  4. Either Jack or Curiosity killed the cat, who is named Tuna.
  5. Tuna is a cat.
  6. Cats are animals.

Goal: Prove that Curiosity killed the cat (Kills(Curiosity,Tuna)\text{Kills}(\text{Curiosity}, \text{Tuna})).

Step A: Negated Goal

¬G:¬Kills(Curiosity,Tuna)\neg G: \quad \neg \text{Kills}(\text{Curiosity}, \text{Tuna})

Step B: Sentences in FOL and CNF Clauses

  • Statement A: x[(yAnimal(y)Loves(x,y))yLoves(y,x)]\forall x \left[ (\forall y \text{Animal}(y) \Rightarrow \text{Loves}(x, y)) \Rightarrow \exists y \text{Loves}(y, x) \right]
    • Clause A1: Animal(F(x))Loves(G(x),x)\text{Animal}(F(x)) \lor \text{Loves}(G(x), x)
    • Clause A2: ¬Loves(x,F(x))Loves(G(x),x)\neg \text{Loves}(x, F(x)) \lor \text{Loves}(G(x), x)
  • Statement B: x[(zAnimal(z)Kills(x,z))(y¬Loves(y,x))]\forall x \left[ (\exists z \text{Animal}(z) \land \text{Kills}(x, z)) \Rightarrow (\forall y \neg \text{Loves}(y, x)) \right]
    • Clause B: ¬Loves(y,x)¬Animal(z)¬Kills(x,z)\neg \text{Loves}(y, x) \lor \neg \text{Animal}(z) \lor \neg \text{Kills}(x, z)
  • Statement C: x(Animal(x)Loves(Jack,x))\forall x (\text{Animal}(x) \Rightarrow \text{Loves}(\text{Jack}, x))
    • Clause C: ¬Animal(w)Loves(Jack,w)\neg \text{Animal}(w) \lor \text{Loves}(\text{Jack}, w)
  • Statement D: Kills(Jack,Tuna)Kills(Curiosity,Tuna)\text{Kills}(\text{Jack}, \text{Tuna}) \lor \text{Kills}(\text{Curiosity}, \text{Tuna})
    • Clause D: Kills(Jack,Tuna)Kills(Curiosity,Tuna)\text{Kills}(\text{Jack}, \text{Tuna}) \lor \text{Kills}(\text{Curiosity}, \text{Tuna})
  • Statement E: Cat(Tuna)\text{Cat}(\text{Tuna})
    • Clause E: Cat(Tuna)\text{Cat}(\text{Tuna})
  • Statement F: x(Cat(x)Animal(x))\forall x (\text{Cat}(x) \Rightarrow \text{Animal}(x))
    • Clause F: ¬Cat(u)Animal(u)\neg \text{Cat}(u) \lor \text{Animal}(u)
  • Statement ¬G\neg G (Negated Goal):
    • Clause G: ¬Kills(Curiosity,Tuna)\neg \text{Kills}(\text{Curiosity}, \text{Tuna})

Step C: Step-by-Step Resolution Trace

  1. Resolve E and F ({u/Tuna}\{u / \text{Tuna}\}):
    • Parent 1: Cat(Tuna)\text{Cat}(\text{Tuna})
    • Parent 2: ¬Cat(u)Animal(u)\neg \text{Cat}(u) \lor \text{Animal}(u)
    • Resolvent R1: Animal(Tuna)\text{Animal}(\text{Tuna})
  2. Resolve D and G:
    • Parent 1: Kills(Jack,Tuna)Kills(Curiosity,Tuna)\text{Kills}(\text{Jack}, \text{Tuna}) \lor \text{Kills}(\text{Curiosity}, \text{Tuna})
    • Parent 2: ¬Kills(Curiosity,Tuna)\neg \text{Kills}(\text{Curiosity}, \text{Tuna})
    • Resolvent R2: Kills(Jack,Tuna)\text{Kills}(\text{Jack}, \text{Tuna})
  3. Resolve B and R2 ({x/Jack,z/Tuna}\{x / \text{Jack}, z / \text{Tuna}\}):
    • Parent 1: ¬Loves(y,x)¬Animal(z)¬Kills(x,z)\neg \text{Loves}(y, x) \lor \neg \text{Animal}(z) \lor \neg \text{Kills}(x, z)
    • Parent 2: Kills(Jack,Tuna)\text{Kills}(\text{Jack}, \text{Tuna})
    • Resolvent R3: ¬Loves(y,Jack)¬Animal(Tuna)\neg \text{Loves}(y, \text{Jack}) \lor \neg \text{Animal}(\text{Tuna})
  4. Resolve R3 and R1:
    • Parent 1: ¬Loves(y,Jack)¬Animal(Tuna)\neg \text{Loves}(y, \text{Jack}) \lor \neg \text{Animal}(\text{Tuna})
    • Parent 2: Animal(Tuna)\text{Animal}(\text{Tuna})
    • Resolvent R4: ¬Loves(y,Jack)\neg \text{Loves}(y, \text{Jack})
  5. Resolve A2 and C ({x/Jack,w/F(Jack)}\{x / \text{Jack}, w / F(\text{Jack})\}):
    • Parent 1: ¬Loves(x,F(x))Loves(G(x),x)\neg \text{Loves}(x, F(x)) \lor \text{Loves}(G(x), x)
    • Parent 2: ¬Animal(w)Loves(Jack,w)\neg \text{Animal}(w) \lor \text{Loves}(\text{Jack}, w)
    • Resolvent R5: ¬Animal(F(Jack))Loves(G(Jack),Jack)\neg \text{Animal}(F(\text{Jack})) \lor \text{Loves}(G(\text{Jack}), \text{Jack})
  6. Resolve R5 and A1 ({x/Jack}\{x / \text{Jack}\}):
    • Parent 1: ¬Animal(F(Jack))Loves(G(Jack),Jack)\neg \text{Animal}(F(\text{Jack})) \lor \text{Loves}(G(\text{Jack}), \text{Jack})
    • Parent 2: Animal(F(x))Loves(G(x),x)\text{Animal}(F(x)) \lor \text{Loves}(G(x), x)
    • Resolvent R6: Loves(G(Jack),Jack)\text{Loves}(G(\text{Jack}), \text{Jack})
  7. Resolve R6 and R4 ({y/G(Jack)}\{y / G(\text{Jack})\}):
    • Parent 1: Loves(G(Jack),Jack)\text{Loves}(G(\text{Jack}), \text{Jack})
    • Parent 2: ¬Loves(y,Jack)\neg \text{Loves}(y, \text{Jack})
    • Resolvent R7: \bot (Contradiction!)

Step D: The Resolution Graph (Curiosity Killed the Cat)

Deriving the empty clause (\bot) confirms that the negated goal is false, proving conclusively that Curiosity killed the cat.

On this page