SlideShare ist ein Scribd-Unternehmen logo
1 von 38
PROLOG
P R I N C I P L E S O F P R O G R A M M I N G L A N G U A G E S
PRESENTED BY:
H A S S A A N A H M A D ( 0 7 )
A Z E E M A S H R A F ( 1 4 )
M U H A M M A D U S A M A I Q B A L ( 1 5 )
S Y E D B A Q A R A B B A S ( 1 9 )
WHAT IS PROLOG?
• Prolog stands for programming in logic (PROgrammation en LOGique).
• Prolog is the most widely used language to have been inspired by logic
programming research.
• Prolog is the only successful example of the family of logic
programming languages.
CONT..
• Prolog is a declarative programming language.
• In the case of prolog, it will tell you whether a prolog sentence is true or not.
• if it contains variables, what the values of the variables need to be.
• Prolog is declarative. A Prolog programmer concentrates on what the program
needs to do, not on how to do it.
A LITTLE HISTORY
• Prolog was invented by Alain Colmerauer, a professor of computer science at
the university of Aix-Marseille in France, in 1972.
• The first application of Prolog was in natural language processing.
• Its theoretical underpinning are due to Donald Loveland of Duke university
through Robert Kowalski (formerly) of the university of Edinburgh
ANATOMY OF PROLOG PROGRAM
• Prolog programs are made up of facts and rules.
• A fact asserts some property of an object, or relation between two or more
objects.
e.g. parent(jane,alan).
Can be read as “Jane is the parent of Alan.”
• Rules allow us to infer that a property or relationship holds based on
preconditions.
e.g. parent(X,Y) :- mother(X,Y).
= “Person X is the parent of person Y if X is Y‟s mother.”
DATA TYPES
• Prolog single data type is the term. Terms are either atoms, numbers or
variables.
• An Atom is a general-purpose name with no inherent meaning.
Examples of atoms include
– X
– Red
– Taco
• Numbers can be floats or integers.
• Variables are denoted by a string consisting of letters, numbers and
underscore characters, and beginning with an upper-case letter or
underscore.
WHY LEARN PROLOG?
• Learning prolog will certainly not always be as fruitful as learning C++,
Java or Python.
• Prolog is most useful in the areas related to Artificial Intelligence
research, such as problem solving, (path) planning or natural language
interpretation.
• As prolog uses certain programming techniques that are considered
difficult or advanced
• prolog programmer will certainly have an in-depth understanding of
such concepts as recursion, searching problem trees etc.
CONT..
• Very complex programs have been written in prolog.
• Most of all prolog is a complex, powerful, and elegant language that
can inspire great satisfaction in its users.
• learning prolog is not easy because Prolog doesn't work as naturally as
procedural languages and therefore requires a specific way of thinking.
INTRODUCTION TO LOGIC
• Since Prolog is based heavily on formal logic, it's useful to have some
experience with it.
• There are two types of logical languages:
– propositional logic
– first-order logic.
PROPOSITIONAL LOGIC
• Propositional logic has two basic elements:
– terms
– Connectives
• Terms are represented by letters (usually upper-case), and represent
the values true and false.
• Connectives, like the word suggests, connect two terms.
• Connectives are usually represented by symbols rather than words.
FIRST ORDER LOGIC
• First Order Logic (also known as predicate logic) expands on
propositional logic, by using predicates, variables and objects.
• In first order logic the atomic sentences are predicates.
• Predicates have a name (starting with a capital) which is followed
by several variables (starting with a lowercase letter).
CONT..
• The following are examples of predicates:
– Predicate(variable1, variable2)
– BrotherOf(sibling, brother)
– MotherOf(child, mother)
– HasWheels(thing)
• these variables can be instantiated with objects.
CONT..
• Objects are elements represented by words that start with a capital
letter.
• Such a collection of sentences that are true is called a knowledge base.
• Such a knowledge base could, for instance contain the following
sentences:
– HasWheels(Car)
– MotherOf(Charles, Elizabeth)
• The sentences tell us that the HasWheels predicate is true
PREDICATE DEFINITIONS
• Both facts and rules are predicate definitions.
• ‘Predicate’ is the name given to the word occurring before the bracket in
a fact
or rule:
– parent (jane,alan).
• By defining a predicate you are specifying which information needs to
be
known for the property denoted by the predicate to be true.
CLAUSES
• Predicate definitions consist of clauses.
• An individual definition (whether it be a fact or rule).
e.g. mother(jane, alan). = Fact
parent(P1,P2):- mother(P1,P2). = Rule
• A clause consists of a head And sometimes a body.
• Facts don't have a body because they are always true.
• Clauses with empty bodies are called facts.
• Clauses with bodies are called rules.
ARGUMENTS
• A predicate head consists of a predicate name and sometimes some
arguments
contained within brackets and separated by commas.
mother(jane, alan).
Predicate name Arguments
• A body can be made up of any number of subgoals (calls to other
predicates) and terms.
CONT..
• Arguments also consist of terms, which can be:
– Constants e.g. jane,
– Variables e.g. Person1, or
– Compound terms
TERMS
CONSTANTS
Constants can either be:
• Numbers:
– integers are the usual form (e.g. 1, 0, -1, etc), but
– floating-point numbers can also be used (e.g. 3.9)
• Symbolic constants:
– always start with a lower case alphabetic character and contain any
mixture of
letters, digits, and underscores (but no spaces, punctuation, or an initial
capital).
– e.g. abc, big_long_constant, x4_3t.
• String constants:
VARIABLES
• Variables always start with an upper case alphabetic character or an
underscore.
• Other than the first character they can be made up of any mixture of letters,
digits, and underscores.
e.g. X, ABC, _89two5, _very_long_variable
• There are no “types” for variables (or constants) – a variable can take any
value.
• All Prolog variables have a “local” scope:
They only keep the same value within a clause; the same variable used
outside
of a clause refers as “global” scope.
NAMING TIPS
• Use real English when naming predicates, constants, and variables.
– e.g. “John wants to help Somebody.”
– Could be: wants(john, to_help , Somebody).
– Not: x87g(j,_789).
• Use a Verb-Subject-Object structure:
– wants(john, to_help).
• BUT do not assume Prolog Understands the meaning of your chosen
names
RUNNING
PROLOG
O N W I N D O W S .
After SWI-Prolog has been installed on a Windows system, the following
important new things are available to the user:
• A folder (in program files) called swipl containing the executable, libraries, etc.,
of the system.
• No files are installed outside this directory.
• Program swipl-win.exe, providing a window for interaction with Prolog.
• The program swipl.exe is a version of SWI-Prolog that runs in a console
window.
• The file extension .pl is associated with the program swipl-win.exe.
EXECUTING A QUERY
After loading a program, one can ask Prolog queries about the program.
?- likes (sam, x) .
X = biryani ;
X = tandoori ;
……
X = chips ;
?-
PROLOG EXECUTION
• Most Prolog clauses have both a declarative reading and a procedural
reading.
• Whenever possible, the declarative reading is to be preferred.
– mother (X, Y) :- parent (X, Y), female (X) .
• Declarative reading: x is the mother of y
– if x is parent of y and x is female
CONT..
Procedural reading :
• To show that x is the mother of y, first show that x is a parent of y, then
show that x is female.
Clauses:
oparent (john, bill) .
oparent (jane, bill) .
ofemale(jane) .
Query:
o| ?- mother (M, bill) .
CONT..
• The clause of mother will be checked, and the unification X=M, Y=bill will occur.
• Then parent (M, bill) will be attempted, resulting in the unification M=john.
• Next, female (john) will be attempted, but will fail.
• Prolog will backtrack to parent (M, bill) and look for another solution for this; it will
succeed and unify M=jane.
• Finally, it will attempt female (jane), and succeed; so the inquiry will succeed,
having performed the unification M=jane.
ADVANTAGES
• Ease of representing knowledge.
• Natural support of pattern-matching.
• Natural support of meta-programming.
• Meaning of programs is independent of how they are executed.
• Simple connection between programs and computed answers and
specifications.
• No need to distinguish programs from databases.
LIMITATIONS
• Although Prolog is widely used in research and education, Prolog and other logic
programming languages have not had a significant impact on the computer
industry in general.
• Most applications are small by industrial standards, with few exceeding 100,000
lines of code.
• Programming in the large is considered to be complicated because not all Prolog
compilers support modules
• because there are compatibility problems between the module systems of the
major Prolog compilers.
• Prolog is not purely declarative because of constructs like the cut operator,
• a procedural reading of a Prolog program is needed to understand it.
EXTENSIONS
• Various implementations have been developed from Prolog to extend logic
programming capabilities
• these include:
– types,
– modes,
– constraint logic programming (CLP),
– object-oriented logic programming (OOLP),
– linear logic (LLP),
– functional and higher-order logic programming capabilities,
– interoperability with knowledge bases
TYPES
• Prolog is an untyped language.
• Attempts to introduce types date back to the 1980s and as of 2008
there are still attempts to extend Prolog with types.
MODES
• The syntax of Prolog does not specify which arguments of a predicate
are inputs and which are outputs.
• Modes provide valuable information when reasoning about Prolog
programs and can also be used to accelerate execution.
EXAMPLE # 1:
EXAMPLE # 2:
GRAPHICS
• Prolog systems that provide a graphics library are:
– SWI-Prolog
– Visual Prolog WIN-PROLOG
– B-Prolog
• SWI also support server-side web programming with support for web
protocols, HTML and XML.
THANK
YOU

