Documentation

LeanPool.OrderMaintenance.Proof.Word.Wrap

Theorem W, stage B3: the wrapper's stored values #

WBW t om nx: the wrapper state om, with next core nx, after t operations: each core bounded at its own word size (WB (wK c.P) c), the element index arrays and the cursor bounded at their core's word size, every handle stored in a core at most nextHandle, and the counters (live, nextHandle, rebuilds) at most t. The next core is a separate argument because the rebuild loop holds it outside the record.

This file proves that the wrapper's operations keep WBW, along the Level M invariant MInv (whose InService, CopyOK and PrepM contexts give each core operation its hypotheses):

The predicate #

The wrapper's values, each core at its own word size.

Instances For
    theorem OrderMaintenance.Proof.Word.WBW.withNxt {t : ℕ} {om : Model.OrderMaintenance} {nx : Option Model.Core} (h : WBW t om nx) (y : Option Model.Core) :
    WBW t { cur := om.cur, curIdx := om.curIdx, nxt := y, nxtIdx := om.nxtIdx, cursor := om.cursor, cursorSet := om.cursorSet, live := om.live, nextHandle := om.nextHandle, rebuilds := om.rebuilds, KB := om.KB } nx
    theorem OrderMaintenance.Proof.Word.WBW.swap {t : ℕ} {om : Model.OrderMaintenance} {n : Model.Core} (h : WBW t om (some n)) (hc : om.cursor = Model.NIL) :
    WBW t (om.swap n) none

    The swap: nxt becomes cur, its index array curIdx.

    Facts about a core in service #

    The element count of a core in service is far below its word size.

    theorem OrderMaintenance.Impl.InService.hframe {c : Model.Core} {L : List ℕ} (h : InService c L) {x : ℕ} (hx : x ∈ L) (hh : ℕ) {y : ℕ} {c' : Model.Core} (hr : EStateM.run (Model.insertAfter x hh) c = EStateM.Result.ok y c') (e : ℕ) :
    (c'.E.getX e).h = if e = c.E.size then hh else (c.E.getX e).h

    The handles across an insertion into a core in service: the new element gets hh.

    theorem OrderMaintenance.Proof.Word.h_le_of_frame {c c' : Model.Core} {hh B : ℕ} (hf : ∀ (e : ℕ), (c'.E.getX e).h = if e = c.E.size then hh else (c.E.getX e).h) (hc : ∀ (i : ℕ), (c.E.getX i).h ≤ B) (hb : hh ≤ B) (i : ℕ) :
    (c'.E.getX i).h ≤ B

    The rebuild loop #

    theorem OrderMaintenance.Proof.Word.copy_wbw {t : ℕ} {om om' : Model.OrderMaintenance} {n n' : Model.Core} (hC : Impl.CopyOK om n) (h : WBW t om (some n)) (hcp : Model.copyAtCursor om n = Except.ok (om', n')) :
    WBW t om' (some n') ∧ n'.P = n.P

    A copy step keeps the bound: the copied element goes after the tail of nxt (a core in service), with its handle; the index array records its index; the cursor moves on.

    theorem OrderMaintenance.Proof.Word.loop_wb {t : ℕ} (f b : ℕ) (om : Model.OrderMaintenance) (n : Model.Core) :
    Impl.RLSafe om n f b → n.P = proofParams n.P.N → WBW t om (some n) → ∀ (R : Model.OrderMaintenance), Model.rebuildLoop om n f b = Except.ok R → WBW t R R.nxt

    The rebuild loop keeps the bound, along Level M's loop context RLSafe: preparation steps (PrepM), copy steps (CopyOK), the swap. The counters do not change.

    The rebuild step #

    The fresh core of a rebuild start has no handles yet.

    theorem OrderMaintenance.Proof.Word.rebuild_wb {t : ℕ} {om : Model.OrderMaintenance} (hX : Impl.MX om) (hF : ∀ (n : Model.Core), om.nxt = some n → Impl.RLSafeP { cur := om.cur, curIdx := om.curIdx, nxtIdx := om.nxtIdx, cursor := om.cursor, cursorSet := om.cursorSet, live := om.live, nextHandle := om.nextHandle, rebuilds := om.rebuilds, KB := om.KB } n (om.KB + 1) om.KB) (hmkN : ∀ (n : Model.Core), om.nxt = some n → n.P = proofParams n.P.N) (hB : WBW t om om.nxt) (hreb : om.rebuilds + 1 ≤ t) {R : Model.OrderMaintenance} (hr : Model.OrderMaintenance.rebuildStep proofParams om = Except.ok R) :
    WBW t R R.nxt

    The rebuild step keeps the bound: a rebuild start (a fresh core, wb_prepStart; one more rebuild), or the loop (loop_wb, with Level M's loop context from loop_M).

    Mirroring an insertion #

    theorem OrderMaintenance.Proof.Word.mirror_wbw {t : ℕ} {om : Model.OrderMaintenance} {hx : Option ℕ} {hy : ℕ} (hB : WBW t om om.nxt) (hhy : hy ≤ om.nextHandle) (hN : ∀ (n : Model.Core), om.nxt = some n → om.cursorSet = true → (hx = none ∨ ∃ (x : ℕ), hx = some x ∧ om.nxtIdx.getX x ≠ 0) → ∃ (B : List ℕ), Impl.InService n B ∧ Impl.mirAnchor om n hx ∈ B) {om2 : Model.OrderMaintenance} (hm : om.mirrorInsert hx hy = Except.ok om2) :
    WBW t om2 om2.nxt ∧ om2.cur = om.cur ∧ om2.live = om.live ∧ om2.rebuilds = om.rebuilds ∧ om2.KB = om.KB ∧ ∀ (n' : Model.Core), om2.nxt = some n' → ∃ (n : Model.Core), om.nxt = some n ∧ n'.P = n.P

    A mirrored insertion keeps the bound: the insertion into nxt (a core in service, at the mirrored anchor), its index, its handle.

    Mirroring a deletion #

    theorem OrderMaintenance.Proof.Word.mirrorDel_wbw {t : ℕ} {om : Model.OrderMaintenance} {x : ℕ} (hB : WBW t om om.nxt) {om2 : Model.OrderMaintenance} (hm : om.mirrorDelete x = Except.ok om2) :
    WBW t om2 om2.nxt ∧ om2.cur = om.cur ∧ om2.live = om.live ∧ om2.rebuilds = om.rebuilds ∧ ∀ (n' : Model.Core), om2.nxt = some n' → ∃ (n : Model.Core), om.nxt = some n ∧ n'.P = n.P

    The operations #

    theorem OrderMaintenance.Proof.Word.WBW.mono {t t' : ℕ} {om : Model.OrderMaintenance} {nx : Option Model.Core} (h : WBW t om nx) (ht : t ≤ t') :
    WBW t' om nx
    theorem OrderMaintenance.Proof.Word.insert_core_wbw {t : ℕ} {om : Model.OrderMaintenance} {L : List ℕ} (hS : Impl.InService om.cur L) {hx : Option ℕ} {c' : Model.Core} (hxL : Impl.insAnchor om hx ∈ L) (hB : WBW t om om.nxt) (hP : c'.P = om.cur.P) (hr : EStateM.run (Model.insertAfter (Impl.insAnchor om hx) om.nextHandle) om.cur = EStateM.Result.ok om.cur.E.size c') :
    WBW (t + 1) (Impl.insOM om c' om.cur.E.size) (Impl.insOM om c' om.cur.E.size).nxt

    Inserting into the current core preserves the wrapper's stored-value bounds, with one additional operation counted.

    theorem OrderMaintenance.Proof.Word.markDead_wbw {t : ℕ} {om : Model.OrderMaintenance} {c' : Model.Core} {x : ℕ} (hB : WBW t om om.nxt) (hr : EStateM.run (Model.markDead (om.curIdx.getX x)) om.cur = EStateM.Result.ok () c') :
    WBW (t + 1) { cur := c', curIdx := om.curIdx.setX x 0, nxt := om.nxt, nxtIdx := om.nxtIdx, cursor := om.cursor, cursorSet := om.cursorSet, live := om.live, nextHandle := om.nextHandle, rebuilds := om.rebuilds, KB := om.KB } { cur := c', curIdx := om.curIdx.setX x 0, nxt := om.nxt, nxtIdx := om.nxtIdx, cursor := om.cursor, cursorSet := om.cursorSet, live := om.live, nextHandle := om.nextHandle, rebuilds := om.rebuilds, KB := om.KB }.nxt

    Marking a current element dead preserves all stored-value bounds and advances only the history allowance.

    theorem OrderMaintenance.Proof.Word.insert_step {t : ℕ} {om : Model.OrderMaintenance} {Sp : Spec.State} (hI : Impl.MInv om Sp) {hx : Option ℕ} (hv : Spec.Op.Valid Sp (insOp hx)) (hB : WBW t om om.nxt) :

    An insertion keeps the Level M invariant and the bound.

    theorem OrderMaintenance.Proof.Word.delete_step {t : ℕ} {om : Model.OrderMaintenance} {Sp : Spec.State} (hI : Impl.MInv om Sp) {x : ℕ} (hv : x ∈ Sp.list) (hB : WBW t om om.nxt) :

    A deletion keeps the Level M invariant and the bound.

    Initialization #

    Initialization: the Level M invariant and the bound after no operation.

    An operation #

    theorem OrderMaintenance.Proof.Word.apply_step {t : ℕ} {om : Model.OrderMaintenance} {Sp : Spec.State} (hI : Impl.MInv om Sp) {op : Spec.Op} (hv : Spec.Op.Valid Sp op) (hB : WBW t om om.nxt) {a : Spec.Ans} {om' : Model.OrderMaintenance} (hr : Model.OrderMaintenance.apply proofParams om op = Except.ok (a, om')) :
    Impl.MInv om' (Spec.step Sp op).1 ∧ WBW (t + 1) om' om'.nxt ∧ om'.KB = om.KB

    An operation keeps the Level M invariant and the bound, one more operation counted.

    Reachable wrapper states #

    The wrapper states reached by initialization and valid operations, with the number of operations and the specification state.

    Instances For
      theorem OrderMaintenance.Proof.Word.reachW_inv {KB : ℕ} (h4 : 4 ≤ KB) {t : ℕ} {om : Model.OrderMaintenance} {Sp : Spec.State} (h : ReachW KB t om Sp) :
      Impl.MInv om Sp ∧ WBW t om om.nxt ∧ om.KB = KB

      Theorem W, option B #

      The word size of a wrapper state: 64·L for the larger L of its two cores.

      Equations
      Instances For
        theorem OrderMaintenance.Proof.Word.theoremW_stored {KB t : ℕ} {om : Model.OrderMaintenance} {Sp : Spec.State} (h4 : 4 ≤ KB) (hKB : KB < 2 ^ 512) (h : ReachW KB t om Sp) :
        OMB (wKom om) t om

        Theorem W (stored values, Level F). On every wrapper state reached by initialization and t valid operations, every value stored in either core is below 2^K, K = 64·L for the larger L = pL N of the two cores (wKom), handles excepted; the element index arrays and the cursor are below 2^K; every handle stored in a core, the live count, the handle counter and the rebuild counter are at most t. (K_B < 2^512 puts the constant K_B below 2^K too.)