Documentation

LeanPool.OrderMaintenance.Proof.Word.Core

Theorem W, stage B1: the core's write sites #

Stored-value bounds for the operations in OrderMaintenance/Model/Core.lean, excluding FALLBACK. The classes of docs/WORD.md §2:

The pure state functions that the cost proof uses for each step (linkElem, allocGroup, linkGroupPair, sizeAdj, moveLState, ..., cmoveSizes, markState) get lemmas wb_*; the monadic functions get Hoare triples ht_*.

Room for labels: the label widths are at most K.

Instances For
    theorem OrderMaintenance.Proof.Word.shift_lt {B K : ℕ} (hB : B ≤ K) :
    1 <<< B ≤ 2 ^ K
    theorem OrderMaintenance.Proof.Word.center_lt {B K : ℕ} (hB : B ≤ K) (hK : 1 ≤ K ∨ 1 ≤ B) :
    1 <<< (B - 1) < 2 ^ K
    theorem OrderMaintenance.Proof.Word.allX_foldChk {K y : ℕ} (hy : y < 2 ^ K) (u labs : List ℕ) (a : Array Model.Group) :
    (∀ (i : ℕ), GroupB K (a.getX i)) → (∀ l ∈ labs, l < 2 ^ K) → ∀ (i : ℕ), GroupB K ((List.foldl (fun (a : Array Model.Group) (p : ℕ × ℕ) => a.modify p.1 fun (G : Model.Group) => { next := G.next, prev := G.prev, first := G.first, last := G.last, chk := y, lab := p.2, size := G.size, st := G.st, src := G.src, l := G.l, r := G.r, alive := G.alive }) a (u.zip labs)).getX i)

    The groups u take chunk y and the labels labs.

    Pure state functions #

    theorem OrderMaintenance.Proof.Word.wb_linkElem {K : ℕ} {s : Model.Core} (h : WB K s) {x y lab hh : ℕ} (hx : x < 2 ^ K) (hy : y < 2 ^ K) (hl : lab < 2 ^ K) (hg : (s.Gs.getX (s.E.getX x).grp).size + 1 < 2 ^ K) (hc : s.count + 1 < 2 ^ K) :
    WB K (Model.linkElem s x y lab hh)

    Element insertion: the new index y (F), its label (Lab), the group size and the count (Sz).

    theorem OrderMaintenance.Proof.Word.wb_allocGroup {K : ℕ} {s : Model.Core} (h : WB K s) {c : ℕ} (hc : c < 2 ^ K) (hsz : s.freeG = [] → s.Gs.size < 2 ^ K) :
    WB K (allocGroup s c).2 ∧ (allocGroup s c).1 < 2 ^ K

    Group allocation: a free group (R) or the next index (F).

    theorem OrderMaintenance.Proof.Word.wb_linkGroupPair {K : ℕ} {s : Model.Core} (h : WB K s) {g gl gr labL labR : ℕ} (hg : g < 2 ^ K) (hgl : gl < 2 ^ K) (hgr : gr < 2 ^ K) (hL : labL < 2 ^ K) (hR : labR < 2 ^ K) :
    WB K (Model.linkGroupPair s g gl gr labL labR)
    theorem OrderMaintenance.Proof.Word.wb_unlinkGroup {K : ℕ} {s : Model.Core} (h : WB K s) {g : ℕ} (hg : g < 2 ^ K) :
    theorem OrderMaintenance.Proof.Word.wb_moveFirstLeft {K : ℕ} {s : Model.Core} (h : WB K s) {g gl e lab : ℕ} (hgl : gl < 2 ^ K) (he : e < 2 ^ K) (hl : lab < 2 ^ K) :
    WB K (Model.moveFirstLeft s g gl e lab)
    theorem OrderMaintenance.Proof.Word.wb_moveLastRight {K : ℕ} {s : Model.Core} (h : WB K s) {g gr e lab : ℕ} (hgr : gr < 2 ^ K) (he : e < 2 ^ K) (hl : lab < 2 ^ K) :
    WB K (Model.moveLastRight s g gr e lab)
    theorem OrderMaintenance.Proof.Word.wb_sizeAdj {K : ℕ} {s : Model.Core} (h : WB K s) {a b : ℕ} (hb : (s.Gs.getX b).size + 1 < 2 ^ K) :
    WB K (sizeAdj s a b)

    A size moved from a to b: the decrement is bounded by the old size (R), the increment needs the bound (Sz).

    theorem OrderMaintenance.Proof.Word.wb_sizeState {K : ℕ} {s : Model.Core} (h : WB K s) {c : ℕ} (hc : (s.C.getX c).size + 1 < 2 ^ K) :
    WB K (sizeState s c)
    theorem OrderMaintenance.Proof.Word.wb_linkChunkPair {K : ℕ} {s : Model.Core} (h : WB K s) {x y z : ℕ} (hx : x < 2 ^ K) (hy : y < 2 ^ K) (hz : z < 2 ^ K) :
    theorem OrderMaintenance.Proof.Word.wb_markState {K : ℕ} {s : Model.Core} (h : WB K s) {x y z : ℕ} {job : Model.Job} (hx : x < 2 ^ K) (hy : y < 2 ^ K) (hz : z < 2 ^ K) (hj : JobB K job) :
    WB K (markState s x y z job)
    theorem OrderMaintenance.Proof.Word.wb_removeState {K : ℕ} {s : Model.Core} (h : WB K s) {p : ℕ} (hp : p < 2 ^ K) :
    WB K (removeState s p)
    theorem OrderMaintenance.Proof.Word.wb_moveGroupsLeft {K : ℕ} {s : Model.Core} (h : WB K s) {x y : ℕ} {u labs : List ℕ} (hy : y < 2 ^ K) (hu : ∀ g ∈ u, g < 2 ^ K) (hl : ∀ l ∈ labs, l < 2 ^ K) :
    WB K (Model.moveGroupsLeft s x y u labs)
    theorem OrderMaintenance.Proof.Word.wb_moveGroupsRight {K : ℕ} {s : Model.Core} (h : WB K s) {x z : ℕ} {u labs : List ℕ} (hz : z < 2 ^ K) (hu : ∀ g ∈ u, g < 2 ^ K) (hl : ∀ l ∈ labs, l < 2 ^ K) :
    WB K (Model.moveGroupsRight s x z u labs)
    theorem OrderMaintenance.Proof.Word.wb_cmoveSizes {K : ℕ} {s : Model.Core} (h : WB K s) {x dst : ℕ} {u : List ℕ} (hd : (s.C.getX dst).size + (List.map (fun (g : ℕ) => (s.Gs.getX g).size) u).sum < 2 ^ K) :
    WB K (cmoveSizes s x dst u)

    Chunk sizes after a chunk-split move: the decrement is R, the increment needs the bound.

    Labels (class Lab) #

    theorem OrderMaintenance.Proof.Word.ht_between {K : ℕ} {P0 : Model.Params} {a b : ℕ} {why : String} (hb : b < 2 ^ K) :
    HT K P0 (Model.between a b why) fun (x : ℕ) => x < 2 ^ K
    theorem OrderMaintenance.Proof.Word.ht_after {K : ℕ} {P0 : Model.Params} {a D B : ℕ} {why : String} (hB : B ≤ K) :
    HT K P0 (Model.after a D B why) fun (x : ℕ) => x < 2 ^ K
    theorem OrderMaintenance.Proof.Word.ht_before {K : ℕ} {P0 : Model.Params} {b D : ℕ} {why : String} (hb : b < 2 ^ K) :
    HT K P0 (Model.before b D why) fun (x : ℕ) => x < 2 ^ K
    theorem OrderMaintenance.Proof.Word.ht_labBefore {K : ℕ} {P0 : Model.Params} (g : ℕ) :
    HT K P0 (Model.labBefore g) fun (x : ℕ) => x < 2 ^ K
    theorem OrderMaintenance.Proof.Word.ht_labAfter {K : ℕ} {P0 : Model.Params} (g : ℕ) (hL : LabRoom K P0) :
    HT K P0 (Model.labAfter g) fun (x : ℕ) => x < 2 ^ K
    theorem OrderMaintenance.Proof.Word.ht_pushBackLabs {K : ℕ} {P0 : Model.Params} {center D B : ℕ} (hc : center < 2 ^ K) (hB : B ≤ K) (prev : Option ℕ) (k : ℕ) :
    HT K P0 (Model.pushBackLabs center D B prev k) fun (l : List ℕ) => ∀ a ∈ l, a < 2 ^ K
    theorem OrderMaintenance.Proof.Word.ht_pushFrontLabs {K : ℕ} {P0 : Model.Params} {center D : ℕ} (hc : center < 2 ^ K) (nxt : Option ℕ) :
    (∀ (n : ℕ), nxt = some n → n < 2 ^ K) → ∀ (k : ℕ), HT K P0 (Model.pushFrontLabs center D nxt k) fun (l : List ℕ) => ∀ a ∈ l, a < 2 ^ K

    Queries and deletion (class R) #

    theorem OrderMaintenance.Proof.Word.ht_order {K : ℕ} {P0 : Model.Params} (x y : ℕ) :
    HT K P0 (Model.order x y) fun (x : Bool) => True

    Chunk sizes (class Sz) #

    theorem OrderMaintenance.Proof.Word.wb_chunkSize {K : ℕ} {s : Model.Core} (h : WB K s) {c : ℕ} {inc : Bool} (hc : c < 2 ^ K) (hsz : inc = true → (s.C.getX c).size + 1 < 2 ^ K) :

    The size update of a chunk and the queue's: the increment needs the bound.

    Element insertion #

    theorem OrderMaintenance.Proof.Word.insertElem_wb {K : ℕ} {s : Model.Core} (h : WB K s) (hL : LabRoom K s.P) {x hh y : ℕ} {s' : Model.Core} (hr : EStateM.run (Model.insertElem x hh) s = EStateM.Result.ok y s') (hx : x < 2 ^ K) (hy : s.E.size < 2 ^ K) (hg : (s.Gs.getX (s.E.getX x).grp).size + 1 < 2 ^ K) (hc : s.count + 1 < 2 ^ K) :
    y = s.E.size ∧ WB K s' ∧ ∃ (lab : ℕ), s' = Model.linkElem s x s.E.size lab hh

    An element insertion writes the new element with a label below 2^K (Lab): the label is below the next element's (between) or below 2^elementBits (after).

    Group splits #

    theorem OrderMaintenance.Proof.Word.wb_splitState {K : ℕ} {s : Model.Core} (h : WB K s) {g labL labR : ℕ} (hg : g < 2 ^ K) (hlL : labL < 2 ^ K) (hlR : labR < 2 ^ K) (hroom : s.Gs.size + 2 ≤ 2 ^ K) :
    WB K (splitState s g labL labR)

    A split start: two fresh groups (F; room for two more groups is the hypothesis) and two labels (Lab, from labBefore/labAfter).

    theorem OrderMaintenance.Proof.Word.wb_moveLState {K : ℕ} {s : Model.Core} (h : WB K s) (hL : LabRoom K s.P) {p : ℕ} (hroom : gF s (gLl s p) ≠ Model.NIL → eL s (gLs s (gLl s p)) + s.P.elementSpacing < 1 <<< s.P.elementBits) (hsz : gSz s (gLl s p) + 1 < 2 ^ K) :
    WB K (moveLState s p)

    A move of the first element of a splitting group to its left sibling: the label (Lab, from the room condition of the move) and the sibling's size (Sz, the hypothesis).

    theorem OrderMaintenance.Proof.Word.wb_moveRState {K : ℕ} {s : Model.Core} (h : WB K s) (hL : LabRoom K s.P) {p : ℕ} (hsz : gSz s (gRr s p) + 1 < 2 ^ K) :
    WB K (moveRState s p)

    The move to the right sibling.

    Chunk splits #

    theorem OrderMaintenance.Proof.Word.unitCand_lt {K : ℕ} {s : Model.Core} (h : WB K s) (x : ℕ) (left : Bool) (a : ℕ) :
    a ∈ Model.unitCand s x left → a < 2 ^ K
    theorem OrderMaintenance.Proof.Word.foldChk_size_eq {y : ℕ} (u labs : List ℕ) (a : Array Model.Group) (g : ℕ) :
    ((List.foldl (fun (a : Array Model.Group) (p : ℕ × ℕ) => a.modify p.1 fun (G : Model.Group) => { next := G.next, prev := G.prev, first := G.first, last := G.last, chk := y, lab := p.2, size := G.size, st := G.st, src := G.src, l := G.l, r := G.r, alive := G.alive }) a (u.zip labs)).getX g).size = (a.getX g).size
    theorem OrderMaintenance.Proof.Word.wb_cmoveLState {K : ℕ} {s : Model.Core} (h : WB K s) {x : ℕ} {u labs : List ℕ} (hu : ∀ g ∈ u, g < 2 ^ K) (hl : ∀ l ∈ labs, l < 2 ^ K) (hsz : cSz s (cLl s x) + (List.map (fun (g : ℕ) => gSz s g) u).sum < 2 ^ K) :
    WB K (cmoveLState s x u labs)

    A chunk-split move to the left sibling: the groups' labels (Lab), and the sibling's size plus the moved groups' sizes (Sz, the hypothesis).

    theorem OrderMaintenance.Proof.Word.wb_cmoveRState {K : ℕ} {s : Model.Core} (h : WB K s) {x : ℕ} {u labs : List ℕ} (hu : ∀ g ∈ u, g < 2 ^ K) (hl : ∀ l ∈ labs, l < 2 ^ K) (hsz : cSz s (cRr s x) + (List.map (fun (g : ℕ) => gSz s g) u).sum < 2 ^ K) :
    WB K (cmoveRState s x u labs)
    theorem OrderMaintenance.Proof.Word.ht_pushLabsL {K : ℕ} {P0 : Model.Params} {s : Model.Core} (hL : LabRoom K s.P) (x k : ℕ) :
    HT K P0 (pushLabsL s x k) fun (l : List ℕ) => ∀ a ∈ l, a < 2 ^ K

    The labels of a left move are below 2^K (Lab: after with groupBits ≤ K, or the centre).

    theorem OrderMaintenance.Proof.Word.ht_pushLabsR {K : ℕ} {P0 : Model.Params} {s : Model.Core} (h : WB K s) (hL : LabRoom K s.P) (x k : ℕ) :
    HT K P0 (pushLabsR s x k) fun (l : List ℕ) => ∀ a ∈ l, a < 2 ^ K

    Reservation: the split start's own writes #

    theorem OrderMaintenance.Proof.Word.jobB_copy {K x y z : ℕ} (hK : 1 ≤ K) (hx : x < 2 ^ K) (hy : y < 2 ^ K) (hz : z < 2 ^ K) :
    JobB K { x := x, y := y, z := z, pc := Model.JobPc.copy 1 }

    Context-free triples for the remaining steps (classes R and Lab) #

    theorem OrderMaintenance.Proof.Word.ht_key {K : ℕ} {P0 : Model.Params} (e : ℕ) :
    HT K P0 (Model.key e) fun (x : ℕ × ℕ × ℕ) => True
    theorem OrderMaintenance.Proof.Word.ht_unlinkStep {K : ℕ} {P0 : Model.Params} {g : ℕ} (hg : g < 2 ^ K) :
    HT K P0 (Model.unlinkStep g) fun (x : Unit) => True
    theorem OrderMaintenance.Proof.Word.ht_unit {K : ℕ} {P0 : Model.Params} (x : ℕ) (left : Bool) :
    HT K P0 (Model.unit x left) fun (u : List ℕ) => ∀ a ∈ u, a < 2 ^ K
    theorem OrderMaintenance.Proof.Word.ht_markSplit {K : ℕ} {P0 : Model.Params} {x y z : ℕ} {job : Model.Job} (hx : x < 2 ^ K) (hy : y < 2 ^ K) (hz : z < 2 ^ K) (hj : JobB K job) :
    HT K P0 (Model.markSplit x y z job) fun (x : Unit) => True

    A chunk removal: the chunk dies, its siblings become quiet and may enter the queue (R).

    theorem OrderMaintenance.Proof.Word.ht_moveElem {K : ℕ} {P0 : Model.Params} (g : ℕ) (hL : LabRoom K P0) :
    HT K P0 (Model.moveElem g) fun (x : ℕ) => x < 2 ^ K

    A move of one element of a splitting group to a sibling (R, Lab).

    theorem OrderMaintenance.Proof.Word.ht_moveUnit {K : ℕ} {P0 : Model.Params} (x : ℕ) (left : Bool) (hL : LabRoom K P0) :
    HT K P0 (Model.moveUnit x left) fun (r : ℕ × List ℕ) => r.1 < 2 ^ K ∧ ∀ a ∈ r.2, a < 2 ^ K

    A chunk-split move of a unit of groups (R, Lab).