Presentation is loading. Please wait.

Presentation is loading. Please wait.

344-302 การเขียนโปรแกรมเชิงตรรกะ และภาษาโพรล็อก (Logic Programming and Prolog) ดร. วิภาดา เวทย์ประสิทธิ์ ภาควิชาวิทยาการคอมพิวเตอร์ คณะวิทยาศาสตร์ มหาวิทยาลัยสงขลานครินทร์

Similar presentations


Presentation on theme: "344-302 การเขียนโปรแกรมเชิงตรรกะ และภาษาโพรล็อก (Logic Programming and Prolog) ดร. วิภาดา เวทย์ประสิทธิ์ ภาควิชาวิทยาการคอมพิวเตอร์ คณะวิทยาศาสตร์ มหาวิทยาลัยสงขลานครินทร์"— Presentation transcript:

1 344-302 การเขียนโปรแกรมเชิงตรรกะ และภาษาโพรล็อก (Logic Programming and Prolog) ดร. วิภาดา เวทย์ประสิทธิ์ ภาควิชาวิทยาการคอมพิวเตอร์ คณะวิทยาศาสตร์ มหาวิทยาลัยสงขลานครินทร์ ห้องทำงาน : CS 320 โทรศัพท์ : 074-288596 E-mail : wwettayaprasit@yahoo.comwwettayaprasit@yahoo.com Website : http://www.cs.psu.ac.th/wiphada

2 344-302 LP and Prolog Chapter 12 วัตถุประสงค์ 1. ให้นักศึกษามีความรู้ความเข้าใจเกี่ยวกับการเขียนโปรแกรมเชิง ตรรกะ 2. ให้นักศึกษาสามารถเขียนโปรแกรมภาษาโพรล็อกได้ วิธีการเรียนการสอน : การบรรยาย ปฏิบัติการ การวัดผล : Assignment 25% สอบกลางภาค 35% สอบปลายภาค 40% เวลาเรียน : จันทร์ 11-12 ห้อง วท 3 ศุกร์ 11-12 ห้อง วท 3 ศุกร์ 13-15 ห้อง CS105 (LAB)

3 344-302 LP and Prolog Chapter 13 Chapter 1 : Introduction to Logic Chapter 2 : Syntax and Meaning of Prolog Programs Chapter 3 : Input and Output Chapter 4 : Knowledge Representation Chapter 5 : Expert System Chapter 6 : Controlling Backtracking Chapter 7 : Lists Operator Chapter 8 : Arithmetic and Program Examples เนื้อหาวิชา

4 344-302 LP and Prolog Chapter 14 PROLOG Programming for Artificial Intelligence, Second Edition, Ivan Bratko, Addison-Wesley, Pulishing, 1990. Prolog : A Relational language and its Applications, John Malpas, Prentice-Hall, Inc. 1987. Expert Systems and Applied Artificial Intelligence, Efraim Turban, Macmillan Publishing Company, 1992. เอกสารอ้างอิง

5 Chapter 1 Introduction

6 Propositional logic Formal Logic Predicate Logic Predicate Calculus Symbolic Logic Logic Programming Content

7 344-302 LP and Prolog Chapter 17 A statement that affirms or denies something. Proposition

8 344-302 LP and Prolog Chapter 18 Proposition : a logical statement that may or may not be true. object relationships of objects A = I like banana.  true B = I like orange.  false C = I like mango.  true A and B = I like banana and orange.  false Proposition

9 344-302 LP and Prolog Chapter 19 All men are mortal Socrates is a man Therefore, Socrates is mortal into propositional logic yieldspropositional logic A B  C (  means "therefore"). Propositional Logic

10 344-302 LP and Prolog Chapter 110 Propositional expression implication a  b  ~a v b ~a  b  a V b equivalence a  b  (a & b) v (~a & ~b) tautologies : always true a v ~a contradiction : always false b & ~b

11 344-302 LP and Prolog Chapter 111 Propositional expression contrapositive law a  b  ~b  ~a

12 344-302 LP and Prolog Chapter 112 A B C : propositions 1. property of and, or A and True = A A and False = False A or True = True A or False = A 2. property of negation A and ~A = False A or ~A = True Proposition expression

13 344-302 LP and Prolog Chapter 113 3. commutative law ( กฎการสลับที่ ) A and B = B and A A or B = B or A 4. associative law ( กฎการเปลี่ยน กลุ่ม ) A and (B and C) = (A and B) and C A or (B or C) = (A or B) or C 5. distributive law ( กฎการแจกแจง ) A and (B or C) = (A and B) or (A and C) A or (B and C) = (A or B) and (A or C) Proposition expression

