[PDF] best laptop under 300
[PDF] Best Masters Ranking in Business Intelligence, Knowledge and - Anciens Et Réunions
[PDF] Best Masters Ranking in Insurance
[PDF] Best men`s fashion to celebrate. - Anciens Et Réunions
[PDF] Best Newsletter Article by a Young Practitioner Award
[PDF] Best n°153 - avril
[PDF] Best n°67, février 1974
[PDF] Best of "Grease"
[PDF] Best Of 2005.pub - Juno Beach Centre
[PDF] best of andorre - LCPA Passion Aventure Junior
[PDF] Best of Australie - Aventure
[PDF] Best of Best Poils Courts Best of Best Poils Mi-Longs Best of
[PDF] Best of Content Marketing 2016
[PDF] Best of Cuba
[PDF] Best of Dance : le quatrième concours de danse moderne amateur - Anciens Et Réunions
LearnPrologNow!
PatrickBlackburn
JohanBos
KristinaStriegnitz
patrick@aplog.org jbos@cogsci.ed.ac.uk kris@coli.uni-sb.de
Thiscourseisalsoavailableonline:
Contents
1Facts,Rules,andQueries1
1.2.1Atoms.............................9
2MatchingandProofSearch17
3Recursion37
4Lists55
5Arithmetic69
6MoreLists81
7DefiniteClauseGrammars93
8MoreDefiniteClauseGrammars109
9ACloserLookatTerms125
10CutsandNegation145
12WorkingWithFiles171
1
Facts,Rules,andQueries
Thisintroductorylecturehastwomaingoals:
performingmatchingwiththeaidofvariables. othersyntacticconcepts.
1.1Somesimpleexamples
wayoflearningProlog,it'stheonlyway...
1.1.1KnowledgeBase1
fourfacts: woman(mia). woman(jody). woman(yolanda). playsAirGuitar(jody).
2Chapter1.Facts,Rules,andQueries
whyalittlelater. isawomanbyposingthequery: ?-woman(mia).
Prologwillanswer
yes ?-playsAirGuitar(jody). supposeweaskwhetherMiaplaysairguitar: ?-playsAirGuitar(mia).
Wewillgettheanswer
no ?-playsAirGuitar(vincent). deducedfromtheinformationinKB1.
Similarly,supposeweposethequery:
?-tatooed(jody). cannotbededucedfromtheinformationinKB1.
1.1.Somesimpleexamples3
1.1.2KnowledgeBase2
HereisKB2,oursecondknowledgebase:
listensToMusic(mia). happy(yolanda). listensToMusic(yolanda):-happy(yolanda). itemsarerules. head. ?-playsAirGuitar(mia). weask: ?-playsAirGuitar(yolanda). listensToMusic(yolanda):-happy(yolanda), explicitlyrecordedintheknowledgebase - itisonlyimplicitlypresent(itisinferred
Thus,togetherwiththerule
4Chapter1.Facts,Rules,andQueries
knowledgebase. listensToMusic happy playsAirGuitar andhowtheyareinter-related. "degeneraterules".
1.1.3KnowledgeBase3
happy(vincent). listensToMusic(butch). playsAirGuitar(vincent):- listensToMusic(vincent), happy(vincent). playsAirGuitar(butch):- happy(butch). playsAirGuitar(butch):- listensToMusic(butch). threerules. rule
1.1.Somesimpleexamples5
playsAirGuitar(vincent):- listensToMusic(vincent), happy(vincent).
Thus,ifweposedthequery
?-playsAirGuitar(vincent). writtenitas codereadable. playsAirGuitar(butch):- happy(butch). playsAirGuitar(butch):- listensToMusic(butch). ?-playsAirGuitar(butch). playsAirGuitar(butch):- listensToMusic(butch).
6Chapter1.Facts,Rules,andQueries
toconcludethatplaysAirGuitar(butch). rulesgivenabovebythesinglerule playsAirGuitar(butch):- happy(butch); listensToMusic(butch).
1.1.4KnowledgeBase4
HereisKB4,ourfourthknowledgebase:
woman(mia). woman(jody). woman(yolanda). loves(vincent,mia). loves(marcellus,mia). loves(pumpkin,honey_bunny). loves(honey_bunny,pumpkin).
Here'sanexample:
?-woman(X). aboutisawoman.
1.1.Somesimpleexamples7
X=mia binding,orinstantiationthatledtosuccess. Butthat'snottheendofthestory.Thewholepointofvariables - andnotjustin Prologeither - isthattheycan"standfor"or"matchwith"differentthings.And
X=jody
time,Prologreturnstheanswer
X=yolanda
Let'stryamorecomplicatedquery,namely
loves(marcellus,X),woman(X). theanswer X=mia ofProlog.Forsure,Prologhasmanyotherinterestingaspects - butwhenyouget variablebindingtousthatiscrucial.
8Chapter1.Facts,Rules,andQueries
1.1.5KnowledgeBase5
KB5: loves(vincent,mia). loves(marcellus,mia). loves(pumpkin,honey_bunny). loves(honey_bunny,pumpkin). jealous(X,Y):-loves(X,Z),loves(Y,Z). doesitsay? orpumpkin,oranyoneinparticular - it'saconditionalstatementabouteverybodyin ourlittleworld.
Supposeweposethequery:
?-jealous(marcellus,W).
Mia.SoPrologwillreturnthevalue
W=vincent
1.2PrologSyntax
1.2.PrologSyntax9
rules,andqueriesbuiltoutof? termsofProlog. unbrokensequenceofcharacters.
1.2.1Atoms
Anatomiseither:
butch,big_kahuna_burger,andm_monroe2. spacesinsuchatoms - infact,acommonreasonforusingsinglequotesisso wecandopreciselythat. pre-definedmeaning.
1.2.2Numbers
inthiscourse.
1.2.3Variables
areallPrologvariables.
10Chapter1.Facts,Rules,andQueries
1.2.4Complexterms
structures. recursivedefinition).Forexample hide(X,father(father(father(butch)))) stantbutch. termwitharity2. pletelydifferentpredicates. listensToMusic happy playsAirGuitar
1.3.Exercises11
weshouldreallysaythatitdefinespredicates listensToMusic/1 happy/1 playsAirGuitar/1 pletelydistinct.
1.3Exercises
variables,andwhichareneither?
1.vINCENT
2.Footmassage
3.variable23
4.Variable2000
5.big_kahuna_burger
6.'bigkahunaburger'
7.bigkahunaburger
8.'Jules'
9._Jules
10.'_Jules'
andarityofeachcomplexterm.
1.loves(Vincent,mia)
2.'loves(Vincent,mia)'
3.Butch(boxer)
4.boxer(Butch)
5.and(big(burger),kahuna(burger))
6.and(big(X),kahuna(X))
7._and(big(X),kahuna(X))
12Chapter1.Facts,Rules,andQueries
8.(ButchkillsVincent)
9.kills(ButchVincent)
10.kills(Butch,Vincent
contain? woman(vincent). woman(mia). man(jules). person(X):-man(X);woman(X). loves(X,Y):-knows(Y,X). father(Y,Z):-man(Y),son(Z,Y). father(Y,Z):-man(Y),daughter(Z,Y).
1.Butchisakiller.
2.MiaandMarcellusaremarried.
3.Zedisdead.
5.Mialoveseveryonewhoisagooddancer.
wizard(ron). hasWand(harry). quidditchPlayer(harry). wizard(X):-hasBroom(X),hasWand(X). hasBroom(X):-quidditchPlayer(X).
1.wizard(ron).
2.witch(ron).
3.wizard(hermione).
4.witch(hermione).
5.wizard(harry).
6.wizard(Y).
7.witch(Y).
1.4.PracticalSession113
1.4PracticalSession1
shorterthanthetextyouhavejustread - thepracticalpartofthecourseisdefinitely downinfrontofacomputerandplaywithProlog - alot! somethinglike return.Thatis,type ?-listing. andpressthereturnkey. aboutanyknowledgebases,soitwilljustsay yes Thisisacorrectanswer:asyetPrologknowsnothing - soitcorrectlydisplaysall anyknowledgebases!"answer. is ?-[kb2].
14Chapter1.Facts,Rules,andQueries
yes file. ?-listing. listensToMusic(mia). happy(yolanda). playsAirGuitar(mia):- listensToMusic(mia). playsAirGuitar(yolanda):- listensToMusic(yolanda). listensToMusic(yolanda):- happy(yolanda). yes beenloaded. ?-listing(playsAirGuitar). icate.SointhiscasePrologwilldisplay playsAirGuitar(mia):- listensToMusic(mia). playsAirGuitar(yolanda):- listensToMusic(yolanda). yes
1.4.PracticalSession115
Well - nowyou'rereadytogo.KB2isloadedandPrologisrunning,soyoucan(and mastertogetthisfar: tousethistowriteyourPrologcode. whereyouwantit. alotlonger). knowledgebasefromscratch...
16Chapter1.Facts,Rules,andQueries
2
MatchingandProofSearch
Today'slecturehastwomaingoals:
Prologpredicateformatching.
2.1Matching
means.
Recallthattherearethreetypesofterm:
24).
2.Variables.
18Chapter2.MatchingandProofSearch
termsequal. theyarethesameatom,orthesamenumber. eachother,andwesaythattheysharevalues.) (a)Theyhavethesamefunctorandarity. (b)Alltheircorrespondingargumentsmatch theymatch. don'tmatch.
2.1.Matching19
2.1.1Examples
ifweposethequery =(mia,mia). =(mia,vincent).
Prologwillrespond'no'.
mia=mia. nicer)infixnotation.
Let'sreturntothisexample:
mia=mia. yes matchingsucceeds. 2=2. yes mia=vincent. no
20Chapter2.MatchingandProofSearch
quotesdbs_dbs27.pdfusesText_33