You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A comprehensive **programming language metatheory library for Lean 4**, providing formally verified proofs of fundamental results in rewriting theory and type systems.
6
+
A comprehensive **programming language metatheory library for Lean 4**, now spanning **130+ Lean files and 58K+ lines** of mechanized proofs and metatheoretic case studies.
8
7
9
8
## Overview
10
9
@@ -20,6 +19,15 @@ Metatheory formalizes core results from programming language theory:
20
19
-**System F** (Polymorphic Lambda Calculus): Subject reduction with type substitution
21
20
-**Term/String Rewriting**: Confluence via Newman's lemma, critical pair analysis, and first-order TRS completion (KBO/LPO)
22
21
-**TRS Proof Comparison**: Diamond vs Newman confluence for a tiny deterministic TRS
22
+
-**Extended Formalizations**: 78 standalone modules covering type systems, semantics, compilation, effects, logic, macros, and automation
-**Standalone modules under `Metatheory/*.lean`**: 78
30
+
-**Top-level dependency model**: no Mathlib requirement in `lakefile.toml`; many standalone modules are self-contained
23
31
24
32
25
33
### Why Metatheory?
@@ -29,7 +37,7 @@ Metatheory formalizes core results from programming language theory:
29
37
|**Multiple proof techniques**| Learn different approaches to confluence (Diamond, Newman, Hindley-Rosen) |
30
38
|**Layered architecture**| Generic framework instantiated by specific systems |
31
39
|**De Bruijn indices**| Capture-avoiding substitution without alpha-equivalence |
32
-
|**Mathlib integration**|Uses Mathlib for standard lemmas; core theorems axiom-free|
40
+
|**Dependency-light design**|Top-level build has no Mathlib requirement; many modules are self-contained|
33
41
|**Axiom/placeholder free**| No `axiom`/`constant` declarations and no `sorry`/`admit`|
34
42
|**Extensively documented**| Docstrings, references, and proof explanations |
35
43
@@ -39,7 +47,6 @@ Metatheory formalizes core results from programming language theory:
39
47
40
48
-[Lean 4](https://lean-lang.org/lean4/doc/setup.html) (version 4.24.0 or compatible)
41
49
-[Lake](https://github.com/leanprover/lake) (included with Lean)
42
-
-[Mathlib](https://github.com/leanprover-community/mathlib4) (automatically fetched by Lake)
43
50
44
51
### Building
45
52
@@ -191,6 +198,109 @@ example {M : Term} {τ : Ty} (h : ⊢ M : τ) : M.IsValue ∨ ∃ N, M.Step N :=
191
198
progress h
192
199
```
193
200
201
+
## Extended Formalizations (Standalone Modules)
202
+
203
+
In addition to the layered core directories (`Rewriting/`, `Lambda/`, `CL/`, `TRS/`, `StringRewriting/`, `STLC/`, `STLCext/`, `STLCextBool/`, `SystemF/`), the project includes **78 standalone modules** at `Metatheory/*.lean`.
204
+
205
+
### Type systems and typing disciplines
206
+
207
+
-`AbstractionSafety.lean` — Safety-oriented typing relation with abstraction-preservation lemmas.
208
+
-`AffineTypes.lean` — Affine ownership typing inspired by Rust-style single-use resources.
209
+
-`Bidirectional.lean` — Bidirectional typing (synthesis/checking) for concise typing derivations.
210
+
-`ContractTypes.lean` — Contract-annotated typing with interface-level guarantees.
211
+
-`DependentPattern.lean` — Dependently typed pattern matching and indexed elimination structure.
212
+
-`EffectSystems.lean` — Type-and-effect judgments with explicit effect labels.
213
+
-`Gradual.lean` — Gradual typing with dynamic type and consistency relations.
This document summarizes the architecture of the `Metatheory` Lean 4 project after reviewing all tracked `.lean` files in the repository.
4
+
5
+
## 1) Two-tier architecture
6
+
7
+
Metatheory has two distinct layers:
8
+
9
+
### A. Core formalized modules (tightly coupled)
10
+
11
+
Core directories:
12
+
13
+
-`Metatheory/Rewriting`
14
+
-`Metatheory/Lambda`
15
+
-`Metatheory/CL`
16
+
-`Metatheory/TRS`
17
+
-`Metatheory/StringRewriting`
18
+
-`Metatheory/STLC`
19
+
-`Metatheory/STLCext`
20
+
-`Metatheory/STLCextBool`
21
+
-`Metatheory/SystemF`
22
+
23
+
Characteristics:
24
+
25
+
- Deep interdependencies across modules (especially through `Rewriting` and between typed/untyped calculi).
26
+
- Shared proof infrastructure (`Star`, `Confluent`, `Diamond`, termination, normal forms).
27
+
- Generic-to-specific proof reuse (e.g., proving a local property once, then lifting to confluence through generic theorems).
28
+
- Mathlib-facing interoperability via `Rewriting/Compat.lean` (mathlib-style naming), plus targeted Mathlib imports in advanced TRS components.
29
+
30
+
### B. Extended standalone modules (broad, mostly self-contained)
31
+
32
+
At `Metatheory/*.lean`, there are about ~70+ standalone modules (currently 78 files) covering topics like effects, macro systems, abstract interpretation, domain/game/category semantics, compilation, and advanced type disciplines.
33
+
34
+
Characteristics:
35
+
36
+
- Usually self-contained, with light or no imports.
37
+
- Repeated use of a lightweight **computational paths** style (`Step`/`Path`) rather than depending on the full generic rewriting stack.
38
+
- Local proof algebra built from path composition and symmetry (`trans`, `symm`) and context lifting (`congrArg`-style transport).
-**TRS/StringRewriting:**`Syntax/Rules → local confluence + termination → Newman-based confluence`
80
+
81
+
---
82
+
83
+
## 3) Core types and relations
84
+
85
+
| Name | Location | Role |
86
+
|---|---|---|
87
+
|`Term`|`Lambda/Term.lean`, `CL/Syntax.lean`, `SystemF/Terms.lean`, `STLCext*/Terms.lean`, `TRS/FirstOrder/Syntax.lean`| Object language terms (de Bruijn in lambda/system F; first-order terms over signatures in TRS). |
88
+
|`Ty`|`STLC/Types.lean`, `STLCext/Types.lean`, `STLCextBool/Types.lean`, `SystemF/Types.lean`| Type grammars for each calculus. |
89
+
|`Subst`|`TRS/FirstOrder/Syntax.lean` (`Nat → Term sig`), `SystemF/StrongNormalization.lean`| Substitution models for first-order and higher-order developments. |
90
+
|`Signature`|`TRS/FirstOrder/Syntax.lean`| Function symbols + arity for first-order TRS. |
91
+
|`Rule` / `RuleSet`|`TRS/FirstOrder/Rules.lean`| Rewrite rules and rule predicates. |
## 5) Computational paths pattern in standalone modules
129
+
130
+
Many standalone modules use a recurring lightweight proof kernel:
131
+
132
+
```lean
133
+
inductive Step (α : Type) : α → α → Type
134
+
inductive Path (α : Type) : α → α → Type
135
+
def Path.trans : Path α a b → Path α b c → Path α a c
136
+
def Path.symm : Path α a b → Path α b a
137
+
def Path.congrArg ...
138
+
```
139
+
140
+
Interpretation:
141
+
142
+
-`Step`: named atomic rewrite/equational moves.
143
+
-`Path`: explicit proof object for multi-step chains.
144
+
-`trans`: composition of chains (path concatenation).
145
+
-`symm`: reversible reasoning.
146
+
-`congrArg` (and variants): lift paths through context/formers.
147
+
148
+
This functions as a local, domain-specific rewriting/equality framework without requiring the full generic ARS stack in each standalone file.
149
+
150
+
---
151
+
152
+
## 6) Design decisions
153
+
154
+
### De Bruijn indices
155
+
156
+
- Used in `Lambda`, `STLC`-adjacent term layers, and `SystemF`.
157
+
- Avoids alpha-conversion bureaucracy and gives direct structural recursion for substitution/shift lemmas.
158
+
159
+
### Parallel reduction for confluence
160
+
161
+
- Core confluence strategy in `Lambda`, `CL`, `STLCext`, `STLCextBool`, and `SystemF`.
162
+
- Standard pipeline: define `ParRed` + `complete` development, prove diamond, then apply generic `confluent_of_diamond`.
163
+
164
+
### Tait/logical-relations method for strong normalization
165
+
166
+
- Used in `STLC/Normalization.lean`, `STLCext/Normalization.lean`, and `SystemF/StrongNormalization.lean`.
167
+
- Main shape: reducibility candidates / reducibility predicate / fundamental lemma / SN corollary.
168
+
169
+
---
170
+
171
+
## 7) Future work and currently parked pieces
172
+
173
+
### TRS FirstOrder case-study modules are intentionally parked
174
+
175
+
The following files contain TODO comment blocks around substantial proof/code regions tied to missing dependency alignment (e.g., `Fin.cons`, `List.Shortlex`, related Mathlib APIs):
176
+
177
+
-`TRS/FirstOrder/GroupTheory.lean`
178
+
-`TRS/FirstOrder/BooleanCaseStudy.lean`
179
+
-`TRS/FirstOrder/DependencyPairs.lean`
180
+
181
+
Related TODO marker:
182
+
183
+
-`TRS/FirstOrder/Examples.lean` includes a restoration note for `Ordering/DependencyPairs`.
184
+
185
+
### STLCext confluence is already present
186
+
187
+
`Metatheory/STLCext/Confluence.lean` exists and proves confluence (Church-Rosser form) using the same parallel-reduction + diamond architecture as other core calculi.
0 commit comments