SlideShare a Scribd company logo
1 of 25
CSE: Introduction to Prolog
AJAYSING ,
JUNAID,
AKASH,
CSE Dept,
SSGMCE,SHEGAON
Introduction
 PROgramming in LOGic
 Emphasis on what rather than how
Basic Machine
Logic Machine
Problem in Declarative Form
Prolog’s strong and weak
points
 Assists thinking in terms of objects and
entities
 Not good for number crunching
 Useful applications of Prolog in
 Expert Systems (Knowledge
Representation and Interencing)
 Natural Language Processing
 Relational Databases
A Typical Prolog program
Compute_length ([],0).
Compute_length ([Head|Tail], Length):-
Compute_length (Tail,Tail_length),
Length is Tail_length+1.
High level explanation:
The length of a list is 1 plus the length of the
tail of the list, obtained by removing the first
element of the list.
This is a declarative description of the
computation.
Fundamentals
(absolute basics for writing
Prolog Programs)
Facts
 John likes Mary
 like(john,mary)
 Names of relationship and objects must begin
with a lower-case letter.
 Relationship is written first (typically the
predicate of the sentence).
 Objects are written separated by commas
and are enclosed by a pair of round brackets.
 The full stop character ‘.’ must come at the
end of a fact.
More facts
Predicate Interpretation
valuable(gold) Gold is valuable.
owns(john,gold) John owns gold.
father(john,mary) John is the father of
Mary
gives (john,book,mary) John gives the book to
Mary
 Questions based on facts
 Answered by matching
Two facts match if their predicates are same
(spelt the same way) and the arguments each
are same.
 If matched, prolog answers yes, else no.
 No does not mean falsity.
Questions
Prolog does theorem proving
 When a question is asked, prolog tries
to match transitively.
 When no match is found, answer is no.
 This means not provable from the given
facts.
Variables
 Always begin with a capital letter
 ?- likes (john,X).
 ?- likes (john, Something).
 But not
 ?- likes (john,something)
Example of usage of variable
Facts:
likes(john,flowers).
likes(john,mary).
likes(paul,mary).
Question:
?- likes(john,X)
Answer:
X=flowers and wait
;
mary
;
no
Conjunctions
 Use ‘,’ and pronounce it as and.
 Example
 Facts:

likes(mary,food).

likes(mary,tea).

likes(john,tea).

likes(john,mary)
 ?-

likes(mary,X),likes(john,X).

Meaning is anything liked by Mary also liked by John?
Backtracking (an inherent property of
prolog programming)
likes(mary,X),likes(john,X)
likes(mary,food)
likes(mary,tea)
likes(john,tea)
likes(john,mary)
1. First goal succeeds. X=food
2. Satisfy likes(john,food)
Backtracking (continued)
Returning to a marked place and trying to resatisfy is
called Backtracking
likes(mary,X),likes(john,X)
likes(mary,food)
likes(mary,tea)
likes(john,tea)
likes(john,mary)
1. Second goal fails
2. Return to marked place
and try to resatisfy the first goal
Backtracking (continued)
likes(mary,X),likes(john,X)
likes(mary,food)
likes(mary,tea)
likes(john,tea)
likes(john,mary)
1. First goal succeeds again, X=tea
2. Attempt to satisfy the likes(john,tea)
Backtracking (continued)
likes(mary,X),likes(john,X)
likes(mary,food)
likes(mary,tea)
likes(john,tea)
likes(john,mary)
1. Second goal also suceeds
2. Prolog notifies success and waits for a reply
Rules
 Statements about objects and their
relationships
 Expess
 If-then conditions

I use an umbrella if there is a rain

use(i, umbrella) :- occur(rain).
 Generalizations

All men are mortal

mortal(X) :- man(X).
 Definitions

An animal is a bird if it has feathers

bird(X) :- animal(X), has_feather(X).
Syntax
 <head> :- <body>
 Read ‘:-’ as ‘if’.
 E.G.
 likes(john,X) :- likes(X,cricket).
 “John likes X if X likes cricket”.
 i.e., “John likes anyone who likes cricket”.
 Rules always end with ‘.’.
Another Example
sister_of (X,Y):- female (X),
parents (X, M, F),
parents (Y, M, F).
X is a sister of Y is
X is a female and
X and Y have same parents
Question Answering in presence
of rules
 Facts
 male (ram).
 male (shyam).
 female (sita).
 female (gita).
 parents (shyam, gita, ram).
 parents (sita, gita, ram).
