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

PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...Umesh Kumar
 
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure Janki Shah
 
Fragmentation and types of fragmentation in Distributed Database
Fragmentation and types of fragmentation in Distributed DatabaseFragmentation and types of fragmentation in Distributed Database
Fragmentation and types of fragmentation in Distributed DatabaseAbhilasha Lahigude
 
queue & its applications
queue & its applicationsqueue & its applications
queue & its applicationssomendra kumar
 
Three Address code
Three Address code Three Address code
Three Address code Pooja Dixit
 
Priority queue in DSA
Priority queue in DSAPriority queue in DSA
Priority queue in DSAjunnubabu
 
Code optimization in compiler design
Code optimization in compiler designCode optimization in compiler design
Code optimization in compiler designKuppusamy P
 
Parsing in Compiler Design
Parsing in Compiler DesignParsing in Compiler Design
Parsing in Compiler DesignAkhil Kaushik
 
Threaded Binary Tree
Threaded Binary TreeThreaded Binary Tree
Threaded Binary Treekhabbab_h
 
Set data structure
Set data structure Set data structure
Set data structure Tech_MX
 
Ppl for students unit 1,2 and 3
Ppl for students unit 1,2 and 3Ppl for students unit 1,2 and 3
Ppl for students unit 1,2 and 3Akshay Nagpurkar
 
Lecture 14 run time environment
Lecture 14 run time environmentLecture 14 run time environment
Lecture 14 run time environmentIffat Anjum
 
Array data structure
Array data structureArray data structure
Array data structuremaamir farooq
 
Algorithm Complexity and Main Concepts
Algorithm Complexity and Main ConceptsAlgorithm Complexity and Main Concepts
Algorithm Complexity and Main ConceptsAdelina Ahadova
 
Bottom - Up Parsing
Bottom - Up ParsingBottom - Up Parsing
Bottom - Up Parsingkunj desai
 

What's hot (20)

Stacks and Queue - Data Structures
Stacks and Queue - Data StructuresStacks and Queue - Data Structures
Stacks and Queue - Data Structures
 
Abstract Data Types
Abstract Data TypesAbstract Data Types
Abstract Data Types
 
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
 
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure
 
Fragmentation and types of fragmentation in Distributed Database
Fragmentation and types of fragmentation in Distributed DatabaseFragmentation and types of fragmentation in Distributed Database
Fragmentation and types of fragmentation in Distributed Database
 
queue & its applications
queue & its applicationsqueue & its applications
queue & its applications
 
Three Address code
Three Address code Three Address code
Three Address code
 
Priority queue in DSA
Priority queue in DSAPriority queue in DSA
Priority queue in DSA
 
Code optimization in compiler design
Code optimization in compiler designCode optimization in compiler design
Code optimization in compiler design
 
Recovery techniques
Recovery techniquesRecovery techniques
Recovery techniques
 
Parsing in Compiler Design
Parsing in Compiler DesignParsing in Compiler Design
Parsing in Compiler Design
 
Threaded Binary Tree
Threaded Binary TreeThreaded Binary Tree
Threaded Binary Tree
 
Set data structure
Set data structure Set data structure
Set data structure
 
Ppl for students unit 1,2 and 3
Ppl for students unit 1,2 and 3Ppl for students unit 1,2 and 3
Ppl for students unit 1,2 and 3
 
Time andspacecomplexity
Time andspacecomplexityTime andspacecomplexity
Time andspacecomplexity
 
Tree in data structure
Tree in data structureTree in data structure
Tree in data structure
 
Lecture 14 run time environment
Lecture 14 run time environmentLecture 14 run time environment
Lecture 14 run time environment
 
Array data structure
Array data structureArray data structure
Array data structure
 
Algorithm Complexity and Main Concepts
Algorithm Complexity and Main ConceptsAlgorithm Complexity and Main Concepts
Algorithm Complexity and Main Concepts
 
Bottom - Up Parsing
Bottom - Up ParsingBottom - Up Parsing
Bottom - Up Parsing
 

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
 
Prolog Programming : Basics
Prolog Programming : BasicsProlog Programming : Basics
Prolog Programming : BasicsMitul Desai
 
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
 

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
 
PROLOG: Introduction To Prolog
PROLOG: Introduction To PrologPROLOG: Introduction To Prolog
PROLOG: Introduction To Prolog
 
Prolog Programming : Basics
Prolog Programming : BasicsProlog Programming : Basics
Prolog Programming : Basics
 
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
 
Ai lab manual
Ai lab manualAi lab manual
Ai lab manual
 
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
 

Recently uploaded

Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 

Recently uploaded (20)

Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 

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).