Download as pdf or txt
Download as pdf or txt
You are on page 1of 15

CS 2740 Knowledge Representation

Lecture 10

First order logic.


Efficient inferences.

Milos Hauskrecht
milos@cs.pitt.edu
5329 Sennott Square

CS 2740 Knowledge Representation M. Hauskrecht

Inference with generalized resolution rule


• Proof by refutation:
– Prove that KB , ¬ α is unsatisfiable
– resolution is refutation-complete

• Main procedure (steps):


1. Convert KB , ¬ α to CNF with ground terms and
universal variables only
2. Apply repeatedly the resolution rule while keeping track
and consistency of substitutions
3. Stop when empty set (contradiction) is derived or no more
new resolvents (conclusions) follow

CS 2740 Knowledge Representation M. Hauskrecht

1
Conversion to CNF
1. Eliminate implications, equivalences
( p ⇒ q ) → (¬ p ∨ q )
( p ⇔ q ) → (¬ p ∨ q ) ∧ (¬ q ∨ p )
2. Move negations inside (DeMorgan’s Laws, double negation)
¬( p ∧ q ) → ¬ p ∨ ¬ q
¬( p ∨ q ) → ¬ p ∧ ¬ q
¬∀ x p → ∃ x ¬ p
¬∃ x p → ∀ x ¬ p
¬¬ p → p
3. Standardize variables (rename duplicate variables)
( ∀ x P ( x )) ∨ ( ∃ x Q ( x )) → ( ∀ x P ( x )) ∨ ( ∃ y Q ( y ))

CS 2740 Knowledge Representation M. Hauskrecht

Conversion to CNF
4. Move all quantifiers left (no invalid capture possible )
( ∀ x P ( x )) ∨ ( ∃ y Q ( y )) → ∀ x ∃ y P ( x ) ∨ Q ( y )

5. Skolemization (removal of existential quantifiers through


elimination)
∃y P ( A) ∨ Q ( y ) → P ( A) ∨ Q ( B )
• If no universal quantifier occurs before the existential
quantifier, replace the variable with a new constant symbol
∀ x ∃ y P ( x ) ∨ Q ( y ) → ∀ x P ( x ) ∨ Q ( F ( x ))
• If a universal quantifier precede the existential quantifier
replace the variable with a function of the “universal” variable
F ( x ) - a Skolem function
CS 2740 Knowledge Representation M. Hauskrecht

2
Conversion to CNF
6. Drop universal quantifiers (all variables are universally
quantified)
∀ x P ( x ) ∨ Q ( F ( x )) → P ( x ) ∨ Q ( F ( x ))

7. Convert to CNF using the distributive laws


p ∨ (q ∧ r ) → ( p ∨ q ) ∧ ( p ∨ r )

The result is a CNF with variables, constants, functions

CS 2740 Knowledge Representation M. Hauskrecht

Resolution example
KB ¬α
¬ P ( w ) ∨ Q ( w ) , ¬ Q ( y ) ∨ S ( y ) , P ( x ) ∨ R ( x ) , ¬ R ( z ) ∨ S ( z ) , ¬S (A)

{ y / w}
¬P (w) ∨ S (w) { x / w}

{ z / w}
S (w) ∨ R (w)

S (w ) { w / A}

KB |= α
Contradiction
CS 2740 Knowledge Representation M. Hauskrecht

3
Answer predicate

CS 2740 Knowledge Representation M. Hauskrecht

Disjunctive answers

CS 2740 Knowledge Representation M. Hauskrecht

4
Efficiency of resolution

For the propositionalized KB


- worst case is exponential in the number literals
Speed ups of the resolution-refutation algorithm:
– Clause elimination. Pure clause contains literal r such that r
does not appear in any other clause. The clause cannot lead to
the contradiction {}.
– Tautology. A clause with a literal and its negation. Any path
to {} can bypass tautology
– Subsumed clause. A clause for which there exists another
clause with only a subset of its literals. A path to {} need only
pass through the short clause.
• can be generalized to allow substitutions

