SlideShare a Scribd company logo
1 of 21
Download to read offline
Prolog Programming
Introduction
Prolog
Prolog is a logic programming language. It
has important role in artificial intelligence.
Unlike many other programming languages,
Prolog is intended primarily as a declarative
programming language. In prolog, logic is
expressed as relations (called as Facts and
Rules). Core heart of prolog lies at
the logic being applied. Formulation or
Computation is carried out by running a
query over these relations.
4
Prolog
Prolog program is simply based on predicate
logic known as Horn clause. In prolog, we
compose the program using facts and rules and
we pose a query on query prompt about the
facts and rules we inserted.
5
Prolog Programming Basics
Horn Clause : Horn clause consists of head (left hand
side) and body (right hand side). Head can have 0 or 1
predicate and body can have list of predicates. That
means LHS has only single literal and RHS can have
more than one literals.
head:- body.
What is Prolog?
» Prolog or PROgramming in LOGics is a logical and
declarative programming language. It is one major example
of the fifth 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.
6
Programming languages are of two kinds:
Procedural (BASIC, Fortran, C++, Pascal,
Java);
Declarative (LISP, Prolog, ML).
In procedural programming, we tell the
computer how to solve a problem.
In declarative programming, we tell the
computer what problem we want solved.
SWI-Prolog offers a comprehensive free Prolog
environment. Since its start in 1987, SWI-Prolog
development has been driven by the needs of real
world applications. SWI-Prolog is widely used in
research and education as well as commercial
applications.
Prolog was originally designed to be an AI language,
and it is very well suited for expert systems, planning
systems and similar AI applications.
Logic Programming: Prolog
SWI - Prolog
The logic programming language PROLOG (Programmation en Logique)
was conceived by Alain Colmerauer at the University of Aix-Marseille,
France, where the language was first implemented in 1973. PROLOG was
further developed by the logician Robert Kowalski, a member of the AI group
at the University of Edinburgh.
8
Machine
Logical Programming
Machine
Answer
Int main()
{
Procedure 1 ()
Procedure 2 ()
return
}
Knowledge
Base Queries
Functional Programming
Prolog Interpreter
Facts & Rules
Rules are extinctions of facts
that contain conditional
clauses. To satisfy a rule
these conditions should be
met.
Rules
And to run a prolog
program, we need some
questions, and those
questions can be answered
by the given facts and rules
Questions
Facts are statements
that describe object
properties or relations
between objects.
The fact is predicate that
is true, for example, if we
say, “Tom is the son of
Jack”, then this is a fact.
Facts
Prolog language basically has three different elements −
Facts Rules Queries
Prolog Syntax
The syntax of Prolog is as follows:
relationship(object1,object2)
Prolog
» Example:
» “Arslan owns the book”
» Owns (arslan, book) relationship(object1, object2)
» The relationship has a specific order, arslan own the
book, but the book dose not owns arslan, and this
relationship and its representation above called fact.
11
English Predicate Calculus Prolog
If → :-
Not ~ Not
Or V ;
and ^ ,
female, Male, X, Y, mother_of, _father, Pro34
Variable is a string. The string can be a combination of lower case or
upper case letters. The string can also contain underscore characters
that begin with an underscore or an upper-case letter. Rules for
forming names and predicate calculus are the same.
Using the following truth-functional symbols, the Prolog
expressions are comprised. These symbols have the same
interpretation as in the predicate calculus.
Symbols
Variables
13
A fact is like a predicate expression. It is used to provide a declarative statement about the
problem. In a Prolog expression, when a variable occurs, it is assumed to be universally
quantified. Facts are specified in the form of the head. Head is known as the clause head. It will
take in the same way as the goal entered at the prompt by the user.
Facts
cat(momo). /* momo is a cat */
dog(pulu). /* pulu is a dog */
likes(arslan, jolie). /* Arslan likes Jolie*/
not(likes(Jolie, pasta)). /* Jolie does not like pasta */
For example:
Queries In Prolog, the query is the action of asking the program about the information which is available
within its database. When a Prolog program is loaded, we will get the query prompt,
?- 'It is sunny'. yes
?-
?- 'It is cold'.
no
?-
no
?-
?- ’momo is cat'. yes
?-
?- ’momo is dog'.
Rules extend the logic program capabilities. Rules are used
to provide the decision-making process in Prolog. Rules are
specified in the form:
head:- t1, t2, t3,….., tk. Where k>=1
The head is known as the clause of the head.
:- is known as the clause neck. It
is read as 'if'. The body of the
clause is specified by t1, t2, t3,…,
tk. It contains one or more
components, and it can be
separated using the commas. A
rule will read as 'head is true if
t1, t2, t3,…., tk are all true'.
Rules
In the following program, first two lines indicate the facts and last two lines indicate the rules:
dog(pulu). large(pulu).
cat(momo). large(momo).
large_animal(A) :- dog(A),large(A).
large_animal(C) :- cat(C),large(C).
The above rules mean that 'large_animal(A) is true if dog(A) is true, and large(A) is true, etc.'
The last line means that 'large_animal(C) is true if cat(C) is true, and large(C) is true.
Facts and Rules make up
the knowledge base.
likes(tarzan, jane).
likes(jane, tarzan).
likes(terk, jane).
facts
Arguments / objects / items
.dot is necessary to end the statement
relation
friends(X,Y):- likes(X,Y), likes(Y,X).
Predicate name
head body
variables
Horn Clause
Example
elephant(george).
elephant(mary).
elephant(X) :- grey(X), mammal(X), hasTrunk(X).
Procedure for elephant
Predicate
Clauses
Rule
Facts
?- elephant(george).
yes
?- elephant(jane).
no
Queries
Replies
Queries
Rules
facts
Example 1 : Below food table shows the facts, rules, goals and their English meanings.
Queries / Goals
?- food(pizza). // Is pizza a food?
?- meal(X), lunch(X). // Which food is meal and lunch?
?- dinner(sandwich). // Is sandwich a dinner?
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
Rule
meal(X) :- food(X).
// Every food is a meal OR
Anything is a meal if it is a food
Queries
Rules
facts
Example 2 : Below student-professor relation table shows the facts, rules, goals and their English meanings.
.
Facts English meanings
studies(charlie, csc135). // charlie studies csc135
studies(olivia, csc135). // olivia studies csc135
studies(jack, csc131). // jack studies csc131
studies(arthur, csc134).
likes('John', car(bmw))
// arthur studies csc134
// Read as : john likes bmw car
gives(john, chocolate, jane). // Read as : john gives chocolate to jane
Rules
professor(X, Y) :-
teaches(X, C), studies(Y, C).
// X is a professor of Y if X teaches
C and Y studies C.
Queries / Goals
?- studies(charlie, What).
// charlie studies what? OR
What does charlie study?
?- professor(kirke, Students).
// Who are the students of
professor kirke.
19
Lists and Sequence in Prolog
In Prolog, the list builder uses brackets[...]. A list is referred by the
notation [A | B] in which, A is the first element, and whose tail is B.
The following example shows the three definitions, where the first
element of the list is refereed by the 'car', the tail of the list is referred
by 'cdr', list constructor is referred by the 'cons'.
car([A | B], A).
cdr([A | B], B).
cons[A, B, [A | S]).
Where,
•A is the head(car) of [A | B].
•B is the tail(car) of [A | B].
•Put A at the head and B as the tail constructs the list [A | S].
The predicate 'member/2' definition is described as follows:
member(A, [A | S]).
member(A, [B | S]) :- member(A, S).
The clauses can be read as follows:
•A is a list member whose first element is A.
•A is a list member whose tail is S if A is a member of S.
The looping facility is contained in most of the programming
languages. Looping is used to enable a set of instructions to
be repeatedly executed either a fixed number of times or
until a given condition met. Prolog has no looping facility,
but we can obtain a similar effect. Using this effect, we can
evaluate a sequence of goals repeatedly. In various ways,
this can be done like built-in predicates, recursion,
backtracking, or a combination of these.
In the above example, we define the loop predicate in
terms of itself. The second clause read as 'to loop from N,
first write the N's value, then subtract one to provide S,
then loop from M'. This process will terminate using
the first clause: 'when the argument is 0, then stop or do
nothing'. Here the first clause is called as terminated
condition.
Looping a fixed number of times
To execute the instruction a fixed number of times, many
programming languages provide 'for loop'. In Prolog, there
is no such facility available directly, but using recursion, we
can obtain a similar effect, which is shown in the following
programs:
Loops in Prolog
Example 1:
This program outputs the integer value from a specified
value down to 1.
loop(0).
loop(N) :- N>0, write('value of N is: '), write(N), nl.
S is N-1, loop(S).
?- loop(4).
value of N is: 4
value of N is: 3
value of N is: 2
value of N is: 1
yes
Here are some simple clauses.
The following queries yield the specified answers.
How do you add the following facts?
likes(mary,food).
likes(mary,juice).
likes(john,juice).
likes(john,mary).
| ?- likes(mary,food).
yes.
| ?- likes(john,juice).
yes.
| ?- likes(john,food).
no.
John likes anything that Mary likes
John likes anyone who likes juice
John likes anyone who likes themselves
Example 3 :
Some Applications of Prolog
Prolog is used in various
domains. It plays a vital role in
automation system. Following
are some other important
fields where Prolog is used −
Prolog is used in various
domains. It plays a vital role in
automation system. Following
are some other important
fields where Prolog is used −
• Intelligent Database Retrieval
• Natural Language Understanding
• Specification Language
• Machine Learning
• Robot Planning
• Automation System
• Problem Solving
• Expert Systems
What is
Prolog used
for
Good at
▪ Grammars and Language processing,
▪ Knowledge representation and reasoning,
▪ Unification,
▪ Pattern matching,
▪ Planning and Search.
i.e. Prolog is good at Symbolic AI.
?
23
Advantages :
1. Easy to build database. Doesn’t
need a lot of programming effort
2. Pattern matching is easy.
Search is recursion based
.3. It has built in list handling.
Makes it easier to play with
any algorithm involving lists.
2. Sometimes input and output is
not easy.
Disadvantages :
1. LISP (another logic
programming language)
dominates over prolog with
respect to I/O features
3. Repetitive number crunching,
Representing complex data
structures,
Input/output (interfaces).

