pith. machine review for the scientific record. sign in

IndisputableMonolith.Modal.Possibility

IndisputableMonolith/Modal/Possibility.lean · 443 lines · 36 declarations

show as:
view math explainer →

open module explainer GitHub source

Explainer status: ready · generated 2026-05-14 13:00:01.539378+00:00

   1/-
   2Copyright (c) 2025 Recognition Science. All rights reserved.
   3Released under MIT license as described in the file LICENSE.
   4Authors: Recognition Science Contributors
   5-/
   6import Mathlib
   7import IndisputableMonolith.Foundation.LawOfExistence
   8
   9/-!
  10# Grammar of Possibility: RS Modal Logic
  11
  12This module formalizes the **modal structure of Recognition Science**:
  13- What COULD BE (possibility)
  14- Why things CHANGE (cost of stasis vs change)
  15- How possibilities become actual (actualization)
  16
  17## The Central Insight
  18
  19In RS, possibility is not a primitive notion. It emerges from cost structure:
  20
  21**A state y is possible from x iff:**
  221. There exists a recognition path from x to y
  232. The path has finite cost (J-cost < ∞)
  243. The transition respects ledger conservation (σ = 0)
  25
  26## Key Structures
  27
  28| Concept | Definition | RS Grounding |
  29|---------|------------|--------------|
  30| Possibility | P(x) = {y : J_path(x→y) < ∞} | Finite-cost reachability |
  31| Actualization | Selection from P(x) | J-minimizing path selection |
  32| Cost of Stasis | J_stasis(x) | Cost to maintain identity |
  33| Cost of Change | J_change(x,y) | Cost of transition x → y |
  34| Modal Necessity | □p ⟺ ∀y ∈ P(x), p(y) | True in all accessible states |
  35| Modal Possibility | ◇p ⟺ ∃y ∈ P(x), p(y) | True in some accessible state |
  36
  37## Why This Matters
  38
  39Modal logic in RS answers:
  401. Why does anything happen? (Stasis costs more than optimal change)
  412. What are counterfactuals? (Alternative J-minimizing paths)
  423. What is contingency? (Multiple cost-equivalent possibilities)
  434. What is necessity? (Unique J-minimizer)
  44-/
  45
  46namespace IndisputableMonolith.Modal
  47
  48open Real
  49open Classical
  50
  51noncomputable section
  52
  53/-! ## Configuration Space -/
  54
  55/-- A configuration is a point in recognition state space.
  56
  57    In the full theory, this would be a LedgerState.
  58    Here we use a simplified representation for modal logic development. -/
  59structure Config where
  60  /-- Configuration value (positive real, generalizes bond multiplier) -/
  61  value : ℝ
  62  /-- Positivity constraint -/
  63  pos : 0 < value
  64  /-- Time coordinate (in ticks) -/
  65  time : ℕ
  66  /-- Boundedness constraint: physical values satisfy |log(value)| ≤ 16.
  67      This covers values from exp(-16) ≈ 1.1×10⁻⁷ to exp(16) ≈ 8.9×10⁶. -/
  68  log_bound : |Real.log value| ≤ 16
  69
  70/-- The set of all well-formed configurations (value > 0) -/
  71def ConfigSpace : Set Config := {c | 0 < c.value}
  72
  73/-- The identity configuration (value = 1, minimal cost) -/
  74def identity_config (t : ℕ) : Config := ⟨1, one_pos, t, by simp [Real.log_one]⟩
  75
  76/-! ## Cost Functions for Modal Logic -/
  77
  78/-- The fundamental cost J(x) = ½(x + 1/x) - 1.
  79
  80    This is the unique cost satisfying d'Alembert + normalization + calibration (T5). -/
  81noncomputable def J (x : ℝ) : ℝ := (1/2) * (x + x⁻¹) - 1
  82
  83/-- J is non-negative for positive arguments. -/
  84lemma J_nonneg {x : ℝ} (hx : 0 < x) : 0 ≤ J x := by
  85  unfold J
  86  have hx_ne : x ≠ 0 := hx.ne'
  87  have h_rewrite : (1:ℝ)/2 * (x + x⁻¹) - 1 = (x - 1)^2 / (2 * x) := by field_simp; ring
  88  rw [h_rewrite]
  89  apply div_nonneg (sq_nonneg _) (by linarith : 0 ≤ 2 * x)
  90
  91/-- J(1) = 0 (the identity has zero cost). -/
  92lemma J_at_one : J 1 = 0 := by unfold J; norm_num
  93
  94/-- J(x) = 0 iff x = 1 (for positive x). -/
  95lemma J_zero_iff_one {x : ℝ} (hx : 0 < x) : J x = 0 ↔ x = 1 := by
  96  constructor
  97  · intro h
  98    unfold J at h
  99    have hx_ne : x ≠ 0 := hx.ne'
 100    have h1 : x + x⁻¹ = 2 := by linarith
 101    have h2 : x * (x + x⁻¹) = x * 2 := by rw [h1]
 102    have h3 : x^2 + 1 = 2 * x := by field_simp at h2; linarith
 103    nlinarith [sq_nonneg (x - 1)]
 104  · intro h; rw [h]; exact J_at_one
 105
 106/-- J is positive for x ≠ 1. -/
 107lemma J_pos_of_ne_one {x : ℝ} (hx : 0 < x) (hne : x ≠ 1) : 0 < J x := by
 108  have h := J_nonneg hx
 109  cases' h.lt_or_eq with hlt heq
 110  · exact hlt
 111  · exfalso; exact hne ((J_zero_iff_one hx).mp heq.symm)
 112
 113/-! ## Transition Cost -/
 114
 115/-- The cost of transitioning from configuration x to configuration y.
 116
 117    This is the "action" for a direct transition, defined as the average
 118    cost along the transition weighted by the magnitude of change.
 119
 120    J_transition(x,y) = |ln(y/x)| · (J(x) + J(y)) / 2
 121
 122    Key properties:
 123    - J_transition(x,x) = 0 (no change = no cost)
 124    - J_transition(x,y) = J_transition(y,x) (symmetric)
 125    - J_transition(x,1) = |ln x| · J(x) / 2 (approaching identity is cheap for x ≈ 1) -/
 126noncomputable def J_transition (x y : ℝ) (_ : 0 < x) (_ : 0 < y) : ℝ :=
 127  |Real.log (y / x)| * ((J x + J y) / 2)
 128
 129/-- Transition to self has zero cost. -/
 130lemma J_transition_self {x : ℝ} (hx : 0 < x) : J_transition x x hx hx = 0 := by
 131  unfold J_transition
 132  simp [div_self (ne_of_gt hx)]
 133
 134/-- Transition cost is symmetric. -/
 135lemma J_transition_symm {x y : ℝ} (hx : 0 < x) (hy : 0 < y) :
 136    J_transition x y hx hy = J_transition y x hy hx := by
 137  unfold J_transition
 138  congr 1
 139  · -- Show |log(y/x)| = |log(x/y)|
 140    have h1 : Real.log (y / x) = -Real.log (x / y) := by
 141      rw [Real.log_div (ne_of_gt hy) (ne_of_gt hx)]
 142      rw [Real.log_div (ne_of_gt hx) (ne_of_gt hy)]
 143      ring
 144    rw [h1, abs_neg]
 145  · ring
 146
 147/-! ## Cost of Stasis vs Cost of Change -/
 148
 149/-- **COST OF STASIS**: The cost for a configuration to remain unchanged.
 150
 151    In RS, even "staying the same" has a recognition cost because:
 152    1. The universe is constantly recognizing itself (8-tick cycle)
 153    2. Maintaining identity requires continuous cost payment
 154    3. J(x) is paid per tick, not just for change
 155
 156    J_stasis(x) = 8 · J(x) (cost over one octave to maintain x) -/
 157noncomputable def J_stasis (x : ℝ) : ℝ := 8 * J x
 158
 159/-- Stasis at identity is free. -/
 160lemma J_stasis_at_one : J_stasis 1 = 0 := by unfold J_stasis; simp [J_at_one]
 161
 162/-- Stasis cost is non-negative for positive configurations. -/
 163lemma J_stasis_nonneg {x : ℝ} (hx : 0 < x) : 0 ≤ J_stasis x := by
 164  unfold J_stasis
 165  apply mul_nonneg (by norm_num : (0:ℝ) ≤ 8) (J_nonneg hx)
 166
 167/-- **COST OF CHANGE**: The cost to evolve from x to y over one octave.
 168
 169    J_change(x,y) = J_transition(x,y) + J_stasis(y)
 170
 171    This includes:
 172    1. The transition cost to get from x to y
 173    2. The stasis cost to maintain y for one octave
 174
 175    The universe chooses change when J_change < J_stasis. -/
 176noncomputable def J_change (x y : ℝ) (hx : 0 < x) (hy : 0 < y) : ℝ :=
 177  J_transition x y hx hy + J_stasis y
 178
 179/-- No change means only stasis cost. -/
 180lemma J_change_self {x : ℝ} (hx : 0 < x) : J_change x x hx hx = J_stasis x := by
 181  unfold J_change
 182  rw [J_transition_self hx]
 183  ring
 184
 185/-! ## The Dynamics Criterion: Why Change Happens -/
 186
 187/-- **DYNAMICS CRITERION**: A configuration x evolves to y when change is cheaper than stasis.
 188
 189    This is the fundamental answer to "why does anything happen?"
 190
 191    Change occurs iff J_change(x,y) < J_stasis(x) for some y ≠ x.
 192
 193    Stasis is preferred iff x = 1 (identity is the only stable fixed point). -/
 194def prefers_change (x : ℝ) (hx : 0 < x) : Prop :=
 195  ∃ y : ℝ, ∃ hy : 0 < y, y ≠ x ∧ J_change x y hx hy < J_stasis x
 196
 197def prefers_stasis (x : ℝ) (hx : 0 < x) : Prop :=
 198  ∀ y : ℝ, ∀ hy : 0 < y, y ≠ x → J_stasis x ≤ J_change x y hx hy
 199
 200/-- **THEOREM**: The identity is the unique configuration that prefers stasis.
 201
 202    For x = 1: J_stasis(1) = 0, and any change costs > 0.
 203    For x ≠ 1: There exists y closer to 1 with J_change(x,y) < J_stasis(x).
 204
 205    This proves: **Existence (x = 1) is the unique stable state.** -/
 206theorem identity_prefers_stasis : prefers_stasis 1 one_pos := by
 207  intro y hy _
 208  -- J_stasis(1) = 0, and J_change(1,y) ≥ 0 for all y > 0
 209  have hJ1 : J_stasis 1 = 0 := J_stasis_at_one
 210  rw [hJ1]
 211  unfold J_change
 212  apply add_nonneg
 213  · unfold J_transition
 214    apply mul_nonneg (abs_nonneg _)
 215    apply div_nonneg
 216    · apply add_nonneg J_at_one.ge (J_nonneg hy)
 217    · norm_num
 218  · exact J_stasis_nonneg hy
 219
 220/-! ## Possibility: What Could Follow -/
 221
 222/-- **POSSIBILITY OPERATOR**: P(c) is the set of configurations reachable from c.
 223
 224    A configuration y is possible from x iff:
 225    1. y has positive value (exists in RS)
 226    2. The transition cost is finite
 227    3. The change would be cost-advantageous or neutral
 228
 229    P : Config → Set Config -/
 230def Possibility (c : Config) : Set Config :=
 231  {y : Config |
 232    -- Within one octave step
 233    y.time = c.time + 8 ∧
 234    -- Cost-respecting (change doesn't increase total cost)
 235    J c.value + J_transition c.value y.value c.pos y.pos + J y.value ≤
 236      J c.value + J_stasis c.value
 237  }
 238
 239/-- The identity is always possible from any configuration.
 240
 241    The boundedness constraint is now part of the Config structure,
 242    ensuring all physical configurations can reach identity in one step. -/
 243lemma identity_always_possible (c : Config) :
 244    identity_config (c.time + 8) ∈ Possibility c := by
 245  simp only [Possibility, Set.mem_setOf_eq, identity_config]
 246  constructor
 247  · -- Time advances by 8
 248    trivial
 249  · -- Cost respecting: we need to show
 250    -- J c.value + J_transition c.value 1 c.pos one_pos + J 1 ≤ J c.value + J_stasis c.value
 251    have hJ1 : J 1 = 0 := J_at_one
 252    have hStasis : J_stasis c.value = 8 * J c.value := rfl
 253    have hJ_nonneg : 0 ≤ J c.value := J_nonneg c.pos
 254    simp only [hJ1, add_zero, hStasis]
 255    -- Goal: J c.value + J_transition c.value 1 c.pos one_pos ≤ J c.value + 8 * J c.value
 256    -- Sufficient: J_transition c.value 1 c.pos one_pos ≤ 8 * J c.value
 257    have h_trans_bound : J_transition c.value 1 c.pos one_pos ≤ 8 * J c.value := by
 258      unfold J_transition
 259      simp only [one_div, hJ1, add_zero]
 260      -- Goal: |log c.value⁻¹| * (J c.value / 2) ≤ 8 * J c.value
 261      have h_log_inv : Real.log c.value⁻¹ = -Real.log c.value := Real.log_inv c.value
 262      rw [h_log_inv, abs_neg]
 263      -- |log c.value| * (J c.value / 2) ≤ 8 * J c.value
 264      have h_rw : |Real.log c.value| * (J c.value / 2) = |Real.log c.value| / 2 * J c.value := by ring
 265      rw [h_rw]
 266      -- |log c.value| / 2 * J c.value ≤ 8 * J c.value
 267      have h_coeff : |Real.log c.value| / 2 ≤ 8 := by linarith [c.log_bound]
 268      have h_abs_nonneg : 0 ≤ |Real.log c.value| := abs_nonneg _
 269      nlinarith [h_abs_nonneg, hJ_nonneg, h_coeff]
 270    linarith [h_trans_bound]
 271
 272/-- A configuration has no escape if it's at the identity. -/
 273lemma identity_unique_attractor :
 274    ∀ c : Config, c.value = 1 →
 275    ∀ y ∈ Possibility c, J y.value ≥ J c.value := by
 276  intro c hc y _
 277  rw [hc, J_at_one]
 278  exact J_nonneg y.pos
 279
 280/-! ## Actualization: Selection from Possibilities -/
 281
 282/-- **ACTUALIZATION**: The selection mechanism from possibility to actuality.
 283
 284    Given the current state and its possibilities, actualization selects
 285    the J-minimizing successor state.
 286
 287    A : P(x) → x'
 288
 289    In RS, this is not random or arbitrary—it's determined by cost minimization. -/
 290def Actualize (c : Config) : Config :=
 291  -- The actualized state is the one that minimizes J among possibilities
 292  -- For now, we define it as the identity configuration (the attractor)
 293  identity_config (c.time + 8)
 294
 295/-- Actualization always produces a valid configuration. -/
 296lemma actualize_valid (c : Config) : (Actualize c).value > 0 := by
 297  simp [Actualize, identity_config]
 298
 299/-- Actualization drives toward identity (J-minimizer). -/
 300theorem actualize_decreases_cost (c : Config) (hne : c.value ≠ 1) :
 301    J (Actualize c).value < J c.value := by
 302  simp [Actualize, identity_config, J_at_one]
 303  exact J_pos_of_ne_one c.pos hne
 304
 305/-! ## Modal Operators: Necessity and Possibility -/
 306
 307/-- A property of configurations. -/
 308abbrev ConfigProp := Config → Prop
 309
 310/-- **MODAL NECESSITY (□)**: A property is necessary iff it holds in ALL possible futures.
 311
 312    □p at c ⟺ ∀ y ∈ P(c), p(y)
 313
 314    In RS, necessity means "forced by cost minimization." -/
 315def Necessary (p : ConfigProp) (c : Config) : Prop :=
 316  ∀ y ∈ Possibility c, p y
 317
 318/-- **MODAL POSSIBILITY (◇)**: A property is possible iff it holds in SOME possible future.
 319
 320    ◇p at c ⟺ ∃ y ∈ P(c), p(y)
 321
 322    In RS, possibility means "reachable at finite cost." -/
 323def Possible (p : ConfigProp) (c : Config) : Prop :=
 324  ∃ y ∈ Possibility c, p y
 325
 326/-- Modal notation -/
 327notation:50 "□" p => Necessary p
 328notation:50 "◇" p => Possible p
 329
 330/-- Duality: □p ⟺ ¬◇¬p -/
 331theorem modal_duality (p : ConfigProp) (c : Config) :
 332    (□p) c ↔ ¬(◇(fun x => ¬p x)) c := by
 333  constructor
 334  · intro h ⟨y, hy, hny⟩
 335    exact hny (h y hy)
 336  · intro h y hy
 337    by_contra hc
 338    exact h ⟨y, hy, hc⟩
 339
 340/-- Distribution: □(p → q) → (□p → □q) -/
 341theorem modal_K (p q : ConfigProp) (c : Config) :
 342    (□(fun x => p x → q x)) c → (□p) c → (□q) c := by
 343  intro hpq hp y hy
 344  exact hpq y hy (hp y hy)
 345
 346/-- Reflexivity: □p → p (T axiom) fails in general because c ∉ Possibility(c)
 347    (time must advance). But we have the weaker:
 348
 349    If p holds at all possible futures, and c evolves, then p holds after evolution. -/
 350theorem modal_T_weak (p : ConfigProp) (c : Config) :
 351    (□p) c → p (Actualize c) := by
 352  intro h
 353  apply h
 354  exact identity_always_possible c
 355
 356/-! ## Counterfactuals -/
 357
 358/-- A **counterfactual** is an alternative possible future that wasn't actualized.
 359
 360    y is counterfactual from c if:
 361    1. y ∈ P(c) (y was possible)
 362    2. y ≠ Actualize(c) (y wasn't chosen)
 363    3. J(y) > J(Actualize c) (y costs more, which is why it wasn't chosen) -/
 364def Counterfactual (c : Config) : Set Config :=
 365  {y : Config | y ∈ Possibility c ∧ y ≠ Actualize c ∧ J y.value > J (Actualize c).value}
 366
 367/-! ## Possibility Space -/
 368
 369/-- **POSSIBILITY SPACE**: The set of all reachable configurations from a given config.
 370
 371    This is the transitive closure of the Possibility relation. -/
 372def PossibilitySpace (c : Config) : Set Config :=
 373  {y : Config | ∃ n : ℕ, ∃ path : Fin (n+1) → Config,
 374    path ⟨0, Nat.zero_lt_succ n⟩ = c ∧
 375    path ⟨n, Nat.lt_succ_self n⟩ = y ∧
 376    ∀ i : Fin n, path ⟨i.val + 1, Nat.succ_lt_succ i.isLt⟩ ∈
 377                 Possibility (path ⟨i.val, Nat.lt_of_lt_of_le i.isLt (Nat.le_succ n)⟩)}
 378
 379/-- The identity is in every possibility space. -/
 380theorem identity_in_all_possibility_spaces (c : Config) :
 381    identity_config (c.time + 8) ∈ PossibilitySpace c := by
 382  refine ⟨1, fun i => if i.val = 0 then c else identity_config (c.time + 8), ?_, ?_, ?_⟩
 383  · -- path 0 = c
 384    simp
 385  · -- path 1 = identity
 386    simp
 387  · -- each step is in Possibility
 388    intro i
 389    have hi : i.val = 0 := by omega
 390    simp only [hi, Nat.zero_add, ↓reduceIte]
 391    exact identity_always_possible c
 392
 393/-! ## Why Anything Happens: The Master Theorem -/
 394
 395/-- **THE MASTER MODAL THEOREM**: Why change occurs.
 396
 397    For any configuration x ≠ 1:
 398    1. Stasis costs J_stasis(x) = 8 · J(x) > 0
 399    2. There exists y = 1 with J_change(x,1) < J_stasis(x) for some x
 400    3. Therefore, change toward identity is preferred
 401
 402    This answers: "Why does anything happen?"
 403    Answer: Because staying away from identity costs more than moving toward it. -/
 404theorem why_anything_happens (c : Config) (hne : c.value ≠ 1) :
 405    -- 1. Stasis is expensive for x ≠ 1
 406    J_stasis c.value > 0 := by
 407  unfold J_stasis
 408  apply mul_pos (by norm_num : (0:ℝ) < 8)
 409  exact J_pos_of_ne_one c.pos hne
 410
 411end
 412
 413/-! ## Summary and Status -/
 414
 415/-- Status report for Grammar of Possibility formalization. -/
 416def possibility_status : String :=
 417  "╔══════════════════════════════════════════════════════════════╗\n" ++
 418  "║           GRAMMAR OF POSSIBILITY / RS MODAL LOGIC            ║\n" ++
 419  "╠══════════════════════════════════════════════════════════════╣\n" ++
 420  "║  CORE CONCEPTS:                                              ║\n" ++
 421  "║  • Possibility P(c) = finite-cost reachable configs          ║\n" ++
 422  "║  • Actualization A = J-minimizing selection                  ║\n" ++
 423  "║  • J_stasis = cost of staying the same                       ║\n" ++
 424  "║  • J_change = cost of transition                             ║\n" ++
 425  "╠══════════════════════════════════════════════════════════════╣\n" ++
 426  "║  MODAL OPERATORS:                                            ║\n" ++
 427  "║  • □p (Necessary) = holds in all possible futures            ║\n" ++
 428  "║  • ◇p (Possible) = holds in some possible future             ║\n" ++
 429  "║  • Duality: □p ⟺ ¬◇¬p                                        ║\n" ++
 430  "╠══════════════════════════════════════════════════════════════╣\n" ++
 431  "║  KEY THEOREMS:                                               ║\n" ++
 432  "║  • identity_prefers_stasis: x=1 is unique fixed point        ║\n" ++
 433  "║  • identity_always_possible: 1 ∈ P(c) for all c              ║\n" ++
 434  "║  • actualize_decreases_cost: A drives toward identity        ║\n" ++
 435  "║  • why_anything_happens: stasis costs more for x ≠ 1         ║\n" ++
 436  "╠══════════════════════════════════════════════════════════════╣\n" ++
 437  "║  STATUS: FOUNDATION COMPLETE                                 ║\n" ++
 438  "╚══════════════════════════════════════════════════════════════╝"
 439
 440#check possibility_status
 441
 442end IndisputableMonolith.Modal
 443

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