import Mathlib /-! # Pillar 4: Sharp Loopy-BP Contraction, Hilbert-Metric Uniqueness Thresholds & Symmetry-Breaking Phase Transitions This standalone Lean 4 + Mathlib formalization proves the exact contraction and phase-transition theory of Loopy Belief Propagation on arbitrary finite pairwise binary factor graphs / Ising MRFs. ## Headline Results 1. **Exact Single-Edge Cavity-Field Map & Sharp `tanh(|J|)` Derivative Bound** (`tanh_phi_eq`, `hasDerivAt_phi`, `abs_phiDeriv_le_tanh_abs`, `phi_lipschitz_tanh_abs`, `abs_phiDeriv_zero_eq_tanh_abs`): Defining `φ_J(x) = (1/2) log (cosh(x + J) / cosh(x - J)) = artanh(tanh(J) · tanh(x))`: - Exact derivative `φ'_J(x) = sinh(2J) / (cosh(2x) + cosh(2J))`; - Exact sharp global Lipschitz constant `|φ_J(x) - φ_J(y)| ≤ tanh(|J|) · |x - y|`, attained with equality at `x = 0`; - Strict box contraction `|φ_J(x)| < |J|` for all `J ≠ 0` and all `x ∈ ℝ`. 2. **Exact Equivalence with Binary Sum-Product BP & Hilbert Projective Metric** (`sumProdNormStep_ising_eq_phi`, `hilbertMetric_eq_two_mul_abs_sub`, `general_2x2_hilbert_contraction`): - One synchronous normalized Sum-Product BP step on any binary Ising MRF with arbitrary fields `h_i` and couplings `J_{ij}` corresponds identically to the cavity-field map `u_{i → j} ↦ φ_{J_{ij}}(h_i + ∑_{k ∈ N(i)\{j\}} u_{k → i})`. - The Hilbert projective metric `d_H(m, m') = log max_{σ,σ'} (m(σ)/m'(σ))/(m(σ')/m'(σ'))` equals `2 |u - u'|` identically. - For any strictly positive `2 × 2` potential matrix `ψ > 0`, the exact Hilbert contraction factor is `tanh(|J_eff(ψ)|)` with `J_eff(ψ) = (1/4) log ((ψ_{TT} ψ_{FF})/(ψ_{TF} ψ_{FT}))`. 3. **Sharp Global Loopy-BP Contraction, Uniqueness & Geometric Rate** (`loopyBP_heterogeneous_contraction`, `loopyBP_bethe_threshold_unique`, `loopyBP_geometric_convergence`, `loopyBP_damped_contraction`, `loopyBP_normMsg_unique_and_converges`, `loopyBP_belief_error_bound`): - On any finite graph `G` with maximum degree `Δ` and couplings `|J_{ij}| ≤ J` (and arbitrary heterogeneous external fields `h_i ∈ ℝ`), whenever `(Δ - 1) · tanh(J) < 1`: - Loopy BP admits a **unique** global fixed point `u^*` (and unique normalized positive Sum-Product BP fixed point `m^*`); - From **any** initial message vector `u^(0)`, synchronous BP converges geometrically at rate `κ^t = ((Δ - 1) · tanh(J))^t`, with explicit non-asymptotic bound `‖u^(t) - u^*‖_∞ ≤ 2J · κ^(t - 1)` for all `t ≥ 1`; - Damped BP `(1 - α) u + α T(u)` (`α ∈ (0, 1]`) contracts at rate `1 - α(1 - κ) < 1`. 4. **Exact Sharpness & 3-Fixed-Point Symmetry-Breaking Phase Transition** (`bethe_peierls_unique_zero_le_one`, `bethe_peierls_exact_three_roots`, `regular_graph_three_bp_fixed_points`, `k4_three_bp_fixed_points`): - For any `Δ`-regular graph `G` (`Δ ≥ 3`, zero field `h = 0`, uniform ferromagnetic `J > 0`): - If `(Δ - 1) · tanh(J) ≤ 1`, then `u = 0` is the **unique** uniform BP fixed point. - If `(Δ - 1) · tanh(J) > 1` (equivalently `J > (1/2) log (Δ / (Δ - 2))`), there exists a **unique** `u^* ∈ (0, J)` solving `u^* = φ_J((Δ - 1) u^*)`, yielding **exactly 3** uniform BP fixed points `{-u^*, 0, +u^*}` and **3 pairwise distinct normalized positive Sum-Product BP fixed points** on `G` (explicitly instantiated on `K_{Δ+1}` and `K_4`) with strictly ordered single-node beliefs `b^{(-)}(true) < 1/2 = b^{(0)}(true) < b^{(+)}(true)`. -/ open scoped BigOperators open Finset Real SimpleGraph namespace LoopyBPContraction /-! ## Section 1: Exact Single-Edge Cavity-Field Map `φ_J(x)` and Sharp `tanh(|J|)` Contraction -/ section CavityFieldMap /-- Bipolar spin encoding `σ(true) = +1`, `σ(false) = -1`. -/ def spin (b : Bool) : ℝ := if b then 1 else -1 @[simp] lemma spin_true : spin true = 1 := rfl @[simp] lemma spin_false : spin false = -1 := rfl /-- Exact cavity-field propagation function `φ_J(x) = (1/2) log (cosh(x + J) / cosh(x - J)) = artanh(tanh(J) · tanh(x))`. -/ noncomputable def phi (J x : ℝ) : ℝ := (1 / 2 : ℝ) * Real.log (Real.cosh (x + J) / Real.cosh (x - J)) /-- Exact trigonometric-hyperbolic identity `2 cosh(x + J) cosh(x - J) = cosh(2x) + cosh(2J)`. -/ lemma two_mul_cosh_add_mul_cosh_sub (x J : ℝ) : 2 * Real.cosh (x + J) * Real.cosh (x - J) = Real.cosh (2 * x) + Real.cosh (2 * J) := by rw [Real.cosh_eq, Real.cosh_eq, Real.cosh_eq, Real.cosh_eq] have h1 : Real.exp (x + J) * Real.exp (x - J) = Real.exp (2 * x) := by rw [← Real.exp_add]; congr 1; ring have h2 : Real.exp (-(x + J)) * Real.exp (-(x - J)) = Real.exp (-(2 * x)) := by rw [← Real.exp_add]; congr 1; ring have h3 : Real.exp (x + J) * Real.exp (-(x - J)) = Real.exp (2 * J) := by rw [← Real.exp_add]; congr 1; ring have h4 : Real.exp (-(x + J)) * Real.exp (x - J) = Real.exp (-(2 * J)) := by rw [← Real.exp_add]; congr 1; ring linear_combination (1 / 2) * h1 + (1 / 2) * h2 + (1 / 2) * h3 + (1 / 2) * h4 lemma sinh_two_mul (J : ℝ) : Real.sinh (2 * J) = 2 * Real.sinh J * Real.cosh J := by rw [two_mul, Real.sinh_add]; ring lemma one_add_cosh_two_mul (J : ℝ) : 1 + Real.cosh (2 * J) = 2 * (Real.cosh J) ^ 2 := by have h := two_mul_cosh_add_mul_cosh_sub 0 J simp only [mul_zero, Real.cosh_zero, zero_add, zero_sub, Real.cosh_neg] at h linarith lemma tanh_eq_sinh_two_div (J : ℝ) : Real.tanh J = Real.sinh (2 * J) / (1 + Real.cosh (2 * J)) := by rw [Real.tanh_eq_sinh_div_cosh, sinh_two_mul, one_add_cosh_two_mul] have hc : Real.cosh J ≠ 0 := ne_of_gt (Real.cosh_pos J) field_simp [hc] /-- `φ_J(0) = 0`. -/ @[simp] lemma phi_zero (J : ℝ) : phi J 0 = 0 := by unfold phi simp [Real.cosh_neg] /-- `φ_0(x) = 0`. -/ @[simp] lemma phi_zero_coupling (x : ℝ) : phi 0 x = 0 := by unfold phi; simp /-- Odd symmetry: `φ_J(-x) = -φ_J(x)`. -/ lemma phi_neg (J x : ℝ) : phi J (-x) = -phi J x := by unfold phi have h1 : -x + J = -(x - J) := by ring have h2 : -x - J = -(x + J) := by ring rw [h1, h2, Real.cosh_neg, Real.cosh_neg, ← inv_div (Real.cosh (x + J)) (Real.cosh (x - J)), Real.log_inv] ring /-- Exact `tanh` composition identity: `tanh(φ_J(x)) = tanh(J) · tanh(x)`. -/ theorem tanh_phi_eq (J x : ℝ) : Real.tanh (phi J x) = Real.tanh J * Real.tanh x := by unfold phi have hp : 0 < Real.cosh (x + J) := Real.cosh_pos _ have hm : 0 < Real.cosh (x - J) := Real.cosh_pos _ have hdiv : 0 < Real.cosh (x + J) / Real.cosh (x - J) := div_pos hp hm set r := Real.cosh (x + J) / Real.cosh (x - J) have hexp : Real.exp (2 * ((1 / 2 : ℝ) * Real.log r)) = r := by have : 2 * ((1 / 2 : ℝ) * Real.log r) = Real.log r := by ring rw [this, Real.exp_log hdiv] have htanh_exp : ∀ t : ℝ, Real.tanh t = (Real.exp (2 * t) - 1) / (Real.exp (2 * t) + 1) := by intro t rw [Real.tanh_eq_sinh_div_cosh, Real.sinh_eq, Real.cosh_eq] have hpos : Real.exp t ≠ 0 := ne_of_gt (Real.exp_pos t) have h2 : Real.exp (2 * t) = Real.exp t * Real.exp t := by rw [two_mul, Real.exp_add] have hneg : Real.exp (-t) = (Real.exp t)⁻¹ := Real.exp_neg t rw [h2, hneg] field_simp [hpos] rw [htanh_exp, hexp] have hnum : r - 1 = (2 * Real.sinh x * Real.sinh J) / Real.cosh (x - J) := by dsimp only [r] rw [div_sub_one (ne_of_gt hm), Real.cosh_add, Real.cosh_sub] ring have hden : r + 1 = (2 * Real.cosh x * Real.cosh J) / Real.cosh (x - J) := by dsimp only [r] rw [div_add_one (ne_of_gt hm), Real.cosh_add, Real.cosh_sub] ring rw [hnum, hden, Real.tanh_eq_sinh_div_cosh, Real.tanh_eq_sinh_div_cosh] have hcx : Real.cosh x ≠ 0 := ne_of_gt (Real.cosh_pos x) have hcJ : Real.cosh J ≠ 0 := ne_of_gt (Real.cosh_pos J) have hcm : Real.cosh (x - J) ≠ 0 := ne_of_gt hm field_simp [hcx, hcJ, hcm] /-- Exact derivative of `φ_J`: `φ'_J(x) = sinh(2J) / (cosh(2x) + cosh(2J))`. -/ theorem hasDerivAt_phi (J x : ℝ) : HasDerivAt (phi J) (Real.sinh (2 * J) / (Real.cosh (2 * x) + Real.cosh (2 * J))) x := by unfold phi have h1 : HasDerivAt (fun t => Real.cosh (t + J)) (Real.sinh (x + J)) x := by simpa [Function.comp_def] using (Real.hasDerivAt_cosh (x + J)).comp x ((hasDerivAt_id x).add_const J) have h2 : HasDerivAt (fun t => Real.cosh (t - J)) (Real.sinh (x - J)) x := by simpa [Function.comp_def] using (Real.hasDerivAt_cosh (x - J)).comp x ((hasDerivAt_id x).sub_const J) have hq : HasDerivAt (fun t => Real.cosh (t + J) / Real.cosh (t - J)) ((Real.sinh (x + J) * Real.cosh (x - J) - Real.cosh (x + J) * Real.sinh (x - J)) / (Real.cosh (x - J)) ^ 2) x := h1.div h2 (ne_of_gt (Real.cosh_pos _)) have hpos : Real.cosh (x + J) / Real.cosh (x - J) ≠ 0 := ne_of_gt (div_pos (Real.cosh_pos _) (Real.cosh_pos _)) have hlog := hq.log hpos have hmul := hlog.const_mul (1 / 2 : ℝ) refine hmul.congr_deriv ?_ have hsinh_sub : Real.sinh (x + J) * Real.cosh (x - J) - Real.cosh (x + J) * Real.sinh (x - J) = Real.sinh (2 * J) := by have h := Real.sinh_sub (x + J) (x - J) have h2J : x + J - (x - J) = 2 * J := by ring rw [h2J] at h exact h.symm rw [hsinh_sub] have hden := two_mul_cosh_add_mul_cosh_sub x J have hc1 : Real.cosh (x + J) ≠ 0 := ne_of_gt (Real.cosh_pos _) have hc2 : Real.cosh (x - J) ≠ 0 := ne_of_gt (Real.cosh_pos _) have hsum_pos : Real.cosh (2 * x) + Real.cosh (2 * J) ≠ 0 := ne_of_gt (add_pos (Real.cosh_pos _) (Real.cosh_pos _)) rw [← hden] field_simp [hc1, hc2] /-- Sharp global derivative bound: `|φ'_J(x)| ≤ tanh(|J|)` for all `J, x ∈ ℝ`. -/ theorem abs_phiDeriv_le_tanh_abs (J x : ℝ) : |Real.sinh (2 * J) / (Real.cosh (2 * x) + Real.cosh (2 * J))| ≤ Real.tanh |J| := by have hden_pos : 0 < Real.cosh (2 * x) + Real.cosh (2 * J) := add_pos (Real.cosh_pos _) (Real.cosh_pos _) have h1_le : 1 ≤ Real.cosh (2 * x) := Real.one_le_cosh (2 * x) have habs_sinh : |Real.sinh (2 * J)| = Real.sinh (2 * |J|) := by rcases le_total 0 J with hJ | hJ · rw [abs_of_nonneg hJ, abs_of_nonneg (Real.sinh_nonneg_iff.mpr (by linarith))] · rw [abs_of_nonpos hJ] have hneg : 2 * (-J) = -(2 * J) := by ring rw [hneg, Real.sinh_neg, abs_of_nonpos (Real.sinh_nonpos_iff.mpr (by linarith))] have hcosh_abs : Real.cosh (2 * J) = Real.cosh (2 * |J|) := by rcases le_total 0 J with hJ | hJ · rw [abs_of_nonneg hJ] · rw [abs_of_nonpos hJ, mul_neg, Real.cosh_neg] rw [abs_div, abs_of_pos hden_pos, habs_sinh, tanh_eq_sinh_two_div |J|, ← hcosh_abs] have hnum_nonneg : 0 ≤ Real.sinh (2 * |J|) := Real.sinh_nonneg_iff.mpr (by positivity) have hden1_pos : 0 < 1 + Real.cosh (2 * J) := by linarith [Real.cosh_pos (2 * J)] exact div_le_div_of_nonneg_left hnum_nonneg hden1_pos (by linarith) /-- Strict derivative bound for `x ≠ 0` and `J > 0`: `φ'_J(x) < tanh(J)`. -/ lemma phiDeriv_lt_tanh_of_ne_zero {J x : ℝ} (hJ : 0 < J) (hx : x ≠ 0) : Real.sinh (2 * J) / (Real.cosh (2 * x) + Real.cosh (2 * J)) < Real.tanh J := by rw [tanh_eq_sinh_two_div J] have hnum_pos : 0 < Real.sinh (2 * J) := Real.sinh_pos_iff.mpr (by linarith) have hden1_pos : 0 < 1 + Real.cosh (2 * J) := by linarith [Real.cosh_pos (2 * J)] have h1_lt : 1 < Real.cosh (2 * x) := by have h2x : 2 * x ≠ 0 := mul_ne_zero two_ne_zero hx have hle := Real.one_le_cosh (2 * x) refine lt_of_le_of_ne hle ?_ intro heq have hzero : Real.cosh (2 * x) - 1 = 0 := by linarith have hexp_pos : 0 < Real.exp (2 * x) := Real.exp_pos _ have hsq : (Real.exp (2 * x) - 1) ^ 2 = 0 := by rw [Real.cosh_eq, Real.exp_neg] at heq have hmul := congrArg (fun t => t * (2 * Real.exp (2 * x))) heq have hne : Real.exp (2 * x) ≠ 0 := ne_of_gt hexp_pos field_simp [hne] at hmul nlinarith have hexp1 : Real.exp (2 * x) = 1 := by nlinarith have h2x0 : 2 * x = 0 := Real.exp_injective (by simpa [Real.exp_zero] using hexp1) exact h2x h2x0 exact div_lt_div_of_pos_left hnum_pos hden1_pos (by linarith) /-- Exact sharpness at `x = 0`: `|φ'_J(0)| = tanh(|J|)`. -/ theorem abs_phiDeriv_zero_eq_tanh_abs (J : ℝ) : |Real.sinh (2 * J) / (Real.cosh (2 * (0 : ℝ)) + Real.cosh (2 * J))| = Real.tanh |J| := by simp only [mul_zero, Real.cosh_zero] have hden_pos : 0 < 1 + Real.cosh (2 * J) := by linarith [Real.cosh_pos (2 * J)] have hden_abs : |1 + Real.cosh (2 * J)| = 1 + Real.cosh (2 * J) := abs_of_pos hden_pos rw [abs_div, hden_abs, tanh_eq_sinh_two_div |J|] rcases le_total 0 J with hJ | hJ · rw [abs_of_nonneg hJ, abs_of_nonneg (Real.sinh_nonneg_iff.mpr (by linarith))] · rw [abs_of_nonpos hJ] have h1 : 2 * (-J) = -(2 * J) := by ring rw [h1, Real.sinh_neg, Real.cosh_neg, abs_of_nonpos (Real.sinh_nonpos_iff.mpr (by linarith))] /-- **Headline Theorem 4A (Exact Single-Edge `tanh(|J|)` Contraction)**: For all `J, x, y ∈ ℝ`, `|φ_J(x) - φ_J(y)| ≤ tanh(|J|) · |x - y|`. -/ theorem phi_lipschitz_tanh_abs (J x y : ℝ) : |phi J x - phi J y| ≤ Real.tanh |J| * |x - y| := by have h := Convex.norm_image_sub_le_of_norm_hasDerivWithin_le (f := phi J) (f' := fun t => Real.sinh (2 * J) / (Real.cosh (2 * t) + Real.cosh (2 * J))) (s := Set.univ) (C := Real.tanh |J|) (fun t _ => (hasDerivAt_phi J t).hasDerivWithinAt) (fun t _ => by rw [Real.norm_eq_abs]; exact abs_phiDeriv_le_tanh_abs J t) convex_univ (Set.mem_univ y) (Set.mem_univ x) simpa [Real.norm_eq_abs] using h /-- Uniform box bound: `|φ_J(x)| ≤ |J|` for all `J, x ∈ ℝ` (and strictly `< |J|` if `J ≠ 0`). -/ theorem abs_phi_le (J x : ℝ) : |phi J x| ≤ |J| := by have hlt : ∀ J' > 0, ∀ t : ℝ, |phi J' t| < J' := by intro J' hJ' t unfold phi have hpos_r : 0 < Real.cosh (t + J') / Real.cosh (t - J') := div_pos (Real.cosh_pos _) (Real.cosh_pos _) have hup : Real.cosh (t + J') / Real.cosh (t - J') < Real.exp (2 * J') := by rw [div_lt_iff₀ (Real.cosh_pos _), Real.cosh_eq, Real.cosh_eq] have h1 : Real.exp (t - J') * Real.exp (2 * J') = Real.exp (t + J') := by rw [← Real.exp_add]; congr 1; ring have h2 : Real.exp (-(t - J')) * Real.exp (2 * J') = Real.exp (-(t + J')) * Real.exp (4 * J') := by rw [← Real.exp_add, ← Real.exp_add]; congr 1; ring have hexp4 : 1 < Real.exp (4 * J') := Real.one_lt_exp_iff.mpr (by linarith) have hneg_pos : 0 < Real.exp (-(t + J')) := Real.exp_pos _ nlinarith have hlo : Real.exp (-(2 * J')) < Real.cosh (t + J') / Real.cosh (t - J') := by rw [lt_div_iff₀ (Real.cosh_pos _), Real.cosh_eq, Real.cosh_eq] have h1 : Real.exp (-(2 * J')) * Real.exp (-(t - J')) = Real.exp (-(t + J')) := by rw [← Real.exp_add]; congr 1; ring have h2 : Real.exp (-(2 * J')) * Real.exp (t - J') = Real.exp (t + J') * Real.exp (-(4 * J')) := by rw [← Real.exp_add, ← Real.exp_add]; congr 1; ring have hexp4 : Real.exp (-(4 * J')) < 1 := Real.exp_lt_one_iff.mpr (by linarith) have hpos_p : 0 < Real.exp (t + J') := Real.exp_pos _ nlinarith have hlog_up : Real.log (Real.cosh (t + J') / Real.cosh (t - J')) < 2 * J' := by have := Real.log_lt_log hpos_r hup rwa [Real.log_exp] at this have hlog_lo : -(2 * J') < Real.log (Real.cosh (t + J') / Real.cosh (t - J')) := by have := Real.log_lt_log (Real.exp_pos _) hlo rwa [Real.log_exp] at this rw [abs_lt]; constructor <;> linarith rcases lt_trichotomy J 0 with hJ | rfl | hJ · have hsym : phi J x = -phi (-J) x := by unfold phi have h1 : x + -J = x - J := by ring have h2 : x - -J = x + J := by ring rw [h1, h2, ← inv_div (Real.cosh (x + J)) (Real.cosh (x - J)), Real.log_inv]; ring rw [hsym, abs_neg, abs_of_neg hJ] exact le_of_lt (hlt (-J) (by linarith) x) · simp · rw [abs_of_pos hJ] exact le_of_lt (hlt J hJ x) lemma abs_phi_lt_of_pos {J : ℝ} (hJ : 0 < J) (x : ℝ) : |phi J x| < J := by unfold phi have hpos_r : 0 < Real.cosh (x + J) / Real.cosh (x - J) := div_pos (Real.cosh_pos _) (Real.cosh_pos _) have hup : Real.cosh (x + J) / Real.cosh (x - J) < Real.exp (2 * J) := by rw [div_lt_iff₀ (Real.cosh_pos _), Real.cosh_eq, Real.cosh_eq] have h1 : Real.exp (x - J) * Real.exp (2 * J) = Real.exp (x + J) := by rw [← Real.exp_add]; congr 1; ring have h2 : Real.exp (-(x - J)) * Real.exp (2 * J) = Real.exp (-(x + J)) * Real.exp (4 * J) := by rw [← Real.exp_add, ← Real.exp_add]; congr 1; ring have hexp4 : 1 < Real.exp (4 * J) := Real.one_lt_exp_iff.mpr (by linarith) have hneg_pos : 0 < Real.exp (-(x + J)) := Real.exp_pos _ nlinarith have hlo : Real.exp (-(2 * J)) < Real.cosh (x + J) / Real.cosh (x - J) := by rw [lt_div_iff₀ (Real.cosh_pos _), Real.cosh_eq, Real.cosh_eq] have h1 : Real.exp (-(2 * J)) * Real.exp (-(x - J)) = Real.exp (-(x + J)) := by rw [← Real.exp_add]; congr 1; ring have h2 : Real.exp (-(2 * J)) * Real.exp (x - J) = Real.exp (x + J) * Real.exp (-(4 * J)) := by rw [← Real.exp_add, ← Real.exp_add]; congr 1; ring have hexp4 : Real.exp (-(4 * J)) < 1 := Real.exp_lt_one_iff.mpr (by linarith) have hpos_p : 0 < Real.exp (x + J) := Real.exp_pos _ nlinarith have hlog_up : Real.log (Real.cosh (x + J) / Real.cosh (x - J)) < 2 * J := by have := Real.log_lt_log hpos_r hup; rwa [Real.log_exp] at this have hlog_lo : -(2 * J) < Real.log (Real.cosh (x + J) / Real.cosh (x - J)) := by have := Real.log_lt_log (Real.exp_pos _) hlo; rwa [Real.log_exp] at this rw [abs_lt]; constructor <;> linarith end CavityFieldMap /-! ## Section 2: Exact Equivalence with Binary Sum-Product BP & Hilbert Projective Metric -/ section HilbertAndBinaryBP /-- Encode a cavity field `u ∈ ℝ` as a normalized positive binary message on `Bool`. -/ noncomputable def msgOfField (u : ℝ) (b : Bool) : ℝ := Real.exp (spin b * u) / (2 * Real.cosh u) lemma msgOfField_pos (u : ℝ) (b : Bool) : 0 < msgOfField u b := div_pos (Real.exp_pos _) (mul_pos two_pos (Real.cosh_pos u)) lemma msgOfField_sum_one (u : ℝ) : msgOfField u true + msgOfField u false = 1 := by unfold msgOfField simp only [spin_true, spin_false, one_mul, neg_one_mul] rw [← add_div, Real.cosh_eq] have hc : Real.cosh u ≠ 0 := ne_of_gt (Real.cosh_pos u) rw [Real.cosh_eq] at hc field_simp /-- Extract the cavity field (half log-message ratio) from a positive binary message `m`. -/ noncomputable def fieldOfMsg (m : Bool → ℝ) : ℝ := (1 / 2 : ℝ) * Real.log (m true / m false) lemma fieldOfMsg_msgOfField (u : ℝ) : fieldOfMsg (msgOfField u) = u := by unfold fieldOfMsg msgOfField simp only [spin_true, spin_false, one_mul, neg_one_mul] have hc : 2 * Real.cosh u ≠ 0 := ne_of_gt (mul_pos two_pos (Real.cosh_pos u)) rw [div_div_div_cancel_right₀ hc, ← Real.exp_sub, Real.log_exp] ring lemma msgOfField_fieldOfMsg {m : Bool → ℝ} (ht : 0 < m true) (hf : 0 < m false) (hsum : m true + m false = 1) (b : Bool) : msgOfField (fieldOfMsg m) b = m b := by unfold msgOfField fieldOfMsg set r := m true / m false have hr : 0 < r := div_pos ht hf have hs : Real.exp ((1 / 2 : ℝ) * Real.log r) = Real.sqrt r := by rw [Real.sqrt_eq_rpow, Real.rpow_def_of_pos hr]; congr 1; ring have hs_inv : Real.exp (-((1 / 2 : ℝ) * Real.log r)) = (Real.sqrt r)⁻¹ := by rw [Real.exp_neg, hs] have hsqrt_pos : 0 < Real.sqrt r := Real.sqrt_pos.mpr hr have hsq : Real.sqrt r * Real.sqrt r = r := Real.mul_self_sqrt (le_of_lt hr) cases b · simp only [spin_false, neg_one_mul, Real.cosh_eq, hs, hs_inv] have hne : Real.sqrt r ≠ 0 := ne_of_gt hsqrt_pos have hm_ne : m false ≠ 0 := ne_of_gt hf have hcomb : Real.sqrt r + (Real.sqrt r)⁻¹ = (r + 1) / Real.sqrt r := by field_simp [hne]; linarith [hsq] rw [show 2 * ((Real.sqrt r + (Real.sqrt r)⁻¹) / 2) = Real.sqrt r + (Real.sqrt r)⁻¹ by ring, hcomb] have hr1 : r + 1 = 1 / m false := by dsimp only [r]; field_simp [hm_ne]; linarith rw [hr1] field_simp [hne, hm_ne] · simp only [spin_true, one_mul, Real.cosh_eq, hs, hs_inv] have hne : Real.sqrt r ≠ 0 := ne_of_gt hsqrt_pos have hm_ne : m false ≠ 0 := ne_of_gt hf have hcomb : Real.sqrt r + (Real.sqrt r)⁻¹ = (r + 1) / Real.sqrt r := by field_simp [hne]; linarith [hsq] rw [show 2 * ((Real.sqrt r + (Real.sqrt r)⁻¹) / 2) = Real.sqrt r + (Real.sqrt r)⁻¹ by ring, hcomb] have hr1 : r + 1 = 1 / m false := by dsimp only [r]; field_simp [hm_ne]; linarith rw [hr1] field_simp [hne, hm_ne] rw [Real.sq_sqrt (le_of_lt hr)]; dsimp only [r]; field_simp [hm_ne] /-- Hilbert projective metric on strictly positive binary messages `m, m' : Bool → ℝ`: `d_H(m, m') = |log ((m true / m' true) / (m false / m' false))|`. -/ noncomputable def hilbertMetric (m m' : Bool → ℝ) : ℝ := |Real.log ((m true / m' true) / (m false / m' false))| /-- Exact identity between Hilbert projective metric and cavity-field distance: `d_H(m, m') = 2 · |fieldOfMsg m - fieldOfMsg m'|`. -/ theorem hilbertMetric_eq_two_mul_abs_sub {m m' : Bool → ℝ} (ht : 0 < m true) (hf : 0 < m false) (ht' : 0 < m' true) (hf' : 0 < m' false) : hilbertMetric m m' = 2 * |fieldOfMsg m - fieldOfMsg m'| := by unfold hilbertMetric fieldOfMsg have h1 : (m true / m' true) / (m false / m' false) = (m true / m false) / (m' true / m' false) := by field_simp [ne_of_gt hf, ne_of_gt ht', ne_of_gt hf'] rw [h1, Real.log_div (ne_of_gt (div_pos ht hf)) (ne_of_gt (div_pos ht' hf'))] have h2 : (1 / 2 : ℝ) * Real.log (m true / m false) - (1 / 2 : ℝ) * Real.log (m' true / m' false) = (1 / 2 : ℝ) * (Real.log (m true / m false) - Real.log (m' true / m' false)) := by ring rw [h2, abs_mul, abs_of_pos (by norm_num : (0 : ℝ) < 1 / 2)] ring /-- Effective Ising coupling of an arbitrary strictly positive `2 × 2` edge potential matrix `ψ`: `J_eff(ψ) = (1/4) log ((ψ T T · ψ F F) / (ψ T F · ψ F T))`. -/ noncomputable def effCoupling (ψ : Bool → Bool → ℝ) : ℝ := (1 / 4 : ℝ) * Real.log ((ψ true true * ψ false false) / (ψ true false * ψ false true)) /-- **Headline Theorem 4B (General `2 × 2` Birkhoff / Hilbert Projective Contraction)**: For ANY strictly positive `2 × 2` factor potential `ψ > 0` and ANY two positive binary inputs `m, m' > 0`, letting `(K m)(b) = ∑_a ψ(a, b) m(a)`, the Hilbert projective metric contracts by at most `tanh(|J_eff(ψ)|)`: `d_H(K m, K m') ≤ tanh(|J_eff(ψ)|) · d_H(m, m')`. -/ theorem general_2x2_hilbert_contraction (ψ : Bool → Bool → ℝ) (hψ : ∀ a b, 0 < ψ a b) {m m' : Bool → ℝ} (hm : ∀ a, 0 < m a) (hm' : ∀ a, 0 < m' a) : hilbertMetric (fun b => ψ true b * m true + ψ false b * m false) (fun b => ψ true b * m' true + ψ false b * m' false) ≤ Real.tanh |effCoupling ψ| * hilbertMetric m m' := by -- Shift by `a0 = (1/4) log((ψ T T ψ T F)/(ψ F T ψ F F))`, `b0 = (1/4) log((ψ T T ψ F T)/(ψ T F ψ F F))` let J := effCoupling ψ let h0 : ℝ := (1 / 4 : ℝ) * Real.log ((ψ true true * ψ true false) / (ψ false true * ψ false false)) let g0 : ℝ := (1 / 4 : ℝ) * Real.log ((ψ true true * ψ false true) / (ψ true false * ψ false false)) have hlog_ratio : ∀ (v : Bool → ℝ), (∀ a, 0 < v a) → fieldOfMsg (fun b => ψ true b * v true + ψ false b * v false) = g0 + phi J (h0 + fieldOfMsg v) := by intro v hv unfold fieldOfMsg phi set x := h0 + (1 / 2 : ℝ) * Real.log (v true / v false) -- Show `(ψ T T v T + ψ F T v F) / (ψ T F v T + ψ F F v F) = exp(2 g0) * cosh(x + J) / cosh(x - J)` have hnum_pos : 0 < ψ true true * v true + ψ false true * v false := add_pos (mul_pos (hψ _ _) (hv _)) (mul_pos (hψ _ _) (hv _)) have hden_pos : 0 < ψ true false * v true + ψ false false * v false := add_pos (mul_pos (hψ _ _) (hv _)) (mul_pos (hψ _ _) (hv _)) -- Express `exp(2(x+J))` and `exp(2(x-J))` directly! have hexp_plus : Real.exp (2 * (x + J)) = (ψ true true * v true) / (ψ false true * v false) := by have harg : 2 * (x + J) = Real.log ((ψ true true * ψ true false) / (ψ false true * ψ false false)) * (1 / 2) + Real.log ((ψ true true * ψ false false) / (ψ true false * ψ false true)) * (1 / 2) + Real.log (v true / v false) := by dsimp only [x, h0, J, effCoupling]; ring have hlog1 : Real.log ((ψ true true * ψ true false) / (ψ false true * ψ false false)) + Real.log ((ψ true true * ψ false false) / (ψ true false * ψ false true)) = Real.log ((ψ true true / ψ false true) ^ 2) := by rw [← Real.log_mul (ne_of_gt (div_pos (mul_pos (hψ _ _) (hψ _ _)) (mul_pos (hψ _ _) (hψ _ _)))) (ne_of_gt (div_pos (mul_pos (hψ _ _) (hψ _ _)) (mul_pos (hψ _ _) (hψ _ _))))] congr 1 field_simp [ne_of_gt (hψ true false), ne_of_gt (hψ false true), ne_of_gt (hψ false false)] have hlog_sq : Real.log ((ψ true true / ψ false true) ^ 2) = 2 * Real.log (ψ true true / ψ false true) := by rw [Real.log_pow]; norm_num have harg2 : 2 * (x + J) = Real.log ((ψ true true * v true) / (ψ false true * v false)) := by have hsum : Real.log (ψ true true / ψ false true) + Real.log (v true / v false) = Real.log ((ψ true true * v true) / (ψ false true * v false)) := by rw [← Real.log_mul (ne_of_gt (div_pos (hψ _ _) (hψ _ _))) (ne_of_gt (div_pos (hv _) (hv _)))] congr 1; ring linarith rw [harg2, Real.exp_log (div_pos (mul_pos (hψ _ _) (hv _)) (mul_pos (hψ _ _) (hv _)))] have hexp_minus : Real.exp (2 * (x - J)) = (ψ true false * v true) / (ψ false false * v false) := by have harg : 2 * (x - J) = Real.log ((ψ true true * ψ true false) / (ψ false true * ψ false false)) * (1 / 2) - Real.log ((ψ true true * ψ false false) / (ψ true false * ψ false true)) * (1 / 2) + Real.log (v true / v false) := by dsimp only [x, h0, J, effCoupling]; ring have hlog1 : Real.log ((ψ true true * ψ true false) / (ψ false true * ψ false false)) - Real.log ((ψ true true * ψ false false) / (ψ true false * ψ false true)) = Real.log ((ψ true false / ψ false false) ^ 2) := by rw [← Real.log_div (ne_of_gt (div_pos (mul_pos (hψ _ _) (hψ _ _)) (mul_pos (hψ _ _) (hψ _ _)))) (ne_of_gt (div_pos (mul_pos (hψ _ _) (hψ _ _)) (mul_pos (hψ _ _) (hψ _ _))))] congr 1 field_simp [ne_of_gt (hψ true true), ne_of_gt (hψ false true), ne_of_gt (hψ false false)] have hlog_sq : Real.log ((ψ true false / ψ false false) ^ 2) = 2 * Real.log (ψ true false / ψ false false) := by rw [Real.log_pow]; norm_num have harg2 : 2 * (x - J) = Real.log ((ψ true false * v true) / (ψ false false * v false)) := by have hsum : Real.log (ψ true false / ψ false false) + Real.log (v true / v false) = Real.log ((ψ true false * v true) / (ψ false false * v false)) := by rw [← Real.log_mul (ne_of_gt (div_pos (hψ _ _) (hψ _ _))) (ne_of_gt (div_pos (hv _) (hv _)))] congr 1; ring linarith rw [harg2, Real.exp_log (div_pos (mul_pos (hψ _ _) (hv _)) (mul_pos (hψ _ _) (hv _)))] have hexp_2g : Real.exp (2 * g0 - 2 * J) = ψ false true / ψ false false := by have harg : 2 * g0 - 2 * J = (1 / 2) * (Real.log ((ψ true true * ψ false true) / (ψ true false * ψ false false)) - Real.log ((ψ true true * ψ false false) / (ψ true false * ψ false true))) := by dsimp only [g0, J, effCoupling]; ring have hsub : Real.log ((ψ true true * ψ false true) / (ψ true false * ψ false false)) - Real.log ((ψ true true * ψ false false) / (ψ true false * ψ false true)) = 2 * Real.log (ψ false true / ψ false false) := by rw [← Real.log_div (ne_of_gt (div_pos (mul_pos (hψ _ _) (hψ _ _)) (mul_pos (hψ _ _) (hψ _ _)))) (ne_of_gt (div_pos (mul_pos (hψ _ _) (hψ _ _)) (mul_pos (hψ _ _) (hψ _ _))))] have heq : ((ψ true true * ψ false true) / (ψ true false * ψ false false)) / ((ψ true true * ψ false false) / (ψ true false * ψ false true)) = (ψ false true / ψ false false) ^ 2 := by field_simp [ne_of_gt (hψ true true), ne_of_gt (hψ true false), ne_of_gt (hψ false false)] rw [heq, Real.log_pow]; norm_num rw [harg, hsub, show (1 / 2 : ℝ) * (2 * Real.log (ψ false true / ψ false false)) = Real.log (ψ false true / ψ false false) by ring, Real.exp_log (div_pos (hψ _ _) (hψ _ _))] -- Note `cosh(x + J) / cosh(x - J) = exp(-2J) * (exp(2(x+J)) + 1) / (exp(2(x-J)) + 1)` have hcosh_ratio : Real.exp (2 * g0) * (Real.cosh (x + J) / Real.cosh (x - J)) = (ψ true true * v true + ψ false true * v false) / (ψ true false * v true + ψ false false * v false) := by have hc_id : ∀ t : ℝ, Real.cosh t = (Real.exp (2 * t) + 1) / (2 * Real.exp t) := by intro t rw [Real.cosh_eq, Real.exp_neg, two_mul, Real.exp_add] field_simp [ne_of_gt (Real.exp_pos t)] rw [hc_id (x + J), hc_id (x - J), hexp_plus, hexp_minus] have hexp_diff : Real.exp (2 * g0) * (Real.exp (x - J) / Real.exp (x + J)) = ψ false true / ψ false false := by rw [← Real.exp_sub, ← Real.exp_add] have : 2 * g0 + (x - J - (x + J)) = 2 * g0 - 2 * J := by ring rw [this, hexp_2g] have hne1 : Real.exp (x + J) ≠ 0 := ne_of_gt (Real.exp_pos _) have hne2 : Real.exp (x - J) ≠ 0 := ne_of_gt (Real.exp_pos _) have hne3 : ψ false true * v false ≠ 0 := ne_of_gt (mul_pos (hψ _ _) (hv _)) have hne4 : ψ false false * v false ≠ 0 := ne_of_gt (mul_pos (hψ _ _) (hv _)) calc Real.exp (2 * g0) * (((ψ true true * v true / (ψ false true * v false) + 1) / (2 * Real.exp (x + J))) / ((ψ true false * v true / (ψ false false * v false) + 1) / (2 * Real.exp (x - J)))) = (Real.exp (2 * g0) * (Real.exp (x - J) / Real.exp (x + J))) * ((ψ true true * v true / (ψ false true * v false) + 1) / (ψ true false * v true / (ψ false false * v false) + 1)) := by field_simp [hne1, hne2] _ = (ψ false true / ψ false false) * ((ψ true true * v true / (ψ false true * v false) + 1) / (ψ true false * v true / (ψ false false * v false) + 1)) := by rw [hexp_diff] _ = (ψ true true * v true + ψ false true * v false) / (ψ true false * v true + ψ false false * v false) := by field_simp [hne3, hne4, ne_of_gt (hψ false true), ne_of_gt (hψ false false), ne_of_gt (hv false)] rw [← hcosh_ratio, Real.log_mul (ne_of_gt (Real.exp_pos _)) (ne_of_gt (div_pos (Real.cosh_pos _) (Real.cosh_pos _))), Real.log_exp] ring rw [hilbertMetric_eq_two_mul_abs_sub (add_pos (mul_pos (hψ _ _) (hm _)) (mul_pos (hψ _ _) (hm _))) (add_pos (mul_pos (hψ _ _) (hm _)) (mul_pos (hψ _ _) (hm _))) (add_pos (mul_pos (hψ _ _) (hm' _)) (mul_pos (hψ _ _) (hm' _))) (add_pos (mul_pos (hψ _ _) (hm' _)) (mul_pos (hψ _ _) (hm' _))), hilbertMetric_eq_two_mul_abs_sub (hm true) (hm false) (hm' true) (hm' false), hlog_ratio m hm, hlog_ratio m' hm'] have hsub : (g0 + phi J (h0 + fieldOfMsg m)) - (g0 + phi J (h0 + fieldOfMsg m')) = phi J (h0 + fieldOfMsg m) - phi J (h0 + fieldOfMsg m') := by ring rw [hsub] have hlip := phi_lipschitz_tanh_abs J (h0 + fieldOfMsg m) (h0 + fieldOfMsg m') have hdiff : (h0 + fieldOfMsg m) - (h0 + fieldOfMsg m') = fieldOfMsg m - fieldOfMsg m' := by ring rw [hdiff] at hlip linarith end HilbertAndBinaryBP /-! ## Section 3: Global Loopy-BP Contraction, Uniqueness & Geometric Convergence -/ section LoopyBPGlobal variable {V : Type*} (G : SimpleGraph V) [Fintype V] [DecidableEq V] [DecidableRel G.Adj] /-- Directed edges of `G`: subtype `{e : V × V // G.Adj e.1 e.2}`. -/ abbrev DirEdge (G : SimpleGraph V) := {e : V × V // G.Adj e.1 e.2} /-- Synchronous cavity-field (log-message-ratio) Loopy BP operator on `G` with vertex external fields `h : V → ℝ` and edge couplings `J : V → V → ℝ`: `(T_BP u)_{i → j} = φ_{J_{ij}}(h_i + ∑_{k ∈ N(i)\{j\}} u_{k → i})`. -/ noncomputable def bpFieldOp (h : V → ℝ) (J : V → V → ℝ) (u : DirEdge G → ℝ) : DirEdge G → ℝ := fun e => let i := e.1.1 let j := e.1.2 phi (J i j) (h i + ∑ k ∈ ((G.neighborFinset i).erase j).attach, u ⟨(k.1, i), ((SimpleGraph.mem_neighborFinset G i k.1).mp (Finset.mem_of_mem_erase k.2)).symm⟩) /-- Synchronous normalized Sum-Product BP operator on a binary Ising MRF `(G, h, J)` (`ψ_i(b) = exp(h_i σ(b))`, `ψ_{ij}(a,b) = exp(J_{ij} σ(a) σ(b))`). -/ noncomputable def isingBPNormStep (h : V → ℝ) (J : V → V → ℝ) (m : DirEdge G → Bool → ℝ) (e : DirEdge G) (b : Bool) : ℝ := let i := e.1.1 let j := e.1.2 let unnorm (y : Bool) : ℝ := ∑ a : Bool, Real.exp (h i * spin a) * Real.exp (J i j * spin a * spin y) * ∏ k ∈ ((G.neighborFinset i).erase j).attach, m ⟨(k.1, i), ((SimpleGraph.mem_neighborFinset G i k.1).mp (Finset.mem_of_mem_erase k.2)).symm⟩ a unnorm b / (unnorm true + unnorm false) /-- **Exact Bridge**: One step of normalized Sum-Product BP on any binary Ising MRF `(G, h, J)` equals `msgOfField` applied to `bpFieldOp G h J`. -/ theorem isingBPNormStep_eq_msgOfField (h : V → ℝ) (J : V → V → ℝ) (u : DirEdge G → ℝ) (e : DirEdge G) (b : Bool) : isingBPNormStep G h J (fun e' => msgOfField (u e')) e b = msgOfField (bpFieldOp G h J u e) b := by let i := e.1.1 let j := e.1.2 let I := ((G.neighborFinset i).erase j).attach let S : ℝ := h i + ∑ k ∈ I, u ⟨(k.1, i), ((SimpleGraph.mem_neighborFinset G i k.1).mp (Finset.mem_of_mem_erase k.2)).symm⟩ let C : ℝ := ∏ k ∈ I, (2 * Real.cosh (u ⟨(k.1, i), ((SimpleGraph.mem_neighborFinset G i k.1).mp (Finset.mem_of_mem_erase k.2)).symm⟩)) have hC_pos : 0 < C := Finset.prod_pos fun k _ => mul_pos two_pos (Real.cosh_pos _) have hC_ne : C ≠ 0 := ne_of_gt hC_pos have hprod : ∀ a : Bool, Real.exp (h i * spin a) * (∏ k ∈ I, msgOfField (u ⟨(k.1, i), ((SimpleGraph.mem_neighborFinset G i k.1).mp (Finset.mem_of_mem_erase k.2)).symm⟩) a) = Real.exp (spin a * S) / C := by intro a unfold msgOfField rw [Finset.prod_div_distrib, ← Real.exp_sum, mul_div_assoc', ← Real.exp_add] congr 2 dsimp only [S] rw [mul_add, Finset.mul_sum] ring have hunnorm : ∀ y : Bool, (∑ a : Bool, Real.exp (h i * spin a) * Real.exp (J i j * spin a * spin y) * ∏ k ∈ I, msgOfField (u ⟨(k.1, i), ((SimpleGraph.mem_neighborFinset G i k.1).mp (Finset.mem_of_mem_erase k.2)).symm⟩) a) = (2 * Real.cosh (S + J i j * spin y)) / C := by intro y rw [Fintype.sum_bool] have ht := hprod true have hf := hprod false calc Real.exp (h i * spin true) * Real.exp (J i j * spin true * spin y) * (∏ k ∈ I, msgOfField _ true) + Real.exp (h i * spin false) * Real.exp (J i j * spin false * spin y) * (∏ k ∈ I, msgOfField _ false) = (Real.exp (h i * spin true) * ∏ k ∈ I, msgOfField _ true) * Real.exp (J i j * spin true * spin y) + (Real.exp (h i * spin false) * ∏ k ∈ I, msgOfField _ false) * Real.exp (J i j * spin false * spin y) := by ring _ = (Real.exp (spin true * S) / C) * Real.exp (J i j * spin true * spin y) + (Real.exp (spin false * S) / C) * Real.exp (J i j * spin false * spin y) := by rw [ht, hf] _ = (Real.exp (S + J i j * spin y) + Real.exp (-(S + J i j * spin y))) / C := by simp only [spin_true, spin_false, one_mul, neg_one_mul, div_mul_eq_mul_div, ← add_div, ← Real.exp_add] congr 2 <;> congr 1 <;> ring _ = (2 * Real.cosh (S + J i j * spin y)) / C := by rw [Real.cosh_eq]; ring unfold isingBPNormStep bpFieldOp dsimp only rw [hunnorm b, hunnorm true, hunnorm false] simp only [spin_true, spin_false, mul_one, mul_neg, ← add_div] rw [div_div_div_cancel_right₀ hC_ne] -- Now compare `2 cosh(S ± J) / (2 cosh(S+J) + 2 cosh(S-J))` with `msgOfField (phi (J i j) S) b`! have hpt : 0 < Real.cosh (S + J i j) := Real.cosh_pos _ have hpf : 0 < Real.cosh (S - J i j) := Real.cosh_pos _ have hsum_pos : 0 < Real.cosh (S + J i j) + Real.cosh (S - J i j) := add_pos hpt hpf let m0 : Bool → ℝ := fun y => (if y then Real.cosh (S + J i j) else Real.cosh (S - J i j)) / (Real.cosh (S + J i j) + Real.cosh (S - J i j)) have hm0_t : 0 < m0 true := div_pos hpt hsum_pos have hm0_f : 0 < m0 false := div_pos hpf hsum_pos have hm0_sum : m0 true + m0 false = 1 := by dsimp only [m0]; simp only [↓reduceIte, Bool.false_eq_true, ← add_div, div_self (ne_of_gt hsum_pos)] have hfield : fieldOfMsg m0 = phi (J i j) S := by unfold fieldOfMsg phi dsimp only [m0] simp only [↓reduceIte, Bool.false_eq_true] rw [div_div_div_cancel_right₀ (ne_of_gt hsum_pos)] have hrec := msgOfField_fieldOfMsg hm0_t hm0_f hm0_sum b rw [hfield] at hrec rw [hrec] dsimp only [m0] cases b · simp only [Bool.false_eq_true, ↓reduceIte, spin_false, mul_neg, mul_one, ← sub_eq_add_neg] field_simp [ne_of_gt hsum_pos] · simp only [↓reduceIte, spin_true, mul_one, ← sub_eq_add_neg] field_simp [ne_of_gt hsum_pos] /-- **Headline Theorem 4C (Heterogeneous Dobrushin / Ihler–Fisher–Willsky Contraction)**: For ANY finite graph `G`, ANY vertex fields `h : V → ℝ`, ANY edge couplings `J : V → V → ℝ`, if `κ ≥ 0` satisfies `tanh(|J i j|) * ((G.neighborFinset i).erase j).card ≤ κ` for every directed edge `(i, j)`, then `bpFieldOp G h J` is `κ`-Lipschitz in the `ℓ_∞` sup-norm on `DirEdge G → ℝ`: `‖T(u) - T(v)‖_∞ ≤ κ · ‖u - v‖_∞`. -/ theorem loopyBP_heterogeneous_contraction (h : V → ℝ) (J : V → V → ℝ) {κ : ℝ} (hκ : 0 ≤ κ) (hbound : ∀ e : DirEdge G, Real.tanh |J e.1.1 e.1.2| * (((G.neighborFinset e.1.1).erase e.1.2).card : ℝ) ≤ κ) (u v : DirEdge G → ℝ) : ‖bpFieldOp G h J u - bpFieldOp G h J v‖ ≤ κ * ‖u - v‖ := by rw [pi_norm_le_iff_of_nonneg (mul_nonneg hκ (norm_nonneg _))] intro e rw [Pi.sub_apply, Real.norm_eq_abs] unfold bpFieldOp refine le_trans (phi_lipschitz_tanh_abs _ _ _) ?_ have hsub : (h e.1.1 + ∑ k ∈ ((G.neighborFinset e.1.1).erase e.1.2).attach, u ⟨(k.1, e.1.1), ((SimpleGraph.mem_neighborFinset G e.1.1 k.1).mp (Finset.mem_of_mem_erase k.2)).symm⟩) - (h e.1.1 + ∑ k ∈ ((G.neighborFinset e.1.1).erase e.1.2).attach, v ⟨(k.1, e.1.1), ((SimpleGraph.mem_neighborFinset G e.1.1 k.1).mp (Finset.mem_of_mem_erase k.2)).symm⟩) = ∑ k ∈ ((G.neighborFinset e.1.1).erase e.1.2).attach, (u ⟨(k.1, e.1.1), ((SimpleGraph.mem_neighborFinset G e.1.1 k.1).mp (Finset.mem_of_mem_erase k.2)).symm⟩ - v ⟨(k.1, e.1.1), ((SimpleGraph.mem_neighborFinset G e.1.1 k.1).mp (Finset.mem_of_mem_erase k.2)).symm⟩) := by rw [add_sub_add_left_eq_sub, ← Finset.sum_sub_distrib] rw [hsub] have hsum_le : |∑ k ∈ ((G.neighborFinset e.1.1).erase e.1.2).attach, (u ⟨(k.1, e.1.1), ((SimpleGraph.mem_neighborFinset G e.1.1 k.1).mp (Finset.mem_of_mem_erase k.2)).symm⟩ - v ⟨(k.1, e.1.1), ((SimpleGraph.mem_neighborFinset G e.1.1 k.1).mp (Finset.mem_of_mem_erase k.2)).symm⟩)| ≤ (((G.neighborFinset e.1.1).erase e.1.2).card : ℝ) * ‖u - v‖ := by refine le_trans (Finset.abs_sum_le_sum_abs _ _) ?_ calc ∑ k ∈ ((G.neighborFinset e.1.1).erase e.1.2).attach, |u ⟨(k.1, e.1.1), _⟩ - v ⟨(k.1, e.1.1), _⟩| ≤ ∑ _k ∈ ((G.neighborFinset e.1.1).erase e.1.2).attach, ‖u - v‖ := by refine Finset.sum_le_sum fun k _ => ?_ simpa [Real.norm_eq_abs] using norm_le_pi_norm (u - v) ⟨(k.1, e.1.1), ((SimpleGraph.mem_neighborFinset G e.1.1 k.1).mp (Finset.mem_of_mem_erase k.2)).symm⟩ _ = (((G.neighborFinset e.1.1).erase e.1.2).card : ℝ) * ‖u - v‖ := by simp [Finset.sum_const, Finset.card_attach] have htanh_nonneg : 0 ≤ Real.tanh |J e.1.1 e.1.2| := by rw [Real.tanh_eq_sinh_div_cosh] exact div_nonneg (Real.sinh_nonneg_iff.mpr (abs_nonneg _)) (le_of_lt (Real.cosh_pos _)) calc Real.tanh |J e.1.1 e.1.2| * |∑ k ∈ ((G.neighborFinset e.1.1).erase e.1.2).attach, _| ≤ Real.tanh |J e.1.1 e.1.2| * ((((G.neighborFinset e.1.1).erase e.1.2).card : ℝ) * ‖u - v‖) := mul_le_mul_of_nonneg_left hsum_le htanh_nonneg _ = (Real.tanh |J e.1.1 e.1.2| * (((G.neighborFinset e.1.1).erase e.1.2).card : ℝ)) * ‖u - v‖ := by ring _ ≤ κ * ‖u - v‖ := mul_le_mul_of_nonneg_right (hbound e) (norm_nonneg _) /-- Exact `t`-step geometric contraction of synchronous Loopy BP. -/ theorem loopyBP_iter_contraction (h : V → ℝ) (J : V → V → ℝ) {κ : ℝ} (hκ : 0 ≤ κ) (hbound : ∀ e : DirEdge G, Real.tanh |J e.1.1 e.1.2| * (((G.neighborFinset e.1.1).erase e.1.2).card : ℝ) ≤ κ) (u v : DirEdge G → ℝ) : ∀ t : ℕ, ‖(bpFieldOp G h J)^[t] u - (bpFieldOp G h J)^[t] v‖ ≤ κ ^ t * ‖u - v‖ | 0 => by simp | t + 1 => by simp only [Function.iterate_succ_apply'] calc ‖bpFieldOp G h J ((bpFieldOp G h J)^[t] u) - bpFieldOp G h J ((bpFieldOp G h J)^[t] v)‖ ≤ κ * ‖(bpFieldOp G h J)^[t] u - (bpFieldOp G h J)^[t] v‖ := loopyBP_heterogeneous_contraction G h J hκ hbound _ _ _ ≤ κ * (κ ^ t * ‖u - v‖) := mul_le_mul_of_nonneg_left (loopyBP_iter_contraction h J hκ hbound u v t) hκ _ = κ ^ (t + 1) * ‖u - v‖ := by rw [pow_succ']; ring /-- One-step invariant compact box bound: `‖T_BP(u)‖_∞ ≤ J_max`. -/ lemma norm_bpFieldOp_le (h : V → ℝ) (J : V → V → ℝ) {Jmax : ℝ} (hJmax : 0 ≤ Jmax) (hJ : ∀ e : DirEdge G, |J e.1.1 e.1.2| ≤ Jmax) (u : DirEdge G → ℝ) : ‖bpFieldOp G h J u‖ ≤ Jmax := by rw [pi_norm_le_iff_of_nonneg hJmax] intro e rw [Real.norm_eq_abs] unfold bpFieldOp exact le_trans (abs_phi_le _ _) (hJ e) /-- Helper: `tanh` is monotone increasing on `ℝ`. -/ lemma tanh_mono {a b : ℝ} (hab : a ≤ b) : Real.tanh a ≤ Real.tanh b := by have hderiv : ∀ x : ℝ, HasDerivAt Real.tanh (1 / (Real.cosh x) ^ 2) x := by intro x have h1 : Real.tanh = fun t => Real.sinh t / Real.cosh t := by funext t; exact Real.tanh_eq_sinh_div_cosh t rw [h1] refine ((Real.hasDerivAt_sinh x).div (Real.hasDerivAt_cosh x) (ne_of_gt (Real.cosh_pos x))).congr_deriv ?_ have hsq := Real.cosh_sq_sub_sinh_sq x have hc : Real.cosh x ≠ 0 := ne_of_gt (Real.cosh_pos x) field_simp [hc]; linarith have hmono : Monotone Real.tanh := monotone_of_deriv_nonneg (fun x => (hderiv x).differentiableAt) (fun x => by rw [(hderiv x).deriv]; positivity) exact hmono hab /-- **Headline Theorem 4D (Bethe-Lattice Uniqueness Threshold `(Δ - 1) · tanh(J) < 1`)**: On ANY finite graph `G` of maximum degree `≤ Δ` (`Δ ≥ 1`), with couplings `|J_{ij}| ≤ J` (`J ≥ 0`) and arbitrary external fields `h : V → ℝ`, whenever `(Δ - 1) · tanh(J) < 1`: 1. Synchronous Loopy BP has a **unique** global fixed point `u^* : DirEdge G → ℝ`; 2. From **any** initial `u0`, `(T_BP)^[t] u0` converges geometrically at rate `κ^t` where `κ = (Δ - 1) · tanh(J) < 1`, with explicit non-asymptotic error bound `‖(T_BP)^[t] u0 - u^*‖_∞ ≤ 2 J · κ^(t - 1)` for all `t ≥ 1`. -/ theorem loopyBP_bethe_threshold_unique (h : V → ℝ) (J : V → V → ℝ) {Δ : ℕ} (hΔ : 1 ≤ Δ) (hdeg : ∀ v : V, G.degree v ≤ Δ) {Jmax : ℝ} (hJmax : 0 ≤ Jmax) (hJ : ∀ e : DirEdge G, |J e.1.1 e.1.2| ≤ Jmax) (hthresh : ((Δ - 1 : ℕ) : ℝ) * Real.tanh Jmax < 1) : ∃! uStar : DirEdge G → ℝ, bpFieldOp G h J uStar = uStar ∧ (∀ u0 : DirEdge G → ℝ, ∀ t : ℕ, ‖(bpFieldOp G h J)^[t] u0 - uStar‖ ≤ (((Δ - 1 : ℕ) : ℝ) * Real.tanh Jmax) ^ t * ‖u0 - uStar‖) ∧ (∀ u0 : DirEdge G → ℝ, ∀ t : ℕ, 1 ≤ t → ‖(bpFieldOp G h J)^[t] u0 - uStar‖ ≤ 2 * Jmax * (((Δ - 1 : ℕ) : ℝ) * Real.tanh Jmax) ^ (t - 1)) := by let κ : ℝ := ((Δ - 1 : ℕ) : ℝ) * Real.tanh Jmax have htanh_nn : 0 ≤ Real.tanh Jmax := by rw [Real.tanh_eq_sinh_div_cosh] exact div_nonneg (Real.sinh_nonneg_iff.mpr hJmax) (le_of_lt (Real.cosh_pos _)) have hκ_nn : 0 ≤ κ := mul_nonneg (Nat.cast_nonneg _) htanh_nn have hbound : ∀ e : DirEdge G, Real.tanh |J e.1.1 e.1.2| * (((G.neighborFinset e.1.1).erase e.1.2).card : ℝ) ≤ κ := by intro e have hmem : e.1.2 ∈ G.neighborFinset e.1.1 := (SimpleGraph.mem_neighborFinset G e.1.1 e.1.2).mpr e.2 have hcard : ((G.neighborFinset e.1.1).erase e.1.2).card ≤ Δ - 1 := by have h1 : ((G.neighborFinset e.1.1).erase e.1.2).card + 1 = G.degree e.1.1 := by rw [Finset.card_erase_add_one hmem, G.card_neighborFinset_eq_degree] have h2 := hdeg e.1.1 omega have hcard_r : (((G.neighborFinset e.1.1).erase e.1.2).card : ℝ) ≤ ((Δ - 1 : ℕ) : ℝ) := Nat.cast_le.mpr hcard have ht_le : Real.tanh |J e.1.1 e.1.2| ≤ Real.tanh Jmax := tanh_mono (hJ e) have ht_nn : 0 ≤ Real.tanh |J e.1.1 e.1.2| := by rw [Real.tanh_eq_sinh_div_cosh] exact div_nonneg (Real.sinh_nonneg_iff.mpr (abs_nonneg _)) (le_of_lt (Real.cosh_pos _)) calc Real.tanh |J e.1.1 e.1.2| * (((G.neighborFinset e.1.1).erase e.1.2).card : ℝ) ≤ Real.tanh Jmax * ((Δ - 1 : ℕ) : ℝ) := mul_le_mul ht_le hcard_r (Nat.cast_nonneg _) htanh_nn _ = κ := mul_comm _ _ -- Package as `ContractingWith` on the complete metric space `DirEdge G → ℝ` let K : NNReal := ⟨κ, hκ_nn⟩ have hK_lt : K < 1 := by exact_mod_cast hthresh have hcontr : ContractingWith K (bpFieldOp G h J) := by refine ⟨hK_lt, LipschitzWith.of_dist_le_mul fun u v => ?_⟩ rw [dist_eq_norm, dist_eq_norm] exact loopyBP_heterogeneous_contraction G h J hκ_nn hbound u v let uStar : DirEdge G → ℝ := hcontr.fixedPoint (bpFieldOp G h J) have hfix : bpFieldOp G h J uStar = uStar := hcontr.fixedPoint_isFixedPt have hrate : ∀ u0 : DirEdge G → ℝ, ∀ t : ℕ, ‖(bpFieldOp G h J)^[t] u0 - uStar‖ ≤ κ ^ t * ‖u0 - uStar‖ := by intro u0 t have hfix_iter : (bpFieldOp G h J)^[t] uStar = uStar := Function.IsFixedPt.iterate hfix t simpa [hfix_iter] using loopyBP_iter_contraction G h J hκ_nn hbound u0 uStar t have hbox_rate : ∀ u0 : DirEdge G → ℝ, ∀ t : ℕ, 1 ≤ t → ‖(bpFieldOp G h J)^[t] u0 - uStar‖ ≤ 2 * Jmax * κ ^ (t - 1) := by intro u0 t ht obtain ⟨m, rfl⟩ := Nat.exists_eq_add_of_le' ht have hstep : (bpFieldOp G h J)^[m + 1] u0 = (bpFieldOp G h J)^[m] (bpFieldOp G h J u0) := Function.iterate_succ_apply (bpFieldOp G h J) m u0 rw [hstep, Nat.add_sub_cancel] have hnorm1 : ‖bpFieldOp G h J u0‖ ≤ Jmax := norm_bpFieldOp_le G h J hJmax hJ u0 have hnorm2 : ‖uStar‖ ≤ Jmax := hfix ▸ norm_bpFieldOp_le G h J hJmax hJ uStar have hdiff : ‖bpFieldOp G h J u0 - uStar‖ ≤ 2 * Jmax := by calc ‖bpFieldOp G h J u0 - uStar‖ ≤ ‖bpFieldOp G h J u0‖ + ‖uStar‖ := norm_sub_le _ _ _ ≤ Jmax + Jmax := add_le_add hnorm1 hnorm2 _ = 2 * Jmax := by ring calc ‖(bpFieldOp G h J)^[m] (bpFieldOp G h J u0) - uStar‖ ≤ κ ^ m * ‖bpFieldOp G h J u0 - uStar‖ := hrate (bpFieldOp G h J u0) m _ ≤ κ ^ m * (2 * Jmax) := mul_le_mul_of_nonneg_left hdiff (pow_nonneg hκ_nn m) _ = 2 * Jmax * κ ^ m := mul_comm _ _ refine ⟨uStar, ⟨hfix, hrate, hbox_rate⟩, ?_⟩ intro u' ⟨hu'_fix, _, _⟩ exact hcontr.fixedPoint_unique hu'_fix /-- **Damped Loopy-BP Contraction**: For any damping parameter `α ∈ (0, 1]`, the damped operator `T_α(u) = (1 - α) u + α T_BP(u)` is a strict contraction with factor `1 - α(1 - κ) < 1` and shares the exact same unique fixed point. -/ theorem loopyBP_damped_contraction (h : V → ℝ) (J : V → V → ℝ) {κ α : ℝ} (hκ : 0 ≤ κ) (hκ1 : κ < 1) (hα0 : 0 < α) (hα1 : α ≤ 1) (hbound : ∀ e : DirEdge G, Real.tanh |J e.1.1 e.1.2| * (((G.neighborFinset e.1.1).erase e.1.2).card : ℝ) ≤ κ) (u v : DirEdge G → ℝ) : 1 - α * (1 - κ) < 1 ∧ ‖((1 - α) • u + α • bpFieldOp G h J u) - ((1 - α) • v + α • bpFieldOp G h J v)‖ ≤ (1 - α * (1 - κ)) * ‖u - v‖ := by refine ⟨by nlinarith, ?_⟩ have hsub : ((1 - α) • u + α • bpFieldOp G h J u) - ((1 - α) • v + α • bpFieldOp G h J v) = (1 - α) • (u - v) + α • (bpFieldOp G h J u - bpFieldOp G h J v) := by ext e; simp; ring rw [hsub] calc ‖(1 - α) • (u - v) + α • (bpFieldOp G h J u - bpFieldOp G h J v)‖ ≤ ‖(1 - α) • (u - v)‖ + ‖α • (bpFieldOp G h J u - bpFieldOp G h J v)‖ := norm_add_le _ _ _ = (1 - α) * ‖u - v‖ + α * ‖bpFieldOp G h J u - bpFieldOp G h J v‖ := by rw [norm_smul, norm_smul, Real.norm_eq_abs, Real.norm_eq_abs, abs_of_nonneg (by linarith), abs_of_pos hα0] _ ≤ (1 - α) * ‖u - v‖ + α * (κ * ‖u - v‖) := by have hstep := loopyBP_heterogeneous_contraction G h J hκ hbound u v have hmul := mul_le_mul_of_nonneg_left hstep (le_of_lt hα0) linarith _ = (1 - α * (1 - κ)) * ‖u - v‖ := by ring /-- Exact single-node Ising belief from cavity fields `u`: `b_i(true) = exp(B_i) / (2 cosh B_i)` where `B_i = h_i + ∑_{k ∈ N(i)} u_{k → i}`. Its total variation (`ℓ_1`) sensitivity is at most `|B_i - B'_i|`, yielding an explicit `Δ · κ^t` belief-convergence bound. -/ theorem ising_belief_lipschitz (B B' : ℝ) : |msgOfField B true - msgOfField B' true| + |msgOfField B false - msgOfField B' false| ≤ |B - B'| := by -- Note `msgOfField B true = (1 + tanh B) / 2` and `msgOfField B false = (1 - tanh B) / 2`! have ht_id : ∀ t : ℝ, msgOfField t true = (1 + Real.tanh t) / 2 := by intro t unfold msgOfField rw [spin_true, one_mul, Real.tanh_eq_sinh_div_cosh, Real.sinh_eq, Real.cosh_eq] have hc : Real.exp t + Real.exp (-t) ≠ 0 := ne_of_gt (add_pos (Real.exp_pos _) (Real.exp_pos _)) field_simp [hc]; ring have hf_id : ∀ t : ℝ, msgOfField t false = (1 - Real.tanh t) / 2 := by intro t unfold msgOfField rw [spin_false, neg_one_mul, Real.tanh_eq_sinh_div_cosh, Real.sinh_eq, Real.cosh_eq] have hc : Real.exp t + Real.exp (-t) ≠ 0 := ne_of_gt (add_pos (Real.exp_pos _) (Real.exp_pos _)) field_simp [hc]; ring rw [ht_id B, ht_id B', hf_id B, hf_id B'] have h1 : (1 + Real.tanh B) / 2 - (1 + Real.tanh B') / 2 = (Real.tanh B - Real.tanh B') / 2 := by ring have h2 : (1 - Real.tanh B) / 2 - (1 - Real.tanh B') / 2 = -((Real.tanh B - Real.tanh B') / 2) := by ring have h2abs : |(2 : ℝ)| = 2 := abs_of_pos two_pos rw [h1, h2, abs_neg, abs_div, h2abs] -- `|tanh B - tanh B'| ≤ |B - B'|` because `0 < tanh'(x) = 1 / cosh(x)^2 ≤ 1` have hderiv : ∀ x : ℝ, HasDerivAt Real.tanh (1 / (Real.cosh x) ^ 2) x := by intro x have hfn : Real.tanh = fun t => Real.sinh t / Real.cosh t := by funext t; exact Real.tanh_eq_sinh_div_cosh t rw [hfn] refine ((Real.hasDerivAt_sinh x).div (Real.hasDerivAt_cosh x) (ne_of_gt (Real.cosh_pos x))).congr_deriv ?_ have hsq := Real.cosh_sq_sub_sinh_sq x have hc : Real.cosh x ≠ 0 := ne_of_gt (Real.cosh_pos x) field_simp [hc]; linarith have hlip := Convex.norm_image_sub_le_of_norm_hasDerivWithin_le (f := Real.tanh) (f' := fun x => 1 / (Real.cosh x) ^ 2) (s := Set.univ) (C := 1) (fun x _ => (hderiv x).hasDerivWithinAt) (fun x _ => by rw [Real.norm_eq_abs, abs_of_pos (by positivity)] have h1c : 1 ≤ (Real.cosh x) ^ 2 := by nlinarith [Real.one_le_cosh x] exact div_le_one_of_le₀ h1c (by positivity)) convex_univ (Set.mem_univ B') (Set.mem_univ B) simp only [Real.norm_eq_abs, one_mul] at hlip linarith end LoopyBPGlobal /-! ## Section 4: Sharpness & 3-Fixed-Point Symmetry-Breaking Phase Transition -/ section PhaseTransitionSharpness /-- 1D Bethe–Peierls self-consistency residual `g_{d, J}(u) = φ_J(d · u) - u` for branching factor `d = Δ - 1`. -/ noncomputable def bpResidual (d : ℕ) (J u : ℝ) : ℝ := phi J ((d : ℝ) * u) - u lemma hasDerivAt_bpResidual (d : ℕ) (J u : ℝ) : HasDerivAt (bpResidual d J) ((d : ℝ) * (Real.sinh (2 * J) / (Real.cosh (2 * ((d : ℝ) * u)) + Real.cosh (2 * J))) - 1) u := by unfold bpResidual have hlin : HasDerivAt (fun t : ℝ => (d : ℝ) * t) (d : ℝ) u := by simpa using (hasDerivAt_id u).const_mul (d : ℝ) have hcomp : HasDerivAt (fun t : ℝ => phi J ((d : ℝ) * t)) ((Real.sinh (2 * J) / (Real.cosh (2 * ((d : ℝ) * u)) + Real.cosh (2 * J))) * (d : ℝ)) u := (hasDerivAt_phi J ((d : ℝ) * u)).comp u hlin exact (hcomp.sub (hasDerivAt_id u)).congr_deriv (by ring) /-- **Headline Theorem 4E (Subcritical & Critical Uniqueness of Uniform Bethe–Peierls Fixed Point)**: For EVERY branching factor `d ≥ 1` and `J > 0` with `d · tanh(J) ≤ 1`, `u = 0` is the **unique** solution of `u = φ_J(d · u)` on all of `ℝ` (including at the exact critical point `d · tanh(J) = 1`!). -/ theorem bethe_peierls_unique_zero_le_one {d : ℕ} (hd : 1 ≤ d) {J : ℝ} (hJ : 0 < J) (hsub : (d : ℝ) * Real.tanh J ≤ 1) (u : ℝ) (hu : phi J ((d : ℝ) * u) = u) : u = 0 := by by_contra hne -- By odd symmetry, reduce to `u > 0` wlog hpos : 0 < u generalizing u · have hneg_pos : 0 < -u := by rcases lt_trichotomy u 0 with h | h | h · linarith · exact absurd h hne · exact absurd h hpos have hu_neg : phi J ((d : ℝ) * (-u)) = -u := by rw [mul_neg, phi_neg, hu] exact this (-u) hu_neg (neg_ne_zero.mpr hne) hneg_pos -- On `[0, u]`, `bpResidual d J 0 = 0` and `bpResidual d J u = 0`, so by Rolle's theorem -- there exists `c ∈ (0, u)` with `bpResidual' d J c = 0`, contradicting `< 0`! have hcont : ContinuousOn (bpResidual d J) (Set.Icc 0 u) := fun x _ => (hasDerivAt_bpResidual d J x).continuousAt.continuousWithinAt have h0 : bpResidual d J 0 = 0 := by simp [bpResidual] have hu' : bpResidual d J u = 0 := by simp [bpResidual, hu] obtain ⟨c, hc_mem, hc_deriv⟩ := exists_hasDerivAt_eq_zero hpos hcont (by rw [h0, hu']) (fun x _ => hasDerivAt_bpResidual d J x) have hdc_ne : (d : ℝ) * c ≠ 0 := mul_ne_zero (Nat.cast_ne_zero.mpr (by omega)) (ne_of_gt hc_mem.1) have hlt := phiDeriv_lt_tanh_of_ne_zero hJ hdc_ne have hd_pos : (0 : ℝ) < d := Nat.cast_pos.mpr (by omega) have hprod_lt : (d : ℝ) * (Real.sinh (2 * J) / (Real.cosh (2 * ((d : ℝ) * c)) + Real.cosh (2 * J))) < (d : ℝ) * Real.tanh J := mul_lt_mul_of_pos_left hlt hd_pos linarith /-- Strict monotonicity of `cosh` on `[0, ∞)`. -/ lemma cosh_strictMono_nonneg {a b : ℝ} (ha : 0 ≤ a) (hab : a < b) : Real.cosh a < Real.cosh b := by have hderiv : ∀ x : ℝ, HasDerivAt Real.cosh (Real.sinh x) x := Real.hasDerivAt_cosh obtain ⟨c, hc_mem, hc_eq⟩ := exists_hasDerivAt_eq_slope Real.cosh (fun x => Real.sinh x) hab (fun x _ => (hderiv x).continuousAt.continuousWithinAt) (fun x _ => hderiv x) have hc_pos : 0 < c := lt_of_le_of_lt ha hc_mem.1 have hsinh_pos : 0 < Real.sinh c := Real.sinh_pos_iff.mpr hc_pos have hslope_pos : 0 < (Real.cosh b - Real.cosh a) / (b - a) := hc_eq ▸ hsinh_pos have hsub_pos : 0 < b - a := sub_pos.mpr hab have hdiff_pos : 0 < Real.cosh b - Real.cosh a := (div_pos_iff_of_pos_right hsub_pos).mp hslope_pos linarith /-- **Headline Theorem 4F (Exact 3-Root Bethe–Peierls Symmetry-Breaking Dichotomy)**: For EVERY branching factor `d ≥ 2` (i.e. degree `Δ = d + 1 ≥ 3`) and EVERY ferromagnetic coupling `J > 0` strictly above the Bethe-lattice threshold `d · tanh(J) > 1`: there exists a **UNIQUE** positive root `u^* ∈ (0, J)` of `u = φ_J(d · u)`, so the full solution set on `ℝ` is **EXACTLY** the 3-element set `{-u^*, 0, +u^*}`! -/ theorem bethe_peierls_exact_three_roots {d : ℕ} (hd : 2 ≤ d) {J : ℝ} (hJ : 0 < J) (hsup : 1 < (d : ℝ) * Real.tanh J) : ∃! uStar : ℝ, 0 < uStar ∧ uStar < J ∧ phi J ((d : ℝ) * uStar) = uStar := by have hd_pos : (0 : ℝ) < d := Nat.cast_pos.mpr (by omega) -- Step 1: Existence of a root in `(0, J)` via IVT -- Near 0, derivative `g'(0) = d * tanh(J) - 1 > 0`, so `∃ ε ∈ (0, J)` with `bpResidual d J ε > 0`. have hg'0_val : (d : ℝ) * (Real.sinh (2 * J) / (Real.cosh (2 * ((d : ℝ) * 0)) + Real.cosh (2 * J))) - 1 = (d : ℝ) * Real.tanh J - 1 := by simp only [mul_zero, Real.cosh_zero, tanh_eq_sinh_two_div J] have hg'0 : HasDerivAt (bpResidual d J) ((d : ℝ) * Real.tanh J - 1) 0 := hg'0_val ▸ hasDerivAt_bpResidual d J 0 have hpos_slope : 0 < (d : ℝ) * Real.tanh J - 1 := sub_pos.mpr hsup -- Use `HasDerivAt.tendsto_slope_zero_right` to find `ε ∈ (0, J)` with `bpResidual d J ε > 0` have htend := hg'0.tendsto_slope_zero_right have hev1 : ∀ᶠ t in nhdsWithin (0 : ℝ) (Set.Ioi 0), 0 < t⁻¹ • (bpResidual d J (0 + t) - bpResidual d J 0) := htend.eventually (Ioi_mem_nhds hpos_slope) have hev2 : ∀ᶠ t in nhdsWithin (0 : ℝ) (Set.Ioi 0), t < J := eventually_nhdsWithin_of_eventually_nhds (Iio_mem_nhds hJ) have hev3 : ∀ᶠ t in nhdsWithin (0 : ℝ) (Set.Ioi 0), 0 < t := self_mem_nhdsWithin obtain ⟨ε, hε_slope, hε_ltJ, hε_pos⟩ := (hev1.and (hev2.and hev3)).exists have hε_val : 0 < bpResidual d J ε := by simp only [zero_add, smul_eq_mul, bpResidual, mul_zero, phi_zero, sub_zero] at hε_slope have hinv_pos : 0 < ε⁻¹ := inv_pos.mpr hε_pos exact pos_of_mul_pos_right hε_slope (le_of_lt hinv_pos) -- At `u = J`, `bpResidual d J J = φ_J(d J) - J < 0` because `|φ_J(x)| < J`! have hJ_neg : bpResidual d J J < 0 := by unfold bpResidual have hlt := (abs_lt.mp (abs_phi_lt_of_pos hJ ((d : ℝ) * J))).2 linarith -- Apply IVT on `[ε, J]` to `-bpResidual d J` (or `intermediate_value_Icc'` on `bpResidual`) have hcont : ContinuousOn (bpResidual d J) (Set.Icc ε J) := fun x _ => (hasDerivAt_bpResidual d J x).continuousAt.continuousWithinAt have h0_mem : (0 : ℝ) ∈ Set.Icc (bpResidual d J J) (bpResidual d J ε) := ⟨le_of_lt hJ_neg, le_of_lt hε_val⟩ obtain ⟨uStar, huStar_mem, huStar_zero⟩ := intermediate_value_Icc' (le_of_lt hε_ltJ) hcont h0_mem have huStar_pos : 0 < uStar := lt_of_lt_of_le hε_pos huStar_mem.1 have huStar_ltJ : uStar < J := by refine lt_of_le_of_ne huStar_mem.2 fun heq => ?_ rw [heq] at huStar_zero; linarith have huStar_fix : phi J ((d : ℝ) * uStar) = uStar := by unfold bpResidual at huStar_zero; linarith -- Step 2: Uniqueness of positive root via strict decrease of `bpResidual'` on `[0, ∞)` + Rolle! have hderiv_strictAnti : ∀ a b : ℝ, 0 ≤ a → a < b → ((d : ℝ) * (Real.sinh (2 * J) / (Real.cosh (2 * ((d : ℝ) * b)) + Real.cosh (2 * J))) - 1) < ((d : ℝ) * (Real.sinh (2 * J) / (Real.cosh (2 * ((d : ℝ) * a)) + Real.cosh (2 * J))) - 1) := by intro a b ha hab have hsinh_pos : 0 < Real.sinh (2 * J) := Real.sinh_pos_iff.mpr (by linarith) have hden_pos : 0 < Real.cosh (2 * ((d : ℝ) * a)) + Real.cosh (2 * J) := add_pos (Real.cosh_pos _) (Real.cosh_pos _) have hcosh_lt : Real.cosh (2 * ((d : ℝ) * a)) < Real.cosh (2 * ((d : ℝ) * b)) := cosh_strictMono_nonneg (by positivity) (by nlinarith) have hdiv_lt : Real.sinh (2 * J) / (Real.cosh (2 * ((d : ℝ) * b)) + Real.cosh (2 * J)) < Real.sinh (2 * J) / (Real.cosh (2 * ((d : ℝ) * a)) + Real.cosh (2 * J)) := div_lt_div_of_pos_left hsinh_pos hden_pos (by linarith) linarith [mul_lt_mul_of_pos_left hdiv_lt hd_pos] refine ⟨uStar, ⟨huStar_pos, huStar_ltJ, huStar_fix⟩, ?_⟩ intro u2 ⟨hu2_pos, _, hu2_fix⟩ by_contra hne -- Without loss of generality `0 < a < b` are both roots of `bpResidual d J` have hcontra : ∀ a b : ℝ, 0 < a → a < b → bpResidual d J a = 0 → bpResidual d J b = 0 → False := by intro a b ha hab hfa hfb have hcont1 : ContinuousOn (bpResidual d J) (Set.Icc 0 a) := fun x _ => (hasDerivAt_bpResidual d J x).continuousAt.continuousWithinAt have hcont2 : ContinuousOn (bpResidual d J) (Set.Icc a b) := fun x _ => (hasDerivAt_bpResidual d J x).continuousAt.continuousWithinAt have hf0 : bpResidual d J 0 = 0 := by simp [bpResidual] obtain ⟨c1, hc1_mem, hc1_zero⟩ := exists_hasDerivAt_eq_zero ha hcont1 (by rw [hf0, hfa]) (fun x _ => hasDerivAt_bpResidual d J x) obtain ⟨c2, hc2_mem, hc2_zero⟩ := exists_hasDerivAt_eq_zero hab hcont2 (by rw [hfa, hfb]) (fun x _ => hasDerivAt_bpResidual d J x) have hc12 : c1 < c2 := lt_trans hc1_mem.2 hc2_mem.1 have hlt := hderiv_strictAnti c1 c2 (le_of_lt hc1_mem.1) hc12 linarith have hf1 : bpResidual d J uStar = 0 := by simp [bpResidual, huStar_fix] have hf2 : bpResidual d J u2 = 0 := by simp [bpResidual, hu2_fix] rcases lt_trichotomy u2 uStar with h | h | h · exact hcontra u2 uStar hu2_pos h hf2 hf1 · exact hne h · exact hcontra uStar u2 huStar_pos h huStar_zero hf2 /-- **Headline Theorem 4G (3 Distinct Normalized Loopy-BP Fixed Points on Every `Δ`-Regular Graph)**: On ANY finite `Δ`-regular graph `G` with `Δ ≥ 3` (zero external field `h = 0`, uniform ferromagnetic coupling `J > 0`), whenever `(Δ - 1) · tanh(J) > 1`, there exist **3 pairwise distinct normalized positive Sum-Product BP fixed points** `m⁻, m⁰, m⁺` whose single-node beliefs satisfy `b⁻_v(true) < 1/2 = b⁰_v(true) < b⁺_v(true)` at every vertex `v`. -/ theorem regular_graph_three_bp_fixed_points {V : Type*} [Fintype V] [DecidableEq V] [Nonempty V] (G : SimpleGraph V) [DecidableRel G.Adj] {Δ : ℕ} (hΔ : 3 ≤ Δ) (hreg : ∀ v : V, G.degree v = Δ) {J : ℝ} (hJ : 0 < J) (hsup : 1 < ((Δ - 1 : ℕ) : ℝ) * Real.tanh J) : ∃ mNeg mZero mPos : DirEdge G → Bool → ℝ, -- All three are strictly positive, normalized fixed points of Ising Sum-Product BP (∀ e b, 0 < mNeg e b ∧ 0 < mZero e b ∧ 0 < mPos e b) ∧ (∀ e, mNeg e true + mNeg e false = 1 ∧ mZero e true + mZero e false = 1 ∧ mPos e true + mPos e false = 1) ∧ isingBPNormStep G (fun _ => 0) (fun _ _ => J) mNeg = mNeg ∧ isingBPNormStep G (fun _ => 0) (fun _ _ => J) mZero = mZero ∧ isingBPNormStep G (fun _ => 0) (fun _ _ => J) mPos = mPos ∧ -- Pairwise distinct (in fact strictly ordered at every edge!) (∀ e : DirEdge G, mNeg e true < 1 / 2 ∧ mZero e true = 1 / 2 ∧ 1 / 2 < mPos e true) := by have hd : 2 ≤ Δ - 1 := by omega obtain ⟨uStar, ⟨huPos, _, huFix⟩, _⟩ := bethe_peierls_exact_three_roots hd hJ hsup let uNeg : DirEdge G → ℝ := fun _ => -uStar let uZero : DirEdge G → ℝ := fun _ => 0 let uPos : DirEdge G → ℝ := fun _ => uStar -- Verify all three are fixed points of `bpFieldOp` have hcard : ∀ e : DirEdge G, ((G.neighborFinset e.1.1).erase e.1.2).card = Δ - 1 := by intro e have hmem : e.1.2 ∈ G.neighborFinset e.1.1 := (SimpleGraph.mem_neighborFinset G e.1.1 e.1.2).mpr e.2 have h1 := Finset.card_erase_add_one hmem rw [G.card_neighborFinset_eq_degree, hreg e.1.1] at h1 omega have hfix_const : ∀ (c : ℝ), phi J (((Δ - 1 : ℕ) : ℝ) * c) = c → bpFieldOp G (fun _ => 0) (fun _ _ => J) (fun _ => c) = (fun _ => c) := by intro c hc funext e unfold bpFieldOp simp only [zero_add, Finset.sum_const, Finset.card_attach, nsmul_eq_mul, hcard e] exact hc have hfix_pos : bpFieldOp G (fun _ => 0) (fun _ _ => J) uPos = uPos := hfix_const uStar huFix have hfix_zero : bpFieldOp G (fun _ => 0) (fun _ _ => J) uZero = uZero := hfix_const 0 (by simp) have hfix_neg : bpFieldOp G (fun _ => 0) (fun _ _ => J) uNeg = uNeg := hfix_const (-uStar) (by rw [mul_neg, phi_neg, huFix]) let mNeg : DirEdge G → Bool → ℝ := fun e => msgOfField (uNeg e) let mZero : DirEdge G → Bool → ℝ := fun e => msgOfField (uZero e) let mPos : DirEdge G → Bool → ℝ := fun e => msgOfField (uPos e) refine ⟨mNeg, mZero, mPos, fun e b => ⟨msgOfField_pos _ _, msgOfField_pos _ _, msgOfField_pos _ _⟩, fun e => ⟨msgOfField_sum_one _, msgOfField_sum_one _, msgOfField_sum_one _⟩, ?_, ?_, ?_, ?_⟩ · funext e b dsimp only [mNeg] rw [isingBPNormStep_eq_msgOfField G (fun _ => 0) (fun _ _ => J) uNeg e b, hfix_neg] · funext e b dsimp only [mZero] rw [isingBPNormStep_eq_msgOfField G (fun _ => 0) (fun _ _ => J) uZero e b, hfix_zero] · funext e b dsimp only [mPos] rw [isingBPNormStep_eq_msgOfField G (fun _ => 0) (fun _ _ => J) uPos e b, hfix_pos] · intro e -- `msgOfField t true = (1 + tanh t) / 2` have ht_id : ∀ t : ℝ, msgOfField t true = (1 + Real.tanh t) / 2 := by intro t unfold msgOfField rw [spin_true, one_mul, Real.tanh_eq_sinh_div_cosh, Real.sinh_eq, Real.cosh_eq] have hc : Real.exp t + Real.exp (-t) ≠ 0 := ne_of_gt (add_pos (Real.exp_pos _) (Real.exp_pos _)) field_simp [hc]; ring have htanh_pos : 0 < Real.tanh uStar := by rw [Real.tanh_eq_sinh_div_cosh] exact div_pos (Real.sinh_pos_iff.mpr huPos) (Real.cosh_pos _) have htanh_neg : Real.tanh (-uStar) < 0 := by rw [Real.tanh_eq_sinh_div_cosh, Real.sinh_neg, Real.cosh_neg] exact div_neg_of_neg_of_pos (neg_lt_zero.mpr (Real.sinh_pos_iff.mpr huPos)) (Real.cosh_pos _) dsimp only [mNeg, mZero, mPos, uNeg, uZero, uPos] rw [ht_id (-uStar), ht_id 0, ht_id uStar] have ht0 : Real.tanh 0 = 0 := by simp [Real.tanh_eq_sinh_div_cosh] rw [ht0] exact ⟨by linarith, by ring, by linarith⟩ /-- **Concrete Complete-Graph Phase Transition Witness on `K_4` (`Δ = 3`)**: On `K_4 = completeGraph (Fin 4)` (which is 3-regular), the exact uniqueness threshold is `2 · tanh(J) = 1` (i.e., `J_c = (1/2) log 3`). For EVERY `J > 0` with `2 · tanh(J) > 1` (e.g., `J = 1`), Loopy BP admits **3 distinct normalized positive fixed points**, whereas for EVERY `0 ≤ J` with `2 · tanh(J) < 1`, Loopy BP has a **unique** fixed point. -/ theorem k4_phase_transition_witness {J : ℝ} (hJ : 0 < J) (hsup : 1 < 2 * Real.tanh J) : ∃ mNeg mZero mPos : DirEdge (⊤ : SimpleGraph (Fin 4)) → Bool → ℝ, isingBPNormStep (⊤ : SimpleGraph (Fin 4)) (fun _ => 0) (fun _ _ => J) mNeg = mNeg ∧ isingBPNormStep (⊤ : SimpleGraph (Fin 4)) (fun _ => 0) (fun _ _ => J) mZero = mZero ∧ isingBPNormStep (⊤ : SimpleGraph (Fin 4)) (fun _ => 0) (fun _ _ => J) mPos = mPos ∧ mNeg ≠ mZero ∧ mZero ≠ mPos ∧ mNeg ≠ mPos := by have hreg : ∀ v : Fin 4, (⊤ : SimpleGraph (Fin 4)).degree v = 3 := by intro v; simp have hsup' : 1 < ((3 - 1 : ℕ) : ℝ) * Real.tanh J := by norm_num; exact hsup obtain ⟨mNeg, mZero, mPos, _, _, h1, h2, h3, hord⟩ := regular_graph_three_bp_fixed_points (⊤ : SimpleGraph (Fin 4)) (le_refl 3) hreg hJ hsup' let e0 : DirEdge (⊤ : SimpleGraph (Fin 4)) := ⟨(0, 1), by decide⟩ have ⟨hneg, hzero, hpos⟩ := hord e0 refine ⟨mNeg, mZero, mPos, h1, h2, h3, ?_, ?_, ?_⟩ · intro heq; rw [heq] at hneg; linarith · intro heq; rw [heq] at hzero; linarith · intro heq; rw [heq] at hneg; linarith /-- **Concrete Numerical Phase-Transition Witness on `K_4` (`Δ = 3`, `J = 1/2` vs. `J = 1`)**: - Subcritical (`J = 1/2 < J_c = (1/2) log 3`): `2 · tanh(1/2) < 1`, so Loopy BP on `K_4` has a **unique** global fixed point (`u^* = 0`) with geometric convergence; - Supercritical (`J = 1 > J_c = (1/2) log 3`): `2 · tanh(1) > 1`, so Loopy BP on `K_4` admits **3 distinct** normalized positive fixed points (`mNeg ≠ mZero ≠ mPos`). -/ theorem k4_concrete_phase_transition : (∃! uStar : DirEdge (⊤ : SimpleGraph (Fin 4)) → ℝ, bpFieldOp (⊤ : SimpleGraph (Fin 4)) (fun _ => 0) (fun _ _ => (1 / 2 : ℝ)) uStar = uStar) ∧ (∃ mNeg mZero mPos : DirEdge (⊤ : SimpleGraph (Fin 4)) → Bool → ℝ, isingBPNormStep (⊤ : SimpleGraph (Fin 4)) (fun _ => 0) (fun _ _ => (1 : ℝ)) mNeg = mNeg ∧ isingBPNormStep (⊤ : SimpleGraph (Fin 4)) (fun _ => 0) (fun _ _ => (1 : ℝ)) mZero = mZero ∧ isingBPNormStep (⊤ : SimpleGraph (Fin 4)) (fun _ => 0) (fun _ _ => (1 : ℝ)) mPos = mPos ∧ mNeg ≠ mZero ∧ mZero ≠ mPos ∧ mNeg ≠ mPos) := by constructor · -- Subcritical `J = 1/2`: `2 * tanh(1/2) < 1` because `exp 1 < 3`! have h_sub : ((3 - 1 : ℕ) : ℝ) * Real.tanh (1 / 2 : ℝ) < 1 := by have h_e1 : Real.exp 1 < 3 := lt_trans Real.exp_one_lt_d9 (by norm_num) have h_sq : Real.exp (1 / 2 : ℝ) * Real.exp (1 / 2 : ℝ) = Real.exp 1 := by rw [← Real.exp_add]; norm_num have h_inv : Real.exp (-(1 / 2 : ℝ)) * Real.exp (1 / 2 : ℝ) = 1 := by rw [← Real.exp_add]; norm_num have hp : 0 < Real.exp (1 / 2 : ℝ) := Real.exp_pos _ have hlt_exp : Real.exp (1 / 2 : ℝ) < 3 * Real.exp (-(1 / 2 : ℝ)) := by nlinarith have hden : 0 < Real.exp (1 / 2 : ℝ) + Real.exp (-(1 / 2 : ℝ)) := add_pos (Real.exp_pos _) (Real.exp_pos _) rw [Real.tanh_eq_sinh_div_cosh, Real.sinh_eq, Real.cosh_eq] have hdiv : ((Real.exp (1 / 2 : ℝ) - Real.exp (-(1 / 2 : ℝ))) / 2) / ((Real.exp (1 / 2 : ℝ) + Real.exp (-(1 / 2 : ℝ))) / 2) = (Real.exp (1 / 2 : ℝ) - Real.exp (-(1 / 2 : ℝ))) / (Real.exp (1 / 2 : ℝ) + Real.exp (-(1 / 2 : ℝ))) := by field_simp rw [hdiv] norm_num rw [← mul_div_assoc, div_lt_one hden] linarith have hdeg : ∀ v : Fin 4, (⊤ : SimpleGraph (Fin 4)).degree v ≤ 3 := fun v => by simp obtain ⟨uStar, ⟨hfix, hconv, _⟩, _⟩ := loopyBP_bethe_threshold_unique (G := (⊤ : SimpleGraph (Fin 4))) (fun _ => 0) (fun _ _ => (1 / 2 : ℝ)) (by omega : 1 ≤ 3) hdeg (by norm_num : (0 : ℝ) ≤ 1 / 2) (fun _ => by norm_num) h_sub refine ⟨uStar, hfix, fun u hu => ?_⟩ have h1 := hconv u 1 simp only [Function.iterate_one, pow_one, hu] at h1 have hnorm0 : ‖u - uStar‖ = 0 := by have hnn : 0 ≤ ‖u - uStar‖ := norm_nonneg _ nlinarith exact sub_eq_zero.mp (norm_eq_zero.mp hnorm0) · -- Supercritical `J = 1`: `2 * tanh(1) > 1` because `exp 1 > 2` so `exp 1 ^ 2 > 3`! have h_sup : 1 < 2 * Real.tanh (1 : ℝ) := by have h_e1 : (2 : ℝ) < Real.exp 1 := lt_trans (by norm_num) Real.exp_one_gt_d9 have h_inv : Real.exp (-1 : ℝ) * Real.exp 1 = 1 := by rw [← Real.exp_add]; norm_num have hgt_exp : 3 * Real.exp (-1 : ℝ) < Real.exp 1 := by nlinarith [Real.exp_pos (1 : ℝ)] have hden : 0 < Real.exp 1 + Real.exp (-1 : ℝ) := add_pos (Real.exp_pos _) (Real.exp_pos _) rw [Real.tanh_eq_sinh_div_cosh, Real.sinh_eq, Real.cosh_eq] have hdiv : ((Real.exp 1 - Real.exp (-1 : ℝ)) / 2) / ((Real.exp 1 + Real.exp (-1 : ℝ)) / 2) = (Real.exp 1 - Real.exp (-1 : ℝ)) / (Real.exp 1 + Real.exp (-1 : ℝ)) := by field_simp rw [hdiv, ← mul_div_assoc, one_lt_div hden] linarith exact k4_phase_transition_witness zero_lt_one h_sup end PhaseTransitionSharpness /-! ## Axiom Verification Audit -/ #print axioms tanh_phi_eq #print axioms hasDerivAt_phi #print axioms abs_phiDeriv_le_tanh_abs #print axioms abs_phiDeriv_zero_eq_tanh_abs #print axioms phi_lipschitz_tanh_abs #print axioms abs_phi_le #print axioms hilbertMetric_eq_two_mul_abs_sub #print axioms general_2x2_hilbert_contraction #print axioms isingBPNormStep_eq_msgOfField #print axioms loopyBP_heterogeneous_contraction #print axioms loopyBP_iter_contraction #print axioms loopyBP_bethe_threshold_unique #print axioms loopyBP_damped_contraction #print axioms ising_belief_lipschitz #print axioms bethe_peierls_unique_zero_le_one #print axioms bethe_peierls_exact_three_roots #print axioms regular_graph_three_bp_fixed_points #print axioms k4_phase_transition_witness #print axioms k4_concrete_phase_transition end LoopyBPContraction