math / data /lean /OAI /Combinatorics /KServer /RosterEdits.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
65 kB
import Mathlib import OAI.Combinatorics.KServer.Tiers namespace OAI noncomputable section open scoped BigOperators open Finset namespace KServer.ActualRoster open RosterLifetimes FiniteBallLaw PartitionProbabilities Chronological attribute [local instance] Classical.propDecidable Classical.decEq lemma final_survival {K a : β„•} (hK : 2 ≀ K) (ha : a+1=K^2) : actualPresence K a=survive (1/(K:ℝ)) (K^2-K) := by have hkk : K+1 ≀ K^2 := by nlinarith have hak : Β¬a<K := by omega have hac : a<K^2 := by omega have he : a-K+1=K^2-K := by omega simp only [actualPresence,ite_eq_right hak,ite_eq_left hac,he] /-- Unconditional marginal death bound. The extra tail is never interpreted as a conditional compulsory hazard. -/ lemma death_marginal {K a b : β„•} (hK : 2 ≀ K) (hab : a ≀ b) (hba : b ≀ a+1) : (βˆ‘ d : Lifetime K, if alive K a d ∧ Β¬alive K b d then lifetimeLaw K d else 0) ≀ (1/(K:ℝ))*actualPresence K a+ if a<K^2 then survive (1/(K:ℝ)) (K^2-K) else 0 := by have hk : 1≀K := by omega have hq := (rate_range hk).1 have hs := (survival_range hk a).1 have ht := (survive_range (rate_range hk) (K^2-K)).1 by_cases he : b=a Β· subst b simp only [and_not_self,ite_false,sum_const_zero] exact add_nonneg (mul_nonneg hq hs) (by split_ifs <;> positivity) Β· have hb : b=a+1 := by omega subst b rw [death_probability hk] by_cases hac : a<K^2 Β· rw [ite_eq_left hac] by_cases hbc : a+1<K^2 Β· exact (ordinary_death_bound hk hbc).trans (le_add_of_nonneg_right ht) Β· have heq : a+1=K^2 := by omega rw [actual_cutoff (a:=a+1) (by omega),sub_zero,final_survival hK heq] exact le_add_of_nonneg_left (mul_nonneg hq ht) Β· rw [ite_eq_right hac,actual_cutoff (le_of_not_gt hac),actual_cutoff (by omega)] simp /-- A literal finite lifetime-tape first-coverer estimate. The `S` hypothesis is only a deterministic candidate count, and is discharged by chronological ages below. -/ theorem first_retirement_bound {H K : β„•} (hK : 2 ≀ K) (a b : Fin H β†’ β„•) (inc : βˆ€ i, a i≀b i ∧ b i≀a i+1) (cover : Fin H β†’ Prop) (S : Finset (Fin H)) (hS : βˆ€ i, cover i β†’ a i<K^2 β†’ i∈S) (hcard : S.card ≀ K^2) : PartitionProbabilities.probability (fun _ : Fin H=>lifetimeLaw K) (firstSeparation (fun i d=>cover i ∧ alive K (a i) d) (fun i d=>cover i ∧ alive K (a i) d ∧ Β¬alive K (b i) d)) ≀ 49/(K:ℝ) := by have hk : 1≀K := by omega have hkp : (0:ℝ)<K := by exact_mod_cast (show 0<K by omega) let T : ℝ := survive (1/(K:ℝ)) (K^2-K) have hT : 0≀T := (survive_range (rate_range hk) _).1 let Ξ΅ : Fin H β†’ ℝ := fun i=>if i∈S then (K:ℝ)*T else 0 have heps : βˆ‘ i, Ξ΅ i=(K:ℝ)*T*S.card := by simp [Ξ΅,sum_ite_mem,mul_comm] have hh := SparseFirstHit.sparse_bound (fun _ : Fin H=>lifetimeLaw K) (fun _=>lifetime_nonneg hk) (fun _=>lifetime_sum hk) (hit:=fun i d=>cover i ∧ alive K (a i) d) (sep:=fun i d=>cover i ∧ alive K (a i) d ∧ Β¬alive K (b i) d) (fun _ _ h=>⟨h.1,h.2.1⟩) Ξ΅ (rate_range hk).1 (fun i=>by dsimp [Ξ΅]; split_ifs <;> positivity) have hm (i : Fin H) : (βˆ‘ d, if cover i ∧ alive K (a i) d ∧ Β¬alive K (b i) d then lifetimeLaw K d else 0) ≀ (1/(K:ℝ))*((βˆ‘ d, if cover i ∧ alive K (a i) d then lifetimeLaw K d else 0)+Ξ΅ i) := by by_cases hc : cover i Β· simp only [hc,true_and] rw [alive_probability hk] have hd := death_marginal hK (inc i).1 (inc i).2 refine hd.trans ?_ by_cases hy : a i<K^2 Β· simp only [ite_eq_left hy,Ξ΅,ite_eq_left (hS i hc hy)] dsimp [T] field_simp exact le_rfl Β· simp only [ite_eq_right hy,add_zero] exact mul_le_mul_of_nonneg_left (le_add_of_nonneg_right (by dsimp [Ξ΅]; split_ifs <;> positivity)) (rate_range hk).1 Β· simp only [hc,false_and,ite_false,sum_const_zero,zero_add] exact mul_nonneg (rate_range hk).1 (by dsimp [Ξ΅]; split_ifs <;> positivity) have hb := hh (fun i=>by convert hm i using 1 Β· apply sum_congr rfl intro d _ by_cases h : cover i ∧ alive K (a i) d ∧ Β¬alive K (b i) d <;> simp [h] Β· apply congrArg (fun z : ℝ=>(1/(K:ℝ))*(z+Ξ΅ i)) apply sum_congr rfl intro d _ by_cases h : cover i ∧ alive K (a i) d <;> simp [h]) rw [heps] at hb have hc : (S.card:ℝ)≀(K:ℝ)^2 := by exact_mod_cast hcard have hfin : (1/(K:ℝ))*(1+(K:ℝ)*T*S.card) ≀ 1/(K:ℝ)+(K:ℝ)^2*T := by calc _ ≀ (1/(K:ℝ))*(1+(K:ℝ)*T*(K:ℝ)^2) := by gcongr _ = _ := by field_simp exact (hb.trans hfin).trans (actual_retirement_bound K hK) variable {Y : Type*} [MetricSpace Y] [Fintype Y] {H K : β„•} /-- The unconditional first-coverer retirement estimate for an actual fixed chronological roster and arbitrary fixed radii. Increment bounds follow from one chronological insertion, not from the realized random presences. -/ theorem chronological_retirement_bound (center : β„• β†’ Y) (I : Finset β„•) {r : ℝ} (hr : 0 < r) (hK : 2≀K) (rad : Fin H β†’ Outcome Y r) (p : Y) (b : Fin H β†’ β„•) (hinc : βˆ€ i : Fin H, age center I (20*r) i≀b i ∧ b i≀age center I (20*r) i+1) : PartitionProbabilities.probability (fun _ : Fin H=>lifetimeLaw K) (firstSeparation (fun i d=>(i:β„•)∈I ∧ dist (center i) p≀radius r (rad i) ∧ alive K (age center I (20*r) i) d) (fun i d=>(i:β„•)∈I ∧ dist (center i) p≀radius r (rad i) ∧ alive K (age center I (20*r) i) d ∧ Β¬alive K (b i) d)) ≀49/(K:ℝ) := by let a : Fin H β†’ β„• := fun i=>age center I (20*r) i let pres : Fin H β†’ Prop := fun i=>(i:β„•)∈I ∧ a i<K^2 let S := SparseFirstHit.candidates r (fun i : Fin H=>center i) pres p p have hb := first_retirement_bound hK a b hinc (fun i=>(i:β„•)∈I ∧ dist (center i) p≀radius r (rad i)) S (fun i hi ha=>by simp only [S,SparseFirstHit.candidates,mem_filter,mem_univ,true_and,min_self] exact ⟨⟨hi.1,ha⟩,hi.2.trans (radius_range hr _).2⟩) (SparseFirstHit.candidate_count hr.le center I pres (fun _ h=>h) p p (by simpa using hr.le)) simpa only [a,and_assoc] using hb end KServer.ActualRoster end noncomputable section open scoped BigOperators open Finset namespace KServer.ActualRoster open Chronological FiniteBallLaw PartitionProbabilities attribute [local instance] Classical.propDecidable Classical.decEq variable {Y : Type*} [MetricSpace Y] [Fintype Y] {H K : β„•} omit [Fintype Y] in lemma age_insert_bounds (center : β„• β†’ Y) (I : Finset β„•) (R : ℝ) (t i : β„•) : age center I R i ≀ age center (insert t I) R i ∧ age center (insert t I) R i ≀ age center I R i+1 := by refine ⟨age_mono center (subset_insert _ _) le_rfl i,?_⟩ unfold age rw [filter_insert] split_ifs Β· exact card_insert_le _ _ Β· omega lemma old_covered_of_new (center : β„• β†’ Y) (I : Finset β„•) (r : ℝ) (t : β„•) (life : Fin H β†’ Lifetime K) (rad : Fin H β†’ Outcome Y r) (p : Y) (i : Fin H) (hit : (i:β„•)β‰ t) (hi : covered center (insert t I) r life rad p i) : covered center I r life rad p i := by refine ⟨⟨(mem_insert.mp hi.1.1).resolve_left hit,?_⟩,hi.2⟩ exact alive_antitone K _ (age_insert_bounds center I (20*r) t i).1 hi.1.2 lemma new_covered_of_persists (center : β„• β†’ Y) (I : Finset β„•) (r : ℝ) (t : β„•) (life : Fin H β†’ Lifetime K) (rad : Fin H β†’ Outcome Y r) (p : Y) (i : Fin H) (hi : covered center I r life rad p i) (hp : present center (insert t I) r life i) : covered center (insert t I) r life rad p i := ⟨hp,hi.2⟩ /-- Chronological appending cannot supersede a surviving first coverer. -/ lemma first_persists (center : β„• β†’ Y) (I : Finset β„•) (r : ℝ) (t : β„•) (hI : βˆ€ i∈I, i<t) (life : Fin H β†’ Lifetime K) (rad : Fin H β†’ Outcome Y r) (p : Y) (i : Fin H) (hfirst : first center I r life rad p=some i) (hp : present center (insert t I) r life i) : first center (insert t I) r life rad p=some i := by obtain ⟨hc,hbefore⟩ := (first_some_iff _ _ _ _ _ _ _).mp hfirst apply (first_some_iff _ _ _ _ _ _ _).mpr refine ⟨new_covered_of_persists center I r t life rad p i hc hp,?_⟩ intro j hj hnew have hji : (j:β„•) < i := hj have hit := hI i hc.1.1 exact hbefore j hj (old_covered_of_new center I r t life rad p j (by omega) hnew) def retired (center : β„• β†’ Y) (I J : Finset β„•) (r : ℝ) (life : Fin H β†’ Lifetime K) (rad : Fin H β†’ Outcome Y r) (p : Y) : Prop := βˆƒ i, first center I r life rad p=some i ∧ Β¬present center J r life i lemma retired_iff (center : β„• β†’ Y) (I J : Finset β„•) (hIJ : IβŠ†J) (r : ℝ) (life : Fin H β†’ Lifetime K) (rad : Fin H β†’ Outcome Y r) (p : Y) : retired center I J r life rad p ↔ firstSeparation (fun i d=>(i:β„•)∈I ∧ dist (center i) p≀radius r (rad i) ∧ alive K (age center I (20*r) i) d) (fun i d=>(i:β„•)∈I ∧ dist (center i) p≀radius r (rad i) ∧ alive K (age center I (20*r) i) d ∧ Β¬alive K (age center J (20*r) i) d) life := by constructor Β· rintro ⟨i,hf,hn⟩ obtain ⟨hi,hbef⟩ := (first_some_iff _ _ _ _ _ _ _).mp hf refine ⟨i,⟨hi.1.1,hi.2,hi.1.2,fun h=>hn ⟨hIJ hi.1.1,h⟩⟩,?_⟩ rintro j hj ⟨hm,hd,ha⟩ exact hbef j hj ⟨⟨hm,ha⟩,hd⟩ Β· rintro ⟨i,⟨hm,hd,ha,hn⟩,hbef⟩ refine ⟨i,(first_some_iff _ _ _ _ _ _ _).mpr ⟨⟨⟨hm,ha⟩,hd⟩,?_⟩,fun h=>hn h.2⟩ intro j hj hh exact hbef j hj ⟨hh.1.1,hh.2,hh.1.2⟩ /-- An actual insertion's exceptional first-coverer retirement row, under the literal lifetime tape and with every radius held fixed. -/ theorem insertion_retirement (center : β„• β†’ Y) (I : Finset β„•) {r : ℝ} (hr : 0<r) (hK : 2≀K) (t : β„•) (rad : Fin H β†’ Outcome Y r) (p : Y) : PartitionProbabilities.probability (fun _ : Fin H=>lifetimeLaw K) (fun life=>retired center I (insert t I) r life rad p) ≀49/(K:ℝ) := by have he : (fun life=>retired center I (insert t I) r life rad p)= firstSeparation (fun i d=>(i:β„•)∈I ∧ dist (center i) p≀radius r (rad i) ∧ alive K (age center I (20*r) i) d) (fun i d=>(i:β„•)∈I ∧ dist (center i) p≀radius r (rad i) ∧ alive K (age center I (20*r) i) d ∧ Β¬alive K (age center (insert t I) (20*r) i) d) := by funext life exact propext (retired_iff center I _ (subset_insert _ _) r life rad p) rw [he] exact chronological_retirement_bound center I hr hK rad p _ (fun i=>age_insert_bounds center I (20*r) t i) /-- The retirement error is supported inside the 22r neighbourhood. -/ lemma retired_near (center : β„• β†’ Y) (I : Finset β„•) {r : ℝ} (hr : 0<r) (t : β„•) (hI : βˆ€ i∈I, i<t) (life : Fin H β†’ Lifetime K) (rad : Fin H β†’ Outcome Y r) (p : Y) (h : retired center I (insert t I) r life rad p) : dist p (center t)≀22*r := by obtain ⟨i,hf,hn⟩ := h obtain ⟨hi,_⟩ := (first_some_iff _ _ _ _ _ _ _).mp hf have hit : (i:β„•)<t := hI i hi.1.1 have ht : tβˆ‰I := fun hh=>Nat.lt_irrefl _ (hI t hh) have hc : dist (center i) (center t)≀20*r := by by_contra hc have ha := age_insert center I (20*r) ht hit rw [ite_eq_right hc,add_zero] at ha apply hn exact ⟨mem_insert_of_mem hi.1.1,ha β–Έ hi.1.2⟩ have hp := hi.2.trans (radius_range hr _).2 have htri := dist_triangle p (center i) (center t) rw [dist_comm p (center i)] at htri linarith /-- A fresh appended ball covers every point within r, pathwise even on zero-probability lifetime tape outcomes. -/ lemma inserted_covers (center : β„• β†’ Y) (I : Finset β„•) {r : ℝ} (hr : 0<r) (hK : 0<K) (t : Fin H) (hI : βˆ€ i∈I, i<t) (life : Fin H β†’ Lifetime K) (rad : Fin H β†’ Outcome Y r) (p : Y) (hp : dist (center t) p≀r) : covered center (insert (t:β„•) I) r life rad p t := by refine ⟨⟨mem_insert_self _ _,?_⟩,hp.trans (radius_range hr _).1⟩ rw [age_new center I (20*r) hI] exact alive_certain hK _ def indicator (P : Prop) : ℝ := if P then 1 else 0 lemma indicator_nonneg (P : Prop) : 0 ≀ indicator P := by unfold indicator; split_ifs <;> norm_num at * lemma indicator_le_one (P : Prop) : indicator P≀1 := by unfold indicator; split_ifs <;> norm_num at * /-- Literal stationary noncoverage table. -/ theorem stationary_table (center : β„• β†’ Y) (I : Finset β„•) (r : ℝ) (t : β„•) (hI : βˆ€ i∈I, i<t) (life : Fin H β†’ Lifetime K) (rad : Fin H β†’ Outcome Y r) (p : Y) : indicator (first center I r life rad pβ‰ first center (insert t I) r life rad p)+ indicator (first center (insert t I) r life rad p=none)- indicator (first center I r life rad p=none) ≀ 2*indicator (retired center I (insert t I) r life rad p) := by cases ho : first center I r life rad p with | none => cases hn : first center (insert t I) r life rad p with | none => simp only [indicator]; split_ifs <;> norm_num at * | some j => simp only [indicator]; split_ifs <;> norm_num at * | some i => by_cases hr : retired center I (insert t I) r life rad p Β· rw [show indicator (retired center I (insert t I) r life rad p)=1 from ite_eq_left hr] cases hn : first center (insert t I) r life rad p with | none => unfold indicator; split_ifs <;> norm_num at * | some j => simp only [indicator]; split_ifs <;> norm_num at * Β· have hp : present center (insert t I) r life i := by by_contra hp; exact hr ⟨i,ho,hp⟩ have hn := first_persists center I r t hI life rad p i ho hp simp [hn,indicator,hr] /-- Mover row, using final guaranteed coverage instead of a stationary final position. Its retirement coefficient is one instead of two. -/ theorem mover_table (center : β„• β†’ Y) (I : Finset β„•) {r : ℝ} (hr : 0<r) (hK : 0<K) (t : Fin H) (hI : βˆ€ i∈I, i<t) (life : Fin H β†’ Lifetime K) (rad : Fin H β†’ Outcome Y r) (p : Y) : indicator (first center I r life rad pβ‰ first center (insert (t:β„•) I) r life rad p)+ indicator (first center (insert (t:β„•) I) r life rad (center t)=none)- indicator (first center I r life rad p=none) ≀ indicator (retired center I (insert (t:β„•) I) r life rad p) := by have hc := inserted_covers center I hr hK t hI life rad (center t) (by simpa using hr.le) have hn : first center (insert (t:β„•) I) r life rad (center t)β‰ none := fun h=>(first_none_iff _ _ _ _ _ _).mp h t hc rw [show indicator (first center (insert (t:β„•) I) r life rad (center t)=none)=0 from ite_eq_right hn,add_zero] cases ho : first center I r life rad p with | none => unfold indicator split_ifs <;> norm_num at * | some i => by_cases he : retired center I (insert (t:β„•) I) r life rad p Β· rw [show indicator (retired center I (insert (t:β„•) I) r life rad p)=1 from ite_eq_left he] unfold indicator split_ifs <;> norm_num at * Β· have hp : present center (insert (t:β„•) I) r life i := by by_contra hp; exact he ⟨i,ho,hp⟩ have hnew := first_persists center I r t hI life rad p i ho hp simp [hnew,indicator,he] end KServer.ActualRoster end /-! One-structure edits of the actual priority map. These lemmas keep earlier structures fixed; in particular a covered heavy key suppresses all tier edits. -/ noncomputable section open scoped BigOperators open Finset namespace KServer.PriorityKeys attribute [local instance] Classical.propDecidable Classical.decEq variable {I Y:Type*} [Fintype I] [LinearOrder I] {A:Iβ†’Type*} lemma selected_congr_point (qβ‚€ q₁:(i:I)β†’Yβ†’Option (A i)) (x:Y) (h:βˆ€ i,qβ‚€ i x=q₁ i x) : selected qβ‚€ x=selected q₁ x := by let uβ‚€:(i:I)β†’Unitβ†’Option (A i):=fun i _=>qβ‚€ i x let u₁:(i:I)β†’Unitβ†’Option (A i):=fun i _=>q₁ i x have hu:uβ‚€=u₁:=funext fun i=>funext fun _=>h i change selected uβ‚€ ()=selected u₁ () rw [hu] lemma key_congr_point (qβ‚€ q₁:(i:I)β†’Yβ†’Option (A i)) (x:Y) (h:βˆ€ i,qβ‚€ i x=q₁ i x) : key qβ‚€ x=key q₁ x := by simp only [key,selected_congr_point qβ‚€ q₁ x h] lemma key_ne_single (qβ‚€ q₁:(i:I)β†’Yβ†’Option (A i)) (x:Y) (j:I) (h:βˆ€ i,iβ‰ jβ†’qβ‚€ i x=q₁ i x) (hn:key qβ‚€ xβ‰ key q₁ x) : qβ‚€ j xβ‰ q₁ j x := by intro he apply hn apply key_congr_point intro i by_cases hi:i=j Β· subst i; exact he Β· exact h i hi lemma single_indicator (qβ‚€ q₁:(i:I)β†’Yβ†’Option (A i)) (x:Y) (j:I) (h:βˆ€ i,iβ‰ jβ†’qβ‚€ i x=q₁ i x) : ActualRoster.indicator (key qβ‚€ xβ‰ key q₁ x) ≀ ActualRoster.indicator (qβ‚€ j xβ‰ q₁ j x) := by unfold ActualRoster.indicator split_ifs with hn hj hj <;> try norm_num exact False.elim (hj (key_ne_single qβ‚€ q₁ x j h hn)) /-- Before and after the elementary edit at structure j. -/ def stageBefore (qβ‚€ q₁:(i:I)β†’Yβ†’Option (A i)) (j:I) : (i:I)β†’Yβ†’Option (A i) := fun i=>if i<j then q₁ i else qβ‚€ i def stageAfter (qβ‚€ q₁:(i:I)β†’Yβ†’Option (A i)) (j:I) : (i:I)β†’Yβ†’Option (A i) := fun i=>if i≀j then q₁ i else qβ‚€ i omit [Fintype I] in lemma stage_at (qβ‚€ q₁:(i:I)β†’Yβ†’Option (A i)) (j:I) : stageBefore qβ‚€ q₁ j j=qβ‚€ j ∧ stageAfter qβ‚€ q₁ j j=q₁ j := by simp [stageBefore,stageAfter] omit [Fintype I] in lemma stage_outside (qβ‚€ q₁:(i:I)β†’Yβ†’Option (A i)) (j i:I) (hi:iβ‰ j) : stageBefore qβ‚€ q₁ j i=stageAfter qβ‚€ q₁ j i := by simp only [stageBefore,stageAfter,le_iff_lt_or_eq,hi,or_false] lemma stage_charge (qβ‚€ q₁:(i:I)β†’Yβ†’Option (A i)) (j:I) (x:Y) : ActualRoster.indicator (key (stageBefore qβ‚€ q₁ j) xβ‰ key (stageAfter qβ‚€ q₁ j) x) ≀ ActualRoster.indicator (qβ‚€ j xβ‰ q₁ j x) := by have h:=single_indicator (stageBefore qβ‚€ q₁ j) (stageAfter qβ‚€ q₁ j) x j (fun i hi=>congrFun (stage_outside qβ‚€ q₁ j i hi) x) simpa only [(stage_at qβ‚€ q₁ j).1,(stage_at qβ‚€ q₁ j).2] using h variable [OrderBot I] lemma selected_bot (q:(i:I)β†’Yβ†’Option (A i)) (x:Y) (a:A βŠ₯) (ha:q βŠ₯ x=some a) : selected q x=some ⟨βŠ₯,a⟩ := by have hc:(covered q x).Nonempty:=⟨βŠ₯,mem_filter.mpr ⟨mem_univ _,by rw [ha]; exact Option.some_ne_none _⟩⟩ have he:(covered q x).min' hc=βŠ₯:=bot_unique (min'_le (covered q x) βŠ₯ (mem_filter.mpr ⟨mem_univ _,by rw [ha]; exact Option.some_ne_none _⟩)) unfold selected rw [dite_eq_left hc] change (q ((covered q x).min' hc) x).map (fun b=>(⟨(covered q x).min' hc,b⟩:Sigma A))=some ⟨βŠ₯,a⟩ rw [he,ha] rfl lemma key_bot (q:(i:I)β†’Yβ†’Option (A i)) (x:Y) (a:A βŠ₯) (ha:q βŠ₯ x=some a) : key q x=Sum.inl ⟨βŠ₯,a⟩ := by simp only [key,selected_bot q x a ha] lemma bot_shadow (qβ‚€ q₁:(i:I)β†’Yβ†’Option (A i)) (x:Y) (a:A βŠ₯) (hβ‚€:qβ‚€ βŠ₯ x=some a) (h₁:q₁ βŠ₯ x=some a) : key qβ‚€ x=key q₁ x := (key_bot qβ‚€ x a hβ‚€).trans (key_bot q₁ x a h₁).symm lemma stage_shadow (qβ‚€ q₁:(i:I)β†’Yβ†’Option (A i)) {j:I} (hj:βŠ₯<j) (x:Y) (a:A βŠ₯) (ha:q₁ βŠ₯ x=some a) : key (stageBefore qβ‚€ q₁ j) x=key (stageAfter qβ‚€ q₁ j) x := by apply bot_shadow _ _ x a Β· simpa only [stageBefore,ite_eq_left hj] using ha Β· simpa only [stageAfter,ite_eq_left hj.le] using ha end KServer.PriorityKeys end /-! Literal finite-label tier edit tables. The old/new difference is bounded through permanent chronological labels; no resampling or independence is assumed at an observed surviving roster. -/ noncomputable section open scoped BigOperators open Finset namespace KServer.TierEdits open ActualRoster Chronological attribute [local instance] Classical.propDecidable Classical.decEq lemma indicator_mono {P Q:Prop} (h:Pβ†’Q) : indicator P≀ indicator Q := by unfold indicator split_ifs with hP hQ hQ <;> try norm_num exact False.elim (hQ (h hP)) lemma map_charge {A B:Type*} (f:Aβ†’B) (a b:Option A) : indicator (a.map fβ‰ b.map f)≀ indicator (aβ‰ b) := indicator_mono (fun hn he=>hn (congrArg (Option.map f) he)) lemma map_none {A B:Type*} (f:Aβ†’B) (a:Option A) : indicator (a.map f=none)=indicator (a=none) := by cases a <;> simp [indicator] variable {Y:Type*} [MetricSpace Y] [Fintype Y] {H K:β„•} lemma key_none (center:β„•β†’Y) {r:ℝ} (hr:0≀r) (q:β„•β†’Prop) (life:Fin Hβ†’Lifetime K) (rad:Fin Hβ†’FiniteBallLaw.Outcome Y r) (t:β„•) (p:Y) : indicator (TierKeys.key center hr K q life rad t p=none)= indicator (first center (schedule center r K q t) r life rad p=none) := map_none _ _ lemma key_change (center:β„•β†’Y) {r:ℝ} (hr:0≀r) (q:β„•β†’Prop) (life:Fin Hβ†’Lifetime K) (rad:Fin Hβ†’FiniteBallLaw.Outcome Y r) (t:β„•) (p:Y) : indicator (TierKeys.key center hr K q life rad t pβ‰ TierKeys.key center hr K q life rad (t+1) p)≀ indicator (first center (schedule center r K q t) r life rad pβ‰  first center (schedule center r K q (t+1)) r life rad p) := map_charge _ _ _ lemma stationary (center:β„•β†’Y) {r:ℝ} (hr:0≀r) (q:β„•β†’Prop) (life:Fin Hβ†’Lifetime K) (rad:Fin Hβ†’FiniteBallLaw.Outcome Y r) (t:β„•) (p:Y) (hin:insertTest center (schedule center r K q t) r K t (q t)) : indicator (TierKeys.key center hr K q life rad t pβ‰ TierKeys.key center hr K q life rad (t+1) p)+ indicator (TierKeys.key center hr K q life rad (t+1) p=none)- indicator (TierKeys.key center hr K q life rad t p=none) ≀ 2*indicator (retired center (schedule center r K q t) (schedule center r K q (t+1)) r life rad p) := by have ht:=stationary_table center (schedule center r K q t) r t (schedule_before _ _ _ _ _) life rad p have hnew:schedule center r K q (t+1)=insert t (schedule center r K q t):=by simp only [schedule,ite_eq_left hin] have hc:=key_change center hr q life rad t p rw [key_none,key_none,hnew] rw [hnew] at hc linarith lemma mover (center:β„•β†’Y) {r:ℝ} (hr:0<r) (hK:0<K) (q:β„•β†’Prop) (life:Fin Hβ†’Lifetime K) (rad:Fin Hβ†’FiniteBallLaw.Outcome Y r) (t:Fin H) (p:Y) (hin:insertTest center (schedule center r K q t) r K t (q t)) : indicator (TierKeys.key center hr.le K q life rad t pβ‰ TierKeys.key center hr.le K q life rad (t.val+1) p)+ indicator (TierKeys.key center hr.le K q life rad (t.val+1) (center t)=none)- indicator (TierKeys.key center hr.le K q life rad t p=none) ≀ indicator (retired center (schedule center r K q t) (schedule center r K q (t.val+1)) r life rad p) := by have ht:=mover_table center (schedule center r K q t) hr hK t (schedule_before _ _ _ _ _) life rad p have hnew:schedule center r K q (t.val+1)=insert (t:β„•) (schedule center r K q t):=by simp only [schedule,ite_eq_left hin] have hc:=key_change center hr.le q life rad t p rw [key_none,key_none,hnew] rw [hnew] at hc linarith lemma no_insert (center:β„•β†’Y) {r:ℝ} (hr:0≀r) (q:β„•β†’Prop) (life:Fin Hβ†’Lifetime K) (rad:Fin Hβ†’FiniteBallLaw.Outcome Y r) (t:β„•) (hin:Β¬insertTest center (schedule center r K q t) r K t (q t)) : TierKeys.key center hr K q life rad (t+1)=TierKeys.key center hr K q life rad t := by funext p simp only [TierKeys.key,schedule,ite_eq_right hin] lemma covered_inner (center:β„•β†’Y) {r:ℝ} (hr:0<r) (hK:0<K) (q:β„•β†’Prop) (life:Fin Hβ†’Lifetime K) (rad:Fin Hβ†’FiniteBallLaw.Outcome Y r) (t:Fin H) (hin:insertTest center (schedule center r K q t) r K t (q t)) (p:Y) (hp:dist (center t) p≀r) : indicator (TierKeys.key center hr.le K q life rad (t.val+1) p=none)=0 := by rw [key_none] have hnew:schedule center r K q (t.val+1)=insert (t:β„•) (schedule center r K q t):=by simp only [schedule,ite_eq_left hin] rw [hnew] apply ite_eq_right intro hh exact (first_none_iff _ _ _ _ _ _).mp hh t (inserted_covers center _ hr hK t (schedule_before _ _ _ _ _) life rad p hp) end KServer.TierEdits end /-! The literal chronological tier edits inside a complete level, including heavy-priority shadowing. Noncoverage deliberately ignores earlier structures. -/ noncomputable section open scoped BigOperators open Finset namespace KServer.LevelTierEdits open LevelKeys LevelCoverage LevelLaw FiniteExperiment TierProcess Pilot open ActualRoster Chronological attribute [local instance] Classical.propDecidable Classical.decEq local instance (priority := 2000) finDecEq (n:β„•) : DecidableEq (Fin n) := Classical.decEq _ variable {Y:Type*} [MetricSpace Y] [Fintype Y] {k H:β„•} [NeZero k] def charge (s:Configuration k Y) (law:RequestLaw Y H) {r:ℝ} (hr:0 ≀ r) (Οƒ:Fin Hβ†’Y) (a:Tape Y k H r) (t:β„•) (i:Tier k) (p:Y) : ℝ := indicator (PriorityKeys.key (PriorityKeys.stageBefore (keys s law hr Οƒ a t) (keys s law hr Οƒ a (t+1)) (i:Structure k)) p β‰  PriorityKeys.key (PriorityKeys.stageAfter (keys s law hr Οƒ a t) (keys s law hr Οƒ a (t+1)) (i:Structure k)) p) def uncovered (s:Configuration k Y) (law:RequestLaw Y H) {r:ℝ} (hr:0 ≀ r) (Οƒ:Fin Hβ†’Y) (a:Tape Y k H r) (t:β„•) (i:Tier k) (p:Y) : ℝ := indicator (keys s law hr Οƒ a t (i:Structure k) p=none) def inserted (s:Configuration k Y) (law:RequestLaw Y H) (r:ℝ) (Οƒ:Fin Hβ†’Y) (t:β„•) (i:Tier k) : Prop := insertTest (request s Οƒ) (schedule (request s Οƒ) r (tierK (height i)) (tierQualifies s law r Οƒ i) t) r (tierK (height i)) t (tierQualifies s law r Οƒ i t) def retirement (s:Configuration k Y) (law:RequestLaw Y H) (r:ℝ) (Οƒ:Fin Hβ†’Y) (a:Tape Y k H r) (t:β„•) (i:Tier k) (p:Y) : Prop := retired (request s Οƒ) (schedule (request s Οƒ) r (tierK (height i)) (tierQualifies s law r Οƒ i) t) (schedule (request s Οƒ) r (tierK (height i)) (tierQualifies s law r Οƒ i) (t+1)) r (a.2 i).1 (a.2 i).2 p lemma charge_nonneg (s:Configuration k Y) (law:RequestLaw Y H) {r:ℝ} (hr:0 ≀ r) (Οƒ:Fin Hβ†’Y) (a:Tape Y k H r) (t:β„•) (i:Tier k) (p:Y) : 0 ≀ charge s law hr Οƒ a t i p := indicator_nonneg _ lemma charge_le (s:Configuration k Y) (law:RequestLaw Y H) {r:ℝ} (hr:0 ≀ r) (Οƒ:Fin Hβ†’Y) (a:Tape Y k H r) (t:β„•) (i:Tier k) (p:Y) : charge s law hr Οƒ a t i p ≀ indicator (keys s law hr Οƒ a t (i:Structure k) pβ‰  keys s law hr Οƒ a (t+1) (i:Structure k) p) := PriorityKeys.stage_charge _ _ _ _ lemma stationary (s:Configuration k Y) (law:RequestLaw Y H) {r:ℝ} (hr:0 ≀ r) (Οƒ:Fin Hβ†’Y) (a:Tape Y k H r) (t:β„•) (i:Tier k) (p:Y) (hin:inserted s law r Οƒ t i) : charge s law hr Οƒ a t i p+uncovered s law hr Οƒ a (t+1) i p- uncovered s law hr Οƒ a t i p ≀ 2*indicator (retirement s law r Οƒ a t i p) := by have ht:=TierEdits.stationary (request s Οƒ) hr (tierQualifies s law r Οƒ i) (a.2 i).1 (a.2 i).2 t p hin have hc:=charge_le s law hr Οƒ a t i p dsimp only [uncovered,retirement,keys] at hc ⊒ linarith lemma mover (s:Configuration k Y) (law:RequestLaw Y H) {r:ℝ} (hr:0 < r) (Οƒ:Fin Hβ†’Y) (a:Tape Y k H r) (t:Fin H) (i:Tier k) (p:Y) (hin:inserted s law r Οƒ t i) : charge s law hr.le Οƒ a t i p+uncovered s law hr.le Οƒ a (t.val+1) i (Οƒ t)- uncovered s law hr.le Οƒ a t i p ≀ indicator (retirement s law r Οƒ a t i p) := by have ht:=TierEdits.mover (request s Οƒ) hr (by have hh:=tierK_ge_two (height_ge i); omega) (tierQualifies s law r Οƒ i) (a.2 i).1 (a.2 i).2 t p hin rw [request_fin] at ht have hc:=charge_le s law hr.le Οƒ a t i p dsimp only [uncovered,retirement,keys] at hc ⊒ linarith lemma no_insert_charge (s:Configuration k Y) (law:RequestLaw Y H) {r:ℝ} (hr:0 ≀ r) (Οƒ:Fin Hβ†’Y) (a:Tape Y k H r) (t:β„•) (i:Tier k) (p:Y) (hin:Β¬inserted s law r Οƒ t i) : charge s law hr Οƒ a t i p=0 := by apply le_antisymm _ (charge_nonneg s law hr Οƒ a t i p) have hc:=charge_le s law hr Οƒ a t i p have he:=congrFun (TierEdits.no_insert (request s Οƒ) hr (tierQualifies s law r Οƒ i) (a.2 i).1 (a.2 i).2 t hin) p change keys s law hr Οƒ a (t+1) (i:Structure k) p=keys s law hr Οƒ a t (i:Structure k) p at he simpa only [he,ne_self_iff_false,indicator,ite_false] using hc lemma no_insert_stationary (s:Configuration k Y) (law:RequestLaw Y H) {r:ℝ} (hr:0 ≀ r) (Οƒ:Fin Hβ†’Y) (a:Tape Y k H r) (t:β„•) (i:Tier k) (p:Y) (hin:Β¬inserted s law r Οƒ t i) : charge s law hr Οƒ a t i p+uncovered s law hr Οƒ a (t+1) i p- uncovered s law hr Οƒ a t i p=0 := by rw [no_insert_charge s law hr Οƒ a t i p hin,zero_add] have he:=congrFun (TierEdits.no_insert (request s Οƒ) hr (tierQualifies s law r Οƒ i) (a.2 i).1 (a.2 i).2 t hin) p change keys s law hr Οƒ a (t+1) (i:Structure k) p=keys s law hr Οƒ a t (i:Structure k) p at he change indicator (_=none)-indicator (_=none)=0 rw [he,sub_self] lemma covered_qualified (s:Configuration k Y) (law:RequestLaw Y H) {r:ℝ} (hr:0 < r) (Οƒ:Fin Hβ†’Y) (a:Tape Y k H r) (t:Fin H) (i:Tier k) (hq:tierQualifies s law r Οƒ i t) : uncovered s law hr.le Οƒ a (t.val+1) i (Οƒ t)=0 := by obtain ⟨b,hb⟩:=TierKeys.guaranteed_coverage (request s Οƒ) hr (by have hh:=tierK_ge_two (height_ge i); omega) (tierQualifies s law r Οƒ i) t t.isLt hq (a.2 i).1 (a.2 i).2 rw [request_fin] at hb change keys s law hr.le Οƒ a (t.val+1) (i:Structure k) (Οƒ t)=some b at hb change indicator (_=none)=0 rw [hb] exact ite_eq_right (Option.some_ne_none _) lemma no_insert_mover (s:Configuration k Y) (law:RequestLaw Y H) {r:ℝ} (hr:0 < r) (Οƒ:Fin Hβ†’Y) (a:Tape Y k H r) (t:Fin H) (i:Tier k) (p:Y) (hin:Β¬inserted s law r Οƒ t i) : charge s law hr.le Οƒ a t i p+uncovered s law hr.le Οƒ a (t.val+1) i (Οƒ t)- uncovered s law hr.le Οƒ a t i p ≀ if tierQualifies s law r Οƒ i t then 0 else indicator (keys s law hr.le Οƒ a (t.val+1) (i:Structure k) (Οƒ t)β‰  keys s law hr.le Οƒ a (t.val+1) (i:Structure k) p) := by rw [no_insert_charge s law hr.le Οƒ a t i p hin,zero_add] by_cases hq:tierQualifies s law r Οƒ i t Β· rw [ite_eq_left hq,covered_qualified s law hr Οƒ a t i hq] exact sub_nonpos.mpr (indicator_nonneg _) Β· rw [ite_eq_right hq] have he:=congrFun (TierEdits.no_insert (request s Οƒ) hr.le (tierQualifies s law r Οƒ i) (a.2 i).1 (a.2 i).2 t hin) p change keys s law hr.le Οƒ a (t.val+1) (i:Structure k) p=keys s law hr.le Οƒ a t (i:Structure k) p at he unfold uncovered rw [←he] unfold indicator split_ifs with hx hp hn hp hn hn <;> try norm_num all_goals simp_all lemma heavy_inner_covers (s:Configuration k Y) (law:RequestLaw Y H) {r:ℝ} (hr:0 < r) (Οƒ:Fin Hβ†’Y) (a:Tape Y k H r) (t:Fin H) (p:Y) (hh:mass (mu s law (t.val+1) Οƒ) (Pilot.ball (Οƒ t) (51200*r)) ≀ (1+heavyDelta)*mass (mu s law (t.val+1) Οƒ) (Pilot.ball (Οƒ t) (heavyGamma*r))) (hp:dist (Οƒ t) p ≀ heavyGamma*r) : βˆƒ b,keys s law hr.le Οƒ a (t.val+1) (βŠ₯:Structure k) p=some b := by obtain ⟨c,hc,hd⟩:=heavy_near_center s law Οƒ t hr.le hh have hv:=HeavySchedule.run_valid s law hr heavyGamma heavyDelta Οƒ a.1 (t.val+1) have hC:=HeavyCenters.centers_separated s law r heavyGamma heavyDelta Οƒ (t.val+1) have hcp:dist c p ≀ (HeavySchedule.run s law r heavyGamma heavyDelta Οƒ a.1 (t.val+1)).rad c:=by have hΞ³:heavyGamma ≀ 1:=by norm_num [heavyGamma] have hm:=mul_le_mul_of_nonneg_right hΞ³ hr.le linarith [dist_triangle c (Οƒ t) p,(hv.1 c hc).1] have he:=(HeavyKeys.centerKey_some hr hC (fun b hb=>(hv.1 b hb).2)).mpr ⟨hc,hcp⟩ refine ⟨(HeavySchedule.run s law r heavyGamma heavyDelta Οƒ a.1 (t.val+1)).label c,?_⟩ change HeavyKeys.key _ _ _ _ _ _ _ _ _=some _ simp only [HeavyKeys.key,he,Option.map_some] lemma heavy_inner_charge (s:Configuration k Y) (law:RequestLaw Y H) {r:ℝ} (hr:0 < r) (Οƒ:Fin Hβ†’Y) (a:Tape Y k H r) (t:Fin H) (i:Tier k) (p:Y) (hh:mass (mu s law (t.val+1) Οƒ) (Pilot.ball (Οƒ t) (51200*r)) ≀ (1+heavyDelta)*mass (mu s law (t.val+1) Οƒ) (Pilot.ball (Οƒ t) (heavyGamma*r))) (hp:dist (Οƒ t) p ≀ heavyGamma*r) : charge s law hr.le Οƒ a t i p=0 := by obtain ⟨b,hb⟩:=heavy_inner_covers s law hr Οƒ a t p hh hp have he:=PriorityKeys.stage_shadow (I:=Structure k) (keys s law hr.le Οƒ a t) (keys s law hr.le Οƒ a (t.val+1)) (j:=(i:Structure k)) (WithBot.bot_lt_coe i) p b hb exact ite_eq_right (not_not.mpr he) lemma heavy_inner_stationary (s:Configuration k Y) (law:RequestLaw Y H) {r:ℝ} (hr:0 < r) (Οƒ:Fin Hβ†’Y) (a:Tape Y k H r) (t:Fin H) (i:Tier k) (p:Y) (hin:inserted s law r Οƒ t i) (hh:mass (mu s law (t.val+1) Οƒ) (Pilot.ball (Οƒ t) (51200*r)) ≀ (1+heavyDelta)*mass (mu s law (t.val+1) Οƒ) (Pilot.ball (Οƒ t) (heavyGamma*r))) (hp:dist (Οƒ t) p ≀ heavyGamma*r) : charge s law hr.le Οƒ a t i p+uncovered s law hr.le Οƒ a (t.val+1) i p- uncovered s law hr.le Οƒ a t i p ≀ 0 := by rw [heavy_inner_charge s law hr Οƒ a t i p hh hp,zero_add] have hcov:=TierEdits.covered_inner (request s Οƒ) hr (by have hh:=tierK_ge_two (height_ge i); omega) (tierQualifies s law r Οƒ i) (a.2 i).1 (a.2 i).2 t hin p (by rw [request_fin]; exact hp.trans (mul_le_of_le_one_left hr.le (by norm_num [heavyGamma]))) change uncovered s law hr.le Οƒ a (t.val+1) i p=0 at hcov rw [hcov] exact sub_nonpos.mpr (indicator_nonneg _) end KServer.LevelTierEdits end /-! Average actual tier retirements over the full finite partition tape, not conditionally on surviving entries. -/ noncomputable section open scoped BigOperators open Finset namespace KServer.LevelRetirement open LevelKeys LevelCoverage LevelLaw LevelTierEdits FiniteExperiment TierProcess Pilot open ActualRoster Chronological FiniteTape PartitionProbabilities attribute [local instance] Classical.propDecidable Classical.decEq local instance (priority := 2000) finDecEq (n:β„•) : DecidableEq (Fin n) := Classical.decEq _ variable {Y:Type*} [MetricSpace Y] [Fintype Y] {k H:β„•} lemma tier_lifetime_bound {r:ℝ} (hr:0 < r) (i:Tier k) (E:(Fin Hβ†’Lifetime (tierK (height i)))β†’(Fin Hβ†’FiniteBallLaw.Outcome Y r)β†’Prop) (c:ℝ) (hc:βˆ€ rad,probability (fun _ : Fin H=>lifetimeLaw (tierK (height i))) (fun life=>E life rad)≀c) : (βˆ‘ a:Tape Y k H r,if E (a.2 i).1 (a.2 i).2 then weight r a else 0)≀c := by have he:=tier_event (H:=H) hr i (fun b=>E b.1 b.2) have heq : (βˆ‘ a:Tape Y k H r,if E (a.2 i).1 (a.2 i).2 then weight r a else 0)= βˆ‘ b:(Fin Hβ†’Lifetime (tierK (height i))) Γ— (Fin Hβ†’FiniteBallLaw.Outcome Y r), if E b.1 b.2 then tierWeight r i b else 0 := by refine Eq.trans ?_ (he.trans ?_) <;> apply sum_congr rfl <;> intro a _ <;> split_ifs <;> rfl rw [heq] simp only [Fintype.sum_prod_type,tierWeight,pair] rw [sum_comm] calc (βˆ‘ rad,βˆ‘ life,if E life rad then lifetimeWeight i life*radiusWeight r i rad else 0)= βˆ‘ rad,radiusWeight r i rad*(βˆ‘ life,if E life rad then lifetimeWeight i life else 0) := by apply sum_congr rfl intro rad _ rw [mul_sum] apply sum_congr rfl intro life _ split_ifs <;> ring _ ≀ βˆ‘ rad,radiusWeight r i rad*c := by apply sum_le_sum intro rad _ apply mul_le_mul_of_nonneg_left _ (radius_nonneg hr i rad) exact hc rad _ = c := by rw [←sum_mul,radius_sum hr i,one_mul] variable [NeZero k] lemma retirement_bound (s:Configuration k Y) (law:RequestLaw Y H) {r:ℝ} (hr:0 < r) (Οƒ:Fin Hβ†’Y) (t:β„•) (i:Tier k) (p:Y) (hin:inserted s law r Οƒ t i) : (βˆ‘ a:Tape Y k H r,if retirement s law r Οƒ a t i p then weight r a else 0) ≀ 49/(tierK (height i):ℝ) := by have hnew:schedule (request s Οƒ) r (tierK (height i)) (tierQualifies s law r Οƒ i) (t+1)= insert t (schedule (request s Οƒ) r (tierK (height i)) (tierQualifies s law r Οƒ i) t):=by change insertTest _ _ _ _ _ _ at hin simp only [schedule,ite_eq_left hin] unfold retirement rw [hnew] refine tier_lifetime_bound hr i (fun life rad => retired (request s Οƒ) (schedule (request s Οƒ) r (tierK (height i)) (tierQualifies s law r Οƒ i) t) (insert t (schedule (request s Οƒ) r (tierK (height i)) (tierQualifies s law r Οƒ i) t)) r life rad p) _ ?_ intro rad exact insertion_retirement (request s Οƒ) _ hr (tierK_ge_two (height_ge i)) t rad p lemma retirement_far (s:Configuration k Y) (law:RequestLaw Y H) {r:ℝ} (hr:0 < r) (Οƒ:Fin Hβ†’Y) (a:Tape Y k H r) (t:Fin H) (i:Tier k) (p:Y) (hin:inserted s law r Οƒ t i) (hp:22*r < dist (Οƒ t) p) : Β¬retirement s law r Οƒ a t i p := by intro he have hnew:schedule (request s Οƒ) r (tierK (height i)) (tierQualifies s law r Οƒ i) (t.val+1)= insert (t:β„•) (schedule (request s Οƒ) r (tierK (height i)) (tierQualifies s law r Οƒ i) t):=by change insertTest _ _ _ _ _ _ at hin simp only [schedule,ite_eq_left hin] unfold retirement at he rw [hnew] at he have hn:=retired_near (request s Οƒ) _ hr t (schedule_before _ _ _ _ _) (a.2 i).1 (a.2 i).2 p he rw [request_fin,dist_comm] at hn exact not_lt_of_ge hn hp def mean (r:ℝ) (f:Tape Y k H r→ℝ) : ℝ := βˆ‘ a,weight r a*f a omit [NeZero k] in lemma mean_mono {r:ℝ} (hr:0<r) {f g:Tape Y k H r→ℝ} (h:βˆ€ a,f a≀g a) : mean r f ≀ mean r g := sum_le_sum (fun a _=>mul_le_mul_of_nonneg_left (h a) (weight_nonneg hr a)) omit [NeZero k] in lemma mean_const {r:ℝ} (hr:0<r) (c:ℝ) : mean (Y:=Y) (k:=k) (H:=H) r (fun _=>c)=c := by unfold mean rw [←sum_mul,weight_sum hr,one_mul] omit [NeZero k] in lemma mean_indicator (r:ℝ) (E:Tape Y k H rβ†’Prop) : mean r (fun a=>indicator (E a))=βˆ‘ a,if E a then weight r a else 0 := by unfold mean apply sum_congr rfl intro a _ by_cases h:E a Β· simp only [indicator,ite_eq_left h,mul_one] Β· simp only [indicator,ite_eq_right h,mul_zero] omit [NeZero k] in lemma mean_scale (r:ℝ) (c:ℝ) (f:Tape Y k H r→ℝ) : mean r (fun a=>c*f a)=c*mean r f := by unfold mean rw [mul_sum] apply sum_congr rfl intro a _ ring lemma stationary_mean (s:Configuration k Y) (law:RequestLaw Y H) {r:ℝ} (hr:0 < r) (Οƒ:Fin Hβ†’Y) (t:Fin H) (i:Tier k) (p:Y) (hin:inserted s law r Οƒ t i) : mean r (fun a=>LevelTierEdits.charge s law hr.le Οƒ a t i p+ uncovered s law hr.le Οƒ a (t.val+1) i p-uncovered s law hr.le Οƒ a t i p) ≀ if dist (Οƒ t) p≀22*r ∧ Β¬(mass (mu s law (t.val+1) Οƒ) (Pilot.ball (Οƒ t) (51200*r)) ≀ (1+heavyDelta)*mass (mu s law (t.val+1) Οƒ) (Pilot.ball (Οƒ t) (heavyGamma*r)) ∧ dist (Οƒ t) p≀heavyGamma*r) then 98/(tierK (height i):ℝ) else 0 := by by_cases hp:dist (Οƒ t) p≀22*r Β· by_cases hh:mass (mu s law (t.val+1) Οƒ) (Pilot.ball (Οƒ t) (51200*r)) ≀ (1+heavyDelta)*mass (mu s law (t.val+1) Οƒ) (Pilot.ball (Οƒ t) (heavyGamma*r)) ∧ dist (Οƒ t) p≀heavyGamma*r Β· rw [ite_eq_right (fun h=>h.2 hh)] exact (mean_mono hr (fun a=>heavy_inner_stationary s law hr Οƒ a t i p hin hh.1 hh.2)).trans_eq (mean_const hr 0) Β· rw [ite_eq_left ⟨hp,hh⟩] have hb:=mean_mono hr (fun a=>LevelTierEdits.stationary s law hr.le Οƒ a t i p hin) rw [mean_scale,mean_indicator] at hb have hc:=mul_le_mul_of_nonneg_left (retirement_bound s law hr Οƒ t i p hin) (by norm_num : (0:ℝ)≀2) exact hb.trans (by convert hc using 1; ring) Β· rw [ite_eq_right (fun h=>hp h.1)] have hb:=mean_mono hr (fun a=>LevelTierEdits.stationary s law hr.le Οƒ a t i p hin) have hz (a:Tape Y k H r):indicator (retirement s law r Οƒ a t i p)=0:= ite_eq_right (retirement_far s law hr Οƒ a t i p hin (lt_of_not_ge hp)) simp only [hz,mul_zero,mean_const hr] at hb exact hb lemma mover_mean (s:Configuration k Y) (law:RequestLaw Y H) {r:ℝ} (hr:0 < r) (Οƒ:Fin Hβ†’Y) (t:Fin H) (i:Tier k) (p:Y) (hin:inserted s law r Οƒ t i) : mean r (fun a=>LevelTierEdits.charge s law hr.le Οƒ a t i p+ uncovered s law hr.le Οƒ a (t.val+1) i (Οƒ t)-uncovered s law hr.le Οƒ a t i p) ≀ 49/(tierK (height i):ℝ) := by have hb:=mean_mono hr (fun a=>LevelTierEdits.mover s law hr Οƒ a t i p hin) rw [mean_indicator] at hb exact hb.trans (retirement_bound s law hr Οƒ t i p hin) end KServer.LevelRetirement end /-! Exact scale-log sums for the true post-request metric posterior. The same absolute shift works for the heavy test and all dyadic tier tests. -/ noncomputable section open scoped BigOperators open Finset namespace KServer.LevelScale open FiniteExperiment Pilot LevelCoverage TierProcess attribute [local instance] Classical.propDecidable Classical.decEq variable {Y:Type*} [Fintype Y] [MetricSpace Y] lemma log_ball_bounds (ΞΌ:Y→ℝ) (hΞΌ:βˆ€ y,0 ≀ ΞΌ y) (x:Y) (hx:1 ≀ ΞΌ x) {k r:ℝ} (hk:βˆ‘ y,ΞΌ y=k) (hr:0 ≀ r) : Real.log (mass ΞΌ (ball x r)) ∈ Set.Icc 0 (Real.log k) := by have hl:1 ≀ mass ΞΌ (ball x r):=hx.trans (single_le_sum (fun y _=>hΞΌ y) (by simp only [ball,mem_filter,mem_univ,true_and,dist_self]; exact hr)) have hu:mass ΞΌ (ball x r) ≀ k:=by simpa only [hk] using ball_mass_total ΞΌ hΞΌ x r exact ⟨Real.log_nonneg hl,Real.log_le_log (by linarith) hu⟩ lemma mass_positive (ΞΌ:Y→ℝ) (hΞΌ:βˆ€ y,0 ≀ ΞΌ y) (x:Y) (hx:1 ≀ ΞΌ x) {r:ℝ} (hr:0 ≀ r) : 0 < mass ΞΌ (ball x r) := by have hl:1 ≀ mass ΞΌ (ball x r):=hx.trans (single_le_sum (fun y _=>hΞΌ y) (by simp only [ball,mem_filter,mem_univ,true_and,dist_self]; exact hr)) linarith lemma logratio_sum (ΞΌ:Y→ℝ) (hΞΌ:βˆ€ y,0 ≀ ΞΌ y) (x:Y) (hx:1 ≀ ΞΌ x) {k rβ‚€ Ο„ Ξ³ D:ℝ} (hk:βˆ‘ y,ΞΌ y=k) (hr:0 ≀ rβ‚€) (hΟ„:0 ≀ Ο„) (hΞ³:0 < Ξ³) (hΞ³D:Ξ³ ≀ D) (p n:β„•) (hp:D ≀ Ξ³*Ο„^p) : (βˆ‘ j∈range n,Real.log (mass ΞΌ (ball x (D*radius rβ‚€ Ο„ j))/ mass ΞΌ (ball x (Ξ³*radius rβ‚€ Ο„ j)))) ≀ p*Real.log k := by have hrad (j:β„•):0 ≀ radius rβ‚€ Ο„ j:=mul_nonneg hr (pow_nonneg hΟ„ _) have hm (j:β„•):0 < mass ΞΌ (ball x (Ξ³*radius rβ‚€ Ο„ j)):= mass_positive ΞΌ hΞΌ x hx (mul_nonneg hΞ³.le (hrad j)) have hM (j:β„•):0 < mass ΞΌ (ball x (D*radius rβ‚€ Ο„ j)):= mass_positive ΞΌ hΞΌ x hx (mul_nonneg (hΞ³.le.trans hΞ³D) (hrad j)) have hstep (j:β„•):mass ΞΌ (ball x (D*radius rβ‚€ Ο„ j)) ≀ mass ΞΌ (ball x (Ξ³*radius rβ‚€ Ο„ (j+p))):=by apply ball_mass_mono ΞΌ hΞΌ x rw [radius_add] nlinarith [mul_le_mul_of_nonneg_right hp (hrad j)] calc _ ≀ βˆ‘ j∈range n,(Real.log (mass ΞΌ (ball x (Ξ³*radius rβ‚€ Ο„ (j+p))))- Real.log (mass ΞΌ (ball x (Ξ³*radius rβ‚€ Ο„ j)))) := by apply sum_le_sum intro j _ rw [Real.log_div (hM j).ne' (hm j).ne'] exact sub_le_sub_right (Real.log_le_log (hM j) (hstep j)) _ _ ≀ _ := by simpa using ScaleMass.shifted_sum_le (fun j=>Real.log (mass ΞΌ (ball x (Ξ³*radius rβ‚€ Ο„ j)))) 0 (Real.log k) (fun j=>log_ball_bounds ΞΌ hΞΌ x hx hk (mul_nonneg hΞ³.le (hrad j))) n p lemma nonheavy_count (ΞΌ:Y→ℝ) (hΞΌ:βˆ€ y,0 ≀ ΞΌ y) (x:Y) (hx:1 ≀ ΞΌ x) {k rβ‚€ Ο„ Ξ³ D Ξ΄:ℝ} (hk:βˆ‘ y,ΞΌ y=k) (hr:0 ≀ rβ‚€) (hΟ„:0 ≀ Ο„) (hΞ³:0 < Ξ³) (hΞ³D:Ξ³ ≀ D) (hΞ΄:0 < Ξ΄) (p n:β„•) (hp:D ≀ Ξ³*Ο„^p) : (βˆ‘ j∈range n,if mass ΞΌ (ball x (D*radius rβ‚€ Ο„ j)) ≀ (1+Ξ΄)*mass ΞΌ (ball x (Ξ³*radius rβ‚€ Ο„ j)) then (0:ℝ) else 1) ≀ (p*Real.log k)/Real.log (1+Ξ΄) := by have hlog:0 < Real.log (1+Ξ΄):=Real.log_pos (by linarith) apply (le_div_iffβ‚€ hlog).mpr trans βˆ‘ j∈range n,Real.log (mass ΞΌ (ball x (D*radius rβ‚€ Ο„ j))/ mass ΞΌ (ball x (Ξ³*radius rβ‚€ Ο„ j))) Β· rw [sum_mul] apply sum_le_sum intro j _ have hrad:0 ≀ radius rβ‚€ Ο„ j:=mul_nonneg hr (pow_nonneg hΟ„ _) have hm:=mass_positive ΞΌ hΞΌ x hx (mul_nonneg hΞ³.le hrad) have hM:=mass_positive ΞΌ hΞΌ x hx (mul_nonneg (hΞ³.le.trans hΞ³D) hrad) have hab:=ball_mass_mono ΞΌ hΞΌ x (mul_le_mul_of_nonneg_right hΞ³D hrad) split_ifs with hh Β· rw [zero_mul] exact Real.log_nonneg ((le_div_iffβ‚€ hm).mpr (by simpa using hab)) Β· rw [one_mul] apply Real.log_le_log (by linarith : 0 < 1+Ξ΄) exact (le_div_iffβ‚€ hm).mpr (le_of_lt (lt_of_not_ge hh)) Β· exact logratio_sum ΞΌ hΞΌ x hx hk hr hΟ„ hΞ³ hΞ³D p n hp lemma tier_shift {Ο„:ℝ} (hΟ„:2 ≀ Ο„) : 100*tierTemplate.R ≀ tierGamma*Ο„^60 := by have hp:(2:ℝ)^60 ≀ Ο„^60:=pow_le_pow_leftβ‚€ (by norm_num) hΟ„ _ have hc:100*tierTemplate.R ≀ tierGamma*(2:ℝ)^60:=by norm_num [tierTemplate,tierGamma] exact hc.trans (mul_le_mul_of_nonneg_left hp (by norm_num [tierGamma])) lemma heavy_shift {Ο„:ℝ} (hΟ„:2 ≀ Ο„) : (51200:ℝ) ≀ heavyGamma*Ο„^60 := by have hp:(2:ℝ)^60 ≀ Ο„^60:=pow_le_pow_leftβ‚€ (by norm_num) hΟ„ _ have hc:(51200:ℝ) ≀ heavyGamma*(2:ℝ)^60:=by norm_num [heavyGamma] exact hc.trans (mul_le_mul_of_nonneg_left hp (by norm_num [heavyGamma])) variable {k H:β„•} [NeZero k] lemma actual_logratio_sum (s:Configuration k Y) (law:FiniteDistribution (Fin Hβ†’Y)) (Οƒ:Fin Hβ†’Y) (hΟƒ:0 < law.val Οƒ) (t:Fin H) {rβ‚€ Ο„:ℝ} (hr:0 ≀ rβ‚€) (hΟ„:2 ≀ Ο„) (n:β„•) : (βˆ‘ j∈range n, logratio s law Οƒ t (radius rβ‚€ Ο„ j)) ≀ 60*Real.log k := by exact logratio_sum (mu s law (t.val+1) Οƒ) (mu_nonneg s law (t.val+1) Οƒ) (Οƒ t) (mu_served s law t Οƒ hΟƒ) (mu_total s law (t.val+1) Οƒ hΟƒ) hr (by linarith) (by norm_num [tierGamma]) (by norm_num [tierGamma,tierTemplate]) 60 n (tier_shift hΟ„) lemma actual_nonheavy_count (s:Configuration k Y) (law:FiniteDistribution (Fin Hβ†’Y)) (Οƒ:Fin Hβ†’Y) (hΟƒ:0 < law.val Οƒ) (t:Fin H) {rβ‚€ Ο„:ℝ} (hr:0 ≀ rβ‚€) (hΟ„:2 ≀ Ο„) (n:β„•) : (βˆ‘ j∈range n,if mass (mu s law (t.val+1) Οƒ) (ball (Οƒ t) (51200*radius rβ‚€ Ο„ j)) ≀ (1+heavyDelta)*mass (mu s law (t.val+1) Οƒ) (ball (Οƒ t) (heavyGamma*radius rβ‚€ Ο„ j)) then (0:ℝ) else 1) ≀ (60*Real.log k)/Real.log (1+heavyDelta) := by exact nonheavy_count (mu s law (t.val+1) Οƒ) (mu_nonneg s law (t.val+1) Οƒ) (Οƒ t) (mu_served s law t Οƒ hΟƒ) (mu_total s law (t.val+1) Οƒ hΟƒ) hr (by linarith) (by norm_num [heavyGamma]) (by norm_num [heavyGamma]) (by norm_num [heavyDelta]) 60 n (heavy_shift hΟ„) end KServer.LevelScale end /-! The complete-level first-covering probability bound, with its individual local log ratio (not the largest tier times the number of scales). -/ noncomputable section open scoped BigOperators open Finset namespace KServer.LevelSpatial open LevelKeys LevelCoverage LevelLaw FiniteExperiment TierProcess Pilot attribute [local instance] Classical.propDecidable attribute [local instance] Classical.decEq local instance (priority := 2000) finDecEq (n:β„•) : DecidableEq (Fin n) := Classical.decEq _ lemma fin_prefix_sum (f:ℕ→ℝ) {N n:β„•} (hn:n < N) : (βˆ‘ i:Fin N,if i.val ≀ n then f i else 0)=βˆ‘ i∈range (n+1),f i := by have he:=Fin.sum_univ_eq_sum_range (fun m:β„•=>if m ≀ n then f m else 0) N rw [he] calc (βˆ‘ i∈range N,if i ≀ n then f i else 0)=βˆ‘ i∈range (n+1),if i ≀ n then f i else 0 := by symm refine sum_subset (range_mono (by omega)) ?_ intro i hi hni exact ite_eq_right (by simp only [mem_range] at hni; omega) _ = _ := by apply sum_congr rfl; intro i hi; exact ite_eq_left (by have := mem_range.mp hi; omega) lemma structure_prefix_sum {k:β„•} (p:Structure k→ℝ) (i:Tier k) : (βˆ‘ j∈univ.filter (fun j:Structure k=>j ≀ (i:Structure k)),p j)= p (βŠ₯:Structure k)+βˆ‘ j:Tier k,if j ≀ i then p (j:Structure k) else 0 := by let f : Structure k β†’ ℝ := fun j=>if j ≀ (i:Structure k) then p j else 0 have hs : (βˆ‘ j∈univ.filter (fun j:Structure k=>j ≀ (i:Structure k)),p j)=βˆ‘ j:Structure k,f j := by rw [sum_filter] rw [hs] let e : Structure k ≃ Option (Tier k) := Equiv.refl _ rw [Fintype.sum_equiv e f (fun j=>f (e.symm j)) (fun _=>rfl)] have he:=Fintype.sum_option (fun j:Option (Tier k)=>f (e.symm j)) rw [he] have hb : f (e.symm none)=p (βŠ₯:Structure k) := by change f (βŠ₯:Structure k)=_ simp only [f,bot_le,ite_true] rw [hb] congr 1 apply sum_congr rfl intro j _ change (if (j:Structure k) ≀ (i:Structure k) then p (j:Structure k) else 0)=_ simp only [WithBot.coe_le_coe] variable {Y:Type*} [MetricSpace Y] [Fintype Y] {k H:β„•} [NeZero k] def separation (s:Configuration k Y) (law:RequestLaw Y H) {r:ℝ} (hr:0 ≀ r) (Οƒ:Fin Hβ†’Y) (t:β„•) (x y:Y) : ℝ := βˆ‘ a:Tape Y k H r,if map s law hr Οƒ a t xβ‰ map s law hr Οƒ a t y then weight r a else 0 lemma separation_nonneg (s:Configuration k Y) (law:RequestLaw Y H) {r:ℝ} (hr:0 < r) (Οƒ:Fin Hβ†’Y) (t:β„•) (x y:Y) : 0 ≀ separation s law hr.le Οƒ t x y := sum_nonneg (fun a _=>by split_ifs <;> first | exact weight_nonneg hr a | exact le_rfl) lemma separation_le_one (s:Configuration k Y) (law:RequestLaw Y H) {r:ℝ} (hr:0 < r) (Οƒ:Fin Hβ†’Y) (t:β„•) (x y:Y) : separation s law hr.le Οƒ t x y ≀ 1 := by calc _ ≀ βˆ‘ a:Tape Y k H r,weight r a := by apply sum_le_sum; intro a _; split_ifs <;> first | exact le_rfl | exact weight_nonneg hr a _ = 1 := weight_sum hr lemma separation_self (s:Configuration k Y) (law:RequestLaw Y H) {r:ℝ} (hr:0 ≀ r) (Οƒ:Fin Hβ†’Y) (t:β„•) (x:Y) : separation s law hr Οƒ t x x=0 := by simp [separation] lemma prefix_bound (s:Configuration k Y) (law:RequestLaw Y H) {r:ℝ} (hr:0 < r) (Οƒ:Fin Hβ†’Y) (t:β„•) (x y:Y) (hxy:4*dist x y < r) (i:Tier k) (hi:βˆ€ a:Tape Y k H r,keys s law hr.le Οƒ a t (some i) xβ‰ none) : separation s law hr.le Οƒ t x y ≀ dist x y/(4*r)+ (262*dist x y/r)*(βˆ‘ j∈range (i.val+1),(2:ℝ)^j) := by have hp:=PriorityKeys.probability_prefix_bound (I:=Structure k) (weight r) (weight_nonneg hr) (fun a:Tape Y k H r=>keys s law hr.le Οƒ a t) x y (i:Structure k) hi have he : separation s law hr.le Οƒ t x y = βˆ‘ a:Tape Y k H r,if PriorityKeys.key (I:=Structure k) (keys s law hr.le Οƒ a t) x β‰  PriorityKeys.key (I:=Structure k) (keys s law hr.le Οƒ a t) y then weight r a else 0 := by apply sum_congr rfl intro a _ unfold LevelKeys.map split_ifs <;> rfl have hp' : separation s law hr.le Οƒ t x y ≀ βˆ‘ j∈univ.filter (fun j:Structure k=>j ≀ (i:Structure k)), βˆ‘ a:Tape Y k H r,if keys s law hr.le Οƒ a t j xβ‰ keys s law hr.le Οƒ a t j y then weight r a else 0 := by rw [he] convert hp using 1 Β· apply sum_congr rfl intro a _ split_ifs <;> rfl Β· simp only [sum_filter] apply sum_congr rfl intro j _ split_ifs <;> rfl rw [structure_prefix_sum] at hp' refine hp'.trans ?_ apply add_le_add (heavy_spatial s law hr Οƒ t x y hxy) have hs:(βˆ‘ j:Tier k,if j ≀ i then height j else 0)=βˆ‘ j∈range (i.val+1),(2:ℝ)^j := by exact fin_prefix_sum (fun n=>(2:ℝ)^n) i.isLt rw [←hs,mul_sum] apply sum_le_sum intro j _ by_cases hj:j ≀ i Β· simp only [hj,ite_true] have hd:dist x y ≀ r:=by linarith [dist_nonneg (x:=x) (y:=y)] have hb:=tier_spatial s law hr Οƒ t j x y hd have hl:Real.log (1+(tierK (height j):ℝ)^2) ≀ 131*height j:= TierDyadic.radius_coefficient (height_ge j) apply hb.trans have hc:=mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left hl (by norm_num : (0:ℝ) ≀ 2)) (div_nonneg (dist_nonneg (x:=x) (y:=y)) hr.le) convert hc using 1 <;> ring Β· simp only [hj,ite_false,mul_zero,le_refl] lemma request_bound (s:Configuration k Y) (law:RequestLaw Y H) {r:ℝ} (hr:0 < r) (Οƒ:Fin Hβ†’Y) (hΟƒ:0 < law.val Οƒ) (t:Fin H) (y:Y) (hxy:4*dist (Οƒ t) y < r) : separation s law hr.le Οƒ (t.val+1) (Οƒ t) y ≀ 1050*(1+logratio s law Οƒ t r)*dist (Οƒ t) y/r := by let i:Tier k:=⟨firstTier s law Οƒ t r,by have hh:=firstTier_le s law Οƒ hΟƒ t hr.le; omega⟩ have hq:tierQualifies s law r Οƒ i t:=firstTier_qualifies s law Οƒ hΟƒ t hr.le have hi (a:Tape Y k H r):keys s law hr.le Οƒ a (t.val+1) (some i) (Οƒ t)β‰ none:=by obtain ⟨b,hb⟩:=TierKeys.guaranteed_coverage (request s Οƒ) hr (lt_of_lt_of_le (by omega : 0 < 2) (tierK_ge_two (height_ge i))) (tierQualifies s law r Οƒ i) t t.isLt hq (a.2 i).1 (a.2 i).2 change TierKeys.key (request s Οƒ) hr.le (tierK (height i)) (tierQualifies s law r Οƒ i) (a.2 i).1 (a.2 i).2 (t.val+1) (Οƒ t)β‰ none rw [request_fin] at hb rw [hb] exact Option.some_ne_none _ have hb:=prefix_bound s law hr Οƒ (t.val+1) (Οƒ t) y hxy i hi have hL:=logratio_bounds s law Οƒ hΟƒ t hr.le have hsum: (βˆ‘ j∈range (i.val+1),(2:ℝ)^j) ≀ 4*(1+logratio s law Οƒ t r):= TierDyadic.qualified_sum hL.1 have hmul:=mul_le_mul_of_nonneg_left hsum (by positivity : 0 ≀ 262*dist (Οƒ t) y/r) have hc:dist (Οƒ t) y/(4*r) ≀ 2*(1+logratio s law Οƒ t r)*dist (Οƒ t) y/r:=by apply (div_le_div_iffβ‚€ (by positivity : 0 < 4*r) hr).mpr have hd:=mul_nonneg hL.1 (dist_nonneg (x:=Οƒ t) (y:=y)) have hdr:=mul_nonneg hd hr.le nlinarith [mul_nonneg (dist_nonneg (x:=Οƒ t) (y:=y)) hr.le] calc _ ≀ dist (Οƒ t) y/(4*r)+(262*dist (Οƒ t) y/r)*(βˆ‘ j∈range (i.val+1),(2:ℝ)^j) := hb _ ≀ 2*(1+logratio s law Οƒ t r)*dist (Οƒ t) y/r+(262*dist (Οƒ t) y/r)*(4*(1+logratio s law Οƒ t r)) := add_le_add hc hmul _ = _ := by ring lemma map_eq_of_heavy (s:Configuration k Y) (law:RequestLaw Y H) {r:ℝ} (hr:0 < r) (Οƒ:Fin Hβ†’Y) (t:Fin H) (y:Y) (hxy:4*dist (Οƒ t) y < r) (hh:mass (mu s law (t.val+1) Οƒ) (Pilot.ball (Οƒ t) (51200*r)) ≀ (1+heavyDelta)*mass (mu s law (t.val+1) Οƒ) (Pilot.ball (Οƒ t) (heavyGamma*r))) (a:Tape Y k H r) : map s law hr.le Οƒ a (t.val+1) (Οƒ t)=map s law hr.le Οƒ a (t.val+1) y := by obtain ⟨b,hb,hby⟩:=heavy_agrees s law Οƒ t hr hh a.1 y hxy by_contra hn obtain ⟨j,hj,hd⟩:=PriorityKeys.key_ne_prefix (keys s law hr.le Οƒ a (t.val+1)) (Οƒ t) y none (by change HeavyKeys.key s law r heavyGamma heavyDelta Οƒ a.1 (t.val+1) (Οƒ t)β‰ none rw [hb]; exact Option.some_ne_none _) hn have he:j=none:=bot_unique hj subst j exact hd (hb.trans hby.symm) lemma heavy_zero (s:Configuration k Y) (law:RequestLaw Y H) {r:ℝ} (hr:0 < r) (Οƒ:Fin Hβ†’Y) (t:Fin H) (y:Y) (hxy:4*dist (Οƒ t) y < r) (hh:mass (mu s law (t.val+1) Οƒ) (Pilot.ball (Οƒ t) (51200*r)) ≀ (1+heavyDelta)*mass (mu s law (t.val+1) Οƒ) (Pilot.ball (Οƒ t) (heavyGamma*r))) : separation s law hr.le Οƒ (t.val+1) (Οƒ t) y=0 := by apply sum_eq_zero intro a _ exact ite_eq_right (not_not.mpr (map_eq_of_heavy s law hr Οƒ t y hxy hh a)) /-- The complete-level estimate (final-map-separation), with an explicit absolute factor and no number-of-scales or largest-tier multiplier. -/ lemma spatial_sum (s:Configuration k Y) (law:RequestLaw Y H) (Οƒ:Fin Hβ†’Y) (hΟƒ:0 < law.val Οƒ) (t:Fin H) (y:Y) {rβ‚€ Ο„:ℝ} (hr:0 < rβ‚€) (hΟ„:2 ≀ Ο„) (n:β„•) : (βˆ‘ j∈range n, Pilot.radius rβ‚€ Ο„ j * separation s law (Pilot.radius_pos hr (by linarith) j).le Οƒ (t.val+1) (Οƒ t) y) ≀ (8+1050*(60/Real.log (1+heavyDelta)+60)*Real.log k)*dist (Οƒ t) y := by let R:=Pilot.radius rβ‚€ Ο„ let L (j:β„•):=logratio s law Οƒ t (R j) let N (j:β„•):ℝ:=if Pilot.mass (mu s law (t.val+1) Οƒ) (Pilot.ball (Οƒ t) (51200*R j)) ≀ (1+heavyDelta)*Pilot.mass (mu s law (t.val+1) Οƒ) (Pilot.ball (Οƒ t) (heavyGamma*R j)) then 0 else 1 have hR (j:β„•):0 < R j:=Pilot.radius_pos hr (by linarith) j have hL (j:β„•):0 ≀ L j:=(logratio_bounds s law Οƒ hΟƒ t (hR j).le).1 have hN (j:β„•):0 ≀ N j:=by dsimp [N]; split_ifs <;> norm_num have hpoint (j:β„•):R j*separation s law (hR j).le Οƒ (t.val+1) (Οƒ t) y ≀ (if R j ≀ 4*dist (Οƒ t) y then R j else 0)+1050*dist (Οƒ t) y*(N j+L j):=by by_cases hsmall:R j ≀ 4*dist (Οƒ t) y Β· rw [ite_eq_left hsmall] have hs:=mul_le_mul_of_nonneg_left (separation_le_one s law (hR j) Οƒ (t.val+1) (Οƒ t) y) (hR j).le have hmore:0 ≀ 1050*dist (Οƒ t) y*(N j+L j):=mul_nonneg (by positivity) (add_nonneg (hN j) (hL j)) linarith Β· rw [ite_eq_right hsmall] have hbig:4*dist (Οƒ t) y < R j:=lt_of_not_ge hsmall dsimp only [N] split_ifs with hh Β· rw [heavy_zero s law (hR j) Οƒ t y hbig hh,mul_zero,zero_add,zero_add] exact mul_nonneg (by positivity) (hL j) Β· have hs:=request_bound s law (hR j) Οƒ hΟƒ t y hbig have hm:=mul_le_mul_of_nonneg_left hs (hR j).le have he:R j*(1050*(1+L j)*dist (Οƒ t) y/R j)=1050*dist (Οƒ t) y*(1+L j):=by field_simp [(hR j).ne'] change R j*separation s law (hR j).le Οƒ (t.val+1) (Οƒ t) y ≀ R j*(1050*(1+L j)*dist (Οƒ t) y/R j) at hm simpa only [he,zero_add] using hm have hsum:=sum_le_sum (fun j (_:j∈range n)=>hpoint j) rw [sum_add_distrib,←mul_sum,sum_add_distrib] at hsum have hsmall:=Pilot.radius_truncated_sum hr.le hΟ„ (by positivity : 0 ≀ 4*dist (Οƒ t) y) n have hlogs:=LevelScale.actual_logratio_sum s law Οƒ hΟƒ t hr.le hΟ„ n have hcount:=LevelScale.actual_nonheavy_count s law Οƒ hΟƒ t hr.le hΟ„ n have hlarge:=mul_le_mul_of_nonneg_left (add_le_add hcount hlogs) (by positivity : 0 ≀ 1050*dist (Οƒ t) y) have htotal:=hsum.trans (add_le_add hsmall hlarge) convert htotal using 1; first | rfl | ring end KServer.LevelSpatial end /-! Physical movement of the tier noncoverage potential on steps without an insertion. Unqualified dyadic heights sum against the local log ratio. -/ noncomputable section open scoped BigOperators open Finset namespace KServer.LevelNoInsert open ActualRoster LevelKeys LevelCoverage LevelLaw LevelTierEdits LevelRetirement FiniteExperiment TierProcess Pilot attribute [local instance] Classical.propDecidable Classical.decEq local instance (priority := 2000) finDecEq (n:β„•) : DecidableEq (Fin n) := Classical.decEq _ lemma filtered_powers {L:ℝ} (hL:0 ≀ L) (n:β„•) : (βˆ‘ i∈range n,if (2:ℝ)^i<L then (2:ℝ)^i else 0) ≀ 2*L := by induction n with | zero => simp only [range_zero,sum_empty]; linarith | succ n ih => by_cases hn:(2:ℝ)^n<L Β· have he : (βˆ‘ i∈range (n+1),if (2:ℝ)^i<L then (2:ℝ)^i else 0)= βˆ‘ i∈range (n+1),(2:ℝ)^i := by apply sum_congr rfl intro i hi exact ite_eq_left ((pow_le_pow_rightβ‚€ (by norm_num : (1:ℝ) ≀ 2) (by have hh:=mem_range.mp hi; omega)).trans_lt hn) rw [he,TierDyadic.tier_sum] linarith Β· rw [sum_range_succ,ite_eq_right hn,add_zero] exact ih lemma tier_count (k:β„•) : (Fintype.card (Tier k):ℝ) ≀ 4*(1+Real.log k) := by by_cases hk:k=0 Β· subst k norm_num [Tier,TierDyadic.index_zero (show (0:ℝ) ≀ 1 by norm_num)] have hl:0 ≀ Real.log k:=Real.log_nonneg (by exact_mod_cast Nat.one_le_iff_ne_zero.mpr hk) have hp:=TierDyadic.qualified_sum hl have hi : (Fintype.card (Tier k):ℝ) ≀ βˆ‘ i∈range (TierDyadic.index (Real.log k)+1),(2:ℝ)^i := by calc _ = βˆ‘ i∈range (TierDyadic.index (Real.log k)+1),(1:ℝ) := by simp [Tier] _ ≀ _ := sum_le_sum (fun i _=>one_le_powβ‚€ (by norm_num)) exact hi.trans hp variable {Y:Type*} [MetricSpace Y] [Fintype Y] {k H:β„•} [NeZero k] lemma unqualified_height_sum (s:Configuration k Y) (law:RequestLaw Y H) {r:ℝ} (hr:0 ≀ r) (Οƒ:Fin Hβ†’Y) (hs:0 < law.val Οƒ) (t:Fin H) : (βˆ‘ i:Tier k,if tierQualifies s law r Οƒ i t then 0 else height i) ≀ 2*logratio s law Οƒ t r := by trans βˆ‘ i:Tier k,if height i<logratio s law Οƒ t r then height i else 0 Β· apply sum_le_sum intro i _ by_cases hq:tierQualifies s law r Οƒ i t Β· rw [ite_eq_left hq]; split_ifs Β· exact (show (0:ℝ) ≀ 1 by norm_num).trans (height_ge i) Β· rfl Β· have hi:height i<logratio s law Οƒ t r:=lt_of_not_ge (fun hn=>hq (qualifies_of_log s law Οƒ hs t hr hn)) rw [ite_eq_right hq,ite_eq_left hi] Β· unfold height have he:=Fin.sum_univ_eq_sum_range (fun j:β„•=>if (2:ℝ)^j<logratio s law Οƒ t r then (2:ℝ)^j else 0) (TierDyadic.index (Real.log k)+1) rw [he] exact filtered_powers (logratio_bounds s law Οƒ hs t hr).1 _ /-- Positive error is zero on insertion steps here; those steps are separately charged to the actual retirement and pilot budgets. -/ def error (s:Configuration k Y) (law:RequestLaw Y H) {r:ℝ} (hr:0 ≀ r) (Οƒ:Fin Hβ†’Y) (t:Fin H) (i:Tier k) (p:Y) : ℝ := if inserted s law r Οƒ t i then 0 else mean r (fun a=> LevelTierEdits.charge s law hr Οƒ a t i p+uncovered s law hr Οƒ a (t.val+1) i (Οƒ t)- uncovered s law hr Οƒ a t i p) lemma error_le_one (s:Configuration k Y) (law:RequestLaw Y H) {r:ℝ} (hr:0 < r) (Οƒ:Fin Hβ†’Y) (t:Fin H) (i:Tier k) (p:Y) : error s law hr.le Οƒ t i p ≀ 1 := by unfold error split_ifs with hin Β· norm_num Β· have hb:=mean_mono hr (fun a=>no_insert_mover s law hr Οƒ a t i p hin) refine hb.trans ((mean_mono hr (fun a=>?_)).trans_eq (mean_const hr 1)) split_ifs Β· norm_num Β· unfold indicator; split_ifs <;> norm_num lemma error_spatial (s:Configuration k Y) (law:RequestLaw Y H) {r:ℝ} (hr:0 < r) (Οƒ:Fin Hβ†’Y) (t:Fin H) (i:Tier k) (p:Y) (hp:dist (Οƒ t) p ≀ r) : error s law hr.le Οƒ t i p ≀ (262*dist (Οƒ t) p/r)*(if tierQualifies s law r Οƒ i t then 0 else height i) := by have hnon:0 ≀ 262*dist (Οƒ t) p/r:=by positivity unfold error by_cases hin:inserted s law r Οƒ t i Β· rw [ite_eq_left hin] exact mul_nonneg hnon (by split_ifs <;> first | rfl | exact (height_ge i).trans' (by norm_num)) Β· rw [ite_eq_right hin] have hb:=mean_mono hr (fun a=>no_insert_mover s law hr Οƒ a t i p hin) by_cases hq:tierQualifies s law r Οƒ i t Β· simp only [ite_eq_left hq,mul_zero,mean_const hr] at hb ⊒ exact hb Β· simp only [ite_eq_right hq] at hb ⊒ rw [mean_indicator] at hb have hc:=LevelLaw.tier_spatial s law hr Οƒ (t.val+1) i (Οƒ t) p hp have hh:=mul_le_mul_of_nonneg_right (TierDyadic.radius_coefficient (height_ge i)) (div_nonneg (dist_nonneg (x:=Οƒ t) (y:=p)) hr.le) dsimp only [keys] at hb hc have hbound : (βˆ‘ a:Tape Y k H r,if TierKeys.key (request s Οƒ) hr.le (tierK (height i)) (tierQualifies s law r Οƒ i) (a.2 i).1 (a.2 i).2 (t.val+1) (Οƒ t) β‰  TierKeys.key (request s Οƒ) hr.le (tierK (height i)) (tierQualifies s law r Οƒ i) (a.2 i).1 (a.2 i).2 (t.val+1) p then weight r a else 0) ≀ (262*dist (Οƒ t) p/r)*height i := by refine hc.trans ?_ convert mul_le_mul_of_nonneg_left hh (by norm_num : (0:ℝ) ≀ 2) using 1 <;> ring apply hb.trans convert hbound using 1; first | rfl | (apply sum_congr rfl; intro a _; congr 1) lemma level_error (s:Configuration k Y) (law:RequestLaw Y H) {r:ℝ} (hr:0 < r) (Οƒ:Fin Hβ†’Y) (hs:0 < law.val Οƒ) (t:Fin H) (p:Y) : r*(βˆ‘ i:Tier k,error s law hr.le Οƒ t i p) ≀ (if r ≀ 4*dist (Οƒ t) p then (Fintype.card (Tier k):ℝ)*r else 0)+ 524*dist (Οƒ t) p*logratio s law Οƒ t r := by by_cases hp:r ≀ 4*dist (Οƒ t) p Β· rw [ite_eq_left hp] have hb:=sum_le_sum (fun i (_:i∈univ)=>error_le_one s law hr Οƒ t i p) simp only [sum_const,card_univ,nsmul_eq_mul,mul_one] at hb have hc:=mul_le_mul_of_nonneg_left hb hr.le have hn:=mul_nonneg (by positivity : 0 ≀ 524*dist (Οƒ t) p) (logratio_bounds s law Οƒ hs t hr.le).1 nlinarith Β· rw [ite_eq_right hp,zero_add] have hdist:dist (Οƒ t) p ≀ r:=by linarith [dist_nonneg (x:=Οƒ t) (y:=p)] have hb:=sum_le_sum (fun i (_:i∈univ)=>error_spatial s law hr Οƒ t i p hdist) rw [←mul_sum] at hb have hc:=hb.trans (mul_le_mul_of_nonneg_left (unqualified_height_sum s law hr.le Οƒ hs t) (by positivity)) have hd:=mul_le_mul_of_nonneg_left hc hr.le calc _ ≀ r*((262*dist (Οƒ t) p/r)*(2*logratio s law Οƒ t r)) := hd _ = _ := by field_simp [hr.ne']; ring lemma scales_error (s:Configuration k Y) (law:RequestLaw Y H) (Οƒ:Fin Hβ†’Y) (hs:0 < law.val Οƒ) (t:Fin H) (p:Y) {rβ‚€ Ο„:ℝ} (hr:0 < rβ‚€) (hΟ„:2 ≀ Ο„) (n:β„•) : (βˆ‘ j∈range n,Pilot.radius rβ‚€ Ο„ j * (βˆ‘ i:Tier k,error s law (Pilot.radius_pos hr (by linarith) j).le Οƒ t i p)) ≀ (32*(1+Real.log k)+31440*Real.log k)*dist (Οƒ t) p := by have hb:=sum_le_sum (fun j (_:j∈range n)=>level_error s law (Pilot.radius_pos hr (by linarith) j) Οƒ hs t p) rw [sum_add_distrib,←mul_sum] at hb have he:(βˆ‘ j∈range n,if Pilot.radius rβ‚€ Ο„ j ≀ 4*dist (Οƒ t) p then (Fintype.card (Tier k):ℝ)*Pilot.radius rβ‚€ Ο„ j else 0)= (Fintype.card (Tier k):ℝ)*βˆ‘ j∈range n,if Pilot.radius rβ‚€ Ο„ j ≀ 4*dist (Οƒ t) p then Pilot.radius rβ‚€ Ο„ j else 0 := by rw [mul_sum] apply sum_congr rfl intro j _ split_ifs <;> ring rw [he] at hb have hsmall:=mul_le_mul_of_nonneg_left (Pilot.radius_truncated_sum hr.le hΟ„ (by positivity : 0 ≀ 4*dist (Οƒ t) p) n) (Nat.cast_nonneg (Fintype.card (Tier k)): (0:ℝ) ≀ _) have hlarge:=mul_le_mul_of_nonneg_left (LevelScale.actual_logratio_sum s law Οƒ hs t hr.le hΟ„ n) (by positivity : 0 ≀ 524*dist (Οƒ t) p) have hcount:=mul_le_mul_of_nonneg_right (tier_count k) (by positivity : 0 ≀ 8*dist (Οƒ t) p) have ht:=hb.trans (add_le_add hsmall hlarge) nlinarith end KServer.LevelNoInsert end end OAI
import Mathlib
import OAI.Combinatorics.KServer.Tiers
namespace OAI
noncomputable section
open scoped BigOperators
open Finset
namespace KServer.ActualRoster
open RosterLifetimes FiniteBallLaw PartitionProbabilities Chronological
attribute [local instance] Classical.propDecidable Classical.decEq
lemma final_survival {K a : β„•} (hK : 2 ≀ K) (ha : a+1=K^2) :
actualPresence K a=survive (1/(K:ℝ)) (K^2-K) := by
have hkk : K+1 ≀ K^2 := by nlinarith
have hak : Β¬a<K := by omega
have hac : a<K^2 := by omega
have he : a-K+1=K^2-K := by omega
simp only [actualPresence,ite_eq_right hak,ite_eq_left hac,he]
/-- Unconditional marginal death bound. The extra tail is never interpreted
as a conditional compulsory hazard. -/
lemma death_marginal {K a b : β„•} (hK : 2 ≀ K) (hab : a ≀ b) (hba : b ≀ a+1) :
(βˆ‘ d : Lifetime K, if alive K a d ∧ Β¬alive K b d then lifetimeLaw K d else 0) ≀
(1/(K:ℝ))*actualPresence K a+
if a<K^2 then survive (1/(K:ℝ)) (K^2-K) else 0 := by
have hk : 1≀K := by omega
have hq := (rate_range hk).1
have hs := (survival_range hk a).1
have ht := (survive_range (rate_range hk) (K^2-K)).1
by_cases he : b=a
Β· subst b
simp only [and_not_self,ite_false,sum_const_zero]
exact add_nonneg (mul_nonneg hq hs) (by split_ifs <;> positivity)
Β· have hb : b=a+1 := by omega
subst b
rw [death_probability hk]
by_cases hac : a<K^2
Β· rw [ite_eq_left hac]
by_cases hbc : a+1<K^2
Β· exact (ordinary_death_bound hk hbc).trans (le_add_of_nonneg_right ht)
Β· have heq : a+1=K^2 := by omega
rw [actual_cutoff (a:=a+1) (by omega),sub_zero,final_survival hK heq]
exact le_add_of_nonneg_left (mul_nonneg hq ht)
Β· rw [ite_eq_right hac,actual_cutoff (le_of_not_gt hac),actual_cutoff (by omega)]
simp
/-- A literal finite lifetime-tape first-coverer estimate. The `S` hypothesis
is only a deterministic candidate count, and is discharged by chronological
ages below. -/
theorem first_retirement_bound {H K : β„•} (hK : 2 ≀ K)
(a b : Fin H β†’ β„•) (inc : βˆ€ i, a i≀b i ∧ b i≀a i+1)
(cover : Fin H β†’ Prop) (S : Finset (Fin H))
(hS : βˆ€ i, cover i β†’ a i<K^2 β†’ i∈S) (hcard : S.card ≀ K^2) :
PartitionProbabilities.probability (fun _ : Fin H=>lifetimeLaw K)
(firstSeparation (fun i d=>cover i ∧ alive K (a i) d)
(fun i d=>cover i ∧ alive K (a i) d ∧ Β¬alive K (b i) d)) ≀ 49/(K:ℝ) := by
have hk : 1≀K := by omega
have hkp : (0:ℝ)<K := by exact_mod_cast (show 0<K by omega)
let T : ℝ := survive (1/(K:ℝ)) (K^2-K)
have hT : 0≀T := (survive_range (rate_range hk) _).1
let Ξ΅ : Fin H β†’ ℝ := fun i=>if i∈S then (K:ℝ)*T else 0
have heps : βˆ‘ i, Ξ΅ i=(K:ℝ)*T*S.card := by simp [Ξ΅,sum_ite_mem,mul_comm]
have hh := SparseFirstHit.sparse_bound (fun _ : Fin H=>lifetimeLaw K)
(fun _=>lifetime_nonneg hk) (fun _=>lifetime_sum hk)
(hit:=fun i d=>cover i ∧ alive K (a i) d)
(sep:=fun i d=>cover i ∧ alive K (a i) d ∧ ¬alive K (b i) d)
(fun _ _ h=>⟨h.1,h.2.1⟩) Ρ (rate_range hk).1
(fun i=>by dsimp [Ξ΅]; split_ifs <;> positivity)
have hm (i : Fin H) : (βˆ‘ d, if cover i ∧ alive K (a i) d ∧ Β¬alive K (b i) d then lifetimeLaw K d else 0) ≀
(1/(K:ℝ))*((βˆ‘ d, if cover i ∧ alive K (a i) d then lifetimeLaw K d else 0)+Ξ΅ i) := by
by_cases hc : cover i
Β· simp only [hc,true_and]
rw [alive_probability hk]
have hd := death_marginal hK (inc i).1 (inc i).2
refine hd.trans ?_
by_cases hy : a i<K^2
Β· simp only [ite_eq_left hy,Ξ΅,ite_eq_left (hS i hc hy)]
dsimp [T]
field_simp
exact le_rfl
Β· simp only [ite_eq_right hy,add_zero]
exact mul_le_mul_of_nonneg_left (le_add_of_nonneg_right (by dsimp [Ξ΅]; split_ifs <;> positivity)) (rate_range hk).1
Β· simp only [hc,false_and,ite_false,sum_const_zero,zero_add]
exact mul_nonneg (rate_range hk).1 (by dsimp [Ξ΅]; split_ifs <;> positivity)
have hb := hh (fun i=>by
convert hm i using 1
Β· apply sum_congr rfl
intro d _
by_cases h : cover i ∧ alive K (a i) d ∧ ¬alive K (b i) d <;> simp [h]
Β· apply congrArg (fun z : ℝ=>(1/(K:ℝ))*(z+Ξ΅ i))
apply sum_congr rfl
intro d _
by_cases h : cover i ∧ alive K (a i) d <;> simp [h])
rw [heps] at hb
have hc : (S.card:ℝ)≀(K:ℝ)^2 := by exact_mod_cast hcard
have hfin : (1/(K:ℝ))*(1+(K:ℝ)*T*S.card) ≀ 1/(K:ℝ)+(K:ℝ)^2*T := by
calc _ ≀ (1/(K:ℝ))*(1+(K:ℝ)*T*(K:ℝ)^2) := by gcongr
_ = _ := by field_simp
exact (hb.trans hfin).trans (actual_retirement_bound K hK)