Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

PROLOG PROGRAMMING AAPP002-4-2-IAI

________________________________________________________________________________________________________

Question 1

A television company is holding auditions for a talent show. The knowledge base below shows some
facts and rules about the competitors.

voice (agnes, excellent).


voice (betty, excellent).
voice (thomas, fair).
voice (zack, excellent.
dance (agnes, fair).
dance (betty, good).
dance (thomas, excellent).
dance (zack, excellent).

a) Based on the given fact above write the following rules:


i) Selected person must have an excellent voice and dance skill.
Zack

ii) If a person has an excellent voice with a good dancing skill, he or she will be reserved.
Betty

b) Identify the result(s) of the following queries:


i) ?-voice(thomas, Y).
True

ii) ?-voice(X, fair);dance(X, good).


False

c) Write a query and its result for the rules a)i) and a)ii).
?-excellent voice, dance (zack)
?-excellent voice, good dancing (Betty)

Question 2

In a school a particular programming language is used to record facts and rules. These include the following:

teaches (mary, programming).


teaches (buvanes, science).
teaches (cooper, science).
learns (ahmad, programming).
learns (minah, programming).
learns (jasper, science).

a) Write the following queries with its result(s):


i) Who is teaching science subject?
?-science (buyanes, cooper)

ii) Who learns programming subject?


?-programming (ahmad, minah)

Version 022021
PROLOG PROGRAMMING AAPP002-4-2-IAI
________________________________________________________________________________________________________
b) Write a rule which will identify which teacher is teaching which students.
Teaches programming (x) :- learn programming (x)
Teaches science (y) :- learn science (y)

Question 3

A logic program is used to represent, as a set of facts and rules, details of parent and child. The set of
facts are shown below:

parent (anita, samantha).


parent (jaydon, samantha).
parent (samantha, jeffrey).
parent (zayn, jeffrey).
parent (bobby, allanna).
female (samantha).
female (allanna).
female (anita).
male (jeffrey).
male (nicholas).
male (jaydon).
male (zayn).
male (bobby).

Complete the following rules:


a) mother(X, Y)
 
mother_of(X,Y):- male(X),
    parent_of(X,Y).

b) father(X, Y)

father_of(X,Y):- male(X),
   parent_of(X,Y).

a) grandfather(X, Y)

grandfather_of(X,Y):- female(X),
    parent_of(X,Z),
    parent_of(Z,Y).

Version 022021

You might also like