1.3 Exercises
Exercise 1.1 Which of the following sequences of characters are atoms, which are variables, and which are neither?
- vINCENT
- Footmassage
- variable23
- Variable2000
- big_kahuna_burger
- ’big kahuna burger’
- big kahuna burger
- ’Jules’
- _Jules
- ’_Jules’
Exercise 1.2 Which of the following sequences of characters are atoms, which are variables, which are complex terms, and which are not terms at all? Give the functor and arity of each complex term.
- loves(Vincent,mia)
- ’loves(Vincent,mia)’
- Butch(boxer)
- boxer(Butch)
- and(big(burger),kahuna(burger))
- and(big(X),kahuna(X))
- _and(big(X),kahuna(X))
- (Butch kills Vincent)
- kills(Butch Vincent)
- kills(Butch,Vincent
Exercise 1.3 How many facts, rules, clauses, and predicates are there in the following knowledge base? What are the heads of the rules, and what are the goals they contain?
woman(vincent). woman(mia). man(jules). person(X):- man(X); woman(X). loves(X,Y):- father(X,Y). father(Y,Z):- man(Y), son(Z,Y). father(Y,Z):- man(Y), daughter(Z,Y).
Exercise 1.4 Represent the following in Prolog:
- Butch is a killer.
- Mia and Marsellus are married.
- Zed is dead.
- Marsellus kills everyone who gives Mia a footmassage.
- Mia loves everyone who is a good dancer.
- Jules eats anything that is nutritious or tasty.
Exercise 1.5 Suppose we are working with the following knowledge base:
wizard(ron). hasWand(harry). quidditchPlayer(harry). wizard(X):- hasBroom(X), hasWand(X). hasBroom(X):- quidditchPlayer(X).
How does Prolog respond to the following queries?
- wizard(ron).
- witch(ron).
- wizard(hermione).
- witch(hermione).
- wizard(harry).
- wizard(Y).
- witch(Y).