Halving recurrences #
A cost T with T n ≤ a T(⌈n/2⌉) + c n for n ≥ 2 grows like a ^ ⌈log₂ n⌉. The
substitution method proves this exactly, with a subtracted linear term
(Nat.add_mul_two_pow_le_mul_pow_of_halving). Assume
1 ≤ aand the slack condition2 c + 2 β ≤ a β;- the base case
T n + β ≤ αfor everyn ≤ 1; - the step: for every
n ≥ 2and everyS, ifT m ≤ Sfor allm ≤ (n + 1) / 2, thenT n ≤ a S + c n.
Then T n + β 2 ^ k ≤ α a ^ k for all k and n ≤ 2 ^ k. Because the step only uses a common
bound S on all sizes up to ⌈n/2⌉, recurrences that split n into ⌊n/2⌋ and ⌈n/2⌉, or
that are not monotone, are covered directly. Nat.pow_clog_two_le_mul_rpow_logb in
CslibFrontier.Foundations.Data.Nat.LogTwoRpow converts a ^ ⌈log₂ n⌉ to n ^ log₂ a.
Main results #
Nat.add_mul_two_pow_le_mul_pow_of_halving: the halving recurrence at a power of two.Nat.add_mul_two_pow_clog_le_of_halving: the same atk = ⌈log₂ n⌉.Nat.clog_two_lt_clog_two_of_le_half: halving lowers⌈log₂⌉, for2 ≤ mandk ≤ ⌈m / 2⌉.Nat.pow_mul_le_of_step: geometric halving bound2 ^ r * C r ≤ C 0from2 * C (k + 1) ≤ C k.
References #
- Cormen, Leiserson, Rivest and Stein, Introduction to Algorithms, Section 4.3 (the substitution method, including subtracting a lower-order term).
Halving recurrence. If T n ≤ a S + c n whenever S bounds T on [0, ⌈n/2⌉] and
n ≥ 2, then T n + β 2 ^ k ≤ α a ^ k for n ≤ 2 ^ k, provided the base case
T n + β ≤ α for n ≤ 1 and the slack condition 2 c + 2 β ≤ a β.
Halving recurrence at k = ⌈log₂ n⌉: T n + β 2 ^ ⌈log₂ n⌉ ≤ α a ^ ⌈log₂ n⌉.