Documentation

LeanPool.OrderMaintenance.Proof.Top.PresDrain

M5: a sweep step keeps the invariant #

drainStep src, in the funding loop of a job (.fund v up src k, k < s), on a ghost with a non-empty range: all its lookups succeed, its tag passes the guard, and the invariant holds afterwards with k + 1 (docs/PROOF.md §4.5.1, SweepStep).

The state after a sweep step #

theorem OrderMaintenance.Proof.Top.dsS_P (s : Model.Core) (v tag : ℕ) :
(dsS s v tag).P = s.P
theorem OrderMaintenance.Proof.Top.dsS_cin (s : Model.Core) (v tag : ℕ) :
(dsS s v tag).cin = s.cin
theorem OrderMaintenance.Proof.Top.dsS_path (s : Model.Core) (v tag : ℕ) :
(dsS s v tag).path = s.path.setX (dsY s v) ((s.path.getX (dsY s v)).setX (s.nodes.getX v).height (dsT s v))
theorem OrderMaintenance.Proof.Top.dsS_C (s : Model.Core) (v tag : ℕ) :
(dsS s v tag).C = s.C.modify (dsY s v) 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 := tag, alive := C.alive }

New range pointers of the ghost.

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

    The ghost range last pointer after transferring one chunk to a target.

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

      New range pointers of the target.

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

        The target range last pointer after receiving the transferred chunk.

        Equations
        • One or more equations did not get rendered due to their size.
        Instances For
          theorem OrderMaintenance.Proof.Top.dsS_node (s : Model.Core) (v tag : ℕ) (hvt : v ≠ dsT s v) (hv : v < s.nodes.size) (ht : dsT s v < s.nodes.size) (u : ℕ) :
          (dsS s v tag).nodes.getX u = if u = v then have __src := s.nodes.getX u; { height := __src.height, livePar := __src.livePar, children := __src.children, weight := __src.weight, table := __src.table, inTables := __src.inTables, first := dsFirstV s v, last := dsLastV s v, draining := __src.draining, t1 := __src.t1, t2 := __src.t2, side := __src.side, overflowOf := __src.overflowOf, alive := __src.alive } else if u = dsT s v then have __src := s.nodes.getX u; { height := __src.height, livePar := __src.livePar, children := __src.children, weight := __src.weight, table := __src.table, inTables := __src.inTables, first := dsFirstT s v, last := dsLastT s v, draining := __src.draining, t1 := __src.t1, t2 := __src.t2, side := __src.side, overflowOf := __src.overflowOf, alive := __src.alive } else s.nodes.getX u

          The top structure's part after a sweep step #

          theorem OrderMaintenance.Proof.Top.dsS_sameTree {s : Model.Core} {v tag : ℕ} (hvt : v ≠ dsT s v) (hv : v < s.nodes.size) (ht : dsT s v < s.nodes.size) :
          SameTree (ts s) (ts (dsS s v tag))
          theorem OrderMaintenance.Proof.Top.dsS_first {s : Model.Core} {v tag : ℕ} (hvt : v ≠ dsT s v) (hv : v < s.nodes.size) (ht : dsT s v < s.nodes.size) (u : ℕ) :
          (nd (ts (dsS s v tag)) u).first = if u = v then dsFirstV s v else if u = dsT s v then dsFirstT s v else (nd (ts s) u).first
          theorem OrderMaintenance.Proof.Top.dsS_last {s : Model.Core} {v tag : ℕ} (hvt : v ≠ dsT s v) (hv : v < s.nodes.size) (ht : dsT s v < s.nodes.size) (u : ℕ) :
          (nd (ts (dsS s v tag)) u).last = if u = v then dsLastV s v else if u = dsT s v then dsLastT s v else (nd (ts s) u).last
          theorem OrderMaintenance.Proof.Top.dsS_weight {s : Model.Core} {v tag : ℕ} (hvt : v ≠ dsT s v) (hv : v < s.nodes.size) (ht : dsT s v < s.nodes.size) (u : ℕ) :
          (nd (ts (dsS s v tag)) u).weight = (nd (ts s) u).weight
          theorem OrderMaintenance.Proof.Top.dsS_pp (s : Model.Core) (v tag : ℕ) (h1 : 1 ≤ (s.nodes.getX v).height) (c j : ℕ) :
          pp (ts (dsS s v tag)) c j = if c = dsY s v ∧ j = (s.nodes.getX v).height then dsT s v else pp (ts s) c j
          theorem OrderMaintenance.Proof.Top.dsS_tag (s : Model.Core) (v tag : ℕ) (hy : dsY s v < s.C.size) (c : ℕ) :
          (ts (dsS s v tag)).tag c = if c = dsY s v then tag else (ts s).tag c

          What a sweep step finds #

          theorem OrderMaintenance.Proof.Top.lab_some_of_mem {s : TS} {X e : ℕ} (h : e ∈ order s X) :
          ∃ (l : ℕ), (nd s X).lab? e = some l
          theorem OrderMaintenance.Proof.Top.getD_of_mem {s : TS} {X e : ℕ} (h : e ∈ order s X) :
          (nd s X).lab? e = some (((nd s X).lab? e).getD 0)
          theorem OrderMaintenance.Proof.Top.lab_lt {s : TS} {cl : List ℕ} {ord : ℕ → List ℕ} (S : ShapeT s cl ord) {X e l : ℕ} (hX : isN s X) (h : (nd s X).lab? e = some l) :
          l < 2 ^ s.P.beta
          theorem OrderMaintenance.Proof.Top.Shape.ghost_ne_anc {s : Model.Core} {cl : List ℕ} {ord : ℕ → List ℕ} (S : Shape (ts s) cl ord) {v c j : ℕ} (hc : c ∈ cl) (hj1 : 1 ≤ j) (hj : j ≤ (ts s).P.H) (hg : ghostN (ts s) v) :
          anc (ts s) c j ≠ v
          theorem OrderMaintenance.Proof.Top.Shape.rng_ghost {s : Model.Core} {cl : List ℕ} {ord : ℕ → List ℕ} (S : Shape (ts s) cl ord) {v c : ℕ} (hg : ghostN (ts s) v) (hc : c ∈ rng (ts s) cl v) :
          c ∈ cl ∧ pp (ts s) c (ht (ts s) v) = v ∧ (anc (ts s) c (ht (ts s) v) = (nd (ts s) v).t1 ∨ anc (ts s) c (ht (ts s) v) = (nd (ts s) v).t2) ∧ belowY s v c = pp (ts s) c (ht (ts s) v - 1) ∧ Model.lookup (nd (ts s) v).side (pp (ts s) c (ht (ts s) v - 1)) = some (if anc (ts s) c (ht (ts s) v) = (nd (ts s) v).t1 then Model.Side.left else Model.Side.right)

          A chunk in a ghost's range: its live ancestor is a target, and the entry below has a side.

          theorem OrderMaintenance.Proof.Top.Shape.t1_ne_t2 {s : Model.Core} {cl : List ℕ} {ord : ℕ → List ℕ} (S : Shape (ts s) cl ord) {v : ℕ} (hg : ghostN (ts s) v) :
          (nd (ts s) v).t1 ≠ (nd (ts s) v).t2
          theorem OrderMaintenance.Proof.Top.rng_sub {s : Model.Core} {cl : List ℕ} (v : ℕ) :
          (rng (ts s) cl v).Sublist cl
          theorem OrderMaintenance.Proof.Top.Shape.pick {s : Model.Core} {cl : List ℕ} {ord : ℕ → List ℕ} (S : Shape (ts s) cl ord) {v : ℕ} (hg : ghostN (ts s) v) (hne : rng (ts s) cl v ≠ []) :
          dsY s v ∈ rng (ts s) cl v ∧ anc (ts s) (dsY s v) (ht (ts s) v) = dsT s v ∧ (goesLeft s v → dsY s v = (rng (ts s) cl v).headD Model.NIL ∧ dsT s v = (nd (ts s) v).t1) ∧ (¬goesLeft s v → dsY s v = (rng (ts s) cl v).getLastD Model.NIL ∧ dsT s v = (nd (ts s) v).t2) ∧ (goesLeft s v ∨ Model.lookup (s.nodes.getX v).side (belowY s v (s.nodes.getX v).first) = some Model.Side.right ∧ Model.lookup (s.nodes.getX v).side (belowY s v (s.nodes.getX v).last) = some Model.Side.right)

          The sweep step's pick: the chunk moved is in the range, its live ancestor is the target, it is the first (moving left) or the last (moving right) of the range.

          The tag part of the invariant after the step #

          theorem OrderMaintenance.Proof.Top.Shape.ds_basics {s : Model.Core} {cl : List ℕ} {ord : ℕ → List ℕ} (S : Shape (ts s) cl ord) {v : ℕ} (hg : ghostN (ts s) v) (hne : rng (ts s) cl v ≠ []) :
          v ≠ dsT s v ∧ v < s.nodes.size ∧ dsT s v < s.nodes.size ∧ liveN (ts s) (dsT s v) ∧ ht (ts s) (dsT s v) = ht (ts s) v ∧ 1 ≤ ht (ts s) v ∧ ht (ts s) v < (ts s).P.H
          theorem OrderMaintenance.Proof.Top.Shape.ds_pp {s : Model.Core} {cl : List ℕ} {ord : ℕ → List ℕ} (S : Shape (ts s) cl ord) {v : ℕ} (hg : ghostN (ts s) v) (hne : rng (ts s) cl v ≠ []) (tag c j : ℕ) :
          pp (ts (dsS s v tag)) c j = if c = dsY s v ∧ j = ht (ts s) v then dsT s v else pp (ts s) c j
          theorem OrderMaintenance.Proof.Top.Shape.drain_shapeT {s : Model.Core} {cl : List ℕ} {ord : ℕ → List ℕ} (S : Shape (ts s) cl ord) {v : ℕ} (hg : ghostN (ts s) v) (hne : rng (ts s) cl v ≠ []) (tag : ℕ) :
          ShapeT (ts (dsS s v tag)) cl ord
          theorem OrderMaintenance.Proof.Top.Shape.ds_digit {s : Model.Core} {cl : List ℕ} {ord : ℕ → List ℕ} (S : Shape (ts s) cl ord) {v : ℕ} (hg : ghostN (ts s) v) (hne : rng (ts s) cl v ≠ []) (tag c j : ℕ) (hj : j ≠ ht (ts s) v) (hj1 : j ≠ ht (ts s) v + 1 ∨ c ≠ dsY s v) :
          digit (ts (dsS s v tag)) c j = digit (ts s) c j
          theorem OrderMaintenance.Proof.Top.Shape.ds_tagF_other {s : Model.Core} {cl : List ℕ} {ord : ℕ → List ℕ} (S : Shape (ts s) cl ord) {v : ℕ} (hg : ghostN (ts s) v) (hne : rng (ts s) cl v ≠ []) (tag c : ℕ) (hc : c ≠ dsY s v) :
          tagF (ts (dsS s v tag)) c = tagF (ts s) c
          theorem OrderMaintenance.Proof.Top.Shape.ds_mem {s : Model.Core} {cl : List ℕ} {ord : ℕ → List ℕ} (S : Shape (ts s) cl ord) {v : ℕ} (hg : ghostN (ts s) v) (hne : rng (ts s) cl v ≠ []) :
          have y := dsY s v; have h := ht (ts s) v; dsT s v ∈ order (ts s) (pp (ts s) y (h + 1)) ∧ pp (ts s) y (h - 1) ∈ order (ts s) (dsT s v) ∧ v ∈ order (ts s) (pp (ts s) y (h + 1)) ∧ pp (ts s) y (h - 1) ∈ order (ts s) v

          The table entries a sweep step reads.

          theorem OrderMaintenance.Proof.Top.Shape.drain_move_facts {s : Model.Core} {cl : List ℕ} {ord : ℕ → List ℕ} (S : Shape (ts s) cl ord) {v : ℕ} (hg : ghostN (ts s) v) (hne : rng (ts s) cl v ≠ []) (hL : LList (cN s) (cP s) s.firstChunk cl) :
          have y := dsY s v; have h := ht (ts s) v; have pv := digit (ts s) y (h + 1); have vb := digit (ts s) y h; have pt := ((nd (ts s) (pp (ts s) y (h + 1))).lab? (dsT s v)).getD 0; have tb := ((nd (ts s) (dsT s v)).lab? (pp (ts s) y (h - 1))).getD 0; ((s.nodes.getX v).alive = true ∧ (s.nodes.getX v).first ≠ Model.NIL ∧ (goesLeft s v ∨ Model.lookup (s.nodes.getX v).side (belowY s v (s.nodes.getX v).first) = some Model.Side.right ∧ Model.lookup (s.nodes.getX v).side (belowY s v (s.nodes.getX v).last) = some Model.Side.right) ∧ (s.nodes.getX v).height + 1 < (s.path.getX (dsY s v)).size ∧ (s.nodes.getX ((s.path.getX (dsY s v)).getX ((s.nodes.getX v).height + 1))).lab? (dsT s v) = some pt ∧ (s.nodes.getX (dsT s v)).lab? (belowY s v (dsY s v)) = some tb ∧ (s.nodes.getX ((s.path.getX (dsY s v)).getX ((s.nodes.getX v).height + 1))).lab? v = some pv ∧ (s.nodes.getX v).lab? (belowY s v (dsY s v)) = some vb ∧ pv <<< ((s.nodes.getX v).height * s.P.beta) ||| vb <<< (((s.nodes.getX v).height - 1) * s.P.beta) ≤ (s.C.getX (dsY s v)).tag ∧ TagOK s (dsY s v) (dsTag s v pt tb pv vb) ∧ 1 ≤ (s.nodes.getX v).height ∧ (s.path.getX (dsY s v)).size = s.P.H + 1 ∧ tb < 2 ^ s.P.beta ∧ vb < 2 ^ s.P.beta ∧ dsT s v ≠ v ∧ v < s.nodes.size ∧ dsT s v < s.nodes.size ∧ dsY s v ∈ cl ∧ (s.nodes.getX v).height < s.P.H ∧ (s.path.getX (dsY s v)).getX ((s.nodes.getX v).height + 1) < s.nodes.size) ∧ dsTag s v pt tb pv vb = tagF (ts (dsS s v (dsTag s v pt tb pv vb))) y

          Shared sweep-step guards, shape bounds and the interpretation of the new tag.

          theorem OrderMaintenance.Proof.Top.Shape.drain_run {s : Model.Core} {cl : List ℕ} {ord : ℕ → List ℕ} (S : Shape (ts s) cl ord) {v : ℕ} (hg : ghostN (ts s) v) (hne : rng (ts s) cl v ≠ []) (hL : LList (cN s) (cP s) s.firstChunk cl) :
          have y := dsY s v; have h := ht (ts s) v; have pv := digit (ts s) y (h + 1); have vb := digit (ts s) y h; have pt := ((nd (ts s) (pp (ts s) y (h + 1))).lab? (dsT s v)).getD 0; have tb := ((nd (ts s) (dsT s v)).lab? (pp (ts s) y (h - 1))).getD 0; EStateM.run (Model.drainStep v) s = EStateM.Result.ok true (dsS s v (dsTag s v pt tb pv vb)) ∧ dsTag s v pt tb pv vb = tagF (ts (dsS s v (dsTag s v pt tb pv vb))) y

          The sweep step runs, and the tag it writes is the tag of the new path.

          The rest of the order invariant after the step #

          theorem OrderMaintenance.Proof.Top.Shape.rng_infix {s : Model.Core} {cl : List ℕ} {ord : ℕ → List ℕ} (S : Shape (ts s) cl ord) (u : ℕ) (hu : isN (ts s) u) :
          rng (ts s) cl u <:+: cl
          theorem OrderMaintenance.Proof.Top.Shape.ds_rng {s : Model.Core} {cl : List ℕ} {ord : ℕ → List ℕ} (S : Shape (ts s) cl ord) {v : ℕ} (hg : ghostN (ts s) v) (hne : rng (ts s) cl v ≠ []) (tag u : ℕ) :
          rng (ts (dsS s v tag)) cl u = if u = v then (rng (ts s) cl v).erase (dsY s v) else if u = dsT s v then if goesLeft s v then rng (ts s) cl (dsT s v) ++ [dsY s v] else dsY s v :: rng (ts s) cl (dsT s v) else rng (ts s) cl u

          The ranges after the step: the chunk leaves the ghost's range and joins the target's, at the end next to it.

          theorem OrderMaintenance.Proof.Top.Shape.ds_ends {s : Model.Core} {cl : List ℕ} {ord : ℕ → List ℕ} (S : Shape (ts s) cl ord) {v : ℕ} (hg : ghostN (ts s) v) (hne : rng (ts s) cl v ≠ []) (hL : LList (cN s) (cP s) s.firstChunk cl) (tag u : ℕ) (hu : isN (ts s) u) :
          (nd (ts (dsS s v tag)) u).first = (rng (ts (dsS s v tag)) cl u).headD Model.NIL ∧ (nd (ts (dsS s v tag)) u).last = (rng (ts (dsS s v tag)) cl u).getLastD Model.NIL

          Range pointers after the step.

          theorem OrderMaintenance.Proof.Top.Shape.drain_shape {s : Model.Core} {cl : List ℕ} {ord : ℕ → List ℕ} (S : Shape (ts s) cl ord) {v : ℕ} (hg : ghostN (ts s) v) (hne : rng (ts s) cl v ≠ []) (hL : LList (cN s) (cP s) s.firstChunk cl) (hcs : ∀ c ∈ cl, c < s.C.size) (tag : ℕ) (htag : tag = tagF (ts (dsS s v tag)) (dsY s v)) :
          Shape (ts (dsS s v tag)) cl ord

          The order invariant after a sweep step.

          Timing, room and the job after the step #

          theorem OrderMaintenance.Proof.Top.SameTree.pend_fund {s s' : TS} (T : SameTree s s') (j : Model.Job) (w up v k k' : ℕ) :
          pend s' (some { x := j.x, y := j.y, z := j.z, pc := Model.JobPc.fund w up v k' }) = pend s (some { x := j.x, y := j.y, z := j.z, pc := Model.JobPc.fund w up v k })
          theorem OrderMaintenance.Proof.Top.SameTree.slack_other {s s' : TS} (T : SameTree s s') (j : Model.Job) (w up v k k' u : ℕ) (hu : u ≠ v) :
          slack s' (some { x := j.x, y := j.y, z := j.z, pc := Model.JobPc.fund w up v k' }) u = slack s (some { x := j.x, y := j.y, z := j.z, pc := Model.JobPc.fund w up v k }) u
          theorem OrderMaintenance.Proof.Top.SameTree.slack_self {s s' : TS} (T : SameTree s s') (j : Model.Job) (w up v k k' : ℕ) (hw : Top.ht s w = Top.ht s v) (hf : Top.anc s j.y (Top.ht s v) = (nd s v).t1 ∨ Top.anc s j.y (Top.ht s v) = (nd s v).t2) :
          slack s' (some { x := j.x, y := j.y, z := j.z, pc := Model.JobPc.fund w up v k' }) v = s.P.s - k' ∧ slack s (some { x := j.x, y := j.y, z := j.z, pc := Model.JobPc.fund w up v k }) v = s.P.s - k
          theorem OrderMaintenance.Proof.Top.inv_drainMove {s : Model.Core} {cl : List ℕ} {ord : ℕ → List ℕ} {dr n0 : ℕ → ℕ} {j : Model.Job} {w up v k : ℕ} (hI : InvJ (ts s) cl ord dr n0 (some { x := j.x, y := j.y, z := j.z, pc := Model.JobPc.fund w up v k })) (hL : LList (cN s) (cP s) s.firstChunk cl) (hcs : ∀ c ∈ cl, c < s.C.size) (hk : k < s.P.s) (hne : rng (ts s) cl v ≠ []) :
          ∃ (s' : Model.Core), EStateM.run (Model.drainStep v) s = EStateM.Result.ok true s' ∧ TopRel s s' ∧ InvJ (ts s') cl ord dr n0 (some { x := j.x, y := j.y, z := j.z, pc := Model.JobPc.fund w up v (k + 1) }) ∧ ∀ (u : ℕ), ht (ts s') u = ht (ts s) u

          A sweep step keeps the invariant, and moves the funding loop on.