Weitere ähnliche Inhalte

Was ist angesagt?

Lec4slides
Lec4slidesLec4slides
Lec4slides
shawiz
 
Representing and Reasoning with Modular Ontologies (2007)
Representing and Reasoning with Modular Ontologies (2007)Representing and Reasoning with Modular Ontologies (2007)
Representing and Reasoning with Modular Ontologies (2007)
Jie Bao
 
Eswc2012 ss ontologies
Eswc2012 ss ontologiesEswc2012 ss ontologies
Eswc2012 ss ontologies
Elena Simperl
 
Towards advanced data retrieval from learning objects repositories
Towards advanced data retrieval from learning objects repositoriesTowards advanced data retrieval from learning objects repositories
Towards advanced data retrieval from learning objects repositories
Valentina Paunovic
 

Was ist angesagt? (20)

Introduction to prolog
Introduction to prologIntroduction to prolog
Introduction to prolog
 
PROLOG: Introduction To Prolog
PROLOG: Introduction To PrologPROLOG: Introduction To Prolog
PROLOG: Introduction To Prolog
 
Prolog
PrologProlog
Prolog
 
Natural Language Processing
Natural Language ProcessingNatural Language Processing
Natural Language Processing
 
NLP Project Full Cycle
NLP Project Full CycleNLP Project Full Cycle
NLP Project Full Cycle
 
