Documentation

CslibFrontier.Algorithms.Lean.OptimalBST.Yao

The quadrangle inequality and monotone optimal roots #

An interval weight f : ℕ → ℕ → β satisfies the quadrangle inequality (QuadrangleIneq) if f i j + f i' j' ≤ f i j' + f i' j whenever i ≤ i' ≤ j ≤ j', and is monotone on intervals (MonotoneOnIntervals) if f i' j ≤ f i j' whenever [i', j] ⊆ [i, j']. Yao proved that if the weight w has both properties, then the optimal cost c = optCost w of the interval recurrence satisfies the quadrangle inequality (quadrangleIneq_optCost), and that the quadrangle inequality for c makes the largest optimal root K = optRoot w monotone: K(i, j - 1) ≤ K(i, j) ≤ K(i + 1, j) (optRoot_mono). For optimal binary search trees this monotonicity is Knuth's theorem; Knuth's weight knuthWeight p q satisfies the quadrangle inequality with equality (knuthWeight_add_knuthWeight), and is monotone on intervals when the weights are nonnegative (monotoneOnIntervals_knuthWeight).

The monotonicity of roots is stated for the largest optimal root. It uses cancellation in β (IsOrderedCancelAddMonoid), which holds for ℕ, ℤ, ℚ and ℝ.

Main definitions #

Main results #

References #

def Cslib.Algorithms.Lean.OptimalBST.QuadrangleIneq {β : Type u_1} [Add β] [LE β] (f : ℕ → ℕ → β) :

The quadrangle inequality: f i j + f i' j' ≤ f i j' + f i' j for i ≤ i' ≤ j ≤ j'.

Monotonicity on the lattice of intervals: f i' j ≤ f i j' whenever [i', j] ⊆ [i, j'].

Yao's lemma: if w satisfies the quadrangle inequality and is monotone on intervals, then the optimal cost c = optCost w of the interval recurrence satisfies the quadrangle inequality.

Root monotonicity in the right endpoint, K(i, j) ≤ K(i, j + 1), for the largest optimal root whenever the optimal cost satisfies the quadrangle inequality.

theorem Cslib.Algorithms.Lean.OptimalBST.optRoot_le_optRoot_add_one_left {β : Type u_1} [AddCommMonoid β] [LinearOrder β] [IsOrderedCancelAddMonoid β] {w : ℕ → ℕ → β} (hc : QuadrangleIneq (optCost w)) {i j : ℕ} (hij : i < j) :
optRoot w i (j + 1) ≤ optRoot w (i + 1) (j + 1)

Root monotonicity in the left endpoint, K(i, j + 1) ≤ K(i + 1, j + 1) for i < j, for the largest optimal root whenever the optimal cost satisfies the quadrangle inequality.

theorem Cslib.Algorithms.Lean.OptimalBST.optRoot_mono {β : Type u_1} [AddCommMonoid β] [LinearOrder β] [IsOrderedCancelAddMonoid β] {w : ℕ → ℕ → β} (hqi : QuadrangleIneq w) (hmono : MonotoneOnIntervals w) {i j : ℕ} (hij : i + 1 < j) :
optRoot w i (j - 1) ≤ optRoot w i j ∧ optRoot w i j ≤ optRoot w (i + 1) j

Monotonicity of optimal roots (Knuth for binary search trees, Yao in general): under the quadrangle inequality and interval monotonicity of w, the largest optimal roots satisfy K(i, j - 1) ≤ K(i, j) ≤ K(i + 1, j) for i + 1 < j.

theorem Cslib.Algorithms.Lean.OptimalBST.knuthWeight_add_knuthWeight {β : Type u_1} [AddCommMonoid β] (p q : ℕ → β) {i i' j j' : ℕ} (h₁ : i ≤ i') (h₂ : i' ≤ j) (h₃ : j ≤ j') :
knuthWeight p q i j + knuthWeight p q i' j' = knuthWeight p q i j' + knuthWeight p q i' j

Knuth's weight satisfies the quadrangle inequality with equality.

theorem Cslib.Algorithms.Lean.OptimalBST.monotoneOnIntervals_knuthWeight {β : Type u_1} [AddCommMonoid β] [PartialOrder β] [IsOrderedAddMonoid β] {p q : ℕ → β} (hp : ∀ (k : ℕ), 0 ≤ p k) (hq : ∀ (g : ℕ), 0 ≤ q g) :

With nonnegative access and failure weights, Knuth's weight is monotone on intervals.