Download data/lean/OAI/Probability/EntangledGames/RelativeEntropy.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 10.6 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/EntangledGames/RelativeEntropy.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Probability/EntangledGames/RelativeEntropy.lean
-
curl -L -o RelativeEntropy.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/EntangledGames/RelativeEntropy.lean
10.6 kB
| import OAI.Probability.EntangledGames.FiniteProbability | |
| namespace OAI | |
| universe u_ΞΉ u_Ξ± u_Ξ² u_n u_m | |
| noncomputable section | |
| open scoped BigOperators ComplexOrder MatrixOrder | |
| open Matrix | |
| namespace ThresholdParallelRepetition | |
| namespace ScalarEntropy | |
| lemma negMulLog_subprob {ΞΉ : Type u_ΞΉ} [Fintype ΞΉ] | |
| (w t : ΞΉ β β) (hw : β i, 0 β€ w i) (hs : β i, w i β€ 1) | |
| (ht : β i, 0 β€ t i) : | |
| (β i, w i * Real.negMulLog (t i)) β€ Real.negMulLog (β i, w i*t i) := by | |
| let W : Option ΞΉ β β := fun i => i.elim (1-β j, w j) w | |
| let T : Option ΞΉ β β := fun i => i.elim 0 t | |
| have hW : β i, 0 β€ W i := by | |
| intro i; cases i with | |
| | none => exact sub_nonneg.mpr hs | |
| | some i => exact hw i | |
| have hsum : β i, W i = 1 := by simp [W, Fintype.sum_option] | |
| have hT : β i, T i β Set.Ici (0 : β) := by | |
| intro i; cases i with | |
| | none => change (0 : β) β€ 0; rfl | |
| | some i => exact ht i | |
| have h := Real.concaveOn_negMulLog.le_map_sum (t := Finset.univ) | |
| (w := W) (p := T) (fun i _ => hW i) hsum (fun i _ => hT i) | |
| simpa [W, T, Fintype.sum_option] using h | |
| lemma hellinger_le_entropy {t : β} (ht : 0 β€ t) : | |
| (Real.sqrt t-1)^2 β€ t*Real.log t-t+1 := by | |
| have hs := Real.sqrt_nonneg t | |
| have hsq := Real.sq_sqrt ht | |
| by_cases hz : t = 0 | |
| Β· simp [hz] | |
| have hp : 0 < Real.sqrt t := Real.sqrt_pos.mpr (lt_of_le_of_ne ht (Ne.symm hz)) | |
| have h := Real.self_sub_one_le_mul_log (le_of_lt hp) | |
| have hl : Real.log t = 2*Real.log (Real.sqrt t) := by | |
| have he : t = (Real.sqrt t)^2 := hsq.symm | |
| rw [he, Real.log_pow] | |
| norm_num | |
| rw [hl] | |
| nlinarith [mul_nonneg hs (sub_nonneg.mpr h)] | |
| lemma weighted_negMulLog_le {ΞΉ : Type u_ΞΉ} [Fintype ΞΉ] | |
| (w t : ΞΉ β β) (hw : β i, 0 β€ w i) (ht : β i, 0 β€ t i) | |
| {d p : β} (hd : 0 < d) (hs : β i, w i β€ d) (hp : 0 < p) | |
| (hm : β i, w i*t i = p) : | |
| (β i, w i*Real.negMulLog (t i)) β€ p*Real.log (d/p) := by | |
| have hw' : β i, 0 β€ w i/d := fun i => div_nonneg (hw i) hd.le | |
| have hs' : β i, w i/d β€ 1 := by rw [β Finset.sum_div]; exact (div_le_one hd).mpr hs | |
| have h := negMulLog_subprob (fun i => w i/d) t hw' hs' ht | |
| have hm' : (β i, w i/d*t i) = p/d := by | |
| simp_rw [div_mul_eq_mul_div]; rw [β Finset.sum_div, hm] | |
| rw [hm'] at h | |
| have hleft : (β i, w i/d*Real.negMulLog (t i)) = | |
| (β i, w i*Real.negMulLog (t i))/d := by | |
| simp_rw [div_mul_eq_mul_div]; rw [Finset.sum_div] | |
| rw [hleft] at h | |
| have h := (div_le_iffβ hd).mp h | |
| have he : Real.negMulLog (p/d)*d = p*Real.log (d/p) := by | |
| change -(p/d)*Real.log (p/d)*d = p*Real.log (d/p) | |
| rw [Real.log_div hp.ne' hd.ne', Real.log_div hd.ne' hp.ne'] | |
| field_simp | |
| ring | |
| exact h.trans_eq he | |
| open FiniteProbability | |
| variable {Ξ± : Type u_Ξ±} {Ξ² : Type u_Ξ²} [Fintype Ξ±] [Fintype Ξ²] | |
| lemma avg_entropy_jensen (p : Law Ξ±) (f : Ξ± β β) (hf : β x, 0 β€ f x) : | |
| p.avg f * Real.log (p.avg f) β€ p.avg (fun x => f x*Real.log (f x)) := by | |
| have h := negMulLog_subprob p.weight f p.nonneg p.total.le hf | |
| change -(β x, p.weight x*f x)*Real.log (β x, p.weight x*f x) β₯ _ at h | |
| have he : (β x, p.weight x*Real.negMulLog (f x)) = | |
| -(p.avg (fun x => f x*Real.log (f x))) := by | |
| simp only [Real.negMulLog_def, Law.avg, smul_eq_mul, mul_neg, β mul_assoc, neg_mul, | |
| Finset.sum_neg_distrib] | |
| rw [he] at h | |
| change p.avg f*Real.log (p.avg f) β€ _ | |
| dsimp only [Law.avg, smul_eq_mul] at * | |
| linarith | |
| lemma avg_entropy_nonneg (p : Law Ξ±) (f : Ξ± β β) (hf : β x, 0 β€ f x) | |
| (ht : p.avg f = 1) : 0 β€ p.avg (fun x => f x*Real.log (f x)) := by | |
| have h := avg_entropy_jensen p f hf | |
| simpa [ht] using h | |
| lemma avg_hellinger_le_entropy (p : Law Ξ±) (f : Ξ± β β) (hf : β x, 0 β€ f x) | |
| (ht : p.avg f = 1) : | |
| p.avg (fun x => (Real.sqrt (f x)-1)^2) β€ p.avg (fun x => f x*Real.log (f x)) := by | |
| have h := p.avg_mono fun x => hellinger_le_entropy (hf x) | |
| have he : p.avg (fun x => f x*Real.log (f x)-f x+1) = | |
| p.avg (fun x => f x*Real.log (f x)) := by | |
| simp only [Law.avg, smul_eq_mul, mul_add, mul_sub, mul_one, | |
| Finset.sum_add_distrib, Finset.sum_sub_distrib, p.total] | |
| change _ - p.avg f + 1 = _ | |
| rw [ht]; ring | |
| exact h.trans_eq he | |
| lemma first_density_entropy_le [DecidableEq Ξ²] (p : Law (Ξ±ΓΞ²)) (bβ : Ξ²) | |
| (f : Ξ±ΓΞ² β β) (hf : β z, 0 β€ f z) : | |
| p.first.avg (fun x => (p.givenFirst bβ x).avg (fun y => f (x,y)) * | |
| Real.log ((p.givenFirst bβ x).avg (fun y => f (x,y)))) β€ | |
| p.avg (fun z => f z*Real.log (f z)) := by | |
| rw [Law.disintegrate_first p bβ] | |
| exact p.first.avg_mono fun x => avg_entropy_jensen _ _ (fun y => hf (x,y)) | |
| lemma second_density_entropy_le [DecidableEq Ξ±] (p : Law (Ξ±ΓΞ²)) (aβ : Ξ±) | |
| (f : Ξ±ΓΞ² β β) (hf : β z, 0 β€ f z) : | |
| p.second.avg (fun y => (p.givenSecond aβ y).avg (fun x => f (x,y)) * | |
| Real.log ((p.givenSecond aβ y).avg (fun x => f (x,y)))) β€ | |
| p.avg (fun z => f z*Real.log (f z)) := by | |
| rw [Law.disintegrate_second p aβ] | |
| exact p.second.avg_mono fun y => avg_entropy_jensen _ _ (fun x => hf (x,y)) | |
| end ScalarEntropy | |
| namespace OperatorEntropy | |
| open Resolvent QuantumSampling | |
| variable {n : Type u_n} [Fintype n] [DecidableEq n] | |
| lemma effectEntropy_nonpos {A : Matrix n n β} (hA : A.PosSemidef) (hA1 : A β€ 1) : | |
| effectEntropy A β€ 0 := by | |
| rw [effectEntropy] | |
| have hz : cfc (fun _ : β => (0 : β)) A = 0 := by simp | |
| rw [β hz] | |
| apply (cfc_le_iff _ _ A (hf := Real.continuous_mul_log.continuousOn) (ha := hA.isHermitian)).mpr | |
| intro t ht | |
| have ht0 := spectrum_nonneg hA ht | |
| have ht1 : t β€ 1 := by | |
| rw [hA.isHermitian.spectrum_real_eq_range_eigenvalues] at ht | |
| obtain β¨i,rflβ© := ht | |
| exact eigenvalues_le_one hA hA1 i | |
| exact Real.mul_log_nonpos ht0 ht1 | |
| lemma spectralLinear_sum (U : Matrix n n β) (v : n β β) : | |
| spectralLinear U v = β i, v i β’ spectralLinear U (Pi.single i 1) := by | |
| have hv : v = β i, v i β’ Pi.single i (1 : β) := by | |
| ext j | |
| simp [Pi.single_apply, Finset.sum_apply] | |
| conv_lhs => rw [hv, map_sum] | |
| simp only [map_smul] | |
| lemma spectralLinear_single_pos (U : Matrix n n β) (i : n) : | |
| (spectralLinear U (Pi.single i 1)).PosSemidef := by | |
| rw [spectralLinear_apply] | |
| apply Matrix.PosSemidef.mul_mul_conjTranspose_same | |
| apply Matrix.PosSemidef.diagonal | |
| intro j | |
| simp only [Pi.single_apply] | |
| split_ifs <;> simp | |
| lemma spectralLinear_one (U : Matrix n n β) (hU : U*Uα΄΄=1) : | |
| spectralLinear U (fun _ => 1) = 1 := by | |
| simp [spectralLinear_apply, Matrix.diagonal_one, hU] | |
| lemma functional_entropy_lower (Ξ¦ : Matrix n n β ββ[β] β) | |
| (hΞ¦ : β A : Matrix n n β, A.PosSemidef β 0 β€ Ξ¦ A) | |
| (hmass : Ξ¦ 1 β€ 1) {A : Matrix n n β} (hA : A.PosSemidef) : | |
| -Ξ¦ (effectEntropy A) β€ Real.negMulLog (Ξ¦ A) := by | |
| let U : Matrix n n β := hA.isHermitian.eigenvectorUnitary | |
| let w : n β β := fun i => Ξ¦ (spectralLinear U (Pi.single i 1)) | |
| have hw : β i, 0 β€ w i := fun i => hΞ¦ _ (spectralLinear_single_pos U i) | |
| have hU : U*Uα΄΄=1 := Unitary.mul_star_self_of_mem hA.isHermitian.eigenvectorUnitary.property | |
| have hone : β i, w i = Ξ¦ 1 := by | |
| rw [β spectralLinear_one U hU, spectralLinear_sum] | |
| simp only [map_sum, map_smul, smul_eq_mul, one_mul, w] | |
| have heval (f : β β β) : Ξ¦ (cfc f A) = β i, w i*f (hA.isHermitian.eigenvalues i) := by | |
| rw [cfc_eq_spectralLinear hA.isHermitian, spectralLinear_sum, map_sum] | |
| simp only [map_smul, smul_eq_mul] | |
| apply Finset.sum_congr rfl | |
| intro i _ | |
| exact mul_comm _ _ | |
| have hid : Ξ¦ A = β i, w i*hA.isHermitian.eigenvalues i := by | |
| have h := heval id | |
| erw [cfc_id' β A hA.isHermitian] at h | |
| exact h | |
| have hh := ScalarEntropy.negMulLog_subprob w hA.isHermitian.eigenvalues hw | |
| (hone.trans_le hmass) hA.eigenvalues_nonneg | |
| rw [β hid] at hh | |
| rw [effectEntropy, heval] | |
| convert hh using 1 | |
| simp only [Real.negMulLog_def, mul_neg, neg_mul, Finset.sum_neg_distrib] | |
| variable {m : Type u_m} [Fintype m] [DecidableEq m] | |
| omit [DecidableEq n] [DecidableEq m] in | |
| lemma prob_smul_left (C : Matrix m n β) (r : β) (A : Matrix m m β) (B : Matrix n n β) : | |
| prob C (r β’ A) B = r*prob C A B := by | |
| simp [prob, eval_eq_trace, Matrix.smul_mul, Matrix.mul_smul, Matrix.trace_smul] | |
| omit [DecidableEq n] [DecidableEq m] in | |
| lemma prob_smul_right (C : Matrix m n β) (r : β) (A : Matrix m m β) (B : Matrix n n β) : | |
| prob C A (r β’ B) = r*prob C A B := by | |
| simp [prob, eval_eq_trace, Matrix.transpose_smul, Matrix.mul_smul, Matrix.trace_smul] | |
| def probLeft (C : Matrix m n β) (B : Matrix n n β) : Matrix m m β ββ[β] β where | |
| toFun A := prob C A B | |
| map_add' A A' := prob_add_left C A A' B | |
| map_smul' r A := prob_smul_left C r A B | |
| def probRight (C : Matrix m n β) (A : Matrix m m β) : Matrix n n β ββ[β] β where | |
| toFun B := prob C A B | |
| map_add' B B' := prob_add_right C A B B' | |
| map_smul' r B := prob_smul_right C r A B | |
| omit [DecidableEq n] [DecidableEq m] in | |
| lemma prob_mono_left (C : Matrix m n β) {A A' : Matrix m m β} {B : Matrix n n β} | |
| (hB : B.PosSemidef) (hA : A β€ A') : prob C A B β€ prob C A' B := by | |
| have h := prob_nonneg (C := C) (show (A'-A).PosSemidef from Matrix.nonneg_iff_posSemidef.mp (sub_nonneg.mpr hA)) hB | |
| rw [prob_sub_left] at h | |
| linarith | |
| omit [DecidableEq n] [DecidableEq m] in | |
| lemma prob_mono_right (C : Matrix m n β) {A : Matrix m m β} {B B' : Matrix n n β} | |
| (hA : A.PosSemidef) (hB : B β€ B') : prob C A B β€ prob C A B' := by | |
| have h := prob_nonneg (C := C) hA (show (B'-B).PosSemidef from Matrix.nonneg_iff_posSemidef.mp (sub_nonneg.mpr hB)) | |
| rw [prob_sub_right] at h | |
| linarith | |
| lemma prob_entropy_left_lower (C : Matrix m n β) (hC : hsSq C β€ 1) | |
| {A : Matrix m m β} {B : Matrix n n β} (hA : A.PosSemidef) | |
| (hB : B.PosSemidef) (hB1 : B β€ 1) : | |
| -prob C (effectEntropy A) B β€ Real.negMulLog (prob C A B) := by | |
| apply functional_entropy_lower (probLeft C B) (fun T hT => prob_nonneg hT hB) _ hA | |
| exact ((prob_mono_right C Matrix.PosSemidef.one hB1).trans_eq (prob_one C)).trans hC | |
| lemma prob_entropy_right_lower (C : Matrix m n β) (hC : hsSq C β€ 1) | |
| {A : Matrix m m β} {B : Matrix n n β} (hA : A.PosSemidef) | |
| (hA1 : A β€ 1) (hB : B.PosSemidef) : | |
| -prob C A (effectEntropy B) β€ Real.negMulLog (prob C A B) := by | |
| apply functional_entropy_lower (probRight C A) (fun T hT => prob_nonneg hA hT) _ hB | |
| exact ((prob_mono_left C Matrix.PosSemidef.one hA1).trans_eq (prob_one C)).trans hC | |
| end OperatorEntropy | |
| end ThresholdParallelRepetition | |
| end | |
| end OAI | |