RuleML2015 PSOA RuleML: Integrated Object-Relational Data and Rules
RuleML2015 PSOA RuleML: Integrated Object-Relational Data and RulesRuleML2015 PSOA RuleML: Integrated Object-Relational Data and Rules
RuleML2015 PSOA RuleML: Integrated Object-Relational Data and Rules
 
Lec4slides
Lec4slidesLec4slides
Lec4slides
 
Representing and Reasoning with Modular Ontologies (2007)
Representing and Reasoning with Modular Ontologies (2007)Representing and Reasoning with Modular Ontologies (2007)
Representing and Reasoning with Modular Ontologies (2007)
 
Lecture 2: Computational Semantics
Lecture 2: Computational SemanticsLecture 2: Computational Semantics
Lecture 2: Computational Semantics
 
NLP_KASHK:Text Normalization
NLP_KASHK:Text NormalizationNLP_KASHK:Text Normalization
NLP_KASHK:Text Normalization
 
Propositional logic(part 2)
Propositional logic(part 2)Propositional logic(part 2)
Propositional logic(part 2)
 
Why Java is not a purely object oriented language?
Why Java is not a purely object oriented language?Why Java is not a purely object oriented language?
Why Java is not a purely object oriented language?
 
Introduction to Ontology Engineering with Fluent Editor 2014
Introduction to Ontology Engineering with Fluent Editor 2014Introduction to Ontology Engineering with Fluent Editor 2014
Introduction to Ontology Engineering with Fluent Editor 2014
 
Semantics and Computational Semantics
Semantics and Computational SemanticsSemantics and Computational Semantics
Semantics and Computational Semantics
 
Eswc2012 ss ontologies
Eswc2012 ss ontologiesEswc2012 ss ontologies
Eswc2012 ss ontologies
 
Towards advanced data retrieval from learning objects repositories
Towards advanced data retrieval from learning objects repositoriesTowards advanced data retrieval from learning objects repositories
Towards advanced data retrieval from learning objects repositories
 
Crash Course in Natural Language Processing (2016)
Crash Course in Natural Language Processing (2016)Crash Course in Natural Language Processing (2016)
Crash Course in Natural Language Processing (2016)
 
Lecture 1: Semantic Analysis in Language Technology
Lecture 1: Semantic Analysis in Language TechnologyLecture 1: Semantic Analysis in Language Technology
Lecture 1: Semantic Analysis in Language Technology
 
