SlideShare a Scribd company logo
1 of 29
PROLOG
PROgramming in LOGic
A Brief Introduction
Compilers
• PDC Visual Prolog
• SWI Prolog
• Bin-Prolog
• K-Prolog
• Prolog ++
http://swish.swi-prolog.org
PRO-LOG
• Programming in Logic
• 1975, Phillippe Roussell
• Predicate Calculus
• Declarative Language
• Predicates and Rules
• Inference Mechanism
PROLOG Paradigm
• PROgramming in LOGic
– Draw inferences from facts and rules
• PROLOG is
– declarative - specify facts and logical relationships
• Non-procedural: "what", not "how". (we specify the problem but not
the solution)
• Database language with automated search and the ability to follow
general rules.
– symbolic - symbols are used to represent objects
– high level - contains a built-in problem solving mechanism
• PROLOG Programming (When we program in ProLog we
need to provide following three things)
– Declaring some facts about objects and their relationships
– Defining some rules about objects and their relationships
– Asking questions about objects and their relationships
PROLOG Paradigm
• The PROLOG Programmer
– Loads facts and rules into the database.
– Makes queries to the database to see if a fact is:
• in the database or
• can be implied from the facts and rules therein
Prolog Database
Facts + Rules
Query
System Interaction
Problem solving in PROLOG
– 1. insert facts and rules into the database
– 2. ask questions (queries) based on the contents of the database
• Facts
– Used to represent unchanging information about objects and their
relationships.
– Only facts in the PROLOG database can be used for problem solving.
– Insert facts into the database by,
• typing the facts into a file and loading (consulting) the file into a running
PROLOG system
System Interaction
• Queries
– Retrieve information from the database by entering QUERIES
– A query,
• is a pattern that PROLOG is asked to match against the database
• has the syntax of a compound query
• may contain variables
– A query will cause PROLOG to
• look at the database
• try to find a match for the query pattern
• execute the body of the matching head
• return an answer
• Logic Programming
• Logic programming is a form of declarative programming
• A program is a collection of axioms
– Each axiom is a Horn clause of the form:
H :- B1, B2, ..., Bn.
where H is the head term and Bi are the body terms
– Meaning H is true if all Bi are true
Basic Proof technique - modus ponens
A -> B
A
---------
B
• Prolog Uses backward chaining
– More efficient than forward chaining for larger
collections of axioms
• Applications: expert systems, artificial
intelligence, natural language understanding,
logical puzzles and games
PROLOG Paradigm
Examples (Facts)
English PROLOG
“A dog is a mammal” isa(dog, mammal).
“A sparrow is a bird” isa(sparrow, bird).
PROLOG Paradigm
Examples (Rules)
English PROLOG
“Something is an animal animal(X) :- isa(X,mammal).
if it is a mammal or a bird” animal(X) :- isa(X, bird).
PROLOG Paradigm
Examples (Queries)
English PROLOG
“is a sparrow an animal?” ?- animal(sparrow).
answer: “yes” yes
“is a table an animal?” ?- animal(table).
answer: “no” no
“what is a dog?” ?- isa(dog, X).
answer: “a mammal” X = mammal
PROLOG syntax
• Constants
– Atoms
• Alphanumeric atoms - alphabetic character sequence starting with
a lower case letter
Examples: apple a1 apple_cart
• Quoted atoms “String” - sequence of characters surrounded by
single quotes
Examples: ‘Apple’ ‘hello world’
• Symbolic atoms - sequence of symbolic characters
Examples: & < > * - + >>
• Special atoms
Examples: ! ; [ ] {}
– Numbers
• Integers and Floating Point numbers
Examples: 0 1 9821 -10 1.3 -1.3E102
PROLOG syntax
• Variable Names
a sequence of alphanumeric characters beginning with an
upper case letter or an underscore
Examples: Anything _var X _
• Compound Terms (structures)
– an atom followed by an argument list containing terms.
The arguments are enclosed within brackets and separated
by commas
Example: isa(dog, mammal)
Prolog syntax
• The names of all relationships and objects must
begin with a lower case letter. For example studies,
ali, programming
• The relationship is written first and the objects are
enclosed within parentheses and are written
separated by commas. For example studies(ali,
programming)
• The full stop character ‘.’ must come at the end of a
fact.
• Order is arbitrary but it should be consistent
Example
 Program with three facts and one
rule:
rainy(columbo).
rainy(ayubia).
cold(ayubia).
Rule: snowy(X) :- rainy(X), cold(X).
 Query and response:
?- snowy(ayubia).
yes
 Query and response:
?- snowy(columbo).
no
 Query and response:
