Presentasi sedang didownload. Silahkan tunggu

Presentasi sedang didownload. Silahkan tunggu

Resolution & Refutation (review) Short Quiz Prolog Introduction & Exercise.

Presentasi serupa


Presentasi berjudul: "Resolution & Refutation (review) Short Quiz Prolog Introduction & Exercise."— Transcript presentasi:

1 Resolution & Refutation (review) Short Quiz Prolog Introduction & Exercise

2

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

4 1. Eliminate implications & bi-conditionals 2. Move  inwards 3. Standardize variables: each quantifier has different ones 4. Skolemize: choose a “fact” to eliminate  5. Eliminate  6. Distribute ^ over v

5  Buktikan bahwa “Marcus membenci Caesar”  Facts 1. Marcus adalah seorang manusia 2. Marcus orang Pompei 3. Marcus mencoba membunuh Caesar 4. Caesar adalah seorang penguasa  Rules 1. Semua orang Pompei adalah orang Romawi 2. Semua orang Romawi setia pada Caesar atau membenci Caesar 3. Setiap orang setia pada minimal 1 orang 4. Orang hanya mencoba membunuh penguasa yang kepadanya mereka tidak setia

6 Facts: 1. man(marcus) 2. pompeian(marcus) 3. tryassassinate(marcus,caesar) 4. ruler(caesar) Rules: 1.  x pompeian(x)  roman(x) 2.  x roman(x)  loyalto(x, caesar) v hate(x,caesar) 3.  x  y loyalto(x, y) 4.  x  y man(x) ^ ruler(y) ^ tryassassinate(x,y)   loyalto(x,y) Prove that: hate(marcus, caesar), use refutation.

7  Make CNF from rules 1.  pompeian(x) v roman(x) 2.  roman(x) v loyalto(x,caesar) v hate(x,caesar) 3. loyalto(x,y) 4.  (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 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 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 student Name Hans Tina Lars Frida Prolog notation: student(hans). student(tina). student(lars). student(frida). interestName Hans Tina Lars Frida Prolog notation: interest(hans,math). interest(tina,datalogi). interest(lars,physics). interest(frida,math). Math Physics Subject Datalogi Math Prolog notation (facts): (arg1, arg2…).

10 Simple IF-THEN statements “Every reasonable student is interested in math.” interest(X,math) :- student(X). headbody 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 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 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 goal try 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) s(Z) Z=aZ=bZ=a q(Z) 3

13 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: facts prove X H F&CB&E FC B BE AC B OR AND

14  (ver )  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  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 GeorgeMum SpencerKyddElizabethPhilipMargaret DianaCharlesAnneMarkAndrewSarahEdward WilliamHarryPeterZaraBeatriceEugenie x xx xxx

17  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  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  [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 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 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 1. [a,b,c,d]=[a,[b,c,d]]. 2. [a,b,c,d]=[a|[b,c,d]]. 3. [a,b,c,d]=[a,b,[c,d]]. 4. [a,b,c,d]=[a,b|[c,d]]. 5. [a,b,c,d]=[a,b,c,[d]]. 6. [a,b,c,d]=[a,b,c|[d]]. 7. [a,b,c,d]=[a,b,c,d,[]]. 8. [a,b,c,d]=[a,b,c,d|[]]. 9. []=_. 10. []=[_]. 11. []=[_|[]]. What should Prolog give as result?

23  Develop a dictionary to translate number from Indonesian to English and vice versa, example:  Translate([satu, sembilan],Y).  Y = [one,nine]  Translate(Z,[one]).  Z = [satu]  Translate([],[]).


Download ppt "Resolution & Refutation (review) Short Quiz Prolog Introduction & Exercise."

Presentasi serupa


Iklan oleh Google