Lidia Pivovarova
Lidia PivovarovaLidia Pivovarova
Lidia Pivovarova
 
Lect6-An introduction to ontologies and ontology development
Lect6-An introduction to ontologies and ontology developmentLect6-An introduction to ontologies and ontology development
Lect6-An introduction to ontologies and ontology development
 

Ähnlich wie Prolog final

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
qasim ali
 
Foundations of Knowledge Representation in Artificial Intelligence.pptx
Foundations of Knowledge Representation in Artificial Intelligence.pptxFoundations of Knowledge Representation in Artificial Intelligence.pptx
Foundations of Knowledge Representation in Artificial Intelligence.pptx
kitsenthilkumarcse
 

Ähnlich wie Prolog final (20)

ARTIFICIAL INTELLIGENCE---UNIT 4.pptx
ARTIFICIAL INTELLIGENCE---UNIT 4.pptxARTIFICIAL INTELLIGENCE---UNIT 4.pptx
ARTIFICIAL INTELLIGENCE---UNIT 4.pptx
 
Prolog,Prolog Programming IN AI.pdf
Prolog,Prolog Programming IN AI.pdfProlog,Prolog Programming IN AI.pdf
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.pptx
 
Chaps 1-3-ai-prolog
Chaps 1-3-ai-prologChaps 1-3-ai-prolog
Chaps 1-3-ai-prolog
 
Plc part 4
Plc  part 4Plc  part 4
Plc part 4
 
Iccs presentation 2k17 : Predicting dark triad personality traits using twit...
Iccs presentation  2k17 : Predicting dark triad personality traits using twit...Iccs presentation  2k17 : Predicting dark triad personality traits using twit...
Iccs presentation 2k17 : Predicting dark triad personality traits using twit...
 
Working with big biomedical ontologies
Working with big biomedical ontologiesWorking with big biomedical ontologies
Working with big biomedical ontologies
 
Foundations of Knowledge Representation in Artificial Intelligence.pptx
Foundations of Knowledge Representation in Artificial Intelligence.pptxFoundations of Knowledge Representation in Artificial Intelligence.pptx
Foundations of Knowledge Representation in Artificial Intelligence.pptx
 
Family Tree on PROLOG
Family Tree on PROLOGFamily Tree on PROLOG
Family Tree on PROLOG
 
Python Training
Python TrainingPython Training
Python Training
 
ICS1019.pdf
ICS1019.pdfICS1019.pdf
ICS1019.pdf
 
Logic in Predicate and Propositional Logic
Logic in Predicate and Propositional LogicLogic in Predicate and Propositional Logic
Logic in Predicate and Propositional Logic
 
Jarrar: ORM in Description Logic
Jarrar: ORM in Description Logic  Jarrar: ORM in Description Logic
Jarrar: ORM in Description Logic
 
Artificial Intelligence Notes Unit 4
Artificial Intelligence Notes Unit 4Artificial Intelligence Notes Unit 4
Artificial Intelligence Notes Unit 4
 
Prolog
Prolog Prolog
Prolog
 
Formal Logic in AI
Formal Logic in AIFormal Logic in AI
Formal Logic in AI
 
Ics1019 ics5003
Ics1019 ics5003Ics1019 ics5003
Ics1019 ics5003
 
Ai lab manual
Ai lab manualAi lab manual
Ai lab manual
 
predicateLogic.ppt
predicateLogic.pptpredicateLogic.ppt
predicateLogic.ppt
 
Ics1019 ics5003
Ics1019 ics5003Ics1019 ics5003
Ics1019 ics5003
 

Kürzlich hochgeladen

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 

Kürzlich hochgeladen (20)

Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
 

