|
| 1 | +# Modernization and extraction sprint |
| 2 | + |
| 3 | +This document records the first modernization and extraction plan for `lean-containers` as part of the broader category-theory contribution program targeting Mathlib and CSLib. |
| 4 | + |
| 5 | +## Current repository position |
| 6 | + |
| 7 | +`lean-containers` is intentionally small and mathlib-free. Its public core consists of container signatures, polynomial functors, W-types, a fold operation, and example signatures. That makes it the cleanest repository in the portfolio for extracting upstreamable mathematical infrastructure, because the core surface is compact and does not depend on tactic internals or old Mathlib APIs. |
| 8 | + |
| 9 | +Current constraints: |
| 10 | + |
| 11 | +- Current toolchain in `lean-toolchain`: `leanprover/lean4:v4.15.0`. |
| 12 | +- Upstream Mathlib baseline for this sprint: Lean 4.31 line. |
| 13 | +- This repository has no Mathlib dependency by design. |
| 14 | +- There is no category-theory bridge layer yet. |
| 15 | +- The nominal `M` type is explicitly not a developed final-coalgebra API and must not be upstreamed as mathematical infrastructure without a separate design pass. |
| 16 | + |
| 17 | +## Sprint objective |
| 18 | + |
| 19 | +The objective is to preserve the standalone core while extracting a Mathlib-facing package of small, reviewable contributions around containers, polynomial functors, and W-type recursion. |
| 20 | + |
| 21 | +The first sprint must not attempt to upstream the whole repository. The upstream goal is a sequence of precise API contributions, each one independently useful and easy to review. |
| 22 | + |
| 23 | +## Modernization gates |
| 24 | + |
| 25 | +### Gate 1: Lean 4.31 compatibility |
| 26 | + |
| 27 | +Run the repository against the current Lean 4.31 line without introducing Mathlib. |
| 28 | + |
| 29 | +Required commands: |
| 30 | + |
| 31 | +```bash |
| 32 | +lake update |
| 33 | +lake build |
| 34 | +lake env lean FinalProductionTest.lean |
| 35 | +lake exe lean-containers |
| 36 | +``` |
| 37 | + |
| 38 | +Expected first failures to check: |
| 39 | + |
| 40 | +- Lake syntax drift from Lean 4.15 to Lean 4.31. |
| 41 | +- Changes in the core `Functor` or `LawfulFunctor` expectations. |
| 42 | +- Any use of deprecated names in test or release scripts. |
| 43 | + |
| 44 | +No upstream extraction should happen until the standalone build works on the 4.31 line. |
| 45 | + |
| 46 | +### Gate 2: law and simp surface |
| 47 | + |
| 48 | +After the port compiles, add explicit named lemmas around the current definitional equalities. These lemmas are useful even when proofs are currently `rfl`, because upstream users should not rely on implementation details. |
| 49 | + |
| 50 | +Candidate local lemmas: |
| 51 | + |
| 52 | +```lean |
| 53 | +@[simp] theorem Poly.map_shape {sig : Container} {α β : Type} |
| 54 | + (f : α → β) (p : Poly sig α) : |
| 55 | + (Poly.map f p).shape = p.shape := rfl |
| 56 | +
|
| 57 | +@[simp] theorem Poly.map_children {sig : Container} {α β : Type} |
| 58 | + (f : α → β) (p : Poly sig α) (i : sig.pos p.shape) : |
| 59 | + (Poly.map f p).children i = f (p.children i) := rfl |
| 60 | +
|
| 61 | +@[simp] theorem Poly.map_id {sig : Container} {α : Type} (p : Poly sig α) : |
| 62 | + Poly.map id p = p := by |
| 63 | + cases p |
| 64 | + rfl |
| 65 | +
|
| 66 | +@[simp] theorem Poly.map_comp {sig : Container} {α β γ : Type} |
| 67 | + (f : α → β) (g : β → γ) (p : Poly sig α) : |
| 68 | + Poly.map g (Poly.map f p) = Poly.map (g ∘ f) p := by |
| 69 | + cases p |
| 70 | + rfl |
| 71 | +``` |
| 72 | + |
| 73 | +These should remain local to this repo until checked against current Mathlib naming and overlap. |
| 74 | + |
| 75 | +### Gate 3: W-fold API |
| 76 | + |
| 77 | +Extract computation lemmas for `W.fold`. |
| 78 | + |
| 79 | +Candidate local lemmas: |
| 80 | + |
| 81 | +```lean |
| 82 | +@[simp] theorem W.fold_sup {sig : Container} {X : Type} |
| 83 | + (alg : Poly sig X → X) (s : sig.shape) (children : sig.pos s → W sig) : |
| 84 | + W.fold alg (W.sup s children) = |
| 85 | + alg ⟨s, fun p => W.fold alg (children p)⟩ := rfl |
| 86 | +``` |
| 87 | + |
| 88 | +The first upstream candidate is not a full initial-algebra development. The first candidate is a small W-type recursion API with examples. |
| 89 | + |
| 90 | +## Extraction targets |
| 91 | + |
| 92 | +### Target A: Mathlib polynomial functor API audit |
| 93 | + |
| 94 | +Before writing a Mathlib PR, check current Mathlib for existing definitions related to: |
| 95 | + |
| 96 | +- polynomial functors; |
| 97 | +- containers; |
| 98 | +- W-types; |
| 99 | +- initial algebras; |
| 100 | +- accessible functors; |
| 101 | +- species or analytic functors, if present. |
| 102 | + |
| 103 | +If Mathlib already has a preferred abstraction, extract lemmas and examples into that abstraction. If Mathlib lacks this abstraction, propose only the smallest core file. |
| 104 | + |
| 105 | +### Target B: container-to-category bridge |
| 106 | + |
| 107 | +A later PR may introduce a categorical bridge, but only after the standalone API is stable. |
| 108 | + |
| 109 | +Candidate bridge concepts: |
| 110 | + |
| 111 | +- `Poly sig` as an endofunctor on `Type`; |
| 112 | +- container morphisms and induced natural transformations; |
| 113 | +- container composition if needed by downstream examples; |
| 114 | +- W-types as initial algebras for polynomial endofunctors. |
| 115 | + |
| 116 | +The first bridge PR should avoid coalgebraic claims. Final coalgebras and M-types need a separate theory design. |
| 117 | + |
| 118 | +### Target C: CSLib semantics bridge |
| 119 | + |
| 120 | +The CSLib-facing use case is coalgebraic or transition-system semantics. The first extraction should be examples, not abstractions. |
| 121 | + |
| 122 | +Candidate examples: |
| 123 | + |
| 124 | +- deterministic transition systems represented by a container shape and positions; |
| 125 | +- nondeterministic branching signatures; |
| 126 | +- tree-shaped executions as W-type values. |
| 127 | + |
| 128 | +## Non-upstream material for now |
| 129 | + |
| 130 | +The following should remain repository-local during this sprint: |
| 131 | + |
| 132 | +- release scripts; |
| 133 | +- Docker packaging; |
| 134 | +- `M sig` as a final-coalgebra placeholder; |
| 135 | +- any categorical bridge not yet aligned with Mathlib conventions. |
| 136 | + |
| 137 | +## First PR candidates generated from this repo |
| 138 | + |
| 139 | +1. Local modernization PR: port standalone repo to the Lean 4.31 line. |
| 140 | +2. Local API PR: add named simp lemmas for `Poly.map` and `W.fold`. |
| 141 | +3. Mathlib audit PR candidate: identify whether current Mathlib already has polynomial functor or W-type infrastructure. |
| 142 | +4. Mathlib extraction PR candidate: add a minimal polynomial-container API only if it fills a confirmed gap. |
| 143 | +5. CSLib example PR candidate: represent simple branching transition systems using container signatures. |
| 144 | + |
| 145 | +## Build certification status |
| 146 | + |
| 147 | +This document is a planning and extraction artifact. It does not certify that the repository has been built on Lean 4.31 yet. Certification requires a successful local or CI run of the commands in Gate 1. |
0 commit comments