Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Define the contextual-equivalence relation ` M =ctx M0 : for pairs of PCF terms M, M0 , PCF types , and PCF type environments .

Define the contextual-equivalence relation ` M =ctx M0 : for pairs of PCF terms M, M0 , PCF types , and PCF type environments . [3 marks] (ii) For PCF terms M and N with respective typings ` M : and ` N : , let N M be the PCF term fn x : . N (M x) , where x 6 dom(), with typing ` N M : . State whether or not if ` M =ctx M0 : and ` N =ctx N0 : then ` N M =ctx N0 M0 : . Justify your answer. [5 marks] (b) By considering the countable chain of functions (Pn)nN in the function domain (N B) given by Pn(k) def = false if k N and k < n otherwise (k N) or otherwise, show that the function from (N B) to B given by (P) def = true if n N. P(n) = true false if n N. P(n) = false otherwise P (N B) is not continuous. Argue as to whether or not is definable by a closed term of type (nat bool) bool in both PCF and PCF+por. [5 marks] (c) Let M be the PCF+por term fn f : (nat bool) bool . fn P : nat bool . por P 0 , f fn n : nat . P (succ(n)) Give an explicit description of [[ fix(M) ]] (N B) B

Let x be an approximate solution of Ax = b, and write r = bAx, e = xx. Derive a computable estimate of the relative error kek/kxk in the approximate solution, and show how this may be used with the l2 norm. [8 marks] (e) Suppose A is a 7 7 matrix whose singular values are 102 , 104 , 1010 , 1016, 1022, 1029, 1056. Construct the matrix W+ that you would use (i) if machine epsilon ' 1015, and (ii) if machine epsilon ' 1030 . (a) Define a function subsets in ML with the type subsets : 'a list -> 'a list list which treats its input list as a set of n elements and returns a list of all 2n subsets of that set. [5 marks] (b) Define an exception NoFit with no arguments, and an exception Success whose constructor takes an int list as an argument. [1 mark each] (c) Use subsets to define a function knapsack with the type knapsack : int -> int list -> int list which finds a subset of the ints in its second argument whose sum is exactly the first argument. Use at least one functional (map, foldl, etc.) in the definition of knapsack. The NoFit exception should be raised in the event that no solution exists. [5 marks] (d) Define another version of knapsack called knapsack2 with the type knapsack2 : int -> int list -> unit knapsack2 should use simple recursion to generate its candidate solutions on-the-fly as it tests them, and should raise Success with the solution on success or return unit if no solution exists. [8 marks] 8 CST.2005.13.9 11 Natural Language Processing (a) The Figure below shows feature structures corresponding to lexical entries for snores and he. HEAD [ CAT verb ] COMP filled SPR HEAD These structures can be combined using a grammar rule to give a feature structure corresponding to the phrase he snores with a semantic structure equivalent to pron(x) snore v(x). Give this grammar rule as a feature structure and show the results of applying the rule to the structures in the Figure. [7 marks] (b) Syntactically the verb rains takes the pleonastic pronoun it as subject but semantically it has no arguments. Give possible feature structures for rains and pleonastic it. Show how ungrammatical sentences such as he rains are avoided, mentioning any modifications to the lexical entries in the Figure that might be necessary. [6 marks] (c) Selectional restrictions can be used to block parses of semantically anomalous sentences such as: The pebble snores. The pebble wrote a book. The dog wrote a book. Describe how selectional restrictions might be encoded in a feature structure grammar. (a) When defining space-complexity we use two-tape Turing Machines, with a read-only tape for input data and a read-write working tape. We count only the space used on the work tape. What difference would be made if we worked with standard one-tape Turing machines, loaded the input data onto the tape to start with and measured space in terms of total tape cells touched by the end of the computation? [4 marks] (b) Comment on the following: "The problem of finding a factor of a number N is NP, because if we have a factor P of N we can do a simple trial division and check it in time related to log(N). Thus finding factors of numbers of the form 2p 1 (these are known as Mersenne Numbers) is a problem in the class NP". [2 marks] (c) Define the class co-NP. State an example of a problem that lies in it. [2 marks] (d) What is a witness function for an NP problem? Why might some problem such as 3-SAT have many different witness functions associated with it? [2 marks] (e) Give and justify a relation between NTIME(f(n)) and SPACE(f(n)). [4 marks] (f ) Matchings on bi-partite graphs can be found in polynomial time. The matching problem on tri-partite graphs is known to be NP-complete. Does this suggest that the corresponding problem with a graph whose nodes are partitioned into four sets ("quad-partite" matching) is liable to be exponential in complexity? Justify your answer. [4 marks] (g) Comment on the following proposition: "Determining which player can force a win from a given starting position in the game of Chess is an NP problem because given any sequence of moves it will be easy to verify that they are all legal moves and easy to see who wins at the end of them."