?- snowy(lahore).
No
• ?- snowy(C).
C = ayubia
– because rainy(ayubia) and
cold(ayubia) are sub-goals
that are both true facts in the
database
– snowy(X) with X=columbo is a
goal that fails, because cold(X)
fails, triggering backtracking
snowy(C)
snowy(X)
AND
rainy(X) cold(X)
C = X
rainy(columbo) rainy(ayubia)
X = columbo X = ayubia
cold(ayubia)
C = X = ayubia
C = ayubia
rainy(columbo).
rainy(ayubia).
cold(ayubia).
snowy(X) :- rainy(X), cold(X).
?- snowy(C).
C = ayubia
OR
Logic Representation : Propositional
Calculus
• Propositional Logic
– Boolean statements
– Logic connectives     
Example – a family
Atomic statements
p: Ahmed is father of Belal
q: Ahmed is brother of Aslam
r : Aslam is uncle of Belal
Complex statements 
Statement Logic
p Ahmed is not father of
Belal
p  q Ahmed is father of Belal or
Ahmed is brother of Aslam
p  q  r If Ahmed is father of Belal
and brother of Aslam then
Aslam is uncle of Belal
Prolog Programming
Predicate Calculus
• Predicates (Facts)
– man(Ahmed)
– father(Ahmed, Belal)
– brother(Belal, Chand)
– brother(Chand, Delawar)
– owns(Belal, car)
– tall(Belal)
– hates(Ahmed, Chand)
– family()
• Formulae
– X,Y,Z(man(X)  man(Y)  father(Z,Y)  father(Z,X) 
brother(X,Y))
• Variables
– X, Y and Z
• Constants
– Ahmed, Belal, Chand, Delawar and car
Prolog code
Predicates
man(symbol)
father(symbol, symbol)
brother(symbol, symbol)
owns(symbol, symbol)
tall(symbol)
hates(symbol, symbol)
family()
Clauses
man(ahmed).
father(ahmed, belal).
brother(ahmed, chand).
owns(belal, car).
tall(belal).
hates(ahmed, chand).
family().
Rule:
brother(X,Y):-
man(X),
man(Y),
father(Z,Y),
father(Z,X).
Goal
brother(ahmed,belal).
Sections of Prolog Program (1-3)
• Predicates
– Declarations of Relations or Rules
– Just like function prototype (declaration).
– Zero or more arguments
– Example
Predicates
man(symbol)
family()
a_new_predicate (integer, char)
Sections of Prolog Program (2-3)
• Clauses
– Definition(s) of Predicate = Sentence OR Phrase
– Types
• Rules (function definitions)
– 0 or more conditions (statements)
• Facts
– 0 conditions
– All parameters constant
– Examples
• Fact
brother(ahmed, chand).
• Rule
brother(X,Y):-
man(X),
man(Y),
father(Z,Y),
father(Z,X).
Sections of Prolog Program (3-3)
• Goal
– Goal of inference
– Only and exactly one instance
– The only tentative section of the program
– The main() of prolog
– Goal truth value = output of program
– Syntactically and Semantically just another clause
• Empty, simple (one goal), or compound (sub-goals)
– Examples
• Goal
brother(X,chand). <or> brother(ahmed,chand).
• Goal
brother(X,chand),
father().
Sample Program Update
domains
person = symbol
predicates
nondeterm father(person,person)
nondeterm brother(person,person)
nondeterm cousin(person,person)
nondeterm grandfather(person,person)
clauses
father(a,b).
father(a,c).
father(a,d).
father(b,e).
father(b,f).
father(b,g).
father(c,h).
father(c,i).
father(d,j).
father(d,k).
brother(X,Y):-
X<>Y,
father(Z,X),
father(Z,Y).
cousin(X,Y):-
father(A,X),
father(B,Y),
brother(A,B).
grandfather(X,Y):-
father(Z,Y),
father(X,Z).
goal
cousin(X,Y).
Prolog Variables
• Constant placeholders (NOT variables)
– Bounded once
• Loosely typed
• Start with Capital letter or underscore
• Examples
– brother(ahmed, Ahmed)
– brother(ahmed, _x)
– Brother(ahmed, X)
• Anonymous variable
– The _
– Some value that isn’t required
– Example
brother(ahmed, _)
Expert system
• A simple medical expert system
• relieves(Drug, Symptom).
– relieves(aspirin, headache).
– relieves(aspirin, moderate_pain).
– relieves(aspirin, moderate_arthritis).
– relieves(aspirin_codine_combination, severe_pain).
– relieves(cough_cure, cough).
– relieves(pain_gone, severe_pain).
– relieves(anti_diarrhea, diarrhea).
– relieves(de_congest, cough).
– relieves(de_congest, nasal_congestion).
– relieves(penicilline, pneumonia).
– relieves(bis_cure, diarrhea).
– relieves(bis_cure, nausea).
– relieves(new_med, headache).
– relieves(new_med, moderate_pain).
– relieves(cong_plus, nasal_congestion).
• aggravates(Drug, Condition).
– aggravates(aspirin, asthma).
– aggravates(aspirin, peptic_ulcer).
– aggravates(anti-diarrhea, fever).
– aggravates(de_congest, high_blood_pressure).
– aggravates(de_congest, heart_disease).
– aggravates(de_congest, diabetes).
– aggravates(de_congest, glaucoma).
– aggravates(penicilline, asthma).
– aggravates(de_congest, high_blood_pressure).
– aggravates(bis_cure, diabetes).
– aggravates(bis_cure, fever).
should_take(Person, Drug) :-
complains_of(Person, Symptom),
relieves(Drug, Symptom),
not(unsuitable_for(Person, Drug)). //conjunction of three classes.
unsuitable_for(Person, Drug) :-
aggravates(Drug, Condition),
suffers_from(Person, Condition).
complains_of(ali, headache).
suffers_from(ali, peptic_ulcer).
?- should_take(ali, Drug).
Drug = new_med;
Books
• Prolog Programming for AI by Ivan Bratko
• Visual Prolog; Language Tutorial by PDC