Question Answering: Y/N type: is sita the
sister of shyam?
female(sita)
parents(sita,M,F) parents(shyam,M,F)
parents(sita,gita,ram)
parents(shyam,gita,ram)
success
?- sister_of (sita, shyam)
Question Answering: wh-type: whose
sister is sita?
female(sita)
parents(sita,M,F) parents(Y,M,F)
parents(sita,gita,ram)
parents(Y,gita,ram)
Success
Y=shyam
parents(shyam,gita,ram)
?- ?- sister_of (sita, X)
Exercise
1. From the above it is possible for
somebody to be her own sister. How
can this be prevented?
References:-
 http://book.simply-
logical.space/part_i.html#a_brief_introd
uction_to_clausal_logic
Thank you!!!

More Related Content

What's hot

Predlogic
PredlogicPredlogic
Predlogicsaru40
 
ProLog (Artificial Intelligence) Introduction
ProLog (Artificial Intelligence) IntroductionProLog (Artificial Intelligence) Introduction
ProLog (Artificial Intelligence) Introductionwahab khan
 
10 logic+programming+with+prolog
10 logic+programming+with+prolog10 logic+programming+with+prolog
10 logic+programming+with+prologbaran19901990
 
Prolog 01
Prolog 01Prolog 01
Prolog 01saru40
 
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
 
Logic programming (1)
Logic programming (1)Logic programming (1)
Logic programming (1)Nitesh Singh
 
#8 formal methods – pro logic
#8 formal methods – pro logic#8 formal methods – pro logic
#8 formal methods – pro logicSharif Omar Salem
 
Brixon Library Technology Initiative
Brixon Library Technology InitiativeBrixon Library Technology Initiative
Brixon Library Technology InitiativeBasil Bibi
 
PROLOG: Cuts And Negation In Prolog
PROLOG: Cuts And Negation In PrologPROLOG: Cuts And Negation In Prolog
PROLOG: Cuts And Negation In PrologDataminingTools Inc
 
Linguistic variable
Linguistic variable Linguistic variable
Linguistic variable Math-Circle
 

What's hot (20)

Predlogic
PredlogicPredlogic
Predlogic
 
ProLog (Artificial Intelligence) Introduction
ProLog (Artificial Intelligence) IntroductionProLog (Artificial Intelligence) Introduction
ProLog (Artificial Intelligence) Introduction
 
Prolog basics
Prolog basicsProlog basics
Prolog basics
 
Prolog 7-Languages
Prolog 7-LanguagesProlog 7-Languages
Prolog 7-Languages
 
Crisp set
Crisp setCrisp set
Crisp set
 
10 logic+programming+with+prolog
10 logic+programming+with+prolog10 logic+programming+with+prolog
10 logic+programming+with+prolog
 
prolog ppt
prolog pptprolog ppt
prolog ppt
 
Prolog 01
Prolog 01Prolog 01
Prolog 01
 
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
 
Overview prolog
Overview prologOverview prolog
Overview prolog
 
Logic programming (1)
Logic programming (1)Logic programming (1)
Logic programming (1)
 
#8 formal methods – pro logic
#8 formal methods – pro logic#8 formal methods – pro logic
#8 formal methods – pro logic
 
Set
SetSet
Set
 
Plc part 4
Plc  part 4Plc  part 4
Plc part 4
 
Python - Lecture 7
Python - Lecture 7Python - Lecture 7
Python - Lecture 7
 
Brixon Library Technology Initiative
Brixon Library Technology InitiativeBrixon Library Technology Initiative
Brixon Library Technology Initiative
 
PROLOG: Cuts And Negation In Prolog
PROLOG: Cuts And Negation In PrologPROLOG: Cuts And Negation In Prolog
PROLOG: Cuts And Negation In Prolog
 
Root Words
Root WordsRoot Words
Root Words
 
Root Words
Root WordsRoot Words
Root Words
 
Linguistic variable
Linguistic variable Linguistic variable
Linguistic variable
 

Similar to Prolog

Cs344 lect15-robotic-knowledge-inferencing-prolog-11feb08
Cs344 lect15-robotic-knowledge-inferencing-prolog-11feb08Cs344 lect15-robotic-knowledge-inferencing-prolog-11feb08
Cs344 lect15-robotic-knowledge-inferencing-prolog-11feb08Praveen Kumar
 
