The State of the Art

The current best algorithm for computing F(n)F(n) can be summarized succinctly using the following three equations:

F(2n+1)=4F(n)2F(n1)2+2(1)nF(2n1)=F(n)2+F(n1)2F(2n)=F(2n+1)F(2n1) \begin{aligned} F(2n + 1) &= 4 F(n)^2 - F(n - 1)^2 + 2(-1)^n \\ F(2n - 1) &= F(n)^2 + F(n - 1)^2 \\ F(2n) &= F(2n + 1) - F(2n - 1) \end{aligned}

We can use these three equations to chain our way to any number we want. We start with F(n1)F(n - 1) and F(n)F(n) where n=1n = 1: these are just our base case values 0 and 1. Then, we compute all three of F(2n1),F(2n),F(2n+1)F(2n - 1), F(2n), F(2n + 1) using just two squares. We can either take the first two of these, in which case our new index is 2n2n, or the last two, in which case our new index is 2n+12n + 1. Either way, for our new index nn', we have F(n1)F(n' - 1) and F(n)F(n'), so we can apply these formulas again.

For example, to compute F(12)F(12):

  • Start with n=1n = 1 and our two values (F(n1),F(n))=(0,1)(F(n - 1), F(n)) = (0, 1).
  • Compute (F(2),F(3))(F(2), F(3)): our new nn is 2n+1=32n + 1 = 3.
  • Compute (F(5),F(6))(F(5), F(6)): our new nn is 2n=62n = 6.
  • Compute (F(11),F(12))(F(11), F(12)): our new nn is 2n=122n = 12.1
  • Done!

How did I know whether to go from nn to 2n+12n + 1 or nn to 2n2n?


  1. For the last step, you can save a multiplication because there are direct formulas for F(2n+1)F(2n + 1) and F(2n)F(2n) that only require one, and because we aren't going any further we don't need the previous Fibonacci number.

The State of the Art

The current best algorithm for computing F(n)F(n) can be summarized succinctly using the following three equations:

F(2n+1)=4F(n)2F(n1)2+2(1)nF(2n1)=F(n)2+F(n1)2F(2n)=F(2n+1)F(2n1) \begin{aligned} F(2n + 1) &= 4 F(n)^2 - F(n - 1)^2 + 2(-1)^n \\ F(2n - 1) &= F(n)^2 + F(n - 1)^2 \\ F(2n) &= F(2n + 1) - F(2n - 1) \end{aligned}

We can use these three equations to chain our way to any number we want. We start with F(n1)F(n - 1) and F(n)F(n) where n=1n = 1: these are just our base case values 0 and 1. Then, we compute all three of F(2n1),F(2n),F(2n+1)F(2n - 1), F(2n), F(2n + 1) using just two squares. We can either take the first two of these, in which case our new index is 2n2n, or the last two, in which case our new index is 2n+12n + 1. Either way, for our new index nn', we have F(n1)F(n' - 1) and F(n)F(n'), so we can apply these formulas again.

For example, to compute F(12)F(12):

  • Start with n=1n = 1 and our two values (F(n1),F(n))=(0,1)(F(n - 1), F(n)) = (0, 1).
  • Compute (F(2),F(3))(F(2), F(3)): our new nn is 2n+1=32n + 1 = 3.
  • Compute (F(5),F(6))(F(5), F(6)): our new nn is 2n=62n = 6.
  • Compute (F(11),F(12))(F(11), F(12)): our new nn is 2n=122n = 12.1
  • Done!

How did I know whether to go from nn to 2n+12n + 1 or nn to 2n2n?


  1. For the last step, you can save a multiplication because there are direct formulas for F(2n+1)F(2n + 1) and F(2n)F(2n) that only require one, and because we aren't going any further we don't need the previous Fibonacci number.