You are on page 1of 5

Om Narayan Singh 1001852431

IIMS College
Putalisadak, Kathmandu, Nepal

Name of Course Instructor: _Purnima Mulmi_____________________________________________

Course Code: __CC303n_________         Course Name: __Programming Models___________________

Program Name: B.Sc(Hons).Computing             Semester: Seven______                    Batch: _Sept 2018

Midterm I / II : Midterm I __________ Assignment Type (Individual/Group): Individual________________

Assignment Title:Answer the following questions._______________________ ______________________

Max. Marks: ______                 Date of Allotment: 10/08/2020___    Date of Submission: 10/08/2020

(Write the individual/group members details below):


Name of the Student UCSI ID number Contact Number Email Id
Om Narayan Singh 1001852431 9860026839 sangam.ale.sa63@gmail.com

Evaluation: ________________________ obtained out of ____________________________

Evaluator’s Comment: ____________________________________________________________

________________________________________________________________________________

____________________________________________________________________________

-------------------------------------------
Evaluator’s Signature & Date
Om Narayan Singh 1001852431

1. Define the following terms with some examples.


a. Atoms
• They are set of character(s) that starts with lower-cased letters or enclosed in single quotes.
◦ Eg: variable, ‘Variable’, ‘ATOM’, etc.
• They form the functor of a complex terms.
◦ Eg: Functor eats and likes as in eats(sheldon, food), likes(om, omi), etc.
• Special characters except reserved ones also makes up an atom when used as initials.
◦ Eg: +plus(X, Y), -minus(Z), etc.

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

2. In the knowledge base given below, answer the following questions:


a. How many clauses are there in the knowledge base? (1 mark) b. How many facts and how many
rules in the knowledge base? (2 marks) c. Identify all the predicates and give the arity of each
predicate. (8 marks)

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

Predicate Arity Arity notation


woman vincent, mia /1
man jules /1
person X /1
loves X, Y /2
Om Narayan Singh 1001852431

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:

You might also like