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

Skyi Aquila Brochure - Zricks.com
Skyi Aquila Brochure - Zricks.comSkyi Aquila Brochure - Zricks.com
Skyi Aquila Brochure - Zricks.comZricks.com
 
Arge Helios Brochure - Zricks.com
Arge Helios Brochure - Zricks.comArge Helios Brochure - Zricks.com
Arge Helios Brochure - Zricks.comZricks.com
 
Bren Starlight Brochure - Zricks.com
Bren Starlight Brochure - Zricks.comBren Starlight Brochure - Zricks.com
Bren Starlight Brochure - Zricks.comZricks.com
 
Reach 3 Roads Brochure - Zricks.com
Reach 3 Roads Brochure - Zricks.comReach 3 Roads Brochure - Zricks.com
Reach 3 Roads Brochure - Zricks.comZricks.com
 
Bren Woods Brochure - Zricks.com
Bren Woods Brochure - Zricks.comBren Woods Brochure - Zricks.com
Bren Woods Brochure - Zricks.comZricks.com
 
Rohan Abhilasha Brochure - Zricks.com
Rohan Abhilasha Brochure - Zricks.comRohan Abhilasha Brochure - Zricks.com
Rohan Abhilasha Brochure - Zricks.comZricks.com
 
Ozone Pinnacle Brochure - Zricks.com
Ozone Pinnacle Brochure - Zricks.comOzone Pinnacle Brochure - Zricks.com
Ozone Pinnacle Brochure - Zricks.comZricks.com
 
Asset Alcazra Brochure - Zricks.com
Asset Alcazra Brochure - Zricks.comAsset Alcazra Brochure - Zricks.com
Asset Alcazra Brochure - Zricks.comZricks.com
 
Supertech Crown Tower Brochure - Zricks.com
Supertech Crown Tower Brochure - Zricks.comSupertech Crown Tower Brochure - Zricks.com
Supertech Crown Tower Brochure - Zricks.comZricks.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.comZricks.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.comZricks.com
 
Spenta Palazzio Brochure - Zricks.com
Spenta Palazzio Brochure - Zricks.comSpenta Palazzio Brochure - Zricks.com
Spenta Palazzio Brochure - Zricks.comZricks.com
 
Spenta Towers Brochure - Zricks.com
Spenta Towers Brochure - Zricks.comSpenta Towers Brochure - Zricks.com
Spenta Towers Brochure - Zricks.comZricks.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-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 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 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 Young Alista

Google appenginejava.ppt
Google appenginejava.pptGoogle appenginejava.ppt
Google appenginejava.pptYoung Alista
 
Motivation for multithreaded architectures
Motivation for multithreaded architecturesMotivation for multithreaded architectures
Motivation for multithreaded architecturesYoung Alista
 
Serialization/deserialization
Serialization/deserializationSerialization/deserialization
Serialization/deserializationYoung Alista
 
Big picture of data mining
Big picture of data miningBig picture of data mining
Big picture of data miningYoung Alista
 
Business analytics and data mining
Business analytics and data miningBusiness analytics and data mining
Business analytics and data miningYoung Alista
 
Data mining and knowledge discovery
Data mining and knowledge discoveryData mining and knowledge discovery
Data mining and knowledge discoveryYoung Alista
 
Directory based cache coherence
Directory based cache coherenceDirectory based cache coherence
Directory based cache coherenceYoung Alista
 
Hardware managed cache
Hardware managed cacheHardware managed cache
Hardware managed cacheYoung Alista
 
How analysis services caching works
How analysis services caching worksHow analysis services caching works
How analysis services caching worksYoung Alista
 
Optimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessorsOptimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessorsYoung Alista
 
Abstract data types
Abstract data typesAbstract data types
Abstract data typesYoung Alista
 
Concurrency with java
Concurrency with javaConcurrency with java
Concurrency with javaYoung Alista
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithmsYoung Alista
 
Cobol, lisp, and python
Cobol, lisp, and pythonCobol, lisp, and python
Cobol, lisp, and pythonYoung Alista
 
Object oriented analysis
Object oriented analysisObject oriented analysis
Object oriented analysisYoung 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

[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
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
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
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
 
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
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
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
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
#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
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
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
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 

Recently uploaded (20)

[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
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
 
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
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
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
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
#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
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
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
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 

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