You are on page 1of 23

Knowledge Representation &

Reasoning
Unification & Resolution
by
Mr. Om Prakash
Department of IT
KIET Group of Institutions
Contents
❑ Unification with examples
❑ Resolution
❑ Algorithm
❑ Steps for Resolution
❑ Examples
Unification
• Unification is a process of making two different logical atomic
expressions identical by finding a substitution. Unification depends on
the substitution process.
• It takes two literals as input and makes them identical using
substitution.
• Let Ψ1 and Ψ2 be two atomic sentences and 𝜎 be a unifier such
that, Ψ1𝜎 = Ψ2𝜎, then it can be expressed as UNIFY(Ψ1, Ψ2).
• Example: Find the MGU for Unify{King(x), King(John)}
Let Ψ1 = King(x), Ψ2 = King(John),
Substitution θ = {John/x} is a unifier for these atoms and applying this
substitution, and both expressions will be identical.
• if we can find a substitution θ such that King(x) and Greedy(x) match
King(John) and Greedy(y) , θ = {x/John, y/John} works
• Unify(α,β) = θ iff αθ = βθ

p q θ
Knows(John,x) Knows(John,Jane) {x/Jane}

Knows(John,x) Knows(y,OJ) {x/OJ, y/John}

Knows(John,x) Knows(y,Mother(y)) {x/Mother(John),


y/John}
Knows(John,x) Knows(x,OJ) {fail}
Convert the following sentences into FOL:
• Every gardener likes the sun.

• You can fool some of the people all of the time.

• You can fool all of the people some of the time.


• All purple mushrooms are poisonous.

• No purple mushroom is poisonous.

• There are exactly two purple mushrooms.


• Bush is not tall.

• X is above Y iff X is on directly on top of Y or there is a pile of one or


more other objects directly on top of one another starting with X and
ending with Y.
CONJUNCTIVE NORMAL FORMULA
(CNF)
• A sentence represented as a conjunction of clauses is said to
be conjunctive normal form or CNF.
• Steps for First Order Logic (FOL) conversion to CNF
• 1. Eliminate bi-conditionals and implications:
• Eliminate ⇔, replacing α ⇔ β with (α ⇒ β) ∧ (β ⇒ α).
• Eliminate ⇒, replacing α ⇒ β with ¬α ∨ β.
• 2. Move ¬ inwards:
• ¬(∀ x p) ≡ ∃ x ¬p,
• ¬(∃ x p) ≡ ∀ x ¬p,
• ¬(α ∨ β) ≡ ¬α ∧ ¬β,
• ¬(α ∧ β) ≡ ¬α ∨ ¬β,
• ¬¬α ≡ α.
3. Standardize variables apart by renaming them: each quantifier
should use a different variable.
4. Skolemize: each existential variable is replaced by a Skolem constant or
Skolem function of the enclosing universally quantified variables.
For instance, ∃x Rich(x) becomes Rich(G1) where G1 is a new Skolem
constant.
“Everyone has a heart” ∀ x Person(x) ⇒ ∃ y Heart(y) ∧ Has(x, y) becomes ∀ x
Person(x) ⇒ Heart(H(x)) ∧ Has(x, H(x)), where H is a new symbol (Skolem
function).
5. Drop universal quantifiers For instance, ∀ x Person(x) becomes
Person(x).
6. Distribute ∧ over ∨: (α ∧ β) ∨ γ ≡ (α ∨ γ) ∧ (β ∨ γ).
Exercise:
• Convert “Everybody who loves all animals is loved by someone” to CNF
• (∀x)[(∀y){Animal(y) → Loves(x,y)} → (∃y) Loves(y,x)]
Solution:
1. Eliminate implications: ∀x [¬∀y ¬Animal(y) ∨ Loves(x, y)] ∨ [∃y Loves(y, x)]
2. Move ¬ inwards

• a) ∀x [∃y ¬(¬Animal(y) ∨ Loves(x, y))] ∨ [∃y Loves(y, x)]


