SlideShare a Scribd company logo
Introduction to Prolog
Outline
• What is Prolog?
• Prolog basics
• Prolog Demo
• Syntax:
– Atoms and Variables
– Complex Terms
– Facts & Queries
– Rules
• Examples
What is Prolog?
• Prolog is the most commonly used logic
– Simple syntax
• PROgramming in LOGic
• High-level interactive language.
• Logic programming language.
What is Prolog? (Cont.)
• Programming languages are of two kinds:
– Procedural (BASIC, Pascal, C++, Java);
– Declarative (LISP, Prolog, ML).
• In procedural programming, we tell the computer how
to solve a problem.
• In declarative programming, we tell the computer what
problem we want solved.
• (However, in Prolog, we are often forced to give clues
as to the solution method).
The use of Prolog
• Prolog is used in artificial intelligence applications such as:
– Natural language interfaces,
– automated reasoning systems and
– Expert systems: usually consist of a data base of facts and
rules and an inference engine, the run time system of Prolog
provides much of the services of an inference engine.
What is Prolog used for?
• Good at
– Grammars and Language processing,
– Knowledge representation and reasoning,
– Unification,
– Pattern matching,
– Planning and Search.
• Poor at:
– Repetitive number crunching,
– Representing complex data structures,
– Input/Output (interfaces).
Basic Elements of Prolog
• A program consists of clauses. These are of 3 types: facts, rules,
and questions (Queries).
• Some are always true (facts):
father( ali, haya).
• Some are dependent on others being true (rules):
parent( Person1, Person2 ) :- father( Person1, Person2 ).
• To run a program, we ask questions about the database.
KB
Prolog
Interpreter
Query
Answer
Prolog in English• Example Database:
– Saleh is a teacher
– Nora is a teacher
– Saleh is the father of Jaber.
– Nora is the mother of Jaber.
– Hamza is the father of Saleh
– Person 1 is a parent of Person 2 if
Person 1 is the father of Person 2 or
Person 1 is the mother of Person 2.
– Person 1 is a grandparent of Person 2 if
some Person 3 is a parent of Person 2 and
Person 1 is a parent of Person 3.
• Example questions:
– Who is Jaber's father?
– Is Nora the mother of Jaber?
– Does Hamza have a grandchild?
Facts
Rules
A knowledge base of facts
• teacher(saleh).
• teacher(nora).
• father( saleh, jaber).
• mother( nora, jaber ).
• father( hamza, saleh ).
Queries we can ask
?- teacher(saleh). Yes
?- teacher(nora). Yes
?- mother( nora, jaber ). Yes
?- mother( nora, saleh ). No
?- grandparent( hamza, X). Jaber
?- nurse(nora).
ERROR: Undefined procedure: nurse/1
More queries we can ask
• ?-teacher(X).
– X=saleh ;
– X=nora ;
– No.
• ?-mother(X,Y).
– X = nora
– Y = jaber ;
– No
Syntax: Atoms and Variables
• Atoms:
– All terms that consist of letters, numbers, and the underscore
and start with a non-capital letter are atoms: uncle_ali, nora,
year2007, . . . .
– All terms that are enclosed in single quotes are atoms:
’Aunt Hiba’, ’(@ *+ ’, . . . .
– Certain special symbols are also atoms: +, ,, . . . .
• Variables:
– All terms that consist of letters, numbers, and the underscore
and start with a capital letter or an underscore are variables:
X, Jaber, Lama, . . . .
– _is an anonymous variable: two occurrences of _are different
variables.
– E.g. if we are interested in people who have children, but not
in the name of the children, then we can simply ask: ?-
parent(X,_).
Syntax: Complex Terms
• Complex terms
– Complex terms are of the form:
functor (argument, ..., argument).
– Functors have to be atoms.
– Arguments can be any kind of Prolog term, e.g., complex
terms.
• likes(lama,apples), likes(amy,X).
Syntax: Facts & Queries
• Facts are complex terms which begin with lower case alphabetic
letter and ends with a full stop.
– teacher(nora).
– female( aunt hiba).
– likes(alia,choclate).
• Queries are also complex terms followed by a full stop.
– ?- teacher(nora).
Query
Prompt provided by the Prolog interpreter.
Syntax: Rules
• A Prolog rule consists of a head and a body.
a(X) :- b(X), c(X)
• Rules are of the form Head :- Body.
• Like facts and queries, they have to be followed by a full stop.
• Head is a complex term.
• Body is complex term or a sequence of complex terms separated by
commas.
happy(uncle_ yussef) :- happy(nora).
grandparent( Person1, Person2 ) :- parent( Person3, Person2 ) ,
parent( Person1, Person3 ).
head body
A knowledge base of facts & Rules
• happy(uncle_ yussef) :- happy(nora).
if ... then ...: If happy(nora) is true, then happy(uncle_ yussef) is true.
• parent( Person1, Person2 ) :- father( Person1, Person2 ).
• parent( Person1, Person2 ) :- mother( Person1, Person2 ).
Person 1 is a parent of Person 2 if Person 1 is the father of Person 2
or Person 1 is the mother of Person 2.
• grandparent( Person1, Person2 ) :- parent( Person3, Person2 )
, parent( Person1, Person3 ).
Person 1 is a grandparent of Person 2 if some Person 3 is a parent of Person 2
and Person 1 is a parent of Person 3.
Querying slide 15
• ?- happy(nora). Yes
• ?-happy(uncle_yussef). yes
• ?- happy(X).
– X = uncle_yussef ;
– X = nora ;
– No
• Does Hamza have a grandchild?
• ?- grandparent(hamza,_).
– Yes
Facts & Rules containing variables
• teacher(saleh).
• teacher(nora).
• father( saleh, jaber).
• mother( nora, jaber ).
• This knowledge base defines 3 predicates:
– teacher/1.
– father/2, and
– mother/2.
• teacher(X) :- father(Y,X), teacher(Y),mother(Z,X), teacher(Z).
• For all X, Y, Z, if father(Y,X)is true and teacher (Y) is true and
mother(Z,X) is true and teacher (Z) is true, then teacher (X) is true.
• I.e., for all X, if X’s father and mother are teachers,
then X is a teacher.
Summary
• A Prolog program consists of a database of facts and rules, and
queries (questions).
– Fact: ... .
– Rule: ... :- ... .
– Query: ?- ... .
– Variables: must begin with an upper case letter or underscore.
• Nora, _nora.
– Constants (atoms): begin with lowercase letter, or enclosed in
single quotes.
• uncle_ali, nora, year2007, .
• numbers 3, 6, 2957, 8.34, ...
– complex terms An atom (the functor) is followed by a comma
separated sequence of Prolog terms enclosed in parenthesis (the
arguments).
• likes(lama,apples), likes(amy,X).

More Related Content

Viewers also liked

Skyi Aquila Brochure - Zricks.com
Skyi Aquila Brochure - Zricks.comSkyi Aquila Brochure - Zricks.com
Skyi Aquila Brochure - Zricks.com
Zricks.com
 
Arge Helios Brochure - Zricks.com
Arge Helios Brochure - Zricks.comArge Helios Brochure - Zricks.com
Arge Helios Brochure - Zricks.com
Zricks.com
 
Bren Starlight Brochure - Zricks.com
Bren Starlight Brochure - Zricks.comBren Starlight Brochure - Zricks.com
Bren Starlight Brochure - Zricks.com
Zricks.com
 
Reach 3 Roads Brochure - Zricks.com
Reach 3 Roads Brochure - Zricks.comReach 3 Roads Brochure - Zricks.com
Reach 3 Roads Brochure - Zricks.com
Zricks.com
 
Bren Woods Brochure - Zricks.com
Bren Woods Brochure - Zricks.comBren Woods Brochure - Zricks.com
Bren Woods Brochure - Zricks.com
Zricks.com
 
Rohan Abhilasha Brochure - Zricks.com
Rohan Abhilasha Brochure - Zricks.comRohan Abhilasha Brochure - Zricks.com
Rohan Abhilasha Brochure - Zricks.com
Zricks.com
 
Ozone Pinnacle Brochure - Zricks.com
Ozone Pinnacle Brochure - Zricks.comOzone Pinnacle Brochure - Zricks.com
Ozone Pinnacle Brochure - Zricks.com
Zricks.com
 
Asset Alcazra Brochure - Zricks.com
Asset Alcazra Brochure - Zricks.comAsset Alcazra Brochure - Zricks.com
Asset Alcazra Brochure - Zricks.com
Zricks.com
 
Supertech Crown Tower Brochure - Zricks.com
Supertech Crown Tower Brochure - Zricks.comSupertech Crown Tower Brochure - Zricks.com
Supertech Crown Tower Brochure - Zricks.com
Zricks.com
 
Adani Marathon Monte South Brochure - Zricks.com
Adani Marathon Monte South Brochure - Zricks.comAdani Marathon Monte South Brochure - Zricks.com
Adani Marathon Monte South Brochure - Zricks.com
Zricks.com
 
Radisu Parkwoods at Anantya Brochure - Zricks.com
Radisu Parkwoods at Anantya Brochure - Zricks.comRadisu Parkwoods at Anantya Brochure - Zricks.com
Radisu Parkwoods at Anantya Brochure - Zricks.com
Zricks.com
 
Spenta Palazzio Brochure - Zricks.com
Spenta Palazzio Brochure - Zricks.comSpenta Palazzio Brochure - Zricks.com
Spenta Palazzio Brochure - Zricks.com
Zricks.com
 
Spenta Towers Brochure - Zricks.com
Spenta Towers Brochure - Zricks.comSpenta Towers Brochure - Zricks.com
Spenta Towers Brochure - Zricks.com
Zricks.com
 

Viewers also liked (13)

Skyi Aquila Brochure - Zricks.com
Skyi Aquila Brochure - Zricks.comSkyi Aquila Brochure - Zricks.com
Skyi Aquila Brochure - Zricks.com
 
Arge Helios Brochure - Zricks.com
Arge Helios Brochure - Zricks.comArge Helios Brochure - Zricks.com
Arge Helios Brochure - Zricks.com
 
Bren Starlight Brochure - Zricks.com
Bren Starlight Brochure - Zricks.comBren Starlight Brochure - Zricks.com
Bren Starlight Brochure - Zricks.com
 
Reach 3 Roads Brochure - Zricks.com
Reach 3 Roads Brochure - Zricks.comReach 3 Roads Brochure - Zricks.com
Reach 3 Roads Brochure - Zricks.com
 
Bren Woods Brochure - Zricks.com
Bren Woods Brochure - Zricks.comBren Woods Brochure - Zricks.com
Bren Woods Brochure - Zricks.com
 
Rohan Abhilasha Brochure - Zricks.com
Rohan Abhilasha Brochure - Zricks.comRohan Abhilasha Brochure - Zricks.com
Rohan Abhilasha Brochure - Zricks.com
 
Ozone Pinnacle Brochure - Zricks.com
Ozone Pinnacle Brochure - Zricks.comOzone Pinnacle Brochure - Zricks.com
Ozone Pinnacle Brochure - Zricks.com
 
Asset Alcazra Brochure - Zricks.com
Asset Alcazra Brochure - Zricks.comAsset Alcazra Brochure - Zricks.com
Asset Alcazra Brochure - Zricks.com
 
Supertech Crown Tower Brochure - Zricks.com
Supertech Crown Tower Brochure - Zricks.comSupertech Crown Tower Brochure - Zricks.com
Supertech Crown Tower Brochure - Zricks.com
 
Adani Marathon Monte South Brochure - Zricks.com
Adani Marathon Monte South Brochure - Zricks.comAdani Marathon Monte South Brochure - Zricks.com
Adani Marathon Monte South Brochure - Zricks.com
 
Radisu Parkwoods at Anantya Brochure - Zricks.com
Radisu Parkwoods at Anantya Brochure - Zricks.comRadisu Parkwoods at Anantya Brochure - Zricks.com
Radisu Parkwoods at Anantya Brochure - Zricks.com
 
Spenta Palazzio Brochure - Zricks.com
Spenta Palazzio Brochure - Zricks.comSpenta Palazzio Brochure - Zricks.com
Spenta Palazzio Brochure - Zricks.com
 
Spenta Towers Brochure - Zricks.com
Spenta Towers Brochure - Zricks.comSpenta Towers Brochure - Zricks.com
Spenta Towers Brochure - Zricks.com
 

Similar to Introduction toprolog

Chaps 1-3-ai-prolog
Chaps 1-3-ai-prologChaps 1-3-ai-prolog
Chaps 1-3-ai-prolog
saru40
 
10 logic+programming+with+prolog
10 logic+programming+with+prolog10 logic+programming+with+prolog
10 logic+programming+with+prolog
baran19901990
 
Prolog final
Prolog finalProlog final
Prolog final
Hassaan Ahmad
 
Plc part 4
Plc  part 4Plc  part 4
Plc part 4
Taymoor Nazmy
 
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...
Ravi Agrawal
 
Ics1019 ics5003
Ics1019 ics5003Ics1019 ics5003
Ics1019 ics5003
Matt Montebello
 
An introduction to Prolog language slide
An introduction to Prolog language slideAn introduction to Prolog language slide
An introduction to Prolog language slide
2021uam4641
 
Artificial Intelligence Notes Unit 4
Artificial Intelligence Notes Unit 4Artificial Intelligence Notes Unit 4
Artificial Intelligence Notes Unit 4
DigiGurukul
 
ProLog (Artificial Intelligence) Introduction
ProLog (Artificial Intelligence) IntroductionProLog (Artificial Intelligence) Introduction
ProLog (Artificial Intelligence) Introduction
wahab khan
 
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
DrBhagirathPrajapati
 
Syntax.ppt
Syntax.pptSyntax.ppt
Syntax.ppt
KhenAguinillo
 
predicateLogic.ppt
predicateLogic.pptpredicateLogic.ppt
predicateLogic.ppt
MUZAMILALI48
 
Predlogic
PredlogicPredlogic
Predlogic
saru40
 
Artificial intelligence course work
Artificial intelligence  course workArtificial intelligence  course work
Artificial intelligence course work
Infinity Tech Solutions
 
#8 formal methods – pro logic
#8 formal methods – pro logic#8 formal methods – pro logic
#8 formal methods – pro logic
Sharif Omar Salem
 
Fuzzy mathematics:An application oriented introduction
Fuzzy mathematics:An application oriented introductionFuzzy mathematics:An application oriented introduction
Fuzzy mathematics:An application oriented introduction
Nagasuri Bala Venkateswarlu
 
Learning rule of first order rules
Learning rule of first order rulesLearning rule of first order rules
Learning rule of first order rules
swapnac12
 
Language Model (N-Gram).pptx
Language Model (N-Gram).pptxLanguage Model (N-Gram).pptx
Language Model (N-Gram).pptx
HeneWijaya
 
lect4-morphology.ppt
lect4-morphology.pptlect4-morphology.ppt
lect4-morphology.ppt
Waqar Ahmed Memon
 
lect4-morphology.pptx
lect4-morphology.pptxlect4-morphology.pptx
lect4-morphology.pptx
SahilAli23165
 

Similar to Introduction toprolog (20)

Chaps 1-3-ai-prolog
Chaps 1-3-ai-prologChaps 1-3-ai-prolog
Chaps 1-3-ai-prolog
 
10 logic+programming+with+prolog
10 logic+programming+with+prolog10 logic+programming+with+prolog
10 logic+programming+with+prolog
 
Prolog final
Prolog finalProlog final
Prolog final
 
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...
 
Ics1019 ics5003
Ics1019 ics5003Ics1019 ics5003
Ics1019 ics5003
 
An introduction to Prolog language slide
An introduction to Prolog language slideAn introduction to Prolog language slide
An introduction to Prolog language slide
 
Artificial Intelligence Notes Unit 4
Artificial Intelligence Notes Unit 4Artificial Intelligence Notes Unit 4
Artificial Intelligence Notes Unit 4
 
ProLog (Artificial Intelligence) Introduction
ProLog (Artificial Intelligence) IntroductionProLog (Artificial Intelligence) Introduction
ProLog (Artificial Intelligence) Introduction
 
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
 
Syntax.ppt
Syntax.pptSyntax.ppt
Syntax.ppt
 
predicateLogic.ppt
predicateLogic.pptpredicateLogic.ppt
predicateLogic.ppt
 
Predlogic
PredlogicPredlogic
Predlogic
 
Artificial intelligence course work
Artificial intelligence  course workArtificial intelligence  course work
Artificial intelligence course work
 
#8 formal methods – pro logic
#8 formal methods – pro logic#8 formal methods – pro logic
#8 formal methods – pro logic
 
Fuzzy mathematics:An application oriented introduction
Fuzzy mathematics:An application oriented introductionFuzzy mathematics:An application oriented introduction
Fuzzy mathematics:An application oriented introduction
 
Learning rule of first order rules
Learning rule of first order rulesLearning rule of first order rules
Learning rule of first order rules
 
Language Model (N-Gram).pptx
Language Model (N-Gram).pptxLanguage Model (N-Gram).pptx
Language Model (N-Gram).pptx
 
lect4-morphology.ppt
lect4-morphology.pptlect4-morphology.ppt
lect4-morphology.ppt
 
lect4-morphology.pptx
lect4-morphology.pptxlect4-morphology.pptx
lect4-morphology.pptx
 

More from Young Alista

Google appenginejava.ppt
Google appenginejava.pptGoogle appenginejava.ppt
Google appenginejava.ppt
Young Alista
 
Motivation for multithreaded architectures
Motivation for multithreaded architecturesMotivation for multithreaded architectures
Motivation for multithreaded architectures
Young Alista
 
Serialization/deserialization
Serialization/deserializationSerialization/deserialization
Serialization/deserialization
Young Alista
 
Big picture of data mining
Big picture of data miningBig picture of data mining
Big picture of data mining
Young Alista
 
Business analytics and data mining
Business analytics and data miningBusiness analytics and data mining
Business analytics and data mining
Young Alista
 
Data mining and knowledge discovery
Data mining and knowledge discoveryData mining and knowledge discovery
Data mining and knowledge discovery
Young Alista
 
Directory based cache coherence
Directory based cache coherenceDirectory based cache coherence
Directory based cache coherence
Young Alista
 
Hardware managed cache
Hardware managed cacheHardware managed cache
Hardware managed cache
Young Alista
 
How analysis services caching works
How analysis services caching worksHow analysis services caching works
How analysis services caching works
Young Alista
 
Optimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessorsOptimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessors
Young Alista
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
Young Alista
 
Abstraction file
Abstraction fileAbstraction file
Abstraction file
Young Alista
 
Concurrency with java
Concurrency with javaConcurrency with java
Concurrency with java
Young Alista
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
Young Alista
 
Cobol, lisp, and python
Cobol, lisp, and pythonCobol, lisp, and python
Cobol, lisp, and python
Young Alista
 
Object oriented analysis
Object oriented analysisObject oriented analysis
Object oriented analysis
Young Alista
 

More from Young Alista (20)

Google appenginejava.ppt
Google appenginejava.pptGoogle appenginejava.ppt
Google appenginejava.ppt
 
Motivation for multithreaded architectures
Motivation for multithreaded architecturesMotivation for multithreaded architectures
Motivation for multithreaded architectures
 
Serialization/deserialization
Serialization/deserializationSerialization/deserialization
Serialization/deserialization
 
Big picture of data mining
Big picture of data miningBig picture of data mining
Big picture of data mining
 
Business analytics and data mining
Business analytics and data miningBusiness analytics and data mining
Business analytics and data mining
 
Data mining and knowledge discovery
Data mining and knowledge discoveryData mining and knowledge discovery
Data mining and knowledge discovery
 
Directory based cache coherence
Directory based cache coherenceDirectory based cache coherence
Directory based cache coherence
 
Cache recap
Cache recapCache recap
Cache recap
 
Hardware managed cache
Hardware managed cacheHardware managed cache
Hardware managed cache
 
How analysis services caching works
How analysis services caching worksHow analysis services caching works
How analysis services caching works
 
Object model
Object modelObject model
Object model
 
Optimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessorsOptimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessors
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
 
Abstraction file
Abstraction fileAbstraction file
Abstraction file
 
Concurrency with java
Concurrency with javaConcurrency with java
Concurrency with java
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
 
Abstract class
Abstract classAbstract class
Abstract class
 
Inheritance
InheritanceInheritance
Inheritance
 
Cobol, lisp, and python
Cobol, lisp, and pythonCobol, lisp, and python
Cobol, lisp, and python
 
Object oriented analysis
Object oriented analysisObject oriented analysis
Object oriented analysis
 

Recently uploaded

To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
Fwdays
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 

Recently uploaded (20)

To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 

Introduction toprolog

  • 2. Outline • What is Prolog? • Prolog basics • Prolog Demo • Syntax: – Atoms and Variables – Complex Terms – Facts & Queries – Rules • Examples
  • 3. What is Prolog? • Prolog is the most commonly used logic – Simple syntax • PROgramming in LOGic • High-level interactive language. • Logic programming language.
  • 4. What is Prolog? (Cont.) • Programming languages are of two kinds: – Procedural (BASIC, Pascal, C++, Java); – Declarative (LISP, Prolog, ML). • In procedural programming, we tell the computer how to solve a problem. • In declarative programming, we tell the computer what problem we want solved. • (However, in Prolog, we are often forced to give clues as to the solution method).
  • 5. The use of Prolog • Prolog is used in artificial intelligence applications such as: – Natural language interfaces, – automated reasoning systems and – Expert systems: usually consist of a data base of facts and rules and an inference engine, the run time system of Prolog provides much of the services of an inference engine.
  • 6. What is Prolog used for? • Good at – Grammars and Language processing, – Knowledge representation and reasoning, – Unification, – Pattern matching, – Planning and Search. • Poor at: – Repetitive number crunching, – Representing complex data structures, – Input/Output (interfaces).
  • 7. Basic Elements of Prolog • A program consists of clauses. These are of 3 types: facts, rules, and questions (Queries). • Some are always true (facts): father( ali, haya). • Some are dependent on others being true (rules): parent( Person1, Person2 ) :- father( Person1, Person2 ). • To run a program, we ask questions about the database. KB Prolog Interpreter Query Answer
  • 8. Prolog in English• Example Database: – Saleh is a teacher – Nora is a teacher – Saleh is the father of Jaber. – Nora is the mother of Jaber. – Hamza is the father of Saleh – Person 1 is a parent of Person 2 if Person 1 is the father of Person 2 or Person 1 is the mother of Person 2. – Person 1 is a grandparent of Person 2 if some Person 3 is a parent of Person 2 and Person 1 is a parent of Person 3. • Example questions: – Who is Jaber's father? – Is Nora the mother of Jaber? – Does Hamza have a grandchild? Facts Rules
  • 9. A knowledge base of facts • teacher(saleh). • teacher(nora). • father( saleh, jaber). • mother( nora, jaber ). • father( hamza, saleh ). Queries we can ask ?- teacher(saleh). Yes ?- teacher(nora). Yes ?- mother( nora, jaber ). Yes ?- mother( nora, saleh ). No ?- grandparent( hamza, X). Jaber ?- nurse(nora). ERROR: Undefined procedure: nurse/1
  • 10. More queries we can ask • ?-teacher(X). – X=saleh ; – X=nora ; – No. • ?-mother(X,Y). – X = nora – Y = jaber ; – No
  • 11. Syntax: Atoms and Variables • Atoms: – All terms that consist of letters, numbers, and the underscore and start with a non-capital letter are atoms: uncle_ali, nora, year2007, . . . . – All terms that are enclosed in single quotes are atoms: ’Aunt Hiba’, ’(@ *+ ’, . . . . – Certain special symbols are also atoms: +, ,, . . . . • Variables: – All terms that consist of letters, numbers, and the underscore and start with a capital letter or an underscore are variables: X, Jaber, Lama, . . . . – _is an anonymous variable: two occurrences of _are different variables. – E.g. if we are interested in people who have children, but not in the name of the children, then we can simply ask: ?- parent(X,_).
  • 12. Syntax: Complex Terms • Complex terms – Complex terms are of the form: functor (argument, ..., argument). – Functors have to be atoms. – Arguments can be any kind of Prolog term, e.g., complex terms. • likes(lama,apples), likes(amy,X).
  • 13. Syntax: Facts & Queries • Facts are complex terms which begin with lower case alphabetic letter and ends with a full stop. – teacher(nora). – female( aunt hiba). – likes(alia,choclate). • Queries are also complex terms followed by a full stop. – ?- teacher(nora). Query Prompt provided by the Prolog interpreter.
  • 14. Syntax: Rules • A Prolog rule consists of a head and a body. a(X) :- b(X), c(X) • Rules are of the form Head :- Body. • Like facts and queries, they have to be followed by a full stop. • Head is a complex term. • Body is complex term or a sequence of complex terms separated by commas. happy(uncle_ yussef) :- happy(nora). grandparent( Person1, Person2 ) :- parent( Person3, Person2 ) , parent( Person1, Person3 ). head body
  • 15. A knowledge base of facts & Rules • happy(uncle_ yussef) :- happy(nora). if ... then ...: If happy(nora) is true, then happy(uncle_ yussef) is true. • parent( Person1, Person2 ) :- father( Person1, Person2 ). • parent( Person1, Person2 ) :- mother( Person1, Person2 ). Person 1 is a parent of Person 2 if Person 1 is the father of Person 2 or Person 1 is the mother of Person 2. • grandparent( Person1, Person2 ) :- parent( Person3, Person2 ) , parent( Person1, Person3 ). Person 1 is a grandparent of Person 2 if some Person 3 is a parent of Person 2 and Person 1 is a parent of Person 3.
  • 16. Querying slide 15 • ?- happy(nora). Yes • ?-happy(uncle_yussef). yes • ?- happy(X). – X = uncle_yussef ; – X = nora ; – No • Does Hamza have a grandchild? • ?- grandparent(hamza,_). – Yes
  • 17. Facts & Rules containing variables • teacher(saleh). • teacher(nora). • father( saleh, jaber). • mother( nora, jaber ). • This knowledge base defines 3 predicates: – teacher/1. – father/2, and – mother/2. • teacher(X) :- father(Y,X), teacher(Y),mother(Z,X), teacher(Z). • For all X, Y, Z, if father(Y,X)is true and teacher (Y) is true and mother(Z,X) is true and teacher (Z) is true, then teacher (X) is true. • I.e., for all X, if X’s father and mother are teachers, then X is a teacher.
  • 18. Summary • A Prolog program consists of a database of facts and rules, and queries (questions). – Fact: ... . – Rule: ... :- ... . – Query: ?- ... . – Variables: must begin with an upper case letter or underscore. • Nora, _nora. – Constants (atoms): begin with lowercase letter, or enclosed in single quotes. • uncle_ali, nora, year2007, . • numbers 3, 6, 2957, 8.34, ... – complex terms An atom (the functor) is followed by a comma separated sequence of Prolog terms enclosed in parenthesis (the arguments). • likes(lama,apples), likes(amy,X).