The list update problem: arrangements, inversions and the cost model #
This file instantiates Cslib.DataStructure.Online.Problem for the static list update (list
accessing) problem of Sleator and Tarjan, Amortized Efficiency of List Update and Paging
Rules, Section 2; see also Borodin and El-Yaniv, Online Computation and
Competitive Analysis, Chapter 1.
Over a finite universe α, a configuration is an arrangement: a duplicate-free list containing
every element of α (IsArrangement). Serving a request r by moving from arrangement s to
arrangement s' costs
stepCost s r s' = inversions s s' + (s'.idxOf r + 1),
where inversions s s' counts the pairs of items in different relative order in s and s',
and s'.idxOf r + 1 is the 1-based position of r in s'.
Relation to the Sleator–Tarjan cost model #
In [ST85a], accessing the ith item costs i. Immediately after the access, the
accessed item may be moved forward at no cost ("free exchanges"), and any other exchange of
adjacent items costs 1 ("paid exchanges"). stepCost s r s' is the cheapest way to go from s
to s' while serving r in that model. Doing the paid exchanges first and then accessing r
costs exactly stepCost s r s'. Conversely, any implementation that pays for X exchanges,
accesses r at position i and then moves it forward F places satisfies
X + i ≥ stepCost s r s': each adjacent exchange changes the inversion count by one, and moving
r forward F places creates F inversions. Paid exchanges made after an access can be counted
as made before the next access (and dropped after the last one), so this form of a step is no
restriction. Every online strategy and every offline schedule therefore costs at least as much in
the Sleator–Tarjan model as in this one, and move-to-front costs the same in both (moveToFront,
in CslibFrontier.DataStructure.ListUpdate.MoveToFront).
This justification is informal and is not formalized here.
Main definitions #
Cslib.DataStructure.ListUpdate.IsArrangement: duplicate-free lists containing every element.ListUpdate.inversionSet,ListUpdate.inversions: ordered pairs in different relative order, and their number (the Kendall tau distance between the two arrangements).ListUpdate.crossBefore: items in front ofrin one list and behind it in another.ListUpdate.stepCost,ListUpdate.problem: the list-updateOnline.Problem.ListUpdate.accessCost,ListUpdate.exchangeCost: the access and rearrangement parts of a schedule's cost.
Main results #
inversions_self,inversions_comm,inversions_triangle,two_mul_inversions_le: the inversion count is a metric on arrangements bounded byn (n - 1) / 2.card_filter_idxOf_lt: in an arrangement, exactlyl.idxOf ritems preceder.idxOf_le_card_crossBefore_add,card_filter_ne_add_card_crossBefore_le,idxOf_le_inversions_add: counting items that change sides ofr; in particularl.idxOf r ≤ inversions l l' + l'.idxOf r.scheduleCost_eq_accessCost_add_exchangeCost: cost decomposition of schedules.
References #
An arrangement of the universe α is a duplicate-free list containing every element.
The enumeration Finset.univ.toList of a finite type is an arrangement.
An arrangement lists each element of α exactly once.
The reversal of an arrangement is an arrangement.
Positions in an arrangement are injective.
Positions in a list and its reversal add up to the length minus one.
In an arrangement, exactly l.idxOf r items precede r.
Inversions #
Ordered pairs (x, y) with x before y in l but y before x in l'.
The number of pairs of items in different relative order in l and l' (the Kendall tau
distance between two arrangements).
Triangle inequality for inversions through an intermediate arrangement.
Any two lists have at most n (n - 1) / 2 inversions, where n = Fintype.card α.
Items that precede r in l but follow it in l'.
The inversions avoiding r and the inversions (x, r) are disjoint parts of all inversions.
Items in front of r in l are either in front of r in l' or in crossBefore l l' r.
If r sits at position l.idxOf r in l, then moving to l' either creates inversions or
keeps the items in front of r: l.idxOf r ≤ inversions l l' + l'.idxOf r.
The list-update problem #
Cost of serving request r by moving from arrangement s to arrangement s': the inversions
between s and s' (paid exchanges) plus the 1-based position of r in s' (access).
The list-update Online.Problem over a finite universe α: configurations are arrangements,
every arrangement is reachable in one step, and stepCost charges rearrangement plus access.
Total access cost ∑ᵢ pos(rᵢ, sᵢ) of a schedule.
Total rearrangement cost ∑ᵢ inversions(sᵢ₋₁, sᵢ) of a schedule starting at s.
The cost of a schedule splits into access cost and rearrangement cost.