More Related Content

What's hot

First order predicate logic (fopl)
First order predicate logic (fopl)First order predicate logic (fopl)
First order predicate logic (fopl)chauhankapil
 
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 IMohamed Loey
 
AI_Session 7 Greedy Best first search algorithm.pptx
AI_Session 7 Greedy Best first search algorithm.pptxAI_Session 7 Greedy Best first search algorithm.pptx
AI_Session 7 Greedy Best first search algorithm.pptxAsst.prof M.Gokilavani
 
Introduction on Prolog - Programming in Logic
Introduction on Prolog - Programming in LogicIntroduction on Prolog - Programming in Logic
Introduction on Prolog - Programming in LogicVishal Tandel
 
Minimization of Boolean Functions
Minimization of Boolean FunctionsMinimization of Boolean Functions
Minimization of Boolean Functionsblaircomp2003
 
Algorithms Lecture 7: Graph Algorithms
Algorithms Lecture 7: Graph AlgorithmsAlgorithms Lecture 7: Graph Algorithms
Algorithms Lecture 7: Graph AlgorithmsMohamed Loey
 
I. Mini-Max Algorithm in AI
I. Mini-Max Algorithm in AII. Mini-Max Algorithm in AI
I. Mini-Max Algorithm in AIvikas dhakane
 