More Related Content

What's hot

AI 7 | Constraint Satisfaction Problem
AI 7 | Constraint Satisfaction ProblemAI 7 | Constraint Satisfaction Problem
AI 7 | Constraint Satisfaction ProblemMohammad Imam Hossain
 
Knowledge representation and Predicate logic
Knowledge representation and Predicate logicKnowledge representation and Predicate logic
Knowledge representation and Predicate logicAmey Kerkar
 
Knowledge representation In Artificial Intelligence
Knowledge representation In Artificial IntelligenceKnowledge representation In Artificial Intelligence
Knowledge representation In Artificial IntelligenceRamla Sheikh
 
Unification and Lifting
Unification and LiftingUnification and Lifting
Unification and LiftingMegha Sharma
 
Artificial Intelligence Notes Unit 2
Artificial Intelligence Notes Unit 2Artificial Intelligence Notes Unit 2
Artificial Intelligence Notes Unit 2DigiGurukul
 
Artificial Intelligence Notes Unit 1
Artificial Intelligence Notes Unit 1 Artificial Intelligence Notes Unit 1
Artificial Intelligence Notes Unit 1 DigiGurukul
 
knowledge representation using rules
knowledge representation using rulesknowledge representation using rules
knowledge representation using rulesHarini Balamurugan
 
First order predicate logic (fopl)
First order predicate logic (fopl)First order predicate logic (fopl)
First order predicate logic (fopl)chauhankapil
 
First Order Logic resolution
First Order Logic resolutionFirst Order Logic resolution
First Order Logic resolutionAmar Jukuntla
 
Propositional logic
Propositional logicPropositional logic
Propositional logicRushdi Shams
 
Artificial intelligence- Logic Agents
Artificial intelligence- Logic AgentsArtificial intelligence- Logic Agents
Artificial intelligence- Logic AgentsNuruzzaman Milon
 
Design and analysis of algorithms
Design and analysis of algorithmsDesign and analysis of algorithms
Design and analysis of algorithmsDr Geetha Mohan
 
Knowledge representation in AI
Knowledge representation in AIKnowledge representation in AI
Knowledge representation in AIVishal Singh
 
Knowledge Representation in Artificial intelligence
Knowledge Representation in Artificial intelligence Knowledge Representation in Artificial intelligence
Knowledge Representation in Artificial intelligence Yasir Khan
 
Artificial Intelligence Searching Techniques
Artificial Intelligence Searching TechniquesArtificial Intelligence Searching Techniques
Artificial Intelligence Searching TechniquesDr. C.V. Suresh Babu
 
Ch 7 Knowledge Representation.pdf
Ch 7 Knowledge Representation.pdfCh 7 Knowledge Representation.pdf
Ch 7 Knowledge Representation.pdfKrishnaMadala1
 
Learning set of rules
Learning set of rulesLearning set of rules
Learning set of rulesswapnac12
 

What's hot (20)

Frames
FramesFrames
Frames
 
AI 7 | Constraint Satisfaction Problem
AI 7 | Constraint Satisfaction ProblemAI 7 | Constraint Satisfaction Problem
AI 7 | Constraint Satisfaction Problem
 
Knowledge representation and Predicate logic
Knowledge representation and Predicate logicKnowledge representation and Predicate logic
Knowledge representation and Predicate logic
 
Knowledge representation In Artificial Intelligence
Knowledge representation In Artificial IntelligenceKnowledge representation In Artificial Intelligence
Knowledge representation In Artificial Intelligence
 
Unification and Lifting
Unification and LiftingUnification and Lifting
Unification and Lifting
 
Predicate logic
 Predicate logic Predicate logic
Predicate logic
 
