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