14 344-302 LP and Prolog Chapter 114 6. de morgan ’ s laws not (A and B) = not A or not B not (A or B) = not A and not B 7. inference rule ( กฎการอนุมาน ) chain rule modus ponens 1 A  B 1 A 2 B  C2 A  B A  CB Proposition expression

15 344-302 LP and Prolog Chapter 115 Chain rule (1) All California are American. เหตุ (2) All American are Car-Drivers. เหตุ (3) All California are Car-Drivers. ผล C  A A  D C  D

16 344-302 LP and Prolog Chapter 116 Modus Ponens If P implies Q, and P is true, then Q is true.

17 344-302 LP and Prolog Chapter 117 Transitive (1) All baseball player are gum-chewers. เหตุ (2) Some baseball players are from Boston. เหตุ (3) Some (people) from Boston are gum-chewers. ผล 2 1

18 344-302 LP and Prolog Chapter 118 any logical system that abstracts the form of statements away from their content in order to establish abstract criteria of consistency and validity Formal Logic

19 344-302 LP and Prolog Chapter 119 Formal Logic Logic ( ตรรก ): true, false truth table : and, or, not, xor, implies, if and only if AB A and B A or B A xor B A  B A  B ~A TTT T F T T F TFF T T F F F FTF T T T F T FFF F F T T T Formal Logic : use to describe propositions check proposition for validation

20 344-302 LP and Prolog Chapter 120 Name Symbol Example Meaning Precedence negation ~ ~a not a1 conjunction &a & ba and b2 disjunction Va v ba or b2 equivalence  a  b a is equivalent to b2 implication  a  b a implies b (if a then b) 3 double negation : ~ ~ a = a compound propositions a & b  c a & ~b  d : (a & ( ~b))  d well-formed formula (wff) : a complex formula that includes logical connectives Formal Logic

21 344-302 LP and Prolog Chapter 121 predicate logic or First-order logic (FOL) is a language in symbolic science, which is used by mathematicians, philosophers, linguists, and computer scientists. FOL is a system of deduction extending propositional logic by the ability to express relations between individuals (e.g. people, numbers, and "things") more generally.deduction propositional logic Predicate Logic

22 344-302 LP and Prolog Chapter 122  x (Man(x) → Mortal(x)) Man(Socrates)  Mortal(Socrates) Predicate Logic

23 344-302 LP and Prolog Chapter 123 constants : a symbol that represent an object. man john variables : a symbol that can represent different objects at different times man(X). ( ตัวอักษรตัวใหญ่ ) compound term 1. functor :function symbol that name the relation 2. an ordered list of parameters man(john) like(bob,steak) Predicate Logic

24 344-302 LP and Prolog Chapter 124 variable can be appear in propositions using quantifiers ( ตัวบ่งปริมาณ ). Name Example Meaning universal  XP For all X, P is true existential  XP There exists a value of X such that P is true. quantifiers have highest precedence than any of the operators Predicate Logic

25 344-302 LP and Prolog Chapter 125 Traditional Logic All S is P.  No S is P. ~  Some S is P.  Some S is not P. ~  All baseball player are gum-chewers. Some taxi-driver are not aggressive.  X(woman(X)  human(X))  X(mother(mary,X) & male(X))

26 344-302 LP and Prolog Chapter 126 Quantifiers p, q : predicates X, Y : variables ~  Xp(X) =  X~p(X) ~  Xp(X) =  X~p(X)  Xp(X) =  Yp(Y)  Xp(X) =  Yp(Y)  X(p(X) & q(Y)) =  Yp(Y) &  Yq(Y)  X(p(X) & q(Y)) =  Yp(Y) &  Yq(Y)

27 344-302 LP and Prolog Chapter 127 Predicate calculus The branch of symbolic logic that deals not only with relations between propositions as a whole but also with their internal structure, especially the relation between subject and predicate. Symbols are used to represent the subject and predicate of the proposition, and the existential or universal quantifier is used to denote whether the proposition is universal or particular in its application.

28 344-302 LP and Prolog Chapter 128 Predicate calculus a system of symbolic logic that represents individuals and predicates and quantification over individuals (as well as the relations between propositions)

29 344-302 LP and Prolog Chapter 129 Predicate calculus If it is not rain tomorrow, Tom will go to the mountains. ~weather(rain,tomorrow)  go(tom,mountain) Emma is a Doberman and a good dog. gooddog(emma) & isa(emma,doberman)

