Question: 6 . ( 1 0 points ) . The scalar product of two lists of integers xs and ys of length n is given by
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:
n
xsi ysi i
In a similar manner to chisqr defined below show how a list comprehension can be used to define a function scalarproduct :: IntInt Int that returns the scalar product of two lists. For example in GHCi:
scalarproduct
Note: that the mathematical equation for computing the chisquare statistic for comparing lists os and es of length n is given by the following sum:
and can be represented in Haskell as:
chisqr :: FloatFloat Float
chisqr os es sum oee oe zip os es
nosi esi
esi
i
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, ie with a list comprehension involving zip.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