AI: Learning in AI
AI: Learning in AI AI: Learning in AI
AI: Learning in AI
 
Artificial Intelligence Notes Unit 2
Artificial Intelligence Notes Unit 2Artificial Intelligence Notes Unit 2
Artificial Intelligence Notes Unit 2
 
Artificial Intelligence Notes Unit 1
Artificial Intelligence Notes Unit 1 Artificial Intelligence Notes Unit 1
Artificial Intelligence Notes Unit 1
 
knowledge representation using rules
knowledge representation using rulesknowledge representation using rules
knowledge representation using rules
 
First order predicate logic (fopl)
First order predicate logic (fopl)First order predicate logic (fopl)
First order predicate logic (fopl)
 
First Order Logic resolution
First Order Logic resolutionFirst Order Logic resolution
First Order Logic resolution
 
Propositional logic
Propositional logicPropositional logic
Propositional logic
 
Artificial intelligence- Logic Agents
Artificial intelligence- Logic AgentsArtificial intelligence- Logic Agents
Artificial intelligence- Logic Agents
 
Design and analysis of algorithms
Design and analysis of algorithmsDesign and analysis of algorithms
Design and analysis of algorithms
 
Knowledge representation in AI
Knowledge representation in AIKnowledge representation in AI
Knowledge representation in AI
 
Knowledge Representation in Artificial intelligence
Knowledge Representation in Artificial intelligence Knowledge Representation in Artificial intelligence
Knowledge Representation in Artificial intelligence
 
Artificial Intelligence Searching Techniques
Artificial Intelligence Searching TechniquesArtificial Intelligence Searching Techniques
Artificial Intelligence Searching Techniques
 
Ch 7 Knowledge Representation.pdf
Ch 7 Knowledge Representation.pdfCh 7 Knowledge Representation.pdf
Ch 7 Knowledge Representation.pdf
 
Learning set of rules
Learning set of rulesLearning set of rules
Learning set of rules
 

Viewers also liked

Artificial intelligence Prolog Language
Artificial intelligence Prolog LanguageArtificial intelligence Prolog Language
Artificial intelligence Prolog LanguageREHMAT ULLAH
 
Introduction on Prolog - Programming in Logic
Introduction on Prolog - Programming in LogicIntroduction on Prolog - Programming in Logic
Introduction on Prolog - Programming in LogicVishal Tandel
 
Prolog Code [Family Tree] by Shahzeb Pirzada
Prolog Code [Family Tree] by Shahzeb PirzadaProlog Code [Family Tree] by Shahzeb Pirzada
Prolog Code [Family Tree] by Shahzeb PirzadaShahzeb Pirzada
 
PROLOG: Recursion And Lists In Prolog
PROLOG: Recursion And Lists In PrologPROLOG: Recursion And Lists In Prolog
PROLOG: Recursion And Lists In PrologDataminingTools Inc
 
PROLOG: Cuts And Negation In Prolog
PROLOG: Cuts And Negation In PrologPROLOG: Cuts And Negation In Prolog
PROLOG: Cuts And Negation In PrologDataminingTools Inc
 
Prolog: Arithmetic Operations In Prolog
Prolog: Arithmetic Operations In PrologProlog: Arithmetic Operations In Prolog
Prolog: Arithmetic Operations In PrologPROLOG CONTENT
 
Prolog programming
Prolog programmingProlog programming
Prolog programmingHarry Potter
 
PROLOG: Fact Roles And Queries In Prolog
PROLOG: Fact Roles And Queries In PrologPROLOG: Fact Roles And Queries In Prolog
PROLOG: Fact Roles And Queries In PrologPROLOG CONTENT
 
Expert Systems & Prolog
Expert Systems & PrologExpert Systems & Prolog
Expert Systems & PrologFatih Karatana
 
Combining Data Mining and Ontology Engineering to enrich Ontologies and Linke...
Combining Data Mining and Ontology Engineering to enrich Ontologies and Linke...Combining Data Mining and Ontology Engineering to enrich Ontologies and Linke...
Combining Data Mining and Ontology Engineering to enrich Ontologies and Linke...Mathieu d'Aquin
 
Hubot and Playbook - Oct 2016 ChatbotsAU meetup
Hubot and Playbook - Oct 2016 ChatbotsAU meetupHubot and Playbook - Oct 2016 ChatbotsAU meetup
Hubot and Playbook - Oct 2016 ChatbotsAU meetupTim Kinnane
 
12 quelques prédicats prédéfinis de swi
12  quelques prédicats prédéfinis de swi12  quelques prédicats prédéfinis de swi
12 quelques prédicats prédéfinis de swiSiham Rim Boudaoud
 
Introduccion a prolog
Introduccion a prologIntroduccion a prolog
Introduccion a prologJeffoG92
 

Viewers also liked (20)

