CCP2410 – LOGIC PROGRAMMING | My Assignment Tutor

CITY COLLEGE, INTERNATIONAL FACULTY OF THE UNIVERSITY OF SHEFFIELDCOMPUTER SCIENCE DEPARTMENTASSESSED LAB Date:WEDESDAY 18 NOVEMBER 2020Time:14:00 – 15:00Duration:1 hourProgramme of Study:BSc in COMPUTER SCIENCELevel of Studies:2Unit:CCP2410 – LOGIC PROGRAMMINGTURNITIN class ID:TURNITIN Enrollment Key:Emergency:In case of emergency please contact immediately by email: [email protected] General Instructions: You are allowed to have access to notes / books / internet / articles / reference materials etc. toaid you in the exam taking.The duration of this examination is strict and no submissions will be accepted after thespecified end time. Specific Exam Instructions: Answer ALL questions.You must provide your answers inside ONE .pl file. Use your Registration Number to namethe file, e.g. submit, upload your .pl file on the units page on MOLE under Assignments > 2020-2021Assessed Lab 1 Remember that: A Prolog line comment starts with the % character.To interrupt compilation or execution of an expression you need to type CONTROL-C and thentype ‘a’ (for abort). By participating and submitting work for this assessed lab you declare that: DECLARATIONI have completed and submitted this paper by myself without assistance from or communicationwith another person either external or fellow student. I understand that not working on my own willbe considered grounds for unfair means and will result in fail mark for this work and might invokedisciplinary actions. It is at the instructor’s discretion to conduct an oral examination if necessary,which will result in the award of the final grade for that particular piece of work. 1. A classic IQ test is called analogy: “You are given three expressions. The first and the second are relatedsomehow. Find the fourth expression which is related to the third with the same relation.” For example,consider the following expressions:2x x2 2y y2 xy yx 25 52 2y 5y 5xExamples: If you are given 2x, x2 and yx, then the requested fourth expression is xy (because the first twoexpressions 2x and x2 are inverse, and xy is the inverse of yx). If you are given 2y, 5y and 2x then the requested fourth expression is 5x (because the first twoexpressions 2y, 5y have the same exponent, and 5x has the same exponent as the third expression2x).a) Write a number of Prolog facts item/1 that represent the above expressions.[10%]b) Write Prolog facts that represent at least two relations, e.g. inverse, same exponent, same base,etc. between two expressions.[10%]c) Write a Prolog definition for the predicate analogy/5 that solves the analogy problem andreturns the fourth item as well as the relation involved, for example:?- analogy(expression(2,x), expression(x,2), expression(y,x), I4, R).I4 = expression(x,y)R = inverse?- analogy(expression(2,y), expression(5,y), expression(2,x), I4, R).I4 = expression(5,x)R = same_exponent[25%] 2.You are given the following facts that represent who is taller compared to someone else and by howmany centimetres. For example:taller(kostas,katerina,15).taller(katerina, maria, 2).% Kostas is 15cm taller than Katerina taller(maria,nikos,5).taller(nikos,eleni,8).a) Write a recursive Prolog definition is_taller/2 which given two names verifies that the firstis taller than the second one. For example:?- is_taller(katerina, eleni).true[20%]b) Modify the program to write a recursive Prolog definition how_much_taller/3 which givenany two names verifies that the first is taller than the second and also returns the heightdifference in cm.?- how_much_taller(katerina, eleni, H).H = 15[15%]3. a) What does the following predicate p/3 do?p(N,N,N).p(N1,N2,R):-N1>0,N2>0,N1 < N2,NN2 is N2-1,p(N1,NN2,R1),R is R1*N2.[10%]b) What will happen if you replace R is R1*N2 with R = R1*N2 and why? (Answer inside file using a comment.)[10%]END OF QUESTION PAPER


Leave a Reply

Your email address will not be published.