• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
PROLOG: Matching And Proof Search In Prolog
 

PROLOG: Matching And Proof Search In Prolog

on

  • 2,227 views

PROLOG: Matching And Proof Search In Prolog

PROLOG: Matching And Proof Search In Prolog

Statistics

Views

Total Views
2,227
Views on SlideShare
2,212
Embed Views
15

Actions

Likes
1
Downloads
0
Comments
0

2 Embeds 15

http://oliva.uhk.cz 8
http://www.slideshare.net 7

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    PROLOG: Matching And Proof Search In Prolog PROLOG: Matching And Proof Search In Prolog Presentation Transcript

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