PosteriorVariance.lean
1module23public import SubentropyCertificates.PosteriorStability45/-! The variance identity following Proposition 12 in Section 3.5. -/6@[expose] public section7noncomputable section8set_option autoImplicit false9open Matrix10open scoped BigOperators ComplexOrder MatrixOrder1112namespace SubentropyCertificates.PosteriorStability13open SubentropyCertificates.ClassicalCurve14open SubentropyCertificates.StrongConcavity15open SubentropyCertificates.MeasurementPosterior16open SubentropyCertificates.Discrimination17open D5.S3.Quantum.Foundation.FiniteStateChannel1819variable {X : Type*} [Fintype X] [DecidableEq X]2021/-- Orthogonal decomposition at a single outcome. The reference error22may be any real number. In the measurement identity it is the mean error. -/23theorem posterior_deviation_at_label (m : ℕ) (hn : Fintype.card X = m+2)24 (b : X → ℝ) (hb : b ∈ probabilitySimplex X) (i : X) (e : ℝ) :25 let n := (Fintype.card X : ℝ)26 let err := 1-b i27 energy (b-target m i e) =28 (∑ x ∈ Finset.univ.erase i, (b x-err/(n-1))^2) + n/(n-1)*(err-e)^2 := by29 let T := Finset.univ.erase i30 let k : ℝ := (m+1 : ℕ)31 let err := 1-b i32 have hk : k ≠ 0 := by dsimp [k]; positivity33 have hn' : (Fintype.card X : ℝ) = k+1 := by rw [hn]; dsimp [k]; push_cast; ring34 have hcard : (T.card : ℝ) = k := by35 dsimp [T,k]36 rw [Finset.card_erase_of_mem (Finset.mem_univ i),Finset.card_univ,hn]37 rfl38 have hmass : ∑ x ∈ T,b x = err := by39 have h := Finset.sum_erase_add Finset.univ b (Finset.mem_univ i)40 rw [hb.2] at h41 change (∑ x ∈ T,b x) + b i = 1 at h42 dsimp [err]; linarith43 have hcenter : ∑ x ∈ T,(b x-err/k) = 0 := by44 rw [Finset.sum_sub_distrib,hmass,Finset.sum_const,nsmul_eq_mul,hcard]45 field_simp46 ring47 let shift := (err-e)/k48 have expand (x : X) : (b x-e/k)^2 =49 (b x-err/k)^2 + 2*shift*(b x-err/k) + shift^2 := by50 dsimp [shift]; ring51 have htail : ∑ x ∈ T,(b x-e/k)^2 =52 (∑ x ∈ T,(b x-err/k)^2) + k*shift^2 := by53 simp_rw [expand]54 rw [Finset.sum_add_distrib,Finset.sum_add_distrib,← Finset.mul_sum,hcenter,55 mul_zero,add_zero,Finset.sum_const,nsmul_eq_mul,hcard]56 have splitEnergy : energy (b-target m i e) =57 (∑ x ∈ T,(b x-e/k)^2) + (err-e)^2 := by58 unfold energy59 rw [← Finset.sum_erase_add _ _ (Finset.mem_univ i)]60 apply congrArg₂ (· + ·)61 · apply Finset.sum_congr rfl62 intro x hx63 simp only [Pi.sub_apply,target,ite_eq_right (Finset.mem_erase.mp hx).1,k]64 · simp [target,err]; ring65 have hfactor : k*shift^2 + (err-e)^2 = (k+1)/k*(err-e)^2 := by66 dsimp [shift]; field_simp; ring67 dsimp only68 rw [hn',add_sub_cancel_right,splitEnergy,htail,add_assoc,hfactor]6970variable {B Y : Type*} [Fintype B] [DecidableEq B] [Fintype Y]7172/-- Equation eq:posterior-variance. The variance is the outcome-weighted73central second moment of the posterior error. Only positive-mass outcomes74enter either sum. The identity holds for every selection of labels. -/75theorem measurement_posterior_variance (m : ℕ) (hn : Fintype.card X = m+2)76 (p : X → ℝ) (hp : ∀ x,0 ≤ p x) (ρ : X → DensityState B)77 (F : Y → Matrix B B ℂ) (hF : ∀ y,(F y).PosSemidef) (selected : Y → X) :78 let n := (Fintype.card X : ℝ)79 let q (y : Y) := outcomeProbability p ρ (F y)80 let S := Finset.univ.filter (fun y => 0 < q y)81 let b (y : Y) := posterior p ρ (F y)82 let err (y : Y) := 1-b y (selected y)83 let e := measurementError p ρ F selected84 posteriorDeviation m p ρ F selected e =85 (∑ y ∈ S, q y * ∑ x ∈ Finset.univ.erase (selected y), (b y x-err y/(n-1))^2) +86 n/(n-1) * ∑ y ∈ S, q y*(err y-e)^2 := by87 dsimp only88 unfold posteriorDeviation89 rw [Finset.mul_sum,← Finset.sum_add_distrib]90 apply Finset.sum_congr rfl91 intro y hy92 have hb := posterior_probability p hp ρ (F y) (hF y) (Finset.mem_filter.mp hy).293 rw [posterior_deviation_at_label m hn _ hb (selected y) (measurementError p ρ F selected)]94 ring9596/-- For normalized priors and a POVM, the error variance in the97decomposition is also the second moment minus the squared mean. -/98theorem measurement_error_variance_eq_second_moment99 (p : X → ℝ) (hp : ∀ x,0 ≤ p x) (hs : ∑ x,p x=1) (ρ : X → DensityState B)100 (F : Y → Matrix B B ℂ) (hF : ∀ y,(F y).PosSemidef) (hsF : ∑ y,F y=1) (selected : Y → X) :101 let q (y : Y) := outcomeProbability p ρ (F y)102 let S := Finset.univ.filter (fun y => 0 < q y)103 let err (y : Y) := 1-posterior p ρ (F y) (selected y)104 let e := measurementError p ρ F selected105 (∑ y ∈ S,q y*(err y-e)^2) = (∑ y ∈ S,q y*(err y)^2) - e^2 := by106 intro q S err e107 have hq y : 0 ≤ q y := outcomeProbability_nonneg p hp ρ (F y) (hF y)108 have hsum : ∑ y ∈ S,q y = 1 :=109 (sum_over_positive q hq q (fun _ hz => hz)).trans (sum_outcomeProbability p hp hs ρ F hsF)110 have hmean : ∑ y ∈ S,q y*err y = e := rfl111 have expand (y : Y) : q y*(err y-e)^2 = q y*(err y)^2 - (q y*err y)*(2*e) + q y*e^2 := by ring112 simp_rw [expand]113 rw [Finset.sum_add_distrib,Finset.sum_sub_distrib,← Finset.sum_mul,← Finset.sum_mul,hmean,hsum]114 ring115116end SubentropyCertificates.PosteriorStability
Axioms used
Choose a statement to see which axioms its proof uses.