Artificial intelligence Prolog Language
Artificial intelligence Prolog LanguageArtificial intelligence Prolog Language
Artificial intelligence Prolog Language
 
Introduction on Prolog - Programming in Logic
Introduction on Prolog - Programming in LogicIntroduction on Prolog - Programming in Logic
Introduction on Prolog - Programming in Logic
 
Prolog Code [Family Tree] by Shahzeb Pirzada
Prolog Code [Family Tree] by Shahzeb PirzadaProlog Code [Family Tree] by Shahzeb Pirzada
Prolog Code [Family Tree] by Shahzeb Pirzada
 
Prolog 7-Languages
Prolog 7-LanguagesProlog 7-Languages
Prolog 7-Languages
 
PROLOG: Recursion And Lists In Prolog
PROLOG: Recursion And Lists In PrologPROLOG: Recursion And Lists In Prolog
PROLOG: Recursion And Lists In Prolog
 
Prolog & lisp
Prolog & lispProlog & lisp
Prolog & lisp
 
PROLOG: Cuts And Negation In Prolog
PROLOG: Cuts And Negation In PrologPROLOG: Cuts And Negation In Prolog
PROLOG: Cuts And Negation In Prolog
 
Prolog: Arithmetic Operations In Prolog
Prolog: Arithmetic Operations In PrologProlog: Arithmetic Operations In Prolog
Prolog: Arithmetic Operations In Prolog
 
Prolog programming
Prolog programmingProlog programming
Prolog programming
 
PROLOG: Fact Roles And Queries In Prolog
PROLOG: Fact Roles And Queries In PrologPROLOG: Fact Roles And Queries In Prolog
PROLOG: Fact Roles And Queries In Prolog
 
Logic Programming and ILP
Logic Programming and ILPLogic Programming and ILP
Logic Programming and ILP
 
Expert Systems & Prolog
Expert Systems & PrologExpert Systems & Prolog
Expert Systems & Prolog
 
Combining Data Mining and Ontology Engineering to enrich Ontologies and Linke...
Combining Data Mining and Ontology Engineering to enrich Ontologies and Linke...Combining Data Mining and Ontology Engineering to enrich Ontologies and Linke...
Combining Data Mining and Ontology Engineering to enrich Ontologies and Linke...
 
Social Media Marketing Strategies for PR , Journalism Workshop in Bangalore....
Social Media Marketing Strategies for PR , Journalism  Workshop in Bangalore....Social Media Marketing Strategies for PR , Journalism  Workshop in Bangalore....
Social Media Marketing Strategies for PR , Journalism Workshop in Bangalore....
 
Hubot and Playbook - Oct 2016 ChatbotsAU meetup
Hubot and Playbook - Oct 2016 ChatbotsAU meetupHubot and Playbook - Oct 2016 ChatbotsAU meetup
Hubot and Playbook - Oct 2016 ChatbotsAU meetup
 
5
55
5
 
12 quelques prédicats prédéfinis de swi
12  quelques prédicats prédéfinis de swi12  quelques prédicats prédéfinis de swi
12 quelques prédicats prédéfinis de swi
 
Jean Rohmer
Jean RohmerJean Rohmer
Jean Rohmer
 
Introduccion a prolog
Introduccion a prologIntroduccion a prolog
Introduccion a prolog
 
Ch10 Recursion
Ch10 RecursionCh10 Recursion
Ch10 Recursion
 

Similar to ProLog (Artificial Intelligence) Introduction

10 logic+programming+with+prolog
10 logic+programming+with+prolog10 logic+programming+with+prolog
10 logic+programming+with+prologbaran19901990
 
Challenge@RuleML2015 Datalog+, RuleML and OWL 2 - Formats and Translations f...
Challenge@RuleML2015  Datalog+, RuleML and OWL 2 - Formats and Translations f...Challenge@RuleML2015  Datalog+, RuleML and OWL 2 - Formats and Translations f...
Challenge@RuleML2015 Datalog+, RuleML and OWL 2 - Formats and Translations f...RuleML
 
Logic programming (1)
Logic programming (1)Logic programming (1)
Logic programming (1)Nitesh Singh
 
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
 
app4.pptx
app4.pptxapp4.pptx
app4.pptxsg4795
 
Chaps 1-3-ai-prolog
Chaps 1-3-ai-prologChaps 1-3-ai-prolog
Chaps 1-3-ai-prologsaru40
 
#8 formal methods – pro logic
#8 formal methods – pro logic#8 formal methods – pro logic
#8 formal methods – pro logicSharif Omar Salem
 
Jarrar: ORM in Description Logic
Jarrar: ORM in Description Logic  Jarrar: ORM in Description Logic
Jarrar: ORM in Description Logic Mustafa Jarrar
 
