import Mathlib /-! # Exponential Families, Exact Cumulant Derivatives, Legendre–Bregman Duality, Generalized Bregman Pythagorean Theorem & Exact I/M-Projection Duality This standalone Lean 4 + Mathlib module formalizes Pillars 1 and 3 of classical Information Geometry (Amari–Nagaoka, Csiszár, Banerjee et al.): 1. **Discrete Regular Exponential Families & Exact Cumulant Derivative Identities:** Genuine `HasDerivAt` proofs of the 1st, 2nd, and 3rd cumulant identities (`∇ψ(θ) = η(θ) = E_θ[T]`, `∇²ψ(θ) = Cov_θ(T) = I(θ)`, `∇³ψ(θ) = T_{ijk}(θ)`), exact positive-definiteness iff minimal representation, strict global convexity of `ψ`, and global injectivity of the mirror map `θ ↦ η(θ)`. 2. **Exact Legendre–Fenchel Duality, Negative Entropy & KL–Bregman Argument Reversal:** Exact Fenchel–Young gap identity `φ(p) - (⟨θ, η(p)⟩ - ψ(θ)) = D_KL(p ‖ p_θ)`, exact Legendre conjugate `φ(η) = sup_θ (⟨θ, η⟩ - ψ(θ)) = -H(p_η) - E[log h]`, Gibbs variational principle `ψ(θ) = sup_p (⟨θ, η(p)⟩ - φ(p))`, and the three-way KL–Bregman duality identity `D_KL(p_{θ₁} ‖ p_{θ₂}) = D_ψ(θ₂, θ₁) = D_φ(η₁, η₂)` with exact Jeffreys symmetrization and Bernoulli strict asymmetry witness. 3. **Generalized Bregman Pythagorean Theorem & Exact M- and I-Projection Duality:** Exact generalized Pythagorean identity and Fisher-orthogonality equivalence, exact M-projection onto exponential families (= Maximum Likelihood / moment matching), exact I-projection onto linear/moment families (= Gibbs / MaxEnt exponential tilting), and exact convex Pythagorean inequalities for both m-convex and e-convex sets. -/ noncomputable section open scoped BigOperators open Finset namespace InfoGeomExpBregman /-! ## Section 1: Finite Inner Products, Strict Probabilities & KL Divergence -/ /-- Standard Euclidean inner product on `Fin d → ℝ`. -/ def dotFin {d : ℕ} (u v : Fin d → ℝ) : ℝ := ∑ i : Fin d, u i * v i /-- Standard coordinate basis vector `e_i : Fin d → ℝ`. -/ def basisVec {d : ℕ} (i : Fin d) : Fin d → ℝ := fun j => if j = i then 1 else 0 lemma dotFin_comm {d : ℕ} (u v : Fin d → ℝ) : dotFin u v = dotFin v u := by unfold dotFin refine Finset.sum_congr rfl ?_ intro i _ ring lemma dotFin_add_left {d : ℕ} (u v w : Fin d → ℝ) : dotFin (fun i => u i + v i) w = dotFin u w + dotFin v w := by unfold dotFin rw [← Finset.sum_add_distrib] refine Finset.sum_congr rfl ?_ intro i _ ring lemma dotFin_sub_left {d : ℕ} (u v w : Fin d → ℝ) : dotFin (fun i => u i - v i) w = dotFin u w - dotFin v w := by unfold dotFin rw [← Finset.sum_sub_distrib] refine Finset.sum_congr rfl ?_ intro i _ ring lemma dotFin_sub_right {d : ℕ} (u v w : Fin d → ℝ) : dotFin u (fun i => v i - w i) = dotFin u v - dotFin u w := by rw [dotFin_comm, dotFin_sub_left, dotFin_comm v u, dotFin_comm w u] lemma dotFin_smul_left {d : ℕ} (c : ℝ) (u v : Fin d → ℝ) : dotFin (fun i => c * u i) v = c * dotFin u v := by unfold dotFin rw [Finset.mul_sum] refine Finset.sum_congr rfl ?_ intro i _ ring lemma dotFin_basis_left {d : ℕ} (i : Fin d) (v : Fin d → ℝ) : dotFin (basisVec i) v = v i := by unfold dotFin basisVec simp lemma dotFin_basis_right {d : ℕ} (u : Fin d → ℝ) (i : Fin d) : dotFin u (basisVec i) = u i := by rw [dotFin_comm, dotFin_basis_left] /-- A strictly positive probability distribution on a finite carrier `ι`. -/ @[ext] structure StrictProb (ι : Type*) [Fintype ι] where p : ι → ℝ pos : ∀ x, 0 < p x sum_one : ∑ x : ι, p x = 1 /-- Expectation of an observable `f : ι → ℝ` under `p`. -/ def expVal {ι : Type*} [Fintype ι] (p : StrictProb ι) (f : ι → ℝ) : ℝ := ∑ x : ι, p.p x * f x /-- Kullback–Leibler divergence `D_KL(p ‖ q) = ∑ p(x) log (p(x) / q(x))`. -/ def klDiv {ι : Type*} [Fintype ι] (p q : StrictProb ι) : ℝ := ∑ x : ι, p.p x * Real.log (p.p x / q.p x) /-- Shannon entropy `H(p) = - ∑ p(x) log p(x)`. -/ def shannonEntropy {ι : Type*} [Fintype ι] (p : StrictProb ι) : ℝ := - ∑ x : ι, p.p x * Real.log (p.p x) /-- Symmetrized Jeffreys divergence `J(p, q) = D_KL(p ‖ q) + D_KL(q ‖ p)`. -/ def jeffreysDiv {ι : Type*} [Fintype ι] (p q : StrictProb ι) : ℝ := klDiv p q + klDiv q p lemma expVal_const {ι : Type*} [Fintype ι] (p : StrictProb ι) (c : ℝ) : expVal p (fun _ => c) = c := by unfold expVal rw [← Finset.sum_mul, p.sum_one, one_mul] lemma expVal_add {ι : Type*} [Fintype ι] (p : StrictProb ι) (f g : ι → ℝ) : expVal p (fun x => f x + g x) = expVal p f + expVal p g := by unfold expVal rw [← Finset.sum_add_distrib] refine Finset.sum_congr rfl ?_ intro x _ ring lemma expVal_sub {ι : Type*} [Fintype ι] (p : StrictProb ι) (f g : ι → ℝ) : expVal p (fun x => f x - g x) = expVal p f - expVal p g := by unfold expVal rw [← Finset.sum_sub_distrib] refine Finset.sum_congr rfl ?_ intro x _ ring lemma expVal_mul_const {ι : Type*} [Fintype ι] (p : StrictProb ι) (c : ℝ) (f : ι → ℝ) : expVal p (fun x => c * f x) = c * expVal p f := by unfold expVal rw [Finset.mul_sum] refine Finset.sum_congr rfl ?_ intro x _ ring lemma expVal_nonneg {ι : Type*} [Fintype ι] (p : StrictProb ι) {f : ι → ℝ} (hf : ∀ x, 0 ≤ f x) : 0 ≤ expVal p f := by unfold expVal exact Finset.sum_nonneg fun x _ => mul_nonneg (le_of_lt (p.pos x)) (hf x) lemma expVal_sq_eq_zero_iff {ι : Type*} [Fintype ι] (p : StrictProb ι) (f : ι → ℝ) : expVal p (fun x => (f x) ^ 2) = 0 ↔ ∀ x, f x = 0 := by constructor · intro h0 x have hterm : p.p x * (f x) ^ 2 = 0 := by have hnonneg : ∀ y ∈ (Finset.univ : Finset ι), 0 ≤ p.p y * (f y) ^ 2 := fun y _ => mul_nonneg (le_of_lt (p.pos y)) (sq_nonneg (f y)) exact (Finset.sum_eq_zero_iff_of_nonneg hnonneg).mp h0 x (Finset.mem_univ x) rcases mul_eq_zero.mp hterm with hp0 | hf0 · linarith [p.pos x] · exact sq_eq_zero_iff.mp hf0 · intro hf unfold expVal simp [hf] /-- **Gibbs' Inequality:** `D_KL(p ‖ q) ≥ 0` for all strictly positive distributions `p, q`. -/ theorem klDiv_nonneg {ι : Type*} [Fintype ι] (p q : StrictProb ι) : 0 ≤ klDiv p q := by have hle : ∑ x : ι, p.p x * Real.log (q.p x / p.p x) ≤ 0 := by have h1 : ∀ x : ι, p.p x * Real.log (q.p x / p.p x) ≤ q.p x - p.p x := by intro x have hpos : 0 < q.p x / p.p x := div_pos (q.pos x) (p.pos x) have hlog := Real.log_le_sub_one_of_pos hpos have hmul := mul_le_mul_of_nonneg_left hlog (le_of_lt (p.pos x)) have hsimp : p.p x * (q.p x / p.p x - 1) = q.p x - p.p x := by have hpne : p.p x ≠ 0 := ne_of_gt (p.pos x) field_simp [hpne] linarith calc ∑ x : ι, p.p x * Real.log (q.p x / p.p x) ≤ ∑ x : ι, (q.p x - p.p x) := Finset.sum_le_sum fun x _ => h1 x _ = (∑ x : ι, q.p x) - (∑ x : ι, p.p x) := Finset.sum_sub_distrib _ _ _ = 1 - 1 := by rw [q.sum_one, p.sum_one] _ = 0 := sub_self 1 have hneg : klDiv p q = - ∑ x : ι, p.p x * Real.log (q.p x / p.p x) := by unfold klDiv rw [← Finset.sum_neg_distrib] refine Finset.sum_congr rfl ?_ intro x _ have hinv : Real.log (p.p x / q.p x) = - Real.log (q.p x / p.p x) := by rw [← Real.log_inv, inv_div] rw [hinv] ring linarith /-- **Strict Gibbs Uniqueness:** `D_KL(p ‖ q) = 0 ↔ p = q`. -/ theorem klDiv_eq_zero_iff {ι : Type*} [Fintype ι] (p q : StrictProb ι) : klDiv p q = 0 ↔ p = q := by constructor · intro h0 ext x by_contra hne have hratio_ne : q.p x / p.p x ≠ 1 := by intro h1 have hpne : p.p x ≠ 0 := ne_of_gt (p.pos x) have hqp : q.p x = p.p x := by have := (div_eq_one_iff_eq hpne).mp h1 exact this exact hne hqp.symm have hstrict_x : p.p x * Real.log (q.p x / p.p x) < q.p x - p.p x := by have hlog := Real.log_lt_sub_one_of_pos (div_pos (q.pos x) (p.pos x)) hratio_ne have hmul := mul_lt_mul_of_pos_left hlog (p.pos x) have hpne : p.p x ≠ 0 := ne_of_gt (p.pos x) have hsimp : p.p x * (q.p x / p.p x - 1) = q.p x - p.p x := by field_simp [hpne] linarith have hle_all : ∀ y ∈ (Finset.univ : Finset ι), p.p y * Real.log (q.p y / p.p y) ≤ q.p y - p.p y := by intro y _ have hlog := Real.log_le_sub_one_of_pos (div_pos (q.pos y) (p.pos y)) have hmul := mul_le_mul_of_nonneg_left hlog (le_of_lt (p.pos y)) have hpne : p.p y ≠ 0 := ne_of_gt (p.pos y) have hsimp : p.p y * (q.p y / p.p y - 1) = q.p y - p.p y := by field_simp [hpne] linarith have hsum_lt : ∑ y : ι, p.p y * Real.log (q.p y / p.p y) < ∑ y : ι, (q.p y - p.p y) := Finset.sum_lt_sum hle_all ⟨x, Finset.mem_univ x, hstrict_x⟩ have hsum_rhs : ∑ y : ι, (q.p y - p.p y) = 0 := by rw [Finset.sum_sub_distrib, q.sum_one, p.sum_one, sub_self] have hneg : klDiv p q = - ∑ y : ι, p.p y * Real.log (q.p y / p.p y) := by unfold klDiv rw [← Finset.sum_neg_distrib] refine Finset.sum_congr rfl ?_ intro y _ have hinv : Real.log (p.p y / q.p y) = - Real.log (q.p y / p.p y) := by rw [← Real.log_inv, inv_div] rw [hinv] ring linarith · intro heq subst heq unfold klDiv refine Finset.sum_eq_zero ?_ intro x _ have hpne : p.p x ≠ 0 := ne_of_gt (p.pos x) simp [div_self hpne] lemma klDiv_pos_of_ne {ι : Type*} [Fintype ι] {p q : StrictProb ι} (hne : p ≠ q) : 0 < klDiv p q := by have hge := klDiv_nonneg p q rcases lt_or_eq_of_le hge with hlt | heq · exact hlt · exact absurd ((klDiv_eq_zero_iff p q).mp heq.symm) hne /-! ## Section 2: Discrete Regular Exponential Families & Exact Cumulant Derivatives -/ /-- A discrete regular exponential family on finite sample space `ι` with parameter dimension `d`, sufficient statistic `T : ι → Fin d → ℝ`, and strictly positive base measure `h : ι → ℝ`. -/ structure DiscreteExpFamily (ι : Type*) [Fintype ι] [Nonempty ι] (d : ℕ) where T : ι → Fin d → ℝ h : ι → ℝ h_pos : ∀ x, 0 < h x namespace DiscreteExpFamily variable {ι : Type*} [Fintype ι] [Nonempty ι] {d : ℕ} (ef : DiscreteExpFamily ι d) /-- Partition function `Z(θ) = ∑_x h(x) exp(⟨θ, T(x)⟩)`. -/ def Z (θ : Fin d → ℝ) : ℝ := ∑ x : ι, ef.h x * Real.exp (dotFin θ (ef.T x)) lemma Z_pos (θ : Fin d → ℝ) : 0 < ef.Z θ := by unfold Z obtain ⟨x₀⟩ := ‹Nonempty ι› exact Finset.sum_pos' (fun x _ => le_of_lt (mul_pos (ef.h_pos x) (Real.exp_pos _))) ⟨x₀, Finset.mem_univ x₀, mul_pos (ef.h_pos x₀) (Real.exp_pos _)⟩ /-- Log-partition / cumulant generating function `ψ(θ) = log Z(θ)`. -/ def psi (θ : Fin d → ℝ) : ℝ := Real.log (ef.Z θ) /-- Exponential family distribution `p_θ(x) = h(x) exp(⟨θ, T(x)⟩ - ψ(θ))`. -/ def prob (θ : Fin d → ℝ) : StrictProb ι where p x := ef.h x * Real.exp (dotFin θ (ef.T x) - ef.psi θ) pos x := mul_pos (ef.h_pos x) (Real.exp_pos _) sum_one := by have hZ : 0 < ef.Z θ := ef.Z_pos θ have hrewrite : ∀ x : ι, ef.h x * Real.exp (dotFin θ (ef.T x) - ef.psi θ) = ef.h x * Real.exp (dotFin θ (ef.T x)) / ef.Z θ := by intro x rw [Real.exp_sub, psi, Real.exp_log hZ, mul_div_assoc] simp_rw [hrewrite, ← Finset.sum_div] exact div_self (ne_of_gt hZ) lemma prob_eq_div_Z (θ : Fin d → ℝ) (x : ι) : (ef.prob θ).p x = ef.h x * Real.exp (dotFin θ (ef.T x)) / ef.Z θ := by simp only [prob, psi, Real.exp_sub, Real.exp_log (ef.Z_pos θ), mul_div_assoc] lemma log_prob_eq (θ : Fin d → ℝ) (x : ι) : Real.log ((ef.prob θ).p x) = dotFin θ (ef.T x) - ef.psi θ + Real.log (ef.h x) := by simp only [prob] rw [Real.log_mul (ne_of_gt (ef.h_pos x)) (ne_of_gt (Real.exp_pos _)), Real.log_exp] ring /-- Expectation parameter of an arbitrary distribution `p`: `η(p)_i = E_p[T_i]`. -/ def etaOf (p : StrictProb ι) : Fin d → ℝ := fun i => expVal p (fun x => ef.T x i) /-- Expectation parameter (mean sufficient statistic) `η(θ)_i = E_θ[T_i]`. -/ def eta (θ : Fin d → ℝ) : Fin d → ℝ := ef.etaOf (ef.prob θ) /-- Fisher information / covariance matrix `g_{ij}(θ) = Cov_θ(T_i, T_j)`. -/ def fisher (θ : Fin d → ℝ) (i j : Fin d) : ℝ := expVal (ef.prob θ) (fun x => (ef.T x i - ef.eta θ i) * (ef.T x j - ef.eta θ j)) /-- Amari–Chentsov symmetric 3-tensor `T_{ijk}(θ) = E_θ[(T_i - η_i)(T_j - η_j)(T_k - η_k)]`. -/ def amariChentsov (θ : Fin d → ℝ) (i j k : Fin d) : ℝ := expVal (ef.prob θ) (fun x => (ef.T x i - ef.eta θ i) * (ef.T x j - ef.eta θ j) * (ef.T x k - ef.eta θ k)) /-- Centered score vector `s_i(θ, x) = T_i(x) - η_i(θ)` has zero expectation. -/ lemma score_mean_zero (θ : Fin d → ℝ) (i : Fin d) : expVal (ef.prob θ) (fun x => ef.T x i - ef.eta θ i) = 0 := by rw [expVal_sub, expVal_const] exact sub_self _ /-- Directional derivative of `t ↦ Z(θ + t v)` at `t = 0`. -/ lemma hasDerivAt_Z_dir (θ v : Fin d → ℝ) : HasDerivAt (fun t : ℝ => ef.Z (fun a => θ a + t * v a)) (∑ x : ι, ef.h x * Real.exp (dotFin θ (ef.T x)) * dotFin v (ef.T x)) 0 := by have hterm : ∀ x : ι, HasDerivAt (fun t : ℝ => ef.h x * Real.exp (dotFin (fun a => θ a + t * v a) (ef.T x))) (ef.h x * Real.exp (dotFin θ (ef.T x)) * dotFin v (ef.T x)) 0 := by intro x have hfn : (fun t : ℝ => ef.h x * Real.exp (dotFin (fun a => θ a + t * v a) (ef.T x))) = (fun t : ℝ => ef.h x * Real.exp (dotFin θ (ef.T x) + t * dotFin v (ef.T x))) := by funext t rw [dotFin_add_left, dotFin_smul_left] rw [hfn] have hlin : HasDerivAt (fun t : ℝ => dotFin θ (ef.T x) + t * dotFin v (ef.T x)) (dotFin v (ef.T x)) 0 := by simpa using ((hasDerivAt_id (0 : ℝ)).mul_const (dotFin v (ef.T x))).const_add (dotFin θ (ef.T x)) have hexp : HasDerivAt (fun t : ℝ => Real.exp (dotFin θ (ef.T x) + t * dotFin v (ef.T x))) (Real.exp (dotFin θ (ef.T x) + 0 * dotFin v (ef.T x)) * dotFin v (ef.T x)) 0 := hlin.exp simpa [mul_assoc] using hexp.const_mul (ef.h x) have hsum := HasDerivAt.fun_sum (u := Finset.univ) fun x _ => hterm x simpa [Z] using hsum /-- **Theorem 1.1 (Exact First Cumulant Derivative Identity):** `d/dt|_{t=0} ψ(θ + t v) = ⟨v, η(θ)⟩`. -/ theorem hasDerivAt_psi_dir (θ v : Fin d → ℝ) : HasDerivAt (fun t : ℝ => ef.psi (fun a => θ a + t * v a)) (dotFin v (ef.eta θ)) 0 := by have hZ0 : ef.Z (fun a => θ a + (0 : ℝ) * v a) ≠ 0 := by simpa using ne_of_gt (ef.Z_pos θ) have hlog : HasDerivAt (fun t : ℝ => Real.log (ef.Z (fun a => θ a + t * v a))) ((∑ x : ι, ef.h x * Real.exp (dotFin θ (ef.T x)) * dotFin v (ef.T x)) / ef.Z (fun a => θ a + (0 : ℝ) * v a)) 0 := (ef.hasDerivAt_Z_dir θ v).log hZ0 have hval : (∑ x : ι, ef.h x * Real.exp (dotFin θ (ef.T x)) * dotFin v (ef.T x)) / ef.Z (fun a => θ a + (0 : ℝ) * v a) = dotFin v (ef.eta θ) := by have hθ0 : (fun a => θ a + (0 : ℝ) * v a) = θ := by funext a; ring rw [hθ0, Finset.sum_div] calc ∑ x : ι, ef.h x * Real.exp (dotFin θ (ef.T x)) * dotFin v (ef.T x) / ef.Z θ = ∑ x : ι, (ef.prob θ).p x * dotFin v (ef.T x) := by refine Finset.sum_congr rfl ?_ intro x _ rw [ef.prob_eq_div_Z] ring _ = ∑ x : ι, ∑ i : Fin d, (ef.prob θ).p x * (v i * ef.T x i) := by refine Finset.sum_congr rfl ?_ intro x _ unfold dotFin rw [Finset.mul_sum] _ = ∑ i : Fin d, ∑ x : ι, v i * ((ef.prob θ).p x * ef.T x i) := by rw [Finset.sum_comm] refine Finset.sum_congr rfl ?_ intro i _ refine Finset.sum_congr rfl ?_ intro x _ ring _ = dotFin v (ef.eta θ) := by unfold dotFin eta etaOf expVal refine Finset.sum_congr rfl ?_ intro i _ rw [← Finset.mul_sum] rw [hval] at hlog exact hlog /-- Coordinate partial derivative `∂_i ψ(θ) = η_i(θ) = E_θ[T_i]`. -/ theorem deriv_psi_coord (θ : Fin d → ℝ) (i : Fin d) : deriv (fun t : ℝ => ef.psi (fun a => θ a + t * basisVec i a)) 0 = ef.eta θ i := by rw [(ef.hasDerivAt_psi_dir θ (basisVec i)).deriv, dotFin_basis_left] /-- Exact directional derivative of probability mass `t ↦ p_{θ + t v}(x)` at `t = 0`: `d/dt|_{t=0} p_{θ + t v}(x) = p_θ(x) (⟨v, T(x)⟩ - ⟨v, η(θ)⟩)`. -/ theorem hasDerivAt_prob_dir (θ v : Fin d → ℝ) (x : ι) : HasDerivAt (fun t : ℝ => (ef.prob (fun a => θ a + t * v a)).p x) ((ef.prob θ).p x * (dotFin v (ef.T x) - dotFin v (ef.eta θ))) 0 := by have hdot : (fun t : ℝ => dotFin (fun a => θ a + t * v a) (ef.T x)) = (fun t : ℝ => dotFin θ (ef.T x) + t * dotFin v (ef.T x)) := by funext t rw [dotFin_add_left, dotFin_smul_left] have hlin : HasDerivAt (fun t : ℝ => dotFin (fun a => θ a + t * v a) (ef.T x)) (dotFin v (ef.T x)) 0 := by rw [hdot] simpa using ((hasDerivAt_id (0 : ℝ)).mul_const (dotFin v (ef.T x))).const_add (dotFin θ (ef.T x)) have hsub := hlin.fun_sub (ef.hasDerivAt_psi_dir θ v) have hexp := hsub.exp.const_mul (ef.h x) have hθ0 : (fun a => θ a + (0 : ℝ) * v a) = θ := by funext a; ring have heq : ef.h x * (Real.exp (dotFin (fun a => θ a + (0 : ℝ) * v a) (ef.T x) - ef.psi (fun a => θ a + (0 : ℝ) * v a)) * (dotFin v (ef.T x) - dotFin v (ef.eta θ))) = (ef.prob θ).p x * (dotFin v (ef.T x) - dotFin v (ef.eta θ)) := by rw [hθ0] simp only [prob] ring rw [heq] at hexp exact hexp /-- **Theorem 1.2 (Exact Second Cumulant Derivative Identity / Fisher = Covariance = Hessian):** `d/dt|_{t=0} η_i(θ + t v) = ∑_j v_j g_{ij}(θ)`. -/ theorem hasDerivAt_eta_dir (θ v : Fin d → ℝ) (i : Fin d) : HasDerivAt (fun t : ℝ => ef.eta (fun a => θ a + t * v a) i) (∑ j : Fin d, v j * ef.fisher θ i j) 0 := by have hterm : ∀ x : ι, HasDerivAt (fun t : ℝ => (ef.prob (fun a => θ a + t * v a)).p x * ef.T x i) ((ef.prob θ).p x * (dotFin v (ef.T x) - dotFin v (ef.eta θ)) * ef.T x i) 0 := fun x => (ef.hasDerivAt_prob_dir θ v x).mul_const (ef.T x i) have hsum := HasDerivAt.fun_sum (u := Finset.univ) fun x _ => hterm x have hval : ∑ x : ι, (ef.prob θ).p x * (dotFin v (ef.T x) - dotFin v (ef.eta θ)) * ef.T x i = ∑ j : Fin d, v j * ef.fisher θ i j := by have hzero : ∑ x : ι, (ef.prob θ).p x * (dotFin v (ef.T x) - dotFin v (ef.eta θ)) * ef.eta θ i = 0 := by have h1 : ∑ x : ι, (ef.prob θ).p x * (dotFin v (ef.T x) - dotFin v (ef.eta θ)) = 0 := by calc ∑ x : ι, (ef.prob θ).p x * (dotFin v (ef.T x) - dotFin v (ef.eta θ)) = ∑ x : ι, ∑ j : Fin d, v j * ((ef.prob θ).p x * (ef.T x j - ef.eta θ j)) := by refine Finset.sum_congr rfl ?_ intro x _ rw [← dotFin_sub_right] unfold dotFin rw [Finset.mul_sum] refine Finset.sum_congr rfl ?_ intro j _ ring _ = ∑ j : Fin d, v j * expVal (ef.prob θ) (fun x => ef.T x j - ef.eta θ j) := by rw [Finset.sum_comm] refine Finset.sum_congr rfl ?_ intro j _ unfold expVal rw [← Finset.mul_sum] _ = 0 := by refine Finset.sum_eq_zero ?_ intro j _ rw [ef.score_mean_zero θ j, mul_zero] rw [← Finset.sum_mul, h1, zero_mul] calc ∑ x : ι, (ef.prob θ).p x * (dotFin v (ef.T x) - dotFin v (ef.eta θ)) * ef.T x i = ∑ x : ι, (ef.prob θ).p x * (dotFin v (ef.T x) - dotFin v (ef.eta θ)) * (ef.T x i - ef.eta θ i) := by have hdiff : ∑ x : ι, (ef.prob θ).p x * (dotFin v (ef.T x) - dotFin v (ef.eta θ)) * (ef.T x i - ef.eta θ i) = (∑ x : ι, (ef.prob θ).p x * (dotFin v (ef.T x) - dotFin v (ef.eta θ)) * ef.T x i) - (∑ x : ι, (ef.prob θ).p x * (dotFin v (ef.T x) - dotFin v (ef.eta θ)) * ef.eta θ i) := by rw [← Finset.sum_sub_distrib] refine Finset.sum_congr rfl ?_ intro x _ ring linarith _ = ∑ x : ι, ∑ j : Fin d, v j * ((ef.prob θ).p x * ((ef.T x i - ef.eta θ i) * (ef.T x j - ef.eta θ j))) := by refine Finset.sum_congr rfl ?_ intro x _ rw [← dotFin_sub_right] unfold dotFin rw [Finset.mul_sum, Finset.sum_mul] refine Finset.sum_congr rfl ?_ intro j _ ring _ = ∑ j : Fin d, v j * ef.fisher θ i j := by rw [Finset.sum_comm] refine Finset.sum_congr rfl ?_ intro j _ unfold fisher expVal rw [← Finset.mul_sum] rw [hval] at hsum exact hsum /-- Coordinate partial derivative `∂_j η_i(θ) = ∂_j ∂_i ψ(θ) = g_{ij}(θ)`. -/ theorem hessian_psi_eq_fisher (θ : Fin d → ℝ) (i j : Fin d) : deriv (fun t : ℝ => ef.eta (fun a => θ a + t * basisVec j a) i) 0 = ef.fisher θ i j := by rw [(ef.hasDerivAt_eta_dir θ (basisVec j) i).deriv] simp [basisVec] /-- **Theorem 1.3 (Exact Third Cumulant Derivative Identity / Amari–Chentsov Tensor):** `d/dt|_{t=0} g_{ij}(θ + t v) = ∑_k v_k T_{ijk}(θ)`. -/ theorem hasDerivAt_fisher_dir (θ v : Fin d → ℝ) (i j : Fin d) : HasDerivAt (fun t : ℝ => ef.fisher (fun a => θ a + t * v a) i j) (∑ k : Fin d, v k * ef.amariChentsov θ i j k) 0 := by have hci : HasDerivAt (fun t : ℝ => ef.eta (fun a => θ a + t * v a) i) (∑ k : Fin d, v k * ef.fisher θ i k) 0 := ef.hasDerivAt_eta_dir θ v i have hcj : HasDerivAt (fun t : ℝ => ef.eta (fun a => θ a + t * v a) j) (∑ k : Fin d, v k * ef.fisher θ j k) 0 := ef.hasDerivAt_eta_dir θ v j have hθ0 : (fun a => θ a + (0 : ℝ) * v a) = θ := by funext a; ring have hterm : ∀ x : ι, HasDerivAt (fun t : ℝ => (ef.prob (fun a => θ a + t * v a)).p x * ((ef.T x i - ef.eta (fun a => θ a + t * v a) i) * (ef.T x j - ef.eta (fun a => θ a + t * v a) j))) (((ef.prob θ).p x * (dotFin v (ef.T x) - dotFin v (ef.eta θ))) * ((ef.T x i - ef.eta θ i) * (ef.T x j - ef.eta θ j)) + (ef.prob θ).p x * ((-(∑ k : Fin d, v k * ef.fisher θ i k)) * (ef.T x j - ef.eta θ j) + (ef.T x i - ef.eta θ i) * (-(∑ k : Fin d, v k * ef.fisher θ j k)))) 0 := by intro x have hp := ef.hasDerivAt_prob_dir θ v x have hsi : HasDerivAt (fun t : ℝ => ef.T x i - ef.eta (fun a => θ a + t * v a) i) (-(∑ k : Fin d, v k * ef.fisher θ i k)) 0 := by simpa using (hasDerivAt_const (0 : ℝ) (ef.T x i)).fun_sub hci have hsj : HasDerivAt (fun t : ℝ => ef.T x j - ef.eta (fun a => θ a + t * v a) j) (-(∑ k : Fin d, v k * ef.fisher θ j k)) 0 := by simpa using (hasDerivAt_const (0 : ℝ) (ef.T x j)).fun_sub hcj have hprod := hp.fun_mul (hsi.fun_mul hsj) rw [hθ0] at hprod exact hprod have hsum := HasDerivAt.fun_sum (u := Finset.univ) fun x _ => hterm x have hval : ∑ x : ι, (((ef.prob θ).p x * (dotFin v (ef.T x) - dotFin v (ef.eta θ))) * ((ef.T x i - ef.eta θ i) * (ef.T x j - ef.eta θ j)) + (ef.prob θ).p x * ((-(∑ k : Fin d, v k * ef.fisher θ i k)) * (ef.T x j - ef.eta θ j) + (ef.T x i - ef.eta θ i) * (-(∑ k : Fin d, v k * ef.fisher θ j k)))) = ∑ k : Fin d, v k * ef.amariChentsov θ i j k := by rw [Finset.sum_add_distrib] have hvanish : ∑ x : ι, (ef.prob θ).p x * ((-(∑ k : Fin d, v k * ef.fisher θ i k)) * (ef.T x j - ef.eta θ j) + (ef.T x i - ef.eta θ i) * (-(∑ k : Fin d, v k * ef.fisher θ j k))) = 0 := by have hsplit : ∑ x : ι, (ef.prob θ).p x * ((-(∑ k : Fin d, v k * ef.fisher θ i k)) * (ef.T x j - ef.eta θ j) + (ef.T x i - ef.eta θ i) * (-(∑ k : Fin d, v k * ef.fisher θ j k))) = (-(∑ k : Fin d, v k * ef.fisher θ i k)) * expVal (ef.prob θ) (fun x => ef.T x j - ef.eta θ j) + (-(∑ k : Fin d, v k * ef.fisher θ j k)) * expVal (ef.prob θ) (fun x => ef.T x i - ef.eta θ i) := by unfold expVal rw [Finset.mul_sum, Finset.mul_sum, ← Finset.sum_add_distrib] refine Finset.sum_congr rfl ?_ intro x _ ring rw [hsplit, ef.score_mean_zero θ j, ef.score_mean_zero θ i] ring rw [hvanish, add_zero] calc ∑ x : ι, (ef.prob θ).p x * (dotFin v (ef.T x) - dotFin v (ef.eta θ)) * ((ef.T x i - ef.eta θ i) * (ef.T x j - ef.eta θ j)) = ∑ x : ι, ∑ k : Fin d, v k * ((ef.prob θ).p x * ((ef.T x i - ef.eta θ i) * (ef.T x j - ef.eta θ j) * (ef.T x k - ef.eta θ k))) := by refine Finset.sum_congr rfl ?_ intro x _ rw [← dotFin_sub_right] unfold dotFin rw [Finset.mul_sum, Finset.sum_mul] refine Finset.sum_congr rfl ?_ intro k _ ring _ = ∑ k : Fin d, v k * ef.amariChentsov θ i j k := by rw [Finset.sum_comm] refine Finset.sum_congr rfl ?_ intro k _ unfold amariChentsov expVal rw [← Finset.mul_sum] rw [hval] at hsum exact hsum /-- Coordinate partial derivative `∂_k g_{ij}(θ) = ∂_k ∂_j ∂_i ψ(θ) = T_{ijk}(θ)`. -/ theorem third_deriv_psi_eq_amariChentsov (θ : Fin d → ℝ) (i j k : Fin d) : deriv (fun t : ℝ => ef.fisher (fun a => θ a + t * basisVec k a) i j) 0 = ef.amariChentsov θ i j k := by rw [(ef.hasDerivAt_fisher_dir θ (basisVec k) i j).deriv] simp [basisVec] /-! ## Section 3: Positive Definiteness, Minimality, Strict Convexity & Mirror Map Injectivity -/ /-- Exact quadratic-form identity: `vᵀ I(θ) v = Var_θ(⟨v, T⟩) ≥ 0`. -/ theorem fisher_quadForm_eq_var (θ v : Fin d → ℝ) : ∑ i : Fin d, ∑ j : Fin d, v i * ef.fisher θ i j * v j = expVal (ef.prob θ) (fun x => (dotFin v (ef.T x) - dotFin v (ef.eta θ)) ^ 2) := by unfold fisher expVal calc ∑ i : Fin d, ∑ j : Fin d, v i * (∑ x : ι, (ef.prob θ).p x * ((ef.T x i - ef.eta θ i) * (ef.T x j - ef.eta θ j))) * v j = ∑ i : Fin d, ∑ j : Fin d, ∑ x : ι, (ef.prob θ).p x * ((v i * (ef.T x i - ef.eta θ i)) * (v j * (ef.T x j - ef.eta θ j))) := by refine Finset.sum_congr rfl ?_ intro i _ refine Finset.sum_congr rfl ?_ intro j _ rw [Finset.mul_sum, Finset.sum_mul] refine Finset.sum_congr rfl ?_ intro x _ ring _ = ∑ x : ι, ∑ i : Fin d, ∑ j : Fin d, (ef.prob θ).p x * ((v i * (ef.T x i - ef.eta θ i)) * (v j * (ef.T x j - ef.eta θ j))) := by trans (∑ i : Fin d, ∑ x : ι, ∑ j : Fin d, (ef.prob θ).p x * ((v i * (ef.T x i - ef.eta θ i)) * (v j * (ef.T x j - ef.eta θ j)))) · refine Finset.sum_congr rfl ?_ intro i _ exact Finset.sum_comm · exact Finset.sum_comm _ = ∑ x : ι, (ef.prob θ).p x * (dotFin v (ef.T x) - dotFin v (ef.eta θ)) ^ 2 := by refine Finset.sum_congr rfl ?_ intro x _ rw [← dotFin_sub_right] unfold dotFin rw [sq, Finset.sum_mul_sum, Finset.mul_sum] refine Finset.sum_congr rfl ?_ intro i _ rw [Finset.mul_sum] /-- Fisher information matrix is always positive semidefinite. -/ theorem fisher_psd (θ v : Fin d → ℝ) : 0 ≤ ∑ i : Fin d, ∑ j : Fin d, v i * ef.fisher θ i j * v j := by rw [ef.fisher_quadForm_eq_var] exact expVal_nonneg _ fun x => sq_nonneg _ /-- Minimal exponential family representation: no nonzero `v` makes `x ↦ ⟨v, T(x)⟩` constant. -/ def IsMinimal : Prop := ∀ v : Fin d → ℝ, (∃ c : ℝ, ∀ x : ι, dotFin v (ef.T x) = c) → v = 0 /-- **Theorem 1.4 (Strict Positive Definiteness ↔ Minimal Representation):** `I(θ) ≻ 0` at `θ` if and only if the exponential family is minimal! -/ theorem fisher_posDef_iff_minimal (θ : Fin d → ℝ) : (∀ v : Fin d → ℝ, v ≠ 0 → 0 < ∑ i : Fin d, ∑ j : Fin d, v i * ef.fisher θ i j * v j) ↔ ef.IsMinimal := by constructor · intro hpd v ⟨c, hc⟩ by_contra hv0 have hpos := hpd v hv0 rw [ef.fisher_quadForm_eq_var] at hpos have heta_eq : dotFin v (ef.eta θ) = c := by calc dotFin v (ef.eta θ) = ∑ i : Fin d, v i * (∑ x : ι, (ef.prob θ).p x * ef.T x i) := rfl _ = ∑ x : ι, (ef.prob θ).p x * dotFin v (ef.T x) := by simp_rw [Finset.mul_sum] rw [Finset.sum_comm] refine Finset.sum_congr rfl ?_ intro x _ unfold dotFin rw [Finset.mul_sum] refine Finset.sum_congr rfl ?_ intro i _ ring _ = ∑ x : ι, (ef.prob θ).p x * c := by refine Finset.sum_congr rfl ?_ intro x _ rw [hc x] _ = c := expVal_const (ef.prob θ) c have hzero : expVal (ef.prob θ) (fun x => (dotFin v (ef.T x) - dotFin v (ef.eta θ)) ^ 2) = 0 := by unfold expVal refine Finset.sum_eq_zero ?_ intro x _ dsimp only rw [hc x, heta_eq, sub_self] ring linarith · intro hmin v hv0 have hge := ef.fisher_psd θ v rcases lt_or_eq_of_le hge with hlt | heq · exact hlt · rw [ef.fisher_quadForm_eq_var] at heq have hall := (expVal_sq_eq_zero_iff (ef.prob θ) _).mp heq.symm have hconst : ∀ x : ι, dotFin v (ef.T x) = dotFin v (ef.eta θ) := fun x => sub_eq_zero.mp (hall x) exact absurd (hmin v ⟨dotFin v (ef.eta θ), hconst⟩) hv0 /-- Under minimality, `p_{θ₁} = p_{θ₂}` implies `θ₁ = θ₂` (identifiability). -/ theorem prob_injective_of_minimal (hmin : ef.IsMinimal) {θ₁ θ₂ : Fin d → ℝ} (heq : ef.prob θ₁ = ef.prob θ₂) : θ₁ = θ₂ := by have hconst : ∀ x : ι, dotFin (fun i => θ₁ i - θ₂ i) (ef.T x) = ef.psi θ₁ - ef.psi θ₂ := by intro x have hpx : (ef.prob θ₁).p x = (ef.prob θ₂).p x := congrArg (fun q => q.p x) heq have hlog := congrArg Real.log hpx rw [ef.log_prob_eq θ₁ x, ef.log_prob_eq θ₂ x] at hlog rw [dotFin_sub_left] linarith have hzero := hmin (fun i => θ₁ i - θ₂ i) ⟨ef.psi θ₁ - ef.psi θ₂, hconst⟩ funext i exact sub_eq_zero.mp (congrFun hzero i) /-! ## Section 4: Exact Legendre–Fenchel Duality, Negative Entropy & KL–Bregman Duality -/ /-- Dual potential (negative entropy relative to base measure `h`): `φ(p) = ∑_x p(x) log (p(x) / h(x)) = -H(p) - E_p[log h]`. -/ def negEntropyBase (p : StrictProb ι) : ℝ := ∑ x : ι, p.p x * Real.log (p.p x / ef.h x) /-- Exact relation to Shannon entropy: `φ(p) = -H(p) - E_p[log h]`. -/ theorem negEntropyBase_eq_neg_shannon_sub_base (p : StrictProb ι) : ef.negEntropyBase p = - shannonEntropy p - expVal p (fun x => Real.log (ef.h x)) := by unfold negEntropyBase shannonEntropy expVal rw [neg_neg, ← Finset.sum_sub_distrib] refine Finset.sum_congr rfl ?_ intro x _ rw [Real.log_div (ne_of_gt (p.pos x)) (ne_of_gt (ef.h_pos x))] ring /-- For counting base measure `h ≡ 1`, the dual potential `φ(p)` is identically `-H(p)`. -/ theorem negEntropyBase_eq_neg_shannon_of_counting (hh : ∀ x, ef.h x = 1) (p : StrictProb ι) : ef.negEntropyBase p = - shannonEntropy p := by rw [ef.negEntropyBase_eq_neg_shannon_sub_base] have hzero : expVal p (fun x => Real.log (ef.h x)) = 0 := by unfold expVal simp [hh] linarith /-- **Theorem 1.5a (Exact Fenchel–Young Gap Identity):** For EVERY `θ ∈ ℝ^d` and EVERY `p ∈ Δ_ι°`, `φ(p) - (⟨θ, η(p)⟩ - ψ(θ)) = D_KL(p ‖ p_θ)`. -/ theorem fenchel_young_exact_gap (θ : Fin d → ℝ) (p : StrictProb ι) : ef.negEntropyBase p - (dotFin θ (ef.etaOf p) - ef.psi θ) = klDiv p (ef.prob θ) := by have hdot : dotFin θ (ef.etaOf p) = expVal p (fun x => dotFin θ (ef.T x)) := by unfold dotFin etaOf expVal simp_rw [Finset.mul_sum] rw [Finset.sum_comm] refine Finset.sum_congr rfl ?_ intro x _ refine Finset.sum_congr rfl ?_ intro i _ ring rw [hdot] unfold negEntropyBase klDiv expVal have hpsi : ef.psi θ = ∑ x : ι, p.p x * ef.psi θ := (expVal_const p (ef.psi θ)).symm rw [hpsi] rw [← Finset.sum_sub_distrib, ← Finset.sum_sub_distrib] refine Finset.sum_congr rfl ?_ intro x _ rw [Real.log_div (ne_of_gt (p.pos x)) (ne_of_gt (ef.h_pos x)), Real.log_div (ne_of_gt (p.pos x)) (ne_of_gt ((ef.prob θ).pos x)), ef.log_prob_eq θ x] ring /-- **Theorem 1.5b (Fenchel–Young Inequality):** `⟨θ, η(p)⟩ - ψ(θ) ≤ φ(p)`. -/ theorem fenchel_young_le (θ : Fin d → ℝ) (p : StrictProb ι) : dotFin θ (ef.etaOf p) - ef.psi θ ≤ ef.negEntropyBase p := by have h := ef.fenchel_young_exact_gap θ p have hkl := klDiv_nonneg p (ef.prob θ) linarith /-- **Theorem 1.5c (Fenchel–Young Equality Characterization):** `⟨θ, η(p)⟩ - ψ(θ) = φ(p) ↔ p = p_θ`. -/ theorem fenchel_young_eq_iff (θ : Fin d → ℝ) (p : StrictProb ι) : dotFin θ (ef.etaOf p) - ef.psi θ = ef.negEntropyBase p ↔ p = ef.prob θ := by have h := ef.fenchel_young_exact_gap θ p rw [← klDiv_eq_zero_iff] constructor <;> intro h1 <;> linarith /-- **Exact Dual Potential Value at `p_θ`:** `φ(p_θ) = ⟨θ, η(θ)⟩ - ψ(θ)`. -/ theorem negEntropyBase_prob_eq (θ : Fin d → ℝ) : ef.negEntropyBase (ef.prob θ) = dotFin θ (ef.eta θ) - ef.psi θ := by exact ((ef.fenchel_young_eq_iff θ (ef.prob θ)).mpr rfl).symm /-- **Theorem 1.6a (Exact Variational Legendre–Fenchel Conjugate `φ = ψ*`):** `φ(p_{θ₀}) = max_θ (⟨θ, η(θ₀)⟩ - ψ(θ)) = ⨆_θ (⟨θ, η(θ₀)⟩ - ψ(θ))`. -/ theorem legendre_conjugate_isGreatest (θ₀ : Fin d → ℝ) : IsGreatest (Set.range (fun θ : Fin d → ℝ => dotFin θ (ef.eta θ₀) - ef.psi θ)) (ef.negEntropyBase (ef.prob θ₀)) := by constructor · exact ⟨θ₀, (ef.negEntropyBase_prob_eq θ₀).symm⟩ · rintro y ⟨θ, rfl⟩ exact ef.fenchel_young_le θ (ef.prob θ₀) theorem legendre_conjugate_iSup_eq (θ₀ : Fin d → ℝ) : (⨆ θ : Fin d → ℝ, (dotFin θ (ef.eta θ₀) - ef.psi θ)) = ef.negEntropyBase (ef.prob θ₀) := (ef.legendre_conjugate_isGreatest θ₀).csSup_eq /-- **Theorem 1.6b (Gibbs Variational Principle / Dual Conjugate `ψ = φ*`):** `ψ(θ) = max_{p ∈ Δ_ι°} (⟨θ, η(p)⟩ - φ(p))`. -/ theorem gibbs_variational_isGreatest (θ : Fin d → ℝ) : IsGreatest (Set.range (fun p : StrictProb ι => dotFin θ (ef.etaOf p) - ef.negEntropyBase p)) (ef.psi θ) := by constructor · refine ⟨ef.prob θ, ?_⟩ have h := ef.negEntropyBase_prob_eq θ unfold eta at h linarith · rintro y ⟨p, rfl⟩ have h := ef.fenchel_young_le θ p linarith /-- Primal Bregman divergence generated by `ψ`: `D_ψ(θ₂, θ₁) = ψ(θ₂) - ψ(θ₁) - ⟨∇ψ(θ₁), θ₂ - θ₁⟩`. -/ def bregmanPsi (θ₂ θ₁ : Fin d → ℝ) : ℝ := ef.psi θ₂ - ef.psi θ₁ - dotFin (ef.eta θ₁) (fun i => θ₂ i - θ₁ i) /-- Dual Bregman divergence generated by `φ` (using `∇φ(η₂) = θ₂`): `D_φ(η₁, η₂) = φ(p_{θ₁}) - φ(p_{θ₂}) - ⟨θ₂, η₁ - η₂⟩`. -/ def bregmanPhi (θ₁ θ₂ : Fin d → ℝ) : ℝ := ef.negEntropyBase (ef.prob θ₁) - ef.negEntropyBase (ef.prob θ₂) - dotFin θ₂ (fun i => ef.eta θ₁ i - ef.eta θ₂ i) /-- **Theorem 1.7a (Exact KL–Bregman Primal Duality with Exact Argument Reversal):** `D_KL(p_{θ₁} ‖ p_{θ₂}) = D_ψ(θ₂, θ₁)`. -/ theorem kl_eq_bregmanPsi (θ₁ θ₂ : Fin d → ℝ) : klDiv (ef.prob θ₁) (ef.prob θ₂) = ef.bregmanPsi θ₂ θ₁ := by rw [← ef.fenchel_young_exact_gap θ₂ (ef.prob θ₁), ef.negEntropyBase_prob_eq θ₁] unfold bregmanPsi eta rw [dotFin_sub_right, dotFin_comm (ef.etaOf (ef.prob θ₁)) θ₂, dotFin_comm (ef.etaOf (ef.prob θ₁)) θ₁] ring /-- **Theorem 1.7b (Exact KL–Bregman Dual Identity):** `D_KL(p_{θ₁} ‖ p_{θ₂}) = D_φ(η₁, η₂)`. -/ theorem kl_eq_bregmanPhi (θ₁ θ₂ : Fin d → ℝ) : klDiv (ef.prob θ₁) (ef.prob θ₂) = ef.bregmanPhi θ₁ θ₂ := by rw [← ef.fenchel_young_exact_gap θ₂ (ef.prob θ₁)] unfold bregmanPhi rw [ef.negEntropyBase_prob_eq θ₂, dotFin_sub_right] unfold eta ring /-- **Theorem 1.7c (Three-Way KL–Bregman–Fenchel Duality Master Identity):** `D_KL(p_{θ₁} ‖ p_{θ₂}) = D_ψ(θ₂, θ₁) = D_φ(η₁, η₂) = ψ(θ₂) + φ(p_{θ₁}) - ⟨θ₂, η₁⟩`. -/ theorem kl_bregman_fenchel_master_duality (θ₁ θ₂ : Fin d → ℝ) : klDiv (ef.prob θ₁) (ef.prob θ₂) = ef.bregmanPsi θ₂ θ₁ ∧ ef.bregmanPsi θ₂ θ₁ = ef.bregmanPhi θ₁ θ₂ ∧ ef.bregmanPhi θ₁ θ₂ = ef.psi θ₂ + ef.negEntropyBase (ef.prob θ₁) - dotFin θ₂ (ef.eta θ₁) := by have h1 := ef.kl_eq_bregmanPsi θ₁ θ₂ have h2 := ef.kl_eq_bregmanPhi θ₁ θ₂ have h3 := ef.fenchel_young_exact_gap θ₂ (ef.prob θ₁) unfold eta refine ⟨h1, by linarith, by linarith⟩ /-- **Global Convexity of `ψ`:** `ψ(θ₂) ≥ ψ(θ₁) + ⟨∇ψ(θ₁), θ₂ - θ₁⟩`. -/ theorem psi_convex_subgrad (θ₁ θ₂ : Fin d → ℝ) : ef.psi θ₁ + dotFin (ef.eta θ₁) (fun i => θ₂ i - θ₁ i) ≤ ef.psi θ₂ := by have h := ef.kl_eq_bregmanPsi θ₁ θ₂ have hge := klDiv_nonneg (ef.prob θ₁) (ef.prob θ₂) unfold bregmanPsi at h linarith /-- **Global Strict Convexity of `ψ` under Minimal Representation:** For all `θ₁ ≠ θ₂`, `ψ(θ₂) > ψ(θ₁) + ⟨∇ψ(θ₁), θ₂ - θ₁⟩` (i.e., `D_ψ(θ₂, θ₁) > 0`). -/ theorem psi_strict_convex_of_minimal (hmin : ef.IsMinimal) {θ₁ θ₂ : Fin d → ℝ} (hne : θ₁ ≠ θ₂) : ef.psi θ₁ + dotFin (ef.eta θ₁) (fun i => θ₂ i - θ₁ i) < ef.psi θ₂ := by have hne_prob : ef.prob θ₁ ≠ ef.prob θ₂ := fun heq => hne (ef.prob_injective_of_minimal hmin heq) have hpos := klDiv_pos_of_ne hne_prob rw [ef.kl_eq_bregmanPsi] at hpos unfold bregmanPsi at hpos linarith /-- **Exact Jeffreys–Bregman Symmetrization Identity:** `J(p_{θ₁}, p_{θ₂}) = D_ψ(θ₁, θ₂) + D_ψ(θ₂, θ₁) = ⟨θ₁ - θ₂, η(θ₁) - η(θ₂)⟩`. -/ theorem jeffreys_eq_dual_pairing (θ₁ θ₂ : Fin d → ℝ) : jeffreysDiv (ef.prob θ₁) (ef.prob θ₂) = dotFin (fun i => θ₁ i - θ₂ i) (fun i => ef.eta θ₁ i - ef.eta θ₂ i) := by unfold jeffreysDiv rw [ef.kl_eq_bregmanPsi θ₁ θ₂, ef.kl_eq_bregmanPsi θ₂ θ₁] unfold bregmanPsi rw [dotFin_sub_right (ef.eta θ₁), dotFin_sub_right (ef.eta θ₂), dotFin_sub_left θ₁ θ₂, dotFin_sub_right θ₁, dotFin_sub_right θ₂, dotFin_comm (ef.eta θ₁) θ₂, dotFin_comm (ef.eta θ₁) θ₁, dotFin_comm (ef.eta θ₂) θ₁, dotFin_comm (ef.eta θ₂) θ₂] ring /-- **Global Injectivity & Strict Monotonicity of the Mirror Map `θ ↦ η(θ)` under Minimality:** `⟨θ₁ - θ₂, η(θ₁) - η(θ₂)⟩ > 0` for all `θ₁ ≠ θ₂`, hence `η(θ₁) = η(θ₂) → θ₁ = θ₂`. -/ theorem eta_strict_monotone_of_minimal (hmin : ef.IsMinimal) {θ₁ θ₂ : Fin d → ℝ} (hne : θ₁ ≠ θ₂) : 0 < dotFin (fun i => θ₁ i - θ₂ i) (fun i => ef.eta θ₁ i - ef.eta θ₂ i) := by rw [← ef.jeffreys_eq_dual_pairing] unfold jeffreysDiv have hne_prob : ef.prob θ₁ ≠ ef.prob θ₂ := fun heq => hne (ef.prob_injective_of_minimal hmin heq) exact add_pos (klDiv_pos_of_ne hne_prob) (klDiv_pos_of_ne hne_prob.symm) theorem eta_injective_of_minimal (hmin : ef.IsMinimal) {θ₁ θ₂ : Fin d → ℝ} (heq : ef.eta θ₁ = ef.eta θ₂) : θ₁ = θ₂ := by by_contra hne have hpos := ef.eta_strict_monotone_of_minimal hmin hne have hzero : dotFin (fun i => θ₁ i - θ₂ i) (fun i => ef.eta θ₁ i - ef.eta θ₂ i) = 0 := by unfold dotFin simp [heq] linarith /-! ## Section 5: Generalized Bregman Pythagorean Theorem & Exact M- and I-Projection Duality -/ /-- **Theorem 3.1a (Exact Generalized Bregman Pythagorean Identity):** For EVERY `p ∈ Δ_ι°` and EVERY `θ_q, θ_r ∈ ℝ^d`, `D_KL(p ‖ p_{θ_r}) = D_KL(p ‖ p_{θ_q}) + D_KL(p_{θ_q} ‖ p_{θ_r}) - ⟨θ_r - θ_q, η(p) - η(θ_q)⟩`. -/ theorem generalized_pythagorean_identity (p : StrictProb ι) (θq θr : Fin d → ℝ) : klDiv p (ef.prob θr) = klDiv p (ef.prob θq) + klDiv (ef.prob θq) (ef.prob θr) - dotFin (fun i => θr i - θq i) (fun i => ef.etaOf p i - ef.eta θq i) := by rw [← ef.fenchel_young_exact_gap θr p, ← ef.fenchel_young_exact_gap θq p, ef.kl_eq_bregmanPsi θq θr] unfold bregmanPsi rw [dotFin_sub_left θr θq, dotFin_sub_right θr, dotFin_sub_right θq, dotFin_sub_right (ef.eta θq), dotFin_comm (ef.eta θq) θr, dotFin_comm (ef.eta θq) θq] ring /-- **Theorem 3.1b (Exact Pythagorean Equality ↔ Dual Fisher-Orthogonality):** `D_KL(p ‖ p_{θ_r}) = D_KL(p ‖ p_{θ_q}) + D_KL(p_{θ_q} ‖ p_{θ_r}) ↔ ⟨θ_r - θ_q, η(p) - η(θ_q)⟩ = 0`. -/ theorem pythagorean_eq_iff_orthogonal (p : StrictProb ι) (θq θr : Fin d → ℝ) : klDiv p (ef.prob θr) = klDiv p (ef.prob θq) + klDiv (ef.prob θq) (ef.prob θr) ↔ dotFin (fun i => θr i - θq i) (fun i => ef.etaOf p i - ef.eta θq i) = 0 := by rw [ef.generalized_pythagorean_identity p θq θr] constructor <;> intro h <;> linarith /-- **Theorem 3.2a (Exact M-Projection Pythagorean Decomposition):** If `p_{θ*}` matches the moments of `p` (`η(θ*) = η(p)`), then for EVERY `θ ∈ ℝ^d`, `D_KL(p ‖ p_θ) = D_KL(p ‖ p_{θ*}) + D_KL(p_{θ*} ‖ p_θ)`. -/ theorem mProjection_pythagorean (p : StrictProb ι) (θstar θ : Fin d → ℝ) (hmatch : ef.eta θstar = ef.etaOf p) : klDiv p (ef.prob θ) = klDiv p (ef.prob θstar) + klDiv (ef.prob θstar) (ef.prob θ) := by rw [ef.pythagorean_eq_iff_orthogonal] unfold dotFin simp [hmatch] /-- **Theorem 3.2b (Exact M-Projection Optimality & Uniqueness):** Moment matching `η(θ*) = η(p)` uniquely minimizes `θ ↦ D_KL(p ‖ p_θ)` over the exponential family! -/ theorem mProjection_min_and_unique (p : StrictProb ι) (θstar : Fin d → ℝ) (hmatch : ef.eta θstar = ef.etaOf p) : (∀ θ : Fin d → ℝ, klDiv p (ef.prob θstar) ≤ klDiv p (ef.prob θ)) ∧ (∀ θ : Fin d → ℝ, klDiv p (ef.prob θ) = klDiv p (ef.prob θstar) ↔ ef.prob θ = ef.prob θstar) := by constructor · intro θ rw [ef.mProjection_pythagorean p θstar θ hmatch] linarith [klDiv_nonneg (ef.prob θstar) (ef.prob θ)] · intro θ rw [ef.mProjection_pythagorean p θstar θ hmatch] constructor · intro h have h0 : klDiv (ef.prob θstar) (ef.prob θ) = 0 := by linarith exact ((klDiv_eq_zero_iff _ _).mp h0).symm · intro heq rw [heq] have h0 := (klDiv_eq_zero_iff (ef.prob θstar) (ef.prob θstar)).mpr rfl linarith /-- Under minimality, the M-projection natural parameter `θ*` is strictly unique. -/ theorem mProjection_unique_param_of_minimal (hmin : ef.IsMinimal) (p : StrictProb ι) (θstar : Fin d → ℝ) (hmatch : ef.eta θstar = ef.etaOf p) (θ : Fin d → ℝ) : klDiv p (ef.prob θ) = klDiv p (ef.prob θstar) ↔ θ = θstar := by rw [(ef.mProjection_min_and_unique p θstar hmatch).2 θ] exact ⟨ef.prob_injective_of_minimal hmin, fun h => by rw [h]⟩ /-- **Theorem 3.2c (Exact M-Projection = Maximum Likelihood Equivalence):** Moment matching `η(θ*) = η(p)` uniquely maximizes expected log-likelihood `E_p[log p_θ]`, with exact excess `E_p[log p_{θ*}] - E_p[log p_θ] = D_KL(p_{θ*} ‖ p_θ) ≥ 0`. -/ theorem mProjection_eq_mle (p : StrictProb ι) (θstar θ : Fin d → ℝ) (hmatch : ef.eta θstar = ef.etaOf p) : expVal p (fun x => Real.log ((ef.prob θstar).p x)) - expVal p (fun x => Real.log ((ef.prob θ).p x)) = klDiv (ef.prob θstar) (ef.prob θ) := by have hpyth := ef.mProjection_pythagorean p θstar θ hmatch have hkl_exp : ∀ q : StrictProb ι, klDiv p q = - shannonEntropy p - expVal p (fun x => Real.log (q.p x)) := by intro q unfold klDiv shannonEntropy expVal rw [neg_neg, ← Finset.sum_sub_distrib] refine Finset.sum_congr rfl ?_ intro x _ rw [Real.log_div (ne_of_gt (p.pos x)) (ne_of_gt (q.pos x))] ring rw [hkl_exp (ef.prob θ), hkl_exp (ef.prob θstar)] at hpyth linarith /-- Exponential tilting family with reference distribution `r` as base measure. -/ def tiltFamily (r : StrictProb ι) (T : ι → Fin d → ℝ) : DiscreteExpFamily ι d where T := T h := r.p h_pos := r.pos /-- **Theorem 3.3a (Exact I-Projection onto Linear/Moment Families = Gibbs Tilting):** Let `q*(x) = r(x) exp(⟨θ*, T(x)⟩ - ψ_r(θ*))` be the exponential tilt of `r`. Then for EVERY distribution `q` sharing the same moments `E_q[T] = E_{q*}[T]`, `D_KL(q ‖ r) = D_KL(q ‖ q*) + D_KL(q* ‖ r)`. -/ theorem iProjection_pythagorean (r : StrictProb ι) (T : ι → Fin d → ℝ) (θstar : Fin d → ℝ) (q : StrictProb ι) (hmatch : (tiltFamily r T).etaOf q = (tiltFamily r T).eta θstar) : klDiv q r = klDiv q ((tiltFamily r T).prob θstar) + klDiv ((tiltFamily r T).prob θstar) r := by have h0 : (tiltFamily r T).prob (fun _ => 0) = r := by ext x have hZ0 : (tiltFamily r T).Z (fun _ => 0) = 1 := by unfold Z tiltFamily dotFin simp [r.sum_one] have hd : dotFin (fun _ : Fin d => (0 : ℝ)) (T x) = 0 := by unfold dotFin; simp change r.p x * Real.exp (dotFin (fun _ : Fin d => (0 : ℝ)) (T x) - Real.log ((tiltFamily r T).Z (fun _ => 0))) = r.p x rw [hd, hZ0, Real.log_one, sub_zero, Real.exp_zero, mul_one] have hpyth := (tiltFamily r T).generalized_pythagorean_identity q θstar (fun _ => 0) rw [h0] at hpyth have horth : dotFin (fun i => 0 - θstar i) (fun i => (tiltFamily r T).etaOf q i - (tiltFamily r T).eta θstar i) = 0 := by unfold dotFin simp [hmatch] linarith /-- **Theorem 3.3b (Exact I-Projection Unique Optimality):** `q*` uniquely minimizes `D_KL(q ‖ r)` over the linear moment family `{q : E_q[T] = c}`. -/ theorem iProjection_min_and_unique (r : StrictProb ι) (T : ι → Fin d → ℝ) (θstar : Fin d → ℝ) : (∀ q : StrictProb ι, (tiltFamily r T).etaOf q = (tiltFamily r T).eta θstar → klDiv ((tiltFamily r T).prob θstar) r ≤ klDiv q r) ∧ (∀ q : StrictProb ι, (tiltFamily r T).etaOf q = (tiltFamily r T).eta θstar → (klDiv q r = klDiv ((tiltFamily r T).prob θstar) r ↔ q = (tiltFamily r T).prob θstar)) := by constructor · intro q hmatch rw [iProjection_pythagorean r T θstar q hmatch] linarith [klDiv_nonneg q ((tiltFamily r T).prob θstar)] · intro q hmatch rw [iProjection_pythagorean r T θstar q hmatch] constructor · intro h have h0 : klDiv q ((tiltFamily r T).prob θstar) = 0 := by linarith exact (klDiv_eq_zero_iff _ _).mp h0 · intro heq rw [heq] have h0 := (klDiv_eq_zero_iff ((tiltFamily r T).prob θstar) ((tiltFamily r T).prob θstar)).mpr rfl linarith /-- Uniform distribution on a finite nonempty carrier `ι`. -/ def uniformProb (ι : Type*) [Fintype ι] [Nonempty ι] : StrictProb ι where p _ := (1 : ℝ) / (Fintype.card ι : ℝ) pos _ := div_pos one_pos (Nat.cast_pos.mpr Fintype.card_pos) sum_one := by simp only [Finset.sum_const, Finset.card_univ, nsmul_eq_mul] have hc : (Fintype.card ι : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero field_simp [hc] /-- **Theorem 3.3c (Exact Maximum Entropy Principle — Jaynes / Gibbs):** For uniform reference `u`, the Gibbs distribution `q*(x) ∝ exp(⟨θ*, T(x)⟩)` uniquely maximizes Shannon entropy `H(q)` over all distributions matching moments `E_q[T] = E_{q*}[T]`, with exact entropy deficit `H(q*) - H(q) = D_KL(q ‖ q*) ≥ 0`. -/ theorem maxEnt_gibbs_exact_deficit (T : ι → Fin d → ℝ) (θstar : Fin d → ℝ) (q : StrictProb ι) (hmatch : (tiltFamily (uniformProb ι) T).etaOf q = (tiltFamily (uniformProb ι) T).eta θstar) : shannonEntropy ((tiltFamily (uniformProb ι) T).prob θstar) - shannonEntropy q = klDiv q ((tiltFamily (uniformProb ι) T).prob θstar) := by have hkl_unif : ∀ p : StrictProb ι, klDiv p (uniformProb ι) = Real.log (Fintype.card ι : ℝ) - shannonEntropy p := by intro p unfold klDiv shannonEntropy uniformProb have hc : (0 : ℝ) < (Fintype.card ι : ℝ) := Nat.cast_pos.mpr Fintype.card_pos calc ∑ x : ι, p.p x * Real.log (p.p x / (1 / (Fintype.card ι : ℝ))) = ∑ x : ι, (p.p x * Real.log (p.p x) + p.p x * Real.log (Fintype.card ι : ℝ)) := by refine Finset.sum_congr rfl ?_ intro x _ have hdiv : p.p x / (1 / (Fintype.card ι : ℝ)) = p.p x * (Fintype.card ι : ℝ) := by field_simp [ne_of_gt hc] rw [hdiv, Real.log_mul (ne_of_gt (p.pos x)) (ne_of_gt hc)] ring _ = (∑ x : ι, p.p x * Real.log (p.p x)) + Real.log (Fintype.card ι : ℝ) := by rw [Finset.sum_add_distrib, ← Finset.sum_mul, p.sum_one, one_mul] _ = Real.log (Fintype.card ι : ℝ) - (- ∑ x : ι, p.p x * Real.log (p.p x)) := by ring have hpyth := iProjection_pythagorean (uniformProb ι) T θstar q hmatch rw [hkl_unif q, hkl_unif ((tiltFamily (uniformProb ι) T).prob θstar)] at hpyth linarith theorem maxEnt_gibbs_unique_max (T : ι → Fin d → ℝ) (θstar : Fin d → ℝ) (q : StrictProb ι) (hmatch : (tiltFamily (uniformProb ι) T).etaOf q = (tiltFamily (uniformProb ι) T).eta θstar) : shannonEntropy q ≤ shannonEntropy ((tiltFamily (uniformProb ι) T).prob θstar) ∧ (shannonEntropy q = shannonEntropy ((tiltFamily (uniformProb ι) T).prob θstar) ↔ q = (tiltFamily (uniformProb ι) T).prob θstar) := by have hdef := maxEnt_gibbs_exact_deficit T θstar q hmatch have hge := klDiv_nonneg q ((tiltFamily (uniformProb ι) T).prob θstar) refine ⟨by linarith, ?_⟩ rw [← klDiv_eq_zero_iff] constructor <;> intro h <;> linarith /-! ## Section 6: Exact Convex Pythagorean Inequalities (m-Convex & e-Convex Sets) -/ /-- Mixture distribution `(1 - t) p + t q` for `t ∈ [0, 1]`. -/ def mixProb {ι : Type*} [Fintype ι] (p q : StrictProb ι) (t : ℝ) (ht0 : 0 ≤ t) (ht1 : t ≤ 1) : StrictProb ι where p x := (1 - t) * p.p x + t * q.p x pos x := by by_cases ht : t = 0 · subst ht; simpa using p.pos x · have htpos : 0 < t := lt_of_le_of_ne ht0 (Ne.symm ht) have h1 : 0 ≤ (1 - t) * p.p x := mul_nonneg (by linarith) (le_of_lt (p.pos x)) have h2 : 0 < t * q.p x := mul_pos htpos (q.pos x) linarith sum_one := by rw [Finset.sum_add_distrib, ← Finset.mul_sum, ← Finset.mul_sum, p.sum_one, q.sum_one] ring /-- **Theorem 3.4a (Exact m-Convex Pythagorean Inequality):** If `C` is m-convex and `q* ∈ C` minimizes `q ↦ D_KL(q ‖ r)` over `C`, then for ALL `q ∈ C`, `D_KL(q ‖ r) ≥ D_KL(q ‖ q*) + D_KL(q* ‖ r)`. -/ theorem mConvex_pythagorean_ineq {ι : Type*} [Fintype ι] (C : Set (StrictProb ι)) (hconv : ∀ p ∈ C, ∀ q ∈ C, ∀ (t : ℝ) (ht0 : 0 ≤ t) (ht1 : t ≤ 1), mixProb p q t ht0 ht1 ∈ C) (r qstar : StrictProb ι) (hqstar : qstar ∈ C) (hmin : ∀ q ∈ C, klDiv qstar r ≤ klDiv q r) : ∀ q ∈ C, klDiv q qstar + klDiv qstar r ≤ klDiv q r := by intro q hq -- Define smooth extension f(t) = ∑_x ((1-t)q*(x) + t q(x)) log (((1-t)q*(x) + t q(x)) / r(x)) let f : ℝ → ℝ := fun t => ∑ x : ι, ((1 - t) * qstar.p x + t * q.p x) * Real.log (((1 - t) * qstar.p x + t * q.p x) / r.p x) have hf_deriv : HasDerivAt f (∑ x : ι, (q.p x - qstar.p x) * Real.log (qstar.p x / r.p x)) 0 := by have hterm : ∀ x : ι, HasDerivAt (fun t : ℝ => ((1 - t) * qstar.p x + t * q.p x) * Real.log (((1 - t) * qstar.p x + t * q.p x) / r.p x)) ((q.p x - qstar.p x) * Real.log (qstar.p x / r.p x) + (q.p x - qstar.p x)) 0 := by intro x have hlin : HasDerivAt (fun t : ℝ => (1 - t) * qstar.p x + t * q.p x) (q.p x - qstar.p x) 0 := by have h1 : HasDerivAt (fun t : ℝ => 1 - t) (-1) 0 := by simpa using (hasDerivAt_const (0 : ℝ) (1 : ℝ)).fun_sub (hasDerivAt_id (0 : ℝ)) have h2 := (h1.mul_const (qstar.p x)).fun_add ((hasDerivAt_id (0 : ℝ)).mul_const (q.p x)) rw [show (-1 : ℝ) * qstar.p x + 1 * q.p x = q.p x - qstar.p x by ring] at h2 exact h2 have hdiv : HasDerivAt (fun t : ℝ => ((1 - t) * qstar.p x + t * q.p x) / r.p x) ((q.p x - qstar.p x) / r.p x) 0 := hlin.div_const (r.p x) have hne0 : ((1 - (0 : ℝ)) * qstar.p x + (0 : ℝ) * q.p x) / r.p x ≠ 0 := by simp [ne_of_gt (qstar.pos x), ne_of_gt (r.pos x)] have hlog := hdiv.log hne0 have hprod := hlin.fun_mul hlog have hval : (q.p x - qstar.p x) * Real.log (((1 - (0 : ℝ)) * qstar.p x + (0 : ℝ) * q.p x) / r.p x) + ((1 - (0 : ℝ)) * qstar.p x + (0 : ℝ) * q.p x) * (((q.p x - qstar.p x) / r.p x) / (((1 - (0 : ℝ)) * qstar.p x + (0 : ℝ) * q.p x) / r.p x)) = (q.p x - qstar.p x) * Real.log (qstar.p x / r.p x) + (q.p x - qstar.p x) := by have hqne : qstar.p x ≠ 0 := ne_of_gt (qstar.pos x) have hrne : r.p x ≠ 0 := ne_of_gt (r.pos x) simp only [sub_zero, one_mul, zero_mul, add_zero] field_simp [hqne, hrne] rw [hval] at hprod exact hprod have hsum := HasDerivAt.fun_sum (u := Finset.univ) fun x _ => hterm x have hsum_eq : ∑ x : ι, ((q.p x - qstar.p x) * Real.log (qstar.p x / r.p x) + (q.p x - qstar.p x)) = ∑ x : ι, (q.p x - qstar.p x) * Real.log (qstar.p x / r.p x) := by rw [Finset.sum_add_distrib, Finset.sum_sub_distrib, q.sum_one, qstar.sum_one, sub_self, add_zero] rw [hsum_eq] at hsum exact hsum have hf_ge : ∀ t ∈ Set.Icc (0 : ℝ) 1, f 0 ≤ f t := by intro t ⟨ht0, ht1⟩ have hm := hmin (mixProb qstar q t ht0 ht1) (hconv qstar hqstar q hq t ht0 ht1) have hf0 : f 0 = klDiv qstar r := by simp [f, klDiv] have hft : f t = klDiv (mixProb qstar q t ht0 ht1) r := by simp [f, klDiv, mixProb] linarith have hslope_nonneg : 0 ≤ ∑ x : ι, (q.p x - qstar.p x) * Real.log (qstar.p x / r.p x) := by have hlim := hf_deriv.tendsto_slope_zero_right have hev : ∀ᶠ t : ℝ in nhdsWithin 0 (Set.Ioi 0), 0 ≤ t⁻¹ • (f (0 + t) - f 0) := by filter_upwards [Ioo_mem_nhdsGT (show (0 : ℝ) < 1 by norm_num)] with t ht rw [smul_eq_mul, zero_add] exact mul_nonneg (inv_nonneg.mpr (le_of_lt ht.1)) (sub_nonneg.mpr (hf_ge t ⟨le_of_lt ht.1, le_of_lt ht.2⟩)) exact ge_of_tendsto hlim hev have hid : klDiv q r - klDiv q qstar - klDiv qstar r = ∑ x : ι, (q.p x - qstar.p x) * Real.log (qstar.p x / r.p x) := by unfold klDiv rw [← Finset.sum_sub_distrib, ← Finset.sum_sub_distrib] refine Finset.sum_congr rfl ?_ intro x _ rw [Real.log_div (ne_of_gt (q.pos x)) (ne_of_gt (r.pos x)), Real.log_div (ne_of_gt (q.pos x)) (ne_of_gt (qstar.pos x)), Real.log_div (ne_of_gt (qstar.pos x)) (ne_of_gt (r.pos x))] ring linarith /-- **Theorem 3.4b (Exact e-Convex Pythagorean Inequality):** If `Θ ⊆ ℝ^d` is convex and `θ* ∈ Θ` minimizes `θ ↦ D_KL(p ‖ p_θ)` over `Θ`, then for ALL `θ ∈ Θ`, `D_KL(p ‖ p_θ) ≥ D_KL(p ‖ p_{θ*}) + D_KL(p_{θ*} ‖ p_θ)`. -/ theorem eConvex_pythagorean_ineq (Θ : Set (Fin d → ℝ)) (hconv : Convex ℝ Θ) (p : StrictProb ι) (θstar : Fin d → ℝ) (hθstar : θstar ∈ Θ) (hmin : ∀ θ ∈ Θ, klDiv p (ef.prob θstar) ≤ klDiv p (ef.prob θ)) : ∀ θ ∈ Θ, klDiv p (ef.prob θstar) + klDiv (ef.prob θstar) (ef.prob θ) ≤ klDiv p (ef.prob θ) := by intro θ hθ let v : Fin d → ℝ := fun i => θ i - θstar i let g : ℝ → ℝ := fun t => klDiv p (ef.prob (fun i => θstar i + t * v i)) have hg_eq : ∀ t : ℝ, g t = ef.negEntropyBase p - (dotFin (fun i => θstar i + t * v i) (ef.etaOf p) - ef.psi (fun i => θstar i + t * v i)) := by intro t exact (ef.fenchel_young_exact_gap (fun i => θstar i + t * v i) p).symm have hg_deriv : HasDerivAt g (dotFin v (fun i => ef.eta θstar i - ef.etaOf p i)) 0 := by have hfun : g = fun t => ef.negEntropyBase p - (dotFin θstar (ef.etaOf p) + t * dotFin v (ef.etaOf p) - ef.psi (fun i => θstar i + t * v i)) := by funext t rw [hg_eq t, dotFin_add_left, dotFin_smul_left] rw [hfun] have h1 : HasDerivAt (fun t : ℝ => dotFin θstar (ef.etaOf p) + t * dotFin v (ef.etaOf p)) (dotFin v (ef.etaOf p)) 0 := by simpa using ((hasDerivAt_id (0 : ℝ)).mul_const (dotFin v (ef.etaOf p))).const_add (dotFin θstar (ef.etaOf p)) have h2 := h1.fun_sub (ef.hasDerivAt_psi_dir θstar v) have h3 := (hasDerivAt_const (0 : ℝ) (ef.negEntropyBase p)).fun_sub h2 have hval : 0 - (dotFin v (ef.etaOf p) - dotFin v (ef.eta θstar)) = dotFin v (fun i => ef.eta θstar i - ef.etaOf p i) := by rw [dotFin_sub_right] ring rw [hval] at h3 exact h3 have hg_ge : ∀ t ∈ Set.Icc (0 : ℝ) 1, g 0 ≤ g t := by intro t ⟨ht0, ht1⟩ have hmem : (fun i => θstar i + t * v i) ∈ Θ := by have hmix := hconv hθstar hθ (by linarith : 0 ≤ 1 - t) ht0 (by ring : (1 - t) + t = 1) have heq : (1 - t) • θstar + t • θ = (fun i => θstar i + t * v i) := by funext i simp only [Pi.add_apply, Pi.smul_apply, smul_eq_mul, v] ring rwa [heq] at hmix have hm := hmin _ hmem have hg0 : g 0 = klDiv p (ef.prob θstar) := by simp [g] linarith have hslope_nonneg : 0 ≤ dotFin v (fun i => ef.eta θstar i - ef.etaOf p i) := by have hlim := hg_deriv.tendsto_slope_zero_right have hev : ∀ᶠ t : ℝ in nhdsWithin 0 (Set.Ioi 0), 0 ≤ t⁻¹ • (g (0 + t) - g 0) := by filter_upwards [Ioo_mem_nhdsGT (show (0 : ℝ) < 1 by norm_num)] with t ht rw [smul_eq_mul, zero_add] exact mul_nonneg (inv_nonneg.mpr (le_of_lt ht.1)) (sub_nonneg.mpr (hg_ge t ⟨le_of_lt ht.1, le_of_lt ht.2⟩)) exact ge_of_tendsto hlim hev have hpyth := ef.generalized_pythagorean_identity p θstar θ have hneg : dotFin (fun i => θ i - θstar i) (fun i => ef.etaOf p i - ef.eta θstar i) = - dotFin v (fun i => ef.eta θstar i - ef.etaOf p i) := by unfold dotFin v rw [← Finset.sum_neg_distrib] refine Finset.sum_congr rfl ?_ intro i _ ring linarith end DiscreteExpFamily /-! ## Section 7: Concrete Sharpness Witnesses (Bernoulli Family & Bregman Asymmetry) -/ /-- Canonical Bernoulli exponential family on `Bool` (`T(false)=0, T(true)=1, h ≡ 1`). -/ def bernoulliFamily : DiscreteExpFamily Bool 1 where T b _ := if b then 1 else 0 h _ := 1 h_pos _ := one_pos /-- Bernoulli family is minimal (strictly convex log-partition `ψ(θ) = log(1 + e^θ)`). -/ theorem bernoulli_isMinimal : bernoulliFamily.IsMinimal := by intro v ⟨c, hc⟩ have h0 := hc false have h1 := hc true unfold dotFin bernoulliFamily at h0 h1 simp at h0 h1 funext i fin_cases i simp [h0, h1] /-- Exact Bernoulli log-partition function `ψ(θ) = log(1 + e^θ)`. -/ theorem bernoulli_psi_exact (θ : ℝ) : bernoulliFamily.psi (fun _ => θ) = Real.log (1 + Real.exp θ) := by unfold DiscreteExpFamily.psi DiscreteExpFamily.Z bernoulliFamily dotFin simp only [Fintype.sum_bool, Fin.sum_univ_one] simp [add_comm] /-- Exact Bernoulli expectation parameter `η(θ) = σ(θ) = e^θ / (1 + e^θ)`. -/ theorem bernoulli_eta_exact (θ : ℝ) : bernoulliFamily.eta (fun _ => θ) 0 = Real.exp θ / (1 + Real.exp θ) := by unfold DiscreteExpFamily.eta DiscreteExpFamily.etaOf expVal simp only [Fintype.sum_bool] rw [bernoulliFamily.prob_eq_div_Z, bernoulliFamily.prob_eq_div_Z] unfold DiscreteExpFamily.Z bernoulliFamily dotFin simp only [Fintype.sum_bool, Fin.sum_univ_one] simp [add_comm] /-- Exact Bernoulli Fisher information `g(θ) = σ(θ)(1 - σ(θ))` and Amari–Chentsov 3-tensor `T(θ) = σ(θ)(1 - σ(θ))(1 - 2σ(θ))`. -/ theorem bernoulli_fisher_and_chentsov_exact (θ : ℝ) : let p := Real.exp θ / (1 + Real.exp θ) bernoulliFamily.fisher (fun _ => θ) 0 0 = p * (1 - p) ∧ bernoulliFamily.amariChentsov (fun _ => θ) 0 0 0 = p * (1 - p) * (1 - 2 * p) := by intro p have hp_eta : bernoulliFamily.eta (fun _ => θ) 0 = p := bernoulli_eta_exact θ have hden : 1 + Real.exp θ ≠ 0 := ne_of_gt (by positivity) have hpt : (bernoulliFamily.prob (fun _ => θ)).p true = p := by rw [bernoulliFamily.prob_eq_div_Z] unfold DiscreteExpFamily.Z bernoulliFamily dotFin simp only [Fintype.sum_bool, Fin.sum_univ_one] simp [p, add_comm] have hpf : (bernoulliFamily.prob (fun _ => θ)).p false = 1 - p := by have hsum := (bernoulliFamily.prob (fun _ => θ)).sum_one rw [Fintype.sum_bool, hpt] at hsum linarith constructor · unfold DiscreteExpFamily.fisher expVal rw [Fintype.sum_bool, hpt, hpf, hp_eta] simp [bernoulliFamily] ring · unfold DiscreteExpFamily.amariChentsov expVal rw [Fintype.sum_bool, hpt, hpf, hp_eta] simp [bernoulliFamily] ring /-- **Exact Bregman Divergence Asymmetry Witness (Bernoulli `θ₁ = 0` vs `θ₂ = log 3`):** `D_ψ(log 3, 0) - D_ψ(0, log 3) = (1/4) log(256/243) > 0`, proving `D_ψ(θ₂, θ₁) ≠ D_ψ(θ₁, θ₂)`. -/ theorem bernoulli_bregman_strict_asymmetry : bernoulliFamily.bregmanPsi (fun _ => Real.log 3) (fun _ => 0) - bernoulliFamily.bregmanPsi (fun _ => 0) (fun _ => Real.log 3) = (1 / 4 : ℝ) * Real.log (256 / 243) ∧ bernoulliFamily.bregmanPsi (fun _ => 0) (fun _ => Real.log 3) < bernoulliFamily.bregmanPsi (fun _ => Real.log 3) (fun _ => 0) := by have hpsi0 : bernoulliFamily.psi (fun _ => 0) = Real.log 2 := by rw [bernoulli_psi_exact] norm_num have hpsi3 : bernoulliFamily.psi (fun _ => Real.log 3) = Real.log 4 := by rw [bernoulli_psi_exact, Real.exp_log (by norm_num : (0 : ℝ) < 3)] norm_num have heta0 : bernoulliFamily.eta (fun _ => 0) 0 = 1 / 2 := by rw [bernoulli_eta_exact] norm_num have heta3 : bernoulliFamily.eta (fun _ => Real.log 3) 0 = 3 / 4 := by rw [bernoulli_eta_exact, Real.exp_log (by norm_num : (0 : ℝ) < 3)] norm_num have hlog4 : Real.log 4 = 2 * Real.log 2 := by have : (4 : ℝ) = 2 ^ (2 : ℕ) := by norm_num rw [this, Real.log_pow] norm_num have hlog256 : Real.log (256 / 243 : ℝ) = 8 * Real.log 2 - 5 * Real.log 3 := by rw [Real.log_div (by norm_num) (by norm_num)] have h256 : (256 : ℝ) = 2 ^ (8 : ℕ) := by norm_num have h243 : (243 : ℝ) = 3 ^ (5 : ℕ) := by norm_num rw [h256, h243, Real.log_pow, Real.log_pow] norm_num have hdiff : bernoulliFamily.bregmanPsi (fun _ => Real.log 3) (fun _ => 0) - bernoulliFamily.bregmanPsi (fun _ => 0) (fun _ => Real.log 3) = (1 / 4 : ℝ) * Real.log (256 / 243) := by unfold DiscreteExpFamily.bregmanPsi dotFin simp only [Fin.sum_univ_one] rw [hpsi0, hpsi3, heta0, heta3, hlog4, hlog256] ring refine ⟨hdiff, ?_⟩ have hpos : 0 < (1 / 4 : ℝ) * Real.log (256 / 243) := mul_pos (by norm_num) (Real.log_pos (by norm_num)) linarith /-! ## Section 8: Kernel Axiom Audit -/ #print axioms klDiv_nonneg #print axioms klDiv_eq_zero_iff #print axioms DiscreteExpFamily.hasDerivAt_psi_dir #print axioms DiscreteExpFamily.deriv_psi_coord #print axioms DiscreteExpFamily.hasDerivAt_prob_dir #print axioms DiscreteExpFamily.hasDerivAt_eta_dir #print axioms DiscreteExpFamily.hessian_psi_eq_fisher #print axioms DiscreteExpFamily.hasDerivAt_fisher_dir #print axioms DiscreteExpFamily.third_deriv_psi_eq_amariChentsov #print axioms DiscreteExpFamily.fisher_quadForm_eq_var #print axioms DiscreteExpFamily.fisher_psd #print axioms DiscreteExpFamily.fisher_posDef_iff_minimal #print axioms DiscreteExpFamily.prob_injective_of_minimal #print axioms DiscreteExpFamily.negEntropyBase_eq_neg_shannon_sub_base #print axioms DiscreteExpFamily.negEntropyBase_eq_neg_shannon_of_counting #print axioms DiscreteExpFamily.fenchel_young_exact_gap #print axioms DiscreteExpFamily.fenchel_young_le #print axioms DiscreteExpFamily.fenchel_young_eq_iff #print axioms DiscreteExpFamily.negEntropyBase_prob_eq #print axioms DiscreteExpFamily.legendre_conjugate_isGreatest #print axioms DiscreteExpFamily.legendre_conjugate_iSup_eq #print axioms DiscreteExpFamily.gibbs_variational_isGreatest #print axioms DiscreteExpFamily.kl_eq_bregmanPsi #print axioms DiscreteExpFamily.kl_eq_bregmanPhi #print axioms DiscreteExpFamily.kl_bregman_fenchel_master_duality #print axioms DiscreteExpFamily.psi_convex_subgrad #print axioms DiscreteExpFamily.psi_strict_convex_of_minimal #print axioms DiscreteExpFamily.jeffreys_eq_dual_pairing #print axioms DiscreteExpFamily.eta_strict_monotone_of_minimal #print axioms DiscreteExpFamily.eta_injective_of_minimal #print axioms DiscreteExpFamily.generalized_pythagorean_identity #print axioms DiscreteExpFamily.pythagorean_eq_iff_orthogonal #print axioms DiscreteExpFamily.mProjection_pythagorean #print axioms DiscreteExpFamily.mProjection_min_and_unique #print axioms DiscreteExpFamily.mProjection_unique_param_of_minimal #print axioms DiscreteExpFamily.mProjection_eq_mle #print axioms DiscreteExpFamily.iProjection_pythagorean #print axioms DiscreteExpFamily.iProjection_min_and_unique #print axioms DiscreteExpFamily.maxEnt_gibbs_exact_deficit #print axioms DiscreteExpFamily.maxEnt_gibbs_unique_max #print axioms DiscreteExpFamily.mConvex_pythagorean_ineq #print axioms DiscreteExpFamily.eConvex_pythagorean_ineq #print axioms bernoulli_isMinimal #print axioms bernoulli_psi_exact #print axioms bernoulli_eta_exact #print axioms bernoulli_fisher_and_chentsov_exact #print axioms bernoulli_bregman_strict_asymmetry end InfoGeomExpBregman