math / data /lean /OAI /Probability /EntangledGames /RelativeEntropy.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
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