Documentation

CslibFrontier.DataStructure.ListUpdate.MoveToFront

Move-to-front is 2-competitive for list update #

This file formalizes Theorem 1 of Sleator and Tarjan, Amortized Efficiency of List Update and Paging Rules, Section 2 in the list-update model of CslibFrontier.DataStructure.ListUpdate.Basic. It includes the generalization stated after the proof, where the online and offline lists start from different arrangements.

The move-to-front strategy mtf serves request r by moving r to the front of its list, without changing the relative order of the other items. It pays exactly the position of r (stepCost_moveToFront). For every offline schedule serving m requests, starting from an arrangement s₀ while move-to-front starts from m₀, cost_MTF + inversions(final MTF list, final offline list) + m ≤ 2 * accessCost + exchangeCost + inversions m₀ s₀ (mtf_cost_add_inversions_add_length_le). This is the Sleator–Tarjan bound C_MF(s) ≤ 2 C_A(s) + X_A(s) - F_A(s) - m + I, with the offline schedule's paid and free exchanges accounted for by exchangeCost, which counts the inversions between consecutive offline arrangements. The module docstring of CslibFrontier.DataStructure.ListUpdate.Basic gives the informal translation between the two cost models; it is not formalized.

The proof uses the Sleator–Tarjan potential, the number of inversions between move-to-front's list and the offline list. Serving r costs move-to-front k = pos(r). Moving r to the front creates at most pos_A(r) - 1 new inversions and destroys at least k - pos_A(r) old ones, for an amortized cost of at most 2 pos_A(r) - 1 (inversions_moveToFront_le). A rearrangement by the offline schedule raises the potential by at most its own cost (inversions_triangle).

Main definitions #

Main results #

References #

Move r to the front of l, keeping the relative order of the other items.

theorem Cslib.DataStructure.ListUpdate.idxOf_moveToFront_of_ne {α : Type} [DecidableEq α] {r x : α} (h : x ≠ r) (l : List α) :

List.idxOf_cons_ne for moveToFront, the companion of idxOf_moveToFront_self: every other item moves back one place.

theorem Cslib.DataStructure.ListUpdate.idxOf_erase_lt_iff {α : Type} [DecidableEq α] {r x y : α} (hx : x ≠ r) (hy : y ≠ r) (l : List α) :

Erasing r keeps the relative order of the other items.

theorem Cslib.DataStructure.ListUpdate.idxOf_moveToFront_lt_iff {α : Type} [DecidableEq α] {r x y : α} (hx : x ≠ r) (hy : y ≠ r) (l : List α) :

Moving r to the front keeps the relative order of the other items.

Moving an item to the front of an arrangement gives an arrangement.

@[reducible, inline]

The move-to-front strategy for list update over the finite universe α.

Moving r to the front creates exactly l.idxOf r inversions.

Move-to-front pays exactly the position of the requested item.

theorem Cslib.DataStructure.ListUpdate.inversions_moveToFront_le {α : Type} [DecidableEq α] [Fintype α] {m L : List α} (hm : IsArrangement m) (hL : IsArrangement L) (r : α) :
List.idxOf r m + 1 + inversions (moveToFront r m) L ≤ 2 * (List.idxOf r L + 1) - 1 + inversions m L

Amortized step inequality ([ST85a], proof of Theorem 1): if r is at position k = m.idxOf r + 1 in move-to-front's list and at position i = L.idxOf r + 1 in the offline list, then moving r to the front changes the potential by at most 2i - 1 - k.

theorem Cslib.DataStructure.ListUpdate.mtf_costFrom_add_inversions_add_length_le {α : Type} [DecidableEq α] [Fintype α] {m₀ s₀ : List α} (hm₀ : IsArrangement m₀) (hs₀ : IsArrangement s₀) {reqs : List α} {states : List (List α)} (hv : (problem α).ValidSchedule s₀ reqs states) :
(mtf α).costFrom m₀ reqs + inversions ((mtf α).runMem m₀ reqs) ((problem α).finalState s₀ states) + reqs.length ≤ 2 * accessCost reqs states + exchangeCost s₀ reqs states + inversions m₀ s₀

Move-to-front bound ([ST85a], Theorem 1 and the remark after its proof): for every valid offline schedule states serving reqs from s₀, move-to-front started from m₀ satisfies cost + inversions(final lists) + |reqs| ≤ 2 * accessCost + exchangeCost + inversions m₀ s₀.

theorem Cslib.DataStructure.ListUpdate.mtf_cost_add_inversions_add_length_le {α : Type} [DecidableEq α] [Fintype α] {m₀ s₀ : List α} (hm₀ : IsArrangement m₀) (hs₀ : IsArrangement s₀) {reqs : List α} {states : List (List α)} (hv : (problem α).ValidSchedule s₀ reqs states) :
(mtf α).cost m₀ reqs + inversions ((mtf α).runMem m₀ reqs) ((problem α).finalState s₀ states) + reqs.length ≤ 2 * accessCost reqs states + exchangeCost s₀ reqs states + inversions m₀ s₀

[ST85a], Theorem 1 with different initial lists, for DetStrategy.cost.

theorem Cslib.DataStructure.ListUpdate.mtf_cost_add_length_le {α : Type} [DecidableEq α] [Fintype α] {m₀ s₀ : List α} (hm₀ : IsArrangement m₀) (hs₀ : IsArrangement s₀) {reqs : List α} {states : List (List α)} (hv : (problem α).ValidSchedule s₀ reqs states) :
(mtf α).cost m₀ reqs + reqs.length ≤ 2 * (problem α).scheduleCost s₀ reqs states + inversions m₀ s₀

Move-to-front costs at most twice any offline schedule, plus the initial inversions: cost_MTF ≤ 2 * cost_A - |reqs| + inversions m₀ s₀.

Move-to-front is (2, 0)-competitive from a common initial arrangement.

Move-to-front is (2, n (n - 1) / 2)-competitive across arbitrary initial arrangements, where n = Fintype.card α.