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

Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programmingJames Wong
 
Puasa dan pendidikan karakter
Puasa dan pendidikan karakterPuasa dan pendidikan karakter
Puasa dan pendidikan karakterSuyanto Suyanto
 
Kecemasan kurikulum 2013
Kecemasan kurikulum 2013Kecemasan kurikulum 2013
Kecemasan kurikulum 2013Suyanto Suyanto
 
Heil jebus
Heil jebusHeil jebus
Heil jebuschitut
 
Computer security
Computer securityComputer security
Computer securityJames Wong
 
Vaak komen vaders bij me met de vraag hoe ze de relatie met hun stiefkinderen...
Vaak komen vaders bij me met de vraag hoe ze de relatie met hun stiefkinderen...Vaak komen vaders bij me met de vraag hoe ze de relatie met hun stiefkinderen...
Vaak komen vaders bij me met de vraag hoe ze de relatie met hun stiefkinderen...Ervin Molnár
 
Ada yang menolak kurikulum
Ada yang menolak kurikulum Ada yang menolak kurikulum
Ada yang menolak kurikulum Suyanto Suyanto
 
ลงทุนออนไลน์ (Internet trading)
ลงทุนออนไลน์ (Internet trading)ลงทุนออนไลน์ (Internet trading)
ลงทุนออนไลน์ (Internet trading)Peerapat Teerawattanasuk
 
Memory basic concept hierarchy and cache memory 1
Memory basic concept hierarchy and cache memory 1Memory basic concept hierarchy and cache memory 1
Memory basic concept hierarchy and cache memory 1Asif Iqbal
 
Text Classification/Categorization
Text Classification/CategorizationText Classification/Categorization
Text Classification/CategorizationOswal Abhishek
 
การเข้าใช้งานโปรแกรม Streaming pro
การเข้าใช้งานโปรแกรม Streaming proการเข้าใช้งานโปรแกรม Streaming pro
การเข้าใช้งานโปรแกรม Streaming proPeerapat Teerawattanasuk
 
Database introduction
Database introductionDatabase introduction
Database introductionYoung Alista
 
Stacks queues lists
Stacks queues listsStacks queues lists
Stacks queues listsYoung Alista
 
การแจกแจงความน่าจะเป็น
การแจกแจงความน่าจะเป็นการแจกแจงความน่าจะเป็น
การแจกแจงความน่าจะเป็นSariffuddeen Samoh
 

Viewers also liked (19)

Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
Puasa dan pendidikan karakter
Puasa dan pendidikan karakterPuasa dan pendidikan karakter
Puasa dan pendidikan karakter
 
Maven
MavenMaven
Maven
 
Kecemasan kurikulum 2013
Kecemasan kurikulum 2013Kecemasan kurikulum 2013
Kecemasan kurikulum 2013
 
it
itit
it
 
Heil jebus
Heil jebusHeil jebus
Heil jebus
 
Computer security
Computer securityComputer security
Computer security
 
Vaak komen vaders bij me met de vraag hoe ze de relatie met hun stiefkinderen...
Vaak komen vaders bij me met de vraag hoe ze de relatie met hun stiefkinderen...Vaak komen vaders bij me met de vraag hoe ze de relatie met hun stiefkinderen...
Vaak komen vaders bij me met de vraag hoe ze de relatie met hun stiefkinderen...
 
Ada yang menolak kurikulum
Ada yang menolak kurikulum Ada yang menolak kurikulum
Ada yang menolak kurikulum
 
ลงทุนออนไลน์ (Internet trading)
ลงทุนออนไลน์ (Internet trading)ลงทุนออนไลน์ (Internet trading)
ลงทุนออนไลน์ (Internet trading)
 
Aportes en foros
Aportes en forosAportes en foros
Aportes en foros
 
Memory basic concept hierarchy and cache memory 1
Memory basic concept hierarchy and cache memory 1Memory basic concept hierarchy and cache memory 1
Memory basic concept hierarchy and cache memory 1
 
Text Classification/Categorization
Text Classification/CategorizationText Classification/Categorization
Text Classification/Categorization
 
Presentaciones Efectivas
Presentaciones EfectivasPresentaciones Efectivas
Presentaciones Efectivas
 
การเข้าใช้งานโปรแกรม Streaming pro
การเข้าใช้งานโปรแกรม Streaming proการเข้าใช้งานโปรแกรม Streaming pro
การเข้าใช้งานโปรแกรม Streaming pro
 
Database introduction
Database introductionDatabase introduction
Database introduction
 
Big data
Big dataBig data
Big data
 
Stacks queues lists
Stacks queues listsStacks queues lists
Stacks queues lists
 
การแจกแจงความน่าจะเป็น
การแจกแจงความน่าจะเป็นการแจกแจงความน่าจะเป็น
การแจกแจงความน่าจะเป็น
 

