You are on page 1of 4

LAB 8

1. Are there any other jealous people in KB5?

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

6. Represent the following in Prolog:


a. Butch is a killer. Killer(butch).
b. Mia and Marsellus are married. Married(mia,marsellus)

c. Zed is dead. Dead(zed).

d. Marsellus kills everyone who gives Mia a foot massage.


kills(marcellus,X) :- footmassage(X,mia).
b. Mia loves everyone who is a good dancer.
loves(mia,X) :- good_dancer(X);

c.Jules eats anything that is nutritious or tasty.


eats(jules,X) :- nutritious(X); tasty(X).

7. 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).

8. How does Prolog respond to the following queries?

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)

The following queries yield the specified answers.


Is marry likes food? YES
Is marry likes cold drinks? YES
Is marry likes john? NO
Is john likes food? NO

How do you add the following facts?

1.John likes anything that Mary likes


LIKES(JOHN,X):- LIKES(MARRY,X)

2.John likes anyone who likes wine


LIKES(JOHN,X):- LIKES(VINE)

3.John likes anyone who likes themselves


LIKES(JOHN,X):- LIKES(X).

You might also like