Documentation

CslibFrontier.Foundations.Data.Nat.Fib

Fibonacci growth bounds for height-balanced trees #

A binary tree whose sibling heights differ by at most one has at least Nat.fib (h + 2) leaves (or nodes, counted suitably) at height h. These lemmas turn that count into the logarithmic height bound h ≤ 2 * Nat.log 2 n, without real numbers. AVL trees, ropes and Fibonacci heaps share them.

Main results #

theorem Nat.fib_max_add_three_le {n m : ℕ} (hnm : n ≤ m + 1) (hmn : m ≤ n + 1) :
fib (max n m + 3) ≤ fib (n + 2) + fib (m + 2)

The Fibonacci step for a node whose children have heights n and m differing by at most one: Nat.fib (max n m + 3) ≤ Nat.fib (n + 2) + Nat.fib (m + 2).

theorem Nat.two_pow_half_succ_le_fib (h : ℕ) :
2 ^ ((h + 1) / 2) ≤ fib (h + 2)

Fibonacci numbers grow at least as fast as √2: 2 ^ ((h + 1) / 2) ≤ Nat.fib (h + 2).

theorem Nat.le_two_mul_log_of_fib_le {h n : ℕ} (hf : fib (h + 2) ≤ n) :
h ≤ 2 * log 2 n

A height h with Nat.fib (h + 2) ≤ n is at most 2 * Nat.log 2 n.