Boyre Moore Algorithm | Computer Science
Boyre Moore Algorithm | Computer ScienceBoyre Moore Algorithm | Computer Science
Boyre Moore Algorithm | Computer ScienceTransweb Global Inc
 
Searching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And AlgorithmSearching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And Algorithm03446940736
 
Knowledge representation in AI
Knowledge representation in AIKnowledge representation in AI
Knowledge representation in AIVishal Singh
 
Ch 7 Knowledge Representation.pdf
Ch 7 Knowledge Representation.pdfCh 7 Knowledge Representation.pdf
Ch 7 Knowledge Representation.pdfKrishnaMadala1
 
The role of the parser and Error recovery strategies ppt in compiler design
The role of the parser and Error recovery strategies ppt in compiler designThe role of the parser and Error recovery strategies ppt in compiler design
The role of the parser and Error recovery strategies ppt in compiler designSadia Akter
 
Artificial Intelligence Notes Unit 4
Artificial Intelligence Notes Unit 4Artificial Intelligence Notes Unit 4
Artificial Intelligence Notes Unit 4DigiGurukul
 

What's hot (20)

First order predicate logic (fopl)
First order predicate logic (fopl)First order predicate logic (fopl)
First order predicate logic (fopl)
 
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
 
AI_Session 7 Greedy Best first search algorithm.pptx
AI_Session 7 Greedy Best first search algorithm.pptxAI_Session 7 Greedy Best first search algorithm.pptx
AI_Session 7 Greedy Best first search algorithm.pptx
 
