Documentation

LeanPool.OrderMaintenance.Proof.Word.TopStart

Theorem W, stage B2: a split's insertion into the top structure #

insertAround x y z reads labels for the new chunks y, z around x (insertAroundPrep, read-only), writes their tags (Tag), and inserts them into the tables, paths and children of the top structure (insertAroundFinish: R, F for y, z, Lab for the labels). The tags are bounded by the top invariant of the state after the split (tag_lt_of_topInv), as a hypothesis on the final state: the finish leaves the chunk records alone, so the final tags of y, z are the written ones.

Read-only and chunk-preserving runs #

The state is unchanged.

Equations
Instances For

    The chunk records are unchanged.

    Equations
    Instances For
      theorem OrderMaintenance.Proof.Word.cs_insertAroundFinish (x y z : ℕ) (tabs ly lz : List ℕ) (lp : ℕ) :
      Pres CS (Model.insertAroundFinish x y z tabs ly lz lp)
      theorem OrderMaintenance.Proof.Word.guardedSetTag_ok {s s' : Model.Core} {c t : ℕ} {u : PUnit.{1}} (h : EStateM.run (Model.guardedSetTag c t) s = EStateM.Result.ok u s') :
      s' = { P := s.P, E := s.E, Gs := s.Gs, C := s.C.modify c fun (C : Model.Chunk) => { next := C.next, prev := C.prev, first := C.first, last := C.last, size := C.size, st := C.st, src := C.src, l := C.l, r := C.r, tag := t, alive := C.alive }, freeG := s.freeG, count := s.count, head := s.head, tail := s.tail, firstGroup := s.firstGroup, firstChunk := s.firstChunk, ready := s.ready, prep := s.prep, resJob := s.resJob, fallbacks := s.fallbacks, pqHead := s.pqHead, pqNext := s.pqNext, pqPrev := s.pqPrev, pqWhere := s.pqWhere, nbNext := s.nbNext, nbPrev := s.nbPrev, pqHi := s.pqHi, pqLo := s.pqLo, nodes := s.nodes, path := s.path, cin := s.cin, lpar := s.lpar }

      A guarded tag write that succeeds writes the tag.

      Triples #

      theorem OrderMaintenance.Proof.Word.NodeB.tab {K : ℕ} {n : Model.Node} (h : NodeB K n) (p : ℕ × ℕ) :
      p ∈ n.table → p.1 < 2 ^ K ∧ p.2 < 2 ^ K
      theorem OrderMaintenance.Proof.Word.NodeB.sd {K : ℕ} {n : Model.Node} (h : NodeB K n) (p : ℕ × Model.Side) :
      p ∈ n.side → p.1 < 2 ^ K
      theorem OrderMaintenance.Proof.Word.half_lt {lo hi B : ℕ} (h : ¬lo ≥ hi) (hB : hi ≤ B) :
      (lo + hi - 1) / 2 < B
      theorem OrderMaintenance.Proof.Word.ht_roomNextTo {K : ℕ} {P0 : Model.Params} (hβ : P0.beta ≤ K) (t e : ℕ) (b : Bool) :
      HT K P0 (Model.roomNextTo t e b) fun (x : ℕ) => x < 2 ^ K

      A label next to an entry is below its upper neighbour, a label or 2^β, hence below 2^K.

      theorem OrderMaintenance.Proof.Word.ht_tableInsert {K : ℕ} {P0 : Model.Params} {t e new : ℕ} {before : Bool} {lab : ℕ} (hn : new < 2 ^ K) (hl : lab < 2 ^ K) :
      HT K P0 (Model.tableInsert t e new before lab) fun (x : Unit) => True

      A table insertion: the new entry and its label (hypotheses), the side list (R).

      theorem OrderMaintenance.Proof.Word.ht_insertAroundIn {K : ℕ} {P0 : Model.Params} {v v1 v2 : ℕ} {q : ℕ × ℕ × ℕ} (h1 : v1 < 2 ^ K) (h2 : v2 < 2 ^ K) (ha : q.2.1 < 2 ^ K) (hb : q.2.2 < 2 ^ K) :
      HT K P0 (Model.insertAroundIn v v1 v2 q) fun (x : Unit) => True
      theorem OrderMaintenance.Proof.Word.ht_joinChunk {K : ℕ} {P0 : Model.Params} {tabs : List ℕ} {lp c : ℕ} (ht : ∀ T ∈ tabs, T < 2 ^ K) (hlp : lp < 2 ^ K) :
      HT K P0 (Model.joinChunk tabs lp c) fun (x : Unit) => True
      theorem OrderMaintenance.Proof.Word.ht_insertAroundFinish {K : ℕ} {P0 : Model.Params} {x y z lp : ℕ} {tabs ly lz : List ℕ} (hK : 1 ≤ K) (hx : x < 2 ^ K) (hy : y < 2 ^ K) (hz : z < 2 ^ K) (ht : ∀ T ∈ tabs, T < 2 ^ K) (hly : ∀ a ∈ ly, a < 2 ^ K) (hlz : ∀ a ∈ lz, a < 2 ^ K) (hlp : lp < 2 ^ K) :
      HT K P0 (Model.insertAroundFinish x y z tabs ly lz lp) (JobB K)

      The rest of a split's insertion (R, F, Lab): the new chunks y, z enter the tables (labels ly, lz), the paths (NIL rows), the tables lists (tabs), the live parent and its children.

      theorem OrderMaintenance.Proof.Word.ht_mapM_roomNextTo {K : ℕ} {P0 : Model.Params} (hβ : P0.beta ≤ K) (l : List ℕ) (e : ℕ) (b : Bool) :
      HT K P0 (List.mapM (fun (x : ℕ) => Model.roomNextTo x e b) l) fun (r : List ℕ) => ∀ a ∈ r, a < 2 ^ K
      theorem OrderMaintenance.Proof.Word.ht_getLpar {K : ℕ} {P0 : Model.Params} (c : ℕ) :
      HT K P0 (Model.getLpar c) fun (x : ℕ) => x < 2 ^ K
      theorem OrderMaintenance.Proof.Word.ht_insertAroundPrep {K : ℕ} {P0 : Model.Params} (hβ : P0.beta ≤ K) (x : ℕ) :
      HT K P0 (Model.insertAroundPrep x) fun (r : ℕ × ℕ × List ℕ × List ℕ × List ℕ × ℕ) => (∀ T ∈ r.2.2.1, T < 2 ^ K) ∧ (∀ a ∈ r.2.2.2.1, a < 2 ^ K) ∧ (∀ a ∈ r.2.2.2.2.1, a < 2 ^ K) ∧ r.2.2.2.2.2 < 2 ^ K

      The read-only part of a split's insertion returns bounded tables, labels and parent.

      theorem OrderMaintenance.Proof.Word.insertAround_wb {K : ℕ} {t : Model.Core} {x y z : ℕ} (hW : WB K t) (hK : 1 ≤ K) (hβ : t.P.beta ≤ K) (hx : x < 2 ^ K) (hy : y < 2 ^ K) (hz : z < 2 ^ K) (hyz : y ≠ z) (hys : y < t.C.size) (hzs : z < t.C.size) {job : Model.Job} {s2 : Model.Core} (hr : EStateM.run (Model.insertAround x y z) t = EStateM.Result.ok job s2) (htag : (s2.C.getX y).tag < 2 ^ K ∧ (s2.C.getX z).tag < 2 ^ K) :
      WB K s2 ∧ JobB K job

      A split's insertion into the top structure keeps the stored-value bound, given the new chunks below 2^K and the bound of their final tags (which the top invariant after the split gives).

      The construction of the initial chain #

      Room for the construction: heights up to H + 1, labels and tags.

      Instances For
        theorem OrderMaintenance.Proof.Word.WB.withPrep {K : ℕ} {s : Model.Core} (h : WB K s) {p : Option Model.Prep} (hp : ∀ (q : Model.Prep), p = some q → PrepB K q) :
        WB K { P := s.P, E := s.E, Gs := s.Gs, C := s.C, freeG := s.freeG, count := s.count, head := s.head, tail := s.tail, firstGroup := s.firstGroup, firstChunk := s.firstChunk, ready := s.ready, prep := p, resJob := s.resJob, fallbacks := s.fallbacks, pqHead := s.pqHead, pqNext := s.pqNext, pqPrev := s.pqPrev, pqWhere := s.pqWhere, nbNext := s.nbNext, nbPrev := s.nbPrev, pqHi := s.pqHi, pqLo := s.pqLo, nodes := s.nodes, path := s.path, cin := s.cin, lpar := s.lpar }
        theorem OrderMaintenance.Proof.Word.PrepRoom.chainTag {K : ℕ} {P : Model.Params} (h : PrepRoom K P) {m : ℕ} (hm : m ≤ P.H) :
        Top.chainTag P m < 2 ^ K
        theorem OrderMaintenance.Proof.Word.chainNew_nodeB {K : ℕ} {P : Model.Params} {pr : Model.Prep} {n : Model.Node} (hn : NodeB K n) (hc : pr.chunk < 2 ^ K) (hb : pr.below < 2 ^ K) (hK : 1 < 2 ^ K) (hce : 1 <<< (P.beta - 1) < 2 ^ K) :
        NodeB K (Top.chainNew P pr n)
        theorem OrderMaintenance.Proof.Word.prepNext_prepB {K : ℕ} {P : Model.Params} {pr : Model.Prep} {v : ℕ} (hp : PrepB K pr) (hh : pr.h + 1 < 2 ^ K) (hv : v < 2 ^ K) (ht : pr.tag ||| 1 <<< (P.beta - 1) <<< ((pr.h - 1) * P.beta) < 2 ^ K) :
        PrepB K (Top.prepNext P pr v)
        theorem OrderMaintenance.Proof.Word.initStep_wb {K : ℕ} {P : Model.Params} {h : ℕ} {s : Model.Core} (S : Top.Stage P h s) (hW : WB K s) (hR : PrepRoom K P) (h1 : 1 ≤ h) (hH : h ≤ P.H + 1) {b : Bool} {s' : Model.Core} (hr : EStateM.run Model.initStep s = EStateM.Result.ok b s') :
        WB K s'

        A construction step keeps the stored-value bound (stage h of Stage): a chain node (index nodes.size = h, F; its table holds the centre, Lab), the next height and the tag of the chain so far (chainTag, below 2^(hβ)), or, at the end, the stored path and tag.

        theorem OrderMaintenance.Proof.Word.wb_prepStart {K : ℕ} {P : Model.Params} (hP : ParamsB K P) (hL : LabRoom K P) (r : Bool) :
        WB K (have __src := Model.initState P; { P := __src.P, E := __src.E, Gs := __src.Gs, C := __src.C, freeG := __src.freeG, count := __src.count, head := __src.head, tail := __src.tail, firstGroup := __src.firstGroup, firstChunk := __src.firstChunk, ready := r, prep := some { chunk := 1, below := 1, path := Array.replicate (P.H + 1) Model.NIL }, resJob := __src.resJob, fallbacks := __src.fallbacks, pqHead := __src.pqHead, pqNext := __src.pqNext, pqPrev := __src.pqPrev, pqWhere := __src.pqWhere, nbNext := __src.nbNext, nbPrev := __src.nbPrev, pqHi := __src.pqHi, pqLo := __src.pqLo, nodes := __src.nodes, path := __src.path, cin := __src.cin, lpar := __src.lpar })

        The fresh core before its chain is built.

        theorem OrderMaintenance.Proof.Word.wb_initLoop {K : ℕ} {P : Model.Params} (hPP : Top.topPP P) (hR : PrepRoom K P) (l : List ℕ) (h : ℕ) (s : Model.Core) :
        Top.Stage P h s → WB K s → 1 ≤ h → h ≤ P.H + 1 → ∀ (s' : Model.Core), EStateM.run (forIn l PUnit.unit fun (x : ℕ) (x_1 : PUnit.{1}) => do let b ← Model.initStep if b = true then pure (ForInStep.done PUnit.unit) else pure (ForInStep.yield PUnit.unit)) s = EStateM.Result.ok () s' → WB K s'

        The eager construction's loop keeps the stored-value bound.

        theorem OrderMaintenance.Proof.Word.initCore_wb {K : ℕ} {lazy : Bool} {s s' : Model.Core} (hP : ParamsB K s.P) (hL : LabRoom K s.P) (hR : PrepRoom K s.P) (hPP : Top.topPP s.P) (hr : EStateM.run (Model.initCore lazy) s = EStateM.Result.ok () s') :
        WB K s'

        A fresh core keeps the stored-value bound (initCore, eager or lazy), from bounded parameters and room for labels, tags and heights.

        theorem OrderMaintenance.Proof.Word.newCore_wb {K : ℕ} {P : Model.Params} {lazy : Bool} {c : Model.Core} (hP : ParamsB K P) (hL : LabRoom K P) (hR : PrepRoom K P) (hPP : Top.topPP P) (hc : Model.newCore P lazy = Except.ok c) :
        WB K c

        A fresh core, as the wrapper makes it (newCore).

        theorem OrderMaintenance.Proof.Word.prepareStep_wb {K : ℕ} {s : Model.Core} (hI : s.ready = true ∨ Top.topPI s) (hW : WB K s) (hR : PrepRoom K s.P) {b : Bool} {s' : Model.Core} (hr : EStateM.run Model.prepareStep s = EStateM.Result.ok b s') :
        WB K s'

        A preparation step keeps the stored-value bound, on a core whose chain is being built (topPI) or that is ready.