SlideShare a Scribd company logo
Prolog Programming
BY: MITUL K. DESAI
What is Prolog?
 Prolog stands for programming in logic (PROgrammation en LOgique).
 Prolog is the most widely used language to have been inspired by logic
programming research.
 Prolog is the only successful example of the family of logic programming
languages.
 A Prolog program is a theory written in a subset of first-order logic, called
Horn clause logic.
 Prolog is declarative. A Prolog programmer concentrates on what the program
needs to do, not on how to do it.
A Little History
 Prolog was invented by Alain Colmerauer, a professor of computer science at
the university of Aix-Marseille in France, in 1972.
 The first application of Prolog was in natural language processing.
 Its theoretical underpinning are due to Donald Loveland of Duke university
through Robert Kowalski (formerly) of the university of Edinburgh
Main Advantages
 Ease of representing knowledge.
 Natural support of pattern-matching.
 Natural support of meta-programming.
 Meaning of programs is independent of how they are executed.
 Simple connection between programs and computed answers and
specifications.
 No need to distinguish programs from databases.
Anatomy of Prolog Program
 Prolog programs are made up of facts and rules.
 A fact asserts some property of an object, or relation between two or more
objects.
e.g. parent(jane,alan).
Can be read as “Jane is the parent of Alan.”
 Rules allow us to infer that a property or relationship holds based on
preconditions.
e.g. parent(X,Y) :- mother(X,Y).
= “Person X is the parent of person Y if X is Y‟s mother.”
Predicate Definitions
 Both facts and rules are predicate definitions.
 ‘Predicate’is the name given to the word occurring before the bracket in a fact
or rule:
parent (jane,alan).
 By defining a predicate you are specifying which information needs to be
known for the property denoted by the predicate to be true.
Predicate name
Clauses
 Predicate definitions consist of clauses.
= An individual definition (whether it be a fact or rule).
e.g. mother(jane, alan). = Fact
parent(P1,P2):- mother(P1,P2). = Rule
 A clause consists of a head
 And sometimes a body.
-- Facts don‟t have a body because they are always true.
head body
Arguments
 A predicate head consists of a predicate name and sometimes some arguments
contained within brackets and separated by commas.
mother(jane, alan).
 A body can be made up of any number of subgoals (calls to other predicates) and
terms.
 Arguments also consist of terms, which can be:
-- Constants e.g. jane,
-- Variables e.g. Person1, or
-- Compound terms
Predicate name Arguments
Terms: Constants
Constants can either be:
 Numbers:
 integers are the usual form (e.g. 1, 0, -1, etc), but
 floating-point numbers can also be used (e.g. 3.0E7)
 Symbolic constants:
 always start with a lower case alphabetic character and contain any mixture of
letters, digits, and underscores (but no spaces, punctuation, or an initial capital).
 e.g. abc, big_long_constant, x4_3t.
 String constants:
 are anything between single quotes e.g. „Like this‟.
Terms: Variables
 Variables always start with an upper case alphabetic character or an underscore.
 Other than the first character they can be made up of any mixture of letters, digits, and
underscores.
e.g. X, ABC, _89two5, _very_long_variable
 There are no “types” for variables (or constants) – a variable can take any value.
 All Prolog variables have a “local” scope:
--- they only keep the same value within a clause; the same variable used outside
of a clause does not inherit the value (this would be a “global” scope).
Naming Tips
 Use real English when naming predicates, constants, and variables.
e.g. “John wants to help Somebody.”
Could be: wants(john, to_help, Somebody).
Not: x87g(j,_789).
 Use a Verb Subject Object structure:
wants(john, to_help).
 BUT do not assume Prolog Understands the meaning of your chosen
names!
-- You create meaning by specifying the body (i.e. preconditions) of a clause.
Using Predicate Definitions
Command line programming is tedious
e.g. | ?- write(„What is your name?‟), nl, read(X),
write(„Hello „), write(X).
We can define predicates to automate commands:
| ?- greetings.
What is your name?
|: tim.
Hello tim
X = tim ?
yes
Prolog Code Terminal
greetings:-
write(‘What is your name?’),
nl,
read(X),
write(‘Hello ‘),
write(X).
Running prolog program on windows
After SWI-Prolog has been installed on a Windows system, the following important new things
are available to the user:
 A folder (called directory in the remainder of this document) called swipl containing the
executable, libraries, etc., of the system.
No files are installed outside this directory.
 A program swipl-win.exe, providing a window for interaction with Prolog.
 The program swipl.exe is a version of SWI-Prolog that runs in a console window.
 The file extension .p1 is associated with the program swipl-win.exe.
 Opening a .p1 file will cause swipl-win.exe to start, change directory to the directory in which
