Fibonacci Numbers #
This file defines the fibonacci series, proves results about it and introduces methods to compute it quickly.
The Fibonacci Sequence #
Summary #
Definition of the Fibonacci sequence F₀ = 0, F₁ = 1, Fₙ₊₂ = Fₙ + Fₙ₊₁
.
Main Definitions #
Nat.fib
returns the stream of Fibonacci numbers.
Main Statements #
Nat.fib_add_two
: shows thatfib
indeed satisfies the Fibonacci recurrenceFₙ₊₂ = Fₙ + Fₙ₊₁.
.Nat.fib_gcd
:fib n
is a strong divisibility sequence.Nat.fib_succ_eq_sum_choose
:fib
is given by the sum ofNat.choose
along an antidiagonal.Nat.fib_succ_eq_succ_sum
: shows thatF₀ + F₁ + ⋯ + Fₙ = Fₙ₊₂ - 1
.Nat.fib_two_mul
andNat.fib_two_mul_add_one
are the basis for an efficient algorithm to computefib
(seeNat.fastFib
). There arebit0
/bit1
variants of these can be used to simplifyfib
expressions: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
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.fastFib
.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Computes Nat.fib n
using the binary representation of n
.
Proved to be equal to Nat.fib
in Nat.fast_fib_eq
.
Equations
- Nat.fastFib n = (Nat.fastFibAux n).1
Instances For
theorem
Nat.fib_succ_eq_sum_choose
(n : ℕ)
:
Nat.fib (n + 1) = Finset.sum (Finset.antidiagonal n) fun (p : ℕ × ℕ) => Nat.choose p.1 p.2
theorem
Nat.fib_succ_eq_succ_sum
(n : ℕ)
:
Nat.fib (n + 1) = (Finset.sum (Finset.range n) fun (k : ℕ) => Nat.fib k) + 1