Pratik Patil

ClassicalEquality.lean

1module23public import SubentropyCertificates.ClassicalFano45/-!6# Equality on the classical subentropy error curve78The first equality is strict Jensen applied to the cyclic permutations already9used in the fixed-coordinate bound. The second is strict Jensen for the10outcome errors. The selected label may depend on the outcome. Selecting any11maximizer gives the MAP statement, including ties.12-/1314@[expose] public section15noncomputable section16set_option autoImplicit false17open Set18open scoped BigOperators1920namespace SubentropyCertificates.ClassicalCurve2122theorem classical_coordinate_eq_iff_extremal (m : ℕ) (p : Option (Fin (m + 1)) → ℝ)23    (hp : p ∈ probabilitySimplex (Option (Fin (m + 1)))) :24    classicalSubentropy p = phi m (1 - p none) ↔ p = extremalVector m (1 - p none) := by25  have hm : ((m + 1 : ℕ) : ℝ) ≠ 0 := by positivity26  have hw : ∑ _j : Fin (m + 1), ((m + 1 : ℕ) : ℝ)⁻¹ = 1 := by27    simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul]28    exact mul_inv_cancel₀ hm29  have h := classical_subentropy_strictConcave.map_sum_eq_iff30    (t := Finset.univ) (w := fun _ : Fin (m + 1) => ((m + 1 : ℕ) : ℝ)⁻¹)31    (p := fun j => p ∘ tailShift m j) (fun _ _ => by positivity) hw32    (fun j _ => simplex_reindex p hp (tailShift m j))33  rw [average_tail_shifts m p hp] at h34  simp only [classical_subentropy_reindex, smul_eq_mul, Finset.sum_const, Finset.card_univ,35    Fintype.card_fin, nsmul_eq_mul, mul_inv_cancel_left₀ hm] at h36  constructor37  · intro he38    have h0 := h.mp he.symm 0 (Finset.mem_univ _)39    calc40      p = p ∘ tailShift m 0 := by41        funext x42        cases x <;> simp [tailShift]43      _ = _ := h044  · exact fun he => congrArg classicalSubentropy he4546/-- The other coordinates must each carry exactly their share of the error. -/47theorem classical_coordinate_eq_iff {X : Type*} [Fintype X] [DecidableEq X]48    (m : ℕ) (hn : Fintype.card X = m + 2) (p : X → ℝ)49    (hp : p ∈ probabilitySimplex X) (i : X) :50    classicalSubentropy p = phi m (1 - p i) ↔51      ∀ j, j ≠ i → p j = (1 - p i) / (m + 1 : ℕ) := by52  let a : Option (Fin (m + 1)) ≃ X := Fintype.equivOfCardEq (by simp [hn, Nat.add_assoc])53  let e := a.trans (Equiv.swap (a none) i)54  have hi : e none = i := by simp [e]55  have he : classicalSubentropy p = phi m (1 - p i) ↔56      p ∘ e = extremalVector m (1 - p i) := by57    simpa only [classical_subentropy_reindex, Function.comp_apply, hi] using58      classical_coordinate_eq_iff_extremal m (p ∘ e) (simplex_reindex p hp e)59  rw [he]60  constructor61  · intro h j hj62    obtain ⟨k, rfl⟩ := e.surjective j63    cases k with64    | none => exact (hj hi).elim65    | some k => exact congrFun h (some k)66  · intro h67    funext k68    cases k with69    | none => simp [hi, extremalVector]70    | some k =>71      exact h _ (fun heq => Option.some_ne_none k (e.injective (heq.trans hi.symm)))7273/-- Equal unselected coordinates suffice, since their sum is fixed. -/74theorem classical_coordinate_eq_iff_equal_tail {X : Type*} [Fintype X] [DecidableEq X]75    (m : ℕ) (hn : Fintype.card X = m + 2) (p : X → ℝ)76    (hp : p ∈ probabilitySimplex X) (i : X) :77    classicalSubentropy p = phi m (1 - p i) ↔78      ∀ j, j ≠ i → ∀ k, k ≠ i → p j = p k := by79  rw [classical_coordinate_eq_iff m hn p hp i]80  constructor81  · exact fun h j hj k hk => (h j hj).trans (h k hk).symm82  · intro h j hj83    have hsum := Finset.sum_erase_add Finset.univ p (Finset.mem_univ i)84    have hconst : ∑ k ∈ Finset.univ.erase i, p k = ∑ _k ∈ Finset.univ.erase i, p j :=85      Finset.sum_congr rfl (fun k hk => h k (Finset.mem_erase.mp hk).1 j hj)86    have hcard : (Finset.univ.erase i).card = m + 1 := by87      rw [Finset.card_erase_of_mem (Finset.mem_univ i), Finset.card_univ, hn]88      omega89    rw [hp.2, hconst, Finset.sum_const, hcard, nsmul_eq_mul] at hsum90    apply (eq_div_iff (by positivity : ((m + 1 : ℕ) : ℝ) ≠ 0)).mpr91    rw [mul_comm]92    exact eq_sub_of_add_eq hsum9394theorem binary_coordinate_eq {X : Type*} [Fintype X] [DecidableEq X]95    (hn : Fintype.card X = 2) (p : X → ℝ) (hp : p ∈ probabilitySimplex X) (i : X) :96    classicalSubentropy p = phi 0 (1 - p i) := by97  apply (classical_coordinate_eq_iff_equal_tail 0 hn p hp i).mpr98  have hc : (Finset.univ.erase i).card ≤ 1 := by99    rw [Finset.card_erase_of_mem (Finset.mem_univ i), Finset.card_univ, hn]100  intro j hj k hk101  exact congrArg p (Finset.card_le_one_iff.mp hc102    (Finset.mem_erase.mpr ⟨hj, Finset.mem_univ _⟩)103    (Finset.mem_erase.mpr ⟨hk, Finset.mem_univ _⟩))104105theorem positive_priors_of_map_equality {X : Type*} [Fintype X] [DecidableEq X]106    (m : ℕ) (hn : Fintype.card X = m + 2) (p : X → ℝ) (hp : p ∈ probabilitySimplex X)107    (i : X) (hmax : ∀ j, p j ≤ p i) (herr : 0 < 1 - p i)108    (heq : classicalSubentropy p = phi m (1 - p i)) : ∀ j, 0 < p j := by109  intro j110  by_cases hji : j = i111  · rw [hji]112    have hr := (classical_error_range m hn p hp i hmax).2113    unfold uniformError at hr114    have : (0 : ℝ) < 1 / (m + 2 : ℕ) := by positivity115    linarith116  · rw [(classical_coordinate_eq_iff m hn p hp i).mp heq j hji]117    exact div_pos herr (by positivity)118119/-- Equality for an average over the support of the outcome distribution.120The value `e` is its average error. No posterior is required outside `S`. -/121theorem classical_posterior_eq_iff {X Y : Type*} [Fintype X] [DecidableEq X]122    (m : ℕ) (hn : Fintype.card X = m + 2) (S : Finset Y) (q : Y → ℝ)123    (hq : ∀ y ∈ S, 0 < q y) (hs : ∑ y ∈ S, q y = 1)124    (b : Y → X → ℝ) (hb : ∀ y ∈ S, b y ∈ probabilitySimplex X)125    (selected : Y → X) (e : ℝ) (he : ∑ y ∈ S, q y * (1 - b y (selected y)) = e) :126    (∑ y ∈ S, q y * classicalSubentropy (b y)) = phi m e ↔127      ∀ y ∈ S, 1 - b y (selected y) = e ∧128        ∀ j, j ≠ selected y → b y j = e / (m + 1 : ℕ) := by129  let err (y : Y) := 1 - b y (selected y)130  have hmem (y : Y) (hy : y ∈ S) : err y ∈ Icc (0 : ℝ) 1 := by131    have hle : b y (selected y) ≤ 1 := by132      rw [← (hb y hy).2]133      exact Finset.single_le_sum (fun i _ => (hb y hy).1 i) (Finset.mem_univ _)134    exact ⟨sub_nonneg.mpr hle, sub_le_self _ ((hb y hy).1 _)⟩135  have hterm (y : Y) (hy : y ∈ S) :136      q y * classicalSubentropy (b y) ≤ q y * phi m (err y) :=137    mul_le_mul_of_nonneg_left138      (classical_coordinate_bound_finite m hn (b y) (hb y hy) (selected y)) (hq y hy).le139  have havg : ∑ y ∈ S, q y • err y = e := he140  have hj := (phi_strictConcave m).map_sum_eq_iff hq hs hmem141  have hbound := (phi_concave m).le_map_sum (fun y hy => (hq y hy).le) hs hmem142  rw [havg] at hj hbound143  simp only [smul_eq_mul] at hj hbound144  constructor145  · intro h146    have hsum := Finset.sum_le_sum hterm147    have hmiddle := le_antisymm hsum (hbound.trans_eq h.symm)148    have herr := hj.mp (h.symm.trans hmiddle)149    intro y hy150    have hlocal := (Finset.sum_eq_sum_iff_of_le hterm).mp hmiddle y hy151    have hycurve := mul_left_cancel₀ (hq y hy).ne' hlocal152    have htail := (classical_coordinate_eq_iff m hn (b y) (hb y hy) (selected y)).mp hycurve153    have hyerr : 1 - b y (selected y) = e := herr y hy154    exact ⟨hyerr, fun j hne => by rw [htail j hne, hyerr]⟩155  · intro h156    apply Eq.trans _ (hj.mpr (fun y hy => (h y hy).1)).symm157    apply Finset.sum_congr rfl158    intro y hy159    apply congrArg (q y * ·)160    apply (classical_coordinate_eq_iff m hn (b y) (hb y hy) (selected y)).mpr161    intro j hne162    rw [(h y hy).1]163    exact (h y hy).2 j hne164165end SubentropyCertificates.ClassicalCurve

Axioms used

Choose a statement to see which axioms its proof uses.