© Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught...
-
date post
20-Dec-2015 -
Category
Documents
-
view
218 -
download
0
Transcript of © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught...
![Page 1: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/1.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Logic Programming
• About the course– Taught in English– Tuesday: mostly theory– Thursday: practical work [lab]
• Teaching material– Learn Prolog Now!– SWI Prolog interpreter
![Page 2: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/2.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Learn Prolog Now!
![Page 3: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/3.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
SWI Prolog
• Freely available Prolog interpreter
• Works with – Linux, – Windows, or – Mac OS
• There are many more Prolog interpreters
• Not all are ISO compliant
![Page 4: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/4.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Lecture 1
• Theory– Introduction to Prolog– Facts, Rules and Queries– Prolog Syntax
• Exercises– Exercises of LPN chapter 1 – Practical work
![Page 5: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/5.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Aim of this lecture
• Give some simple examples of Prolog programs
• Discuss the three basic constructs in Prolog: – Facts– Rules– Queries
• Introduce other concepts, such as – the role of logic– unification with the help of variables
• Begin the systematic study of Prolog by defining terms, atoms, and variables
![Page 6: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/6.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Prolog
• "Programming with Logic"
• Declarative
• Very different from other (procedural) programming languages
• Good for knowledge-rich tasks
![Page 7: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/7.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
History of Prolog
1972 1977 1980 1980s/1990s 2005
first Prolog interpreter by Colmerauer and Roussel
![Page 8: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/8.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
History of Prolog
1972 1977 1980 1980s/1990s 2005
implementation of DEC10 compiler by
Warren
![Page 9: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/9.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
History of Prolog
1972 1977 1980 1980s/1990s 2005
Definite Clause Grammars implementation by Pereira
and Warren
![Page 10: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/10.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
History of Prolog
1972 1977 1980 1980s/1990s 2005
Prolog grows in popularity especially in Europe and Japan
![Page 11: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/11.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
History of Prolog
1972 1977 1980 1980s/1990s 2005
Prolog used to program natural language
interface in International Space
Station by NASA
![Page 12: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/12.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Basic idea of Prolog
• Describe the situation of interest
• Ask a question
• Prolog logically deduces new facts about the situation we described
• Prolog gives us its deductions back as answers
![Page 13: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/13.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Consequences
• Think declaratively, not procedurally– Challenging– Requires a different mindset
• High-level language– Not as efficient as, say, C– Good for rapid prototyping – Useful in many AI applications
![Page 14: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/14.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Knowledge Base 1
woman(mia).
woman(jody).
woman(yolanda).
playsAirGuitar(jody).
party.
![Page 15: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/15.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Knowledge Base 1
woman(mia).
woman(jody).
woman(yolanda).
playsAirGuitar(jody).
party.
?-
![Page 16: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/16.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Knowledge Base 1
woman(mia).
woman(jody).
woman(yolanda).
playsAirGuitar(jody).
party.
?- woman(mia).
![Page 17: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/17.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Knowledge Base 1
woman(mia).
woman(jody).
woman(yolanda).
playsAirGuitar(jody).
party.
?- woman(mia).
yes
?-
![Page 18: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/18.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Knowledge Base 1
woman(mia).
woman(jody).
woman(yolanda).
playsAirGuitar(jody).
party.
?- woman(mia).
yes
?- playsAirGuitar(jody).
![Page 19: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/19.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Knowledge Base 1
woman(mia).
woman(jody).
woman(yolanda).
playsAirGuitar(jody).
party.
?- woman(mia).
yes
?- playsAirGuitar(jody).
yes
?-
![Page 20: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/20.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Knowledge Base 1
woman(mia).
woman(jody).
woman(yolanda).
playsAirGuitar(jody).
party.
?- woman(mia).
yes
?- playsAirGuitar(jody).
yes
?- playsAirGuitar(mia).
no
![Page 21: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/21.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Knowledge Base 1
woman(mia).
woman(jody).
woman(yolanda).
playsAirGuitar(jody).
party.
?- tattoed(jody).
![Page 22: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/22.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Knowledge Base 1
woman(mia).
woman(jody).
woman(yolanda).
playsAirGuitar(jody).
party.
?- tattoed(jody).
no
?-
![Page 23: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/23.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Knowledge Base 1
woman(mia).
woman(jody).
woman(yolanda).
playsAirGuitar(jody).
party.
?- tattoed(jody).
ERROR: predicate tattoed/1 not defined.
?-
![Page 24: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/24.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Knowledge Base 1
woman(mia).
woman(jody).
woman(yolanda).
playsAirGuitar(jody).
party.
?- party.
![Page 25: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/25.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Knowledge Base 1
woman(mia).
woman(jody).
woman(yolanda).
playsAirGuitar(jody).
party.
?- party.
yes
?-
![Page 26: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/26.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Knowledge Base 1
woman(mia).
woman(jody).
woman(yolanda).
playsAirGuitar(jody).
party.
?- rockConcert.
![Page 27: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/27.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Knowledge Base 1
woman(mia).
woman(jody).
woman(yolanda).
playsAirGuitar(jody).
party.
?- rockConcert.
no
?-
![Page 28: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/28.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Knowledge Base 2
happy(yolanda).
listens2music(mia).
listens2music(yolanda):- happy(yolanda).
playsAirGuitar(mia):- listens2music(mia).
playsAirGuitar(yolanda):- listens2music(yolanda).
![Page 29: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/29.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Knowledge Base 2
happy(yolanda).
listens2music(mia).
listens2music(yolanda):- happy(yolanda).
playsAirGuitar(mia):- listens2music(mia).
playsAirGuitar(yolanda):- listens2music(yolanda).
fact
![Page 30: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/30.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Knowledge Base 2
happy(yolanda).
listens2music(mia).
listens2music(yolanda):- happy(yolanda).
playsAirGuitar(mia):- listens2music(mia).
playsAirGuitar(yolanda):- listens2music(yolanda).
factfact
![Page 31: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/31.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Knowledge Base 2
happy(yolanda).
listens2music(mia).
listens2music(yolanda):- happy(yolanda).
playsAirGuitar(mia):- listens2music(mia).
playsAirGuitar(yolanda):- listens2music(yolanda).
factfact
rule
![Page 32: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/32.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Knowledge Base 2
happy(yolanda).
listens2music(mia).
listens2music(yolanda):- happy(yolanda).
playsAirGuitar(mia):- listens2music(mia).
playsAirGuitar(yolanda):- listens2music(yolanda).
factfact
rulerule
![Page 33: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/33.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Knowledge Base 2
happy(yolanda).
listens2music(mia).
listens2music(yolanda):- happy(yolanda).
playsAirGuitar(mia):- listens2music(mia).
playsAirGuitar(yolanda):- listens2music(yolanda).
factfact
rulerule
rule
![Page 34: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/34.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Knowledge Base 2
happy(yolanda).
listens2music(mia).
listens2music(yolanda):- happy(yolanda).
playsAirGuitar(mia):- listens2music(mia).
playsAirGuitar(yolanda):- listens2music(yolanda).
head body
![Page 35: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/35.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Knowledge Base 2
happy(yolanda).
listens2music(mia).
listens2music(yolanda):- happy(yolanda).
playsAirGuitar(mia):- listens2music(mia).
playsAirGuitar(yolanda):- listens2music(yolanda).
?-
![Page 36: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/36.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Knowledge Base 2
happy(yolanda).
listens2music(mia).
listens2music(yolanda):- happy(yolanda).
playsAirGuitar(mia):- listens2music(mia).
playsAirGuitar(yolanda):- listens2music(yolanda).
?- playsAirGuitar(mia).
yes
?-
![Page 37: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/37.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Knowledge Base 2
happy(yolanda).
listens2music(mia).
listens2music(yolanda):- happy(yolanda).
playsAirGuitar(mia):- listens2music(mia).
playsAirGuitar(yolanda):- listens2music(yolanda).
?- playsAirGuitar(mia).
yes
?- playsAirGuitar(yolanda).
yes
![Page 38: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/38.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Clauses
happy(yolanda).
listens2music(mia).
listens2music(yolanda):- happy(yolanda).
playsAirGuitar(mia):- listens2music(mia).
playsAirGuitar(yolanda):- listens2music(yolanda).
There are five clauses in this knowledge base:two facts, and three rules.
The end of a clause is marked with a full stop.
![Page 39: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/39.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Predicates
happy(yolanda).
listens2music(mia).
listens2music(yolanda):- happy(yolanda).
playsAirGuitar(mia):- listens2music(mia).
playsAirGuitar(yolanda):- listens2music(yolanda).
There are three predicates in this knowledge base:
happy, listens2music, and playsAirGuitar
![Page 40: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/40.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Knowledge Base 3
happy(vincent).
listens2music(butch).
playsAirGuitar(vincent):- listens2music(vincent), happy(vincent).
playsAirGuitar(butch):- happy(butch).
playsAirGuitar(butch):- listens2music(butch).
![Page 41: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/41.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Expressing Conjunction
happy(vincent).
listens2music(butch).
playsAirGuitar(vincent):- listens2music(vincent), happy(vincent).
playsAirGuitar(butch):- happy(butch).
playsAirGuitar(butch):- listens2music(butch).
The comma “," expresses conjunction in Prolog
![Page 42: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/42.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Knowledge Base 3
happy(vincent).
listens2music(butch).
playsAirGuitar(vincent):- listens2music(vincent), happy(vincent).
playsAirGuitar(butch):- happy(butch).
playsAirGuitar(butch):- listens2music(butch).
?- playsAirGuitar(vincent).
no
?-
![Page 43: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/43.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Knowledge Base 3
happy(vincent).
listens2music(butch).
playsAirGuitar(vincent):- listens2music(vincent), happy(vincent).
playsAirGuitar(butch):- happy(butch).
playsAirGuitar(butch):- listens2music(butch).
?- playsAirGuitar(butch).
yes
?-
![Page 44: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/44.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Expressing Disjunction
happy(vincent).
listens2music(butch).
playsAirGuitar(vincent):- listens2music(vincent), happy(vincent).
playsAirGuitar(butch):- happy(butch).
playsAirGuitar(butch):- listens2music(butch).
happy(vincent).
listens2music(butch).
playsAirGuitar(vincent):- listens2music(vincent), happy(vincent).
playsAirGuitar(butch):- happy(butch); listens2music(butch).
![Page 45: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/45.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Prolog and Logic
• Clearly Prolog has something to do with logic
• Operators– Implication :-– Conjunction ,– Disjunction ;
• Use of modus ponens
• Negation
![Page 46: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/46.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Knowledge Base 4
woman(mia).woman(jody).woman(yolanda).
loves(vincent, mia).loves(marsellus, mia).loves(pumpkin, honey_bunny).loves(honey_bunny, pumpkin).
![Page 47: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/47.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Prolog Variables
woman(mia).woman(jody).woman(yolanda).
loves(vincent, mia).loves(marsellus, mia).loves(pumpkin, honey_bunny).loves(honey_bunny, pumpkin).
?- woman(X).
![Page 48: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/48.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Variable Instantiation
woman(mia).woman(jody).woman(yolanda).
loves(vincent, mia).loves(marsellus, mia).loves(pumpkin, honey_bunny).loves(honey_bunny, pumpkin).
?- woman(X).
X=mia
![Page 49: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/49.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Asking Alternatives
woman(mia).woman(jody).woman(yolanda).
loves(vincent, mia).loves(marsellus, mia).loves(pumpkin, honey_bunny).loves(honey_bunny, pumpkin).
?- woman(X).
X=mia;
![Page 50: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/50.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Asking Alternatives
woman(mia).woman(jody).woman(yolanda).
loves(vincent, mia).loves(marsellus, mia).loves(pumpkin, honey_bunny).loves(honey_bunny, pumpkin).
?- woman(X).
X=mia;
X=jody
![Page 51: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/51.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Asking Alternatives
woman(mia).woman(jody).woman(yolanda).
loves(vincent, mia).loves(marsellus, mia).loves(pumpkin, honey_bunny).loves(honey_bunny, pumpkin).
?- woman(X).
X=mia;
X=jody;
X=yolanda
![Page 52: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/52.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Asking Alternatives
woman(mia).woman(jody).woman(yolanda).
loves(vincent, mia).loves(marsellus, mia).loves(pumpkin, honey_bunny).loves(honey_bunny, pumpkin).
?- woman(X).
X=mia;
X=jody;
X=yolanda;
no
![Page 53: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/53.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Knowledge Base 4
woman(mia).woman(jody).woman(yolanda).
loves(vincent, mia).loves(marsellus, mia).loves(pumpkin, honey_bunny).loves(honey_bunny, pumpkin).
?- loves(marsellus,X), woman(X).
![Page 54: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/54.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Knowledge Base 4
woman(mia).woman(jody).woman(yolanda).
loves(vincent, mia).loves(marsellus, mia).loves(pumpkin, honey_bunny).loves(honey_bunny, pumpkin).
?- loves(marsellus,X), woman(X).
X=mia
yes
?-
![Page 55: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/55.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Knowledge Base 4
woman(mia).woman(jody).woman(yolanda).
loves(vincent, mia).loves(marsellus, mia).loves(pumpkin, honey_bunny).loves(honey_bunny, pumpkin).
?- loves(pumpkin,X), woman(X).
![Page 56: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/56.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Knowledge Base 4
woman(mia).woman(jody).woman(yolanda).
loves(vincent, mia).loves(marsellus, mia).loves(pumpkin, honey_bunny).loves(honey_bunny, pumpkin).
?- loves(pumpkin,X), woman(X).
no
?-
![Page 57: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/57.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Knowledge Base 5
loves(vincent,mia).
loves(marsellus,mia).
loves(pumpkin, honey_bunny).
loves(honey_bunny, pumpkin).
jealous(X,Y):- loves(X,Z), loves(Y,Z).
![Page 58: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/58.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Knowledge Base 5
loves(vincent,mia).
loves(marsellus,mia).
loves(pumpkin, honey_bunny).
loves(honey_bunny, pumpkin).
jealous(X,Y):- loves(X,Z), loves(Y,Z).
?- jealous(marsellus,W).
![Page 59: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/59.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Knowledge Base 5
loves(vincent,mia).
loves(marsellus,mia).
loves(pumpkin, honey_bunny).
loves(honey_bunny, pumpkin).
jealous(X,Y):- loves(X,Z), loves(Y,Z).
?- jealous(marsellus,W).
W=vincent
?-
![Page 60: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/60.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Prolog Syntax
• What exactly are facts, rules and queries built out of?
Terms
Simple Terms Complex Terms
Constants Variables
Atoms Numbers
Terms
Simple Terms Complex Terms
Constants Variables
Atoms Numbers
![Page 61: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/61.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Atoms
• A sequence of characters of upper-case letters, lower-case letters, digits, or underscore, starting with a lowercase letter• Examples: butch, big_kahuna_burger, playGuitar
• An arbitrary sequence of characters enclosed in single quotes• Examples: 'Vincent', 'Five dollar shake', '@$%'
• A sequence of special characters• Examples: : , ; . :-
![Page 62: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/62.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Numbers
• Integers: 12, -34, 22342
• Floats: 34573.3234
![Page 63: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/63.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Variables
• A sequence of characters of upper-case letters, lower-case letters, digits, or underscore, starting with either an uppercase letter or an underscore
• Examples:
X, Y, Variable, Vincent, _tag
![Page 64: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/64.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Complex Terms
• Atoms, numbers and variables are building blocks for complex terms
• Complex terms are built out of a functor directly followed by a sequence of arguments
• Arguments are put in round brackets, separated by commas
• The functor must be an atom
![Page 65: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/65.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Examples of complex terms
• Examples we have seen before:– playsAirGuitar(jody)– loves(vincent, mia)– jealous(marsellus, W)
• Complex terms inside complex terms:– hide(X,father(father(father(butch))))
![Page 66: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/66.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Arity
• The number of arguments a complex term has is called its arity
• Examples:
woman(mia) is a term with arity 1 loves(vincent,mia) has arity 2 father(father(butch)) arity 1
![Page 67: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/67.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Arity is important
• In Prolog you can define two predicates with the same functor but with different arity
• Prolog would treat this as two different predicates
• In Prolog documentation arity of a predicate is usually indicated with the suffix "/" followed by a number to indicate the arity
![Page 68: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/68.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Example of Arity
• This knowledge base defines– happy/1– listens2music/1– playsAirGuitar/1
happy(yolanda).
listens2music(mia).
listens2music(yolanda):- happy(yolanda).
playsAirGuitar(mia):- listens2music(mia).
playsAirGuitar(yolanda):- listens2music(yolanda).
![Page 69: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/69.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Exercises
![Page 70: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/70.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Summary of this lecture
• Simple examples of Prolog programs• Introduced three basic constructs in Prolog:
– Facts– Rules– Queries
• Discussed other concepts, such as – the role of logic– unification with the help of variables
• Definition of Prolog constructs: terms, atoms, and variables
![Page 71: © Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d445503460f94a20627/html5/thumbnails/71.jpg)
© P
atr
ick B
lackb
urn
, Jo
han
Bos &
Kri
sti
na S
trie
gn
itz
Next lecture
• Discuss unification in Prolog
• Prolog's search strategy