Блог пользователя stould

Автор stould, 10 лет назад, По-английски

The following formula: F(n) = F(n-2) + F(n-1) + 1 give to me how many calls I need to generate the N-th term of Fibonacci. But I don't know how to handle the constant value + 1 to find the recurrence matrix.

I'm bit lost, and I found the following (but wrong) recurrence:

F(0) = 1, F(1) = 1

[F(0), F(1)] * [[0,2], [1, 1]]^(n-1) = [F(n), F(n+1)]

Can someone help me to understand ? Thank you.

  • Проголосовать: нравится
  • +1
  • Проголосовать: не нравится

»
10 лет назад, # |
Rev. 2   Проголосовать: нравится +15 Проголосовать: не нравится

In this case, you need a 3x3 matrix that converts to .

Alternatively, you could define Gn = Fn + c such that Gn = Gn - 1 + Gn - 2, find the constant c, calculate Gn and from it Fn.

»
10 лет назад, # |
Rev. 3   Проголосовать: нравится 0 Проголосовать: не нравится

I definitely solved this problem some time ago, cant remember when and where. Can you please provide the link?

Anyway, let G0 = 1; G1 = 1; Gn = Gn - 2 + Gn - 1 + 1. One can be proved that Gn = Fn - 1 + Ln - 1, where Fn - 1 is (n - 1)-th Fibonacci number and Ln is n-th Lucas number

»
10 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

The only thing to observe is that we can reuse the equation A(n-2) = A(n-2) to make a square matrix that are required for binary exponentiation. so, A(n) = A(n-1) + A(n-2) + 1 A(n-1) = A(n-1) 1 = 1 ,using these three equations we can form the following matrix W = [[1,1,1], [1,0,0], [0,0,1]]

now M(n) = W * M(n-1) which is now a simpler version of the problem, here is a quick python implementation : http://ideone.com/kOYLeZ

hope it helps !