The areas / V32. Logic, model theory and computability
Mathlib.Computability.AkraBazzi.AkraBazzi
17 declarations. Mathlib docs · Source
Divide-and-conquer recurrences and the Akra-Bazzi theorem
A divide-and-conquer recurrence is a function T : ℕ → ℝ that satisfies a recurrence relation of
the form T(n) = ∑_{i=0}^{k-1} a_i T(r_i(n)) + g(n) for sufficiently large n, where r_i(n) is
a function such that ‖r_i(n) - b_i n‖ ∈ o(n / (log n)^2) for every i, the coefficients a_i
are positive, and the coefficients b_i are real numbers in (0, 1). (This assumption can be
relaxed to O(n / (log n)^(1+ε)), for some ε > 0; we leave this as future work.) These
recurrences arise mainly in the analysis of divide-and-conquer algorithms such as mergesort or
Strassen's algorithm for matrix multiplication. This class of algorithms works by dividing an
instance of the problem of size n, into k smaller instances, where the i-th instance is of
size roughly b_i n, and calling itself recursively on those smaller instances. T(n) then
represents the running time of the algorithm, and g(n) represents the running time required to
divide the instance and process the answers produced by the recursive calls. Since virtually all
such algorithms produce instances that are only approximately of size b_i n (they must round up
or down, at the very least), we allow the instance sizes to be given by a function r_i(n) that
approximates b_i n.
The Akra-Bazzi theorem gives the asymptotic order of such a recurrence: it states that
T(n) ∈ Θ(n^p (1 + ∑_{u=0}^{n-1} g(n) / u^{p+1})),
where p is the unique real number such that ∑ a_i b_i^p = 1.
Main definitions and results
isTheta_asympBound: The main result stating thatT(n) ∈ Θ(n^p (1 + ∑_{u=0}^{n-1} g(n) / u^{p+1}))
Implementation
Note that the original version of the Akra–Bazzi theorem uses an integral rather than the sum in
the above expression, and first considers the T : ℝ → ℝ case before moving on to ℕ → ℝ. We
prove the version with a sum here, as it is simpler and more relevant for algorithms.
TODO
- Relax the assumption described in the introduction from
o(n / (log n)^2)toO(n / (log n)^(1+ε)), for someε > 0. - Specialize this theorem to the very common case where the recurrence is of the form
T(n) = ℓT(r_i(n)) + g(n)whereg(n) ∈ Θ(n^t)for somet. (This is often called the "master theorem" in the literature.) - Add the original version of the theorem with an integral instead of a sum.
References
- Mohamad Akra and Louay Bazzi, On the solution of linear recurrence equations
- Tom Leighton, Notes on better master theorems for divide-and-conquer recurrences
- Manuel Eberl, Asymptotic reasoning in a proof assistant
Technical lemmas
The next several lemmas are technical results leading up to rpow_p_mul_one_sub_smoothingFn_le and
rpow_p_mul_one_add_smoothingFn_ge, which are key steps in the main proof.
Main proof
This final section proves the Akra-Bazzi theorem.
theorem AkraBazziRecurrence.mk.congr_simp E1 #
∀ {α : Type u_1} [inst : Fintype α] [inst_1 : Nonempty α] {T : ℕ → ℝ} {g : ℝ → ℝ} {a b : α → ℝ} {r : α → ℕ → ℕ}
(n₀ n₀_1 : ℕ) (e_n₀ : n₀ = n₀_1) (n₀_gt_zero : 0 < n₀) (a_pos : ∀ (i : α), 0 < a i) (b_pos : ∀ (i : α), 0 < b i)
(b_lt_one : ∀ (i : α), b i < 1) (g_nonneg : ∀ x ≥ 0, 0 ≤ g x) (g_grows_poly : AkraBazziRecurrence.GrowsPolynomially g)
(h_rec : ∀ (n : ℕ), n₀ ≤ n → T n = ∑ i, a i * T (r i n) + g ↑n) (T_gt_zero' : ∀ n < n₀, 0 < T n)
(r_lt_n : ∀ (i : α) (n : ℕ), n₀ ≤ n → r i n < n)
(dist_r_b : ∀ (i : α), (fun n ↦ ↑(r i n) - b i * ↑n) =o[Filter.atTop] fun n ↦ ↑n / Real.log ↑n ^ 2),
{ n₀ := n₀, n₀_gt_zero := n₀_gt_zero, a_pos := a_pos, b_pos := b_pos, b_lt_one := b_lt_one, g_nonneg := g_nonneg,
g_grows_poly := g_grows_poly, h_rec := h_rec, T_gt_zero' := T_gt_zero', r_lt_n := r_lt_n, dist_r_b := dist_r_b } =
{ n₀ := n₀_1, n₀_gt_zero := ⋯, a_pos := a_pos, b_pos := b_pos, b_lt_one := b_lt_one, g_nonneg := g_nonneg,
g_grows_poly := g_grows_poly, h_rec := ⋯, T_gt_zero' := ⋯, r_lt_n := ⋯, dist_r_b := dist_r_b }
theorem AkraBazziRecurrence.eventually_deriv_rpow_p_mul_one_sub_smoothingFn E1 #
∀ (p : ℝ),
(deriv fun z ↦ z ^ p * (1 - AkraBazziRecurrence.smoothingFn z)) =ᶠ[Filter.atTop] fun z ↦
p * z ^ (p - 1) * (1 - AkraBazziRecurrence.smoothingFn z) + z ^ (p - 1) / Real.log z ^ 2
theorem AkraBazziRecurrence.eventually_deriv_rpow_p_mul_one_add_smoothingFn E1 #
∀ (p : ℝ),
(deriv fun z ↦ z ^ p * (1 + AkraBazziRecurrence.smoothingFn z)) =ᶠ[Filter.atTop] fun z ↦
p * z ^ (p - 1) * (1 + AkraBazziRecurrence.smoothingFn z) - z ^ (p - 1) / Real.log z ^ 2
theorem AkraBazziRecurrence.isEquivalent_deriv_rpow_p_mul_one_sub_smoothingFn E1 #
∀ {p : ℝ},
p ≠ 0 →
Asymptotics.IsEquivalent Filter.atTop (deriv fun z ↦ z ^ p * (1 - AkraBazziRecurrence.smoothingFn z)) fun z ↦
p * z ^ (p - 1)
theorem AkraBazziRecurrence.isEquivalent_deriv_rpow_p_mul_one_add_smoothingFn E1 #
∀ {p : ℝ},
p ≠ 0 →
Asymptotics.IsEquivalent Filter.atTop (deriv fun z ↦ z ^ p * (1 + AkraBazziRecurrence.smoothingFn z)) fun z ↦
p * z ^ (p - 1)
theorem AkraBazziRecurrence.isTheta_deriv_rpow_p_mul_one_sub_smoothingFn E1 #
∀ {p : ℝ},
p ≠ 0 →
(fun x ↦ ‖deriv (fun z ↦ z ^ p * (1 - AkraBazziRecurrence.smoothingFn z)) x‖) =Θ[Filter.atTop] fun z ↦ z ^ (p - 1)
theorem AkraBazziRecurrence.isTheta_deriv_rpow_p_mul_one_add_smoothingFn E1 #
∀ {p : ℝ},
p ≠ 0 →
(fun x ↦ ‖deriv (fun z ↦ z ^ p * (1 + AkraBazziRecurrence.smoothingFn z)) x‖) =Θ[Filter.atTop] fun z ↦ z ^ (p - 1)
theorem AkraBazziRecurrence.growsPolynomially_deriv_rpow_p_mul_one_sub_smoothingFn E1 #
∀ (p : ℝ),
AkraBazziRecurrence.GrowsPolynomially fun x ↦ ‖deriv (fun z ↦ z ^ p * (1 - AkraBazziRecurrence.smoothingFn z)) x‖
theorem AkraBazziRecurrence.growsPolynomially_deriv_rpow_p_mul_one_add_smoothingFn E1 #
∀ (p : ℝ),
AkraBazziRecurrence.GrowsPolynomially fun x ↦ ‖deriv (fun z ↦ z ^ p * (1 + AkraBazziRecurrence.smoothingFn z)) x‖
theorem AkraBazziRecurrence.isBigO_apply_r_sub_b E1 #
∀ {α : Type u_1} [inst : Fintype α] {T : ℕ → ℝ} {g : ℝ → ℝ} {a b : α → ℝ} {r : α → ℕ → ℕ} [inst_1 : Nonempty α]
(R : AkraBazziRecurrence T g a b r) (q : ℝ → ℝ),
DifferentiableOn ℝ q (Set.Ioi 1) →
(AkraBazziRecurrence.GrowsPolynomially fun x ↦ ‖deriv q x‖) →
∀ (i : α), (fun n ↦ q ↑(r i n) - q (b i * ↑n)) =O[Filter.atTop] fun n ↦ deriv q ↑n * (↑(r i n) - b i * ↑n)
theorem AkraBazziRecurrence.rpow_p_mul_one_sub_smoothingFn_le E1 #
∀ {α : Type u_1} [inst : Fintype α] {T : ℕ → ℝ} {g : ℝ → ℝ} {a b : α → ℝ} {r : α → ℕ → ℕ} [inst_1 : Nonempty α]
(R : AkraBazziRecurrence T g a b r),
∀ᶠ (n : ℕ) in Filter.atTop,
∀ (i : α),
↑(r i n) ^ AkraBazziRecurrence.p a b * (1 - AkraBazziRecurrence.smoothingFn ↑(r i n)) ≤
b i ^ AkraBazziRecurrence.p a b * ↑n ^ AkraBazziRecurrence.p a b * (1 - AkraBazziRecurrence.smoothingFn ↑n)
theorem AkraBazziRecurrence.rpow_p_mul_one_add_smoothingFn_ge E1 #
∀ {α : Type u_1} [inst : Fintype α] {T : ℕ → ℝ} {g : ℝ → ℝ} {a b : α → ℝ} {r : α → ℕ → ℕ} [inst_1 : Nonempty α]
(R : AkraBazziRecurrence T g a b r),
∀ᶠ (n : ℕ) in Filter.atTop,
∀ (i : α),
b i ^ AkraBazziRecurrence.p a b * ↑n ^ AkraBazziRecurrence.p a b * (1 + AkraBazziRecurrence.smoothingFn ↑n) ≤
↑(r i n) ^ AkraBazziRecurrence.p a b * (1 + AkraBazziRecurrence.smoothingFn ↑(r i n))
theorem AkraBazziRecurrence.T_isBigO_smoothingFn_mul_asympBound E2 #
∀ {α : Type u_1} [inst : Fintype α] {T : ℕ → ℝ} {g : ℝ → ℝ} {a b : α → ℝ} {r : α → ℕ → ℕ} [inst_1 : Nonempty α]
(R : AkraBazziRecurrence T g a b r),
T =O[Filter.atTop] fun n ↦ (1 - AkraBazziRecurrence.smoothingFn ↑n) * AkraBazziRecurrence.asympBound g a b n
The main proof of the upper-bound part of the Akra-Bazzi theorem. The factor 1 - ε n does not
change the asymptotic order, but it is needed for the induction step to go through.
theorem AkraBazziRecurrence.smoothingFn_mul_asympBound_isBigO_T E2 #
∀ {α : Type u_1} [inst : Fintype α] {T : ℕ → ℝ} {g : ℝ → ℝ} {a b : α → ℝ} {r : α → ℕ → ℕ} [inst_1 : Nonempty α]
(R : AkraBazziRecurrence T g a b r),
(fun n ↦ (1 + AkraBazziRecurrence.smoothingFn ↑n) * AkraBazziRecurrence.asympBound g a b n) =O[Filter.atTop] T
The main proof of the lower-bound part of the Akra-Bazzi theorem. The factor 1 + ε n does not
change the asymptotic order, but it is needed for the induction step to go through.
theorem AkraBazziRecurrence.isBigO_asympBound E3 #
∀ {α : Type u_1} [inst : Fintype α] {T : ℕ → ℝ} {g : ℝ → ℝ} {a b : α → ℝ} {r : α → ℕ → ℕ} [inst_1 : Nonempty α]
(R : AkraBazziRecurrence T g a b r), T =O[Filter.atTop] AkraBazziRecurrence.asympBound g a b
The Akra-Bazzi theorem: T ∈ O(n^p (1 + ∑_u^n g(u) / u^{p+1}))
theorem AkraBazziRecurrence.isBigO_symm_asympBound E2 #
∀ {α : Type u_1} [inst : Fintype α] {T : ℕ → ℝ} {g : ℝ → ℝ} {a b : α → ℝ} {r : α → ℕ → ℕ} [inst_1 : Nonempty α]
(R : AkraBazziRecurrence T g a b r), AkraBazziRecurrence.asympBound g a b =O[Filter.atTop] T
The Akra-Bazzi theorem: T ∈ Ω(n^p (1 + ∑_u^n g(u) / u^{p+1}))
theorem AkraBazziRecurrence.isTheta_asympBound E3 #
∀ {α : Type u_1} [inst : Fintype α] {T : ℕ → ℝ} {g : ℝ → ℝ} {a b : α → ℝ} {r : α → ℕ → ℕ} [inst_1 : Nonempty α]
(R : AkraBazziRecurrence T g a b r), T =Θ[Filter.atTop] AkraBazziRecurrence.asympBound g a b
The Akra-Bazzi theorem: T ∈ Θ(n^p (1 + ∑_u^n g(u) / u^{p+1}))