Ayasdi Accelerates with $55M Investment
ayasdi.com1 pointsby sbi0 comments
(aA + b)(cA + d) = acA^2 + (ad + bc)A + bd
= (ad + bc + ac)A + (bd + ac)
= ((a + b)(c + d) - bd)A + (bd + ac)
(In fact, A^n = F_n A + F_{n-1} I_2). This step requires 3 multiplications and 4 additions and is more-or-less equivalent to the "fast doubling" algorithm in reference [11], which is more optimized. But this derivation is completely generic---it just relies on the characteristic polynomial of A, namely A^2 - A - 1 = 0. fib :: Integer -> Integer
fib n = fst . loop (0, 1) base . abs $ n
where pmul (a, b) (c, d) = ((a + b)*(c + d) - b*d, b*d + a*c)
base = if n >= 0 then (1, 0) else (1, -1)
loop acc sq m
| m == 0 = acc
| m `mod` 2 == 0 = loop acc (pmul sq sq) (m `div` 2)
| otherwise = loop (pmul sq acc) (pmul sq sq) (m `div` 2)