Loading [MathJax]/jax/output/CommonHTML/jax.js

Computing Fibonacci Sequence with Matrix Multiplication

2022. 9. 6. 12:49Algorithm/알고리즘 이론 정리

Fibonacci Sequence as Recursive Formula 

F0=0

F1=1

Fn=Fn1+Fn2,n2

 

Fibonacci Sequence as Matrix Multiplication Form

|FnFn1|=|1110|n1|F1F0|,n1

 

Fast Recursive Powering for elements of Monoid

Suppose we are calculating Xn for XM,nN

if n=1, X is the result

if n is even, calculate Xn2 first and square it.

if n is odd, calculate Xn12 first and square it. then multiply X to it.

We can cleary see this method needs log2n monoid operations because each recursive function call, n becomes half of it.

 

Check this for the iterative Algorithm

더보기

Fast Iterative Powering for elements of Monoid

Suppose we are calculating Xn for XM,nN

let I the identity element of M

First start by expressing n with binary number. 

We can calculate all Xk for kN,klog2n in log2n monoid operations by keep squaring the element starting from X

starting from Initial result I,  if the kth bit of n is 1, we multiply Xk to the result.

By this procedure, we can calculate Xn in log2n monoid operations.

 

Since Matrix and it's multiplication operation is a Monoid,

we can apply Fast Iterative Powering to calculate the nth Fibonacci Number.

 

Number of bits in Fn

Let's consider n2. Since Fn=Fn1+Fn22×Fn2, we can easily show Fn2n2, by induction.

Similary, we can show Fn<2n1.

In conclusion, 2n2Fn<2n1 and the number of bits in Fn is  Θ(n)

 

Matrix Multiplication

Naive Matrix Multiplication between n×n matrixs requires O(n3) Integer multiplications and additions. The fastest algorithm current is Willams' Algorithm due to wikipedia. To find advanced informations, check out this document. However, we are only treating n=2 in this problem, so 8 multiplications and 4 additions are enough for us. 

 

Integer multiplication in O(nlogn) time
Pages 563-617 from Volume 193 (2021), Issue 2 by David Harvey, Joris van der Hoeven

https://hal.archives-ouvertes.fr/hal-02070778v2/document

reduce the integer multiplication problem to a collection of multidimensional discrete Fourier transforms over the complex numbers, whose dimensions are all powers of two.

 

This Algorithm uses fast fourier transform to compute integer multiplication

 

Analysis of bit operations in Computing Fibonacci Sequence with Matrix Multiplication

let T(n) the number of bit operations to calculate |1110|n

Brielfy, let's think |1110|n contains n bit elements.

Then, T(n)=T(n2)+O(nlogn)=O(nlog2n)

What will be the tight T(n)? Since we can't apply master theorem to compute it, we need an another method.

 

728x90
Pentagon재밌게