Name of Teacher: Dr.
Anuja Soni
Assignment 1
Paper No. CSHT 616 (ii)
(Prolog Programming)
(Chapters 1, 2)
Q 1. Explain how Prolog is suitable for A.I. programming?
Q 2. Following is a knowledge-base:
invented(edison,lightbulb).
invented(colmeraurer,prolog).
iq(einstein,210).
iq(edison,160).
iq(waldorf,90).
genius(Person):-
iq(Person,IQ),
IQ > 150.
genius(Person):-
invented(Person,_).
Give the answer of following queries.
i. When we ask the query ?-genius(A). what is the first answer that
prolog will return?
a) Person = edison
b) Person = einstein
c) A = edison
d) A = einstein
e) No
ii. When we ask the query ?-genius(A). how many answers (if we
cycle through all answers by pressing ';' after each answer) will
prolog show us?
a) 0
b) 1
c) 2
d) 3
e) 4
iii. Define a predicate smart_invention, which returns inventions that
are invented by people with an IQ of 160 or more.
iv. Which of the following are prolog variables (mark all correct
answers):
a) variable
b) Result
c) _somethingElse
d) This thing
e) _
v. When we add the fact iq(Feigenbaum, 180) to our knowledge base,
then does the query genius(waldorf) succeeds. Explain why?
vi. Following is a knowledge base:
no_beam:-
genius(Person),
write('I found intelligent life, sir!'),nl.
When we ask the query ?- no_beam. how many times will prolog
write out the 'I found intelligent life, sir!' sentence?
Q3. Following is a knowledge base:
likes(mary,food).
likes(mary,wine).
likes(john,wine).
likes(john,mary).
How do you add the following rules in the knowledge base?
a. John likes anything that Mary likes
b. John likes anyone who likes wine
c. John likes anyone who likes themselves
Q4. Following is a knowledge base:
male(james1).
male(charles1).
male(charles2).
male(james2).
male(george1).
female(catherine).
female(elizabeth).
female(sophia).
parent(charles1, james1).
parent(elizabeth, james1).
parent(charles2, charles1).
parent(catherine, charles1).
parent(james2, charles1).
parent(sophia, elizabeth).
parent(george1, sophia).
How would you formulate the following queries:
Was George1 the parent of Charles1?
Who was Charles1's parent?
Who were the children of Charles1?
Q 4. Explain Backtracking in PROLOG by giving one example.
Q5. Express the following rules in PROLOG:
1. M is the mother of X if she is a parent of X and is
female 2. F is the father of X if he is a parent of X and is
male 3. X is a sibling of Y if they both have the same
parent.
Furthermore add rules defining:
"sister", "brother",
"aunt", "uncle",
"grandparent", "cousin"
Q6. Using prolog, write a series of facts and rules that asserts the facts
that Bob and Mary speak Russian and John and Mary speak English. It
also defines the relation "understands" between two persons, which is
true exactly when they both speak the same language. Your program
should answer the following queries:
a) ?- speaks(X, Russian).
b) ?- understands(John, Bob).
c) ?- understands(X, Bob).
d) ?- understands(P1, P2).