Sheet9 - McMaster University Department of Computing and...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
McMaster University Department of Computing and Software Dr. W. Kahl COMP SCI 1FC3 Exercise Sheet 9 COMP SCI 1FC3 — Mathematics for Computing 20 March 2009 Exercise 9.1 — Recursive Haskell Functions on Numbers (a) The double factorial of a number n is the product of every other number from 1(or 2) up to n . For ex- ample, the double factorial of 8 is 8 * 6 * 4 * 2 = 384 , and the double factorial of 7 is 7 * 5 * 3 * 1= 105 . De±ne a doublefactorial function in Haskell. (b) Implement the function log2 , which computes the integer logarithm (base 2) of its argument. That is, log2 computes the exponent of the largest power of 2 which is less than or equal to its argument. For example, log2 16 = 4 , log2 11= 3 , and log2 1= 0 . (c) State as a predicate logic formula the speci±cation of log2 , namely: “ log2 computes the exponent of the largest natural power of 2 which is less than or equal to its argument.” (d) Use induction to prove correctness of your implementation of (b). Exercise 9.2 — Recursive Haskell Functions on Lists De±ne the following Haskell functions: (a) stutter :: [ a ] -> [ a ] duplicates each element of its argument lists, e.g.: stutter
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 2

Sheet9 - McMaster University Department of Computing and...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online