SlideShare a Scribd company logo
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

PPT
Introduction to prolog
PPTX
Crisp sets
PPTX
PROLOG: Introduction To Prolog
PPT
Chaps 1-3-ai-prolog
PPTX
Prolog Programming : Basics
PPT
Chaps 1-3-ai-prolog
PPTX
Prolog -Cpt114 - Week3
Introduction to prolog
Crisp sets
PROLOG: Introduction To Prolog
Chaps 1-3-ai-prolog
Prolog Programming : Basics
Chaps 1-3-ai-prolog
Prolog -Cpt114 - Week3

What's hot (20)

PPT
Predlogic
PPTX
ProLog (Artificial Intelligence) Introduction
PPT
Prolog basics
PPTX
Prolog 7-Languages
PPTX
Crisp set
PDF
10 logic+programming+with+prolog
PPT
prolog ppt
PPT
Prolog 01
PPTX
PROLOG: Fact Roles And Queries In Prolog
PPTX
Overview prolog
PDF
Logic programming (1)
PPTX
#8 formal methods – pro logic
PPTX
Plc part 4
PDF
Python - Lecture 7
PPTX
Brixon Library Technology Initiative
PPTX
PROLOG: Cuts And Negation In Prolog
DOCX
Root Words
DOCX
Root Words
PPTX
Linguistic variable
Predlogic
ProLog (Artificial Intelligence) Introduction
Prolog basics
Prolog 7-Languages
Crisp set
10 logic+programming+with+prolog
prolog ppt
Prolog 01
PROLOG: Fact Roles And Queries In Prolog
Overview prolog
Logic programming (1)
#8 formal methods – pro logic
Plc part 4
Python - Lecture 7
Brixon Library Technology Initiative
PROLOG: Cuts And Negation In Prolog
Root Words
Root Words
Linguistic variable
Ad

Similar to Prolog (20)

PPT
cs344-lect15-robotic-knowledge-inferencing-prolog-11feb08.ppt
DOCX
Prolog_Programminvfygugy7gtugbugtg_Notes.docx
PDF
PROLOG in artificial intelligence(Basic of pprolog)).pdf
PPT
Cs344 lect15-robotic-knowledge-inferencing-prolog-11feb08
PPTX
Untitled presentation unification algorithm.pptx
PPTX
An introduction to Prolog language slide
PPT
Artificial intelligence Prolog Language
DOCX
AI Lab Manual.docx
PPT
PPT
KNOWLEDGE Representation unit 3 for data mining
PPT
Jarrar.lecture notes.aai.2011s.ch8.fol.introduction
PPTX
First order logic
PPT
Pl vol1
PDF
Prolog PPT_merged.pdf
PPTX
logic for Advanced Programming Practice.pptx
PPT
Pl vol1
PDF
PPTX
PPTX
PROLOG: Recursion And Lists In Prolog
cs344-lect15-robotic-knowledge-inferencing-prolog-11feb08.ppt
Prolog_Programminvfygugy7gtugbugtg_Notes.docx
PROLOG in artificial intelligence(Basic of pprolog)).pdf
Cs344 lect15-robotic-knowledge-inferencing-prolog-11feb08
Untitled presentation unification algorithm.pptx
An introduction to Prolog language slide
Artificial intelligence Prolog Language
AI Lab Manual.docx
KNOWLEDGE Representation unit 3 for data mining
Jarrar.lecture notes.aai.2011s.ch8.fol.introduction
First order logic
Pl vol1
Prolog PPT_merged.pdf
logic for Advanced Programming Practice.pptx
Pl vol1
PROLOG: Recursion And Lists In Prolog
Ad

Recently uploaded (20)

PPT
Total quality management ppt for engineering students
PDF
22EC502-MICROCONTROLLER AND INTERFACING-8051 MICROCONTROLLER.pdf
PDF
August 2025 - Top 10 Read Articles in Network Security & Its Applications
PDF
Categorization of Factors Affecting Classification Algorithms Selection
PDF
Accra-Kumasi Expressway - Prefeasibility Report Volume 1 of 7.11.2018.pdf
PDF
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
PPTX
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
PPTX
Software Engineering and software moduleing
PDF
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
PPTX
Safety Seminar civil to be ensured for safe working.
PPTX
Information Storage and Retrieval Techniques Unit III
PDF
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
PDF
BIO-INSPIRED HORMONAL MODULATION AND ADAPTIVE ORCHESTRATION IN S-AI-GPT
PDF
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
PDF
BIO-INSPIRED ARCHITECTURE FOR PARSIMONIOUS CONVERSATIONAL INTELLIGENCE : THE ...
PPTX
Management Information system : MIS-e-Business Systems.pptx
PDF
Design Guidelines and solutions for Plastics parts
PDF
Influence of Green Infrastructure on Residents’ Endorsement of the New Ecolog...
PDF
UNIT no 1 INTRODUCTION TO DBMS NOTES.pdf
PDF
SMART SIGNAL TIMING FOR URBAN INTERSECTIONS USING REAL-TIME VEHICLE DETECTI...
Total quality management ppt for engineering students
22EC502-MICROCONTROLLER AND INTERFACING-8051 MICROCONTROLLER.pdf
August 2025 - Top 10 Read Articles in Network Security & Its Applications
Categorization of Factors Affecting Classification Algorithms Selection
Accra-Kumasi Expressway - Prefeasibility Report Volume 1 of 7.11.2018.pdf
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
Software Engineering and software moduleing
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
Safety Seminar civil to be ensured for safe working.
Information Storage and Retrieval Techniques Unit III
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
BIO-INSPIRED HORMONAL MODULATION AND ADAPTIVE ORCHESTRATION IN S-AI-GPT
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
BIO-INSPIRED ARCHITECTURE FOR PARSIMONIOUS CONVERSATIONAL INTELLIGENCE : THE ...
Management Information system : MIS-e-Business Systems.pptx
Design Guidelines and solutions for Plastics parts
Influence of Green Infrastructure on Residents’ Endorsement of the New Ecolog...
UNIT no 1 INTRODUCTION TO DBMS NOTES.pdf
SMART SIGNAL TIMING FOR URBAN INTERSECTIONS USING REAL-TIME VEHICLE DETECTI...

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?