This is an individual assignment, which you must complete in accordance with the instructions given in the Professional Conduct and Assignments sections of the Syllabus .
Write the Haskell functions described in the following exercises. You should put all the definitions in the same script (i.e., source code) file, but please add comments that enable your instructor to determine which functions comprise your work on each exercise.
Please format and document your source code appropriately. Also test your programs thoroughly.
n
.
If n
is even, then 2^n = 2^(2*m) = (2^m)^2
for some m
.
If n
is odd, then 2^n = 2^(2*m + 1) = ((2^m)^2)*2
for some m
.
Using these ideas, give a recursive definition of a Haskell function
twopow n
that computes 2 ^ n
for any natural
number n
. Your function cannot use the exponentiation
operator ^
or any exponentiation function in the standard
prelude. The number of calls your program makes to
twopow
during execution should be proportional to the
logarithm of n
(base 2).
natToBase
and
baseToNat
described in exercise 7 on page 49 of the
Notes on Functional Programming with Gofer.
When this assignment is complete, submit:
Be sure that all items submitted are clearly labeled with your name and the assignment number.
UP to CSCI 555 assignments document?