Documentation

CslibFrontier.Foundations.Data.Nat.MasterTheoremAsymptotics

The master theorem in asymptotic form #

This module converts the explicit bounds of CslibFrontier.Foundations.Data.Nat.MasterTheorem into real powers and Mathlib's Asymptotics.IsBigO and Asymptotics.IsTheta.

For upper bounds Nat.DivideConquerBound T a b n₀ T₀ f with b ≥ 2 and n₀ ≥ 1:

For lower bounds Nat.DivideConquerLower and matching recurrences Nat.DivideConquerEq, this module proves the dual Ω bounds (rpow_isBigO, pow_mul_log_isBigO, isBigO_self) and matching Θ bounds across all three cases:

This complements Mathlib's Mathlib.Computability.AkraBazzi: Akra–Bazzi proves a more general Θ bound for real-valued recurrences with smooth, polynomially growing driving functions, whereas the statements here work directly on integer recurrences T : ℕ → ℕ with floor/ceiling division n / b and cover non-polynomial regular driving functions (such as n log n, n ^ 2 log n, or 2 ^ n) as well as one-sided upper and lower inequalities.

The conversions to real powers and logarithms are Nat.pow_clog_le_mul_rpow_logb and Nat.clog_le_two_mul_logb (CslibFrontier.Foundations.Data.Nat.LogTwoRpow).

Main results #

References #

theorem Nat.DivideConquerBound.le_mul_rpow {T : ℕ → ℕ} {a b n₀ T₀ c d : ℕ} (h : DivideConquerBound T a b n₀ T₀ fun (n : ℕ) => c * n ^ d) (hb : 1 < b) (hn₀ : 1 ≤ n₀) (hlt : b ^ d < a) {n : ℕ} (hn : n ≠ 0) :
↑(T n) ≤ (↑T₀ + ↑c * ↑n₀ ^ d * ↑b ^ d / (↑a - ↑b ^ d)) * ↑a * ↑n ^ Real.logb ↑b ↑a

Master theorem, case 1, with a real power: if b ^ d < a and n ≠ 0, then T n ≤ (T₀ + c n₀ ^ d b ^ d / (a - b ^ d)) a n ^ log_b a.

theorem Nat.DivideConquerBound.isBigO_rpow {T : ℕ → ℕ} {a b n₀ T₀ c d : ℕ} (h : DivideConquerBound T a b n₀ T₀ fun (n : ℕ) => c * n ^ d) (hb : 1 < b) (hn₀ : 1 ≤ n₀) (hlt : b ^ d < a) :
(fun (n : ℕ) => ↑(T n)) =O[Filter.atTop] fun (n : ℕ) => ↑n ^ Real.logb ↑b ↑a

Master theorem, case 1: if b ^ d < a, then T = O(n ^ log_b a).

theorem Nat.DivideConquerBound.isBigO_pow_mul_log {T : ℕ → ℕ} {a b n₀ T₀ c d : ℕ} (h : DivideConquerBound T a b n₀ T₀ fun (n : ℕ) => c * n ^ d) (hb : 1 < b) (hn₀ : 1 ≤ n₀) (had : a = b ^ d) :
(fun (n : ℕ) => ↑(T n)) =O[Filter.atTop] fun (n : ℕ) => ↑n ^ d * Real.log ↑n

Master theorem, case 2: if a = b ^ d, then T = O(n ^ d log n).

theorem Nat.DivideConquerBound.isBigO_pow {T : ℕ → ℕ} {a b n₀ T₀ c d : ℕ} (h : DivideConquerBound T a b n₀ T₀ fun (n : ℕ) => c * n ^ d) (ha : 1 ≤ a) (hb : 1 < b) (hn₀ : 1 ≤ n₀) (hlt : a < b ^ d) :
(fun (n : ℕ) => ↑(T n)) =O[Filter.atTop] fun (n : ℕ) => ↑n ^ d

Master theorem, case 3: if a < b ^ d, then T = O(n ^ d).

theorem Nat.DivideConquerBound.isBigO_of_regular {T : ℕ → ℕ} {a b n₀ T₀ : ℕ} {f : ℕ → ℕ} (h : DivideConquerBound T a b n₀ T₀ f) (hb : 1 < b) (hf : Monotone f) (hpos : ∃ (N : ℕ), 0 < f N) {c : ℝ} (hc : c < 1) (hreg : ∀ᶠ (n : ℕ) in Filter.atTop, ↑a * ↑(f (n / b)) ≤ c * ↑(f n)) :
(fun (n : ℕ) => ↑(T n)) =O[Filter.atTop] fun (n : ℕ) => ↑(f n)

Master theorem, case 3 (general regularity condition): if f is monotone, not identically zero, and satisfies a * f (n / b) ≤ c * f n for some c < 1 and all sufficiently large n, then T = O(f).

