So I sort of understand of how these identities came about from reading this article.
- $F_{2n+1} = F_{n}^2 + F_{n+1}^2$
- $F_{2n} = 2F_{n+1}F_{n}-F_{n}^2 $
But I don't understand how to apply them. I can certainly derive these identities myself and calculate them, but once I have them how do I use them to calculate the nth Fibonacci number? Why is there a branch statement for even and odd? I tried to look up more information, but there wasn't all that much on it with the exception of some academic papers which are written so esoterically and are way beyond me.
Suppose you want to calculate $F(n)$ for a given $n$. Here are the key ideas:
Actual example - let's calculate $F(5)$ using these ideas:
So now we have found that $F(5) = 5$.
Further reading - math and code: https://www.nayuki.io/page/fast-fibonacci-algorithms