An introduction to Prolog language slide
An introduction to Prolog language slideAn introduction to Prolog language slide
An introduction to Prolog language slide2021uam4641
 
Artificial intelligence Prolog Language
Artificial intelligence Prolog LanguageArtificial intelligence Prolog Language
Artificial intelligence Prolog LanguageREHMAT ULLAH
 
Jarrar.lecture notes.aai.2011s.ch8.fol.introduction
Jarrar.lecture notes.aai.2011s.ch8.fol.introductionJarrar.lecture notes.aai.2011s.ch8.fol.introduction
Jarrar.lecture notes.aai.2011s.ch8.fol.introductionPalGov
 
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: Recursion And Lists In Prolog
PROLOG: Recursion And Lists In PrologPROLOG: Recursion And Lists In Prolog
PROLOG: Recursion And Lists In PrologPROLOG CONTENT
 
Prolog fundamentals for beeginers in windows.ppt
Prolog  fundamentals for beeginers in windows.pptProlog  fundamentals for beeginers in windows.ppt
Prolog fundamentals for beeginers in windows.pptDrBhagirathPrajapati
 
GDSC SSN - solution Challenge : Fundamentals of Decision Making
GDSC SSN - solution Challenge : Fundamentals of Decision MakingGDSC SSN - solution Challenge : Fundamentals of Decision Making
GDSC SSN - solution Challenge : Fundamentals of Decision MakingGDSCSSN
 

Similar to Prolog (19)

Cs344 lect15-robotic-knowledge-inferencing-prolog-11feb08
Cs344 lect15-robotic-knowledge-inferencing-prolog-11feb08Cs344 lect15-robotic-knowledge-inferencing-prolog-11feb08
Cs344 lect15-robotic-knowledge-inferencing-prolog-11feb08
 
An introduction to Prolog language slide
An introduction to Prolog language slideAn introduction to Prolog language slide
An introduction to Prolog language slide
 
Fol
FolFol
Fol
 
Artificial intelligence Prolog Language
Artificial intelligence Prolog LanguageArtificial intelligence Prolog Language
Artificial intelligence Prolog Language
 
AI Lab Manual.docx
AI Lab Manual.docxAI Lab Manual.docx
AI Lab Manual.docx
 
Semantics
SemanticsSemantics
Semantics
 
Jarrar.lecture notes.aai.2011s.ch8.fol.introduction
Jarrar.lecture notes.aai.2011s.ch8.fol.introductionJarrar.lecture notes.aai.2011s.ch8.fol.introduction
Jarrar.lecture notes.aai.2011s.ch8.fol.introduction
 
First order logic
First order logicFirst order logic
First order logic
 
Pl vol1
Pl vol1Pl vol1
Pl vol1
 
Prolog PPT_merged.pdf
Prolog PPT_merged.pdfProlog PPT_merged.pdf
Prolog PPT_merged.pdf
 
Pl vol1
Pl vol1Pl vol1
Pl vol1
 
lacl (1)
lacl (1)lacl (1)
lacl (1)
 
Prolog2 (1)
Prolog2 (1)Prolog2 (1)
Prolog2 (1)
 
PROLOG: Recursion And Lists In Prolog
PROLOG: Recursion And Lists In PrologPROLOG: Recursion And Lists In Prolog
PROLOG: Recursion And Lists In Prolog
 
PROLOG: Recursion And Lists In Prolog
PROLOG: Recursion And Lists In PrologPROLOG: Recursion And Lists In Prolog
PROLOG: Recursion And Lists In Prolog
 
Prolog fundamentals for beeginers in windows.ppt
Prolog  fundamentals for beeginers in windows.pptProlog  fundamentals for beeginers in windows.ppt
Prolog fundamentals for beeginers in windows.ppt
 
GDSC SSN - solution Challenge : Fundamentals of Decision Making
GDSC SSN - solution Challenge : Fundamentals of Decision MakingGDSC SSN - solution Challenge : Fundamentals of Decision Making
GDSC SSN - solution Challenge : Fundamentals of Decision Making
 
ppt
pptppt
ppt
 
ppt
pptppt
ppt
 

Recently uploaded

High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).pptssuser5c9d4b1
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLDeelipZope
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 

Recently uploaded (20)

Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCL
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 

