Fibonacci in forty steps: matrix exponentiation

The board shows a number as a row of switches. This lesson reads the switches of an exponent, and uses them to decide which squares to multiply.
A coding test gives you this task. The Fibonacci numbers start 0, 1, 1, 2, 3, 5, 8. Each number is the sum of the two before it. Print the number at position 1,000,000,000,000,000,000 (that is 10^18), and print only the remainder after dividing by 1,000,000,007, because the true number has far too many digits to print.
The loop you already know adds two numbers, one position at a time. It needs 10^18 additions. This lesson gives a method that needs about 84 matrix multiplications, and the same method solves any recurrence where each number is a fixed sum of the few numbers before it.
By the end you will be able to turn such a recurrence into a small grid of numbers, raise that grid to a power with the doubling idea from Clinic #31: Pow(x, n), and read off the answer for position 10^18.
The history (optional)
Leonardo of Pisa, known as Fibonacci, put a rabbit problem in his book Liber Abaci, which he completed in 1202. One pair of rabbits produces a new pair every month, and the monthly counts give the sequence 1, 1, 2, 3, 5, 8 and on. The French mathematician Edouard Lucas gave the sequence the name Fibonacci numbers in 1876.
Before you start. Clinic #31: Pow(x, n) gave you fast exponentiation: raise a number to the power n by squaring it again and again and multiplying in the squares that the binary digits of n ask for, about log n steps instead of n. The clock that wraps around gave you the modulus: keep only the remainder after every multiplication and the final remainder stays correct, so numbers never grow. Climbing a tree in powers of two used the same jump sizes of 1, 2, 4, 8 to climb a tree. Read the code in this track in twenty minutes solved LeetCode 509, Fibonacci Number, with a plain loop.