| This is a course page of David Casperson |
|
… can be found
under Assigned…
(http://web.unbc.ca/Semesters/2017-05F/370-homework-pending.php)
Bonus: How many of these are fair and interesting?
1.
(require rackunit)
.
F0 = 0; F1 = 1; Fn = Fn-1 + Fn-2 .
Program this in Racket and Haskell.
F0 = 0;
Fn =
(Fn-1 +
Gn-1) / 2;
G0 = 2;
Gn =
(5 × Fn-1 +
Gn-1) / 2;
.
Program this in Racket and Haskell by writing functions that return the (Fn, Gn) pair as a function of n.
Comment on how fast or slow this is.
F2n =
Fn ×
Gn ;
G2n =
(5 × Fn2 +
Gn2) / 2;
.
Write a Program to compute Fibonacci numbers in Racket and in Haskell that use this relation for non-zero even arguments, and the code from the previous part otherwise.
Comment on how fast or slow this is.
Y (from the days
when everything was ASCII) or μ (by analogy with
λ).
In Haskell
functions need to be lower case so it is convenient to use
μ or
mu.
It is defined by
μ ff x = ff (μ ff) x
Determine the type of μ by reasoning from its definition.
Verify your answer using ghci.
(What do you think μ is good for?)
fib fib n = if n<2 then n else fib (n-1) + fib (n-2)
in place of
fib n = if n<2 then n else fib (n-1) + fib (n-2)
fib ff n = if n<2 then n else ff (n-1) + ff (n-2)
fib function?
Why?
fib ff n = if n<(2::Int)
then (fromIntegral n)::Integer
else ff (n-1) + ff (n-2)
to force some of the numeric types, what is the type of
this fib function?
fib recursively defined?undefinedfib undefinedfib . fib $ undefinedfib . fib . fib $ undefined(fib undefined) 1(fib undefined) 2(fib . fib $ undefined) 2 (fib . fib $ undefined) 3 (fib . fib . fib $ undefined) 3 μ and fib functions from the
preceding two questions, what is the value of μ fib
10?
Explain what is going on.
fall-2024