The Fibonacci Sequence #
Summary #
Definition of the Fibonacci sequence F₀ = 0, F₁ = 1, Fₙ₊₂ = Fₙ + Fₙ₊₁.
Main Definitions #
nat.fibreturns the stream of Fibonacci numbers.
Main Statements #
nat.fib_add_two: shows thatfibindeed satisfies the Fibonacci recurrenceFₙ₊₂ = Fₙ + Fₙ₊₁..nat.fib_gcd:fib nis a strong divisibility sequence.nat.fib_succ_eq_sum_choose:fibis given by the sum ofnat.choosealong an antidiagonal.nat.fib_succ_eq_succ_sum: shows thatF₀ + F₁ + ⋯ + Fₙ = Fₙ₊₂ - 1.nat.fib_two_mulandnat.fib_two_mul_add_oneare the basis for an efficient algorithm to computefib(seenat.fast_fib). There arebit0/bit1variants of these can be used to simplifyfibexpressions:simp only [nat.fib_bit0, nat.fib_bit1, nat.fib_bit0_succ, nat.fib_bit1_succ, nat.fib_one, nat.fib_two].
Implementation Notes #
For efficiency purposes, the sequence is defined using stream.iterate.
Tags #
fib, fibonacci
Implementation of the fibonacci sequence satisfying
fib 0 = 0, fib 1 = 1, fib (n + 2) = fib n + fib (n + 1).
Note: We use a stream iterator for better performance when compared to the naive recursive implementation.
fib (n + 2) is strictly monotone.
Subsequent Fibonacci numbers are coprime, see https://proofwiki.org/wiki/Consecutive_Fibonacci_Numbers_are_Coprime
Computes (nat.fib n, nat.fib (n + 1)) using the binary representation of n.
Supports nat.fast_fib.
Computes nat.fib n using the binary representation of n.
Proved to be equal to nat.fib in nat.fast_fib_eq.
Equations
- n.fast_fib = n.fast_fib_aux.fst
fib n is a strong divisibility sequence,
see https://proofwiki.org/wiki/GCD_of_Fibonacci_Numbers
norm_num plugin for fib #
The norm_num plugin uses a strategy parallel to that of nat.fast_fib, but it instead
produces proofs of what nat.fib evaluates to.