Asymptotic notation for natural number functions #
This module defines Complexity.BigO and Complexity.LittleO, thin adapters
that lift Mathlib's Asymptotics.IsBigO and Asymptotics.IsLittleO to
ℕ → ℕ functions (casting through ℝ).
The scoped notations f =O g and f =o g are available when Complexity is
opened and read like standard complexity-theoretic asymptotic notation.
Main definitions #
Main results #
BigO #
BigO.refl— reflexivityBigO.trans— transitivityBigO.of_le— pointwise≤implies big-OBigO.add— sum of big-O is big-OBigO.const_mul_left— constant multiple preserves big-OBigO.le_add_left/BigO.le_add_right— projections from a sumBigO.const_mul_add—c * f₁ + f₂ = O(T₁ + T₂)
LittleO #
LittleO.isBigO— little-o implies big-OLittleO.trans— transitivityLittleO.trans_bigO— mixed:othenOgivesoBigO.trans_littleO— mixed:OthenogivesoLittleO.add— sum of little-o is little-oLittleO.const_mul_left— constant multiple preserves little-o
f grows at most as fast as g asymptotically: f(n) = O(g(n)) as n → ∞.
Lifts Mathlib's Asymptotics.IsBigO to ℕ → ℕ functions, avoiding
repeated Nat.cast coercions in complexity class definitions.
Unfolding: f =O g ↔ ∃ C, ∀ᶠ n in atTop, ↑(f n) ≤ C * ↑(g n).
Equations
- Complexity.BigO f g = (fun (n : ℕ) => ↑(f n)) =O[Filter.atTop] fun (n : ℕ) => ↑(g n)
Instances For
f grows at most as fast as g asymptotically: f(n) = O(g(n)) as n → ∞.
Lifts Mathlib's Asymptotics.IsBigO to ℕ → ℕ functions, avoiding
repeated Nat.cast coercions in complexity class definitions.
Unfolding: f =O g ↔ ∃ C, ∀ᶠ n in atTop, ↑(f n) ≤ C * ↑(g n).
Equations
- Complexity.«term_=O_» = Lean.ParserDescr.trailingNode `Complexity.«term_=O_» 50 50 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " =O ") (Lean.ParserDescr.cat `term 51))
Instances For
f grows strictly slower than g asymptotically: f(n) = o(g(n)) as n → ∞.
Lifts Mathlib's Asymptotics.IsLittleO to ℕ → ℕ functions.
Unfolding: f =o g ↔ ∀ ε > 0, ∀ᶠ n in atTop, ↑(f n) ≤ ε * ↑(g n).
Equations
- Complexity.LittleO f g = (fun (n : ℕ) => ↑(f n)) =o[Filter.atTop] fun (n : ℕ) => ↑(g n)
Instances For
f grows strictly slower than g asymptotically: f(n) = o(g(n)) as n → ∞.
Lifts Mathlib's Asymptotics.IsLittleO to ℕ → ℕ functions.
Unfolding: f =o g ↔ ∀ ε > 0, ∀ᶠ n in atTop, ↑(f n) ≤ ε * ↑(g n).
Equations
- Complexity.«term_=o_» = Lean.ParserDescr.trailingNode `Complexity.«term_=o_» 50 50 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " =o ") (Lean.ParserDescr.cat `term 51))
Instances For
From f =O (·^k) to an explicit polynomial bound. If f : ℕ → ℕ
is big-O of n^k, then there exists a polynomial p in Polynomial ℕ
with f n ≤ p.eval n for every n (not just eventually).
The standard big-O definition gives only an asymptotic bound; this lemma
turns that into an everywhere-bound by (i) extracting a real constant
C and threshold N such that f n ≤ C · n^k for n ≥ N, (ii)
rounding C up to a natural number, and (iii) adding a constant term
that dominates f on the initial segment [0, N).
This is the bridge from big-O hypotheses to the explicit
Polynomial ℕ shape expected by definitions like PolyBalanced and
by time-bound packaging in the WitnessNTMConstruction
construction.
From a polynomial bound to =O (·^deg). If f : ℕ → ℕ is
pointwise bounded by a polynomial p, then f =O (·^p.natDegree).
Companion to BigO.pow_polynomial_bound; the pair lets you convert
freely between the big-O form used by complexity classes and the
explicit Polynomial ℕ shape used in PolyBalanced and in
running-time packaging for composite machines.