Documentation

LeanPool.OrderMaintenance.Proof.Correct.GroupSplit

Starting a group split preserves INV-S (Lemma 3.2, StartSplit) #

startGroupSplit g checks that g is alive (hence in the group list), computes guarded labels for two new groups, allocates them (from the free list or fresh) and links them right before and after g, in the group list and in g's chunk. Their runs are empty, so the element list does not change.

Running the pieces #

Group allocation, as a pure function.

Equations
  • One or more equations did not get rendered due to their size.
Instances For
    theorem OrderMaintenance.Proof.startGroupSplit_run (s : Model.Core) (g : ℕ) :
    (∃ (labL : ℕ), ∃ (labR : ℕ), g ≠ Model.NIL ∧ g < s.Gs.size ∧ gA s g = true ∧ labL < gL s g ∧ (g ≠ cF s (gC s g) → gL s (gP s g) < labL) ∧ gL s g < labR ∧ (g ≠ cLs s (gC s g) → labR < gL s (gN s g)) ∧ EStateM.run (Model.startGroupSplit g) s = EStateM.Result.ok () (Model.linkGroupPair (allocGroup (allocGroup s (gC s g)).snd (gC s g)).snd g (allocGroup s (gC s g)).fst (allocGroup (allocGroup s (gC s g)).snd (gC s g)).fst labL labR)) ∨ ∃ (msg : String), EStateM.run (Model.startGroupSplit g) s = EStateM.Result.error (Model.Err.guard msg) s

    Allocation #

    What allocation needs: the free list holds unused allocated indices.

    Instances For
      theorem OrderMaintenance.Proof.allocGroup_spec {s : Model.Core} {L : List ℕ} (h : FreeOK s L) (c : ℕ) :
      have p := allocGroup s c; ¬p.fst ∈ L ∧ 1 ≤ p.fst ∧ p.fst < p.snd.Gs.size ∧ p.snd.Gs.getX p.fst = { chk := c } ∧ (∀ (b : ℕ), b ≠ p.fst → p.snd.Gs.getX b = s.Gs.getX b) ∧ ¬p.fst ∈ p.snd.freeG ∧ s.Gs.size ≤ p.snd.Gs.size ∧ (∀ (b : ℕ), b ∈ p.snd.freeG → b ∈ s.freeG) ∧ FreeOK p.snd L ∧ (∀ (b : ℕ), b < s.Gs.size → ¬b ∈ s.freeG → b ≠ p.fst) ∧ p.snd.E = s.E ∧ p.snd.C = s.C ∧ p.snd.head = s.head ∧ p.snd.tail = s.tail ∧ p.snd.firstGroup = s.firstGroup ∧ p.snd.firstChunk = s.firstChunk ∧ p.snd.Gs.size ≤ s.Gs.size + 1 ∧ (s.Gs.size < p.snd.Gs.size → p.fst = s.Gs.size)

      Lists #

      theorem OrderMaintenance.Proof.replace1_mid {l1 l2 ys : List ℕ} {x : ℕ} (h : ¬x ∈ l1) :
      (l1 ++ x :: l2).replace1 x ys = l1 ++ ys ++ l2
      theorem OrderMaintenance.Proof.replace1_not_mem {l ys : List ℕ} {x : ℕ} (h : ¬x ∈ l) :
      l.replace1 x ys = l
      theorem OrderMaintenance.Proof.replace1_append (x : ℕ) (ys a b : List ℕ) :
      (a ++ b).replace1 x ys = if x ∈ a then a.replace1 x ys ++ b else a ++ b.replace1 x ys
      theorem OrderMaintenance.Proof.flatMap_replace1 {L : List ℕ} {F F' : ℕ → List ℕ} {c g : ℕ} {ys : List ℕ} (hnd : (List.flatMap F L).Nodup) (hcnd : L.Nodup) (hc : c ∈ L) (hg : g ∈ F c) (hF : ∀ (b : ℕ), F' b = if b = c then (F c).replace1 g ys else F b) :
      theorem OrderMaintenance.Proof.isChain_around {l1 l2 : List ℕ} {x a b : ℕ} {f f' : ℕ → ℕ} (hs : List.IsChain (fun (x1 x2 : ℕ) => x1 < x2) (List.map f (l1 ++ x :: l2))) (hagree : ∀ (z : ℕ), z ∈ l1 ++ x :: l2 → f' z = f z) (ha1 : ∀ (w : ℕ), w ∈ l1.getLast? → f w < f' a) (ha2 : f' a < f x) (hb1 : f x < f' b) (hb2 : ∀ (w : ℕ), w ∈ l2.head? → f' b < f w) :
      List.IsChain (fun (x1 x2 : ℕ) => x1 < x2) (List.map f' (l1 ++ a :: x :: b :: l2))

      Sortedness after inserting a before and b after x.

      The records after linkGroupPair #

      structure OrderMaintenance.Proof.LinkOK (s : Model.Core) (g gl gr : ℕ) :

      The hypotheses under which linkGroupPair does what it should: distinct indices, in range.

      Instances For
        theorem OrderMaintenance.Proof.LinkOK.gN' {s : Model.Core} {g gl gr labL labR : ℕ} (h : LinkOK s g gl gr) (z : ℕ) :
        gN (Model.linkGroupPair s g gl gr labL labR) z = if z = g then gr else if z = gl then g else if z = gr then gN s g else if z = gP s g ∧ gP s g ≠ Model.NIL then gl else gN s z
        theorem OrderMaintenance.Proof.LinkOK.gP' {s : Model.Core} {g gl gr labL labR : ℕ} (h : LinkOK s g gl gr) (z : ℕ) :
        gP (Model.linkGroupPair s g gl gr labL labR) z = if z = g then gl else if z = gl then gP s g else if z = gr then g else if z = gN s g ∧ gN s g ≠ Model.NIL then gr else gP s z
        theorem OrderMaintenance.Proof.linkGroupPair_gF {s : Model.Core} {g gl gr labL labR : ℕ} (z : ℕ) :
        gF (Model.linkGroupPair s g gl gr labL labR) z = gF s z
        theorem OrderMaintenance.Proof.linkGroupPair_gLs {s : Model.Core} {g gl gr labL labR : ℕ} (z : ℕ) :
        gLs (Model.linkGroupPair s g gl gr labL labR) z = gLs s z
        theorem OrderMaintenance.Proof.linkGroupPair_gC {s : Model.Core} {g gl gr labL labR : ℕ} (z : ℕ) :
        gC (Model.linkGroupPair s g gl gr labL labR) z = gC s z
        theorem OrderMaintenance.Proof.linkGroupPair_gA {s : Model.Core} {g gl gr labL labR : ℕ} (z : ℕ) :
        gA (Model.linkGroupPair s g gl gr labL labR) z = gA s z
        theorem OrderMaintenance.Proof.LinkOK.gL' {s : Model.Core} {g gl gr labL labR : ℕ} (h : LinkOK s g gl gr) (z : ℕ) :
        gL (Model.linkGroupPair s g gl gr labL labR) z = if z = gl then labL else if z = gr then labR else gL s z
        theorem OrderMaintenance.Proof.linkGroupPair_Gsize {s : Model.Core} {g gl gr labL labR : ℕ} :
        (Model.linkGroupPair s g gl gr labL labR).Gs.size = s.Gs.size
        theorem OrderMaintenance.Proof.linkGroupPair_C {s : Model.Core} {g gl gr labL labR : ℕ} (z : ℕ) (hc : gC s g < s.C.size) :
        (Model.linkGroupPair s g gl gr labL labR).C.getX z = if z = gC s g then have __src := s.C.getX z; { next := __src.next, prev := __src.prev, first := if cF s (gC s g) = g then gl else cF s (gC s g), last := if cLs s (gC s g) = g then gr else cLs s (gC s g), size := __src.size, st := __src.st, src := __src.src, l := __src.l, r := __src.r, tag := __src.tag, alive := __src.alive } else s.C.getX z
        theorem OrderMaintenance.Proof.linkGroupPair_rest {s : Model.Core} {g gl gr labL labR : ℕ} :
        (Model.linkGroupPair s g gl gr labL labR).E = s.E ∧ (Model.linkGroupPair s g gl gr labL labR).C.size = s.C.size ∧ (Model.linkGroupPair s g gl gr labL labR).freeG = s.freeG ∧ (Model.linkGroupPair s g gl gr labL labR).head = s.head ∧ (Model.linkGroupPair s g gl gr labL labR).tail = s.tail ∧ (Model.linkGroupPair s g gl gr labL labR).firstChunk = s.firstChunk ∧ (Model.linkGroupPair s g gl gr labL labR).firstGroup = if gP s g ≠ Model.NIL then s.firstGroup else gl

        The abstract nesting after a split start: gl, g, gr in place of g in chunk c, with empty runs for gl and gr.

        Equations
        • One or more equations did not get rendered due to their size.
        Instances For
          theorem OrderMaintenance.Proof.INV.mem_of_alive {s : Model.Core} {A : Abs} (h : INV s A) {g : ℕ} (h0 : g ≠ Model.NIL) (hs : g < s.Gs.size) (ha : gA s g = true) :
          theorem OrderMaintenance.Proof.INV.gP_mem {s : Model.Core} {A : Abs} (h : INV s A) {g : ℕ} (hg : g ∈ A.glist) :
          theorem OrderMaintenance.Proof.INV.gN_mem {s : Model.Core} {A : Abs} (h : INV s A) {g : ℕ} (hg : g ∈ A.glist) :
          structure OrderMaintenance.Proof.GroupSplitFrame (s t : Model.Core) (A : Abs) (g gl gr labL labR : ℕ) :

          Concrete field changes and fresh indices produced by starting a group split.

          Instances For
            theorem OrderMaintenance.Proof.groupSplit_frame {s : Model.Core} {A : Abs} (hI : INV s A) {g : ℕ} (hg : g ∈ A.glist) (labL labR : ℕ) :
            have left := allocGroup s (gC s g); have right := allocGroup left.snd (gC s g); GroupSplitFrame s (Model.linkGroupPair right.snd g left.fst right.fst labL labR) A g left.fst right.fst labL labR
            theorem OrderMaintenance.Proof.GroupSplitFrame.groupList {s t : Model.Core} {A : Abs} {g gl gr labL labR : ℕ} (F : GroupSplitFrame s t A g gl gr labL labR) (hI : INV s A) (hg : g ∈ A.glist) :
            LList (gN t) (gP t) t.firstGroup (A.splitStart (gC s g) g gl gr).glist
            theorem OrderMaintenance.Proof.GroupSplitFrame.groupSorted {s t : Model.Core} {A : Abs} {g gl gr labL labR : ℕ} (F : GroupSplitFrame s t A g gl gr labL labR) (hI : INV s A) (hg : g ∈ A.glist) (hL1 : labL < gL s g) (hL2 : g ≠ cF s (gC s g) → gL s (gP s g) < labL) (hR1 : gL s g < labR) (hR2 : g ≠ cLs s (gC s g) → labR < gL s (gN s g)) (c : ℕ) :
            c ∈ (A.splitStart (gC s g) g gl gr).chunks → List.IsChain (fun (x1 x2 : ℕ) => x1 < x2) (List.map (gL t) ((A.splitStart (gC s g) g gl gr).grps c))
            theorem OrderMaintenance.Proof.GroupSplitFrame.chunkEnds {s t : Model.Core} {A : Abs} {g gl gr labL labR : ℕ} (F : GroupSplitFrame s t A g gl gr labL labR) (hI : INV s A) (hg : g ∈ A.glist) (c : ℕ) :
            c ∈ (A.splitStart (gC s g) g gl gr).chunks → Ends (cF t c) (cLs t c) ((A.splitStart (gC s g) g gl gr).grps c)
            theorem OrderMaintenance.Proof.GroupSplitFrame.invariant {s t : Model.Core} {A : Abs} {g gl gr labL labR : ℕ} (F : GroupSplitFrame s t A g gl gr labL labR) (hI : INV s A) (hg : g ∈ A.glist) (hL1 : labL < gL s g) (hL2 : g ≠ cF s (gC s g) → gL s (gP s g) < labL) (hR1 : gL s g < labR) (hR2 : g ≠ cLs s (gC s g) → labR < gL s (gN s g)) :
            INV t (A.splitStart (gC s g) g gl gr) ∧ (A.splitStart (gC s g) g gl gr).elist = A.elist
            theorem OrderMaintenance.Proof.GroupSplitFrame.elementFrame {s t : Model.Core} {A : Abs} {g gl gr labL labR : ℕ} (F : GroupSplitFrame s t A g gl gr labL labR) :
            EFrame s t

            Starting a group split preserves INV-S.