1 / 46

344-302 การเขียนโปรแกรมเชิงตรรกะและภาษาโพรล็อก ( Logic Programming and Prolog)

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

marlis
Download Presentation

344-302 การเขียนโปรแกรมเชิงตรรกะและภาษาโพรล็อก ( Logic Programming and Prolog)

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

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

  3. เนื้อหาวิชา • 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 Chapter 1

  4. เอกสารอ้างอิง • 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. Chapter 1

  5. Chapter 1 Introduction

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

  7. Proposition • A statement that affirms or denies something. Chapter 1

  8. Proposition • 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 Chapter 1

  9. Propositional Logic • All men are mortal • Socrates is a man • Therefore, Socrates is mortal • into propositional logic yields • A • B •  C • (means "therefore"). Chapter 1

  10. 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 Chapter 1

  11. Propositional expression • contrapositive law a  b  ~b  ~a Chapter 1

  12. Proposition expression • 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 Chapter 1

  13. Proposition expression 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) Chapter 1

  14. Proposition expression 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 Chapter 1

  15. 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 Chapter 1

  16. Modus Ponens • If P implies Q, and P is true, • then Q is true. Chapter 1

  17. Transitive 2 1 • (1)All baseball player are gum-chewers.เหตุ • (2) Some baseball players are from Boston. เหตุ • (3) Some (people) from Boston are gum-chewers. ผล Chapter 1

  18. Formal Logic • any logical system that abstracts the form of statements away from their content in order to establish abstract criteria of consistency and validity Chapter 1

  19. Formal Logic • Logic (ตรรก): true, false • truth table : and, or, not, xor, implies, if and only if A B A and B A or B A xor B AB AB ~A T T T T F T T F T F F T T F F F F T F T T T F T F F F FF T T T • Formal Logic : use to describe propositions • check proposition for validation Chapter 1

  20. Formal Logic well-formed formula (wff) : a complex formula that includes logical connectives Name Symbol Example Meaning Precedence • negation ~ ~a not a 1 • conjunction &a & b a and b 2 • disjunction V a v b a or b 2 • equivalence  a  b a is equivalent to b 2 • 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 Chapter 1

  21. Predicate Logic • predicate logicor 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. Chapter 1

  22. Predicate Logic •  x (Man(x) → Mortal(x)) • Man(Socrates) •  Mortal(Socrates) Chapter 1

  23. Predicate Logic • 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) Chapter 1

  24. Predicate Logic • 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 Chapter 1

  25. 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)) Chapter 1

  26. 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) Chapter 1

  27. 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. Chapter 1

  28. Predicate calculus a system of symbolic logic that represents individuals and predicates and quantification over individuals (as well as the relations between propositions) Chapter 1

  29. 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) Chapter 1

  30. 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) Chapter 1

  31. c b a d A blocks world Chapter 1

  32. c b a d A blocks world • on(c,a). • on(b,d). • ontable(a). • ontable(d). • clear(b). • clear(c). • hand_empty. Chapter 1

  33. c b a d 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)) Chapter 1

  34. vertebrate ISA hascovering hasproperty features bird flies ISA hassize hascolor blue small bluebird Semantic network Chapter 1

  35. vertebrate ISA hascovering hasproperty features bird flies ISA hassize hascolor blue small bluebird Predicate Calculus Semantic Network hassize(bluebird, small)hascovering(bird,features)hascolor(bluebird,blue)hadproperty(bird,flies)isa(bluebird,bird)isa(bird,vertebrate) Predicate Calculus Chapter 1

  36. Predicate calculus knows(mary, bob) knows(sam, bob) knows(sam, petricia). • Who knows bob? • Who knows bob and petricia? • Does mary know anybody? Chapter 1

  37. U B N 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) Chapter 1

  38. U B N john bill daniel kenneth 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) Chapter 1

  39. Predicate calculus • “george likes susie if george like kate.” • likes(george, susie) :- likes(george, kate) • “kate does not like wine.” • not(likes(kate,wine)) Chapter 1

  40. 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) Chapter 1

  41. Symbolic Logic • A treatment of formal logic in which a system of symbols is used to represent quantities and relationships. Chapter 1

  42. Symbolic Logic • 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) Chapter 1

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

  44. Logic Programming • Logic programming .....use a form of symbolic logic • Logic programming language .....language base on symbolic logic Chapter 1

  45. 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. Chapter 1

  46. The elevator to success is out of order. You have to use the stairs...one step at a time.

More Related