Homework 61. Write a function reduce: (a * a -> a) -> a list -> a list thatbehaves like foldl except that it takes the rst element of the list as theinitial value.For example, reduce (op -) [1,2,3] evaluates to 3 (2 1) = 2.This method does not apply to empty list.For the rest of the questions, use zip, map, and reduce to solvethe problems, where zip function is from homework 4.The following questions are about vectors and matrix. We rep-resent row vectors using lists. For example, [2,3,5,4] representsa row vector of four integers. We represent a matrix using a listof lists. For example, the matrix1 2 34 5 6is written as [ [1,2,3], [4, 5, 6] ].2. Write a function vectorAdd: int list * int list -> int list thatadd two integer vectors of the same size.For example, vectorAdd ([1,2,3], [4,5,6]) should return [5, 7, 9].3. Write a function svProduct: int * int list -> int list that multi-ple an integer with an integer list.For example, svProduct(2, [1,2,3]) should return [2,4,6].4. Write a function vmProduct that multiple a row vector of size n with amatrix with n rows and m columns to produce a vector of size m. Forexample, vmProduct([1,2,3], [[1,1], [2,1], [3,1]]) should return[14, 6]. Or,[1 2 3] 241 12 13 135 = 1 [1 1] + 2 [2 1] + 3 [3 1]= [1 1] + [4 2] + [9 3]= [14 6]This function uses the functions svProduct and vectorAdd de ned earlier.15. Write a function matrixProduct that multiple a mn matrix with a nkmatrix to obtain a m k matrix. For example1 2 31 1 1241 12 13 135 =v1v2=14 66 3wherev1 = [1 2 3] 241 12 13 135 =14 6andv2 = [1 1 1] 241 12 13 135 =6 3That is,matrixProduct([ [1, 2, 3], [1, 1, 1] ], [ [1, 1], [2, 1], [3, 1] ])= [ [14, 6], [6, 3] ]This problem will use the function vmProduct de ned previously.2
CS 431
[Solved] CS 431 Programming Language Concepts Homework 6
$25
File Name: CS_431_Programming_Language_Concepts_Homework_6.zip
File Size: 442.74 KB
Only logged in customers who have purchased this product may leave a review.
Reviews
There are no reviews yet.