theorem Nat.DivideConquerLower.rpow_le_mul {T f : ℕ → ℕ} {a b n₀ T₀ : ℕ} (h : DivideConquerLower T a b n₀ T₀ f) (ha : 1 ≤ a) (hb : 1 < b) (hnb : b ≤ n₀ + 1) {n : ℕ} (hn : n₀ ≤ n) :
↑T₀ * ↑n ^ Real.logb ↑b ↑a ≤ ↑n₀ ^ Real.logb ↑b ↑a * ↑a * ↑(T n)

Master theorem lower bound, case 1, with a real power: for n₀ ≤ n, T₀ * n ^ log_b a ≤ n₀ ^ log_b a * a * T n.

theorem Nat.DivideConquerLower.rpow_isBigO {T f : ℕ → ℕ} {a b n₀ T₀ : ℕ} (h : DivideConquerLower T a b n₀ T₀ f) (ha : 1 ≤ a) (hb : 1 < b) (hnb : b ≤ n₀ + 1) (hT₀ : 1 ≤ T₀) :
(fun (n : ℕ) => ↑n ^ Real.logb ↑b ↑a) =O[Filter.atTop] fun (n : ℕ) => ↑(T n)

Master theorem lower bound, case 1: T = Ω(n ^ log_b a).

theorem Nat.DivideConquerLower.pow_mul_log_isBigO {T : ℕ → ℕ} {a b n₀ T₀ c d : ℕ} (h : DivideConquerLower T a b n₀ T₀ fun (n : ℕ) => c * n ^ d) (hb : 1 < b) (hn₀ : 1 ≤ n₀) (hc : 1 ≤ c) (had : a = b ^ d) :
(fun (n : ℕ) => ↑n ^ d * Real.log ↑n) =O[Filter.atTop] fun (n : ℕ) => ↑(T n)

Master theorem lower bound, case 2: if a = b ^ d and 1 ≤ c, then T = Ω(n ^ d log n).

theorem Nat.DivideConquerLower.isBigO_self {T f : ℕ → ℕ} {a b n₀ T₀ : ℕ} (h : DivideConquerLower T a b n₀ T₀ f) :
(fun (n : ℕ) => ↑(f n)) =O[Filter.atTop] fun (n : ℕ) => ↑(T n)

Master theorem lower bound, case 3: T = Ω(f).

theorem Nat.DivideConquerEq.isTheta_rpow {T : ℕ → ℕ} {a b n₀ Tmin Tmax c d : ℕ} (h : DivideConquerEq T a b n₀ Tmin Tmax fun (n : ℕ) => c * n ^ d) (hb : 1 < b) (hnb : b ≤ n₀ + 1) (hTmin : 1 ≤ Tmin) (hlt : b ^ d < a) :
(fun (n : ℕ) => ↑(T n)) =Θ[Filter.atTop] fun (n : ℕ) => ↑n ^ Real.logb ↑b ↑a

Master theorem, case 1 (Θ form): if b ^ d < a, b ≤ n₀ + 1, and 1 ≤ Tmin, then T = Θ(n ^ log_b a).

theorem Nat.DivideConquerEq.isTheta_pow_mul_log {T : ℕ → ℕ} {a b n₀ Tmin Tmax c d : ℕ} (h : DivideConquerEq T a b n₀ Tmin Tmax fun (n : ℕ) => c * n ^ d) (hb : 1 < b) (hn₀ : 1 ≤ n₀) (hc : 1 ≤ c) (had : a = b ^ d) :
(fun (n : ℕ) => ↑(T n)) =Θ[Filter.atTop] fun (n : ℕ) => ↑n ^ d * Real.log ↑n

Master theorem, case 2 (Θ form): if a = b ^ d and 1 ≤ c, then T = Θ(n ^ d log n).

theorem Nat.DivideConquerEq.isTheta_of_regular {T f : ℕ → ℕ} {a b n₀ Tmin Tmax : ℕ} (h : DivideConquerEq T a b n₀ Tmin Tmax f) (hb : 1 < b) (hf : Monotone f) (hpos : ∃ (N : ℕ), 0 < f N) {c : ℝ} (hc : c < 1) (hreg : ∀ᶠ (n : ℕ) in Filter.atTop, ↑a * ↑(f (n / b)) ≤ c * ↑(f n)) :
(fun (n : ℕ) => ↑(T n)) =Θ[Filter.atTop] fun (n : ℕ) => ↑(f n)

Master theorem, case 3 (Θ form, general regularity condition): if f is monotone, not identically zero, and satisfies a * f (n / b) ≤ c * f n for some c < 1 and all sufficiently large n, then T = Θ(f).

theorem Nat.DivideConquerEq.isTheta_pow {T : ℕ → ℕ} {a b n₀ Tmin Tmax c d : ℕ} (h : DivideConquerEq T a b n₀ Tmin Tmax fun (n : ℕ) => c * n ^ d) (hb : 1 < b) (hc : 1 ≤ c) (hlt : a < b ^ d) :
(fun (n : ℕ) => ↑(T n)) =Θ[Filter.atTop] fun (n : ℕ) => ↑n ^ d

Master theorem, case 3 (Θ form, polynomial driving term): if a < b ^ d and 1 ≤ c, then T = Θ(n ^ d).