Prolog - PowerPoint PPT Presentation

1 / 11
About This Presentation
Title:

Prolog

Description:

find an X such that ancestor (X, cindy) and sibling (X, jeffrey) ... mother(mary, cindy). Goals :- ancestor(john,X). Conditions (or rules) ... – PowerPoint PPT presentation

Number of Views:105
Avg rating:3.0/5.0
Slides: 12
Provided by: davidbru
Category:
Tags: cindy | prolog

less

Transcript and Presenter's Notes

Title: Prolog


1
Prolog
  • Developed in the early 1970s
  • Algol interpreter in 1972
  • Fortran interpreter in 1973
  • Pascal interpreter in 1976

2
Parts of a program
  • series of clauses that define the problem domain
  • clauses stating a number of particular facts
  • a question

3
Example - define the problem domain
  • parent (X, Y) - father(X,Y).
  • parent (X, Y) - mother (X, Y).
  • grandparent (X, Z) - parent (X, Y), parent (Y,
    Z).
  • ancestor (X, Z) - parent (X, Z).
  • ancestor (X, Z) - parent (X, Y), ancestor (Y,
    Z).
  • sibling(X,Y) - mother(M,X), mother(M,Y),
    father(F,X), father(F,Y), X \ Y.
  • cousin(X,Y) - parent(U,X), parent(V,Y),
    sibling(U,V).

4
Example - stating facts
  • father(albert, jeffrey).
  • mother(alice, jeffrey).
  • father(albert, george).
  • mother(alice, george).
  • father(john, mary).
  • mother(sue, mary).
  • father(george, cindy).
  • mother(mary, cindy).
  • father(george, victor).
  • mother(mary, victor).

5
Example - question
  • Goal of program
  • - ancestor(X, cindy), sibling (X, jeffrey).
  • Program response
  • X george
  • is a fact is provable
  • - grandparent(albert, victor).
  • yes
  • - cousin(alice, john).
  • no

6
Multiple answers
  • - sibling(A,B).
  • Response
  • A jeffrey, B george
  • A jeffrey, B george
  • A george, B jeffrey
  • A cindy, B victor
  • A victor, B cindy
  • no

7
Proving the Theorem
  • - ancestor (X, cindy), sibling(X, jeffrey).
  • answer X George
  • find an X such that ancestor (X, cindy) and
    sibling (X, jeffrey)
  • sibling (X, jeffrey) is true if there are M and F
    such that mother (M, jeffrey),father (F,
    jeffrey),mother (M, X), and father (F, X)
  • if M alice and F albert, then mother (M,
    jeffrey) and father (F, jeffrey)
  • find X such that mother (alice, X) and father
    (albert, X)
  • X is george

8
Clauses Are Constructed from Relationships
  • Hypotheses (or facts)
  • mother(mary, cindy).
  • Goals
  • - ancestor(john,X).
  • Conditions (or rules)
  • grandparent (X, Z) - parent (X, Y), parent (Y,
    Z).
  • General form of a clause
  • - .
  • Goal if omitted

9
Relationships and Terms
  • Terms in the relationships may be
  • atoms, such as john or 25
  • variables, such as X or
  • compound terms

10
Terms Can Be Compound
  • d (X, plus (U, V), plus (DU,DV)) - d(X,U,DU),
    d(X,V,DV).
  • name plus is called a functor because it acts
    like a function
  • d (X, U V, DU DV) - d (X, U, DU), d (X, V,
    DV).
  • d (X, W, Z) - sum (U, V, W), d (X, U, DU), d (X,
    V, DV), sum (DU, DV, Z).

11
Few Primitives and No Constructors
  • natural number arithmetic
  • sum(succ(X), Y, succ(Z)) - sum(X, Y, Z).
  • sum(0, X, X). dif(X, Y, Z) - sum (Z, Y, X).
  • dif(X, Y, Z) - sum(Z, Y, Z).
  • Goal
  • - sum(succ(succ(0)), succ(succ(succ(0))), A).
  • 23A
  • Response
  • A succ(succ(succ(succ(succ(0)))))
  • 5
Write a Comment
User Comments (0)
About PowerShow.com