the file to open resides, and load this file.
Executing a query
After loading a program, one can ask Prolog queries about the program.
?- likes (sam, x) .
X = dahl ;
X = tandoori ;
……
X = chips ;
?-
Prolog Execution
Most Prolog clauses have both a declarative reading and a procedural reading.
Whenever possible, the declarative reading is to be preferred.
mother (X, Y) :- parent (X, Y), female (X) .
Declarative reading: x is the mother of y
if x is parent of y and x is female
Prolog Execution
Procedural reading :
To show that x is the mother of y, first show that x is a parent of y, then show that x is female.
Clauses:
parent (john, bill) .
parent (jane, bill) .
female(jane) .
Query:
| ?- mother (M, bill) .
Prolog Execution
 The clause of mother /2 will be located, and the unification X=M, Y=bill will occur.
 Then parent (M, bill) will be attempted, resulting in the unification M=john.
 Next, female (john) will be attempted, but will fail.
 Prolog will backtrack to parent (M, bill) and look for another solution for this; it will
succeed and unify M=jane.
 Finally, it will attempt female (jane), and succeed; so the inquiry will succeed,
having performed the unification M=jane.
Thank You

More Related Content

What's hot

10 logic+programming+with+prolog
10 logic+programming+with+prolog10 logic+programming+with+prolog
10 logic+programming+with+prolog
baran19901990
 
Artificial intelligence Prolog Language
Artificial intelligence Prolog LanguageArtificial intelligence Prolog Language
Artificial intelligence Prolog Language
REHMAT ULLAH
 
First Order Logic resolution
First Order Logic resolutionFirst Order Logic resolution
First Order Logic resolution
Amar Jukuntla
 
Knowledge Engineering in FOL.
Knowledge Engineering in FOL.Knowledge Engineering in FOL.
Knowledge Engineering in FOL.
Megha Sharma
 
Time complexity
Time complexityTime complexity
Time complexity
Katang Isip
 
Time and Space Complexity
Time and Space ComplexityTime and Space Complexity
Time and Space Complexity
Ashutosh Satapathy
 
DESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSDESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSGayathri Gaayu
 
Complexity analysis in Algorithms
Complexity analysis in AlgorithmsComplexity analysis in Algorithms
Complexity analysis in Algorithms
Daffodil International University
 
Propositional logic
Propositional logicPropositional logic
Propositional logicRushdi Shams
 
Knowledge representation in AI
Knowledge representation in AIKnowledge representation in AI
Knowledge representation in AIVishal Singh
 
Design and analysis of algorithms
Design and analysis of algorithmsDesign and analysis of algorithms
Design and analysis of algorithms
Dr Geetha Mohan
 
Pattern matching
Pattern matchingPattern matching
Pattern matchingshravs_188
 
What is knowledge representation and reasoning ?
What is knowledge representation and reasoning ?What is knowledge representation and reasoning ?
What is knowledge representation and reasoning ?
Anant Soft Computing
 
Prolog Programming Language
Prolog Programming  LanguageProlog Programming  Language
Prolog Programming Language
Reham AlBlehid
 
Asymptotic Notation and Complexity
Asymptotic Notation and ComplexityAsymptotic Notation and Complexity
Asymptotic Notation and Complexity
Rajandeep Gill
 
Knowledge representation
Knowledge representationKnowledge representation
Knowledge representation
Md. Tanvir Masud
 
Algorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms IAlgorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms I
Mohamed Loey
 
Informed search
Informed searchInformed search
Informed search
Amit Kumar Rathi
 
Knowledge Representation & Reasoning
Knowledge Representation & ReasoningKnowledge Representation & Reasoning
Knowledge Representation & ReasoningSajid Marwat
 

What's hot (20)

10 logic+programming+with+prolog
10 logic+programming+with+prolog10 logic+programming+with+prolog
10 logic+programming+with+prolog
 
Artificial intelligence Prolog Language
Artificial intelligence Prolog LanguageArtificial intelligence Prolog Language
Artificial intelligence Prolog Language
 
First Order Logic resolution
First Order Logic resolutionFirst Order Logic resolution
First Order Logic resolution
 
Knowledge Engineering in FOL.
Knowledge Engineering in FOL.Knowledge Engineering in FOL.
Knowledge Engineering in FOL.
 
Time complexity
Time complexityTime complexity
Time complexity
 
