SlideShare a Scribd company logo
SWI-Prolog
Content
•Introduction
•SWI_PROLOG
•Fundamentals of PROLOG
•Applications
•References
https://www.swi-prolog.org/download/stable
SWI-Prolog has been under continuous development since 1987. Its main
author is Jan Wielemaker. The name SWI is derived from Sociaal-
Wetenschappelijke Informatica ("Social Science Informatics"), the former
name of the group at the University of Amsterdam, where Wielemaker is
employed.
sudo apt-add-repository ppa:swi-prolog/stable
sudo apt-get update
sudo apt-get install swi-prolog
What is Prolog?
Prolog or PROgramming in LOGics is a logical and declarative programming language. It is one
major example of the fourth generation language that supports the declarative programming
paradigm. This is particularly suitable for programs that involve symbolic or non-numeric
computation. This is the main reason to use Prolog as the programming language in Artificial
Intelligence, where symbol manipulation and inference manipulation are the fundamental
tasks.
In Prolog, we need not mention the way how one problem can be solved, we just need to mention
what the problem is, so that Prolog automatically solves it. However, in Prolog we are supposed to
give clues as the solution method.
Prolog language basically has three different elements −
Facts The fact is predicate that is true, for example, if we say, “Tom is the son of Jack”, then this is
−
a fact.
Rules Rules are extinctions of facts that contain conditional clauses. To satisfy a rule these
−
conditions should be met. For example, if we define a rule as −
grandfather(X, Y) :- father(X, Z), parent(Z, Y)
This implies that for X to be the grandfather of Y, Z should be a parent of Y and X should be father of
Z.
Questions And to run a prolog program, we need some questions, and those questions can be
−
Open source software
• Open source software is software that can be freely used, changed, and shared (in modified or
unmodified form) by anyone.
SWI-Prolog
•SWI-Prolog offers a comprehensive FREE SOFTWARE
• Prolog environment.
Link for downloading:
•http://www.swi-prolog.org/download/stable
•A Self-installing executable for MS-Windows: swipl-
win.exe
•Works on Windows
•LINUX versions are also available.
Introduction-PROLOG
• PROgramming in LOGic
FACTS RULES
CONCLUSIONS
• Olivia likes Pizza.
likes(olivia, pizza).
FACTS OBJECTS RELATIONSHIP
Introduction-PROLOG
OBJECTS
FACTS
RELATIONSHIP
• Olivia is student.
student(olivia).
FACTS OBJECTS RELATIONSHIP
Introduction-PROLOG
OBJECT
FACT
RELATIONSHIP
• Beginning with lower case letters.
• End the fact with period (full stop).
Basic Constructs of Prolog progarm
Knowledge Base
Introduction-PROLOG
PROLOG programming is all about writing knowledge base
Clauses
}
Facts are statements about what is true about a problem, instead of instructions
how to accomplish the solution.
}
The Prolog system uses the facts to work out how to accomplish the solution by
searching through the space of possible solutions.
}
It is defined by an identifier followed by an n-tuple of constants.
}
A relation identifier is referred to as a predicate
}
When a tuple of values is in a relation we say the tuple satisfies the predicate.
}
Names of relationship and objects must begin with a lower-
case letter.
}
Relationship is written first (typically the predicate of the
sentence).
}
Objects are written separated by commas and are enclosed
by a pair of round brackets.
}
The full stop character ‘.’ must come at the end of a fact.
•Predicate
•valuable(gold)
owns(john,gold)
father(john,mary)
•gives (john,book,mary)
Interpretation
Gold is valuable.
John owns gold.
John is the father of Mary
John gives the book to Mary
Examples
}
Specifies under what conditions a tuple of values satisfies a
predicate.
}
The basic building block of a rule is called an atom
}
Atom :- Atom1, ..., Atomn
If each of Atom1,...,Atomn is true, then Atom is also true.
Knowledge base
• General Rule:
–If the body of the rule is true then head implies true
• Clauses: 5
• Predicates 3
• ?- author(khalid).
• What is result of the query?
– True
Example 1 : Below food table shows the facts, rules, goals and their
English meanings
.
Facts English meanings
food(burger). // burger is a food
food(sandwich). // sandwich is a food
food(pizza). // pizza is a food
lunch(sandwich). // sandwich is a lunch
dinner(pizza). // pizza is a dinner
Rules
meal(X) :- food(X). // Every food is a meal OR
Anything is a meal if it is a food
Queries / Goals
?- food(pizza).
// Is pizza a food?
?- meal(X), lunch(X). //Which food is meal and lunch?
?- dinner(sandwich). // Is sandwich a dinner?
• From Example 1 :
(1) ?- meal(X), dinner(X).
(2) ?- meal(What).
(3) ?- meal(X), dinner(Y).
Syntax of Prolog: Terms
⮚ Constants: Identifiers
🞂 sequences of letters, digits, or underscore “_” that start with lower
case letters.
🞂 mary, anna, x25, x_25, alpha_beta
🞂 Numbers
🞂 1.001, 2, 3.03
🞂 Strings enclosed in single quotes
🞂 'Mary', '1.01‘, ‘string'
◻ Note can start with upper case letter, or can be a number now
treated as a string.
⮚ Variables
🞂 Sequence of letters digits or underscore that start with an
upper case letter or the underscore.
🞂 _x, Anna, Successor_State,
Syntax of Prolog: Terms
🞂 Constants:
🞂 Variables
🞂 Structures (like function applications)
🞂 <identifier>(Term1, ..., Termk)
🞂 date(1, may, 1983)
🞂 point(X, Y, Z)
🞂 Note that the definition is recursive. So each term
can itself be a structure
🞂 date(+(0,1), may, +(1900,-(183,100)))
🞂 Structures can be represented as a tree
Syntax of Prolog: Terms
🞂 Structures as trees
🞂 date(+(0,1), may, +(1900,-(183,100)))
+ may +
0 1 1900 +
0 1
date
Syntax of Prolog: Lists as special terms
🞂 Lists are a very useful data structure in Prolog.
🞂 Lists are structured terms represented in a special way.
🞂 [a,b,c,d]
🞂 This is actually the structured term
[a | [c | [b | [d | []]]]]
🞂 Where [] is a special constant the empty list.
🞂 Each list is thus of the form [<head> | <rest_of_list>]
🞂 <head> an element of the list.
🞂 <rest_of_list> is a list (a sub-list).
🞂 also, [a,b,c,d]=[a|[b,c,d]] =[a,b|[c,d]] = [a,b,c|[d]]
🞂 List elements can be any term! For example the list [a, f(a), 2, 3+5,
point(X,1.5,Z)] contains 5 elements.
Syntax of Prolog: Predicates
🞂 Predicates are syntactically identical to structured terms
<identifier>(Term1, ..., Termk)
🞂 elephant(mary)
🞂 taller_than(john, fred)
True (if they unify)
?-X = Y
False (otherwise)
built in
Rules:-
i) X and Y are permitted to be uninstantiated variables.
ii) Integers and atoms are always equal to themselves.
iii) 2 structures are equal only if :-
a) Same functions.
b) No. of components.
c) corresponding components are equal.
Eg. a(b,c(d,e))= a(X, c(Y, e))
X = b
Y = d
X = Y
Y = 10
X= 10
Prolog language programming in the facts.pptx
Operation
🞂 p(1) :- a(1).
p(1) :- b(1).
a(1) :- c(1).
c(1) :- d(1).
c(1) :- d(2).
b(1) :- e(1).
🞂 Backtracking can occur at every stage as the query is
processed.
p(1)
a(1)
c(1)
b(1)
e(1) d(3)
e(1).
d(3).

