30
Inference in Pro positional 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

  • Upload
    atira

  • View
    36

  • Download
    1

Embed Size (px)

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 Presentation

Citation preview

Page 1: Inference in Propositional Logic

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

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

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

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

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

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

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

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

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

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

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

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

ห้ลั�กการืของ 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

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

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

จากต่�ว่อย�างเด้�ม่

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

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

โดยวิ�ธี 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

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

Prolog•ม่าจาก PROgramming in LOGic•เป็�น logic programming language•แทน variable ด้�ว่ยต่�ว่พิ่�ม่พิ่+ให้ญ่� เช่�น X•constant แทนด้�ว่ย ต่�ว่เลั.กห้รือข/&นต่�น

ด้�ว่ยต่�ว่เลัขได้�•ท(กๆ rule ต่�องจบด้�ว่ย .

Page 21: Inference in Propositional Logic

ข้�อแตกต�างระหวิ�าง 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

ต�วิอย�าง 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

แปลงเป�น 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

แปลงเป�น 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

ด�งน��นได�เป�นภาษา 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

โจทย"•? – apartment(X).• ใช่�ว่�ธี! depth-first search with

backtracking•rules จะป็รืะกอบไป็ด้�ว่ย variable•facts จะม่!แค่� constant•จะไป็ห้า fact ของส�$งท!$ต่�องการืห้าก�อน•ถ้�าไม่�ม่! fact จะไป็เรื�$ม่ห้าท!$ rule ข�อท!$ 1 แลั�ว่ท�าไป็

เรื$อยๆ ถ้�าห้าไม่�ได้�ก.จะย�อนกลั�บม่า

Page 27: Inference in Propositional Logic

ต�วิอย�าง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

?- 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

?- 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