Time and Space Complexity
Time and Space ComplexityTime and Space Complexity
Time and Space Complexity
 
DESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSDESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMS
 
Complexity analysis in Algorithms
Complexity analysis in AlgorithmsComplexity analysis in Algorithms
Complexity analysis in Algorithms
 
Propositional logic
Propositional logicPropositional logic
Propositional logic
 
Knowledge representation in AI
Knowledge representation in AIKnowledge representation in AI
Knowledge representation in AI
 
First order logic
First order logicFirst order logic
First order logic
 
Design and analysis of algorithms
Design and analysis of algorithmsDesign and analysis of algorithms
Design and analysis of algorithms
 
Pattern matching
Pattern matchingPattern matching
Pattern matching
 
What is knowledge representation and reasoning ?
What is knowledge representation and reasoning ?What is knowledge representation and reasoning ?
What is knowledge representation and reasoning ?
 
Prolog Programming Language
Prolog Programming  LanguageProlog Programming  Language
Prolog Programming Language
 
Asymptotic Notation and Complexity
Asymptotic Notation and ComplexityAsymptotic Notation and Complexity
Asymptotic Notation and Complexity
 
Knowledge representation
Knowledge representationKnowledge representation
Knowledge representation
 
Algorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms IAlgorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms I
 
Informed search
Informed searchInformed search
Informed search
 
Knowledge Representation & Reasoning
Knowledge Representation & ReasoningKnowledge Representation & Reasoning
Knowledge Representation & Reasoning
 

Similar to Prolog Programming : Basics

Prolog,Prolog Programming IN AI.pdf
Prolog,Prolog Programming IN AI.pdfProlog,Prolog Programming IN AI.pdf
Prolog,Prolog Programming IN AI.pdf
CS With Logic
 
Prolog final
Prolog finalProlog final
Prolog final
Hassaan Ahmad
 
UOS-BSIT-3811-Artificial-Intelligence-Introduction-to-prolog-PDF.pptx
UOS-BSIT-3811-Artificial-Intelligence-Introduction-to-prolog-PDF.pptxUOS-BSIT-3811-Artificial-Intelligence-Introduction-to-prolog-PDF.pptx
UOS-BSIT-3811-Artificial-Intelligence-Introduction-to-prolog-PDF.pptx
qasim ali
 
Ai lab manual
Ai lab manualAi lab manual
Ai lab manual
Shipra Swati
 
Ics1019 ics5003
Ics1019 ics5003Ics1019 ics5003
Ics1019 ics5003
Matt Montebello
 
ICS1019.pdf
ICS1019.pdfICS1019.pdf
ICS1019.pdf
Matt Montebello
 
An introduction to Prolog language slide
An introduction to Prolog language slideAn introduction to Prolog language slide
An introduction to Prolog language slide
2021uam4641
 
Prolog fundamentals for beeginers in windows.ppt
Prolog  fundamentals for beeginers in windows.pptProlog  fundamentals for beeginers in windows.ppt
Prolog fundamentals for beeginers in windows.ppt
DrBhagirathPrajapati
 
Logic programming (1)
Logic programming (1)Logic programming (1)
Logic programming (1)Nitesh Singh
 
MACHINE LEARNING-LEARNING RULE
MACHINE LEARNING-LEARNING RULEMACHINE LEARNING-LEARNING RULE
MACHINE LEARNING-LEARNING RULE
DrBindhuM
 
continuity of module 2.pptx
continuity of module 2.pptxcontinuity of module 2.pptx
continuity of module 2.pptx
AnkitaVerma776806
 
Prolog (present)
Prolog (present) Prolog (present)
Prolog (present) Melody Joey
 
AI Lab Manual.docx
AI Lab Manual.docxAI Lab Manual.docx
AI Lab Manual.docx
KPRevathiAsstprofITD
 
Ics1019 ics5003
Ics1019 ics5003Ics1019 ics5003
Ics1019 ics5003
Matt Montebello
 
Plc part 4
Plc  part 4Plc  part 4
Plc part 4
Taymoor Nazmy
 
ARTIFICIAL INTELLIGENCE---UNIT 4.pptx
ARTIFICIAL INTELLIGENCE---UNIT 4.pptxARTIFICIAL INTELLIGENCE---UNIT 4.pptx
ARTIFICIAL INTELLIGENCE---UNIT 4.pptx
RuchitaMaaran
 
Tutorial - Introduction to Rule Technologies and Systems
Tutorial - Introduction to Rule Technologies and SystemsTutorial - Introduction to Rule Technologies and Systems
Tutorial - Introduction to Rule Technologies and Systems
Adrian Paschke
 
