projects
/
yorgey.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
0ee67ca
)
hw6: fib4 using Matrix operation
author
Ramakrishnan Muthukrishnan
<ram@rkrishnan.org>
Mon, 22 Dec 2014 16:52:43 +0000
(22:22 +0530)
committer
Ramakrishnan Muthukrishnan
<ram@rkrishnan.org>
Mon, 22 Dec 2014 16:52:43 +0000
(22:22 +0530)
hw6/Fibonacci.hs
patch
|
blob
|
history
diff --git
a/hw6/Fibonacci.hs
b/hw6/Fibonacci.hs
index 15b563bc6137c13a115ab3e5c8341746423916cc..39f3349348215075c38f4362851a15279fc0232d 100644
(file)
--- a/
hw6/Fibonacci.hs
+++ b/
hw6/Fibonacci.hs
@@
-96,3
+96,18
@@
instance Fractional (Stream Integer) where
r
fibs3 :: Stream Integer
fibs3 = x' / (streamRepeat 1 - x' - x' * x')
+
+-- exercise 7
+data Matrix = Matrix Integer Integer Integer Integer
+
+instance Num Matrix where
+ (*) :: Matrix -> Matrix -> Matrix
+ (*) (Matrix a1 b1 c1 d1) (Matrix a2 b2 c2 d2) =
+ Matrix (a1*a2 + b1*c2) (a1*b2 + b1*d2) (c1*a2 + d1*c2) (c1*b2 + d1*d2)
+
+fib4 :: Integer -> Integer
+fib4 0 = 0
+fib4 n = let f0 = (Matrix 1 1 1 0)
+ (Matrix _ b _ _) = f0 ^ n
+ in
+ b