Eliza
ElizaEliza
Eliza
 
Introduction on Prolog - Programming in Logic
Introduction on Prolog - Programming in LogicIntroduction on Prolog - Programming in Logic
Introduction on Prolog - Programming in Logic
 
Minimization of Boolean Functions
Minimization of Boolean FunctionsMinimization of Boolean Functions
Minimization of Boolean Functions
 
Algorithms Lecture 7: Graph Algorithms
Algorithms Lecture 7: Graph AlgorithmsAlgorithms Lecture 7: Graph Algorithms
Algorithms Lecture 7: Graph Algorithms
 
I. Mini-Max Algorithm in AI
I. Mini-Max Algorithm in AII. Mini-Max Algorithm in AI
I. Mini-Max Algorithm in AI
 
Daa unit 1
Daa unit 1Daa unit 1
Daa unit 1
 
Ai lab manual
Ai lab manualAi lab manual
Ai lab manual
 
Informed search
Informed searchInformed search
Informed search
 
Prolog basics
Prolog basicsProlog basics
Prolog basics
 
PROLOG: Introduction To Prolog
PROLOG: Introduction To PrologPROLOG: Introduction To Prolog
PROLOG: Introduction To Prolog
 
Boyre Moore Algorithm | Computer Science
Boyre Moore Algorithm | Computer ScienceBoyre Moore Algorithm | Computer Science
Boyre Moore Algorithm | Computer Science
 
Searching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And AlgorithmSearching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And Algorithm
 
Knowledge representation in AI
Knowledge representation in AIKnowledge representation in AI
Knowledge representation in AI
 
Ch 7 Knowledge Representation.pdf
Ch 7 Knowledge Representation.pdfCh 7 Knowledge Representation.pdf
Ch 7 Knowledge Representation.pdf
 
The role of the parser and Error recovery strategies ppt in compiler design
The role of the parser and Error recovery strategies ppt in compiler designThe role of the parser and Error recovery strategies ppt in compiler design
The role of the parser and Error recovery strategies ppt in compiler design
 
AI: AI & Problem Solving
AI: AI & Problem SolvingAI: AI & Problem Solving
AI: AI & Problem Solving
 
Artificial Intelligence Notes Unit 4
Artificial Intelligence Notes Unit 4Artificial Intelligence Notes Unit 4
Artificial Intelligence Notes Unit 4
 

Similar to Prolog,Prolog Programming IN AI.pdf

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.pptxqasim ali
 
An introduction to Prolog language slide
An introduction to Prolog language slideAn introduction to Prolog language slide
An introduction to Prolog language slide2021uam4641
 
Introduction to prolog
Introduction to prologIntroduction to prolog
Introduction to prologRakhi Sinha
 
Logic Progamming in Perl
Logic Progamming in PerlLogic Progamming in Perl
Logic Progamming in PerlCurtis Poe
 
________ ________1.ppt
________ ________1.ppt________ ________1.ppt
________ ________1.pptSamiAAli44
 
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 SystemsAdrian Paschke
 
Introduction to Prolog
Introduction to Prolog Introduction to Prolog
Introduction to Prolog Showkot Usman
 
Artificial Intelligence and Expert System
Artificial Intelligence and Expert System Artificial Intelligence and Expert System
Artificial Intelligence and Expert System Showkot Usman
 
MACHINE LEARNING-LEARNING RULE
MACHINE LEARNING-LEARNING RULEMACHINE LEARNING-LEARNING RULE
MACHINE LEARNING-LEARNING RULEDrBindhuM
 
Prolog (present)
Prolog (present) Prolog (present)
Prolog (present) Melody Joey
 
