chương 3 tri thức và lập luận
DESCRIPTION
Chương 3 Tri thức và lập luận. Nội dung chính chương 3. Logic – ngôn ngữ của tư duy Logic mệnh đề (cú pháp, ngữ nghĩa, sức mạnh biểu diễn, các thuật toán suy diễn) Prolog (cú pháp, ngữ nghĩa, lập trình prolog, bài tập và thực hành) - PowerPoint PPT PresentationTRANSCRIPT
Chương 3Tri thức và lập luận
Nội dung chính chương 3
I. Logic – ngôn ngữ của tư duy
II. Logic mệnh đề (cú pháp, ngữ nghĩa, sức mạnh biểu diễn, các thuật toán suy diễn)
III. Prolog (cú pháp, ngữ nghĩa, lập trình prolog, bài tập và thực hành)
IV. Logic cấp một (cú pháp, ngữ nghĩa, sức mạnh biểu diễn, các thuật toán suy diễn)
Lecture 1
Lecture 2
Lecture 3,4
Lecture 4Inference in First-Order Logic
CS 561, Session 16-18 4
Lecture 4: Inference in First-Order Logic - Outline
Proofs (chứng minh)
Unification (hợp nhất)
Generalized modus ponens - GMP(Luật modus ponens tổng quát)
Inference procedures based on GMP (các thủ tục dựa trên luật modus ponens tổng quát)
• Forward chaining (suy diễn tiến)
• Backward chaining (suy diễn lùi)
Incompleteness of GMP-based inferences (tính không đầy đủ của suy diễn tiến và lùi).
Inference procedures based on Resolution (thủ tục suy diễn hợp giải, thủ tục có tính đầy đủ trong logic cấp một)
Logic programming (lập trình logic)
Entailment and proof - Hệ quả logic và chứng minh
CS 561, Session 16-18 5
CS 561, Session 16-18 6
Remember:propositionallogic
Nhớ lại:Các định lý trong logicmệnh đề
CS 561, Session 16-18 7
Proofs – chứng minh
CS 561, Session 16-18 8
Proofs – Chứng minh (tiếp)
The three new inference rules for FOL (compared to propositional logic) are:
• Universal Elimination (UE):for any sentence , variable x and ground term ,
x {x/}
• Existential Elimination (EE):for any sentence , variable x and constant symbol k not in KB,
x {x/k}
• Existential Introduction (EI):for any sentence , variable x not in and ground term g in ,
x {g/x}
CS 561, Session 16-18 9
Proofs – Chứng minh (tiếp)
The three new inference rules for FOL (compared to propositional logic) are:
• Universal Elimination (UE):for any sentence , variable x and ground term ,
x e.g., from x Likes(x, Candy) and {x/Joe} {x/} we can infer Likes(Joe, Candy)
• Existential Elimination (EE):for any sentence , variable x and constant symbol k not in KB,
x e.g., from x Kill(x, Victim) we can infer{x/k} Kill(Murderer, Victim), if Murderer new
symbol
• Existential Introduction (EI):for any sentence , variable x not in and ground term g in ,
e.g., from Likes(Joe, Candy) we can inferx {g/x} x Likes(x, Candy)
CS 561, Session 16-18 10
Example Proof
CS 561, Session 16-18 11
Example Proof
CS 561, Session 16-18 12
Example Proof
CS 561, Session 16-18 13
Example Proof
CS 561, Session 16-18 14
Search with primitive example rules
Unification – Hợp nhất
• Unification is a "pattern matching" procedure that takes two atomic sentences, called literals, as input, and returns "failure" if they do not match and a substitution list, Theta, if they do match. • That is, unify(p,q) = Theta means subst(Theta, p) =
subst(Theta, q) for two atomic sentences p and q. • Theta is called the most general unifier (mgu)
• All variables in the given two literals are implicitly universally quantified
• To make literals match, replace (universally-quantified) variables by terms
CS 561, Session 16-18 16
Unification – Hợp nhất
Goal of unification: finding σ
CS 561, Session 16-18 17
Unification – Hợp nhất
Unification Algorithm – Giải thuật hợp nhất
procedure unify(p, q, theta) Scan p and q left-to-right and find the first
corresponding terms where p and q "disagree" ; where p and q not equal
If there is no disagreement, return theta ; success
Let r and s be the terms in p and q, respectively, where disagreement first occurs
If variable(r) then theta = union(theta, {r/s}) unify(subst(theta, p), subst(theta, q), theta)
else if variable(s) then theta = union(theta, {s/r}) unify(subst(theta, p), subst(theta, q), theta)
else return "failure" end
Unification…
• Examples
Literal 1 Literal 2 theta
parents(x, father(x), mother(Bill))
parents(x, father(x), mother(Bill))
parents(x, father(x), mother(Jane))
parents(Bill, father(Bill), y)
parents(Bill, father(y), z)
parents(Bill, father(y), mother(y))
{x/Bill, y/mother(Bill)}
{x/Bill, y/Bill, z/mother(Bill)}
Failure
CS 561, Session 16-18 20
More Unification Examples
1 – unify(P(a,X), P(a,b)) σ = {X/b}
2 – unify(P(a,X), P(Y,b)) σ = {Y/a, X/b}
3 – unify(P(a,X), P(Y,f(a)) σ = {Y/a, X/f(a)}
4 – unify(P(a,X), P(X,b)) σ = failure
Note: If P(a,X) and P(X,b) are independent, then we can replace X with Y and get the unification to work.
VARIABLE term
CS 561, Session 16-18 21
Generalized Modus Ponens (GMP) - Luật Modus Ponens tổng quát
CS 561, Session 16-18 22
Soundness of GMP – Tính đúng đắn của GMP
CS 561, Session 16-18 23
Horn form – Dạng câu Horn
• We convert sentences to Horn form as they are entered into the KB
• Using Existential Elimination and And Elimination
• e.g., x Owns(Nono, x) Missile(x) becomes
Owns(Nono, M)Missile(M)
(with M a new symbol that was not already in the KB)
CS 561, Session 16-18 24
Forward chaining procedure – Thủ tục suy diễn tiến
CS 561, Session 16-18 25
Backward chaining procedure – Thủ tục suy diễn lùi
CS 561, Session 16-18 26
An Example (from Konelsky)
• Nintendo example.• Nintendo says it is Criminal for a programmer to provide
emulators to people. My friends don’t have a Nintendo 64, but they use software that runs N64 games on their PC, which is written by Reality Man, who is a programmer.
• Query: Has Reality Man done anything criminal?
CS 561, Session 16-18 27
Forward Chaining
Programmer(x) Emulator(y) People(z) Provide(x,z,y) Criminal(x)(1)
Use(friends, x) Runs(x, N64 games) Provide(Reality Man, friends, x)(2)
Software(x) Runs(x, N64 games) Emulator(x)(3)
Programmer(Reality Man) (4)People(friends) (5)
Software(U64) (6)Use(friends, U64) (7)
Runs(U64, N64 games) (8)
• Premises (6), (7) and (8) satisfy the implications fully.
CS 561, Session 16-18 28
Forward Chaining
Programmer(x) Emulator(y) People(z) Provide(x,z,y) Criminal(x) (1)
Use(friends, x) Runs(x, N64 games) Provide(Reality Man, friends, x) (2)
Software(x) Runs(x, N64 games) Emulator(x) (3)
Programmer(Reality Man) (4)People(friends) (5)
Software(U64) (6)Use(friends, U64) (7)
Runs(U64, N64 games) (8)
• So we can infer the consequents, which are now added to the knowledge base (this is done in two separate steps).
CS 561, Session 16-18 29
Forward Chaining
Programmer(x) Emulator(y) People(z) Provide(x,z,y) Criminal(x) (1)
Use(friends, x) Runs(x, N64 games) Provide(Reality Man, friends, x) (2)
Software(x) Runs(x, N64 games) Emulator(x) (3)
Programmer(Reality Man) (4)People(friends) (5)
Software(U64) (6)Use(friends, U64) (7)
Runs(U64, N64 games) (8)Provide(Reality Man, friends, U64) (9)
Emulator(U64) (10)
• Addition of these new facts triggers further forward chaining.
CS 561, Session 16-18 30
Forward Chaining
Programmer(x) Emulator(y) People(z) Provide(x,z,y) Criminal(x) (1)
Use(friends, x) Runs(x, N64 games) Provide(Reality Man, friends, x) (2)
Software(x) Runs(x, N64 games) Emulator(x) (3)
Programmer(Reality Man) (4)
People(friends) (5)
Software(U64) (6)
Use(friends, U64) (7)
Runs(U64, N64 games) (8)Provide(Reality Man, friends, U64) (9)
Emulator(U64) (10)
Criminal(Reality Man) (11)
• Which results in the final conclusion: Criminal(Reality Man)
CS 561, Session 16-18 31
Backward Chaining
• Question: Has Reality Man done anything criminal?
• We will use the same knowledge as in our forward-chaining version of this example:
Programmer(x) Emulator(y) People(z) Provide(x,z,y) Criminal(x)
Use(friends, x) Runs(x, N64 games) Provide(Reality Man, friends, x)
Software(x) Runs(x, N64 games) Emulator(x)
Programmer(Reality Man)
People(friends)
Software(U64)
Use(friends, U64)
Runs(U64, N64 games)
CS 561, Session 16-18 32
Backward Chaining
• Question: Has Reality Man done anything criminal?
Criminal(x)
CS 561, Session 16-18 33
Backward Chaining
• Question: Has Reality Man done anything criminal?
Yes, {x/Reality Man}
Criminal(x)
Programmer(x)
CS 561, Session 16-18 34
Backward Chaining
• Question: Has Reality Man done anything criminal?
Yes, {x/Reality Man} Yes, {z/friends}
Criminal(x)
People(Z)Programmer(x)
CS 561, Session 16-18 35
Backward Chaining
• Question: Has Reality Man done anything criminal?
Yes, {x/Reality Man} Yes, {z/friends}
Criminal(x)
People(Z)Programmer(x) Emulator(y)
CS 561, Session 16-18 36
Backward Chaining
• Question: Has Reality Man done anything criminal?
Yes, {x/Reality Man} Yes, {z/friends}
Yes, {y/U64}
Criminal(x)
People(z)Programmer(x) Emulator(y)
Software(y)
CS 561, Session 16-18 37
Backward Chaining
• Question: Has Reality Man done anything criminal?
Yes, {x/Reality Man} Yes, {z/friends}
Yes, {y/U64} yes, {}
Criminal(x)
People(z)Programmer(x) Emulator(y)
Software(y)
Runs(U64, N64 games)
CS 561, Session 16-18 38
Backward Chaining
• Question: Has Reality Man done anything criminal?
Yes, {x/Reality Man} Yes, {z/friends}
Yes, {y/U64} yes, {}
Criminal(x)
People(z)Programmer(x) Emulator(y)
Software(y)
Runs(U64, N64 games)
Provide(reality man,
U64,friends)
CS 561, Session 16-18 39
Backward Chaining
• Question: Has Reality Man done anything criminal?
Yes, {x/Reality Man} Yes, {z/friends}
Yes, {y/U64}
yes, {}
Criminal(x)
People(z)Programmer(x) Emulator(y)
Software(y)
Runs(U64, N64 games)
Provide(reality man,
U64,friends)
Use(friends, U64)
CS 561, Session 16-18 40
Backward Chaining
• Backward Chaining benefits from the fact that it is directed toward proving one statement or answering one question.
• In a focused, specific knowledge base, this greatly decreases the amount of superfluous work that needs to be done in searches.
• However, in broad knowledge bases with extensive information and numerous implications, many search paths may be irrelevant to the desired conclusion.
• Unlike forward chaining, where all possible inferences are made, a strictly backward chaining system makes inferences only when called upon to answer a query.
CS 561, Session 16-18 41
Completeness
• As explained earlier, Generalized Modus Ponens requires sentences to be in Horn form:• atomic, or
• an implication with a conjunction of atomic sentences as the antecedent and an atom as the consequent.
• However, some sentences cannot be expressed in Horn form.• e.g.: x bored_of_this_lecture (x)
• E.g.: x P(x) => Q(x)• Cannot be expressed in Horn form due to presence of negation.
Generalized Modus PonensBackward chaining
Forward chaining
CS 561, Session 16-18 42
Completeness
• A significant problem since Modus Ponens cannot operate on such a sentence, and thus cannot use it in inference.
• Knowledge exists but cannot be used.
• Thus inference using Modus Ponens is incomplete.
CS 561, Session 16-18 43
Completeness
• However, Kurt Gödel in 1930-31 developed the completeness theorem, which shows that it is possible to find complete inference rules.
• The theorem states:• any sentence entailed by a set of sentences can be
proven from that set.
=> Resolution Algorithm which is a complete inference method.
CS 561, Session 16-18 44
Completeness in FOL
Resolution Procedure… Thủ tục hợp giải
• Proof by contradiction method
• Given a consistent set of axioms KB and goal sentence Q, we want to show that KB |= Q. This means that every interpretation I that satisfies KB, satisfies Q. But we know that any interpretation I satisfies either Q or ~Q, but not both. Therefore if in fact KB |= Q, an interpretation that satisfies KB, satisfies Q and does not satisfy ~Q. Hence KB union {~Q} is unsatisfiable, i.e., that it's false under all interpretations.
• In other words, (KB |- Q) <=> (KB ^ ~Q |- False)
• What's the gain? If KB union ~Q is unsatisfiable, then some finite subset is unsatisfiable
• Resolution procedure can be used to establish that a given sentence Q is entailed by KB; however, it cannot, in general, be used to generate all logical consequences of a set sentences. Also, the resolution procedure cannot be used to prove that Q is not entailed by KB.
CS 561, Session 16-18 46
Resolution inference rule
Resolution Algorithm – Giải thuật hợp giải
procedure resolution-refutation(KB, Q)
;; KB is a set of consistent, true FOL sentences
;; Q is a goal sentence that we want to derive
;; return success if KB |- Q, and failure otherwise
KB = union(KB, ~Q)
while false not in KB do
pick 2 sentences, S1 and S2, in KB that contain literals that unify (if none, return "failure“)
resolvent = resolution-rule(S1, S2)
KB = union(KB, resolvent)
return "success"
CS 561, Session 16-18 48
Kinship Example
KB:
(1) father (art, jon) (2) father (bob, kim) (3) father (X, Y) parent (X, Y)
Goal: parent (art, jon)?
CS 561, Session 16-18 49
Refutation Proof/Graph
¬parent(art,jon) ¬ father(X, Y) \/ parent(X, Y) \ /
¬ father (art, jon) father (art, jon) \ / []
Problems yet to be addressed – Các vấn đề cần giải quyết khi áp dụng hợp giải.
• Resolution rule of inference is only applicable with sentences that are in the form P1 v P2 v ... v Pn, where each Pi is a negated or nonnegated predicate and contains functions, constants, and universally quantified variables, so can we convert every FOL sentence into this form?
• Resolution strategy• How to pick which pair of sentences to resolve?
• How to pick which pair of literals, one from each sentence, to unify?
CS 561, Session 16-18 51
Remember: normal forms
“sum of products of simple variables ornegated simple variables”
“product of sums of simple variables ornegated simple variables”
CS 561, Session 16-18 52
Conjunctive normal form
CS 561, Session 16-18 53
Skolemization
CS 561, Session 16-18 54
Examples: Converting FOL sentences to clause form…
Convert the sentence
1. (x){P(x) => [(y)(P(y) => P(f(x,y))) ^ ¬(y)(Q(x,y) => P(y)))]
(like A => B ^ C)(chú ý: để dễ nhìn, dùng “[“, “]”,”{“ và “}” thay cho”(“ và “)” trong một vài vị
trí)
2. Eliminate => (x){¬P(x) [(y)(¬P(y) P(f(x,y))) ^ ¬(y)(¬Q(x,y) P(y)))]
3. Reduce scope of negation(x){¬P(x) [(y)(¬P(y) P(f(x,y))) ^ (y)(Q(x,y) ^ ¬P(y)))]
4. Standardize variables(x){¬P(x) [(y)(¬P(y) P(f(x,y))) ^ (z)(Q(x,z) ^ ¬P(z)))]
CS 561, Session 16-18 55
Examples: Converting FOL sentences to clause form…
5. Eliminate existential quantification(x){¬P(x) [(y)(¬P(y) P(f(x,y))) ^ (Q(x,g(x)) ^
¬P(g(x))))]
6. Drop universal quantification symbols{¬P(x) [(¬P(y) P(f(x,y))) ^ (Q(x,g(x)) ^
¬P(g(x))))]
7. Convert to conjunction of disjunctions[¬P(x) ¬P(y) P(f(x,y))] ^ [¬P(x) Q(x,g(x))]
^[¬P(x) ¬P(g(x))]
CS 561, Session 16-18 56
Examples: Converting FOL sentences to clause form…
8. Create separate clauses¬P(x) ¬P(y) P(f(x,y)) ¬P(x) Q(x,g(x)) ¬P(x) ¬P(g(x))
9. Standardize variables¬P(x) ¬P(y) P(f(x,y)) ¬P(z) Q(z,g(z)) ¬P(w) ¬P(g(w))
CS 561, Session 16-18 57
Resolution proof
CS 561, Session 16-18 58
Resolution proof
Problems yet to be addressed – Các vấn đề cần giải quyết khi áp dụng hợp giải.
• Resolution rule of inference is only applicable with sentences that are in the form P1 v P2 v ... v Pn, where each Pi is a negated or nonnegated predicate and contains functions, constants, and universally quantified variables, so can we convert every FOL sentence into this form?
• Resolution strategy• How to pick which pair of sentences to resolve?
• How to pick which pair of literals, one from each sentence, to unify?
CS 561, Session 16-18 60
Example of Refutation Proof(in conjunctive normal form)
(1) Cats like fish(2) Cats eat everything they
like(3) Josephine is a cat.(4) Prove: Josephine eats
fish.
cat (x) likes (x,fish)cat (y) likes (y,z) eats (y,z)cat (jo) eats (jo,fish)
CS 561, Session 16-18 61
Backward Chaining – Hợp giải lùi
Negation of goal wff: eats(jo, fish)
eats(jo, fish) cat(y) likes(y, z) eats(y, z)
= {y/jo, z/fish}
cat(jo) likes(jo, fish) cat(jo)
=
cat(x) likes(x, fish) likes(jo, fish)
= {x/jo}
cat(jo) cat(jo)
(contradiction)
CS 561, Session 16-18 62
Forward chaining – Hợp giải tiến
cat (jo) cat (X) likes (X,fish) \ / likes (jo,fish) cat (Y) likes (Y,Z) eats (Y,Z)
\ / cat (jo) eats (jo,fish) cat (jo)
\ /eats (jo,fish) eats (jo,fish)
\ / [] []
Logic programming, Prolog
Language: Horn forms (at most 1 positive literal)• KB: definite clauses: (Horn forms with exact 1 positive
literal)
• Query (q): not(q) is a negative clause (Horn forms with 0 positive literal)
Inference procedure: Backward chaining resolution (actually, SLD Resolution – Selected literals Linear from Definite clauses Resolution)• Idea: Bắt đầu với Q=not(q), hợp giải với câu trong KB,
được câu hợp giải mới, câu mới này lại hợp giải với câu trong KB đến khi nào câu [] tìm thấy
• Đlý: Vơi KB gồm positive clauses và Q là negative clause:
KB Q |= [] khi và chỉ khi KB Q |-- SDL []