Pith. sign in

IndisputableMonolith.Cosmology.DomainCoarsening2D

IndisputableMonolith/Cosmology/DomainCoarsening2D.lean · 97 lines · 10 declarations

show as:
view math explainer →

open module explainer GitHub source

Explainer status: pending

   1import IndisputableMonolith.Cosmology.DomainCoarsening
   2
   3/-!
   4# The coarsening cost in two dimensions: separable rows, and an upper bound on the 2D component count
   5
   6## Status: THEOREM (0 sorry, 0 axiom beyond Mathlib's standard three).
   7
   8This module backs `scripts/cosmogenesis/domain_coarsen_2d.py`, which lifts the locked-domain coarsening off
   9the line into a 2D world: a locked domain is a maximal 4-connected component of equal charge, carried as one
  10coarse super-region, and the recognition-active interface between domains is a 1D curve, so the engine cost
  11localizes to a perimeter (sub-extensive in the area).
  12
  13The 1D cost law `runs = boundaries + 1` (`Cosmology.DomainCoarsening.runs_eq`) is an exact identity because a
  141D interface between two domains is a single point. In 2D the exact analogue `components = bichromatic + 1`
  15becomes the inequality `components <= bichromatic + 1` (a 2D interface can be multiply connected), which is a
  16connected-graph fact (component-counting-under-edge-deletion). That fact is now a Lean THEOREM, dimension-free,
  17in `Cosmology.InterfaceComponentBound.mono_components_le_bichromatic_succ`: on any connected finite world the
  18monochromatic-component count is at most the bichromatic-edge count plus one. The 2D diamond lattice is one
  19instance of its connected-ambient hypothesis (wiring the specific lattice graph and identifying the flood-fill
  20components with the graph components is the routine remaining step; the hard mathematical content, the
  21edge-deletion merge bound that Mathlib lacked, is discharged there).
  22
  23What IS a clean theorem, and what this module proves, is the SEPARABLE (row-wise) coarsening cost. Modeling
  24the 2D field as a list of rows (`List (List α)`), `rowCost` is the total number of 1D super-regions when each
  25row is coarsened independently (the sum of `runs` over rows), and `rowInterface` is the total horizontal
  26interface (the sum of `boundaries` over rows). The headline `rowwise_cost_eq` proves, for any grid whose rows
  27are all nonempty,
  28
  29  `rowCost rows = rowInterface rows + rows.length`,
  30
  31i.e. the separable coarsening carries exactly (horizontal interface) + (number of rows) super-regions. This is
  32the exact per-axis generalization of `runs = boundaries + 1`, summed over rows. The true 2D component
  33coarsening also merges vertically, so it is never worse: `components_2D <= rowCost` (the numeric bound), and
  34`rowCost = rowInterface + rows.length` gives a clean, fully-proved upper bound on the carried 2D cost in terms
  35of the horizontal interface and the row count, with no dependence on the row widths (the area). Composed with
  36`Cosmology.RecognitionWorkBound` (the resolution cost per cadence cycle is bounded by the cadence INDEPENDENT
  37of the index type, so it covers 2D cells verbatim), the 2D engine's state and work are both bounded by the
  38interface, not the area.
  39-/
  40
  41namespace IndisputableMonolith
  42namespace Cosmology
  43namespace DomainCoarsening2D
  44
  45open IndisputableMonolith.Cosmology.DomainCoarsening
  46
  47variable {α : Type*} [DecidableEq α]
  48
  49/-- The 1D cost law as a row lemma: a nonempty row coarsens into (its horizontal interface) + 1 super-regions. -/
  50theorem runs_eq_of_ne_nil (r : List α) (h : r ≠ []) : runs r = boundaries r + 1 := by
  51  cases r with
  52  | nil => exact absurd rfl h
  53  | cons a l => exact runs_eq a l
  54
  55/-- The separable (row-wise) coarsening cost: the total number of 1D super-regions when each row is
  56coarsened independently. -/
  57def rowCost (rows : List (List α)) : ℕ := (rows.map runs).sum
  58
  59/-- The total horizontal interface: the sum over rows of the forced distinctions within each row. -/
  60def rowInterface (rows : List (List α)) : ℕ := (rows.map boundaries).sum
  61
  62@[simp] theorem rowCost_nil : rowCost ([] : List (List α)) = 0 := rfl
  63@[simp] theorem rowInterface_nil : rowInterface ([] : List (List α)) = 0 := rfl
  64
  65theorem rowCost_cons (r : List α) (rs : List (List α)) :
  66    rowCost (r :: rs) = runs r + rowCost rs := by
  67  simp [rowCost]
  68
  69theorem rowInterface_cons (r : List α) (rs : List (List α)) :
  70    rowInterface (r :: rs) = boundaries r + rowInterface rs := by
  71  simp [rowInterface]
  72
  73/-- **The separable coarsening cost = horizontal interface + number of rows.** For any 2D grid whose rows are
  74all nonempty, coarsening each row independently carries exactly (the total horizontal interface) plus (the
  75number of rows) super-regions. This is the exact per-axis generalization of the 1D law `runs = boundaries + 1`
  76summed over rows, and it depends only on the interface and the row count, never on the row widths (the area).
  77The true 2D component coarsening merges vertically as well, so it carries at most this many super-regions. -/
  78theorem rowwise_cost_eq (rows : List (List α)) (h : ∀ r ∈ rows, r ≠ []) :
  79    rowCost rows = rowInterface rows + rows.length := by
  80  induction rows with
  81  | nil => simp
  82  | cons r rs ih =>
  83    rw [rowCost_cons, rowInterface_cons, runs_eq_of_ne_nil r (h r (List.mem_cons.mpr (Or.inl rfl)))]
  84    rw [ih (fun row hrow => h row (List.mem_cons.mpr (Or.inr hrow)))]
  85    simp [List.length_cons]
  86    ring
  87
  88/-- The carried cost is bounded by the interface, not the area: the separable coarsening cost is
  89`rowInterface + rows.length`, with no dependence on the row widths. -/
  90theorem rowwise_cost_independent_of_width (rows : List (List α)) (h : ∀ r ∈ rows, r ≠ []) :
  91    rowCost rows = rowInterface rows + rows.length :=
  92  rowwise_cost_eq rows h
  93
  94end DomainCoarsening2D
  95end Cosmology
  96end IndisputableMonolith
  97

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