Predicate logic_2(Artificial Intelligence)
Predicate logic_2(Artificial Intelligence)Predicate logic_2(Artificial Intelligence)
Predicate logic_2(Artificial Intelligence)SHUBHAM KUMAR GUPTA
 
Knowledege Representation.pptx
Knowledege Representation.pptxKnowledege Representation.pptx
Knowledege Representation.pptxArslanAliArslanAli
 

Similar to Prolog,Prolog Programming IN AI.pdf (20)

ICS1019.pdf
ICS1019.pdfICS1019.pdf
ICS1019.pdf
 
Ics1019 ics5003
Ics1019 ics5003Ics1019 ics5003
Ics1019 ics5003
 
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
 
An introduction to Prolog language slide
An introduction to Prolog language slideAn introduction to Prolog language slide
An introduction to Prolog language slide
 
AI Lab Manual.docx
AI Lab Manual.docxAI Lab Manual.docx
AI Lab Manual.docx
 
Prolog final
Prolog finalProlog final
Prolog final
 
Ics1019 ics5003
Ics1019 ics5003Ics1019 ics5003
Ics1019 ics5003
 
Introduction to prolog
Introduction to prologIntroduction to prolog
Introduction to prolog
 
Logic Progamming in Perl
Logic Progamming in PerlLogic Progamming in Perl
Logic Progamming in Perl
 
________ ________1.ppt
________ ________1.ppt________ ________1.ppt
________ ________1.ppt
 
Python ppt_118.pptx
Python ppt_118.pptxPython ppt_118.pptx
Python ppt_118.pptx
 
Turbo prolog 2.0 basics
Turbo prolog 2.0 basicsTurbo prolog 2.0 basics
Turbo prolog 2.0 basics
 
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 Prolog Introduction to Prolog
Introduction to Prolog
 
Artificial Intelligence and Expert System
Artificial Intelligence and Expert System Artificial Intelligence and Expert System
Artificial Intelligence and Expert System
 
MACHINE LEARNING-LEARNING RULE
MACHINE LEARNING-LEARNING RULEMACHINE LEARNING-LEARNING RULE
MACHINE LEARNING-LEARNING RULE
 
Introduction to programming languages part 2
Introduction to programming languages   part 2Introduction to programming languages   part 2
Introduction to programming languages part 2
 
Prolog (present)
Prolog (present) Prolog (present)
Prolog (present)
 
Predicate logic_2(Artificial Intelligence)
Predicate logic_2(Artificial Intelligence)Predicate logic_2(Artificial Intelligence)
Predicate logic_2(Artificial Intelligence)
 
Knowledege Representation.pptx
Knowledege Representation.pptxKnowledege Representation.pptx
Knowledege Representation.pptx
 

Recently uploaded

APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 

Recently uploaded (20)

APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 

