# TODO Design decisions are in `README.md`; this file tracks the work. ## Level equality (chosen approach) `~` is level equality lifted to whole terms; `≈` is conversion. - [x] **Separate level syntax.** `Tm` indexed by a sort (`Term`, `Lvl`), coercions `` `lvl `` / `` `latom `` with `` `latom (`lvl l) ↪ l ``, level well-formedness `_⊢ₗ_` (see README). Ordinary terms no longer carry level equations. - [x] **Equational theory.** `_~_` as the congruence closure of the level equations (`Specification/LevelEquality.agda`). - [x] **Structure of `~` on terms.** `~→≋`: one layer of matching constructors; injectivity of every term constructor; different constructors are never `~`-equal (`Metatheory/Levels/Equality.agda`). - [x] **Stability.** `~` is stable under renaming and substitution (`~-ren`, `~-sub`, `~σ-sub`, `~-[]`). - [x] **Commutation with complete development.** `u ~ u' → u⁺ ~ u'⁺` (`Metatheory/Confluence/Modulo.agda`). - [x] **Church–Rosser modulo `~`.** `_↪~*_` is confluent, via the triangle property of `~ ; ↪ₚ ; ~` (`Metatheory/Confluence/Modulo.agda`). - [x] **Conversion.** `≈` is a common reduct under `_↪~*_`; equivalence, congruence, renaming, substitution (`Metatheory/Confluence/Conversion.agda`). - [x] **Downstream proofs.** `Metatheory/Typing/Inversion.agda`, `Metatheory/Typing/Substitution.agda`, `Metatheory/Typing/SubjectReduction.agda` (subject reduction holds for the full system). - [x] **Level normal forms.** `nf`, `compare` and its order laws, soundness and completeness, ported to the separate level syntax (`Metatheory/Levels/NormalForm.agda`, `Metatheory/Levels/NormalForm/`). - [x] **Decidability.** `_~?_ : Dec (u ~ u')` in `Metatheory/Levels/Decision.agda`, tested by computation. Reference for the algebra: Bezem & Coquand, *Loop-checking and the uniform word problem for join-semilattices with an inflationary endomorphism* (TCS 2022). - [x] **Injectivity of `lsuc`**: `~-lsuc-inj : lsuc l ~ lsuc l' → l ~ l'` via the normaliser (`Metatheory/Levels/Decision.agda`). - [ ] **η for the coercions** (optional, only if an example needs it): `` `lvl (`latom e) `` and `e` are not convertible (only `` `latom (`lvl l) ↪ l `` holds). This matters when level-typed terms are compared as terms, e.g. `F (lvl (latom x ⊔ lzero))` vs `F x` for `F : Level → Set`, or in `≡`. - As a reduction rule `` `lvl (`latom e) ↪ e ``: left-linear, its only overlap with `β-latom` is trivial, and subject reduction needs only `T ≈ Level` from inverting `⊢-lvl` (plus `Level≉Setn`). - Cost: `~` hides η-redexes (`` `lvl (`latom e `⊔ `latom e) ~ `lvl (`latom e) ↪ e ``), so `~-⁺` fails. `⁺` would have to contract `` `lvl l `` whenever `nf l ≡ `latom e`, making `Metatheory/Confluence/Modulo` depend on the normaliser's soundness and completeness. - As an equation in `~` instead: breaks `~→≋` (different heads become `~`-equal), so not recommended. ## Universe hierarchy (typing) - [x] Cumulativity: lifting rules `⊢-Set≤Setω` and `⊢-Setω≤`. - [x] `⊢-∀` split into `⊢-∀`, `⊢-∀ω` and `⊢-∀-dep` (result level determined by the premises; level-dependent codomains only in `Set`, so `∀ (l : Level) → Setω l` is rejected). Checked with example derivations, e.g. `∀ (l : Level) → Set l : Setω lzero`. - [x] `⊢-Setn` and `⊢-Setω` require the level to be well formed (`Γ ⊢ₗ l`). - [x] `⊢-λ` requires the domain to be a type: `Γ ⊢ t₁ ⦂ Setω l` (small domains reach `Setω lzero` via `⊢-Set≤Setω`). - [x] `⊢-∃` mirrors `⊢-∀`: `⊢-∃`, `⊢-∃ω`, `⊢-∃-dep`. - [x] `⊢-≡` requires `Γ ⊢ t ⦂ Set l` and lives in `Set l`; the motive of `⊢-subst` is in `Set (ren wk l)`. - [x] `⊢-,` requires its codomain to be a type, `Γ , t₁ ⊢ t₂ ⦂ Setω l`, as in Agda. Without it, `(λz. Unit , tt) : ∃[x⦂ ∀ (z : Level) → Setω 0 ] (x · x)` is derivable, although `x · x` is not a type, so no reducible type is convertible to the pair's type (see the decidability section). - [x] True and False: `` `True = `Unit `` (member `` `trivial = `tt ``); `` `False : Set `` with ex falso `` `absurd P e : P `` for `e : False` (`⊢-False`, `⊢-absurd`), neutral when `e` is. Covered by all proofs, including the model (`no-False`). - [x] Unit type: `` `Unit : Set `` (`⊢-Unit`) with `` `tt : `Unit `` (`⊢-tt`); both are values, inert under reduction and `~`, and covered by confluence, the level normaliser, subject reduction and progress. - [x] Proofs for the new rules: `≈-Γ-⊢`, `⊢ren` / `⊢sub` (weakened levels realigned with `wk-extᵣ-fusion` / `wk-extₛ-fusion`), inversion through the lifting rules (universes are never convertible to `∀`, `∃` or `≡`), subject reduction. - [x] Natural numbers: `` `ℕ : Set ``, `` `zero ``, `` `suc ``, and `` `natrec P z s t `` with the motive as a function term, at `Set l` (`⊢-natrec`) or `Setω m` (`⊢-natrecω`). Covered by level equality (`~-suc`, `~-natrec`), confluence, the level normaliser, subject reduction, progress and the decidability proofs; `Tests/Nat.agda` types plus, times and factorial. ## Values - [x] `val-Setω` requires `Value l`, as `val-Setn` does. - [x] `val-l` renamed to `val-lzero`. - [x] `val-⊔`: `_⊔_` of values is a value (`⊔` does not reduce; level equality is handled by conversion). - [x] `val-lvl`, `val-latom` (`` `latom e `` is a value if `e` is neutral). - [x] `Value` describes normal forms (values under binders), matching the full reduction relation; `Neutral` the stuck terms. - [x] **Progress** for open terms: `progress : Γ ⊢ e ⦂ t → Value e ⊎ ∃[ e' ] e ↪ e'` (with `progressₗ` for levels), and `value-normal : Value e → ¬ (e ↪ e')` (`Metatheory/Typing/Progress.agda`). ## Decidability of conversion - [x] **Decidability of conversion** for well-typed terms in well-formed contexts: `decidable-≈ : Decidable-≈` and `decidable-≈ₗ : Decidable-≈ₗ` (`Decidability/Fundamental.agda`). Existing theorems are unchanged; `⊢-,` gained the premise that its codomain is a type (see above). The proof is described in the README, "Decidability of conversion". - [x] **Normalisation by `↪*` alone**: `normalisation` / `normalisationₗ` (`Fundamental.agda`); inductive SN has no `~` clause (it was never needed). - [x] **Strong normalisation** (accessibility of `↪`): `strong-normalisation` / `strong-normalisationₗ` (`Decidability/SN/Strong.agda`), by soundness of inductive SN; the core is backward closure under weak head expansion. - [x] **Canonicity**: closed terms reduce to introduction forms (`canonicity`), closed natural numbers to numerals (`canonicity-ℕ`) (`Decidability/Canonicity.agda`). Not computational, since the substitution lemmas use `fun-ext`. ## Consistency via a set-theoretic model (branch `con-leche`) Following con-leche (Breitner, Lean FRO): give every well-typed term a meaning in set theory and prove soundness, so that types denoting `∅` are uninhabited. Relative to ZFC with ω·2 inaccessibles. - [x] **Annotated λ**: `λ[x⦂ A ] e`, so that a λ denotes the graph of its body over its domain. Reduction also reduces the annotation (`ξ-λ₁`); β discards it (inductive SN gets the side condition). - [x] ~~Targets of `⊢-≈` are types~~: not needed. Soundness is stated up to conversion (a well-denoted witness `W ≈ T`), so junk targets of `⊢-≈` never need a meaning. - [x] **Codomain levels are well formed**: `⊢-∀` / `⊢-∃` require `Γ ⊢ₗ l₂`; over an empty domain the codomain says nothing about it. - [x] **Set-theory interface** (a module parameter, no postulate): carrier, membership, `∅`, pairs, dependent function and pair sets, `ω`, and cumulative universes `U : Stratum → V` for `fin k` and `ω+ m`. - [x] **Interpretation**: levels to ℕ (`⊔ ↦ max`, `lsuc ↦ suc`, atoms via `ω`); `Set l ↦ U (fin ⟦l⟧)`, `Setω k ↦ U (ω+ k)`; `∀` / `∃` as dependent function / pair sets; `≡` as `{∅}` or `∅`; `Unit` as `{∅}`; `ℕ` and `Level` as `ω`; `natrec` by recursion on ω; contexts as sets of environments. - [x] **Lemmas**: interpretation commutes with renaming and substitution; `~` preserves meaning (semilattice laws in ℕ); reduction of well-typed terms preserves meaning. - [x] **Soundness**, up to conversion: `Γ ⊢ e ⦂ T` gives a well-denoted witness `W ≈ T` with `⟦e⟧ ρ ∈ ⟦W⟧ ρ` (`Model/Soundness.agda`). - [x] **ZF axioms**: the set theory is con-leche's (ZF with Grothendieck universes, here along the ω·2 strata, and classical logic as `em`); the model's operations are derived from it (`Model/ZF.agda`, `Model/FromZF.agda`, `Model/ConsistencyZF.agda`). - [x] **Published set theories**: ZFC with Grothendieck's universe axiom (`Model/Grothendieck.agda`) and Tarski–Grothendieck set theory (`Model/TarskiGrothendieck.agda`), each deriving the ZF record; Tarski universes are shown to be Grothendieck universes without choice (`Model/FromTarski.agda`); the rules of Mathlib's `ZFSet` (`Model/Mathlib.agda`) plus Grothendieck's universe axiom. - [x] **Consistency**: no closed term of `False`, of `zero ≡ suc zero` or of `∀ (A : Set) → A` (`Model/Consistency.agda`).