Prolog programming: a do-it-yourself course for beginners
Prolog programming: a do-it-yourself course for beginners
Kristina Striegnitz
Department of Computational Linguistics
Saarland University, Saarbrücken, Germany
[email protected]
http://www.coli.uni-sb.de/˜kris
Dudley Harry
parent of(ruth,james).
parent of(petunia,dudley).
parent of(vernon,dudley).
parent of(lili,harry).
parent of(james,harry).
and they are ancestors of anybody that their children may be an-
cestors of (i.e., of all the descendants of their children).
and they are ancestors of anybody that their children may be an-
cestors of (i.e., of all the descendants of their children).
KB: wizard(harry).
wizard(ron).
wizard(hermione).
muggle(uncle vernon).
muggle(aunt petunia).
chases(crookshanks,scabbars).
Query: ?- wizard(hermione).
yes
• Prolog checks for facts that match the query. (There are three.)
• Prolog starts from the top of the knowledge base and, therefore,
finds wizard(harry) first.
• Typing ; forces Prolog to check whether there are other possibilities.
KB: eating(dudley).
happy(dudley) :- kicking(dudley,harry).
happy(dudley) :- eating(dudley).
Query: ?- happy(aunt petunia).
yes
KB: eating(dudley).
happy(aunt petunia):-happy(dudley).
happy(uncle vernon):-happy(dudley),unhappy(harry).
happy(dudley):-kicking(dudley,harry).
happy(dudley):-eating(dudley).
Query: ?- happy(X).
happy(X)
X=ap X=d
X=uv X=d
X=ap unhappy(d)
I3=lili
wizard(lili)
parent of(paul,petunia).
parent of(helen,petunia).
parent_of(albert,harry)
parent of(paul,lili).
parent of(helen,lili). parent_of(albert,I1)
parent of(albert,james). ancestor_of(I1,harry)
parent of(ruth,james).
I1=james
parent of(petunia,dudley).
parent of(vernon,dudley).
parent of(lili,harry). ancestor_of(james,harry)
parent of(james,harry).
• matching
• proof search
• recursion
http://www.coli.uni-sb.de/˜kris/esslli04prolog
(Maybe it’s a good idea to bookmark it, if you haven’t done so already.)