Let $\mathbb{Z}[\phi]$ be the ring of integers extended by $\phi = \frac{1 + \sqrt{5}}{2}$. Note that $\phi^2 = 1 + \phi$.
In this ring, $\phi^n = \mathrm{F}_n\phi + \mathrm{F}_{n-1}$, where $\mathrm{F}_n$ is the $n$th Fibonacci number (assuming $\mathrm{F}_0, \mathrm{F}_1, \mathrm{F}_2 = 0, 1, 1$). Proof by induction: $\phi = \mathrm{F}_1\phi + \mathrm{F}_0$, and $\phi^{n+1} = \phi\phi^n = \phi(\mathrm{F}_n\phi + \mathrm{F}_{n-1}) = \mathrm{F}_n\phi^2 + \mathrm{F}_{n-1}\phi = (\mathrm{F}_{n-1} + \mathrm{F}_n)\phi + \mathrm{F}_n = \mathrm{F}_{n+1}\phi + \mathrm{F}_n$.
Comparing the $\phi$ and constant terms at the two ends of this calculation give the two doubling formulae: $\mathrm{F}_{2n}\phi + \mathrm{F}_{2n-1} = \phi^{2n} = (\phi^n)^2 = (\mathrm{F}_n\phi + \mathrm{F}_{n-1})^2 = \mathrm{F}_n^2\phi^2 + 2\mathrm{F}_n\mathrm{F}_{n-1}\phi + \mathrm{F}_{n-1}^2 = (\mathrm{F}_n^2 + 2\mathrm{F}_n\mathrm{F}_{n-1})\phi + \mathrm{F}_n^2 + \mathrm{F}_{n-1}^2$.
But one can finesse the doubling formulae (using them indirectly), by computing $\phi^n$ in $\mathbb{Z}[\phi]$ in code.
First, define a generic exponentiation-by-doubling power function pow(x, n) where n is a positive integer, defined in terms of a multiplication operator mult:
def power(x, n):
if n == 1: return x
if n % 2 == 0:
p = power(x, n//2)
return mult(p, p)
return mult(x, power(x, n-1))
The argument n halves at most every two recursive calls, so this performs $O(\mathrm{log}\ n)$ multiplications.
Now one needs to define mult on our ring $\mathbb{Z}[\phi]$. $(a\phi+b)(c\phi+d) = ac\phi^2 + (ad+bc)\phi + bd = (ad+bc+ac)\phi + (bd+ac)$. So, representing $a\phi + b$ as the pair (a, b).
def mult((a, b), (c, d)):
return (a*d + b*c + a*c, b*d + a*c)
Now we can compute Fibonacci numbers by calculating pow((1, 0), n). The result will be the pair $(\mathrm{F}_n, \mathrm{F}_{n-1})$, so we just output the first item of the tuple.
for n in xrange(1, 21):
print power((1, 0), n)[0],
The output is the first 20 Fibonacci numbers:
1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765
As a side note, and somewhat surprisingly, one can partially emulate $\mathbb{Z}[\phi]$ in the integers. Let $X$ be a large number, and express $a\phi + b$ as $aX + b$. Perform calculations modulo $X^2 - X - 1$. When $a$ and $b$ are small relative to $X$, it's easy to check that multiplication works the same as in the true ring. As before $X^n = \mathrm{F}_nX + \mathrm{F}_{n-1}$ (when $n$ is small enough that $\mathrm{F}_n < X - 1$).
Then one can compute Fibonacci numbers efficiently, and with barely any code:
X = 1000000
for i in xrange(1, 21):
print pow(X, i, X*X-X-1) // X,
(Note that the 3-argument pow(x, n, m) of Python computes $x^n$ modulo $m$). Increasing $X$ allows a larger range of Fibonacci numbers to be calculated.