Query:
d(1) d(2)
p(1)
27
Operation
🞂 With backtracking we can get more answers by using “;”
🞂 p(1) :- a(1).
p(1) :- b(1).
a(1) :- c(1).
c(1) :- d(1).
c(1) :- d(2).
b(1) :- e(1).
b(1) :- d(3).
p(1)
a(1)
c(1)
b(1)
e(1)
e(1).
d(3).

Query:
d(1) d(2)
p(1)
d(3)
28
Prolog language programming in the facts.pptx
• Prolog uses two types of comments:
• Line comments go from the “%” symbol to the end of the line
– % This is a comment AAn Introduction to Prolog
• Multiline comments begin with a “/*” and end with a “*/”
– /* this is a comment */

More Related Content

PPTX
Prolog final
PPTX
Prolog 7-Languages
PDF
Logic Programming and ILP
PDF
Prolog,Prolog Programming IN AI.pdf
PPTX
Prolog Programming Language
PPTX
Python Training
PPTX
Plc part 4
PPTX
Unit 3 Prolog.pptxUnit 3 Prolog.pptxUnit 3 Prolog.pptxUnit 3 Prolog.pptxUnit
Prolog final
Prolog 7-Languages
Logic Programming and ILP
Prolog,Prolog Programming IN AI.pdf
Prolog Programming Language
Python Training
Plc part 4
Unit 3 Prolog.pptxUnit 3 Prolog.pptxUnit 3 Prolog.pptxUnit 3 Prolog.pptxUnit