Prolog

  • 1. CSE: Introduction to Prolog AJAYSING , JUNAID, AKASH, CSE Dept, SSGMCE,SHEGAON
  • 2. Introduction  PROgramming in LOGic  Emphasis on what rather than how Basic Machine Logic Machine Problem in Declarative Form
  • 3. Prolog’s strong and weak points  Assists thinking in terms of objects and entities  Not good for number crunching  Useful applications of Prolog in  Expert Systems (Knowledge Representation and Interencing)  Natural Language Processing  Relational Databases
  • 4. A Typical Prolog program Compute_length ([],0). Compute_length ([Head|Tail], Length):- Compute_length (Tail,Tail_length), Length is Tail_length+1. High level explanation: The length of a list is 1 plus the length of the tail of the list, obtained by removing the first element of the list. This is a declarative description of the computation.
  • 5. Fundamentals (absolute basics for writing Prolog Programs)
  • 6. Facts  John likes Mary  like(john,mary)  Names of relationship and objects must begin with a lower-case letter.  Relationship is written first (typically the predicate of the sentence).  Objects are written separated by commas and are enclosed by a pair of round brackets.  The full stop character ‘.’ must come at the end of a fact.
  • 7. More facts Predicate Interpretation valuable(gold) Gold is valuable. owns(john,gold) John owns gold. father(john,mary) John is the father of Mary gives (john,book,mary) John gives the book to Mary
  • 8.  Questions based on facts  Answered by matching Two facts match if their predicates are same (spelt the same way) and the arguments each are same.  If matched, prolog answers yes, else no.  No does not mean falsity. Questions
  • 9. Prolog does theorem proving  When a question is asked, prolog tries to match transitively.  When no match is found, answer is no.  This means not provable from the given facts.
  • 10. Variables  Always begin with a capital letter  ?- likes (john,X).  ?- likes (john, Something).  But not  ?- likes (john,something)
  • 11. Example of usage of variable Facts: likes(john,flowers). likes(john,mary). likes(paul,mary). Question: ?- likes(john,X) Answer: X=flowers and wait ; mary ; no
  • 12. Conjunctions  Use ‘,’ and pronounce it as and.  Example  Facts:  likes(mary,food).  likes(mary,tea).  likes(john,tea).  likes(john,mary)  ?-  likes(mary,X),likes(john,X).  Meaning is anything liked by Mary also liked by John?
  • 13. Backtracking (an inherent property of prolog programming) likes(mary,X),likes(john,X) likes(mary,food) likes(mary,tea) likes(john,tea) likes(john,mary) 1. First goal succeeds. X=food 2. Satisfy likes(john,food)
  • 14. Backtracking (continued) Returning to a marked place and trying to resatisfy is called Backtracking likes(mary,X),likes(john,X) likes(mary,food) likes(mary,tea) likes(john,tea) likes(john,mary) 1. Second goal fails 2. Return to marked place and try to resatisfy the first goal
  • 17. Rules  Statements about objects and their relationships  Expess  If-then conditions  I use an umbrella if there is a rain  use(i, umbrella) :- occur(rain).  Generalizations  All men are mortal  mortal(X) :- man(X).  Definitions  An animal is a bird if it has feathers  bird(X) :- animal(X), has_feather(X).
  • 18. Syntax  <head> :- <body>  Read ‘:-’ as ‘if’.  E.G.  likes(john,X) :- likes(X,cricket).  “John likes X if X likes cricket”.  i.e., “John likes anyone who likes cricket”.  Rules always end with ‘.’.
  • 19. Another Example sister_of (X,Y):- female (X), parents (X, M, F), parents (Y, M, F). X is a sister of Y is X is a female and X and Y have same parents
  • 20. Question Answering in presence of rules  Facts  male (ram).  male (shyam).  female (sita).  female (gita).  parents (shyam, gita, ram).  parents (sita, gita, ram).
  • 21. Question Answering: Y/N type: is sita the sister of shyam? female(sita) parents(sita,M,F) parents(shyam,M,F) parents(sita,gita,ram) parents(shyam,gita,ram) success ?- sister_of (sita, shyam)
  • 22. Question Answering: wh-type: whose sister is sita? female(sita) parents(sita,M,F) parents(Y,M,F) parents(sita,gita,ram) parents(Y,gita,ram) Success Y=shyam parents(shyam,gita,ram) ?- ?- sister_of (sita, X)
  • 23. Exercise 1. From the above it is possible for somebody to be her own sister. How can this be prevented?