The Mathlib Handbook

The volumes of the handbook are not written yet. This site shows the map of Mathlib that they will follow, at Mathlib 4472534b60.

The areas / V02. Numbers

Mathlib.Data.Nat.Fib.Zeckendorf

26 declarations. Mathlib docs · Source

Zeckendorf's Theorem

This file proves Zeckendorf's theorem: Every natural number can be written uniquely as a sum of distinct non-consecutive Fibonacci numbers.

Main declarations

  • List.IsZeckendorfRep: Predicate for a list to be an increasing sequence of non-consecutive natural numbers greater than or equal to 2, namely a Zeckendorf representation.
  • Nat.greatestFib: Greatest index of a Fibonacci number less than or equal to some natural.
  • Nat.zeckendorf: Send a natural number to its Zeckendorf representation.
  • Nat.zeckendorfEquiv: Zeckendorf's theorem, in the form of an equivalence between natural numbers and Zeckendorf representations.

TODO

We could prove that the order induced by zeckendorfEquiv on Zeckendorf representations is exactly the lexicographic order.

Tags

fibonacci, zeckendorf, digit

theorem Nat.zeckendorf.induct E1 #

∀ (motive : ℕ → Prop),
  motive 0 → (∀ (n : ℕ), motive (n + 1 - Nat.fib (n + 1).greatestFib) → motive n.succ) → ∀ (a : ℕ), motive a

theorem Nat.zeckendorf.match_1.congr_eq_2 E1 #

∀ (motive : ℕ → Sort u_1) (x : ℕ) (h_1 : Unit → motive 0) (h_2 : (m n : ℕ) → m = n + 1 → motive n.succ) (n : ℕ),
  x = n.succ →
    (match x with
      | 0 => h_1 ()
      | m@h:n.succ => h_2 m n h) ≍
      h_2 (n + 1) n ⋯

theorem Nat.zeckendorf.match_1.congr_eq_1 E1 #

∀ (motive : ℕ → Sort u_1) (x : ℕ) (h_1 : Unit → motive 0) (h_2 : (m n : ℕ) → m = n + 1 → motive n.succ),
  x = 0 →
    (match x with
      | 0 => h_1 ()
      | m@h:n.succ => h_2 m n h) ≍
      h_1 ()

theorem instIsTransNatLeHAddOfNat E1 #

IsTrans ℕ fun a b ↦ b + 2 ≤ a

def List.IsZeckendorfRep E3 #

List ℕ → Prop

A list of natural numbers is a Zeckendorf representation (of a natural number) if it is an increasing sequence of non-consecutive numbers greater than or equal to 2.

This is relevant for Zeckendorf's theorem, since if we write a natural n as a sum of Fibonacci numbers (l.map fib).sum, IsZeckendorfRep l exactly means that we can't simplify any expression of the form fib n + fib (n + 1) = fib (n + 2), fib 1 = fib 2 or fib 0 = 0 in the sum.

theorem List.IsZeckendorfRep_nil E0 #

[].IsZeckendorfRep

theorem List.IsZeckendorfRep.sum_fib_lt E1 #

∀ {n : ℕ} {l : List ℕ}, l.IsZeckendorfRep → (∀ a ∈ (l ++ [0]).head?, a < n) → (List.map Nat.fib l).sum < Nat.fib n

def Nat.greatestFib E3 #

ℕ → ℕ

The greatest index of a Fibonacci number less than or equal to n.

theorem Nat.fib_greatestFib_le E1 #

∀ (n : ℕ), Nat.fib n.greatestFib ≤ n

theorem Nat.greatestFib_mono E1 #

Monotone Nat.greatestFib

theorem Nat.le_greatestFib E0 #

∀ {m n : ℕ}, m ≤ n.greatestFib ↔ Nat.fib m ≤ n

theorem Nat.greatestFib_lt E0 #

∀ {m n : ℕ}, m.greatestFib < n ↔ m < Nat.fib n

theorem Nat.lt_fib_greatestFib_add_one E1 #

∀ (n : ℕ), n < Nat.fib (n.greatestFib + 1)

theorem Nat.greatestFib_fib E0 #

∀ {n : ℕ}, n ≠ 1 → (Nat.fib n).greatestFib = n

theorem Nat.greatestFib_eq_zero E0 #

∀ {n : ℕ}, n.greatestFib = 0 ↔ n = 0

theorem Nat.greatestFib_ne_zero E1 #

∀ {n : ℕ}, n.greatestFib ≠ 0 ↔ n ≠ 0

theorem Nat.greatestFib_pos E0 #

∀ {n : ℕ}, 0 < n.greatestFib ↔ 0 < n

theorem Nat.greatestFib_sub_fib_greatestFib_le_greatestFib E1 #

∀ {n : ℕ}, n ≠ 0 → (n - Nat.fib n.greatestFib).greatestFib ≤ n.greatestFib - 2

def Nat.zeckendorf E3 #

ℕ → List ℕ

The Zeckendorf representation of a natural number.

Note: For unfolding, you should use the equational lemmas Nat.zeckendorf_zero and Nat.zeckendorf_of_pos instead of the autogenerated one.

theorem Nat.zeckendorf_zero E0 #

Nat.zeckendorf 0 = []

theorem Nat.zeckendorf_succ E0 #

∀ (n : ℕ), (n + 1).zeckendorf = (n + 1).greatestFib :: (n + 1 - Nat.fib (n + 1).greatestFib).zeckendorf

theorem Nat.zeckendorf_of_pos E0 #

∀ {n : ℕ}, 0 < n → n.zeckendorf = n.greatestFib :: (n - Nat.fib n.greatestFib).zeckendorf

theorem Nat.isZeckendorfRep_zeckendorf E1 #

∀ (n : ℕ), n.zeckendorf.IsZeckendorfRep

theorem Nat.zeckendorf_sum_fib E1 #

∀ {l : List ℕ}, l.IsZeckendorfRep → (List.map Nat.fib l).sum.zeckendorf = l

theorem Nat.sum_zeckendorf_fib E0 #

∀ (n : ℕ), (List.map Nat.fib n.zeckendorf).sum = n

def Nat.zeckendorfEquiv E3 #

ℕ ≃ { l // l.IsZeckendorfRep }

Zeckendorf's Theorem as an equivalence between natural numbers and Zeckendorf representations. Every natural number can be written uniquely as a sum of non-consecutive Fibonacci numbers (if we forget about the first two terms F₀ = 0, F₁ = 1).