Similar to Prolog language programming in the facts.pptx (20)

PPTX
Information Retrieval and Extraction - Module 7
PPTX
python programming ppt-230111072927-1c7002a5.pptx
PPTX
Prolog Programming : Basics
PPTX
PYTHON PPT.pptx
PDF
Python basics_ part1
PPTX
All_About_Python_and_more+Cambridge.pptx
PPTX
Family Tree on PROLOG
PPTX
PPTX
ProLog (Artificial Intelligence) Introduction
PPTX
Python training
PDF
Doctoral Consortium@RuleML2015: Seamless Cooperation of JAVA and PROLOG for ...
PDF
NLP Project Full Cycle
PPTX
PROGRAMMING-QUARTER-2-PYTHON.pptxnsnsndn
PDF
Crash-course in Natural Language Processing
PPTX
Major Programming Paradigms
PPT
Chaps 1-3-ai-prolog
PPTX
ARTIFICIAL INTELLIGENCE---UNIT 4.pptx
PPTX
Basic concept of Python.pptx includes design tool, identifier, variables.
PPTX
bhaskars.pptx
PPTX
Programming paradigms Techniques_part2.pptx
Information Retrieval and Extraction - Module 7
python programming ppt-230111072927-1c7002a5.pptx
Prolog Programming : Basics
PYTHON PPT.pptx
Python basics_ part1
All_About_Python_and_more+Cambridge.pptx
Family Tree on PROLOG
ProLog (Artificial Intelligence) Introduction
Python training
Doctoral Consortium@RuleML2015: Seamless Cooperation of JAVA and PROLOG for ...
NLP Project Full Cycle
PROGRAMMING-QUARTER-2-PYTHON.pptxnsnsndn
Crash-course in Natural Language Processing
Major Programming Paradigms
Chaps 1-3-ai-prolog
ARTIFICIAL INTELLIGENCE---UNIT 4.pptx
Basic concept of Python.pptx includes design tool, identifier, variables.
bhaskars.pptx
Programming paradigms Techniques_part2.pptx
Ad

More from jaymalachavan (6)

PPTX
comparative_analysis_CIFAR10_YouTube8M (1).pptx
PPT
Chapter4_protyping and construction_uidppt.ppt
PPT
Chapter4_interaction design process_uidppt.ppt
PPTX
8. Functional Programming_updated(1).pptx
PPTX
Optimization_Algorithms_and_Problems.pptx
PPTX
Optimization_Algorithms_and_Problems.pptx
comparative_analysis_CIFAR10_YouTube8M (1).pptx
Chapter4_protyping and construction_uidppt.ppt
Chapter4_interaction design process_uidppt.ppt
8. Functional Programming_updated(1).pptx
Optimization_Algorithms_and_Problems.pptx
Optimization_Algorithms_and_Problems.pptx
Ad

Recently uploaded (20)

PDF
Arduino robotics embedded978-1-4302-3184-4.pdf
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPTX
CH1 Production IntroductoryConcepts.pptx
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PDF
composite construction of structures.pdf
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PPTX
Geodesy 1.pptx...............................................
PPTX
web development for engineering and engineering
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PPT
Mechanical Engineering MATERIALS Selection
PDF
Well-logging-methods_new................
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PDF
Digital Logic Computer Design lecture notes
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PPTX
Sustainable Sites - Green Building Construction
Arduino robotics embedded978-1-4302-3184-4.pdf
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
CH1 Production IntroductoryConcepts.pptx
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
composite construction of structures.pdf
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
Geodesy 1.pptx...............................................
web development for engineering and engineering
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
Mechanical Engineering MATERIALS Selection
Well-logging-methods_new................
CYBER-CRIMES AND SECURITY A guide to understanding
Digital Logic Computer Design lecture notes
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Foundation to blockchain - A guide to Blockchain Tech
Sustainable Sites - Green Building Construction

