Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Big O notation wikipedia , lookup
Functional decomposition wikipedia , lookup
Principia Mathematica wikipedia , lookup
Continuous function wikipedia , lookup
Elementary mathematics wikipedia , lookup
Non-standard calculus wikipedia , lookup
Dirac delta function wikipedia , lookup
Function of several real variables wikipedia , lookup
RYERSON UNIVERSITY DEPARTMENT OF COMPUTER SCIENCE CPS506 – Comparative Programming Language Winter 2010 Assignment 2 – Due: Sunday February 28, 2010 1- Using an example in C++ show that how late binding increases the flexibility of writing a generic program. 2- By using “Rule of Assignment” and “Rule of Sequence” in Axiomatic Semantics, and by assuming the provided Q as the post-condition of the following block of code, find the weakest pre-condition of the block. P: {?} s = s + t = s * u = t – Q: {u > 10; 2; 20; s} 3- Find the loop Invariant and pre-condition of the following while loop using Axiom rules in Axiomatic Semantics. Is the pre-condition you found a weakest pre-condition as well? If No, find the weakest precondition of that. s = 0; while ( t > 0) { s = s + t; t = t – 1; } Q: {s > 60} 4- Using signed and unsigned char in C++ as formal parameters write two overloaded functions, and one or more ambiguous calls to those functions. 1 5a. Write a generic sort program in Java, such as the ones in Ada (page 60 in the sixth lecture note) and in C++ (page 65 in the sixth lecture note). b. Do the same in C#. For the following questions you need to install Standard ML, using the link provided in the first lecture note of ML, to write and test your programs. 6- What is the complete and exact result (output) of executing each of the following commands? (both result value and type) Example: ~ 1 + 2 - 3 * 4 div 5 mod 6; val it = ~1 : int 5 + ~7 * 4 div 3; 12.0 / ~9.0 * 2.0 + 1.0; 12.0 / (~9.0 * 2.0) + 1.0; let val x = 6.5 val y = 3 in x + real y – 0.3 end; let val (x,y) = (72,72.1) in implode [chr(x),chr(ceil y)] end; 7- Write an ML function to flip the order of each pair inside a list. Example of the execution of your function could be: flip [("a",1),("b",2),("c",3)]; [(1,"a"),(2,"b"),(3,"c")] 8- Write an ML function to compute the power of a number. Example of the execution of your function could be: power (3,5); 243 2 9- Write an ML function to return the n-th item of a list, as a list containing that item. Example of the execution of your function could be: getItem ([1,4,12,3,9],3); [12] 10a. Write an ML function to check whether an integer number is even or not. Example of the execution of your function could be: even even 12; 5; true false b. Function you have developed in part a, is called a predicate function which return true or false according to the input value. Now, write a curried function to retrieve all the items from a list satisfying a given predicate function. The signature of the function could be: fun span f argument = … in which f is a predicate function and argument is the input, which is a list. Then, you can test your curried function using the even function that you have written in part a. Example of the execution of your curried function using even could be: span even [1,2,4,5,7,10,11]; [2,4,10] by which you separate the even numbers from the input list. c. Using the logic you have used in part b, write another curried function to create a tuple of two lists, such that the first list contains all the items from the input list satisfying a given predicate 3 function, and the second list contains the remaining items. The signature of the function could be: fun span2 f argument = … in which f is a predicate function and argument is the input, which is a list. Then, you can test your curried function using the even function that you have written in part a. Example of the execution of your curried function using even could be: span2 even [1,2,4,5,7,10,11]; 4 ([2,4,10], [1,5,7,11])