Introduction to prolog
Introduction to prologIntroduction to prolog
Introduction to prolog
Rakhi Sinha
 

Similar to Prolog Programming : Basics (20)

Prolog,Prolog Programming IN AI.pdf
Prolog,Prolog Programming IN AI.pdfProlog,Prolog Programming IN AI.pdf
Prolog,Prolog Programming IN AI.pdf
 
Prolog final
Prolog finalProlog final
Prolog final
 
UOS-BSIT-3811-Artificial-Intelligence-Introduction-to-prolog-PDF.pptx
UOS-BSIT-3811-Artificial-Intelligence-Introduction-to-prolog-PDF.pptxUOS-BSIT-3811-Artificial-Intelligence-Introduction-to-prolog-PDF.pptx
UOS-BSIT-3811-Artificial-Intelligence-Introduction-to-prolog-PDF.pptx
 
Ai lab manual
Ai lab manualAi lab manual
Ai lab manual
 
Ics1019 ics5003
Ics1019 ics5003Ics1019 ics5003
Ics1019 ics5003
 
ICS1019.pdf
ICS1019.pdfICS1019.pdf
ICS1019.pdf
 
An introduction to Prolog language slide
An introduction to Prolog language slideAn introduction to Prolog language slide
An introduction to Prolog language slide
 
Prolog fundamentals for beeginers in windows.ppt
Prolog  fundamentals for beeginers in windows.pptProlog  fundamentals for beeginers in windows.ppt
Prolog fundamentals for beeginers in windows.ppt
 
Logic programming (1)
Logic programming (1)Logic programming (1)
Logic programming (1)
 
01bkb04p.ppt
01bkb04p.ppt01bkb04p.ppt
01bkb04p.ppt
 
MACHINE LEARNING-LEARNING RULE
MACHINE LEARNING-LEARNING RULEMACHINE LEARNING-LEARNING RULE
MACHINE LEARNING-LEARNING RULE
 
Chaps 1-3-ai-prolog
Chaps 1-3-ai-prologChaps 1-3-ai-prolog
Chaps 1-3-ai-prolog
 
continuity of module 2.pptx
continuity of module 2.pptxcontinuity of module 2.pptx
continuity of module 2.pptx
 
Prolog (present)
Prolog (present) Prolog (present)
Prolog (present)
 
AI Lab Manual.docx
AI Lab Manual.docxAI Lab Manual.docx
AI Lab Manual.docx
 
Ics1019 ics5003
Ics1019 ics5003Ics1019 ics5003
Ics1019 ics5003
 
Plc part 4
Plc  part 4Plc  part 4
Plc part 4
 
ARTIFICIAL INTELLIGENCE---UNIT 4.pptx
ARTIFICIAL INTELLIGENCE---UNIT 4.pptxARTIFICIAL INTELLIGENCE---UNIT 4.pptx
ARTIFICIAL INTELLIGENCE---UNIT 4.pptx
 
Tutorial - Introduction to Rule Technologies and Systems
Tutorial - Introduction to Rule Technologies and SystemsTutorial - Introduction to Rule Technologies and Systems
Tutorial - Introduction to Rule Technologies and Systems
 
Introduction to prolog
Introduction to prologIntroduction to prolog
Introduction to prolog
 

Recently uploaded

Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 

Recently uploaded (20)

Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 

