overview prolog
TRANSCRIPT
![Page 1: Overview prolog](https://reader030.vdocument.in/reader030/viewer/2022033106/58757bc31a28ab78498b613b/html5/thumbnails/1.jpg)
1
An Overview of Prolog
![Page 2: Overview prolog](https://reader030.vdocument.in/reader030/viewer/2022033106/58757bc31a28ab78498b613b/html5/thumbnails/2.jpg)
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.
![Page 3: Overview prolog](https://reader030.vdocument.in/reader030/viewer/2022033106/58757bc31a28ab78498b613b/html5/thumbnails/3.jpg)
3
Chapter One: Introduction to Prolog1. Defining relations by facts2. Defining relations by rules3. Recursive rules4. How Prolog answers questions5. Declarative and procedural meaning of
programs
![Page 4: Overview prolog](https://reader030.vdocument.in/reader030/viewer/2022033106/58757bc31a28ab78498b613b/html5/thumbnails/4.jpg)
4
Chapter one:
1. Defining relations by facts2. Defining relations by rules
![Page 5: Overview prolog](https://reader030.vdocument.in/reader030/viewer/2022033106/58757bc31a28ab78498b613b/html5/thumbnails/5.jpg)
5
1.1 Defining relations by factsExampleThe fact that tom is a parent of bobparent(tom, bob).
the name of a relation argument1 argument2
Fact clause
tom bob annpat jimliz
pam
![Page 6: Overview prolog](https://reader030.vdocument.in/reader030/viewer/2022033106/58757bc31a28ab78498b613b/html5/thumbnails/6.jpg)
6
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 one fact about parent relation (particular instance of the parent relation) * a relation is the set of all its instances
tom bob annpat jimliz
pam
![Page 7: Overview prolog](https://reader030.vdocument.in/reader030/viewer/2022033106/58757bc31a28ab78498b613b/html5/thumbnails/7.jpg)
7
1.1 Defining relations by factsWhen 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: True
?- parent(liz, pat)Prolog answer: No solutions
?- parent(tom, pat)
Prolog answer: No solutions
tom bob annpat jimliz
pam
![Page 8: Overview prolog](https://reader030.vdocument.in/reader030/viewer/2022033106/58757bc31a28ab78498b613b/html5/thumbnails/8.jpg)
8
1.1 Defining relations by factsWho is liz’s parent??- parent(X, liz)Prolog answer: X = tom
Who are bob’s children??- parent(bob, X)Prolog answer: X = ann.X = pat.
tom bob annpat jimliz
pam
![Page 9: Overview prolog](https://reader030.vdocument.in/reader030/viewer/2022033106/58757bc31a28ab78498b613b/html5/thumbnails/9.jpg)
9
1.1 Defining relations by factsFind X and Y such that X is a parent of Y.?- parent (X, Y).Prolog answers: X = pam.Y = bob.
X = tom.Y = bob.
X = tom.Y = liz.
X = bob.Y = ann.
X = bob.Y = pat.
X = pat.Y = jim.
tom bob annpat jimliz
pam
![Page 10: Overview prolog](https://reader030.vdocument.in/reader030/viewer/2022033106/58757bc31a28ab78498b613b/html5/thumbnails/10.jpg)
10
1.1 Defining relations by factsWho is a grandparent of jim?Who is the parent of jim? Assume that this is YWho 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 affect the result.?- parent(X, jim), parent (Y, X)
Prolog answer: X = pat. Y = bob.
?- parent(X, jim), parent (X, Y) Prolog answer: X = pat. Y = jim.
tom bob annpat jimliz
pam
√
xx
![Page 11: Overview prolog](https://reader030.vdocument.in/reader030/viewer/2022033106/58757bc31a28ab78498b613b/html5/thumbnails/11.jpg)
11
1.1 Defining relations by factsDo 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
tom bob annpat jimliz
pam
![Page 12: Overview prolog](https://reader030.vdocument.in/reader030/viewer/2022033106/58757bc31a28ab78498b613b/html5/thumbnails/12.jpg)
12
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.
Gender(pam, female).Gender(tom, male).Gender(bob, male).
tom bob annpat jimliz
pam
![Page 13: Overview prolog](https://reader030.vdocument.in/reader030/viewer/2022033106/58757bc31a28ab78498b613b/html5/thumbnails/13.jpg)
13
1.2 Defining relations by rulesLet 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 ifX is a parent of Yoffspring(Y, X) :- parent(X, Y). Rule clause
tom bob annpat jimliz
pam
Fact caluses
![Page 14: Overview prolog](https://reader030.vdocument.in/reader030/viewer/2022033106/58757bc31a28ab78498b613b/html5/thumbnails/14.jpg)
14
1.2 Defining relations by rulesThere 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
![Page 15: Overview prolog](https://reader030.vdocument.in/reader030/viewer/2022033106/58757bc31a28ab78498b613b/html5/thumbnails/15.jpg)
15
1.2 Defining relations by rulesQuestions Is liz an offspring of tom??- offspring(liz, tom).Prolog answer: TrueHow Prolog answer this question using the rule:Offspring(Y, X) :- parent(X, Y).
Prolog answer: True
![Page 16: Overview prolog](https://reader030.vdocument.in/reader030/viewer/2022033106/58757bc31a28ab78498b613b/html5/thumbnails/16.jpg)
16
1.2 Defining relations by rules How to express:
Mother relation Grandparent relation Sister relation
in Prolog?
![Page 17: Overview prolog](https://reader030.vdocument.in/reader030/viewer/2022033106/58757bc31a28ab78498b613b/html5/thumbnails/17.jpg)
17
Important Points