1 / 30

Inference in Propositional Logic

Inference in Propositional Logic. Which one is valid? If there are no bugs, then the program compiles There are no bugs The program compiles If there are no bugs, then the program compiles The program compiles There are no bugs. Inference in Propositional Logic. How about these?

atira
Télécharger la présentation

Inference in Propositional Logic

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Inference in Propositional Logic Which one is valid? • If there are no bugs, then the program compiles There are no bugs The program compiles • If there are no bugs, then the program compiles The program compiles There are no bugs

  2. Inference in Propositional Logic How about these? • p q,¬qr, r; p • p(qr), q; p  r How about these? • ให้  = A  B • ให้ KB = (AC) (B¬C) • หาว่า KB 

  3. Inference Rules for Propositional Logic • ModusPonens หรือ Implication-Elimination   ,  • And-Elimination 1 2 ,…  n • And-Introduction 1, 2 ,… , n • Or-Introduction • Double-Negation Elimination ¬¬  • Unit Resolution  , ¬  • Resolution   , ¬     i 1 2 ,…  n i 1 2 ,…  n     

  4. Limitation of Propositional Logic • Consider a classic argument All men are mortal = P Sam is a man = Q Therefore, Joe is mortal • Can weprove its validity using propositional logic?

  5. Example • All elephants are mammals. • Some elephants are mammals. • Some elephants are not mammals. • No elephants are mammals. • Not all elephant are mammals. • There exists a white elephant. • There exists two white elephants. • There uniquely exists a white elephant.

  6. Example(ต่อ) • All elephants are mammals. x elephant (x)  mammals (x) • Some elephants are mammals. x elephant (x)  mammals (x) • Some elephants are not mammals. x elephant (x)   mammals (x)

  7. Example(ต่อ) • No elephants are mammals. x elephant (x)   mammals (x) • Not all elephant are mammals. x elephant (x)  mammals (x) • There exists a white elephant. x white-elephant (x)

  8. Example(ต่อ) • There exists two white elephants. x white-elephant (x)  y white-elephant (y)  (xy) • There uniquely exists a white elephant. x white-elephant (x)  y white-elephant (y)  (x=y)

  9. Homework • John likes all kind of food. • Apple are food. • Chicken are food. • Anything anyone eats and isn’t killed by is food. • Bill eat peanuts and still alive. • Sue eats everything Bill eats.

  10. Answer • John likes all kind of food. x Food(x)  Like(John,x) 2. Apple are food. x Apple(x)  Food(x) หรือ Food(Apple) 3. Chicken are food. x Chicken(x)  Food(x) หรือ Food(Chicken)

  11. Answer 4. Anything anyone eats and isn’t killed by is food. x y Eat(x,y)  Killed-by(x,y) Food(y) 5. Bill eat peanuts and still alive. 5a. Eat(Bill,Peanuts) 5b. Alive(Bill) 6. Sue eats everything Bill eats. x Eat(Bill, x)  Eat(Sue, x)

  12. Unification • Knows (John, x), Knows (y, Jane) {x/Jane, y/John} • ถ้า Predicate แทนด้วย constant ไม่ได้จะทำอย่างไร P (x, x), P (y, z) unify(x, y) {x/y} unify(x, z) {x/z} ผิด unify(y, z) {y/z} หลังจากแทน y ด้วย z แล้ว จะได้ P (y, y), P (y, z) เป็น P (z, z), P (z, z)

  13. หลักการของ Most General Unifier • hate (x, y) • hate (John, z) • {x/John, y/z} • {x/John, z/y} • {x/John, y/Jane, z/Jane} • {x/John, y/Smith, z/Smith} จะ general กว่า จะเรียกว่า “Most General Unifier (MGU)”

  14. Prove โดย Backward Chaining • ต้องการ prove ว่า “John likes Peanuts” เราอาจต้องเพิ่มกฏเข้าไปอีกว่า 7. x,y Alive(x)  Killed-by(x,y) แล้วทำการ prove โดย Backward Chaining

  15. Like(John, Peanuts) ...from 1 , {x/Peanuts} Food(Peanuts) ...from 4 , {y/Peanuts} Eat(Bill, Peanuts) Killed-by(Bill, Peanuts) ...from 5a { } ...from 7 , {x/Bill} alive(Bill) ...from 5b { }

  16. จากตัวอย่างเดิม 1.x Food(x)  Like(John,x) 2.x y Eat(x,y)  Killed-by(x,y)  Food(y) 3.Eat(Bill,Peanuts)  Killed-by(Bill,Peanuts) 4. x Eat(Bill, x)  Eat(Sue, x)

  17. Prove แบบ Resolution • ต้องการ prove ว่า Does John like peanuts? • จะได้ like(John, peanuts) 1. Food(x1)  Like(John,x1) 2. Eat(x2,y2)  Killed-by(x2,y2)  Food(y2) 3.a. Eat(Bill,Peanuts) b. Killed-by(Bill,Peanuts) 4. Eat(Bill, x3)  Eat(Sue, x3)

  18. โดยวิธี Backward Chaining like(John, Peanuts) Food(Peanuts) Eat(x2,Peanuts)  Killed-by(x2,Peanuts) Eat(Bill, Peanuts) From 1 {x1/Peanuts} From 2 {y2/Peanuts} From 3b {x2/Bill} eat(Bill, Peanuts) From 3a เกิด Contradiction ดังนั้นสรุปได้ว่า John likes peanuts.

  19. Prove แบบ Resolution • What food does Sue like? • ให้ prove แบบวิธี Resolution 4. Eat(Bill, x3)  Eat(Sue, x3) 3a.Eat(Bill,Peanuts) {x/Peanuts} eat(Sue, Peanuts) ดังนั้นสรุปได้ว่า Sue likes peanuts.

  20. Prolog • มาจาก PROgramming in LOGic • เป็น logic programming language • แทน variable ด้วยตัวพิมพ์ใหญ่เช่น X • constant แทนด้วย ตัวเล็กหรือขึ้นต้นด้วยตัวเลขได้ • ทุกๆ rule ต้องจบด้วย .

  21. ข้อแตกต่างระหว่าง Logic และ Prolog

  22. ตัวอย่าง • x pet(x)  small(x)  apartment(x) • x cat(x)  dog(x)  pet(x) • x poodle(x)  small(x)  dog(x) • poodle(puff)

  23. แปลงเป็น Prolog • x pet(x)  small(x)  apartment(x) apartment(X) :- pet(X), small(X). • x cat(x)  dog(x)  pet(x) (cat(x) dog(x))  pet(x) (cat(x)  dog(x))  pet(x) (cat(x)  pet(x)) ( dog(x)  pet(x)) cat(x)  pet(x) dog(x)  pet(x) pet(X) :- cat(X). pet(X) :- dog(X).

  24. แปลงเป็น Prolog • x poodle(x)  small(x)  dog(x) poodle(x)  (small(x)  dog(x)) (poodle(x)  small(x))  (poodle(x) dog(x)) poodle(x)  small(x) poodle(x)  dog(x) small(X) :- poodle(X). dog(X) :- poodle(X).

  25. ดังนั้นได้เป็นภาษา Prolog ดังนี้ • apartment(X) :- pet(X), small(X). • pet(X) :- cat(X). • pet(X) :- dog(X). • small(X) :- poodle(X). • dog(X) :- poodle(X). • poodle(puff).

  26. โจทย์ • ? – apartment(X). • ใช้วิธี depth-first search with backtracking • rules จะประกอบไปด้วย variable • facts จะมีแค่ constant • จะไปหา fact ของสิ่งที่ต้องการหาก่อน • ถ้าไม่มี fact จะไปเริ่มหาที่ rule ข้อที่ 1 แล้วทำไปเรื่อยๆ ถ้าหาไม่ได้ก็จะย้อนกลับมา

  27. ตัวอย่าง • grandson(X, Y) :- parent(Z, X) , parent(Y, Z). • parent(X, Y) :- son(Y, X). • parent(X,Y) :- mother(X,Y). • parent(X,Y) :- father(X,Y). • son(john, tom). • son(paul, john). • mother(john, mary).

  28. ?- grandson(U, tom). 1. grandson(U, tom) :- parent(Z, U) , parent(tom, Z). {X/U, Y/tom} 2. parent(Z, U) :- son(U, Z). 5. son(john, tom). {U/john, Z=tom} 2. parent(tom, tom) :- son(tom,tom). 5. fail ไม่สามารถแทน (john, tom) กับ (tom, tom) ได้ 6. fail ไม่สามารถแทน (paul, john) กับ (tom, tom) ได้ จะ backtracking กลับไปที่ข้อ 3 เพราะว่าแทนข้อ 2 ไม่ได้แล้ว

  29. ?- grandson(U, tom). 3. <backtracking> parent(tom, tom) :- mother(tom,tom). 7. fail 4. <backtracking> parent(tom, tom) :- father(tom,tom). fail เพราะไม่มี rule เกี่ยวกับ father 6. <backtracking> son(paul, john) {U/paul, Z/john} 2. parent(tom, john) :- son(john, tom) 5. success { } ดังนั้น U = paul

More Related