The following tables are part of a library's database system. Book(book id, title, number owned, number borrowed) Person(person id, name, address) Borrowed(person id, book id, number) The primary keys of each table are in bold. In the table Book the column number owned is the number of copies of the book owned by the library, while the column number borrowed is the number of copies currently out on loan. In table Borrowed the column person id is a foreign key into the Person table, the column book id is a foreign key into the Book table. The column number is the number of copies of the book borrowed by the associated person. (This library is used by primary school teachers who frequently check out many copies of a book for the use in their classes.) If the database is internally consistent, then the column number borrowed is redundant information that can be computed from the actual number borrowed, and this can be derived from the Borrowed table. (a) Write an SQL query that checks the internal consistency of this database. It should return records of the form (book id, number borrowed, actual number borrowed) only for those books where number borrowed and actual number borrowed are not equal. That is, if the database is consistent the query will return no records. [5 marks] (b) Your job is to redesign this schema so that there is no need for such consistency checks. The first step is to design an Entity-Relationship model. You will do this by introducing a new entity called Copy Of. Each copy of a book owned by the library will be associated with a unique member of the Copy Of entity. Design an Entity-Relationship diagram based on this idea and argue that cardinality constraints will ensure that the database is internally consistent. [5 marks] (c) Discuss at least two options for implementing your ER model in an SQL database. [5 marks] (d) Using one of your relational implementations from the previous part, write an SQL query that reproduces the contents of the Book table from the original design. That is, write an SQL query that returns records of the form (book id, title, number owned, number borrowed). [5 marks] 2 CST0+CST1.2021.3.3 2 Databases This question involves the relational movie database used in our SQL practical. In each part you are given the result of an SQL query together with a possibly incorrect conclusion drawn from this result. In each case your task is to argue for or against the conclusion. You must clearly justify your reasoning. If the SQL query can be corrected, then do so. (a) The following query returns 1422. Conclusion: Our database contains information on 1422 directors. select count(*) from has_position where position = 'director'; [6 marks] (b) The following query returns these records: --------- ------------ -------- ----- nm0498278 Stan Lee writer 15 Conclusion: Stan Lee did not produce any of the movies in our database. select person_id, name, position, count(*) as total from has_position as hp join people as p on p.person_id = hp.person_id where position <> 'actor' and name = 'Stan Lee' group by person_id, name, position

Write java program to read in a 32-bit pattern and translate to a IEEE-754 floating point number. Be sure to look for infinity, -infinity, zero and NaN patterns