• b) ∀x [∃y ¬¬Animal(y) ∧ ¬Loves(x, y)] ∨ [∃y Loves(y, x)] (De Morgan)
• c) ∀x [∃y Animal(y) ∧ ¬Loves(x, y)] ∨ [∃y Loves(y, x)] (double negation)
3. Standardize variables:
∀x [∃y Animal(y) ∧ ¬Loves(x, y)] ∨ [∃z Loves(z, x)]
4. Skolemization:
∀x [Animal(F(x)) ∧ ¬Loves(x, F(x))] ∨ [Loves(G(x), x)]
5. Drop universal quantifiers:
[Animal(F(x)) ∧ ¬Loves(x, F(x))] ∨ [Loves(G(x), x)]
6. Distribute ∨ over ∧:
[Animal(F(x)) ∨ Loves(G(x), x)] ∧ [¬Loves(x, F(x)) ∨ Loves(G(x), x)]
RESOLUTION
• Resolution yields a complete inference algorithm when coupled with
any complete search algorithm.
• Resolution makes use of the inference rules.
• Resolution performs deductive inference.
• Resolution uses proof by contradiction.
• One can perform Resolution from a Knowledge Base.
• A Knowledge Base is a collection of facts or one can even call it a
database with all facts.
ALGORITHM
Let f be a set of given statements and S is a statement to be proved.
• 1. Covert all the statements of F to clause form.
• 2. Negate S and convert the result to clause form. Add it to the set of
clauses obtained in 1.
• 3. Repeat until either a contradiction is found or no progress can be made
or a predetermined amount of effort has been expended.
a. Select two clauses. Call them parent clauses.
b. Resolve them together. The resolvent will be the
disjunction of all of these literals of both clauses.
• If there is a pair of literals T1 and T2 such that one parent clause
contains T1 and the other contains T2 and if T1 and T2 are unifiable,
then neither T1 nor T2 should appear in the resolvent.
• Here T1 and T2 are called complimentary literals.
c. If the resolvent is the empty clause, then a contradiction has been
found. If it is not, then add it to the set of clauses available to the
procedure.
Steps for Resolution
1. Conversion of facts into first-order logic.
2. Convert FOL statements into CNF(Conjuctive Normal Form)
3. Negate the statement which needs to prove (proof by contradiction)
4. Draw resolution graph (unification).
• To better understand all the above steps, we will take an example in
which we will apply resolution.
• Example:
• Convert the following sentence into predicate logic and then prove "Was
Marcus loyal to Caesar? using resolution:
1. Marcus was a man.
2. Marcus was a Pompeian.
3. All Pompeians were Romans.
4. Caesar was a ruler.
5. All Romans were either loyal to Caesar or hated him.
6. Everyone is loyal to someone.
7. People only try to assassinate rulers they are not loyal to.
8. Marcus tried to assassinate Caesar.
• Step-1: Conversion of Facts into FOL
• 1. Marcus was a man. man(Marcus)
• 2. Marcus was a Pompeian. Pompeian(Marcus)
• 3. All Pompeians were Romans.
• ∀x: Pompeian(x) → Roman(x)
• 4. Caesar was a ruler. ruler(Caesar)
• 5. All Romans were either loyal to Caesar or hated him.
∀x: Roman(x) → loyalto(X, Caesar) V hate(x, Caesar)
• 6. Everyone is loyal to someone.
∀x : → y: Ioyalto(x,y)
• 7. People only try to assassinate rulers they are not loyal to.
∀ x : ∀ y : person(x) ∧ ruler(y) ∧ tryassassinate(x,y) → ¬ Ioyalto(x,y)
• 8. Marcus tried to assassinate Caesar.
tryassassinate (Marcus, Caesar)
• Additional: ∀x: man(x) → person(x)
∀x: rman(x) V person(x)
• 9. rman(x) V person(x)
• Step-2: Conversion of FOL into CNF
• Eliminate all implication (→) and rewrite
• Move negation (¬)inwards and rewrite
• Rename variables or standardize variables
• Eliminate existential instantiation quantifier by elimination
• Drop Universal quantifiers
CNF
• man(Marcus)
• Pompeian(Marcus)
• ¬ Pompeian(x1) V Roman(x1)
• ruler(Caesar)
• ¬ Roman(x2) V loyalto(x2, Caesar) V hate(x2, Caesar)
• loyalto(x3, S1(x3))
• ¬ person(x4) V ¬ruler(y1) V ¬Vtryassassinate(x4, y1) V ¬loyalto(x4, y1)
• tryassassinate(Marcus, Caesar)
• Step-3: Negate the statement to be proved

• In this statement, we will apply negation to the conclusion


statements, which will be written as loyalto(M,C)
Resolution tree:
Step-4: Draw Resolution graph:
Thank
You

You might also like