Documentation

LeanPool.OrderMaintenance.Proof.Correct.Wrapper

The wrapper (Invariant R) #

cur is a well-formed core whose live handles, in list order, are the specification's list, and curIdx maps each of them to its element. A rebuild core nxt is either being prepared (the sentinel alone) or holds exactly the live handles of the part pre of cur's list before the cursor, with nxtIdx mapping them; mirrored operations keep this.

theorem OrderMaintenance.Proof.runCore_ok {α : Type} {c : Model.Core} {act : Model.CM α} {a : α} {s : Model.Core} (h : EStateM.run act c = EStateM.Result.ok a s) :
theorem OrderMaintenance.Proof.onCur_ok {α : Type} {om : Model.OrderMaintenance} {act : Model.CM α} {a : α} {s : Model.Core} (h : EStateM.run act om.cur = EStateM.Result.ok a s) :
om.onCur act = Except.ok (a, { cur := s, curIdx := om.curIdx, nxt := om.nxt, nxtIdx := om.nxtIdx, cursor := om.cursor, cursorSet := om.cursorSet, live := om.live, nextHandle := om.nextHandle, rebuilds := om.rebuilds, KB := om.KB })

The invariant #

The rebuild core n relative to cur = c with nesting A.

Equations
  • One or more equations did not get rendered due to their size.