predicateLogic.ppt
predicateLogic.pptpredicateLogic.ppt
predicateLogic.pptMUZAMILALI48
 
Prolog,Prolog Programming IN AI.pdf
Prolog,Prolog Programming IN AI.pdfProlog,Prolog Programming IN AI.pdf
Prolog,Prolog Programming IN AI.pdfCS With Logic
 

Similar to ProLog (Artificial Intelligence) Introduction (20)

10 logic+programming+with+prolog
10 logic+programming+with+prolog10 logic+programming+with+prolog
10 logic+programming+with+prolog
 
Challenge@RuleML2015 Datalog+, RuleML and OWL 2 - Formats and Translations f...
Challenge@RuleML2015  Datalog+, RuleML and OWL 2 - Formats and Translations f...Challenge@RuleML2015  Datalog+, RuleML and OWL 2 - Formats and Translations f...
Challenge@RuleML2015 Datalog+, RuleML and OWL 2 - Formats and Translations f...
 
Prolog final
Prolog finalProlog final
Prolog final
 
Logic programming (1)
Logic programming (1)Logic programming (1)
Logic programming (1)
 
Plc part 4
Plc  part 4Plc  part 4
Plc part 4
 
Chaps 1-3-ai-prolog
Chaps 1-3-ai-prologChaps 1-3-ai-prolog
Chaps 1-3-ai-prolog
 
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
 
Prolog2 (1)
Prolog2 (1)Prolog2 (1)
Prolog2 (1)
 
Prolog
PrologProlog
Prolog
 
Pl vol1
Pl vol1Pl vol1
Pl vol1
 
Pl vol1
Pl vol1Pl vol1
Pl vol1
 
app4.pptx
app4.pptxapp4.pptx
app4.pptx
 
Chaps 1-3-ai-prolog
Chaps 1-3-ai-prologChaps 1-3-ai-prolog
Chaps 1-3-ai-prolog
 
#8 formal methods – pro logic
#8 formal methods – pro logic#8 formal methods – pro logic
#8 formal methods – pro logic
 
Jarrar: ORM in Description Logic
Jarrar: ORM in Description Logic  Jarrar: ORM in Description Logic
Jarrar: ORM in Description Logic
 
predicateLogic.ppt
predicateLogic.pptpredicateLogic.ppt
predicateLogic.ppt
 
AI-09 Logic in AI
AI-09 Logic in AIAI-09 Logic in AI
AI-09 Logic in AI
 
tutorial.ppt
tutorial.ppttutorial.ppt
tutorial.ppt
 
Regular Expressions
Regular ExpressionsRegular Expressions
Regular Expressions
 
Prolog,Prolog Programming IN AI.pdf
Prolog,Prolog Programming IN AI.pdfProlog,Prolog Programming IN AI.pdf
Prolog,Prolog Programming IN AI.pdf
 

Recently uploaded

DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 

Recently uploaded (20)

DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 

