Download data/lean/OAI/Combinatorics/KServer/RosterEdits.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 65 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/KServer/RosterEdits.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Combinatorics/KServer/RosterEdits.lean
-
curl -L -o RosterEdits.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/KServer/RosterEdits.lean
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)