inference in propositional logic
DESCRIPTION
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? - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Inference in Propositional Logic](https://reader030.vdocuments.net/reader030/viewer/2022012902/56814b0c550346895db8246f/html5/thumbnails/1.jpg)
Inference in Proposi tional Logic
Which one is valid?• If there are no bugs, then the program
compilesThere are no bugsThe program compiles
• If there are no bugs, then the program compilesThe program compilesThere are no bugs
![Page 2: Inference in Propositional Logic](https://reader030.vdocuments.net/reader030/viewer/2022012902/56814b0c550346895db8246f/html5/thumbnails/2.jpg)
Inference in Proposi tional Logic
How about these?• p q, ¬q r, r; p• p (q r), q; p r
How about these?• ให้� = A B• ให้� KB = (AC) (B¬C)• ห้าว่�า KB
![Page 3: Inference in Propositional Logic](https://reader030.vdocuments.net/reader030/viewer/2022012902/56814b0c550346895db8246f/html5/thumbnails/3.jpg)
Inference Rules for Pr opositional Logic
1 .Modus Ponens ห้รือ Implication-Elimination ,
2. And-Elimination 1 2 ,… n3. And-Introduction 1, 2 ,… , n4. Or-Introduction5. Double-Negation Elimination ¬¬ 6. Unit Resolution , ¬ 7. Resolution , ¬
i
1 2 ,… ni
1 2 ,… n
![Page 4: Inference in Propositional Logic](https://reader030.vdocuments.net/reader030/viewer/2022012902/56814b0c550346895db8246f/html5/thumbnails/4.jpg)
Limitation of Propositional Logic
•Consider a classic argumentAll men are mortal = PSam is a man = QTherefore, Joe is mortal
•Can we prove its validity using propositional logic?
![Page 5: Inference in Propositional Logic](https://reader030.vdocuments.net/reader030/viewer/2022012902/56814b0c550346895db8246f/html5/thumbnails/5.jpg)
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.
![Page 6: Inference in Propositional Logic](https://reader030.vdocuments.net/reader030/viewer/2022012902/56814b0c550346895db8246f/html5/thumbnails/6.jpg)
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)
![Page 7: Inference in Propositional Logic](https://reader030.vdocuments.net/reader030/viewer/2022012902/56814b0c550346895db8246f/html5/thumbnails/7.jpg)
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)
![Page 8: Inference in Propositional Logic](https://reader030.vdocuments.net/reader030/viewer/2022012902/56814b0c550346895db8246f/html5/thumbnails/8.jpg)
Example(ต่�อ)• There exists two white elephants.
x white-elephant (x) y white-elephant (y) (xy)
• There uniquely exists a white elephant.x white-elephant (x) y white-elephant (y) (x=y)
![Page 9: Inference in Propositional Logic](https://reader030.vdocuments.net/reader030/viewer/2022012902/56814b0c550346895db8246f/html5/thumbnails/9.jpg)
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.
![Page 10: Inference in Propositional Logic](https://reader030.vdocuments.net/reader030/viewer/2022012902/56814b0c550346895db8246f/html5/thumbnails/10.jpg)
Answer1.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)
![Page 11: Inference in Propositional Logic](https://reader030.vdocuments.net/reader030/viewer/2022012902/56814b0c550346895db8246f/html5/thumbnails/11.jpg)
Answer4. 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)
![Page 12: Inference in Propositional Logic](https://reader030.vdocuments.net/reader030/viewer/2022012902/56814b0c550346895db8246f/html5/thumbnails/12.jpg)
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)
![Page 13: Inference in Propositional Logic](https://reader030.vdocuments.net/reader030/viewer/2022012902/56814b0c550346895db8246f/html5/thumbnails/13.jpg)
ห้ลั�กการืของ 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)”
![Page 14: Inference in Propositional Logic](https://reader030.vdocuments.net/reader030/viewer/2022012902/56814b0c550346895db8246f/html5/thumbnails/14.jpg)
Prove โด้ย Backward Chaining
• ต่�องการื prove ว่�า “John likes Peanuts” เรืาอาจต่�องเพิ่�$ม่กฏเข�าไป็อ!กว่�า
7. x,y Alive(x) Killed-by(x,y) แลั�ว่ท�าการื prove โด้ย Backward Chaining
![Page 15: Inference in Propositional Logic](https://reader030.vdocuments.net/reader030/viewer/2022012902/56814b0c550346895db8246f/html5/thumbnails/15.jpg)
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 { }
![Page 16: Inference in Propositional Logic](https://reader030.vdocuments.net/reader030/viewer/2022012902/56814b0c550346895db8246f/html5/thumbnails/16.jpg)
จากต่�ว่อย�างเด้�ม่
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)
![Page 17: Inference in Propositional Logic](https://reader030.vdocuments.net/reader030/viewer/2022012902/56814b0c550346895db8246f/html5/thumbnails/17.jpg)
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)
![Page 18: Inference in Propositional Logic](https://reader030.vdocuments.net/reader030/viewer/2022012902/56814b0c550346895db8246f/html5/thumbnails/18.jpg)
โดยวิ�ธี 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}
From 3aเก�ด้ Contradiction
eat(Bill, Peanuts)
ด้�งน�&นสรื(ป็ได้�ว่�า John likes peanuts.
![Page 19: Inference in Propositional Logic](https://reader030.vdocuments.net/reader030/viewer/2022012902/56814b0c550346895db8246f/html5/thumbnails/19.jpg)
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.
![Page 20: Inference in Propositional Logic](https://reader030.vdocuments.net/reader030/viewer/2022012902/56814b0c550346895db8246f/html5/thumbnails/20.jpg)
Prolog•ม่าจาก PROgramming in LOGic•เป็�น logic programming language•แทน variable ด้�ว่ยต่�ว่พิ่�ม่พิ่+ให้ญ่� เช่�น X•constant แทนด้�ว่ย ต่�ว่เลั.กห้รือข/&นต่�น
ด้�ว่ยต่�ว่เลัขได้�•ท(กๆ rule ต่�องจบด้�ว่ย .
![Page 21: Inference in Propositional Logic](https://reader030.vdocuments.net/reader030/viewer/2022012902/56814b0c550346895db8246f/html5/thumbnails/21.jpg)
ข้�อแตกต�างระหวิ�าง Logic และ Prolog
Logic Prologp q q :- p(and) , (comma)
(or) ไม่�ม่!xy q(x,y) p(x)
p(X) :- q(X,Y)
Control strategy is not fixed
Depth-first search with backtracking
cat(meaw) Close world assumption(CWA)
![Page 22: Inference in Propositional Logic](https://reader030.vdocuments.net/reader030/viewer/2022012902/56814b0c550346895db8246f/html5/thumbnails/22.jpg)
ต�วิอย�าง x pet(x) small(x) apartment(x)
x cat(x) dog(x) pet(x) x poodle(x) small(x) dog(x)
•poodle(puff)
![Page 23: Inference in Propositional Logic](https://reader030.vdocuments.net/reader030/viewer/2022012902/56814b0c550346895db8246f/html5/thumbnails/23.jpg)
แปลงเป�น 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).
![Page 24: Inference in Propositional Logic](https://reader030.vdocuments.net/reader030/viewer/2022012902/56814b0c550346895db8246f/html5/thumbnails/24.jpg)
แปลงเป�น 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).
![Page 25: Inference in Propositional Logic](https://reader030.vdocuments.net/reader030/viewer/2022012902/56814b0c550346895db8246f/html5/thumbnails/25.jpg)
ด�งน��นได�เป�นภาษา Prolog ด�งน�
1.apartment(X) :- pet(X), small(X).2.pet(X) :- cat(X).3.pet(X) :- dog(X).4.small(X) :- poodle(X). 5.dog(X) :- poodle(X).6.poodle(puff).
![Page 26: Inference in Propositional Logic](https://reader030.vdocuments.net/reader030/viewer/2022012902/56814b0c550346895db8246f/html5/thumbnails/26.jpg)
โจทย"•? – apartment(X).• ใช่�ว่�ธี! depth-first search with
backtracking•rules จะป็รืะกอบไป็ด้�ว่ย variable•facts จะม่!แค่� constant•จะไป็ห้า fact ของส�$งท!$ต่�องการืห้าก�อน•ถ้�าไม่�ม่! fact จะไป็เรื�$ม่ห้าท!$ rule ข�อท!$ 1 แลั�ว่ท�าไป็
เรื$อยๆ ถ้�าห้าไม่�ได้�ก.จะย�อนกลั�บม่า
![Page 27: Inference in Propositional Logic](https://reader030.vdocuments.net/reader030/viewer/2022012902/56814b0c550346895db8246f/html5/thumbnails/27.jpg)
ต�วิอย�าง1.grandson(X, Y) :- parent(Z, X) ,
parent(Y, Z).2.parent(X, Y) :- son(Y, X).3.parent(X,Y) :- mother(X,Y). 4.parent(X,Y) :- father(X,Y).5.son(john, tom).6.son(paul, john).7.mother(john, mary).
![Page 28: Inference in Propositional Logic](https://reader030.vdocuments.net/reader030/viewer/2022012902/56814b0c550346895db8246f/html5/thumbnails/28.jpg)
?- 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 ไม่�ได้�แลั�ว่
![Page 29: Inference in Propositional Logic](https://reader030.vdocuments.net/reader030/viewer/2022012902/56814b0c550346895db8246f/html5/thumbnails/29.jpg)
?- grandson(U, tom).3. <backtracking> parent(tom, tom) :-
mother(tom,tom).7. fail
4. <backtracking> parent(tom, tom) :- father(tom,tom).fail เพิ่รืาะไม่�ม่! rule เก!$ยว่ก�บ father6. <backtracking> son(paul, john) {U/paul, Z/john}
2. parent(tom, john) :- son(john, tom)5. success { }ด้�งน�&น U = paul
![Page 30: Inference in Propositional Logic](https://reader030.vdocuments.net/reader030/viewer/2022012902/56814b0c550346895db8246f/html5/thumbnails/30.jpg)