Upload
others
View
2
Download
0
Embed Size (px)
Citation preview
Using Predicate LogicChapter 5Chapter 5Chapter 5Chapter 5
2
26 March, 2009
Cao Hoang Tru
CSE Faculty - HCMUT
Using Propositional LogicRepresenting simple facts
It is rainingRAINING
It is sunnySUNNY
It is windyWINDY
If it is raining, then it is not sunnyRAINING → ¬SUNNY
3
26 March, 2009
Cao Hoang Tru
CSE Faculty - HCMUT
Using Propositional Logic• Theorem proving is decidable
• Cannot represent objects and quantification
4
26 March, 2009
Cao Hoang Tru
CSE Faculty - HCMUT
Using Predicate Logic• Can represent objects and quantification
• Theorem proving is semi-decidable
5
26 March, 2009
Cao Hoang Tru
CSE Faculty - HCMUT
Predicate Logic Syntax• Constant symbols: a, b, c, John, …
to represent primitive objects
• Variable symbols: x, y, z, …
to represent unknown objects
• Predicate symbols: safe, married, love, …
to represent relations
married(John)
love(John, Mary)
6
26 March, 2009
Cao Hoang Tru
CSE Faculty - HCMUT
Predicate Logic Syntax• Function symbols: square, father, …
to represent simple objects
safe(square(1, 2))
love(father(John), mother(John))
• Terms:
to represent complex objects
– Constant symbols
– If f is a function symbol, and t1, t2, …, tn are terms,
then so is f(t1, t2, …, tn)
love(mother(father(John)), John)
7
26 March, 2009
Cao Hoang Tru
CSE Faculty - HCMUT
Predicate Logic Syntax• Logical connectives: ¬, ∧, ∨, ⇒, ⇔
• Universal quantifier: ∀x: p(x)
∀x: love(father(x), mother(x))
• Existential quantifier: ∃x: p(x) ≡ ¬∀x: ¬p(x)
∃x: ¬married(x)
8
26 March, 2009
Cao Hoang Tru
CSE Faculty - HCMUT
Predicate Logic Syntax• Sentences:
– Atomic sentences: p(t1, t2, …, tn)– If α is a sentence, then so are ¬α and (α)– If α and β are sentences, then so are α ∧ β, α ∨ β, α ⇒ β,
and α ⇔ β
– If α is a sentence, then so are ∀α and ∃α
9
26 March, 2009
Cao Hoang Tru
CSE Faculty - HCMUT
Using Predicate Logic1. Marcus was a man.2. Marcus was a Pompeian.3. All Pompeians were Romans.4. Caesar was a ruler.5. All Pompeians were either loyal to Caesar or hated him.6. Every one is loyal to someone.7. People only try to assassinate rulers they are not loyal to.8. Marcus tried to assassinate Caesar.
10
26 March, 2009
Cao Hoang Tru
CSE Faculty - HCMUT
Using Predicate Logic1. Marcus was a man.
man(Marcus)
11
26 March, 2009
Cao Hoang Tru
CSE Faculty - HCMUT
Using Predicate Logic2. Marcus was a Pompeian.
Pompeian(Marcus)
12
26 March, 2009
Cao Hoang Tru
CSE Faculty - HCMUT
Using Predicate Logic3. All Pompeians were Romans.
∀x: Pompeian(x) → Roman(x)
13
26 March, 2009
Cao Hoang Tru
CSE Faculty - HCMUT
Using Predicate Logic4. Caesar was a ruler.
ruler(Caesar)
14
26 March, 2009
Cao Hoang Tru
CSE Faculty - HCMUT
Using Predicate Logic5. All Pompeians were either loyal to Caesar or hated him.
inclusive-or∀x: Roman(x) → loyalto(x, Caesar) ∨ hate(x, Caesar)
exclusive-or∀x: Roman(x) → (loyalto(x, Caesar) ∧ ¬hate(x, Caesar)) ∨
(¬loyalto(x, Caesar) ∧ hate(x, Caesar))
15
26 March, 2009
Cao Hoang Tru
CSE Faculty - HCMUT
Using Predicate Logic6. Every one is loyal to someone.
∀x: ∃y: loyalto(x, y) ∃y: ∀x: loyalto(x, y)
16
26 March, 2009
Cao Hoang Tru
CSE Faculty - HCMUT
Using Predicate Logic7. People only try to assassinate rulers they are not loyal to.
∀x: ∀y: person(x) ∧ ruler(y) ∧ tryassassinate(x, y) → ¬loyalto(x, y)
17
26 March, 2009
Cao Hoang Tru
CSE Faculty - HCMUT
Using Predicate Logic7. People only try to assassinate rulers they are not loyal to.
∀x: ∀y: person(x) ∧ ruler(y) ∧ tryassassinate(x, y) → ¬loyalto(x, y)
18
26 March, 2009
Cao Hoang Tru
CSE Faculty - HCMUT
Using Predicate Logic8. Marcus tried to assassinate Caesar.
tryassassinate(Marcus, Caesar)
19
26 March, 2009
Cao Hoang Tru
CSE Faculty - HCMUT
Using Predicate LogicWas Marcus loyal to Caesar?
man(Marcus)ruler(Caesar)tryassassinate(Marcus, Caesar)
⇓ ∀x: man(x) → person(x)¬loyalto(Marcus, Caesar)
20
26 March, 2009
Cao Hoang Tru
CSE Faculty - HCMUT
Using Predicate Logic• Many English sentences are ambiguous.• There is often a choice of how to represent knowledge.
21
26 March, 2009
Cao Hoang Tru
CSE Faculty - HCMUT
Reasoning1. Marcus was a Pompeian.2. All Pompeians died when the volcano erupted in 79 A.D.3. It is now 2008 A.D.
Is Marcus alive?
22
26 March, 2009
Cao Hoang Tru
CSE Faculty - HCMUT
Reasoning1. Marcus was a Pompeian.
Pompeian(Marcus)2. All Pompeians died when the volcano erupted in 79 A.D.
erupted(volcano, 79) ∧ ∀x: Pompeian(x) → died(x, 79)3. It is now 2008 A.D.
now = 2008
23
26 March, 2009
Cao Hoang Tru
CSE Faculty - HCMUT
Reasoning1. Marcus was a Pompeian.
Pompeian(Marcus)2. All Pompeians died when the volcano erupted in 79 A.D.
erupted(volcano, 79) ∧ ∀x: Pompeian(x) → died(x, 79)3. It is now 2008 A.D.
now = 2008∀x: ∀t1: ∀t2: died(x, t1) ∧ greater-than(t2, t1) → dead(x, t2)
24
26 March, 2009
Cao Hoang Tru
CSE Faculty - HCMUT
Reasoning• Obvious information may be necessary for reasoning• We may not know in advance which statements to
deduce (P or ¬P).
25
26 March, 2009
Cao Hoang Tru
CSE Faculty - HCMUT
ReasoningKB ||||==== α (α is a logical consequence of KB)
How to prove it automatically?
26
26 March, 2009
Cao Hoang Tru
CSE Faculty - HCMUT
ResolutionRobinson, J.A. 1965. A machine-oriented logic based on the resolution principle. Journal of ACM 12 (1): 23-41.
27
26 March, 2009
Cao Hoang Tru
CSE Faculty - HCMUT
ResolutionProof by refutation
KB ||||==== α ⇔⇔⇔⇔ KB ∧∧∧∧ ¬¬¬¬α ||||==== false (empty clause)
28
26 March, 2009
Cao Hoang Tru
CSE Faculty - HCMUT
ResolutionResolution inference rule
(α ∨∨∨∨ ¬¬¬¬β) ∧∧∧∧ (γ ∨∨∨∨ β) premise
(α ∨∨∨∨ γ) conclusion
29
26 March, 2009
Cao Hoang Tru
CSE Faculty - HCMUT
Resolution in Propositional Logic1. Convert all the propositions of KB to clause form (S).
L1 ∨∨∨∨ L2 ∨∨∨∨ … ∨∨∨∨ Ln
P or ¬¬¬¬P
30
26 March, 2009
Cao Hoang Tru
CSE Faculty - HCMUT
Resolution in Propositional Logic1. Convert all the propositions of KB to clause form (S).2. Negate α and convert it to clause form. Add it to S.3. Repeat until either a contradiction is found or no progress can
be made:a. Select two clauses (α ∨∨∨∨ ¬¬¬¬P) and (γ ∨∨∨∨ P).b. Add the resolvent (α ∨∨∨∨ γ) to S.
31
26 March, 2009
Cao Hoang Tru
CSE Faculty - HCMUT
Resolution in Propositional LogicExample:
KB = {P, (P ∧∧∧∧ Q) →→→→ R, (S ∨∨∨∨ T) →→→→ Q, T}α = R
32
26 March, 2009
Cao Hoang Tru
CSE Faculty - HCMUT
Resolution in Predicate LogicExample:KB = {P(a), ∀∀∀∀x: (P(x) ∧∧∧∧ Q(x)) →→→→ R(x), ∀∀∀∀y: (S(y) ∨∨∨∨ T(y)) →→→→ Q(y), T(a)}α = R(a)
33
26 March, 2009
Cao Hoang Tru
CSE Faculty - HCMUT
Resolution in Predicate LogicUnification:
UNIFY(p, q) = unifier θ where θ(p) = θ(q)
34
26 March, 2009
Cao Hoang Tru
CSE Faculty - HCMUT
Resolution in Predicate LogicUnification:∀∀∀∀x: knows(John, x) →→→→ hates(John, x)knows(John, Jane)∀∀∀∀y: knows(y, Leonid)∀∀∀∀y: knows(y, mother(y))∀∀∀∀x: knows(x, Elizabeth)
35
26 March, 2009
Cao Hoang Tru
CSE Faculty - HCMUT
Resolution in Predicate LogicUnification:∀∀∀∀x: knows(John, x) →→→→ hates(John, x)knows(John, Jane)∀∀∀∀y: knows(y, Leonid)∀∀∀∀y: knows(y, mother(y))∀∀∀∀x: knows(x, Elizabeth)
UNIFY(knows(John, x), knows(John, Jane)) = {Jane/x}UNIFY(knows(John, x), knows(y, Leonid)) = {Leonid/x, John/y}UNIFY(knows(John, x), knows(y, mother(y))) = {John/y, mother(John)/x}UNIFY(knows(John, x), knows(x, Elizabeth)) = FAIL
36
26 March, 2009
Cao Hoang Tru
CSE Faculty - HCMUT
Resolution in Predicate LogicUnification: Standardization
UNIFY(knows(John, x), knows(y, Elizabeth)) = {John/y, Elizabeth/x}
37
26 March, 2009
Cao Hoang Tru
CSE Faculty - HCMUT
Resolution in Predicate LogicUnification: Occur check
UNIFY(knows(x, x), knows(y, mother(y))) = FAIL
38
26 March, 2009
Cao Hoang Tru
CSE Faculty - HCMUT
Resolution in Predicate LogicUnification: Most general unifier
UNIFY(knows(John, x), knows(y, z)) = {John/y, John/x, John/z}= {John/y, Jane/x, Jane/z}= {John/y, v/x, v/z}= {John/y, z/x, Jane/v}= {John/y, z/x}
39
26 March, 2009
Cao Hoang Tru
CSE Faculty - HCMUT
Conversion to Clause Form1. Eliminate →.
P → Q ≡ ¬P ∨ Q
2. Reduce the scope of each ¬ to a single term.¬(P ∨ Q) ≡ ¬P ∧ ¬Q¬(P ∧ Q) ≡ ¬P ∨ ¬Q¬∀x: P ≡ ∃x: ¬P¬∃x: p ≡ ∀x: ¬P¬¬ P ≡ P
3. Standardize variables so that each quantifier binds a unique variable.
(∀x: P(x)) ∨ (∃x: Q(x)) ≡ (∀x: P(x)) ∨ (∃y: Q(y))
40
26 March, 2009
Cao Hoang Tru
CSE Faculty - HCMUT
Conversion to Clause Form4. Move all quantifiers to the left without changing their relative order.
∀x: (P(x) ∨ ∃y: Q(y)) ≡ ∀x: ∃y: (P(x) ∨ (Q(y))
(∀x: P(x)) ∨ (∃y: Q(y)): don’t move!
5. Eliminate ∃ (Skolemization).∃x: P(x) ≡ P(c) Skolem constant∀x: ∃y P(x, y) ≡ ∀x: P(x, f(x)) Skolem function
6. Drop ∀.∀x: P(x) ≡ P(x)
7. Convert the formula into a conjunction of disjuncts.(P ∧ Q) ∨ R ≡ (P ∨ R) ∧ (Q ∨ R)
8. Create a separate clause corresponding to each conjunct.9. Standardize apart the variables in the set of obtained clauses.
41
26 March, 2009
Cao Hoang Tru
CSE Faculty - HCMUT
Conversion to Clause Form1. Eliminate →.2. Reduce the scope of each ¬ to a single term.3. Standardize variables so that each quantifier binds a unique
variable.4. Move all quantifiers to the left without changing their relative
order.5. Eliminate ∃ (Skolemization).6. Drop ∀.7. Convert the formula into a conjunction of disjuncts.8. Create a separate clause corresponding to each conjunct.9. Standardize apart the variables in the set of obtained clauses.
42
26 March, 2009
Cao Hoang Tru
CSE Faculty - HCMUT
Resolution in Predicate Logic1. Convert all the propositions of KB to clause form (S).2. Negate α and convert it to clause form. Add it to S.3. Repeat until a contradiction is found:
a. Select two clauses (α ∨∨∨∨ ¬¬¬¬ p(t1, t2, …, tn)) and (γ ∨∨∨∨ p(t’1, t’2, …, t’n)).b. θ = mgu(p(t1, t2, …, tn), p(t’1, t’2, …, t’n))c. Add the resolvent θ(α ∨∨∨∨ γ) to S.
43
26 March, 2009
Cao Hoang Tru
CSE Faculty - HCMUT
Resolution in Predicate LogicExample:KB = {P(a), ∀∀∀∀x: (P(x) ∧∧∧∧ Q(x)) →→→→ R(x), ∀∀∀∀y: (S(y) ∨∨∨∨ T(y)) →→→→ Q(y), T(a)}α = R(a)
44
26 March, 2009
Cao Hoang Tru
CSE Faculty - HCMUT
Example1. Marcus was a man.2. Marcus was a Pompeian.3. All Pompeians were Romans.4. Caesar was a ruler.5. All Pompeians were either loyal to Caesar or hated him.6. Every one is loyal to someone.7. People only try to assassinate rulers they are not loyal to.8. Marcus tried to assassinate Caesar.
45
26 March, 2009
Cao Hoang Tru
CSE Faculty - HCMUT
Example1. Man(Marcus).2. Pompeian(Marcus).3. ∀x: Pompeian(x) → Roman(x).4. ruler(Caesar).5. ∀x: Roman(x) → loyalto(x, Caesar) ∨ hate(x, Caesar).6. ∀x: ∃y: loyalto(x, y).7. ∀x: ∀y: person(x) ∧ ruler(y) ∧ tryassassinate(x, y)
→ ¬loyalto(x, y).8. tryassassinate(Marcus, Caesar).
46
26 March, 2009
Cao Hoang Tru
CSE Faculty - HCMUT
ExampleProve:
hate(Marcus, Caesar)
47
26 March, 2009
Cao Hoang Tru
CSE Faculty - HCMUT
Question Answering1. When did Marcus die?2. Whom did Marcus hate?3. Who tried to assassinate a ruler?4. What happen in 79 A.D.?. 5. Did Marcus hate everyone?
48
26 March, 2009
Cao Hoang Tru
CSE Faculty - HCMUT
Soundness and Completeness• Soundness of a reasoning algorithm/system R:
if KB derives α using R, then KB |=|=|=|= α
49
26 March, 2009
Cao Hoang Tru
CSE Faculty - HCMUT
Soundness and Completeness• Completeness of a reasoning algorithm/system R:
if KB |=|=|=|= α, then KB derives α using R
50
26 March, 2009
Cao Hoang Tru
CSE Faculty - HCMUT
Soundness and CompletenessResolution algorithm is sound and complete
51
26 March, 2009
Cao Hoang Tru
CSE Faculty - HCMUT
Soundness and Completeness• In general:
– Soundness: any returned answer is a correct answer.
– Completeness: all correct answers are returned.
52
26 March, 2009
Cao Hoang Tru
CSE Faculty - HCMUT
Programming in LogicPROLOG:• Only Horn sentences are acceptable
A ← B1, B2, …, Bm ≡ A ∨∨∨∨ ¬B1 ∨∨∨∨ ¬B2 ∨∨∨∨ … ∨∨∨∨ ¬Bm
A, Bi: atoms
53
26 March, 2009
Cao Hoang Tru
CSE Faculty - HCMUT
Programming in LogicPROLOG:• The occur-check is omitted from the unification: unsound
test ← P(x, x)
P(x, f(x))
54
26 March, 2009
Cao Hoang Tru
CSE Faculty - HCMUT
Programming in LogicPROLOG:• Backward chaining with depth-first search: incomplete
P(x, y) ← Q(x, y)
P(x, x)
Q(x, y) ← Q(y, x)
55
26 March, 2009
Cao Hoang Tru
CSE Faculty - HCMUT
Programming in LogicPROLOG:• Unsafe cut: incomplete
A ← B, C ← A
B ← D, !, E
D ← ← B, C
← D, !, E, C
← !, E, C
56
26 March, 2009
Cao Hoang Tru
CSE Faculty - HCMUT
Programming in LogicPROLOG:• Negation as failure: ¬P if fails to prove P
57
26 March, 2009
Cao Hoang Tru
CSE Faculty - HCMUT
HomeworkExercises 1-13, Chapter 5, Rich&Knight AI TextbookChapter 4 of the Vietnamese Textbook