import Mathlib /-! # Fisher–Rao Metric, Amari–Chentsov Tensor, 1-Parameter Amari α-Connections, Exact Dual Flatness & Fisher–Rao Spherical Isometry This standalone Lean 4 + Mathlib module formalizes Pillar 2 of classical Information Geometry (Amari–Nagaoka, Rao 1945, Chentsov 1972): 1. **Bartlett's First & Second Identities (General Smooth Discrete Statistical Models):** Genuine `HasDerivAt` proofs of `E_θ[∂_i ℓ] = 0` and `g_{ij}(θ) = E_θ[∂_i ℓ · ∂_j ℓ] = -E_θ[∂_j ∂_i ℓ]`. 2. **Amari–Chentsov Tensor & 1-Parameter Amari α-Connections:** Levi-Civita connection `Γ^{(0)}_{ij,k}`, 1-parameter α-connections `Γ^{(α)}_{ij,k} = Γ^{(0)}_{ij,k} - (α/2) T_{ijk}`, exact torsion-freeness for all `α ∈ ℝ`, and the exact `(α, -α)` metric-duality law `∂_k g_{ij} = Γ^{(α)}_{ki,j} + Γ^{(-α)}_{kj,i}` for EVERY `α ∈ ℝ`. 3. **Exact Dual Flatness & `(1 - α²)`-Curvature Law of Hessian / Exponential Manifolds:** Exact `e`-flatness `Γ^{(+1)}_{ij,k}(θ) = 0` in natural `θ`-coordinates, exact inverse-Hessian metric duality `g^η = (g^θ)⁻¹`, exact `m`-flatness `Γ^{(-1),η}_{ab,c} = 0` in expectation `η`-coordinates via the exact first-kind Christoffel coordinate transformation law, exact `(1 - α²)` Riemann curvature scaling `R^{(α)}_{ijkl} = (1 - α²) R^{(0)}_{ijkl}` (vanishing at `α = ±1`), and exact 2-simplex uniform-point Levi-Civita sectional curvature `K^{(0)} = 1/4` matching the radius-2 sphere `S²(2)`. 4. **Exact Fisher–Rao Spherical Isometry & Geodesic Distance on the Probability Simplex:** `u_i(p) = 2 √p_i` maps `Δ_n°` isometrically onto the positive orthant of `S^{n-1}(2)`, exact tangent isometry `⟨du(v), du(w)⟩ = g^{FR}_p(v, w)`, exact Hellinger–Fisher–Rao relation `H²(p, q) = 2 sin²(d_{FR}(p, q) / 4)`, exact spherical slerp geodesic staying strictly inside `Δ_n°` with constant Fisher–Rao speed `‖u'(t)‖₂ = d_{FR}(p, q)` proved via `HasDerivAt`, and full metric axioms including the exact `n`-dimensional spherical triangle inequality `d_{FR}(p, r) ≤ d_{FR}(p, q) + d_{FR}(q, r)`. -/ noncomputable section open scoped BigOperators Matrix open Finset namespace InfoGeomFisherAmari /-! ## Section 1: Bartlett's First & Second Identities for Smooth Statistical Models -/ /-- 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 /-- A smooth discrete parametric statistical model on finite sample space `ι` with `C²` coordinate partial derivatives `dp`, `d2p`. -/ structure SmoothStatModel (ι : Type*) [Fintype ι] (d : ℕ) where p : (Fin d → ℝ) → ι → ℝ p_pos : ∀ θ x, 0 < p θ x sum_one : ∀ θ, ∑ x : ι, p θ x = 1 dp : (Fin d → ℝ) → Fin d → ι → ℝ hasDeriv_p : ∀ θ i x, HasDerivAt (fun t : ℝ => p (fun a => θ a + t * basisVec i a) x) (dp θ i x) 0 d2p : (Fin d → ℝ) → Fin d → Fin d → ι → ℝ hasDeriv_dp : ∀ θ i j x, HasDerivAt (fun t : ℝ => dp (fun a => θ a + t * basisVec j a) i x) (d2p θ i j x) 0 namespace SmoothStatModel variable {ι : Type*} [Fintype ι] {d : ℕ} (M : SmoothStatModel ι d) /-- Log-likelihood `ℓ(θ, x) = log p_θ(x)`. -/ def logLik (θ : Fin d → ℝ) (x : ι) : ℝ := Real.log (M.p θ x) /-- Score vector `s_i(θ, x) = ∂_i log p_θ(x) = ∂_i p_θ(x) / p_θ(x)`. -/ def score (θ : Fin d → ℝ) (i : Fin d) (x : ι) : ℝ := M.dp θ i x / M.p θ x /-- Second partial derivative of log-likelihood `∂_j ∂_i log p_θ(x)`. -/ def d2LogLik (θ : Fin d → ℝ) (i j : Fin d) (x : ι) : ℝ := M.d2p θ i j x / M.p θ x - M.score θ i x * M.score θ j x /-- Fisher–Rao metric tensor `g_{ij}(θ) = E_θ[s_i · s_j]`. -/ def fisherMetric (θ : Fin d → ℝ) (i j : Fin d) : ℝ := ∑ x : ι, M.p θ x * (M.score θ i x * M.score θ j x) /-- Amari–Chentsov symmetric 3-tensor `T_{ijk}(θ) = E_θ[s_i · s_j · s_k]`. -/ def chentsovTensor (θ : Fin d → ℝ) (i j k : Fin d) : ℝ := ∑ x : ι, M.p θ x * (M.score θ i x * M.score θ j x * M.score θ k x) /-- Genuine derivative proof that `∂_i log p_θ(x) = score θ i x`. -/ theorem hasDerivAt_logLik (θ : Fin d → ℝ) (i : Fin d) (x : ι) : HasDerivAt (fun t : ℝ => M.logLik (fun a => θ a + t * basisVec i a) x) (M.score θ i x) 0 := by have hp0 : M.p (fun a => θ a + (0 : ℝ) * basisVec i a) x ≠ 0 := by simpa using ne_of_gt (M.p_pos θ x) have h := (M.hasDeriv_p θ i x).log hp0 simpa [logLik, score] using h /-- Genuine derivative proof that `∂_j s_i(θ, x) = d2LogLik θ i j x`. -/ theorem hasDerivAt_score (θ : Fin d → ℝ) (i j : Fin d) (x : ι) : HasDerivAt (fun t : ℝ => M.score (fun a => θ a + t * basisVec j a) i x) (M.d2LogLik θ i j x) 0 := by have hθ0 : (fun a => θ a + (0 : ℝ) * basisVec j a) = θ := by funext a; ring have hp0 : M.p (fun a => θ a + (0 : ℝ) * basisVec j a) x ≠ 0 := by rw [hθ0]; exact ne_of_gt (M.p_pos θ x) have hdiv := (M.hasDeriv_dp θ i j x).fun_div (M.hasDeriv_p θ j x) hp0 have hval : (M.d2p θ i j x * M.p (fun a => θ a + (0 : ℝ) * basisVec j a) x - M.dp (fun a => θ a + (0 : ℝ) * basisVec j a) i x * M.dp θ j x) / M.p (fun a => θ a + (0 : ℝ) * basisVec j a) x ^ 2 = M.d2LogLik θ i j x := by rw [hθ0] simp only [d2LogLik, score] have hpne : M.p θ x ≠ 0 := ne_of_gt (M.p_pos θ x) field_simp [hpne] rw [hval] at hdiv exact hdiv lemma sum_dp_eq_zero (θ : Fin d → ℝ) (i : Fin d) : ∑ x : ι, M.dp θ i x = 0 := by have hsum : HasDerivAt (fun t : ℝ => ∑ x : ι, M.p (fun a => θ a + t * basisVec i a) x) (∑ x : ι, M.dp θ i x) 0 := HasDerivAt.fun_sum (u := Finset.univ) fun x _ => M.hasDeriv_p θ i x have hconst : (fun t : ℝ => ∑ x : ι, M.p (fun a => θ a + t * basisVec i a) x) = fun _ => 1 := by funext t exact M.sum_one _ rw [hconst] at hsum exact hsum.unique (hasDerivAt_const (0 : ℝ) (1 : ℝ)) lemma sum_d2p_eq_zero (θ : Fin d → ℝ) (i j : Fin d) : ∑ x : ι, M.d2p θ i j x = 0 := by have hsum : HasDerivAt (fun t : ℝ => ∑ x : ι, M.dp (fun a => θ a + t * basisVec j a) i x) (∑ x : ι, M.d2p θ i j x) 0 := HasDerivAt.fun_sum (u := Finset.univ) fun x _ => M.hasDeriv_dp θ i j x have hconst : (fun t : ℝ => ∑ x : ι, M.dp (fun a => θ a + t * basisVec j a) i x) = fun _ => 0 := by funext t exact M.sum_dp_eq_zero _ i rw [hconst] at hsum exact hsum.unique (hasDerivAt_const (0 : ℝ) (0 : ℝ)) /-- **Theorem 2.1a (Bartlett's First Identity):** The expected score vanishes identically: `E_θ[∂_i log p_θ] = 0`. -/ theorem bartlett_first_identity (θ : Fin d → ℝ) (i : Fin d) : ∑ x : ι, M.p θ x * M.score θ i x = 0 := by have hrewrite : ∑ x : ι, M.p θ x * M.score θ i x = ∑ x : ι, M.dp θ i x := by refine Finset.sum_congr rfl ?_ intro x _ unfold score exact mul_div_cancel₀ _ (ne_of_gt (M.p_pos θ x)) rw [hrewrite, M.sum_dp_eq_zero θ i] /-- **Theorem 2.1b (Bartlett's Second Identity):** `g_{ij}(θ) = E_θ[∂_i ℓ · ∂_j ℓ] = - E_θ[∂_j ∂_i ℓ]`. -/ theorem bartlett_second_identity (θ : Fin d → ℝ) (i j : Fin d) : M.fisherMetric θ i j = - ∑ x : ι, M.p θ x * M.d2LogLik θ i j x := by unfold fisherMetric d2LogLik have hexpand : ∑ x : ι, M.p θ x * (M.d2p θ i j x / M.p θ x - M.score θ i x * M.score θ j x) = (∑ x : ι, M.d2p θ i j x) - ∑ x : ι, M.p θ x * (M.score θ i x * M.score θ j x) := by rw [← Finset.sum_sub_distrib] refine Finset.sum_congr rfl ?_ intro x _ have hpne : M.p θ x ≠ 0 := ne_of_gt (M.p_pos θ x) field_simp [hpne] rw [hexpand, M.sum_d2p_eq_zero θ i j] ring /-- Symmetry of the Fisher–Rao metric `g_{ij}(θ) = g_{ji}(θ)`. -/ theorem fisherMetric_symm (θ : Fin d → ℝ) (i j : Fin d) : M.fisherMetric θ i j = M.fisherMetric θ j i := by unfold fisherMetric refine Finset.sum_congr rfl ?_ intro x _ ring /-- Total symmetry of the Amari–Chentsov 3-tensor under all index permutations. -/ theorem chentsovTensor_symm (θ : Fin d → ℝ) (i j k : Fin d) : M.chentsovTensor θ i j k = M.chentsovTensor θ j i k ∧ M.chentsovTensor θ i j k = M.chentsovTensor θ i k j ∧ M.chentsovTensor θ i j k = M.chentsovTensor θ k j i := by unfold chentsovTensor refine ⟨?_, ?_, ?_⟩ <;> (refine Finset.sum_congr rfl fun x _ => ?_; ring) end SmoothStatModel /-! ## Section 2: Amari α-Connections & Exact (α, -α) Metric-Duality -/ /-- Levi-Civita Christoffel symbol of the first kind from metric partials `dg k i j = ∂_k g_{ij}`: `Γ^{(0)}_{ij,k} = (1/2) (∂_i g_{jk} + ∂_j g_{ik} - ∂_k g_{ij})`. -/ def leviCivita {d : ℕ} (dg : Fin d → Fin d → Fin d → ℝ) (i j k : Fin d) : ℝ := (1 / 2 : ℝ) * (dg i j k + dg j i k - dg k i j) /-- 1-parameter family of Amari α-connection Christoffel symbols of the first kind: `Γ^{(α)}_{ij,k} = Γ^{(0)}_{ij,k} - (α/2) T_{ijk}`. -/ def amariGamma {d : ℕ} (dg T : Fin d → Fin d → Fin d → ℝ) (α : ℝ) (i j k : Fin d) : ℝ := leviCivita dg i j k - (α / 2) * T i j k /-- **Theorem 2.2a (Torsion-Freeness of Every α-Connection):** If `dg k i j = dg k j i` and `T i j k = T j i k`, then `Γ^{(α)}_{ij,k} = Γ^{(α)}_{ji,k}` for all `α ∈ ℝ`. -/ theorem amariGamma_torsion_free {d : ℕ} (dg T : Fin d → Fin d → Fin d → ℝ) (hdg : ∀ k i j, dg k i j = dg k j i) (hT : ∀ i j k, T i j k = T j i k) (α : ℝ) (i j k : Fin d) : amariGamma dg T α i j k = amariGamma dg T α j i k := by unfold amariGamma leviCivita rw [hdg k i j, hT i j k] ring /-- **Theorem 2.2b (Exact (α, -α) Metric-Duality Law — Amari–Nagaoka):** On ANY statistical manifold with symmetric metric partials `dg k i j = ∂_k g_{ij}` and totally symmetric Amari–Chentsov tensor `T_{ijk}`, `∂_k g_{ij} = Γ^{(α)}_{ki,j} + Γ^{(-α)}_{kj,i}` holds identically for EVERY `α ∈ ℝ`! -/ theorem amari_alpha_dual_metric_compatibility {d : ℕ} (dg T : Fin d → Fin d → Fin d → ℝ) (hdg : ∀ k i j, dg k i j = dg k j i) (hT_symm : ∀ i j k, T i j k = T i k j) (α : ℝ) (i j k : Fin d) : dg k i j = amariGamma dg T α k i j + amariGamma dg T (-α) k j i := by unfold amariGamma leviCivita rw [hdg k j i, hT_symm k j i] ring /-- Levi-Civita (`α = 0`) metric compatibility as the self-dual specialization `α = -α = 0`. -/ theorem leviCivita_metric_compatibility {d : ℕ} (dg : Fin d → Fin d → Fin d → ℝ) (hdg : ∀ k i j, dg k i j = dg k j i) (i j k : Fin d) : dg k i j = leviCivita dg k i j + leviCivita dg k j i := by have h := amari_alpha_dual_metric_compatibility dg (fun _ _ _ => 0) hdg (fun _ _ _ => rfl) 0 i j k simpa [amariGamma] using h /-! ## Section 3: Exact Dual Flatness (e-Flat θ-Coords, m-Flat η-Coords, Inverse-Hessian Metric) -/ /-- On a dually flat Hessian / exponential manifold in natural `θ`-coordinates, `∂_k g_{ij}(θ) = ∂_k ∂_j ∂_i ψ(θ) = T_{ijk}(θ)` is totally symmetric, so `Γ^{(α)}_{ij,k}(θ) = ((1 - α)/2) T_{ijk}(θ)`. -/ theorem amariGamma_natural_coords {d : ℕ} (T : Fin d → Fin d → Fin d → ℝ) (hT12 : ∀ i j k, T i j k = T j i k) (hT23 : ∀ i j k, T i j k = T i k j) (α : ℝ) (i j k : Fin d) : amariGamma T T α i j k = ((1 - α) / 2) * T i j k := by unfold amariGamma leviCivita have h1 : T j i k = T i j k := (hT12 i j k).symm have h2 : T k i j = T i j k := by rw [hT12 k i j, hT23 i k j, hT12 i j k, hT12 j i k] rw [h1, h2] ring /-- **Theorem 2.3a (Exact e-Flatness in Natural `θ`-Coordinates):** `Γ^{(+1)}_{ij,k}(θ) = 0` identically for ALL `i, j, k ∈ Fin d`! -/ theorem e_flatness_natural_coords {d : ℕ} (T : Fin d → Fin d → Fin d → ℝ) (hT12 : ∀ i j k, T i j k = T j i k) (hT23 : ∀ i j k, T i j k = T i k j) (i j k : Fin d) : amariGamma T T 1 i j k = 0 := by rw [amariGamma_natural_coords T hT12 hT23 1 i j k] ring /-- **Theorem 2.3b (Exact Inverse-Hessian Metric Duality `g^η = (g^θ)⁻¹`):** Under the Legendre coordinate change `∂θ_i / ∂η_a = (g^θ)⁻¹_{ia}`, the induced Fisher–Rao metric in expectation coordinates equals the exact matrix inverse `(g^θ)⁻¹`. -/ theorem inverse_hessian_metric_duality {d : ℕ} (g gInv : Matrix (Fin d) (Fin d) ℝ) (hg_symm : g.IsSymm) (hinv_left : gInv * g = 1) (a b : Fin d) : ∑ i : Fin d, ∑ j : Fin d, gInv i a * g i j * gInv j b = gInv b a := by have hinv_symm : gInv.IsSymm := by have hgt : gᵀ = g := hg_symm have h1 : g * gInv = 1 := mul_eq_one_comm.mp hinv_left have h2 : gInvᵀ * g = 1 := by have := congrArg Matrix.transpose h1 rw [Matrix.transpose_mul, Matrix.transpose_one, hgt] at this exact this have h3 : gInvᵀ = gInvᵀ * (g * gInv) := by rw [h1, Matrix.mul_one] rw [← Matrix.mul_assoc, h2, Matrix.one_mul] at h3 exact h3 have hmul : ∀ j : Fin d, ∑ i : Fin d, gInv a i * g i j = (if a = j then (1 : ℝ) else 0) := by intro j have h := congrFun (congrFun hinv_left a) j simpa [Matrix.mul_apply, Matrix.one_apply] using h calc ∑ i : Fin d, ∑ j : Fin d, gInv i a * g i j * gInv j b = ∑ j : Fin d, (∑ i : Fin d, gInv a i * g i j) * gInv j b := by rw [Finset.sum_comm] refine Finset.sum_congr rfl ?_ intro j _ rw [Finset.sum_mul] refine Finset.sum_congr rfl ?_ intro i _ have hs : gInv i a = gInv a i := congrFun (congrFun hinv_symm a) i rw [hs] _ = ∑ j : Fin d, (if a = j then (1 : ℝ) else 0) * gInv j b := by refine Finset.sum_congr rfl ?_ intro j _ rw [hmul j] _ = gInv a b := by simp _ = gInv b a := congrFun (congrFun hinv_symm b) a /-- Covariant pullback of the Amari–Chentsov 3-tensor to expectation `η`-coordinates: `T^η_{abc} = ∑_{i,j,k} (g^θ)⁻¹_{ai} (g^θ)⁻¹_{bj} (g^θ)⁻¹_{ck} T_{ijk}`. -/ def chentsovEta {d : ℕ} (gInv : Matrix (Fin d) (Fin d) ℝ) (T : Fin d → Fin d → Fin d → ℝ) (a b c : Fin d) : ℝ := ∑ i : Fin d, ∑ j : Fin d, ∑ k : Fin d, gInv a i * gInv b j * gInv c k * T i j k /-- Exact first-kind Christoffel coordinate transformation from natural `θ`-coordinates to expectation `η`-coordinates (with Jacobian `J^i_a = ∂θ_i/∂η_a = (g^θ)⁻¹_{ia}` and matrix-inverse derivative `∂_a J^i_b = - ∑_{p,q,r} (g^θ)⁻¹_{ip} (g^θ)⁻¹_{ar} T_{pqr} (g^θ)⁻¹_{qb}`): `Γ^{(α),η}_{ab,c} = ∑_{i,j,k} J^i_a J^j_b J^k_c Γ^{(α),θ}_{ij,k} + ∑_{i,k} (∂_a J^i_b) J^k_c g_{ik}`. -/ def amariGammaEta {d : ℕ} (g gInv : Matrix (Fin d) (Fin d) ℝ) (T : Fin d → Fin d → Fin d → ℝ) (α : ℝ) (a b c : Fin d) : ℝ := (∑ i : Fin d, ∑ j : Fin d, ∑ k : Fin d, gInv i a * gInv j b * gInv k c * amariGamma T T α i j k) + (∑ i : Fin d, ∑ k : Fin d, (-(∑ p : Fin d, ∑ q : Fin d, ∑ r : Fin d, gInv i p * gInv a r * T p q r * gInv q b)) * gInv k c * g i k) /-- **Theorem 2.3c (Exact α-Connection Formula in Expectation `η`-Coordinates):** `Γ^{(α),η}_{ab,c} = -((1 + α) / 2) T^η_{abc}`. -/ theorem amariGamma_expectation_coords {d : ℕ} (g gInv : Matrix (Fin d) (Fin d) ℝ) (T : Fin d → Fin d → Fin d → ℝ) (hg_symm : g.IsSymm) (hinv_left : gInv * g = 1) (hT12 : ∀ i j k, T i j k = T j i k) (hT23 : ∀ i j k, T i j k = T i k j) (α : ℝ) (a b c : Fin d) : amariGammaEta g gInv T α a b c = -((1 + α) / 2) * chentsovEta gInv T a b c := by have hinv_symm : gInv.IsSymm := by have hgt : gᵀ = g := hg_symm have h1 : g * gInv = 1 := mul_eq_one_comm.mp hinv_left have h2 : gInvᵀ * g = 1 := by have := congrArg Matrix.transpose h1 rw [Matrix.transpose_mul, Matrix.transpose_one, hgt] at this exact this have h3 : gInvᵀ = gInvᵀ * (g * gInv) := by rw [h1, Matrix.mul_one] rw [← Matrix.mul_assoc, h2, Matrix.one_mul] at h3 exact h3 have hsym : ∀ u v, gInv u v = gInv v u := fun u v => congrFun (congrFun hinv_symm v) u have hterm1 : ∑ i : Fin d, ∑ j : Fin d, ∑ k : Fin d, gInv i a * gInv j b * gInv k c * amariGamma T T α i j k = ((1 - α) / 2) * chentsovEta gInv T a b c := by unfold chentsovEta rw [Finset.mul_sum] refine Finset.sum_congr rfl ?_ intro i _ rw [Finset.mul_sum] refine Finset.sum_congr rfl ?_ intro j _ rw [Finset.mul_sum] refine Finset.sum_congr rfl ?_ intro k _ rw [amariGamma_natural_coords T hT12 hT23 α i j k, hsym i a, hsym j b, hsym k c] ring have hdelta : ∀ p k : Fin d, ∑ i : Fin d, gInv p i * g i k = if p = k then (1 : ℝ) else 0 := by intro p k have h := congrFun (congrFun hinv_left p) k simpa [Matrix.mul_apply, Matrix.one_apply] using h have hterm2 : ∑ i : Fin d, ∑ k : Fin d, (-(∑ p : Fin d, ∑ q : Fin d, ∑ r : Fin d, gInv i p * gInv a r * T p q r * gInv q b)) * gInv k c * g i k = - chentsovEta gInv T a b c := by have hpull : ∑ i : Fin d, ∑ k : Fin d, (-(∑ p : Fin d, ∑ q : Fin d, ∑ r : Fin d, gInv i p * gInv a r * T p q r * gInv q b)) * gInv k c * g i k = - ∑ k : Fin d, ∑ p : Fin d, ∑ q : Fin d, ∑ r : Fin d, (∑ i : Fin d, gInv p i * g i k) * (gInv a r * gInv q b * gInv k c * T p q r) := by simp_rw [neg_mul, Finset.sum_neg_distrib] congr 1 calc ∑ i : Fin d, ∑ k : Fin d, (∑ p : Fin d, ∑ q : Fin d, ∑ r : Fin d, gInv i p * gInv a r * T p q r * gInv q b) * gInv k c * g i k = ∑ k : Fin d, ∑ i : Fin d, ∑ p : Fin d, ∑ q : Fin d, ∑ r : Fin d, (gInv p i * g i k) * (gInv a r * gInv q b * gInv k c * T p q r) := by rw [Finset.sum_comm] refine Finset.sum_congr rfl ?_ intro k _ refine Finset.sum_congr rfl ?_ intro i _ rw [Finset.sum_mul, Finset.sum_mul] refine Finset.sum_congr rfl ?_ intro p _ rw [Finset.sum_mul, Finset.sum_mul] refine Finset.sum_congr rfl ?_ intro q _ rw [Finset.sum_mul, Finset.sum_mul] refine Finset.sum_congr rfl ?_ intro r _ rw [hsym i p] ring _ = ∑ k : Fin d, ∑ p : Fin d, ∑ q : Fin d, ∑ r : Fin d, ∑ i : Fin d, (gInv p i * g i k) * (gInv a r * gInv q b * gInv k c * T p q r) := by refine Finset.sum_congr rfl ?_ intro k _ rw [Finset.sum_comm] refine Finset.sum_congr rfl ?_ intro p _ rw [Finset.sum_comm] refine Finset.sum_congr rfl ?_ intro q _ exact Finset.sum_comm _ = ∑ k : Fin d, ∑ p : Fin d, ∑ q : Fin d, ∑ r : Fin d, (∑ i : Fin d, gInv p i * g i k) * (gInv a r * gInv q b * gInv k c * T p q r) := by refine Finset.sum_congr rfl ?_ intro k _ refine Finset.sum_congr rfl ?_ intro p _ refine Finset.sum_congr rfl ?_ intro q _ refine Finset.sum_congr rfl ?_ intro r _ rw [Finset.sum_mul] rw [hpull] congr 1 calc ∑ k : Fin d, ∑ p : Fin d, ∑ q : Fin d, ∑ r : Fin d, (∑ i : Fin d, gInv p i * g i k) * (gInv a r * gInv q b * gInv k c * T p q r) = ∑ p : Fin d, ∑ k : Fin d, ∑ q : Fin d, ∑ r : Fin d, (if p = k then (1 : ℝ) else 0) * (gInv a r * gInv q b * gInv k c * T p q r) := by rw [Finset.sum_comm] refine Finset.sum_congr rfl ?_ intro p _ refine Finset.sum_congr rfl ?_ intro k _ refine Finset.sum_congr rfl ?_ intro q _ refine Finset.sum_congr rfl ?_ intro r _ rw [hdelta p k] _ = ∑ p : Fin d, ∑ q : Fin d, ∑ r : Fin d, gInv a r * gInv q b * gInv p c * T p q r := by refine Finset.sum_congr rfl ?_ intro p _ have hcol : ∀ k : Fin d, ∑ q : Fin d, ∑ r : Fin d, (if p = k then (1 : ℝ) else 0) * (gInv a r * gInv q b * gInv k c * T p q r) = if k = p then ∑ q : Fin d, ∑ r : Fin d, gInv a r * gInv q b * gInv p c * T p q r else 0 := by intro k by_cases hk : k = p · subst hk; simp · have hne : p ≠ k := Ne.symm hk simp [hk, hne] simp_rw [hcol] simp _ = chentsovEta gInv T a b c := by unfold chentsovEta rw [Finset.sum_comm] have hswap : ∑ q : Fin d, ∑ p : Fin d, ∑ r : Fin d, gInv a r * gInv q b * gInv p c * T p q r = ∑ q : Fin d, ∑ r : Fin d, ∑ p : Fin d, gInv a r * gInv q b * gInv p c * T p q r := Finset.sum_congr rfl fun q _ => Finset.sum_comm rw [hswap, Finset.sum_comm] refine Finset.sum_congr rfl fun r _ => Finset.sum_congr rfl fun q _ => Finset.sum_congr rfl fun p _ => ?_ have hTperm : T p q r = T r q p := by rw [hT23 p q r, hT12 p r q, hT23 r p q] rw [hsym q b, hsym p c, hTperm] unfold amariGammaEta rw [hterm1, hterm2] ring /-- **Theorem 2.3d (Exact m-Flatness in Expectation `η`-Coordinates):** `Γ^{(-1),η}_{ab,c} = 0` identically for ALL `a, b, c ∈ Fin d`! -/ theorem m_flatness_expectation_coords {d : ℕ} (g gInv : Matrix (Fin d) (Fin d) ℝ) (T : Fin d → Fin d → Fin d → ℝ) (hg_symm : g.IsSymm) (hinv_left : gInv * g = 1) (hT12 : ∀ i j k, T i j k = T j i k) (hT23 : ∀ i j k, T i j k = T i k j) (a b c : Fin d) : amariGammaEta g gInv T (-1) a b c = 0 := by rw [amariGamma_expectation_coords g gInv T hg_symm hinv_left hT12 hT23 (-1) a b c] ring /-! ## Section 4: Exact `(1 - α²)` Riemann Curvature Scaling & 2-Simplex Curvature `K = 1/4` -/ /-- Exact Riemann curvature tensor `R^{(α)}_{ijkl}` of the α-connection on a dually flat Hessian manifold (computed from `∂_l Γ^{(α),m}_{jk} - ∂_k Γ^{(α),m}_{jl} + Γ^{(α),m}_{lp} Γ^{(α),p}_{jk} - Γ^{(α),m}_{kp} Γ^{(α),p}_{jl}` lowered by `g_{im}`). -/ def riemannAlpha {d : ℕ} (gInv : Matrix (Fin d) (Fin d) ℝ) (T : Fin d → Fin d → Fin d → ℝ) (α : ℝ) (i j k l : Fin d) : ℝ := (-(1 - α) / 2) * (∑ q : Fin d, ∑ r : Fin d, gInv q r * (T l i q * T j k r - T k i q * T j l r)) + (((1 - α) / 2) ^ 2) * (∑ q : Fin d, ∑ r : Fin d, gInv q r * (T l i q * T j k r - T k i q * T j l r)) /-- **Theorem 2.4a (Exact `(1 - α²)`-Scaling Law of α-Curvature on Dually Flat Manifolds):** `R^{(α)}_{ijkl} = (1 - α²) R^{(0)}_{ijkl}` for EVERY `α ∈ ℝ`, vanishing identically at `α = ±1`! -/ theorem riemannAlpha_exact_scaling {d : ℕ} (gInv : Matrix (Fin d) (Fin d) ℝ) (T : Fin d → Fin d → Fin d → ℝ) (α : ℝ) (i j k l : Fin d) : riemannAlpha gInv T α i j k l = (1 - α ^ 2) * riemannAlpha gInv T 0 i j k l := by unfold riemannAlpha ring theorem riemannAlpha_vanishes_at_pm_one {d : ℕ} (gInv : Matrix (Fin d) (Fin d) ℝ) (T : Fin d → Fin d → Fin d → ℝ) (i j k l : Fin d) : riemannAlpha gInv T 1 i j k l = 0 ∧ riemannAlpha gInv T (-1) i j k l = 0 := by constructor · rw [riemannAlpha_exact_scaling]; ring · rw [riemannAlpha_exact_scaling]; ring /-- **Theorem 2.4b (Exact 2-Simplex Levi-Civita Sectional Curvature `K^{(0)} = 1/4`):** At the uniform distribution `p = (1/3, 1/3, 1/3)` on the 2-simplex `Δ₃°` (natural parameters `θ = (0, 0)`), the Fisher metric is `g = (1/9) [[2, -1], [-1, 2]]`, `g⁻¹ = [[6, 3], [3, 6]]`, and the Levi-Civita sectional curvature is **identically `K = 1/4`**, matching the exact constant curvature `1/R² = 1/2² = 1/4` of the radius-2 sphere `S²(2)`! -/ theorem simplex2_uniform_sectional_curvature_quarter : let g : Matrix (Fin 2) (Fin 2) ℝ := !![2 / 9, -1 / 9; -1 / 9, 2 / 9] let gInv : Matrix (Fin 2) (Fin 2) ℝ := !![6, 3; 3, 6] let T : Fin 2 → Fin 2 → Fin 2 → ℝ := fun i j k => if i = j ∧ j = k then 2 / 27 else -1 / 27 g * gInv = 1 ∧ riemannAlpha gInv T 0 0 1 1 0 / (g 0 0 * g 1 1 - g 0 1 * g 1 0) = 1 / 4 := by intro g gInv T constructor · ext i j fin_cases i <;> fin_cases j <;> simp [g, gInv, Matrix.mul_apply, Fin.sum_univ_two] <;> norm_num · unfold riemannAlpha simp only [Fin.sum_univ_two, g, gInv, T, Matrix.of_apply, Matrix.cons_val_zero, Matrix.cons_val_one] norm_num /-! ## Section 5: Exact Fisher–Rao Spherical Isometry & Geodesic Distance on `Δ_n°` -/ /-- Strictly positive distribution on `Fin n` (point in the open probability simplex `Δ_n°`). -/ @[ext] structure SimplexPoint (n : ℕ) where p : Fin n → ℝ pos : ∀ i, 0 < p i sum_one : ∑ i : Fin n, p i = 1 /-- Fisher–Rao inner product on the tangent space `T_p Δ_n°`: `g^{FR}_p(v, w) = ∑_i (v_i w_i) / p_i`. -/ def fisherRaoInner {n : ℕ} (p : SimplexPoint n) (v w : Fin n → ℝ) : ℝ := ∑ i : Fin n, v i * w i / p.p i /-- Spherical embedding `Φ : Δ_n° → S^{n-1}_+(2)` given by `u_i(p) = 2 √p_i`. -/ def sphereMap {n : ℕ} (p : SimplexPoint n) (i : Fin n) : ℝ := 2 * Real.sqrt (p.p i) /-- Differential of `Φ` at `p` acting on tangent vector `v`: `du_i(v) = v_i / √p_i`. -/ def dSphereMap {n : ℕ} (p : SimplexPoint n) (v : Fin n → ℝ) (i : Fin n) : ℝ := v i / Real.sqrt (p.p i) /-- **Theorem 2.5a (Radius-2 Sphere Constraint):** `∑_i u_i(p)² = 4 = 2²` and `u_i(p) > 0` for every `p ∈ Δ_n°`. -/ theorem sphereMap_on_radius_two_sphere {n : ℕ} (p : SimplexPoint n) : (∀ i, 0 < sphereMap p i) ∧ ∑ i : Fin n, (sphereMap p i) ^ 2 = 4 := by constructor · intro i exact mul_pos two_pos (Real.sqrt_pos.mpr (p.pos i)) · unfold sphereMap calc ∑ i : Fin n, (2 * Real.sqrt (p.p i)) ^ 2 = ∑ i : Fin n, 4 * p.p i := by refine Finset.sum_congr rfl ?_ intro i _ rw [mul_pow, Real.sq_sqrt (le_of_lt (p.pos i))] ring _ = 4 * ∑ i : Fin n, p.p i := (Finset.mul_sum _ _ _).symm _ = 4 := by rw [p.sum_one, mul_one] /-- **Theorem 2.5b (Tangent Orthogonality & Exact Fisher–Rao Spherical Isometry):** For all tangent vectors `v, w ∈ T_p Δ_n°` (`∑ v_i = ∑ w_i = 0`), `du(v)` is tangent to `S^{n-1}(2)` (`⟨u(p), du(v)⟩ = 0`) and `⟨du(v), du(w)⟩_{ℝ^n} = g^{FR}_p(v, w)` identically! -/ theorem fisherRao_spherical_isometry {n : ℕ} (p : SimplexPoint n) (v w : Fin n → ℝ) (hv : ∑ i : Fin n, v i = 0) : (∑ i : Fin n, sphereMap p i * dSphereMap p v i = 0) ∧ (∑ i : Fin n, dSphereMap p v i * dSphereMap p w i = fisherRaoInner p v w) := by constructor · unfold sphereMap dSphereMap calc ∑ i : Fin n, (2 * Real.sqrt (p.p i)) * (v i / Real.sqrt (p.p i)) = ∑ i : Fin n, 2 * v i := by refine Finset.sum_congr rfl ?_ intro i _ have hs : Real.sqrt (p.p i) ≠ 0 := ne_of_gt (Real.sqrt_pos.mpr (p.pos i)) field_simp [hs] _ = 2 * ∑ i : Fin n, v i := (Finset.mul_sum _ _ _).symm _ = 0 := by rw [hv, mul_zero] · unfold dSphereMap fisherRaoInner refine Finset.sum_congr rfl ?_ intro i _ have hsq : Real.sqrt (p.p i) * Real.sqrt (p.p i) = p.p i := Real.mul_self_sqrt (le_of_lt (p.pos i)) rw [div_mul_div_comm, hsq] /-- Bhattacharyya affinity / cosine `B(p, q) = ∑_i √(p_i q_i)`. -/ def bhattacharyya {n : ℕ} (p q : SimplexPoint n) : ℝ := ∑ i : Fin n, Real.sqrt (p.p i) * Real.sqrt (q.p i) /-- Squared Hellinger distance `H²(p, q) = (1/2) ∑_i (√p_i - √q_i)²`. -/ def hellingerSq {n : ℕ} (p q : SimplexPoint n) : ℝ := (1 / 2 : ℝ) * ∑ i : Fin n, (Real.sqrt (p.p i) - Real.sqrt (q.p i)) ^ 2 /-- Exact Fisher–Rao geodesic distance on `Δ_n°`: `d_{FR}(p, q) = 2 arccos(B(p, q))`. -/ def fisherRaoDist {n : ℕ} (p q : SimplexPoint n) : ℝ := 2 * Real.arccos (bhattacharyya p q) lemma hellingerSq_eq_one_sub_bhattacharyya {n : ℕ} (p q : SimplexPoint n) : hellingerSq p q = 1 - bhattacharyya p q := by unfold hellingerSq bhattacharyya have hsum : ∑ i : Fin n, (Real.sqrt (p.p i) - Real.sqrt (q.p i)) ^ 2 = (∑ i : Fin n, p.p i) + (∑ i : Fin n, q.p i) - 2 * ∑ i : Fin n, Real.sqrt (p.p i) * Real.sqrt (q.p i) := by rw [Finset.mul_sum, ← Finset.sum_add_distrib, ← Finset.sum_sub_distrib] refine Finset.sum_congr rfl ?_ intro i _ have hsp := Real.sq_sqrt (le_of_lt (p.pos i)) have hsq := Real.sq_sqrt (le_of_lt (q.pos i)) linarith [show (Real.sqrt (p.p i) - Real.sqrt (q.p i)) ^ 2 = Real.sqrt (p.p i) ^ 2 + Real.sqrt (q.p i) ^ 2 - 2 * (Real.sqrt (p.p i) * Real.sqrt (q.p i)) by ring] rw [hsum, p.sum_one, q.sum_one] ring lemma bhattacharyya_pos {n : ℕ} [NeZero n] (p q : SimplexPoint n) : 0 < bhattacharyya p q := by unfold bhattacharyya have h0 : (0 : Fin n) ∈ (Finset.univ : Finset (Fin n)) := Finset.mem_univ _ exact Finset.sum_pos' (fun i _ => le_of_lt (mul_pos (Real.sqrt_pos.mpr (p.pos i)) (Real.sqrt_pos.mpr (q.pos i)))) ⟨0, h0, mul_pos (Real.sqrt_pos.mpr (p.pos 0)) (Real.sqrt_pos.mpr (q.pos 0))⟩ lemma bhattacharyya_le_one {n : ℕ} (p q : SimplexPoint n) : bhattacharyya p q ≤ 1 := by have h := hellingerSq_eq_one_sub_bhattacharyya p q have hnn : 0 ≤ hellingerSq p q := by unfold hellingerSq exact mul_nonneg (by norm_num) (Finset.sum_nonneg fun i _ => sq_nonneg _) linarith lemma bhattacharyya_eq_one_iff {n : ℕ} (p q : SimplexPoint n) : bhattacharyya p q = 1 ↔ p = q := by have h := hellingerSq_eq_one_sub_bhattacharyya p q constructor · intro hb1 have hh0 : ∑ i : Fin n, (Real.sqrt (p.p i) - Real.sqrt (q.p i)) ^ 2 = 0 := by unfold hellingerSq at h linarith ext i have hi : (Real.sqrt (p.p i) - Real.sqrt (q.p i)) ^ 2 = 0 := (Finset.sum_eq_zero_iff_of_nonneg fun j _ => sq_nonneg _).mp hh0 i (Finset.mem_univ i) have hsqrt : Real.sqrt (p.p i) = Real.sqrt (q.p i) := sub_eq_zero.mp (sq_eq_zero_iff.mp hi) have hsq := congrArg (fun x => x ^ 2) hsqrt rwa [Real.sq_sqrt (le_of_lt (p.pos i)), Real.sq_sqrt (le_of_lt (q.pos i))] at hsq · intro heq subst heq unfold bhattacharyya calc ∑ i : Fin n, Real.sqrt (p.p i) * Real.sqrt (p.p i) = ∑ i : Fin n, p.p i := by refine Finset.sum_congr rfl ?_ intro i _ exact Real.mul_self_sqrt (le_of_lt (p.pos i)) _ = 1 := p.sum_one /-- **Theorem 2.5c (Exact Hellinger–Fisher–Rao Trigonometric Identity):** `H²(p, q) = 2 sin²(d_{FR}(p, q) / 4)` and `2 H(p, q) ≤ d_{FR}(p, q)`. -/ theorem hellingerSq_eq_two_sin_sq_fisherRao {n : ℕ} [NeZero n] (p q : SimplexPoint n) : hellingerSq p q = 2 * Real.sin (fisherRaoDist p q / 4) ^ 2 := by rw [hellingerSq_eq_one_sub_bhattacharyya] unfold fisherRaoDist have hdiv : 2 * Real.arccos (bhattacharyya p q) / 4 = Real.arccos (bhattacharyya p q) / 2 := by ring rw [hdiv] have hcos : Real.cos (Real.arccos (bhattacharyya p q)) = bhattacharyya p q := Real.cos_arccos (by linarith [bhattacharyya_pos p q]) (bhattacharyya_le_one p q) have hdouble : Real.cos (Real.arccos (bhattacharyya p q)) = 1 - 2 * Real.sin (Real.arccos (bhattacharyya p q) / 2) ^ 2 := by have h2 := Real.cos_two_mul (Real.arccos (bhattacharyya p q) / 2) have hpy := Real.sin_sq_add_cos_sq (Real.arccos (bhattacharyya p q) / 2) have harg : 2 * (Real.arccos (bhattacharyya p q) / 2) = Real.arccos (bhattacharyya p q) := by ring rw [harg] at h2 linarith linarith /-- **Theorem 2.5d (Exact Great-Circle Spherical Geodesic & Constant Fisher–Rao Speed):** For any `p ≠ q ∈ Δ_n°` with `θ = arccos B(p, q) ∈ (0, π/2)`, the spherical slerp curve `u(t) = (sin((1-t)θ)/sin θ) u(p) + (sin(tθ)/sin θ) u(q)` stays strictly in the positive orthant of `S^{n-1}(2)` for all `t ∈ [0, 1]`, connects `u(p)` to `u(q)`, and has exact constant speed `‖u'(t)‖₂² = d_{FR}(p, q)²` proved via `HasDerivAt`! -/ def slerpCurve {n : ℕ} (p q : SimplexPoint n) (t : ℝ) (i : Fin n) : ℝ := let θ := Real.arccos (bhattacharyya p q) (Real.sin ((1 - t) * θ) / Real.sin θ) * sphereMap p i + (Real.sin (t * θ) / Real.sin θ) * sphereMap q i theorem slerp_geodesic_exact {n : ℕ} [NeZero n] (p q : SimplexPoint n) (hne : p ≠ q) : let θ := Real.arccos (bhattacharyya p q) (0 < θ ∧ θ < Real.pi / 2) ∧ (∀ i, slerpCurve p q 0 i = sphereMap p i) ∧ (∀ i, slerpCurve p q 1 i = sphereMap q i) ∧ (∀ t ∈ Set.Icc (0 : ℝ) 1, ∀ i, 0 < slerpCurve p q t i) ∧ (∀ t : ℝ, ∑ i : Fin n, (slerpCurve p q t i) ^ 2 = 4) ∧ (∀ t : ℝ, ∃ v : Fin n → ℝ, (∀ i, HasDerivAt (fun s => slerpCurve p q s i) (v i) t) ∧ ∑ i : Fin n, (v i) ^ 2 = (fisherRaoDist p q) ^ 2) := by intro θ have hb_pos : 0 < bhattacharyya p q := bhattacharyya_pos p q have hb_lt1 : bhattacharyya p q < 1 := lt_of_le_of_ne (bhattacharyya_le_one p q) (fun h => hne ((bhattacharyya_eq_one_iff p q).mp h)) have hθ_pos : 0 < θ := by have : Real.arccos 1 < Real.arccos (bhattacharyya p q) := Real.arccos_lt_arccos (by linarith) hb_lt1 le_rfl simpa [θ] using this have hθ_lt : θ < Real.pi / 2 := by have : Real.arccos (bhattacharyya p q) < Real.arccos 0 := Real.arccos_lt_arccos (by linarith) hb_pos (le_of_lt hb_lt1) simpa [θ] using this have hsin_pos : 0 < Real.sin θ := Real.sin_pos_of_pos_of_lt_pi hθ_pos (by linarith [Real.pi_pos]) have hsin_ne : Real.sin θ ≠ 0 := ne_of_gt hsin_pos have hcosθ : Real.cos θ = bhattacharyya p q := Real.cos_arccos (by linarith) (le_of_lt hb_lt1) have hdot_uv : ∑ i : Fin n, sphereMap p i * sphereMap q i = 4 * Real.cos θ := by unfold sphereMap rw [hcosθ] unfold bhattacharyya rw [Finset.mul_sum] refine Finset.sum_congr rfl ?_ intro i _ ring have hnorm_p := (sphereMap_on_radius_two_sphere p).2 have hnorm_q := (sphereMap_on_radius_two_sphere q).2 refine ⟨⟨hθ_pos, hθ_lt⟩, ?_, ?_, ?_, ?_, ?_⟩ · intro i change (Real.sin ((1 - 0) * θ) / Real.sin θ) * sphereMap p i + (Real.sin (0 * θ) / Real.sin θ) * sphereMap q i = sphereMap p i simp [div_self hsin_ne] · intro i change (Real.sin ((1 - 1) * θ) / Real.sin θ) * sphereMap p i + (Real.sin (1 * θ) / Real.sin θ) * sphereMap q i = sphereMap q i simp [div_self hsin_ne] · intro t ⟨ht0, ht1⟩ i change 0 < (Real.sin ((1 - t) * θ) / Real.sin θ) * sphereMap p i + (Real.sin (t * θ) / Real.sin θ) * sphereMap q i have hup : 0 < sphereMap p i := (sphereMap_on_radius_two_sphere p).1 i have huq : 0 < sphereMap q i := (sphereMap_on_radius_two_sphere q).1 i by_cases ht_zero : t = 0 · subst ht_zero simp [div_self hsin_ne, hup] · have ht_pos : 0 < t := lt_of_le_of_ne ht0 (Ne.symm ht_zero) have h1 : 0 ≤ Real.sin ((1 - t) * θ) / Real.sin θ * sphereMap p i := by apply mul_nonneg (div_nonneg _ (le_of_lt hsin_pos)) (le_of_lt hup) exact Real.sin_nonneg_of_nonneg_of_le_pi (mul_nonneg (by linarith) (le_of_lt hθ_pos)) (by nlinarith [Real.pi_pos]) have h2 : 0 < Real.sin (t * θ) / Real.sin θ * sphereMap q i := by apply mul_pos (div_pos _ hsin_pos) huq exact Real.sin_pos_of_pos_of_lt_pi (mul_pos ht_pos hθ_pos) (by nlinarith [Real.pi_pos]) linarith · intro t unfold slerpCurve set a := Real.sin ((1 - t) * θ) / Real.sin θ set b := Real.sin (t * θ) / Real.sin θ have hexpand : ∑ i : Fin n, (a * sphereMap p i + b * sphereMap q i) ^ 2 = a ^ 2 * (∑ i : Fin n, (sphereMap p i) ^ 2) + b ^ 2 * (∑ i : Fin n, (sphereMap q i) ^ 2) + 2 * a * b * (∑ i : Fin n, sphereMap p i * sphereMap q i) := by simp_rw [Finset.mul_sum, ← Finset.sum_add_distrib] refine Finset.sum_congr rfl ?_ intro i _ ring rw [hexpand, hnorm_p, hnorm_q, hdot_uv] have htrig : Real.sin ((1 - t) * θ) ^ 2 + Real.sin (t * θ) ^ 2 + 2 * Real.sin ((1 - t) * θ) * Real.sin (t * θ) * Real.cos θ = Real.sin θ ^ 2 := by have hadd := Real.sin_add ((1 - t) * θ) (t * θ) rw [show (1 - t) * θ + t * θ = θ by ring] at hadd have hcos_add := Real.cos_add ((1 - t) * θ) (t * θ) rw [show (1 - t) * θ + t * θ = θ by ring] at hcos_add have hp1 := Real.sin_sq_add_cos_sq ((1 - t) * θ) have hp2 := Real.sin_sq_add_cos_sq (t * θ) rw [hadd, hcos_add] linear_combination -(Real.sin ((1 - t) * θ) ^ 2) * hp2 - (Real.sin (t * θ) ^ 2) * hp1 have h1 : a ^ 2 + b ^ 2 + 2 * a * b * Real.cos θ = 1 := by simp only [a, b] have hsq : Real.sin θ ^ 2 ≠ 0 := pow_ne_zero 2 hsin_ne rw [div_pow, div_pow] have hcomb : Real.sin ((1 - t) * θ) ^ 2 / Real.sin θ ^ 2 + Real.sin (t * θ) ^ 2 / Real.sin θ ^ 2 + 2 * (Real.sin ((1 - t) * θ) / Real.sin θ) * (Real.sin (t * θ) / Real.sin θ) * Real.cos θ = (Real.sin ((1 - t) * θ) ^ 2 + Real.sin (t * θ) ^ 2 + 2 * Real.sin ((1 - t) * θ) * Real.sin (t * θ) * Real.cos θ) / Real.sin θ ^ 2 := by field_simp [hsin_ne] rw [hcomb, htrig, div_self hsq] linarith · intro t let a' := -θ * Real.cos ((1 - t) * θ) / Real.sin θ let b' := θ * Real.cos (t * θ) / Real.sin θ refine ⟨fun i => a' * sphereMap p i + b' * sphereMap q i, ?_, ?_⟩ · intro i unfold slerpCurve have h1 : HasDerivAt (fun s : ℝ => (1 - s) * θ) (-θ) t := by have hs : HasDerivAt (fun s : ℝ => 1 - s) (-1) t := by simpa using (hasDerivAt_const t (1 : ℝ)).fun_sub (hasDerivAt_id t) simpa using hs.mul_const θ have h2 : HasDerivAt (fun s : ℝ => s * θ) θ t := by simpa using (hasDerivAt_id t).mul_const θ have hsin1 := ((h1.sin).div_const (Real.sin θ)).mul_const (sphereMap p i) have hsin2 := ((h2.sin).div_const (Real.sin θ)).mul_const (sphereMap q i) have htot := hsin1.fun_add hsin2 have hval : Real.cos ((1 - t) * θ) * -θ / Real.sin θ * sphereMap p i + Real.cos (t * θ) * θ / Real.sin θ * sphereMap q i = a' * sphereMap p i + b' * sphereMap q i := by dsimp only [a', b'] ring rw [hval] at htot exact htot · have hexpand : ∑ i : Fin n, (a' * sphereMap p i + b' * sphereMap q i) ^ 2 = a' ^ 2 * (∑ i : Fin n, (sphereMap p i) ^ 2) + b' ^ 2 * (∑ i : Fin n, (sphereMap q i) ^ 2) + 2 * a' * b' * (∑ i : Fin n, sphereMap p i * sphereMap q i) := by simp_rw [Finset.mul_sum, ← Finset.sum_add_distrib] refine Finset.sum_congr rfl ?_ intro i _ ring rw [hexpand, hnorm_p, hnorm_q, hdot_uv] have htrig2 : Real.cos ((1 - t) * θ) ^ 2 + Real.cos (t * θ) ^ 2 - 2 * Real.cos ((1 - t) * θ) * Real.cos (t * θ) * Real.cos θ = Real.sin θ ^ 2 := by have hadd := Real.sin_add ((1 - t) * θ) (t * θ) rw [show (1 - t) * θ + t * θ = θ by ring] at hadd have hcos_add := Real.cos_add ((1 - t) * θ) (t * θ) rw [show (1 - t) * θ + t * θ = θ by ring] at hcos_add have hp1 := Real.sin_sq_add_cos_sq ((1 - t) * θ) have hp2 := Real.sin_sq_add_cos_sq (t * θ) rw [hadd, hcos_add] linear_combination -(Real.cos ((1 - t) * θ) ^ 2) * hp2 - (Real.cos (t * θ) ^ 2) * hp1 have hspeed : a' ^ 2 + b' ^ 2 + 2 * a' * b' * Real.cos θ = θ ^ 2 := by have hsq : Real.sin θ ^ 2 ≠ 0 := pow_ne_zero 2 hsin_ne have hcomb : a' ^ 2 + b' ^ 2 + 2 * a' * b' * Real.cos θ = θ ^ 2 * (Real.cos ((1 - t) * θ) ^ 2 + Real.cos (t * θ) ^ 2 - 2 * Real.cos ((1 - t) * θ) * Real.cos (t * θ) * Real.cos θ) / Real.sin θ ^ 2 := by dsimp only [a', b'] field_simp [hsin_ne] ring rw [hcomb, htrig2, mul_div_cancel_right₀ _ hsq] unfold fisherRaoDist change a' ^ 2 * 4 + b' ^ 2 * 4 + 2 * a' * b' * (4 * Real.cos θ) = (2 * θ) ^ 2 linarith /-- **Theorem 2.5e (Full Metric Axioms for Fisher–Rao Geodesic Distance on `Δ_n°`):** Non-negativity, identity of indiscernibles, symmetry, and the exact `n`-dimensional spherical triangle inequality `d_{FR}(p, r) ≤ d_{FR}(p, q) + d_{FR}(q, r)`! -/ theorem fisherRaoDist_nonneg {n : ℕ} (p q : SimplexPoint n) : 0 ≤ fisherRaoDist p q := by unfold fisherRaoDist exact mul_nonneg (by norm_num) (Real.arccos_nonneg _) theorem fisherRaoDist_eq_zero_iff {n : ℕ} [NeZero n] (p q : SimplexPoint n) : fisherRaoDist p q = 0 ↔ p = q := by unfold fisherRaoDist rw [mul_eq_zero] simp only [OfNat.ofNat_ne_zero, false_or] rw [← bhattacharyya_eq_one_iff] constructor · intro h have hcos := congrArg Real.cos h rw [Real.cos_arccos (by linarith [bhattacharyya_pos p q]) (bhattacharyya_le_one p q), Real.cos_zero] at hcos exact hcos · intro h rw [h, Real.arccos_one] theorem fisherRaoDist_symm {n : ℕ} (p q : SimplexPoint n) : fisherRaoDist p q = fisherRaoDist q p := by unfold fisherRaoDist bhattacharyya congr 1 congr 1 refine Finset.sum_congr rfl ?_ intro i _ ring theorem fisherRaoDist_triangle {n : ℕ} [NeZero n] (p q r : SimplexPoint n) : fisherRaoDist p r ≤ fisherRaoDist p q + fisherRaoDist q r := by unfold fisherRaoDist set a := bhattacharyya p q set b := bhattacharyya q r set c := bhattacharyya p r set α := Real.arccos a set β := Real.arccos b set γ := Real.arccos c suffices h : γ ≤ α + β by linarith have ha_pos : 0 < a := bhattacharyya_pos p q have hb_pos : 0 < b := bhattacharyya_pos q r have hc_pos : 0 < c := bhattacharyya_pos p r have ha_le1 : a ≤ 1 := bhattacharyya_le_one p q have hb_le1 : b ≤ 1 := bhattacharyya_le_one q r have hc_le1 : c ≤ 1 := bhattacharyya_le_one p r have hγ_le_half : γ ≤ Real.pi / 2 := by have : Real.arccos c ≤ Real.arccos 0 := Real.arccos_le_arccos (le_of_lt hc_pos) simpa [γ] using this by_cases hsum : Real.pi / 2 ≤ α + β · linarith · push Not at hsum have hα_nn : 0 ≤ α := Real.arccos_nonneg a have hβ_nn : 0 ≤ β := Real.arccos_nonneg b have hγ_nn : 0 ≤ γ := Real.arccos_nonneg c have hcos_le : Real.cos (α + β) ≤ Real.cos γ := by rw [Real.cos_add, Real.cos_arccos (by linarith) ha_le1, Real.cos_arccos (by linarith) hb_le1, Real.cos_arccos (by linarith) hc_le1, Real.sin_arccos, Real.sin_arccos] -- Orthogonal projections x_⊥ = √p - a √q, z_⊥ = √r - b √q let x : Fin n → ℝ := fun i => Real.sqrt (p.p i) - a * Real.sqrt (q.p i) let z : Fin n → ℝ := fun i => Real.sqrt (r.p i) - b * Real.sqrt (q.p i) have hx2 : ∑ i : Fin n, (x i) ^ 2 = 1 - a ^ 2 := by calc ∑ i : Fin n, (Real.sqrt (p.p i) - a * Real.sqrt (q.p i)) ^ 2 = (∑ i : Fin n, p.p i) - 2 * a * bhattacharyya p q + a ^ 2 * (∑ i : Fin n, q.p i) := by unfold bhattacharyya rw [Finset.mul_sum, Finset.mul_sum, ← Finset.sum_sub_distrib, ← Finset.sum_add_distrib] refine Finset.sum_congr rfl ?_ intro i _ have hsp := Real.sq_sqrt (le_of_lt (p.pos i)) have hsq := Real.sq_sqrt (le_of_lt (q.pos i)) nlinarith _ = 1 - a ^ 2 := by rw [p.sum_one, q.sum_one]; ring have hz2 : ∑ i : Fin n, (z i) ^ 2 = 1 - b ^ 2 := by calc ∑ i : Fin n, (Real.sqrt (r.p i) - b * Real.sqrt (q.p i)) ^ 2 = (∑ i : Fin n, r.p i) - 2 * b * bhattacharyya q r + b ^ 2 * (∑ i : Fin n, q.p i) := by unfold bhattacharyya rw [Finset.mul_sum, Finset.mul_sum, ← Finset.sum_sub_distrib, ← Finset.sum_add_distrib] refine Finset.sum_congr rfl ?_ intro i _ have hsr := Real.sq_sqrt (le_of_lt (r.pos i)) have hsq := Real.sq_sqrt (le_of_lt (q.pos i)) nlinarith _ = 1 - b ^ 2 := by rw [r.sum_one, q.sum_one]; ring have hxz : ∑ i : Fin n, x i * z i = c - a * b := by calc ∑ i : Fin n, (Real.sqrt (p.p i) - a * Real.sqrt (q.p i)) * (Real.sqrt (r.p i) - b * Real.sqrt (q.p i)) = bhattacharyya p r - a * bhattacharyya q r - b * bhattacharyya p q + a * b * (∑ i : Fin n, q.p i) := by unfold bhattacharyya rw [Finset.mul_sum, Finset.mul_sum, Finset.mul_sum, ← Finset.sum_sub_distrib, ← Finset.sum_sub_distrib, ← Finset.sum_add_distrib] refine Finset.sum_congr rfl ?_ intro i _ have hexp : (Real.sqrt (p.p i) - a * Real.sqrt (q.p i)) * (Real.sqrt (r.p i) - b * Real.sqrt (q.p i)) = Real.sqrt (p.p i) * Real.sqrt (r.p i) - a * (Real.sqrt (q.p i) * Real.sqrt (r.p i)) - b * (Real.sqrt (p.p i) * Real.sqrt (q.p i)) + a * b * (Real.sqrt (q.p i) * Real.sqrt (q.p i)) := by ring rw [hexp, Real.mul_self_sqrt (le_of_lt (q.pos i))] _ = c - a * b := by rw [q.sum_one]; ring have hcs : (c - a * b) ^ 2 ≤ (1 - a ^ 2) * (1 - b ^ 2) := by rw [← hxz, ← hx2, ← hz2] exact Finset.sum_mul_sq_le_sq_mul_sq Finset.univ x z have hsqrt_le : a * b - c ≤ Real.sqrt (1 - a ^ 2) * Real.sqrt (1 - b ^ 2) := by rw [← Real.sqrt_mul (by nlinarith : 0 ≤ 1 - a ^ 2)] have h1 : (a * b - c) ^ 2 ≤ (1 - a ^ 2) * (1 - b ^ 2) := by linarith exact Real.le_sqrt_of_sq_le h1 linarith by_contra hlt push Not at hlt have hgt : Real.cos γ < Real.cos (α + β) := Real.strictAntiOn_cos ⟨by linarith, by linarith [Real.pi_pos]⟩ ⟨hγ_nn, by linarith [Real.pi_pos]⟩ hlt linarith /-! ## Section 6: Kernel Axiom Audit -/ #print axioms SmoothStatModel.hasDerivAt_logLik #print axioms SmoothStatModel.hasDerivAt_score #print axioms SmoothStatModel.bartlett_first_identity #print axioms SmoothStatModel.bartlett_second_identity #print axioms SmoothStatModel.fisherMetric_symm #print axioms SmoothStatModel.chentsovTensor_symm #print axioms amariGamma_torsion_free #print axioms amari_alpha_dual_metric_compatibility #print axioms leviCivita_metric_compatibility #print axioms amariGamma_natural_coords #print axioms e_flatness_natural_coords #print axioms inverse_hessian_metric_duality #print axioms amariGamma_expectation_coords #print axioms m_flatness_expectation_coords #print axioms riemannAlpha_exact_scaling #print axioms riemannAlpha_vanishes_at_pm_one #print axioms simplex2_uniform_sectional_curvature_quarter #print axioms sphereMap_on_radius_two_sphere #print axioms fisherRao_spherical_isometry #print axioms hellingerSq_eq_two_sin_sq_fisherRao #print axioms slerp_geodesic_exact #print axioms fisherRaoDist_nonneg #print axioms fisherRaoDist_eq_zero_iff #print axioms fisherRaoDist_symm #print axioms fisherRaoDist_triangle end InfoGeomFisherAmari