This version of Learn Prolog Now! embeds SWI SH , SWI-Prolog for SHaring. The current version rewrites the Learn Prolog Now! HTML on the fly, recognising source code and example queries. It is not yet good at recognising the relations between source code fragments and queries. Also Learn Prolog Now! needs some updating to be more compatible with SWI-Prolog. All sources are on GitHub:
LearnPrologNow LPN SWISH Proxy SWISH

2.3 Exercises

Exercise  2.1 Which of the following pairs of terms unify? Where relevant, give the variable instantiations that lead to successful unification.

  1. bread  =  bread
  2. ’Bread’  =  bread
  3. ’bread’  =  bread
  4. Bread  =  bread
  5. bread  =  sausage
  6. food(bread)  =  bread
  7. food(bread)  =  X
  8. food(X)  =  food(bread)
  9. food(bread,X)  =  food(Y,sausage)
  10. food(bread,X,beer)  =  food(Y,sausage,X)
  11. food(bread,X,beer)  =  food(Y,kahuna_burger)
  12. food(X)  =  X
  13. meal(food(bread),drink(beer))  =  meal(X,Y)
  14. meal(food(bread),X)  =  meal(X,drink(beer))

Exercise  2.2 We are working with the following knowledge base:

house_elf(dobby).
witch(hermione).
witch('McGonagall').
witch(rita_skeeter).
magic(X):- house_elf(X).
magic(X):- wizard(X).
magic(X):- witch(X).

Which of the following queries are satisfied? Where relevant, give all the variable instantiations that lead to success.

  1. ?-  magic(house_elf).
  2. ?-  wizard(harry).
  3. ?-  magic(wizard).
  4. ?-  magic(’McGonagall’).
  5. ?-  magic(Hermione).

Draw the search tree for the query magic(Hermione) .

Exercise  2.3 Here is a tiny lexicon (that is, information about individual words) and a mini grammar consisting of one syntactic rule (which defines a sentence to be an entity consisting of five words in the following order: a determiner, a noun, a verb, a determiner, a noun).

word(determiner,a).
word(determiner,every).
word(noun,criminal).
word(noun,'big kahuna burger').
word(verb,eats).
word(verb,likes).

sentence(Word1,Word2,Word3,Word4,Word5):-
   word(determiner,Word1),
   word(noun,Word2),
   word(verb,Word3),
   word(determiner,Word4),
   word(noun,Word5).

What query do you have to pose in order to find out which sentences the grammar can generate? List all sentences that this grammar can generate in the order that Prolog will generate them in.

Exercise  2.4 Here are six Italian words:

astante , astoria , baratto , cobalto , pistola , statale .

They are to be arranged, crossword puzzle fashion, in the following grid:

*Pic not found*

The following knowledge base represents a lexicon containing these words:

word(astante, a,s,t,a,n,t,e).
word(astoria, a,s,t,o,r,i,a).
word(baratto, b,a,r,a,t,t,o).
word(cobalto, c,o,b,a,l,t,o).
word(pistola, p,i,s,t,o,l,a).
word(statale, s,t,a,t,a,l,e).

Write a predicate crossword/6 that tells us how to fill in the grid. The first three arguments should be the vertical words from left to right, and the last three arguments the horizontal words from top to bottom.

eXTReMe Tracker
© 2006-2012 Patrick Blackburn, Johan Bos, Kristina Striegnitz