Prolog language programming in the facts.pptx

  • 3. https://www.swi-prolog.org/download/stable SWI-Prolog has been under continuous development since 1987. Its main author is Jan Wielemaker. The name SWI is derived from Sociaal- Wetenschappelijke Informatica ("Social Science Informatics"), the former name of the group at the University of Amsterdam, where Wielemaker is employed. sudo apt-add-repository ppa:swi-prolog/stable sudo apt-get update sudo apt-get install swi-prolog
  • 4. What is Prolog? Prolog or PROgramming in LOGics is a logical and declarative programming language. It is one major example of the fourth generation language that supports the declarative programming paradigm. This is particularly suitable for programs that involve symbolic or non-numeric computation. This is the main reason to use Prolog as the programming language in Artificial Intelligence, where symbol manipulation and inference manipulation are the fundamental tasks. In Prolog, we need not mention the way how one problem can be solved, we just need to mention what the problem is, so that Prolog automatically solves it. However, in Prolog we are supposed to give clues as the solution method. Prolog language basically has three different elements − Facts The fact is predicate that is true, for example, if we say, “Tom is the son of Jack”, then this is − a fact. Rules Rules are extinctions of facts that contain conditional clauses. To satisfy a rule these − conditions should be met. For example, if we define a rule as − grandfather(X, Y) :- father(X, Z), parent(Z, Y) This implies that for X to be the grandfather of Y, Z should be a parent of Y and X should be father of Z. Questions And to run a prolog program, we need some questions, and those questions can be −
  • 5. Open source software • Open source software is software that can be freely used, changed, and shared (in modified or unmodified form) by anyone.
  • 6. SWI-Prolog •SWI-Prolog offers a comprehensive FREE SOFTWARE • Prolog environment. Link for downloading: •http://www.swi-prolog.org/download/stable •A Self-installing executable for MS-Windows: swipl- win.exe •Works on Windows •LINUX versions are also available.
  • 7. Introduction-PROLOG • PROgramming in LOGic FACTS RULES CONCLUSIONS
  • 8. • Olivia likes Pizza. likes(olivia, pizza). FACTS OBJECTS RELATIONSHIP Introduction-PROLOG OBJECTS FACTS RELATIONSHIP
  • 9. • Olivia is student. student(olivia). FACTS OBJECTS RELATIONSHIP Introduction-PROLOG OBJECT FACT RELATIONSHIP • Beginning with lower case letters. • End the fact with period (full stop).
  • 10. Basic Constructs of Prolog progarm
  • 11. Knowledge Base Introduction-PROLOG PROLOG programming is all about writing knowledge base Clauses
  • 12. } Facts are statements about what is true about a problem, instead of instructions how to accomplish the solution. } The Prolog system uses the facts to work out how to accomplish the solution by searching through the space of possible solutions. } It is defined by an identifier followed by an n-tuple of constants. } A relation identifier is referred to as a predicate } When a tuple of values is in a relation we say the tuple satisfies the predicate.
  • 13. } Names of relationship and objects must begin with a lower- case letter. } Relationship is written first (typically the predicate of the sentence). } Objects are written separated by commas and are enclosed by a pair of round brackets. } The full stop character ‘.’ must come at the end of a fact.
  • 14. •Predicate •valuable(gold) owns(john,gold) father(john,mary) •gives (john,book,mary) Interpretation Gold is valuable. John owns gold. John is the father of Mary John gives the book to Mary Examples
  • 15. } Specifies under what conditions a tuple of values satisfies a predicate. } The basic building block of a rule is called an atom } Atom :- Atom1, ..., Atomn If each of Atom1,...,Atomn is true, then Atom is also true.
  • 16. Knowledge base • General Rule: –If the body of the rule is true then head implies true • Clauses: 5 • Predicates 3
  • 17. • ?- author(khalid). • What is result of the query? – True
  • 18. Example 1 : Below food table shows the facts, rules, goals and their English meanings . Facts English meanings food(burger). // burger is a food food(sandwich). // sandwich is a food food(pizza). // pizza is a food lunch(sandwich). // sandwich is a lunch dinner(pizza). // pizza is a dinner Rules meal(X) :- food(X). // Every food is a meal OR Anything is a meal if it is a food Queries / Goals ?- food(pizza). // Is pizza a food? ?- meal(X), lunch(X). //Which food is meal and lunch? ?- dinner(sandwich). // Is sandwich a dinner?
  • 19. • From Example 1 : (1) ?- meal(X), dinner(X). (2) ?- meal(What). (3) ?- meal(X), dinner(Y).
  • 20. Syntax of Prolog: Terms ⮚ Constants: Identifiers 🞂 sequences of letters, digits, or underscore “_” that start with lower case letters. 🞂 mary, anna, x25, x_25, alpha_beta 🞂 Numbers 🞂 1.001, 2, 3.03 🞂 Strings enclosed in single quotes 🞂 'Mary', '1.01‘, ‘string' ◻ Note can start with upper case letter, or can be a number now treated as a string. ⮚ Variables 🞂 Sequence of letters digits or underscore that start with an upper case letter or the underscore. 🞂 _x, Anna, Successor_State,
  • 21. Syntax of Prolog: Terms 🞂 Constants: 🞂 Variables 🞂 Structures (like function applications) 🞂 <identifier>(Term1, ..., Termk) 🞂 date(1, may, 1983) 🞂 point(X, Y, Z) 🞂 Note that the definition is recursive. So each term can itself be a structure 🞂 date(+(0,1), may, +(1900,-(183,100))) 🞂 Structures can be represented as a tree
  • 22. Syntax of Prolog: Terms 🞂 Structures as trees 🞂 date(+(0,1), may, +(1900,-(183,100))) + may + 0 1 1900 + 0 1 date
  • 23. Syntax of Prolog: Lists as special terms 🞂 Lists are a very useful data structure in Prolog. 🞂 Lists are structured terms represented in a special way. 🞂 [a,b,c,d] 🞂 This is actually the structured term [a | [c | [b | [d | []]]]] 🞂 Where [] is a special constant the empty list. 🞂 Each list is thus of the form [<head> | <rest_of_list>] 🞂 <head> an element of the list. 🞂 <rest_of_list> is a list (a sub-list). 🞂 also, [a,b,c,d]=[a|[b,c,d]] =[a,b|[c,d]] = [a,b,c|[d]] 🞂 List elements can be any term! For example the list [a, f(a), 2, 3+5, point(X,1.5,Z)] contains 5 elements.
  • 24. Syntax of Prolog: Predicates 🞂 Predicates are syntactically identical to structured terms <identifier>(Term1, ..., Termk) 🞂 elephant(mary) 🞂 taller_than(john, fred)
  • 25. True (if they unify) ?-X = Y False (otherwise) built in Rules:- i) X and Y are permitted to be uninstantiated variables. ii) Integers and atoms are always equal to themselves. iii) 2 structures are equal only if :- a) Same functions. b) No. of components. c) corresponding components are equal. Eg. a(b,c(d,e))= a(X, c(Y, e)) X = b Y = d X = Y Y = 10 X= 10
  • 27. Operation 🞂 p(1) :- a(1). p(1) :- b(1). a(1) :- c(1). c(1) :- d(1). c(1) :- d(2). b(1) :- e(1). 🞂 Backtracking can occur at every stage as the query is processed. p(1) a(1) c(1) b(1) e(1) d(3) e(1). d(3).  Query: d(1) d(2) p(1) 27
  • 28. Operation 🞂 With backtracking we can get more answers by using “;” 🞂 p(1) :- a(1). p(1) :- b(1). a(1) :- c(1). c(1) :- d(1). c(1) :- d(2). b(1) :- e(1). b(1) :- d(3). p(1) a(1) c(1) b(1) e(1) e(1). d(3).  Query: d(1) d(2) p(1) d(3) 28
  • 30. • Prolog uses two types of comments: • Line comments go from the “%” symbol to the end of the line – % This is a comment AAn Introduction to Prolog • Multiline comments begin with a “/*” and end with a “*/” – /* this is a comment */