1 / 23

PIB Pertemuan 12

Resolution & Refutation (review) Short Quiz Prolog Introduction & Exercise. PIB Pertemuan 12. Resolution & Refutation. General Steps. Translate facts and rules into predicate logic Tranform sentence into CNF (conjunctive normal form) / horn clause / well formed formula.

myra
Télécharger la présentation

PIB Pertemuan 12

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. Resolution & Refutation (review) Short Quiz Prolog Introduction & Exercise PIB Pertemuan 12

  2. Resolution & Refutation

  3. General Steps • Translate facts and rules into predicate logic • Tranform sentence into CNF (conjunctive normal form) / horn clause / well formed formula

  4. Specific Steps To Produce CNF • Eliminate implications & bi-conditionals • Move  inwards • Standardize variables: each quantifier has different ones • Skolemize: choose a “fact” to eliminate  • Eliminate  • Distribute ^ over v

  5. Short Quiz (1) • Buktikan bahwa “Marcus membenci Caesar” • Facts • Marcus adalah seorang manusia • Marcus orang Pompei • Marcus mencoba membunuh Caesar • Caesar adalah seorang penguasa • Rules • Semua orang Pompei adalah orang Romawi • Semua orang Romawi setia pada Caesar atau membenci Caesar • Setiap orang setia pada minimal 1 orang • Orang hanya mencoba membunuh penguasa yang kepadanya mereka tidak setia

  6. Translation into Predicate Logic Facts: • man(marcus) • pompeian(marcus) • tryassassinate(marcus,caesar) • ruler(caesar) Rules: • x pompeian(x)  roman(x) • x roman(x)  loyalto(x, caesar) v hate(x,caesar) • x y loyalto(x, y) • x y man(x) ^ ruler(y) ^ tryassassinate(x,y)  loyalto(x,y) Prove that: hate(marcus, caesar), use refutation.

  7. Inference on “Marcus’s Case” • Make CNF from rules • pompeian(x) v roman(x) • roman(x) v loyalto(x,caesar) v hate(x,caesar) • loyalto(x,y) • (man(x) ^ ruler(y) ^ tryassassinate(x,y)) v loyalto(x,y) man(x) v ruler(y) v tryassassinate(x,y) v loyalto(x,y) Apply substitutions into variable, and try to change rules into facts.

  8. Introduction to prolog • PROLOG = “Programmation en logique” (Marseille, 1972) • Declarative programming language with procedural elements • Used for problems of AI / knowledge-based (expert) systems • Motivation: • reconcile use of logic as declarative knowledge representation with • procedural representation of knowledge • Strengths: • Logical descriptions of problems, instead of HOW to solve them  let • computer work out the solution • Well-suited for problems involving search • Simple programs can be understood by reading the code • Limitations • Flow of control / procedural semantics

  9. Facts • Prolog-program = collection of clauses = meta programming • Facts • Rules • Goals (queries), shaped liked facts • Facts describe properties of objects and relations between objects; comparable to tables in a relational database Name Subject student interest Name Hans Hans Math Tina Tina Datalogi Lars Lars Physics Frida Math Frida Prolog notation: student(hans). student(tina). student(lars). student(frida). Prolog notation: interest(hans,math). interest(tina,datalogi). interest(lars,physics). interest(frida,math). Prolog notation (facts): <predicate_name>(arg1, arg2…).

  10. Rules • Simple IF-THEN statements • “Every reasonable student is interested in math.” • interest(X,math) :- student(X). head body • All specified conditions in the body (all clauses) must be true to make the predicate in the head true. • Conjunctions (AND connected): • mother(X,Person) :- parent(X,Person),sex(X,female). • Disjunctions (OR connected): • interest(X,prolog) :- interest(X,artificial_intelligence). • interest(X,prolog) :- interest(X,logic).

  11. Goals • Goals are queries • One ore more subgoals • ?- student(thomas). • => no • Pattern matching: a fact matches a goal if • Same predicate • Same corresponding arguments. • Goals can contain variables: • ?- student(X). • => X = hans ; • => X = tina ; • => X = lars ; • => X = frida ; • => no. • Variables are instantiated( included in rules),but cannot be declared!

  12. Prolog’s Inference mechanism Leftmost-depth-first search for solutions Matching: either two terms are identical, or they become identical by variable substitution (resolution based on pred.logic) Processing of subgoals from left to right Backtracking (from goaltry to substitute variables into facts or rules) 1: s(a). 2: s(b). 3: q(a). 4: p(X) :- s(X). 5: p(Y) :- q(Y). ?- p(Z). p(Z) 4 5 s(Z) q(Z) 2 3 1 Z=a Z=b Z=a

  13. Backward Chaining • The Prolog interpreter uses backward chaining: • starting from a goal (theorem) • prove the goal by searching for rules whose ”head” (action part) matches the goal • Given are the following rules: 1 X 2 H 3 OR 4 F&C B&E 5 AND AND facts prove F C B E AND A C B B

  14. SWI Prolog • http://www.swi-prolog.org (ver. 5.6.62) • Graphical User Interface (XPCE) • Interface with Java, C++ • Steps: • Consult / Compile • Goal search / Execute • Debug > Graphical Debugger • Trace: show you how the unification & substitution occurs

  15. Exercise 1 • Use prolog to prove the “Marcus’s Case” man(marcus). pompeian(marcus). ruler(caesar). tryassassinate(marcus, caesar). roman(X) :- pompeian(X). hate(X, Y) :- man(X), ruler(Y), tryassassinate(X, Y). loyalto(X, Y) :- man(X), ruler(Y).

  16. Exercise 2: Family Relation (Kinship) George x Mum Spencer x Kydd Elizabeth x Philip Margaret Diana x Charles Anne x Mark Andrew x Sarah Edward William Harry Peter Zara Beatrice Eugenie

  17. Exercise 2 (cont’d) • Buat fakta berdasarkan pohon keluarga di atas • Buat aturan untuk aturan: • saudaraLaki(X,Y)  X berjenis kelamin laki-laki, X dan Y adalah anak dari seseorang, X dan Y bukan orang yang sama • saudaraPerempuan(X,Y)  X berjenis kelamin perempuan, X dan Y adalah anak dari seseorang, X dan Y bukan orang yang sama • bersaudaraKandung(X,Y)  X dan Y memiliki ayah dan ibu yang sama, X dan Y bukan orang yang sama • kakek(X,Y,Z)  X adalah ayah dari Y, Y adalah ayah dari Z • nenek(X,Y,Z)  X adalah ibu dari Y, Y adalah ibu dari Z

  18. Prolog’s List • Simple data structure to process non-numeric relation • A list is a set of ordered sequential elements [2,2,1,1,4,4,5,6] [b,u,d,i] [budi, iwan, wati] • How to use a list? • Simple case: empty [] • Ordered element: [head|tail] • [2,2,1,1,4,4,5,6]  [ 2 | [2,1,1,4,4,5,6] ]

  19. Rules on Prolog’s List • [a,b,c] unifies with [Head|Tail] resulting in Head=a and Tail=[b,c] • [a] unifies with [H|T] resulting in H=a and T=[] • [a,b,c] unifies with [a|T] resulting in T=[b,c] • [a,b,c] doesn't unify with [b|T] • [] doesn't unify with [H|T] • [] unifies with []. Two empty lists always can be unified.

  20. Example “Member List” Predicate: member(X,List). X is a member of List, in case of: 1. X is a head, or 2. X is a member of the tail member(X,[X|Tail]). member(X,[Head|Tail]):- member(X,Tail).

  21. Example “Reverse” reverse([],X,X). reverse([X|Y],Z,W) :- reverse(Y,[X|Z],W). reverse([1,2,3],[],A)         reverse([2,3],[1],A)         reverse([3],[2,1],A)         reverse([],[3,2,1],A)         true  A = [3,2,1]

  22. Please try this (1) • [a,b,c,d]=[a,[b,c,d]]. • [a,b,c,d]=[a|[b,c,d]]. • [a,b,c,d]=[a,b,[c,d]]. • [a,b,c,d]=[a,b|[c,d]]. • [a,b,c,d]=[a,b,c,[d]]. • [a,b,c,d]=[a,b,c|[d]]. • [a,b,c,d]=[a,b,c,d,[]]. • [a,b,c,d]=[a,b,c,d|[]]. • []=_. • []=[_]. • []=[_|[]]. What should Prolog give as result?

  23. Please try this (2) • Develop a dictionary to translate number 1..10 from Indonesian to English and vice versa, example: • Translate([satu, sembilan],Y).  Y = [one,nine] • Translate(Z,[one]).  Z = [satu] • Translate([],[]).

More Related