Instances For

    Require the replacement-core invariant when an incremental rebuild is active.

    Equations
    Instances For

      Invariant R.

      Instances For
        theorem OrderMaintenance.Proof.FM_sub_nodup {p : ℕ → Bool} {f : ℕ → ℕ} {pre post : List ℕ} (h : (FM p f (pre ++ post)).Nodup) :
        (FM p f pre).Nodup ∧ (FM p f post).Nodup
        theorem OrderMaintenance.Proof.liveH_append (c : Model.Core) (l1 l2 : List ℕ) :
        liveH c (l1 ++ l2) = liveH c l1 ++ liveH c l2
        theorem OrderMaintenance.Proof.liveH_insertAfterL (c : Model.Core) {l : List ℕ} {a b : ℕ} (ha : a ∈ l) (hpa : live c a = true) (hnd : (liveH c l).Nodup) (hb : b ∉ l) (hpb : live c b = true) :
        liveH c (Spec.insertAfterL a b l) = Spec.insertAfterL (hdl c a) (hdl c b) (liveH c l)
        theorem OrderMaintenance.Proof.liveH_insertAfterL_head (c : Model.Core) {a b : ℕ} (t : List ℕ) (hpa : live c a = false) (hpb : live c b = true) :
        liveH c (Spec.insertAfterL a b (a :: t)) = hdl c b :: liveH c t
        theorem OrderMaintenance.Proof.headD_pre {pre post : List ℕ} (hpre : pre ≠ []) :
        (pre ++ post).headD Model.NIL ∈ pre
        theorem OrderMaintenance.Proof.nxtR_copied {c' : Model.Core} {A' : Abs} {om : Model.OrderMaintenance} {n n' : Model.Core} {B B' : Abs} {hy y' : ℕ} {pre post : List ℕ} (hRB' : CoreR n' B') (hIB : IdxOK n B om.nxtIdx (liveH n B.elist)) (hzB : ∀ (x : ℕ), om.nxtIdx.getX x ≠ 0 → x ∈ liveH n B.elist) (hsub : ∀ e ∈ B.elist, e ∈ B'.elist) (hy'B : y' ∈ B'.elist) (hrecB : ∀ e ∈ B.elist, live n' e = live n e ∧ hdl n' e = hdl n e) (hly' : live n' y' = true) (hhy' : hdl n' y' = hy) (hfreshB : hy ∉ liveH n B.elist) (hL : ∀ (z : ℕ), z ∈ liveH n' B'.elist ↔ z = hy ∨ z ∈ liveH n B.elist) (hset : om.cursorSet = true) (hsplit : A'.elist = pre ++ post) (hcur : om.cursor = post.headD Model.NIL) (hpre : pre ≠ []) (hLB : liveH n' B'.elist = liveH c' pre) :
        NxtR' c' A' { cur := om.cur, curIdx := om.curIdx, nxt := some n', nxtIdx := om.nxtIdx.setX hy y', cursor := om.cursor, cursorSet := om.cursorSet, live := om.live, nextHandle := om.nextHandle, rebuilds := om.rebuilds, KB := om.KB } n'
        theorem OrderMaintenance.Proof.mirrorInsert_ok {om : Model.OrderMaintenance} {c c' : Model.Core} {A A' : Abs} {hx : Option ℕ} {xi y hy : ℕ} (hN : NxtR c A om) (hR : CoreR c A) (hnd : (liveH c A.elist).Nodup) (hxi : xi ∈ A.elist) (hxn : hx = none → xi = c.head) (hxs : ∀ (x : ℕ), hx = some x → live c xi = true ∧ hdl c xi = x) (hA' : A'.elist = Spec.insertAfterL xi y A.elist) (hyA : y ∉ A.elist) (hrec : ∀ e ∈ A.elist, live c' e = live c e ∧ hdl c' e = hdl c e) (hly : live c' y = true) (hhy : hdl c' y = hy) (hfresh : hy ∉ liveH c A.elist) :
        ∃ (om2 : Model.OrderMaintenance), om.mirrorInsert hx hy = Except.ok om2 ∧ om2.cur = om.cur ∧ om2.curIdx = om.curIdx ∧ om2.nextHandle = om.nextHandle ∧ om2.live = om.live ∧ om2.KB = om.KB ∧ NxtR c' A' om2
        theorem OrderMaintenance.Proof.liveH_kill {c c' : Model.Core} {l : List ℕ} {a : ℕ} (ha : a ∈ l) (hpa : live c a = true) (hp'a : live c' a = false) (hp' : ∀ (e : ℕ), e ≠ a → live c' e = live c e) (hh : ∀ (e : ℕ), hdl c' e = hdl c e) (hl : l.Nodup) (hnd : (liveH c l).Nodup) :
        liveH c' l = (liveH c l).erase (hdl c a)
        theorem OrderMaintenance.Proof.mirrorDelete_ok {om : Model.OrderMaintenance} {c c' : Model.Core} {A : Abs} {x xi : ℕ} (hN : NxtR c A om) (hR : CoreR c A) (hnd : (liveH c A.elist).Nodup) (hxi : xi ∈ A.elist) (hlx : live c xi = true) (hhx : hdl c xi = x) (hrec : ∀ (e : ℕ), e ≠ xi → live c' e = live c e) (hhdl : ∀ (e : ℕ), hdl c' e = hdl c e) (hdead : live c' xi = false) :
        ∃ (om2 : Model.OrderMaintenance), om.mirrorDelete x = Except.ok om2 ∧ om2.cur = om.cur ∧ om2.curIdx = om.curIdx ∧ om2.nextHandle = om.nextHandle ∧ om2.live = om.live ∧ om2.KB = om.KB ∧ NxtR c' A om2

        The rebuild #

        theorem OrderMaintenance.Proof.post_nil {A : Abs} {c : Model.Core} (hR : CoreR c A) {pre post : List ℕ} (hs : A.elist = pre ++ post) (h : post.headD Model.NIL = Model.NIL) :
        post = []
        theorem OrderMaintenance.Proof.swap_ok {om : Model.OrderMaintenance} {n : Model.Core} {A : Abs} {S : Spec.State} (hN : NxtR' om.cur A om n) (hR : CoreR om.cur A) (hL : liveH om.cur A.elist = S.list) (hset : om.cursorSet = true) (hcur : om.cursor = Model.NIL) (hS : Spec.Inv S) (hf : om.nextHandle = S.fresh) :
        WInv (om.swap n) S

        The swap: once the cursor has passed the end, nxt holds every live handle.

        theorem OrderMaintenance.Proof.copy_ok {om : Model.OrderMaintenance} {n : Model.Core} {A : Abs} (hN : NxtR' om.cur A om n) (hR : CoreR om.cur A) (hnd : (liveH om.cur A.elist).Nodup) (hset : om.cursorSet = true) (hcur : om.cursor ≠ Model.NIL) :
        ∃ (om' : Model.OrderMaintenance) (n' : Model.Core), Model.copyAtCursor om n = Except.ok (om', n') ∧ om'.cur = om.cur ∧ om'.curIdx = om.curIdx ∧ om'.nxt = om.nxt ∧ om'.cursorSet = om.cursorSet ∧ om'.nextHandle = om.nextHandle ∧ om'.live = om.live ∧ om'.KB = om.KB ∧ NxtR' om.cur A om' n'

        Copying one element at the cursor.

        theorem OrderMaintenance.Proof.prepare_ok {om : Model.OrderMaintenance} {n : Model.Core} {A : Abs} (hN : NxtR' om.cur A om n) (hR : CoreR om.cur A) (hset : om.cursorSet = false) :
        ∃ (ready : Bool) (n' : Model.Core), Model.runCore n Model.prepareStep = Except.ok (ready, n') ∧ NxtR' om.cur A om n' ∧ (ready = true → NxtR' om.cur A { cur := om.cur, curIdx := om.curIdx, nxt := om.nxt, nxtIdx := om.nxtIdx, cursor := (om.cur.E.getX om.cur.head).next, cursorSet := true, live := om.live, nextHandle := om.nextHandle, rebuilds := om.rebuilds, KB := om.KB } n')

        One preparation step of nxt; when it completes, the cursor starts after the sentinel.

        theorem OrderMaintenance.Proof.rebuildLoop_ok {S : Spec.State} (hS : Spec.Inv S) (fuel budget : ℕ) (om : Model.OrderMaintenance) (n : Model.Core) (A : Abs) :
        CoreR om.cur A → liveH om.cur A.elist = S.list → IdxOK om.cur A om.curIdx S.list → NxtR' om.cur A om n → om.nextHandle = S.fresh → ∃ (om' : Model.OrderMaintenance), Model.rebuildLoop om n fuel budget = Except.ok om' ∧ WInv om' S
        theorem OrderMaintenance.Proof.rebuildStep_ok {mk : ℕ → Model.Params} (hmk : ∀ (N : ℕ), CoreP (mk N)) {om : Model.OrderMaintenance} {S : Spec.State} (hW : WInv om S) :

        The rebuild step keeps Invariant R.

        theorem OrderMaintenance.Proof.insertion_position {om : Model.OrderMaintenance} {Sp : Spec.State} {A : Abs} (hR : CoreR om.cur A) (hI : IdxOK om.cur A om.curIdx Sp.list) (hx : Option ℕ) (hv : Spec.Op.Valid Sp (insOp hx)) :
        ∃ xi ∈ A.elist, (xi = match hx, hv with | none, hv => om.cur.head | some x, hv => om.curIdx.getX x) ∧ (hx = none → xi = om.cur.head) ∧ ∀ (x : ℕ), hx = some x → live om.cur xi = true ∧ hdl om.cur xi = x

        The wrapper's index supplies a concrete insertion position, including the sentinel case.

        theorem OrderMaintenance.Proof.step_ins_mem (Sp : Spec.State) (hx : Option ℕ) (hv : Spec.Op.Valid Sp (insOp hx)) (z : Spec.Elem) :
        z ∈ (Spec.step Sp (insOp hx)).1.list ↔ z = Sp.fresh ∨ z ∈ Sp.list

        A valid specification insertion adds exactly the fresh handle to the live list.

        theorem OrderMaintenance.Proof.inserted_live_handles {om : Model.OrderMaintenance} {Sp : Spec.State} {A : Abs} {c' : Model.Core} {xi : ℕ} {hx : Option ℕ} (hR : CoreR om.cur A) (hf : om.nextHandle = Sp.fresh) (hL : liveH om.cur A.elist = Sp.list) (hnd : (liveH om.cur A.elist).Nodup) (hxi : xi ∈ A.elist) (hxn : hx = none → xi = om.cur.head) (hxs : ∀ (x : ℕ), hx = some x → live om.cur xi = true ∧ hdl om.cur xi = x) (hrec : ∀ e ∈ A.elist, live c' e = live om.cur e ∧ hdl c' e = hdl om.cur e) (hly : live c' om.cur.E.size = true) (hhy : hdl c' om.cur.E.size = om.nextHandle) (hyA : om.cur.E.size ∉ A.elist) :

        Core insertion preserves the live-handle interpretation, including insertion at the sentinel.

        theorem OrderMaintenance.Proof.IdxOK.insert_update {om : Model.OrderMaintenance} {Sp : Spec.State} {A A' : Abs} {c' : Model.Core} {xi : ℕ} {hx : Option ℕ} (hS : Spec.Inv Sp) (hf : om.nextHandle = Sp.fresh) (hI : IdxOK om.cur A om.curIdx Sp.list) (hv : Spec.Op.Valid Sp (insOp hx)) (hA' : A'.elist = Spec.insertAfterL xi om.cur.E.size A.elist) (hxi : xi ∈ A.elist) (hrec : ∀ e ∈ A.elist, live c' e = live om.cur e ∧ hdl c' e = hdl om.cur e) (hly : live c' om.cur.E.size = true) (hhy : hdl c' om.cur.E.size = om.nextHandle) :
        IdxOK c' A' (om.curIdx.setX om.nextHandle om.cur.E.size) (Spec.step Sp (insOp hx)).1.list

        Updating the fresh handle's index preserves every live element's lookup.

        theorem OrderMaintenance.Proof.IdxOK.delete_update {c c' : Model.Core} {A : Abs} {idx : Array ℕ} {L : List ℕ} {x : ℕ} (hI : IdxOK c A idx L) (hnd : L.Nodup) (hhx : hdl c (idx.getX x) = x) (hrec : ∀ (e : ℕ), e ≠ idx.getX x → live c' e = live c e) (hhdl : ∀ (e : ℕ), hdl c' e = hdl c e) :
        IdxOK c' A (idx.setX x 0) (L.erase x)

        Deleting a handle preserves all remaining index entries when the other elements stay live.

        theorem OrderMaintenance.Proof.WInv.insert_after_mirror {om om2 : Model.OrderMaintenance} {Sp : Spec.State} {A A' : Abs} {c' : Model.Core} {xi : ℕ} {hx : Option ℕ} (hS : Spec.Inv Sp) (hf : om.nextHandle = Sp.fresh) (hI : IdxOK om.cur A om.curIdx Sp.list) (hv : Spec.Op.Valid Sp (insOp hx)) (hR' : CoreR c' A') (hL' : liveH c' A'.elist = (Spec.step Sp (insOp hx)).1.list) (hA' : A'.elist = Spec.insertAfterL xi om.cur.E.size A.elist) (hxi : xi ∈ A.elist) (hrec : ∀ e ∈ A.elist, live c' e = live om.cur e ∧ hdl c' e = hdl om.cur e) (hly : live c' om.cur.E.size = true) (hhy : hdl c' om.cur.E.size = om.nextHandle) (hcur : om2.cur = c') (hidx : om2.curIdx = om.curIdx.setX om.nextHandle om.cur.E.size) (hfresh : om2.nextHandle = om.nextHandle + 1) (hN : NxtR c' A' { cur := om2.cur, curIdx := om2.curIdx, nxt := om2.nxt, nxtIdx := om2.nxtIdx, cursor := om2.cursor, cursorSet := om2.cursorSet, live := om2.live + 1, nextHandle := om2.nextHandle, rebuilds := om2.rebuilds, KB := om2.KB }) :
        WInv { cur := om2.cur, curIdx := om2.curIdx, nxt := om2.nxt, nxtIdx := om2.nxtIdx, cursor := om2.cursor, cursorSet := om2.cursorSet, live := om2.live + 1, nextHandle := om2.nextHandle, rebuilds := om2.rebuilds, KB := om2.KB } (Spec.step Sp (insOp hx)).1

        The common wrapper invariant after a core insertion has been mirrored.

        theorem OrderMaintenance.Proof.WInv.delete_after_mirror {om om2 : Model.OrderMaintenance} {Sp : Spec.State} {A : Abs} {c' : Model.Core} {x : ℕ} (hS : Spec.Inv Sp) (hf : om.nextHandle = Sp.fresh) (hI : IdxOK om.cur A om.curIdx Sp.list) (hv : x ∈ Sp.list) (hR' : CoreR c' A) (hL' : liveH c' A.elist = Sp.list.erase x) (hhx : hdl om.cur (om.curIdx.getX x) = x) (hrec : ∀ (e : ℕ), e ≠ om.curIdx.getX x → live c' e = live om.cur e) (hhdl : ∀ (e : ℕ), hdl c' e = hdl om.cur e) (hcur : om2.cur = c') (hidx : om2.curIdx = om.curIdx.setX x 0) (hfresh : om2.nextHandle = om.nextHandle) (hN : NxtR c' A { cur := om2.cur, curIdx := om2.curIdx, nxt := om2.nxt, nxtIdx := om2.nxtIdx, cursor := om2.cursor, cursorSet := om2.cursorSet, live := om2.live - 1, nextHandle := om2.nextHandle, rebuilds := om2.rebuilds, KB := om2.KB }) :
        WInv { cur := om2.cur, curIdx := om2.curIdx, nxt := om2.nxt, nxtIdx := om2.nxtIdx, cursor := om2.cursor, cursorSet := om2.cursorSet, live := om2.live - 1, nextHandle := om2.nextHandle, rebuilds := om2.rebuilds, KB := om2.KB } (Spec.step Sp (Spec.Op.delete x)).1

        The common wrapper invariant after a core deletion has been mirrored.

        theorem OrderMaintenance.Proof.insert_ok {mk : ℕ → Model.Params} (hmk : ∀ (N : ℕ), CoreP (mk N)) {om : Model.OrderMaintenance} {S : Spec.State} (hW : WInv om S) (hx : Option ℕ) (hv : Spec.Op.Valid S (insOp hx)) :

        Insertion keeps Invariant R and returns the specification's new name.

        theorem OrderMaintenance.Proof.delete_ok {mk : ℕ → Model.Params} (hmk : ∀ (N : ℕ), CoreP (mk N)) {om : Model.OrderMaintenance} {S : Spec.State} (hW : WInv om S) {x : ℕ} (hv : x ∈ S.list) :

        Deletion keeps Invariant R.

        theorem OrderMaintenance.Proof.order_ok {om : Model.OrderMaintenance} {S : Spec.State} (hW : WInv om S) {x y : ℕ} (hx : x ∈ S.list) (hy : y ∈ S.list) :

        Order queries answer as the specification.

        Initialization establishes Invariant R for the empty list.

        theorem OrderMaintenance.Proof.apply_ok {mk : ℕ → Model.Params} (hmk : ∀ (N : ℕ), CoreP (mk N)) {om : Model.OrderMaintenance} {S : Spec.State} (hW : WInv om S) {op : Spec.Op} (hv : Spec.Op.Valid S op) :

        Each operation answers as the specification and keeps Invariant R.

        theorem OrderMaintenance.Proof.runOps_ok {mk : ℕ → Model.Params} (hmk : ∀ (N : ℕ), CoreP (mk N)) (ops : List Spec.Op) {om : Model.OrderMaintenance} {S : Spec.State} :
        WInv om S → Spec.Valid S ops → Model.OrderMaintenance.runOps mk om ops = Except.ok (Spec.run S ops)

        Theorem A (correctness of Level F). For parameters satisfying the conditions of docs/PROOF.md §3.4 at every capacity, the structure initializes, and on every valid sequence of operations it never fails and answers exactly as the list specification.

        theorem OrderMaintenance.Proof.coreP_of_shape (P : Model.Params) (hD : P.elementSpacing = 2 ^ (P.elementBits - 1) / (8 * P.G + 8)) (hB : 8 * P.G + 8 ≤ 2 ^ (P.elementBits - 1)) (hT : P.T + 1 < 2 ^ P.groupBits) :

        The parameter conditions hold for the prototype's shape (Params.for_capacity): elementSpacing = 2^(elementBits-1) / (8G+8) with 8G+8 ≤ 2^(elementBits-1), and T + 1 < 2^groupBits.