Prolog final

  • 1. PROLOG P R I N C I P L E S O F P R O G R A M M I N G L A N G U A G E S
  • 2. PRESENTED BY: H A S S A A N A H M A D ( 0 7 ) A Z E E M A S H R A F ( 1 4 ) M U H A M M A D U S A M A I Q B A L ( 1 5 ) S Y E D B A Q A R A B B A S ( 1 9 )
  • 3. WHAT IS PROLOG? • Prolog stands for programming in logic (PROgrammation en LOGique). • Prolog is the most widely used language to have been inspired by logic programming research. • Prolog is the only successful example of the family of logic programming languages.
  • 4. CONT.. • Prolog is a declarative programming language. • In the case of prolog, it will tell you whether a prolog sentence is true or not. • if it contains variables, what the values of the variables need to be. • Prolog is declarative. A Prolog programmer concentrates on what the program needs to do, not on how to do it.
  • 5. A LITTLE HISTORY • Prolog was invented by Alain Colmerauer, a professor of computer science at the university of Aix-Marseille in France, in 1972. • The first application of Prolog was in natural language processing. • Its theoretical underpinning are due to Donald Loveland of Duke university through Robert Kowalski (formerly) of the university of Edinburgh
  • 6. ANATOMY OF PROLOG PROGRAM • Prolog programs are made up of facts and rules. • A fact asserts some property of an object, or relation between two or more objects. e.g. parent(jane,alan). Can be read as “Jane is the parent of Alan.” • Rules allow us to infer that a property or relationship holds based on preconditions. e.g. parent(X,Y) :- mother(X,Y). = “Person X is the parent of person Y if X is Y‟s mother.”
  • 7. DATA TYPES • Prolog single data type is the term. Terms are either atoms, numbers or variables. • An Atom is a general-purpose name with no inherent meaning. Examples of atoms include – X – Red – Taco • Numbers can be floats or integers. • Variables are denoted by a string consisting of letters, numbers and underscore characters, and beginning with an upper-case letter or underscore.
  • 8. WHY LEARN PROLOG? • Learning prolog will certainly not always be as fruitful as learning C++, Java or Python. • Prolog is most useful in the areas related to Artificial Intelligence research, such as problem solving, (path) planning or natural language interpretation. • As prolog uses certain programming techniques that are considered difficult or advanced • prolog programmer will certainly have an in-depth understanding of such concepts as recursion, searching problem trees etc.
  • 9. CONT.. • Very complex programs have been written in prolog. • Most of all prolog is a complex, powerful, and elegant language that can inspire great satisfaction in its users. • learning prolog is not easy because Prolog doesn't work as naturally as procedural languages and therefore requires a specific way of thinking.
  • 10. INTRODUCTION TO LOGIC • Since Prolog is based heavily on formal logic, it's useful to have some experience with it. • There are two types of logical languages: – propositional logic – first-order logic.
  • 11. PROPOSITIONAL LOGIC • Propositional logic has two basic elements: – terms – Connectives • Terms are represented by letters (usually upper-case), and represent the values true and false. • Connectives, like the word suggests, connect two terms. • Connectives are usually represented by symbols rather than words.
  • 12.
  • 13. FIRST ORDER LOGIC • First Order Logic (also known as predicate logic) expands on propositional logic, by using predicates, variables and objects. • In first order logic the atomic sentences are predicates. • Predicates have a name (starting with a capital) which is followed by several variables (starting with a lowercase letter).
  • 14. CONT.. • The following are examples of predicates: – Predicate(variable1, variable2) – BrotherOf(sibling, brother) – MotherOf(child, mother) – HasWheels(thing) • these variables can be instantiated with objects.
  • 15. CONT.. • Objects are elements represented by words that start with a capital letter. • Such a collection of sentences that are true is called a knowledge base. • Such a knowledge base could, for instance contain the following sentences: – HasWheels(Car) – MotherOf(Charles, Elizabeth) • The sentences tell us that the HasWheels predicate is true
  • 16. PREDICATE DEFINITIONS • Both facts and rules are predicate definitions. • ‘Predicate’ is the name given to the word occurring before the bracket in a fact or rule: – parent (jane,alan). • By defining a predicate you are specifying which information needs to be known for the property denoted by the predicate to be true.
  • 17. CLAUSES • Predicate definitions consist of clauses. • An individual definition (whether it be a fact or rule). e.g. mother(jane, alan). = Fact parent(P1,P2):- mother(P1,P2). = Rule • A clause consists of a head And sometimes a body. • Facts don't have a body because they are always true. • Clauses with empty bodies are called facts. • Clauses with bodies are called rules.
  • 18. ARGUMENTS • A predicate head consists of a predicate name and sometimes some arguments contained within brackets and separated by commas. mother(jane, alan). Predicate name Arguments • A body can be made up of any number of subgoals (calls to other predicates) and terms.
  • 19. CONT.. • Arguments also consist of terms, which can be: – Constants e.g. jane, – Variables e.g. Person1, or – Compound terms
  • 20. TERMS
  • 21. CONSTANTS Constants can either be: • Numbers: – integers are the usual form (e.g. 1, 0, -1, etc), but – floating-point numbers can also be used (e.g. 3.9) • Symbolic constants: – always start with a lower case alphabetic character and contain any mixture of letters, digits, and underscores (but no spaces, punctuation, or an initial capital). – e.g. abc, big_long_constant, x4_3t. • String constants:
  • 22. VARIABLES • Variables always start with an upper case alphabetic character or an underscore. • Other than the first character they can be made up of any mixture of letters, digits, and underscores. e.g. X, ABC, _89two5, _very_long_variable • There are no “types” for variables (or constants) – a variable can take any value. • All Prolog variables have a “local” scope: They only keep the same value within a clause; the same variable used outside of a clause refers as “global” scope.
  • 23. NAMING TIPS • Use real English when naming predicates, constants, and variables. – e.g. “John wants to help Somebody.” – Could be: wants(john, to_help , Somebody). – Not: x87g(j,_789). • Use a Verb-Subject-Object structure: – wants(john, to_help). • BUT do not assume Prolog Understands the meaning of your chosen names
  • 24. RUNNING PROLOG O N W I N D O W S .
  • 25. After SWI-Prolog has been installed on a Windows system, the following important new things are available to the user: • A folder (in program files) called swipl containing the executable, libraries, etc., of the system. • No files are installed outside this directory. • Program swipl-win.exe, providing a window for interaction with Prolog. • The program swipl.exe is a version of SWI-Prolog that runs in a console window. • The file extension .pl is associated with the program swipl-win.exe.
  • 26. EXECUTING A QUERY After loading a program, one can ask Prolog queries about the program. ?- likes (sam, x) . X = biryani ; X = tandoori ; …… X = chips ; ?-
  • 27. PROLOG EXECUTION • Most Prolog clauses have both a declarative reading and a procedural reading. • Whenever possible, the declarative reading is to be preferred. – mother (X, Y) :- parent (X, Y), female (X) . • Declarative reading: x is the mother of y – if x is parent of y and x is female
  • 28. CONT.. Procedural reading : • To show that x is the mother of y, first show that x is a parent of y, then show that x is female. Clauses: oparent (john, bill) . oparent (jane, bill) . ofemale(jane) . Query: o| ?- mother (M, bill) .
  • 29. CONT.. • The clause of mother will be checked, and the unification X=M, Y=bill will occur. • Then parent (M, bill) will be attempted, resulting in the unification M=john. • Next, female (john) will be attempted, but will fail. • Prolog will backtrack to parent (M, bill) and look for another solution for this; it will succeed and unify M=jane. • Finally, it will attempt female (jane), and succeed; so the inquiry will succeed, having performed the unification M=jane.
  • 30. ADVANTAGES • Ease of representing knowledge. • Natural support of pattern-matching. • Natural support of meta-programming. • Meaning of programs is independent of how they are executed. • Simple connection between programs and computed answers and specifications. • No need to distinguish programs from databases.
  • 31. LIMITATIONS • Although Prolog is widely used in research and education, Prolog and other logic programming languages have not had a significant impact on the computer industry in general. • Most applications are small by industrial standards, with few exceeding 100,000 lines of code. • Programming in the large is considered to be complicated because not all Prolog compilers support modules • because there are compatibility problems between the module systems of the major Prolog compilers. • Prolog is not purely declarative because of constructs like the cut operator, • a procedural reading of a Prolog program is needed to understand it.
  • 32. EXTENSIONS • Various implementations have been developed from Prolog to extend logic programming capabilities • these include: – types, – modes, – constraint logic programming (CLP), – object-oriented logic programming (OOLP), – linear logic (LLP), – functional and higher-order logic programming capabilities, – interoperability with knowledge bases
  • 33. TYPES • Prolog is an untyped language. • Attempts to introduce types date back to the 1980s and as of 2008 there are still attempts to extend Prolog with types.
  • 34. MODES • The syntax of Prolog does not specify which arguments of a predicate are inputs and which are outputs. • Modes provide valuable information when reasoning about Prolog programs and can also be used to accelerate execution.
  • 37. GRAPHICS • Prolog systems that provide a graphics library are: – SWI-Prolog – Visual Prolog WIN-PROLOG – B-Prolog • SWI also support server-side web programming with support for web protocols, HTML and XML.

Hinweis der Redaktion

  1. You create meaning by specifying the body (i.e. preconditions) of a clause.
  2. Sociaal-Wetenschappelijke Informatica ("Social Science Informatics")