1 / 16

An Overview of Prolog

An Overview of Prolog. What is Prolog. Prolog is a powerful language for AI and non-numerical programming Stands for programming in logic Centered around a small set of basic mechanisms, including: Pattern matching Tree-based data structuring Automatic back tracking

jaser
Download Presentation

An Overview of Prolog

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. An Overview of Prolog

  2. What is Prolog • Prolog is a powerful language for AI and non-numerical programming • Stands for programming in logic • Centered around a small set of basic mechanisms, including: • Pattern matching • Tree-based data structuring • Automatic back tracking • Well suited for problems that involves structured objects and relations between them.

  3. Chapter One: Introduction to Prolog • Defining relations by facts • Defining relations by rules • Recursive rules • How Prolog answers questions • Declarative and procedural meaning of programs

  4. 1.1 Defining relations by facts Example The fact that tom is a parent of bob parent(ahemd, bob). the name of a relation argument1 argument2 Fact clause

  5. 1.1 Defining relations by facts • The family tree is defined by the following Prolog program:parent(pam, bob).parent(tom, bob).parent(tom, liz).parent(bob, ann).parent(bob, pat).parent(pat, jim).This program consists of six clauses. Each clause declares onefact about parent relation (particular instance of the parentrelation) * a relation is the set of all its instances

  6. 1.1 Defining relations by facts When the program communicated to Prolog system, Prolog can be posed some questions about the parent relation: Is bob a parent of pat? ?- parent(bob, pat). Prolog answer: yes ?- parent(liz, pat). Prolog answer: no ?- parent(tom, pat). Prolog answer:no

  7. 1.1 Defining relations by facts Who is liz’s parent? ?- parent(X, liz). Prolog answer: X = tom Who are bob’s children? ?- parent(bob, X). Prolog answer: X = ann We can request anther solution by typing ; X = pat If we request more solution, Prolog will answer no

  8. 1.1 Defining relations by facts Find X and Y such that X is a parent of Y. ?- parent (X, Y). Prolog answers: X = pamY = bob; X = tomY = bob; X = tomY = liz; … we can stop the stream of solutions by typing a return

  9. 1.1 Defining relations by facts Who is a grandparent of jim? Who is the parent of jim? Assume that this is Y Who is the parent of Y? Assume that this is X ?- parent(Y, jim), parent (X, Y) Prolog answer: X = bob Y = pat * Changing the order of the requirements will NOT affect the result.

  10. 1.1 Defining relations by facts Do ann and pat have a common parent? Who is a parent X of ann? Is X a parent of pat? ?- parent (X, ann), parent(X, pat) Prolog answer: X = bob

  11. 1.2 Defining relations by rules • We can add the information on the sex of the people that occur in the parent relation: female(pam). male(tom). male(bob). female(liz). female(pat). female(ann). male(jim). male and female are unary relations, whereas parent is a binary relation. sex(pam, female). sex(tom, male). sex(bob, male).

  12. 1.2 Defining relations by rules Let us introduce the offspring relation (inverse of parent) offspring(liz, tom). offspring(bob, tom). ... The logical statement is: For all X and Y, Y is an offspring of X if X is a parent of Y Offspring(Y, X) :- parent(X, Y). Rule clause Fact caluses

  13. 1.2 Defining relations by rules There is an important difference between facts and rules: • Facts is something that is always, unconditionally, trueparent(tom, liz). • Rules specify things that are true if some condition is satisfied. Rules have: • Condition part (right-hand side) = body • Conclusion part (left-hand side) = head Offspring(Y, X) :- parent(X, Y). head body

  14. 1.2 Defining relations by rules Questions • Is liz an offspring of tom? ?- offspring(liz, tom). How Prolog answer this question using the rule: Offspring(Y, X) :- parent(X, Y). Prolog answer: yes

  15. 1.2 Defining relations by rules • How to express: • Mother relation • Grandparent relation • Sister relation in Prolog?

  16. Important Points

More Related