Documentation

CslibFrontier.Foundations.Analysis.Asymptotics.LogCostBound

Logarithmic asymptotic cost bounds and halving recurrences #

This module extends CslibFrontier.Foundations.Analysis.Asymptotics.CostBound with logarithmic Cslib.CostIsBigO rules (O(log₂ n)), bit-length / binary-logarithm big-O equivalences, general halving-recurrence call-count bounds, and the positive-integer-witness characterization of Asymptotics.IsBigO on eventually nonnegative sequences ℕ → ℝ.

Main results #

theorem Cslib.isBigO_iff_exists_pos_nat {f g : ℕ → ℝ} (hf : ∀ᶠ (n : ℕ) in Filter.atTop, 0 ≤ f n) (hg : ∀ᶠ (n : ℕ) in Filter.atTop, 0 ≤ g n) :
f =O[Filter.atTop] g ↔ ∃ (c : ℕ) (n₀ : ℕ), 0 < c ∧ 0 < n₀ ∧ ∀ (n : ℕ), n₀ ≤ n → f n ≤ ↑c * g n

For eventually nonnegative sequences f, g : ℕ → ℝ, f =O[atTop] g holds iff there exist positive natural numbers c and n₀ such that f n ≤ c * g n for all n ≥ n₀.

theorem Cslib.Nat.size_le_two_mul_logb {n : ℕ} (hn : 2 ≤ n) :
↑n.size ≤ 2 * Real.logb 2 ↑n

For n ≥ 2, n.size ≤ 2 * Real.logb 2 n.

theorem Cslib.Nat.size_isBigO_logb :
(fun (n : ℕ) => ↑n.size) =O[Filter.atTop] fun (n : ℕ) => Real.logb 2 ↑n

Binary bit-length Nat.size is O(log₂ n) along Filter.atTop.

theorem Cslib.Nat.logb_isBigO_size :
(fun (n : ℕ) => Real.logb 2 ↑n) =O[Filter.atTop] fun (n : ℕ) => ↑n.size

Real binary logarithm Real.logb 2 is O(Nat.size) along Filter.atTop.

theorem Cslib.Nat.log_isBigO_logb :
(fun (n : ℕ) => ↑(Nat.log 2 n)) =O[Filter.atTop] fun (n : ℕ) => Real.logb 2 ↑n

Integer floor binary logarithm Nat.log 2 is O(log₂ n) along Filter.atTop.

theorem Cslib.Nat.le_size_of_halving {f : ℕ → ℕ} (hf₀ : f 0 = 0) (hf_step : ∀ (w : ℕ), 0 < w → ∃ w' ≤ w / 2, f w ≤ 1 + f w') (w : ℕ) :
f w ≤ w.size

General halving recurrence bound: if f 0 = 0 and every positive w halves to some w' ≤ w / 2 with f w ≤ 1 + f w', then f w ≤ w.size.

theorem Cslib.Nat.succ_le_size_of_halving {f : ℕ → ℕ} (hf_step : ∀ (w : ℕ), 0 < w → f w = 0 ∨ ∃ (w' : ℕ), 0 < w' ∧ w' ≤ w / 2 ∧ f w ≤ 1 + f w') (w : ℕ) :
0 < w → f w + 1 ≤ w.size

Early-stopping halving recurrence bound: if every positive w either stops (f w = 0) or halves to a positive w' ≤ w / 2 with f w ≤ 1 + f w', then f w + 1 ≤ w.size for 0 < w.

theorem Cslib.CostIsBigO.of_le_add_mul_size {α : Type u_1} {size cost : α → ℕ} (a b : ℕ) (h : ∀ (x : α), cost x ≤ a + b * (size x).size) :
CostIsBigO Filter.atTop (fun (n : ℕ) => Real.logb 2 ↑n) size cost

A cost at most a + b * (size x).size is O(log₂ (size x)) along atTop.

theorem Cslib.CostIsBigO.of_le_add_mul_log {α : Type u_1} {size cost : α → ℕ} (a b : ℕ) (h : ∀ (x : α), cost x ≤ a + b * Nat.log 2 (size x)) :
CostIsBigO Filter.atTop (fun (n : ℕ) => Real.logb 2 ↑n) size cost

A cost at most a + b * Nat.log 2 (size x) is O(log₂ (size x)) along atTop.

theorem Cslib.CostIsBigO.of_le_add_mul_clog {α : Type u_1} {size cost : α → ℕ} (a b : ℕ) (h : ∀ (x : α), cost x ≤ a + b * Nat.clog 2 (size x)) :
CostIsBigO Filter.atTop (fun (n : ℕ) => Real.logb 2 ↑n) size cost

A cost at most a + b * Nat.clog 2 (size x) is O(log₂ (size x)) along atTop.

theorem Cslib.CostIsBigO.of_halving {α : Type u_1} {size cost : α → ℕ} {f : ℕ → ℕ} (a b : ℕ) (hf₀ : f 0 = 0) (hf_step : ∀ (w : ℕ), 0 < w → ∃ w' ≤ w / 2, f w ≤ 1 + f w') (h : ∀ (x : α), cost x ≤ a + b * f (size x)) :
CostIsBigO Filter.atTop (fun (n : ℕ) => Real.logb 2 ↑n) size cost

Any cost bounded by an affine function of a halving recurrence f is O(log₂ (size x)).