30 344-302 LP and Prolog Chapter 130 Predicate calculus All basketball player are tall.  X(basketball_player(X)  tall(X)) Some people like wine.  X(person(X) & like(X,wine)) Nobody likes taxes ~  Xlike(X,taxes)

31 344-302 LP and Prolog Chapter 131 a c d b A blocks world

32 344-302 LP and Prolog Chapter 132 A blocks world on(c,a). on(b,d). ontable(a). ontable(d). clear(b). clear(c). hand_empty. a c d b

33 344-302 LP and Prolog Chapter 133 A blocks world a block is clear :  X (~  Y on(Y,X)  clear(X)). pick up X and putdown X on Y :  X  Y ((hand_empty & clear(X) & clear(Y) pick_up(X) & put_down(X,Y))  stack(X,Y)) a c d b

34 344-302 LP and Prolog Chapter 134 vertebrate bird bluebirdsmall featuresflies blue ISA hasproperty hascolor hascovering hassize Semantic network

35 344-302 LP and Prolog Chapter 135 Predicate Calculus vertebrate bird bluebirdsmall featuresflies blue ISA hasproperty hascolor hascovering hassize hassize(bluebird, small) hascovering(bird,features) hascolor(bluebird,blue) hadproperty(bird,flies) isa(bluebird,bird) isa(bird,vertebrate) Semantic Network Predicate Calculus

36 344-302 LP and Prolog Chapter 136 Predicate calculus knows(mary, bob) knows(sam, bob) knows(sam, petricia). Who knows bob? Who knows bob and petricia? Does mary know anybody?

37 344-302 LP and Prolog Chapter 137 Predicate calculus Facts: father(bill, daniel) father(bill, kenneth) brother(daniel, kenneth) brother(john, bill) Rule: uncle(U,N) :- brother(U,B), father(B,N) uncle(U,N) :- brother(U,B), mother(B,N) U B N

38 344-302 LP and Prolog Chapter 138 Facts: father(bill, daniel) father(bill, kenneth) brother(daniel, kenneth) brother(john, bill) Rule: uncle(U,N) :- brother(U,B), father(B,N) U B N john bill daniel kenneth Predicate calculus

39 344-302 LP and Prolog Chapter 139 Predicate calculus “ george likes susie if george like kate. ” likes(george, susie) :- likes(george, kate) “ kate does not like wine. ” not(likes(kate,wine))

40 344-302 LP and Prolog Chapter 140 Predicate calculus Facts : likes(george,kate) likes(george,susie) likes(george,wine) likes(susie,wine) likes(kate,beer) likes(kate,susie) Rule : friend(X,Y) :- likes(X,Z), likes(Y,Z)

41 344-302 LP and Prolog Chapter 141 A treatment of formal logic in which a system of symbols is used to represent quantities and relationships. Symbolic Logic

42 344-302 LP and Prolog Chapter 142 express proposition. express the......relationship between the prepositions. describe how new propositions can be inferred from other prepositions that are assumed to be true. EX : john is a man. man(john) wichai is a man.man(wichai) EX : man(X) Symbolic Logic

43 344-302 LP and Prolog Chapter 143 Logic Programming B1 and … and Bn implies H treats the implications as goal-reduction procedures to show/solve H, show/solve B1 and … and Bn. creating a program that enables the computer to reason logically

44 344-302 LP and Prolog Chapter 144 Logic Programming Logic programming.....use a form of symbolic logic Logic programming language.....language base on symbolic logic

45 344-302 LP and Prolog Chapter 145 Homework 1 I married a window (W) who has a grown-up daughter (D). My father (F) who visited us quite often, fell in love with my step-daughter and married her. Hence my father became my son-in-law and my step-daughter become my mother. Some months later, my wife gave birth to a son (S1), who became the brother–in-law of my father, as well as my uncle. The wife of my father, that is, my step-daughter, also had a son (S2). Question 1. Is this statement true? “ I am my own grandfather. ” Question 2. Explain how to receive your solution.

46


Download ppt "344-302 การเขียนโปรแกรมเชิงตรรกะ และภาษาโพรล็อก (Logic Programming and Prolog) ดร. วิภาดา เวทย์ประสิทธิ์ ภาควิชาวิทยาการคอมพิวเตอร์ คณะวิทยาศาสตร์ มหาวิทยาลัยสงขลานครินทร์"

Similar presentations


Ads by Google