Documentation

LeanPool.OrderMaintenance.Impl.WrapM

M6: the wrapper as machine code #

Layout. The cores live in slots 0 and 1 (arrays 1000·p + code); the wrapper's own arrays are numbered from 2000, outside both slots:

WEnc om m p says that machine state m holds wrapper state om with cur in slot p. The wrapper code tests the parity and runs the code specialized to it.

Array name of one of the wrapper's eight scalar cells.

Equations
Instances For

    Array name of the external-handle map associated with a core slot.

    Equations
    Instances For
      theorem OrderMaintenance.Impl.wa_notSlot {p k : ℕ} (hp : p < 2) :
      ¬InSlot p (wa k)
      theorem OrderMaintenance.Impl.wIdx_notSlot {p q : ℕ} (hp : p < 2) :

      The encoding of the wrapper state.

      Instances For
        theorem OrderMaintenance.Impl.WEnc.of_slot {om : Model.OrderMaintenance} {m m' : Machine.State} {p : ℕ} (h : WEnc om m p) (hcur : Enc p (capsOf om.cur.P) om.cur m') (hS : ∀ (b : ℕ), ¬InSlot p b → Machine.Same b m m') :
        WEnc om m' p

        The wrapper state survives anything that keeps slot p's core, the other slot, and the wrapper's arrays.

        theorem OrderMaintenance.Impl.WEnc.bump {om : Model.OrderMaintenance} {m : Machine.State} {p : ℕ} (h : WEnc om m p) (v : ℕ) :
        WEnc om (m.bump v) p
        theorem OrderMaintenance.Impl.WEnc.setLoc {om : Model.OrderMaintenance} {m : Machine.State} {p : ℕ} (h : WEnc om m p) (x : Machine.Reg) (v : ℕ) :
        WEnc om (m.setLoc x v) p

        The parity test.

        Equations
        • One or more equations did not get rendered due to their size.
        Instances For
          theorem OrderMaintenance.Impl.wp_byPar {om : Model.OrderMaintenance} {m : Machine.State} {p : ℕ} (h : WEnc om m p) {c : ℕ → Machine.Stmt} {Q : Machine.State → ℕ → Prop} (hc : Machine.wp (c p) (fun (s' : Machine.State) (n : ℕ) => Q s' (1 + parE.cost + n)) (m.bump (Machine.Expr.maxv m parE))) :

          Order queries #

          Order of the handles in locals x, y; the answer in local r.

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

            Dispatch an order query to the slot containing the current core.

            Equations
            Instances For
              theorem OrderMaintenance.Impl.orderW_ok {om : Model.OrderMaintenance} {m : Machine.State} {p : ℕ} (h : WEnc om m p) {x y : ℕ} (hx : m.loc "x" = x) (hy : m.loc "y" = y) (hxc : x < m.cap (wIdx p)) (hyc : y < m.cap (wIdx p)) {P : Model.Params} {n R : ℕ} {L : List ℕ} (hC : Proof.CostInv (Proof.TIat Proof.Top.TopInv P) Proof.Top.topMu (Proof.Top.topJ P) n R L om.cur) (hP : om.cur.P = P) (hxL : om.curIdx.getX x ∈ L) (hyL : om.curIdx.getX y ∈ L) (hcntL : om.cur.count = L.length) (hM : Mc (capsOf P) P om.cur) {b : Bool} {s' : Model.Core} (hr : EStateM.run (Model.order (om.curIdx.getX x) (om.curIdx.getX y)) om.cur = EStateM.Result.ok b s') :
              Machine.wp orderWS (fun (m' : Machine.State) (c : ℕ) => WEnc om m' p ∧ m'.loc "r" = b2n b ∧ c ≤ 100) m

              An order query at the machine level.

              Writing the current handle map #

              theorem OrderMaintenance.Impl.WEnc.writeC {om : Model.OrderMaintenance} {m : Machine.State} {p : ℕ} (h : WEnc om m p) {x v : ℕ} :
              WEnc { cur := om.cur, curIdx := om.curIdx.setX x v, nxt := om.nxt, nxtIdx := om.nxtIdx, cursor := om.cursor, cursorSet := om.cursorSet, live := om.live, nextHandle := om.nextHandle, rebuilds := om.rebuilds, KB := om.KB } (m.write (wIdx p) x v) p

              Writing v at handle x of the current handle map.

              Deletion #

              Delete the element of handle x from cur.

              Equations
              • One or more equations did not get rendered due to their size.
              Instances For
                theorem OrderMaintenance.Impl.curDelW_ok {om : Model.OrderMaintenance} {m : Machine.State} {p : ℕ} (h : WEnc om m p) {x : ℕ} (hx : m.loc "x" = x) (hxc : x < m.cap (wIdx p)) {P : Model.Params} {n R : ℕ} {L : List ℕ} (hC : Proof.CostInv (Proof.TIat Proof.Top.TopInv P) Proof.Top.topMu (Proof.Top.topJ P) n R L om.cur) (hP : om.cur.P = P) (hxL : om.curIdx.getX x ∈ L) (hcntL : om.cur.count = L.length) (hM : Mc (capsOf P) P om.cur) {c' : Model.Core} (hr : EStateM.run (Model.markDead (om.curIdx.getX x)) om.cur = EStateM.Result.ok () c') :
                Machine.wp (curDelC p) (fun (m' : Machine.State) (k : ℕ) => WEnc { 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 } m' p ∧ m'.loc = Machine.State.upd m.loc "xi" (om.curIdx.getX x) ∧ k ≤ 40) m

                The next core #

                theorem OrderMaintenance.Impl.WEnc.of_nxt {om : Model.OrderMaintenance} {m m' : Machine.State} {p : ℕ} (h : WEnc om m p) {n n' : Model.Core} (hn : om.nxt = some n) (hE : Enc (1 - p) (capsOf n'.P) n' m') (hS : ∀ (b : ℕ), ¬InSlot (1 - p) b → Machine.Same b m m') (hcnt : n'.count = n.count) (hP : n'.P = n.P) :
                WEnc { cur := om.cur, curIdx := om.curIdx, nxt := some n', nxtIdx := om.nxtIdx, cursor := om.cursor, cursorSet := om.cursorSet, live := om.live, nextHandle := om.nextHandle, rebuilds := om.rebuilds, KB := om.KB } m' p

                The next core changes (in its slot), with the same parameters and count.

                theorem OrderMaintenance.Impl.WEnc.writeN {om : Model.OrderMaintenance} {m : Machine.State} {p : ℕ} (h : WEnc om m p) {x v : ℕ} :
                WEnc { cur := om.cur, curIdx := om.curIdx, nxt := om.nxt, nxtIdx := om.nxtIdx.setX x v, cursor := om.cursor, cursorSet := om.cursorSet, live := om.live, nextHandle := om.nextHandle, rebuilds := om.rebuilds, KB := om.KB } (m.write (wIdx (1 - p)) x v) p

                Writing v at handle x of the next handle map.

                Mirroring a deletion into nxt #

                Mirror a deletion into the replacement core when its handle is already copied.

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

                  The core facts a deletion from nxt needs.

                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For
                    theorem OrderMaintenance.Impl.mirrorDelW_ok {om : Model.OrderMaintenance} {m : Machine.State} {p : ℕ} (h : WEnc om m p) {x : ℕ} (hx : m.loc "x" = x) (hxc : om.nxt.isSome = true → x < m.cap (wIdx (1 - p))) (hN : ∀ (n : Model.Core), om.nxt = some n → om.nxtIdx.getX x ≠ 0 → DelOK n (om.nxtIdx.getX x)) {om2 : Model.OrderMaintenance} (hr : om.mirrorDelete x = Except.ok om2) :
                    Machine.wp (mirrorDelC p) (fun (m' : Machine.State) (k : ℕ) => WEnc om2 m' p ∧ m'.loc "x" = x ∧ k ≤ 50) m

                    Writing the wrapper's scalars #

                    theorem OrderMaintenance.Impl.wa_ne {i j : ℕ} (h : i ≠ j) :
                    wa i ≠ wa j
                    theorem OrderMaintenance.Impl.wa_ne_idx {k q : ℕ} (hk : k < 8) :
                    wa k ≠ wIdx q
                    theorem OrderMaintenance.Impl.WEnc.scalarFrame {om : Model.OrderMaintenance} {m : Machine.State} {p k v : ℕ} (h : WEnc om m p) (hk : k < 8) :
                    Enc p (capsOf om.cur.P) om.cur (m.write (wa k) 0 v) ∧ (∀ (n : Model.Core), om.nxt = some n → Enc (1 - p) (capsOf n.P) n (m.write (wa k) 0 v)) ∧ (∀ (j : ℕ), j ≠ k → (m.write (wa k) 0 v).mem (wa j) 0 = m.mem (wa j) 0) ∧ (∀ (q : ℕ), Machine.Same (wIdx q) m (m.write (wa k) 0 v)) ∧ (m.write (wa k) 0 v).cap = m.cap ∧ (m.write (wa k) 0 v).mem (wa k) 0 = v

                    A write to scalar k: the other scalars, the cores and the maps are unchanged.

                    theorem OrderMaintenance.Impl.WEnc.writeCursor {om : Model.OrderMaintenance} {m : Machine.State} {p : ℕ} (h : WEnc om m p) (v : ℕ) :
                    WEnc { cur := om.cur, curIdx := om.curIdx, nxt := om.nxt, nxtIdx := om.nxtIdx, cursor := v, cursorSet := om.cursorSet, live := om.live, nextHandle := om.nextHandle, rebuilds := om.rebuilds, KB := om.KB } (m.write (wa 2) 0 v) p
                    theorem OrderMaintenance.Impl.WEnc.writeCset {om : Model.OrderMaintenance} {m : Machine.State} {p : ℕ} (h : WEnc om m p) (b : Bool) :
                    WEnc { cur := om.cur, curIdx := om.curIdx, nxt := om.nxt, nxtIdx := om.nxtIdx, cursor := om.cursor, cursorSet := b, live := om.live, nextHandle := om.nextHandle, rebuilds := om.rebuilds, KB := om.KB } (m.write (wa 3) 0 (b2n b)) p
                    theorem OrderMaintenance.Impl.WEnc.writeLive {om : Model.OrderMaintenance} {m : Machine.State} {p : ℕ} (h : WEnc om m p) (v : ℕ) :
                    WEnc { cur := om.cur, curIdx := om.curIdx, nxt := om.nxt, nxtIdx := om.nxtIdx, cursor := om.cursor, cursorSet := om.cursorSet, live := v, nextHandle := om.nextHandle, rebuilds := om.rebuilds, KB := om.KB } (m.write (wa 4) 0 v) p
                    theorem OrderMaintenance.Impl.WEnc.writeNext {om : Model.OrderMaintenance} {m : Machine.State} {p : ℕ} (h : WEnc om m p) (v : ℕ) (hrC : v + (om.cur.P.N - om.cur.count) ≤ m.cap (wIdx p)) (hrN : ∀ (n : Model.Core), om.nxt = some n → v + (om.cur.P.N - om.cur.count) + (n.P.N - n.count) ≤ m.cap (wIdx (1 - p))) :
                    WEnc { cur := om.cur, curIdx := om.curIdx, nxt := om.nxt, nxtIdx := om.nxtIdx, cursor := om.cursor, cursorSet := om.cursorSet, live := om.live, nextHandle := v, rebuilds := om.rebuilds, KB := om.KB } (m.write (wa 5) 0 v) p
                    theorem OrderMaintenance.Impl.WEnc.writeReb {om : Model.OrderMaintenance} {m : Machine.State} {p : ℕ} (h : WEnc om m p) (v : ℕ) :
                    WEnc { cur := om.cur, curIdx := om.curIdx, nxt := om.nxt, nxtIdx := om.nxtIdx, cursor := om.cursor, cursorSet := om.cursorSet, live := om.live, nextHandle := om.nextHandle, rebuilds := v, KB := om.KB } (m.write (wa 6) 0 v) p
                    theorem OrderMaintenance.Impl.WEnc.of_cur {om : Model.OrderMaintenance} {m m' : Machine.State} {p : ℕ} (h : WEnc om m p) {c' : Model.Core} (hE : Enc p (capsOf c'.P) c' m') (hS : ∀ (b : ℕ), ¬InSlot p b → Machine.Same b m m') (hrC : om.nextHandle + (c'.P.N - c'.count) ≤ m.cap (wIdx p)) (hrN : ∀ (n : Model.Core), om.nxt = some n → om.nextHandle + (c'.P.N - c'.count) + (n.P.N - n.count) ≤ m.cap (wIdx (1 - p))) :
                    WEnc { cur := c', 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 } m' p

                    The current core changes (in its slot).

                    Insertion into cur #

                    Insert after the element of handle x (local hx = 1) or at the front (hx = 0); the new handle is the counter nextHandle (local hy), and the new element lands in local y.

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

                      The element a wrapper insertion goes after, in cur.

                      Equations
                      Instances For

                        The wrapper state after the insertion into cur.

                        Equations
                        • One or more equations did not get rendered due to their size.
                        Instances For
                          theorem OrderMaintenance.Impl.curInsW_ok {om : Model.OrderMaintenance} {m : Machine.State} {p : ℕ} (h : WEnc om m p) {hx : Option ℕ} (hhx : m.loc "hx" = b2n hx.isSome) (hxx : ∀ (x : ℕ), hx = some x → m.loc "x" = x ∧ x < m.cap (wIdx p)) {P : Model.Params} {n R : ℕ} {L : List ℕ} (hC : Proof.CostInv (Proof.TIat Proof.Top.TopInv P) Proof.Top.topMu (Proof.Top.topJ P) n R L om.cur) (hP : om.cur.P = P) (hxL : insAnchor om hx ∈ L) (hcntL : om.cur.count = L.length) (hcnt : om.cur.count + 1 ≤ P.N) (hM : Mc (capsOf P) P om.cur) (hk : 1 ≤ om.cur.P.reservationBudget) (hR : Proof.Top.topJ P / om.cur.P.reservationBudget + 1 ≤ R) (hn : 1 ≤ n) (hsize : 2 + 2 * ((om.cur.count + 1) / (om.cur.P.theta + 1 - Proof.cmax om.cur.P)) ≤ n + 1) (hcap : 2 + 2 * ((om.cur.count + 1) / (om.cur.P.theta + 1 - Proof.cmax om.cur.P)) ≤ Proof.Top.capT om.cur.P) (hI5 : ↑om.cur.P.theta + ↑R * (Zeroing.Hn (n - 1) + 1) ≤ ↑om.cur.P.T) (hpow : om.cur.P.a = 2 ^ om.cur.P.a.log2) :
                          ∃ (c' : Model.Core) (y : ℕ), EStateM.run (Model.insertAfter (insAnchor om hx) om.nextHandle) om.cur = EStateM.Result.ok y c' ∧ Proof.CostInv (Proof.TIat Proof.Top.TopInv P) Proof.Top.topMu (Proof.Top.topJ P) n R (Spec.insertAfterL (insAnchor om hx) om.cur.E.size L) c' ∧ c'.count = om.cur.count + 1 ∧ c'.P = om.cur.P ∧ Mc (capsOf P) P c' ∧ y = om.cur.E.size ∧ Machine.wp (curInsC p) (fun (m' : Machine.State) (k : ℕ) => WEnc (insOM om c' y) m' p ∧ m'.loc "hy" = om.nextHandle ∧ m'.loc "y" = y ∧ m'.loc "hx" = m.loc "hx" ∧ m'.loc "x" = m.loc "x" ∧ k ≤ insBound P + 100) m

                          Cores in service #

                          A core in service, as the wrapper's Level M steps need it: Level F's CoreOK for the proof parameters, room for one more element, and the capacity predicate.

                          Instances For

                            The parameter conditions of insertAgreeM, for a core in service.

                            theorem OrderMaintenance.Impl.InService.insert {c : Model.Core} {L : List ℕ} (h : InService c L) {x : ℕ} (hx : x ∈ L) (hh : ℕ) (Lx : Loc) (hLx : Lx "x" = x) (hLh : Lx "h" = hh) :

                            An insertion into a core in service, at Level M.

                            Insertion into nxt #

                            Insert after the element in local xn of nxt, with handle hh; record it in the next handle map.

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

                              The wrapper state after an insertion into nxt.

                              Equations
                              • One or more equations did not get rendered due to their size.
                              Instances For
                                theorem OrderMaintenance.Impl.nxtInsW_ok {om : Model.OrderMaintenance} {m : Machine.State} {p : ℕ} (h : WEnc om m p) {n : Model.Core} (hn : om.nxt = some n) {B : List ℕ} (hS : InService n B) {xn hh : ℕ} (hxn : xn ∈ B) (hlx : m.loc "xn" = xn) (hlh : m.loc "hh" = hh) (hhc : hh < m.cap (wIdx (1 - p))) :
                                theorem OrderMaintenance.Impl.wp_assign_seq {x : Machine.Reg} {e : Machine.Expr} {c : Machine.Stmt} {Q : Machine.State → ℕ → Prop} {s : Machine.State} {v : ℕ} (he : Machine.Expr.eval s e = some v) (h : ∀ (s' : Machine.State), s'.loc = Machine.State.upd s.loc x v → s'.mem = s.mem → s'.cap = s.cap → Machine.wp c (fun (s'' : Machine.State) (n : ℕ) => Q s'' (1 + e.cost + n)) s') :
                                Machine.wp (x ::= e;; c) Q s

                                An assignment followed by code: the code runs from any state that differs only in the local.

                                theorem OrderMaintenance.Impl.WEnc.congr {om : Model.OrderMaintenance} {m m' : Machine.State} {p : ℕ} (h : WEnc om m p) (hm : m'.mem = m.mem) (hc : m'.cap = m.cap) :
                                WEnc om m' p

                                Mirroring an insertion into nxt #

                                Mirror an insertion into the replacement core when the copying frontier permits it.

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

                                  The anchor of a mirrored insertion in nxt.

                                  Equations
                                  Instances For
                                    theorem OrderMaintenance.Impl.mirrorInsW_ok {om : Model.OrderMaintenance} {m : Machine.State} {p : ℕ} (h : WEnc om m p) {hx : Option ℕ} {hy : ℕ} (hhx : m.loc "hx" = b2n hx.isSome) (hxx : ∀ (x : ℕ), hx = some x → m.loc "x" = x ∧ (om.nxt.isSome = true → x < m.cap (wIdx (1 - p)))) (hhy : m.loc "hy" = hy) (hhyc : om.nxt.isSome = true → hy < m.cap (wIdx (1 - p))) (hN : ∀ (n : Model.Core), om.nxt = some n → om.cursorSet = true → (hx = none ∨ ∃ (x : ℕ), hx = some x ∧ om.nxtIdx.getX x ≠ 0) → ∃ (B : List ℕ), InService n B ∧ mirAnchor om n hx ∈ B) {om2 : Model.OrderMaintenance} (hr : om.mirrorInsert hx hy = Except.ok om2) :
                                    Machine.wp (mirrorInsC p) (fun (m' : Machine.State) (k : ℕ) => WEnc om2 m' p ∧ (∀ (x : String), x ≠ "xn" → x ≠ "hh" → x ≠ "y2" → m'.loc x = m.loc x) ∧ k ≤ insBound ((Option.map (fun (x : Model.Core) => x.P) om.nxt).getD om.cur.P) + 100) m

                                    The swap #

                                    nxt replaces cur: flip the parity, and nxt is gone.

                                    Equations
                                    • One or more equations did not get rendered due to their size.
                                    Instances For
                                      theorem OrderMaintenance.Impl.swapW_ok {om : Model.OrderMaintenance} {m : Machine.State} {p : ℕ} (h : WEnc om m p) {n : Model.Core} (hn : om.nxt = some n) {Q : Machine.State → ℕ → Prop} (hQ : ∀ (m' : Machine.State) (k : ℕ), WEnc (om.swap n) m' (1 - p) → (∀ (x : Machine.Reg), m'.loc x = m.loc x) → k ≤ 10 → Q m' k) :