Download data/lean/OAI/Computability/BinPacking/Information/SideInformation.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 16.6 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/BinPacking/Information/SideInformation.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Computability/BinPacking/Information/SideInformation.lean
-
curl -L -o SideInformation.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/BinPacking/Information/SideInformation.lean
16.6 kB
| import Mathlib.Data.Fintype.BigOperators | |
| import Mathlib.Data.Fintype.Pi | |
| import OAI.Computability.BinPacking.Information.GamesAdapter | |
| namespace OAI | |
| namespace BinPackingGames.Foundations.Information | |
| section | |
| open scoped BigOperators | |
| variable {ΞΉ Ξ± : Type*} [Fintype ΞΉ] [Fintype Ξ±] [DecidableEq ΞΉ] | |
| noncomputable def coordinateMarginal (p : (ΞΉ β Ξ±) β β) (i : ΞΉ) (a : Ξ±) : β := by | |
| classical | |
| exact β x, if x i = a then p x else 0 | |
| noncomputable def independentProduct (q : ΞΉ β Ξ± β β) (x : ΞΉ β Ξ±) : β := β i, q i (x i) | |
| theorem coordinateMarginal_isProbability (p : (ΞΉ β Ξ±) β β) (hp : IsProbability p) (i : ΞΉ) : | |
| IsProbability (coordinateMarginal p i) := by | |
| classical | |
| constructor | |
| Β· intro a | |
| apply Finset.sum_nonneg | |
| intro x _ | |
| split_ifs | |
| Β· exact hp.1 x | |
| Β· exact le_rfl | |
| Β· simp only [coordinateMarginal] | |
| rw [Finset.sum_comm] | |
| simpa using hp.2 | |
| theorem point_le_coordinateMarginal (p : (ΞΉ β Ξ±) β β) (hp : IsProbability p) | |
| (i : ΞΉ) (x : ΞΉ β Ξ±) : p x β€ coordinateMarginal p i (x i) := by | |
| classical | |
| have h := Finset.single_le_sum | |
| (f := fun y : ΞΉ β Ξ± => if y i = x i then p y else 0) | |
| (fun y _ => by split_ifs; exact hp.1 y; exact le_rfl) (Finset.mem_univ x) | |
| simpa [coordinateMarginal] using h | |
| theorem marginal_expectation (p : (ΞΉ β Ξ±) β β) (i : ΞΉ) (f : Ξ± β β) : | |
| (β x, p x * f (x i)) = β a, coordinateMarginal p i a * f a := by | |
| classical | |
| simp only [coordinateMarginal, Finset.sum_mul] | |
| rw [Finset.sum_comm] | |
| apply Finset.sum_congr rfl | |
| intro x _ | |
| simp [ite_mul] | |
| theorem independentProduct_isProbability (q : ΞΉ β Ξ± β β) (hq : β i, IsProbability (q i)) : | |
| IsProbability (independentProduct q) := by | |
| classical | |
| constructor | |
| Β· intro x | |
| exact Finset.prod_nonneg (fun i _ => (hq i).1 (x i)) | |
| Β· simp only [independentProduct, β Fintype.prod_sum, (hq _).2, Finset.prod_const_one] | |
| theorem joint_supportedBy_product_coordinateMarginals (p : (ΞΉ β Ξ±) β β) | |
| (hp : IsProbability p) : SupportedBy p (independentProduct (coordinateMarginal p)) := by | |
| intro x hx | |
| apply Finset.prod_ne_zero_iff.mpr | |
| intro i _ | |
| exact ne_of_gt ((lt_of_le_of_ne (hp.1 x) (Ne.symm hx)).trans_le | |
| (point_le_coordinateMarginal p hp i x)) | |
| theorem relativeEntropy_independent_reference (p : (ΞΉ β Ξ±) β β) (q : ΞΉ β Ξ± β β) | |
| (hp : IsProbability p) (_hq : β i, IsProbability (q i)) | |
| (hs : β i, SupportedBy (coordinateMarginal p i) (q i)) : | |
| relativeEntropy p (independentProduct q) = | |
| relativeEntropy p (independentProduct (coordinateMarginal p)) + | |
| β i, relativeEntropy (coordinateMarginal p i) (q i) := by | |
| classical | |
| have hpoint : β x : ΞΉ β Ξ±, p x * Real.log (p x / independentProduct q x) = | |
| p x * Real.log (p x / independentProduct (coordinateMarginal p) x) + | |
| β i, p x * Real.log (coordinateMarginal p i (x i) / q i (x i)) := by | |
| intro x | |
| by_cases hx : p x = 0 | |
| Β· simp [hx] | |
| have hm : β i, coordinateMarginal p i (x i) β 0 := by | |
| intro i | |
| exact ne_of_gt ((lt_of_le_of_ne (hp.1 x) (Ne.symm hx)).trans_le | |
| (point_le_coordinateMarginal p hp i x)) | |
| have hqne : β i, q i (x i) β 0 := fun i => hs i (x i) (hm i) | |
| have hmp : (β i, coordinateMarginal p i (x i)) β 0 := | |
| Finset.prod_ne_zero_iff.mpr (fun i _ => hm i) | |
| have hqp : (β i, q i (x i)) β 0 := | |
| Finset.prod_ne_zero_iff.mpr (fun i _ => hqne i) | |
| simp only [independentProduct, Real.log_div hx hmp, Real.log_div hx hqp, | |
| Real.log_prod (fun i _ => hm i), Real.log_prod (fun i _ => hqne i)] | |
| simp_rw [Real.log_div (hm _) (hqne _)] | |
| rw [β Finset.mul_sum, Finset.sum_sub_distrib] | |
| ring | |
| calc | |
| relativeEntropy p (independentProduct q) = | |
| β x, (p x * Real.log (p x / independentProduct (coordinateMarginal p) x) + | |
| β i, p x * Real.log (coordinateMarginal p i (x i) / q i (x i))) := by | |
| exact Finset.sum_congr rfl (fun x _ => hpoint x) | |
| _ = relativeEntropy p (independentProduct (coordinateMarginal p)) + | |
| β i, β x, p x * Real.log (coordinateMarginal p i (x i) / q i (x i)) := by | |
| rw [Finset.sum_add_distrib, Finset.sum_comm] | |
| rfl | |
| _ = relativeEntropy p (independentProduct (coordinateMarginal p)) + | |
| β i, relativeEntropy (coordinateMarginal p i) (q i) := by | |
| congr 1 | |
| apply Finset.sum_congr rfl | |
| intro i _ | |
| exact marginal_expectation p i (fun a => Real.log (coordinateMarginal p i a / q i a)) | |
| theorem coordinate_relativeEntropy_sum_le (p : (ΞΉ β Ξ±) β β) (q : ΞΉ β Ξ± β β) | |
| (hp : IsProbability p) (hq : β i, IsProbability (q i)) | |
| (hs : β i, SupportedBy (coordinateMarginal p i) (q i)) : | |
| (β i, relativeEntropy (coordinateMarginal p i) (q i)) β€ | |
| relativeEntropy p (independentProduct q) := by | |
| rw [relativeEntropy_independent_reference p q hp hq hs] | |
| exact le_add_of_nonneg_left (relativeEntropy_nonneg _ _ hp | |
| (independentProduct_isProbability _ (coordinateMarginal_isProbability p hp)) | |
| (joint_supportedBy_product_coordinateMarginals p hp)) | |
| theorem coordinate_totalVariation_sq_sum_le (p : (ΞΉ β Ξ±) β β) (q : ΞΉ β Ξ± β β) | |
| (hp : IsProbability p) (hq : β i, IsProbability (q i)) | |
| (hs : β i, SupportedBy (coordinateMarginal p i) (q i)) : | |
| (β i, totalVariation (coordinateMarginal p i) (q i) ^ 2) β€ | |
| relativeEntropy p (independentProduct q) := by | |
| exact (Finset.sum_le_sum (fun i _ => totalVariation_sq_le_relativeEntropy _ _ | |
| (coordinateMarginal_isProbability p hp i) (hq i) (hs i))).trans | |
| (coordinate_relativeEntropy_sum_le p q hp hq hs) | |
| theorem posterior_coordinate_supportedBy (q : ΞΉ β Ξ± β β) (w : (ΞΉ β Ξ±) β β) | |
| (z : β) (i : ΞΉ) : | |
| SupportedBy (coordinateMarginal (posterior (independentProduct q) w z) i) (q i) := by | |
| classical | |
| intro a ha hqa | |
| apply ha | |
| unfold coordinateMarginal | |
| apply Finset.sum_eq_zero | |
| intro x _ | |
| by_cases hxa : x i = a | |
| Β· have hzprod : independentProduct q x = 0 := by | |
| exact Finset.prod_eq_zero (Finset.mem_univ i) (by simpa only [hxa] using hqa) | |
| simp [hxa, posterior, hzprod] | |
| Β· simp [hxa] | |
| theorem posterior_coordinate_totalVariation_sq_sum_le_log | |
| (q : ΞΉ β Ξ± β β) (hq : β i, IsProbability (q i)) (w : (ΞΉ β Ξ±) β β) | |
| (hw : β x, 0 β€ w x) (hw_one : β x, w x β€ 1) {z : β} (hz : 0 < z) | |
| (hmass : β x, independentProduct q x * w x = z) : | |
| (β i, totalVariation | |
| (coordinateMarginal (posterior (independentProduct q) w z) i) (q i) ^ 2) β€ | |
| Real.log (1 / z) := by | |
| have hp := independentProduct_isProbability q hq | |
| exact (coordinate_totalVariation_sq_sum_le _ q | |
| (posterior_isProbability _ w hp hw hz hmass) hq | |
| (posterior_coordinate_supportedBy q w z)).trans | |
| (posterior_relativeEntropy_le _ w hp hw hw_one hz hmass) | |
| theorem posterior_coordinate_totalVariation_sum_le_sqrt | |
| (q : ΞΉ β Ξ± β β) (hq : β i, IsProbability (q i)) (w : (ΞΉ β Ξ±) β β) | |
| (hw : β x, 0 β€ w x) (hw_one : β x, w x β€ 1) {z : β} (hz : 0 < z) | |
| (hmass : β x, independentProduct q x * w x = z) : | |
| (β i, totalVariation | |
| (coordinateMarginal (posterior (independentProduct q) w z) i) (q i)) β€ | |
| Real.sqrt ((Fintype.card ΞΉ : β) * Real.log (1 / z)) := by | |
| let d : ΞΉ β β := fun i => totalVariation | |
| (coordinateMarginal (posterior (independentProduct q) w z) i) (q i) | |
| have hsq := posterior_coordinate_totalVariation_sq_sum_le_log q hq w hw hw_one hz hmass | |
| have hcs := Finset.sum_mul_sq_le_sq_mul_sq (Finset.univ : Finset ΞΉ) d (fun _ => (1 : β)) | |
| simp only [mul_one, one_pow, Finset.sum_const, Finset.card_univ, nsmul_eq_mul, mul_one] at hcs | |
| have hln : 0 β€ Real.log (1 / z) := by | |
| have hp := independentProduct_isProbability q hq | |
| exact (relativeEntropy_nonneg _ _ (posterior_isProbability _ w hp hw hz hmass) hp | |
| (posterior_supportedBy _ w z)).trans | |
| (posterior_relativeEntropy_le _ w hp hw hw_one hz hmass) | |
| have hcard : 0 β€ (Fintype.card ΞΉ : β) := Nat.cast_nonneg _ | |
| have hmul := mul_le_mul_of_nonneg_left hsq hcard | |
| have hsqrt := Real.sq_sqrt (mul_nonneg hcard hln) | |
| have hsqrtpos := Real.sqrt_nonneg ((Fintype.card ΞΉ : β) * Real.log (1 / z)) | |
| change (β i, d i) β€ _ | |
| change (β i, d i ^ 2) β€ _ at hsq | |
| change (Fintype.card ΞΉ : β) * (β i, d i ^ 2) β€ _ at hmul | |
| nlinarith | |
| theorem posterior_coordinate_totalVariation_sq_sum_le_binaryLog | |
| (q : ΞΉ β Ξ± β β) (hq : β i, IsProbability (q i)) (w : (ΞΉ β Ξ±) β β) | |
| (hw : β x, 0 β€ w x) (hw_one : β x, w x β€ 1) {z : β} (hz : 0 < z) | |
| (hmass : β x, independentProduct q x * w x = z) : | |
| (β i, totalVariation | |
| (coordinateMarginal (posterior (independentProduct q) w z) i) (q i) ^ 2) β€ | |
| Real.log (1 / z) / Real.log 2 := by | |
| exact le_binaryLog_of_le_log (Finset.sum_nonneg (fun _ _ => sq_nonneg _)) | |
| (posterior_coordinate_totalVariation_sq_sum_le_log q hq w hw hw_one hz hmass) | |
| end | |
| open scoped BigOperators | |
| noncomputable def posteriorOrOriginal | |
| {A : Type*} [Fintype A] (p e : A β β) (z : β) : A β β := by | |
| classical | |
| exact if 0 < z then posterior p e z else p | |
| theorem posteriorOrOriginal_isProbability | |
| {A : Type*} [Fintype A] (p e : A β β) | |
| (hp : IsProbability p) (he : β a, 0 β€ e a) | |
| {z : β} (hmass : β a, p a * e a = z) : | |
| IsProbability (posteriorOrOriginal p e z) := by | |
| classical | |
| by_cases hz : 0 < z | |
| Β· simpa only [posteriorOrOriginal, ite_eq_left hz] using | |
| posterior_isProbability p e hp he hz hmass | |
| Β· simpa only [posteriorOrOriginal, ite_eq_right hz] using hp | |
| theorem mass_mul_posteriorOrOriginal | |
| {A : Type*} [Fintype A] (p e : A β β) | |
| (hp : IsProbability p) (he : β a, 0 β€ e a) | |
| {c : β} (hmass : β a, p a * e a = c) (x : A) : | |
| c * posteriorOrOriginal p e c x = p x * e x := by | |
| classical | |
| by_cases hc : 0 < c | |
| Β· simp only [posteriorOrOriginal, ite_eq_left hc, posterior] | |
| field_simp [hc.ne'] | |
| Β· have hcnonneg : 0 β€ c := by | |
| rw [β hmass] | |
| exact Finset.sum_nonneg (fun a _ => mul_nonneg (hp.1 a) (he a)) | |
| have hc0 : c = 0 := le_antisymm (le_of_not_gt hc) hcnonneg | |
| have hpoint := Finset.single_le_sum | |
| (fun a (_ : a β (Finset.univ : Finset A)) => mul_nonneg (hp.1 a) (he a)) | |
| (Finset.mem_univ x) | |
| rw [hmass, hc0] at hpoint | |
| have hzero : p x * e x = 0 := le_antisymm hpoint (mul_nonneg (hp.1 x) (he x)) | |
| simp [posteriorOrOriginal, hc0, hzero] | |
| theorem weighted_coordinate_posterior_recombine | |
| {I A : Type*} [Fintype I] [Fintype A] [DecidableEq I] [DecidableEq A] | |
| (p e : (I β A) β β) (hp : IsProbability p) (he : β x, 0 β€ e x) | |
| {c : β} (hmass : β x, p x * e x = c) (b z : β) (i : I) (a : A) : | |
| (b * c / z) * coordinateMarginal (posteriorOrOriginal p e c) i a = | |
| (b / z) * β x, if x i = a then p x * e x else 0 := by | |
| classical | |
| simp only [coordinateMarginal, Finset.mul_sum] | |
| apply Finset.sum_congr rfl | |
| intro x _ | |
| by_cases hxa : x i = a | |
| Β· simp only [ite_eq_left hxa] | |
| calc | |
| (b * c / z) * posteriorOrOriginal p e c x = | |
| (b / z) * (c * posteriorOrOriginal p e c x) := by ring | |
| _ = (b / z) * (p x * e x) := by | |
| rw [mass_mul_posteriorOrOriginal p e hp he hmass x] | |
| Β· simp [hxa] | |
| variable {J I A : Type*} | |
| variable [Fintype J] [Fintype I] [Fintype A] [DecidableEq I] | |
| theorem side_information_bound | |
| (w b c : J β β) | |
| (q : J β I β A β β) | |
| (e : J β (I β A) β β) | |
| (hw : IsProbability w) | |
| (hb : β j, 0 β€ b j) | |
| (hq : β j i, IsProbability (q j i)) | |
| (he : β j x, 0 β€ e j x) | |
| (he_one : β j x, e j x β€ 1) | |
| (hmass : β j, β x, independentProduct (q j) x * e j x = c j) | |
| {z B : β} (hz : 0 < z) (hB : 0 < B) | |
| (hbase : β j, b j = B) | |
| (hweight : β j, w j = b j * c j / z) : | |
| (β i, totalVariation | |
| (fun ja : J Γ A => w ja.1 * coordinateMarginal | |
| (posteriorOrOriginal (independentProduct (q ja.1)) | |
| (e ja.1) (c ja.1)) i ja.2) | |
| (fun ja : J Γ A => w ja.1 * q ja.1 i ja.2)) β€ | |
| Real.sqrt ((Fintype.card I : β) * Real.log (B / z)) := by | |
| classical | |
| let d : J β I β β := fun j i => totalVariation | |
| (coordinateMarginal | |
| (posteriorOrOriginal (independentProduct (q j)) (e j) (c j)) i) | |
| (q j i) | |
| have hbudget : β j, | |
| w j * (β i, d j i ^ 2) β€ w j * Real.log (1 / c j) := by | |
| intro j | |
| by_cases hwzero : w j = 0 | |
| Β· simp [hwzero] | |
| have hcne : c j β 0 := by | |
| intro hczero | |
| apply hwzero | |
| rw [hweight j, hczero, mul_zero, zero_div] | |
| have hcnonneg : 0 β€ c j := by | |
| rw [β hmass j] | |
| exact Finset.sum_nonneg (fun x _ => mul_nonneg | |
| ((independentProduct_isProbability (q j) (hq j)).1 x) (he j x)) | |
| have hcpos : 0 < c j := lt_of_le_of_ne hcnonneg (Ne.symm hcne) | |
| have hlocal := posterior_coordinate_totalVariation_sq_sum_le_log | |
| (q j) (hq j) (e j) (he j) (he_one j) hcpos (hmass j) | |
| have hweighted := mul_le_mul_of_nonneg_left hlocal (hw.1 j) | |
| simpa only [d, posteriorOrOriginal, ite_eq_left hcpos] using hweighted | |
| have hcs := weighted_coordinate_sum_sq_le | |
| w d (fun j => Real.log (1 / c j)) hw hbudget | |
| have hlog := posterior_weighted_log_inverse_le w b c hw hb hz hB hbase hweight | |
| have hsq : (β i, β j, w j * d j i)^2 β€ | |
| (Fintype.card I : β) * Real.log (B / z) := | |
| hcs.trans (mul_le_mul_of_nonneg_left hlog (Nat.cast_nonneg _)) | |
| have htv : β i, totalVariation | |
| (fun ja : J Γ A => w ja.1 * coordinateMarginal | |
| (posteriorOrOriginal (independentProduct (q ja.1)) | |
| (e ja.1) (c ja.1)) i ja.2) | |
| (fun ja : J Γ A => w ja.1 * q ja.1 i ja.2) = | |
| β j, w j * d j i := by | |
| intro i | |
| exact totalVariation_joint_common_weights w | |
| (fun j => coordinateMarginal | |
| (posteriorOrOriginal (independentProduct (q j)) (e j) (c j)) i) | |
| (fun j => q j i) hw.1 | |
| simp_rw [htv] | |
| have hradicand : 0 β€ (Fintype.card I : β) * Real.log (B / z) := | |
| (sq_nonneg _).trans hsq | |
| have hsqrt := Real.sq_sqrt hradicand | |
| have hsqrt_nonneg := Real.sqrt_nonneg ((Fintype.card I : β) * Real.log (B / z)) | |
| nlinarith | |
| variable {T V : Type*} [Fintype T] [Fintype V] [Nonempty V] | |
| theorem finite_side_information_bound | |
| (pT : T β β) (q : T β I β A β β) | |
| (e : T Γ V β (I β A) β β) (c w : T Γ V β β) | |
| (hpT : IsProbability pT) | |
| (hq : β t i, IsProbability (q t i)) | |
| (he : β tv x, 0 β€ e tv x) | |
| (he_sum : β t x, (β v, e (t, v) x) β€ 1) | |
| (hc : β tv, β x, independentProduct (q tv.1) x * e tv x = c tv) | |
| {z : β} (hz : 0 < z) | |
| (hZ : β tv, pT tv.1 * c tv = z) | |
| (hweight : β tv, w tv = pT tv.1 * c tv / z) : | |
| (β i, totalVariation | |
| (fun tva : (T Γ V) Γ A => w tva.1 * coordinateMarginal | |
| (posteriorOrOriginal (independentProduct (q tva.1.1)) | |
| (e tva.1) (c tva.1)) i tva.2) | |
| (fun tva : (T Γ V) Γ A => w tva.1 * q tva.1.1 i tva.2)) β€ | |
| Real.sqrt ((Fintype.card I : β) * | |
| (Real.log (Fintype.card V : β) + Real.log (1 / z))) := by | |
| classical | |
| have hcnonneg : β tv, 0 β€ c tv := by | |
| intro tv | |
| rw [β hc tv] | |
| exact Finset.sum_nonneg (fun x _ => mul_nonneg | |
| ((independentProduct_isProbability (q tv.1) (hq tv.1)).1 x) (he tv x)) | |
| have hw : IsProbability w := by | |
| constructor | |
| Β· intro tv | |
| rw [hweight tv] | |
| exact div_nonneg (mul_nonneg (hpT.1 tv.1) (hcnonneg tv)) hz.le | |
| Β· simp_rw [hweight, div_eq_mul_inv] | |
| rw [β Finset.sum_mul, hZ, mul_inv_cancelβ hz.ne'] | |
| have he_one : β tv x, e tv x β€ 1 := by | |
| intro tv x | |
| have hsingle : e tv x β€ β v, e (tv.1, v) x := | |
| Finset.single_le_sum (fun v _ => he (tv.1, v) x) (Finset.mem_univ tv.2) | |
| exact hsingle.trans (he_sum tv.1 x) | |
| have hB : 0 < (Fintype.card V : β) := Nat.cast_pos.mpr Fintype.card_pos | |
| have hbase : (β tv : T Γ V, pT tv.1) = (Fintype.card V : β) := by | |
| simp only [Fintype.sum_prod_type, Finset.sum_const, Finset.card_univ, | |
| nsmul_eq_mul, β Finset.mul_sum, hpT.2, mul_one] | |
| have h := side_information_bound w (fun tv : T Γ V => pT tv.1) c | |
| (fun tv => q tv.1) e hw (fun tv => hpT.1 tv.1) (fun tv => hq tv.1) | |
| he he_one hc hz hB hbase hweight | |
| have hlog : Real.log ((Fintype.card V : β) / z) = | |
| Real.log (Fintype.card V : β) + Real.log (1 / z) := by | |
| rw [Real.log_div hB.ne' hz.ne', Real.log_div one_ne_zero hz.ne', Real.log_one] | |
| ring | |
| simpa only [hlog] using h | |
| end BinPackingGames.Foundations.Information | |
| end OAI | |