Professional Documents
Culture Documents
IIMS College
Putalisadak, Kathmandu, Nepal
________________________________________________________________________________
____________________________________________________________________________
-------------------------------------------
Evaluator’s Signature & Date
Om Narayan Singh 1001852431
b. Complex terms
• Combination of simple terms to depict relations.
◦ Eg: eats(barbara, beer), female(mia), grandson(son(X), Y), etc.
• Only atom can serve as a functor in a complex term.
◦ These are not complex terms: Eats(barbara, beer), 2Female(mia), _grandson(son(X), Y),
etc.
• Each complex term comprises of arguments called arity.
◦ Eg: atom(arity1, arity2), eats(barbara, beer).
c. Functors
• They are atom in a complex term along with the arity(ies).
• For complex term eats(sam, food), functor can be represented as eats/2. Here, 2 defines the
number of arguments (sam and food) in the complex term.
• For more complex terms, the principle functor is at the outermost level.
◦ Eg: grandson/2 is the functor for grandson(son(X), Y).
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).
Clauses: 7
Facts: 3
Rules: 4
father Y, Z /2
3. Given the following knowledge base, draw a complete search tree for sibling(X,Y):
father(jim,kim).
father(jim,john).
sibling(X,Y):-father(Z,X),father(Z,Y).
Om Narayan Singh 1001852431
4. Write prolog program that multiply each element in a list by 3 and store in another list. (8 marks)
Base clause:
product([],[]).
Rule:
product([X|T],[X1|Result]):- product(T, Result) , X1 is X * 3.
Output:
5. Imagine that the following knowledge base describes a maze. The facts determine which points
are connected, i.e., from which point you can get to which other point in one step. Furthermore,
imagine that all paths are one-way streets, so that you can only walk them in one direction. So, you
can get from point 1 to point 2, but not the other way round.
connected(1,2).
connected(3,4).
connected(5,6).
connected(7,8).
connected(9,10).
connected(12,13).
connected(13,14).
connected(15,16).
connected(17,18).
connected(19,20).
connected(4,1).
connected(6,3).
connected(4,7).
connected(6,11).
connected(14,9).
connected(11,15).
connected(16,12).
connected(14,17).
connected(16,19).
Write a predicate path/2 that tells you from which point in the maze you can get to which other
point when chaining together connections given in the above knowledge base. Can you get from
point 5 to point 10? Which other point can you get to when starting in point 1? And which points
can be reached from point 13?
Ans:
Om Narayan Singh 1001852431
Facts:
connected(1, 2).
connected(3, 4).
connected(5, 6).
connected(7, 8).
connected(9, 10).
connected(12, 13).
connected(13, 14).
connected(15, 16).
connected(17, 18).
connected(19, 20).
connected(4, 1).
connected(6, 3).
connected(4, 7).
connected(6, 11).
connected(14, 9).
connected(11, 15).
connected(16, 12).
connected(14, 17).
connected(16, 19).
Rules:
path(A, B) :- connected(A, B).
path(A, B) :- connected(A, X), path(X, B).
Output: