math / data /lean /OAI /Combinatorics /KServer /Hierarchy.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
12.2 kB
import Mathlib
import OAI.Combinatorics.KServer.OutputRules
import OAI.Combinatorics.KServer.Trees
namespace OAI
/-! Conditional ranks of literal complete-prefix cells, connected to the
allocation's filtered process and compatible lower envelopes. No local
allocation or competitiveness assertion is an input. -/
noncomputable section
open scoped BigOperators
open Finset
namespace KServer.HierarchicalRanks
attribute [local instance] Classical.propDecidable Classical.decEq
open RankTracking PosteriorRanks HierarchyCounts
variable {Ξ© A Y : Type} [Fintype Ξ©] [Fintype A] {k d : β„•}
variable {w : Ξ© β†’ ℝ} (hw : βˆ€ Ο‰,0≀w Ο‰)
variable (H : β„• β†’ Ξ© β†’ β„•)
variable (hr : βˆ€ t Ο‰ ρ,H (t+1) Ο‰=H (t+1) ρ β†’ H t Ο‰=H t ρ)
variable (maps : β„• β†’ Ξ© β†’ β„• β†’ Y β†’ A) (q : β„• β†’ Ξ© β†’ Fin k β†’ Y)
def family (word : Fin d β†’ A) (a : Fin k) : FilteredRanks w :=
rankProcess hw H hr (fun t Ο‰=>count (maps t Ο‰) word (q t Ο‰)) a.val
def lower (word : Fin d β†’ A) (z : ℝ) (t : β„•) (Ο‰ : Ξ©) : ℝ :=
βˆ‘ a : Fin k, RankFunctions.rank z ((family hw H hr maps q word a).p t Ο‰)
def size (word : Fin d β†’ A) (t : β„•) (Ο‰ : Ξ©) : ℝ :=
CoarseProcess.size (family hw H hr maps q word) t Ο‰
omit [Fintype A] in
lemma family_value (word : Fin d β†’ A) (a : Fin k) (t : β„•) (Ο‰ : Ξ©) :
(family hw H hr maps q word a).p t Ο‰=
RankOrder.countRank (conditional w (H t) Ο‰)
(fun ρ=>count (maps t ρ) word (q t ρ)) a.val :=
(conditional_rank w (H t) Ο‰ _ _).symm
omit [Fintype A] in
lemma lower_eq (word : Fin d β†’ A) (z : ℝ) (t : β„•) (Ο‰ : Ξ©) :
lower hw H hr maps q word z t Ο‰=CompatibleBounds.L k (conditional w (H t) Ο‰)
(fun ρ=>count (maps t ρ) word (q t ρ)) z := by
simp only [lower,CompatibleBounds.L,family_value]
omit [Fintype A] in
lemma size_eq (word : Fin d β†’ A) (t : β„•) (Ο‰ : Ξ©) :
size hw H hr maps q word t Ο‰=CompatibleBounds.M k (conditional w (H t) Ο‰)
(fun ρ=>count (maps t ρ) word (q t ρ)) := by
simp only [size,CoarseProcess.size,CompatibleBounds.M,family_value]
lemma lower_superadditive (word : Fin d β†’ A) {z : ℝ}
(hz : z∈Set.Icc 0 (1/100:ℝ)) (t : β„•) (Ο‰ : Ξ©) (hΟ‰ : 0<w Ο‰) :
(βˆ‘ a : A,lower hw H hr maps q (Fin.snoc word a) z t Ο‰) ≀ lower hw H hr maps q word z t Ο‰ := by
simp_rw [lower_eq]
exact (HierarchyCounts.compatible w hw (H t) ω hω (maps t) word (q t) hz).1
lemma size_superadditive (word : Fin d → A) (t : ℕ) (ω : Ω) (hω : 0<w ω) :
(βˆ‘ a : A,size hw H hr maps q (Fin.snoc word a) t Ο‰) ≀ size hw H hr maps q word t Ο‰ := by
simp_rw [size_eq]
exact (HierarchyCounts.compatible w hw (H t) ω hω (maps t) word (q t)
(z:=0) (by norm_num)).2.1
omit [Fintype A] in
lemma family_root (word : Fin 0 β†’ A) (a : Fin k) (t : β„•) (Ο‰ : Ξ©) :
(family hw H hr maps q word a).p t Ο‰=0 := by
change posterior w (H t) (PosteriorRanks.rank _ a.val) Ο‰=0
have he : PosteriorRanks.rank (fun ρ=>count (maps t ρ) word (q t ρ)) a.val=fun _=>0 := by
funext ρ
simp only [PosteriorRanks.rank,count_zero]
exact ite_eq_right (by omega)
rw [he]
simp [posterior,numerator]
omit [Fintype A] in
lemma lower_root (word : Fin 0 β†’ A) (z : ℝ) (t : β„•) (Ο‰ : Ξ©) :
lower hw H hr maps q word z t Ο‰=k := by
simp only [lower,family_root,RankFunctions.rank_zero]
simp
omit [Fintype A] in
lemma size_root (word : Fin 0 β†’ A) (t : β„•) (Ο‰ : Ξ©) :
size hw H hr maps q word t Ο‰=k := by
simp only [size,CoarseProcess.size,family_root]
norm_num [RankFunctions.sizeRank]
omit [Fintype A] in
lemma lower_nonneg (word : Fin d β†’ A) {z : ℝ} (hz : z∈Set.Icc 0 (1/100:ℝ))
(t : β„•) (Ο‰ : Ξ©) : 0≀lower hw H hr maps q word z t Ο‰ :=
sum_nonneg fun _ _=>RankFunctions.rank_nonneg hz _
omit [Fintype A] in
lemma lower_size (word : Fin d β†’ A) {z : ℝ} (hz : z∈Set.Icc 0 (1/100:ℝ))
(t : β„•) (Ο‰ : Ξ©) : lower hw H hr maps q word z t Ο‰ ≀36*size hw H hr maps q word t Ο‰ := by
unfold lower size CoarseProcess.size
rw [mul_sum]
exact sum_le_sum fun a _=>CompatibleBounds.rank_size_domination hz
((family hw H hr maps q word a).range t Ο‰).1
omit [Fintype A] in
lemma size_bound (word : Fin d β†’ A) (t : β„•) (Ο‰ : Ξ©) : size hw H hr maps q word t Ο‰ ≀ k := by
calc _ ≀ βˆ‘ _a : Fin k,(1:ℝ) := by
unfold size CoarseProcess.size
apply sum_le_sum
intro a _
have h:=(family hw H hr maps q word a).range t Ο‰
exact (RankFunctions.sizeRank_le_complement h).trans (by linarith [h.1])
_ = _ := by simp
omit [Fintype A] in
/-- The first reward rank is exactly zero if each possible hidden placement
has a member in the current observed cell. This is a fiber, not an independence
assertion and does not condition on any rounding outcomes. -/
lemma first_rank_zero {k : β„•} (hk : 0<k) (q : β„• β†’ Ξ© β†’ Fin k β†’ Y)
(word : Fin d β†’ A) (t : β„•) (Ο‰ : Ξ©)
(hs : βˆ€ ρ,H t ρ=H t Ο‰ β†’ βˆƒ l,hit (maps t ρ) word (q t ρ l)) :
(family hw H hr maps q word ⟨0,hk⟩).p t Ο‰=0 := by
change posterior w (H t) (PosteriorRanks.rank _ 0) Ο‰=0
unfold posterior numerator
have hn : (βˆ‘ ρ∈fiber (H t) (H t Ο‰),w ρ*PosteriorRanks.rank
(fun z=>count (maps t z) word (q t z)) 0 ρ)=0 := by
apply sum_eq_zero
intro ρ hρ
obtain ⟨l,hl⟩:=hs ρ (mem_filter.mp hρ).2
have hc : 0<count (maps t ρ) word (q t ρ) := card_pos.mpr ⟨l,by simp [hl]⟩
simp [PosteriorRanks.rank,not_le.mpr hc]
rw [hn,zero_div]
omit [Fintype A] in
lemma served_lower {k : β„•} (hk : 0<k) (q : β„• β†’ Ξ© β†’ Fin k β†’ Y)
(word : Fin d β†’ A) {z : ℝ} (hz : z∈Set.Icc 0 (1/100:ℝ)) (t : β„•) (Ο‰ : Ξ©)
(hs : βˆ€ ρ,H t ρ=H t Ο‰ β†’ βˆƒ l,hit (maps t ρ) word (q t ρ l)) :
1≀lower hw H hr maps q word z t Ο‰ := by
have h:=single_le_sum (s:=univ)
(fun a _=>RankFunctions.rank_nonneg hz ((family hw H hr maps q word a).p t Ο‰))
(mem_univ (⟨0,hk⟩:Fin k))
rw [first_rank_zero hw H hr maps hk q word t Ο‰ hs,RankFunctions.rank_zero] at h
exact h
end KServer.HierarchicalRanks
end
/-! Actual top-down fractional quotas on all complete-prefix labels. The
parent budget is obtained from conditional count superadditivity, not posited
as an allocation oracle. Fixed unused labels remain present. -/
noncomputable section
open scoped BigOperators
open Finset
namespace KServer.HierarchicalQuota
attribute [local instance] Classical.propDecidable Classical.decEq
open RankTracking ActualStar
variable {Ξ© A Y:Type} [Fintype Ξ©] [Fintype A] {k:β„•} {w:Ω→ℝ}
variable (hw:βˆ€ Ο‰,0≀w Ο‰) (H:β„•β†’Ξ©β†’β„•)
variable (hr:βˆ€ t Ο‰ ρ,H (t+1) Ο‰=H (t+1) ρ→H t Ο‰=H t ρ)
variable (maps:ℕ→Ω→ℕ→Y→A) (q:ℕ→Ω→Fin k→Y)
def children {d:ℕ} (word:Fin d→A):A→Fin k→FilteredRanks w:=
fun a=>HierarchicalRanks.family hw H hr maps q (Fin.snoc word a)
def parent {d:ℕ} (word:Fin d→A):Fin k→FilteredRanks w:=
HierarchicalRanks.family hw H hr maps q word
def quota (hk:1≀(k:ℝ)): (d:β„•)β†’(Fin dβ†’A)→ℕ→Ω→ℝ
| 0,_ ,_,_ => k
| d+1,word,t,Ο‰=>ActualOutput.out hk (children hw H hr maps q (Fin.init word))
(parent hw H hr maps q (Fin.init word)) t Ο‰
(quota hk d (Fin.init word) t Ο‰) (word (Fin.last d))
lemma quota_snoc (hk:1≀(k:ℝ)) {d:β„•} (word:Fin dβ†’A) (a:A) (t:β„•) (Ο‰:Ξ©):
quota hw H hr maps q hk (d+1) (Fin.snoc word a) t Ο‰=
ActualOutput.out hk (children hw H hr maps q word) (parent hw H hr maps q word)
t Ο‰ (quota hw H hr maps q hk d word t Ο‰) a:=by
simp only [quota,Fin.init_snoc,Fin.snoc_last]
lemma sizes {d:β„•} (word:Fin dβ†’A) (hwpos:βˆ€ Ο‰,0<w Ο‰) (t:β„•) (Ο‰:Ξ©):
(βˆ‘ a,CoarseProcess.size (children hw H hr maps q word a) t Ο‰)≀
CoarseProcess.size (parent hw H hr maps q word) t Ο‰:=
HierarchicalRanks.size_superadditive hw H hr maps q word t Ο‰ (hwpos Ο‰)
omit [Fintype A] in
lemma size_bound {d:ℕ} (word:Fin d→A) (t:ℕ) (ω:Ω):
CoarseProcess.size (parent hw H hr maps q word) t ω≀k:=
HierarchicalRanks.size_bound hw H hr maps q word t Ο‰
lemma parent_budget (hk:1≀(k:ℝ)) {d:β„•} (word:Fin dβ†’A) (hwpos:βˆ€ Ο‰,0<w Ο‰)
(t:β„•) (Ο‰:Ξ©) (x:ℝ) (hx:ActualOutput.lower k (parent hw H hr maps q word) t ω≀x):
(βˆ‘ a,(ActualOutput.n (children hw H hr maps q word) t Ο‰ a-
Ξ² k (parent hw H hr maps q word) t Ο‰*ActualOutput.B (children hw H hr maps q word) t Ο‰ a+
ActualOutput.f k (children hw H hr maps q word) (parent hw H hr maps q word) t Ο‰ a))≀x:=by
have hz:=(ActualCaps.ranges hk (parent hw H hr maps q word) t Ο‰ (size_bound hw H hr maps q word t Ο‰)).1
have hs:=HierarchicalRanks.lower_superadditive hw H hr maps q word hz t Ο‰ (hwpos Ο‰)
have heq : (βˆ‘ a,(ActualOutput.n (children hw H hr maps q word) t Ο‰ a-
Ξ² k (parent hw H hr maps q word) t Ο‰*ActualOutput.B (children hw H hr maps q word) t Ο‰ a+
ActualOutput.f k (children hw H hr maps q word) (parent hw H hr maps q word) t Ο‰ a))=
βˆ‘ a,HierarchicalRanks.lower hw H hr maps q (Fin.snoc word a)
(ActualCaps.z k (parent hw H hr maps q word) t Ο‰) t Ο‰ := by
apply sum_congr rfl
intro a _
exact (TrackedCaps.decomposition (children hw H hr maps q word a)
(ActualCaps.z k (parent hw H hr maps q word) t Ο‰) t Ο‰).symm
rw [heq]
exact hs.trans hx
lemma quota_bounds (hk:1≀(k:ℝ)) (hwpos:βˆ€ Ο‰,0<w Ο‰) (d:β„•) (word:Fin dβ†’A) (t:β„•) (Ο‰:Ξ©):
ActualOutput.lower k (parent hw H hr maps q word) t ω≀quota hw H hr maps q hk d word t Ο‰ ∧
quota hw H hr maps q hk d word t ω≀72*CoarseProcess.size (parent hw H hr maps q word) t Ο‰:=by
induction d with
| zero=>
have hl:=HierarchicalRanks.lower_root hw H hr maps q word (ActualCaps.z k (parent hw H hr maps q word) t Ο‰) t Ο‰
have hs:=HierarchicalRanks.size_root hw H hr maps q word t Ο‰
change ActualOutput.lower k (parent hw H hr maps q word) t Ο‰=(k:ℝ) at hl
change CoarseProcess.size (parent hw H hr maps q word) t Ο‰=(k:ℝ) at hs
simp only [quota,hl,hs]
constructor
Β· rfl
Β· linarith
| succ d ih=>
have hp:=parent_budget hw H hr maps q hk (Fin.init word) hwpos t Ο‰ _ (ih (Fin.init word)).1
have hf:=ActualOutput.out_feasible hk (children hw H hr maps q (Fin.init word))
(parent hw H hr maps q (Fin.init word)) (sizes hw H hr maps q (Fin.init word) hwpos)
(size_bound hw H hr maps q (Fin.init word)) t Ο‰ _ hp
have hd:=ActualOutput.output_domination hk (children hw H hr maps q (Fin.init word))
(parent hw H hr maps q (Fin.init word)) (sizes hw H hr maps q (Fin.init word) hwpos)
(size_bound hw H hr maps q (Fin.init word)) t Ο‰ _ hp (word (Fin.last d))
have he:Fin.snoc (Fin.init word) (word (Fin.last d))=word:=Fin.snoc_init_self word
have hl := (hf.1 (word (Fin.last d))).1
have hu := hd.2
simp only [children,he] at hl hu
exact ⟨hl,hu⟩
lemma children_budget (hk:1≀(k:ℝ)) (hwpos:βˆ€ Ο‰,0<w Ο‰) {d:β„•} (word:Fin dβ†’A) (t:β„•) (Ο‰:Ξ©):
(βˆ‘ a,quota hw H hr maps q hk (d+1) (Fin.snoc word a) t Ο‰)≀quota hw H hr maps q hk d word t Ο‰:=by
simp_rw [quota_snoc]
exact (ActualOutput.out_feasible hk _ _ (sizes hw H hr maps q word hwpos)
(size_bound hw H hr maps q word) t Ο‰ _ (parent_budget hw H hr maps q hk word hwpos t Ο‰ _
(quota_bounds hw H hr maps q hk hwpos d word t Ο‰).1)).2
lemma quota_nonneg (hk:1≀(k:ℝ)) (hwpos:βˆ€ Ο‰,0<w Ο‰) {d:β„•} (word:Fin dβ†’A) (t:β„•) (Ο‰:Ξ©):
0≀quota hw H hr maps q hk d word t Ο‰:=
(ActualOutput.lower_nonneg hk _ t Ο‰ (size_bound hw H hr maps q word t Ο‰)).trans
(quota_bounds hw H hr maps q hk hwpos d word t Ο‰).1
lemma served (hk:1≀(k:ℝ)) (hwpos:βˆ€ Ο‰,0<w Ο‰) {d:β„•} (word:Fin dβ†’A) (t:β„•) (Ο‰:Ξ©)
(hs:βˆ€ ρ,H t ρ=H t Ο‰β†’βˆƒ l,HierarchyCounts.hit (maps t ρ) word (q t ρ l)):
1≀quota hw H hr maps q hk d word t Ο‰:=by
have hkp:0<k:=by exact_mod_cast (show (0:ℝ)<k by linarith)
exact (HierarchicalRanks.served_lower hw H hr maps hkp q word
(ActualCaps.ranges hk _ t Ο‰ (size_bound hw H hr maps q word t Ο‰)).1 t Ο‰ hs).trans
(quota_bounds hw H hr maps q hk hwpos d word t Ο‰).1
end KServer.HierarchicalQuota
end
end OAI