CS 2740 Knowledge Representation M. Hauskrecht

Efficiency of resolution

Speed-ups:
• Ordering strategies
– many possible ways to order search, but best and simplest is
the unit preference
– prefer to resolve unit clauses first
– Why? Given unit clause and another clause, the resolvent is a
smaller one
• Set of support
– KB is usually satisfiable, so not very useful to resolve among
clauses with only ancestors in KB
– contradiction arises from interaction with the negated theorem
– always resolve with at least one clause that has an ancestor in
the negated theorem
CS 2740 Knowledge Representation M. Hauskrecht

5
Efficiency of resolution

Speed-ups:
• Special treatment for equality
– instead of using axioms for equality
– use new inference rule: paramodulation
• Sorted logic
– terms get sorts: (types)
– x: Male mother:[Person Æ Female]
– keep taxonomy of sorts
– only unify P(s) with P(t) when sorts are compatible assumes
only “meaningful” paths will lead to {}

CS 2740 Knowledge Representation M. Hauskrecht

Efficiency of resolution

• Special treatment for equality


– instead of using axioms for equality
– use new inference rule: paramodulation
• Demodulation rule
σ = UNIFY ( z , t1 ) ≠ fail where φk [z] is a literal with z
φ1 ∨ φ2 K∨ φk [ z], t1 = t2
φ1 ∨ K∨ φk [SUBST(σ , t2 )]

• Example: P( f (a)), f ( x) = x
P( a )
• Paramodulation rule: more powerful
• Resolution+paramodulation give a refutation-complete proof
theory for FOL
CS 2740 Knowledge Representation M. Hauskrecht

6
Sentences in Horn normal form
• Horn normal form (HNF) in the propositional logic
– a special type of clause with at most one positive literal
( A ∨ ¬ B ) ∧ (¬ A ∨ ¬ C ∨ D )
Typically written as: ( B ⇒ A ) ∧ (( A ∧ C ) ⇒ D )

• A clause with one literal, e.g. A, is also called a fact


• A clause representing an implication (with a conjunction of
positive literals in antecedent and one positive literal in
consequent), is also called a rule
• Inference for definite clauses:
– Modus ponens inference rule

CS 2740 Knowledge Representation M. Hauskrecht

Horn normal form in FOL


First-order logic (FOL)
– adds variables, works with terms
Generalized modus ponens rule:

