pith. machine review for the scientific record. sign in

IndisputableMonolith.Thermodynamics.RecognitionThermodynamics

IndisputableMonolith/Thermodynamics/RecognitionThermodynamics.lean · 292 lines · 26 declarations

show as:
view math explainer →

open module explainer GitHub source

Explainer status: pending

   1import Mathlib
   2import IndisputableMonolith.Cost
   3import IndisputableMonolith.Foundation.PhiForcing
   4
   5/-!
   6# Recognition Thermodynamics
   7
   8This module defines the statistical mechanics of Recognition Science (RS).
   9It extends the "T=0" cost minimization (J=0) to finite Recognition Temperature (TR).
  10
  11## Core Definitions
  12
  131. **Recognition Temperature (TR)**: Parameterizes the strictness of J-minimization.
  142. **Recognition Beta (β)**: Thermodynamic beta (1/TR), the "inverse temperature".
  153. **Gibbs Measure**: The probability distribution p(x) ∝ exp(-J(x)/TR).
  164. **Recognition Entropy (SR)**: Quantifies the degeneracy of near-minima.
  175. **Recognition Free Energy (FR)**: The quantity minimized by RS dynamics at finite TR.
  18
  19## Connection to RS Foundation
  20
  21The key insight is that RS already has the structure for thermodynamics:
  22- J(x) = ½(x + 1/x) - 1 is the "energy" (cost)
  23- The Born rule weight exp(-C) from cost C is the Gibbs weight
  24- φ-ladder structure provides natural discretization
  25- 8-tick cycle provides fundamental time unit τ₀
  26
  27## References
  28- RS_UNDISCOVERED_TERRITORIES.md
  29- Recognition-Science-Full-Theory.txt
  30-/
  31
  32namespace IndisputableMonolith
  33namespace Thermodynamics
  34
  35open Real
  36open Cost
  37open scoped BigOperators
  38
  39/-! ## Core Thermodynamic Structures -/
  40
  41/-- Recognition Temperature parameterizes the noise/exploration level.
  42    T_R = 0 corresponds to deterministic RS (only J=0 states exist).
  43    T_R → ∞ corresponds to maximum disorder. -/
  44structure RecognitionSystem where
  45  TR : ℝ
  46  TR_pos : 0 < TR
  47
  48/-- Thermodynamic beta (inverse temperature) for a recognition system. -/
  49noncomputable def RecognitionSystem.beta (sys : RecognitionSystem) : ℝ := 1 / sys.TR
  50
  51/-- Beta is positive. -/
  52theorem RecognitionSystem.beta_pos (sys : RecognitionSystem) : 0 < sys.beta := by
  53  unfold RecognitionSystem.beta
  54  exact div_pos one_pos sys.TR_pos
  55
  56/-- Beta * TR = 1. -/
  57theorem RecognitionSystem.beta_mul_TR (sys : RecognitionSystem) : sys.beta * sys.TR = 1 := by
  58  unfold RecognitionSystem.beta
  59  field_simp [sys.TR_pos.ne']
  60
  61/-! ## Gibbs Weights and Partition Functions -/
  62
  63/-- The Gibbs weight (Boltzmann factor) of a state with ratio x.
  64    This is the unnormalized probability: exp(-J(x)/TR). -/
  65noncomputable def gibbs_weight (sys : RecognitionSystem) (x : ℝ) : ℝ :=
  66  exp (- Jcost x / sys.TR)
  67
  68/-- Gibbs weight is always positive. -/
  69theorem gibbs_weight_pos (sys : RecognitionSystem) (x : ℝ) : 0 < gibbs_weight sys x :=
  70  exp_pos _
  71
  72/-- Gibbs weight at x=1 is exp(0) = 1 (the ground state). -/
  73theorem gibbs_weight_one (sys : RecognitionSystem) : gibbs_weight sys 1 = 1 := by
  74  unfold gibbs_weight
  75  simp [Jcost_unit0]
  76
  77/-- The Partition Function Z for a discrete set of states.
  78    Z = ∑_ω exp(-J(X(ω))/TR) -/
  79noncomputable def partition_function {Ω : Type*} [Fintype Ω]
  80    (sys : RecognitionSystem) (X : Ω → ℝ) : ℝ :=
  81  ∑ ω, gibbs_weight sys (X ω)
  82
  83/-- The partition function is positive. -/
  84theorem partition_function_pos {Ω : Type*} [Fintype Ω] [Nonempty Ω]
  85    (sys : RecognitionSystem) (X : Ω → ℝ) : 0 < partition_function sys X := by
  86  unfold partition_function
  87  apply Finset.sum_pos
  88  · intro ω _
  89    exact gibbs_weight_pos sys (X ω)
  90  · exact Finset.univ_nonempty
  91
  92/-- The Gibbs probability distribution on a discrete set of states.
  93    p(ω) = exp(-J(X(ω))/TR) / Z -/
  94noncomputable def gibbs_measure {Ω : Type*} [Fintype Ω]
  95    (sys : RecognitionSystem) (X : Ω → ℝ) (ω : Ω) : ℝ :=
  96  gibbs_weight sys (X ω) / partition_function sys X
  97
  98/-- Gibbs measure is non-negative. -/
  99theorem gibbs_measure_nonneg {Ω : Type*} [Fintype Ω] [Nonempty Ω]
 100    (sys : RecognitionSystem) (X : Ω → ℝ) (ω : Ω) : 0 ≤ gibbs_measure sys X ω := by
 101  unfold gibbs_measure
 102  exact div_nonneg (gibbs_weight_pos sys (X ω)).le (partition_function_pos sys X).le
 103
 104/-- Gibbs measure sums to 1. -/
 105theorem gibbs_measure_sum_one {Ω : Type*} [Fintype Ω] [Nonempty Ω]
 106    (sys : RecognitionSystem) (X : Ω → ℝ) : ∑ ω, gibbs_measure sys X ω = 1 := by
 107  unfold gibbs_measure partition_function
 108  rw [← Finset.sum_div]
 109  exact div_self (partition_function_pos sys X).ne'
 110
 111/-- Gibbs measure is always positive. -/
 112theorem gibbs_measure_pos {Ω : Type*} [Fintype Ω] [Nonempty Ω]
 113    (sys : RecognitionSystem) (X : Ω → ℝ) (ω : Ω) : 0 < gibbs_measure sys X ω := by
 114  unfold gibbs_measure
 115  apply div_pos
 116  · exact gibbs_weight_pos sys (X ω)
 117  · exact partition_function_pos sys X
 118
 119/-- A probability distribution on a discrete set of states. -/
 120structure ProbabilityDistribution (Ω : Type*) [Fintype Ω] where
 121  p : Ω → ℝ
 122  nonneg : ∀ ω, 0 ≤ p ω
 123  sum_one : ∑ ω, p ω = 1
 124
 125/-! ## Entropy and Free Energy -/
 126
 127/-- Recognition Entropy S_R for a probability distribution p.
 128    S_R(p) = -∑_ω p(ω) ln(p(ω))
 129    Convention: 0 * ln(0) = 0 (handled via lim). -/
 130noncomputable def recognition_entropy {Ω : Type*} [Fintype Ω] (p : Ω → ℝ) : ℝ :=
 131  - ∑ ω, if p ω > 0 then p ω * log (p ω) else 0
 132
 133/-- Expected J-cost under a probability distribution p.
 134    E_p[J] = ∑_ω p(ω) * J(X(ω)) -/
 135noncomputable def expected_cost {Ω : Type*} [Fintype Ω] (p : Ω → ℝ) (X : Ω → ℝ) : ℝ :=
 136  ∑ ω, p ω * Jcost (X ω)
 137
 138/-- Recognition Free Energy F_R = E[J] - TR * S_R.
 139    This is the fundamental variational quantity in RS thermodynamics. -/
 140noncomputable def recognition_free_energy {Ω : Type*} [Fintype Ω]
 141    (sys : RecognitionSystem) (p : Ω → ℝ) (X : Ω → ℝ) : ℝ :=
 142  expected_cost p X - sys.TR * recognition_entropy p
 143
 144/-- Alternative formulation: F_R = -TR * ln(Z) for the Gibbs measure. -/
 145noncomputable def free_energy_from_Z {Ω : Type*} [Fintype Ω]
 146    (sys : RecognitionSystem) (X : Ω → ℝ) : ℝ :=
 147  - sys.TR * log (partition_function sys X)
 148
 149/-- **THEOREM: Free Energy Identity**
 150    F_R = -TR * ln(Z) for the Gibbs measure. -/
 151theorem free_energy_identity {Ω : Type*} [Fintype Ω] [Nonempty Ω]
 152    (sys : RecognitionSystem) (X : Ω → ℝ) :
 153    recognition_free_energy sys (gibbs_measure sys X) X = free_energy_from_Z sys X := by
 154  simp only [recognition_free_energy, expected_cost, recognition_entropy, free_energy_from_Z,
 155             gibbs_measure, gibbs_weight, partition_function]
 156  set Z := ∑ ω, exp (-Jcost (X ω) / sys.TR) with hZ
 157  have hZ_pos : 0 < Z := by
 158    rw [hZ]
 159    apply Finset.sum_pos
 160    · intro ω _
 161      exact exp_pos _
 162    · exact Finset.univ_nonempty
 163  -- LHS = Σ (p * J) - TR * (- Σ p log p) = Σ (p * J) + TR * Σ p log p
 164  -- Simplify the expression first
 165  simp only [sub_eq_add_neg, neg_neg, neg_mul, ← mul_neg]
 166  -- Now LHS = Σ (p * J) + TR * Σ (p * log p)
 167  rw [Finset.mul_sum]
 168  -- Expand the log in entropy: log(exp(-J/TR) / Z)
 169  have h_log : ∀ ω, (if exp (-Jcost (X ω) / sys.TR) / Z > 0 then
 170      (exp (-Jcost (X ω) / sys.TR) / Z) * log (exp (-Jcost (X ω) / sys.TR) / Z) else 0) =
 171      (exp (-Jcost (X ω) / sys.TR) / Z) * (-Jcost (X ω) / sys.TR - log Z) := by
 172    intro ω
 173    have h_p_pos : exp (-Jcost (X ω) / sys.TR) / Z > 0 := div_pos (exp_pos _) hZ_pos
 174    simp only [h_p_pos, if_true]
 175    rw [log_div (exp_pos _).ne' hZ_pos.ne', log_exp]
 176  simp only [h_log]
 177  -- Now we have: Σ (p * J) + Σ (TR * p * (-J/TR - log Z))
 178  rw [← Finset.sum_add_distrib]
 179  -- Combine terms for each ω
 180  have h_omega : ∀ ω, (exp (-Jcost (X ω) / sys.TR) / Z) * Jcost (X ω) +
 181                      sys.TR * ((exp (-Jcost (X ω) / sys.TR) / Z) * (-Jcost (X ω) / sys.TR - log Z)) =
 182                      -sys.TR * log Z * (exp (-Jcost (X ω) / sys.TR) / Z) := by
 183    intro ω
 184    field_simp [sys.TR_pos.ne', hZ_pos.ne']
 185    ring
 186  simp only [h_omega]
 187  rw [← Finset.mul_sum]
 188  have h_sum_p : (∑ ω, exp (-Jcost (X ω) / sys.TR) / Z) = 1 := by
 189    rw [← Finset.sum_div, div_self hZ_pos.ne']
 190  rw [h_sum_p]
 191  ring
 192
 193/-! ## Kullback-Leibler Divergence -/
 194
 195/-- The KL divergence D_KL(q || p) measures how q differs from p.
 196    D_KL(q || p) = ∑_ω q(ω) * ln(q(ω)/p(ω)) -/
 197noncomputable def kl_divergence {Ω : Type*} [Fintype Ω] (q p : Ω → ℝ) : ℝ :=
 198  ∑ ω, if q ω > 0 ∧ p ω > 0 then q ω * log (q ω / p ω) else 0
 199
 200/-- KL divergence is non-negative (Gibbs' inequality).
 201    D_KL(q || p) ≥ 0 with equality iff q = p. -/
 202theorem kl_divergence_nonneg {Ω : Type*} [Fintype Ω]
 203    (q p : Ω → ℝ) (hq : ∀ ω, 0 ≤ q ω) (hp : ∀ ω, 0 < p ω)
 204    (hq_sum : ∑ ω, q ω = 1) (hp_sum : ∑ ω, p ω = 1) :
 205    0 ≤ kl_divergence q p := by
 206  unfold kl_divergence
 207  -- Use log x ≤ x - 1, which implies -log x ≥ 1 - x
 208  -- q log (q/p) = -q log (p/q) ≥ q (1 - p/q) = q - p
 209  have h_le : ∀ ω, (if q ω > 0 ∧ p ω > 0 then q ω * log (q ω / p ω) else 0) ≥ q ω - p ω := by
 210    intro ω
 211    split_ifs with h
 212    · -- case q ω > 0 and p ω > 0
 213      obtain ⟨hq_pos, hp_pos⟩ := h
 214      have hr_pos : 0 < p ω / q ω := div_pos hp_pos hq_pos
 215      have : log (q ω / p ω) ≥ 1 - p ω / q ω := by
 216        rw [log_div hq_pos.ne' hp_pos.ne']
 217        have h_log_le := log_le_sub_one_of_pos hr_pos
 218        rw [log_div hp_pos.ne' hq_pos.ne'] at h_log_le
 219        linarith
 220      have hq_q : q ω * log (q ω / p ω) ≥ q ω * (1 - p ω / q ω) := by
 221        apply mul_le_mul_of_nonneg_left this hq_pos.le
 222      rw [mul_sub, mul_one, mul_div_cancel₀ _ hq_pos.ne'] at hq_q
 223      exact hq_q
 224    · -- case q ω ≤ 0 or p ω ≤ 0
 225      have hq0 : q ω = 0 := by
 226        have : ¬ (q ω > 0 ∧ p ω > 0) := h
 227        simp only [hp ω, and_true, not_lt] at this
 228        exact le_antisymm this (hq ω)
 229      rw [hq0]
 230      linarith [hp ω]
 231
 232  -- Sum over all ω
 233  calc 0 = (∑ ω, q ω) - (∑ ω, p ω) := by rw [hq_sum, hp_sum, sub_self]
 234       _ = ∑ ω, (q ω - p ω) := by rw [Finset.sum_sub_distrib]
 235       _ ≤ ∑ ω, (if q ω > 0 ∧ p ω > 0 then q ω * log (q ω / p ω) else 0) := Finset.sum_le_sum (fun ω _ => h_le ω)
 236
 237
 238
 239/-! ## Connecting to RS: φ-Temperature Scale -/
 240
 241/-- The natural temperature scale in RS is set by the φ-ladder.
 242    T_φ = J_bit = ln(φ) where φ is the golden ratio. -/
 243noncomputable def T_phi : ℝ := log Foundation.PhiForcing.φ
 244
 245/-- T_φ > 0 since φ > 1. -/
 246theorem T_phi_pos : 0 < T_phi := by
 247  unfold T_phi
 248  exact log_pos Foundation.PhiForcing.phi_gt_one
 249
 250/-- A recognition system at the φ-temperature. -/
 251noncomputable def phi_temperature_system : RecognitionSystem where
 252  TR := T_phi
 253  TR_pos := T_phi_pos
 254
 255/-! ## Coherence Threshold -/
 256
 257/-- The coherence parameter C = 1 marks a phase transition.
 258    When TR < T_critical, the system is in a "frozen" (coherent) phase.
 259    When TR > T_critical, the system is "hot" (disordered). -/
 260structure CoherenceThreshold where
 261  /-- The critical temperature for phase transition -/
 262  T_critical : ℝ
 263  /-- Critical temperature is positive -/
 264  T_critical_pos : 0 < T_critical
 265  /-- The coherence parameter at temperature T -/
 266  coherence : ℝ → ℝ
 267  /-- Coherence = 1 at the critical point -/
 268  coherence_at_critical : coherence T_critical = 1
 269
 270/-- The RS coherence threshold: C = T_φ / TR.
 271    C ≥ 1 corresponds to coherent (quantum/recognition) regime.
 272    C < 1 corresponds to decoherent (classical) regime. -/
 273noncomputable def rs_coherence (sys : RecognitionSystem) : ℝ := T_phi / sys.TR
 274
 275/-- At the φ-temperature, coherence = 1 (critical point). -/
 276theorem coherence_at_phi_temp : rs_coherence phi_temperature_system = 1 := by
 277  unfold rs_coherence phi_temperature_system
 278  simp [T_phi_pos.ne']
 279
 280/-! ## Eight-Tick Structure -/
 281
 282/-- The fundamental time unit in RS is 8 ticks (τ₀). -/
 283def eight_tick : ℕ := 8
 284
 285/-- The natural frequency scale: f_0 = 1 / (8 * τ₀).
 286    This sets the IR cutoff for recognition dynamics. -/
 287noncomputable def fundamental_frequency (tau_0 : ℝ) (_h : tau_0 > 0) : ℝ :=
 288  1 / (eight_tick * tau_0)
 289
 290end Thermodynamics
 291end IndisputableMonolith
 292

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