Documentation

CslibFrontier.Foundations.Analysis.Asymptotics.CostBoundCombinators

Compositional combinators and linearithmic bounds for Cslib.CostIsBigO #

Extends CslibFrontier.Foundations.Analysis.Asymptotics.CostBound (Cslib.CostIsBigO) with constant, additive, scalar-multiple, and multiplicative composition combinators together with ceiling-logarithm bounds (Nat.clog 2 n ≤ n, (Nat.clog 2 n : ℝ) ≤ (2 / Real.log 2) * Real.log n) and linearithmic / quadratic comparison lemmas (n * Real.log n =O[atTop] n ^ 2).

Main results #

theorem Cslib.CostIsBigO.const {α : Type u_1} {ι : Type u_2} [Preorder ι] {l : Filter ι} {size : α → ι} {cost : α → ℕ} (c : ℕ) (hc : ∀ (x : α), cost x ≤ c) :
CostIsBigO l (fun (x : ι) => 1) size cost

A cost uniformly bounded by a constant c : ℕ is O(1) along any filter l.

theorem Cslib.CostIsBigO.add {α : Type u_1} {ι : Type u_2} [Preorder ι] {l : Filter ι} {size : α → ι} {g : ι → ℝ} {cost₁ cost₂ : α → ℕ} (h₁ : CostIsBigO l g size cost₁) (h₂ : CostIsBigO l g size cost₂) :
CostIsBigO l g size fun (x : α) => cost₁ x + cost₂ x

Sequential sum of two costs sharing the same asymptotic bound g.

theorem Cslib.CostIsBigO.add_of_isBigO {α : Type u_1} {ι : Type u_2} [Preorder ι] {l : Filter ι} {size : α → ι} {g₁ g₂ g : ι → ℝ} {cost₁ cost₂ : α → ℕ} (h₁ : CostIsBigO l g₁ size cost₁) (h₂ : CostIsBigO l g₂ size cost₂) (hg₁ : g₁ =O[l] g) (hg₂ : g₂ =O[l] g) :
CostIsBigO l g size fun (x : α) => cost₁ x + cost₂ x

Sequential sum of two costs whose respective bounds g₁, g₂ are each O(g).

theorem Cslib.CostIsBigO.const_mul {α : Type u_1} {ι : Type u_2} [Preorder ι] {l : Filter ι} {size : α → ι} {g : ι → ℝ} {cost : α → ℕ} (c : ℕ) (h : CostIsBigO l g size cost) :
CostIsBigO l g size fun (x : α) => c * cost x

Scaling an operation count by a constant c : ℕ preserves CostIsBigO.

theorem Cslib.CostIsBigO.mul {α : Type u_1} {ι : Type u_2} [Preorder ι] {l : Filter ι} {size : α → ι} {g₁ g₂ : ι → ℝ} {cost₁ cost₂ : α → ℕ} (h₁ : CostIsBigO l g₁ size cost₁) (h₂ : CostIsBigO l g₂ size cost₂) :
CostIsBigO l (fun (i : ι) => g₁ i * g₂ i) size fun (x : α) => cost₁ x * cost₂ x

Product of two CostIsBigO bounds yields a CostIsBigO bound for fun i ↦ g₁ i * g₂ i.

The binary ceiling logarithm satisfies Nat.clog 2 n ≤ n for every n : ℕ.

theorem Cslib.CostIsBigO.cast_clog_two_le_mul_log {n : ℕ} (hn : 2 ≤ n) :
↑(Nat.clog 2 n) ≤ 2 / Real.log 2 * Real.log ↑n

For n ≥ 2, (Nat.clog 2 n : ℝ) ≤ (2 / Real.log 2) * Real.log n.

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

Any operation count bounded by a + b * size x + c * (size x * Nat.clog 2 (size x)) satisfies Cslib.CostIsBigO atTop (fun n : ℕ ↦ (n : ℝ) * Real.log n) size cost.

theorem Cslib.CostIsBigO.isBigO_mul_log_sq :
(fun (n : ℕ) => ↑n * Real.log ↑n) =O[Filter.atTop] fun (n : ℕ) => ↑n ^ 2

Linearithmic growth n * Real.log n is dominated by quadratic growth n ^ 2 as n → ∞.