σ = a substitution s.t. ∀i SUBST (σ , φi ' ) = SUBST (σ , φi )


φ1 ' , φ 2 ' K , φ n ' , φ1 ∧ φ 2 ∧ K φ n ⇒ τ
SUBST (σ , τ )

Generalized modus ponens:


• is sound and complete for definite clauses and no functions;
• In general it is semidecidable
• Not all first-order logic sentences can be expressed in the HNF
form

CS 2740 Knowledge Representation M. Hauskrecht

7
Forward and backward chaining
Two inference procedures based on modus ponens for Horn KBs:
• Forward chaining
Idea: Whenever the premises of a rule are satisfied, infer the
conclusion. Continue with rules that became satisfied.
Typical usage: If we want to infer all sentences entailed by the
existing KB.
• Backward chaining (goal reduction)
Idea: To prove the fact that appears in the conclusion of a rule
prove the premises of the rule. Continue recursively.
Typical usage: If we want to prove that the target (goal)
sentence α is entailed by the existing KB.

CS 2740 Knowledge Representation M. Hauskrecht

Forward chaining example


• Forward chaining
Idea: Whenever the premises of a rule are satisfied, infer the
conclusion. Continue with rules that became satisfied
Assume the KB with the following rules:
KB: R1: Steamboat ( x ) ∧ Sailboat ( y ) ⇒ Faster ( x , y )
R2: Sailboat ( y ) ∧ RowBoat ( z ) ⇒ Faster ( y , z )
R3: Faster ( x , y ) ∧ Faster ( y , z ) ⇒ Faster ( x , z )
F1: Steamboat (Titanic )
F2: Sailboat (Mistral )
F3: RowBoat (PondArrow)

Theorem: Faster (Titanic , PondArrow ) ?


CS 2740 Knowledge Representation M. Hauskrecht

8
Forward chaining example

KB: R1: Steamboat ( x ) ∧ Sailboat ( y ) ⇒ Faster ( x , y )


R2: Sailboat ( y ) ∧ RowBoat ( z ) ⇒ Faster ( y , z )
R3: Faster ( x , y ) ∧ Faster ( y , z ) ⇒ Faster ( x , z )

F1: Steamboat (Titanic )


F2: Sailboat (Mistral )
F3: RowBoat (PondArrow)
?

CS 2740 Knowledge Representation M. Hauskrecht

Forward chaining example

KB: R1: Steamboat ( x ) ∧ Sailboat ( y ) ⇒ Faster ( x , y )


R2: Sailboat ( y ) ∧ RowBoat ( z ) ⇒ Faster ( y , z )
R3: Faster ( x , y ) ∧ Faster ( y , z ) ⇒ Faster ( x , z )

F1: Steamboat (Titanic )


F2: Sailboat (Mistral )
F3: RowBoat (PondArrow)
Rule R1 is satisfied:
F4: Faster (Titanic, Mistral )

CS 2740 Knowledge Representation M. Hauskrecht

9
Forward chaining example

KB: R1: Steamboat ( x ) ∧ Sailboat ( y ) ⇒ Faster ( x , y )


R2: Sailboat ( y ) ∧ RowBoat ( z ) ⇒ Faster ( y , z )
R3: Faster ( x , y ) ∧ Faster ( y , z ) ⇒ Faster ( x , z )

F1: Steamboat (Titanic )


F2: Sailboat (Mistral )
F3: RowBoat(PondArrow)
Rule R1 is satisfied:
F4: Faster (Titanic, Mistral )
Rule R2 is satisfied:
F5: Faster ( Mistral , PondArrow)

CS 2740 Knowledge Representation M. Hauskrecht

Forward chaining example

KB: R1: Steamboat ( x ) ∧ Sailboat ( y ) ⇒ Faster ( x , y )


R2: Sailboat ( y ) ∧ RowBoat ( z ) ⇒ Faster ( y , z )
R3: Faster ( x , y ) ∧ Faster ( y , z ) ⇒ Faster ( x , z )

F1: Steamboat (Titanic )


F2: Sailboat (Mistral )
F3: RowBoat (PondArrow)
Rule R1 is satisfied:
F4: Faster (Titanic, Mistral )
Rule R2 is satisfied:
F5: Faster ( Mistral , PondArrow)
Rule R3 is satisfied:
F6: Faster (Titanic, PondArrow)
CS 2740 Knowledge Representation M. Hauskrecht

10
Backward chaining example
• Backward chaining (goal reduction)
Idea: To prove the fact that appears in the conclusion of a rule
prove the antecedents (if part) of the rule & repeat recursively.
KB: R1: Steamboat ( x ) ∧ Sailboat ( y ) ⇒ Faster ( x , y )
R2: Sailboat ( y ) ∧ RowBoat ( z ) ⇒ Faster ( y , z )
R3: Faster ( x , y ) ∧ Faster ( y , z ) ⇒ Faster ( x , z )
F1: Steamboat (Titanic )
F2: Sailboat (Mistral )
F3: RowBoat (PondArrow)

Theorem: Faster (Titanic , PondArrow )


CS 2740 Knowledge Representation M. Hauskrecht

Backward chaining example

Faster (Titanic , PondArrow )


F1: Steamboat (Titanic )
R1 F2: Sailboat (Mistral )
F3: RowBoat(PondArrow)
Steamboat(Titanic)

Sailboat(PondArrow)

Steamboat ( x ) ∧ Sailboat ( y ) ⇒ Faster ( x , y )


Faster (Titanic , PondArrow )
{ x / Titanic , y / PondArrow }
CS 2740 Knowledge Representation M. Hauskrecht

11
Backward chaining example

Faster (Titanic , PondArrow ) F1: Steamboat (Titanic )


F2: Sailboat (Mistral )
R1 F3: RowBoat(PondArrow)
R2
Steamboat (Titanic )
Sailboat (Titanic )

Sailboat ( PondArrow ) RowBoat (PondArrow )

Sailboat ( y ) ∧ RowBoat ( z ) ⇒ Faster ( y , z )

Faster (Titanic , PondArrow )


{ y / Titanic , z / PondArrow }
CS 2740 Knowledge Representation M. Hauskrecht

Backward chaining example

F1: Steamboat (Titanic )


Faster (Titanic , PondArrow )
F2: Sailboat (Mistral )
F3: RowBoat(PondArrow)
R1 R3
R2
Steamboat (Titanic )
Sailboat (Titanic ) Faster( y, PondArrow)
Faster(Titanic, y)
Sailboat (PondArrow ) RowBoat (PondArrow )

CS 2740 Knowledge Representation M. Hauskrecht

12
Backward chaining example

F1: Steamboat (Titanic )


Faster (Titanic , PondArrow )
F2: Sailboat (Mistral )
F3: RowBoat(PondArrow)
R1 R3
R2
Steamboat (Titanic )
Sailboat (Titanic ) Faster( y, PondArrow)
Faster(Titanic, y)
Sailboat (PondArrow ) RowBoat (PondArrow )

R1
Steamboat (Titanic )

Sailboat (Mistral )
{ y / Mistral }
CS 2740 Knowledge Representation M. Hauskrecht

Backward chaining example

F1: Steamboat (Titanic )


Faster (Titanic , PondArrow )
F2: Sailboat (Mistral )
F3: RowBoat(PondArrow)
R1 R3
R2
Steamboat (Titanic )
Sailboat (Titanic ) Faster(Mistral, PondArrow)
Faster(Titanic, y)
Sailboat (PondArrow ) RowBoat (PondArrow )

R1
Steamboat (Titanic )

Sailboat (Mistral )
{ y / Mistral }
CS 2740 Knowledge Representation M. Hauskrecht

13
Backward chaining example

F1: Steamboat (Titanic )


Faster (Titanic , PondArrow )
F2: Sailboat (Mistral )
F3: RowBoat(PondArrow)
R1 R3
R2
Steamboat (Titanic )
Sailboat (Titanic ) Faster(Mistral, PondArrow)
Faster(Titanic, y)
Sailboat (PondArrow ) RowBoat (PondArrow )

R2
R1
Steamboat (Titanic ) Sailboat (Mistral )

RowBoat (PondArrow )
Sailboat (Mistral )
{ y / Mistral }
CS 2740 Knowledge Representation M. Hauskrecht

Backward chaining

Faster (Titanic , PondArrow )


y must be bound to
R1 the same term
R2 R3
Steamboat (Titanic )
Sailboat (Titanic ) Faster( y, PondArrow)
Faster(Titanic, y)
Sailboat(PondArrow) RowBoat (PondArrow )

R2
R1
Steamboat (Titanic ) Sailboat (Mistral )

RowBoat (PondArrow )
Sailboat (Mistral )

CS 2740 Knowledge Representation M. Hauskrecht

14
Properties of backward chaining
• Depth-first recursive proof search:
– space is linear in the size of proof
• Incomplete due to possible infinite loops
– fix by checking current goal against every goal on stack
• Inefficient due to repeated subgoals (both success and failure)
– fix using caching of previous results (extra space)
• Widely used for logic programming

CS 2740 Knowledge Representation M. Hauskrecht

15

You might also like