Proofs: Fibonacci search
These are the human proofs of Fibonacci search, at full length.
Fibonacci search finds the mode of a strictly unimodal sequence with the optimal number of evaluations full
This proof shows: correctness.
We use the pseudocode of the page and the Fibonacci numbers , , . Let be strictly unimodal for a maximum on with mode , and let be the smallest number with .
Padding. Extend to on by for and for , where is larger than . Then is strictly unimodal with the same mode : it increases up to , decreases from to , and keeps decreasing after with values below all values of . Line L7 does not evaluate for ; it treats as worse than , which is what answers as long as . The invariant below shows , so the run is exactly the run on .
Comparison lemma. For : implies ; implies ; implies . This is the lemma on the page unimodal function.
Invariant. Before each test of line L5, with the value of the counter:
- , and the two parts and are and in some order;
- ;
- and ;
- the number of evaluations made so far is at most .
Initialization. Lines L2 to L4 set , , and . The parts are and . Since , item 2 holds. If , then . If , minimality of gives , so . One evaluation has been made, and .
Maintenance. Let . Then , so the larger part is the one of length , and line L6 picks it. Suppose it is the right part, , so with because . (The left case is the mirror image.)
- If and (line L8), the lemma gives , so . The new state is , , , with parts and . Also and .
- Otherwise (line L9) : either , and then by the padding, or . If the lemma gives ; if it gives . In both cases . The new state is with parts and , and is unchanged.
In both cases, with , the parts are and , and at most one evaluation was made, so item 4 holds.
Termination and result. Each iteration decreases by 1, so the loop stops with . Then the parts are , so and . By item 2 the only integer strictly between them, , is . Line L11 returns after at most evaluations, by item 4.
Optimality. By the discrete theorem on the page unimodal optimization, no method can guarantee to find the mode of every strictly unimodal function on points with fewer than evaluations, where is the smallest number with . This is the of the algorithm, so Fibonacci search is optimal in the worst case.