Documentation

LeanPool.OrderMaintenance.Proof.Cost.Labels

Lemma C3: group labels inside chunks (docs/PROOF.md §4.3) #

A chunk's group labels change through split starts (a halving of each gap next to the splitting group, or a push at an end of the chunk), group removals (two gaps merge), and chunk-split moves (groups pushed at the receiving end; groups leaving at the other chunk's end).

The Lean proof counts all halvings of a chunk X in one ghost counter hv X (each split start in X halves at most two gaps), instead of following each gap's halving history as PROOF.md does. Split starts are bounded as in PROOF.md:

Pushes are counted per end, as in PROOF.md. The coarser halving count needs a wider group label: groupBits ≈ 30L bits for the proof parameters instead of about 9L, still Θ(L).

Constants #

Units a chunk-split source moves, at most: units(T) + k_C(T).

Equations
Instances For

    Insertions into a chunk over its life, at most: T + 2 k_C(T).

    Equations
    Instances For

      Child splits in a chunk's life, at most.

      Equations
      Instances For

        Root splits in a chunk's life, at most.

        Equations
        Instances For

          Halvings in a chunk's life, at most.

          Equations
          Instances For

            The centre of the group label range.

            Equations
            Instances For

              The parameter conditions for group labels (I10, in the coarser form).

              Instances For

                Ghost state #

                Ghost counters tracking each chunk’s label halvings, splits, pushes and arrivals.

                • child : ℕ → Bool

                  A group created by a split start in its current chunk, and not moved since.

                • hv : ℕ → ℕ

                  Halvings, child splits, root splits, insertions of a chunk.

                • cs : ℕ → ℕ

                  Child splits started in each chunk.

                • rs : ℕ → ℕ

                  Root splits started in each chunk.

                • ins : ℕ → ℕ

                  Insertions charged to each chunk.

                • pb : ℕ → ℕ

                  Pushes at the back and front, and groups arrived at the back and front.

                • pf : ℕ → ℕ

                  Label pushes at the front of each chunk.

                • arB : ℕ → ℕ

                  Groups arriving at the back of each chunk.

                • arF : ℕ → ℕ

                  Groups arriving at the front of each chunk.

                • e0 : ℕ → ℕ

                  The size of a quiet chunk when it became quiet.

                Instances For

                  Counts over the groups of a chunk #

                  The groups of chunk c (as indices).

                  Equations
                  Instances For

                    Unsplit roots of chunk c: groups that are neither children nor splitting.

                    Equations
                    Instances For

                      The charge waiting to be converted into child splits (Claim 2): a family whose children were created in c carries its insertions, a quiet child carries its progress towards a split.

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

                        The invariant #

                        structure OrderMaintenance.Proof.LInv (s : Model.Core) (lg : LGh) (s₀ δ δu : ℕ → ℕ) :

                        Group-label separation, range and charging bounds across chunk phases.

                        Instances For

                          The labels of a split start #

                          theorem OrderMaintenance.Proof.labBefore_val {s : Model.Core} {g lab : ℕ} (h : EStateM.run (Model.labBefore g) s = EStateM.Result.ok lab s) :
                          lab = if g = cF s (gC s g) then gL s g - s.P.groupSpacing else (gL s (gP s g) + gL s g) / 2
                          theorem OrderMaintenance.Proof.labAfter_val {s : Model.Core} {g lab : ℕ} (h : EStateM.run (Model.labAfter g) s = EStateM.Result.ok lab s) :
                          lab = if g = cLs s (gC s g) then gL s g + s.P.groupSpacing else (gL s g + gL s (gN s g)) / 2
                          theorem OrderMaintenance.Proof.labBefore_guard {s : Model.Core} {g lab : ℕ} (h : EStateM.run (Model.labBefore g) s = EStateM.Result.ok lab s) :
                          (g = cF s (gC s g) → s.P.groupSpacing ≤ gL s g ∧ s.P.groupSpacing ≠ 0) ∧ (g ≠ cF s (gC s g) → gL s (gP s g) + 1 < gL s g)

                          The guard conditions of labBefore, when it succeeds.

                          theorem OrderMaintenance.Proof.labAfter_guard {s : Model.Core} {g lab : ℕ} (h : EStateM.run (Model.labAfter g) s = EStateM.Result.ok lab s) :
                          (g = cLs s (gC s g) → gL s g + s.P.groupSpacing < 1 <<< s.P.groupBits ∧ s.P.groupSpacing ≠ 0) ∧ (g ≠ cLs s (gC s g) → gL s g + 1 < gL s (gN s g))

                          Across a split start #

                          def OrderMaintenance.Proof.LGh.split (lg : LGh) (s : Model.Core) (g gl gr : ℕ) :

                          The ghost update of a split start of g (new groups gl, gr, in chunk c).

                          Equations
                          • One or more equations did not get rendered due to their size.
                          Instances For
                            theorem OrderMaintenance.Proof.GrpsC_split {s s' : Model.Core} {g gl gr labL labR : ℕ} (S : SplitSpec s s' g gl gr labL labR) (c : ℕ) :
                            GrpsC s' c = if c = gC s g then insert gl (insert gr (GrpsC s c)) else GrpsC s c
                            theorem OrderMaintenance.Proof.INV.prev_in_chunk {s : Model.Core} {A : Abs} (hI : INV s A) {g : ℕ} (hg : LiveG s g) (hf : g ≠ cF s (gC s g)) :
                            LiveG s (gP s g) ∧ gC s (gP s g) = gC s g ∧ gN s (gP s g) = g ∧ gP s g ≠ cLs s (gC s g)

                            The group before a non-first group of a chunk lies in the same chunk, right before it.

                            theorem OrderMaintenance.Proof.pending_split {s s' : Model.Core} {g gl gr labL labR : ℕ} (S : SplitSpec s s' g gl gr labL labR) (hg : LiveG s g) (hq : gSt s g = Model.St.quiet) (lg : LGh) (c : ℕ) :
                            (pending s' (lg.split s g gl gr) c + if c = gC s g ∧ lg.child g = false then 1 else 0) = pending s lg c

                            Unsplit roots after a split start: the splitting group stops being one.

                            One group's term in charge.

                            Equations
                            • One or more equations did not get rendered due to their size.
                            Instances For
                              theorem OrderMaintenance.Proof.charge_eq (s : Model.Core) (lg : LGh) (c : ℕ) :
                              charge s lg c = ∑ g ∈ GrpsC s c, chTerm s lg g
                              theorem OrderMaintenance.Proof.charge_split {s s' : Model.Core} {L : List ℕ} {gh : GGh} {δ : ℕ → ℕ} {ex g gl gr labL labR : ℕ} (S : SplitSpec s s' g gl gr labL labR) (hG : GInvE s L gh δ ex) (hg : LiveG s g) (hq : gSt s g = Model.St.quiet) (hsz : gSz s g = s.P.G) (lg : LGh) (c : ℕ) :
                              (charge s' (lg.split s g gl gr) c + if c = gC s g ∧ lg.child g = true then gmin s.P else 0) = charge s lg c

                              The charge after a split start: a quiet child's g_min became a child split.

                              theorem OrderMaintenance.Proof.INV.next_in_chunk {s : Model.Core} {A : Abs} (hI : INV s A) {g : ℕ} (hg : LiveG s g) (hl : g ≠ cLs s (gC s g)) :
                              LiveG s (gN s g) ∧ gC s (gN s g) = gC s g

                              The group after a non-last group of a chunk lies in the same chunk.

                              theorem OrderMaintenance.Proof.INV.last_of_next {s : Model.Core} {A : Abs} (hI : INV s A) {g : ℕ} (hg : LiveG s g) (hc : gN s g ≠ Model.NIL → gC s (gN s g) ≠ gC s g) :
                              g = cLs s (gC s g)

                              A group followed by a group of another chunk is the last of its chunk.

                              theorem OrderMaintenance.Proof.div_two_pow_succ (D k : ℕ) :
                              D / 2 ^ (k + 1) = D / 2 ^ k / 2
                              theorem OrderMaintenance.Proof.linv_splitStart_gaps {s : Model.Core} {A : Abs} {lg : LGh} {s₀ δ δu : ℕ → ℕ} {g labL labR : ℕ} (hI : INV s A) (hL : LInv s lg s₀ δ δu) (hg : LiveG s g) (hLb : EStateM.run (Model.labBefore g) s = EStateM.Result.ok labL s) (hLa : EStateM.run (Model.labAfter g) s = EStateM.Result.ok labR s) :
                              have t := splitState s g labL labR; have lg' := lg.split s g (splitL s g) (splitR s g); ∀ (h : ℕ), LiveG t h → h ≠ cLs t (gC t h) → gL t h + t.P.groupSpacing / 2 ^ lg'.hv (gC t h) ≤ gL t (gN t h)

                              Starting a group split preserves the gap between consecutive labels.

                              theorem OrderMaintenance.Proof.linv_splitStart {s : Model.Core} {A : Abs} {L : List ℕ} {gh : GGh} {δg s₀ δ δu : ℕ → ℕ} {ex : ℕ} {lg : LGh} {g labL labR : ℕ} (hI : INV s A) (hG : GInvE s L gh δg ex) (hL : LInv s lg s₀ δ δu) (hg : LiveG s g) (hq : gSt s g = Model.St.quiet) (hsz : gSz s g = s.P.G) (hLb : EStateM.run (Model.labBefore g) s = EStateM.Result.ok labL s) (hLa : EStateM.run (Model.labAfter g) s = EStateM.Result.ok labR s) :
                              LInv (splitState s g labL labR) (lg.split s g (splitL s g) (splitR s g)) s₀ δ δu

                              The group-label invariant across a split start.

                              Across a split move #

                              theorem OrderMaintenance.Proof.linv_move {s s' : Model.Core} {A : Abs} {L : List ℕ} {gh : GGh} {δg s₀ δ δu : ℕ → ℕ} {ex : ℕ} {lg : LGh} {src dst e lab : ℕ} (hI : INV s A) (hG : GInvE s L gh δg ex) (hL : LInv s lg s₀ δ δu) (M : MoveSpec s s' src dst e lab) (hsrc : LiveG s src) (hss : gSt s src = Model.St.splitting) (hdst : dst = gLl s src ∨ dst = gRr s src) (hne : 1 ≤ gSz s src) :
                              LInv s' lg s₀ δ δu

                              The group-label invariant across a split move (an element moves inside a family).

                              Across a group removal #

                              theorem OrderMaintenance.Proof.FamOK.source_inside_chunk {s : Model.Core} {A : Abs} {p : ℕ} (hI : INV s A) (F : FamOK s p) (hp : LiveG s p) :
                              cF s (gC s p) ≠ Model.NIL ∧ p ≠ cF s (gC s p) ∧ p ≠ cLs s (gC s p)

                              A splitting group's nonempty chunk starts before it and ends after it.

                              theorem OrderMaintenance.Proof.pending_remove_family {s s' : Model.Core} {lg : LGh} {p l r : ℕ} (hgrps : ∀ (d z : ℕ), z ∈ GrpsC s' d ↔ z ∈ GrpsC s d ∧ z ≠ p) (hst : ∀ (z : ℕ), gSt s' z = if z = l ∨ z = r then Model.St.quiet else gSt s z) (hs : gSt s p = Model.St.splitting) (hlst : gSt s l = Model.St.overflow) (hrst : gSt s r = Model.St.overflow) (d : ℕ) :
                              pending s' lg d = pending s lg d

                              Removing a split family keeps the count of pending root splits unchanged.

                              theorem OrderMaintenance.Proof.linv_remove {s : Model.Core} {A : Abs} {L : List ℕ} {gh : GGh} {δg s₀ δ δu : ℕ → ℕ} {ex : ℕ} {lg : LGh} {p : ℕ} (hI : INV s A) (hG : GInvE s L gh δg ex) (hL : LInv s lg s₀ δ δu) (hp : LiveG s p) (hs : gSt s p = Model.St.splitting) (he : gSz s p = 0) (hql : gmin s.P ≤ gSz s (gLl s p)) (hqr : gmin s.P ≤ gSz s (gRr s p)) (hg2 : 2 * gmin s.P ≤ s.P.G) :
                              LInv (removeState s p) lg s₀ δ (Function.update δu (gC s p) (δu (gC s p) + 1))

                              The group-label invariant across a group removal: two gaps merge, the siblings become quiet, and the family's charge pays for theirs.

                              Across an insertion #

                              What an insertion into group g changes for the label invariant (the element link and the chunk-size update): the sizes of g and of its chunk.

                              Instances For

                                The group whose charge an insertion into g may raise: g, or its family's source.

                                Equations
                                Instances For
                                  theorem OrderMaintenance.Proof.chTerm_ins {s s' : Model.Core} {A : Abs} {L : List ℕ} {gh : GGh} {δg : ℕ → ℕ} {ex g : ℕ} (hI : INV s A) (hG : GInvE s L gh δg ex) (S : InsSpec s s' g) (lg : LGh) {z : ℕ} (hz : LiveG s z) :
                                  chTerm s' lg z ≤ chTerm s lg z + if z = insOwner s g then 1 else 0

                                  One charge term grows, by at most one.

                                  theorem OrderMaintenance.Proof.charge_ins {s s' : Model.Core} {A : Abs} {L : List ℕ} {gh : GGh} {δg : ℕ → ℕ} {ex g : ℕ} (hI : INV s A) (hG : GInvE s L gh δg ex) (S : InsSpec s s' g) (hg : LiveG s g) (lg : LGh) (d : ℕ) :
                                  charge s' lg d ≤ charge s lg d + if d = gC s g then 1 else 0

                                  A chunk's charge grows by at most one, and only in the inserted group's chunk.

                                  theorem OrderMaintenance.Proof.linv_ins {s s' : Model.Core} {A : Abs} {L : List ℕ} {gh : GGh} {δg s₀ δ δu : ℕ → ℕ} {ex : ℕ} {lg : LGh} {g : ℕ} (hI : INV s A) (hG : GInvE s L gh δg ex) (hL : LInv s lg s₀ δ δu) (S : InsSpec s s' g) (hg : LiveG s g) (hcov : cSt s (gC s g) = Model.St.overflow → cLl s (cSrc s (gC s g)) = gC s g ∨ cRr s (cSrc s (gC s g)) = gC s g) :
                                  LInv s' { child := lg.child, hv := lg.hv, cs := lg.cs, rs := lg.rs, ins := Function.update lg.ins (gC s g) (lg.ins (gC s g) + 1), pb := lg.pb, pf := lg.pf, arB := lg.arB, arF := lg.arF, e0 := lg.e0 } s₀ (Function.update δ (gC s g) (δ (gC s g) + 1)) δu

                                  The group-label invariant across an insertion: the chunk's insertion count grows with its size and its charge.