SlideShare a Scribd company logo
An Overview of Prolog
1
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.
2
Chapter One: Introduction to Prolog
1. Defining relations by facts
2. Defining relations by rules
3. Recursive rules
4. How Prolog answers questions
5. Declarative and procedural meaning of programs
3
Chapter one:
1. Defining relations by facts
2. Defining relations by rules
4
1.1 Defining relations by facts
5
Example
The fact that tom is a parent of bob
parent(tom, bob).
the name of a relation argument1 argument2
Fact clause
1.1 Defining relations by facts
6
 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
1.1 Defining relations by facts
7
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: True
?- parent(liz, pat)
Prolog answer: No solutions
?- parent(tom, pat)
Prolog answer: No solutions
tom
bob
ann
pat jim
liz
pam
1.1 Defining relations by facts
8
Who 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
ann
pat jim
liz
pam
1.1 Defining relations by facts
9
Find 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
ann
pat jim
liz
pam
1.1 Defining relations by facts
10
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 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.
√
x
x
1.1 Defining relations by facts
11
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
tom
bob
ann
pat jim
liz
pam
1.2 Defining relations by rules
12
 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).
1.2 Defining relations by rules
13
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
tom
bob
ann
pat jim
liz
pam
Fact
caluses
1.2 Defining relations by rules
14
There is an important difference between facts and
rules:
 Facts is something that is always, unconditionally,
true
parent(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
1.2 Defining relations by rules
15
Questions
 Is liz an offspring of tom?
?- offspring(liz, tom).
Prolog answer: True
How Prolog answer this question using the rule:
Offspring(Y, X) :- parent(X, Y).
Prolog answer: True
1.2 Defining relations by rules
16
 How to express:
 Mother relation
 Grandparent relation
 Sister relation
in Prolog?
Important Points
17

More Related Content

PPTX
Overview prolog
PPT
PPT
Basic dns-mod
PPTX
Explain Knowledge Representation(prolog) in AI.pptx
DOCX
Prolog_Programminvfygugy7gtugbugtg_Notes.docx
PDF
Prolog PPT_merged.pdf
PDF
PROLOG in artificial intelligence(Basic of pprolog)).pdf
PPT
First order logic.ppt
Overview prolog
Basic dns-mod
Explain Knowledge Representation(prolog) in AI.pptx
Prolog_Programminvfygugy7gtugbugtg_Notes.docx
Prolog PPT_merged.pdf
PROLOG in artificial intelligence(Basic of pprolog)).pdf
First order logic.ppt

More from James Wong (20)

PPT
Data race
PPT
Multi threaded rtos
PPT
Recursion
PPTX
Business analytics and data mining
PPTX
Data mining and knowledge discovery
PPTX
Cache recap
PPTX
Big picture of data mining
PPTX
How analysis services caching works
PPTX
Optimizing shared caches in chip multiprocessors
PPTX
Directory based cache coherence
PPT
Abstract data types
PPTX
Abstraction file
PPTX
Hardware managed cache
PPTX
Object model
PPT
Abstract class
PPTX
Object oriented analysis
PPTX
Concurrency with java
PPTX
Data structures and algorithms
PPTX
Cobol, lisp, and python
PPTX
Inheritance
Data race
Multi threaded rtos
Recursion
Business analytics and data mining
Data mining and knowledge discovery
Cache recap
Big picture of data mining
How analysis services caching works
Optimizing shared caches in chip multiprocessors
Directory based cache coherence
Abstract data types
Abstraction file
Hardware managed cache
Object model
Abstract class
Object oriented analysis
Concurrency with java
Data structures and algorithms
Cobol, lisp, and python
Inheritance
Ad

Recently uploaded (20)

PPTX
Big Data Technologies - Introduction.pptx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
A Presentation on Artificial Intelligence
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Approach and Philosophy of On baking technology
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Machine Learning_overview_presentation.pptx
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
Tartificialntelligence_presentation.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Electronic commerce courselecture one. Pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
Big Data Technologies - Introduction.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
MYSQL Presentation for SQL database connectivity
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
A Presentation on Artificial Intelligence
Encapsulation_ Review paper, used for researhc scholars
Unlocking AI with Model Context Protocol (MCP)
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Group 1 Presentation -Planning and Decision Making .pptx
Building Integrated photovoltaic BIPV_UPV.pdf
Approach and Philosophy of On baking technology
Network Security Unit 5.pdf for BCA BBA.
20250228 LYD VKU AI Blended-Learning.pptx
Machine Learning_overview_presentation.pptx
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Tartificialntelligence_presentation.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Electronic commerce courselecture one. Pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
Ad

Overview prolog

  • 1. An Overview of Prolog 1
  • 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. 2
  • 3. Chapter One: Introduction to Prolog 1. Defining relations by facts 2. Defining relations by rules 3. Recursive rules 4. How Prolog answers questions 5. Declarative and procedural meaning of programs 3
  • 4. Chapter one: 1. Defining relations by facts 2. Defining relations by rules 4
  • 5. 1.1 Defining relations by facts 5 Example The fact that tom is a parent of bob parent(tom, bob). the name of a relation argument1 argument2 Fact clause
  • 6. 1.1 Defining relations by facts 6  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
  • 7. 1.1 Defining relations by facts 7 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: True ?- parent(liz, pat) Prolog answer: No solutions ?- parent(tom, pat) Prolog answer: No solutions tom bob ann pat jim liz pam
  • 8. 1.1 Defining relations by facts 8 Who 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 ann pat jim liz pam
  • 9. 1.1 Defining relations by facts 9 Find 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 ann pat jim liz pam
  • 10. 1.1 Defining relations by facts 10 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 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. √ x x
  • 11. 1.1 Defining relations by facts 11 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 tom bob ann pat jim liz pam
  • 12. 1.2 Defining relations by rules 12  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).
  • 13. 1.2 Defining relations by rules 13 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 tom bob ann pat jim liz pam Fact caluses
  • 14. 1.2 Defining relations by rules 14 There is an important difference between facts and rules:  Facts is something that is always, unconditionally, true parent(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
  • 15. 1.2 Defining relations by rules 15 Questions  Is liz an offspring of tom? ?- offspring(liz, tom). Prolog answer: True How Prolog answer this question using the rule: Offspring(Y, X) :- parent(X, Y). Prolog answer: True
  • 16. 1.2 Defining relations by rules 16  How to express:  Mother relation  Grandparent relation  Sister relation in Prolog?

Editor's Notes

  • #14: offspring(bob, pam). offspring(ann, bob). offspring(pat, bob). offspring(jim, pat).