Question: 6 . ( 1 0 points ) . The scalar product of two lists of integers xs and ys of length n is given by

6.(10 points). The scalar product of two lists of integers xs and ys of length n is given by the sum of the products of their corresponding integers:
n1
(xsi ysi) i=0
In a similar manner to chisqr (defined below), show how a list comprehension can be used to define a function scalarproduct :: [Int]->[Int]-> Int that returns the scalar product of two lists. For example (in GHCi):
> scalarproduct [1,2,3][4,5,6]
32
Note: that the mathematical equation for computing the chi-square statistic for comparing lists os and es of length n is given by the following sum:
and can be represented in Haskell as:
chisqr :: [Float]->[Float]-> Float
chisqr os es = sum [((o-e)^2)/e |(o,e)<- zip os es]
n1(osi esi)2
esi
i=0
2
Hint: Since the scalar product of a pair of lists is also zipping a pair of lists (but doing something slightly different with the pairs), it will be defined quite similarly, i.e., with a list comprehension involving zip.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!