Similar to Introduction to Prolog

Chaps 1-3-ai-prolog
Chaps 1-3-ai-prologChaps 1-3-ai-prolog
Chaps 1-3-ai-prologsaru40
 
10 logic+programming+with+prolog
10 logic+programming+with+prolog10 logic+programming+with+prolog
10 logic+programming+with+prologbaran19901990
 
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
 
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 Notes Unit 4
Artificial Intelligence Notes Unit 4Artificial Intelligence Notes Unit 4
Artificial Intelligence Notes Unit 4DigiGurukul
 
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
 
predicateLogic.ppt
predicateLogic.pptpredicateLogic.ppt
predicateLogic.pptMUZAMILALI48
 
Predlogic
PredlogicPredlogic
Predlogicsaru40
 
#8 formal methods – pro logic
#8 formal methods – pro logic#8 formal methods – pro logic
#8 formal methods – pro logicSharif Omar Salem
 
Fuzzy mathematics:An application oriented introduction
Fuzzy mathematics:An application oriented introductionFuzzy mathematics:An application oriented introduction
Fuzzy mathematics:An application oriented introductionNagasuri Bala Venkateswarlu
 
Learning rule of first order rules
Learning rule of first order rulesLearning rule of first order rules
Learning rule of first order rulesswapnac12
 
Language Model (N-Gram).pptx
Language Model (N-Gram).pptxLanguage Model (N-Gram).pptx
Language Model (N-Gram).pptxHeneWijaya
 
lect4-morphology.ppt
lect4-morphology.pptlect4-morphology.ppt
lect4-morphology.pptKrismalita
 
lect4-morphology.pptx
lect4-morphology.pptxlect4-morphology.pptx
lect4-morphology.pptxSahilAli23165
 

Similar to Introduction to Prolog (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 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.ppt
lect4-morphology.pptlect4-morphology.ppt
lect4-morphology.ppt
 
lect4-morphology.pptx
lect4-morphology.pptxlect4-morphology.pptx
lect4-morphology.pptx
 

More from James Wong

Multi threaded rtos
Multi threaded rtosMulti threaded rtos
Multi threaded rtosJames Wong
 
Business analytics and data mining
Business analytics and data miningBusiness analytics and data mining
Business analytics and data miningJames Wong
 
Data mining and knowledge discovery
Data mining and knowledge discoveryData mining and knowledge discovery
Data mining and knowledge discoveryJames Wong
 
Big picture of data mining
Big picture of data miningBig picture of data mining
Big picture of data miningJames Wong
 
How analysis services caching works
How analysis services caching worksHow analysis services caching works
How analysis services caching worksJames Wong
 
Optimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessorsOptimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessorsJames Wong
 
Directory based cache coherence
Directory based cache coherenceDirectory based cache coherence
Directory based cache coherenceJames Wong
 
Abstract data types
Abstract data typesAbstract data types
Abstract data typesJames Wong
 
Abstraction file
Abstraction fileAbstraction file
Abstraction fileJames Wong
 
Hardware managed cache
Hardware managed cacheHardware managed cache
Hardware managed cacheJames Wong
 
Abstract class
Abstract classAbstract class
Abstract classJames Wong
 
Object oriented analysis
Object oriented analysisObject oriented analysis
Object oriented analysisJames Wong
 
Concurrency with java
Concurrency with javaConcurrency with java
Concurrency with javaJames Wong
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithmsJames Wong
 
Cobol, lisp, and python
Cobol, lisp, and pythonCobol, lisp, and python
Cobol, lisp, and pythonJames Wong
 

More from James Wong (20)

Data race
Data raceData race
Data race
 
Multi threaded rtos
Multi threaded rtosMulti threaded rtos
Multi threaded rtos
 
Recursion
RecursionRecursion
Recursion
 
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
 
Cache recap
Cache recapCache recap
Cache recap
 
Big picture of data mining
Big picture of data miningBig picture of data mining
Big picture of data mining
 
How analysis services caching works
How analysis services caching worksHow analysis services caching works
How analysis services caching works
 
Optimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessorsOptimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessors
 
Directory based cache coherence
Directory based cache coherenceDirectory based cache coherence
Directory based cache coherence
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
 
Abstraction file
Abstraction fileAbstraction file
Abstraction file
 
Hardware managed cache
Hardware managed cacheHardware managed cache
Hardware managed cache
 
Object model
Object modelObject model
Object model
 
Abstract class
Abstract classAbstract class
Abstract class
 
Object oriented analysis
Object oriented analysisObject oriented analysis
Object oriented analysis
 
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
 
Cobol, lisp, and python
Cobol, lisp, and pythonCobol, lisp, and python
Cobol, lisp, and python
 
Inheritance
InheritanceInheritance
Inheritance
 

Recently uploaded

Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 

Recently uploaded (20)

Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 

Introduction to Prolog

  • 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).