(c) The following query attempts to return records (role, year, total) where Jennifer Lawrence plays the same role during the year a total number of times in different movies. The query returns these records: ROLE YEAR TOTAL ---------------- ---- ----- Tiffany 2012 1 Mystique 2011 1 Raven 2011 1 Aurora Lane 2016 1 Katniss Everdeen 2012 2 Ree 2010 1 Rosalyn Rosenfeld 2013 1 Katniss Everdeen 2013 2 Conclusion: Jennifer Lawrence played Katniss Everdeen in two movies in 2012. select r1.role, m1.year, count(*) as total from plays_role as r1 join plays_role as r2 on r2.person_id = r1.person_id join movies as m1 on m1.movie_id = r1.movie_id join movies as m2 on m2.movie_id = r2.movie_id join people as p on p.person_id = r1.person_id where p.name = 'Jennifer Lawrence' and r1.role = r2.role group by r1.role, m1.year; [8 marks] 4 CST0+CST1.2021.3.5 SECTION B 3 Introduction to Graphics You are provided with a 2D triangle mesh defined by a set of vertices V [k] = (xk, yk, ak) for k = 1, . . . , N, and a triangle index table T of dimension M3, where M is the number of triangles. xk and yk are the coordinates of vertex k and ak is its scalar attribute. An example of such a triangle mesh is shown below. (a) Write down the triangle index table of the mesh shown in the figure above. Ensure that all triangles are forward-facing. [4 marks] (b) Write pseudocode for a function a = lookup a(x, y, V, T), which returns the value of the linearly interpolated attribute at the point (x, y) when the point lies on the mesh and 1 otherwise. Use square brackets to index vertex (V [i]) and triangle (T[i, j]) tables. The pseudocode should include the formulas needed to compute the interpolated attribute value and to check whether the point is inside the triangles. [10 marks] (c) Suppose that now vertices also include a depth, so that V [k] = (xk, yk, zk, ak), and triangles overlap and occlude one another. How do you need to modify the pseudocode to return the attribute of the visible triangle that has the lowest z-value at a given point? Due to memory limitations, you cannot use the Z-buffer algorithm. [6 marks] 5 CST0+CST1.2021.3.6 4 Introduction to Graphics Your task is to create a simple visualization of SARS-CoV-2 using only two primitives: a sphere of radius 1, and a cylinder of a height 2, its base of radius 1, and the main axis aligned with OZ, both centred at the origin. An example of such a visualization is shown in Fig. 1 below. (Fig. 1) (Fig. 2) x y z (r, , ) r (a) Draw a scene graph for the SARS-CoV-2 model, shown in Fig. 1, in which the main shape is a sphere and each spike consists of a cylinder and a sphere. Use the hierarchy of the primitives (sphere cylinder sphere) so that the entire object can be animated by transforming the main shape. [4 marks] (b) Provide transformation matrices for each node of the graph. You do not need to provide the results of the matrix multiplication. Assume that you have a list of N spherical coordinates (k, k), for k = 1, . . . , N, which indicate the positions of the spikes. Use the coordinates as shown in Fig. 2. The main body has a radius of 1, the cylinder of the spike has a length of 0.1, a radius of 0.025 and the sphere of the spike has a radius of 0.05 with the centre at the base of the cylinder. [10 marks] (c) How can you randomly generate the spherical coordinates (k,k) of the spikes so that they are (a) evenly distributed over the sphere and (b) not clustered together (two or more spikes are not too close to each other)? Write pseudocode for generating (k,k). [6 marks] 6 CST0+CST1.2021.3.7 SECTION C 5 Interaction Design Nowadays, timepieces (such as clocks, wristwatches, etc.) have a variety of functions. They not only tell the time and date but they can speak to you, remind you when it's time to do something, and provide a light in the dark, among other things. Mostly, the interface for these devices, however, shows the time in one of two basic ways: as a digital number such as 23:40 or through an analog display with two or three hands - one to represent the hour, one for the minutes, and one for the seconds. In this question, we ask you to design a new timepiece for your own use. This could be in the form of a wristwatch, a mantelpiece clock, an electronic clock, or any other kind of timepiece you fancy. (a) Think about the interactive product you are designing: describe what you want it to do for you. Write a list of functional and non-functional requirements. [4 marks] (b) Sketch out an initial low-fidelity prototype for the timepiece and develop at least two distinct alternatives that both meet your set of requirements listed above. [8 marks] (c) Nielsen's heuristics used for Heuristic Evaluation are: (1) visibility of system status, (2) match between system and real world, (3) user control and freedom, (4) consistency and standards, (5) error prevention, (6) recognition rather than recall, (7) flexibility and efficiency of use, (8) aesthetic and minimalist design, (9) help users recognize and recover from errors, and (10) help and documentation. Evaluate the two low-fidelity prototypes using Heuristic Evaluation. [8 marks] 7 CST0+CST1.2021.3.8 6 Interaction Design A weather app, whose main screen is shown in the figure above, has been created specifically for event organizers as primary stakeholders. (a) Evaluate the provided low-fidelity prototype using Cognitive Walkthrough and the visualised screens (if you need to, you may come up with your own assumptions regarding the primary stakeholders), for the following tasks: (i) (starting from the main screen) View details of the event called Field Day (ii) (starting from the main screen) Add a new event [continued . . . ] 8 CST0+CST1.2021.3.9 (iii) (starting from the main screen) View detailed weather forecast for Field Day (iv) (starting from the main screen) Change the units of measurement for the temperature information provided (v) (starting from the main screen) Modify the volume setting to 150 [14 marks] (b) Using the outcome of the CW you have conducted above, provide a list of suggestions for re-designing this weather app. [3 marks] (c) Considering that user-centred design is iterative, how would you go about gathering another round of data from the target user group using your findings from the CW? Explain which data gathering techniques you would use and why. [3 marks]

