Documentation

LeanPool.OrderMaintenance.Proof.Cost.Groups

Groups: Lemmas G1, G2 and G4 (docs/PROOF.md §4.2) #

The group-level cost invariant GInv, between operations and inside one, and its preservation by every step that touches groups or elements. It gives:

Ghost counters are not part of the model: the invariant holds for some ghost state.

Undriven insertions. Inside an operation, the insertion precedes the drive of its family. δ g is the number of insertions into g not yet followed by a drive (0 or 1); the size conditions are stated for the sizes before those insertions.

Accessors and constants #

@[reducible, inline]

The element count stored in a group.

Equations
Instances For
    @[reducible, inline]

    The current split state of a group.

    Equations
    Instances For
      @[reducible, inline]

      The source group recorded by an overflow group.

      Equations
      Instances For
        @[reducible, inline]

        The left sibling recorded by a splitting group.

        Equations
        Instances For
          @[reducible, inline]

          The right sibling recorded by a splitting group.

          Equations
          Instances For

            A live group: in the group list (INV.mem_glist_iff).

            Equations
            Instances For

              k_G: insertions into a family until its split ends (floor form of PROOF.md's k_G).

              Equations
              Instances For

                The least size of a freshly quiet group, ⌈(G−3)/2⌉.

                Equations
                Instances For

                  The centre of the element label range.

                  Equations
                  Instances For

                    The parameter conditions for the group level (I1, I2).

                    Instances For

                      Ghost state #

                      Ghost counters per group: halvings, pushes at the back and at the front.

                      • hv : ℕ → ℕ

                        The number of label halvings charged to each group.

                      • pb : ℕ → ℕ

                        The number of label pushes at the back of each group.

                      • pf : ℕ → ℕ

                        The number of label pushes at the front of each group.

                      Instances For

                        The invariant #

                        The family of a splitting group g: its siblings are live, adjacent, overflow nodes with source g, in g's chunk (invariant F).

                        Instances For
                          def OrderMaintenance.Proof.G1 (s : Model.Core) (δ : ℕ → ℕ) (g : ℕ) :

                          Lemma G1's invariant for the family of g, at the sizes before the undriven insertions.

                          Equations
                          • One or more equations did not get rendered due to their size.
                          Instances For
                            theorem OrderMaintenance.Proof.G1.excess_le {s : Model.Core} {δ : ℕ → ℕ} {g : ℕ} (h : G1 s δ g) (hK : 2 ≤ s.P.groupBudget) :
                            gSz s (gLl s g) - δ (gLl s g) + (gSz s g - δ g) + (gSz s (gRr s g) - δ (gRr s g)) - s.P.G ≤ s.P.G / (s.P.groupBudget - 1)

                            G1 bounds the excess family size by the quotient of its split budget.

                            theorem OrderMaintenance.Proof.G1.drive_bounds {s : Model.Core} {δ : ℕ → ℕ} {g : ℕ} (h : G1 s δ g) (hK : 2 ≤ s.P.groupBudget) (hδs : δ (gLl s g) + δ g + δ (gRr s g) ≤ 1) (hδle : δ (gLl s g) ≤ gSz s (gLl s g) ∧ δ g ≤ gSz s g ∧ δ (gRr s g) ≤ gSz s (gRr s g)) :
                            s.P.G ≤ gSz s (gLl s g) + gSz s g + gSz s (gRr s g) ∧ gSz s (gLl s g) + gSz s g + gSz s (gRr s g) ≤ s.P.G + s.P.G / (s.P.groupBudget - 1) + 1 ∧ gSz s (gLl s g) ≤ gSz s (gRr s g) + 2 ∧ gSz s (gRr s g) ≤ gSz s (gLl s g) + 2

                            The common size and balance bounds used by every group-drive simulation.

                            structure OrderMaintenance.Proof.GInvE (s : Model.Core) (L : List ℕ) (gh : GGh) (δ : ℕ → ℕ) (x : ℕ) :

                            The group-level invariant, exempting the size conditions of the family of x (a family being driven).

                            Instances For
                              @[reducible, inline]
                              abbrev OrderMaintenance.Proof.GInv (s : Model.Core) (L : List ℕ) (gh : GGh) (δ : ℕ → ℕ) :

                              The group-level invariant, with no family exempt.

                              Equations
                              Instances For

                                Frame: steps that change none of the fields GInv reads #

                                The fields GInv reads are equal.

                                Instances For
                                  theorem OrderMaintenance.Proof.GSame.trans {s t u : Model.Core} (h1 : GSame s t) (h2 : GSame t u) :
                                  GSame s u
                                  theorem OrderMaintenance.Proof.GSame.liveG {s s' : Model.Core} (h : GSame s s') (g : ℕ) :
                                  LiveG s' g ↔ LiveG s g
                                  theorem OrderMaintenance.Proof.GSame.runOf {s s' : Model.Core} (h : GSame s s') (L : List ℕ) (g : ℕ) :
                                  theorem OrderMaintenance.Proof.GSame.famOK {s s' : Model.Core} (h : GSame s s') {g : ℕ} (hf : FamOK s g) :
                                  FamOK s' g
                                  theorem OrderMaintenance.Proof.GSame.g1 {s s' : Model.Core} (h : GSame s s') {δ : ℕ → ℕ} {g : ℕ} (hg : G1 s δ g) :
                                  G1 s' δ g
                                  theorem OrderMaintenance.Proof.GInvE.of_gsame {s s' : Model.Core} {L : List ℕ} {gh : GGh} {δ : ℕ → ℕ} {x : ℕ} (hG : GInvE s L gh δ x) (h : GSame s s') :
                                  GInvE s' L gh δ x

                                  Bounds between operations #

                                  theorem OrderMaintenance.Proof.G1.zero {s : Model.Core} {δ : ℕ → ℕ} {g : ℕ} (h : G1 s δ g) (hδ : ∀ (b : ℕ), δ b = 0) :
                                  s.P.G ≤ famT s g ∧ gSz s g + (s.P.groupBudget - 1) * (famT s g - s.P.G) ≤ s.P.G ∧ gSz s (gLl s g) ≤ gSz s (gRr s g) + 1 ∧ gSz s (gRr s g) ≤ gSz s (gLl s g) + 1
                                  theorem OrderMaintenance.Proof.GInv.famT_le {s : Model.Core} {L : List ℕ} {gh : GGh} (hG : GInv s L gh fun (x : ℕ) => 0) (hP : GParams s.P) {g : ℕ} (hg : LiveG s g) (hs : gSt s g = Model.St.splitting) :
                                  famT s g ≤ s.P.G + s.P.G / (s.P.groupBudget - 1)
                                  theorem OrderMaintenance.Proof.GInv.quiet0 {s : Model.Core} {L : List ℕ} {gh : GGh} (hG : GInv s L gh fun (x : ℕ) => 0) {g : ℕ} (hg : LiveG s g) (hs : gSt s g = Model.St.quiet) :
                                  gSz s g < s.P.G
                                  theorem OrderMaintenance.Proof.GInv.size_le {s : Model.Core} {L : List ℕ} {gh : GGh} (hG : GInv s L gh fun (x : ℕ) => 0) (hP : GParams s.P) {g : ℕ} (hg : LiveG s g) :
                                  gSz s g ≤ s.P.G + s.P.G / (s.P.groupBudget - 1)
                                  theorem OrderMaintenance.Proof.GInv.push_le {s : Model.Core} {L : List ℕ} {gh : GGh} (hG : GInv s L gh fun (x : ℕ) => 0) (hP : GParams s.P) {g : ℕ} (hg : LiveG s g) :
                                  gh.pb g + gh.pf g + 1 ≤ s.P.G + kG s.P
                                  theorem OrderMaintenance.Proof.GInv.hv_lt {s : Model.Core} {L : List ℕ} {gh : GGh} (hG : GInv s L gh fun (x : ℕ) => 0) (hP : GParams s.P) {g : ℕ} (hg : LiveG s g) :
                                  gh.hv g + 1 ≤ UG s.P
                                  theorem OrderMaintenance.Proof.two_le_div_pow {D U h : ℕ} (hD : 2 ^ U ≤ D) (hh : h + 1 ≤ U) :
                                  2 ≤ D / 2 ^ h
                                  theorem OrderMaintenance.Proof.GLinks.liveG {s s' : Model.Core} (h : GLinks s s') (g : ℕ) :
                                  LiveG s' g ↔ LiveG s g
                                  theorem OrderMaintenance.Proof.GLinks.famOK {s s' : Model.Core} (h : GLinks s s') {g : ℕ} (hf : FamOK s g) :
                                  FamOK s' g
                                  theorem OrderMaintenance.Proof.GLinks.ovf {s s' : Model.Core} (h : GLinks s s') {g : ℕ} (hf : LiveG s (gSrc s g) ∧ gSt s (gSrc s g) = Model.St.splitting ∧ (gLl s (gSrc s g) = g ∨ gRr s (gSrc s g) = g)) :
                                  LiveG s' (gSrc s' g) ∧ gSt s' (gSrc s' g) = Model.St.splitting ∧ (gLl s' (gSrc s' g) = g ∨ gRr s' (gSrc s' g) = g)

                                  Element insertion #

                                  theorem OrderMaintenance.Proof.insertElem_run' (s : Model.Core) (x hh : ℕ) :
                                  EStateM.run (Model.insertElem x hh) s = if x = gLs s (eG s x) then if eL s x + s.P.elementSpacing ≥ 1 <<< s.P.elementBits ∨ eL s x + s.P.elementSpacing ≤ eL s x then EStateM.Result.error (Model.Err.guard "elem: no room after last") s else EStateM.Result.ok s.E.size (Model.linkElem s x s.E.size (eL s x + s.P.elementSpacing) hh) else if eL s x + 1 ≥ eL s (eN s x) then EStateM.Result.error (Model.Err.guard "elem: no room between") s else EStateM.Result.ok s.E.size (Model.linkElem s x s.E.size ((eL s x + eL s (eN s x)) / 2) hh)
                                  theorem OrderMaintenance.Proof.linkElem_Gs (s : Model.Core) (x lab hh b : ℕ) :
                                  (Model.linkElem s x s.E.size lab hh).Gs.getX b = if eG s x = b ∧ eG s x < s.Gs.size then have __src := s.Gs.getX b; { next := __src.next, prev := __src.prev, first := __src.first, last := if (s.Gs.getX b).last = x then s.E.size else (s.Gs.getX b).last, chk := __src.chk, lab := __src.lab, size := (s.Gs.getX b).size + 1, st := __src.st, src := __src.src, l := __src.l, r := __src.r, alive := __src.alive } else s.Gs.getX b
                                  theorem OrderMaintenance.Proof.linkElem_gSz (s : Model.Core) (x lab hh b : ℕ) (hg : eG s x < s.Gs.size) :
                                  gSz (Model.linkElem s x s.E.size lab hh) b = if b = eG s x then gSz s b + 1 else gSz s b
                                  theorem OrderMaintenance.Proof.linkElem_P (s : Model.Core) (x lab hh : ℕ) :
                                  (Model.linkElem s x s.E.size lab hh).P = s.P
                                  structure OrderMaintenance.Proof.GhStep (gh gh' : GGh) (g : ℕ) :

                                  The ghost update of an insertion into group g: one more halving or push.

                                  Instances For
                                    theorem OrderMaintenance.Proof.div_pow_anti (D : ℕ) {a b : ℕ} (h : a ≤ b) :
                                    D / 2 ^ b ≤ D / 2 ^ a
                                    theorem OrderMaintenance.Proof.isChain_gap_mono {l : List ℕ} {w w' : ℕ} (h : List.IsChain (fun (a b : ℕ) => a + w ≤ b) l) (hw : w' ≤ w) :
                                    List.IsChain (fun (a b : ℕ) => a + w' ≤ b) l
                                    theorem OrderMaintenance.Proof.INV.next_in_run {s : Model.Core} {A : Abs} (hI : INV s A) {x : ℕ} (hx : x ∈ A.elist) (hl : x ≠ gLs s (eG s x)) :
                                    ∃ (r1 : List ℕ) (r2 : List ℕ), runOf s A.elist (eG s x) = r1 ++ x :: eN s x :: r2

                                    Unless x is the last of its group, the element after x follows it in the group's run.

                                    theorem OrderMaintenance.Proof.ginv_insertElem {s : Model.Core} {A : Abs} {gh : GGh} (hI : INV s A) (hG : GInv s A.elist gh fun (x : ℕ) => 0) (hP : GParams s.P) {x : ℕ} (hx : x ∈ A.elist) (hh : ℕ) :
                                    ∃ (lab : ℕ), EStateM.run (Model.insertElem x hh) s = EStateM.Result.ok s.E.size (Model.linkElem s x s.E.size lab hh) ∧ ∃ (gh' : GGh), GInv (Model.linkElem s x s.E.size lab hh) (Spec.insertAfterL x s.E.size A.elist) gh' fun (b : ℕ) => if b = eG s x then 1 else 0

                                    Lemma G4 for insertions. Between operations, element insertion passes its label guard; the new state satisfies GInv with one undriven insertion in x's group.