Prolog,Prolog Programming IN AI.pdf

  • 2. Introduction Prolog Prolog is a logic programming language. It has important role in artificial intelligence. Unlike many other programming languages, Prolog is intended primarily as a declarative programming language. In prolog, logic is expressed as relations (called as Facts and Rules). Core heart of prolog lies at the logic being applied. Formulation or Computation is carried out by running a query over these relations. 4 Prolog
  • 3. Prolog program is simply based on predicate logic known as Horn clause. In prolog, we compose the program using facts and rules and we pose a query on query prompt about the facts and rules we inserted. 5 Prolog Programming Basics Horn Clause : Horn clause consists of head (left hand side) and body (right hand side). Head can have 0 or 1 predicate and body can have list of predicates. That means LHS has only single literal and RHS can have more than one literals. head:- body.
  • 4. What is Prolog? » Prolog or PROgramming in LOGics is a logical and declarative programming language. It is one major example of the fifth 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. 6
  • 5. Programming languages are of two kinds: Procedural (BASIC, Fortran, C++, Pascal, Java); Declarative (LISP, Prolog, ML). In procedural programming, we tell the computer how to solve a problem. In declarative programming, we tell the computer what problem we want solved. SWI-Prolog offers a comprehensive free Prolog environment. Since its start in 1987, SWI-Prolog development has been driven by the needs of real world applications. SWI-Prolog is widely used in research and education as well as commercial applications. Prolog was originally designed to be an AI language, and it is very well suited for expert systems, planning systems and similar AI applications. Logic Programming: Prolog SWI - Prolog The logic programming language PROLOG (Programmation en Logique) was conceived by Alain Colmerauer at the University of Aix-Marseille, France, where the language was first implemented in 1973. PROLOG was further developed by the logician Robert Kowalski, a member of the AI group at the University of Edinburgh.
  • 6. 8 Machine Logical Programming Machine Answer Int main() { Procedure 1 () Procedure 2 () return } Knowledge Base Queries Functional Programming Prolog Interpreter Facts & Rules
  • 7. Rules are extinctions of facts that contain conditional clauses. To satisfy a rule these conditions should be met. Rules And to run a prolog program, we need some questions, and those questions can be answered by the given facts and rules Questions Facts are statements that describe object properties or relations between objects. The fact is predicate that is true, for example, if we say, “Tom is the son of Jack”, then this is a fact. Facts Prolog language basically has three different elements − Facts Rules Queries
  • 8. Prolog Syntax The syntax of Prolog is as follows: relationship(object1,object2)
  • 9. Prolog » Example: » “Arslan owns the book” » Owns (arslan, book) relationship(object1, object2) » The relationship has a specific order, arslan own the book, but the book dose not owns arslan, and this relationship and its representation above called fact. 11
  • 10. English Predicate Calculus Prolog If → :- Not ~ Not Or V ; and ^ , female, Male, X, Y, mother_of, _father, Pro34 Variable is a string. The string can be a combination of lower case or upper case letters. The string can also contain underscore characters that begin with an underscore or an upper-case letter. Rules for forming names and predicate calculus are the same. Using the following truth-functional symbols, the Prolog expressions are comprised. These symbols have the same interpretation as in the predicate calculus. Symbols Variables
  • 11. 13 A fact is like a predicate expression. It is used to provide a declarative statement about the problem. In a Prolog expression, when a variable occurs, it is assumed to be universally quantified. Facts are specified in the form of the head. Head is known as the clause head. It will take in the same way as the goal entered at the prompt by the user. Facts cat(momo). /* momo is a cat */ dog(pulu). /* pulu is a dog */ likes(arslan, jolie). /* Arslan likes Jolie*/ not(likes(Jolie, pasta)). /* Jolie does not like pasta */ For example: Queries In Prolog, the query is the action of asking the program about the information which is available within its database. When a Prolog program is loaded, we will get the query prompt, ?- 'It is sunny'. yes ?- ?- 'It is cold'. no ?- no ?- ?- ’momo is cat'. yes ?- ?- ’momo is dog'.
  • 12. Rules extend the logic program capabilities. Rules are used to provide the decision-making process in Prolog. Rules are specified in the form: head:- t1, t2, t3,….., tk. Where k>=1 The head is known as the clause of the head. :- is known as the clause neck. It is read as 'if'. The body of the clause is specified by t1, t2, t3,…, tk. It contains one or more components, and it can be separated using the commas. A rule will read as 'head is true if t1, t2, t3,…., tk are all true'. Rules In the following program, first two lines indicate the facts and last two lines indicate the rules: dog(pulu). large(pulu). cat(momo). large(momo). large_animal(A) :- dog(A),large(A). large_animal(C) :- cat(C),large(C). The above rules mean that 'large_animal(A) is true if dog(A) is true, and large(A) is true, etc.' The last line means that 'large_animal(C) is true if cat(C) is true, and large(C) is true. Facts and Rules make up the knowledge base.
  • 13. likes(tarzan, jane). likes(jane, tarzan). likes(terk, jane). facts Arguments / objects / items .dot is necessary to end the statement relation friends(X,Y):- likes(X,Y), likes(Y,X). Predicate name head body variables Horn Clause
  • 14. Example elephant(george). elephant(mary). elephant(X) :- grey(X), mammal(X), hasTrunk(X). Procedure for elephant Predicate Clauses Rule Facts ?- elephant(george). yes ?- elephant(jane). no Queries Replies
  • 15. Queries Rules facts Example 1 : Below food table shows the facts, rules, goals and their English meanings. Queries / Goals ?- food(pizza). // Is pizza a food? ?- meal(X), lunch(X). // Which food is meal and lunch? ?- dinner(sandwich). // Is sandwich a dinner? 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 Rule meal(X) :- food(X). // Every food is a meal OR Anything is a meal if it is a food
  • 16. Queries Rules facts Example 2 : Below student-professor relation table shows the facts, rules, goals and their English meanings. . Facts English meanings studies(charlie, csc135). // charlie studies csc135 studies(olivia, csc135). // olivia studies csc135 studies(jack, csc131). // jack studies csc131 studies(arthur, csc134). likes('John', car(bmw)) // arthur studies csc134 // Read as : john likes bmw car gives(john, chocolate, jane). // Read as : john gives chocolate to jane Rules professor(X, Y) :- teaches(X, C), studies(Y, C). // X is a professor of Y if X teaches C and Y studies C. Queries / Goals ?- studies(charlie, What). // charlie studies what? OR What does charlie study? ?- professor(kirke, Students). // Who are the students of professor kirke.
  • 17. 19 Lists and Sequence in Prolog In Prolog, the list builder uses brackets[...]. A list is referred by the notation [A | B] in which, A is the first element, and whose tail is B. The following example shows the three definitions, where the first element of the list is refereed by the 'car', the tail of the list is referred by 'cdr', list constructor is referred by the 'cons'. car([A | B], A). cdr([A | B], B). cons[A, B, [A | S]). Where, •A is the head(car) of [A | B]. •B is the tail(car) of [A | B]. •Put A at the head and B as the tail constructs the list [A | S]. The predicate 'member/2' definition is described as follows: member(A, [A | S]). member(A, [B | S]) :- member(A, S). The clauses can be read as follows: •A is a list member whose first element is A. •A is a list member whose tail is S if A is a member of S.
  • 18. The looping facility is contained in most of the programming languages. Looping is used to enable a set of instructions to be repeatedly executed either a fixed number of times or until a given condition met. Prolog has no looping facility, but we can obtain a similar effect. Using this effect, we can evaluate a sequence of goals repeatedly. In various ways, this can be done like built-in predicates, recursion, backtracking, or a combination of these. In the above example, we define the loop predicate in terms of itself. The second clause read as 'to loop from N, first write the N's value, then subtract one to provide S, then loop from M'. This process will terminate using the first clause: 'when the argument is 0, then stop or do nothing'. Here the first clause is called as terminated condition. Looping a fixed number of times To execute the instruction a fixed number of times, many programming languages provide 'for loop'. In Prolog, there is no such facility available directly, but using recursion, we can obtain a similar effect, which is shown in the following programs: Loops in Prolog Example 1: This program outputs the integer value from a specified value down to 1. loop(0). loop(N) :- N>0, write('value of N is: '), write(N), nl. S is N-1, loop(S). ?- loop(4). value of N is: 4 value of N is: 3 value of N is: 2 value of N is: 1 yes
  • 19. Here are some simple clauses. The following queries yield the specified answers. How do you add the following facts? likes(mary,food). likes(mary,juice). likes(john,juice). likes(john,mary). | ?- likes(mary,food). yes. | ?- likes(john,juice). yes. | ?- likes(john,food). no. John likes anything that Mary likes John likes anyone who likes juice John likes anyone who likes themselves Example 3 :
  • 20. Some Applications of Prolog Prolog is used in various domains. It plays a vital role in automation system. Following are some other important fields where Prolog is used − Prolog is used in various domains. It plays a vital role in automation system. Following are some other important fields where Prolog is used − • Intelligent Database Retrieval • Natural Language Understanding • Specification Language • Machine Learning • Robot Planning • Automation System • Problem Solving • Expert Systems What is Prolog used for Good at ▪ Grammars and Language processing, ▪ Knowledge representation and reasoning, ▪ Unification, ▪ Pattern matching, ▪ Planning and Search. i.e. Prolog is good at Symbolic AI. ?
  • 21. 23 Advantages : 1. Easy to build database. Doesn’t need a lot of programming effort 2. Pattern matching is easy. Search is recursion based .3. It has built in list handling. Makes it easier to play with any algorithm involving lists. 2. Sometimes input and output is not easy. Disadvantages : 1. LISP (another logic programming language) dominates over prolog with respect to I/O features 3. Repetitive number crunching, Representing complex data structures, Input/output (interfaces).