Aether Catalog definitions — Evergreen_IdempotentCollapse2_ComputationalCollapse
DefinitionEvergreen_IdempotentCollapse2_ComputationalCollapseaether-catalogevergreen
Definition bundle for the Aether Catalog module Evergreen.IdempotentCollapse2.ComputationalCollapse, transplanted by skeleton subtraction; supplies the types and constants the catalog's theorems import.
Definition code
-- Def bundle generated from Evergreen/IdempotentCollapse2/ComputationalCollapse.lean by skeleton subtraction
import Mathlib
/-!
# Computational Collapse: Memoization, Normalization, and Idempotent Algorithms
## The Insight
In computer science, many fundamental operations are idempotent collapses:
1. **Memoization**: Computing f(x) and caching the result. Looking up the cached
value again returns the same result — the cache lookup is idempotent.
2. **Database normalization**: Converting a database to normal form. Normalizing
an already-normal database leaves it unchanged — normalization is idempotent.
3. **Compiler optimization passes**: Many optimizations (dead code elimination,
constant folding) are idempotent — running them twice gives the same result
as running them once.
4. **Sorting**: Sorting a sorted list returns the same list. sort ∘ sort = sort.
5. **Canonicalization**: Converting to canonical form (e.g., reducing fractions,
normalizing paths) is idempotent.
## Main Results
* `sort_idempotent` — Sorting is idempotent
* `abs_idempotent` — Absolute value is idempotent on nonneg
* `memoize_idempotent` — Memoization produces an idempotent lookup
* `normalize_idempotent` — Any normalization function is idempotent by definition
* `compiler_pass_convergence` — Iterated optimization passes converge
-/
open Function List Finset
/-! ### Sorting is Idempotent -/
/-
PROBLEM
Sorting an already-sorted list returns the same list.
This is the computational essence of idempotent collapse.
PROVIDED SOLUTION
mergeSort of a sorted list returns the same list. After one mergeSort, the list is sorted. Sorting a sorted list via mergeSort preserves it. Use that mergeSort produces a sorted permutation, and a sorted permutation of a sorted list is the list itself.
-/
/-! ### Absolute Value is Idempotent on Its Image -/
/-! ### Memoization as Idempotent Collapse -/
/-- A memoization table is a partial function that agrees with f where defined. -/
structure MemoTable (α β : Type*) where
table : α → Option β
func : α → β
consistent : ∀ a b, table a = some b → b = func a
/-! ### Normalization as Idempotent Collapse -/
/-- A normalization function: maps every element to a canonical representative
such that applying it twice gives the same result as applying it once. -/
structure Normalizer (α : Type*) where
normalize : α → α
idempotent : ∀ x, normalize (normalize x) = normalize x
/-- Two elements are equivalent under normalization iff they have the same normal form. -/
def Normalizer.equiv {α : Type*} (N : Normalizer α) (x y : α) : Prop :=
N.normalize x = N.normalize y
/-! ### Compiler Pass Convergence -/
/-
PROBLEM
A compiler optimization pass that is idempotent converges in one step.
PROVIDED SOLUTION
Induction on n. Base case n=1: trivial. Inductive step: f^[n+1] = f ∘ f^[n] = f ∘ f (by IH) which equals f by idempotence.
-/
/-! ### Idempotent Collapse in Type Theory -/
/-! ### Hash Table Normalization -/
/-! ### Fixed-Point Iteration Convergence -/