ProLog (Artificial Intelligence) Introduction

  • 1. PROLOG PROgramming in LOGic A Brief Introduction
  • 2. Compilers • PDC Visual Prolog • SWI Prolog • Bin-Prolog • K-Prolog • Prolog ++ http://swish.swi-prolog.org
  • 3. PRO-LOG • Programming in Logic • 1975, Phillippe Roussell • Predicate Calculus • Declarative Language • Predicates and Rules • Inference Mechanism
  • 4. PROLOG Paradigm • PROgramming in LOGic – Draw inferences from facts and rules • PROLOG is – declarative - specify facts and logical relationships • Non-procedural: "what", not "how". (we specify the problem but not the solution) • Database language with automated search and the ability to follow general rules. – symbolic - symbols are used to represent objects – high level - contains a built-in problem solving mechanism • PROLOG Programming (When we program in ProLog we need to provide following three things) – Declaring some facts about objects and their relationships – Defining some rules about objects and their relationships – Asking questions about objects and their relationships
  • 5. PROLOG Paradigm • The PROLOG Programmer – Loads facts and rules into the database. – Makes queries to the database to see if a fact is: • in the database or • can be implied from the facts and rules therein Prolog Database Facts + Rules Query
  • 6. System Interaction Problem solving in PROLOG – 1. insert facts and rules into the database – 2. ask questions (queries) based on the contents of the database • Facts – Used to represent unchanging information about objects and their relationships. – Only facts in the PROLOG database can be used for problem solving. – Insert facts into the database by, • typing the facts into a file and loading (consulting) the file into a running PROLOG system
  • 7. System Interaction • Queries – Retrieve information from the database by entering QUERIES – A query, • is a pattern that PROLOG is asked to match against the database • has the syntax of a compound query • may contain variables – A query will cause PROLOG to • look at the database • try to find a match for the query pattern • execute the body of the matching head • return an answer
  • 8. • Logic Programming • Logic programming is a form of declarative programming • A program is a collection of axioms – Each axiom is a Horn clause of the form: H :- B1, B2, ..., Bn. where H is the head term and Bi are the body terms – Meaning H is true if all Bi are true
  • 9. Basic Proof technique - modus ponens A -> B A --------- B
  • 10. • Prolog Uses backward chaining – More efficient than forward chaining for larger collections of axioms • Applications: expert systems, artificial intelligence, natural language understanding, logical puzzles and games
  • 11. PROLOG Paradigm Examples (Facts) English PROLOG “A dog is a mammal” isa(dog, mammal). “A sparrow is a bird” isa(sparrow, bird).
  • 12. PROLOG Paradigm Examples (Rules) English PROLOG “Something is an animal animal(X) :- isa(X,mammal). if it is a mammal or a bird” animal(X) :- isa(X, bird).
  • 13. PROLOG Paradigm Examples (Queries) English PROLOG “is a sparrow an animal?” ?- animal(sparrow). answer: “yes” yes “is a table an animal?” ?- animal(table). answer: “no” no “what is a dog?” ?- isa(dog, X). answer: “a mammal” X = mammal
  • 14. PROLOG syntax • Constants – Atoms • Alphanumeric atoms - alphabetic character sequence starting with a lower case letter Examples: apple a1 apple_cart • Quoted atoms “String” - sequence of characters surrounded by single quotes Examples: ‘Apple’ ‘hello world’ • Symbolic atoms - sequence of symbolic characters Examples: & < > * - + >> • Special atoms Examples: ! ; [ ] {} – Numbers • Integers and Floating Point numbers Examples: 0 1 9821 -10 1.3 -1.3E102
  • 15. PROLOG syntax • Variable Names a sequence of alphanumeric characters beginning with an upper case letter or an underscore Examples: Anything _var X _ • Compound Terms (structures) – an atom followed by an argument list containing terms. The arguments are enclosed within brackets and separated by commas Example: isa(dog, mammal)
  • 16. Prolog syntax • The names of all relationships and objects must begin with a lower case letter. For example studies, ali, programming • The relationship is written first and the objects are enclosed within parentheses and are written separated by commas. For example studies(ali, programming) • The full stop character ‘.’ must come at the end of a fact. • Order is arbitrary but it should be consistent
  • 17. Example  Program with three facts and one rule: rainy(columbo). rainy(ayubia). cold(ayubia). Rule: snowy(X) :- rainy(X), cold(X).  Query and response: ?- snowy(ayubia). yes  Query and response: ?- snowy(columbo). no  Query and response: ?- snowy(lahore). No • ?- snowy(C). C = ayubia – because rainy(ayubia) and cold(ayubia) are sub-goals that are both true facts in the database – snowy(X) with X=columbo is a goal that fails, because cold(X) fails, triggering backtracking
  • 18. snowy(C) snowy(X) AND rainy(X) cold(X) C = X rainy(columbo) rainy(ayubia) X = columbo X = ayubia cold(ayubia) C = X = ayubia C = ayubia rainy(columbo). rainy(ayubia). cold(ayubia). snowy(X) :- rainy(X), cold(X). ?- snowy(C). C = ayubia OR
  • 19. Logic Representation : Propositional Calculus • Propositional Logic – Boolean statements – Logic connectives      Example – a family Atomic statements p: Ahmed is father of Belal q: Ahmed is brother of Aslam r : Aslam is uncle of Belal Complex statements  Statement Logic p Ahmed is not father of Belal p  q Ahmed is father of Belal or Ahmed is brother of Aslam p  q  r If Ahmed is father of Belal and brother of Aslam then Aslam is uncle of Belal
  • 20. Prolog Programming Predicate Calculus • Predicates (Facts) – man(Ahmed) – father(Ahmed, Belal) – brother(Belal, Chand) – brother(Chand, Delawar) – owns(Belal, car) – tall(Belal) – hates(Ahmed, Chand) – family() • Formulae – X,Y,Z(man(X)  man(Y)  father(Z,Y)  father(Z,X)  brother(X,Y)) • Variables – X, Y and Z • Constants – Ahmed, Belal, Chand, Delawar and car Prolog code Predicates man(symbol) father(symbol, symbol) brother(symbol, symbol) owns(symbol, symbol) tall(symbol) hates(symbol, symbol) family() Clauses man(ahmed). father(ahmed, belal). brother(ahmed, chand). owns(belal, car). tall(belal). hates(ahmed, chand). family(). Rule: brother(X,Y):- man(X), man(Y), father(Z,Y), father(Z,X). Goal brother(ahmed,belal).
  • 21. Sections of Prolog Program (1-3) • Predicates – Declarations of Relations or Rules – Just like function prototype (declaration). – Zero or more arguments – Example Predicates man(symbol) family() a_new_predicate (integer, char)
  • 22. Sections of Prolog Program (2-3) • Clauses – Definition(s) of Predicate = Sentence OR Phrase – Types • Rules (function definitions) – 0 or more conditions (statements) • Facts – 0 conditions – All parameters constant – Examples • Fact brother(ahmed, chand). • Rule brother(X,Y):- man(X), man(Y), father(Z,Y), father(Z,X).
  • 23. Sections of Prolog Program (3-3) • Goal – Goal of inference – Only and exactly one instance – The only tentative section of the program – The main() of prolog – Goal truth value = output of program – Syntactically and Semantically just another clause • Empty, simple (one goal), or compound (sub-goals) – Examples • Goal brother(X,chand). <or> brother(ahmed,chand). • Goal brother(X,chand), father().
  • 24. Sample Program Update domains person = symbol predicates nondeterm father(person,person) nondeterm brother(person,person) nondeterm cousin(person,person) nondeterm grandfather(person,person) clauses father(a,b). father(a,c). father(a,d). father(b,e). father(b,f). father(b,g). father(c,h). father(c,i). father(d,j). father(d,k). brother(X,Y):- X<>Y, father(Z,X), father(Z,Y). cousin(X,Y):- father(A,X), father(B,Y), brother(A,B). grandfather(X,Y):- father(Z,Y), father(X,Z). goal cousin(X,Y).
  • 25. Prolog Variables • Constant placeholders (NOT variables) – Bounded once • Loosely typed • Start with Capital letter or underscore • Examples – brother(ahmed, Ahmed) – brother(ahmed, _x) – Brother(ahmed, X) • Anonymous variable – The _ – Some value that isn’t required – Example brother(ahmed, _)
  • 26. Expert system • A simple medical expert system • relieves(Drug, Symptom). – relieves(aspirin, headache). – relieves(aspirin, moderate_pain). – relieves(aspirin, moderate_arthritis). – relieves(aspirin_codine_combination, severe_pain). – relieves(cough_cure, cough). – relieves(pain_gone, severe_pain). – relieves(anti_diarrhea, diarrhea). – relieves(de_congest, cough). – relieves(de_congest, nasal_congestion). – relieves(penicilline, pneumonia). – relieves(bis_cure, diarrhea). – relieves(bis_cure, nausea). – relieves(new_med, headache). – relieves(new_med, moderate_pain). – relieves(cong_plus, nasal_congestion).
  • 27. • aggravates(Drug, Condition). – aggravates(aspirin, asthma). – aggravates(aspirin, peptic_ulcer). – aggravates(anti-diarrhea, fever). – aggravates(de_congest, high_blood_pressure). – aggravates(de_congest, heart_disease). – aggravates(de_congest, diabetes). – aggravates(de_congest, glaucoma). – aggravates(penicilline, asthma). – aggravates(de_congest, high_blood_pressure). – aggravates(bis_cure, diabetes). – aggravates(bis_cure, fever).
  • 28. should_take(Person, Drug) :- complains_of(Person, Symptom), relieves(Drug, Symptom), not(unsuitable_for(Person, Drug)). //conjunction of three classes. unsuitable_for(Person, Drug) :- aggravates(Drug, Condition), suffers_from(Person, Condition). complains_of(ali, headache). suffers_from(ali, peptic_ulcer). ?- should_take(ali, Drug). Drug = new_med;
  • 29. Books • Prolog Programming for AI by Ivan Bratko • Visual Prolog; Language Tutorial by PDC

