Professional Documents
Culture Documents
ANS :YES
2. Suppose we wanted Prolog to tell us about all the jealous people: what query would
we pose? Do any of the answers surprise you? Do any seem silly?
Ans: jealous(w,t).
3. Which of the following sequences of characters are atoms, which are variables, and
which are neither?
a. vINCENT atom
b. Footmassage variable
c. variable23 atom
d. Variable2000 variable
e. big_kahuna_burger atom
f. ’big kahuna burger’ neither
g. big kahuna burger neither
h. ’Jules’ atom
i. _Jules variable
j. ’_Jules’ atom
4. 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.
a. loves(Vincent,mia) complex terms
b. ’loves(Vincent,mia)’ atom
c. Butch(boxer) neither
d. boxer(Butch) complex term
e. and(big(burger), kahuna(burger)) complex term
f. and(big(X), kahuna(X)) complex
g. _and(big(X), kahuna(X)) neither
h. (Butch kills Vincent) neither
i. kills(Butch Vincent) neither
j. kills(Butch,Vincent) neither
5. 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).
facts - 3:
woman(vincent).
woman(mia).
man(jules).
rules - 4:
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).
clauses - 7:
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).
predicates - woman/1, man/1, person/1, loves/2, knows/2, father/2, son/2, daughter/2 - 8
Rules - heads, goals
person(X) :- man(X); woman(X). - head: person/1, goals: man/1, woman/1
loves(X,Y) :- knows(Y,X). - head: loves/2, goals: knows/2
father(Y,Z) :- man(Y), son(Z,Y). - head: father/2, goals: man/1, son/1
father(Y,Z) :- man(Y), daughter(Z,Y). - head: father/2, goals: man/1, daughter/2
wizard(ron).
hasWand(harry).
quidditchPlayer(harry).
wizard(X):- hasBroom(X), hasWand(X).
hasBroom(X):- quidditchPlayer(X).
a. wizard(ron). YES
b. witch(ron). undefined
c. wizard(hermione). NO
d. witch(hermione). UNDEFIND
e. wizard(harry). YES
f. wizard(Y).
g. witch(Y). UNDEFIND
9. Translate the following sentences into a Prolog program:
Marry likes food likes(marry,food)
Mary likes cold drinks likes(marry,cold drinks)
John likes cold drinks likes(john,cold drinks)
John likes marry likes (john,marry)