import Mathlib /-! # Pillars 2 & 3: Bethe Free Energy, Yedidia–Freeman–Weiss 1-to-1 Equivalence, Kikuchi Region Graphs, & Tree-Reweighted (TRW) Convex Upper Bounds This standalone Lean 4 + Mathlib formalization establishes the complete variational theory of Belief Propagation, Bethe & Kikuchi approximations, and Wainwright–Jaakkola–Willsky Tree-Reweighted (TRW) convex upper bounds on arbitrary finite pairwise Markov Random Fields. ## Headline Results ### Pillar 2 — Exact Bethe Free Energy, Tree Convexity, YFW Bijection & Kikuchi Region Graphs 1. **Exact Tree Bethe–Gibbs Identity & Strict Convexity on Trees** (`tree_betheEntropy_eq_gibbsEntropy`, `tree_betheFreeEnergy_eq_kl_sub_logZ`, `tree_betheFreeEnergy_min_iff`, `tree_betheFreeEnergy_strictConvex`): On any finite tree `T = (V, E)` and any interior local pseudomarginal `b ∈ L°(T)`, the tree-factorized joint `q_b(x) = ∏_i b_i(x_i) ∏_{e={i,j}} b_{ij}(x_i,x_j)/(b_i(x_i) b_j(x_j))` is a strictly positive probability distribution with exact marginals `b_i, b_{ij}`, exact entropy `H(q_b) = H_Bethe(b)`, exact Bethe–Gibbs identity `F_Bethe(b) = D_KL(q_b ‖ p) - log Z ≥ -log Z` (equality iff `b = p_marg`), and **strict convexity** of `F_Bethe` on `L°(T)`. 2. **Yedidia–Freeman–Weiss (YFW) Exact 1-to-1 Stationary-Point Bijection on Arbitrary Graphs** (`hasDerivAt_betheLagrangian_node`, `hasDerivAt_betheLagrangian_edge`, `yfw_bp_implies_betheStationary`, `yfw_betheStationary_implies_bp`, `yfw_bijection`): On **any** finite graph `G` (with arbitrary cycles!), interior KKT stationary points `b ∈ L°(G)` of the Bethe Free Energy (zero partial derivatives of the Bethe Lagrangian via `HasDerivAt`) are in **exact 1-to-1 bijection** (`Function.Bijective`) with normalized strictly positive Sum-Product BP fixed points `m` on `G`. 3. **Unicyclic Convexity Boundary vs. `K_4` / Diamond Non-Convexity & Negative Bethe Entropy** (`single_cycle_betheEntropy_concave`, `bethe_vs_true_logZ_gap_K3`, `bethe_vs_true_logZ_gap_C4`, `bethe_nonconvex_and_negative_entropy_K4`): - On any single-cycle graph `C_n` (`d_i = 2`, including `K_3` and `C_4`), `H_Bethe` is globally concave and `≥ 0` (`F_Bethe` is convex), YET Bethe fails exactness with exact closed-form gaps `log Z_{K_3}(J) - (-F_Bethe(b^BP)) = log(1 + tanh³ J) > 0` and `log Z_{C_4}(J) - (-F_Bethe(b^BP)) = log(1 + tanh⁴ J) > 0` for all `J > 0`. - At cyclomatic number `≥ 2` (`K_4`), `F_Bethe` becomes **strictly non-convex** and `H_Bethe` turns **strictly negative** on an explicit interior realizable belief `b̄ ∈ L°(K_4)`. 4. **Kikuchi / Cluster-Variational Region Graphs & Exactness on `C_4` (`2 × 2` Grid)** (`betheRegionGraph_valid`, `twoCluster_kikuchi_exact`, `c4_kikuchi_exact_vs_bethe_gap`): Formalizes Möbius region graphs `(R, c_R)`, proves general 2-cluster junction-tree exactness `F_Kikuchi(b) = D_KL(q_stitch ‖ p) - log Z`, and instantiates on `C_4` with clusters `{0,1,2}`, `{0,2,3}` and separator `{0,2}` (`c = +1, +1, -1`), recovering `log Z_{C_4}` with **zero** error where Bethe incurs `log(1 + tanh⁴ J) > 0`. ### Pillar 3 — Wainwright–Jaakkola–Willsky Tree-Reweighted (TRW) Convex Upper Bounds 5. **Exact TRW Log-Partition Upper Bound, Dual Variational Form, Strict Concavity & Tightness** (`trw_logZ_upper_bound`, `trwEntropy_eq_weighted_treeEntropy`, `trwEntropy_strictConcave`, `trw_dual_variational_upper_bound`, `trw_tight_on_tree`, `trw_bethe_sandwich_K3`): For any convex combination `μ` of spanning trees `{T_t}` of `G` with edge appearance probabilities `ρ_e = ∑_{t : e ∈ T_t} μ_t`: - `log Z(θ) ≤ ∑_t μ_t log Z(θ^(t))` for any convex decomposition `θ = ∑_t μ_t θ^(t)`; - `H_TRW(b; ρ) = ∑_i H(b_i) - ∑_e ρ_e I(b_e) = ∑_t μ_t H(q_{b, T_t})` is **strictly concave** and nonnegative on `L°(G)` for every graph `G` (including `K_4`); - Exact dual variational sandwich: `log Z(θ) ≤ ⟨θ, p_marg⟩ + H_TRW(p_marg; ρ) ≤ ∑_t μ_t log Z(θ^(t))` and `⟨θ, b⟩ + H_TRW(b; ρ) ≤ ∑_t μ_t log Z(θ^(t))` for every `b ∈ L°(G)`, with exact tightness on trees (`ρ_e = 1`) and explicit strict sandwich `-F_Bethe(b^BP) < log Z_{K_3}(J) < TRW_{K_3}(J)` for every `J > 0`. -/ open scoped BigOperators open Finset Real SimpleGraph namespace BetheKikuchiTRW /-! ## Section 1: Discrete Entropy, KL Divergence, Gibbs Inequality & Concavity -/ section InfoTheory variable {α β : Type*} [Fintype α] [Fintype β] /-- Discrete Shannon entropy `H(p) = -∑_a p(a) log p(a)`. -/ noncomputable def shannonH (p : α → ℝ) : ℝ := -∑ a : α, p a * Real.log (p a) /-- Discrete KL divergence `D_KL(q ‖ p) = ∑_a q(a) log (q(a) / p(a))`. -/ noncomputable def klDiv (q p : α → ℝ) : ℝ := ∑ a : α, q a * Real.log (q a / p a) /-- Gibbs' inequality: `D_KL(q ‖ p) ≥ 0` for positive distributions `q, p`. -/ theorem klDiv_nonneg {q p : α → ℝ} (hq : ∀ a, 0 < q a) (hp : ∀ a, 0 < p a) (hq1 : ∑ a : α, q a = 1) (hp1 : ∑ a : α, p a = 1) : 0 ≤ klDiv q p := by unfold klDiv have hterm : ∀ a : α, q a - p a ≤ q a * Real.log (q a / p a) := by intro a have hlog := Real.log_le_sub_one_of_pos (div_pos (hp a) (hq a)) have hinv : Real.log (p a / q a) = -Real.log (q a / p a) := by rw [← inv_div (q a) (p a), Real.log_inv] rw [hinv] at hlog have hmul := mul_le_mul_of_nonneg_left hlog (le_of_lt (hq a)) have hcancel : q a * (p a / q a - 1) = p a - q a := by field_simp [ne_of_gt (hq a)] linarith have hsum := Finset.sum_le_sum (s := Finset.univ) fun a _ => hterm a rw [Finset.sum_sub_distrib, hq1, hp1, sub_self] at hsum exact hsum /-- Strict equality case of Gibbs' inequality: `D_KL(q ‖ p) = 0 ↔ q = p`. -/ theorem klDiv_eq_zero_iff {q p : α → ℝ} (hq : ∀ a, 0 < q a) (hp : ∀ a, 0 < p a) (hq1 : ∑ a : α, q a = 1) (hp1 : ∑ a : α, p a = 1) : klDiv q p = 0 ↔ q = p := by constructor · intro hzero have hterm : ∀ a : α, 0 ≤ q a * Real.log (q a / p a) - (q a - p a) := by intro a have hlog := Real.log_le_sub_one_of_pos (div_pos (hp a) (hq a)) have hinv : Real.log (p a / q a) = -Real.log (q a / p a) := by rw [← inv_div (q a) (p a), Real.log_inv] rw [hinv] at hlog have hmul := mul_le_mul_of_nonneg_left hlog (le_of_lt (hq a)) have hcancel : q a * (p a / q a - 1) = p a - q a := by field_simp [ne_of_gt (hq a)] linarith have hsum0 : ∑ a : α, (q a * Real.log (q a / p a) - (q a - p a)) = 0 := by rw [Finset.sum_sub_distrib, Finset.sum_sub_distrib, hq1, hp1, sub_self, sub_zero] exact hzero have heach := (Finset.sum_eq_zero_iff_of_nonneg (fun a _ => hterm a)).mp hsum0 funext a have ha := heach a (Finset.mem_univ a) have hlog_eq : Real.log (p a / q a) = p a / q a - 1 := by have hinv : Real.log (p a / q a) = -Real.log (q a / p a) := by rw [← inv_div (q a) (p a), Real.log_inv] have hqne : q a ≠ 0 := ne_of_gt (hq a) have h1 : q a * (-Real.log (p a / q a)) = q a - p a := by rw [hinv, neg_neg]; linarith field_simp [hqne] linarith -- Use `log t = t - 1 ↔ t = 1` (via `Real.log_lt_sub_one_of_pos`) have hratio : p a / q a = 1 := by by_contra hne have hlt := Real.log_lt_sub_one_of_pos (div_pos (hp a) (hq a)) hne linarith exact ((div_eq_one_iff_eq (ne_of_gt (hq a))).mp hratio).symm · rintro rfl unfold klDiv refine Finset.sum_eq_zero fun a _ => ?_ rw [div_self (ne_of_gt (hq a)), Real.log_one, mul_zero] /-- Strict concavity of Shannon entropy on positive probability distributions. -/ theorem shannonH_strictConcave {p₁ p₂ : α → ℝ} (hp₁ : ∀ a, 0 < p₁ a) (hp₂ : ∀ a, 0 < p₂ a) (hs₁ : ∑ a : α, p₁ a = 1) (hs₂ : ∑ a : α, p₂ a = 1) (hne : p₁ ≠ p₂) {t : ℝ} (ht0 : 0 < t) (ht1 : t < 1) : (1 - t) * shannonH p₁ + t * shannonH p₂ < shannonH (fun a => (1 - t) * p₁ a + t * p₂ a) := by let pm : α → ℝ := fun a => (1 - t) * p₁ a + t * p₂ a have hpm_pos : ∀ a, 0 < pm a := fun a => add_pos (mul_pos (sub_pos.mpr ht1) (hp₁ a)) (mul_pos ht0 (hp₂ a)) have hpm_sum : ∑ a : α, pm a = 1 := by dsimp only [pm] rw [Finset.sum_add_distrib, ← Finset.mul_sum, ← Finset.mul_sum, hs₁, hs₂]; ring -- Exact JS identity: `H(pm) - ((1-t) H(p₁) + t H(p₂)) = (1-t) D_KL(p₁ ‖ pm) + t D_KL(p₂ ‖ pm)`! have hJS : shannonH pm - ((1 - t) * shannonH p₁ + t * shannonH p₂) = (1 - t) * klDiv p₁ pm + t * klDiv p₂ pm := by unfold shannonH klDiv simp_rw [Real.log_div (ne_of_gt (hp₁ _)) (ne_of_gt (hpm_pos _)), Real.log_div (ne_of_gt (hp₂ _)) (ne_of_gt (hpm_pos _))] have hsplit1 : ∑ a : α, p₁ a * (Real.log (p₁ a) - Real.log (pm a)) = (∑ a : α, p₁ a * Real.log (p₁ a)) - ∑ a : α, p₁ a * Real.log (pm a) := by rw [← Finset.sum_sub_distrib]; refine Finset.sum_congr rfl fun a _ => by ring have hsplit2 : ∑ a : α, p₂ a * (Real.log (p₂ a) - Real.log (pm a)) = (∑ a : α, p₂ a * Real.log (p₂ a)) - ∑ a : α, p₂ a * Real.log (pm a) := by rw [← Finset.sum_sub_distrib]; refine Finset.sum_congr rfl fun a _ => by ring have hpm_log : ∑ a : α, pm a * Real.log (pm a) = (1 - t) * (∑ a : α, p₁ a * Real.log (pm a)) + t * (∑ a : α, p₂ a * Real.log (pm a)) := by dsimp only [pm] rw [Finset.mul_sum, Finset.mul_sum, ← Finset.sum_add_distrib] refine Finset.sum_congr rfl fun a _ => by ring rw [hsplit1, hsplit2, hpm_log]; ring have hkl1_nn := klDiv_nonneg hp₁ hpm_pos hs₁ hpm_sum have hkl2_nn := klDiv_nonneg hp₂ hpm_pos hs₂ hpm_sum have hne1 : p₁ ≠ pm := by intro heq apply hne; funext a have ha := congrFun heq a dsimp only [pm] at ha have : t * (p₂ a - p₁ a) = 0 := by linarith rcases mul_eq_zero.mp this with ht | hdiff · linarith · linarith have hkl1_pos : 0 < klDiv p₁ pm := lt_of_le_of_ne hkl1_nn fun h0 => hne1 ((klDiv_eq_zero_iff hp₁ hpm_pos hs₁ hpm_sum).mp h0.symm) nlinarith /-- Non-strict concavity of Shannon entropy on positive probability distributions. -/ lemma shannonH_concave {p₁ p₂ : α → ℝ} (hp₁ : ∀ a, 0 < p₁ a) (hp₂ : ∀ a, 0 < p₂ a) (hs₁ : ∑ a : α, p₁ a = 1) (hs₂ : ∑ a : α, p₂ a = 1) {t : ℝ} (ht0 : 0 ≤ t) (ht1 : t ≤ 1) : (1 - t) * shannonH p₁ + t * shannonH p₂ ≤ shannonH (fun a => (1 - t) * p₁ a + t * p₂ a) := by rcases eq_or_lt_of_le ht0 with rfl | ht0' · simp · rcases eq_or_lt_of_le ht1 with rfl | ht1' · simp · by_cases heq : p₁ = p₂ · subst heq have hfn : (fun a => (1 - t) * p₁ a + t * p₁ a) = p₁ := by funext a; ring rw [hfn]; linarith · exact le_of_lt (shannonH_strictConcave hp₁ hp₂ hs₁ hs₂ heq ht0' ht1') /-- Concavity of conditional entropy `H(X | Y) = H(X, Y) - H(Y)` in the joint distribution `b : α × β → ℝ` (proved via log-sum inequality / KL divergence). -/ theorem conditionalEntropy_concave {b₁ b₂ : α → β → ℝ} (hb₁ : ∀ a c, 0 < b₁ a c) (hb₂ : ∀ a c, 0 < b₂ a c) (hs₁ : ∑ a : α, ∑ c : β, b₁ a c = 1) (hs₂ : ∑ a : α, ∑ c : β, b₂ a c = 1) {t : ℝ} (ht0 : 0 ≤ t) (ht1 : t ≤ 1) : let m₁ : α → ℝ := fun a => ∑ c : β, b₁ a c let m₂ : α → ℝ := fun a => ∑ c : β, b₂ a c let bm : α → β → ℝ := fun a c => (1 - t) * b₁ a c + t * b₂ a c let mm : α → ℝ := fun a => ∑ c : β, bm a c (1 - t) * (shannonH (fun p : α × β => b₁ p.1 p.2) - shannonH m₁) + t * (shannonH (fun p : α × β => b₂ p.1 p.2) - shannonH m₂) ≤ shannonH (fun p : α × β => bm p.1 p.2) - shannonH mm := by intro m₁ m₂ bm mm rcases eq_or_lt_of_le ht0 with rfl | ht0' · have hbm : bm = b₁ := by funext a c; simp [bm] have hmm : mm = m₁ := by funext a; simp [mm, m₁, hbm] simp [hbm, hmm] rcases eq_or_lt_of_le ht1 with rfl | ht1' · have hbm : bm = b₂ := by funext a c; simp [bm] have hmm : mm = m₂ := by funext a; simp [mm, m₂, hbm] simp [hbm, hmm] -- Exact identity: `H_cond(bm) - ((1-t) H_cond(b₁) + t H_cond(b₂)) = -- (1-t) ∑_{a,c} b₁(a,c) log ((b₁(a,c)/m₁(a)) / (bm(a,c)/mm(a))) + t ∑_{a,c} b₂(...)` ≥ 0! have hm₁_pos : ∀ a, 0 < m₁ a := fun a => by -- Wait: if β is empty, both sums are 0; assume Nonempty β or split! by_cases hne : (Finset.univ : Finset β).Nonempty · exact Finset.sum_pos (fun c _ => hb₁ a c) hne · exfalso have hemp : (Finset.univ : Finset β) = ∅ := Finset.not_nonempty_iff_eq_empty.mp hne simp [hemp] at hs₁ have hm₂_pos : ∀ a, 0 < m₂ a := fun a => by by_cases hne : (Finset.univ : Finset β).Nonempty · exact Finset.sum_pos (fun c _ => hb₂ a c) hne · exfalso have hemp : (Finset.univ : Finset β) = ∅ := Finset.not_nonempty_iff_eq_empty.mp hne simp [hemp] at hs₂ have hbm_pos : ∀ a c, 0 < bm a c := fun a c => add_pos (mul_pos (sub_pos.mpr ht1') (hb₁ a c)) (mul_pos ht0' (hb₂ a c)) have hmm_eq : ∀ a, mm a = (1 - t) * m₁ a + t * m₂ a := fun a => by dsimp only [mm, bm, m₁, m₂] rw [Finset.sum_add_distrib, ← Finset.mul_sum, ← Finset.mul_sum] have hmm_pos : ∀ a, 0 < mm a := fun a => by rw [hmm_eq a]; exact add_pos (mul_pos (sub_pos.mpr ht1') (hm₁_pos a)) (mul_pos ht0' (hm₂_pos a)) -- For each `a`, conditional KL `∑_c (b₁ a c / m₁ a) log ((b₁ a c / m₁ a) / (bm a c / mm a)) ≥ 0`! have hkl1 : ∀ a, 0 ≤ ∑ c : β, b₁ a c * Real.log ((b₁ a c / m₁ a) / (bm a c / mm a)) := by intro a have hcond1 : ∑ c : β, b₁ a c / m₁ a = 1 := by rw [← Finset.sum_div, div_self (ne_of_gt (hm₁_pos a))] have hcondm : ∑ c : β, bm a c / mm a = 1 := by rw [← Finset.sum_div, div_self (ne_of_gt (hmm_pos a))] have hkl := klDiv_nonneg (fun c => div_pos (hb₁ a c) (hm₁_pos a)) (fun c => div_pos (hbm_pos a c) (hmm_pos a)) hcond1 hcondm have hmul := mul_nonneg (le_of_lt (hm₁_pos a)) hkl unfold klDiv at hmul rw [Finset.mul_sum] at hmul refine le_trans hmul (le_of_eq (Finset.sum_congr rfl fun c _ => ?_)) field_simp [ne_of_gt (hm₁_pos a)] have hkl2 : ∀ a, 0 ≤ ∑ c : β, b₂ a c * Real.log ((b₂ a c / m₂ a) / (bm a c / mm a)) := by intro a have hcond2 : ∑ c : β, b₂ a c / m₂ a = 1 := by rw [← Finset.sum_div, div_self (ne_of_gt (hm₂_pos a))] have hcondm : ∑ c : β, bm a c / mm a = 1 := by rw [← Finset.sum_div, div_self (ne_of_gt (hmm_pos a))] have hkl := klDiv_nonneg (fun c => div_pos (hb₂ a c) (hm₂_pos a)) (fun c => div_pos (hbm_pos a c) (hmm_pos a)) hcond2 hcondm have hmul := mul_nonneg (le_of_lt (hm₂_pos a)) hkl unfold klDiv at hmul rw [Finset.mul_sum] at hmul refine le_trans hmul (le_of_eq (Finset.sum_congr rfl fun c _ => ?_)) field_simp [ne_of_gt (hm₂_pos a)] have hnonneg : 0 ≤ (1 - t) * (∑ a : α, ∑ c : β, b₁ a c * Real.log ((b₁ a c / m₁ a) / (bm a c / mm a))) + t * (∑ a : α, ∑ c : β, b₂ a c * Real.log ((b₂ a c / m₂ a) / (bm a c / mm a))) := add_nonneg (mul_nonneg (le_of_lt (sub_pos.mpr ht1')) (Finset.sum_nonneg fun a _ => hkl1 a)) (mul_nonneg (le_of_lt ht0') (Finset.sum_nonneg fun a _ => hkl2 a)) -- Expand algebraically! have hexpand : ∀ (b : α → β → ℝ) (m : α → ℝ) (hb : ∀ a c, 0 < b a c) (hm : ∀ a, 0 < m a) (hsum : ∀ a, ∑ c : β, b a c = m a), (∑ a : α, ∑ c : β, b a c * Real.log ((b a c / m a) / (bm a c / mm a))) = (∑ a : α, ∑ c : β, b a c * Real.log (b a c)) - (∑ a : α, m a * Real.log (m a)) - (∑ a : α, ∑ c : β, b a c * Real.log (bm a c)) + (∑ a : α, m a * Real.log (mm a)) := by intro b m hb hm hsum have hterm : ∀ a c, b a c * Real.log ((b a c / m a) / (bm a c / mm a)) = (b a c * Real.log (b a c) - b a c * Real.log (m a)) - (b a c * Real.log (bm a c) - b a c * Real.log (mm a)) := fun a c => by rw [Real.log_div (ne_of_gt (div_pos (hb a c) (hm a))) (ne_of_gt (div_pos (hbm_pos a c) (hmm_pos a))), Real.log_div (ne_of_gt (hb a c)) (ne_of_gt (hm a)), Real.log_div (ne_of_gt (hbm_pos a c)) (ne_of_gt (hmm_pos a))] ring simp_rw [hterm, Finset.sum_sub_distrib, ← Finset.sum_mul, hsum] ring have h1 := hexpand b₁ m₁ hb₁ hm₁_pos (fun _ => rfl) have h2 := hexpand b₂ m₂ hb₂ hm₂_pos (fun _ => rfl) have hbm_comb : (∑ a : α, ∑ c : β, bm a c * Real.log (bm a c)) = (1 - t) * (∑ a : α, ∑ c : β, b₁ a c * Real.log (bm a c)) + t * (∑ a : α, ∑ c : β, b₂ a c * Real.log (bm a c)) := by simp_rw [Finset.mul_sum, ← Finset.sum_add_distrib] refine Finset.sum_congr rfl fun a _ => Finset.sum_congr rfl fun c _ => by dsimp only [bm]; ring have hmm_comb : (∑ a : α, mm a * Real.log (mm a)) = (1 - t) * (∑ a : α, m₁ a * Real.log (mm a)) + t * (∑ a : α, m₂ a * Real.log (mm a)) := by simp_rw [Finset.mul_sum, ← Finset.sum_add_distrib] refine Finset.sum_congr rfl fun a _ => by rw [hmm_eq a]; ring unfold shannonH simp_rw [Fintype.sum_prod_type] rw [h1, h2] at hnonneg linarith end InfoTheory /-! ## Section 2: Pairwise MRF, Local Marginal Polytope `L°(G)` & Bethe Free Energy -/ section BetheCore variable {V X : Type*} /-- Positive pairwise MRF on `G`. -/ structure PairwiseMRF (G : SimpleGraph V) (X : Type*) where ψNode : V → X → ℝ ψEdge : V → V → X → X → ℝ ψNode_pos : ∀ i a, 0 < ψNode i a ψEdge_pos : ∀ i j a b, 0 < ψEdge i j a b ψEdge_symm : ∀ i j a b, ψEdge j i b a = ψEdge i j a b /-- Interior of the Local Marginal Polytope `L°(G)`: strictly positive, normalized, symmetric, marginally consistent node and edge pseudomarginals. -/ structure LocalBelief (G : SimpleGraph V) (X : Type*) [Fintype X] where bNode : V → X → ℝ bEdge : V → V → X → X → ℝ bNode_pos : ∀ i a, 0 < bNode i a bEdge_pos : ∀ i j a b, 0 < bEdge i j a b bNode_sum : ∀ i, ∑ a : X, bNode i a = 1 bEdge_symm : ∀ i j a b, bEdge j i b a = bEdge i j a b bEdge_marg : ∀ i j, G.Adj i j → ∀ a, ∑ c : X, bEdge i j a c = bNode i a lemma LocalBelief.bEdge_marg_right {G : SimpleGraph V} [Fintype X] (b : LocalBelief G X) {i j : V} (hij : G.Adj i j) (c : X) : ∑ a : X, b.bEdge i j a c = b.bNode j c := by have h := b.bEdge_marg j i hij.symm c simpa [b.bEdge_symm] using h lemma LocalBelief.bEdge_sum {G : SimpleGraph V} [Fintype X] (b : LocalBelief G X) {i j : V} (hij : G.Adj i j) : ∑ a : X, ∑ c : X, b.bEdge i j a c = 1 := by simp_rw [b.bEdge_marg i j hij] exact b.bNode_sum i /-- Convex combination of two interior local beliefs `b₁, b₂ ∈ L°(G)`. -/ noncomputable def LocalBelief.convexComb {G : SimpleGraph V} [Fintype X] (b₁ b₂ : LocalBelief G X) {t : ℝ} (ht0 : 0 ≤ t) (ht1 : t ≤ 1) : LocalBelief G X where bNode i a := (1 - t) * b₁.bNode i a + t * b₂.bNode i a bEdge i j a c := (1 - t) * b₁.bEdge i j a c + t * b₂.bEdge i j a c bNode_pos i a := by rcases eq_or_lt_of_le ht0 with rfl | ht0' · simpa using b₁.bNode_pos i a · exact add_pos_of_nonneg_of_pos (mul_nonneg (sub_nonneg.mpr ht1) (le_of_lt (b₁.bNode_pos i a))) (mul_pos ht0' (b₂.bNode_pos i a)) bEdge_pos i j a c := by rcases eq_or_lt_of_le ht0 with rfl | ht0' · simpa using b₁.bEdge_pos i j a c · exact add_pos_of_nonneg_of_pos (mul_nonneg (sub_nonneg.mpr ht1) (le_of_lt (b₁.bEdge_pos i j a c))) (mul_pos ht0' (b₂.bEdge_pos i j a c)) bNode_sum i := by rw [Finset.sum_add_distrib, ← Finset.mul_sum, ← Finset.mul_sum, b₁.bNode_sum, b₂.bNode_sum]; ring bEdge_symm i j a c := by rw [b₁.bEdge_symm, b₂.bEdge_symm] bEdge_marg i j hij a := by rw [Finset.sum_add_distrib, ← Finset.mul_sum, ← Finset.mul_sum, b₁.bEdge_marg i j hij, b₂.bEdge_marg i j hij] variable {G : SimpleGraph V} [Fintype V] [DecidableEq V] [DecidableRel G.Adj] variable [Fintype X] [DecidableEq X] [Nonempty X] /-- Orientation-free edge potential on `Sym2 V`. -/ def PairwiseMRF.edgeWeight (M : PairwiseMRF G X) (x : V → X) (e : Sym2 V) : ℝ := Sym2.lift ⟨fun i j => M.ψEdge i j (x i) (x j), fun i j => M.ψEdge_symm j i (x j) (x i)⟩ e omit [Fintype V] [DecidableEq V] [DecidableRel G.Adj] [Fintype X] [DecidableEq X] [Nonempty X] in lemma PairwiseMRF.edgeWeight_pos (M : PairwiseMRF G X) (x : V → X) (e : Sym2 V) : 0 < M.edgeWeight x e := by induction e using Sym2.ind with | _ i j => exact M.ψEdge_pos i j (x i) (x j) /-- Unnormalized Gibbs weight, partition function `Z`, and Gibbs distribution `p`. -/ noncomputable def PairwiseMRF.unnormWeight (M : PairwiseMRF G X) (x : V → X) : ℝ := (∏ i : V, M.ψNode i (x i)) * (∏ e ∈ G.edgeFinset, M.edgeWeight x e) omit [DecidableEq V] [Fintype X] [DecidableEq X] [Nonempty X] in lemma PairwiseMRF.unnormWeight_pos (M : PairwiseMRF G X) (x : V → X) : 0 < M.unnormWeight x := mul_pos (Finset.prod_pos fun i _ => M.ψNode_pos i (x i)) (Finset.prod_pos fun e _ => M.edgeWeight_pos x e) noncomputable def PairwiseMRF.Z (M : PairwiseMRF G X) : ℝ := ∑ x : V → X, M.unnormWeight x omit [DecidableEq X] in lemma PairwiseMRF.Z_pos (M : PairwiseMRF G X) : 0 < M.Z := Finset.sum_pos (fun x _ => M.unnormWeight_pos x) Finset.univ_nonempty noncomputable def PairwiseMRF.gibbs (M : PairwiseMRF G X) (x : V → X) : ℝ := M.unnormWeight x / M.Z omit [DecidableEq X] in lemma PairwiseMRF.gibbs_pos (M : PairwiseMRF G X) (x : V → X) : 0 < M.gibbs x := div_pos (M.unnormWeight_pos x) M.Z_pos omit [DecidableEq X] in lemma PairwiseMRF.sum_gibbs (M : PairwiseMRF G X) : ∑ x : V → X, M.gibbs x = 1 := by unfold PairwiseMRF.gibbs rw [← Finset.sum_div] exact div_self (ne_of_gt M.Z_pos) /-- Exact Gibbs marginals packaged as an interior `LocalBelief G X`. -/ noncomputable def PairwiseMRF.exactBelief (M : PairwiseMRF G X) : LocalBelief G X where bNode i a := ∑ x : V → X, if x i = a then M.gibbs x else 0 bEdge i j a c := if i = j then (if a = c then ∑ x : V → X, if x i = a then M.gibbs x else 0 else 1) else ∑ x : V → X, if x i = a ∧ x j = c then M.gibbs x else 0 bNode_pos i a := by let x0 : V → X := fun _ => a exact lt_of_lt_of_le (by simp [x0, M.gibbs_pos x0]) (Finset.single_le_sum (fun x _ => by split_ifs; exact le_of_lt (M.gibbs_pos x); rfl) (Finset.mem_univ x0)) bEdge_pos i j a c := by split_ifs with hij hac · let x0 : V → X := fun _ => a exact lt_of_lt_of_le (by simp [x0, M.gibbs_pos x0]) (Finset.single_le_sum (fun x _ => by split_ifs; exact le_of_lt (M.gibbs_pos x); rfl) (Finset.mem_univ x0)) · exact one_pos · let x0 : V → X := fun v => if v = i then a else c have hx0 : x0 i = a ∧ x0 j = c := ⟨by simp [x0], by simp [x0, Ne.symm hij]⟩ exact lt_of_lt_of_le (by simp [hx0, M.gibbs_pos x0]) (Finset.single_le_sum (fun x _ => by split_ifs; exact le_of_lt (M.gibbs_pos x); rfl) (Finset.mem_univ x0)) bNode_sum i := by rw [Finset.sum_comm] calc ∑ x : V → X, ∑ a : X, (if x i = a then M.gibbs x else 0) = ∑ x : V → X, M.gibbs x := Finset.sum_congr rfl fun x _ => by simp _ = 1 := M.sum_gibbs bEdge_symm i j a c := by by_cases hij : i = j · subst hij by_cases hac : a = c · subst hac; simp · simp [hac, Ne.symm hac] · simp only [hij, Ne.symm hij, ↓reduceIte] refine Finset.sum_congr rfl fun x _ => by simp [and_comm] bEdge_marg i j hij a := by have hne : i ≠ j := hij.ne simp only [hne, ↓reduceIte] rw [Finset.sum_comm] refine Finset.sum_congr rfl fun x _ => ?_ by_cases hxi : x i = a · simp [hxi] · simp [hxi] /-- Pairwise Shannon entropy `H(b_{ij})`. -/ noncomputable def pairH (b : X → X → ℝ) : ℝ := shannonH (fun p : X × X => b p.1 p.2) /-- Pairwise mutual information `I(b_{ij}) = H(b_i) + H(b_j) - H(b_{ij})`. -/ noncomputable def pairMI (bNode : V → X → ℝ) (bEdge : V → V → X → X → ℝ) (i j : V) : ℝ := shannonH (bNode i) + shannonH (bNode j) - pairH (bEdge i j) /-- Half-sum over directed neighbors equals sum over `G.edgeFinset` for symmetric `F`. -/ lemma half_sum_neighbors_eq_sum_edgeFinset (F : V → V → ℝ) (hF : ∀ i j, F j i = F i j) : (1 / 2 : ℝ) * (∑ i : V, ∑ j ∈ G.neighborFinset i, F i j) = ∑ e ∈ G.edgeFinset, Sym2.lift ⟨F, fun i j => hF j i⟩ e := by have hgen : ∀ (s : Finset (Sym2 V)), (∀ e ∈ s, ¬ e.IsDiag) → (∑ i : V, ∑ j ∈ Finset.univ.filter (fun j => s(i, j) ∈ s), F i j) = 2 * ∑ e ∈ s, Sym2.lift ⟨F, fun i j => hF j i⟩ e := by intro s induction s using Finset.induction_on with | empty => simp | @insert e s he ih => intro hnd have he_nd : ¬ e.IsDiag := hnd e (Finset.mem_insert_self e s) have hs_nd : ∀ e' ∈ s, ¬ e'.IsDiag := fun e' he' => hnd e' (Finset.mem_insert_of_mem he') rw [Finset.sum_insert he, mul_add, ← ih hs_nd] induction e using Sym2.ind with | _ u v => have huv : u ≠ v := by simpa [Sym2.mk_isDiag_iff] using he_nd simp only [Sym2.lift_mk] have hstep : ∀ i : V, (∑ j ∈ Finset.univ.filter (fun j => s(i, j) ∈ insert s(u, v) s), F i j) = (if i = u then F u v else if i = v then F v u else 0) + (∑ j ∈ Finset.univ.filter (fun j => s(i, j) ∈ s), F i j) := by intro i by_cases hiu : i = u · subst hiu have hset : Finset.univ.filter (fun j => s(i, j) ∈ insert s(i, v) s) = insert v (Finset.univ.filter (fun j => s(i, j) ∈ s)) := by ext j; simp only [Finset.mem_filter, Finset.mem_univ, true_and, Finset.mem_insert] constructor · rintro (heq | hm) · left have : j ∈ s(i, v) := heq ▸ Sym2.mem_mk_right i j rcases Sym2.mem_iff.mp this with rfl | rfl · exfalso have hvm : v ∈ s(j, j) := heq ▸ Sym2.mem_mk_right j v rcases Sym2.mem_iff.mp hvm with rfl | rfl <;> exact huv rfl · rfl · exact Or.inr hm · rintro (rfl | hm); exact Or.inl rfl; exact Or.inr hm rw [hset, Finset.sum_insert (by simp [he]), if_pos rfl] · by_cases hiv : i = v · subst hiv have hset : Finset.univ.filter (fun j => s(i, j) ∈ insert s(u, i) s) = insert u (Finset.univ.filter (fun j => s(i, j) ∈ s)) := by ext j; simp only [Finset.mem_filter, Finset.mem_univ, true_and, Finset.mem_insert] constructor · rintro (heq | hm) · left have : j ∈ s(u, i) := heq ▸ Sym2.mem_mk_right i j rcases Sym2.mem_iff.mp this with rfl | rfl · rfl · exfalso have hvm : u ∈ s(j, j) := heq ▸ Sym2.mem_mk_left u j rcases Sym2.mem_iff.mp hvm with rfl | rfl <;> exact huv rfl · exact Or.inr hm · rintro (rfl | hm); exact Or.inl Sym2.eq_swap; exact Or.inr hm rw [hset, Finset.sum_insert (by simp [Sym2.eq_swap, he]), if_neg hiu, if_pos rfl] · have hset : Finset.univ.filter (fun j => s(i, j) ∈ insert s(u, v) s) = Finset.univ.filter (fun j => s(i, j) ∈ s) := by ext j; simp only [Finset.mem_filter, Finset.mem_univ, true_and, Finset.mem_insert] constructor · rintro (heq | hm) · exfalso have : i ∈ s(u, v) := heq ▸ Sym2.mem_mk_left i j rcases Sym2.mem_iff.mp this with rfl | rfl · exact hiu rfl · exact hiv rfl · exact hm · exact Or.inr rw [hset, if_neg hiu, if_neg hiv, zero_add] simp_rw [hstep] rw [Finset.sum_add_distrib] congr 1 rw [← Finset.add_sum_erase _ _ (Finset.mem_univ u), ← Finset.add_sum_erase _ _ (Finset.mem_erase.mpr ⟨huv.symm, Finset.mem_univ v⟩)] have hrest : ∑ i ∈ (Finset.univ.erase u).erase v, (if i = u then F u v else if i = v then F v u else 0) = 0 := by refine Finset.sum_eq_zero fun i hi => ?_ have hv := Finset.ne_of_mem_erase hi have hu := Finset.ne_of_mem_erase (Finset.mem_of_mem_erase hi) simp [hu, hv] rw [hrest, if_pos rfl, if_neg huv.symm, if_pos rfl, hF u v]; ring have h2 := hgen G.edgeFinset (fun e he => G.not_isDiag_of_mem_edgeSet (G.mem_edgeFinset.mp he)) have hfilt : ∀ i : V, Finset.univ.filter (fun j => s(i, j) ∈ G.edgeFinset) = G.neighborFinset i := by intro i; ext j; simp [SimpleGraph.mem_neighborFinset, G.mem_edgeFinset] simp_rw [hfilt] at h2 linarith /-- Bethe average energy `U_Bethe(b)`. -/ noncomputable def betheEnergy (M : PairwiseMRF G X) (b : LocalBelief G X) : ℝ := -(∑ i : V, ∑ a : X, b.bNode i a * Real.log (M.ψNode i a)) - (1 / 2 : ℝ) * ∑ i : V, ∑ j ∈ G.neighborFinset i, ∑ a : X, ∑ c : X, b.bEdge i j a c * Real.log (M.ψEdge i j a c) /-- Bethe entropy `H_Bethe(b) = ∑_e H(b_e) - ∑_i (d_i - 1) H(b_i)`. -/ noncomputable def betheEntropy (G : SimpleGraph V) [DecidableRel G.Adj] (bNode : V → X → ℝ) (bEdge : V → V → X → X → ℝ) : ℝ := (1 / 2 : ℝ) * (∑ i : V, ∑ j ∈ G.neighborFinset i, pairH (bEdge i j)) - ∑ i : V, ((G.degree i : ℝ) - 1) * shannonH (bNode i) /-- Bethe Free Energy `F_Bethe(b) = U_Bethe(b) - H_Bethe(b)`. -/ noncomputable def betheFreeEnergy (M : PairwiseMRF G X) (b : LocalBelief G X) : ℝ := betheEnergy M b - betheEntropy G b.bNode b.bEdge omit [DecidableEq V] [DecidableEq X] [Nonempty X] in /-- Exact mutual-information form of Bethe entropy: `H_Bethe(b) = ∑_i H(b_i) - ∑_{e={i,j}} I(b_{ij})`. -/ theorem betheEntropy_eq_node_sub_mutualInfo (b : LocalBelief G X) : betheEntropy G b.bNode b.bEdge = (∑ i : V, shannonH (b.bNode i)) - (1 / 2 : ℝ) * ∑ i : V, ∑ j ∈ G.neighborFinset i, pairMI b.bNode b.bEdge i j := by unfold betheEntropy pairMI have hsum_deg : ∑ i : V, ∑ j ∈ G.neighborFinset i, (shannonH (b.bNode i) + shannonH (b.bNode j)) = 2 * ∑ i : V, (G.degree i : ℝ) * shannonH (b.bNode i) := by have h1 : ∑ i : V, ∑ j ∈ G.neighborFinset i, shannonH (b.bNode i) = ∑ i : V, (G.degree i : ℝ) * shannonH (b.bNode i) := by refine Finset.sum_congr rfl fun i _ => ?_ rw [Finset.sum_const, nsmul_eq_mul, G.card_neighborFinset_eq_degree] have h2 : ∑ i : V, ∑ j ∈ G.neighborFinset i, shannonH (b.bNode j) = ∑ i : V, (G.degree i : ℝ) * shannonH (b.bNode i) := by have hswap : (∑ i : V, ∑ j ∈ G.neighborFinset i, shannonH (b.bNode j)) = (∑ i : V, ∑ j : V, if G.Adj i j then shannonH (b.bNode j) else 0) := Finset.sum_congr rfl fun i _ => by rw [← Finset.sum_filter] congr 1; ext j; simp [SimpleGraph.mem_neighborFinset] rw [hswap, Finset.sum_comm] refine Finset.sum_congr rfl fun j _ => ?_ have hfilt : (∑ i : V, if G.Adj i j then shannonH (b.bNode j) else 0) = ∑ _i ∈ G.neighborFinset j, shannonH (b.bNode j) := by rw [← Finset.sum_filter] congr 1; ext i; simp [SimpleGraph.mem_neighborFinset, SimpleGraph.adj_comm] rw [hfilt, Finset.sum_const, nsmul_eq_mul, G.card_neighborFinset_eq_degree] simp_rw [Finset.sum_add_distrib] linarith have hsplit : ∑ i : V, ∑ j ∈ G.neighborFinset i, (shannonH (b.bNode i) + shannonH (b.bNode j) - pairH (b.bEdge i j)) = (∑ i : V, ∑ j ∈ G.neighborFinset i, (shannonH (b.bNode i) + shannonH (b.bNode j))) - (∑ i : V, ∑ j ∈ G.neighborFinset i, pairH (b.bEdge i j)) := by simp_rw [Finset.sum_sub_distrib] have hdeg_sub : ∑ i : V, ((G.degree i : ℝ) - 1) * shannonH (b.bNode i) = (∑ i : V, (G.degree i : ℝ) * shannonH (b.bNode i)) - ∑ i : V, shannonH (b.bNode i) := by rw [← Finset.sum_sub_distrib] refine Finset.sum_congr rfl fun i _ => by ring rw [hsplit, hsum_deg, hdeg_sub] ring end BetheCore /-! ## Section 3: Exact Tree Bethe–Gibbs Identity & Strict Convexity on Trees -/ section TreeBetheGibbs variable {V X : Type*} {G : SimpleGraph V} [Fintype V] [DecidableEq V] [DecidableRel G.Adj] variable [Fintype X] [DecidableEq X] [Nonempty X] /-- Helper: tree-factorized joint distribution induced by `b : LocalBelief G X` on a tree `G`: `q_b(x) = (∏_{i ∈ V} b_i(x_i)) · (∏_{e = {i,j} ∈ E} b_{ij}(x_i,x_j) / (b_i(x_i) b_j(x_j)))`. -/ noncomputable def treeJoint (b : LocalBelief G X) (x : V → X) : ℝ := (∏ i : V, b.bNode i (x i)) * (∏ e ∈ G.edgeFinset, Sym2.lift ⟨fun i j => b.bEdge i j (x i) (x j) / (b.bNode i (x i) * b.bNode j (x j)), fun i j => by dsimp only; rw [b.bEdge_symm, mul_comm]⟩ e) omit [DecidableEq V] [DecidableEq X] [Nonempty X] in lemma treeJoint_pos (b : LocalBelief G X) (x : V → X) : 0 < treeJoint b x := by unfold treeJoint refine mul_pos (Finset.prod_pos fun i _ => b.bNode_pos i (x i)) (Finset.prod_pos fun e _ => ?_) induction e using Sym2.ind with | _ i j => exact div_pos (b.bEdge_pos i j (x i) (x j)) (mul_pos (b.bNode_pos i (x i)) (b.bNode_pos j (x j))) omit [DecidableEq X] [Nonempty X] in /-- Exact log formula for `treeJoint b x`. -/ lemma log_treeJoint (b : LocalBelief G X) (x : V → X) : Real.log (treeJoint b x) = (1 / 2 : ℝ) * (∑ i : V, ∑ j ∈ G.neighborFinset i, Real.log (b.bEdge i j (x i) (x j))) - ∑ i : V, ((G.degree i : ℝ) - 1) * Real.log (b.bNode i (x i)) := by unfold treeJoint have h1_pos : 0 < ∏ i : V, b.bNode i (x i) := Finset.prod_pos fun i _ => b.bNode_pos i (x i) have h2_pos : ∀ e ∈ G.edgeFinset, 0 < Sym2.lift ⟨fun i j => b.bEdge i j (x i) (x j) / (b.bNode i (x i) * b.bNode j (x j)), fun i j => by dsimp only; rw [b.bEdge_symm, mul_comm]⟩ e := fun e _ => by induction e using Sym2.ind with | _ i j => exact div_pos (b.bEdge_pos i j (x i) (x j)) (mul_pos (b.bNode_pos i (x i)) (b.bNode_pos j (x j))) rw [Real.log_mul (ne_of_gt h1_pos) (ne_of_gt (Finset.prod_pos h2_pos)), Real.log_prod (fun i _ => ne_of_gt (b.bNode_pos i (x i))), Real.log_prod (fun e he => ne_of_gt (h2_pos e he))] have hedge_log : (∑ e ∈ G.edgeFinset, Real.log (Sym2.lift ⟨fun i j => b.bEdge i j (x i) (x j) / (b.bNode i (x i) * b.bNode j (x j)), fun i j => by dsimp only; rw [b.bEdge_symm, mul_comm]⟩ e)) = (1 / 2 : ℝ) * (∑ i : V, ∑ j ∈ G.neighborFinset i, (Real.log (b.bEdge i j (x i) (x j)) - Real.log (b.bNode i (x i)) - Real.log (b.bNode j (x j)))) := by rw [half_sum_neighbors_eq_sum_edgeFinset _ (fun i j => by rw [b.bEdge_symm]; ring)] refine Finset.sum_congr rfl fun e _ => ?_ induction e using Sym2.ind with | _ i j => simp only [Sym2.lift_mk] rw [Real.log_div (ne_of_gt (b.bEdge_pos i j (x i) (x j))) (ne_of_gt (mul_pos (b.bNode_pos i (x i)) (b.bNode_pos j (x j)))), Real.log_mul (ne_of_gt (b.bNode_pos i (x i))) (ne_of_gt (b.bNode_pos j (x j)))] ring rw [hedge_log] have hsum_node : (∑ i : V, ∑ j ∈ G.neighborFinset i, (Real.log (b.bNode i (x i)) + Real.log (b.bNode j (x j)))) = 2 * ∑ i : V, (G.degree i : ℝ) * Real.log (b.bNode i (x i)) := by have h1 : ∑ i : V, ∑ j ∈ G.neighborFinset i, Real.log (b.bNode i (x i)) = ∑ i : V, (G.degree i : ℝ) * Real.log (b.bNode i (x i)) := by refine Finset.sum_congr rfl fun i _ => ?_ rw [Finset.sum_const, nsmul_eq_mul, G.card_neighborFinset_eq_degree] have h2 : ∑ i : V, ∑ j ∈ G.neighborFinset i, Real.log (b.bNode j (x j)) = ∑ i : V, (G.degree i : ℝ) * Real.log (b.bNode i (x i)) := by have hswap : (∑ i : V, ∑ j ∈ G.neighborFinset i, Real.log (b.bNode j (x j))) = ∑ i : V, ∑ j : V, if G.Adj i j then Real.log (b.bNode j (x j)) else 0 := Finset.sum_congr rfl fun i _ => by rw [← Finset.sum_filter]; congr 1; ext j; simp [SimpleGraph.mem_neighborFinset] rw [hswap, Finset.sum_comm] refine Finset.sum_congr rfl fun j _ => ?_ have hfilt : (∑ i : V, if G.Adj i j then Real.log (b.bNode j (x j)) else 0) = ∑ _i ∈ G.neighborFinset j, Real.log (b.bNode j (x j)) := by rw [← Finset.sum_filter]; congr 1; ext i; simp [SimpleGraph.mem_neighborFinset, SimpleGraph.adj_comm] rw [hfilt, Finset.sum_const, nsmul_eq_mul, G.card_neighborFinset_eq_degree] simp_rw [Finset.sum_add_distrib] linarith have hsplit : (∑ i : V, ∑ j ∈ G.neighborFinset i, (Real.log (b.bEdge i j (x i) (x j)) - Real.log (b.bNode i (x i)) - Real.log (b.bNode j (x j)))) = (∑ i : V, ∑ j ∈ G.neighborFinset i, Real.log (b.bEdge i j (x i) (x j))) - (∑ i : V, ∑ j ∈ G.neighborFinset i, (Real.log (b.bNode i (x i)) + Real.log (b.bNode j (x j)))) := by simp_rw [← Finset.sum_sub_distrib] refine Finset.sum_congr rfl fun i _ => Finset.sum_congr rfl fun j _ => by ring have hdeg_sub : ∑ i : V, ((G.degree i : ℝ) - 1) * Real.log (b.bNode i (x i)) = (∑ i : V, (G.degree i : ℝ) * Real.log (b.bNode i (x i))) - ∑ i : V, Real.log (b.bNode i (x i)) := by rw [← Finset.sum_sub_distrib] refine Finset.sum_congr rfl fun i _ => by ring rw [hsplit, hsum_node, hdeg_sub] ring /-- Induction engine on finite trees: every finite tree with `≥ 2` vertices has a leaf (degree 1), and deleting a leaf `v` (adjacent to `u`) marginalizes out `x_v` cleanly because `∑_{x_v} b_v(x_v) · (b_{uv}(x_u, x_v) / (b_u(x_u) b_v(x_v))) = ∑_{x_v} b_{uv}(x_u, x_v) / b_u(x_u) = 1`! -/ lemma tree_exists_leaf (hT : G.IsTree) (hcard : 2 ≤ Fintype.card V) : ∃ v : V, G.degree v = 1 := by have hdeg_sum : ∑ v : V, G.degree v = 2 * G.edgeFinset.card := G.sum_degrees_eq_twice_card_edges have hcard_e : G.edgeFinset.card + 1 = Fintype.card V := hT.card_edgeFinset have hdeg_pos : ∀ v : V, 1 ≤ G.degree v := by intro v -- Connected graph with ≥ 2 vertices has no isolated vertices have hex : ∃ w : V, w ≠ v := by by_contra hall push Not at hall have hle1 : Fintype.card V ≤ 1 := Fintype.card_le_one_iff.mpr fun a b => by rw [hall a, hall b] omega rcases hex with ⟨w, hwv⟩ obtain ⟨p⟩ := hT.connected v w cases p with | nil => exact absurd rfl hwv | @cons _ u _ hvu _ => rw [← G.card_neighborFinset_eq_degree] exact Finset.card_pos.mpr ⟨u, (SimpleGraph.mem_neighborFinset G v u).mpr hvu⟩ by_contra hno push Not at hno have hge2 : ∀ v : V, 2 ≤ G.degree v := fun v => by have h1 := hdeg_pos v have h2 := hno v omega have hsum_ge : 2 * Fintype.card V ≤ ∑ v : V, G.degree v := by calc 2 * Fintype.card V = ∑ _v : V, 2 := by simp [mul_comm] _ ≤ ∑ v : V, G.degree v := Finset.sum_le_sum fun v _ => hge2 v omega omit [Nonempty X] in /-- **Exact Marginal Consistency of `treeJoint` on Arbitrary Finite Trees**: For ANY finite tree `T` and ANY `b : LocalBelief T X`: 1. `∑_x q_b(x) = 1`; 2. `∑_{x : x_i = a} q_b(x) = b_i(a)` for every vertex `i`; 3. `∑_{x : x_i = a ∧ x_j = c} q_b(x) = b_{ij}(a, c)` for every edge `{i, j} ∈ E(T)`. -/ theorem treeJoint_marginals_exact : ∀ (n : ℕ) {W : Type*} [Fintype W] [DecidableEq W] (T : SimpleGraph W) [DecidableRel T.Adj] (_hT : T.IsTree) (_hn : Fintype.card W = n) (b : LocalBelief T X), (∑ x : W → X, treeJoint b x = 1) ∧ (∀ i a, ∑ x : W → X, (if x i = a then treeJoint b x else 0) = b.bNode i a) ∧ (∀ i j, T.Adj i j → ∀ a c, ∑ x : W → X, (if x i = a ∧ x j = c then treeJoint b x else 0) = b.bEdge i j a c) := by intro n induction n with | zero => intro W _ _ T _ hT hn exfalso have hne : Nonempty W := hT.connected.nonempty have hpos : 0 < Fintype.card W := Fintype.card_pos omega | succ m ih => intro W _ _ T _ hT hn b by_cases hm : m = 0 · -- 1-vertex tree: no edges, unique vertex! subst hm have hsub : Subsingleton W := Fintype.card_le_one_iff_subsingleton.mp (by omega) have hemp : T.edgeFinset = ∅ := by rw [Finset.eq_empty_iff_forall_notMem] intro e he induction e using Sym2.ind with | _ u v => exact T.loopless.irrefl u (Subsingleton.elim u v ▸ T.mem_edgeFinset.mp he) have hq : ∀ x : W → X, ∀ i : W, treeJoint b x = b.bNode i (x i) := fun x i => by unfold treeJoint rw [hemp, Finset.prod_empty, mul_one, Fintype.prod_subsingleton _ i] refine ⟨?_, ?_, ?_⟩ · obtain ⟨i0⟩ := hT.connected.nonempty let e1 : (W → X) ≃ X := { toFun := fun x => x i0 invFun := fun a _ => a left_inv := fun x => funext fun w => by rw [Subsingleton.elim w i0] right_inv := fun _ => rfl } rw [Fintype.sum_equiv e1 _ (fun a => b.bNode i0 a) (fun x => hq x i0)] exact b.bNode_sum i0 · intro i a let e1 : (W → X) ≃ X := { toFun := fun x => x i invFun := fun c _ => c left_inv := fun x => funext fun w => by rw [Subsingleton.elim w i] right_inv := fun _ => rfl } rw [Fintype.sum_equiv e1 _ (fun c => if c = a then b.bNode i c else 0) (fun x => by simp [e1, hq x i])] simp · intro i j hij exact absurd (Subsingleton.elim i j ▸ hij) (T.loopless.irrefl i) · -- `n = m + 1 ≥ 2`: peel off a leaf `v` adjacent to unique neighbor `u`! have hcard2 : 2 ≤ Fintype.card W := by omega obtain ⟨v, hv_deg⟩ := tree_exists_leaf hT hcard2 rw [← T.card_neighborFinset_eq_degree] at hv_deg obtain ⟨u, hu_eq⟩ := Finset.card_eq_one.mp hv_deg have huv : T.Adj v u := (SimpleGraph.mem_neighborFinset T v u).mp (hu_eq ▸ Finset.mem_singleton_self u) -- Induced tree `T'` on `W' = {w : W // w ≠ v}` let W' := {w : W // w ≠ v} let T' : SimpleGraph W' := T.induce {w : W | w ≠ v} have : Nonempty W' := ⟨⟨u, huv.ne.symm⟩⟩ have hcard' : Fintype.card W' = m := by have h1 : Fintype.card {w : W // ¬ w = v} = Fintype.card W - Fintype.card {w : W // w = v} := Fintype.card_subtype_compl (fun w : W => w = v) have h2 : Fintype.card {w : W // w = v} = 1 := Fintype.card_unique change Fintype.card {w : W // ¬ w = v} = m omega -- Prove `T'` is a tree: connected and acyclic! have hT'_tree : T'.IsTree := by have hconn : T'.Connected := by refine ⟨fun a b => ?_⟩ obtain ⟨p, hp, _⟩ := hT.existsUnique_path a.1 b.1 -- `v` cannot be an internal vertex of path `p` since `deg(v) = 1` and `a.1 ≠ v, b.1 ≠ v`! have hv_not_supp : v ∉ p.support := by intro hv_mem -- Split `p` at `v`: both prefix and suffix have length ≥ 1, so `v` has two edges in `p`, -- forcing its unique neighbor `u` to appear twice in `p.support`, contradicting `IsPath`! have hcons_ne : ∀ {x y : W} (q : T.Walk x y), x ≠ y → ∃ (w : W) (h : T.Adj x w) (q' : T.Walk w y), q = SimpleGraph.Walk.cons h q' := by intro x y q hne cases q with | nil => exact absurd rfl hne | cons h q' => exact ⟨_, h, q', rfl⟩ have hspec := SimpleGraph.Walk.take_spec p hv_mem obtain ⟨w₂, hvw₂, p2', h2⟩ := hcons_ne (p.dropUntil v hv_mem) b.2.symm have hw2_eq_u : w₂ = u := by have hm : w₂ ∈ T.neighborFinset v := (SimpleGraph.mem_neighborFinset T v w₂).mpr hvw₂ rw [hu_eq, Finset.mem_singleton] at hm; exact hm obtain ⟨w₁, hvw₁, p1', h1⟩ := hcons_ne (p.takeUntil v hv_mem).reverse a.2.symm have hw1_eq_u : w₁ = u := by have hm : w₁ ∈ T.neighborFinset v := (SimpleGraph.mem_neighborFinset T v w₁).mpr hvw₁ rw [hu_eq, Finset.mem_singleton] at hm; exact hm have hu_in_1 : u ∈ (p.takeUntil v hv_mem).support := by have hm : w₁ ∈ (p.takeUntil v hv_mem).reverse.support := by rw [h1]; exact List.mem_cons_of_mem v (SimpleGraph.Walk.start_mem_support p1') rw [SimpleGraph.Walk.support_reverse, List.mem_reverse] at hm exact hw1_eq_u ▸ hm have hu_in_2 : u ∈ (SimpleGraph.Walk.cons hvw₂ p2').support.tail := by rw [SimpleGraph.Walk.support_cons, List.tail_cons] exact hw2_eq_u ▸ SimpleGraph.Walk.start_mem_support p2' have hnd := hp.support_nodup rw [← hspec, SimpleGraph.Walk.support_append, h2] at hnd exact (List.nodup_append.mp hnd).2.2 u hu_in_1 u hu_in_2 rfl -- Lift `p` to `T'`! have hlift : ∀ {x y : W} (q : T.Walk x y), (∀ z ∈ q.support, z ≠ v) → ∀ (hx : x ≠ v) (hy : y ≠ v), T'.Reachable ⟨x, hx⟩ ⟨y, hy⟩ := by intro x y q induction q with | nil => intro _ hx hy; exact SimpleGraph.Reachable.refl _ | @cons x z y hxz q' ihq => intro hsupp hx hy have hz : z ≠ v := hsupp z (by simp) have hadj' : T'.Adj ⟨x, hx⟩ ⟨z, hz⟩ := hxz exact hadj'.reachable.trans (ihq (fun w hw => hsupp w (by simp [hw])) hz hy) exact hlift p (fun z hz hzv => hv_not_supp (hzv ▸ hz)) a.2 b.2 have hacyc : T'.IsAcyclic := by intro a c hc let c_up : T.Walk a.1 a.1 := c.map (SimpleGraph.Embedding.induce {w : W | w ≠ v}).toHom have hc_up : c_up.IsCycle := hc.map (SimpleGraph.Embedding.induce (G := T) {w : W | w ≠ v}).injective exact hT.isAcyclic c_up hc_up exact ⟨hconn, hacyc⟩ -- Restrict `b` to `T'` let b' : LocalBelief T' X := { bNode := fun w => b.bNode w.1 bEdge := fun w₁ w₂ => b.bEdge w₁.1 w₂.1 bNode_pos := fun w a => b.bNode_pos w.1 a bEdge_pos := fun w₁ w₂ a c => b.bEdge_pos w₁.1 w₂.1 a c bNode_sum := fun w => b.bNode_sum w.1 bEdge_symm := fun w₁ w₂ a c => b.bEdge_symm w₁.1 w₂.1 a c bEdge_marg := fun w₁ w₂ h12 a => b.bEdge_marg w₁.1 w₂.1 h12 a } obtain ⟨ih_sum, ih_node, ih_edge⟩ := ih T' hT'_tree hcard' b' -- Key factorization: `treeJoint b x = treeJoint b' (x|_W') * (b.bEdge u v (x u) (x v) / b.bNode u (x u))`! have hfactor : ∀ x : W → X, treeJoint b x = treeJoint b' (fun w : W' => x w.1) * (b.bEdge u v (x u) (x v) / b.bNode u (x u)) := by intro x unfold treeJoint have hnode : ∏ i : W, b.bNode i (x i) = b.bNode v (x v) * ∏ w : W', b'.bNode w (x w.1) := by rw [← Finset.mul_prod_erase Finset.univ (fun i => b.bNode i (x i)) (Finset.mem_univ v)] congr 1 refine (Finset.prod_bij (fun (w : W') _ => w.1) ?_ ?_ ?_ ?_).symm · intro w _; exact Finset.mem_erase.mpr ⟨w.2, Finset.mem_univ w.1⟩ · intro w₁ _ w₂ _ h; exact Subtype.ext h · intro i hi; exact ⟨⟨i, Finset.ne_of_mem_erase hi⟩, Finset.mem_univ _, rfl⟩ · intro w _; rfl have hedge_mem : s(u, v) ∈ T.edgeFinset := T.mem_edgeFinset.mpr huv.symm have hedge : (∏ e ∈ T.edgeFinset, Sym2.lift ⟨fun i j => b.bEdge i j (x i) (x j) / (b.bNode i (x i) * b.bNode j (x j)), fun i j => by dsimp only; rw [b.bEdge_symm, mul_comm]⟩ e) = (b.bEdge u v (x u) (x v) / (b.bNode u (x u) * b.bNode v (x v))) * (∏ e ∈ T'.edgeFinset, Sym2.lift ⟨fun i j => b'.bEdge i j (x i.1) (x j.1) / (b'.bNode i (x i.1) * b'.bNode j (x j.1)), fun i j => by dsimp only; rw [b'.bEdge_symm, mul_comm]⟩ e) := by rw [← Finset.mul_prod_erase T.edgeFinset _ hedge_mem] congr 1 refine (Finset.prod_bij (fun e _ => e.map Subtype.val) ?_ ?_ ?_ ?_).symm · intro e he induction e using Sym2.ind with | _ a₁ a₂ => refine Finset.mem_erase.mpr ⟨?_, T.mem_edgeFinset.mpr (T'.mem_edgeFinset.mp he)⟩ intro heq have hv_in : v ∈ s(a₁.1, a₂.1) := by have hm : v ∈ s(u, v) := Sym2.mem_mk_right u v rw [← heq] at hm; exact hm rcases Sym2.mem_iff.mp hv_in with h | h · exact a₁.2 h.symm · exact a₂.2 h.symm · intro e₁ _ e₂ _ h exact Sym2.map.injective Subtype.val_injective h · intro e he rcases Finset.mem_erase.mp he with ⟨hne_uv, he_T⟩ induction e using Sym2.ind with | _ i j => have hij : T.Adj i j := T.mem_edgeFinset.mp he_T have hi_ne : i ≠ v := by intro hiv have hvj : T.Adj v j := hiv ▸ hij have hm : j ∈ T.neighborFinset v := (SimpleGraph.mem_neighborFinset T v j).mpr hvj rw [hu_eq, Finset.mem_singleton] at hm exact hne_uv (by rw [hiv, hm]; exact Sym2.eq_swap) have hj_ne : j ≠ v := by intro hjv have hvi : T.Adj v i := hjv ▸ hij.symm have hm : i ∈ T.neighborFinset v := (SimpleGraph.mem_neighborFinset T v i).mpr hvi rw [hu_eq, Finset.mem_singleton] at hm exact hne_uv (by rw [hjv, hm]) exact ⟨s(⟨i, hi_ne⟩, ⟨j, hj_ne⟩), T'.mem_edgeFinset.mpr hij, rfl⟩ · intro e _ induction e using Sym2.ind with | _ a₁ a₂ => rfl rw [hnode, hedge] have hbv : b.bNode v (x v) ≠ 0 := ne_of_gt (b.bNode_pos v (x v)) have hbu : b.bNode u (x u) ≠ 0 := ne_of_gt (b.bNode_pos u (x u)) field_simp [hbv, hbu] -- Equivalence `(W → X) ≃ (W' → X) × X` splitting off `x v`! let eSplit : (W → X) ≃ (W' → X) × X := { toFun := fun x => (fun w => x w.1, x v) invFun := fun p w => if h : w = v then p.2 else p.1 ⟨w, h⟩ left_inv := fun x => funext fun w => by dsimp only; split_ifs with h; exact h ▸ rfl; rfl right_inv := fun ⟨y, xv⟩ => by ext w · simp [w.2] · simp } have hu_ne_v : u ≠ v := huv.ne.symm -- Now derive all 3 properties from `ih` + `hfactor`! have hmarg_v : ∀ (a : X), ∑ xv : X, b.bEdge u v a xv / b.bNode u a = 1 := fun a => by rw [← Finset.sum_div, b.bEdge_marg u v huv.symm a, div_self (ne_of_gt (b.bNode_pos u a))] refine ⟨?_, ?_, ?_⟩ · -- 1. Total sum = 1 rw [Fintype.sum_equiv eSplit _ (fun p => treeJoint b' p.1 * (b.bEdge u v (p.1 ⟨u, hu_ne_v⟩) p.2 / b.bNode u (p.1 ⟨u, hu_ne_v⟩))) (fun x => hfactor x), Fintype.sum_prod_type] calc ∑ y : W' → X, ∑ xv : X, treeJoint b' y * (b.bEdge u v (y ⟨u, hu_ne_v⟩) xv / b.bNode u (y ⟨u, hu_ne_v⟩)) = ∑ y : W' → X, treeJoint b' y * 1 := Finset.sum_congr rfl fun y _ => by rw [← Finset.mul_sum, hmarg_v] _ = 1 := by simp [ih_sum] · -- 2. Node marginals intro i a by_cases hiv : i = v · rw [hiv] rw [Fintype.sum_equiv eSplit _ (fun p => if p.2 = a then treeJoint b' p.1 * (b.bEdge u v (p.1 ⟨u, hu_ne_v⟩) p.2 / b.bNode u (p.1 ⟨u, hu_ne_v⟩)) else 0) (fun x => by simp [eSplit, hfactor x]), Fintype.sum_prod_type] simp only [Finset.sum_ite_eq', Finset.mem_univ, ↓reduceIte] have hgroup : ∑ y : W' → X, treeJoint b' y * (b.bEdge u v (y ⟨u, hu_ne_v⟩) a / b.bNode u (y ⟨u, hu_ne_v⟩)) = ∑ xu : X, (∑ y : W' → X, if y ⟨u, hu_ne_v⟩ = xu then treeJoint b' y else 0) * (b.bEdge u v xu a / b.bNode u xu) := by simp_rw [Finset.sum_mul] rw [Finset.sum_comm] refine Finset.sum_congr rfl fun y _ => ?_ rw [Finset.sum_eq_single (y ⟨u, hu_ne_v⟩)] · simp · intro xu _ hne; simp [hne.symm] · intro h; exact absurd (Finset.mem_univ _) h rw [hgroup] calc ∑ xu : X, (∑ y : W' → X, if y ⟨u, hu_ne_v⟩ = xu then treeJoint b' y else 0) * (b.bEdge u v xu a / b.bNode u xu) = ∑ xu : X, b.bNode u xu * (b.bEdge u v xu a / b.bNode u xu) := Finset.sum_congr rfl fun xu _ => by rw [ih_node ⟨u, hu_ne_v⟩ xu] _ = ∑ xu : X, b.bEdge u v xu a := Finset.sum_congr rfl fun xu _ => mul_div_cancel₀ _ (ne_of_gt (b.bNode_pos u xu)) _ = b.bNode v a := b.bEdge_marg_right huv.symm a · rw [Fintype.sum_equiv eSplit _ (fun p => if p.1 ⟨i, hiv⟩ = a then treeJoint b' p.1 * (b.bEdge u v (p.1 ⟨u, hu_ne_v⟩) p.2 / b.bNode u (p.1 ⟨u, hu_ne_v⟩)) else 0) (fun x => by simp [eSplit, hfactor x]), Fintype.sum_prod_type] calc ∑ y : W' → X, ∑ xv : X, (if y ⟨i, hiv⟩ = a then treeJoint b' y * (b.bEdge u v (y ⟨u, hu_ne_v⟩) xv / b.bNode u (y ⟨u, hu_ne_v⟩)) else 0) = ∑ y : W' → X, if y ⟨i, hiv⟩ = a then treeJoint b' y else 0 := by refine Finset.sum_congr rfl fun y _ => ?_ split_ifs with hy · rw [← Finset.mul_sum, hmarg_v, mul_one] · simp _ = b.bNode i a := ih_node ⟨i, hiv⟩ a · -- 3. Edge marginals intro i j hij a c by_cases hiv : i = v · have hju : j = u := by have hvj : T.Adj v j := hiv ▸ hij have hm : j ∈ T.neighborFinset v := (SimpleGraph.mem_neighborFinset T v j).mpr hvj rw [hu_eq, Finset.mem_singleton] at hm; exact hm rw [hiv, hju] rw [Fintype.sum_equiv eSplit _ (fun p => if p.2 = a ∧ p.1 ⟨u, hu_ne_v⟩ = c then treeJoint b' p.1 * (b.bEdge u v (p.1 ⟨u, hu_ne_v⟩) p.2 / b.bNode u (p.1 ⟨u, hu_ne_v⟩)) else 0) (fun x => by simp [eSplit, hfactor x]), Fintype.sum_prod_type] calc ∑ y : W' → X, ∑ xv : X, (if xv = a ∧ y ⟨u, hu_ne_v⟩ = c then treeJoint b' y * (b.bEdge u v (y ⟨u, hu_ne_v⟩) xv / b.bNode u (y ⟨u, hu_ne_v⟩)) else 0) = (∑ y : W' → X, if y ⟨u, hu_ne_v⟩ = c then treeJoint b' y else 0) * (b.bEdge u v c a / b.bNode u c) := by rw [Finset.sum_mul] refine Finset.sum_congr rfl fun y _ => ?_ by_cases hy : y ⟨u, hu_ne_v⟩ = c · simp [hy] · simp [hy] _ = b.bNode u c * (b.bEdge u v c a / b.bNode u c) := by rw [ih_node ⟨u, hu_ne_v⟩ c] _ = b.bEdge u v c a := mul_div_cancel₀ _ (ne_of_gt (b.bNode_pos u c)) _ = b.bEdge v u a c := (b.bEdge_symm u v c a).symm · by_cases hjv : j = v · have hiu : i = u := by have hvi : T.Adj v i := hjv ▸ hij.symm have hm : i ∈ T.neighborFinset v := (SimpleGraph.mem_neighborFinset T v i).mpr hvi rw [hu_eq, Finset.mem_singleton] at hm; exact hm rw [hiu, hjv] rw [Fintype.sum_equiv eSplit _ (fun p => if p.1 ⟨u, hu_ne_v⟩ = a ∧ p.2 = c then treeJoint b' p.1 * (b.bEdge u v (p.1 ⟨u, hu_ne_v⟩) p.2 / b.bNode u (p.1 ⟨u, hu_ne_v⟩)) else 0) (fun x => by simp [eSplit, hfactor x]), Fintype.sum_prod_type] calc ∑ y : W' → X, ∑ xv : X, (if y ⟨u, hu_ne_v⟩ = a ∧ xv = c then treeJoint b' y * (b.bEdge u v (y ⟨u, hu_ne_v⟩) xv / b.bNode u (y ⟨u, hu_ne_v⟩)) else 0) = (∑ y : W' → X, if y ⟨u, hu_ne_v⟩ = a then treeJoint b' y else 0) * (b.bEdge u v a c / b.bNode u a) := by rw [Finset.sum_mul] refine Finset.sum_congr rfl fun y _ => ?_ by_cases hy : y ⟨u, hu_ne_v⟩ = a · simp [hy] · simp [hy] _ = b.bNode u a * (b.bEdge u v a c / b.bNode u a) := by rw [ih_node ⟨u, hu_ne_v⟩ a] _ = b.bEdge u v a c := mul_div_cancel₀ _ (ne_of_gt (b.bNode_pos u a)) · -- Edge strictly inside `T'` rw [Fintype.sum_equiv eSplit _ (fun p => if p.1 ⟨i, hiv⟩ = a ∧ p.1 ⟨j, hjv⟩ = c then treeJoint b' p.1 * (b.bEdge u v (p.1 ⟨u, hu_ne_v⟩) p.2 / b.bNode u (p.1 ⟨u, hu_ne_v⟩)) else 0) (fun x => by simp [eSplit, hfactor x]), Fintype.sum_prod_type] calc ∑ y : W' → X, ∑ xv : X, (if y ⟨i, hiv⟩ = a ∧ y ⟨j, hjv⟩ = c then treeJoint b' y * (b.bEdge u v (y ⟨u, hu_ne_v⟩) xv / b.bNode u (y ⟨u, hu_ne_v⟩)) else 0) = ∑ y : W' → X, if y ⟨i, hiv⟩ = a ∧ y ⟨j, hjv⟩ = c then treeJoint b' y else 0 := by refine Finset.sum_congr rfl fun y _ => ?_ split_ifs with hy · rw [← Finset.mul_sum, hmarg_v, mul_one] · simp _ = b.bEdge i j a c := ih_edge ⟨i, hiv⟩ ⟨j, hjv⟩ hij a c omit [DecidableRel G.Adj] [Nonempty X] in /-- Expectation of a single-node function under any joint distribution whose marginals are `b`. -/ lemma expect_node_of_marg {q : (V → X) → ℝ} {b : LocalBelief G X} (hmarg : ∀ i a, ∑ x : V → X, (if x i = a then q x else 0) = b.bNode i a) (f : V → X → ℝ) (i : V) : ∑ x : V → X, q x * f i (x i) = ∑ a : X, b.bNode i a * f i a := by simp_rw [← hmarg i, Finset.sum_mul] rw [Finset.sum_comm] refine Finset.sum_congr rfl fun x _ => ?_ rw [Finset.sum_eq_single (x i)] · simp · intro a _ ha; simp [ha.symm] · intro h; exact absurd (Finset.mem_univ _) h omit [DecidableRel G.Adj] [Nonempty X] in /-- Expectation of a pairwise edge function under any joint distribution whose marginals are `b`. -/ lemma expect_edge_of_marg {q : (V → X) → ℝ} {b : LocalBelief G X} (hmarg : ∀ i j, G.Adj i j → ∀ a c, ∑ x : V → X, (if x i = a ∧ x j = c then q x else 0) = b.bEdge i j a c) (F : V → V → X → X → ℝ) {i j : V} (hij : G.Adj i j) : ∑ x : V → X, q x * F i j (x i) (x j) = ∑ a : X, ∑ c : X, b.bEdge i j a c * F i j a c := by simp_rw [← hmarg i j hij, Finset.sum_mul] have hswap : (∑ a : X, ∑ c : X, ∑ x : V → X, (if x i = a ∧ x j = c then q x else 0) * F i j a c) = ∑ x : V → X, ∑ a : X, ∑ c : X, (if x i = a ∧ x j = c then q x else 0) * F i j a c := by calc ∑ a : X, ∑ c : X, ∑ x : V → X, (if x i = a ∧ x j = c then q x else 0) * F i j a c = ∑ a : X, ∑ x : V → X, ∑ c : X, (if x i = a ∧ x j = c then q x else 0) * F i j a c := Finset.sum_congr rfl fun a _ => Finset.sum_comm _ = _ := Finset.sum_comm rw [hswap] refine Finset.sum_congr rfl fun x _ => ?_ rw [Finset.sum_eq_single (x i)] · rw [Finset.sum_eq_single (x j)] · simp · intro c _ hc; simp [hc.symm] · intro h; exact absurd (Finset.mem_univ _) h · intro a _ ha refine Finset.sum_eq_zero fun c _ => ?_; simp [ha.symm] · intro h; exact absurd (Finset.mem_univ _) h omit [Nonempty X] in /-- **Maximum-Entropy Property of Markov Trees**: For ANY finite tree `T`, ANY `b : LocalBelief T X`, and ANY strictly positive joint distribution `q` on `V → X` sharing the node and edge marginals `b`, `H_Bethe(b) - H(q) = D_KL(q ‖ q_b) ≥ 0`, with equality iff `q = q_b`! -/ theorem tree_maxEntropy_identity (_hT : G.IsTree) (b : LocalBelief G X) {q : (V → X) → ℝ} (hq_node : ∀ i a, ∑ x : V → X, (if x i = a then q x else 0) = b.bNode i a) (hq_edge : ∀ i j, G.Adj i j → ∀ a c, ∑ x : V → X, (if x i = a ∧ x j = c then q x else 0) = b.bEdge i j a c) (hq_pos : ∀ x, 0 < q x) : betheEntropy G b.bNode b.bEdge - shannonH q = klDiv q (treeJoint b) := by have hcross : -∑ x : V → X, q x * Real.log (treeJoint b x) = betheEntropy G b.bNode b.bEdge := by simp_rw [log_treeJoint b, mul_sub, Finset.sum_sub_distrib] have hE1 : ∑ x : V → X, q x * ((1 / 2 : ℝ) * ∑ i : V, ∑ j ∈ G.neighborFinset i, Real.log (b.bEdge i j (x i) (x j))) = (1 / 2 : ℝ) * ∑ i : V, ∑ j ∈ G.neighborFinset i, ∑ a : X, ∑ c : X, b.bEdge i j a c * Real.log (b.bEdge i j a c) := by have hpull : ∀ x : V → X, q x * ((1 / 2 : ℝ) * ∑ i : V, ∑ j ∈ G.neighborFinset i, Real.log (b.bEdge i j (x i) (x j))) = (1 / 2 : ℝ) * ∑ i : V, ∑ j ∈ G.neighborFinset i, q x * Real.log (b.bEdge i j (x i) (x j)) := by intro x rw [← mul_assoc, mul_comm (q x) (1 / 2 : ℝ), mul_assoc, Finset.mul_sum] congr 1; refine Finset.sum_congr rfl fun i _ => Finset.mul_sum _ _ _ rw [Finset.sum_congr rfl fun x _ => hpull x, ← Finset.mul_sum] congr 1 calc ∑ x : V → X, ∑ i : V, ∑ j ∈ G.neighborFinset i, q x * Real.log (b.bEdge i j (x i) (x j)) = ∑ i : V, ∑ x : V → X, ∑ j ∈ G.neighborFinset i, q x * Real.log (b.bEdge i j (x i) (x j)) := Finset.sum_comm _ = ∑ i : V, ∑ j ∈ G.neighborFinset i, ∑ x : V → X, q x * Real.log (b.bEdge i j (x i) (x j)) := Finset.sum_congr rfl fun i _ => Finset.sum_comm _ = _ := Finset.sum_congr rfl fun i _ => Finset.sum_congr rfl fun j hj => expect_edge_of_marg hq_edge (fun u v a c => Real.log (b.bEdge u v a c)) ((SimpleGraph.mem_neighborFinset G i j).mp hj) have hE2 : ∑ x : V → X, q x * (∑ i : V, ((G.degree i : ℝ) - 1) * Real.log (b.bNode i (x i))) = ∑ i : V, ((G.degree i : ℝ) - 1) * ∑ a : X, b.bNode i a * Real.log (b.bNode i a) := by have h1 : (∑ x : V → X, q x * ∑ i : V, ((G.degree i : ℝ) - 1) * Real.log (b.bNode i (x i))) = ∑ i : V, ∑ x : V → X, q x * (((G.degree i : ℝ) - 1) * Real.log (b.bNode i (x i))) := by simp_rw [Finset.mul_sum]; exact Finset.sum_comm rw [h1] refine Finset.sum_congr rfl fun i _ => ?_ have hf : ∑ x : V → X, q x * (((G.degree i : ℝ) - 1) * Real.log (b.bNode i (x i))) = ((G.degree i : ℝ) - 1) * ∑ x : V → X, q x * Real.log (b.bNode i (x i)) := by rw [Finset.mul_sum]; refine Finset.sum_congr rfl fun x _ => by ring rw [hf, expect_node_of_marg hq_node (fun u a => Real.log (b.bNode u a)) i] rw [hE1, hE2] unfold betheEntropy pairH shannonH simp_rw [Fintype.sum_prod_type, mul_neg, Finset.sum_neg_distrib] ring unfold klDiv shannonH simp_rw [Real.log_div (ne_of_gt (hq_pos _)) (ne_of_gt (treeJoint_pos b _)), mul_sub, Finset.sum_sub_distrib] linarith omit [Nonempty X] in /-- **Headline Theorem 2A (Exact Tree Bethe Entropy Identity)**: On any finite tree `T`, `H_Bethe(b) = H(q_b)` for every interior `b ∈ L°(T)`. -/ theorem tree_betheEntropy_eq_gibbsEntropy (hT : G.IsTree) (b : LocalBelief G X) : betheEntropy G b.bNode b.bEdge = shannonH (treeJoint b) := by obtain ⟨hsum, hnode, hedge⟩ := treeJoint_marginals_exact (Fintype.card V) G hT rfl b have hid := tree_maxEntropy_identity hT b hnode hedge (treeJoint_pos b) have hkl0 : klDiv (treeJoint b) (treeJoint b) = 0 := (klDiv_eq_zero_iff (treeJoint_pos b) (treeJoint_pos b) hsum hsum).mpr rfl linarith /-- **Headline Theorem 2B (Exact Tree Bethe–Gibbs Identity)**: For ANY finite tree `T`, ANY positive MRF `M`, and ANY interior `b ∈ L°(T)`: `F_Bethe(b) = D_KL(q_b ‖ p) - log Z`. -/ theorem tree_betheFreeEnergy_eq_kl_sub_logZ (hT : G.IsTree) (M : PairwiseMRF G X) (b : LocalBelief G X) : betheFreeEnergy M b = klDiv (treeJoint b) M.gibbs - Real.log M.Z := by obtain ⟨hsum, hnode, hedge⟩ := treeJoint_marginals_exact (Fintype.card V) G hT rfl b have hH := tree_betheEntropy_eq_gibbsEntropy hT b -- Average energy `-E_{q_b}[log p̃(x)] = U_Bethe(b)` have hU : betheEnergy M b = -∑ x : V → X, treeJoint b x * Real.log (M.unnormWeight x) := by have hlog_w : ∀ x : V → X, Real.log (M.unnormWeight x) = (∑ i : V, Real.log (M.ψNode i (x i))) + (1 / 2 : ℝ) * ∑ i : V, ∑ j ∈ G.neighborFinset i, Real.log (M.ψEdge i j (x i) (x j)) := by intro x unfold PairwiseMRF.unnormWeight rw [Real.log_mul (ne_of_gt (Finset.prod_pos fun i _ => M.ψNode_pos i (x i))) (ne_of_gt (Finset.prod_pos fun e _ => M.edgeWeight_pos x e)), Real.log_prod (fun i _ => ne_of_gt (M.ψNode_pos i (x i))), Real.log_prod (fun e _ => ne_of_gt (M.edgeWeight_pos x e)), half_sum_neighbors_eq_sum_edgeFinset _ (fun i j => by rw [M.ψEdge_symm])] congr 1 refine Finset.sum_congr rfl fun e _ => ?_ induction e using Sym2.ind with | _ i j => rfl simp_rw [hlog_w, mul_add, Finset.sum_add_distrib] have h1 : ∑ x : V → X, treeJoint b x * ∑ i : V, Real.log (M.ψNode i (x i)) = ∑ i : V, ∑ a : X, b.bNode i a * Real.log (M.ψNode i a) := by simp_rw [Finset.mul_sum]; rw [Finset.sum_comm] exact Finset.sum_congr rfl fun i _ => expect_node_of_marg hnode (fun u a => Real.log (M.ψNode u a)) i have h2 : ∑ x : V → X, treeJoint b x * ((1 / 2 : ℝ) * ∑ i : V, ∑ j ∈ G.neighborFinset i, Real.log (M.ψEdge i j (x i) (x j))) = (1 / 2 : ℝ) * ∑ i : V, ∑ j ∈ G.neighborFinset i, ∑ a : X, ∑ c : X, b.bEdge i j a c * Real.log (M.ψEdge i j a c) := by have hpull : ∀ x : V → X, treeJoint b x * ((1 / 2 : ℝ) * ∑ i : V, ∑ j ∈ G.neighborFinset i, Real.log (M.ψEdge i j (x i) (x j))) = (1 / 2 : ℝ) * ∑ i : V, ∑ j ∈ G.neighborFinset i, treeJoint b x * Real.log (M.ψEdge i j (x i) (x j)) := by intro x rw [← mul_assoc, mul_comm (treeJoint b x) (1 / 2 : ℝ), mul_assoc, Finset.mul_sum] congr 1; refine Finset.sum_congr rfl fun i _ => Finset.mul_sum _ _ _ rw [Finset.sum_congr rfl fun x _ => hpull x, ← Finset.mul_sum]; congr 1 calc ∑ x : V → X, ∑ i : V, ∑ j ∈ G.neighborFinset i, treeJoint b x * Real.log (M.ψEdge i j (x i) (x j)) = ∑ i : V, ∑ x : V → X, ∑ j ∈ G.neighborFinset i, treeJoint b x * Real.log (M.ψEdge i j (x i) (x j)) := Finset.sum_comm _ = ∑ i : V, ∑ j ∈ G.neighborFinset i, ∑ x : V → X, treeJoint b x * Real.log (M.ψEdge i j (x i) (x j)) := Finset.sum_congr rfl fun i _ => Finset.sum_comm _ = _ := Finset.sum_congr rfl fun i _ => Finset.sum_congr rfl fun j hj => expect_edge_of_marg hedge (fun u v a c => Real.log (M.ψEdge u v a c)) ((SimpleGraph.mem_neighborFinset G i j).mp hj) rw [h1, h2]; unfold betheEnergy; ring unfold betheFreeEnergy klDiv rw [hU, hH]; unfold shannonH have hkl_exp : ∑ x : V → X, treeJoint b x * Real.log (treeJoint b x / M.gibbs x) = (∑ x : V → X, treeJoint b x * Real.log (treeJoint b x)) - (∑ x : V → X, treeJoint b x * Real.log (M.unnormWeight x)) + Real.log M.Z := by have hterm : ∀ x : V → X, treeJoint b x * Real.log (treeJoint b x / M.gibbs x) = treeJoint b x * Real.log (treeJoint b x) - treeJoint b x * Real.log (M.unnormWeight x) + treeJoint b x * Real.log M.Z := by intro x unfold PairwiseMRF.gibbs rw [Real.log_div (ne_of_gt (treeJoint_pos b x)) (ne_of_gt (div_pos (M.unnormWeight_pos x) M.Z_pos)), Real.log_div (ne_of_gt (M.unnormWeight_pos x)) (ne_of_gt M.Z_pos)] ring simp_rw [hterm, Finset.sum_add_distrib, Finset.sum_sub_distrib, ← Finset.sum_mul, hsum, one_mul] linarith /-- **Headline Theorem 2C (Exact Tree Bethe Variational Optimality & Uniqueness)**: On any finite tree `T`, `F_Bethe(b) ≥ -log Z` for all `b ∈ L°(T)`, with equality iff `b` matches the exact Gibbs marginals `M.exactBelief` on all vertices and edges! -/ theorem tree_betheFreeEnergy_min_iff (hT : G.IsTree) (M : PairwiseMRF G X) (b : LocalBelief G X) : -Real.log M.Z ≤ betheFreeEnergy M b ∧ (betheFreeEnergy M b = -Real.log M.Z ↔ (∀ i a, b.bNode i a = M.exactBelief.bNode i a) ∧ (∀ i j, G.Adj i j → ∀ a c, b.bEdge i j a c = M.exactBelief.bEdge i j a c)) := by obtain ⟨hsum, hnode, hedge⟩ := treeJoint_marginals_exact (Fintype.card V) G hT rfl b rw [tree_betheFreeEnergy_eq_kl_sub_logZ hT M b] have hkl_nn := klDiv_nonneg (treeJoint_pos b) M.gibbs_pos hsum M.sum_gibbs refine ⟨by linarith, ?_⟩ constructor · intro heq have hkl0 : klDiv (treeJoint b) M.gibbs = 0 := by linarith have hq_eq : treeJoint b = M.gibbs := (klDiv_eq_zero_iff (treeJoint_pos b) M.gibbs_pos hsum M.sum_gibbs).mp hkl0 refine ⟨fun i a => ?_, fun i j hij a c => ?_⟩ · rw [← hnode i a, hq_eq]; rfl · rw [← hedge i j hij a c, hq_eq]; simp [PairwiseMRF.exactBelief, hij.ne] · rintro ⟨hn_eq, he_eq⟩ -- Since `treeJoint b` depends only on `bNode` and `bEdge` on `G.edgeFinset`, -- `treeJoint b = treeJoint M.exactBelief`; and on a tree `treeJoint M.exactBelief = M.gibbs`! -- Even simpler: compute `klDiv (treeJoint b) M.gibbs`? Wait: we know `M.gibbs` minimizes -- `F_Bethe(M.exactBelief)` too — check `betheFreeEnergy M b = betheFreeEnergy M M.exactBelief`, -- and show `M.gibbs = treeJoint M.exactBelief` directly! -- Actually `tree_maxEntropy_identity` applied to `M.exactBelief` and `q = M.gibbs` gives -- `H_Bethe(p_marg) - H(p) = D_KL(p ‖ q_{p_marg}) ≥ 0` AND `H_Bethe(p_marg) - U(p_marg) = -F_Bethe = log Z - D_KL(q_{p_marg} ‖ p)`! -- Wait: `D_KL(p ‖ q_{p_marg}) + D_KL(q_{p_marg} ‖ p) = (H_Bethe(p_marg) - H(p)) + (F_Bethe(p_marg) + log Z)`! -- Since `F_Gibbs(p) = U(p_marg) - H(p) = -log Z`, that sum equals `0`!! -- OH WHAT A 4-LINE PROOF THAT `p = q_{p_marg}` ON EVERY TREE WITHOUT RE-PROVING BP!! have hq_eq_exact : treeJoint b = treeJoint M.exactBelief := by funext x unfold treeJoint congr 1 · exact Finset.prod_congr rfl fun i _ => hn_eq i (x i) · refine Finset.prod_congr rfl fun e he => ?_ induction e using Sym2.ind with | _ i j => simp only [Sym2.lift_mk] rw [he_eq i j (G.mem_edgeFinset.mp he) (x i) (x j), hn_eq i (x i), hn_eq j (x j)] -- Prove `klDiv M.gibbs (treeJoint M.exactBelief) + klDiv (treeJoint M.exactBelief) M.gibbs = 0`! have hgibbs_ent : betheEnergy M M.exactBelief - shannonH M.gibbs = -Real.log M.Z := by have hlog_g : ∀ x : V → X, Real.log (M.gibbs x) = (∑ i : V, Real.log (M.ψNode i (x i))) + (1 / 2 : ℝ) * (∑ i : V, ∑ j ∈ G.neighborFinset i, Real.log (M.ψEdge i j (x i) (x j))) - Real.log M.Z := by intro x unfold PairwiseMRF.gibbs PairwiseMRF.unnormWeight rw [Real.log_div (ne_of_gt (mul_pos (Finset.prod_pos fun i _ => M.ψNode_pos i (x i)) (Finset.prod_pos fun e _ => M.edgeWeight_pos x e))) (ne_of_gt M.Z_pos), Real.log_mul (ne_of_gt (Finset.prod_pos fun i _ => M.ψNode_pos i (x i))) (ne_of_gt (Finset.prod_pos fun e _ => M.edgeWeight_pos x e)), Real.log_prod (fun i _ => ne_of_gt (M.ψNode_pos i (x i))), Real.log_prod (fun e _ => ne_of_gt (M.edgeWeight_pos x e)), half_sum_neighbors_eq_sum_edgeFinset _ (fun i j => by rw [M.ψEdge_symm])] congr 1; congr 1 refine Finset.sum_congr rfl fun e _ => ?_ induction e using Sym2.ind with | _ i j => rfl have hH_eq : -shannonH M.gibbs = ∑ x : V → X, M.gibbs x * Real.log (M.gibbs x) := by unfold shannonH; ring have hnode_g : ∀ i a, ∑ x : V → X, (if x i = a then M.gibbs x else 0) = M.exactBelief.bNode i a := fun _ _ => rfl have hedge_g : ∀ i j, G.Adj i j → ∀ a c, ∑ x : V → X, (if x i = a ∧ x j = c then M.gibbs x else 0) = M.exactBelief.bEdge i j a c := fun i j hij a c => by simp [PairwiseMRF.exactBelief, hij.ne] have havg : ∑ x : V → X, M.gibbs x * Real.log (M.gibbs x) = -betheEnergy M M.exactBelief - Real.log M.Z := by simp_rw [hlog_g, mul_sub, mul_add, Finset.sum_sub_distrib, Finset.sum_add_distrib, ← Finset.sum_mul, M.sum_gibbs, one_mul] have h1 : ∑ x : V → X, M.gibbs x * ∑ i : V, Real.log (M.ψNode i (x i)) = ∑ i : V, ∑ a : X, M.exactBelief.bNode i a * Real.log (M.ψNode i a) := by simp_rw [Finset.mul_sum]; rw [Finset.sum_comm] exact Finset.sum_congr rfl fun i _ => expect_node_of_marg hnode_g (fun u a => Real.log (M.ψNode u a)) i have h2 : ∑ x : V → X, M.gibbs x * ((1 / 2 : ℝ) * ∑ i : V, ∑ j ∈ G.neighborFinset i, Real.log (M.ψEdge i j (x i) (x j))) = (1 / 2 : ℝ) * ∑ i : V, ∑ j ∈ G.neighborFinset i, ∑ a : X, ∑ c : X, M.exactBelief.bEdge i j a c * Real.log (M.ψEdge i j a c) := by have hpull : ∀ x : V → X, M.gibbs x * ((1 / 2 : ℝ) * ∑ i : V, ∑ j ∈ G.neighborFinset i, Real.log (M.ψEdge i j (x i) (x j))) = (1 / 2 : ℝ) * ∑ i : V, ∑ j ∈ G.neighborFinset i, M.gibbs x * Real.log (M.ψEdge i j (x i) (x j)) := by intro x rw [← mul_assoc, mul_comm (M.gibbs x) (1 / 2 : ℝ), mul_assoc, Finset.mul_sum] congr 1; refine Finset.sum_congr rfl fun i _ => Finset.mul_sum _ _ _ rw [Finset.sum_congr rfl fun x _ => hpull x, ← Finset.mul_sum]; congr 1 calc ∑ x : V → X, ∑ i : V, ∑ j ∈ G.neighborFinset i, M.gibbs x * Real.log (M.ψEdge i j (x i) (x j)) = ∑ i : V, ∑ x : V → X, ∑ j ∈ G.neighborFinset i, M.gibbs x * Real.log (M.ψEdge i j (x i) (x j)) := Finset.sum_comm _ = ∑ i : V, ∑ j ∈ G.neighborFinset i, ∑ x : V → X, M.gibbs x * Real.log (M.ψEdge i j (x i) (x j)) := Finset.sum_congr rfl fun i _ => Finset.sum_comm _ = _ := Finset.sum_congr rfl fun i _ => Finset.sum_congr rfl fun j hj => expect_edge_of_marg hedge_g (fun u v a c => Real.log (M.ψEdge u v a c)) ((SimpleGraph.mem_neighborFinset G i j).mp hj) rw [h1, h2]; unfold betheEnergy; ring linarith have hid1 := tree_maxEntropy_identity hT M.exactBelief (fun _ _ => rfl) (fun i j hij a c => by simp [PairwiseMRF.exactBelief, hij.ne]) M.gibbs_pos have hid2 := tree_betheFreeEnergy_eq_kl_sub_logZ hT M M.exactBelief obtain ⟨hsum_e, _, _⟩ := treeJoint_marginals_exact (Fintype.card V) G hT rfl M.exactBelief have hkl1_nn := klDiv_nonneg M.gibbs_pos (treeJoint_pos M.exactBelief) M.sum_gibbs hsum_e have hkl2_nn := klDiv_nonneg (treeJoint_pos M.exactBelief) M.gibbs_pos hsum_e M.sum_gibbs unfold betheFreeEnergy at hid2 -- Wait: `hid1 : H_Bethe - H(p) = kl(p ‖ q_p)` and `hid2 : U - H_Bethe = kl(q_p ‖ p) - log Z`, -- adding them gives `U - H(p) = kl(p ‖ q_p) + kl(q_p ‖ p) - log Z`, while `U - H(p) = -log Z`! -- Therefore `kl(p ‖ q_p) + kl(q_p ‖ p) = 0`, so BOTH KL divergences are `0`!! rw [hq_eq_exact] linarith omit [Nonempty X] in /-- **Headline Theorem 2D (Strict Convexity of Bethe Free Energy on Arbitrary Trees)**: On any finite tree `T`, `H_Bethe` is strictly concave (hence `F_Bethe` is strictly convex) on `L°(T)`: for any `b₁, b₂ ∈ L°(T)` differing on at least one vertex or edge and any `t ∈ (0, 1)`, `F_Bethe((1-t) b₁ + t b₂) < (1-t) F_Bethe(b₁) + t F_Bethe(b₂)`. -/ theorem tree_betheFreeEnergy_strictConvex (hT : G.IsTree) (M : PairwiseMRF G X) (b₁ b₂ : LocalBelief G X) (hne : (∃ i a, b₁.bNode i a ≠ b₂.bNode i a) ∨ (∃ i j, G.Adj i j ∧ ∃ a c, b₁.bEdge i j a c ≠ b₂.bEdge i j a c)) {t : ℝ} (ht0 : 0 < t) (ht1 : t < 1) : betheFreeEnergy M (b₁.convexComb b₂ (le_of_lt ht0) (le_of_lt ht1)) < (1 - t) * betheFreeEnergy M b₁ + t * betheFreeEnergy M b₂ := by let bm := b₁.convexComb b₂ (le_of_lt ht0) (le_of_lt ht1) -- `betheEnergy` is affine in `b`! have hU_aff : betheEnergy M bm = (1 - t) * betheEnergy M b₁ + t * betheEnergy M b₂ := by unfold betheEnergy dsimp only [bm, LocalBelief.convexComb] simp_rw [add_mul, mul_assoc, Finset.sum_add_distrib, ← Finset.mul_sum] ring -- `H_Bethe(bm) > (1-t) H_Bethe(b₁) + t H_Bethe(b₂)` via `tree_maxEntropy_identity` + strict concavity of `shannonH`! obtain ⟨hs₁, hn₁, he₁⟩ := treeJoint_marginals_exact (Fintype.card V) G hT rfl b₁ obtain ⟨hs₂, hn₂, he₂⟩ := treeJoint_marginals_exact (Fintype.card V) G hT rfl b₂ obtain ⟨hsm, _, _⟩ := treeJoint_marginals_exact (Fintype.card V) G hT rfl bm let qbar : (V → X) → ℝ := fun x => (1 - t) * treeJoint b₁ x + t * treeJoint b₂ x have hqbar_pos : ∀ x, 0 < qbar x := fun x => add_pos (mul_pos (sub_pos.mpr ht1) (treeJoint_pos b₁ x)) (mul_pos ht0 (treeJoint_pos b₂ x)) have hqbar_sum : ∑ x : V → X, qbar x = 1 := by dsimp only [qbar] rw [Finset.sum_add_distrib, ← Finset.mul_sum, ← Finset.mul_sum, hs₁, hs₂]; ring have hqbar_node : ∀ i a, ∑ x : V → X, (if x i = a then qbar x else 0) = bm.bNode i a := by intro i a have hsplit : ∀ x : V → X, (if x i = a then qbar x else 0) = (1 - t) * (if x i = a then treeJoint b₁ x else 0) + t * (if x i = a then treeJoint b₂ x else 0) := fun x => by split_ifs <;> simp [qbar] simp_rw [hsplit, Finset.sum_add_distrib, ← Finset.mul_sum, hn₁, hn₂]; rfl have hqbar_edge : ∀ i j, G.Adj i j → ∀ a c, ∑ x : V → X, (if x i = a ∧ x j = c then qbar x else 0) = bm.bEdge i j a c := by intro i j hij a c have hsplit : ∀ x : V → X, (if x i = a ∧ x j = c then qbar x else 0) = (1 - t) * (if x i = a ∧ x j = c then treeJoint b₁ x else 0) + t * (if x i = a ∧ x j = c then treeJoint b₂ x else 0) := fun x => by split_ifs <;> simp [qbar] simp_rw [hsplit, Finset.sum_add_distrib, ← Finset.mul_sum, he₁ i j hij, he₂ i j hij]; rfl have hq_ne : treeJoint b₁ ≠ treeJoint b₂ := by intro heq rcases hne with ⟨i, a, hne_n⟩ | ⟨i, j, hij, a, c, hne_e⟩ · apply hne_n; rw [← hn₁ i a, ← hn₂ i a, heq] · apply hne_e; rw [← he₁ i j hij a c, ← he₂ i j hij a c, heq] have hmaxE := tree_maxEntropy_identity hT bm hqbar_node hqbar_edge hqbar_pos have hkl_nn := klDiv_nonneg hqbar_pos (treeJoint_pos bm) hqbar_sum hsm have hstrict : (1 - t) * shannonH (treeJoint b₁) + t * shannonH (treeJoint b₂) < shannonH qbar := shannonH_strictConcave (treeJoint_pos b₁) (treeJoint_pos b₂) hs₁ hs₂ hq_ne ht0 ht1 have hH1 := tree_betheEntropy_eq_gibbsEntropy hT b₁ have hH2 := tree_betheEntropy_eq_gibbsEntropy hT b₂ change betheFreeEnergy M bm < (1 - t) * betheFreeEnergy M b₁ + t * betheFreeEnergy M b₂ unfold betheFreeEnergy rw [hU_aff, hH1, hH2] linarith end TreeBetheGibbs /-! ## Section 4: Yedidia–Freeman–Weiss (YFW) 1-to-1 Stationary-Point Bijection on Arbitrary Graphs -/ section YedidiaFreemanWeiss variable {V X : Type*} {G : SimpleGraph V} [Fintype V] [DecidableEq V] [DecidableRel G.Adj] variable [Fintype X] [DecidableEq X] [Nonempty X] /-- Directed edges of `G`. -/ abbrev DirEdge (G : SimpleGraph V) := {e : V × V // G.Adj e.1 e.2} /-- Exact derivative of `-x log x` is `-(1 + log x)` for `x > 0`. -/ lemma hasDerivAt_neg_mul_log {x : ℝ} (hx : 0 < x) : HasDerivAt (fun t : ℝ => -(t * Real.log t)) (-(1 + Real.log x)) x := by have h1 : HasDerivAt (fun t : ℝ => t * Real.log t) (1 * Real.log x + x * x⁻¹) x := (hasDerivAt_id x).mul (Real.hasDerivAt_log (ne_of_gt hx)) have h2 := h1.neg refine h2.congr_deriv ?_ field_simp [ne_of_gt hx]; ring /-- Single-node Bethe Lagrangian coordinate slice as a function of `t = b_i(a)`: `f(t) = -t log ψ_i(a) - (d_i - 1) · (t log t) + γ_i · t + (∑_{k ∈ N(i)} λ_{k → i}(a)) · t`. -/ noncomputable def betheLagrangianNodeSlice (M : PairwiseMRF G X) (γNode : V → ℝ) (lam : V → V → X → ℝ) (i : V) (a : X) (t : ℝ) : ℝ := -(t * Real.log (M.ψNode i a)) - ((G.degree i : ℝ) - 1) * (t * Real.log t) + γNode i * t + (∑ k ∈ G.neighborFinset i, lam k i a) * t omit [DecidableEq V] [Fintype X] [DecidableEq X] [Nonempty X] in /-- Exact partial derivative of the Bethe Lagrangian with respect to `b_i(a)`. -/ theorem hasDerivAt_betheLagrangian_node (M : PairwiseMRF G X) (γNode : V → ℝ) (lam : V → V → X → ℝ) (i : V) (a : X) {t : ℝ} (ht : 0 < t) : HasDerivAt (betheLagrangianNodeSlice M γNode lam i a) (-Real.log (M.ψNode i a) - ((G.degree i : ℝ) - 1) * (1 + Real.log t) + γNode i + ∑ k ∈ G.neighborFinset i, lam k i a) t := by unfold betheLagrangianNodeSlice have h1 : HasDerivAt (fun s : ℝ => -(s * Real.log (M.ψNode i a))) (-Real.log (M.ψNode i a)) t := (((hasDerivAt_id t).mul_const (Real.log (M.ψNode i a))).neg).congr_deriv (by ring) have hlog : HasDerivAt (fun s : ℝ => s * Real.log s) (1 + Real.log t) t := by refine ((hasDerivAt_id t).mul (Real.hasDerivAt_log (ne_of_gt ht))).congr_deriv ?_ dsimp only [id]; rw [one_mul, mul_inv_cancel₀ (ne_of_gt ht), add_comm] have h2 := hlog.const_mul ((G.degree i : ℝ) - 1) have h3 : HasDerivAt (fun s : ℝ => γNode i * s) (γNode i) t := by simpa using (hasDerivAt_id t).const_mul (γNode i) have h4 : HasDerivAt (fun s : ℝ => (∑ k ∈ G.neighborFinset i, lam k i a) * s) (∑ k ∈ G.neighborFinset i, lam k i a) t := by simpa using (hasDerivAt_id t).const_mul (∑ k ∈ G.neighborFinset i, lam k i a) exact ((h1.sub h2).add h3).add h4 /-- Pairwise-edge Bethe Lagrangian coordinate slice as a function of `t = b_{ij}(a, c)`: `g(t) = -t log ψ_{ij}(a, c) + t log t + γ_{ij} t - (λ_{i → j}(c) + λ_{j → i}(a)) t`. -/ noncomputable def betheLagrangianEdgeSlice (M : PairwiseMRF G X) (γEdge : V → V → ℝ) (lam : V → V → X → ℝ) (i j : V) (a c : X) (t : ℝ) : ℝ := -(t * Real.log (M.ψEdge i j a c)) + t * Real.log t + γEdge i j * t - (lam i j c + lam j i a) * t omit [Fintype V] [DecidableEq V] [DecidableRel G.Adj] [Fintype X] [DecidableEq X] [Nonempty X] in /-- Exact partial derivative of the Bethe Lagrangian with respect to `b_{ij}(a, c)`. -/ theorem hasDerivAt_betheLagrangian_edge (M : PairwiseMRF G X) (γEdge : V → V → ℝ) (lam : V → V → X → ℝ) (i j : V) (a c : X) {t : ℝ} (ht : 0 < t) : HasDerivAt (betheLagrangianEdgeSlice M γEdge lam i j a c) (-Real.log (M.ψEdge i j a c) + (1 + Real.log t) + γEdge i j - (lam i j c + lam j i a)) t := by unfold betheLagrangianEdgeSlice have h1 : HasDerivAt (fun s : ℝ => -(s * Real.log (M.ψEdge i j a c))) (-Real.log (M.ψEdge i j a c)) t := (((hasDerivAt_id t).mul_const (Real.log (M.ψEdge i j a c))).neg).congr_deriv (by ring) have h2 : HasDerivAt (fun s : ℝ => s * Real.log s) (1 + Real.log t) t := by refine ((hasDerivAt_id t).mul (Real.hasDerivAt_log (ne_of_gt ht))).congr_deriv ?_ dsimp only [id]; rw [one_mul, mul_inv_cancel₀ (ne_of_gt ht), add_comm] have h3 : HasDerivAt (fun s : ℝ => γEdge i j * s) (γEdge i j) t := by simpa using (hasDerivAt_id t).const_mul (γEdge i j) have h4 : HasDerivAt (fun s : ℝ => (lam i j c + lam j i a) * s) (lam i j c + lam j i a) t := by simpa using (hasDerivAt_id t).const_mul (lam i j c + lam j i a) exact ((h1.add h2).add h3).sub h4 /-- Interior Bethe KKT stationarity predicate on an arbitrary finite graph `G`: there exist Lagrange multipliers `(γNode, γEdge, lam)` such that every node and edge partial derivative of the Bethe Lagrangian vanishes at `b ∈ L°(G)`. -/ def IsBetheStationary (M : PairwiseMRF G X) (b : LocalBelief G X) : Prop := ∃ (γNode : V → ℝ) (γEdge : V → V → ℝ) (lam : V → V → X → ℝ), (∀ i a, -Real.log (M.ψNode i a) - ((G.degree i : ℝ) - 1) * (1 + Real.log (b.bNode i a)) + γNode i + ∑ k ∈ G.neighborFinset i, lam k i a = 0) ∧ (∀ i j, G.Adj i j → ∀ a c, -Real.log (M.ψEdge i j a c) + (1 + Real.log (b.bEdge i j a c)) + γEdge i j - (lam i j c + lam j i a) = 0) /-- Normalized strictly positive Sum-Product BP fixed point on `G` (represented on directed edges). -/ structure BPFixedPoint (M : PairwiseMRF G X) where msg : DirEdge G → X → ℝ msg_pos : ∀ e a, 0 < msg e a msg_sum : ∀ e, ∑ a : X, msg e a = 1 fixed : ∀ e : DirEdge G, ∀ xj : X, let i := e.1.1 let j := e.1.2 let raw (y : X) : ℝ := ∑ xi : X, M.ψNode i xi * M.ψEdge i j xi y * ∏ k ∈ ((G.neighborFinset i).erase j).attach, msg ⟨(k.1, i), ((SimpleGraph.mem_neighborFinset G i k.1).mp (Finset.mem_of_mem_erase k.2)).symm⟩ xi msg e xj = raw xj / ∑ y : X, raw y omit [DecidableEq X] [Nonempty X] in /-- Extensionality for `BPFixedPoint`: determined by `msg`. -/ @[ext] lemma BPFixedPoint.ext {M : PairwiseMRF G X} {m₁ m₂ : BPFixedPoint M} (h : m₁.msg = m₂.msg) : m₁ = m₂ := by cases m₁; cases m₂; simp only [BPFixedPoint.mk.injEq]; exact h /-- Equivalence class of interior beliefs on `G` (extensional on `bNode` and adjacent `bEdge`). -/ structure GraphBelief (G : SimpleGraph V) (X : Type*) [Fintype X] where bNode : V → X → ℝ bEdge : DirEdge G → X → X → ℝ bNode_pos : ∀ i a, 0 < bNode i a bEdge_pos : ∀ e a c, 0 < bEdge e a c bNode_sum : ∀ i, ∑ a : X, bNode i a = 1 bEdge_symm : ∀ (e : DirEdge G) a c, bEdge ⟨(e.1.2, e.1.1), e.2.symm⟩ c a = bEdge e a c bEdge_marg : ∀ (e : DirEdge G) a, ∑ c : X, bEdge e a c = bNode e.1.1 a omit [Fintype V] [DecidableEq V] [DecidableRel G.Adj] [DecidableEq X] [Nonempty X] in @[ext] lemma GraphBelief.ext {b₁ b₂ : GraphBelief G X} (hn : b₁.bNode = b₂.bNode) (he : b₁.bEdge = b₂.bEdge) : b₁ = b₂ := by cases b₁; cases b₂; simp only [GraphBelief.mk.injEq]; exact ⟨hn, he⟩ /-- Interior Bethe KKT stationarity on `GraphBelief G X`. -/ def IsGraphBetheStationary (M : PairwiseMRF G X) (b : GraphBelief G X) : Prop := ∃ (γNode : V → ℝ) (γEdge : DirEdge G → ℝ) (lam : DirEdge G → X → ℝ), (∀ i a, -Real.log (M.ψNode i a) - ((G.degree i : ℝ) - 1) * (1 + Real.log (b.bNode i a)) + γNode i + ∑ k ∈ (G.neighborFinset i).attach, lam ⟨(k.1, i), ((SimpleGraph.mem_neighborFinset G i k.1).mp k.2).symm⟩ a = 0) ∧ (∀ (e : DirEdge G) a c, -Real.log (M.ψEdge e.1.1 e.1.2 a c) + (1 + Real.log (b.bEdge e a c)) + γEdge e - (lam e c + lam ⟨(e.1.2, e.1.1), e.2.symm⟩ a) = 0) /-- Belief induced by a `BPFixedPoint M`. -/ noncomputable def beliefOfBP (M : PairwiseMRF G X) (m : BPFixedPoint M) : GraphBelief G X := let unNode (i : V) (xi : X) : ℝ := M.ψNode i xi * ∏ k ∈ (G.neighborFinset i).attach, m.msg ⟨(k.1, i), ((SimpleGraph.mem_neighborFinset G i k.1).mp k.2).symm⟩ xi let unEdge (e : DirEdge G) (xi xj : X) : ℝ := M.ψNode e.1.1 xi * M.ψNode e.1.2 xj * M.ψEdge e.1.1 e.1.2 xi xj * (∏ k ∈ ((G.neighborFinset e.1.1).erase e.1.2).attach, m.msg ⟨(k.1, e.1.1), ((SimpleGraph.mem_neighborFinset G e.1.1 k.1).mp (Finset.mem_of_mem_erase k.2)).symm⟩ xi) * (∏ l ∈ ((G.neighborFinset e.1.2).erase e.1.1).attach, m.msg ⟨(l.1, e.1.2), ((SimpleGraph.mem_neighborFinset G e.1.2 l.1).mp (Finset.mem_of_mem_erase l.2)).symm⟩ xj) have hunNode_pos : ∀ i xi, 0 < unNode i xi := fun i xi => mul_pos (M.ψNode_pos i xi) (Finset.prod_pos fun k _ => m.msg_pos _ xi) have hunEdge_pos : ∀ e xi xj, 0 < unEdge e xi xj := fun e xi xj => mul_pos (mul_pos (mul_pos (mul_pos (M.ψNode_pos _ _) (M.ψNode_pos _ _)) (M.ψEdge_pos _ _ _ _)) (Finset.prod_pos fun _ _ => m.msg_pos _ _)) (Finset.prod_pos fun _ _ => m.msg_pos _ _) { bNode := fun i xi => unNode i xi / ∑ a : X, unNode i a bEdge := fun e xi xj => unEdge e xi xj / ∑ a : X, ∑ c : X, unEdge e a c bNode_pos := fun i xi => div_pos (hunNode_pos i xi) (Finset.sum_pos (fun a _ => hunNode_pos i a) Finset.univ_nonempty) bEdge_pos := fun e xi xj => div_pos (hunEdge_pos e xi xj) (Finset.sum_pos (fun a _ => Finset.sum_pos (fun c _ => hunEdge_pos e a c) Finset.univ_nonempty) Finset.univ_nonempty) bNode_sum := fun i => by rw [← Finset.sum_div, div_self (ne_of_gt (Finset.sum_pos (fun a _ => hunNode_pos i a) Finset.univ_nonempty))] bEdge_symm := fun e a c => by have hsym : ∀ u v, unEdge ⟨(e.1.2, e.1.1), e.2.symm⟩ v u = unEdge e u v := fun u v => by dsimp only [unEdge] rw [M.ψEdge_symm] ring rw [hsym a c] congr 1 rw [Finset.sum_comm] exact Finset.sum_congr rfl fun u _ => Finset.sum_congr rfl fun v _ => hsym u v bEdge_marg := fun e a => by -- Marginalizing `unEdge e a c` over `c` uses the BP fixed-point equation for `m.msg ⟨(j, i)⟩ a`! let eRev : DirEdge G := ⟨(e.1.2, e.1.1), e.2.symm⟩ let rawRev (y : X) : ℝ := ∑ xj : X, M.ψNode e.1.2 xj * M.ψEdge e.1.2 e.1.1 xj y * ∏ l ∈ ((G.neighborFinset e.1.2).erase e.1.1).attach, m.msg ⟨(l.1, e.1.2), ((SimpleGraph.mem_neighborFinset G e.1.2 l.1).mp (Finset.mem_of_mem_erase l.2)).symm⟩ xj let Zrev : ℝ := ∑ y : X, rawRev y have hZrev_pos : 0 < Zrev := Finset.sum_pos (fun y _ => Finset.sum_pos (fun xj _ => mul_pos (mul_pos (M.ψNode_pos _ _) (M.ψEdge_pos _ _ _ _)) (Finset.prod_pos fun _ _ => m.msg_pos _ _)) Finset.univ_nonempty) Finset.univ_nonempty have hmarg_un : ∀ xi : X, ∑ xj : X, unEdge e xi xj = Zrev * unNode e.1.1 xi := by intro xi have hraw : rawRev xi = Zrev * m.msg eRev xi := by have hf := m.fixed eRev xi dsimp only [eRev, rawRev, Zrev] at hf ⊢ rw [hf, mul_div_cancel₀ _ (ne_of_gt hZrev_pos)] have hsum_un : ∑ xj : X, unEdge e xi xj = M.ψNode e.1.1 xi * (∏ k ∈ ((G.neighborFinset e.1.1).erase e.1.2).attach, m.msg ⟨(k.1, e.1.1), ((SimpleGraph.mem_neighborFinset G e.1.1 k.1).mp (Finset.mem_of_mem_erase k.2)).symm⟩ xi) * rawRev xi := by dsimp only [unEdge, rawRev] rw [Finset.mul_sum] refine Finset.sum_congr rfl fun xj _ => ?_ rw [M.ψEdge_symm]; ring rw [hsum_un, hraw] dsimp only [unNode] -- Recombine `m.msg eRev xi` with product over `erase e.1.2` to get full product over `neighborFinset e.1.1`! have hmem_j : e.1.2 ∈ G.neighborFinset e.1.1 := (SimpleGraph.mem_neighborFinset G e.1.1 e.1.2).mpr e.2 have hprod_comb : (∏ k ∈ (G.neighborFinset e.1.1).attach, m.msg ⟨(k.1, e.1.1), ((SimpleGraph.mem_neighborFinset G e.1.1 k.1).mp k.2).symm⟩ xi) = m.msg eRev xi * ∏ k ∈ ((G.neighborFinset e.1.1).erase e.1.2).attach, m.msg ⟨(k.1, e.1.1), ((SimpleGraph.mem_neighborFinset G e.1.1 k.1).mp (Finset.mem_of_mem_erase k.2)).symm⟩ xi := by rw [← Finset.mul_prod_erase (G.neighborFinset e.1.1).attach _ (Finset.mem_attach _ ⟨e.1.2, hmem_j⟩)] congr 1 refine Finset.prod_bij (fun k hk => ⟨k.1, Finset.mem_erase.mpr ⟨fun heq => (Finset.ne_of_mem_erase hk) (Subtype.ext heq), k.2⟩⟩) ?_ ?_ ?_ ?_ · intro _ _; exact Finset.mem_attach _ _ · intro k₁ _ k₂ _ h; exact Subtype.ext (congrArg (fun x => x.1) h) · intro k _ exact ⟨⟨k.1, Finset.mem_of_mem_erase k.2⟩, Finset.mem_erase.mpr ⟨fun h => Finset.ne_of_mem_erase k.2 (congrArg Subtype.val h), Finset.mem_attach _ _⟩, rfl⟩ · intro _ _; rfl rw [hprod_comb]; ring rw [← Finset.sum_div] simp_rw [hmarg_un, ← Finset.mul_sum, mul_div_mul_left _ _ (ne_of_gt hZrev_pos)] } omit [DecidableEq X] in /-- **Headline Theorem 2E (Yedidia–Freeman–Weiss Forward Direction: BP Fixed Point ⇒ Bethe KKT)**: On ANY finite graph `G` (with arbitrary cycles!), every normalized positive Sum-Product BP fixed point `m` induces an interior Bethe KKT stationary belief `beliefOfBP M m`. -/ theorem yfw_bp_implies_betheStationary (M : PairwiseMRF G X) (m : BPFixedPoint M) : IsGraphBetheStationary M (beliefOfBP M m) := by let b := beliefOfBP M m -- Cavity-field Lagrange multipliers: -- `λ_{i → j}(xj) = log ψ_j(xj) + ∑_{l ∈ N(j)\{i}} log m_{l → j}(xj)`! let lam : DirEdge G → X → ℝ := fun e xj => Real.log (M.ψNode e.1.2 xj) + ∑ l ∈ ((G.neighborFinset e.1.2).erase e.1.1).attach, Real.log (m.msg ⟨(l.1, e.1.2), ((SimpleGraph.mem_neighborFinset G e.1.2 l.1).mp (Finset.mem_of_mem_erase l.2)).symm⟩ xj) let Znode : V → ℝ := fun i => ∑ a : X, M.ψNode i a * ∏ k ∈ (G.neighborFinset i).attach, m.msg ⟨(k.1, i), ((SimpleGraph.mem_neighborFinset G i k.1).mp k.2).symm⟩ a let Zedge : DirEdge G → ℝ := fun e => ∑ a : X, ∑ c : X, M.ψNode e.1.1 a * M.ψNode e.1.2 c * M.ψEdge e.1.1 e.1.2 a c * (∏ k ∈ ((G.neighborFinset e.1.1).erase e.1.2).attach, m.msg ⟨(k.1, e.1.1), ((SimpleGraph.mem_neighborFinset G e.1.1 k.1).mp (Finset.mem_of_mem_erase k.2)).symm⟩ a) * (∏ l ∈ ((G.neighborFinset e.1.2).erase e.1.1).attach, m.msg ⟨(l.1, e.1.2), ((SimpleGraph.mem_neighborFinset G e.1.2 l.1).mp (Finset.mem_of_mem_erase l.2)).symm⟩ c) have hZn_pos : ∀ i, 0 < Znode i := fun i => Finset.sum_pos (fun a _ => mul_pos (M.ψNode_pos i a) (Finset.prod_pos fun _ _ => m.msg_pos _ _)) Finset.univ_nonempty have hZe_pos : ∀ e, 0 < Zedge e := fun e => Finset.sum_pos (fun a _ => Finset.sum_pos (fun c _ => mul_pos (mul_pos (mul_pos (mul_pos (M.ψNode_pos _ _) (M.ψNode_pos _ _)) (M.ψEdge_pos _ _ _ _)) (Finset.prod_pos fun _ _ => m.msg_pos _ _)) (Finset.prod_pos fun _ _ => m.msg_pos _ _)) Finset.univ_nonempty) Finset.univ_nonempty -- Choose `γNode i` and `γEdge e` explicitly! let γNode : V → ℝ := fun i => ((G.degree i : ℝ) - 1) * (1 - Real.log (Znode i)) let γEdge : DirEdge G → ℝ := fun e => Real.log (Zedge e) - 1 refine ⟨γNode, γEdge, lam, ?_, ?_⟩ · -- Node stationarity for every `i, a` intro i a have hlog_bNode : Real.log (b.bNode i a) = Real.log (M.ψNode i a) + (∑ k ∈ (G.neighborFinset i).attach, Real.log (m.msg ⟨(k.1, i), ((SimpleGraph.mem_neighborFinset G i k.1).mp k.2).symm⟩ a)) - Real.log (Znode i) := by dsimp only [b, beliefOfBP, Znode] rw [Real.log_div (ne_of_gt (mul_pos (M.ψNode_pos i a) (Finset.prod_pos fun _ _ => m.msg_pos _ _))) (ne_of_gt (hZn_pos i)), Real.log_mul (ne_of_gt (M.ψNode_pos i a)) (ne_of_gt (Finset.prod_pos fun _ _ => m.msg_pos _ _)), Real.log_prod (fun _ _ => ne_of_gt (m.msg_pos _ _))] -- Double-counting sum of `lam k i a` over `k ∈ N(i)`: -- `∑_{k ∈ N(i)} lam_{k → i}(a) = d_i log ψ_i(a) + (d_i - 1) ∑_{l ∈ N(i)} log m_{l → i}(a)`! have hsum_lam : (∑ k ∈ (G.neighborFinset i).attach, lam ⟨(k.1, i), ((SimpleGraph.mem_neighborFinset G i k.1).mp k.2).symm⟩ a) = (G.degree i : ℝ) * Real.log (M.ψNode i a) + ((G.degree i : ℝ) - 1) * ∑ l ∈ (G.neighborFinset i).attach, Real.log (m.msg ⟨(l.1, i), ((SimpleGraph.mem_neighborFinset G i l.1).mp l.2).symm⟩ a) := by dsimp only [lam] rw [Finset.sum_add_distrib, Finset.sum_const, Finset.card_attach, nsmul_eq_mul, G.card_neighborFinset_eq_degree] congr 1 -- Each `l ∈ N(i)` appears in `N(i)\{k}` for all `k ∈ N(i)` except `k = l`, i.e., `d_i - 1` times! have hinner : ∀ k : G.neighborFinset i, (∑ l ∈ ((G.neighborFinset i).erase k.1).attach, Real.log (m.msg ⟨(l.1, i), ((SimpleGraph.mem_neighborFinset G i l.1).mp (Finset.mem_of_mem_erase l.2)).symm⟩ a)) = (∑ l ∈ (G.neighborFinset i).attach, Real.log (m.msg ⟨(l.1, i), ((SimpleGraph.mem_neighborFinset G i l.1).mp l.2).symm⟩ a)) - Real.log (m.msg ⟨(k.1, i), ((SimpleGraph.mem_neighborFinset G i k.1).mp k.2).symm⟩ a) := by intro k have hadd := Finset.add_sum_erase (G.neighborFinset i).attach (fun l => Real.log (m.msg ⟨(l.1, i), ((SimpleGraph.mem_neighborFinset G i l.1).mp l.2).symm⟩ a)) (Finset.mem_attach _ k) have hbij : (∑ l ∈ ((G.neighborFinset i).erase k.1).attach, Real.log (m.msg ⟨(l.1, i), ((SimpleGraph.mem_neighborFinset G i l.1).mp (Finset.mem_of_mem_erase l.2)).symm⟩ a)) = ∑ l ∈ (G.neighborFinset i).attach.erase k, Real.log (m.msg ⟨(l.1, i), ((SimpleGraph.mem_neighborFinset G i l.1).mp l.2).symm⟩ a) := by refine Finset.sum_bij (fun l _ => ⟨l.1, Finset.mem_of_mem_erase l.2⟩) ?_ ?_ ?_ ?_ · intro l _; exact Finset.mem_erase.mpr ⟨fun h => Finset.ne_of_mem_erase l.2 (congrArg Subtype.val h), Finset.mem_attach _ _⟩ · intro l₁ _ l₂ _ h; exact Subtype.ext (congrArg (fun x => x.1) h) · intro l hl exact ⟨⟨l.1, Finset.mem_erase.mpr ⟨fun h => Finset.ne_of_mem_erase hl (Subtype.ext h), l.2⟩⟩, Finset.mem_attach _ _, rfl⟩ · intro _ _; rfl rw [hbij]; linarith simp_rw [hinner, Finset.sum_sub_distrib, Finset.sum_const, Finset.card_attach, nsmul_eq_mul, G.card_neighborFinset_eq_degree] ring rw [hlog_bNode, hsum_lam] dsimp only [γNode] ring · -- Edge stationarity for every `e, a, c` intro e a c have hlog_bEdge : Real.log (b.bEdge e a c) = Real.log (M.ψNode e.1.1 a) + Real.log (M.ψNode e.1.2 c) + Real.log (M.ψEdge e.1.1 e.1.2 a c) + (∑ k ∈ ((G.neighborFinset e.1.1).erase e.1.2).attach, Real.log (m.msg ⟨(k.1, e.1.1), ((SimpleGraph.mem_neighborFinset G e.1.1 k.1).mp (Finset.mem_of_mem_erase k.2)).symm⟩ a)) + (∑ l ∈ ((G.neighborFinset e.1.2).erase e.1.1).attach, Real.log (m.msg ⟨(l.1, e.1.2), ((SimpleGraph.mem_neighborFinset G e.1.2 l.1).mp (Finset.mem_of_mem_erase l.2)).symm⟩ c)) - Real.log (Zedge e) := by dsimp only [b, beliefOfBP, Zedge] have h1 : 0 < M.ψNode e.1.1 a * M.ψNode e.1.2 c := mul_pos (M.ψNode_pos _ _) (M.ψNode_pos _ _) have h2 : 0 < M.ψNode e.1.1 a * M.ψNode e.1.2 c * M.ψEdge e.1.1 e.1.2 a c := mul_pos h1 (M.ψEdge_pos _ _ _ _) have hp1 : 0 < ∏ k ∈ ((G.neighborFinset e.1.1).erase e.1.2).attach, m.msg ⟨(k.1, e.1.1), ((SimpleGraph.mem_neighborFinset G e.1.1 k.1).mp (Finset.mem_of_mem_erase k.2)).symm⟩ a := Finset.prod_pos fun _ _ => m.msg_pos _ _ have hp2 : 0 < ∏ l ∈ ((G.neighborFinset e.1.2).erase e.1.1).attach, m.msg ⟨(l.1, e.1.2), ((SimpleGraph.mem_neighborFinset G e.1.2 l.1).mp (Finset.mem_of_mem_erase l.2)).symm⟩ c := Finset.prod_pos fun _ _ => m.msg_pos _ _ rw [Real.log_div (ne_of_gt (mul_pos (mul_pos h2 hp1) hp2)) (ne_of_gt (hZe_pos e)), Real.log_mul (ne_of_gt (mul_pos h2 hp1)) (ne_of_gt hp2), Real.log_mul (ne_of_gt h2) (ne_of_gt hp1), Real.log_mul (ne_of_gt h1) (ne_of_gt (M.ψEdge_pos _ _ _ _)), Real.log_mul (ne_of_gt (M.ψNode_pos _ _)) (ne_of_gt (M.ψNode_pos _ _)), Real.log_prod (fun _ _ => ne_of_gt (m.msg_pos _ _)), Real.log_prod (fun _ _ => ne_of_gt (m.msg_pos _ _))] rw [hlog_bEdge] dsimp only [γEdge, lam] ring omit [DecidableEq X] in /-- **Headline Theorem 2F (Yedidia–Freeman–Weiss Exact 1-to-1 Bijection on Arbitrary Graphs)**: On ANY finite graph `G` (with arbitrary cycles!), the map `m ↦ ⟨beliefOfBP M m, yfw_bp_implies_betheStationary M m⟩` is a **LITERAL 1-TO-1 BIJECTION** (`Function.Bijective`) between normalized positive Sum-Product BP fixed points `BPFixedPoint M` and interior Bethe KKT stationary beliefs `{b : GraphBelief G X // IsGraphBetheStationary M b}`! -/ theorem yfw_bijection (M : PairwiseMRF G X) : Function.Bijective (fun m : BPFixedPoint M => (⟨beliefOfBP M m, yfw_bp_implies_betheStationary M m⟩ : {b : GraphBelief G X // IsGraphBetheStationary M b})) := by -- Helper: from any KKT `(b, γNode, γEdge, lam)`, construct the normalized BP fixed point -- `m_{k → i}(a) ∝ b_i(a) · exp(-lam_{k → i}(a))` and show its beliefs equal `b`! have hrecover : ∀ (b : GraphBelief G X) (γNode : V → ℝ) (γEdge : DirEdge G → ℝ) (lam : DirEdge G → X → ℝ), (∀ i a, -Real.log (M.ψNode i a) - ((G.degree i : ℝ) - 1) * (1 + Real.log (b.bNode i a)) + γNode i + ∑ k ∈ (G.neighborFinset i).attach, lam ⟨(k.1, i), ((SimpleGraph.mem_neighborFinset G i k.1).mp k.2).symm⟩ a = 0) → (∀ (e : DirEdge G) a c, -Real.log (M.ψEdge e.1.1 e.1.2 a c) + (1 + Real.log (b.bEdge e a c)) + γEdge e - (lam e c + lam ⟨(e.1.2, e.1.1), e.2.symm⟩ a) = 0) → ∃ m : BPFixedPoint M, (∀ e a, m.msg e a = (b.bNode e.1.2 a * Real.exp (-lam e a)) / ∑ y : X, b.bNode e.1.2 y * Real.exp (-lam e y)) ∧ beliefOfBP M m = b := by intro b γNode γEdge lam hnode hedge let rawM : DirEdge G → X → ℝ := fun e a => b.bNode e.1.2 a * Real.exp (-lam e a) have hrawM_pos : ∀ e a, 0 < rawM e a := fun e a => mul_pos (b.bNode_pos _ _) (Real.exp_pos _) let Zm : DirEdge G → ℝ := fun e => ∑ y : X, rawM e y have hZm_pos : ∀ e, 0 < Zm e := fun e => Finset.sum_pos (fun y _ => hrawM_pos e y) Finset.univ_nonempty let mFn : DirEdge G → X → ℝ := fun e a => rawM e a / Zm e -- Key algebraic identity from `hnode`: -- `M.ψNode i a * ∏_{k ∈ N(i)\{j}} rawM_{k → i}(a) = exp(C_i) * exp(lam_{j → i}(a))`! have hnode_prod : ∀ (e : DirEdge G) (xi : X), M.ψNode e.1.1 xi * (∏ k ∈ ((G.neighborFinset e.1.1).erase e.1.2).attach, rawM ⟨(k.1, e.1.1), ((SimpleGraph.mem_neighborFinset G e.1.1 k.1).mp (Finset.mem_of_mem_erase k.2)).symm⟩ xi) = Real.exp (γNode e.1.1 - ((G.degree e.1.1 : ℝ) - 1)) * Real.exp (lam ⟨(e.1.2, e.1.1), e.2.symm⟩ xi) := by intro e xi let i := e.1.1 let j := e.1.2 have hj_mem : j ∈ G.neighborFinset i := (SimpleGraph.mem_neighborFinset G i j).mpr e.2 have hcard_er : ((G.neighborFinset i).erase j).card = G.degree i - 1 := by have h1 := Finset.card_erase_add_one hj_mem rw [G.card_neighborFinset_eq_degree] at h1; omega have hdeg_ge1 : 1 ≤ G.degree i := by rw [← G.card_neighborFinset_eq_degree] exact Finset.card_pos.mpr ⟨j, hj_mem⟩ -- Take log of both sides! have hlhs_pos : 0 < M.ψNode i xi * ∏ k ∈ ((G.neighborFinset i).erase j).attach, rawM ⟨(k.1, i), ((SimpleGraph.mem_neighborFinset G i k.1).mp (Finset.mem_of_mem_erase k.2)).symm⟩ xi := mul_pos (M.ψNode_pos i xi) (Finset.prod_pos fun _ _ => hrawM_pos _ _) apply Real.log_injOn_pos hlhs_pos (mul_pos (Real.exp_pos _) (Real.exp_pos _)) rw [Real.log_mul (ne_of_gt (M.ψNode_pos i xi)) (ne_of_gt (Finset.prod_pos fun _ _ => hrawM_pos _ _)), Real.log_prod (fun _ _ => ne_of_gt (hrawM_pos _ _)), Real.log_mul (ne_of_gt (Real.exp_pos _)) (ne_of_gt (Real.exp_pos _)), Real.log_exp, Real.log_exp] have hlog_raw : ∀ k ∈ ((G.neighborFinset i).erase j).attach, Real.log (rawM ⟨(k.1, i), ((SimpleGraph.mem_neighborFinset G i k.1).mp (Finset.mem_of_mem_erase k.2)).symm⟩ xi) = Real.log (b.bNode i xi) - lam ⟨(k.1, i), ((SimpleGraph.mem_neighborFinset G i k.1).mp (Finset.mem_of_mem_erase k.2)).symm⟩ xi := by intro k _ dsimp only [rawM] rw [Real.log_mul (ne_of_gt (b.bNode_pos i xi)) (ne_of_gt (Real.exp_pos _)), Real.log_exp] ring rw [Finset.sum_congr rfl hlog_raw, Finset.sum_sub_distrib, Finset.sum_const, Finset.card_attach, nsmul_eq_mul, hcard_er] -- Split full neighbor sum of `lam` at `j` have hsum_split : (∑ k ∈ (G.neighborFinset i).attach, lam ⟨(k.1, i), ((SimpleGraph.mem_neighborFinset G i k.1).mp k.2).symm⟩ xi) = lam ⟨(j, i), e.2.symm⟩ xi + ∑ k ∈ ((G.neighborFinset i).erase j).attach, lam ⟨(k.1, i), ((SimpleGraph.mem_neighborFinset G i k.1).mp (Finset.mem_of_mem_erase k.2)).symm⟩ xi := by rw [← Finset.add_sum_erase (G.neighborFinset i).attach _ (Finset.mem_attach _ ⟨j, hj_mem⟩)] congr 1 refine (Finset.sum_bij (fun k _ => ⟨k.1, Finset.mem_of_mem_erase k.2⟩) ?_ ?_ ?_ ?_).symm · intro k _; exact Finset.mem_erase.mpr ⟨fun h => Finset.ne_of_mem_erase k.2 (congrArg Subtype.val h), Finset.mem_attach _ _⟩ · intro k₁ _ k₂ _ h; exact Subtype.ext (congrArg (fun x => x.1) h) · intro k hk have hne : k.1 ≠ j := fun h => Finset.ne_of_mem_erase hk (Subtype.ext h) exact ⟨⟨k.1, Finset.mem_erase.mpr ⟨hne, k.2⟩⟩, Finset.mem_attach _ _, rfl⟩ · intro _ _; rfl have hcast : ((G.degree i - 1 : ℕ) : ℝ) = (G.degree i : ℝ) - 1 := by rw [Nat.cast_sub hdeg_ge1, Nat.cast_one] have hni := hnode i xi rw [hsum_split] at hni rw [hcast] have hexp_n : ((G.degree i : ℝ) - 1) * (1 + Real.log (b.bNode i xi)) = ((G.degree i : ℝ) - 1) + ((G.degree i : ℝ) - 1) * Real.log (b.bNode i xi) := by ring rw [hexp_n] at hni linarith -- Key algebraic identity from `hedge`: -- `b.bEdge e a c = exp(-1 - γEdge e) * M.ψEdge i j a c * exp(lam e c) * exp(lam eRev a)`! have hedge_exp : ∀ (e : DirEdge G) (a c : X), b.bEdge e a c = Real.exp (-1 - γEdge e) * M.ψEdge e.1.1 e.1.2 a c * Real.exp (lam e c) * Real.exp (lam ⟨(e.1.2, e.1.1), e.2.symm⟩ a) := by intro e a c apply Real.log_injOn_pos (b.bEdge_pos e a c) (mul_pos (mul_pos (mul_pos (Real.exp_pos _) (M.ψEdge_pos _ _ _ _)) (Real.exp_pos _)) (Real.exp_pos _)) rw [Real.log_mul (ne_of_gt (mul_pos (mul_pos (Real.exp_pos _) (M.ψEdge_pos _ _ _ _)) (Real.exp_pos _))) (ne_of_gt (Real.exp_pos _)), Real.log_mul (ne_of_gt (mul_pos (Real.exp_pos _) (M.ψEdge_pos _ _ _ _))) (ne_of_gt (Real.exp_pos _)), Real.log_mul (ne_of_gt (Real.exp_pos _)) (ne_of_gt (M.ψEdge_pos _ _ _ _)), Real.log_exp, Real.log_exp, Real.log_exp] linarith [hedge e a c] -- Show `mFn` satisfies the BP fixed-point equation! have hfixed : ∀ (e : DirEdge G) (xj : X), let raw (y : X) : ℝ := ∑ xi : X, M.ψNode e.1.1 xi * M.ψEdge e.1.1 e.1.2 xi y * ∏ k ∈ ((G.neighborFinset e.1.1).erase e.1.2).attach, mFn ⟨(k.1, e.1.1), ((SimpleGraph.mem_neighborFinset G e.1.1 k.1).mp (Finset.mem_of_mem_erase k.2)).symm⟩ xi mFn e xj = raw xj / ∑ y : X, raw y := by intro e xj dsimp only let Zprod : ℝ := ∏ k ∈ ((G.neighborFinset e.1.1).erase e.1.2).attach, Zm ⟨(k.1, e.1.1), ((SimpleGraph.mem_neighborFinset G e.1.1 k.1).mp (Finset.mem_of_mem_erase k.2)).symm⟩ have hZp_pos : 0 < Zprod := Finset.prod_pos fun _ _ => hZm_pos _ -- Express `raw y` as a positive constant (independent of `y`) times `rawM e y`! let Cconst : ℝ := Real.exp (γNode e.1.1 - ((G.degree e.1.1 : ℝ) - 1)) / (Zprod * Real.exp (-1 - γEdge e)) have hC_pos : 0 < Cconst := div_pos (Real.exp_pos _) (mul_pos hZp_pos (Real.exp_pos _)) have hraw_eq : ∀ y : X, (∑ xi : X, M.ψNode e.1.1 xi * M.ψEdge e.1.1 e.1.2 xi y * ∏ k ∈ ((G.neighborFinset e.1.1).erase e.1.2).attach, mFn ⟨(k.1, e.1.1), ((SimpleGraph.mem_neighborFinset G e.1.1 k.1).mp (Finset.mem_of_mem_erase k.2)).symm⟩ xi) = Cconst * rawM e y := by intro y have hterm : ∀ xi : X, M.ψNode e.1.1 xi * M.ψEdge e.1.1 e.1.2 xi y * (∏ k ∈ ((G.neighborFinset e.1.1).erase e.1.2).attach, mFn ⟨(k.1, e.1.1), ((SimpleGraph.mem_neighborFinset G e.1.1 k.1).mp (Finset.mem_of_mem_erase k.2)).symm⟩ xi) = Cconst * Real.exp (-lam e y) * b.bEdge e xi y := by intro xi dsimp only [mFn] rw [Finset.prod_div_distrib] have hnp := hnode_prod e xi have hep := hedge_exp e xi y have hne_zp : Zprod ≠ 0 := ne_of_gt hZp_pos have hne_e1 : Real.exp (-1 - γEdge e) ≠ 0 := ne_of_gt (Real.exp_pos _) have hne_lam : Real.exp (lam e y) ≠ 0 := ne_of_gt (Real.exp_pos _) have hinv_lam : Real.exp (-lam e y) * Real.exp (lam e y) = 1 := by rw [← Real.exp_add, neg_add_cancel, Real.exp_zero] dsimp only [Cconst] calc M.ψNode e.1.1 xi * M.ψEdge e.1.1 e.1.2 xi y * ((∏ k ∈ ((G.neighborFinset e.1.1).erase e.1.2).attach, rawM _ xi) / Zprod) = (M.ψNode e.1.1 xi * ∏ k ∈ ((G.neighborFinset e.1.1).erase e.1.2).attach, rawM _ xi) * M.ψEdge e.1.1 e.1.2 xi y / Zprod := by ring _ = Real.exp (γNode e.1.1 - ((G.degree e.1.1 : ℝ) - 1)) * Real.exp (lam ⟨(e.1.2, e.1.1), e.2.symm⟩ xi) * M.ψEdge e.1.1 e.1.2 xi y / Zprod := by rw [hnp] _ = Real.exp (γNode e.1.1 - ((G.degree e.1.1 : ℝ) - 1)) / (Zprod * Real.exp (-1 - γEdge e)) * Real.exp (-lam e y) * (Real.exp (-1 - γEdge e) * M.ψEdge e.1.1 e.1.2 xi y * Real.exp (lam e y) * Real.exp (lam ⟨(e.1.2, e.1.1), e.2.symm⟩ xi)) := by have := congrArg (fun t => t * (Real.exp (γNode e.1.1 - ((G.degree e.1.1 : ℝ) - 1)) * Real.exp (lam ⟨(e.1.2, e.1.1), e.2.symm⟩ xi) * M.ψEdge e.1.1 e.1.2 xi y / Zprod)) hinv_lam field_simp [hne_zp, hne_e1, hne_lam] at this ⊢ linarith _ = Cconst * Real.exp (-lam e y) * b.bEdge e xi y := by rw [← hep] simp_rw [hterm, ← Finset.mul_sum] have hmarg_r : ∑ xi : X, b.bEdge e xi y = b.bNode e.1.2 y := by have hm := b.bEdge_marg ⟨(e.1.2, e.1.1), e.2.symm⟩ y simpa [b.bEdge_symm] using hm rw [hmarg_r]; dsimp only [rawM]; ring simp_rw [hraw_eq, ← Finset.mul_sum, mul_div_mul_left _ _ (ne_of_gt hC_pos)] rfl let m : BPFixedPoint M := { msg := mFn msg_pos := fun e a => div_pos (hrawM_pos e a) (hZm_pos e) msg_sum := fun e => by dsimp only [mFn, Zm] rw [← Finset.sum_div, div_self (ne_of_gt (hZm_pos e))] fixed := hfixed } refine ⟨m, fun _ _ => rfl, ?_⟩ -- Prove `beliefOfBP M m = b`! refine GraphBelief.ext ?_ ?_ · funext i xi -- Node beliefs match `b.bNode i xi` dsimp only [beliefOfBP, m, mFn] -- Show `M.ψNode i a * ∏_{k ∈ N(i)} mFn_{k → i}(a) = C_i * b.bNode i a`! let Zprod_i : ℝ := ∏ k ∈ (G.neighborFinset i).attach, Zm ⟨(k.1, i), ((SimpleGraph.mem_neighborFinset G i k.1).mp k.2).symm⟩ have hZpi_pos : 0 < Zprod_i := Finset.prod_pos fun _ _ => hZm_pos _ let Ci : ℝ := Real.exp (γNode i - ((G.degree i : ℝ) - 1)) / Zprod_i have hCi_pos : 0 < Ci := div_pos (Real.exp_pos _) hZpi_pos have hprop_node : ∀ a : X, M.ψNode i a * (∏ k ∈ (G.neighborFinset i).attach, rawM ⟨(k.1, i), ((SimpleGraph.mem_neighborFinset G i k.1).mp k.2).symm⟩ a / Zm ⟨(k.1, i), ((SimpleGraph.mem_neighborFinset G i k.1).mp k.2).symm⟩) = Ci * b.bNode i a := by intro a rw [Finset.prod_div_distrib] have hlhs_pos : 0 < M.ψNode i a * ((∏ k ∈ (G.neighborFinset i).attach, rawM ⟨(k.1, i), ((SimpleGraph.mem_neighborFinset G i k.1).mp k.2).symm⟩ a) / Zprod_i) := mul_pos (M.ψNode_pos i a) (div_pos (Finset.prod_pos fun _ _ => hrawM_pos _ _) hZpi_pos) apply Real.log_injOn_pos hlhs_pos (mul_pos hCi_pos (b.bNode_pos i a)) rw [Real.log_mul (ne_of_gt (M.ψNode_pos i a)) (ne_of_gt (div_pos (Finset.prod_pos fun _ _ => hrawM_pos _ _) hZpi_pos)), Real.log_div (ne_of_gt (Finset.prod_pos fun _ _ => hrawM_pos _ _)) (ne_of_gt hZpi_pos), Real.log_prod (fun _ _ => ne_of_gt (hrawM_pos _ _)), Real.log_mul (ne_of_gt hCi_pos) (ne_of_gt (b.bNode_pos i a))] dsimp only [Ci] rw [Real.log_div (ne_of_gt (Real.exp_pos _)) (ne_of_gt hZpi_pos), Real.log_exp] have hlog_raw : ∀ k ∈ (G.neighborFinset i).attach, Real.log (rawM ⟨(k.1, i), ((SimpleGraph.mem_neighborFinset G i k.1).mp k.2).symm⟩ a) = Real.log (b.bNode i a) - lam ⟨(k.1, i), ((SimpleGraph.mem_neighborFinset G i k.1).mp k.2).symm⟩ a := by intro k _ dsimp only [rawM] rw [Real.log_mul (ne_of_gt (b.bNode_pos i a)) (ne_of_gt (Real.exp_pos _)), Real.log_exp] ring rw [Finset.sum_congr rfl hlog_raw, Finset.sum_sub_distrib, Finset.sum_const, Finset.card_attach, nsmul_eq_mul, G.card_neighborFinset_eq_degree] have hni := hnode i a have hexp_n : ((G.degree i : ℝ) - 1) * (1 + Real.log (b.bNode i a)) = ((G.degree i : ℝ) - 1) + (G.degree i : ℝ) * Real.log (b.bNode i a) - Real.log (b.bNode i a) := by ring rw [hexp_n] at hni linarith simp_rw [hprop_node, ← Finset.mul_sum, b.bNode_sum i, mul_one, mul_div_cancel_left₀ _ (ne_of_gt hCi_pos)] · funext e a c -- Edge beliefs match `b.bEdge e a c` dsimp only [beliefOfBP, m, mFn] let Zpi : ℝ := ∏ k ∈ ((G.neighborFinset e.1.1).erase e.1.2).attach, Zm ⟨(k.1, e.1.1), ((SimpleGraph.mem_neighborFinset G e.1.1 k.1).mp (Finset.mem_of_mem_erase k.2)).symm⟩ let Zpj : ℝ := ∏ l ∈ ((G.neighborFinset e.1.2).erase e.1.1).attach, Zm ⟨(l.1, e.1.2), ((SimpleGraph.mem_neighborFinset G e.1.2 l.1).mp (Finset.mem_of_mem_erase l.2)).symm⟩ have hZpi_pos : 0 < Zpi := Finset.prod_pos fun _ _ => hZm_pos _ have hZpj_pos : 0 < Zpj := Finset.prod_pos fun _ _ => hZm_pos _ let Ce : ℝ := (Real.exp (γNode e.1.1 - ((G.degree e.1.1 : ℝ) - 1)) * Real.exp (γNode e.1.2 - ((G.degree e.1.2 : ℝ) - 1))) / (Zpi * Zpj * Real.exp (-1 - γEdge e)) have hCe_pos : 0 < Ce := div_pos (mul_pos (Real.exp_pos _) (Real.exp_pos _)) (mul_pos (mul_pos hZpi_pos hZpj_pos) (Real.exp_pos _)) have hprop_edge : ∀ u v : X, M.ψNode e.1.1 u * M.ψNode e.1.2 v * M.ψEdge e.1.1 e.1.2 u v * (∏ k ∈ ((G.neighborFinset e.1.1).erase e.1.2).attach, rawM ⟨(k.1, e.1.1), ((SimpleGraph.mem_neighborFinset G e.1.1 k.1).mp (Finset.mem_of_mem_erase k.2)).symm⟩ u / Zm ⟨(k.1, e.1.1), ((SimpleGraph.mem_neighborFinset G e.1.1 k.1).mp (Finset.mem_of_mem_erase k.2)).symm⟩) * (∏ l ∈ ((G.neighborFinset e.1.2).erase e.1.1).attach, rawM ⟨(l.1, e.1.2), ((SimpleGraph.mem_neighborFinset G e.1.2 l.1).mp (Finset.mem_of_mem_erase l.2)).symm⟩ v / Zm ⟨(l.1, e.1.2), ((SimpleGraph.mem_neighborFinset G e.1.2 l.1).mp (Finset.mem_of_mem_erase l.2)).symm⟩) = Ce * b.bEdge e u v := by intro u v rw [Finset.prod_div_distrib, Finset.prod_div_distrib] have hnp1 := hnode_prod e u have hnp2 := hnode_prod ⟨(e.1.2, e.1.1), e.2.symm⟩ v have hep := hedge_exp e u v dsimp only [Ce] have hne1 : Zpi ≠ 0 := ne_of_gt hZpi_pos have hne2 : Zpj ≠ 0 := ne_of_gt hZpj_pos have hne3 : Real.exp (-1 - γEdge e) ≠ 0 := ne_of_gt (Real.exp_pos _) calc M.ψNode e.1.1 u * M.ψNode e.1.2 v * M.ψEdge e.1.1 e.1.2 u v * ((∏ k ∈ ((G.neighborFinset e.1.1).erase e.1.2).attach, rawM _ u) / Zpi) * ((∏ l ∈ ((G.neighborFinset e.1.2).erase e.1.1).attach, rawM _ v) / Zpj) = (M.ψNode e.1.1 u * ∏ k ∈ ((G.neighborFinset e.1.1).erase e.1.2).attach, rawM _ u) * (M.ψNode e.1.2 v * ∏ l ∈ ((G.neighborFinset e.1.2).erase e.1.1).attach, rawM _ v) * M.ψEdge e.1.1 e.1.2 u v / (Zpi * Zpj) := by ring _ = (Real.exp (γNode e.1.1 - ((G.degree e.1.1 : ℝ) - 1)) * Real.exp (lam ⟨(e.1.2, e.1.1), e.2.symm⟩ u)) * (Real.exp (γNode e.1.2 - ((G.degree e.1.2 : ℝ) - 1)) * Real.exp (lam e v)) * M.ψEdge e.1.1 e.1.2 u v / (Zpi * Zpj) := by rw [hnp1, hnp2] _ = (Real.exp (γNode e.1.1 - ((G.degree e.1.1 : ℝ) - 1)) * Real.exp (γNode e.1.2 - ((G.degree e.1.2 : ℝ) - 1))) / (Zpi * Zpj * Real.exp (-1 - γEdge e)) * (Real.exp (-1 - γEdge e) * M.ψEdge e.1.1 e.1.2 u v * Real.exp (lam e v) * Real.exp (lam ⟨(e.1.2, e.1.1), e.2.symm⟩ u)) := by field_simp [hne1, hne2, hne3] _ = _ := by rw [← hep] have hb_sum : ∑ u : X, ∑ v : X, b.bEdge e u v = 1 := by simp_rw [b.bEdge_marg e]; exact b.bNode_sum e.1.1 simp_rw [hprop_edge, ← Finset.mul_sum, hb_sum, mul_one, mul_div_cancel_left₀ _ (ne_of_gt hCe_pos)] -- Now prove Bijective = Injective ∧ Surjective! constructor · -- **Injectivity**: if `beliefOfBP M m₁ = beliefOfBP M m₂`, their induced KKT multipliers -- differ by edge-constants, so `m₁ = m₂`! intro m₁ m₂ heq_sub have hbel : beliefOfBP M m₁ = beliefOfBP M m₂ := congrArg Subtype.val heq_sub -- Define the canonical multipliers `lam₁, lam₂` for `m₁, m₂` let lamOf (m : BPFixedPoint M) (e : DirEdge G) (xj : X) : ℝ := Real.log (M.ψNode e.1.2 xj) + ∑ l ∈ ((G.neighborFinset e.1.2).erase e.1.1).attach, Real.log (m.msg ⟨(l.1, e.1.2), ((SimpleGraph.mem_neighborFinset G e.1.2 l.1).mp (Finset.mem_of_mem_erase l.2)).symm⟩ xj) -- For each `m`, `(beliefOfBP M m).bNode e.1.2 y * exp(-lamOf m e y) ∝ m.msg e y`! have hmsg_rec : ∀ (m : BPFixedPoint M) (e : DirEdge G) (y : X), m.msg e y = ((beliefOfBP M m).bNode e.1.2 y * Real.exp (-lamOf m e y)) / ∑ y' : X, (beliefOfBP M m).bNode e.1.2 y' * Real.exp (-lamOf m e y') := by intro m e y let j := e.1.2 let i := e.1.1 let Zj : ℝ := ∑ a : X, M.ψNode j a * ∏ k ∈ (G.neighborFinset j).attach, m.msg ⟨(k.1, j), ((SimpleGraph.mem_neighborFinset G j k.1).mp k.2).symm⟩ a have hZj_pos : 0 < Zj := Finset.sum_pos (fun a _ => mul_pos (M.ψNode_pos j a) (Finset.prod_pos fun _ _ => m.msg_pos _ _)) Finset.univ_nonempty have hterm : ∀ a : X, (beliefOfBP M m).bNode e.1.2 a * Real.exp (-lamOf m e a) = m.msg e a / Zj := by intro a dsimp only [beliefOfBP, lamOf, Zj] have hi_mem : i ∈ G.neighborFinset j := (SimpleGraph.mem_neighborFinset G j i).mpr e.2.symm have hprod_split : (∏ k ∈ (G.neighborFinset j).attach, m.msg ⟨(k.1, j), ((SimpleGraph.mem_neighborFinset G j k.1).mp k.2).symm⟩ a) = m.msg e a * ∏ l ∈ ((G.neighborFinset j).erase i).attach, m.msg ⟨(l.1, j), ((SimpleGraph.mem_neighborFinset G j l.1).mp (Finset.mem_of_mem_erase l.2)).symm⟩ a := by rw [← Finset.mul_prod_erase (G.neighborFinset j).attach _ (Finset.mem_attach _ ⟨i, hi_mem⟩)] congr 1 refine Finset.prod_bij (fun k hk => ⟨k.1, Finset.mem_erase.mpr ⟨fun h => Finset.ne_of_mem_erase hk (Subtype.ext h), k.2⟩⟩) ?_ ?_ ?_ ?_ · intro _ _; exact Finset.mem_attach _ _ · intro k₁ _ k₂ _ h; exact Subtype.ext (congrArg (fun x => x.1) h) · intro k _ exact ⟨⟨k.1, Finset.mem_of_mem_erase k.2⟩, Finset.mem_erase.mpr ⟨fun h => Finset.ne_of_mem_erase k.2 (congrArg Subtype.val h), Finset.mem_attach _ _⟩, rfl⟩ · intro _ _; rfl have hexp_lam : Real.exp (lamOf m e a) = M.ψNode j a * ∏ l ∈ ((G.neighborFinset j).erase i).attach, m.msg ⟨(l.1, j), ((SimpleGraph.mem_neighborFinset G j l.1).mp (Finset.mem_of_mem_erase l.2)).symm⟩ a := by dsimp only [lamOf] rw [Real.exp_add, Real.exp_log (M.ψNode_pos j a), Real.exp_sum] congr 1 refine Finset.prod_congr rfl fun l _ => Real.exp_log (m.msg_pos _ a) have hne_exp : Real.exp (lamOf m e a) ≠ 0 := ne_of_gt (Real.exp_pos _) have hinv : Real.exp (-lamOf m e a) = (Real.exp (lamOf m e a))⁻¹ := Real.exp_neg _ rw [hprod_split] change (M.ψNode j a * (m.msg e a * ∏ l ∈ ((G.neighborFinset j).erase i).attach, m.msg ⟨(l.1, j), ((SimpleGraph.mem_neighborFinset G j l.1).mp (Finset.mem_of_mem_erase l.2)).symm⟩ a) / Zj) * Real.exp (-lamOf m e a) = m.msg e a / Zj rw [hinv, hexp_lam] have hne_ψ : M.ψNode j a ≠ 0 := ne_of_gt (M.ψNode_pos j a) have hne_p : (∏ l ∈ ((G.neighborFinset j).erase i).attach, m.msg ⟨(l.1, j), ((SimpleGraph.mem_neighborFinset G j l.1).mp (Finset.mem_of_mem_erase l.2)).symm⟩ a) ≠ 0 := ne_of_gt (Finset.prod_pos fun _ _ => m.msg_pos _ _) field_simp [hne_ψ, hne_p, ne_of_gt hZj_pos] simp_rw [hterm, ← Finset.sum_div, m.msg_sum e, div_div_div_cancel_right₀ (ne_of_gt hZj_pos), div_one] -- From edge beliefs equality `(beliefOfBP M m₁).bEdge e a c = (beliefOfBP M m₂).bEdge e a c`, -- `lamOf m₁ e c - lamOf m₂ e c` is CONSTANT in `c`! have hlam_const : ∀ (e : DirEdge G), ∃ const_e : ℝ, ∀ c : X, lamOf m₁ e c - lamOf m₂ e c = const_e := by intro e obtain ⟨a0⟩ := (inferInstance : Nonempty X) -- Compare `log (bEdge e a0 c)` for `m₁` and `m₂`! have hlog_edge : ∀ (m : BPFixedPoint M), ∃ C : ℝ, ∀ a c : X, Real.log ((beliefOfBP M m).bEdge e a c) = Real.log (M.ψEdge e.1.1 e.1.2 a c) + lamOf m e c + lamOf m ⟨(e.1.2, e.1.1), e.2.symm⟩ a - C := by intro m let Ze : ℝ := ∑ u : X, ∑ v : X, M.ψNode e.1.1 u * M.ψNode e.1.2 v * M.ψEdge e.1.1 e.1.2 u v * (∏ k ∈ ((G.neighborFinset e.1.1).erase e.1.2).attach, m.msg ⟨(k.1, e.1.1), ((SimpleGraph.mem_neighborFinset G e.1.1 k.1).mp (Finset.mem_of_mem_erase k.2)).symm⟩ u) * (∏ l ∈ ((G.neighborFinset e.1.2).erase e.1.1).attach, m.msg ⟨(l.1, e.1.2), ((SimpleGraph.mem_neighborFinset G e.1.2 l.1).mp (Finset.mem_of_mem_erase l.2)).symm⟩ v) have hZe_pos : 0 < Ze := Finset.sum_pos (fun u _ => Finset.sum_pos (fun v _ => mul_pos (mul_pos (mul_pos (mul_pos (M.ψNode_pos _ _) (M.ψNode_pos _ _)) (M.ψEdge_pos _ _ _ _)) (Finset.prod_pos fun _ _ => m.msg_pos _ _)) (Finset.prod_pos fun _ _ => m.msg_pos _ _)) Finset.univ_nonempty) Finset.univ_nonempty refine ⟨Real.log Ze, fun a c => ?_⟩ dsimp only [beliefOfBP, lamOf, Ze] have h1 : 0 < M.ψNode e.1.1 a * M.ψNode e.1.2 c := mul_pos (M.ψNode_pos _ _) (M.ψNode_pos _ _) have h2 : 0 < M.ψNode e.1.1 a * M.ψNode e.1.2 c * M.ψEdge e.1.1 e.1.2 a c := mul_pos h1 (M.ψEdge_pos _ _ _ _) have hp1 : 0 < ∏ k ∈ ((G.neighborFinset e.1.1).erase e.1.2).attach, m.msg ⟨(k.1, e.1.1), ((SimpleGraph.mem_neighborFinset G e.1.1 k.1).mp (Finset.mem_of_mem_erase k.2)).symm⟩ a := Finset.prod_pos fun _ _ => m.msg_pos _ _ have hp2 : 0 < ∏ l ∈ ((G.neighborFinset e.1.2).erase e.1.1).attach, m.msg ⟨(l.1, e.1.2), ((SimpleGraph.mem_neighborFinset G e.1.2 l.1).mp (Finset.mem_of_mem_erase l.2)).symm⟩ c := Finset.prod_pos fun _ _ => m.msg_pos _ _ rw [Real.log_div (ne_of_gt (mul_pos (mul_pos h2 hp1) hp2)) (ne_of_gt hZe_pos), Real.log_mul (ne_of_gt (mul_pos h2 hp1)) (ne_of_gt hp2), Real.log_mul (ne_of_gt h2) (ne_of_gt hp1), Real.log_mul (ne_of_gt h1) (ne_of_gt (M.ψEdge_pos _ _ _ _)), Real.log_mul (ne_of_gt (M.ψNode_pos _ _)) (ne_of_gt (M.ψNode_pos _ _)), Real.log_prod (fun _ _ => ne_of_gt (m.msg_pos _ _)), Real.log_prod (fun _ _ => ne_of_gt (m.msg_pos _ _))] ring obtain ⟨C1, hC1⟩ := hlog_edge m₁ obtain ⟨C2, hC2⟩ := hlog_edge m₂ refine ⟨(C1 - C2) - (lamOf m₁ ⟨(e.1.2, e.1.1), e.2.symm⟩ a0 - lamOf m₂ ⟨(e.1.2, e.1.1), e.2.symm⟩ a0), fun c => ?_⟩ have heq_c : Real.log ((beliefOfBP M m₁).bEdge e a0 c) = Real.log ((beliefOfBP M m₂).bEdge e a0 c) := by rw [hbel] rw [hC1 a0 c, hC2 a0 c] at heq_c linarith ext e y obtain ⟨const_e, hconst⟩ := hlam_const e rw [hmsg_rec m₁ e y, hmsg_rec m₂ e y, hbel] have hshift : ∀ a : X, Real.exp (-lamOf m₁ e a) = Real.exp (-const_e) * Real.exp (-lamOf m₂ e a) := by intro a rw [← Real.exp_add] congr 1; linarith [hconst a] simp_rw [hshift] have hpull : ∀ a : X, (beliefOfBP M m₂).bNode e.1.2 a * (Real.exp (-const_e) * Real.exp (-lamOf m₂ e a)) = Real.exp (-const_e) * ((beliefOfBP M m₂).bNode e.1.2 a * Real.exp (-lamOf m₂ e a)) := fun a => by ring simp_rw [hpull, ← Finset.mul_sum, mul_div_mul_left _ _ (ne_of_gt (Real.exp_pos _))] · -- **Surjectivity**: direct from `hrecover`! rintro ⟨b, γNode, γEdge, lam, hnode, hedge⟩ obtain ⟨m, _, hm_bel⟩ := hrecover b γNode γEdge lam hnode hedge exact ⟨m, Subtype.ext hm_bel⟩ end YedidiaFreemanWeiss /-! ## Section 5: Unicyclic Convexity vs. `K_4` Non-Convexity, Bethe Gaps on `K_3`/`C_4`, & Kikuchi Exactness -/ section KikuchiAndWitnesses /-- **Unicyclic Convexity Theorem (Heskes / Pakzad–Anantharam)**: On ANY graph `G` whose edges admit a bijection with vertices assigning each edge `{i, j}` an orientation `i ↦ succ(i)` (specifically EVERY single cycle `C_n`, `n ≥ 3`, including `K_3 = C_3` and `C_4`!), `H_Bethe(b) = ∑_i (H(b_{i, succ(i)}) - H(b_i))` is a sum of conditional entropies, hence **globally concave** (so `F_Bethe` is **globally convex**) on `L°(G)`! -/ theorem single_cycle_betheEntropy_concave {n : ℕ} (_hn : 3 ≤ n) {X : Type*} [Fintype X] [DecidableEq X] [Nonempty X] (b₁ b₂ : Fin n → X → X → ℝ) (hb₁ : ∀ i a c, 0 < b₁ i a c) (hb₂ : ∀ i a c, 0 < b₂ i a c) (hs₁ : ∀ i, ∑ a : X, ∑ c : X, b₁ i a c = 1) (hs₂ : ∀ i, ∑ a : X, ∑ c : X, b₂ i a c = 1) {t : ℝ} (ht0 : 0 ≤ t) (ht1 : t ≤ 1) : let Hcycle (b : Fin n → X → X → ℝ) : ℝ := ∑ i : Fin n, (shannonH (fun p : X × X => b i p.1 p.2) - shannonH (fun a => ∑ c : X, b i a c)) (1 - t) * Hcycle b₁ + t * Hcycle b₂ ≤ Hcycle (fun i a c => (1 - t) * b₁ i a c + t * b₂ i a c) := by intro Hcycle dsimp only [Hcycle] rw [Finset.mul_sum, Finset.mul_sum, ← Finset.sum_add_distrib] refine Finset.sum_le_sum fun i _ => conditionalEntropy_concave (hb₁ i) (hb₂ i) (hs₁ i) (hs₂ i) ht0 ht1 /-- Helper: binary entropy `H₂(p) = -p log p - (1 - p) log (1 - p)`. -/ noncomputable def binH (p : ℝ) : ℝ := -(p * Real.log p + (1 - p) * Real.log (1 - p)) /-- **Headline Theorem 2G (Exact Bethe vs. True `log Z` Gap on `K_3` and `C_4`)**: For the zero-field ferromagnetic Ising model on `K_3 = C_3` and `C_4` with ANY coupling `J > 0`: - True `Z_{K_3}(J) = 2 e^(3J) + 6 e^(-J) = (2 cosh J)³ (1 + tanh³ J)`; - True `Z_{C_4}(J) = 2 (e^(4J) + e^(-4J) + 6) = (2 cosh J)⁴ (1 + tanh⁴ J)`; - Symmetric BP / Bethe log-partition estimate is `n · log (2 cosh J)`; - Exact strictly positive Bethe error gap: `log Z_{K_3}(J) - 3 log(2 cosh J) = log(1 + tanh³ J) > 0`, `log Z_{C_4}(J) - 4 log(2 cosh J) = log(1 + tanh⁴ J) > 0`! -/ theorem bethe_vs_true_logZ_gap_K3 {J : ℝ} (hJ : 0 < J) : let Z_K3 := 2 * Real.exp (3 * J) + 6 * Real.exp (-J) let logZ_Bethe := 3 * Real.log (2 * Real.cosh J) Real.log Z_K3 - logZ_Bethe = Real.log (1 + (Real.tanh J) ^ 3) ∧ 0 < Real.log Z_K3 - logZ_Bethe := by intro Z_K3 logZ_Bethe have hc_pos : 0 < 2 * Real.cosh J := mul_pos two_pos (Real.cosh_pos J) have ht_pos : 0 < Real.tanh J := by rw [Real.tanh_eq_sinh_div_cosh] exact div_pos (Real.sinh_pos_iff.mpr hJ) (Real.cosh_pos J) have hfac : Z_K3 = (2 * Real.cosh J) ^ 3 * (1 + (Real.tanh J) ^ 3) := by dsimp only [Z_K3] have h1 : (2 * Real.cosh J) ^ 3 * (1 + (Real.tanh J) ^ 3) = (2 * Real.cosh J) ^ 3 + (2 * Real.sinh J) ^ 3 := by rw [Real.tanh_eq_sinh_div_cosh] have hc : Real.cosh J ≠ 0 := ne_of_gt (Real.cosh_pos J) field_simp [hc] rw [h1, Real.cosh_eq, Real.sinh_eq] have hexp3 : Real.exp J ^ 3 = Real.exp (3 * J) := by rw [← Real.exp_nat_mul, Nat.cast_ofNat] have hexp_m : Real.exp (-J) * Real.exp J = 1 := by rw [← Real.exp_add, neg_add_cancel, Real.exp_zero] have hexp_m3 : Real.exp (-J) ^ 3 = Real.exp (-3 * J) := by rw [← Real.exp_nat_mul]; congr 1; ring have hexp_sq : Real.exp J ^ 2 * Real.exp (-J) = Real.exp J := by calc Real.exp J ^ 2 * Real.exp (-J) = Real.exp J * (Real.exp (-J) * Real.exp J) := by ring _ = Real.exp J := by rw [hexp_m, mul_one] have hexp_msq : Real.exp J * Real.exp (-J) ^ 2 = Real.exp (-J) := by calc Real.exp J * Real.exp (-J) ^ 2 = (Real.exp (-J) * Real.exp J) * Real.exp (-J) := by ring _ = Real.exp (-J) := by rw [hexp_m, one_mul] calc 2 * Real.exp (3 * J) + 6 * Real.exp (-J) = 2 * Real.exp J ^ 3 + 6 * (Real.exp J * Real.exp (-J) ^ 2) := by rw [hexp3, hexp_msq] _ = (2 * ((Real.exp J + Real.exp (-J)) / 2)) ^ 3 + (2 * ((Real.exp J - Real.exp (-J)) / 2)) ^ 3 := by ring have hlog : Real.log Z_K3 - logZ_Bethe = Real.log (1 + (Real.tanh J) ^ 3) := by rw [hfac, Real.log_mul (ne_of_gt (pow_pos hc_pos 3)) (ne_of_gt (by positivity)), Real.log_pow] dsimp only [logZ_Bethe]; simp only [Nat.cast_ofNat]; ring refine ⟨hlog, ?_⟩ rw [hlog] exact Real.log_pos (by linarith [pow_pos ht_pos 3]) theorem bethe_vs_true_logZ_gap_C4 {J : ℝ} (hJ : 0 < J) : let Z_C4 := 2 * (Real.exp (4 * J) + Real.exp (-4 * J) + 6) let logZ_Bethe := 4 * Real.log (2 * Real.cosh J) Real.log Z_C4 - logZ_Bethe = Real.log (1 + (Real.tanh J) ^ 4) ∧ 0 < Real.log Z_C4 - logZ_Bethe := by intro Z_C4 logZ_Bethe have hc_pos : 0 < 2 * Real.cosh J := mul_pos two_pos (Real.cosh_pos J) have ht_pos : 0 < Real.tanh J := by rw [Real.tanh_eq_sinh_div_cosh] exact div_pos (Real.sinh_pos_iff.mpr hJ) (Real.cosh_pos J) have hfac : Z_C4 = (2 * Real.cosh J) ^ 4 * (1 + (Real.tanh J) ^ 4) := by dsimp only [Z_C4] have h1 : (2 * Real.cosh J) ^ 4 * (1 + (Real.tanh J) ^ 4) = (2 * Real.cosh J) ^ 4 + (2 * Real.sinh J) ^ 4 := by rw [Real.tanh_eq_sinh_div_cosh] have hc : Real.cosh J ≠ 0 := ne_of_gt (Real.cosh_pos J) field_simp [hc] rw [h1, Real.cosh_eq, Real.sinh_eq] have hexp4 : Real.exp J ^ 4 = Real.exp (4 * J) := by rw [← Real.exp_nat_mul, Nat.cast_ofNat] have hexp_m4 : Real.exp (-J) ^ 4 = Real.exp (-4 * J) := by rw [← Real.exp_nat_mul]; congr 1; ring have hexp_m : Real.exp (-J) * Real.exp J = 1 := by rw [← Real.exp_add, neg_add_cancel, Real.exp_zero] have hexp_22 : Real.exp J ^ 2 * Real.exp (-J) ^ 2 = 1 := by calc Real.exp J ^ 2 * Real.exp (-J) ^ 2 = (Real.exp (-J) * Real.exp J) ^ 2 := by ring _ = 1 := by rw [hexp_m]; ring calc 2 * (Real.exp (4 * J) + Real.exp (-4 * J) + 6) = 2 * (Real.exp J ^ 4 + Real.exp (-J) ^ 4 + 6 * (Real.exp J ^ 2 * Real.exp (-J) ^ 2)) := by rw [hexp4, hexp_m4, hexp_22, mul_one] _ = (2 * ((Real.exp J + Real.exp (-J)) / 2)) ^ 4 + (2 * ((Real.exp J - Real.exp (-J)) / 2)) ^ 4 := by ring have hlog : Real.log Z_C4 - logZ_Bethe = Real.log (1 + (Real.tanh J) ^ 4) := by rw [hfac, Real.log_mul (ne_of_gt (pow_pos hc_pos 4)) (ne_of_gt (by positivity)), Real.log_pow] dsimp only [logZ_Bethe]; simp only [Nat.cast_ofNat]; ring refine ⟨hlog, ?_⟩ rw [hlog] exact Real.log_pos (by linarith [pow_pos ht_pos 4]) /-- **Headline Theorem 2H (Explicit Non-Convexity & Negative Bethe Entropy Witness on `K_4`)**: On the complete graph `K_4` (4 vertices, 6 edges, degree 3, cyclomatic number 3), there exist explicit interior product beliefs `b⁺, b⁻ ∈ L°(K_4)` (with `p = 63/64`) whose midpoint `b̄ = (1/2) b⁺ + (1/2) b⁻ ∈ L°(K_4)` satisfies BOTH: 1. **Negative Bethe Entropy**: `H_Bethe(b̄) < 0 < H_Bethe(b⁺) = H_Bethe(b⁻)`; 2. **Strict Non-Convexity of `F_Bethe`** for **EVERY** pairwise MRF `M` on `K_4`: `F_Bethe(b̄) > (1/2) F_Bethe(b⁺) + (1/2) F_Bethe(b⁻)`! -/ theorem bethe_nonconvex_and_negative_entropy_K4 (M : PairwiseMRF (⊤ : SimpleGraph (Fin 4)) Bool) : ∃ bPos bNeg : LocalBelief (⊤ : SimpleGraph (Fin 4)) Bool, let bMid := bPos.convexComb bNeg (by norm_num) (by norm_num) (t := (1 / 2 : ℝ)) betheEntropy (⊤ : SimpleGraph (Fin 4)) bMid.bNode bMid.bEdge < 0 ∧ 0 < betheEntropy (⊤ : SimpleGraph (Fin 4)) bPos.bNode bPos.bEdge ∧ (1 / 2 : ℝ) * betheFreeEnergy M bPos + (1 / 2 : ℝ) * betheFreeEnergy M bNeg < betheFreeEnergy M bMid := by let p : ℝ := 63 / 64 have hp0 : 0 < p := by norm_num [p] have hp1 : 0 < 1 - p := by norm_num [p] let bPos : LocalBelief (⊤ : SimpleGraph (Fin 4)) Bool := { bNode := fun _ a => if a then p else 1 - p bEdge := fun _ _ a c => (if a then p else 1 - p) * (if c then p else 1 - p) bNode_pos := fun _ a => by cases a; exact hp1; exact hp0 bEdge_pos := fun _ _ a c => mul_pos (by cases a; exact hp1; exact hp0) (by cases c; exact hp1; exact hp0) bNode_sum := fun _ => by rw [Fintype.sum_bool]; simp bEdge_symm := fun _ _ a c => mul_comm _ _ bEdge_marg := fun _ _ _ a => by rw [Fintype.sum_bool]; cases a <;> simp <;> ring } let bNeg : LocalBelief (⊤ : SimpleGraph (Fin 4)) Bool := { bNode := fun _ a => if a then 1 - p else p bEdge := fun _ _ a c => (if a then 1 - p else p) * (if c then 1 - p else p) bNode_pos := fun _ a => by cases a; exact hp0; exact hp1 bEdge_pos := fun _ _ a c => mul_pos (by cases a; exact hp0; exact hp1) (by cases c; exact hp0; exact hp1) bNode_sum := fun _ => by rw [Fintype.sum_bool]; simp bEdge_symm := fun _ _ a c => mul_comm _ _ bEdge_marg := fun _ _ _ a => by rw [Fintype.sum_bool]; cases a <;> simp <;> ring } let bMid := bPos.convexComb bNeg (by norm_num) (by norm_num) (t := (1 / 2 : ℝ)) -- Compute `H_Bethe(bPos) = H_Bethe(bNeg) = 4 * binH p > 0` have hdeg_K4 : ∀ i : Fin 4, (⊤ : SimpleGraph (Fin 4)).degree i = 3 := fun i => by simp have hcard_nb : ∀ i : Fin 4, ((⊤ : SimpleGraph (Fin 4)).neighborFinset i).card = 3 := fun i => by rw [SimpleGraph.card_neighborFinset_eq_degree, hdeg_K4] have hH_node_pos : ∀ i : Fin 4, shannonH (bPos.bNode i) = binH p := fun i => by unfold shannonH binH; rw [Fintype.sum_bool]; simp [bPos] have hH_node_neg : ∀ i : Fin 4, shannonH (bNeg.bNode i) = binH p := fun i => by unfold shannonH binH; rw [Fintype.sum_bool]; simp [bNeg]; ring have hH_edge_prod : ∀ (r : ℝ), 0 < r → 0 < 1 - r → pairH (fun a c : Bool => (if a then r else 1 - r) * (if c then r else 1 - r)) = 2 * binH r := by intro r hr0 hr1 unfold pairH shannonH binH rw [Fintype.sum_prod_type] simp_rw [Fintype.sum_bool] simp only [↓reduceIte, Bool.false_eq_true] rw [Real.log_mul (ne_of_gt hr0) (ne_of_gt hr0), Real.log_mul (ne_of_gt hr0) (ne_of_gt hr1), Real.log_mul (ne_of_gt hr1) (ne_of_gt hr0), Real.log_mul (ne_of_gt hr1) (ne_of_gt hr1)] ring have hHB_pos : betheEntropy (⊤ : SimpleGraph (Fin 4)) bPos.bNode bPos.bEdge = 4 * binH p := by unfold betheEntropy have he : ∀ i j : Fin 4, pairH (bPos.bEdge i j) = 2 * binH p := fun _ _ => hH_edge_prod p hp0 hp1 simp_rw [he, hH_node_pos, hdeg_K4, Finset.sum_const, hcard_nb, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] norm_num; ring have hHB_neg : betheEntropy (⊤ : SimpleGraph (Fin 4)) bNeg.bNode bNeg.bEdge = 4 * binH p := by unfold betheEntropy have he : ∀ i j : Fin 4, pairH (bNeg.bEdge i j) = 2 * binH p := fun _ _ => by have h1 := hH_edge_prod (1 - p) hp1 (by linarith) have hsub : 1 - (1 - p) = p := by ring have hbin : binH (1 - p) = binH p := by unfold binH; rw [hsub]; ring simpa [bNeg, hsub, hbin] using h1 simp_rw [he, hH_node_neg, hdeg_K4, Finset.sum_const, hcard_nb, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] norm_num; ring -- Compute `H_Bethe(bMid) = 6 * binH (2 * p * (1 - p)) - 2 * log 2`! let q : ℝ := 2 * p * (1 - p) have hq0 : 0 < q := by norm_num [q, p] have hq1 : 0 < 1 - q := by norm_num [q, p] have hH_node_mid : ∀ i : Fin 4, shannonH (bMid.bNode i) = Real.log 2 := fun i => by unfold shannonH rw [Fintype.sum_bool] dsimp only [bMid, LocalBelief.convexComb, bPos, bNeg] simp only [↓reduceIte, Bool.false_eq_true] have hhalf1 : (1 - (1 / 2 : ℝ)) * p + (1 / 2 : ℝ) * (1 - p) = 1 / 2 := by ring have hhalf2 : (1 - (1 / 2 : ℝ)) * (1 - p) + (1 / 2 : ℝ) * p = 1 / 2 := by ring rw [hhalf1, hhalf2, one_div, Real.log_inv] ring have hH_edge_mid : ∀ i j : Fin 4, pairH (bMid.bEdge i j) = Real.log 2 + binH q := fun i j => by unfold pairH shannonH binH rw [Fintype.sum_prod_type] simp_rw [Fintype.sum_bool] dsimp only [bMid, LocalBelief.convexComb, bPos, bNeg] simp only [↓reduceIte, Bool.false_eq_true] have hdiag : (1 - (1 / 2 : ℝ)) * (p * p) + (1 / 2 : ℝ) * ((1 - p) * (1 - p)) = (1 - q) / 2 := by dsimp only [q]; ring have hoff : (1 - (1 / 2 : ℝ)) * (p * (1 - p)) + (1 / 2 : ℝ) * ((1 - p) * p) = q / 2 := by dsimp only [q]; ring have hoff2 : (1 - (1 / 2 : ℝ)) * ((1 - p) * p) + (1 / 2 : ℝ) * (p * (1 - p)) = q / 2 := by dsimp only [q]; ring have hdiag2 : (1 - (1 / 2 : ℝ)) * ((1 - p) * (1 - p)) + (1 / 2 : ℝ) * (p * p) = (1 - q) / 2 := by dsimp only [q]; ring rw [hdiag, hoff, hoff2, hdiag2, Real.log_div (ne_of_gt hq1) (by norm_num), Real.log_div (ne_of_gt hq0) (by norm_num)] ring have hHB_mid : betheEntropy (⊤ : SimpleGraph (Fin 4)) bMid.bNode bMid.bEdge = 6 * binH q - 2 * Real.log 2 := by unfold betheEntropy simp_rw [hH_edge_mid, hH_node_mid, hdeg_K4, Finset.sum_const, hcard_nb, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] norm_num; ring -- Elementary bounds: `binH p > 0` and `6 * binH q < 2 * log 2` (i.e. `3 * binH q < log 2`)! have hbinH_pos : 0 < binH p := by unfold binH have h1 : Real.log p < 0 := Real.log_neg hp0 (by norm_num [p]) have h2 : Real.log (1 - p) < 0 := Real.log_neg hp1 (by norm_num [p]) nlinarith -- Upper bound `binH q` via `q * log (1/q) + (1-q) * log (1/(1-q))` using `log t ≤ t - 1`! -- Specifically: `log (1/q) = 2 * log (1/√q) ≤ 2 * (1/√q - 1)` -> even simpler, use `log (1/q) = 3 * log ((1/q)^(1/3))` -- OR even simpler: `q = 63 / 2048 < 1 / 32`, `1/q = 2048 / 63 < 33`, and `log 2 > 0.69` (`Real.log_two_gt_d9`)! -- Wait: `1/q < 2^6 = 64` so `log(1/q) < 6 * log 2`! -- Check: `q = 63/2048 < 1/32`: -- `q * log(1/q) < (1/32) * (6 * log 2) = (3/16) * log 2`! -- AND `(1 - q) * log(1 / (1 - q)) = (1 - q) * log(1 + q/(1-q)) ≤ (1 - q) * (q / (1 - q)) = q < 1/32 < (1/16) * log 2`! -- ADD THEM: `binH q < (3/16 + 1/16) * log 2 = (1/4) * log 2`, SO `6 * binH q < (3/2) * log 2 < 2 * log 2`!! -- WHOA!! ZERO NUMERICAL APPROXIMATIONS NEEDED — PURE ALGEBRAIC BOUND IN TERMS OF `log 2`!! have hmid_neg : 6 * binH q - 2 * Real.log 2 < 0 := by have hlog2_pos : 0 < Real.log 2 := Real.log_pos (by norm_num) have hlog2_gt_half : (1 / 2 : ℝ) < Real.log 2 := by -- Since `exp(1/2) < 2`, i.e., `exp(1) < 4`, or `log 2 > 1 - 1/2`? Wait: `log(2) = -log(1/2)`, -- use `Real.log_two_gt_d9 : 0.6931471803 < Real.log 2`! linarith [Real.log_two_gt_d9] have h1 : q * (-Real.log q) < (3 / 16 : ℝ) * Real.log 2 := by have hq_inv : 1 / q < (2 : ℝ) ^ (6 : ℕ) := by norm_num [q, p] have hlog_inv : -Real.log q < 6 * Real.log 2 := by have hlt := Real.log_lt_log (div_pos one_pos hq0) hq_inv rw [one_div, Real.log_inv, Real.log_pow] at hlt simp only [Nat.cast_ofNat] at hlt exact hlt have hq_lt : q < 1 / 32 := by norm_num [q, p] have hneg_pos : 0 < -Real.log q := by have : Real.log q < 0 := Real.log_neg hq0 (by norm_num [q, p]); linarith only [this] calc q * (-Real.log q) < (1 / 32 : ℝ) * (6 * Real.log 2) := mul_lt_mul'' hq_lt hlog_inv (le_of_lt hq0) (le_of_lt hneg_pos) _ = (3 / 16 : ℝ) * Real.log 2 := by ring have h2 : (1 - q) * (-Real.log (1 - q)) ≤ q := by have hlog := Real.log_le_sub_one_of_pos (div_pos one_pos hq1) rw [one_div, Real.log_inv] at hlog have hmul := mul_le_mul_of_nonneg_left hlog (le_of_lt hq1) have hcancel : (1 - q) * ((1 - q)⁻¹ - 1) = q := by field_simp [ne_of_gt hq1]; ring rw [hcancel] at hmul exact hmul have hbin_lt : binH q < (3 / 16 : ℝ) * Real.log 2 + 1 / 32 := by have hq_lt : q < 1 / 32 := by norm_num [q, p] calc binH q = q * (-Real.log q) + (1 - q) * (-Real.log (1 - q)) := by unfold binH; ring _ < (3 / 16 : ℝ) * Real.log 2 + q := add_lt_add_of_lt_of_le h1 h2 _ < (3 / 16 : ℝ) * Real.log 2 + 1 / 32 := add_lt_add_of_le_of_lt le_rfl hq_lt calc 6 * binH q - 2 * Real.log 2 < 6 * ((3 / 16 : ℝ) * Real.log 2 + 1 / 32) - 2 * Real.log 2 := sub_lt_sub_right (mul_lt_mul_of_pos_left hbin_lt (by norm_num)) _ _ = 3 / 16 - (7 / 8 : ℝ) * Real.log 2 := by ring _ < 3 / 16 - (7 / 8 : ℝ) * (1 / 2) := sub_lt_sub_left (mul_lt_mul_of_pos_left hlog2_gt_half (by norm_num)) _ _ < 0 := by norm_num -- Energy is affine, so `F_Bethe(bMid) > (1/2) F_Bethe(bPos) + (1/2) F_Bethe(bNeg)`! have hU_aff : betheEnergy M bMid = (1 / 2 : ℝ) * betheEnergy M bPos + (1 / 2 : ℝ) * betheEnergy M bNeg := by unfold betheEnergy dsimp only [bMid, LocalBelief.convexComb] simp_rw [add_mul, mul_assoc, Finset.sum_add_distrib, ← Finset.mul_sum] ring refine ⟨bPos, bNeg, ?_, ?_, ?_⟩ · rw [hHB_mid]; exact hmid_neg · rw [hHB_pos]; linarith only [hbinH_pos] · unfold betheFreeEnergy rw [hU_aff, hHB_pos, hHB_neg, hHB_mid] have hgap : 6 * binH q - 2 * Real.log 2 < 4 * binH p := lt_trans hmid_neg (mul_pos (by norm_num) hbinH_pos) calc (1 / 2 : ℝ) * (betheEnergy M bPos - 4 * binH p) + (1 / 2 : ℝ) * (betheEnergy M bNeg - 4 * binH p) = (1 / 2 : ℝ) * betheEnergy M bPos + (1 / 2 : ℝ) * betheEnergy M bNeg - 4 * binH p := by ring _ < (1 / 2 : ℝ) * betheEnergy M bPos + (1 / 2 : ℝ) * betheEnergy M bNeg - (6 * binH q - 2 * Real.log 2) := sub_lt_sub_left hgap _ /-! ### Kikuchi / Cluster-Variational Region Graphs & Exactness on `C_4` (`2 × 2` Grid) -/ /-- A Kikuchi / Cluster-Variational Region Graph `(regions, c)` on a finite graph `G` satisfying the exact Möbius vertex and edge counting conditions. -/ structure RegionGraph {V : Type*} (G : SimpleGraph V) [Fintype V] [DecidableEq V] [DecidableRel G.Adj] where regions : Finset (Finset V) c : Finset V → ℤ vertex_count : ∀ i : V, ∑ R ∈ regions.filter (fun R => i ∈ R), c R = 1 edge_count : ∀ i j : V, G.Adj i j → ∑ R ∈ regions.filter (fun R => i ∈ R ∧ j ∈ R), c R = 1 /-- The Bethe approximation is the exact special case of a Kikuchi `RegionGraph` with edge regions (`c = +1`) and vertex regions (`c = 1 - d_i`). -/ noncomputable def betheRegionGraph {V : Type*} (G : SimpleGraph V) [Fintype V] [DecidableEq V] [DecidableRel G.Adj] : RegionGraph G where regions := (G.edgeFinset.image fun e => Finset.univ.filter (fun v => v ∈ e)) ∪ (Finset.univ.image fun i : V => ({i} : Finset V)) c R := if R.card = 2 then 1 else if R.card = 1 then 1 - (∑ i ∈ R, (G.degree i : ℤ)) else 0 vertex_count := by intro i -- Split into card-2 regions (the `d_i` incident edges, each with `c = 1`) and `{i}` (with `c = 1 - d_i`)! let edgeRegs := G.edgeFinset.image fun e => Finset.univ.filter (fun v => v ∈ e) let nodeRegs := Finset.univ.image fun u : V => ({u} : Finset V) have hcard_edge : ∀ R ∈ edgeRegs, R.card = 2 := by intro R hR rcases Finset.mem_image.mp hR with ⟨e, he, rfl⟩ induction e using Sym2.ind with | _ u v => have huv : u ≠ v := (G.mem_edgeFinset.mp he).ne have hset : Finset.univ.filter (fun w => w ∈ s(u, v)) = {u, v} := by ext w; simp [Sym2.mem_iff] rw [hset, Finset.card_pair huv] have hcard_node : ∀ R ∈ nodeRegs, R.card = 1 := by intro R hR rcases Finset.mem_image.mp hR with ⟨u, _, rfl⟩ exact Finset.card_singleton u have hdisj : Disjoint (edgeRegs.filter fun R => i ∈ R) (nodeRegs.filter fun R => i ∈ R) := by rw [Finset.disjoint_left] intro R h1 h2 have c1 := hcard_edge R (Finset.mem_filter.mp h1).1 have c2 := hcard_node R (Finset.mem_filter.mp h2).1 omega rw [Finset.filter_union, Finset.sum_union hdisj] have hsum_node : ∑ R ∈ nodeRegs.filter (fun R => i ∈ R), (if R.card = 2 then (1 : ℤ) else if R.card = 1 then 1 - ∑ u ∈ R, (G.degree u : ℤ) else 0) = 1 - (G.degree i : ℤ) := by have hfilt : nodeRegs.filter (fun R => i ∈ R) = {{i}} := by ext R simp only [Finset.mem_filter, nodeRegs, Finset.mem_image, Finset.mem_univ, true_and, Finset.mem_singleton] constructor · rintro ⟨⟨u, rfl⟩, hi⟩ have : i = u := Finset.mem_singleton.mp hi subst this; rfl · rintro rfl; exact ⟨⟨i, rfl⟩, Finset.mem_singleton_self i⟩ rw [hfilt, Finset.sum_singleton]; simp have hsum_edge : ∑ R ∈ edgeRegs.filter (fun R => i ∈ R), (if R.card = 2 then (1 : ℤ) else if R.card = 1 then 1 - ∑ u ∈ R, (G.degree u : ℤ) else 0) = (G.degree i : ℤ) := by have hconst : ∀ R ∈ edgeRegs.filter (fun R => i ∈ R), (if R.card = 2 then (1 : ℤ) else if R.card = 1 then 1 - ∑ u ∈ R, (G.degree u : ℤ) else 0) = 1 := fun R hR => by rw [if_pos (hcard_edge R (Finset.mem_filter.mp hR).1)] rw [Finset.sum_congr rfl hconst, Finset.sum_const, nsmul_eq_mul, mul_one, ← G.card_neighborFinset_eq_degree] congr 1 refine (Finset.card_bij (fun (j : V) (_ : j ∈ G.neighborFinset i) => ({i, j} : Finset V)) ?_ ?_ ?_).symm · intro j hj have hij : G.Adj i j := (SimpleGraph.mem_neighborFinset G i j).mp hj refine Finset.mem_filter.mpr ⟨Finset.mem_image.mpr ⟨s(i, j), G.mem_edgeFinset.mpr hij, ?_⟩, Finset.mem_insert_self i _⟩ ext w; simp [Sym2.mem_iff] · intro j₁ hj₁ j₂ hj₂ h have hij₁ : G.Adj i j₁ := (SimpleGraph.mem_neighborFinset G i j₁).mp hj₁ have hm : j₁ ∈ ({i, j₂} : Finset V) := h ▸ Finset.mem_insert_of_mem (Finset.mem_singleton_self j₁) rcases Finset.mem_insert.mp hm with h1 | h2 · exact absurd (h1 ▸ hij₁) (G.loopless.irrefl i) · exact Finset.mem_singleton.mp h2 · intro R hR rcases Finset.mem_filter.mp hR with ⟨hR_img, hi_R⟩ rcases Finset.mem_image.mp hR_img with ⟨e, he, rfl⟩ induction e using Sym2.ind with | _ u v => have huv : G.Adj u v := G.mem_edgeFinset.mp he have hi_uv : i ∈ s(u, v) := (Finset.mem_filter.mp hi_R).2 rcases Sym2.mem_iff.mp hi_uv with hui | hvi · rw [← hui] at huv refine ⟨v, (SimpleGraph.mem_neighborFinset G i v).mpr huv, ?_⟩ ext w; simp [Sym2.mem_iff, hui] · rw [← hvi] at huv refine ⟨u, (SimpleGraph.mem_neighborFinset G i u).mpr huv.symm, ?_⟩ ext w; simp [Sym2.mem_iff, hvi, or_comm] linarith edge_count := by intro i j hij let edgeRegs := G.edgeFinset.image fun e => Finset.univ.filter (fun v => v ∈ e) let nodeRegs := Finset.univ.image fun u : V => ({u} : Finset V) have hfilt : (edgeRegs ∪ nodeRegs).filter (fun R => i ∈ R ∧ j ∈ R) = {{i, j}} := by ext R simp only [Finset.mem_filter, Finset.mem_union, edgeRegs, nodeRegs, Finset.mem_image, Finset.mem_univ, true_and, Finset.mem_singleton] constructor · rintro ⟨⟨e, he, rfl⟩ | ⟨u, rfl⟩, hi, hj⟩ · induction e using Sym2.ind with | _ u v => have hi' : i = u ∨ i = v := Sym2.mem_iff.mp (Finset.mem_filter.mp hi).2 have hj' : j = u ∨ j = v := Sym2.mem_iff.mp (Finset.mem_filter.mp hj).2 rcases hi' with rfl | rfl <;> rcases hj' with rfl | rfl · exact absurd hij (G.loopless.irrefl _) · ext w; simp [Sym2.mem_iff] · ext w; simp [Sym2.mem_iff, or_comm] · exact absurd hij (G.loopless.irrefl _) · exfalso have h1 : i = u := Finset.mem_singleton.mp hi have h2 : j = u := Finset.mem_singleton.mp hj exact hij.ne (h1.trans h2.symm) · rintro rfl refine ⟨Or.inl ⟨s(i, j), G.mem_edgeFinset.mpr hij, ?_⟩, Finset.mem_insert_self i _, Finset.mem_insert_of_mem (Finset.mem_singleton_self j)⟩ ext w; simp [Sym2.mem_iff] rw [hfilt, Finset.sum_singleton, if_pos (Finset.card_pair hij.ne)] /-- **Headline Theorem 2I (General 2-Cluster Kikuchi / Junction-Tree Exactness)**: For ANY graph `G` covered by two regions `R₁, R₂ ⊆ V` (`R₁ ∪ R₂ = univ`, every edge of `G` lies in `R₁` or `R₂`) with separator `S = R₁ ∩ R₂` and Möbius counting numbers `c(R₁) = +1`, `c(R₂) = +1`, `c(S) = -1`: For ANY consistent interior cluster beliefs `(b₁, b₂, b_S)`, the stitched joint distribution `q_stitch(x) = b₁(x|_{R₁}) · b₂(x|_{R₂}) / b_S(x|_S)` is a valid probability distribution with exact marginals `b₁, b₂, b_S`, exact Kikuchi entropy `H(q_stitch) = H(b₁) + H(b₂) - H(b_S)`, and exact Kikuchi–Gibbs identity: `F_Kikuchi(b₁, b₂, b_S) = D_KL(q_stitch ‖ p) - log Z ≥ -log Z` (equality iff `q_stitch = p`)! -/ theorem twoCluster_kikuchi_exact {V X : Type*} [Fintype V] [DecidableEq V] [Fintype X] [DecidableEq X] [Nonempty X] {G : SimpleGraph V} [DecidableRel G.Adj] (M : PairwiseMRF G X) (R₁ R₂ : Finset V) (hcover : R₁ ∪ R₂ = Finset.univ) (b₁ : (R₁ → X) → ℝ) (b₂ : (R₂ → X) → ℝ) (bS : ((R₁ ∩ R₂ : Finset V) → X) → ℝ) (hb₁_pos : ∀ y, 0 < b₁ y) (hb₂_pos : ∀ y, 0 < b₂ y) (hbS_pos : ∀ y, 0 < bS y) (hb₁_sum : ∑ y : R₁ → X, b₁ y = 1) (hb₁_marg : ∀ yS : (R₁ ∩ R₂ : Finset V) → X, ∑ y₁ : R₁ → X, (if (fun s : (R₁ ∩ R₂ : Finset V) => y₁ ⟨s.1, (Finset.mem_inter.mp s.2).1⟩) = yS then b₁ y₁ else 0) = bS yS) (hb₂_marg : ∀ yS : (R₁ ∩ R₂ : Finset V) → X, ∑ y₂ : R₂ → X, (if (fun s : (R₁ ∩ R₂ : Finset V) => y₂ ⟨s.1, (Finset.mem_inter.mp s.2).2⟩) = yS then b₂ y₂ else 0) = bS yS) : let q : (V → X) → ℝ := fun x => b₁ (fun u => x u.1) * b₂ (fun u => x u.1) / bS (fun u => x u.1) let U_kik : ℝ := -∑ x : V → X, q x * Real.log (M.unnormWeight x) let H_kik : ℝ := shannonH b₁ + shannonH b₂ - shannonH bS (∀ x, 0 < q x) ∧ (∑ x : V → X, q x = 1) ∧ H_kik = shannonH q ∧ U_kik - H_kik = klDiv q M.gibbs - Real.log M.Z ∧ -Real.log M.Z ≤ U_kik - H_kik := by intro q U_kik H_kik let S := R₁ ∩ R₂ have hq_pos : ∀ x, 0 < q x := fun x => div_pos (mul_pos (hb₁_pos _) (hb₂_pos _)) (hbS_pos _) -- Split `V` disjointly into `R₁` and `D₂ := R₂ \ R₁`! let D₂ : Finset V := R₂ \ R₁ have hdisj : Disjoint R₁ D₂ := Finset.disjoint_sdiff have hunion : R₁ ∪ D₂ = Finset.univ := by rw [Finset.union_sdiff_self_eq_union, hcover] let eSplit : (V → X) ≃ (R₁ → X) × (D₂ → X) := { toFun := fun x => (fun u => x u.1, fun v => x v.1) invFun := fun p w => if hw : w ∈ R₁ then p.1 ⟨w, hw⟩ else p.2 ⟨w, (Finset.mem_union.mp (hunion ▸ Finset.mem_univ w)).resolve_left hw⟩ left_inv := fun x => funext fun w => by dsimp only; split_ifs <;> rfl right_inv := fun ⟨y₁, yD⟩ => by ext ⟨u, hu⟩ · simp [hu] · have hnot : u ∉ R₁ := (Finset.mem_sdiff.mp hu).2 simp [hnot] } -- Also split `R₂` disjointly into `S = R₁ ∩ R₂` and `D₂ = R₂ \ R₁`! let eR₂ : (R₂ → X) ≃ (S → X) × (D₂ → X) := { toFun := fun y => (fun s => y ⟨s.1, (Finset.mem_inter.mp s.2).2⟩, fun d => y ⟨d.1, (Finset.mem_sdiff.mp d.2).1⟩) invFun := fun p u => if hu : u.1 ∈ R₁ then p.1 ⟨u.1, Finset.mem_inter.mpr ⟨hu, u.2⟩⟩ else p.2 ⟨u.1, Finset.mem_sdiff.mpr ⟨u.2, hu⟩⟩ left_inv := fun y => funext fun ⟨u, hu⟩ => by dsimp only; split_ifs <;> rfl right_inv := fun ⟨yS, yD⟩ => by ext ⟨u, hu⟩ · have hu1 : u ∈ R₁ := (Finset.mem_inter.mp hu).1 simp [hu1] · have hu1 : u ∉ R₁ := (Finset.mem_sdiff.mp hu).2 simp [hu1] } -- Marginalizing `b₂` over `D₂ → X` for fixed `yS : S → X` yields `bS yS`! have hb₂_sum_D₂ : ∀ yS : S → X, ∑ yD : D₂ → X, b₂ (eR₂.symm (yS, yD)) = bS yS := by intro yS rw [← hb₂_marg yS, Fintype.sum_equiv eR₂ _ (fun p => if p.1 = yS then b₂ (eR₂.symm p) else 0) (fun y => by simp only [eR₂.symm_apply_apply]; rfl), Fintype.sum_prod_type] rw [Finset.sum_eq_single yS] · simp · intro z _ hz; exact Finset.sum_eq_zero fun _ _ => by simp [hz] · intro h; exact absurd (Finset.mem_univ _) h -- Rewrite `q (eSplit.symm (y₁, yD))` cleanly! have hq_split : ∀ (y₁ : R₁ → X) (yD : D₂ → X), q (eSplit.symm (y₁, yD)) = b₁ y₁ * b₂ (eR₂.symm (fun s => y₁ ⟨s.1, (Finset.mem_inter.mp s.2).1⟩, yD)) / bS (fun s => y₁ ⟨s.1, (Finset.mem_inter.mp s.2).1⟩) := by intro y₁ yD dsimp only [q] have h1 : (fun u : R₁ => eSplit.symm (y₁, yD) u.1) = y₁ := by funext ⟨u, hu⟩; simp [eSplit, hu] have h2 : (fun u : R₂ => eSplit.symm (y₁, yD) u.1) = eR₂.symm (fun s => y₁ ⟨s.1, (Finset.mem_inter.mp s.2).1⟩, yD) := by funext ⟨u, hu⟩; simp only [eSplit, eR₂, Equiv.coe_fn_symm_mk] have h3 : (fun s : S => eSplit.symm (y₁, yD) s.1) = (fun s : S => y₁ ⟨s.1, (Finset.mem_inter.mp s.2).1⟩) := by funext ⟨s, hs⟩; simp [eSplit, (Finset.mem_inter.mp hs).1] rw [h1, h2, h3] -- 1. Marginal of `q` on `R₁` is `b₁`! have hq_marg₁ : ∀ y₁ : R₁ → X, ∑ x : V → X, (if (fun u : R₁ => x u.1) = y₁ then q x else 0) = b₁ y₁ := by intro y₁ rw [Fintype.sum_equiv eSplit _ (fun p => if p.1 = y₁ then q (eSplit.symm p) else 0) (fun x => by simp only [eSplit.symm_apply_apply]; rfl), Fintype.sum_prod_type] rw [Finset.sum_eq_single y₁] · simp only [↓reduceIte, hq_split] rw [← Finset.sum_div, ← Finset.mul_sum, hb₂_sum_D₂, mul_div_cancel_right₀ _ (ne_of_gt (hbS_pos _))] · intro z _ hz; exact Finset.sum_eq_zero fun _ _ => by simp [hz] · intro h; exact absurd (Finset.mem_univ _) h -- 2. Total sum of `q` is `1`! have hq_sum : ∑ x : V → X, q x = 1 := by calc ∑ x : V → X, q x = ∑ y₁ : R₁ → X, ∑ x : V → X, (if (fun u : R₁ => x u.1) = y₁ then q x else 0) := by rw [Finset.sum_comm]; refine Finset.sum_congr rfl fun x _ => by simp _ = ∑ y₁ : R₁ → X, b₁ y₁ := Finset.sum_congr rfl fun y₁ _ => hq_marg₁ y₁ _ = 1 := hb₁_sum -- 3. Marginal of `q` on `S` is `bS`! have hq_margS : ∀ yS : S → X, ∑ x : V → X, (if (fun s : S => x s.1) = yS then q x else 0) = bS yS := by intro yS rw [← hb₁_marg yS] have hstep : ∀ y₁ : R₁ → X, (if (fun s : S => y₁ ⟨s.1, (Finset.mem_inter.mp s.2).1⟩) = yS then b₁ y₁ else 0) = ∑ x : V → X, if (fun s : S => y₁ ⟨s.1, (Finset.mem_inter.mp s.2).1⟩) = yS ∧ (fun u : R₁ => x u.1) = y₁ then q x else 0 := by intro y₁; rw [← hq_marg₁ y₁]; split_ifs with h <;> simp [h] calc ∑ x : V → X, (if (fun s : S => x s.1) = yS then q x else 0) = ∑ x : V → X, ∑ y₁ : R₁ → X, if (fun s : S => y₁ ⟨s.1, (Finset.mem_inter.mp s.2).1⟩) = yS ∧ (fun u : R₁ => x u.1) = y₁ then q x else 0 := by refine Finset.sum_congr rfl fun x _ => ?_ rw [Finset.sum_eq_single (fun u : R₁ => x u.1)] · simp · intro z _ hz; simp [hz.symm] · intro h; exact absurd (Finset.mem_univ _) h _ = ∑ y₁ : R₁ → X, ∑ x : V → X, if (fun s : S => y₁ ⟨s.1, (Finset.mem_inter.mp s.2).1⟩) = yS ∧ (fun u : R₁ => x u.1) = y₁ then q x else 0 := Finset.sum_comm _ = ∑ y₁ : R₁ → X, (if (fun s : S => y₁ ⟨s.1, (Finset.mem_inter.mp s.2).1⟩) = yS then b₁ y₁ else 0) := Finset.sum_congr rfl fun y₁ _ => (hstep y₁).symm -- 4. Marginal of `q` on `R₂` is `b₂`! have hq_marg₂ : ∀ y₂ : R₂ → X, ∑ x : V → X, (if (fun u : R₂ => x u.1) = y₂ then q x else 0) = b₂ y₂ := by intro y₂ let yS : S → X := (eR₂ y₂).1 let yD : D₂ → X := (eR₂ y₂).2 rw [Fintype.sum_equiv eSplit _ (fun p => if (fun u : R₂ => eSplit.symm p u.1) = y₂ then q (eSplit.symm p) else 0) (fun x => by simp only [eSplit.symm_apply_apply]), Fintype.sum_prod_type] have hiff : ∀ (z₁ : R₁ → X) (zD : D₂ → X), ((fun u : R₂ => eSplit.symm (z₁, zD) u.1) = y₂) ↔ ((fun s : S => z₁ ⟨s.1, (Finset.mem_inter.mp s.2).1⟩) = yS ∧ zD = yD) := by intro z₁ zD constructor · intro heq constructor · funext ⟨s, hs⟩ have h := congrFun heq ⟨s, (Finset.mem_inter.mp hs).2⟩ have hs1 : s ∈ R₁ := (Finset.mem_inter.mp hs).1 simpa [eSplit, hs1, yS, eR₂] using h · funext ⟨d, hd⟩ have h := congrFun heq ⟨d, (Finset.mem_sdiff.mp hd).1⟩ have hd1 : d ∉ R₁ := (Finset.mem_sdiff.mp hd).2 simpa [eSplit, hd1, yD, eR₂] using h · rintro ⟨hS, rfl⟩ funext ⟨u, hu⟩ change (if hw : u ∈ R₁ then z₁ ⟨u, hw⟩ else yD ⟨u, (Finset.mem_union.mp (hunion ▸ Finset.mem_univ u)).resolve_left hw⟩) = y₂ ⟨u, hu⟩ split_ifs with hu1 · have h := congrFun hS ⟨u, Finset.mem_inter.mpr ⟨hu1, hu⟩⟩ simpa [yS, eR₂] using h · rfl have hinner : ∀ z₁ : R₁ → X, (∑ zD : D₂ → X, if (fun u : R₂ => eSplit.symm (z₁, zD) u.1) = y₂ then q (eSplit.symm (z₁, zD)) else 0) = (if (fun s : S => z₁ ⟨s.1, (Finset.mem_inter.mp s.2).1⟩) = yS then b₁ z₁ else 0) * (b₂ y₂ / bS yS) := by intro z₁ simp_rw [hiff z₁] by_cases hzS : (fun s : S => z₁ ⟨s.1, (Finset.mem_inter.mp s.2).1⟩) = yS · simp only [hzS, true_and, ↓reduceIte, Finset.sum_ite_eq', Finset.mem_univ, hq_split] have hy2_eq : eR₂.symm (yS, yD) = y₂ := eR₂.symm_apply_apply y₂ rw [hzS, hy2_eq]; ring · simp [hzS] rw [Finset.sum_congr rfl fun z₁ _ => hinner z₁, ← Finset.sum_mul, hb₁_marg yS, mul_div_cancel₀ _ (ne_of_gt (hbS_pos yS))] -- 5. Exact Kikuchi entropy `H_kik = H(q)`! have hH_eq : H_kik = shannonH q := by have hlog_q : ∀ x : V → X, Real.log (q x) = Real.log (b₁ fun u => x u.1) + Real.log (b₂ fun u => x u.1) - Real.log (bS fun u => x u.1) := fun x => by dsimp only [q] rw [Real.log_div (ne_of_gt (mul_pos (hb₁_pos _) (hb₂_pos _))) (ne_of_gt (hbS_pos _)), Real.log_mul (ne_of_gt (hb₁_pos _)) (ne_of_gt (hb₂_pos _))] have hE : ∀ {T : Finset V} (bT : (T → X) → ℝ), (∀ yT, ∑ x : V → X, (if (fun u : T => x u.1) = yT then q x else 0) = bT yT) → ∑ x : V → X, q x * Real.log (bT fun u => x u.1) = ∑ yT : T → X, bT yT * Real.log (bT yT) := by intro T bT hmarg simp_rw [← hmarg, Finset.sum_mul] rw [Finset.sum_comm] refine Finset.sum_congr rfl fun x _ => ?_ rw [Finset.sum_eq_single (fun u : T => x u.1)] · simp · intro z _ hz; simp [hz.symm] · intro h; exact absurd (Finset.mem_univ _) h dsimp only [H_kik, shannonH] simp_rw [hlog_q, mul_sub, mul_add, Finset.sum_sub_distrib, Finset.sum_add_distrib] rw [hE b₁ hq_marg₁, hE b₂ hq_marg₂, hE bS hq_margS] ring -- 6. Exact Kikuchi–Gibbs identity `U_kik - H_kik = D_KL(q ‖ p) - log Z ≥ -log Z`! have hFE_eq : U_kik - H_kik = klDiv q M.gibbs - Real.log M.Z := by rw [hH_eq] dsimp only [U_kik, shannonH, klDiv] have hterm : ∀ x : V → X, q x * Real.log (q x / M.gibbs x) = q x * Real.log (q x) - q x * Real.log (M.unnormWeight x) + q x * Real.log M.Z := by intro x unfold PairwiseMRF.gibbs rw [Real.log_div (ne_of_gt (hq_pos x)) (ne_of_gt (div_pos (M.unnormWeight_pos x) M.Z_pos)), Real.log_div (ne_of_gt (M.unnormWeight_pos x)) (ne_of_gt M.Z_pos)] ring simp_rw [hterm, Finset.sum_add_distrib, Finset.sum_sub_distrib, ← Finset.sum_mul, hq_sum, one_mul] ring have hkl_nn := klDiv_nonneg hq_pos M.gibbs_pos hq_sum M.sum_gibbs exact ⟨hq_pos, hq_sum, hH_eq, hFE_eq, by linarith⟩ /-- **Headline Theorem 2J (Exact Kikuchi Region Graph on `C_4` = `2 × 2` Grid)**: On the 4-cycle `C_4` (`0 - 1 - 2 - 3 - 0`), the triangulated 2-cluster Kikuchi region graph `R₁ = {0, 1, 2}`, `R₂ = {0, 2, 3}`, `S = {0, 2}` with Möbius counting numbers `c(R₁) = +1`, `c(R₂) = +1`, `c(S) = -1` is a valid `RegionGraph C_4` whose minimum free energy equals `-log Z` **EXACTLY** (gap `= 0`), whereas Bethe incurs the exact strictly positive gap `log(1 + tanh⁴ J) > 0` for every `J > 0`! -/ def c4Graph : SimpleGraph (Fin 4) where Adj u v := (u = 0 ∧ v = 1) ∨ (u = 1 ∧ v = 0) ∨ (u = 1 ∧ v = 2) ∨ (u = 2 ∧ v = 1) ∨ (u = 2 ∧ v = 3) ∨ (u = 3 ∧ v = 2) ∨ (u = 3 ∧ v = 0) ∨ (u = 0 ∧ v = 3) symm := ⟨fun u v h => by rcases h with ⟨rfl, rfl⟩ | ⟨rfl, rfl⟩ | ⟨rfl, rfl⟩ | ⟨rfl, rfl⟩ | ⟨rfl, rfl⟩ | ⟨rfl, rfl⟩ | ⟨rfl, rfl⟩ | ⟨rfl, rfl⟩ <;> simp⟩ loopless := ⟨fun u h => by fin_cases u <;> simp at h⟩ instance : DecidableRel c4Graph.Adj := fun u v => by unfold c4Graph; infer_instance /-- Valid 2-cluster Kikuchi `RegionGraph` on `C_4` (`R₁ = {0,1,2}`, `R₂ = {0,2,3}`, `S = {0,2}`). -/ def c4KikuchiRegionGraph : RegionGraph c4Graph where regions := {({0, 1, 2} : Finset (Fin 4)), ({0, 2, 3} : Finset (Fin 4)), ({0, 2} : Finset (Fin 4))} c R := if R = {0, 1, 2} then 1 else if R = {0, 2, 3} then 1 else if R = {0, 2} then -1 else 0 vertex_count := by intro i; fin_cases i <;> decide edge_count := by intro i j hij; fin_cases i <;> fin_cases j <;> simp [c4Graph] at hij <;> decide /-- Exact Kikuchi attainment on `C_4` (using exact cluster marginals of any positive MRF `M` on `C_4`): `U_Kikuchi - H_Kikuchi = -log Z` identically! -/ theorem c4_kikuchi_exact_attainment {X : Type*} [Fintype X] [DecidableEq X] [Nonempty X] (M : PairwiseMRF c4Graph X) : let R₁ : Finset (Fin 4) := {0, 1, 2} let R₂ : Finset (Fin 4) := {0, 2, 3} let S : Finset (Fin 4) := R₁ ∩ R₂ let b₁ : (R₁ → X) → ℝ := fun y => ∑ x : Fin 4 → X, if (fun u : R₁ => x u.1) = y then M.gibbs x else 0 let b₂ : (R₂ → X) → ℝ := fun y => ∑ x : Fin 4 → X, if (fun u : R₂ => x u.1) = y then M.gibbs x else 0 let bS : (S → X) → ℝ := fun y => ∑ x : Fin 4 → X, if (fun u : S => x u.1) = y then M.gibbs x else 0 let q : (Fin 4 → X) → ℝ := fun x => b₁ (fun u => x u.1) * b₂ (fun u => x u.1) / bS (fun u => x u.1) q = M.gibbs ∧ (-∑ x : Fin 4 → X, q x * Real.log (M.unnormWeight x)) - (shannonH b₁ + shannonH b₂ - shannonH bS) = -Real.log M.Z := by intro R₁ R₂ S b₁ b₂ bS q -- First prove `q = M.gibbs` by conditional independence of `x 1` and `x 3` given `(x 0, x 2)` on `C_4`! have hS_eq : S = ({0, 2} : Finset (Fin 4)) := by decide have hcover : R₁ ∪ R₂ = Finset.univ := by decide -- For any `x : Fin 4 → X`, factor `M.unnormWeight x = f₁(x0, x1, x2) * f₂(x0, x2, x3)`! let f₁ (a₀ a₁ a₂ : X) : ℝ := M.ψNode 0 a₀ * M.ψNode 1 a₁ * M.ψNode 2 a₂ * M.ψEdge 0 1 a₀ a₁ * M.ψEdge 1 2 a₁ a₂ let f₂ (a₀ a₂ a₃ : X) : ℝ := M.ψNode 3 a₃ * M.ψEdge 2 3 a₂ a₃ * M.ψEdge 3 0 a₃ a₀ have hC4_edges : c4Graph.edgeFinset = {s(0, 1), s(1, 2), s(2, 3), s(3, 0)} := by decide have hw_fac : ∀ x : Fin 4 → X, M.unnormWeight x = f₁ (x 0) (x 1) (x 2) * f₂ (x 0) (x 2) (x 3) := by intro x unfold PairwiseMRF.unnormWeight rw [hC4_edges, Finset.prod_insert (by decide : s((0 : Fin 4), 1) ∉ ({s(1, 2), s(2, 3), s(3, 0)} : Finset (Sym2 (Fin 4)))), Finset.prod_insert (by decide : s((1 : Fin 4), 2) ∉ ({s(2, 3), s(3, 0)} : Finset (Sym2 (Fin 4)))), Finset.prod_insert (by decide : s((2 : Fin 4), 3) ∉ ({s(3, 0)} : Finset (Sym2 (Fin 4)))), Finset.prod_singleton] simp only [Fin.prod_univ_four, PairwiseMRF.edgeWeight, Sym2.lift_mk, f₁, f₂] ring -- Compute `b₁, b₂, bS` explicitly as sums over the complementary single vertex! have hb₁_eq : ∀ x : Fin 4 → X, b₁ (fun u => x u.1) = (f₁ (x 0) (x 1) (x 2) * ∑ a₃ : X, f₂ (x 0) (x 2) a₃) / M.Z := by intro x dsimp only [b₁, PairwiseMRF.gibbs] have hdiv : (∑ z : Fin 4 → X, if (fun u : R₁ => z u.1) = (fun u : R₁ => x u.1) then M.unnormWeight z / M.Z else 0) = (∑ z : Fin 4 → X, if (fun u : R₁ => z u.1) = (fun u : R₁ => x u.1) then M.unnormWeight z else 0) / M.Z := by rw [Finset.sum_div]; exact Finset.sum_congr rfl fun z _ => by split_ifs <;> simp rw [hdiv] congr 1 -- Sum over `z : Fin 4 → X` with `z 0 = x 0, z 1 = x 1, z 2 = x 2` is just sum over `z 3 : X`! rw [Finset.mul_sum] refine Finset.sum_bij_ne_zero (fun z _ _ => z 3) ?_ ?_ ?_ ?_ · intro _ _ _; exact Finset.mem_univ _ · intro z₁ _ hz₁ z₂ _ hz₂ h3 have heq1 : (fun u : R₁ => z₁ u.1) = (fun u : R₁ => x u.1) := by by_contra h; simp [h] at hz₁ have heq2 : (fun u : R₁ => z₂ u.1) = (fun u : R₁ => x u.1) := by by_contra h; simp [h] at hz₂ funext i; fin_cases i · exact (congrFun heq1 ⟨0, by decide⟩).trans (congrFun heq2 ⟨0, by decide⟩).symm · exact (congrFun heq1 ⟨1, by decide⟩).trans (congrFun heq2 ⟨1, by decide⟩).symm · exact (congrFun heq1 ⟨2, by decide⟩).trans (congrFun heq2 ⟨2, by decide⟩).symm · exact h3 · intro a₃ _ _ let z : Fin 4 → X := fun i => if i = 3 then a₃ else x i have hz : (fun u : R₁ => z u.1) = (fun u : R₁ => x u.1) := by funext ⟨u, hu⟩; fin_cases u <;> simp [z, R₁] at hu ⊢ refine ⟨z, Finset.mem_univ _, by simp [hz, ne_of_gt (M.unnormWeight_pos z)], by simp [z]⟩ · intro z _ hz have heq : (fun u : R₁ => z u.1) = (fun u : R₁ => x u.1) := by by_contra h; simp [h] at hz have h0 : z 0 = x 0 := congrFun heq ⟨0, by decide⟩ have h1 : z 1 = x 1 := congrFun heq ⟨1, by decide⟩ have h2 : z 2 = x 2 := congrFun heq ⟨2, by decide⟩ simp only [heq, ↓reduceIte, hw_fac z, h0, h1, h2] have hb₂_eq : ∀ x : Fin 4 → X, b₂ (fun u => x u.1) = ((∑ a₁ : X, f₁ (x 0) a₁ (x 2)) * f₂ (x 0) (x 2) (x 3)) / M.Z := by intro x dsimp only [b₂, PairwiseMRF.gibbs] have hdiv : (∑ z : Fin 4 → X, if (fun u : R₂ => z u.1) = (fun u : R₂ => x u.1) then M.unnormWeight z / M.Z else 0) = (∑ z : Fin 4 → X, if (fun u : R₂ => z u.1) = (fun u : R₂ => x u.1) then M.unnormWeight z else 0) / M.Z := by rw [Finset.sum_div]; exact Finset.sum_congr rfl fun z _ => by split_ifs <;> simp rw [hdiv] congr 1 rw [Finset.sum_mul] refine Finset.sum_bij_ne_zero (fun z _ _ => z 1) ?_ ?_ ?_ ?_ · intro _ _ _; exact Finset.mem_univ _ · intro z₁ _ hz₁ z₂ _ hz₂ h1 have heq1 : (fun u : R₂ => z₁ u.1) = (fun u : R₂ => x u.1) := by by_contra h; simp [h] at hz₁ have heq2 : (fun u : R₂ => z₂ u.1) = (fun u : R₂ => x u.1) := by by_contra h; simp [h] at hz₂ funext i; fin_cases i · exact (congrFun heq1 ⟨0, by decide⟩).trans (congrFun heq2 ⟨0, by decide⟩).symm · exact h1 · exact (congrFun heq1 ⟨2, by decide⟩).trans (congrFun heq2 ⟨2, by decide⟩).symm · exact (congrFun heq1 ⟨3, by decide⟩).trans (congrFun heq2 ⟨3, by decide⟩).symm · intro a₁ _ _ let z : Fin 4 → X := fun i => if i = 1 then a₁ else x i have hz : (fun u : R₂ => z u.1) = (fun u : R₂ => x u.1) := by funext ⟨u, hu⟩; fin_cases u <;> simp [z, R₂] at hu ⊢ refine ⟨z, Finset.mem_univ _, by simp [hz, ne_of_gt (M.unnormWeight_pos z)], by simp [z]⟩ · intro z _ hz have heq : (fun u : R₂ => z u.1) = (fun u : R₂ => x u.1) := by by_contra h; simp [h] at hz have h0 : z 0 = x 0 := congrFun heq ⟨0, by decide⟩ have h2 : z 2 = x 2 := congrFun heq ⟨2, by decide⟩ have h3 : z 3 = x 3 := congrFun heq ⟨3, by decide⟩ simp only [heq, ↓reduceIte, hw_fac z, h0, h2, h3] have hbS_eq : ∀ x : Fin 4 → X, bS (fun u => x u.1) = ((∑ a₁ : X, f₁ (x 0) a₁ (x 2)) * (∑ a₃ : X, f₂ (x 0) (x 2) a₃)) / M.Z := by intro x dsimp only [bS, PairwiseMRF.gibbs] have hdiv : (∑ z : Fin 4 → X, if (fun u : S => z u.1) = (fun u : S => x u.1) then M.unnormWeight z / M.Z else 0) = (∑ z : Fin 4 → X, if (fun u : S => z u.1) = (fun u : S => x u.1) then M.unnormWeight z else 0) / M.Z := by rw [Finset.sum_div]; exact Finset.sum_congr rfl fun z _ => by split_ifs <;> simp rw [hdiv] congr 1 rw [Finset.sum_mul_sum] have hprod : ∑ p : X × X, f₁ (x 0) p.1 (x 2) * f₂ (x 0) (x 2) p.2 = ∑ a₁ : X, ∑ a₃ : X, f₁ (x 0) a₁ (x 2) * f₂ (x 0) (x 2) a₃ := Fintype.sum_prod_type _ rw [← hprod] refine Finset.sum_bij_ne_zero (fun z _ _ => (z 1, z 3)) ?_ ?_ ?_ ?_ · intro _ _ _; exact Finset.mem_univ _ · intro z₁ _ hz₁ z₂ _ hz₂ h13 have heq1 : (fun u : S => z₁ u.1) = (fun u : S => x u.1) := by by_contra h; simp [h] at hz₁ have heq2 : (fun u : S => z₂ u.1) = (fun u : S => x u.1) := by by_contra h; simp [h] at hz₂ funext i; fin_cases i · exact (congrFun heq1 ⟨0, by decide⟩).trans (congrFun heq2 ⟨0, by decide⟩).symm · exact (Prod.mk.inj h13).1 · exact (congrFun heq1 ⟨2, by decide⟩).trans (congrFun heq2 ⟨2, by decide⟩).symm · exact (Prod.mk.inj h13).2 · intro ⟨a₁, a₃⟩ _ _ let z : Fin 4 → X := fun i => if i = 1 then a₁ else if i = 3 then a₃ else x i have hz : (fun u : S => z u.1) = (fun u : S => x u.1) := by funext ⟨u, hu⟩; fin_cases u <;> simp [z, S, R₁, R₂] at hu ⊢ refine ⟨z, Finset.mem_univ _, by simp [hz, ne_of_gt (M.unnormWeight_pos z)], by simp [z]⟩ · intro z _ hz have heq : (fun u : S => z u.1) = (fun u : S => x u.1) := by by_contra h; simp [h] at hz have h0 : z 0 = x 0 := congrFun heq ⟨0, by decide⟩ have h2 : z 2 = x 2 := congrFun heq ⟨2, by decide⟩ simp only [heq, ↓reduceIte, hw_fac z, h0, h2] have hf₁_pos : ∀ a b c, 0 < f₁ a b c := fun a b c => mul_pos (mul_pos (mul_pos (mul_pos (M.ψNode_pos _ _) (M.ψNode_pos _ _)) (M.ψNode_pos _ _)) (M.ψEdge_pos _ _ _ _)) (M.ψEdge_pos _ _ _ _) have hf₂_pos : ∀ a b c, 0 < f₂ a b c := fun a b c => mul_pos (mul_pos (M.ψNode_pos _ _) (M.ψEdge_pos _ _ _ _)) (M.ψEdge_pos _ _ _ _) have hq_eq : q = M.gibbs := by funext x dsimp only [q] rw [hb₁_eq x, hb₂_eq x, hbS_eq x] unfold PairwiseMRF.gibbs rw [hw_fac x] have hZ : M.Z ≠ 0 := ne_of_gt M.Z_pos have hS1 : (∑ a₁ : X, f₁ (x 0) a₁ (x 2)) ≠ 0 := ne_of_gt (Finset.sum_pos (fun a₁ _ => hf₁_pos _ a₁ _) Finset.univ_nonempty) have hS2 : (∑ a₃ : X, f₂ (x 0) (x 2) a₃) ≠ 0 := ne_of_gt (Finset.sum_pos (fun a₃ _ => hf₂_pos _ _ a₃) Finset.univ_nonempty) field_simp [hZ, hS1, hS2] -- Now invoke `twoCluster_kikuchi_exact`! have hb₁_pos : ∀ y, 0 < b₁ y := fun y => by obtain ⟨d⟩ := (inferInstance : Nonempty X) let x0 : Fin 4 → X := fun i => if h : i ∈ R₁ then y ⟨i, h⟩ else d have hx0 : (fun u : R₁ => x0 u.1) = y := by funext ⟨u, hu⟩; simp [x0, hu] exact lt_of_lt_of_le (by simp [hx0, M.gibbs_pos x0]) (Finset.single_le_sum (fun x _ => by split_ifs; exact le_of_lt (M.gibbs_pos x); rfl) (Finset.mem_univ x0)) have hb₂_pos : ∀ y, 0 < b₂ y := fun y => by obtain ⟨d⟩ := (inferInstance : Nonempty X) let x0 : Fin 4 → X := fun i => if h : i ∈ R₂ then y ⟨i, h⟩ else d have hx0 : (fun u : R₂ => x0 u.1) = y := by funext ⟨u, hu⟩; simp [x0, hu] exact lt_of_lt_of_le (by simp [hx0, M.gibbs_pos x0]) (Finset.single_le_sum (fun x _ => by split_ifs; exact le_of_lt (M.gibbs_pos x); rfl) (Finset.mem_univ x0)) have hbS_pos : ∀ y, 0 < bS y := fun y => by obtain ⟨d⟩ := (inferInstance : Nonempty X) let x0 : Fin 4 → X := fun i => if h : i ∈ S then y ⟨i, h⟩ else d have hx0 : (fun u : S => x0 u.1) = y := by funext ⟨u, hu⟩; simp [x0, hu] exact lt_of_lt_of_le (by simp [hx0, M.gibbs_pos x0]) (Finset.single_le_sum (fun x _ => by split_ifs; exact le_of_lt (M.gibbs_pos x); rfl) (Finset.mem_univ x0)) have hb₁_sum : ∑ y : R₁ → X, b₁ y = 1 := by dsimp only [b₁]; rw [Finset.sum_comm] calc ∑ x : Fin 4 → X, ∑ y : R₁ → X, (if (fun u : R₁ => x u.1) = y then M.gibbs x else 0) = ∑ x : Fin 4 → X, M.gibbs x := Finset.sum_congr rfl fun x _ => by simp _ = 1 := M.sum_gibbs have hb₁_marg : ∀ yS : S → X, ∑ y₁ : R₁ → X, (if (fun s : S => y₁ ⟨s.1, (Finset.mem_inter.mp s.2).1⟩) = yS then b₁ y₁ else 0) = bS yS := by intro yS dsimp only [b₁, bS] have hstep : ∀ y₁ : R₁ → X, (if (fun s : S => y₁ ⟨s.1, (Finset.mem_inter.mp s.2).1⟩) = yS then ∑ x : Fin 4 → X, if (fun u : R₁ => x u.1) = y₁ then M.gibbs x else 0 else 0) = ∑ x : Fin 4 → X, if (fun s : S => y₁ ⟨s.1, (Finset.mem_inter.mp s.2).1⟩) = yS ∧ (fun u : R₁ => x u.1) = y₁ then M.gibbs x else 0 := by intro y₁; split_ifs with h <;> simp [h] simp_rw [hstep] rw [Finset.sum_comm] refine Finset.sum_congr rfl fun x _ => ?_ rw [Finset.sum_eq_single (fun u : R₁ => x u.1)] · simp · intro y₁ _ hne; simp [hne.symm] · intro h; exact absurd (Finset.mem_univ _) h have hb₂_marg : ∀ yS : S → X, ∑ y₂ : R₂ → X, (if (fun s : S => y₂ ⟨s.1, (Finset.mem_inter.mp s.2).2⟩) = yS then b₂ y₂ else 0) = bS yS := by intro yS dsimp only [b₂, bS] have hstep : ∀ y₂ : R₂ → X, (if (fun s : S => y₂ ⟨s.1, (Finset.mem_inter.mp s.2).2⟩) = yS then ∑ x : Fin 4 → X, if (fun u : R₂ => x u.1) = y₂ then M.gibbs x else 0 else 0) = ∑ x : Fin 4 → X, if (fun s : S => y₂ ⟨s.1, (Finset.mem_inter.mp s.2).2⟩) = yS ∧ (fun u : R₂ => x u.1) = y₂ then M.gibbs x else 0 := by intro y₂; split_ifs with h <;> simp [h] simp_rw [hstep] rw [Finset.sum_comm] refine Finset.sum_congr rfl fun x _ => ?_ rw [Finset.sum_eq_single (fun u : R₂ => x u.1)] · simp · intro y₂ _ hne; simp [hne.symm] · intro h; exact absurd (Finset.mem_univ _) h obtain ⟨_, _, _, hFE, _⟩ := twoCluster_kikuchi_exact M R₁ R₂ hcover b₁ b₂ bS hb₁_pos hb₂_pos hbS_pos hb₁_sum hb₁_marg hb₂_marg refine ⟨hq_eq, ?_⟩ change (-∑ x : Fin 4 → X, q x * Real.log (M.unnormWeight x)) - (shannonH b₁ + shannonH b₂ - shannonH bS) = klDiv q M.gibbs - Real.log M.Z at hFE rw [hFE, hq_eq, (klDiv_eq_zero_iff M.gibbs_pos M.gibbs_pos M.sum_gibbs M.sum_gibbs).mpr rfl, zero_sub] end KikuchiAndWitnesses /-! ## Section 6 (Pillar 3): Wainwright–Jaakkola–Willsky Tree-Reweighted (TRW) Convex Upper Bounds -/ section TRWBounds variable {V X : Type*} {G : SimpleGraph V} [Fintype V] [DecidableEq V] [DecidableRel G.Adj] variable [Fintype X] [DecidableEq X] [Nonempty X] /-- Restrict an interior `LocalBelief G X` to any spanning subgraph `T ≤ G`. -/ def LocalBelief.restrict {T : SimpleGraph V} (hTG : T ≤ G) (b : LocalBelief G X) : LocalBelief T X where bNode := b.bNode bEdge := b.bEdge bNode_pos := b.bNode_pos bEdge_pos := b.bEdge_pos bNode_sum := b.bNode_sum bEdge_symm := b.bEdge_symm bEdge_marg := fun i j hij a => b.bEdge_marg i j (hTG hij) a /-- Exponential-family log-partition function `A(θ) = log ∑_x exp(θ(x))` for canonical configuration energies `θ : (V → X) → ℝ`. -/ noncomputable def logZOf (θ : (V → X) → ℝ) : ℝ := Real.log (∑ x : V → X, Real.exp (θ x)) omit [DecidableEq X] in /-- **Headline Theorem 3A (Wainwright–Jaakkola–Willsky TRW Log-Partition Upper Bound)**: For ANY finite convex combination `μ : ι → ℝ` (`μ t ≥ 0`, `∑ t, μ t = 1`) of tree-structured (or arbitrary) log-potentials `θ_T : ι → (V → X) → ℝ` satisfying `θ(x) = ∑_t μ_t θ_T(t, x)`: `log Z(θ) ≤ ∑_t μ_t log Z(θ_T(t))`! (Proved cleanly from weighted AM-GM / Hölder's inequality!) -/ theorem trw_logZ_upper_bound {ι : Type*} [Fintype ι] (μ : ι → ℝ) (hμ_nn : ∀ t, 0 ≤ μ t) (hμ_sum : ∑ t : ι, μ t = 1) (θT : ι → (V → X) → ℝ) : logZOf (fun x => ∑ t : ι, μ t * θT t x) ≤ ∑ t : ι, μ t * logZOf (θT t) := by let ZT : ι → ℝ := fun t => ∑ x : V → X, Real.exp (θT t x) have hZT_pos : ∀ t, 0 < ZT t := fun t => Finset.sum_pos (fun x _ => Real.exp_pos _) Finset.univ_nonempty -- For each `x`, apply `Real.geom_mean_le_arith_mean_weighted` to `a_t = exp(θT t x) / ZT t > 0`! -- Wait: `∏_t (exp(θT t x) / ZT t) ^ (μ t) ≤ ∑_t μ t * (exp(θT t x) / ZT t)`! -- Summing over `x`: `∑_x exp(∑_t μ t θT t x) / ∏_t (ZT t)^(μ t) ≤ ∑_t μ t * (ZT t / ZT t) = 1`! -- Taking `log`: `log Z(θ) ≤ ∑_t μ t log ZT(t)`!! have hpoint : ∀ x : V → X, Real.exp (∑ t : ι, μ t * θT t x) / Real.exp (∑ t : ι, μ t * Real.log (ZT t)) ≤ ∑ t : ι, μ t * (Real.exp (θT t x) / ZT t) := by intro x have hgeom := Real.geom_mean_le_arith_mean_weighted Finset.univ μ (fun t => Real.exp (θT t x) / ZT t) (fun t _ => hμ_nn t) hμ_sum (fun t _ => le_of_lt (div_pos (Real.exp_pos _) (hZT_pos t))) have hlhs : (∏ t : ι, (Real.exp (θT t x) / ZT t) ^ (μ t)) = Real.exp (∑ t : ι, μ t * θT t x) / Real.exp (∑ t : ι, μ t * Real.log (ZT t)) := by have hterm : ∀ t : ι, (Real.exp (θT t x) / ZT t) ^ (μ t) = Real.exp (μ t * θT t x - μ t * Real.log (ZT t)) := fun t => by rw [Real.rpow_def_of_pos (div_pos (Real.exp_pos _) (hZT_pos t)), Real.log_div (ne_of_gt (Real.exp_pos _)) (ne_of_gt (hZT_pos t)), Real.log_exp] congr 1; ring simp_rw [hterm, ← Real.exp_sum, Finset.sum_sub_distrib, Real.exp_sub] linarith have hsum_le : (∑ x : V → X, Real.exp (∑ t : ι, μ t * θT t x)) / Real.exp (∑ t : ι, μ t * Real.log (ZT t)) ≤ 1 := by rw [Finset.sum_div] calc ∑ x : V → X, Real.exp (∑ t : ι, μ t * θT t x) / Real.exp (∑ t : ι, μ t * Real.log (ZT t)) ≤ ∑ x : V → X, ∑ t : ι, μ t * (Real.exp (θT t x) / ZT t) := Finset.sum_le_sum fun x _ => hpoint x _ = ∑ t : ι, μ t * ((∑ x : V → X, Real.exp (θT t x)) / ZT t) := by rw [Finset.sum_comm] refine Finset.sum_congr rfl fun t _ => ?_ rw [← Finset.mul_sum, ← Finset.sum_div] _ = ∑ t : ι, μ t * 1 := Finset.sum_congr rfl fun t _ => by rw [div_self (ne_of_gt (hZT_pos t))] _ = 1 := by simp [hμ_sum] have hZ_pos : 0 < ∑ x : V → X, Real.exp (∑ t : ι, μ t * θT t x) := Finset.sum_pos (fun x _ => Real.exp_pos _) Finset.univ_nonempty have hle_exp : ∑ x : V → X, Real.exp (∑ t : ι, μ t * θT t x) ≤ Real.exp (∑ t : ι, μ t * Real.log (ZT t)) := (div_le_one (Real.exp_pos _)).mp hsum_le unfold logZOf have hlog := Real.log_le_log hZ_pos hle_exp rwa [Real.log_exp] at hlog /-- Edge appearance probability `ρ_{ij} = ∑_{t : T_t.Adj i j} μ_t` for a spanning-tree mixture `(T, μ)` on `G`. -/ noncomputable def edgeAppearProb {ι : Type*} [Fintype ι] (T : ι → SimpleGraph V) [∀ t, DecidableRel (T t).Adj] (μ : ι → ℝ) (i j : V) : ℝ := ∑ t : ι, if (T t).Adj i j then μ t else 0 /-- Tree-Reweighted (TRW) entropy `H_TRW(b; ρ) = ∑_i H(b_i) - ∑_{e={i,j}} ρ_e I(b_{ij})`. -/ noncomputable def trwEntropy (G : SimpleGraph V) [DecidableRel G.Adj] (ρ : V → V → ℝ) (b : LocalBelief G X) : ℝ := (∑ i : V, shannonH (b.bNode i)) - (1 / 2 : ℝ) * ∑ i : V, ∑ j ∈ G.neighborFinset i, ρ i j * pairMI b.bNode b.bEdge i j omit [Nonempty X] in /-- **Headline Theorem 3B (Exact Spanning-Tree Mixture Identity for TRW Entropy)**: For ANY convex combination `μ` of spanning trees `{T_t ≤ G}` (`∑_t μ_t = 1`) with edge appearance probabilities `ρ_{ij} = ∑_{t : T_t.Adj i j} μ_t`: `H_TRW(b; ρ) = ∑_t μ_t H_Bethe(T_t; b) = ∑_t μ_t H(q_{b, T_t})` for EVERY `b ∈ L°(G)`! -/ theorem trwEntropy_eq_weighted_treeEntropy {ι : Type*} [Fintype ι] (T : ι → SimpleGraph V) [∀ t, DecidableRel (T t).Adj] (hsub : ∀ t, T t ≤ G) (hTree : ∀ t, (T t).IsTree) (μ : ι → ℝ) (hμ_sum : ∑ t : ι, μ t = 1) (b : LocalBelief G X) : trwEntropy G (edgeAppearProb T μ) b = ∑ t : ι, μ t * betheEntropy (T t) b.bNode b.bEdge ∧ trwEntropy G (edgeAppearProb T μ) b = ∑ t : ι, μ t * shannonH (treeJoint (b.restrict (hsub t))) := by have h1 : trwEntropy G (edgeAppearProb T μ) b = ∑ t : ι, μ t * betheEntropy (T t) b.bNode b.bEdge := by have htree_mi : ∀ t : ι, betheEntropy (T t) b.bNode b.bEdge = (∑ i : V, shannonH (b.bNode i)) - (1 / 2 : ℝ) * ∑ i : V, ∑ j ∈ (T t).neighborFinset i, pairMI b.bNode b.bEdge i j := fun t => betheEntropy_eq_node_sub_mutualInfo (b.restrict (hsub t)) simp_rw [htree_mi, mul_sub, Finset.sum_sub_distrib, ← Finset.sum_mul, hμ_sum, one_mul] unfold trwEntropy edgeAppearProb congr 1 -- Swap sums over `t` and `(i, j)` using `T t ≤ G`! have hpull : ∑ t : ι, μ t * ((1 / 2 : ℝ) * ∑ i : V, ∑ j ∈ (T t).neighborFinset i, pairMI b.bNode b.bEdge i j) = (1 / 2 : ℝ) * ∑ t : ι, ∑ i : V, ∑ j ∈ G.neighborFinset i, (if (T t).Adj i j then μ t else 0) * pairMI b.bNode b.bEdge i j := by rw [Finset.mul_sum] refine Finset.sum_congr rfl fun t _ => ?_ have hsub_nb : ∀ i : V, (T t).neighborFinset i ⊆ G.neighborFinset i := fun i j hj => (SimpleGraph.mem_neighborFinset G i j).mpr (hsub t ((SimpleGraph.mem_neighborFinset (T t) i j).mp hj)) have hinner : ∀ i : V, μ t * (∑ j ∈ (T t).neighborFinset i, pairMI b.bNode b.bEdge i j) = ∑ j ∈ G.neighborFinset i, (if (T t).Adj i j then μ t else 0) * pairMI b.bNode b.bEdge i j := by intro i rw [Finset.mul_sum] rw [← Finset.sum_subset (hsub_nb i)] · refine Finset.sum_congr rfl fun j hj => ?_ have hadj : (T t).Adj i j := (SimpleGraph.mem_neighborFinset (T t) i j).mp hj simp [hadj] · intro j _ hj_not have hnot : ¬ (T t).Adj i j := fun hadj => hj_not ((SimpleGraph.mem_neighborFinset (T t) i j).mpr hadj) simp [hnot] calc μ t * ((1 / 2 : ℝ) * ∑ i : V, ∑ j ∈ (T t).neighborFinset i, pairMI b.bNode b.bEdge i j) = (1 / 2 : ℝ) * ∑ i : V, μ t * (∑ j ∈ (T t).neighborFinset i, pairMI b.bNode b.bEdge i j) := by rw [← Finset.mul_sum]; ring _ = (1 / 2 : ℝ) * ∑ i : V, ∑ j ∈ G.neighborFinset i, (if (T t).Adj i j then μ t else 0) * pairMI b.bNode b.bEdge i j := by congr 1; exact Finset.sum_congr rfl fun i _ => hinner i rw [hpull] congr 1 simp_rw [Finset.sum_mul] rw [Finset.sum_comm] refine Finset.sum_congr rfl fun i _ => ?_ rw [Finset.sum_comm] refine ⟨h1, ?_⟩ rw [h1] refine Finset.sum_congr rfl fun t _ => ?_ congr 1 exact tree_betheEntropy_eq_gibbsEntropy (hTree t) (b.restrict (hsub t)) omit [Nonempty X] in /-- **Headline Theorem 3C (Global Concavity & Strict Concavity of `H_TRW` on Arbitrary Graphs)**: Unlike `H_Bethe` (which is non-concave and even negative on `K_4`), for ANY finite graph `G` and ANY spanning-tree mixture `μ` (`μ t ≥ 0`, `∑ μ_t = 1`), `H_TRW(b; ρ)` is **ALWAYS nonnegative** and **globally concave** on `L°(G)` — and **STRICTLY concave** whenever `b₁, b₂` differ on any vertex or any edge with positive appearance probability `ρ_e > 0`! -/ theorem trwEntropy_nonneg_and_strictConcave {ι : Type*} [Fintype ι] (T : ι → SimpleGraph V) [∀ t, DecidableRel (T t).Adj] (hsub : ∀ t, T t ≤ G) (hTree : ∀ t, (T t).IsTree) (μ : ι → ℝ) (hμ_nn : ∀ t, 0 ≤ μ t) (hμ_sum : ∑ t : ι, μ t = 1) (b₁ b₂ : LocalBelief G X) {s : ℝ} (hs0 : 0 < s) (hs1 : s < 1) : 0 ≤ trwEntropy G (edgeAppearProb T μ) b₁ ∧ (1 - s) * trwEntropy G (edgeAppearProb T μ) b₁ + s * trwEntropy G (edgeAppearProb T μ) b₂ ≤ trwEntropy G (edgeAppearProb T μ) (b₁.convexComb b₂ (le_of_lt hs0) (le_of_lt hs1)) ∧ ((∃ t : ι, 0 < μ t ∧ ((∃ i a, b₁.bNode i a ≠ b₂.bNode i a) ∨ (∃ i j, (T t).Adj i j ∧ ∃ a c, b₁.bEdge i j a c ≠ b₂.bEdge i j a c))) → (1 - s) * trwEntropy G (edgeAppearProb T μ) b₁ + s * trwEntropy G (edgeAppearProb T μ) b₂ < trwEntropy G (edgeAppearProb T μ) (b₁.convexComb b₂ (le_of_lt hs0) (le_of_lt hs1))) := by let bm := b₁.convexComb b₂ (le_of_lt hs0) (le_of_lt hs1) have hH_nn : ∀ (b : LocalBelief G X) (t : ι), 0 ≤ shannonH (treeJoint (b.restrict (hsub t))) := by intro b t obtain ⟨hsum, _, _⟩ := treeJoint_marginals_exact (Fintype.card V) (T t) (hTree t) rfl (b.restrict (hsub t)) unfold shannonH have hle1 : ∀ x : V → X, treeJoint (b.restrict (hsub t)) x ≤ 1 := fun x => by have hle := Finset.single_le_sum (f := treeJoint (b.restrict (hsub t))) (fun y _ => le_of_lt (treeJoint_pos _ y)) (Finset.mem_univ x) linarith have hterm : ∀ x : V → X, treeJoint (b.restrict (hsub t)) x * Real.log (treeJoint (b.restrict (hsub t)) x) ≤ 0 := fun x => mul_nonpos_of_nonneg_of_nonpos (le_of_lt (treeJoint_pos _ x)) (Real.log_nonpos (le_of_lt (treeJoint_pos _ x)) (hle1 x)) have hsum_np : ∑ x : V → X, treeJoint (b.restrict (hsub t)) x * Real.log (treeJoint (b.restrict (hsub t)) x) ≤ 0 := Finset.sum_nonpos fun x _ => hterm x linarith -- Per-tree concavity (and strict concavity when `b₁, b₂` differ on tree `T t`) have htree_conc : ∀ t : ι, (1 - s) * betheEntropy (T t) b₁.bNode b₁.bEdge + s * betheEntropy (T t) b₂.bNode b₂.bEdge ≤ betheEntropy (T t) bm.bNode bm.bEdge := by intro t let M0 : PairwiseMRF (T t) X := { ψNode := fun _ _ => 1, ψEdge := fun _ _ _ _ => 1, ψNode_pos := fun _ _ => one_pos, ψEdge_pos := fun _ _ _ _ => one_pos, ψEdge_symm := fun _ _ _ _ => rfl } have hU0 : ∀ b : LocalBelief (T t) X, betheEnergy M0 b = 0 := fun b => by unfold betheEnergy; simp [M0] by_cases hne : (∃ i a, b₁.bNode i a ≠ b₂.bNode i a) ∨ (∃ i j, (T t).Adj i j ∧ ∃ a c, b₁.bEdge i j a c ≠ b₂.bEdge i j a c) · have hst := tree_betheFreeEnergy_strictConvex (hTree t) M0 (b₁.restrict (hsub t)) (b₂.restrict (hsub t)) hne hs0 hs1 unfold betheFreeEnergy at hst rw [hU0, hU0, hU0] at hst change 0 - betheEntropy (T t) bm.bNode bm.bEdge < (1 - s) * (0 - betheEntropy (T t) b₁.bNode b₁.bEdge) + s * (0 - betheEntropy (T t) b₂.bNode b₂.bEdge) at hst linarith · push Not at hne have h1 : betheEntropy (T t) b₁.bNode b₁.bEdge = betheEntropy (T t) bm.bNode bm.bEdge := by unfold betheEntropy pairH shannonH congr 1 · congr 1 refine Finset.sum_congr rfl fun i _ => Finset.sum_congr rfl fun j hj => ?_ have hij : (T t).Adj i j := (SimpleGraph.mem_neighborFinset (T t) i j).mp hj congr 1; refine Finset.sum_congr rfl fun p _ => ?_ have heq := hne.2 i j hij p.1 p.2 dsimp only [bm, LocalBelief.convexComb] rw [← heq]; ring_nf · refine Finset.sum_congr rfl fun i _ => ?_ congr 1; congr 1; refine Finset.sum_congr rfl fun a _ => ?_ have heq := hne.1 i a dsimp only [bm, LocalBelief.convexComb] rw [← heq]; ring_nf have h2 : betheEntropy (T t) b₂.bNode b₂.bEdge = betheEntropy (T t) bm.bNode bm.bEdge := by unfold betheEntropy pairH shannonH congr 1 · congr 1 refine Finset.sum_congr rfl fun i _ => Finset.sum_congr rfl fun j hj => ?_ have hij : (T t).Adj i j := (SimpleGraph.mem_neighborFinset (T t) i j).mp hj congr 1; refine Finset.sum_congr rfl fun p _ => ?_ have heq := hne.2 i j hij p.1 p.2 dsimp only [bm, LocalBelief.convexComb] rw [heq]; ring_nf · refine Finset.sum_congr rfl fun i _ => ?_ congr 1; congr 1; refine Finset.sum_congr rfl fun a _ => ?_ have heq := hne.1 i a dsimp only [bm, LocalBelief.convexComb] rw [heq]; ring_nf rw [h1, h2]; linarith refine ⟨?_, ?_, ?_⟩ · rw [(trwEntropy_eq_weighted_treeEntropy T hsub hTree μ hμ_sum b₁).2] exact Finset.sum_nonneg fun t _ => mul_nonneg (hμ_nn t) (hH_nn b₁ t) · rw [(trwEntropy_eq_weighted_treeEntropy T hsub hTree μ hμ_sum b₁).1, (trwEntropy_eq_weighted_treeEntropy T hsub hTree μ hμ_sum b₂).1, (trwEntropy_eq_weighted_treeEntropy T hsub hTree μ hμ_sum bm).1, Finset.mul_sum, Finset.mul_sum, ← Finset.sum_add_distrib] refine Finset.sum_le_sum fun t _ => ?_ have hm := mul_le_mul_of_nonneg_left (htree_conc t) (hμ_nn t) linarith · rintro ⟨t0, ht0_pos, hne0⟩ rw [(trwEntropy_eq_weighted_treeEntropy T hsub hTree μ hμ_sum b₁).1, (trwEntropy_eq_weighted_treeEntropy T hsub hTree μ hμ_sum b₂).1, (trwEntropy_eq_weighted_treeEntropy T hsub hTree μ hμ_sum bm).1, Finset.mul_sum, Finset.mul_sum, ← Finset.sum_add_distrib] let M0 : PairwiseMRF (T t0) X := { ψNode := fun _ _ => 1, ψEdge := fun _ _ _ _ => 1, ψNode_pos := fun _ _ => one_pos, ψEdge_pos := fun _ _ _ _ => one_pos, ψEdge_symm := fun _ _ _ _ => rfl } have hU0 : ∀ b : LocalBelief (T t0) X, betheEnergy M0 b = 0 := fun b => by unfold betheEnergy; simp [M0] have hst := tree_betheFreeEnergy_strictConvex (hTree t0) M0 (b₁.restrict (hsub t0)) (b₂.restrict (hsub t0)) hne0 hs0 hs1 unfold betheFreeEnergy at hst rw [hU0, hU0, hU0] at hst change 0 - betheEntropy (T t0) bm.bNode bm.bEdge < (1 - s) * (0 - betheEntropy (T t0) b₁.bNode b₁.bEdge) + s * (0 - betheEntropy (T t0) b₂.bNode b₂.bEdge) at hst refine Finset.sum_lt_sum (fun t _ => by have hm := mul_le_mul_of_nonneg_left (htree_conc t) (hμ_nn t); linarith) ⟨t0, Finset.mem_univ t0, by nlinarith⟩ /-- **Headline Theorem 3D (Exact Dual Variational TRW Upper Bound & Tightness on Trees)**: For ANY pairwise MRF `M` on `G`, ANY spanning-tree mixture `(T, μ)` (`μ t ≥ 0`, `∑ μ_t = 1`), and ANY tree-reweighted MRF family `MT : ι → PairwiseMRF (T t) X` whose log-potentials average to `M` (`log M.unnormWeight x = ∑_t μ_t log (MT t).unnormWeight x`): 1. **Universal Dual Variational Upper Bound**: For EVERY `b ∈ L°(G)`, `-betheEnergy M b + H_TRW(b; ρ) = ∑_t μ_t (log Z(MT t) - D_KL(q_{b, T_t} ‖ p_{MT t})) ≤ ∑_t μ_t log Z(MT t)`; 2. **Exact Sandwich at Exact Gibbs Marginals**: `log Z(M) ≤ -betheEnergy M M.exactBelief + H_TRW(M.exactBelief; ρ) ≤ ∑_t μ_t log Z(MT t)`! 3. **Exact Tightness on Trees (`ρ_e = 1`)**: When `G` itself is a tree (`ι = Unit`, `T () = G`, `μ () = 1`), `log Z(M) = -betheEnergy M M.exactBelief + H_TRW(M.exactBelief; ρ)`! -/ theorem trw_dual_variational_upper_bound {ι : Type*} [Fintype ι] (M : PairwiseMRF G X) (T : ι → SimpleGraph V) [∀ t, DecidableRel (T t).Adj] (hsub : ∀ t, T t ≤ G) (hTree : ∀ t, (T t).IsTree) (μ : ι → ℝ) (hμ_nn : ∀ t, 0 ≤ μ t) (hμ_sum : ∑ t : ι, μ t = 1) (MT : ∀ t : ι, PairwiseMRF (T t) X) (hdecomp_energy : ∀ b : LocalBelief G X, betheEnergy M b = ∑ t : ι, μ t * betheEnergy (MT t) (b.restrict (hsub t))) : -- 1. Exact variational identity & upper bound for EVERY `b ∈ L°(G)` (∀ b : LocalBelief G X, -betheEnergy M b + trwEntropy G (edgeAppearProb T μ) b = ∑ t : ι, μ t * (Real.log (MT t).Z - klDiv (treeJoint (b.restrict (hsub t))) (MT t).gibbs) ∧ -betheEnergy M b + trwEntropy G (edgeAppearProb T μ) b ≤ ∑ t : ι, μ t * Real.log (MT t).Z) ∧ -- 2. Exact lower bound by `log Z(M)` at `M.exactBelief`! Real.log M.Z ≤ -betheEnergy M M.exactBelief + trwEntropy G (edgeAppearProb T μ) M.exactBelief := by have h1 : ∀ b : LocalBelief G X, -betheEnergy M b + trwEntropy G (edgeAppearProb T μ) b = ∑ t : ι, μ t * (Real.log (MT t).Z - klDiv (treeJoint (b.restrict (hsub t))) (MT t).gibbs) := by intro b rw [hdecomp_energy b, (trwEntropy_eq_weighted_treeEntropy T hsub hTree μ hμ_sum b).1] have hstep : ∀ t : ι, -(μ t * betheEnergy (MT t) (b.restrict (hsub t))) + μ t * betheEntropy (T t) b.bNode b.bEdge = μ t * (Real.log (MT t).Z - klDiv (treeJoint (b.restrict (hsub t))) (MT t).gibbs) := by intro t have hFE := tree_betheFreeEnergy_eq_kl_sub_logZ (hTree t) (MT t) (b.restrict (hsub t)) unfold betheFreeEnergy at hFE have hbn : (b.restrict (hsub t)).bNode = b.bNode := rfl have hbe : (b.restrict (hsub t)).bEdge = b.bEdge := rfl rw [hbn, hbe] at hFE linarith [congrArg (fun z => μ t * z) hFE] rw [← Finset.sum_neg_distrib, ← Finset.sum_add_distrib] exact Finset.sum_congr rfl fun t _ => hstep t refine ⟨fun b => ⟨h1 b, ?_⟩, ?_⟩ · rw [h1 b] refine Finset.sum_le_sum fun t _ => ?_ obtain ⟨hsum_t, _, _⟩ := treeJoint_marginals_exact (Fintype.card V) (T t) (hTree t) rfl (b.restrict (hsub t)) have hkl := klDiv_nonneg (treeJoint_pos _) (MT t).gibbs_pos hsum_t (MT t).sum_gibbs nlinarith [hμ_nn t] · -- Prove `log Z(M) ≤ -betheEnergy M M.exactBelief + H_TRW(M.exactBelief; ρ)` via -- `log Z(M) = -betheEnergy M M.exactBelief + H(M.gibbs)` and `H(M.gibbs) ≤ H_Bethe(T_t; M.exactBelief)`! have hgibbs_eq : Real.log M.Z = -betheEnergy M M.exactBelief + shannonH M.gibbs := by have hlog_g : ∀ x : V → X, Real.log (M.gibbs x) = (∑ i : V, Real.log (M.ψNode i (x i))) + (1 / 2 : ℝ) * (∑ i : V, ∑ j ∈ G.neighborFinset i, Real.log (M.ψEdge i j (x i) (x j))) - Real.log M.Z := by intro x unfold PairwiseMRF.gibbs PairwiseMRF.unnormWeight rw [Real.log_div (ne_of_gt (mul_pos (Finset.prod_pos fun i _ => M.ψNode_pos i (x i)) (Finset.prod_pos fun e _ => M.edgeWeight_pos x e))) (ne_of_gt M.Z_pos), Real.log_mul (ne_of_gt (Finset.prod_pos fun i _ => M.ψNode_pos i (x i))) (ne_of_gt (Finset.prod_pos fun e _ => M.edgeWeight_pos x e)), Real.log_prod (fun i _ => ne_of_gt (M.ψNode_pos i (x i))), Real.log_prod (fun e _ => ne_of_gt (M.edgeWeight_pos x e)), half_sum_neighbors_eq_sum_edgeFinset _ (fun i j => by rw [M.ψEdge_symm])] congr 1; congr 1 refine Finset.sum_congr rfl fun e _ => ?_ induction e using Sym2.ind with | _ i j => rfl have hnode_g : ∀ i a, ∑ x : V → X, (if x i = a then M.gibbs x else 0) = M.exactBelief.bNode i a := fun _ _ => rfl have hedge_g : ∀ i j, G.Adj i j → ∀ a c, ∑ x : V → X, (if x i = a ∧ x j = c then M.gibbs x else 0) = M.exactBelief.bEdge i j a c := fun i j hij a c => by simp [PairwiseMRF.exactBelief, hij.ne] unfold shannonH simp_rw [hlog_g, mul_sub, mul_add, Finset.sum_sub_distrib, Finset.sum_add_distrib, ← Finset.sum_mul, M.sum_gibbs, one_mul] have h1e : ∑ x : V → X, M.gibbs x * ∑ i : V, Real.log (M.ψNode i (x i)) = ∑ i : V, ∑ a : X, M.exactBelief.bNode i a * Real.log (M.ψNode i a) := by simp_rw [Finset.mul_sum]; rw [Finset.sum_comm] exact Finset.sum_congr rfl fun i _ => expect_node_of_marg hnode_g (fun u a => Real.log (M.ψNode u a)) i have h2e : ∑ x : V → X, M.gibbs x * ((1 / 2 : ℝ) * ∑ i : V, ∑ j ∈ G.neighborFinset i, Real.log (M.ψEdge i j (x i) (x j))) = (1 / 2 : ℝ) * ∑ i : V, ∑ j ∈ G.neighborFinset i, ∑ a : X, ∑ c : X, M.exactBelief.bEdge i j a c * Real.log (M.ψEdge i j a c) := by have hpull : ∀ x : V → X, M.gibbs x * ((1 / 2 : ℝ) * ∑ i : V, ∑ j ∈ G.neighborFinset i, Real.log (M.ψEdge i j (x i) (x j))) = (1 / 2 : ℝ) * ∑ i : V, ∑ j ∈ G.neighborFinset i, M.gibbs x * Real.log (M.ψEdge i j (x i) (x j)) := by intro x rw [← mul_assoc, mul_comm (M.gibbs x) (1 / 2 : ℝ), mul_assoc, Finset.mul_sum] congr 1; refine Finset.sum_congr rfl fun i _ => Finset.mul_sum _ _ _ rw [Finset.sum_congr rfl fun x _ => hpull x, ← Finset.mul_sum]; congr 1 calc ∑ x : V → X, ∑ i : V, ∑ j ∈ G.neighborFinset i, M.gibbs x * Real.log (M.ψEdge i j (x i) (x j)) = ∑ i : V, ∑ x : V → X, ∑ j ∈ G.neighborFinset i, M.gibbs x * Real.log (M.ψEdge i j (x i) (x j)) := Finset.sum_comm _ = ∑ i : V, ∑ j ∈ G.neighborFinset i, ∑ x : V → X, M.gibbs x * Real.log (M.ψEdge i j (x i) (x j)) := Finset.sum_congr rfl fun i _ => Finset.sum_comm _ = _ := Finset.sum_congr rfl fun i _ => Finset.sum_congr rfl fun j hj => expect_edge_of_marg hedge_g (fun u v a c => Real.log (M.ψEdge u v a c)) ((SimpleGraph.mem_neighborFinset G i j).mp hj) rw [h1e, h2e]; unfold betheEnergy; ring -- For every spanning tree `T t ≤ G`, `H(M.gibbs) ≤ H_Bethe(T t; M.exactBelief)` by `tree_maxEntropy_identity`! have hH_le_tree : ∀ t : ι, shannonH M.gibbs ≤ betheEntropy (T t) M.exactBelief.bNode M.exactBelief.bEdge := by intro t have hid := tree_maxEntropy_identity (hTree t) (M.exactBelief.restrict (hsub t)) (fun _ _ => rfl) (fun i j hij a c => by simp [LocalBelief.restrict, PairwiseMRF.exactBelief, (hsub t hij).ne]) M.gibbs_pos obtain ⟨hsum_t, _, _⟩ := treeJoint_marginals_exact (Fintype.card V) (T t) (hTree t) rfl (M.exactBelief.restrict (hsub t)) have hkl := klDiv_nonneg M.gibbs_pos (treeJoint_pos _) M.sum_gibbs hsum_t change betheEntropy (T t) M.exactBelief.bNode M.exactBelief.bEdge - shannonH M.gibbs = _ at hid linarith rw [hgibbs_eq, (trwEntropy_eq_weighted_treeEntropy T hsub hTree μ hμ_sum M.exactBelief).1] have havg : shannonH M.gibbs ≤ ∑ t : ι, μ t * betheEntropy (T t) M.exactBelief.bNode M.exactBelief.bEdge := by calc shannonH M.gibbs = (∑ t : ι, μ t) * shannonH M.gibbs := by rw [hμ_sum, one_mul] _ = ∑ t : ι, μ t * shannonH M.gibbs := Finset.sum_mul _ _ _ _ ≤ ∑ t : ι, μ t * betheEntropy (T t) M.exactBelief.bNode M.exactBelief.bEdge := Finset.sum_le_sum fun t _ => mul_le_mul_of_nonneg_left (hH_le_tree t) (hμ_nn t) linarith /-- **Exact Tightness of TRW on Trees (`ρ_e = 1`)**: When `G` is a tree and `μ` puts mass 1 on `G` itself, `H_TRW = H_Bethe` and the TRW variational upper bound equals `log Z(M)` **EXACTLY**. -/ theorem trw_tight_on_tree (hT : G.IsTree) (M : PairwiseMRF G X) : -betheEnergy M M.exactBelief + trwEntropy G (edgeAppearProb (fun _ : Unit => G) (fun _ => 1)) M.exactBelief = Real.log M.Z := by have htrw := (trwEntropy_eq_weighted_treeEntropy (fun _ : Unit => G) (fun _ => le_refl G) (fun _ => hT) (fun _ => 1) (by simp) M.exactBelief).1 simp only [Finset.univ_unique, Finset.sum_singleton, one_mul] at htrw rw [htrw] have hmin := (tree_betheFreeEnergy_min_iff hT M M.exactBelief).2.mpr ⟨fun _ _ => rfl, fun _ _ _ _ _ => rfl⟩ unfold betheFreeEnergy at hmin linarith /-- **Headline Theorem 3E (Strict Bethe–True–TRW Sandwich on `K_3`)**: On the triangle `K_3` with uniform spanning-tree distribution (`μ_T = 1/3`, `ρ_e = 2/3`) and ANY ferromagnetic Ising coupling `J > 0`: `-F_Bethe(b^BP) = 3 log(2 cosh J) < log Z_{K_3}(J) < log 2 + 2 log(2 cosh(3J/2)) = TRW_{K_3}(J)`! -/ theorem trw_bethe_sandwich_K3 {J : ℝ} (hJ : 0 < J) : let Z_K3 := 2 * Real.exp (3 * J) + 6 * Real.exp (-J) let logZ_Bethe := 3 * Real.log (2 * Real.cosh J) let logZ_TRW := Real.log 2 + 2 * Real.log (2 * Real.cosh ((3 / 2 : ℝ) * J)) logZ_Bethe < Real.log Z_K3 ∧ Real.log Z_K3 < logZ_TRW := by intro Z_K3 logZ_Bethe logZ_TRW have h1 := (bethe_vs_true_logZ_gap_K3 hJ).2 refine ⟨by linarith, ?_⟩ -- Prove `Z_K3 < 2 * (2 cosh(3J/2))^2 = 2 * (e^(3J) + 2 + e^(-3J))`! -- Notice `2(e^(3J) + 2 + e^(-3J)) - (2 e^(3J) + 6 e^(-J)) = 2(2 + e^(-3J) - 3 e^(-J)) = 2(1 - e^(-J))^2 (2 + e^(-J)) > 0`!! -- WHOA!! LOOK AT THAT EXACT ALGEBRAIC FACTORIZATION: -- `2 + t^3 - 3t = (1 - t)^2 * (2 + t) > 0` for ALL `t = e^(-J) ∈ (0, 1)`!! have hTRW_eq : logZ_TRW = Real.log (2 * (2 * Real.cosh ((3 / 2 : ℝ) * J)) ^ 2) := by dsimp only [logZ_TRW] have hc_pos : 0 < 2 * Real.cosh ((3 / 2 : ℝ) * J) := mul_pos two_pos (Real.cosh_pos _) rw [Real.log_mul (by norm_num) (ne_of_gt (pow_pos hc_pos 2)), Real.log_pow] norm_num rw [hTRW_eq] have hZK3_pos : 0 < Z_K3 := add_pos (mul_pos two_pos (Real.exp_pos _)) (mul_pos (by norm_num) (Real.exp_pos _)) apply Real.log_lt_log hZK3_pos have hexp_sq : (2 * Real.cosh ((3 / 2 : ℝ) * J)) ^ 2 = Real.exp (3 * J) + 2 + Real.exp (-3 * J) := by rw [Real.cosh_eq] have h1a : Real.exp ((3 / 2 : ℝ) * J) ^ 2 = Real.exp (3 * J) := by rw [sq, ← Real.exp_add]; congr 1; ring have h2a : Real.exp (-((3 / 2 : ℝ) * J)) ^ 2 = Real.exp (-3 * J) := by rw [sq, ← Real.exp_add]; congr 1; ring have h3a : Real.exp ((3 / 2 : ℝ) * J) * Real.exp (-((3 / 2 : ℝ) * J)) = 1 := by rw [← Real.exp_add, add_neg_cancel, Real.exp_zero] calc (2 * ((Real.exp ((3 / 2 : ℝ) * J) + Real.exp (-((3 / 2 : ℝ) * J))) / 2)) ^ 2 = Real.exp ((3 / 2 : ℝ) * J) ^ 2 + 2 * (Real.exp ((3 / 2 : ℝ) * J) * Real.exp (-((3 / 2 : ℝ) * J))) + Real.exp (-((3 / 2 : ℝ) * J)) ^ 2 := by ring _ = Real.exp (3 * J) + 2 + Real.exp (-3 * J) := by rw [h1a, h2a, h3a]; ring rw [hexp_sq] dsimp only [Z_K3] set t := Real.exp (-J) have ht_pos : 0 < t := Real.exp_pos (-J) have ht_lt1 : t < 1 := Real.exp_lt_one_iff.mpr (by linarith) have ht3 : Real.exp (-3 * J) = t ^ 3 := by dsimp only [t]; rw [← Real.exp_nat_mul]; congr 1; ring rw [ht3] have hfact : 2 * (Real.exp (3 * J) + 2 + t ^ 3) - (2 * Real.exp (3 * J) + 6 * t) = 2 * (1 - t) ^ 2 * (2 + t) := by ring have hpos_diff : 0 < 2 * (1 - t) ^ 2 * (2 + t) := mul_pos (mul_pos two_pos (sq_pos_of_pos (sub_pos.mpr ht_lt1))) (by linarith) linarith end TRWBounds /-! ## Axiom Verification Audit -/ #print axioms klDiv_nonneg #print axioms klDiv_eq_zero_iff #print axioms shannonH_strictConcave #print axioms conditionalEntropy_concave #print axioms betheEntropy_eq_node_sub_mutualInfo #print axioms treeJoint_marginals_exact #print axioms tree_maxEntropy_identity #print axioms tree_betheEntropy_eq_gibbsEntropy #print axioms tree_betheFreeEnergy_eq_kl_sub_logZ #print axioms tree_betheFreeEnergy_min_iff #print axioms tree_betheFreeEnergy_strictConvex #print axioms hasDerivAt_betheLagrangian_node #print axioms hasDerivAt_betheLagrangian_edge #print axioms yfw_bp_implies_betheStationary #print axioms yfw_bijection #print axioms single_cycle_betheEntropy_concave #print axioms bethe_vs_true_logZ_gap_K3 #print axioms bethe_vs_true_logZ_gap_C4 #print axioms bethe_nonconvex_and_negative_entropy_K4 #print axioms twoCluster_kikuchi_exact #print axioms c4_kikuchi_exact_attainment #print axioms trw_logZ_upper_bound #print axioms trwEntropy_eq_weighted_treeEntropy #print axioms trwEntropy_nonneg_and_strictConcave #print axioms trw_dual_variational_upper_bound #print axioms trw_tight_on_tree #print axioms trw_bethe_sandwich_K3 end BetheKikuchiTRW