# Sheet9 - McMaster University Department of Computing and...

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

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

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

View Full Document
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
Ask a homework question - tutors are online