Like this presentation? Why not share!

- PROLOG: Clauses Grammer In Prolog by DataminingTools Inc 3194 views
- PROLOG: Recursion And Lists In Prolog by DataminingTools Inc 13895 views
- PROLOG: Cuts And Negation In Prolog by DataminingTools Inc 8507 views
- PROLOG: Introduction To Prolog by DataminingTools Inc 2764 views
- Prolog basics by shivani saluja 1715 views
- Prolog Programming : Basics by Mitul Desai 676 views

1,817

Published on

PROLOG: Matching And Proof Search In Prolog

Published in:
Technology

No Downloads

Total Views

1,817

On Slideshare

0

From Embeds

0

Number of Embeds

1

Shares

0

Downloads

0

Comments

0

Likes

1

No embeds

No notes for slide

- 1. Matching and Proof search in Prolog<br />
- 2. OVERVIEW<br />Matching<br />Occurs check<br />Programming with matching<br />Proof search<br />Examples<br />
- 3. MATCHING<br />The basic idea for a Two terms match is:<br />The two terms are equal or if they contain variables that can be instantiated in such a way that the resulting terms are equal.<br />If term1 and term2 are constants, then term1 and term2 match if and only if they are the same atom, or the same number.<br />
- 4. MATCHING<br />If term1 is a variable and term2 is any type of term, then term1 and term2 match and term1 is instantiated to term2. <br />Similarly, if term2 is a variable and term1 is any type of term, then term1 and term2 match, and term2 is instantiated to term1.<br />If term1 and term2 are complex terms, then they match if and only if:<br /><ul><li>a. They have the same functor and arity.
- 5. b. All their corresponding arguments match
- 6. c. and the variable instantiations are compatible.</li></ul>Two terms match if and only if it follows from the previous three clauses that they match.<br />
- 7. The occurs check<br />Consider the following query:<br />father(X) = X.<br /><ul><li>A standard unification algorithm would say: No, these don't match.</li></ul>Pick any term and instantiate X to the term you picked. <br />For ex:<br />if you instantiate X to father(father(butch)), the left hand side becomes father(father(father(butch))), and the right hand side becomes father(father(butch)). Obviously these don't match.<br />SICStus Prolog or SWI returns the answer like:<br />X = father(father(father(father(father(father(...))))))))))<br />The dots are indicating that there is an infinite nesting of father functors.<br />
- 8. Programming with matching<br />Matching plays a key role in Prolog proof search and this alone makes it vital.<br />Matching can then be used to pull out the information you want.<br />Ex: The following two line knowledge base<br />defines two predicates, namely vertical/2 and horizontal/2,<br />which specify what it means for a line to be vertical or<br />horizontal respectively.<br />vertical(line(point(X,Y),point(X,Z))).<br />horizontal(line(point(X,Y),point(Z,Y))).<br />
- 9. The definition of vertical/1 simply says that a line that goes between two points that have the same x-coordinate is vertical.<br />The definition of vertical/1 simply says that a line that goes between two points that have the same x-coordinate is vertical.<br />Ex:<br /> vertical(line(point(1,1),point(1,3))).<br />yes<br />vertical(line(point(1,1),point(3,2))).<br />no<br />
- 10. Proof search<br />Consider the following Knowledge Base:<br />f(a).<br />f(b).<br />g(a).<br />g(b).<br />h(b).<br />k(X) :- f(X),g(X),h(X).<br />On posing the query k(X).<br /> Prolog returns k(b)<br />
- 11. Proof search<br />Prolog reads the knowledge base, and tries to match k(X) with either a fact, or the head of a rule.<br />It searches the knowledge base top to bottom, and carries out the matching, if it can, at the first place possible. <br />Here there is only one possibility, it must match k(X) to the head of the rule:<br />k(X) :- f(X),g(X),h(X).<br />
- 12. Examples:<br />the original query now reads k(_G348) and Prolog knows that is:<br />k(_G348) :- f(_G348),g(_G348),h(_G348).<br />The query says: `I want to find an individual that has property k'.<br />The rule says,`an individual has property k if it has properties f, g, and h'.<br />So if Prolog can<br />find an individual with properties f, g, and h, it will have satisfied the original query. So Prolog<br />replaces the original query with the following list of goals:<br />f(_G348),g(_G348),h(_G348).<br />
- 13. Graphical representation<br />X= _G348<br />K(x)<br />f(_G348), g(_G348), h(_G348) <br />
- 14. Visit more self help tutorials<br />Pick a tutorial of your choice and browse through it at your own pace.<br />The tutorials section is free, self-guiding and will not involve any additional support.<br />Visit us at www.dataminingtools.net<br />

Be the first to comment