Download data/lean/OAI/Combinatorics/KServer/Minimization.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 27.2 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/KServer/Minimization.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Combinatorics/KServer/Minimization.lean
-
curl -L -o Minimization.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/KServer/Minimization.lean
27.2 kB
| import Mathlib | |
| import OAI.Combinatorics.KServer.Ranks | |
| namespace OAI | |
| noncomputable section | |
| open scoped BigOperators | |
| open Finset | |
| namespace KServer.AdaptiveMinimization | |
| open Finset KServer.RankTracking | |
| variable {I J Ξ : Type*} [Fintype I] [Fintype J] | |
| lemma avg_sum_any {Ξ© : Type} [Fintype Ξ©] (w : Ξ© β β) {ΞΉ : Type*} [Fintype ΞΉ] (f : ΞΉ β Ξ© β β) : | |
| avg w (fun Ο => β i, f i Ο)=β i, avg w (f i) := by | |
| simp only [avg,mul_sum]; rw [sum_comm] | |
| /-- The source primitives are affine in the rank inputs when the held parameters | |
| and the state are fixed. Both simplex and side domains are compact. -/ | |
| structure Family (Ξ : Type*) (I J : Type*) [Fintype I] [Fintype J] where | |
| domain : Ξ β Set (J β β) | |
| compact : β ΞΈ, IsCompact (domain ΞΈ) | |
| seed : β ΞΈ, {a // a β domain ΞΈ} | |
| offset : Ξ β (J β β) β β | |
| coefficient : Ξ β (J β β) β I β β | |
| offset_continuous : β ΞΈ, ContinuousOn (offset ΞΈ) (domain ΞΈ) | |
| coefficient_continuous : β ΞΈ i, ContinuousOn (fun a => coefficient ΞΈ a i) (domain ΞΈ) | |
| def Family.value (F : Family Ξ I J) (ΞΈ : Ξ) (p : I β β) (a : J β β) : β := | |
| F.offset ΞΈ a + β i, F.coefficient ΞΈ a i*p i | |
| def movement (a b : J β β) : β := β j, |a j-b j| | |
| lemma movement_nonneg (a b : J β β) : 0 β€ movement a b := | |
| sum_nonneg fun _ _ => abs_nonneg _ | |
| lemma movement_self (a : J β β) : movement a a=0 := by simp [movement] | |
| lemma movement_triangle (a b c : J β β) : movement a c β€ movement a b+movement b c := by | |
| unfold movement | |
| rw [β sum_add_distrib] | |
| exact sum_le_sum fun j _ => abs_sub_le (a j) (b j) (c j) | |
| lemma Family.value_continuous (F : Family Ξ I J) (ΞΈ : Ξ) (p : I β β) : | |
| ContinuousOn (F.value ΞΈ p) (F.domain ΞΈ) := by | |
| apply (F.offset_continuous ΞΈ).add | |
| exact continuousOn_finsetSum _ fun i _ => (F.coefficient_continuous ΞΈ i).mul_const _ | |
| lemma movement_continuous (b : J β β) : Continuous (fun a => movement a b) := | |
| continuous_finsetSum _ fun j _ => ((continuous_apply j).sub continuous_const).abs | |
| lemma Family.exists_update (F : Family Ξ I J) (ΞΈ : Ξ) (p : I β β) | |
| (c : β) (a : J β β) : | |
| β b β F.domain ΞΈ, IsMinOn (fun b => F.value ΞΈ p b+c*movement b a) (F.domain ΞΈ) b := by | |
| exact (F.compact ΞΈ).exists_isMinOn β¨(F.seed ΞΈ).val,(F.seed ΞΈ).propertyβ© | |
| ((F.value_continuous ΞΈ p).add ((movement_continuous a).continuousOn.const_mul c)) | |
| /-- A fixed noncomputable selection, only from the currently supplied data. -/ | |
| def Family.update (F : Family Ξ I J) (ΞΈ : Ξ) (p : I β β) (c : β) (a : J β β) : J β β := | |
| (F.exists_update ΞΈ p c a).choose | |
| lemma Family.update_mem (F : Family Ξ I J) (ΞΈ : Ξ) (p : I β β) (c : β) (a : J β β) : | |
| F.update ΞΈ p c a β F.domain ΞΈ := (F.exists_update ΞΈ p c a).choose_spec.1 | |
| lemma Family.update_payment (F : Family Ξ I J) (ΞΈ : Ξ) (p : I β β) (c : β) | |
| {a : J β β} (ha : a β F.domain ΞΈ) : | |
| c*movement (F.update ΞΈ p c a) a β€ F.value ΞΈ p a-F.value ΞΈ p (F.update ΞΈ p c a) := by | |
| have h := (F.exists_update ΞΈ p c a).choose_spec.2 ha | |
| change F.value ΞΈ p (F.update ΞΈ p c a)+c*movement (F.update ΞΈ p c a) a β€ | |
| F.value ΞΈ p a+c*movement a a at h | |
| rw [movement_self,mul_zero,add_zero] at h | |
| linarith | |
| lemma Family.input_difference (F : Family Ξ I J) (ΞΈ : Ξ) (p q : I β β) (a : J β β) : | |
| F.value ΞΈ p a-F.value ΞΈ q a=β i, F.coefficient ΞΈ a i*(p i-q i) := by | |
| simp only [Family.value,mul_sub,sum_sub_distrib] | |
| ring | |
| lemma Family.input_lipschitz (F : Family Ξ I J) (ΞΈ : Ξ) (p q : I β β) | |
| (a : J β β) {L : β} (hL : β i, |F.coefficient ΞΈ a i| β€ L) : | |
| |F.value ΞΈ p a-F.value ΞΈ q a| β€ L*β i, |p i-q i| := by | |
| rw [F.input_difference,mul_sum] | |
| exact (abs_sum_le_sum_abs _ _).trans (sum_le_sum fun i _ => by | |
| rw [abs_mul]; exact mul_le_mul_of_nonneg_right (hL i) (abs_nonneg _)) | |
| variable {Ξ© : Type} [Fintype Ξ©] | |
| /-- Domain transport is computed from old/new held parameters and new rank | |
| inputs. For the manuscript it is the prepared update followed by deletion and | |
| zero insertion. It is not permitted to depend on the unrealized future. -/ | |
| structure Transport (F : Family Ξ I J) where | |
| map : Ξ β Ξ β (I β β) β (J β β) β (J β β) | |
| mem : β ΞΈ ΞΈ' p a, a β F.domain ΞΈ β map ΞΈ ΞΈ' p a β F.domain ΞΈ' | |
| def state (F : Family Ξ I J) (T : Transport F) (ΞΈ : β β Ξ© β Ξ) | |
| (p : β β Ξ© β I β β) (c : β β Ξ© β β) : β β Ξ© β J β β | |
| | 0, Ο => (F.seed (ΞΈ 0 Ο)).val | |
| | t+1, Ο => F.update (ΞΈ (t+1) Ο) (p (t+1) Ο) (c (t+1) Ο) | |
| (T.map (ΞΈ t Ο) (ΞΈ (t+1) Ο) (p (t+1) Ο) (state F T ΞΈ p c t Ο)) | |
| omit [Fintype Ξ©] in | |
| lemma state_mem (F : Family Ξ I J) (T : Transport F) (ΞΈ : β β Ξ© β Ξ) | |
| (p : β β Ξ© β I β β) (c : β β Ξ© β β) : | |
| β t Ο, state F T ΞΈ p c t Ο β F.domain (ΞΈ t Ο) := by | |
| intro t Ο | |
| cases t with | |
| | zero => exact (F.seed _).property | |
| | succ t => exact F.update_mem _ _ _ _ | |
| omit [Fintype Ξ©] in | |
| /-- Causality is proved from the recursion (not a fictitious prefix interface). -/ | |
| lemma state_adapted (F : Family Ξ I J) (T : Transport F) (ΞΈ : β β Ξ© β Ξ) | |
| (p : β β Ξ© β I β β) (c : β β Ξ© β β) (H : β β Ξ© β β) | |
| (hr : β t Ο z, H (t+1) Ο=H (t+1) z β H t Ο=H t z) | |
| (hΞΈ : β t Ο z, H t Ο=H t z β ΞΈ t Ο=ΞΈ t z) | |
| (hp : β t Ο z, H t Ο=H t z β p t Ο=p t z) | |
| (hc : β t, Adapted (H t) (c t)) : | |
| β t Ο z, H t Ο=H t z β state F T ΞΈ p c t Ο=state F T ΞΈ p c t z := by | |
| intro t | |
| induction t with | |
| | zero => | |
| intro Ο z hz | |
| exact congrArg (fun u => (F.seed u).val) (hΞΈ 0 Ο z hz) | |
| | succ t ih => | |
| intro Ο z hz | |
| have hprev := hr t Ο z hz | |
| simp only [state,hΞΈ (t+1) Ο z hz,hp (t+1) Ο z hz,hc (t+1) Ο z hz, | |
| hΞΈ t Ο z hprev,ih Ο z hprev] | |
| /-- The signed editing charge, evaluated after filtering and drift but before | |
| the final minimizing update. Preparation payments are allowed to lower it. -/ | |
| def edit (F : Family Ξ I J) (T : Transport F) (ΞΈ : β β Ξ© β Ξ) | |
| (p : β β Ξ© β I β β) (c : β β Ξ© β β) (t : β) (Ο : Ξ©) : β := | |
| let a := state F T ΞΈ p c t Ο | |
| let b := T.map (ΞΈ t Ο) (ΞΈ (t+1) Ο) (p (t+1) Ο) a | |
| F.value (ΞΈ (t+1) Ο) (p (t+1) Ο) b-F.value (ΞΈ t Ο) (p (t+1) Ο) a+ | |
| c (t+1) Ο*movement b a | |
| omit [Fintype Ξ©] in | |
| lemma state_payment (F : Family Ξ I J) (T : Transport F) (ΞΈ : β β Ξ© β Ξ) | |
| (p : β β Ξ© β I β β) (c : β β Ξ© β β) (t : β) (Ο : Ξ©) | |
| (hc : 0 β€ c (t+1) Ο) : | |
| c (t+1) Ο*movement (state F T ΞΈ p c (t+1) Ο) (state F T ΞΈ p c t Ο) β€ | |
| F.value (ΞΈ t Ο) (p (t+1) Ο) (state F T ΞΈ p c t Ο)- | |
| F.value (ΞΈ (t+1) Ο) (p (t+1) Ο) (state F T ΞΈ p c (t+1) Ο)+ | |
| edit F T ΞΈ p c t Ο := by | |
| let a := state F T ΞΈ p c t Ο | |
| let b := T.map (ΞΈ t Ο) (ΞΈ (t+1) Ο) (p (t+1) Ο) a | |
| have hb : b β F.domain (ΞΈ (t+1) Ο) := T.mem _ _ _ _ (state_mem F T ΞΈ p c t Ο) | |
| have hu := F.update_payment (ΞΈ (t+1) Ο) (p (t+1) Ο) (c (t+1) Ο) hb | |
| have ht := mul_le_mul_of_nonneg_left | |
| (movement_triangle (state F T ΞΈ p c (t+1) Ο) b a) hc | |
| change c (t+1) Ο*movement (state F T ΞΈ p c (t+1) Ο) b β€ | |
| F.value (ΞΈ (t+1) Ο) (p (t+1) Ο) b - | |
| F.value (ΞΈ (t+1) Ο) (p (t+1) Ο) (state F T ΞΈ p c (t+1) Ο) at hu | |
| calc | |
| _ β€ c (t+1) Ο * (movement (state F T ΞΈ p c (t+1) Ο) b + movement b a) := ht | |
| _ β€ (F.value (ΞΈ (t+1) Ο) (p (t+1) Ο) b - | |
| F.value (ΞΈ (t+1) Ο) (p (t+1) Ο) (state F T ΞΈ p c (t+1) Ο)) + | |
| c (t+1) Ο * movement b a := by nlinarith [hu] | |
| _ = _ := by dsimp only [edit,a,b]; ring | |
| /-- All ranks are taken under the same true observed history. -/ | |
| def rankVector {w : Ξ© β β} (R : I β FilteredRanks w) (t : β) (Ο : Ξ©) : I β β := | |
| fun i => (R i).p t Ο | |
| def beforeVector {w : Ξ© β β} (R : I β FilteredRanks w) (t : β) (Ο : Ξ©) : I β β := | |
| fun i => (R i).before t Ο | |
| omit [Fintype I] in | |
| lemma rankVector_adapted {w : Ξ© β β} (R : I β FilteredRanks w) (H : β β Ξ© β β) | |
| (hH : β i, (R i).history=H) (t : β) (Ο z : Ξ©) (hz : H t Ο=H t z) : | |
| rankVector R t Ο=rankVector R t z := by | |
| funext i | |
| apply (R i).adapted t Ο z | |
| simpa only [hH i] using hz | |
| /-- Filtering is used on every step with the old held coefficients, before | |
| selecting any ordinary/wholesale event measurable at the new history. -/ | |
| lemma filtering_zero (F : Family Ξ I J) (T : Transport F) {w : Ξ© β β} | |
| (R : I β FilteredRanks w) (ΞΈ : β β Ξ© β Ξ) (c : β β Ξ© β β) | |
| (H : β β Ξ© β β) (hH : β i, (R i).history=H) | |
| (hr : β t Ο z, H (t+1) Ο=H (t+1) z β H t Ο=H t z) | |
| (hΞΈ : β t Ο z, H t Ο=H t z β ΞΈ t Ο=ΞΈ t z) | |
| (hc : β t, Adapted (H t) (c t)) (t : β) : | |
| avg w (fun Ο => | |
| F.value (ΞΈ t Ο) (beforeVector R (t+1) Ο) (state F T ΞΈ (rankVector R) c t Ο)- | |
| F.value (ΞΈ t Ο) (rankVector R t Ο) (state F T ΞΈ (rankVector R) c t Ο))=0 := by | |
| simp_rw [F.input_difference] | |
| rw [avg_sum_any] | |
| apply sum_eq_zero | |
| intro i _ | |
| apply filtering_affine (R i) | |
| intro Ο z hz | |
| rw [hH i] at hz | |
| have hs := state_adapted F T ΞΈ (rankVector R) c H hr hΞΈ | |
| (rankVector_adapted R H hH) hc t Ο z hz | |
| dsimp only | |
| rw [hΞΈ t Ο z hz,hs] | |
| lemma expected_payment_step (F : Family Ξ I J) (T : Transport F) {w : Ξ© β β} | |
| (hw : β Ο, 0 β€ w Ο) (R : I β FilteredRanks w) | |
| (ΞΈ : β β Ξ© β Ξ) (c : β β Ξ© β β) | |
| (H : β β Ξ© β β) (hH : β i, (R i).history=H) | |
| (hr : β t Ο z, H (t+1) Ο=H (t+1) z β H t Ο=H t z) | |
| (hΞΈ : β t Ο z, H t Ο=H t z β ΞΈ t Ο=ΞΈ t z) | |
| (hc : β t, Adapted (H t) (c t)) (hcn : β t Ο, 0 β€ c t Ο) | |
| {L : β} (hL : β ΞΈ a, a β F.domain ΞΈ β β i, |F.coefficient ΞΈ a i| β€ L) | |
| (t : β) : | |
| avg w (fun Ο => c (t+1) Ο*movement (state F T ΞΈ (rankVector R) c (t+1) Ο) | |
| (state F T ΞΈ (rankVector R) c t Ο)) β€ | |
| avg w (fun Ο => F.value (ΞΈ t Ο) (rankVector R t Ο) (state F T ΞΈ (rankVector R) c t Ο))- | |
| avg w (fun Ο => F.value (ΞΈ (t+1) Ο) (rankVector R (t+1) Ο) | |
| (state F T ΞΈ (rankVector R) c (t+1) Ο)) + | |
| L*(β i, avg w (fun Ο => |(R i).p (t+1) Ο-(R i).before (t+1) Ο|))+ | |
| avg w (edit F T ΞΈ (rankVector R) c t) := by | |
| let a := state F T ΞΈ (rankVector R) c | |
| have hpoint (Ο : Ξ©) : c (t+1) Ο*movement (a (t+1) Ο) (a t Ο) β€ | |
| (F.value (ΞΈ t Ο) (rankVector R t Ο) (a t Ο)- | |
| F.value (ΞΈ (t+1) Ο) (rankVector R (t+1) Ο) (a (t+1) Ο))+ | |
| (F.value (ΞΈ t Ο) (beforeVector R (t+1) Ο) (a t Ο)- | |
| F.value (ΞΈ t Ο) (rankVector R t Ο) (a t Ο))+ | |
| L*(β i, |(R i).p (t+1) Ο-(R i).before (t+1) Ο|)+ | |
| edit F T ΞΈ (rankVector R) c t Ο := by | |
| have hm := state_payment F T ΞΈ (rankVector R) c t Ο (hcn (t+1) Ο) | |
| have hd := (le_abs_self (F.value (ΞΈ t Ο) (rankVector R (t+1) Ο) (a t Ο)- | |
| F.value (ΞΈ t Ο) (beforeVector R (t+1) Ο) (a t Ο))).trans | |
| (F.input_lipschitz (ΞΈ t Ο) (rankVector R (t+1) Ο) (beforeVector R (t+1) Ο) | |
| (a t Ο) (hL _ _ (state_mem F T ΞΈ (rankVector R) c t Ο))) | |
| change _ β€ L*(β i, |(R i).p (t+1) Ο-(R i).before (t+1) Ο|) at hd | |
| change c (t+1) Ο*movement (a (t+1) Ο) (a t Ο) β€ | |
| F.value (ΞΈ t Ο) (rankVector R (t+1) Ο) (a t Ο)- | |
| F.value (ΞΈ (t+1) Ο) (rankVector R (t+1) Ο) (a (t+1) Ο)+ | |
| edit F T ΞΈ (rankVector R) c t Ο at hm | |
| linarith | |
| have he := avg_mono hw hpoint | |
| simp only [avg_add,avg_sub,avg_mul,avg_sum_any] at he | |
| have hf := filtering_zero F T R ΞΈ c H hH hr hΞΈ hc t | |
| rw [avg_sub] at hf | |
| change avg w (fun Ο => F.value (ΞΈ t Ο) (beforeVector R (t+1) Ο) (a t Ο))- | |
| avg w (fun Ο => F.value (ΞΈ t Ο) (rankVector R t Ο) (a t Ο))=0 at hf | |
| rw [hf,add_zero] at he | |
| exact he | |
| /-- The full causal minimizer telescope. The computed signed edit term must be | |
| bounded from the actual coordinate preparation/deletion and coarse schedules; | |
| there is no asserted policy or asserted coarse-budget estimate here. -/ | |
| theorem expected_payment (F : Family Ξ I J) (T : Transport F) {w : Ξ© β β} | |
| (hw : β Ο, 0 β€ w Ο) (R : I β FilteredRanks w) | |
| (ΞΈ : β β Ξ© β Ξ) (c : β β Ξ© β β) | |
| (H : β β Ξ© β β) (hH : β i, (R i).history=H) | |
| (hr : β t Ο z, H (t+1) Ο=H (t+1) z β H t Ο=H t z) | |
| (hΞΈ : β t Ο z, H t Ο=H t z β ΞΈ t Ο=ΞΈ t z) | |
| (hc : β t, Adapted (H t) (c t)) (hcn : β t Ο, 0 β€ c t Ο) | |
| {L : β} (hL : β ΞΈ a, a β F.domain ΞΈ β β i, |F.coefficient ΞΈ a i| β€ L) | |
| (n : β) : | |
| (β t β range n, avg w (fun Ο => c (t+1) Ο*movement | |
| (state F T ΞΈ (rankVector R) c (t+1) Ο) (state F T ΞΈ (rankVector R) c t Ο))) β€ | |
| avg w (fun Ο => F.value (ΞΈ 0 Ο) (rankVector R 0 Ο) (state F T ΞΈ (rankVector R) c 0 Ο))- | |
| avg w (fun Ο => F.value (ΞΈ n Ο) (rankVector R n Ο) (state F T ΞΈ (rankVector R) c n Ο))+ | |
| L*(β t β range n, β i, avg w (fun Ο => |(R i).p (t+1) Ο-(R i).before (t+1) Ο|))+ | |
| β t β range n, avg w (edit F T ΞΈ (rankVector R) c t) := by | |
| induction n with | |
| | zero => simp | |
| | succ n ih => | |
| simp only [sum_range_succ] | |
| have hs := expected_payment_step F T hw R ΞΈ c H hH hr hΞΈ hc hcn hL n | |
| linarith | |
| /-- Uniform endpoint removal: a bound depending only on the fixed finite | |
| family, not on the horizon or its law, contributes at most twice that bound. -/ | |
| theorem expected_payment_bounded (F : Family Ξ I J) (T : Transport F) {w : Ξ© β β} | |
| (hw : β Ο, 0 β€ w Ο) (hw1 : β Ο, w Ο=1) (R : I β FilteredRanks w) | |
| (ΞΈ : β β Ξ© β Ξ) (c : β β Ξ© β β) | |
| (H : β β Ξ© β β) (hH : β i, (R i).history=H) | |
| (hr : β t Ο z, H (t+1) Ο=H (t+1) z β H t Ο=H t z) | |
| (hΞΈ : β t Ο z, H t Ο=H t z β ΞΈ t Ο=ΞΈ t z) | |
| (hc : β t, Adapted (H t) (c t)) (hcn : β t Ο, 0 β€ c t Ο) | |
| {L B : β} (hL : β ΞΈ a, a β F.domain ΞΈ β β i, |F.coefficient ΞΈ a i| β€ L) | |
| (hB : β ΞΈ p a, a β F.domain ΞΈ β (β i, p i β Set.Icc 0 1) β |F.value ΞΈ p a| β€ B) | |
| (n : β) : | |
| (β t β range n, avg w (fun Ο => c (t+1) Ο*movement | |
| (state F T ΞΈ (rankVector R) c (t+1) Ο) (state F T ΞΈ (rankVector R) c t Ο))) β€ | |
| L*(β t β range n, β i, avg w (fun Ο => |(R i).p (t+1) Ο-(R i).before (t+1) Ο|))+ | |
| (β t β range n, avg w (edit F T ΞΈ (rankVector R) c t))+2*B := by | |
| have hb (t : β) (Ο : Ξ©) := hB (ΞΈ t Ο) (rankVector R t Ο) | |
| (state F T ΞΈ (rankVector R) c t Ο) (state_mem F T ΞΈ (rankVector R) c t Ο) | |
| (fun i => (R i).range t Ο) | |
| have htop := avg_mono hw (fun Ο => (abs_le.mp (hb 0 Ο)).2) | |
| have hbot := avg_mono hw (fun Ο => (abs_le.mp (hb n Ο)).1) | |
| rw [avg_const w hw1] at htop hbot | |
| have he := expected_payment F T hw R ΞΈ c H hH hr hΞΈ hc hcn hL n | |
| linarith | |
| /-- The rank inputs of the recursion can be instantiated directly from the | |
| actual finite hidden counts, not from a postulated martingale interface. -/ | |
| def countRanks {w : Ξ© β β} (hw : β Ο, 0 β€ w Ο) (H : β β Ξ© β β) | |
| (hr : β t Ο z, H (t+1) Ο=H (t+1) z β H t Ο=H t z) | |
| {k : β} (N : β β Ξ© β J β β) : J Γ Fin k β FilteredRanks w := | |
| fun ja => PosteriorRanks.rankProcess hw H hr (fun t Ο => N t Ο ja.1) ja.2.val | |
| omit [Fintype J] in | |
| lemma countRanks_history {w : Ξ© β β} (hw : β Ο, 0 β€ w Ο) (H : β β Ξ© β β) | |
| (hr : β t Ο z, H (t+1) Ο=H (t+1) z β H t Ο=H t z) | |
| {k : β} (N : β β Ξ© β J β β) (ja : J Γ Fin k) : | |
| (countRanks hw H hr N ja).history=H := rfl | |
| lemma countRanks_drift {w : Ξ© β β} (hw : β Ο, 0 β€ w Ο) (H : β β Ξ© β β) | |
| (hr : β t Ο z, H (t+1) Ο=H (t+1) z β H t Ο=H t z) | |
| {k : β} (N : β β Ξ© β J β β) (hN : β t Ο j, N t Ο j β€ k) (t : β) : | |
| (β ja : J Γ Fin k, avg w (fun Ο => |(countRanks hw H hr N ja).p (t+1) Ο- | |
| (countRanks hw H hr N ja).before (t+1) Ο|)) β€ | |
| avg w (fun Ο => β j, |(N (t+1) Ο j : β)-N t Ο j|) := by | |
| rw [Fintype.sum_prod_type,avg_sum_any] | |
| exact sum_le_sum fun j _ => PosteriorRanks.rankProcess_drift hw H hr | |
| (fun t Ο => N t Ο j) (fun t Ο => hN t Ο j) t | |
| /-- Hidden-count variation is controlled by the explicit edit expression. -/ | |
| theorem hidden_count_payment {k : β} (F : Family Ξ (J Γ Fin k) J) (T : Transport F) | |
| {w : Ξ© β β} (hw : β Ο, 0 β€ w Ο) (hw1 : β Ο, w Ο=1) | |
| (H : β β Ξ© β β) (hr : β t Ο z, H (t+1) Ο=H (t+1) z β H t Ο=H t z) | |
| (N : β β Ξ© β J β β) (hN : β t Ο j, N t Ο j β€ k) | |
| (ΞΈ : β β Ξ© β Ξ) (c : β β Ξ© β β) | |
| (hΞΈ : β t Ο z, H t Ο=H t z β ΞΈ t Ο=ΞΈ t z) | |
| (hc : β t, Adapted (H t) (c t)) (hcn : β t Ο, 0 β€ c t Ο) | |
| {L B : β} (hLn : 0 β€ L) | |
| (hL : β ΞΈ a, a β F.domain ΞΈ β β i, |F.coefficient ΞΈ a i| β€ L) | |
| (hB : β ΞΈ p a, a β F.domain ΞΈ β (β i, p i β Set.Icc 0 1) β |F.value ΞΈ p a| β€ B) | |
| (n : β) : | |
| let R := countRanks hw H hr N | |
| (β t β range n, avg w (fun Ο => c (t+1) Ο*movement | |
| (state F T ΞΈ (rankVector R) c (t+1) Ο) (state F T ΞΈ (rankVector R) c t Ο))) β€ | |
| L*(β t β range n, avg w (fun Ο => β j, |(N (t+1) Ο j : β)-N t Ο j|))+ | |
| (β t β range n, avg w (edit F T ΞΈ (rankVector R) c t))+2*B := by | |
| dsimp only | |
| have he := expected_payment_bounded F T hw hw1 (countRanks hw H hr N) ΞΈ c H | |
| (countRanks_history hw H hr N) hr hΞΈ hc hcn hL hB n | |
| apply he.trans | |
| gcongr | |
| exact countRanks_drift hw H hr N hN _ | |
| end KServer.AdaptiveMinimization | |
| /-! Actual zero-extension and synthetic-input operations in Β§04. In particular | |
| zero weight and singleton transitions are included, not divided away. -/ | |
| noncomputable section | |
| open scoped BigOperators | |
| open Finset | |
| namespace KServer.ChangingDomains | |
| variable {J R : Type*} [Fintype J] [DecidableEq J] [Fintype R] | |
| def variation (a b : J β β) : β := β i, |a i-b i| | |
| omit [DecidableEq J] in | |
| lemma variation_self (a : J β β) : variation a a=0 := by simp [variation] | |
| omit [DecidableEq J] in | |
| lemma variation_nonneg (a b : J β β) : 0 β€ variation a b := | |
| sum_nonneg fun _ _ => abs_nonneg _ | |
| omit [DecidableEq J] in | |
| lemma variation_triangle (a b c : J β β) : variation a c β€ variation a b+variation b c := by | |
| rw [variation,variation,variation,βsum_add_distrib] | |
| exact sum_le_sum fun i _ => abs_sub_le _ _ _ | |
| def simplex (A : Finset J) : Set (J β β) := | |
| {a | (β i, 0 β€ a i) β§ (β i, a i)=(if A.Nonempty then 1 else 0) β§ β i β A, a i=0} | |
| def canonical (A : Finset J) : J β β := | |
| if h : A.Nonempty then fun i => if i=h.choose then 1 else 0 else fun _ => 0 | |
| lemma canonical_mem (A : Finset J) : canonical A β simplex A := by | |
| classical | |
| by_cases h : A.Nonempty | |
| Β· unfold canonical simplex | |
| rw [dite_eq_left h] | |
| refine β¨fun i => by dsimp only; split_ifs <;> norm_num,?_,?_β© | |
| Β· simp [h] | |
| Β· intro i hi | |
| have hn : iβ h.choose := by intro he; subst i; exact hi h.choose_spec | |
| simp [hn] | |
| Β· simp [canonical,simplex,h] | |
| omit [DecidableEq J] in | |
| lemma simplex_coordinate {A : Finset J} {a : J β β} (ha : a β simplex A) (i : J) : | |
| a i β Set.Icc 0 1 := by | |
| refine β¨ha.1 i,?_β© | |
| have hh := single_le_sum (fun j _ => ha.1 j) (mem_univ i) | |
| rw [ha.2.1] at hh | |
| split_ifs at hh <;> linarith | |
| omit [DecidableEq J] in | |
| lemma simplex_compact (A : Finset J) : IsCompact (simplex A) := by | |
| have hc : IsClosed (simplex A) := by | |
| change IsClosed ({a : J β β | β i, 0 β€ a i} β© | |
| ({a : J β β | β i, a i=(if A.Nonempty then 1 else 0)} β© | |
| {a : J β β | β i β A, a i=0})) | |
| refine IsClosed.inter ?_ (IsClosed.inter ?_ ?_) | |
| Β· simp only [Set.ofPred_forall] | |
| exact isClosed_iInter fun i => isClosed_le continuous_const (continuous_apply i) | |
| Β· exact isClosed_eq (continuous_finsetSum _ fun i _ => continuous_apply i) continuous_const | |
| Β· simp only [Set.ofPred_forall] | |
| exact isClosed_iInter fun i => isClosed_iInter fun _ => | |
| isClosed_eq (continuous_apply i) continuous_const | |
| apply (isCompact_pi_infinite fun _ : J => isCompact_Icc (a := (0:β)) (b := 1)).of_isClosed_subset hc | |
| intro a ha i | |
| exact simplex_coordinate ha i | |
| omit [DecidableEq J] in | |
| lemma simplex_variation {A B : Finset J} {a b : J β β} | |
| (ha : a β simplex A) (hb : b β simplex B) : variation a b β€ 2 := by | |
| calc _ β€ β i, (a i+b i) := sum_le_sum fun i _ => by | |
| calc |a i-b i| β€ |a i|+|b i| := abs_sub _ _ | |
| _ = _ := by rw [abs_of_nonneg (ha.1 i),abs_of_nonneg (hb.1 i)] | |
| _ β€ 2 := by | |
| rw [sum_add_distrib,ha.2.1,hb.2.1] | |
| split_ifs <;> norm_num | |
| /-- Deletion plus zero insertion. At zero synthetic total choose a fresh | |
| canonical vector; this has exactly zero synthetic weighted movement. -/ | |
| def transposeSimplex (A : Finset J) (S : β) (a : J β β) : J β β := | |
| if S=0 then canonical A else a | |
| lemma transposeSimplex_mem {A B : Finset J} {S : β} {a v Ξ³ : J β β} | |
| (hA : A.Nonempty) (hB : B.Nonempty) (ha : a β simplex A) (hS : 0 β€ S) | |
| (hc : β i, S*a i β€ Ξ³ i*v i) (hv : β i β B, v i=0) : | |
| transposeSimplex B S a β simplex B := by | |
| by_cases hs : S=0 | |
| Β· simpa [transposeSimplex,hs] using canonical_mem B | |
| Β· have hsp : 0 < S := lt_of_le_of_ne hS (Ne.symm hs) | |
| simp only [transposeSimplex,ite_eq_right hs] | |
| refine β¨ha.1,?_,?_β© | |
| Β· simpa only [ite_eq_left hA,ite_eq_left hB] using ha.2.1 | |
| Β· intro i hi | |
| have hh := hc i | |
| rw [hv i hi,mul_zero] at hh | |
| nlinarith [ha.1 i] | |
| lemma transposeSimplex_payment (A : Finset J) (S : β) (a : J β β) : | |
| S*variation (transposeSimplex A S a) a=0 := by | |
| by_cases h : S=0 | |
| Β· simp [h] | |
| Β· simp [transposeSimplex,h,variation_self] | |
| omit [DecidableEq J] in | |
| /-- Literal Β§04 weight comparison for the prepared and final minimizers. -/ | |
| lemma prepared_weight_comparison {Aβ Aβ Aβ : Finset J} {aβ aβ aβ aβ : J β β} | |
| (haβ : aβ β simplex Aβ) (haβ : aβ β simplex Aβ) | |
| (haβ : aβ β simplex Aβ) | |
| {S T : β} (hS : 0 β€ S) (hST : S β€ T) | |
| (hzero : S*variation aβ aβ=0) : | |
| T*variation aβ aβ β€ S*variation aβ aβ+T*variation aβ aβ+4*(T-S) := by | |
| have ht := variation_triangle aβ aβ aβ | |
| have ht' := variation_triangle aβ aβ aβ | |
| have hdβ := simplex_variation haβ haβ | |
| have hdβ := simplex_variation haβ haβ | |
| have htn : 0 β€ T := hS.trans hST | |
| have hp := mul_le_mul_of_nonneg_left ht htn | |
| have hp' := mul_le_mul_of_nonneg_left ht' htn | |
| have hΞ΄ : 0 β€ T-S := sub_nonneg.mpr hST | |
| have hβ := mul_le_mul_of_nonneg_left hdβ hΞ΄ | |
| have hβ := mul_le_mul_of_nonneg_left hdβ hΞ΄ | |
| nlinarith | |
| def sideDomain (A : Finset J) (W : β) : Set (J β β) := | |
| {a | (β i, 0 β€ a i) β§ (β i, a i) β€ W β§ β i β A, a i=0} | |
| def transposeSide (A : Finset J) (a : J β β) : J β β := fun i => if iβA then a i else 0 | |
| lemma transposeSide_mem {A B : Finset J} {W : β} {a : J β β} | |
| (ha : a β sideDomain A W) : transposeSide B a β sideDomain B W := by | |
| refine β¨?_,?_,?_β© | |
| Β· intro i | |
| simp only [transposeSide] | |
| split_ifs | |
| Β· exact ha.1 i | |
| Β· exact le_rfl | |
| Β· apply le_trans _ ha.2.1 | |
| exact sum_le_sum fun i _ => by simp only [transposeSide]; split_ifs; rfl; exact ha.1 i | |
| Β· intro i hi; simp [transposeSide,hi] | |
| lemma transposeSide_payment {B : Finset J} {D : β} {a v Ξ³ : J β β} | |
| (ha : β i, 0 β€ a i) (hD : 0 β€ D) | |
| (hc : β i, D*a i β€ Ξ³ i*v i) (hv : β i β B, v i=0) : | |
| D*variation (transposeSide B a) a=0 := by | |
| by_cases hd : D=0 | |
| Β· simp [hd] | |
| Β· have hdp : 0 < D := lt_of_le_of_ne hD (Ne.symm hd) | |
| have he : transposeSide B a=a := by | |
| funext i | |
| by_cases hi : iβB | |
| Β· simp [transposeSide,hi] | |
| Β· have hh := hc i | |
| rw [hv i hi,mul_zero] at hh | |
| have haz : a i=0 := by nlinarith [ha i] | |
| simp [transposeSide,hi,haz] | |
| simp [he,variation_self] | |
| def core (f : J β R β Bool) (p : J β R β β) (i : J) : β := | |
| β a, if f i a then p i a else 0 | |
| def syntheticFlags (A B : Finset J) (f : J β R β Bool) : J β R β Bool := | |
| fun i a => if iβAβ©B then f i a else false | |
| def changedFlags (f g : J β R β Bool) : β := | |
| β i, β a, if f i a=g i a then 0 else 1 | |
| omit [Fintype J] [DecidableEq J] in | |
| lemma core_nonneg {f : J β R β Bool} {p : J β R β β} (hp : β i a, 0 β€ p i a) (i : J) : | |
| 0 β€ core f p i := by | |
| apply sum_nonneg | |
| intro a _ | |
| split_ifs | |
| Β· exact hp i a | |
| Β· rfl | |
| omit [Fintype J] in | |
| lemma synthetic_zero {A B : Finset J} (f : J β R β Bool) (p : J β R β β) | |
| {i : J} (hi : iβAβ©B) : core (syntheticFlags A B f) p i=0 := by | |
| simp [core,syntheticFlags,hi] | |
| omit [Fintype J] [Fintype R] in | |
| lemma synthetic_error_terms {A B : Finset J} {f g : J β R β Bool} | |
| {p : J β R β β} (hp : β i a, p i a β Set.Icc 0 1) | |
| (hf : β i β A, β a, f i a=false) (hg : β i β B, β a, g i a=false) | |
| (i : J) (a : R) : | |
| |(if f i a then p i a else 0)-(if syntheticFlags A B g i a then p i a else 0)| β€ | |
| (if f i a=g i a then (0:β) else 1) β§ | |
| |(if g i a then p i a else 0)-(if syntheticFlags A B g i a then p i a else 0)| β€ | |
| (if f i a=g i a then (0:β) else 1) := by | |
| have hn := (hp i a).1 | |
| have hu := (hp i a).2 | |
| by_cases hi : iβA <;> by_cases hj : iβB | |
| Β· cases hfi : f i a <;> cases hgi : g i a <;> | |
| simp [syntheticFlags,hi,hj,hgi,abs_of_nonneg hn,abs_of_nonpos (neg_nonpos.mpr hn),hu] | |
| Β· have hgi := hg i hj a | |
| cases hfi : f i a <;> | |
| simp [syntheticFlags,hi,hj,hgi,abs_of_nonneg hn,hu] | |
| Β· have hfi := hf i hi a | |
| cases hgi : g i a <;> | |
| simp [syntheticFlags,hi,hj,hfi,abs_of_nonneg hn,hu] | |
| Β· have hfi := hf i hi a | |
| have hgi := hg i hj a | |
| simp [syntheticFlags,hi,hj,hfi,hgi] | |
| /-- Both synthetic-core discrepancies are paid by the actual number of flags | |
| that changed, even when the observed rank probabilities changed drastically. -/ | |
| theorem synthetic_errors {A B : Finset J} {f g : J β R β Bool} | |
| {p : J β R β β} (hp : β i a, p i a β Set.Icc 0 1) | |
| (hf : β i β A, β a, f i a=false) (hg : β i β B, β a, g i a=false) : | |
| variation (core f p) (core (syntheticFlags A B g) p) β€ changedFlags f g β§ | |
| variation (core g p) (core (syntheticFlags A B g) p) β€ changedFlags f g := by | |
| constructor | |
| all_goals | |
| apply sum_le_sum | |
| intro i _ | |
| unfold core | |
| rw [βsum_sub_distrib] | |
| apply (abs_sum_le_sum_abs _ _).trans | |
| apply sum_le_sum | |
| intro a _ | |
| Β· exact (synthetic_error_terms hp hf hg i a).1 | |
| Β· exact (synthetic_error_terms hp hf hg i a).2 | |
| lemma synthetic_total {A B : Finset J} {g : J β R β Bool} {p : J β R β β} | |
| (hp : β i a, 0 β€ p i a) : | |
| 0 β€ (β i, core g p i)-(β i, core (syntheticFlags A B g) p i) := by | |
| apply sub_nonneg.mpr | |
| apply sum_le_sum | |
| intro i _ | |
| by_cases hi : iβAβ©B | |
| Β· simp [core,syntheticFlags,hi] | |
| Β· rw [synthetic_zero g p hi] | |
| exact core_nonneg hp i | |
| end KServer.ChangingDomains | |
| end | |
| end | |
| end OAI | |