Levels Tought:
Elementary,Middle School,High School,College,University,PHD
Teaching Since: | Apr 2017 |
Last Sign in: | 10 Weeks Ago, 5 Days Ago |
Questions Answered: | 4870 |
Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
help here please
Question 1 [10](a) Write a Prolog procedure to split a given list into two separate lists, one containingintegers and the other one real numbers. All other items in the given list should beignored. (6)(b) Briefly discuss the difference between green cuts and red cuts. (4)Question 2 [12](a) Write a procedure filter(List,PredName,Result) that removes all theelements X in List for which PredName(X) fails, and returns the resulting list inResult. The predicate PredName/1 should be defined when calling the procedurefilter.Let test be defined as test(N):- atomic(N).?- filter([a,b,-6,7,A,-1,0,B],test,L).L = [a,b,-6,7,-1,0],Hint: Use the Prolog built-in predicate =.. (6)(b) Write a procedure map(List,PredName,Result) that applies the predicatePredName(Arg,Res) to all the elements in List, and returns the result in the listResult.2Let test be defined as test(N,R):- R is N^3.?- map([3,5,-2],test,L).L = [27,125,-8] (6)Question 3 [24]3.1 Use the database you defined for question 1 of assignment 1 to determine thefollowing using setof, bagof or findall:(a) How many different kinds of birds are listed in the database? (4)(b) How many birds defined in the database include insects in their diet? (5)(c) How many different sizes of bird are defined in the database? (4)3.2 Lists can be used to represent sets in Prolog. Write the following Prolog proceduresusing the Prolog built-in predicates setof, bagof or findall.(a) The procedure intersection(A,B,L) returns the intersection L of sets A and B,i.e.the set L contains all elements that belong to A and to B. (5)(b) The procedure complement(A,U,C) returns the complement L of set A given theuniversal set U (A is a subset of U). The complement of set A consists of all thoseelements that belong to U but not to A. (6)Question 4 [5]Consider the following set of Prolog clauses concerning big cats in the National Parks inSouth Africa.leopard(X):-not lion(X),not cheetah(X).lion(simba).lion(mufasa).lion(scar).Sometimes Prolog returns unexpected results, e.g. if the query leopard(sylvester) isentered using the information given above, Prolog retuns yes. (For those of you not familiarwith Sylvester the lion: he was declared a habitual criminal after escaping twice from one ofour national parks. His new home is the Addo Elephant Park in the Eastern Cape.)(a) Explain why this happens. (4)(b) What assumption causes the phenomenon mentioned above? (1)3Question 5 [4]Construct a table listing the symbols that can be used to compare two terms X and Y and statethe meaning of each. (For your own benefit, make sure you understand the meaning of each.)Question 6 [11]The way in which cryptarithmetic puzzles can be solved in Prolog is discussed in section 4.4of Bratko. Use the guidelines given by Bratko to solve the following puzzle:CROSS + ROADS = DANGER.Question 7 [10]The Russian Multiplication problem can be defined as follows: Say you want to multiply xwith y giving z. The problem is solved using the following iterative loop:With each iteration, x gets the value x/2 and y gets the value y*2. If x is even, the y-entry isignored. If x is odd, y is added to a running total. The loop terminates when x = 0.For example:Calculate z = 24 * 52.x y Calculation of total (T) Total24 52 012 104 06 208 03 416 T = T + 416 4161 832 T = T + 832 12480 1248Write a Prolog program to implement the Russian Multiplication Problem.4Question 8 [10]Assume that your database currently contains the following facts:p(a). q(a,1). r(1,1). r(3,5).p(b). q(a,2). r(1,2). r(3,6).q(b,3). r(2,3). r(4,7).q(b,4). r(2,4). r(4,8).What are the effects of the following queries?(a) ?- p(X),q(X,Y),r(Y,Z).(b) ?- p(X),!,q(X,Y),r(Y,Z).(c) ?- p(X),q(X,Y),!,r(Y,Z).(d) ?- p(X),once(q(X,Y)),r(Y,Z).
Â
1COS4851 Assignment 2 (2016)Important:The main purpose of this assignment is to develop your skills regarding the use ofbuilt-in predicates in Prolog, the control of backtracking and the way in which Prolog can beused for simple arithmetic procedures.Please note that you need to submit screen shots (usingfn+prt scfor Windows in mostinstances) of results for questions where a program/procedure or query is required. This willassist us to see whether you obtained the correct results and if not, try to point out where youwent wrong.Your programs should also berobust. This means that it should check whether all the inputarguments for a specific procedure are legal. For example, if you know you are working withintegers, an input of the constant that is not an integer is not acceptable.Important note:It is not advisable that you search for Prolog solutions to the questions in thisassignment on the internet. You may find a solution to a specific problem but that will notassist you in acquiring the necessary skills for mastering this programming paradigm.Question 1[10](a)Write a Prolog procedure to split a given list into two separate lists, one containingintegers and the other one real numbers. All other items in the given list should beignored.(6)(b)Briefly discuss the difference between green cuts and red cuts.(4)Question 2[12](a)Write a procedurefilter(List,PredName,Result)that removes all theelementsXinListfor whichPredName(X)fails, and returns the resulting list inResult.The predicatePredName/1should be defined when calling the procedurefilter.Lettestbe defined astest(N):- atomic(N).?- filter([a,b,-6,7,A,-1,0,B],test,L).L = [a,b,-6,7,-1,0],Hint:Use the Prolog built-in predicate=..(6)(b)Write a proceduremap(List,PredName,Result)that applies the predicatePredName(Arg,Res)to all the elements inList,and returns the result in the listResult.
Attachments:-----------