Exact Lean source
Nonadditivity.QuantumCodingSampling
Download original .lean · View on GitHub · Jump to source
Direct imports
Mathlib.Algebra.BigOperators.Ring.FinsetdependencyMathlib.Algebra.Order.BigOperators.Ring.FinsetdependencyMathlib.Tacticdependency
Imported by project modules
2 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
26 project constants, including generated, internal and private declarations.
26 declarations
Nonadditivity.QuantumCoding.Sampling.codebookCostNonadditivity.QuantumCoding.Sampling.codebookCost._proof_1internal/detail/privateNonadditivity.QuantumCoding.Sampling.codebookCost._proof_2internal/detail/privateNonadditivity.QuantumCoding.Sampling.codebookCost._proof_3internal/detail/privateNonadditivity.QuantumCoding.Sampling.exists_codebook_cost_leNonadditivity.QuantumCoding.Sampling.exists_le_expectNonadditivity.QuantumCoding.Sampling.expectNonadditivity.QuantumCoding.Sampling.expect.congr_simpNonadditivity.QuantumCoding.Sampling.expect.eq_1internal/detail/privateNonadditivity.QuantumCoding.Sampling.expect_addNonadditivity.QuantumCoding.Sampling.expect_codebookCost_leNonadditivity.QuantumCoding.Sampling.expect_constNonadditivity.QuantumCoding.Sampling.expect_finset_sumNonadditivity.QuantumCoding.Sampling.expect_monoNonadditivity.QuantumCoding.Sampling.expect_mul_constNonadditivity.QuantumCoding.Sampling.expect_oneNonadditivity.QuantumCoding.Sampling.expect_productNonadditivity.QuantumCoding.Sampling.expect_product._simp_1_3internal/detail/privateNonadditivity.QuantumCoding.Sampling.expect_sumNonadditivity.QuantumCoding.Sampling.expect_twoNonadditivity.QuantumCoding.Sampling.expect_two._simp_1_2internal/detail/privateNonadditivity.QuantumCoding.Sampling.expect_two_productNonadditivity.QuantumCoding.Sampling.weightNonadditivity.QuantumCoding.Sampling.weight.eq_1internal/detail/privateNonadditivity.QuantumCoding.Sampling.weight_nonnegNonadditivity.QuantumCoding.Sampling.weight_sum
Full module
1/-2Copyright (c) 2026 the Nonadditivity project contributors.3All rights reserved. See COPYRIGHT.md for licensing and attribution.4-/56import Mathlib.Algebra.BigOperators.Ring.Finset7import Mathlib.Algebra.Order.BigOperators.Ring.Finset8import Mathlib.Tactic910/-! # Finite independent random codebooks and their exact marginal averages -/1112noncomputable section13namespace Nonadditivity.QuantumCoding.Sampling14open scoped BigOperators1516variable {α J : Type*} [Fintype α] [Fintype J] [DecidableEq J]1718def weight (p : α → ℝ) (c : J → α) : ℝ := ∏ i, p (c i)1920def expect (p : α → ℝ) (f : (J → α) → ℝ) : ℝ := ∑ c, weight p c * f c2122omit [Fintype α] [DecidableEq J] in23theorem weight_nonneg (p : α → ℝ) (hp : ∀x, 0 ≤ p x) (c : J → α) :240 ≤ weight p c := Finset.prod_nonneg (fun i _ => hp (c i))2526theorem weight_sum (p : α → ℝ) (hsum : ∑x, p x = 1) :27∑ c : J → α, weight p c = 1 := by28unfold weight29rw [← Fintype.prod_sum]30simp only [hsum, Finset.prod_const_one]3132theorem expect_const (p : α → ℝ) (hsum : ∑x, p x = 1) (r : ℝ) :33expect p (fun _ : J → α => r) = r := by34rw [expect, ← Finset.sum_mul, weight_sum p hsum, one_mul]3536theorem expect_add (p : α → ℝ) (f g : (J → α) → ℝ) :37expect p (fun c => f c + g c) = expect p f + expect p g := by38simp only [expect, mul_add, Finset.sum_add_distrib]3940theorem expect_sum {K : Type*} [Fintype K] (p : α → ℝ)41(f : K → (J → α) → ℝ) : expect p (fun c => ∑ k, f k c) = ∑ k, expect p (f k) := by42simp only [expect, Finset.mul_sum]43exact Finset.sum_comm4445theorem expect_finset_sum {K : Type*} (p : α → ℝ) (s : Finset K)46(f : K → (J → α) → ℝ) :47expect p (fun c => ∑ k ∈ s, f k c) = ∑ k ∈ s, expect p (f k) := by48simp only [expect, Finset.mul_sum]49exact Finset.sum_comm5051theorem expect_mul_const (p : α → ℝ) (f : (J → α) → ℝ) (a : ℝ) :52expect p (fun c => a * f c) = a * expect p f := by53simp only [expect, Finset.mul_sum]54congr 155funext c56ring5758theorem expect_mono (p : α → ℝ) (hp : ∀x, 0 ≤ p x)59{f g : (J → α) → ℝ} (h : ∀c, f c ≤ g c) : expect p f ≤ expect p g :=60Finset.sum_le_sum (fun c _ => mul_le_mul_of_nonneg_left (h c) (weight_nonneg p hp c))6162theorem expect_product (p : α → ℝ) (f : J → α → ℝ) :63expect p (fun c => ∏ i, f i (c i)) = ∏ i, ∑x, p x * f i x := by64simp only [expect, weight, ← Finset.prod_mul_distrib]65exact (Fintype.prod_sum (fun i x => p x * f i x)).symm6667theorem expect_one (p : α → ℝ) (hsum : ∑x, p x = 1) (i : J) (f : α → ℝ) :68expect p (fun c => f (c i)) = ∑x, p x * f x := by69have h := expect_product p (fun j x => if j = i then f x else 1)70simpa only [Fintype.prod_ite_eq', mul_ite, mul_one,71Finset.sum_ite_irrel, hsum] using h7273theorem expect_two_product (p : α → ℝ) (hsum : ∑x, p x = 1)74{i j : J} (hij : i ≠ j) (f g : α → ℝ) :75expect p (fun c => f (c i) * g (c j)) =76(∑x, p x * f x) * (∑y, p y * g y) := by77have h := expect_product p78(fun k x => (if k = i then f x else 1) * (if k = j then g x else 1))79have hprod (c : J → α) :80(∏ k, (if k = i then f (c k) else 1) * (if k = j then g (c k) else 1)) =81f (c i) * g (c j) := by82rw [Finset.prod_mul_distrib, Fintype.prod_ite_eq', Fintype.prod_ite_eq']83have hsum' (k : J) :84(∑x, p x * ((if k = i then f x else 1) * (if k = j then g x else 1))) =85(if k = i then ∑x, p x * f x else 1) *86(if k = j then ∑x, p x * g x else 1) := by87by_cases hi : k=i88· subst k89simp only [ite_true, if_neg hij, mul_one]90· by_cases hj : k=j91· subst k92simp only [if_neg hi, ite_true, one_mul]93· simp only [if_neg hi, if_neg hj, mul_one, hsum]94simp_rw [hprod, hsum'] at h95simpa only [Finset.prod_mul_distrib, Fintype.prod_ite_eq'] using h9697theorem expect_two (p : α → ℝ) (hsum : ∑x, p x = 1)98{i j : J} (hij : i ≠ j) (f : α → α → ℝ) :99expect p (fun c => f (c i) (c j)) = ∑x, ∑y, p x * p y * f x y := by100classical101have hexp (c : J → α) : f (c i) (c j) =102∑x, ∑y, f x y * ((if c i = x then 1 else 0) * (if c j = y then 1 else 0)) := by103simp104simp_rw [hexp]105rw [expect_sum]106apply Finset.sum_congr rfl107intro x _108rw [expect_sum]109apply Finset.sum_congr rfl110intro y _111rw [expect_mul_const, expect_two_product p hsum hij112(fun z => if z=x then 1 else 0) (fun z => if z=y then 1 else 0)]113simp only [mul_ite, mul_one, mul_zero, Finset.sum_ite_eq', Finset.mem_univ, if_true]114ring115116/-- A finite probability average has at least one outcome no larger than it. -/117theorem exists_le_expect (p : α → ℝ) (hp : ∀x, 0 ≤ p x) (hsum : ∑x, p x = 1)118(f : (J → α) → ℝ) : ∃c, f c ≤ expect p f := by119classical120by_contra h121push_neg at h122have hnonempty : Nonempty (J → α) := by123have hs := weight_sum (J := J) p hsum124by_contra hne125letI : IsEmpty (J → α) := not_nonempty_iff.mp hne126simp at hs127letI := hnonempty128obtain ⟨c, hcmem, hc⟩ := Finset.exists_lt_of_sum_lt129(show (∑ _c : J → α, (0 : ℝ)) < ∑ c : J → α, weight p c by130rw [weight_sum p hsum]; simp)131have hs : expect p f < expect p f := by132calc133expect p f = ∑ c : J → α, weight p c * expect p f := by134rw [← Finset.sum_mul, weight_sum p hsum, one_mul]135_ < ∑ c, weight p c * f c := by136apply Finset.sum_lt_sum137· intro a _138exact mul_le_mul_of_nonneg_left (h a).le (weight_nonneg p hp a)139· exact ⟨c, hcmem, mul_lt_mul_of_pos_left (h c) hc⟩140_ = expect p f := rfl141exact (lt_irrefl _) hs142143/-- The explicit three-term cost of an independently sampled finite codebook. -/144def codebookCost {M : ℕ} (f g : α → ℝ) (cross : α → α → ℝ) (c : Fin M → α) : ℝ :=145(M : ℝ)⁻¹ * ∑ i, (9*f (c i) + 8*g (c i) +1464*∑ j ∈ Finset.univ.erase i, cross (c i) (c j))147148theorem expect_codebookCost_le (p : α → ℝ) (hsum : ∑x, p x = 1)149{M : ℕ} (hM : 0 < M) (f g : α → ℝ) (cross : α → α → ℝ)150{εf εg β : ℝ} (hf : ∑x, p x * f x ≤ εf) (hg : ∑x, p x * g x ≤ εg)151(hc : ∑x, ∑y, p x * p y * cross x y ≤ β) :152expect p (codebookCost (M := M) f g cross) ≤ 9*εf+8*εg+4*(M-1:ℕ)*β := by153have hlocal (i : Fin M) :154expect p (fun c : Fin M → α => 9*f (c i)+8*g (c i)+1554*∑ j ∈ Finset.univ.erase i, cross (c i) (c j)) ≤ 9*εf+8*εg+4*(M-1:ℕ)*β := by156rw [expect_add, expect_add, expect_mul_const, expect_mul_const, expect_mul_const,157expect_one p hsum, expect_one p hsum, expect_finset_sum]158have hcross : (∑ j ∈ Finset.univ.erase i,159expect p (fun c : Fin M → α => cross (c i) (c j))) ≤ (M-1:ℕ)*β := by160calc161_ ≤ ∑ j ∈ Finset.univ.erase i, β := by162apply Finset.sum_le_sum163intro j hj164rw [expect_two p hsum (Ne.symm (Finset.mem_erase.mp hj).1) cross]165exact hc166_ = (M-1:ℕ)*β := by simp167linarith168unfold codebookCost169rw [expect_mul_const, expect_sum]170have hs := Finset.sum_le_sum (fun i (_ : i ∈ Finset.univ) => hlocal i)171have hm : (M : ℝ) ≠ 0 := by exact_mod_cast (Nat.ne_of_gt hM)172calc173_ ≤ (M : ℝ)⁻¹ * ∑ _i : Fin M, (9*εf+8*εg+4*(M-1:ℕ)*β) :=174mul_le_mul_of_nonneg_left hs (inv_nonneg.mpr (Nat.cast_nonneg _))175_ = _ := by simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin,176nsmul_eq_mul]; rw [← mul_assoc, inv_mul_cancel₀ hm, one_mul]177178theorem exists_codebook_cost_le (p : α → ℝ) (hp : ∀x, 0 ≤ p x) (hsum : ∑x, p x = 1)179{M : ℕ} (hM : 0 < M) (f g : α → ℝ) (cross : α → α → ℝ)180{εf εg β : ℝ} (hf : ∑x, p x * f x ≤ εf) (hg : ∑x, p x * g x ≤ εg)181(hc : ∑x, ∑y, p x * p y * cross x y ≤ β) :182∃c : Fin M → α, codebookCost f g cross c ≤ 9*εf+8*εg+4*(M-1:ℕ)*β := by183obtain ⟨c, hc⟩ := exists_le_expect p hp hsum (codebookCost (M := M) f g cross)184exact ⟨c, hc.trans (expect_codebookCost_le p hsum hM f g cross hf hg ‹_›)⟩185186end Nonadditivity.QuantumCoding.Sampling