pith. machine review for the scientific record. sign in

IndisputableMonolith.Thermodynamics.JCostBoltzmann

IndisputableMonolith/Thermodynamics/JCostBoltzmann.lean · 141 lines · 9 declarations

show as:
view math explainer →

open module explainer GitHub source

Explainer status: ready · generated 2026-05-16 16:27:21.155265+00:00

   1import Mathlib
   2import IndisputableMonolith.Thermodynamics.RecognitionThermodynamics
   3
   4/-!
   5# J-Cost Boltzmann Bridge for Biology
   6
   7Connects the J-cost function to Boltzmann statistical mechanics with
   8explicit biology-facing theorems. Builds on RecognitionThermodynamics
   9which already provides gibbs_weight, partition_function, and free_energy.
  10
  11This module adds:
  12- Weight maximization at x=1 (ground state dominates)
  13- Weight symmetry (J(x) = J(1/x) implies w(x) = w(1/x))
  14- Monotonicity of Gibbs weight in J-cost
  15- Temperature-dependent selection pressure
  16- Biology certificate packaging all thermodynamic bridge results
  17
  18## Lean status: 0 sorry, 0 axiom
  19-/
  20
  21namespace IndisputableMonolith
  22namespace Thermodynamics
  23namespace JCostBoltzmann
  24
  25open Real Cost
  26
  27noncomputable section
  28
  29/-! ## Weight Properties -/
  30
  31/-- Gibbs weight at x=1 equals 1 (maximum, since J(1)=0). -/
  32theorem weight_at_ground_state (sys : RecognitionSystem) :
  33    gibbs_weight sys 1 = 1 :=
  34  gibbs_weight_one sys
  35
  36/-- Gibbs weight at any positive x is at most 1 (= weight at x=1).
  37    Since J(x) >= 0 for x > 0, we have -J(x)/T <= 0, so exp(-J/T) <= exp(0) = 1. -/
  38theorem weight_maximized_at_one (sys : RecognitionSystem) (x : ℝ) (hx : 0 < x) :
  39    gibbs_weight sys x ≤ gibbs_weight sys 1 := by
  40  rw [gibbs_weight_one]
  41  unfold gibbs_weight
  42  have hJ : 0 ≤ Jcost x := Jcost_nonneg hx
  43  have hT : 0 < sys.TR := sys.TR_pos
  44  have h_neg : -Jcost x / sys.TR ≤ 0 := by
  45    apply div_nonpos_of_nonpos_of_nonneg
  46    · linarith
  47    · linarith
  48  calc exp (-Jcost x / sys.TR)
  49      ≤ exp 0 := exp_le_exp.mpr h_neg
  50    _ = 1 := exp_zero
  51
  52/-- Gibbs weight is symmetric: w(x, T) = w(1/x, T) for x > 0.
  53    This follows from J(x) = J(1/x). -/
  54theorem weight_symmetric (sys : RecognitionSystem) (x : ℝ) (hx : 0 < x) :
  55    gibbs_weight sys x = gibbs_weight sys x⁻¹ := by
  56  unfold gibbs_weight
  57  rw [Jcost_symm hx]
  58
  59/-- Higher J-cost means lower Gibbs weight: if J(x) > J(y) then w(x) < w(y).
  60    This is the thermodynamic basis for natural selection. -/
  61theorem higher_cost_lower_weight (sys : RecognitionSystem) (x y : ℝ)
  62    (h : Jcost x > Jcost y) :
  63    gibbs_weight sys x < gibbs_weight sys y := by
  64  unfold gibbs_weight
  65  apply exp_lt_exp.mpr
  66  have hT := sys.TR_pos
  67  exact div_lt_div_of_pos_right (by linarith) hT
  68
  69/-! ## Selection Pressure -/
  70
  71/-- At low temperature, the weight ratio between ground state (x=1)
  72    and any other state (x ≠ 1) diverges. This models strong selection. -/
  73theorem low_temp_selection (x : ℝ) (hx : 0 < x) (hx_ne : x ≠ 1) :
  74    0 < Jcost x := by
  75  rw [Jcost_eq_sq (ne_of_gt hx)]
  76  apply div_pos
  77  · exact sq_pos_iff.mpr (sub_ne_zero.mpr hx_ne)
  78  · exact mul_pos (by norm_num) hx
  79
  80/-- The weight ratio between x=1 (ground state) and x > 0, x ≠ 1 is > 1.
  81    The ground state always has strictly higher probability than any excited state. -/
  82theorem ground_state_dominates (sys : RecognitionSystem) (x : ℝ)
  83    (hx : 0 < x) (hx_ne : x ≠ 1) :
  84    gibbs_weight sys x < gibbs_weight sys 1 := by
  85  rw [gibbs_weight_one]
  86  unfold gibbs_weight
  87  have hJ : 0 < Jcost x := low_temp_selection x hx hx_ne
  88  have hT := sys.TR_pos
  89  have h_neg : -Jcost x / sys.TR < 0 := by
  90    exact div_neg_of_neg_of_pos (by linarith) hT
  91  calc exp (-Jcost x / sys.TR) < exp 0 := exp_lt_exp.mpr h_neg
  92    _ = 1 := exp_zero
  93
  94/-! ## Free Energy Bridge -/
  95
  96/-- Free energy is nonpositive for any nonempty state space.
  97    F = -T * ln(Z) and Z >= 1 (from the ground state alone). -/
  98theorem free_energy_nonpos {Ω : Type*} [Fintype Ω] [Nonempty Ω]
  99    (sys : RecognitionSystem) (X : Ω → ℝ)
 100    (h_ground : ∃ ω, X ω = 1) :
 101    free_energy_from_Z sys X ≤ 0 := by
 102  unfold free_energy_from_Z
 103  have hT := sys.TR_pos
 104  have hZ := partition_function_pos sys X
 105  suffices h : 1 ≤ partition_function sys X by
 106    have h_log : 0 ≤ log (partition_function sys X) :=
 107      log_nonneg (by linarith)
 108    nlinarith
 109  unfold partition_function
 110  obtain ⟨ω₀, hω₀⟩ := h_ground
 111  calc (1 : ℝ) = gibbs_weight sys 1 := (gibbs_weight_one sys).symm
 112    _ = gibbs_weight sys (X ω₀) := by rw [hω₀]
 113    _ ≤ ∑ ω, gibbs_weight sys (X ω) :=
 114        Finset.single_le_sum (fun ω _ => (gibbs_weight_pos sys (X ω)).le)
 115          (Finset.mem_univ ω₀)
 116
 117/-! ## Certificate -/
 118
 119structure JCostBoltzmannCert where
 120  weight_at_one : ∀ sys : RecognitionSystem, gibbs_weight sys 1 = 1
 121  weight_max : ∀ (sys : RecognitionSystem) (x : ℝ),
 122    0 < x → gibbs_weight sys x ≤ gibbs_weight sys 1
 123  weight_sym : ∀ (sys : RecognitionSystem) (x : ℝ),
 124    0 < x → gibbs_weight sys x = gibbs_weight sys x⁻¹
 125  ground_dominates : ∀ (sys : RecognitionSystem) (x : ℝ),
 126    0 < x → x ≠ 1 → gibbs_weight sys x < gibbs_weight sys 1
 127  cost_positive : ∀ (x : ℝ), 0 < x → x ≠ 1 → 0 < Jcost x
 128
 129def jcostBoltzmannCert : JCostBoltzmannCert where
 130  weight_at_one := weight_at_ground_state
 131  weight_max := weight_maximized_at_one
 132  weight_sym := weight_symmetric
 133  ground_dominates := ground_state_dominates
 134  cost_positive := low_temp_selection
 135
 136end
 137
 138end JCostBoltzmann
 139end Thermodynamics
 140end IndisputableMonolith
 141

source mirrored from github.com/jonwashburn/shape-of-logic