The wrapper: cost and Lemma W #
Every core the wrapper runs satisfies the cost invariant whenever an operation reaches it, and its element count stays within its capacity (Lemma W). So no core operation ever takes FALLBACK.
The split at the cursor #
The elements before the cursor.
Equations
- OrderMaintenance.Proof.preOf l c = List.takeWhile (fun (x : ℕ) => decide (x ≠ c)) l
Instances For
The elements from the cursor on.
Equations
- OrderMaintenance.Proof.postOf l c = List.dropWhile (fun (x : ℕ) => decide (x ≠ c)) l
Instances For
The element count of a core equals its list's length (an extra invariant the wrapper uses).
Instances For
What the wrapper's cost proof assumes: the top structure's contracts (M5), the parameter
conditions, and Lemma R's I5 (M5 fixes J and H).
- top : TopContractP TI μ Jf capf
- prep : PrepContract TI PI ν PP
- pp (N : ℕ) : PP (mk N)
Instances For
A core in service: the cost invariant for its element list, which it counts.
Instances For
Insertion into a core in service: no FALLBACK while its count stays within capacity.
Deletion in a core in service.
A core whose top structure is being built: it holds the sentinel alone.
- pi : PI n
Instances For
A lazily built fresh core.
An eagerly built fresh core is in service.
A preparation step of a core being built: it finishes (the core is in service) or it
decreases ν.
Lemma W's record of a rebuild in progress: c₀ elements and live₀ live ones at the
trigger, I insertions and D deletions since. The work left (preparation steps, then the
elements not yet scanned) shrinks by K_B − 1 per insertion's worth of operations.
Instances For
The wrapper's cost invariant: Invariant R, both cores' cost invariants, and Lemma W.
- w : WInv om Sp
Instances For
The work left bounds the insertions of a rebuild.
The remaining rebuild work bounds its insertion counter.
Lemma W (1): cur has room for an insertion.
The copies in nxt are live elements of cur, so at most the live count.
Lemma W (2): nxt has room for an insertion.
A copy step keeps the nxt core in service and its fill bound, and advances the cursor.
The rebuild loop's cost invariant, with budget steps left, within the entry potential Φe.
Instances For
What the rebuild loop leaves: the rebuild goes on, having spent the whole budget, or nxt
replaced cur.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Finishing preparation initializes the shared service invariant at the first cursor.
An unfinished preparation spends one budget unit as its potential decreases.
A copy preserves the service invariant when its cursor drops one remaining element.
The live copies are at most the live count, inside the loop.
The rebuild loop (Lemma W's length argument): every budgeted step shrinks the work left by one; the loop ends with the budget spent or with the swap.
Lemma W's record in the middle of an operation: this operation's insertion or deletion is
counted, and its K_B rebuild steps are still to come.
Instances For
The middle-of-operation bounds initialize the rebuild loop's entry potential.
Insertion advances the counters and spends at most one operation's rebuild allowance.
Deletion advances its counter without spending additional insertion allowance.
The rebuild step (Lemma W): it restores the wrapper's cost invariant.
Mirroring an insertion into nxt keeps it in service, within its fill bound.
A wrapper insertion keeps the wrapper's cost invariant: the insertions into cur and
nxt take no FALLBACK, and Lemma W's record advances.
Mirroring a deletion into nxt keeps it in service; the fill bound counts the deletion.
A wrapper deletion keeps the wrapper's cost invariant.
Initialization establishes the wrapper's cost invariant.
Each operation keeps the wrapper's cost invariant.
The wrapper's cost theorem (Level F). Under the setup, the structure initializes into a
state satisfying the cost invariant, and every valid operation keeps it. In every such state,
both cores satisfy the cost invariant within their capacities, so each of their insertions takes
no FALLBACK (CoreOK.insert, insertAfter_cost).
In a state satisfying the wrapper's cost invariant, cur is a core in service with room for
an insertion, and so is nxt once its preparation is over.