Prolog Programming : Basics

  • 2. What is Prolog?  Prolog stands for programming in logic (PROgrammation en LOgique).  Prolog is the most widely used language to have been inspired by logic programming research.  Prolog is the only successful example of the family of logic programming languages.  A Prolog program is a theory written in a subset of first-order logic, called Horn clause logic.  Prolog is declarative. A Prolog programmer concentrates on what the program needs to do, not on how to do it.
  • 3. A Little History  Prolog was invented by Alain Colmerauer, a professor of computer science at the university of Aix-Marseille in France, in 1972.  The first application of Prolog was in natural language processing.  Its theoretical underpinning are due to Donald Loveland of Duke university through Robert Kowalski (formerly) of the university of Edinburgh
  • 4. Main Advantages  Ease of representing knowledge.  Natural support of pattern-matching.  Natural support of meta-programming.  Meaning of programs is independent of how they are executed.  Simple connection between programs and computed answers and specifications.  No need to distinguish programs from databases.
  • 5. Anatomy of Prolog Program  Prolog programs are made up of facts and rules.  A fact asserts some property of an object, or relation between two or more objects. e.g. parent(jane,alan). Can be read as “Jane is the parent of Alan.”  Rules allow us to infer that a property or relationship holds based on preconditions. e.g. parent(X,Y) :- mother(X,Y). = “Person X is the parent of person Y if X is Y‟s mother.”
  • 6. Predicate Definitions  Both facts and rules are predicate definitions.  ‘Predicate’is the name given to the word occurring before the bracket in a fact or rule: parent (jane,alan).  By defining a predicate you are specifying which information needs to be known for the property denoted by the predicate to be true. Predicate name
  • 7. Clauses  Predicate definitions consist of clauses. = An individual definition (whether it be a fact or rule). e.g. mother(jane, alan). = Fact parent(P1,P2):- mother(P1,P2). = Rule  A clause consists of a head  And sometimes a body. -- Facts don‟t have a body because they are always true. head body
  • 8. Arguments  A predicate head consists of a predicate name and sometimes some arguments contained within brackets and separated by commas. mother(jane, alan).  A body can be made up of any number of subgoals (calls to other predicates) and terms.  Arguments also consist of terms, which can be: -- Constants e.g. jane, -- Variables e.g. Person1, or -- Compound terms Predicate name Arguments
  • 9. Terms: Constants Constants can either be:  Numbers:  integers are the usual form (e.g. 1, 0, -1, etc), but  floating-point numbers can also be used (e.g. 3.0E7)  Symbolic constants:  always start with a lower case alphabetic character and contain any mixture of letters, digits, and underscores (but no spaces, punctuation, or an initial capital).  e.g. abc, big_long_constant, x4_3t.  String constants:  are anything between single quotes e.g. „Like this‟.
  • 10. Terms: Variables  Variables always start with an upper case alphabetic character or an underscore.  Other than the first character they can be made up of any mixture of letters, digits, and underscores. e.g. X, ABC, _89two5, _very_long_variable  There are no “types” for variables (or constants) – a variable can take any value.  All Prolog variables have a “local” scope: --- they only keep the same value within a clause; the same variable used outside of a clause does not inherit the value (this would be a “global” scope).
  • 11. Naming Tips  Use real English when naming predicates, constants, and variables. e.g. “John wants to help Somebody.” Could be: wants(john, to_help, Somebody). Not: x87g(j,_789).  Use a Verb Subject Object structure: wants(john, to_help).  BUT do not assume Prolog Understands the meaning of your chosen names! -- You create meaning by specifying the body (i.e. preconditions) of a clause.
  • 12. Using Predicate Definitions Command line programming is tedious e.g. | ?- write(„What is your name?‟), nl, read(X), write(„Hello „), write(X). We can define predicates to automate commands: | ?- greetings. What is your name? |: tim. Hello tim X = tim ? yes Prolog Code Terminal greetings:- write(‘What is your name?’), nl, read(X), write(‘Hello ‘), write(X).
  • 13. Running prolog program on windows After SWI-Prolog has been installed on a Windows system, the following important new things are available to the user:  A folder (called directory in the remainder of this document) called swipl containing the executable, libraries, etc., of the system. No files are installed outside this directory.  A program swipl-win.exe, providing a window for interaction with Prolog.  The program swipl.exe is a version of SWI-Prolog that runs in a console window.  The file extension .p1 is associated with the program swipl-win.exe.  Opening a .p1 file will cause swipl-win.exe to start, change directory to the directory in which the file to open resides, and load this file.
  • 14. Executing a query After loading a program, one can ask Prolog queries about the program. ?- likes (sam, x) . X = dahl ; X = tandoori ; …… X = chips ; ?-
  • 15. Prolog Execution Most Prolog clauses have both a declarative reading and a procedural reading. Whenever possible, the declarative reading is to be preferred. mother (X, Y) :- parent (X, Y), female (X) . Declarative reading: x is the mother of y if x is parent of y and x is female
  • 16. Prolog Execution Procedural reading : To show that x is the mother of y, first show that x is a parent of y, then show that x is female. Clauses: parent (john, bill) . parent (jane, bill) . female(jane) . Query: | ?- mother (M, bill) .
  • 17. Prolog Execution  The clause of mother /2 will be located, and the unification X=M, Y=bill will occur.  Then parent (M, bill) will be attempted, resulting in the unification M=john.  Next, female (john) will be attempted, but will fail.  Prolog will backtrack to parent (M, bill) and look for another solution for this; it will succeed and unify M=jane.  Finally, it will attempt female (jane), and succeed; so the inquiry will succeed, having performed the unification M=jane.