Fibonacci sequence: Difference between revisions
Content deleted Content added
Added EchoLisp |
|||
Line 3,409: | Line 3,409: | ||
where |
where |
||
a = ( 5*f^3 + if even n then 3*f else (- 3*f) ) -- 3n |
a = ( 5*f^3 + if even n then 3*f else (- 3*f) ) -- 3n |
||
⚫ | |||
b = ( g^3 + 3 * g * f^2 - f^3 ) -- 3n+1 |
b = ( g^3 + 3 * g * f^2 - f^3 ) -- 3n+1 |
||
c = ( g^3 + 3 * g^2 * f + f^3 ) -- 3n+2 |
c = ( g^3 + 3 * g^2 * f + f^3 ) -- 3n+2 |
||
⚫ | |||
<code>(fibN2 n)</code> directly calculates a pair <code>(f,g)</code> of two consecutive Fibonacci numbers, <code>(Fib[n], Fib[n+1])</code>, from recursively calculated such pair at about <code>n/3</code>: |
<code>(fibN2 n)</code> directly calculates a pair <code>(f,g)</code> of two consecutive Fibonacci numbers, <code>(Fib[n], Fib[n+1])</code>, from recursively calculated such pair at about <code>n/3</code>: |
||
<lang haskell> *Main> take 10 $ show $ fst $ fibN2 (10^6) |
<lang haskell> *Main> take 10 $ show $ fst $ fibN2 (10^6) |