Documentation

CslibFrontier.Foundations.Analysis.Asymptotics.CostBound

Asymptotic cost bounds #

Cslib.CostIsBigO l g size cost says that the cost of every input is bounded by one cost function of its size, chosen before the input: some monotone, nonnegative f with f =O[l] g satisfies cost a ≤ f (size a) for all a. This is the form of asymptotic cost specification used by Guéneau, Charguéraud and Pottier [GCP18]. Because f is chosen once, the statement is ∃ f, ∀ a. Inductive reasoning with "O(1) + O(1) = O(1)" proves ∀ a, ∃ c instead, which is unsound as a cost claim. The filter makes multivariate bounds explicit: for example, atTop on ℕ × ℕ for a bound in two size parameters.

Exact constants are proved internally and exported in this form: CostIsBigO.of_le_nat turns an exact natural-number bound into an asymptotic one.

Main definitions #

Main results #

References #

def Cslib.CostIsBigO {α : Type u_1} {ι : Type u_2} [Preorder ι] (l : Filter ι) (g : ι → ℝ) (size : α → ι) (cost : α → ℕ) :

The cost of every input a is at most f (size a) for one monotone, nonnegative cost function f with f =O[l] g.

theorem Cslib.CostIsBigO.of_le_nat {α : Type u_1} {ι : Type u_2} [Preorder ι] {l : Filter ι} {g : ι → ℝ} {size : α → ι} {cost : α → ℕ} {F : ι → ℕ} (hF : Monotone F) (hO : (fun (n : ι) => ↑(F n)) =O[l] g) (h : ∀ (a : α), cost a ≤ F (size a)) :
CostIsBigO l g size cost

An exact monotone natural-number bound that is O(g) gives an asymptotic cost bound.

theorem Cslib.CostIsBigO.mono {α : Type u_1} {ι : Type u_2} [Preorder ι] {l : Filter ι} {g : ι → ℝ} {size : α → ι} {cost cost' : α → ℕ} (h : CostIsBigO l g size cost) (hle : ∀ (a : α), cost' a ≤ cost a) :
CostIsBigO l g size cost'

A cost below a bounded cost has the same bound.

theorem Cslib.CostIsBigO.trans_isBigO {α : Type u_1} {ι : Type u_2} [Preorder ι] {l : Filter ι} {g : ι → ℝ} {size : α → ι} {cost : α → ℕ} {g' : ι → ℝ} (h : CostIsBigO l g size cost) (hg : g =O[l] g') :
CostIsBigO l g' size cost

A cost that is O(g) is O(g') whenever g =O[l] g'.

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

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