Editor's Notes

  1. (load “c:/yourprogram.lisp”)
  2. Pro: Programming, Log : Logic Predicate Calculus : Where we define our predicates and then we inference and deduce new information. Theorem proving: [Certain fact + Certain Rules + Query (Is it right or wrong)] Declarative Language: What is the fact and what we need in result?
  3. 4
  4. 5
  5. 6
  6. 7
  7. Modus Ponens (Basic Proof technique): If A is true then B is also true.
  8. Logic Programming: First we write horn clauses (Facts+Fules). We need to establish a Goal with two ways. 1)Forward Chaining 2) Backward Chaining: Back tracking Algorithm I need to prove it or disprove it.
  9. 11
  10. 12
  11. 13
  12. 14
  13. 15
  14. Period (.) must come after fact and rule. [End of statement]
  15. We don’t have any information that Snowy(Columbo) , that fact is not avaliable so we say No. Backward chaining & Inference Mechanism do all these things for us.
  16. 3 Parts. Predicates. Clauses Goal [Goad will only be one]
  17. Goal: Is the result of program. Program: [Facts+Rule]+Query
  18. ProLog have no assignment mechanism. Loosely typed: You associate the value with it..will be behave like that. (-) Place holder just just use for garbage
  19. Aggravates=reactions or side effects.
  20. Expert systems shells