You are on page 1of 4

ITl,:i 24(t1 UNIVERSITY OF MORATUWA Faculty of Information Technology

al

27

Bachelor of Information Technology (BIT) I.evel 2 - SemesterI Examination lTE240l - Logic Programming

T'ime Allowed:3 hours

May 2010

INSTRUCTIONSTO CANDIDATES paper contains 4 questions on 4 pages including this coverpage. 1 lhis 2. Thetotalmarksobtainable for this examination is 100.Themarks issignedfor each question areincludedin square brackets. 3. Thisexamination accounts for 60yoof themodure assessment. 'Ihis 4. is a closed bookexamination. 5. AnswerALL questions. 6. Calculators arenot allowed.

ADDITIONAL MATERIAL None

Continued...

PageI of4

rTti24Ql

r' t.

1 Ouestion (a) Identifytlu'ee reasoning techniques anddiscus theirapplications. [06 MarlcsJ Writetheresultof unification in each of the followingFOL expressions. (i) sister(x, kamal)andsister(masha,y). (ii) fbther(nimal,x) andfbther(x,barhiya). (iii)sister(masha,x) andsister(y,z). [06 Marles] "Anybody a degree and experience in some field he will work in thatfittld. -who'has Anyonevthopracticesin a particular Jield will get experience in thatfield. Nimal practicesin theprogramming_/ield and he hasa degree" (i) (ii) (iii) Write aboveparagraph in predicate logic. Convert theminto CNF. Usingthe methodof contradiction, provethat Nimal canwork asa programmer. [.t 3 Marks|

(b)

(c ')

2 Question (a) (b) Usingsuitable examples, briefly describe how Prologlanguage answers a query, [05MarksJ The following Prologprogramdefines the relation,count(N,X,L), which is true if and only if N is thenumber of the termin the list L, whichhasvaluelessthanX. count(O,X,[ ]). count(N,X,[HlT]) :- H<X, count(p,X,T), N is p+I. count(N,X, [HlT]) :-H>:X, count(N,X,T). Drawthederivation treefor the query?_count(N,10,[15.1 1,6,12,5f) (c ) II2MarlcsJ lJsing a suitable example showhowtheconcept of backtracking worksin prolog. [08 MarlaJ

Continued...

Page 2 of4

lTr! 2401
Ouestion 3
(a)

Definethe following asusedin prolos. (i) List. (ii) Headof a List. (iii)Tailof a List.

(b)

[03llartuJ Usingdot notationwritesthe following list and draw tree representations for each. (i) [sumudu,jaliyaJ (ii) [b,[c]l (iii)[lx],yl
[06 MarltsJ Definea predicate conc(Ll,L2rLl),where L3 is the concatenation of two listsLl ancl L2. Using.the conc/3predicate definethe following predicates: (i) member(X,L) is trueif theitem X occurs in list L. (ii) one-before-last(X,L) is true if the item X is onebeforethe lastelementin list L. (iii) nth-element(X,L,N) is trueif X is theNrh.i";;;i" hst L.
tl2 MarlcsJ

(c)

(d)

Define the relation devidelist(LrLlrL2) 2) so that the'elements the,elen of list L are prrtitioned betweenlist Ll and list L2. For example?_devidelist([a,b,c,d,e], [a,c,e,],L). L:[b,d]

[0./ MarlcsJ Ouestion4 (a) A knowledge base consists of factsaboutsuppliers, pffis, projectsandshipments of the form, suppliers(supplier_no,supplier__name,phone_no,city). parts(partno,part_name,color,wei ght). projects(proj ect_no,proj ect name,City). shipments(supplier_no,part_no,proj eci_no,quantity). Writequeries to accomplish thefbllowing; (i) List the supplier names in colombo. (ii) List alr the part numbers together with their color. (iii)Findtheprojects names for projectsuppried by supplier s1. (iv)Findtheshipments where the quantity is in theranje 300to 750inclusive. [08 MarksJ
Continued...

Page 3 of4

rrE 24ol
(b)

l;
\f

)J

Write Prolog programs to do thefollowingn (i) Entersupplier-no,supplier-name, phone-noandclty of a srpplicrfrrom the keyboard. (ii) Assert entercd information into supplier/4, if theentryis not in tfo database, and delete or modiff a database entryif it is in. (iii) Display thelist of all suppliers. [09 MarksJ Explainwhy Prologprogramming is suitable for progranrming in Artificial Intelligence. [08 MarksJ

(c)

EndofPaper

Page 4 of4

You might also like