Each of the following ML functions contains a function call that passes a function parameter f. In each case, will the function f use its nesting link when it is called? Why? (15 points)
fun addone theList =
let fun f x = x + 1;
in map f theList
end;
fun addall n theList =
let fun f x = x + n;
in map f theList
end;
fun do123 f =
map f [1, 2, 3]
SOLUTION :-
============================================================================================
Each of the following ML functions contains a function call that passes a function parameter f....
Question #2 Write a function fun call that has two arguments: f, a function that has one argument that is a number and num.list that is a list of numbers. The command fun call(f, numlist) should produce a tuple that consists of the values obtained by applying the function f to each of the numbers in num.list in sequence. As an example, the command fun call (abs, [-1, 3, -4.5, 0]) should return the tuple (1, 3, 4.5, 0) since...
20. [5 points] Rewrite the following ML. function using patterns fun factn. ifn-0 then 1 else n fact (n-1) 21. [S points) Using map function, write an ML function int2real of type int list real list that takes a list of integers and returns the same numbers converted to real. For example, if the input is [1,2,3], the output should be like [1.0,2.0,3.0 22. [5 points] Using foldr function, write a function duplist of type·a list 'a list that takes...
Consider the sequence of functions fn : [0,1| R where each fn is defined to be the unique piecewise linear function with domain [0, 1] whose graph passes through the points (0,0) (, n), (j,0), and (1,0) (a) Sketch the graphs of fi, f2, and f3. (b) Computefn(x) dx. (Hint: Compute the area under the graph of any fn) (c) Find a function f : [0, 1] -> R such that fn -* f pointwise, i.e. the pointwise limit of...
2 Functions a. A function f : A-B is called injective or one-to-one if whenever f(x)-f(y) for some x, y E A then x = y. That is Vz, y A f(x) = f(y) → x = y. Which of the following functions are injective? In each case explain why or why not i. f:Z-Z given by f() 3r +7 (1 mark ii. f which maps a QUT student number to the last name of the student with that student...
Call stack question! Long one...
The call stack is part of main memory that is reserved for function calling. Like all r memory it is finite, so can be exhausted resulting in a stack overflow. Recursive functions allocate space on the stack for each recursive call: if there are many such recursive calls a stack overflow can result. The questions that follow ask you to investigate recursive functions and stack overflows. Note that when running programs in the Linux terminal...
Let {h} be a sequence ofRiemann integrable functions on [a,b], such that for each x, {h(x)) is a decreasing sequence. Suppose n) converges pointwise to a Riemann integrable function f Prove that f(x)dxf(x)dx. lim n00
Let {h} be a sequence ofRiemann integrable functions on [a,b], such that for each x, {h(x)) is a decreasing sequence. Suppose n) converges pointwise to a Riemann integrable function f Prove that f(x)dxf(x)dx. lim n00
Odd and Even Functions An even function has the property f(x) =f(-x). Consider the function f(x) Now, f (-a)-(-a)"-d f(a) An odd function has the property f(-x)-f(x). Consider the function f(x) Now, f (-a) = (-a)' =-a3 =-f(a) Declarative & Procedural Knowledge Comment on the meaning of the definitions of even and odd functions in term of transformations. (i) (ii) Show that functions of the formx) are even. bx2 +c Show, that f(x) = asin xis odd and g(x) =...
Write a program that contains a main function, a “double custom_operator_function(int op_type, double x, double y)”, a “double min(double,double)”, a double max(double x,double y), and a double pow(double x, int y). The main function is used to call the custom operator function. Next, the custom operator function calls the min/max/pow functions based on the op_type. From the main, call the custom operator function with the three inputs 1/-3/5, 2/4/5, and 3/4/5. Print the result of each input to screen. i)...
Question 1 (10 points) Which of the following functions is not an onto function? f: R → R, where f(x) = 2x + 7 f: R – R, where f(x) = 6x - 1 Of: Z – Z, where f(n) = n + 3 f: Z - Z, where f(n) = 3n + 1
In C++: A. Write 3 functions that are called in the program. 1. Function readInput prompt user to enter an integer to store to the parameter. 2. Function isPerfectSquare take an integer parameter and checks whether it's a perfect square, that it's square root is an integer. 3. Function min3 return the mainimum value of the parameter values, it shouldn’t use any if statement to compare the parameters but call min2 to do the comparison. Extra Credit: Function printPrimeFactorization print...