Documentation

LeanPool.OrderMaintenance.Impl.Caps

M6: the capacities (step 4 of the glue) #

The Level M side conditions (TopCaps, GCaps, InsCaps, PQCaps, ...) bound the record counts of a core. Level F bounds the element and chunk counts already (E.size = count + 1, CountInv.chunks). Here are the bounds Level F lacks:

Steps that keep the node count #

The node count is unchanged.

Equations
Instances For
    theorem OrderMaintenance.Proof.ns_fundLoop (j : Model.Job) (v up src k : ℕ) :
    Pres NS (Model.fundLoop j v up src k)
    theorem OrderMaintenance.Proof.Pres.ok {R : Model.Core → Model.Core → Prop} {α : Type} {m : Model.CM α} (h : Pres R m) {s s' : Model.Core} {a : α} (hr : EStateM.run m s = EStateM.Result.ok a s') :
    R s s'

    Top steps keep the preparation state #

    The preparation state is unchanged.

    Equations
    Instances For
      theorem OrderMaintenance.Proof.tp_tableInsert (t e new : ℕ) (b : Bool) (lab : ℕ) :
      Pres TP (Model.tableInsert t e new b lab)
      theorem OrderMaintenance.Proof.tp_fundLoop (j : Model.Job) (v up src k : ℕ) :
      Pres TP (Model.fundLoop j v up src k)
      theorem OrderMaintenance.Proof.tp_insertAroundFinish (x y z : ℕ) (tabs ly lz : List ℕ) (lp : ℕ) :
      Pres TP (Model.insertAroundFinish x y z tabs ly lz lp)

      insertAround keeps the node count #

      theorem OrderMaintenance.Proof.ns_tableInsert (t e new : ℕ) (b : Bool) (lab : ℕ) :
      Pres NS (Model.tableInsert t e new b lab)
      theorem OrderMaintenance.Proof.ns_insertAroundFinish (x y z : ℕ) (tabs ly lz : List ℕ) (lp : ℕ) :
      Pres NS (Model.insertAroundFinish x y z tabs ly lz lp)

      The node count across a job step #

      theorem OrderMaintenance.Proof.walk_nodes {s : Model.Core} {cl : List ℕ} {ord : ℕ → List ℕ} {dr n0 : ℕ → ℕ} {j : Model.Job} {v : ℕ} (hpc : j.pc = Model.JobPc.walk (some v)) (hTP : Top.TopParams s.P) (hI : Top.InvJ (Top.ts s) cl ord dr n0 (some j)) {r : Option Model.Job} {t1 : Model.Core} (h : EStateM.run (Model.walkBody j v) s = EStateM.Result.ok r t1) :
      t1.nodes.size = s.nodes.size ∨ t1.nodes.size = s.nodes.size + 2 ∧ (∃ (j' : Model.Job), r = some j') ∧ ∀ (j' : Model.Job), r = some j' → Top.jobLeft (Top.ts t1) j' + 2 ≤ Top.jobLeft (Top.ts s) j

      A walk step adds no nodes, or starts a drain: 2 nodes, and the job measure drops by at least 2.

      theorem OrderMaintenance.Proof.node_step {s : Model.Core} {job : Model.Job} (hT : Top.TopInv s) (hres : s.resJob = some job) {r : Option Model.Job} {t1 : Model.Core} (h : EStateM.run (Model.jobStep job) s = EStateM.Result.ok r t1) :
      t1.nodes.size + Top.topMu { P := t1.P, E := t1.E, Gs := t1.Gs, C := t1.C, freeG := t1.freeG, count := t1.count, head := t1.head, tail := t1.tail, firstGroup := t1.firstGroup, firstChunk := t1.firstChunk, ready := t1.ready, prep := t1.prep, resJob := r, fallbacks := t1.fallbacks, pqHead := t1.pqHead, pqNext := t1.pqNext, pqPrev := t1.pqPrev, pqWhere := t1.pqWhere, nbNext := t1.nbNext, nbPrev := t1.nbPrev, pqHi := t1.pqHi, pqLo := t1.pqLo, nodes := t1.nodes, path := t1.path, cin := t1.cin, lpar := t1.lpar } ≤ s.nodes.size + Top.topMu s

      The node count across a job step: nodes.size + topMu does not grow.

      A split start keeps the node count and the preparation state, and adds two chunks.

      Top steps without path writes keep the paths and the chunk count #

      The paths and the chunk count are unchanged.

      Equations
      Instances For
        theorem OrderMaintenance.Proof.pcs_tableInsert (t e new : ℕ) (b : Bool) (lab : ℕ) :
        Pres PCS (Model.tableInsert t e new b lab)

        Path rows beyond the chunks stay zero #

        The path rows of chunks not yet allocated read zero.

        Equations
        Instances For
          theorem OrderMaintenance.Proof.PZ.of_frame {s s' : Model.Core} (h : PZ s) (hC : s.C.size ≤ s'.C.size) (hp : ∀ (c : ℕ), s.C.size ≤ c → s'.path.getX c = s.path.getX c) :
          PZ s'
          theorem OrderMaintenance.Proof.PZ.setX {s s' : Model.Core} (h : PZ s) (hC : s'.C.size = s.C.size) {y : ℕ} {row : Array ℕ} (hy : y < s.C.size) (hp : s'.path = s.path.setX y row) :
          PZ s'
          theorem OrderMaintenance.Proof.dsS_frame (s : Model.Core) (v tag : ℕ) :
          (Top.dsS s v tag).path = s.path.setX (Top.dsY s v) ((s.path.getX (Top.dsY s v)).setX (s.nodes.getX v).height (Top.dsT s v)) ∧ (Top.dsS s v tag).C.size = s.C.size
          theorem OrderMaintenance.Proof.drain_pz {s : Model.Core} {cl : List ℕ} {ord : ℕ → List ℕ} (S : Top.Shape (Top.ts s) cl ord) {v : ℕ} (hg : Top.ghostN (Top.ts s) v) (hcl : Top.CLok s cl) {b : Bool} {t : Model.Core} (h : EStateM.run (Model.drainStep v) s = EStateM.Result.ok b t) :
          t.C.size = s.C.size ∧ (PZ s → PZ t)

          A sweep step keeps the zero rows and the chunk count.

          theorem OrderMaintenance.Proof.fund_pz {s : Model.Core} {cl : List ℕ} {ord : ℕ → List ℕ} {dr n0 : ℕ → ℕ} {j : Model.Job} {v up src k : ℕ} (hcl : Top.CLok s cl) (hI : Top.InvJ (Top.ts s) cl ord dr n0 (some { x := j.x, y := j.y, z := j.z, pc := Model.JobPc.fund v up src k })) {r : Option Model.Job} {t : Model.Core} (h : EStateM.run (Model.fundLoop j v up src k) s = EStateM.Result.ok r t) :
          t.C.size = s.C.size ∧ (PZ s → PZ t)

          The funding loop keeps the zero rows and the chunk count.

          theorem OrderMaintenance.Proof.walk_pz {s : Model.Core} {cl : List ℕ} {ord : ℕ → List ℕ} {dr n0 : ℕ → ℕ} {j : Model.Job} {v : ℕ} (hpc : j.pc = Model.JobPc.walk (some v)) (hcl : Top.CLok s cl) (hI : Top.InvJ (Top.ts s) cl ord dr n0 (some j)) {r : Option Model.Job} {t1 : Model.Core} (h : EStateM.run (Model.walkBody j v) s = EStateM.Result.ok r t1) :
          t1.C.size = s.C.size ∧ (PZ s → PZ t1)

          A walk step keeps the zero rows and the chunk count.

          theorem OrderMaintenance.Proof.copyC_frame (s : Model.Core) (j : Model.Job) (l : ℕ) :
          (Top.copyC s j l).C.size = s.C.size ∧ ∀ (c : ℕ), c ≠ j.y → c ≠ j.z → (Top.copyC s j l).path.getX c = s.path.getX c
          theorem OrderMaintenance.Proof.path_step {s : Model.Core} {job : Model.Job} (hT : Top.TopInv s) (hres : s.resJob = some job) {r : Option Model.Job} {t1 : Model.Core} (h : EStateM.run (Model.jobStep job) s = EStateM.Result.ok r t1) :
          t1.C.size = s.C.size ∧ (PZ s → PZ t1)

          A job step keeps the zero rows and the chunk count.

          The path rows from n on are unchanged.

          Equations
          Instances For
            theorem OrderMaintenance.Proof.py_setPath (n : ℕ) {c : ℕ} (p : Array ℕ) (hc : c < n) :
            theorem OrderMaintenance.Proof.py_tableInsert (n t e new : ℕ) (b : Bool) (lab : ℕ) :
            Pres (PY n) (Model.tableInsert t e new b lab)
            theorem OrderMaintenance.Proof.py_insertAroundFinish (n : ℕ) {x y z : ℕ} (tabs ly lz : List ℕ) (lp : ℕ) (hy : y < n) (hz : z < n) :
            Pres (PY n) (Model.insertAroundFinish x y z tabs ly lz lp)
            theorem OrderMaintenance.Proof.py_insertAround (n : ℕ) {x y z : ℕ} (hy : y < n) (hz : z < n) :

            A split start keeps the zero rows.

            A queue pop changes only the queue #

            A split start keeps the queue.

            The capacity conditions #

            The chunk bound of a core of capacity P.N (CountInv.chunks).

            Equations
            Instances For

              The nodes of a fresh core.

              Equations
              Instances For

                The capacities as functions of the parameters.

                Instances For
                  theorem OrderMaintenance.Impl.topCaps_of {κ : Caps} {s : Model.Core} (K : CapsOK κ s.P) (hN : NodeB s) (hC : s.C.size ≤ cb s.P) :
                  TopCaps κ s

                  The capacity predicate of the reservation rounds.

                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For
                    theorem OrderMaintenance.Impl.Mc.caps {κ : Caps} {P : Model.Params} (K : CapsOK κ P) {t : Model.Core} (h : Mc κ P t) :
                    TopCaps κ t ∧ PQCaps κ t ∧ t.prep = none ∧ ∀ (c : ℕ), t.C.size ≤ c → ∀ (j : ℕ), (t.path.getX c).getX j = 0
                    theorem OrderMaintenance.Impl.ts_eq_of {s s' : Model.Core} (hP : s'.P = s.P) (hN : s'.nodes = s.nodes) (hp : s'.path = s.path) (hc : s'.cin = s.cin) (hl : s'.lpar = s.lpar) (hC : s'.C = s.C) :
                    theorem OrderMaintenance.Impl.mc_pop {κ : Caps} {P : Model.Params} {t t1 : Model.Core} {c : ℕ} (h : Mc κ P t) (hp : EStateM.run Model.pqPopMax t = EStateM.Result.ok c t1) :
                    Mc κ P t1
                    theorem OrderMaintenance.Impl.mc_job {κ : Caps} {P : Model.Params} {t : Model.Core} {job : Model.Job} (hT : Proof.Top.TopInv t) (h : Mc κ P t) (hres : t.resJob = some job) {r : Option Model.Job} {t1 : Model.Core} (hr : EStateM.run (Model.jobStep job) t = EStateM.Result.ok r t1) :
                    Mc κ P { P := t1.P, E := t1.E, Gs := t1.Gs, C := t1.C, freeG := t1.freeG, count := t1.count, head := t1.head, tail := t1.tail, firstGroup := t1.firstGroup, firstChunk := t1.firstChunk, ready := t1.ready, prep := t1.prep, resJob := r, fallbacks := t1.fallbacks, pqHead := t1.pqHead, pqNext := t1.pqNext, pqPrev := t1.pqPrev, pqWhere := t1.pqWhere, nbNext := t1.nbNext, nbPrev := t1.nbPrev, pqHi := t1.pqHi, pqLo := t1.pqLo, nodes := t1.nodes, path := t1.path, cin := t1.cin, lpar := t1.lpar }
                    theorem OrderMaintenance.Impl.mc_split {κ : Caps} {P : Model.Params} {t t1 t2 : Model.Core} {c : ℕ} (h : Mc κ P t) (hnone : t.resJob = none) (hp : EStateM.run Model.pqPopMax t = EStateM.Result.ok c t1) (hs : EStateM.run (Model.splitChunkStart c) t1 = EStateM.Result.ok () t2) (hP2 : t2.P = P) (hmu : Proof.Top.topMu t2 ≤ Proof.Top.topJ P) (hC2 : t2.C.size ≤ cb P) (hc2 : t2.count ≤ P.N) (hce : t2.count = t.count) :
                    Mc κ P t2
                    theorem OrderMaintenance.Impl.cb_of {t : Model.Core} {L : List ℕ} (hL : Proof.LowInv t L) (hc : t.count ≤ t.P.N) :
                    t.C.size ≤ cb t.P

                    The chunk bound at a state of the low invariant whose count is at most N.

                    The element count of a core is its number of element records.

                    theorem OrderMaintenance.Impl.insCaps_of {κ : Caps} {s : Model.Core} {L : List ℕ} (K : CapsOK κ s.P) (hM : Mc κ s.P s) (hL : Proof.LowInv s L) (hcntL : s.count = L.length) (hcnt : s.count + 1 ≤ s.P.N) :
                    InsCaps κ s

                    The capacities at the start of an insertion, from the capacity conditions and the invariants.

                    @[reducible, inline]

                    The cost bound of an insertion at Level M, at parameters P.

                    Equations
                    Instances For
                      theorem OrderMaintenance.Impl.insertAgreeM {P : Model.Params} {n R : ℕ} {L : List ℕ} {s : Model.Core} {x : ℕ} (hC : Proof.CostInv (Proof.TIat Proof.Top.TopInv P) Proof.Top.topMu (Proof.Top.topJ P) n R L s) (hsP : s.P = P) (hx : x ∈ L) (hk : 1 ≤ s.P.reservationBudget) (hR : Proof.Top.topJ P / s.P.reservationBudget + 1 ≤ R) (hn : 1 ≤ n) (hsize : 2 + 2 * ((s.count + 1) / (s.P.theta + 1 - Proof.cmax s.P)) ≤ n + 1) (hcap : 2 + 2 * ((s.count + 1) / (s.P.theta + 1 - Proof.cmax s.P)) ≤ Proof.Top.capT s.P) (hI5 : ↑s.P.theta + ↑R * (Zeroing.Hn (n - 1) + 1) ≤ ↑s.P.T) (hh : ℕ) {κ : Caps} (Lx : Loc) (hLx : Lx "x" = x) (hLh : Lx "h" = hh) (hpow : s.P.a = 2 ^ s.P.a.log2) (K : CapsOK κ P) (hcntL : s.count = L.length) (hcnt : s.count + 1 ≤ P.N) (hM0 : Mc κ P s) :

                      An insertion agrees at Level M under the cost invariant, the capacity conditions, the node budget, the zero path rows, and no preparation in progress.

                      Deletion and order #

                      theorem OrderMaintenance.Impl.markDeadAgreeM {P : Model.Params} {n R : ℕ} {L : List ℕ} {s : Model.Core} {x : ℕ} (hC : Proof.CostInv (Proof.TIat Proof.Top.TopInv P) Proof.Top.topMu (Proof.Top.topJ P) n R L s) (hsP : s.P = P) (hx : x ∈ L) {κ : Caps} (Lx : Loc) (hLx : Lx "x" = x) (K : CapsOK κ P) (hcntL : s.count = L.length) (hM : Mc κ P s) :

                      A deletion agrees and keeps the capacity predicate.

                      theorem OrderMaintenance.Impl.orderAgreeM {P : Model.Params} {n R : ℕ} {L : List ℕ} {s : Model.Core} {x y : ℕ} (hC : Proof.CostInv (Proof.TIat Proof.Top.TopInv P) Proof.Top.topMu (Proof.Top.topJ P) n R L s) (hx : x ∈ L) (hy : y ∈ L) {κ : Caps} (Lxy : Loc) (hLx : Lxy "x" = x) (hLy : Lxy "y" = y) (K : CapsOK κ P) (hcntL : s.count = L.length) (hM : Mc κ P s) {b : Bool} {s' : Model.Core} (h : EStateM.run (Model.order x y) s = EStateM.Result.ok b s') :
                      ∃ (L' : Loc) (m : ℕ), evalF κ orderP.body s Lxy = Res.ok s' L' m ∧ L' "r" = b2n b ∧ m ≤ 80

                      An order query agrees; it changes nothing.

                      A fresh core #

                      The path rows from 2 on are empty (a core under construction).

                      Equations
                      Instances For
                        theorem OrderMaintenance.Impl.prep_pz1 {P : Model.Params} {h : ℕ} {s s' : Model.Core} {b : Bool} (S : Proof.Top.Stage P h s) (hH1 : 1 ≤ P.H) (hz : PZ1 s) (hr : EStateM.run Model.initStep s = EStateM.Result.ok b s') :
                        PZ1 s'

                        A construction step keeps the empty rows.

                        theorem OrderMaintenance.Impl.mc_final {κ : Caps} {P : Model.Params} (K : CapsOK κ P) (hN : 1 ≤ P.N) {s : Model.Core} (F : Proof.Top.Final P s) (hz : PZ1 s) :
                        Mc κ P s

                        A ready fresh core satisfies the capacity predicate.

                        The capacities of a core #

                        The capacities of a core with parameters P: every bound above, exactly. The list capacities are constants (they fix the strides of the compiled code), except the free-group stack's, which has stride 0.

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

                          The list capacities do not depend on the parameters, so neither does the compiled code.

                          theorem OrderMaintenance.Impl.Exp.compile_congr {p : ℕ} {κ κ' : Caps} (h : ∀ (k : LK), LK.stride κ.lcap k = LK.stride κ'.lcap k) (e : Exp) :
                          compile p κ e = compile p κ' e
                          theorem OrderMaintenance.Impl.Stm.compile_congr {p : ℕ} {κ κ' : Caps} (h : ∀ (k : LK), LK.stride κ.lcap k = LK.stride κ'.lcap k) (c : Stm) :
                          compile p κ c = compile p κ' c

                          The compiled code does not depend on the capacities, beyond the list strides.

                          A preparation step #

                          A core under construction, as Level M needs it: Level F's stage invariant, empty path rows from 2 on, and empty top arrays at the first stage.

                          Equations
                          • One or more equations did not get rendered due to their size.
                          Instances For
                            theorem OrderMaintenance.Impl.prepAgreeM {s : Model.Core} (hM : PrepM s) (hN : 1 ≤ s.P.N) {b : Bool} {s' : Model.Core} (hr : EStateM.run Model.prepareStep s = EStateM.Result.ok b s') (L : Loc) :
                            (∃ (L' : Loc) (c : ℕ), evalF (capsOf s.P) prepP.body s L = Res.ok s' L' c ∧ L' "r" = b2n b ∧ c ≤ 440) ∧ s'.P = s.P ∧ (b = false → PrepM s') ∧ (b = true → Mc (capsOf s.P) s.P s' ∧ Proof.Top.TopInv s' ∧ s'.resJob = none)

                            A preparation step agrees, and keeps the construction's invariant or makes the core ready with the capacity predicate.