Documentation

LeanPool.OrderMaintenance.Proof.Cost.LMove

Lemma C3 across chunk-split moves #

A chunk-split move carries a unit (a quiet group, or a whole family) from one end of the splitting chunk x to the adjacent end of a sibling dst. The moved groups get fresh labels pushed at that end and stop being children; the sibling's arrivals and pushes grow by the unit's length.

linv_cmove_core handles every field but the gaps and the label range, which depend on the direction and are proved separately.

theorem OrderMaintenance.Proof.linv_cmove_core {s s' : Model.Core} {A : Abs} {s₀ δ δu : ℕ → ℕ} {lg lg' : LGh} {x dst : ℕ} {u labs : List ℕ} (hI : INV s A) (hC : CInvE s A.elist δ δu s₀ x) (hL : LInv s lg s₀ δ δu) (M : CMoveSpec s s' x dst u labs) (hxL : LiveC s x) (hst : cSt s x = Model.St.splitting) (hdst : dst = cLl s x ∨ dst = cRr s x) (hu : ∀ g ∈ u, LiveG s g ∧ gC s g = x) (hk : u.length ≤ 3) (hunits : units s' x + 1 = units s x) (hm : (List.map (fun (g : ℕ) => gSz s g) u).sum ≤ cSz s x) (hcl : FamClosed s u) (hchild : ∀ (g : ℕ), lg'.child g = if g ∈ u then false else lg.child g) (hhv : lg'.hv = lg.hv) (hcs : lg'.cs = lg.cs) (hrs : lg'.rs = lg.rs) (hins : lg'.ins = lg.ins) (he0 : lg'.e0 = lg.e0) (hpb : ∀ (c : ℕ), lg'.pb c ≤ lg'.arB c + lg'.rs c + lg'.cs c) (hpf : ∀ (c : ℕ), lg'.pf c ≤ lg'.arF c + lg'.rs c + lg'.cs c) (harr : ∀ (c : ℕ), lg'.arB c + lg'.arF c = lg.arB c + lg.arF c + if c = dst then u.length else 0) (hgaps : ∀ (g : ℕ), LiveG s' g → g ≠ cLs s' (gC s' g) → gL s' g + s'.P.groupSpacing / 2 ^ lg'.hv (gC s' g) ≤ gL s' (gN s' g)) (hrange : ∀ (g : ℕ), LiveG s' g → cG s'.P ≤ gL s' g + lg'.pf (gC s' g) * s'.P.groupSpacing ∧ gL s' g ≤ cG s'.P + lg'.pb (gC s' g) * s'.P.groupSpacing) :
LInv s' lg' s₀ δ δu

The group-label invariant across a chunk-split move, given the gaps and ranges after it.

Facts for the two directions #

theorem OrderMaintenance.Proof.INV.gN_cLs {s : Model.Core} {A : Abs} (hI : INV s A) {y x : ℕ} (hy : y ∈ A.chunks) (hyx : cN s y = x) (hx0 : x ≠ Model.NIL) (hyne : cF s y ≠ Model.NIL) (hxne : cF s x ≠ Model.NIL) :
gN s (cLs s y) = cF s x

Across a chunk boundary, the last group of a chunk is followed by the first of the next.

theorem OrderMaintenance.Proof.pushBackLabs_vals {s : Model.Core} {center D B k : ℕ} {prev : Option ℕ} {labs : List ℕ} :
EStateM.run (Model.pushBackLabs center D B prev k) s = EStateM.Result.ok labs s → labs = List.map (fun (i : ℕ) => (match prev with | none => center | some p => p + D) + i * D) (List.range k)

The labels pushed at the back: b₀, b₀ + D, …, from the centre or after p.

theorem OrderMaintenance.Proof.pushFrontLabs_vals {s : Model.Core} {center D k : ℕ} {nxt : Option ℕ} {labs : List ℕ} :
EStateM.run (Model.pushFrontLabs center D nxt k) s = EStateM.Result.ok labs s → labs = List.map (fun (i : ℕ) => (match nxt with | none => center + D | some n => n) - (k - i) * D) (List.range k) ∧ (k * D ≤ match nxt with | none => center + D | some n => n) ∧ (k ≠ 0 → D ≠ 0 ∨ nxt = none)

The labels pushed at the front: …, n₀ − 2D, n₀ − D, before n (or the centre's n₀).

theorem OrderMaintenance.Proof.cmoveL_ends {s : Model.Core} {x : ℕ} {u labs : List ℕ} (hxy : x ≠ cLl s x) (hx : x < s.C.size) (hy : cLl s x < s.C.size) :
cLs (cmoveLState s x u labs) (cLl s x) = u.getLastD Model.NIL ∧ cLs (cmoveLState s x u labs) x = if cLs s x = u.getLastD Model.NIL then Model.NIL else cLs s x

The chunk ends after a move to the left sibling.

theorem OrderMaintenance.Proof.cmoveR_ends {s : Model.Core} {x : ℕ} {u labs : List ℕ} (hxz : x ≠ cRr s x) (hx : x < s.C.size) (hz : cRr s x < s.C.size) :
cF (cmoveRState s x u labs) (cRr s x) = u.headD Model.NIL ∧ (cLs (cmoveRState s x u labs) (cRr s x) = if cF s (cRr s x) = Model.NIL then u.getLastD Model.NIL else cLs s (cRr s x)) ∧ cLs (cmoveRState s x u labs) x = if cF s x = u.headD Model.NIL then Model.NIL else gP s (u.headD Model.NIL)

The chunk ends after a move to the right sibling.

theorem OrderMaintenance.Proof.INV.cF_ne_of_live {s : Model.Core} {A : Abs} (hI : INV s A) {g : ℕ} (hg : LiveG s g) :
cF s (gC s g) ≠ Model.NIL

A live group's chunk is not empty.

The shape of a unit: one group, or three consecutive groups.

Equations
Instances For
    theorem OrderMaintenance.Proof.UnitShape.pred {s : Model.Core} {A : Abs} (hI : INV s A) {u : List ℕ} (hsh : UnitShape s u) (hu : ∀ g ∈ u, LiveG s g) {h : ℕ} (hh : LiveG s h) (hnu : h ∉ u) (hm : gN s h ∈ u) :

    A group outside a unit followed by a member of it precedes the unit's head.

    theorem OrderMaintenance.Proof.CMoveSpec.gL_out {s s' : Model.Core} {x dst : ℕ} {u labs : List ℕ} (M : CMoveSpec s s' x dst u labs) {g : ℕ} (hg : g ∉ u) :
    gL s' g = gL s g
    theorem OrderMaintenance.Proof.CMoveSpec.gL_in {s s' : Model.Core} {x dst : ℕ} {u labs : List ℕ} (M : CMoveSpec s s' x dst u labs) {g : ℕ} (hg : g ∈ u) :
    gL s' g = labs.getD (List.idxOf g u) 0
    theorem OrderMaintenance.Proof.gaps_frame {s s' : Model.Core} {s₀ δ δu : ℕ → ℕ} {lg lg' : LGh} {x dst : ℕ} {u labs : List ℕ} (M : CMoveSpec s s' x dst u labs) (hL : LInv s lg s₀ δ δu) (hhv : lg'.hv = lg.hv) {h : ℕ} (hh : LiveG s h) (hnu : h ∉ u) (hnu' : gN s h ∉ u) (hl : h ≠ cLs s (gC s h)) :
    gL s' h + s'.P.groupSpacing / 2 ^ lg'.hv (gC s' h) ≤ gL s' (gN s' h)

    A gap away from the moved unit is unchanged.

    theorem OrderMaintenance.Proof.gaps_left {s s' : Model.Core} {A : Abs} {s₀ δ δu : ℕ → ℕ} {lg lg' : LGh} {x : ℕ} {u labs : List ℕ} (hI : INV s A) (hL : LInv s lg s₀ δ δu) (M : CMoveSpec s s' x (cLl s x) u labs) (hxy : cLl s x ≠ x) (hyx : cN s (cLl s x) = x) (hyC : LiveC s (cLl s x)) (hxL : LiveC s x) (hne : cF s x ≠ Model.NIL) (hsh : UnitShape s u) (hhead : u.headD Model.NIL = cF s x) (hnd : u.Nodup) (hu : ∀ g ∈ u, LiveG s g ∧ gC s g = x) (hlabs : labs = List.map (fun (i : ℕ) => (if cF s (cLl s x) = Model.NIL then cG s.P else gL s (cLs s (cLl s x)) + s.P.groupSpacing) + i * s.P.groupSpacing) (List.range u.length)) (hlast' : cLs s' (cLl s x) = u.getLastD Model.NIL) (hxlast' : cLs s' x = if cLs s x = u.getLastD Model.NIL then Model.NIL else cLs s x) (hhv : lg'.hv = lg.hv) (g : ℕ) :
    LiveG s' g → g ≠ cLs s' (gC s' g) → gL s' g + s'.P.groupSpacing / 2 ^ lg'.hv (gC s' g) ≤ gL s' (gN s' g)

    The gaps after a move to the left sibling.

    theorem OrderMaintenance.Proof.gaps_right {s s' : Model.Core} {A : Abs} {s₀ δ δu : ℕ → ℕ} {lg lg' : LGh} {x : ℕ} {u labs : List ℕ} (hI : INV s A) (hL : LInv s lg s₀ δ δu) (M : CMoveSpec s s' x (cRr s x) u labs) (hxz : cRr s x ≠ x) (hxzN : cN s x = cRr s x) (hzC : LiveC s (cRr s x)) (hxL : LiveC s x) (hne : cF s x ≠ Model.NIL) (hsh : UnitShape s u) (hlastu' : u.getLastD Model.NIL = cLs s x) (hnd : u.Nodup) (hu : ∀ g ∈ u, LiveG s g ∧ gC s g = x) (hlabs : labs = List.map (fun (i : ℕ) => (if cF s (cRr s x) = Model.NIL then cG s.P + s.P.groupSpacing else gL s (cF s (cRr s x))) - (u.length - i) * s.P.groupSpacing) (List.range u.length)) (hkD : u.length * s.P.groupSpacing ≤ if cF s (cRr s x) = Model.NIL then cG s.P + s.P.groupSpacing else gL s (cF s (cRr s x))) (hzlast' : cLs s' (cRr s x) = if cF s (cRr s x) = Model.NIL then u.getLastD Model.NIL else cLs s (cRr s x)) (hxlast' : cLs s' x = if cF s x = u.headD Model.NIL then Model.NIL else gP s (u.headD Model.NIL)) (hhv : lg'.hv = lg.hv) (g : ℕ) :
    LiveG s' g → g ≠ cLs s' (gC s' g) → gL s' g + s'.P.groupSpacing / 2 ^ lg'.hv (gC s' g) ≤ gL s' (gN s' g)

    The gaps after a move to the right sibling.

    theorem OrderMaintenance.Proof.pushBackLabs_ok (s : Model.Core) {center D B : ℕ} (hD : 0 < D) {k : ℕ} {prev : Option ℕ} :
    (∀ j < k, (match prev with | none => center | some p => p + D) + j * D < 1 <<< B) → ∃ (labs : List ℕ), EStateM.run (Model.pushBackLabs center D B prev k) s = EStateM.Result.ok labs s

    Pushing at the back succeeds when every label fits.

    theorem OrderMaintenance.Proof.pushFrontLabs_ok (s : Model.Core) {center D : ℕ} (hD : 0 < D) {k : ℕ} {nxt : Option ℕ} :
    (k * D ≤ match nxt with | none => center + D | some n => n) → ∃ (labs : List ℕ), EStateM.run (Model.pushFrontLabs center D nxt k) s = EStateM.Result.ok labs s

    Pushing at the front succeeds when every label stays nonnegative.

    theorem OrderMaintenance.Proof.push_room {s : Model.Core} {A : Abs} {lg : LGh} {s₀ δ δu : ℕ → ℕ} {x c k : ℕ} (hC : CInvE s A.elist δ δu s₀ x) (hL : LInv s lg s₀ δ δu) (hP : GParams s.P) (hxL : LiveC s x) (hst : cSt s x = Model.St.splitting) (hFB : FamBound s δ s₀ x) (hun : 1 ≤ units s x) (hc : c = cLl s x ∨ c = cRr s x) (hk : k ≤ 3) :
    lg.pb c + k ≤ PC s.P ∧ lg.pf c + k ≤ PC s.P

    Room for pushes at a sibling of a splitting chunk: with at least one unit left in x, its pushes plus one more unit stay within PC.

    theorem OrderMaintenance.Proof.range_cmove {s s' : Model.Core} {s₀ δ δu : ℕ → ℕ} {lg lg' : LGh} {x dst : ℕ} {u labs : List ℕ} (M : CMoveSpec s s' x dst u labs) (hL : LInv s lg s₀ δ δu) (hpb : ∀ (c : ℕ), lg.pb c ≤ lg'.pb c) (hpf : ∀ (c : ℕ), lg.pf c ≤ lg'.pf c) (hin : ∀ i < u.length, cG s.P ≤ labs.getD i 0 + lg'.pf dst * s.P.groupSpacing ∧ labs.getD i 0 ≤ cG s.P + lg'.pb dst * s.P.groupSpacing) (g : ℕ) :
    LiveG s' g → cG s'.P ≤ gL s' g + lg'.pf (gC s' g) * s'.P.groupSpacing ∧ gL s' g ≤ cG s'.P + lg'.pb (gC s' g) * s'.P.groupSpacing

    The label range after a move, given the range of the pushed labels.

    theorem OrderMaintenance.Proof.INV.cLs_live {s : Model.Core} {A : Abs} (hI : INV s A) {c : ℕ} (hne : cF s c ≠ Model.NIL) :
    LiveG s (cLs s c) ∧ gC s (cLs s c) = c

    The last group of a non-empty chunk is live and lies in it.

    theorem OrderMaintenance.Proof.INV.cF_live {s : Model.Core} {A : Abs} (hI : INV s A) {c : ℕ} (hne : cF s c ≠ Model.NIL) :
    LiveG s (cF s c) ∧ gC s (cF s c) = c

    The first group of a non-empty chunk is live and lies in it.

    theorem OrderMaintenance.Proof.units_pos {s : Model.Core} {x um : ℕ} (h : UnitG s x um) :
    1 ≤ units s x
    theorem OrderMaintenance.Proof.linv_cmoveL {s : Model.Core} {A : Abs} {gh : GGh} {lg : LGh} {s₀ δ δu : ℕ → ℕ} {x : ℕ} (hI : INV s A) (hG : GInv s A.elist gh fun (x : ℕ) => 0) (hP : GParams s.P) (hLP : LParams s.P) (hC : CInvE s A.elist δ δu s₀ x) (hL : LInv s lg s₀ δ δu) (hxL : LiveC s x) (hst : cSt s x = Model.St.splitting) (he : cF s x ≠ Model.NIL) (hFB : FamBound s δ s₀ x) :
    ∃ (labs : List ℕ), EStateM.run (pushLabsL s x (Model.unitCand s x true).length) s = EStateM.Result.ok labs s ∧ ∃ (lg' : LGh), LInv (cmoveLState s x (Model.unitCand s x true) labs) lg' s₀ δ δu

    Lemma C3 across a move to the left sibling (the chunk drive's hook): the pushed labels fit, and the invariant holds after the move.

    theorem OrderMaintenance.Proof.linv_cmoveR {s : Model.Core} {A : Abs} {gh : GGh} {lg : LGh} {s₀ δ δu : ℕ → ℕ} {x : ℕ} (hI : INV s A) (hG : GInv s A.elist gh fun (x : ℕ) => 0) (hP : GParams s.P) (hLP : LParams s.P) (hC : CInvE s A.elist δ δu s₀ x) (hL : LInv s lg s₀ δ δu) (hxL : LiveC s x) (hst : cSt s x = Model.St.splitting) (he : cF s x ≠ Model.NIL) (hFB : FamBound s δ s₀ x) :
    ∃ (labs : List ℕ), EStateM.run (pushLabsR s x (Model.unitCand s x false).length) s = EStateM.Result.ok labs s ∧ ∃ (lg' : LGh), LInv (cmoveRState s x (Model.unitCand s x false) labs) lg' s₀ δ δu

    Lemma C3 across a move to the right sibling (the chunk drive's hook).

    theorem OrderMaintenance.Proof.linv_cremove {s : Model.Core} {A : Abs} {lg : LGh} {s₀ δ δu : ℕ → ℕ} {x : ℕ} (hI : INV s A) (hC : CInvE s A.elist δ δu s₀ x) (hL : LInv s lg s₀ δ δu) (hxL : LiveC s x) (hst : cSt s x = Model.St.splitting) (hFB : FamBound s δ s₀ x) :
    LInv (cremoveState s x) { child := lg.child, hv := lg.hv, cs := lg.cs, rs := lg.rs, ins := lg.ins, pb := lg.pb, pf := lg.pf, arB := lg.arB, arF := lg.arF, e0 := fun (c : ℕ) => if c = cLl s x ∨ c = cRr s x then cSz s c else lg.e0 c } s₀ (fun (x : ℕ) => 0) fun (x : ℕ) => 0

    Lemma C3 across a chunk removal: the emptied chunk dies, its siblings become quiet with their current sizes as e0, and every undriven insertion counts as driven.