A certain program has to maintain an array, count, of N counters which are all initialised to zero. The value of counter i can be incremented by one by the call: increment(i), and this is the only way the program changes counter values. Two variables, mincount and maxcount, must always hold the smallest and largest of the counter values whenever the point of execution is not within the function increment. You may assume that increment is called about 1000N times when the program is run and that its argument is typically uniformly randomly distributed between 1 and N, but on some runs it cycles through the numbers 1 to N in order 1000 times. (a) Describe, in detail, an efficient data structure and algorithm to use when N is expected to be about 10. [5 marks] (b) Describe, in detail, an alternative data structure and algorithm to use when N is about a million. [10 marks] (c) Suppose your algorithm for (a) above were used when N = 106 , estimate how much slower it would be compared with your algorithm for (b). [5 marks] 2 Computer Design (a) What is a data cache and why is it vital for high performance processors? [5 marks] (b) What is a cache line and how big is it likely to be? [3 marks] (c) What is a page and how big is it likely to be? [3 marks] (d) What is a snoopy cache and in what system is it likely to be used? [3 marks] (e) A computer system has the following memory parameters: memory level access time in clock cycles first level cache 1 second level cache 3 main memory 100 If the probability of a hit in the first level cache is 80%, what hit rate do we need in the second level cache if the mean access time is to be two clock cycles? For this part, use the approximation that the cache line length is just one machine word. [6 marks] 2 CST.2005.13.3 3 Digital Communication I (a) Describe on-off flow control. In what circumstances is it appropriate? [4 marks] (b) Describe the operation of window-based flow control. [4 marks] (c) What happens if window-based flow control is used on a flow passing through a highly loaded resource (e.g. router) that is not participating in the flow control protocol? [4 marks] (d) How is this addressed in the Internet? [4 marks] (e) What are the advantages and disadvantages of having Internet routers participate in window-based flow control of every TCP connection? [4 marks] 4 Distributed Systems P4 P3 P2 P1 0000 0000 0000 0000 = message delivery algorithm time --> The above diagram represents a process group that communicates by means of multicast messages. At each process-hosting node, message delivery software decides whether a given incoming message should be delivered to the process or buffered for later delivery. This is achieved by the use of vector clocks. (a) Describe, by means of the above example, the vector clock algorithm for delivery of messages in causal order. [15 marks] (b) By means of a similar example, show that total ordering of messages is not achieved by this algorithm.

(a) Give a program which gives different results according to whether dynamic or static binding is used. [3 marks] (b) Summarise two different methods of implementing functions which have free variables statically bound in an outer nested function, paying particular attention to (i) the lifetime of any storage used and (ii) any language restrictions which the implementation requires. Note also, for each case, what the effect is of assignment to such free variables, e.g. when calls to g() and h() are interleaved in f(int x) { int a = x+7; int g() { a++; } int h(int y) { return a+y; } ... } [8 marks] (c) Give a program in which a function is called recursively without any value or function being defined recursively. [3 marks] (d) Give a program which produces three distinct results according to whether parameters are passed by value, by reference, or by value-result. [3 marks] (e) Explain the likely storage layouts for Java objects p and q respectively of classes P and Q defined by class P { int a,b; int f() { } } class Q extends P { int c; int f() { } int g() { } } [3 marks] 4 CST.2005.13.5 6 Computer Graphics and Image Processing (a) In ray tracing, once we have determined where a ray strikes an object, the illumination at the intersection point can be calculated using the formula: I = Iaka + X i Iikd(Li N) +X i Iiks(Ri V) n . Explain what real effect each of the three terms is trying to model, how accurately it models the real effect, and explain what each of the following symbols means, within the context of this formula: I, Ia, i, Ii , ka, kd, ks,Li , N, Ri , V, n. [12 marks] (b) Compare and contrast the ray tracing and z-buffer algorithms. [8 marks] 7 Comparative Programming Languages (a) Many computer scientists believe that languages with strong compile-time type checking are better than those that are typeless, dynamically typed, or are weakly type checked. Discuss the reasons for this view. [7 marks] (b) If strictly-checked data types are seen as good, discuss whether augmenting a language with many more primitive data types is better. Consider, in particular, the possibility of incorporating into a language such as Java many new numerical types such as packed decimal of various precisions, scaled arithmetic, and new types to hold values representing distance, mass and time. How would these additions affect the readability and reliability of programs? [7 marks] (c) Some languages allow different modes of calling of function arguments, such as call by value, call by reference and call by name. Discuss the advantages and disadvantages of incorporating the argument calling modes into the data types of functions.

kindly answer all the questions

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Discrete and Combinatorial Mathematics An Applied Introduction

Authors: Ralph P. Grimaldi

5th edition

201726343, 978-0201726343

More Books

Students also viewed these Programming questions

Question

What was the first language you learned to speak?

Answered: 1 week ago