Holevo Additivity Gap in Lean 4

Lean explorer

Exact Lean source

Nonadditivity.QuantumCodingTypicality

Download original .lean · View on GitHub · Jump to source

Direct imports

  • Nonadditivity.Entropy
  • Mathlib.Algebra.BigOperators.Ring.Finset dependency
  • Mathlib.Logic.Equiv.Fin.Basic dependency

Imported by project modules

3 direct reverse imports

Relationships above come from literal import commands. The declarations below link to types and references extracted from Lean’s environment. Source text is complete and unchanged.

Declarations in this module

69 project constants, including generated, internal and private declarations.

69 declarations

Full module

1/-2Copyright (c) 2026 the Nonadditivity project contributors.3All rights reserved. See COPYRIGHT.md for licensing and attribution.4-/56import Nonadditivity.Entropy7import Mathlib.Algebra.BigOperators.Ring.Finset8import Mathlib.Logic.Equiv.Fin.Basic910/-! # Finite independent sampling and entropy typicality1112All expectations below are literal finite sums against the product law.13Zeros in the single-letter distribution are allowed; their words have zero14weight, so no full-support assumption is needed.15-/16noncomputable section17namespace Nonadditivity.QuantumCodingTypicality18open scoped BigOperators19variable {ι : Type*} [Fintype ι]2021def wordProbability (p : ι → ℝ) (n : ℕ) (x : Fin n → ι) : ℝ := ∏ i, p (x i)2223def wordSum (f : ι → ℝ) (n : ℕ) (x : Fin n → ι) : ℝ := ∑ i, f (x i)2425def expectation (p : ι → ℝ) (n : ℕ) (f : (Fin n → ι) → ℝ) : ℝ :=26  ∑ x, wordProbability p n x * f x2728def entropy (p : ι → ℝ) : ℝ := Entropy.shannon p2930def information (p : ι → ℝ) (i : ι) : ℝ := -Real.log (p i)3132def surprisal (p : ι → ℝ) (n : ℕ) : (Fin n → ι) → ℝ := wordSum (information p) n3334def variance (p : ι → ℝ) : ℝ := ∑ i, p i * (information p i - entropy p)^23536def wordConsEquiv (n : ℕ) : ι × (Fin n → ι) ≃ (Fin (n+1) → ι) where37  toFun x := Fin.cons x.1 x.238  invFun x := (x 0, fun i => x i.succ)39  left_inv x := by cases x; rfl40  right_inv x := by funext i; exact Fin.cases rfl (fun j => rfl) i4142theorem sum_words_succ (n : ℕ) (f : (Fin (n+1) → ι) → ℝ) :43    ∑ x, f x = ∑ a, ∑ x, f (Fin.cons a x) := by44  rw [←(wordConsEquiv (ι := ι) n).sum_comp f]45  simp only [Fintype.sum_prod_type, wordConsEquiv, Equiv.coe_fn_mk]4647omit [Fintype ι] in48@[simp] theorem wordProbability_cons (p : ι → ℝ) (n : ℕ) (a : ι) (x : Fin n → ι) :49    wordProbability p (n+1) (Fin.cons a x) = p a * wordProbability p n x := by50  simp [wordProbability, Fin.prod_univ_succ]5152omit [Fintype ι] in53@[simp] theorem wordSum_cons (f : ι → ℝ) (n : ℕ) (a : ι) (x : Fin n → ι) :54    wordSum f (n+1) (Fin.cons a x) = f a + wordSum f n x := by55  simp [wordSum, Fin.sum_univ_succ]5657omit [Fintype ι] in58theorem wordProbability_nonneg (p : ι → ℝ) (hp : ∀ i, 0 ≤ p i)59    (n : ℕ) (x : Fin n → ι) : 0 ≤ wordProbability p n x :=60  Finset.prod_nonneg (fun i _ => hp (x i))6162theorem sum_wordProbability (p : ι → ℝ) (hp : ∑ i, p i = 1) (n : ℕ) :63    ∑ x, wordProbability p n x = 1 := by64  induction n with65  | zero => simp [wordProbability]66  | succ n ih =>67    rw [sum_words_succ]68    simp_rw [wordProbability_cons, ←Finset.mul_sum, ih, mul_one]69    exact hp7071theorem expectation_const (p : ι → ℝ) (hp : ∑ i, p i = 1) (n : ℕ) (c : ℝ) :72    expectation p n (fun _ => c) = c := by73  simp only [expectation, ←Finset.sum_mul, sum_wordProbability p hp, one_mul]7475theorem expectation_add (p : ι → ℝ) (n : ℕ) (f g : (Fin n → ι) → ℝ) :76    expectation p n (fun x => f x + g x) = expectation p n f + expectation p n g := by77  simp only [expectation, mul_add, Finset.sum_add_distrib]7879theorem expectation_mul_const (p : ι → ℝ) (n : ℕ) (f : (Fin n → ι) → ℝ) (c : ℝ) :80    expectation p n (fun x => f x * c) = expectation p n f * c := by81  simp only [expectation, ←mul_assoc, Finset.sum_mul]8283theorem expectation_succ (p : ι → ℝ) (n : ℕ) (f : (Fin (n+1) → ι) → ℝ) :84    expectation p (n+1) f = ∑ a, p a * expectation p n (fun x => f (Fin.cons a x)) := by85  unfold expectation86  rw [sum_words_succ]87  simp only [wordProbability_cons, mul_assoc, Finset.mul_sum]8889theorem expectation_wordSum (p f : ι → ℝ) (hp : ∑ i, p i = 1) (n : ℕ) :90    expectation p n (wordSum f n) = n * ∑ i, p i * f i := by91  induction n with92  | zero => simp [expectation, wordSum]93  | succ n ih =>94    rw [expectation_succ]95    simp only [wordSum_cons, expectation_add, expectation_const p hp, ih,96      mul_add, Finset.sum_add_distrib, ←Finset.sum_mul, hp, one_mul, Nat.cast_add,97      Nat.cast_one]98    ring99100theorem expectation_wordSum_sq_of_centered (p f : ι → ℝ) (hp : ∑ i, p i = 1)101    (hf : ∑ i, p i * f i = 0) (n : ℕ) :102    expectation p n (fun x => (wordSum f n x)^2) = n * ∑ i, p i * (f i)^2 := by103  induction n with104  | zero => simp [expectation, wordSum]105  | succ n ih =>106    rw [expectation_succ]107    have he (a : ι) : expectation p n (fun x => (wordSum f (n+1) (Fin.cons a x))^2) =108        (f a)^2 + n * ∑ i, p i * (f i)^2 := by109      simp only [wordSum_cons]110      have hpoly : (fun x : Fin n → ι => (f a + wordSum f n x)^2) =111          (fun x => (f a)^2 + wordSum f n x * (2*f a) + (wordSum f n x)^2) := by112        funext x113        ring114      rw [hpoly, expectation_add, expectation_add, expectation_const p hp,115        expectation_mul_const, expectation_wordSum p f hp, hf, mul_zero, zero_mul,116        add_zero, ih]117    simp_rw [he, mul_add, Finset.sum_add_distrib, ←Finset.sum_mul, hp, one_mul]118    push_cast119    ring120121theorem information_mean (p : ι → ℝ) : ∑ i, p i * information p i = entropy p := by122  simp only [information, entropy, Entropy.shannon, mul_neg, Finset.sum_neg_distrib]123124theorem information_centered (p : ι → ℝ) (hp : ∑ i, p i = 1) :125    ∑ i, p i * (information p i - entropy p) = 0 := by126  simp only [mul_sub, Finset.sum_sub_distrib, information_mean, ←Finset.sum_mul,127    hp, one_mul, sub_self]128129theorem centered_wordSum (p : ι → ℝ) (n : ℕ) (x : Fin n → ι) :130    wordSum (fun i => information p i - entropy p) n x = surprisal p n x - n*entropy p := by131  simp [wordSum, surprisal, Finset.sum_sub_distrib]132133theorem surprisal_mean (p : ι → ℝ) (hp : ∑ i, p i = 1) (n : ℕ) :134    expectation p n (surprisal p n) = n * entropy p := by135  exact (expectation_wordSum p (information p) hp n).trans (by rw [information_mean])136137theorem surprisal_variance (p : ι → ℝ) (hp : ∑ i, p i = 1) (n : ℕ) :138    expectation p n (fun x => (surprisal p n x - n*entropy p)^2) = n * variance p := by139  simpa only [centered_wordSum, variance] using140    expectation_wordSum_sq_of_centered p (fun i => information p i - entropy p)141      hp (information_centered p hp) n142143theorem variance_nonneg (p : ι → ℝ) (hp : ∀ i, 0 ≤ p i) : 0 ≤ variance p :=144  Finset.sum_nonneg (fun i _ => mul_nonneg (hp i) (sq_nonneg _))145146/-- The finite Chebyshev inequality, proved directly from its weighted sum. -/147theorem finite_chebyshev (w f : ι → ℝ) (hw : ∀ i, 0 ≤ w i)148    (hs : ∑ i, w i = 1) (μ a : ℝ) (ha : 0 < a) :149    1 - (∑ i, w i * (f i-μ)^2)/a^2 ≤150      ∑ i ∈ Finset.univ.filter (fun i => |f i-μ| < a), w i := by151  classical152  let bad := Finset.univ.filter (fun i => ¬ |f i-μ| < a)153  have hb : (∑ i ∈ bad, w i)*a^2 ≤ ∑ i, w i*(f i-μ)^2 := by154    rw [Finset.sum_mul]155    calc156      _ ≤ ∑ i ∈ bad, w i*(f i-μ)^2 := by157        apply Finset.sum_le_sum158        intro i hi159        have hi' : a ≤ |f i-μ| := le_of_not_gt (Finset.mem_filter.mp hi).2160        apply mul_le_mul_of_nonneg_left _ (hw i)161        exact sq_le_sq.mpr (by simpa only [abs_of_pos ha] using hi')162      _ ≤ _ := Finset.sum_le_sum_of_subset_of_nonneg (Finset.filter_subset _ _)163        (fun i _ _ => mul_nonneg (hw i) (sq_nonneg _))164  have hb' := (le_div_iff₀ (sq_pos_of_pos ha)).mpr hb165  have ht := Finset.sum_filter_add_sum_filter_not Finset.univ (fun i => |f i-μ| < a) w166  rw [hs] at ht167  change (∑ i ∈ Finset.univ.filter (fun i => |f i-μ| < a), w i) +168    (∑ i ∈ bad, w i) = 1 at ht169  linarith170171def typicalSet (p : ι → ℝ) (n : ℕ) (δ : ℝ) : Finset (Fin n → ι) := by172  classical173  exact Finset.univ.filter (fun x => |surprisal p n x - n*entropy p| < n*δ)174175/-- Product sampling places all but `V/(n δ²)` of its mass in the entropy176window, including distributions that vanish on part of the alphabet. -/177theorem typical_mass_ge (p : ι → ℝ) (hp : ∀ i, 0 ≤ p i) (hs : ∑ i, p i = 1)178    (n : ℕ) (hn : 0 < n) (δ : ℝ) (hδ : 0 < δ) :179    1 - variance p / (n*δ^2) ≤ ∑ x ∈ typicalSet p n δ, wordProbability p n x := by180  have hn' : (0:ℝ) < n := by exact_mod_cast hn181  have h := finite_chebyshev (wordProbability p n) (surprisal p n)182    (wordProbability_nonneg p hp n) (sum_wordProbability p hs n)183    (n*entropy p) (n*δ) (mul_pos hn' hδ)184  change 1 - expectation p n (fun x => (surprisal p n x-n*entropy p)^2)/(n*δ)^2 ≤ _ at h185  rw [surprisal_variance p hs] at h186  have he : (n:ℝ)*variance p/((n:ℝ)*δ)^2 = variance p/((n:ℝ)*δ^2) := by187    field_simp188  simpa only [he, typicalSet] using h189190omit [Fintype ι] in191/-- On words of positive probability, the sum of letter informations is the192negative logarithm of the actual product probability. -/193theorem log_wordProbability (p : ι → ℝ) (n : ℕ) (x : Fin n → ι)194    (hx : wordProbability p n x ≠ 0) :195    Real.log (wordProbability p n x) = -surprisal p n x := by196  have hcoord : ∀ i ∈ (Finset.univ : Finset (Fin n)), p (x i) ≠ 0 :=197    Finset.prod_ne_zero_iff.mp hx198  rw [wordProbability, Real.log_prod hcoord]199  simp only [surprisal, wordSum, information, Finset.sum_neg_distrib, neg_neg]200201theorem probability_bounds_of_typical (p : ι → ℝ) (n : ℕ) (δ : ℝ) (x : Fin n → ι)202    (hx : x ∈ typicalSet p n δ) (hpos : 0 < wordProbability p n x) :203    Real.exp (-(n*entropy p)-n*δ) ≤ wordProbability p n x ∧204      wordProbability p n x ≤ Real.exp (-(n*entropy p)+n*δ) := by205  have hdev := abs_lt.mp (Finset.mem_filter.mp hx).2206  have hlog := log_wordProbability p n x hpos.ne'207  constructor208  · rw [←Real.exp_log hpos]209    apply Real.exp_le_exp.mpr210    linarith211  · rw [←Real.exp_log hpos]212    apply Real.exp_le_exp.mpr213    linarith214215/-- The actual eigenvalue window has the same guaranteed mass as the216information window. Zero-probability words contribute exactly zero. -/217theorem spectral_band_mass_ge (p : ι → ℝ) (hp : ∀ i, 0 ≤ p i) (hs : ∑ i, p i = 1)218    (n : ℕ) (hn : 0 < n) (δ : ℝ) (hδ : 0 < δ) :219    1 - variance p/(n*δ^2) ≤220      ∑ x ∈ Finset.univ.filter (fun x : Fin n → ι =>221        Real.exp (-(n*entropy p)-n*δ) ≤ wordProbability p n x ∧222        wordProbability p n x ≤ Real.exp (-(n*entropy p)+n*δ)), wordProbability p n x := by223  classical224  apply (typical_mass_ge p hp hs n hn δ hδ).trans225  rw [typicalSet]226  simp only [Finset.sum_filter]227  apply Finset.sum_le_sum228  intro x _229  by_cases ht : |surprisal p n x - n*entropy p| < n*δ230  · by_cases hz : wordProbability p n x = 0231    · simp [hz]232    · have hpos := lt_of_le_of_ne (wordProbability_nonneg p hp n x) (Ne.symm hz)233      have hb := probability_bounds_of_typical p n δ x (Finset.mem_filter.mpr ⟨Finset.mem_univ _,ht⟩) hpos234      simp [ht,hb]235  · simp only [if_neg ht]236    split_ifs237    · exact wordProbability_nonneg p hp n x238    · rfl239240def letterMean (p f : ι → ℝ) : ℝ := ∑ i, p i * f i241242def letterVariance (p f : ι → ℝ) : ℝ := ∑ i, p i * (f i-letterMean p f)^2243244/-- Independent finite sampling has variance exactly `n` times the one-letter245variance for every real observable, including conditional information. -/246theorem wordSum_variance (p f : ι → ℝ) (hp : ∑ i, p i = 1) (n : ℕ) :247    expectation p n (fun x => (wordSum f n x-n*letterMean p f)^2) =248      n*letterVariance p f := by249  have hc : ∑ i, p i*(f i-letterMean p f) = 0 := by250    simp only [mul_sub, Finset.sum_sub_distrib, ←Finset.sum_mul, hp, one_mul]251    exact sub_self _252  have he (x : Fin n → ι) :253      wordSum (fun i => f i-letterMean p f) n x = wordSum f n x-n*letterMean p f := by254    simp [wordSum, Finset.sum_sub_distrib]255  simpa only [he, letterVariance] using256    expectation_wordSum_sq_of_centered p (fun i => f i-letterMean p f) hp hc n257258/-- Typicality for an arbitrary observable; this is also the conditional259entropy typicality estimate when letters are joint input/eigenvalue labels. -/260theorem wordSum_concentration (p f : ι → ℝ) (hp : ∀ i, 0 ≤ p i) (hs : ∑ i, p i = 1)261    (n : ℕ) (hn : 0 < n) (δ : ℝ) (hδ : 0 < δ) :262    1-letterVariance p f/(n*δ^2) ≤263      ∑ x ∈ Finset.univ.filter (fun x : Fin n → ι =>264        |wordSum f n x-n*letterMean p f| < n*δ), wordProbability p n x := by265  have hn' : (0:ℝ) < n := by exact_mod_cast hn266  have h := finite_chebyshev (wordProbability p n) (wordSum f n)267    (wordProbability_nonneg p hp n) (sum_wordProbability p hs n)268    (n*letterMean p f) (n*δ) (mul_pos hn' hδ)269  change 1-expectation p n (fun x => (wordSum f n x-n*letterMean p f)^2)/(n*δ)^2 ≤ _ at h270  rw [wordSum_variance p f hs] at h271  have he : (n:ℝ)*letterVariance p f/((n:ℝ)*δ)^2 = letterVariance p f/((n:ℝ)*δ^2) := by272    field_simp273  simpa only [he] using h274275end Nonadditivity.QuantumCodingTypicality