The con-leche proof idea

Joachim Breitner, Lean FRO

Revision bc6676101c, 2026-11-21

This document was written by an AI agent (Claude, working with the maintainer). It is a self-contained account of the core proof idea of con-leche, a verified kernel checker for Lean 4: the modelling and consistency argument that connects Lean’s own terms, an inductive description of checking, and a set theory given axiomatically. The real proof lives in the repository, and phrases underlined like this oneConLeche/MainTheorem.lean:L47-L5047theorem main_json_model (V : Type w) [SetTheory V] {file : String} {fs : FS} {b : ByteArray}
48 (h : ModelIO.CanGive (Driver.runArgs ["--", file]) fs 0) (hb : fs.file file = some b) :
49 ∃ r, parseChunks [b] = .ok r ∧ ∃ model, IsModel V model (· ∈ constantsOf r.decls.toList) :=
50 json_isModel V h hb
link to it on master, at the definition or theorem being described; phrases underlined like this onewhitepaper/Fragment/Sound.lean:L2293-L22972293theorem soundness [LevelOracle] (m : EnvModel V env) (φ : Name → Nat) :
2294 (∀ {Γ : List Expr} {e e' : Expr}, Red env Γ e e' → RedSem m φ Γ e e') ∧
2295 (∀ {Γ : List Expr} {a b : Expr}, DefEq env Γ a b → DefEqSem m φ Γ a b) ∧
2296 (∀ {Γ : List Expr} {e T : Expr}, Infer env Γ e T → InferSem m φ Γ e T) :=
2297 ⟨red_sound, defeq_sound, infer_sound⟩
link to the paper’s own Lean fragment. In the web version, hovering over such a phrase shows the cited lines.

1. Introduction

1.1. What is proved

con-leche is a checker for Lean 4. It reads an export of a Lean environment, the stream: every definition, theorem and inductive type, in the official kernel’s own terms. It accepts or rejects the stream, checking what the official kernel checks (on a few features it declines instead; Section 9). It comes with a proof, written in Lean itself, of what an acceptance means: every stream the checker accepts has a model in set theoryConLeche/Model/PureChecker.lean:L31-L3431theorem model_exists (V : Type w) [SetTheory V]
32 (pins : List NatOpPinSet) (maxNatSize : Nat) (ds : Array Declaration)
33 (accepted : (checkDecls .verified pins maxNatSize ds).isOk) :
34 ∃ model, IsModel V model (· ∈ constantsOf ds.toList) := by
. Each constant is assigned a setConLeche/IsModel.lean:L212-L213212def IsModel (V : Type w) [SetTheory V] (model : Name → List Nat → V)
213 (C : ConstantInfo → Prop) : Prop :=
, each type denotes a set, and every constant of the stream holds in the model on its own: it is a member of the set its type denotes, a definition denotes what its value denotes, and a recursor computes by its rules, read off its own type. A hole (an axiom, or a declaration whose value uses sorry) is read as an assumption of its statement. Nothing is fixed by name: the prelude’s False denotes the empty set, and its Eq denotes equality, by their declarations’ own clauses, so every equation the checker accepts is an equality of sets. Hence a model of an accepted stream has no constant of type False, since False denotes the empty set, and every accepted theorem is true in the model.

Checked module by module from Lean’s .olean files, every module of an import closure has a model of its own constantsConLeche/MainTheorem.lean:L109-L120109theorem main_modular (V : Type w) [SetTheory V] {dirs root : String} {r : Name} {fs : FS}
110 (hr : Olean.parseModName root = some r)
111 (h : ModelIO.CanGive (Driver.runArgs ["--check-graph", "--search-path=" ++ dirs, "--", root])
112 fs 0)
113 (hwork : ∀ m', Olean.HdrClosure (Driver.searchPathOf dirs) fs [r] m' → ∃ root',
114 Olean.parseModName root' = some m' ∧ ModelIO.CanGive
115 (Driver.runArgs ["--olean", "--module", "--search-path=" ++ dirs, "--", root']) fs 0) :
116 ∃ model : Name → (Name → List Nat → V),
117 (∀ m, Olean.InClosure (Driver.searchPathOf dirs) fs #[r] m →
118 IsModel V (model m) (Olean.moduleConstants (Driver.searchPathOf dirs) fs m)) ∧
119 (∀ m n m', Olean.InClosure (Driver.searchPathOf dirs) fs #[r] m →
120 Olean.Sees (Driver.searchPathOf dirs) fs m n m' → model m n = model m' n) :=
, and a name a module sees as another module’s means there what that module’s model says. A challenge, a module with holes, checked with a solution that fills them, has a model of its own constants too, and that statement does not mention the solution.

1.2. The shape of the argument

The theorem is relative to a model of an abstract set theory, a structure with membership, extensionality, the usual set-forming operations and a chain of universes closed under themConLeche/SetTheory/Core.lean:L95-L100 95/-- A model of set theory of exactly the strength the checker needs:
96membership, the six ZF⁻ axioms (extensionality, pairing, union, power
97set, regularity, Lean-level replacement), and an ω-chain of
98Grothendieck universes. Infinity is derivable; choice is inherited
99from the meta-logic (`Classical.choice`); see the module docstring. -/
100class SetTheory (V : Type u) where
. Such a structure gives a model of Lean, so by Gödel’s second incompleteness theorem Lean cannot prove that one exists, unless Lean is inconsistent. The assumption is standard, though: it follows from the existence of ω many inaccessible cardinals, the hypothesis of the Lean development of Carneiro’s model of Lean (Section 10; §7 of OVERVIEW.md says more).

The usual way to prove such a statement, given a typing judgement for the type theory, has two steps: show that the checker accepts only derivable judgements, and show that derivable judgements are true in the model. The first step needs the metatheory of the type theory: that reduction preserves types (subject reduction), that reduction is confluent, that a function type determines its domain and codomain (injectivity of Π), and that a term has one type up to definitional equality. Our proof needs none of it.

Nor does it have a typing judgement. In its place is a description of what the checker does: three inductively defined relations, one for reductionConLeche/Rules/Rel.lean:L106106inductive Red (env : Env) : Nat → Expr → Expr → Prop where
, one for the verdicts of the definitional-equality testConLeche/Rules/Rel.lean:L348348inductive DefEq (env : Env) : Nat → Expr → Expr → Prop where
and one for type inferenceConLeche/Rules/Rel.lean:L589589inductive Infer (env : Env) : Grade → Nat → Expr → Expr → Prop where
(six in the real proof, where premises about lists get relations of their own; Section 9). Their rules are exactly the moves the checker makes, and each rule’s premises are what the checker verified at that point. On the model side there is a total, term-directed interpretationwhitepaper/Fragment/Interp.lean:L139-L146139noncomputable def interp (M : Name → List Nat → V) (φ : Name → Nat) : (Nat → V) → Expr → V
140 | ρ, .bvar i => ρ i
141 | _, .sort u => typeU (u.eval φ)
142 | _, .const c ls => M c (ls.map (Level.eval φ))
143 | ρ, .app f a => app (interp M φ ρ f) (interp M φ ρ a)
144 | ρ, .lam A b => lamV (interp M φ ρ A) fun x => interp M φ (cons x ρ) b
145 | ρ, .pi A B => piV (interp M φ ρ A) fun x => interp M φ (cons x ρ) B
146 | ρ, .letE _ v b => interp M φ (cons (interp M φ ρ v) ρ) b
: every term denotes a set, well-typed or not, and the interpretation uses nothing beyond what is in the term itself. In particular it uses no typing information, nothing that would have to be inferred. Where a typing judgement would say “this term has that type”, there is a semantic invariantwhitepaper/Fragment/WellDenoted.lean:L61-L7561def WellDenoted : (Nat → V) → Expr → Prop
62 | _, .bvar _ => True
63 | _, .sort _ => True
64 | _, .const _ _ => True
65 | ρ, .app f a =>
66 WellDenoted ρ f ∧ WellDenoted ρ a ∧ AppliesTo (interp M φ ρ f) (interp M φ ρ a)
67 | ρ, .lam A b =>
68 WellDenoted ρ A ∧ IsTy (interp M φ ρ A) ∧
69 (∀ x, x ∈ˢ interp M φ ρ A → WellDenoted (cons x ρ) b)
70 | ρ, .pi A B =>
71 WellDenoted ρ A ∧ IsTy (interp M φ ρ A) ∧
72 (∀ x, x ∈ˢ interp M φ ρ A → WellDenoted (cons x ρ) B) ∧
73 (∀ x, x ∈ˢ interp M φ ρ A → IsTy (interp M φ (cons x ρ) B))
74 | ρ, .letE _ v b =>
75 WellDenoted ρ v ∧ WellDenoted (cons (interp M φ ρ v) ρ) b
on the term’s set, imposed at every subterm: every application applies a function to a member of its domain, every binder’s domain is a type, and so on. One induction over the three relationswhitepaper/Fragment/Sound.lean:L2293-L22972293theorem soundness [LevelOracle] (m : EnvModel V env) (φ : Name → Nat) :
2294 (∀ {Γ : List Expr} {e e' : Expr}, Red env Γ e e' → RedSem m φ Γ e e') ∧
2295 (∀ {Γ : List Expr} {a b : Expr}, DefEq env Γ a b → DefEqSem m φ Γ a b) ∧
2296 (∀ {Γ : List Expr} {e T : Expr}, Infer env Γ e T → InferSem m φ Γ e T) :=
2297 ⟨red_sound, defeq_sound, infer_sound⟩
then proves three claims at once. A reduction step preserves the denotation and the semantic invariant; a verdict “definitionally equal” means that the two sides denote the same set; and an inferred type contains the term, that is, the term’s set is a member of the type’s set.

1.3. How to interpret a ∀ or a lambda

At every binder the interpretation has to decide how to interpret a ∀ or a lambda. In Lean, a Π-type ∀ x : A, B, with x a variable and A, B terms, is a type of functions when B is a type and a proposition when B is a proposition, and in the model these are different kinds of sets. A function space is a set of graphs. A proposition is a truth value, a set with at most one element: the model has one distinguished set, the point, which every proof of every proposition denotes, so proof irrelevance is built in. The two cases look the same on the page, and telling them apart by the sort of B would take type inference. Our interpretation instead reads the answer off the valueswhitepaper/Fragment/Lib.lean:L523-L527523/-- **The function space, regime read off the fibres.** -/
524noncomputable def piV (A : V) (B : V → V) : V := piR (propB A B) A B
525
526/-- **The abstraction, regime read off the body values.** -/
527noncomputable def lamV (A : V) (F : V → V) : V := lamR (ptB A F) A F
: a ∀ denotes a truth value exactly when every one of its fibres (the set B denotes at a member of the domain) is a truth value, and a lambda denotes the point exactly when every value of its body is the point. The terms carry no annotation for the choice; they are Lean’s own.

Over a non-empty domain this reading agrees with the sort of the body. Over an empty domain it does not: fun h => h.elim, of type False → Nat, denotes the point although its type has sort Type (Section 2.5). This shapes the soundness claims: a reduction or an equality claims nothing about a term that denotes the point (Section 2.7). The same mismatch is why the checker makes two checks that the official kernel never makes (Section 2.8): it compares the types of two bodies at lambda congruence and η, and, in one rare case of ι-reduction, it compares a constructor application with the recursor’s arguments and type-checks its fields.

1.4. This document

This document is a pen-and-paper account of that argument on a simplified fragment of the checker. The fragment keeps the terms, the three relations, definitions and inductive types with their recursors. It drops projections, number and string literals, mutual inductive types, quotients, opaques and axioms (a hole is accepted only with a solution that fills it, Section 8), nests inductive types only one container deep and not under a binder (Section 5 describes the full check, without proof), reads False, Eq and Nat from the input alone (the real checker also compares them with pinned copies), and has none of the checker’s performance devices (memo tables, fuel, the parallel check phase). Section 9 lists every omission, with a short account of what the real proof does about it. The fragment is verified in Lean in a small development of its own, whitepaper/Fragment/, which imports nothing from the main proof and is parametric in the same kind of abstract set theory. The underlined source links lead into the real proof and into that development.

Section 2 presents the fragment without an environment: terms and universe levels, the three relations, the set theory, the interpretation, the semantic invariant, and the three claims with their proof. Routine proof cases are listed briefly; the cases where the interpretation of a binder matters, or where a syntactic proof would fail, are discussed in full. It ends with the checks the official kernel skips and with a cheaper mode of inference. The claims (Section 2.7) are a good place to start reading. Section 3 adds the environment and its definitions, and the model that grows with them. Section 4 adds inductive types as least fixed points in the model, their recursors and ι-reduction, and proves the main theorem: every accepted input has a model of its constants, so none of them has an inductive proposition without constructors as its type. Section 5 changes tack: it describes con-leche’s full check for nested inductive types, such as Tree α with its field of type List (Tree α), and only sketches how the model extends. Section 6 derives η for structures and unit-likeness, which the fragment drops, from the extensionality of the model. Section 7 checks a development module by module, each module against the imported views of its imports, and gives every module a model of its own constants that agrees with its imports’ models on the names they share. Section 8 checks an input with holes against a solution that fills them, and shows that the input’s constants have a model of their own, also module by module. Section 9 lists what was left out and how the real proof differs from the fragment, and Section 10 relates the argument to earlier work.

2. The fragment without an environment

This section presents the core of the argument on a fragment of Lean without an environment: first the terms, the levels and the three relations that say what the checker does; then the set theory, the interpretation, the semantic invariant that replaces a typing judgement, and the three soundness claims with their proofs. Everything here is verified in the fragment’s own Lean development and linked, alongside its counterpart in the real proof.

2.1. Terms

The terms of the fragment are the official kernel’s terms, minus what Section 9 leaves out:

𝑒⩴𝑥|𝖲𝗈𝗋𝗍𝑢|𝑒𝑒|𝜆𝑥:𝐴.𝑒|∀𝑥:𝐴.𝑒|𝗅𝖾𝗍𝑥:𝑇≔𝑣;𝑒

A termwhitepaper/Fragment/Syntax.lean:L29-L4829/-- Terms. -/
30inductive Expr where
31 /-- A bound variable, by de Bruijn index. -/
32 | bvar (i : Nat)
33 /-- The sort `Sort l`. -/
34 | sort (l : Level)
35 /-- A constant of the environment at a level instantiation. -/
36 | const (c : Name) (ls : List Level)
37 /-- Application. -/
38 | app (f a : Expr)
39 /-- Abstraction `fun (x : A) => b`. -/
40 | lam (A b : Expr)
41 /-- The Π-type `(x : A) → B`. -/
42 | pi (A B : Expr)
43 /-- `let x : ty := v; b`. Kept as Lean stores it: the
44 checker substitutes the value (`Red.zeta`, `Infer.letE`), and the
45 interpretation reads the body at the value's value, ignoring the type
46 (`Interp.lean`), as con-leche's `Denotes` `let` rule does. -/
47 | letE (ty v b : Expr)
48 deriving DecidableEq
is a variable 𝑥; a sort 𝖲𝗈𝗋𝗍𝑢 at a universe level 𝑢 (Section 2.2), with 𝖯𝗋𝗈𝗉=𝖲𝗈𝗋𝗍0; an application 𝑓𝑎; a function 𝜆𝑥:𝐴.𝑏; a dependent function type, or Π-type, ∀𝑥:𝐴.𝐵, written 𝐴→𝐵 when 𝑥 does not occur in 𝐵; or a let-expression 𝗅𝖾𝗍𝑥:𝑇≔𝑣;𝑏. Types are terms; there is no separate class. A sequence of binders, such as the lambdas of 𝜆𝑥:𝐴.𝜆𝑦:𝐵.𝑒, is a telescope.

The paper writes named variables, with the usual conventions: terms are taken up to renaming of bound variables, and 𝐵[𝑥≔𝑎] is the capture-avoiding substitutionwhitepaper/Fragment/Syntax.lean:L65-L7565/-- Instantiate the bound variable `k` by `a` (and lower the indices
66above it): `e.inst a` is `e[x := a]` for the innermost binder. -/
67def inst : Expr → Expr → (k : Nat := 0) → Expr
68 | bvar i, a, k =>
69 if i < k then bvar i else if i = k then liftN k a else bvar (i - 1)
70 | sort u, _, _ => sort u
71 | const c ls, _, _ => const c ls
72 | app f b, a, k => app (inst f a k) (inst b a k)
73 | lam A b, a, k => lam (inst A a k) (inst b a (k + 1))
74 | pi A B, a, k => pi (inst A a k) (inst B a (k + 1))
75 | letE T v b, a, k => letE (inst T a k) (inst v a k) (inst b a (k + 1))
of 𝑎 for 𝑥. The Lean fragment uses de Bruijn indices instead (a variable is the number of binders between its occurrence and its own), and a rule that mentions the types of the variables in scope carries a context Γ, a list of those types. No rule in this paper needs index arithmetic in its named form.

In con-leche The checker uses neither device. It opens a binder with a fresh free variable that carries its own type, so it keeps no context at all. This is a performance device and changes nothing below.

2.2. Levels

Universe levelswhitepaper/Fragment/Level.lean:L29-L4329/-- Universe levels (`Lean.Level` without `mvar`). -/
30inductive Level where
31 /-- `Prop`'s level, `0`. -/
32 | zero
33 /-- The successor level `u + 1`. -/
34 | succ (l : Level)
35 /-- The maximum `max u v`. -/
36 | max (a b : Level)
37 /-- The impredicative maximum: `imax u v` is `0` when `v` is `0`,
38 else `max u v` — so a `∀` whose codomain is a proposition is a
39 proposition whatever its domain's level. -/
40 | imax (a b : Level)
41 /-- A level parameter of the enclosing declaration. -/
42 | param (n : Name)
43 deriving DecidableEq, Repr
are Lean’s, without metavariablesConLeche/Kernel/Expr.lean:L32-L3732inductive Level where
33 | zero
34 | succ (u : Level)
35 | max (u v : Level)
36 | imax (u v : Level)
37 | param (n : Name)
:

𝑢⩴0|𝑢+1|max(𝑢,𝑣)|imax(𝑢,𝑣)|𝑝

with 𝑢,𝑣 levels and 𝑝 a level parameter of the enclosing declaration. A valuation 𝜑 maps each level parameter to a natural number, and a level means the natural numberwhitepaper/Fragment/Level.lean:L50-L5650/-- The value of a level under a *valuation* `φ` of its parameters. -/
51def eval (φ : Name → Nat) : Level → Nat
52 | zero => 0
53 | succ l => eval φ l + 1
54 | max a b => Max.max (eval φ a) (eval φ b)
55 | imax a b => imaxNat (eval φ a) (eval φ b)
56 | param n => φ n
𝜑(𝑢) (as in con-lecheConLeche/Kernel/Level.lean:L273-L278273def eval (φ : Name → Nat) : Level → Nat
274 | .zero => 0
275 | .succ l => eval φ l + 1
276 | .max l r => Max.max (eval φ l) (eval φ r)
277 | .imax l r => if eval φ r = 0 then 0 else Max.max (eval φ l) (eval φ r)
278 | .param n => φ n
):

𝜑(0)=0,𝜑(𝑢+1)=𝜑(𝑢)+1,𝜑(max(𝑢,𝑣))=max(𝜑(𝑢),𝜑(𝑣)),𝜑(imax(𝑢,𝑣))={0if𝜑(𝑣)=0,max(𝜑(𝑢),𝜑(𝑣))otherwise.

The impredicative maximum is what makes ∀𝑥:𝐴.𝐵 a proposition whenever 𝐵 is one, whatever the level of 𝐴: its sort is 𝖲𝗈𝗋𝗍(imax(𝑢,𝑣)) (rule pi in Section 2.3).

The level oracle. The checker decides 𝑢≤𝑣 and 𝑢=𝑣 between levels with an algorithm. This paper does not present that algorithm and does not verify it. It assumes two Boolean functionswhitepaper/Fragment/Level.lean:L130-L145130/-- **The level oracle** — the checker's decision procedures for `≤` and
131`=` on levels, assumed sound and complete with respect to `eval`: a
132parameter of the development, never defined here. (`le` is what the
133inductive installs of the environment section consume; the env-free
134fragment uses `eq` alone.) -/
135class LevelOracle where
136 /-- `le u v = true` decides `u ≤ v` at every valuation. -/
137 le : Level → Level → Bool
138 /-- `eq u v = true` decides `u = v` at every valuation. -/
139 eq : Level → Level → Bool
140 /-- Soundness and completeness of `le`. -/
141 le_iff : ∀ a b : Level, le a b = true ↔ ∀ φ : Name → Nat, Level.eval φ a ≤ Level.eval φ b
142 /-- Soundness and completeness of `eq`. -/
143 eq_iff : ∀ a b : Level, eq a b = true ↔ ∀ φ : Name → Nat, Level.eval φ a = Level.eval φ b
144
145namespace Level
with a specification:

𝑢≤𝑣answered yes⟺∀𝜑.𝜑(𝑢)≤𝜑(𝑣),𝑢=𝑣answered yes⟺∀𝜑.𝜑(𝑢)=𝜑(𝑣)

(the real ≤ConLeche/Kernel/Level.lean:L144-L146144/-- Decide `l ≤ r` semantically; `none` is an exhausted comparison. -/
145def leq (l r : Level) : Option Bool :=
146 leqCore defaultFuel (simplify l) (simplify r) 0
, the real =ConLeche/Kernel/Level.lean:L164-L167164def isEquiv (l r : Level) : Option Bool := do
165 if l == r then pure true
166 else if simplify l = simplify r then pure true
167 else if ← leq l r then leq r l else pure false
and their soundnessConLeche/Verify/Level.lean:L165-L166165theorem leq_sound {l r : Level} (h : leq l r = some true) :
166 ∀ φ, eval φ l ≤ eval φ r := by
proofsConLeche/Verify/Level.lean:L193-L194193theorem isEquiv_sound {l r : Level} (h : isEquiv l r = some true) :
194 ∀ φ, eval φ l = eval φ r := by
). We write 𝑢≐𝑣 for “the oracle says 𝑢=𝑣”.

2.3. The three relations

The checker is described by three relations over terms, defined together by inference rules: reduction Γ⊢𝑒⇝𝑒′, definitional equality Γ⊢𝑎≡𝑏, and inference Γ⊢𝑒⇒𝑇. A context Γ lists the variables in scope with their types. The complete rule sets are one mutual inductive definitionwhitepaper/Fragment/Rules.lean:L56-L79856mutual
57
58/-- **Reduction**: the head steps of the checker's `whnf`, chained. -/
59inductive Red (env : Env) : List Expr → Expr → Expr → Prop where
60 /-- No step (`Red.refl`, `Rel.lean:106`). -/
61 | refl {Γ : List Expr} {e : Expr} : Red env Γ e e
62 /-- Chaining (`Red.trans`, `Rel.lean:111`). A reduction is a
63 denotation identity, so chaining costs nothing semantically. -/
64 | trans {Γ : List Expr} {e₁ e₂ e₃ : Expr} :
65 Red env Γ e₁ e₂ → Red env Γ e₂ e₃ → Red env Γ e₁ e₃
66 /-- Head reduction inside an application (`Red.appFn`,
67 `Rel.lean:116`): the head is reduced before a redex is looked for. -/
68 | appFn {Γ : List Expr} {f f' a : Expr} :
69 Red env Γ f f' → Red env Γ (app f a) (app f' a)
70 /-- **β**: at every binder, with **no premise** — no
71 inference of the argument, no comparison with the binder's domain.
72 This is Lean's own β (`whnf_core`). The model needs no premise
73 (`Sound.lean`, `Red.beta_sound`): a reduction claims nothing of a
74 redex that denotes the point, and a redex that does not has a lambda that
75 does not, so a graph, which determines its domain: the argument lies
76 in the lambda's domain because it lies in the domain of the slot the
77 semantic invariant gives the application.
78 -/
79 | beta {Γ : List Expr} {A b a : Expr} :
80 Red env Γ (app (lam A b) a) (b.inst a)
81 /-- **ζ**: a `let` reduces to its body with the value
82 substituted, with no certificate, as β (con-leche's `whnfCore` on
83 `.letE`, S0's `inst1M b v`; official `whnf_core`). Unlike β it
84 needs no case split on the point: the `let` and its reduct denote
85 alike at every environment (`interp_zeta`). -/
86 | zeta {Γ : List Expr} {T v b : Expr} :
87 Red env Γ (letE T v b) (b.inst v)
88 /-- **δ** (`Red.delta`, `Rel.lean:140`): a definition unfolds to its
89 value, at the use's level instantiation. (With `appFn`, an applied
90 definition unfolds at its head.) -/
91 | delta {Γ : List Expr} {c : Name} {ls : List Level} {ci : ConstInfo} {v : Expr} :
92 env.find? c = some ci → ci.value? = some v →
93 ls.length = ci.lparams.length →
94 Red env Γ (const c ls) (v.instL ci.lparams ls)
95 /-- **ι** (`Red.iota`, `Rel.lean:200`): a stored recursor applied to
… 703 more lines
, as in con-lecheConLeche/Rules/Rel.lean:L102-L106102mutual
103
104/-- **Reduction**: the head steps of `whnfCore` and the `whnf` loop,
105chained. -/
106inductive Red (env : Env) : Nat → Expr → Expr → Prop where
.

How to read them. The three relations describe what the checker does. Γ⊢𝑎≡𝑏 means that on the terms 𝑎 and 𝑏 the checker’s equality test answers yes. Γ⊢𝑒⇒𝑇 means that, asked for the type of 𝑒, the checker returns 𝑇. We write ⇒ rather than the customary colon so that it is not read as a typing judgement, which this paper does not have. Every relation is stated in the accepting direction only; nothing says what the checker rejects. A rule’s premises are exactly what the checker did at that site: the recursive calls it made, and the tests whose outcome fixes the shape of the conclusion.

A convention: a chain such as Γ⊢𝑎⇒𝑇⇝𝑒 abbreviates consecutive premises in the same context, one per arrow, the right end of each arrow being the subject of the next; here Γ⊢𝑎⇒𝑇 and Γ⊢𝑇⇝𝑒. Chains of any length are read the same way.

2.3.1. Reduction

Reduction chains the head steps the checker makes when it normalises a term. It is reflexive and transitivewhitepaper/Fragment/Rules.lean:L58-L6958/-- **Reduction**: the head steps of the checker's `whnf`, chained. -/
59inductive Red (env : Env) : List Expr → Expr → Expr → Prop where
60 /-- No step (`Red.refl`, `Rel.lean:106`). -/
61 | refl {Γ : List Expr} {e : Expr} : Red env Γ e e
62 /-- Chaining (`Red.trans`, `Rel.lean:111`). A reduction is a
63 denotation identity, so chaining costs nothing semantically. -/
64 | trans {Γ : List Expr} {e₁ e₂ e₃ : Expr} :
65 Red env Γ e₁ e₂ → Red env Γ e₂ e₃ → Red env Γ e₁ e₃
66 /-- Head reduction inside an application (`Red.appFn`,
67 `Rel.lean:116`): the head is reduced before a redex is looked for. -/
68 | appFn {Γ : List Expr} {f f' a : Expr} :
69 Red env Γ f f' → Red env Γ (app f a) (app f' a)
, and it reaches inside the headConLeche/Rules/Rel.lean:L106-L122106inductive Red (env : Env) : Nat → Expr → Expr → Prop where
107 /-- Every `pure e` exit: the value clauses of `whnfCoreBody`
108 (`Kernel/Core.lean`), the stuck fallbacks (`:1003`, `:1033-1035`),
109 an uncertified redex (`:1001`), `iotaRec = none` (`:1003`), the
110 loop's fixpoint (`whnfStep`'s `pure e₁`, `:1088`). -/
111 | refl {d : Nat} {e : Expr} : Red env d e e
112 /-- The recursive `whnfCore` continuations after β/ι/proj
113 (`Core.lean:990`, `:997`, `:1002`, `:1033`), the `whnf` loop
114 (`whnfLoop`, `:1091-1095`), and the major's preparation chain
115 (`prepareMajor`, `:785-807`). -/
116 | trans {d : Nat} {e₁ e₂ e₃ : Expr} :
117 Red env d e₁ e₂ → Red env d e₂ e₃ → Red env d e₁ e₃
118 /-- Head normalisation inside an application (`whnfCoreBody`'s
119 `.app` clause, `Kernel/Core.lean`: `whnfCore f` before the redex
120 tests). -/
121 | appFn {d : Nat} {f f' a : Expr} :
122 Red env d f f' → Red env d (.app f a) (.app f' a)
of an application.

Γ⊢𝑒⇝𝑒reflΓ⊢𝑒1⇝𝑒2Γ⊢𝑒2⇝𝑒3Γ⊢𝑒1⇝𝑒3transΓ⊢𝑓⇝𝑓′Γ⊢𝑓𝑎⇝𝑓′𝑎head

𝛽whitepaper/Fragment/Rules.lean:L70-L8070 /-- **β**: at every binder, with **no premise** — no
71 inference of the argument, no comparison with the binder's domain.
72 This is Lean's own β (`whnf_core`). The model needs no premise
73 (`Sound.lean`, `Red.beta_sound`): a reduction claims nothing of a
74 redex that denotes the point, and a redex that does not has a lambda that
75 does not, so a graph, which determines its domain: the argument lies
76 in the lambda's domain because it lies in the domain of the slot the
77 semantic invariant gives the application.
78 -/
79 | beta {Γ : List Expr} {A b a : Expr} :
80 Red env Γ (app (lam A b) a) (b.inst a)
fires at every redex, and 𝜁whitepaper/Fragment/Rules.lean:L81-L8781 /-- **ζ**: a `let` reduces to its body with the value
82 substituted, with no certificate, as β (con-leche's `whnfCore` on
83 `.letE`, S0's `inst1M b v`; official `whnf_core`). Unlike β it
84 needs no case split on the point: the `let` and its reduct denote
85 alike at every environment (`interp_zeta`). -/
86 | zeta {Γ : List Expr} {T v b : Expr} :
87 Red env Γ (letE T v b) (b.inst v)
substitutes a let-binding’s value into its body; neither has a premise.

Γ⊢(𝜆𝑥:𝐴.𝑏)𝑎⇝𝑏[𝑥≔𝑎]betaΓ⊢(𝗅𝖾𝗍𝑥:𝑇≔𝑣;𝑏)⇝𝑏[𝑥≔𝑣]zeta

As in the official kernel, 𝛽 has no premise, although its soundness needs the argument to lie in the domain of the lambda; Section 2.6 shows where that comes from. 𝜁 is simpler: a let-expression always denotes what its body with the value substituted denotes.

2.3.2. Definitional equality

The checker’s equality testwhitepaper/Fragment/Rules.lean:L547-L566547inductive DefEq (env : Env) : List Expr → Expr → Expr → Prop where
548 /-- The syntactic fast path (`DefEq.refl`, `Rel.lean:362`). -/
549 | refl {Γ : List Expr} {a : Expr} : DefEq env Γ a a
550 /-- Symmetry (`DefEq.symm`, `Rel.lean:365`). Not a checker move: the
551 constructor from which every right-hand variant of a one-sided rule
552 is derived. -/
553 | symm {Γ : List Expr} {a b : Expr} : DefEq env Γ a b → DefEq env Γ b a
554 /-- **Reduce the left side, then continue** (`DefEq.redL`,
555 `Rel.lean:370`): the recursive structure of `isDefEq` — head
556 normalisation of either side (with `symm`) and every lazy-δ
557 continuation. -/
558 | redL {Γ : List Expr} {a a' b : Expr} :
559 Red env Γ a a' → DefEq env Γ a' b → DefEq env Γ a b
560 /-- Two sorts, by the level oracle (`DefEq.sort`, `Rel.lean:373`). -/
561 | sort {Γ : List Expr} {u v : Level} :
562 LevelOracle.eq u v = true → DefEq env Γ (sort u) (sort v)
563 /-- Two constants of the same name at oracle-equal levels
564 (`DefEq.const`, `Rel.lean:384`). -/
565 | const {Γ : List Expr} {c : Name} {ls ls' : List Level} :
566 Level.eqList ls ls' = true → DefEq env Γ (const c ls) (const c ls')
is reflexive and symmetric. The checker never takes a symmetry step; the rule is there so that each one-sided rule below (red-l, 𝜂) need be written once, and its mirror image follows. The test interleaves with reduction in one way: reduce the left side, then continue. Sorts are compared through the level oracleConLeche/Rules/Rel.lean:L362-L364362 /-- Two sorts (`Core.lean:1581`). -/
363 | sort {d : Nat} {u v : Level} :
364 Level.isEquiv u v = some true → DefEq env d (.sort u) (.sort v)
.

Γ⊢𝑎≡𝑎reflΓ⊢𝑎≡𝑏Γ⊢𝑏≡𝑎symΓ⊢𝑎⇝𝑎′Γ⊢𝑎′≡𝑏Γ⊢𝑎≡𝑏red-l𝑢≐𝑣Γ⊢𝖲𝗈𝗋𝗍𝑢≡𝖲𝗈𝗋𝗍𝑣sort

The congruences descend into the two binders and into applications. Domains are compared first, then the bodies, under the right-hand domain. For Π-typeswhitepaper/Fragment/Rules.lean:L567-L575567 /-- `∀`-congruence (`DefEq.forallE`, `Rel.lean:399`): domains, then
568 bodies under the RIGHT domain, and nothing else. A
569 `∀`'s value is a function of its domain's and its fibres' values
570 (`SetLib.piV`: the propositional function space exactly when every fibre is
571 a truth value), and both are types, never the point, so the
572 premises' claims apply everywhere (`Sound.lean`, `DefEq.pi_sound`). -/
573 | pi {Γ : List Expr} {A₁ B₁ A₂ B₂ : Expr} :
574 DefEq env Γ A₁ A₂ → DefEq env (A₂ :: Γ) B₁ B₂ →
575 DefEq env Γ (pi A₁ B₁) (pi A₂ B₂)
that is all.

Γ⊢𝐴1≡𝐴2Γ,𝑥:𝐴2⊢𝐵1≡𝐵2Γ⊢∀𝑥:𝐴1.𝐵1≡∀𝑥:𝐴2.𝐵2piΓ⊢𝑓1≡𝑓2Γ⊢𝑎1≡𝑎2Γ⊢𝑓1𝑎1≡𝑓2𝑎2app

Two lambdas are compared as two lambda telescopes, by an auxiliary relation Γ⊢𝑎≡𝜆𝑏. The checker descends level by levelwhitepaper/Fragment/Rules.lean:L701-L714701inductive DefEqLams (env : Env) : List Expr → Expr → Expr → Prop where
702 /-- Syntactically equal sides (the checker's `a == b` fast path). -/
703 | refl {Γ : List Expr} {a : Expr} : DefEqLams env Γ a a
704 /-- The innermost level: `DefEq.lam`'s premises — domains, bodies,
705 and the bodies' inferred types. -/
706 | inner {Γ : List Expr} {A₁ b₁ A₂ b₂ t₁ t₂ : Expr} :
707 DefEq env Γ A₁ A₂ → DefEq env (A₂ :: Γ) b₁ b₂ →
708 Infer env (A₂ :: Γ) b₁ t₁ → Infer env (A₂ :: Γ) b₂ t₂ → DefEq env (A₂ :: Γ) t₁ t₂ →
709 DefEqLams env Γ (lam A₁ b₁) (lam A₂ b₂)
710 /-- An outer level: the domains, and the bodies by this relation —
711 no inference, no type comparison. -/
712 | outer {Γ : List Expr} {A₁ b₁ A₂ b₂ : Expr} :
713 DefEq env Γ A₁ A₂ → DefEqLams env (A₂ :: Γ) b₁ b₂ →
714 DefEqLams env Γ (lam A₁ b₁) (lam A₂ b₂)
while both bodies are lambdas, comparing the domains at each level (lam-outer). At the innermost level, where the descent stops, it also infers the types of the two bodieswhitepaper/Fragment/Rules.lean:L704-L709704 /-- The innermost level: `DefEq.lam`'s premises — domains, bodies,
705 and the bodies' inferred types. -/
706 | inner {Γ : List Expr} {A₁ b₁ A₂ b₂ t₁ t₂ : Expr} :
707 DefEq env Γ A₁ A₂ → DefEq env (A₂ :: Γ) b₁ b₂ →
708 Infer env (A₂ :: Γ) b₁ t₁ → Infer env (A₂ :: Γ) b₂ t₂ → DefEq env (A₂ :: Γ) t₁ t₂ →
709 DefEqLams env Γ (lam A₁ b₁) (lam A₂ b₂)
under the binder and compares them (lam). That comparison is a check the official kernel does not make. Such checks are typeset in one colour, like this, throughout the paper; a reader who ignores the coloured premises sees the official kernel’s rule. Section 2.8 explains why they are there, and why the outer levels need none.

Γ⊢𝐴1≡𝐴2Γ,𝑥:𝐴2⊢𝑏1≡𝑏2Γ,𝑥:𝐴2⊢𝑏1⇒𝑡1Γ,𝑥:𝐴2⊢𝑏2⇒𝑡2Γ,𝑥:𝐴2⊢𝑡1≡𝑡2Γ⊢𝜆𝑥:𝐴1.𝑏1≡𝜆𝜆𝑥:𝐴2.𝑏2lam
Γ⊢𝐴1≡𝐴2Γ,𝑥:𝐴2⊢𝑏1≡𝜆𝑏2Γ⊢𝜆𝑥:𝐴1.𝑏1≡𝜆𝜆𝑥:𝐴2.𝑏2lam-outerΓ⊢𝑎≡𝜆𝑏Γ⊢𝑎≡𝑏lams

(Two syntactically equal terms are also related by ≡𝜆.) A lambda against a term 𝑏 that is not a lambda is tried by 𝜂whitepaper/Fragment/Rules.lean:L640-L653640 /-- **η** (`DefEq.eta`, `Rel.lean:430`): a lambda against a term `b`
641 whose inferred type reduces to a `∀` with a definitionally equal
642 domain, when the lambda's body is `b` applied to the variable — and,
643 **typed** as lambda congruence is, the lambda's body's inferred
644 type is definitionally equal to the `∀`'s body, so that the lambda's body
645 and `b` applied lie in one type. Sound because a member of a
646 function space is the abstraction of its applications
647 (`SetLib.lamV_eta`). -/
648 | eta {Γ : List Expr} {A₁ b₁ b tb A₂ B t₁ : Expr} :
649 Infer env Γ b tb → Red env Γ tb (pi A₂ B) →
650 DefEq env Γ A₂ A₁ →
651 DefEq env (A₁ :: Γ) b₁ (app (b.liftN 1) (bvar 0)) →
652 Infer env (A₁ :: Γ) b₁ t₁ → DefEq env (A₁ :: Γ) t₁ B →
653 DefEq env Γ (lam A₁ b₁) b
. The type of 𝑏 is inferred and reduced to a Π-type, its domain is compared with the lambda’s, and the body is compared with 𝑏 applied to the bound variable. As at the innermost level of lambda congruence, the type of the lambda’s body is inferred and compared with the Π-type’s body. Two terms are equal by proof irrelevancewhitepaper/Fragment/Rules.lean:L654-L663654 /-- **Proof irrelevance** (`DefEq.proofIrrel`, `Rel.lean:452`): both
655 sides' inferred types have sort `Prop`. **The two types are never
656 compared**: the model justifies that, because every proof denotes the
657 one point. -/
658 | proofIrrel {Γ : List Expr} {a ta tta b tb ttb : Expr} {u v : Level} :
659 Infer env Γ a ta → Infer env Γ ta tta → Red env Γ tta (sort u) →
660 LevelOracle.eq u .zero = true →
661 Infer env Γ b tb → Infer env Γ tb ttb → Red env Γ ttb (sort v) →
662 LevelOracle.eq v .zero = true →
663 DefEq env Γ a b
when both are proofs: each one’s type has type 𝖲𝗈𝗋𝗍𝑢 with 𝑢 oracle-equal to 0.

Γ⊢𝑏⇒𝑇⇝∀𝑥:𝐴2.𝐵Γ⊢𝐴2≡𝐴1Γ,𝑥:𝐴1⊢𝑏1≡𝑏𝑥Γ,𝑥:𝐴1⊢𝑏1⇒𝑡1Γ,𝑥:𝐴1⊢𝑡1≡𝐵Γ⊢𝜆𝑥:𝐴1.𝑏1≡𝑏fun-eta
Γ⊢𝑎⇒𝑇𝑎⇒𝑆𝑎⇝𝖲𝗈𝗋𝗍𝑢𝑢≐0Γ⊢𝑏⇒𝑇𝑏⇒𝑆𝑏⇝𝖲𝗈𝗋𝗍𝑣𝑣≐0Γ⊢𝑎≡𝑏proof-irrel

Proof irrelevance. The rule compares the sorts of the two types, and never the two types. The official kernel also compares 𝑇𝑎 with 𝑇𝑏, so that 𝑎 and 𝑏 are proofs of the same proposition. This checker does not, and so accepts strictly more than the official kernel at this one site. The model justifies it (Section 2.5): every proof denotes the point, so two proofs of two propositions denote the same set.

The list has no transitivity rulewhitepaper/Fragment/Rules.lean:L529-L546529/-- **Definitional equality**: the verdict `true` of the checker's
530`isDefEq`.
531
532**There is no `trans` rule, deliberately** (`Rel.lean:334-357`).
533The relation is the checker's verdict on two terms that are
534well-formed *together*, a fact no rule states because well-formedness
535is semantic (`WellDenoted`) and may not enter this inductive. Every
536rule respects one discipline instead: **the subject of each `DefEq`
537premise is a subterm of the conclusion or is produced by a `Red` or
538`Infer` premise** (a reduct, an inferred type), so the soundness proof
539always has the premise's terms — and their invariant — in hand. A
540`trans` rule is the unique rule that would break it: its middle term
541comes from nowhere, so nothing supplies its invariant, and the
542induction has nothing to apply the hypothesis to. Nor does the
543checker chain through an arbitrary middle term: every comparison it
544makes is one of the rules below, and its one way to chain is
545"reduce, then continue": `redL`.
546-/
, and none can be addedConLeche/Rules/Rel.lean:L324-L347324/-- **Definitional equality**: the verdict `true` of `isDefEq`.
325
326**There is no `trans` rule, deliberately, and none can be added**
327(task #309, the experiment recorded in DESIGN.md). The relation is
328not an equivalence on terms: it is the checker's verdict, and the
329checker only ever compares terms that are well-formed *together* — a
330fact the rules never state, because well-formedness (scoping, the
331readability of the terms, the grading of the reading) is semantic
332and may not enter this inductive. Every rule respects one syntactic
333discipline instead: **the subject of each `DefEq` premise is either a
334subterm of the conclusion or is produced by an existence-form `Red` /
335`Infer` premise** (a reduct, an inferred type), so the soundness proof
336(`ConLeche/Model/Rules/Sound.lean`) always has the premise's terms in
337hand. `trans` is the unique rule that would break it: its middle
338term comes from nowhere, and with it two rules that are each sound
339alone meet — `fvar` compares free variables by index only (their
340types are not compared, as the checker does not), while
341`proofFast` *reads* a head's stored data to decide "definitely a
342proof" — and derive `DefEq env d (.fvar i ty) (.fvar i' ty')` for
343every `i`, `i'`, which no model satisfies. The recursive-structure rules
344(`redL`, `natSucc`, `eta`, `structUnit`) are therefore not a
345proof-engineering convenience but what keeps the relation sound; the
346one chaining that is sound, "reduce, then continue", is `redL`, and
347its right-hand and δ variants are derived in `Derived.lean`. -/
; Section 2.7 explains why. Instead of chaining equalities, the checker chains reductions: it reduces a side, then continues (red-l).

In con-leche In con-leche a transitivity rule would also combine two rules that are each sound alone into an unsound one. Free variables are compared by indexConLeche/Rules/Rel.lean:L365-L371365 /-- Two free variables of the same index (`Kernel/Core.lean`). The
366 carried types are NOT compared, as the checker does not compare them:
367 at a well-formed call `CtxOk` pins every opened variable's type, so
368 the reading ignores them. This is one half of why the relation has
369 no `trans` (see the inductive's docstring). -/
370 | fvar {d i : Nat} {ty₁ ty₂ : Expr} :
371 DefEq env d (.fvar i ty₁) (.fvar i ty₂)
, not by the types they carry, and a fast pathConLeche/Rules/Rel.lean:L429-L435429 /-- **The `isProofFast` yes-arm** (`propIrrel`, `Kernel/Core.lean`):
430 both heads' stored data say "a proposition at every valuation"
431 (`prf_of_isProofFast`). -/
432 | proofFast {d : Nat} {a b : Expr} :
433 isProofFast env.find? env.findTable? a = true →
434 isProofFast env.find? env.findTable? b = true →
435 DefEq env d a b
equates two terms whose heads’ declared types say they are proofs. Chained, the two would equate any two variables: give each the type of a proposition, then compare the two proofs.

2.3.3. Inference

A variable’s type is read off the contextwhitepaper/Fragment/Rules.lean:L740-L748740inductive Infer (env : Env) : List Expr → Expr → Expr → Prop where
741 /-- A bound variable's type is its context entry, lifted over the
742 binders in between (`Infer.fvar`, `Rel.lean:555`; the real checker
743 reads the type off the free variable). -/
744 | bvar {Γ : List Expr} {i : Nat} {A : Expr} :
745 Γ[i]? = some A → Infer env Γ (bvar i) (A.liftN (i + 1))
746 /-- `Sort u : Sort (u + 1)` (`Infer.sort`, `Rel.lean:551`). -/
747 | sort {Γ : List Expr} {u : Level} :
748 Infer env Γ (sort u) (sort (.succ u))
, and a sort has the next sortConLeche/Rules/Rel.lean:L589-L605589inductive Infer (env : Env) : Grade → Nat → Expr → Expr → Prop where
590 /-- `Core.lean:1114` / `:1294`. -/
591 | sort {g : Grade} {d : Nat} {u : Level} :
592 Infer env g d (.sort u) (.sort (.succ u))
593 /-- `Kernel/Core.lean` / `:1295-1297`: an opened variable's stored
594 type, at the leaf scope check. -/
595 | fvar {g : Grade} {d idx : Nat} {ty : Expr} :
596 idx < d → Infer env g d (.fvar idx ty) ty
597 /-- `Kernel/Core.lean` / `:1298-1309`: a stored constant at the right
598 level arity. -/
599 | const {g : Grade} {d : Nat} {n : Name} {us : List Level}
600 {ci : ConstantInfo} :
601 env.find? n = some ci →
602 us.length = ci.toConstantVal.levelParams.length →
603 Infer env g d (.const n us)
604 (ci.toConstantVal.type.instantiateLevelParams
605 ci.toConstantVal.levelParams us)
. The rules of this subsection are the checker’s full inference. The checker also has a cheaper mode, infer_only, which skips some of their checks; Section 2.9 presents it.

(𝑥:𝐴)∈ΓΓ⊢𝑥⇒𝐴varΓ⊢𝖲𝗈𝗋𝗍𝑢⇒𝖲𝗈𝗋𝗍(𝑢+1)sort

The two binder ruleswhitepaper/Fragment/Rules.lean:L754-L771754 /-- **`∀`-formation** (`Infer.forallE`, `Rel.lean:576`): the domain's
755 type reduces to a sort `u`, the body's type (under the domain)
756 reduces to a sort `v`, the result is `Sort (imax u v)`. Nothing is
757 checked beyond Lean's own rule. -/
758 | pi {Γ : List Expr} {A B s t : Expr} {u v : Level} :
759 Infer env Γ A s → Red env Γ s (sort u) →
760 Infer env (A :: Γ) B t → Red env (A :: Γ) t (sort v) →
761 Infer env Γ (pi A B) (sort (.imax u v))
762 /-- **Lambda** (`Infer.lam`, `Rel.lean:589`): the domain's type reduces to
763 a sort, the body is inferred under the domain, and the result is the
764 `∀` of the body's type — Lean's own rule. The body's type's sort is
765 not computed: an inferred type is a type (`InferSem`), which is all
766 the `∀`'s invariant asks of it, and the body's value is read by the
767 interpretation, not by its sort. -/
768 | lam {Γ : List Expr} {A b s bt : Expr} {u : Level} :
769 Infer env Γ A s → Red env Γ s (sort u) →
770 Infer env (A :: Γ) b bt →
771 Infer env Γ (lam A b) (pi A bt)
are Lean’s own. For a Π-type, the domain’s type must reduce to a sort 𝖲𝗈𝗋𝗍𝑢 and the body’s type, under the domain, to a sort 𝖲𝗈𝗋𝗍𝑣; the result is 𝖲𝗈𝗋𝗍(imax(𝑢,𝑣)). For a lambda, the domain’s type must reduce to a sort, and the result is the Π-type over the body’s inferred type; the sort of that type is not computed.

Γ⊢𝐴⇒𝑆⇝𝖲𝗈𝗋𝗍𝑢Γ,𝑥:𝐴⊢𝐵⇒𝑇⇝𝖲𝗈𝗋𝗍𝑣Γ⊢∀𝑥:𝐴.𝐵⇒𝖲𝗈𝗋𝗍(imax(𝑢,𝑣))piΓ⊢𝐴⇒𝑆⇝𝖲𝗈𝗋𝗍𝑢Γ,𝑥:𝐴⊢𝑏⇒𝐵Γ⊢𝜆𝑥:𝐴.𝑏⇒∀𝑥:𝐴.𝐵lam

An application infers the head’s typewhitepaper/Fragment/Rules.lean:L772-L781772 /-- **Application** (`Infer.app`, `Rel.lean:617`): the head's type
773 reduces to a `∀`, and the argument's inferred type is definitionally
774 equal to its domain. This is where a syntactic proof would need
775 Π-injectivity and the semantic one does not: the `∀` the head's type
776 reduces to *is* a function space, and membership in it is what the
777 model needs (`Sound.lean`, `infer_sound`'s `app` case). -/
778 | app {Γ : List Expr} {f a tf A B ta : Expr} :
779 Infer env Γ f tf → Red env Γ tf (pi A B) →
780 Infer env Γ a ta → DefEq env Γ ta A →
781 Infer env Γ (app f a) (B.inst a)
, reduces it to a Π-type, infers the argument’s type and compares it with the domainConLeche/Rules/Rel.lean:L657-L661657 | app {g : Grade} {d : Nat} {f a tf ty body ta : Expr} :
658 Infer env g d f tf → Red env d tf (.forallE ty body) →
659 (g = .full → Infer env .full d a ta) →
660 (g = .full → DefEq env d ta ty) →
661 Infer env g d (.app f a) (body.instantiate1 a)
. A let-expressionwhitepaper/Fragment/Rules.lean:L782-L796782 /-- **`let`, by substitution** (official `infer_let`
783 with the body instantiated rather than opened at a let-variable, as
784 the checker does): the type's type reduces to a
785 sort, the value's inferred type is definitionally equal to the type,
786 and the result is the inferred type of the body with the value
787 substituted. The two checks on the value are Lean's (they reject
788 `let x : T := v; b` with `v : T` false even where the body ignores
789 `x`); the soundness proof does not use them (`Sound.lean`,
790 `Infer.letE_sound`), because `interp` reads no type and the body is
791 inferred at the value itself. -/
792 | letE {Γ : List Expr} {T v b s tv B : Expr} {u : Level} :
793 Infer env Γ T s → Red env Γ s (sort u) →
794 Infer env Γ v tv → DefEq env Γ tv T →
795 Infer env Γ (b.inst v) B →
796 Infer env Γ (letE T v b) B
checks that its type has a sort and that its value’s type agrees with it, as the official kernel does, and then infers the type of the body with the value substituted.

Γ⊢𝑓⇒𝑇⇝∀𝑥:𝐴.𝐵Γ⊢𝑎⇒𝑇𝑎Γ⊢𝑇𝑎≡𝐴Γ⊢𝑓𝑎⇒𝐵[𝑥≔𝑎]app
Γ⊢𝑇⇒𝑆⇝𝖲𝗈𝗋𝗍𝑢Γ⊢𝑣⇒𝑇𝑣Γ⊢𝑇𝑣≡𝑇Γ⊢𝑏[𝑥≔𝑣]⇒𝐵Γ⊢(𝗅𝖾𝗍𝑥:𝑇≔𝑣;𝑏)⇒𝐵let

Reducing to a Π-type. The application rule reduces the inferred type of 𝑓 until a Π-type is syntactically there. It does not take a type of 𝑓 that is a Π-type up to definitional equality and argue that its domain is the right one. That argument is where a syntactic soundness proof needs Π-injectivity, the property that for terms 𝐴,𝐴′,𝐵,𝐵′

Γ⊢∀𝑥:𝐴.𝐵≡∀𝑥:𝐴′.𝐵′impliesΓ⊢𝐴≡𝐴′.

Our proof never needs it, and the model does not validate it: ∀𝑥:𝐴.𝖳𝗋𝗎𝖾 and ∀𝑥:𝐴′.𝖳𝗋𝗎𝖾 denote the same truth value whatever 𝐴 and 𝐴′ are. Our proof argues instead that the head denotes a member of what the Π-type denotes, because reduction preserves denotations; that the argument denotes a member of the domain, by the comparison premise; and that applying a member of a function space to a member of its domain lands in the fibre. The second half of this section carries this out.

The let-expression. The two checks on the value are what the official kernel runs, and they decide verdicts: they reject a let-expression whose value does not have the stated type even where the body ignores it. The soundness proof does not use them (Section 2.7): the interpretation reads no type, and the body is inferred with the value itself in place of the variable.

In con-leche The checker substitutes the value in the same way, both when it reducesConLeche/Kernel/Core.lean:L1074-L10761074 | .letE _ v b =>
1075 -- Task #342 S0: ζ
1076 r.whnfCore cheap depth (b.instantiate1 v)
and when it infersConLeche/Kernel/Core.lean:L1318-L13231318 | .letE ty v b => do
1319 -- Task #342 S0: official `infer_let`
1320 let _ ← ensureSort r env depth (← r.infer depth ty)
1321 unless ← r.defeq depth (← r.infer depth v) ty do
1322 throw (.invalid "let value type mismatch")
1323 r.infer depth (b.instantiate1 v)
; it keeps no variables bound to values. The official kernel opens the body at such a variable instead, which avoids copying the value when the body uses it many times; for con-leche that case is a known performance gap, not a soundness question.

2.4. The set theory we assume

The other side of the argument is a set theory. We do not construct one. The reader is given an axiomatised theory, a type of sets with the operations and laws listed below, and is promised that nothing beyond these laws is used. The theory is stated in Lean’s own logic, so it is higher-order: separation takes any predicate of that logic, and graphs and function spaces are formed from any function of it. It is deliberately not minimal: graphs, dependent function spaces and the universe chain, which a minimal axiom system would construct, are assumed outright with their laws, because how they are built does not matter to the argument. The promise is literal: in the Lean fragment the structure is a class, SetLibwhitepaper/Fragment/Lib.lean:L56-L12556/-- **The set theory we assume.** A type of sets `V` with the
57operators and laws the fragment's proof uses. The theory is stated in
58Lean's logic, so separation is available for every predicate of that
59logic, and the function-space laws quantify over functions on the
60sets. -/
61class SetLib (V : Type u) where
62 /-- Membership. -/
63 Mem : V → V → Prop
64 /-- Extensionality. -/
65 ext : ∀ {x y : V}, (∀ z, Mem z x ↔ Mem z y) → x = y
66 /-- Separation: the members of `A` that satisfy `P`. -/
67 sep : V → (V → Prop) → V
68 /-- The members of a separation. -/
69 mem_sep : ∀ {A : V} {P : V → Prop} {z : V}, Mem z (sep A P) ↔ Mem z A ∧ P z
70 /-- A distinguished set, subject to the point's three laws below. It
71 is the one proof of every true proposition. -/
72 pt : V
73 /-- The one-element set `{pt}`. -/
74 one : V
75 /-- The members of `{pt}`. -/
76 mem_one : ∀ {z : V}, Mem z one ↔ z = pt
77 /-- The universe chain: `univ n` sizes `Sort n`, which denotes the
78 types among its members, `typeU n`. -/
79 univ : Nat → V
80 /-- `univ 0` is the set of subsets of `{pt}` — the truth values. -/
81 mem_univ_zero : ∀ {T : V}, Mem T (univ 0) ↔ ∀ z, Mem z T → z = pt
82 /-- Each universe is a member of the next. -/
83 univ_mem_succ : ∀ n : Nat, Mem (univ n) (univ (n + 1))
84 /-- Cumulativity. -/
85 univ_mono : ∀ {m n : Nat} {x : V}, m ≤ n → Mem x (univ m) → Mem x (univ n)
86 /-- The graph of a function on a domain. -/
87 graph : (V → V) → V → V
88 /-- The dependent function space: the graphs over `A` with values
89 in the fibres `B`. -/
90 piSet : V → (V → V) → V
91 /-- Application. On the point it is the point (a proof applied to
92 anything is a proof); on a graph it reads the graph. -/
93 app : V → V → V
94 /-- A proof applied is the proof. -/
95 app_pt : ∀ a : V, app pt a = pt
… 30 more lines
, and every theorem of the fragment is proved against that class.

In con-leche The real proof is parametric in a smaller interfaceConLeche/SetTheory/Core.lean:L95-L100 95/-- A model of set theory of exactly the strength the checker needs:
96membership, the six ZF⁻ axioms (extensionality, pairing, union, power
97set, regularity, Lean-level replacement), and an ω-chain of
98Grothendieck universes. Infinity is derivable; choice is inherited
99from the meta-logic (`Classical.choice`); see the module docstring. -/
100class SetTheory (V : Type u) where
, ZF without infinity plus a chain of Grothendieck universes (sets closed under all the set-forming operations), from which it derives the operators below.

The laws come in four groups.

Sets, membership, extensionality, separation. A type 𝑉 of sets with a membership relation 𝑥∈𝑦; extensionalitywhitepaper/Fragment/Lib.lean:L64-L6564 /-- Extensionality. -/
65 ext : ∀ {x y : V}, (∀ z, Mem z x ↔ Mem z y) → x = y
: two sets with the same members are equal; and separationwhitepaper/Fragment/Lib.lean:L66-L6966 /-- Separation: the members of `A` that satisfy `P`. -/
67 sep : V → (V → Prop) → V
68 /-- The members of a separation. -/
69 mem_sep : ∀ {A : V} {P : V → Prop} {z : V}, Mem z (sep A P) ↔ Mem z A ∧ P z
: for every set 𝐴 and every property 𝑃 of sets, a set {𝑥∈𝐴|𝑃(𝑥)} whose members are the members of 𝐴 that satisfy 𝑃. A property here is any predicate on sets expressible in Lean’s type theory, the logic the theory is stated in, not only a first-order formula.

The point and the truth values. A distinguished set 𝗉𝗍, the point, and its singleton {𝗉𝗍}whitepaper/Fragment/Lib.lean:L73-L7673 /-- The one-element set `{pt}`. -/
74 one : V
75 /-- The members of `{pt}`. -/
76 mem_one : ∀ {z : V}, Mem z one ↔ z = pt
. The point will be the one proof of every true proposition. For a proposition 𝑃 of the ambient logic we write tv(𝑃) for the separation {𝑥∈{𝗉𝗍}|𝑃} and call it the truth value of 𝑃whitepaper/Fragment/Lib.lean:L141-L143141/-- The truth value of a proposition: `{pt}` if it holds, `∅` if
142not. -/
143def truthVal (P : Prop) : V := sep one (fun _ => P)
. Its only possible member is the point, which it has exactly when 𝑃 holds, so tv(𝑃)={𝗉𝗍} when 𝑃 is true and tv(𝑃)=∅ when it is false. This is an abbreviation, not an axiom. The point itself obeys three lawswhitepaper/Fragment/Lib.lean:L119-L125119 /-- **The point's laws** (1): the point is not a truth value — it has
120 a member other than itself. -/
121 pt_not_mem_univ_zero : ¬ Mem pt (univ 0)
122 /-- (2): the point has at most one member. -/
123 pt_subsingleton : ∀ {x y : V}, Mem x pt → Mem y pt → x = y
124 /-- (3): no graph is a member of the point. -/
125 graph_not_mem_pt : ∀ {F : V → V} {A : V}, ¬ Mem (graph F A) pt
: it is not a truth value (it has a member other than itself), it has at most one member, and no graph (below) is a member of it.

In con-leche The point is the singletonConLeche/SetTheory/Derive/Pt.lean:L68-L6968/-- The proof point `pt = {ptTag}`. -/
69noncomputable def pt : V := sing ptTag
of the set {∅,{{∅}}}ConLeche/SetTheory/Derive/Pt.lean:L44-L4644/-- The proof-point tag `{∅, {{∅}}}` (see the module docstring for the
45selection principle). -/
46noncomputable def ptTag : V := upair empty (sing (sing empty))
, chosen so that no encoding of a value of a data type produces it; the three laws are theorems there.

The universes. A chain of setswhitepaper/Fragment/Lib.lean:L77-L8577 /-- The universe chain: `univ n` sizes `Sort n`, which denotes the
78 types among its members, `typeU n`. -/
79 univ : Nat → V
80 /-- `univ 0` is the set of subsets of `{pt}` — the truth values. -/
81 mem_univ_zero : ∀ {T : V}, Mem T (univ 0) ↔ ∀ z, Mem z T → z = pt
82 /-- Each universe is a member of the next. -/
83 univ_mem_succ : ∀ n : Nat, Mem (univ n) (univ (n + 1))
84 /-- Cumulativity. -/
85 univ_mono : ∀ {m n : Nat} {x : V}, m ≤ n → Mem x (univ m) → Mem x (univ n)
𝒰︀0,𝒰︀1,𝒰︀2,…, with 𝒰︀0 the set of truth values, the subsets of {𝗉𝗍}. Each 𝒰︀𝑛 is a member of 𝒰︀𝑛+1. The chain is cumulative (a member of 𝒰︀𝑚 is a member of every later 𝒰︀𝑛), and every universe is closed under separationwhitepaper/Fragment/Lib.lean:L117-L118117 /-- Closure of the universes under separation. -/
118 sep_mem_univ : ∀ {n : Nat} {A : V} {P : V → Prop}, Mem A (univ n) → Mem (sep A P) (univ n)
.

Graphs, function spaces, application. For a function 𝐹 from sets to sets (a function of the meta-theory, not a set) and a set 𝐴, a set graph(𝐹,𝐴); for a set 𝐴 and a family 𝐵 of sets indexed by sets, again a function of the meta-theory, a set Π(𝐴,𝐵), the dependent function space; and for two sets 𝑓 and 𝑎 a set 𝑓⋅𝑎, the applicationwhitepaper/Fragment/Lib.lean:L86-L9386 /-- The graph of a function on a domain. -/
87 graph : (V → V) → V → V
88 /-- The dependent function space: the graphs over `A` with values
89 in the fibres `B`. -/
90 piSet : V → (V → V) → V
91 /-- Application. On the point it is the point (a proof applied to
92 anything is a proof); on a graph it reads the graph. -/
93 app : V → V → V
. Their laws:

This is all this section needs. When inductive types arrive, Section 4 extends the theory.

Two of these laws are design choices. The first is that application of the point is the point. In the model a proof of a proposition is the point, and a proof of ∀𝑥:𝐴.𝑃 is again the point, not a function. The law makes application one operation that does the right thing on both kinds of value, so the interpretation of 𝑓𝑎 need not know which kind it is applying. The second is that a graph is never the point: a function and a proof are never the same set. Together with domain uniqueness this makes “the domain of 𝑓” a meaningful phrase for every value 𝑓 that may be applied: everything if 𝑓 is the point, 𝐴 if 𝑓 is the graph graph(𝐹,𝐴). This is what lets the reduction rule β fire with no premise at all.

One law is deliberately restricted: closure of a universe under function spaces is stated for 𝒰︀1,𝒰︀2,… and not for 𝒰︀0. A proposition ∀𝑥:𝐴.𝑃 has no function space in the model. It has a truth value, and a truth value is in 𝒰︀0 whatever 𝐴 is. This is the model’s impredicativitywhitepaper/Fragment/Lib.lean:L274-L277274/-- **Impredicativity**: a function space landing in `Prop` is a truth value,
275whatever its domain. -/
276theorem piR_true_mem_univ_zero {A : V} {B : V → V} :
277 piR true A B ∈ˢ (univ 0 : V) := truthVal_mem_univ_zero _
.

2.5. The interpretation

Every term denotes a set. The interpretation is total, defined on every term, well-typed or not, and term-directed: it is a structural recursion on the term, consulting no derivation and no type. It takes two parameters:

We write ⟦𝑒⟧𝜌 for the set the term 𝑒 denotes under 𝜌 (𝜑 stays implicit), and 𝜌,𝑥↦𝑣 for 𝜌 extended with the value 𝑣 for the variable 𝑥. The clauseswhitepaper/Fragment/Interp.lean:L138-L146138/-- **The interpretation**: total, term-directed, reading no type. -/
139noncomputable def interp (M : Name → List Nat → V) (φ : Name → Nat) : (Nat → V) → Expr → V
140 | ρ, .bvar i => ρ i
141 | _, .sort u => typeU (u.eval φ)
142 | _, .const c ls => M c (ls.map (Level.eval φ))
143 | ρ, .app f a => app (interp M φ ρ f) (interp M φ ρ a)
144 | ρ, .lam A b => lamV (interp M φ ρ A) fun x => interp M φ (cons x ρ) b
145 | ρ, .pi A B => piV (interp M φ ρ A) fun x => interp M φ (cons x ρ) B
146 | ρ, .letE _ v b => interp M φ (cons (interp M φ ρ v) ρ) b
:

⟦𝑥⟧𝜌=𝜌(𝑥)⟦𝖲𝗈𝗋𝗍𝑢⟧𝜌=𝒯︀𝜑(𝑢)⟦𝑓𝑎⟧𝜌=⟦𝑓⟧𝜌⋅⟦𝑎⟧𝜌⟦𝜆𝑥:𝐴.𝑏⟧𝜌=Λ(⟦𝐴⟧𝜌,𝑣↦⟦𝑏⟧𝜌,𝑥↦𝑣)⟦∀𝑥:𝐴.𝐵⟧𝜌=Π𝗏(⟦𝐴⟧𝜌,𝑣↦⟦𝐵⟧𝜌,𝑥↦𝑣)⟦𝗅𝖾𝗍𝑥:𝑇≔𝑣;𝑏⟧𝜌=⟦𝑏⟧𝜌,𝑥↦⟦𝑣⟧𝜌

with 𝜑(𝑢) the value of the level 𝑢 at the valuation, and 𝒯︀𝑛 the sets a sort denotes, below. The two binder clauses choose between two readings by the valueswhitepaper/Fragment/Lib.lean:L515-L527515open Classical in
516/-- Is every fibre over the domain a truth value? -/
517noncomputable def propB (A : V) (B : V → V) : Bool := decide (∀ x, x ∈ˢ A → B x ∈ˢ univ 0)
518
519open Classical in
520/-- Is every body value over the domain the point? -/
521noncomputable def ptB (A : V) (F : V → V) : Bool := decide (∀ x, x ∈ˢ A → F x = pt)
522
523/-- **The function space, regime read off the fibres.** -/
524noncomputable def piV (A : V) (B : V → V) : V := piR (propB A B) A B
525
526/-- **The abstraction, regime read off the body values.** -/
527noncomputable def lamV (A : V) (F : V → V) : V := lamR (ptB A F) A F
:

Π𝗏(𝐴,𝐵)={Π0(𝐴,𝐵)if𝐵(𝑣)is a truth value for every𝑣∈𝐴,Π(𝐴,𝐵)otherwise;Λ(𝐴,𝐹)={𝗉𝗍if𝐹(𝑣)=𝗉𝗍for every𝑣∈𝐴,graph(𝐹,𝐴)otherwise.

Here Π0(𝐴,𝐵) is the propositional function spacewhitepaper/Fragment/Lib.lean:L190-L196190/-- **The propositional function space** `Π₀(A, B)`: the truth value "every
191fibre is `{pt}`". When the fibres are truth values it is their
192intersection `⋂ x ∈ A, B x` (the empty intersection being `{pt}`):
193`{pt}` exactly when every fibre is, `∅` otherwise — the function space of
194subsets of a singleton. Reducible, so proofs that unfold `piR true`
195keep working. -/
196abbrev piProp (A : V) (B : V → V) : V := truthVal (∀ x, x ∈ˢ A → B x = one)
, tv(∀𝑣∈𝐴.𝐵(𝑣)={𝗉𝗍}). When the fibres 𝐵(𝑣), for 𝑣∈𝐴, are truth values it is their intersection ⋂𝑣∈𝐴𝐵(𝑣) (the empty intersection being {𝗉𝗍}), which is {𝗉𝗍} exactly when every fibre is and ∅ otherwise: the function space of subsets of a singleton. A let reads its body at the value’s value, and its type is not read, as no type is read anywhere.

So a binder has two interpretations, chosen by the values of its body over the domain. The fibres of ∀𝑥:𝐴.𝐵 are the sets ⟦𝐵⟧𝜌,𝑥↦𝑣 for 𝑣∈⟦𝐴⟧𝜌. If every fibre is a truth value, the Π-type is a proposition, true when every fibre is {𝗉𝗍}; otherwise it is a function space, a set of graphs. Likewise a lambda whose body is the point at every member of the domain is itself the point, a proof; otherwise it is a graph. The choice depends on these values and on nothing else. The interpretation does not know the sort of 𝐵, and does not compute it.

The empty domain. For a well-typed body over a non-empty domain, the values choose the interpretation the sort of the body would choose. Over an empty domain there are no values, and both clauses take their first case: a function space over an empty domain is {𝗉𝗍}whitepaper/Fragment/Lib.lean:L676-L682676/-- Over an empty domain the function space is `{pt}`. -/
677theorem piV_of_empty {A : V} {B : V → V} (h : ∀ x, ¬ x ∈ˢ A) : piV A B = one := by
678 unfold piV
679 rw [propB_eq_true.mpr fun x hx => absurd hx (h x), piR_true]
680 exact ext fun z => by
681 rw [mem_truthVal, mem_one]
682 exact ⟨fun h' => h'.1, fun h' => ⟨h', fun x hx => absurd hx (h x)⟩⟩
, and an abstraction over one is the pointwhitepaper/Fragment/Lib.lean:L684-L686684/-- Over an empty domain the abstraction is the point. -/
685theorem lamV_of_empty {A : V} {F : V → V} (h : ∀ x, ¬ x ∈ˢ A) : lamV A F = pt :=
686 lamV_eq_pt fun x hx => absurd hx (h x)
, whatever the sort of the body. So False → Nat, a type of sort Type, denotes {𝗉𝗍}, and its inhabitant fun h => h.elim denotes the point. A function space over an inhabited domain can do the same: Nat → False → Nat has {𝗉𝗍} as every fibre and is itself {𝗉𝗍}whitepaper/Fragment/Probe.lean:L52-L5452/-- `Nat → False → Nat`: every fibre is `{pt}`, so the function space is the
53truth value `{pt}`, although its sort is `Type`. -/
54theorem piV_const_one {A : V} : piV A (fun _ => one) = one := by
, and fun n h => h.elim is the point. No other reading over the empty domain does better. Whether the codomain is a proposition there is a fact about the syntax, not about any value, and reading an empty Π-type as a function space instead would make the proposition False → False denote a one-element set of graphs, which no truth value is.

What a sort denotes. A set 𝑋∈𝑉 is a typewhitepaper/Fragment/Lib.lean:L297-L301297/-- A **strict** set: not the point, and the point is not a member. -/
298def Strict (X : V) : Prop := X ≠ pt ∧ ¬ pt ∈ˢ X
299
300/-- A **type**: a truth value, or a strict set. -/
301def IsTy (X : V) : Prop := X ∈ˢ univ 0 ∨ Strict X
when it is a truth value or strict, that is, neither the point nor a set holding the point:

𝑋a type⟺𝑋∈𝒰︀0∨(𝑋≠𝗉𝗍∧𝗉𝗍∉𝑋).

The members of a type are all the point or none of itwhitepaper/Fragment/Lib.lean:L358-L363358/-- The members of a type are all the point or none of them. -/
359theorem IsTy.eq_of_ne_pt {T x y : V} (hT : IsTy T) (hx : x ∈ˢ T) (hy : y ∈ˢ T)
360 (h : x ≠ pt → y ≠ pt → x = y) : x = y := by
361 rcases hT with hT | hT
362 · rw [eq_pt_of_mem_univ_zero hT hx, eq_pt_of_mem_univ_zero hT hy]
363 · exact h (ne_pt_of_mem_strict hT hx) (ne_pt_of_mem_strict hT hy)
, and this is the one fact about types the soundness proof reads. A sort denotes the types of its universewhitepaper/Fragment/Lib.lean:L303-L305303/-- **What `Sort n` denotes**: the truth values at `0`, the members of
304`univ n` that are types above. -/
305def typeU (n : Nat) : V := if n = 0 then univ 0 else sep (univ n) IsTy
: 𝒯︀0=𝒰︀0, the truth values, and 𝒯︀𝑛 for 𝑛≥1 the members of 𝒰︀𝑛 that are types. These are cumulative, and 𝒯︀𝑛+1 holds the truth values too. It must, since a function space over an empty domain is {𝗉𝗍}, which is no strict setwhitepaper/Fragment/ValueReading.lean:L58-L6358/-- A function space over an empty domain is `{pt}`, which is no strict set;
59so a positive sort, which holds `False → Nat`, holds a set that is not
60strict. -/
61theorem piV_empty_not_strict {A : V} {B : V → V} (h : ∀ x, ¬ x ∈ˢ A) :
62 ¬ Strict (piV A B) := by
63 rw [piV_of_empty h]; exact fun hs => hs.2 (mem_one.mpr rfl)
. The point is no type, so no sort holds it.

In con-leche con-leche’s sorts denote the same sets: a sort’s universeConLeche/SetTheory/Derive/Univ.lean:L34-L3534/-- **What `Sort n` means**: the universe of types `tyU n`. -/
35noncomputable def univ : Nat → V := tyU
is the universe of typesConLeche/SetTheory/Derive/TypeU.lean:L195-L197195open Classical in
196/-- **The universe of types at level `n`**: the truth values at `0`,
197above the members of the axiomatic level `tg n` that are types. -/
, read off the same notions of a strict setConLeche/SetTheory/Derive/TypeU.lean:L57-L5857/-- A **strict** set: not the point, and the point is not a member. -/
58def Strict (X : V) : Prop := X ≠ pt ∧ ¬ pt ∈ˢ X
and a typeConLeche/SetTheory/Derive/TypeU.lean:L60-L6160/-- A **type**: a truth value, or a strict set. -/
61def IsTy (X : V) : Prop := X ∈ˢ univZero ∨ Strict X
.

This is the whole of the interpretation. Nothing had to be well-typed, no typing judgement was consulted, and there is no partiality to discharge. The next subsection says what replaces typing. Three lemmas about the interpretation are needed later, each proved by induction on the term. Substituting a term for a variablewhitepaper/Fragment/Interp.lean:L242-L246242/-- **The β-substitution lemma**: substituting for the innermost
243variable is consing its value. -/
244theorem interp_inst0 (e a : Expr) (ρ : Nat → V) :
245 interp M φ ρ (e.inst a) = interp M φ (cons (interp M φ ρ a) ρ) e := by
246 rw [interp_inst, shiftE_zero_zero, instE_zero]
is extending the environment with the term’s value, ⟦𝑏[𝑥≔𝑎]⟧𝜌=⟦𝑏⟧𝜌,𝑥↦⟦𝑎⟧𝜌; hence a let denotes what its 𝜁-reduct denoteswhitepaper/Fragment/Interp.lean:L248-L253248/-- **ζ is an identity**: a `let` denotes what its body with the value
249substituted denotes — at every environment, the point included (as β
250is at a lambda that is a graph; ζ has no lambda that could be the point). -/
251theorem interp_zeta (T v b : Expr) (ρ : Nat → V) :
252 interp M φ ρ (.letE T v b) = interp M φ ρ (b.inst v) := by
253 rw [interp_letE, interp_inst0]
, at every environment; and a term does not see a variable it does not mentionwhitepaper/Fragment/Hygiene.lean:L464-L467464/-- **Variables.** The interpretation of a term closed below `k` reads
465the environment below `k` only. -/
466theorem interp_closedAt {k : Nat} {e : Expr} (he : e.closedAt k = true) {ρ ρ' : Nat → V}
467 (h : ∀ i, i < k → ρ i = ρ' i) : interp M φ ρ e = interp M φ ρ' e := by
.

2.6. The semantic invariant

There is no typing judgement in the proof. In its place is a predicate on terms, the semantic invariant: a term is well-denotedwhitepaper/Fragment/WellDenoted.lean:L58-L7558/-- **The semantic invariant** (see the module docstring): a binder's
59domain is a type; a Π's codomain fibres are types; an application's
60argument is in the function's domain (`AppliesTo`). -/
61def WellDenoted : (Nat → V) → Expr → Prop
62 | _, .bvar _ => True
63 | _, .sort _ => True
64 | _, .const _ _ => True
65 | ρ, .app f a =>
66 WellDenoted ρ f ∧ WellDenoted ρ a ∧ AppliesTo (interp M φ ρ f) (interp M φ ρ a)
67 | ρ, .lam A b =>
68 WellDenoted ρ A ∧ IsTy (interp M φ ρ A) ∧
69 (∀ x, x ∈ˢ interp M φ ρ A → WellDenoted (cons x ρ) b)
70 | ρ, .pi A B =>
71 WellDenoted ρ A ∧ IsTy (interp M φ ρ A) ∧
72 (∀ x, x ∈ˢ interp M φ ρ A → WellDenoted (cons x ρ) B) ∧
73 (∀ x, x ∈ˢ interp M φ ρ A → IsTy (interp M φ (cons x ρ) B))
74 | ρ, .letE _ v b =>
75 WellDenoted ρ v ∧ WellDenoted (cons (interp M φ ρ v) ρ) b
when its applications and binders respect domains. It is stated under a valuation 𝜑 and an environment 𝜌, like the interpretation, by recursion on the term: it holds of a term when it holds of the subterms and one condition on the term’s own shape is met. We write 𝜌⊧𝑒 for “𝑒 is well-denoted under 𝜌” (𝜑 is fixed throughout). Variables and sorts are always well-denoted, and, with 𝐹 a function from sets to sets and 𝐴 a set in app-graph,

𝜌⊧𝑓𝜌⊧𝑎⟦𝑓⟧𝜌=𝗉𝗍𝜌⊧𝑓𝑎app-pt𝜌⊧𝑓𝜌⊧𝑎⟦𝑓⟧𝜌=graph(𝐹,𝐴)𝐴a type⟦𝑎⟧𝜌∈𝐴𝜌⊧𝑓𝑎app-graph
𝜌⊧𝐴⟦𝐴⟧𝜌a type∀𝑣∈⟦𝐴⟧𝜌.𝜌,𝑥↦𝑣⊧𝑏𝜌⊧𝜆𝑥:𝐴.𝑏lam𝜌⊧𝐴⟦𝐴⟧𝜌a type∀𝑣∈⟦𝐴⟧𝜌.𝜌,𝑥↦𝑣⊧𝐵∀𝑣∈⟦𝐴⟧𝜌.⟦𝐵⟧𝜌,𝑥↦𝑣a type𝜌⊧∀𝑥:𝐴.𝐵pi
𝜌⊧𝑣𝜌,𝑥↦⟦𝑣⟧𝜌⊧𝑏𝜌⊧𝗅𝖾𝗍𝑥:𝑇≔𝑣;𝑏let

In words: the point may be applied to anything, and a graph to the members of its domain, which is a type; a binder’s domain is a type; and a Π-type’s fibres are types. Nothing is asked of a lambda’s values beyond the body being well-denoted.

The two app rules mention no function space and no type of 𝑓 or 𝑎: they ask of the values only what application needs to be meaningful. A typed application meets them. If ⟦𝑓⟧𝜌 lies in Π𝗏(𝐴,𝐵), 𝐴 is a type and ⟦𝑎⟧𝜌∈𝐴, then ⟦𝑓⟧𝜌 is the point, or it is a member of the function space Π(𝐴,𝐵), by η the graph graph(𝑥↦⟦𝑓⟧𝜌⋅𝑥,𝐴), and app-graph applieswhitepaper/Fragment/Lib.lean:L529-L532529/-- **A typed application meets the application clause** (point, or η). -/
530theorem appliesTo_of_mem_piV {A f a : V} {B : V → V} (hf : f ∈ˢ piV A B)
531 (hA : IsTy A) (ha : a ∈ˢ A) : AppliesTo f a :=
532 appliesTo_of_mem_piR hf hA ha
. This is the step the inference rule for application takes (Section 2.7). That the domain is a type is not needed for application itself but for equality: two applications of one graph to arguments that are equal where neither is the point must be equal, and that needs the two arguments to be both the point or neither, which their common domain, a type, provides.

The semantic invariant records which sets are types; that is what lets the proof conclude that two values in one type are both the point or neither. Where a lambda is typed, its inference rule supplies a family of types holding the body’s values, and then the choice between the two readings agrees with membership: an abstraction is a member of the function spacewhitepaper/Fragment/Lib.lean:L603-L609603/-- **Introduction**: body values in fibres that are types abstract into
604the function space. Where every fibre is a truth value every body value is
605the point, and so is the abstraction; where one fibre is not, it is
606strict, its body value is not the point, and the abstraction is the
607graph. -/
608theorem lamV_mem {A : V} {F B : V → V} (hF : ∀ x, x ∈ˢ A → F x ∈ˢ B x)
609 (hB : ∀ x, x ∈ˢ A → IsTy (B x)) : lamV A F ∈ˢ piV A B := by
of a family of types holding its values. If every fibre is a truth value, every value is the point and so is the abstraction; if one fibre is not, it is strict, the body’s value there is not the point, and the abstraction is the graph.

The semantic invariant is transported by substitutionwhitepaper/Fragment/WellDenoted.lean:L182-L185182theorem WellDenoted_inst0 {e a : Expr} {ρ : Nat → V} (ha : WellDenoted M φ ρ a) :
183 WellDenoted M φ ρ (e.inst a) ↔ WellDenoted M φ (cons (interp M φ ρ a) ρ) e := by
184 have h := WellDenoted_inst M φ e a 0 ρ (by rwa [shiftE_zero_zero])
185 rwa [shiftE_zero_zero, instE_zero] at h
: 𝑏[𝑥≔𝑎] is well-denoted under 𝜌 exactly when 𝑏 is well-denoted under 𝜌,𝑥↦⟦𝑎⟧𝜌, provided 𝑎 itself is. The proof is by induction on the term, using the interpretation’s substitution lemma; no typing derivation is involved.

A context Γ=𝑥1:𝐴1,…,𝑥𝑛:𝐴𝑛, where each type 𝐴𝑖 mentions only the variables before it, is satisfiedwhitepaper/Fragment/WellDenoted.lean:L234-L241234/-- **Satisfaction of a context**: every entry is a well-denoted type
235under the environment beyond it, and the variable's value is a member
236of it. The semantic `Γ ⊢`. -/
237def Sat : List Expr → (Nat → V) → Prop
238 | [], _ => True
239 | A :: Γ, ρ =>
240 Sat Γ (fun i => ρ (i + 1)) ∧ WellDenoted M φ (fun i => ρ (i + 1)) A ∧
241 IsTy (interp M φ (fun i => ρ (i + 1)) A) ∧ ρ 0 ∈ˢ interp M φ (fun i => ρ (i + 1)) A
by 𝜌 when every entry is well-denoted, denotes a type, and holds the variable’s value:

𝜌⊧𝐴𝑖,⟦𝐴𝑖⟧𝜌a type,𝜌(𝑥𝑖)∈⟦𝐴𝑖⟧𝜌for𝑖=1,…,𝑛.

This is the semantic reading of “Γ is a well-formed context”, and it is the only thing the claims below assume about the context.

The first step where the point matters is β. Take a well-denoted redex (𝜆𝑥:𝐴.𝑏)𝑎. For the β law we need ⟦𝑎⟧𝜌∈⟦𝐴⟧𝜌, the argument in the lambda’s domain. The app-graph rule provides it when the lambda’s value is a graph; app-pt, when it is the point, provides nothing.

Lemma 1 (β where the redex is not the point). If (𝜆𝑥:𝐴.𝑏)𝑎 is well-denoted under 𝜌 and does not denote the point, then ⟦(𝜆𝑥:𝐴.𝑏)𝑎⟧𝜌=⟦𝑏[𝑥≔𝑎]⟧𝜌 and 𝑏[𝑥≔𝑎] is well-denoted under 𝜌whitepaper/Fragment/Sound.lean:L107-L125107/-- **β at every binder, with no premise** — `beta_of_ne_pt`. The
108redex is not the point, so neither is its lambda; a lambda that is not the point
109is the graph of its body over its own domain; the application clause (`AppliesTo`)
110puts the argument in that domain. -/
111theorem beta_sound {Γ : List Expr} {A b a : Expr} :
112 RedSem m φ Γ (.app (.lam A b) a) (b.inst a) := by
113 intro ρ _ hw hn
114 rw [WellDenoted_app] at hw
115 obtain ⟨hl, ha, hap⟩ := hw
116 rw [WellDenoted_lam] at hl
117 obtain ⟨-, -, hbody⟩ := hl
118 have hlam := fn_ne_pt hn
119 have hval : interp m.M φ ρ (.lam A b) =
120 graph (fun x => interp m.M φ (cons x ρ) b) (interp m.M φ ρ A) := by
121 rw [interp_lam] at hlam ⊢; exact lamV_eq_graph hlam
122 rw [hval] at hap
123 have haA : interp m.M φ ρ a ∈ˢ interp m.M φ ρ A := (appliesTo_graph.mp hap).2
124 refine ⟨(WellDenoted_inst0 m.M φ ha).mpr (hbody _ haA), ?_⟩
125 rw [interp_app, interp_lam, app_lamV haA, interp_inst0]
.
Proof. The application is not the point, so neither is the lambda, since 𝗉𝗍⋅𝑎=𝗉𝗍. An abstraction that is not the point is a graph, graph(𝑣↦⟦𝑏⟧𝜌,𝑥↦𝑣,⟦𝐴⟧𝜌). A graph is never the point, so the application is well-denoted by app-graph, and as a graph determines its domain, ⟦𝑎⟧𝜌∈⟦𝐴⟧𝜌. The β law computes the application to ⟦𝑏⟧𝜌,𝑥↦⟦𝑎⟧𝜌, which is ⟦𝑏[𝑥≔𝑎]⟧𝜌 by the substitution lemma. The semantic invariant of the reduct is the substitution transport. □

For a redex that does denote the point there is no such lemma. Its lambda may be the point, which carries no domain, and its argument may lie anywhere. Such a redex is well-denoted, and its reduct need not be: (𝜆𝑥:𝐴.𝑔(𝑘𝑥))𝑎whitepaper/Fragment/EtaIota.lean:L697-L714697open EtaWit in
698/-- **Eta on the reduct of the major is outside the claims**.
699The major `maj := (fun x : A => g (k x)) a` is well-denoted
700and the point (a lambda that is the point constrains nothing, so `a` may
701lie outside `A`), and it β-reduces to `maj' := g (k a)`, which is not
702well-denoted (`k` is a graph over `A`). The redex `rec minor maj` is
703well-denoted and not the point. Eta-expanding the major's reduct,
704`minor (p0 maj')`, breaks the reduction claim; eta-expanding the major
705as it stands, `minor (p0 maj)`, satisfies it. So the checker's eta
706path must not reduce the major first (lean4#15371 expands before the
707major's `whnf`). -/
708theorem etaIota_reduced_major_witness [LevelOracle] (φ : Name → Nat) (env : Env)
709 (Γ : List Expr) :
710 Red env Γ maj maj' ∧
711 (∀ ρ : Nat → V, WellDenoted (witM (V := V)) φ ρ redex2 ∧ interp witM φ ρ redex2 ≠ pt ∧
712 interp witM φ ρ maj = pt) ∧
713 ¬ RedSem (EnvModel.empty (witM (V := V))) φ [] redex2 etaRed2 ∧
714 RedSem (EnvModel.empty (witM (V := V))) φ [] redex2 eta2 := by
, with a lambda that is the point and an argument 𝑎 outside the domain 𝐴 of the graph 𝑘, reduces to 𝑔(𝑘𝑎), which is not well-denoted. So the reduction claim below says nothing about a term that denotes the point, and β needs no premise. Section 2.7 shows that the other rules need no more than such a claim.

Why no sort holds the point. The claims below rely on one fact: an inferred type is a type, so it is never the point. It also keeps β sound on stored values. A stored constant (Section 3) 𝑐:𝖲𝗈𝗋𝗍1 whose value is the ill-typed redex (𝜆ℎ:(∀𝑃:𝖯𝗋𝗈𝗉.𝑃).ℎ)𝖯𝗋𝗈𝗉 reduces by δ and β to 𝖯𝗋𝗈𝗉. The redex denotes the point (its lambda is an abstraction over an empty domain), and 𝖯𝗋𝗈𝗉 does not. Such an environment has no modelwhitepaper/Fragment/UniformBeta.lean:L76-L8076/-- **The witness has no model**: the environment
77`c : Sort 1 := (λ (h : ∀ P : Prop, P). h) Prop` — its value denotes the
78point (an abstraction over an empty domain), and `Sort 1`'s members are
79types. -/
80theorem badEnv_no_model (m : EnvModel V badEnv) : False := by
: the constant’s set would have to be the point and a member of 𝒯︀1, which holds no point.

2.7. The three claims and their proof

Theorem 2 (Soundness of the three relations). Fix a valuation 𝜑 and let 𝜌 satisfy Γ. Then:

  1. reduction preserves the denotation and the semantic invariant of a term that is not the point: if Γ⊢𝑒⇝𝑒′, 𝑒 is well-denoted and ⟦𝑒⟧𝜌≠𝗉𝗍, then 𝑒′ is well-denoted and ⟦𝑒⟧𝜌=⟦𝑒′⟧𝜌;
  2. equality means equal sets where neither side is the point: if Γ⊢𝑎≡𝑏, both 𝑎 and 𝑏 are well-denoted and neither denotes the point, then ⟦𝑎⟧𝜌=⟦𝑏⟧𝜌;
  3. inference establishes the semantic invariant and a membership: if Γ⊢𝑒⇒𝑇, then 𝑒 and 𝑇 are well-denoted, ⟦𝑇⟧𝜌 is a type, and ⟦𝑒⟧𝜌∈⟦𝑇⟧𝜌.

(The theorem is soundnesswhitepaper/Fragment/Sound.lean:L2293-L22972293theorem soundness [LevelOracle] (m : EnvModel V env) (φ : Name → Nat) :
2294 (∀ {Γ : List Expr} {e e' : Expr}, Red env Γ e e' → RedSem m φ Γ e e') ∧
2295 (∀ {Γ : List Expr} {a b : Expr}, DefEq env Γ a b → DefEqSem m φ Γ a b) ∧
2296 (∀ {Γ : List Expr} {e T : Expr}, Infer env Γ e T → InferSem m φ Γ e T) :=
2297 ⟨red_sound, defeq_sound, infer_sound⟩
, with the three claims statedwhitepaper/Fragment/Motive.lean:L51-L8451/-- **`Red`'s claim**: on a subject that is not the point, reduction
52preserves the invariant and the denotation. Nothing is claimed of a
53proof. -/
54def RedSem (m : EnvModel V env) (φ : Name → Nat) (Γ : List Expr) (e e' : Expr) : Prop :=
55 ∀ ρ : Nat → V, Sat m.M φ Γ ρ → WellDenoted m.M φ ρ e → interp m.M φ ρ e ≠ pt →
56 WellDenoted m.M φ ρ e' ∧ interp m.M φ ρ e = interp m.M φ ρ e'
57
58/-- **`DefEqLams`' claim**: two well-denoted sides have
59equal denotations — unconditionally, the point included. -/
60def LamsSem (m : EnvModel V env) (φ : Name → Nat) (Γ : List Expr) (a b : Expr) : Prop :=
61 ∀ ρ : Nat → V, Sat m.M φ Γ ρ → WellDenoted m.M φ ρ a → WellDenoted m.M φ ρ b →
62 interp m.M φ ρ a = interp m.M φ ρ b
63
64/-- **`DefEq`'s claim**: two well-denoted sides that are not the point
65have equal denotations. (Two proofs are the point.) -/
66def DefEqSem (m : EnvModel V env) (φ : Name → Nat) (Γ : List Expr) (a b : Expr) : Prop :=
67 ∀ ρ : Nat → V, Sat m.M φ Γ ρ → WellDenoted m.M φ ρ a → WellDenoted m.M φ ρ b →
68 interp m.M φ ρ a ≠ pt → interp m.M φ ρ b ≠ pt → interp m.M φ ρ a = interp m.M φ ρ b
69
70/-- **`DefEqIn`'s claim**: two well-denoted members of one
71well-denoted type have equal denotations — unconditionally, since a
72type's members are all the point or none. -/
73def DefEqInSem (m : EnvModel V env) (φ : Name → Nat) (Γ : List Expr) (T a b : Expr) : Prop :=
74 ∀ ρ : Nat → V, Sat m.M φ Γ ρ → WellDenoted m.M φ ρ T → IsTy (interp m.M φ ρ T) →
75 WellDenoted m.M φ ρ a → WellDenoted m.M φ ρ b →
76 interp m.M φ ρ a ∈ˢ interp m.M φ ρ T → interp m.M φ ρ b ∈ˢ interp m.M φ ρ T →
77 interp m.M φ ρ a = interp m.M φ ρ b
78
79/-- **`Infer`'s claim**: the term and its type are well-denoted, the
80type is a type, and the term's denotation is a member of the type's. -/
81def InferSem (m : EnvModel V env) (φ : Name → Nat) (Γ : List Expr) (e T : Expr) : Prop :=
82 ∀ ρ : Nat → V, Sat m.M φ Γ ρ →
83 WellDenoted m.M φ ρ e ∧ WellDenoted m.M φ ρ T ∧ IsTy (interp m.M φ ρ T) ∧
84 interp m.M φ ρ e ∈ˢ interp m.M φ ρ T
.)

Reduction and equality assume the semantic invariant; inference establishes it. The inference rules are the ones that check a term’s shape, so their soundness proves that the term’s applications and binders respect domains; the other two relations are handed well-denoted terms and pass the semantic invariant along. The first two claims are also conditional on the point: they say nothing about a term that denotes it.

Why the claims may say nothing about the point. A claim that is silent about the point is only useful if every rule that uses a premise’s claim has that premise not the point, or does not need the claim there. Every rule falls into one of four cases.

  1. The subject is a type, never the point. The reductions of an inferred type to a sort or a Π-type (in the binder rules, in app, in 𝜂, in proof irrelevance), the comparisons of two types (an argument’s type with a domain in app, a domain with a domain in the congruences, the checker’s type comparisons in 𝜄), the fibres compared in the congruence for Π-types. The third claim made each subject a type, so the conditional claim applies outright.
  2. The subject is not the point by hypothesis. trans passes the first claim’s denotation on to the second; head reduces the head of an application that is not the point, which is therefore not the point either; red-l reduces a side of an equality that is not the point; app compares the heads of two applications that are not the point.
  3. The two sides share a type, so they are both the point or neither. app’s arguments: the heads are one graph, whose domain is a type and holds both arguments. ι’s comparisons and its major premise (Section 4) are of the same kind. The bodies of lambda congruence and 𝜂 are the one place where nothing else supplies a common type, and that is why those rules compare the bodies’ types (Section 2.8).
  4. The step has its own semantic lemma. β on a redex that is not the point (Lemma 1), 𝜁 and δ (Section 3) claim nothing beyond what holds at every environment.
Corollary 3. If the checker infers ⊢𝑒⇒𝑇 in the empty context, then ⟦𝑒⟧𝜌∈⟦𝑇⟧𝜌 at every valuationwhitepaper/Fragment/Sound.lean:L2301-L23042301theorem closed_infer [LevelOracle] (m : EnvModel V env) (φ : Name → Nat) {e T : Expr}
2302 (h : Infer env [] e T) (ρ : Nat → V) :
2303 interp m.M φ ρ e ∈ˢ interp m.M φ ρ T :=
2304 (infer_sound (m := m) (φ := φ) h ρ (Sat_nil m.M φ ρ)).2.2.2
and every 𝜌.

This is the statement the environment section builds on: a declaration is accepted when its value’s inferred type is definitionally equal to its declared type, and the corollary, with the second claim, puts the value’s set into the declared type’s set.

Terms whose value is the point. The proof asks whether a term’s value is the point, never whether the term is a proof in Lean’s sense (except in the proof-irrelevance rule, whose claim turns out to be empty), and it learns that only through a type the term lies in. So a term whose value is the point is treated like a proof whatever the sort of its type, also when its value is the point only at some values of a variablewhitepaper/Fragment/Probe.lean:L65-L7265/-- `fun (P : Prop) (h : P) => c`, for `c` not the point: a graph, whose
66application at `False` is the point (an abstraction over an empty
67domain) and at `True` is not — a body whose point-ness varies with the
68variable. -/
69theorem mixed_lam {c : V} (hc : c ≠ pt) :
70 lamV (typeU 0) (fun P => lamV P fun _ => c) ≠ pt ∧
71 SetLib.app (lamV (typeU 0) (fun P => lamV P fun _ => c)) (truthVal False) = pt ∧
72 SetLib.app (lamV (typeU 0) (fun P => lamV P fun _ => c)) one ≠ pt := by
.

The three claims are proved together, by one structural inductionwhitepaper/Fragment/Sound.lean:L2173-L22822173theorem red_sound [LevelOracle] : ∀ {Γ : List Expr} {e e' : Expr},
2174 Red env Γ e e' → RedSem m φ Γ e e'
2175 | _, _, _, .refl => Red.refl_sound
2176 | _, _, _, .trans h₁ h₂ => Red.trans_sound (red_sound h₁) (red_sound h₂)
2177 | _, _, _, .appFn h => Red.appFn_sound (red_sound h)
2178 | _, _, _, .beta => Red.beta_sound
2179 | _, _, _, .zeta => Red.zeta_sound
2180 | _, _, _, .delta hfind hv hls => Red.delta_sound hfind hv hls
2181 | _, _, _, .iota hfind hkind hus hlen hpis hmaj hmeq hrl hctor hinst hcij husj hmlen hpis' hresM
2182 hIM hDM hdoms' htys' hI' hD' hlv hP hres hshape hrps hX =>
2183 Red.iota_sound rfl rfl hfind hkind hus hlen hpis (red_sound hmaj) hmeq hrl hctor hinst hcij husj
2184 hmlen hpis' hresM (infer_sound hIM) (defeq_sound hDM)
2185 hdoms' htys' (fun p hp => infer_sound (hI' p hp)) (fun p hp => defeq_sound (hD' p hp))
2186 hlv (fun p hp => defeq_sound (hP p hp)) hres hshape hrps
2187 (fun p hp => defeq_sound (hX p hp))
2188 | _, _, _, .iotaProp hfind hkind hus hlen hpis hmaj hmeq hrl hctor hinst hcij husj hmlen hpis' hresM
2189 hdoms' htys' hI' hD' hlv hP hres hshape hrps hX hI hlsI hpisI hsort hu =>
2190 Red.iotaProp_sound rfl rfl hfind hkind hus hlen hpis (red_sound hmaj) hmeq hrl hctor hinst hcij husj
2191 hmlen hpis' hresM hdoms' htys' (fun p hp => infer_sound (hI' p hp))
2192 (fun p hp => defeq_sound (hD' p hp)) hlv (fun p hp => defeq_sound (hP p hp)) hres hshape hrps
2193 (fun p hp => defeq_sound (hX p hp)) hI hlsI hpisI hsort hu
2194 | _, _, _, .iotaNested hfind hkind hus hlen hpis hmaj hmeq hrl hctor hinst hcij hcijk husj hmlen
2195 hpis' hresM hIM hDM hdoms' htys' hI' hD' _ _ _ hres hshape hrps hX =>
2196 Red.iotaNested_sound rfl rfl hfind hkind hus hlen hpis (red_sound hmaj) hmeq hrl hctor hinst
2197 hcij hcijk husj hmlen hpis' hresM (infer_sound hIM)
2198 (defeq_sound hDM) hdoms' htys' (fun p hp => infer_sound (hI' p hp))
2199 (fun p hp => defeq_sound (hD' p hp)) hres hshape hrps (fun p hp => defeq_sound (hX p hp))
2200 | _, _, _, .iotaSlot hfind hkind hus hlen hpis hmaj hmeq hrl hctor hinst hcij husj hmlen hpis' hresM
2201 hdoms' htys' hI' hD' hlv hP hres hshape hrps hX =>
2202 Red.iotaSlot_sound rfl rfl hfind hkind hus hlen hpis (red_sound hmaj) hmeq hrl hctor hinst hcij husj
2203 hmlen hpis' hresM hdoms' htys' (fun p hp => infer_sound (hI' p hp))
2204 (fun p hp => defeq_sound (hD' p hp)) hlv (fun p hp => defeq_sound (hP p hp)) hres hshape hrps
2205 (fun p hp => defeq_sound (hX p hp))
2206 | _, _, _, .iotaNestedSlot hfind hkind hus hlen hpis hmaj hmeq hrl hctor hinst hcij hcijk husj hmlen
2207 hpis' hresM hdoms' htys' hI' hD' _ _ _ hres hshape hrps hX =>
2208 Red.iotaNestedSlot_sound rfl rfl hfind hkind hus hlen hpis (red_sound hmaj) hmeq hrl hctor hinst
2209 hcij hcijk husj hmlen hpis' hresM hdoms' htys' (fun p hp => infer_sound (hI' p hp))
2210 (fun p hp => defeq_sound (hD' p hp)) hres hshape hrps (fun p hp => defeq_sound (hX p hp))
2211 | _, _, _, .iotaStrict hfind hkind hus hlen hpis hmaj hmeq hrl hctor hinst hcij husj hmlen hpis'
2212 hresM hdM hI₀ hk₀ hls₀ hd₀ hpis₀ hlvl hlv hP hres hshape hrps hX =>
… 70 more lines
over the three mutually inductive relations (as in con-lecheConLeche/Model/Rules/Sound.lean:L77-L7877theorem red_sound (hin : RulesInputs V m φ) :
78 ∀ {d : Nat} {e e' : Expr}, Red env d e e' → RedSem m φ d e e'
). Every rule is one case, and every case is a lemma about that rule alone, with the induction hypothesis for each premise as an assumption. The routine cases are listed at the end; the others follow.

Proof. Rule betawhitepaper/Fragment/Sound.lean:L111-L125111theorem beta_sound {Γ : List Expr} {A b a : Expr} :
112 RedSem m φ Γ (.app (.lam A b) a) (b.inst a) := by
113 intro ρ _ hw hn
114 rw [WellDenoted_app] at hw
115 obtain ⟨hl, ha, hap⟩ := hw
116 rw [WellDenoted_lam] at hl
117 obtain ⟨-, -, hbody⟩ := hl
118 have hlam := fn_ne_pt hn
119 have hval : interp m.M φ ρ (.lam A b) =
120 graph (fun x => interp m.M φ (cons x ρ) b) (interp m.M φ ρ A) := by
121 rw [interp_lam] at hlam ⊢; exact lamV_eq_graph hlam
122 rw [hval] at hap
123 have haA : interp m.M φ ρ a ∈ˢ interp m.M φ ρ A := (appliesTo_graph.mp hap).2
124 refine ⟨(WellDenoted_inst0 m.M φ ha).mpr (hbody _ haA), ?_⟩
125 rw [interp_app, interp_lam, app_lamV haA, interp_inst0]
, (𝜆𝑥:𝐴.𝑏)𝑎⇝𝑏[𝑥≔𝑎]:
This is Lemma 1. The rule has no premise, and the lemma needs none, because the claim is asked only where the redex is not the point.

Rule zetawhitepaper/Fragment/Sound.lean:L127-L135127/-- **ζ, with no certificate**: the `let` and its
128reduct denote alike at every environment (`interp_zeta`), so neither
129the point hypothesis nor the context is used; the reduct's invariant is
130the `let`'s, through the substitution lemma. -/
131theorem zeta_sound {Γ : List Expr} {T v b : Expr} :
132 RedSem m φ Γ (.letE T v b) (b.inst v) := by
133 intro ρ _ hw _
134 rw [WellDenoted_letE] at hw
135 exact ⟨(WellDenoted_inst0 m.M φ hw.1).mpr hw.2, interp_zeta m.M φ T v b ρ⟩
, 𝗅𝖾𝗍𝑥:𝑇≔𝑣;𝑏⇝𝑏[𝑥≔𝑣]:
The two sides denote the same set at every environment, the point included, and the reduct’s semantic invariant is the let’s, through the substitution transport.

Rule red-lwhitepaper/Fragment/Sound.lean:L158-L164158/-- Reduce, then continue — sound with no typing: the side is not the
159point, so its reduction is. -/
160theorem redL_sound {Γ : List Expr} {a a' b : Expr}
161 (hr : RedSem m φ Γ a a') (h : DefEqSem m φ Γ a' b) : DefEqSem m φ Γ a b := by
162 intro ρ hs ha hb hna hnb
163 obtain ⟨ha', he⟩ := hr ρ hs ha hna
164 exact he.trans (h ρ hs ha' hb (he ▸ hna) hnb)
, Γ⊢𝑎≡𝑏 from Γ⊢𝑎⇝𝑎′ and Γ⊢𝑎′≡𝑏:
𝑎 is not the point, so by the first claim 𝑎′ is well-denoted and ⟦𝑎⟧𝜌=⟦𝑎′⟧𝜌. Now 𝑎′ and 𝑏 are both well-denoted and neither is the point, so the second claim applies to the continuation, and the two equalities chain. This is the one sound way to chain in the equality relation, because a reduction step produces the semantic invariant of its result; see the discussion of transitivity below.

Rule sortwhitepaper/Fragment/Sound.lean:L166-L168166theorem sort_sound [LevelOracle] {Γ : List Expr} {u v : Level} (h : LevelOracle.eq u v = true) :
167 DefEqSem m φ Γ (.sort u) (.sort v) :=
168 fun _ _ _ _ _ _ => by simp [eval_eq_of_oracle h]
, 𝖲𝗈𝗋𝗍𝑢≡𝖲𝗈𝗋𝗍𝑣 when 𝑢≐𝑣:
The oracle is assumed correct: it answers yes only if the levels agree at every valuation (Section 2.2), so the two sorts denote the same set.

Rule piwhitepaper/Fragment/Sound.lean:L174-L191174/-- **`∀`-congruence, with no premise beyond domains and bodies**:
175a `∀`'s value is a function of its domain's and fibres' values
176(`SetLib.piV_congr`), and both are types, never the point. -/
177theorem pi_sound {Γ : List Expr} {A₁ B₁ A₂ B₂ : Expr}
178 (hA : DefEqSem m φ Γ A₁ A₂) (hB : DefEqSem m φ (A₂ :: Γ) B₁ B₂) :
179 DefEqSem m φ Γ (.pi A₁ B₁) (.pi A₂ B₂) := by
180 intro ρ hs h₁ h₂ _ _
181 rw [WellDenoted_pi] at h₁ h₂
182 have heA := hA ρ hs h₁.1 h₂.1 h₁.2.1.ne_pt h₂.2.1.ne_pt
183 have hfib : ∀ x, x ∈ˢ interp m.M φ ρ A₂ →
184 interp m.M φ (cons x ρ) B₁ = interp m.M φ (cons x ρ) B₂ := by
185 intro x hx
186 have hx₁ : x ∈ˢ interp m.M φ ρ A₁ := by rw [heA]; exact hx
187 exact hB (cons x ρ) ((Sat_cons m.M φ).mpr ⟨hs, h₂.1, h₂.2.1, hx⟩) (h₁.2.2.1 x hx₁)
188 (h₂.2.2.1 x hx) (h₁.2.2.2 x hx₁).ne_pt (h₂.2.2.2 x hx).ne_pt
189 simp only [interp_pi]
190 rw [heA]
191 exact piV_congr hfib
, ∀𝑥:𝐴1.𝐵1≡∀𝑥:𝐴2.𝐵2 from Γ⊢𝐴1≡𝐴2 and Γ,𝑥:𝐴2⊢𝐵1≡𝐵2:
Both Π-types are well-denoted, so their domains are types, never the point, and the second claim on the domains gives ⟦𝐴1⟧𝜌=⟦𝐴2⟧𝜌. At every 𝑣 in that domain the fibres are types too, so the claim on the bodies makes them equal. A Π-type’s set is a function of its domain’s set and its fibres, the choice of reading included, since that is read off the fibres; so the two Π-types are equal. No comparison of the two sides’ sorts is needed.

Rule lamwhitepaper/Fragment/Sound.lean:L193-L213193/-- **Lambda congruence, typed**: the two bodies lie in one type
194at every value of the variable — their inferred types are equal there
195— so they are both the point or neither is, and where neither is the
196bodies' claim makes them equal. Neither lambda need be a graph. -/
197theorem lam_sound {Γ : List Expr} {A₁ b₁ A₂ b₂ t₁ t₂ : Expr}
198 (hA : DefEqSem m φ Γ A₁ A₂) (hb : DefEqSem m φ (A₂ :: Γ) b₁ b₂)
199 (ht₁ : InferSem m φ (A₂ :: Γ) b₁ t₁) (ht₂ : InferSem m φ (A₂ :: Γ) b₂ t₂)
200 (ht : DefEqSem m φ (A₂ :: Γ) t₁ t₂) :
201 DefEqSem m φ Γ (.lam A₁ b₁) (.lam A₂ b₂) := by
202 intro ρ hs h₁ h₂ _ _
203 rw [WellDenoted_lam] at h₁ h₂
204 have heA := hA ρ hs h₁.1 h₂.1 h₁.2.1.ne_pt h₂.2.1.ne_pt
205 simp only [interp_lam]
206 rw [heA]
207 apply lamV_congr
208 intro x hx
209 have hs' : Sat m.M φ (A₂ :: Γ) (cons x ρ) := (Sat_cons m.M φ).mpr ⟨hs, h₂.1, h₂.2.1, hx⟩
210 obtain ⟨hw₁, hwt₁, hT₁, hm₁⟩ := ht₁ _ hs'
211 obtain ⟨hw₂, hwt₂, hT₂, hm₂⟩ := ht₂ _ hs'
212 rw [ht _ hs' hwt₁ hwt₂ hT₁.ne_pt hT₂.ne_pt] at hm₁
213 exact hT₂.eq_of_ne_pt hm₁ hm₂ (hb _ hs' hw₁ hw₂)
, 𝜆𝑥:𝐴1.𝑏1≡𝜆𝜆𝑥:𝐴2.𝑏2 from the domains, the bodies, and the bodies’ types 𝑡1≡𝑡2:
The domains are equal as for Π-types. Fix 𝑣 in the domain. The third claim puts ⟦𝑏1⟧ in ⟦𝑡1⟧ and ⟦𝑏2⟧ in ⟦𝑡2⟧ (at 𝜌,𝑥↦𝑣), both types, and the second claim on the types, which are not the point, makes them one type. Its members are all the point or none, so either both bodies are the point, or neither is and the claim on the bodies makes them equal. Either way they are equal at every 𝑣, and so are the two abstractions, whether or not either of them is the point. The claim is therefore unconditional; lam-outer passes such a claim outwards (Section 2.8), and lams weakens it to the second claim. Without the type premises the argument breaks at “both or neither”: a body may be the point at some 𝑣 and not at others, and the claim on the bodies says nothing at such a 𝑣.

Rule appwhitepaper/Fragment/Sound.lean:L225-L245225/-- **Application congruence**: the two heads are equal graphs, so the
226two arguments lie in one domain, which is a type — both arguments are
227the point, or neither is. -/
228theorem app_sound {Γ : List Expr} {f₁ a₁ f₂ a₂ : Expr}
229 (hf : DefEqSem m φ Γ f₁ f₂) (ha : DefEqSem m φ Γ a₁ a₂) :
230 DefEqSem m φ Γ (.app f₁ a₁) (.app f₂ a₂) := by
231 intro ρ hs h₁ h₂ hn₁ hn₂
232 obtain ⟨F₁, A₁, he₁, hT₁, hm₁⟩ := app_slot h₁ hn₁
233 obtain ⟨F₂, A₂, he₂, -, hm₂⟩ := app_slot h₂ hn₂
234 have h₁' := h₁
235 have h₂' := h₂
236 rw [WellDenoted_app] at h₁' h₂'
237 have heF := hf ρ hs h₁'.1 h₂'.1 (fn_ne_pt hn₁) (fn_ne_pt hn₂)
238 have hA : A₁ = A₂ := graph_dom_unique (he₁.symm.trans (heF.trans he₂))
239 rw [← hA] at hm₂
240 have heA : interp m.M φ ρ a₁ = interp m.M φ ρ a₂ := by
241 rcases hT₁ with hT | hT
242 · rw [eq_pt_of_mem_univ_zero hT hm₁, eq_pt_of_mem_univ_zero hT hm₂]
243 · exact ha ρ hs h₁'.2.1 h₂'.2.1 (ne_pt_of_mem_strict hT hm₁) (ne_pt_of_mem_strict hT hm₂)
244 simp only [interp_app]
245 rw [heF, heA]
, 𝑓1𝑎1≡𝑓2𝑎2:
Neither application is the point, so neither head is, and the claim on the heads makes them one graph. So both applications are well-denoted by app-graph, and as a graph determines its domain, both arguments lie in that one graph’s domain, a type. They are both the point, or neither is and the claim on the arguments makes them equal.

Rule fun-etawhitepaper/Fragment/Sound.lean:L381-L425381/-- **η, typed**: at every value of the variable the lambda's
382body and `b` applied lie in one type — the body's inferred type is the
383`∀`'s fibre — so they are both the point or neither is, and where
384neither is the body's claim makes them equal; a member of a function space is
385the abstraction of its applications (`SetLib.lamV_eta`). -/
386theorem eta_sound {Γ : List Expr} {A₁ b₁ b tb A₂ B t₁ : Expr}
387 (htb : ∀ ρ, Sat m.M φ Γ ρ → WellDenoted m.M φ ρ b → interp m.M φ ρ b ≠ pt →
388 WellDenoted m.M φ ρ tb ∧ IsTy (interp m.M φ ρ tb) ∧
389 interp m.M φ ρ b ∈ˢ interp m.M φ ρ tb)
390 (hr : RedSem m φ Γ tb (.pi A₂ B))
391 (hA : DefEqSem m φ Γ A₂ A₁)
392 (hbody : DefEqSem m φ (A₁ :: Γ) b₁ (.app (b.liftN 1) (.bvar 0)))
393 (ht₁ : InferSem m φ (A₁ :: Γ) b₁ t₁) (htB : DefEqSem m φ (A₁ :: Γ) t₁ B) :
394 DefEqSem m φ Γ (.lam A₁ b₁) b := by
395 intro ρ hs hlam hwb _ hnb
396 obtain ⟨hwtb, hTtb, hmemb⟩ := htb ρ hs hwb hnb
397 obtain ⟨hwpi, hepi⟩ := hr ρ hs hwtb hTtb.ne_pt
398 rw [hepi, interp_pi] at hmemb
399 rw [WellDenoted_pi] at hwpi
400 have hlam' := hlam
401 rw [WellDenoted_lam] at hlam'
402 have heA := hA ρ hs hwpi.1 hlam'.1 hwpi.2.1.ne_pt hlam'.2.1.ne_pt
403 have hsh : ∀ x, shiftE 1 0 (cons x ρ) = ρ := by
404 intro x; funext i; simp [shiftE]
405 have hlift : ∀ x, interp m.M φ (cons x ρ) (b.liftN 1) = interp m.M φ ρ b := by
406 intro x; rw [interp_liftN, hsh]
407 have hpt : ∀ x, x ∈ˢ interp m.M φ ρ A₁ →
408 interp m.M φ (cons x ρ) b₁ = SetLib.app (interp m.M φ ρ b) x := by
409 intro x hx
410 have hx₂ : x ∈ˢ interp m.M φ ρ A₂ := by rw [heA]; exact hx
411 have hs' : Sat m.M φ (A₁ :: Γ) (cons x ρ) :=
412 (Sat_cons m.M φ).mpr ⟨hs, hlam'.1, hlam'.2.1, hx⟩
413 have happ : WellDenoted m.M φ (cons x ρ) (.app (b.liftN 1) (.bvar 0)) := by
414 rw [WellDenoted_app]
415 exact ⟨(WellDenoted_liftN m.M φ 1 b 0 (cons x ρ)).mpr (by rw [hsh]; exact hwb), trivial,
416 by rw [interp_bvar, cons_zero, hlift]; exact appliesTo_of_mem_piR hmemb hwpi.2.1 hx₂⟩
417 obtain ⟨hwb₁, hwt₁, hT₁, hm₁⟩ := ht₁ _ hs'
418 rw [htB _ hs' hwt₁ (hwpi.2.2.1 x hx₂) hT₁.ne_pt (hwpi.2.2.2 x hx₂).ne_pt] at hm₁
419 have hm₂ : interp m.M φ (cons x ρ) (.app (b.liftN 1) (.bvar 0)) ∈ˢ
420 interp m.M φ (cons x ρ) B := by
… 5 more lines
, 𝜆𝑥:𝐴1.𝑏1≡𝑏 when Γ⊢𝑏⇒𝑇⇝∀𝑥:𝐴2.𝐵, Γ⊢𝐴2≡𝐴1, Γ,𝑥:𝐴1⊢𝑏1≡𝑏𝑥, and the body’s type agrees with 𝐵:
𝑏 is not the point, so the third claim, then the first, put ⟦𝑏⟧𝜌 in the denotation of the Π-type, which is well-denoted; the domains are equal as before. Fix 𝑣 in the domain. The lambda’s body lies in its inferred type, which the type premise makes the fibre ⟦𝐵⟧𝜌,𝑥↦𝑣; the term 𝑏𝑥 lies there by elimination. In one type, they are both the point or neither, and in the second case the claim on the bodies makes them equal. So the lambda denotes the abstraction of 𝑣↦⟦𝑏⟧𝜌⋅𝑣, and a member of a function space of types is the abstraction of its applicationswhitepaper/Fragment/Lib.lean:L625-L628625/-- **η**: a member of a function space whose fibres are types is the
626abstraction of its applications. -/
627theorem lamV_eta {A f : V} {B : V → V} (hf : f ∈ˢ piV A B) (hB : ∀ x, x ∈ˢ A → IsTy (B x)) :
628 lamV A (fun x => app f x) = f := by
.

Rule proof-irrelwhitepaper/Fragment/Sound.lean:L567-L577567/-- **Proof irrelevance claims nothing**: a side whose type's sort is
568`Prop` is the point, and the claim is about sides that are not. -/
569theorem proofIrrel_sound [LevelOracle] {Γ : List Expr} {a ta tta b : Expr} {u : Level}
570 (hta : InferSem m φ Γ a ta) (htta : InferSem m φ Γ ta tta)
571 (hu : RedSem m φ Γ tta (.sort u)) (hu0 : LevelOracle.eq u .zero = true) :
572 DefEqSem m φ Γ a b := by
573 intro ρ hs _ _ hna _
574 obtain ⟨-, hmemT⟩ := Infer.mem_typeU_of htta hu hs
575 obtain ⟨-, -, -, hmem⟩ := hta ρ hs
576 rw [eval_eq_of_oracle hu0, Level.eval_zero, mem_typeU_zero] at hmemT
577 exact absurd (eq_pt_of_mem_univ_zero hmemT hmem) hna
, 𝑎≡𝑏 when Γ⊢𝑎⇒𝑇𝑎⇒𝑆𝑎⇝𝖲𝗈𝗋𝗍𝑢 with 𝑢≐0, and likewise for 𝑏:
By the third claim twice and the first once, ⟦𝑎⟧𝜌∈⟦𝑇𝑎⟧𝜌∈𝒯︀0, a truth value, whose only possible member is the point. So 𝑎 denotes the point, and the claim, which is about sides that are not the point, holds vacuously. The two types 𝑇𝑎 and 𝑇𝑏 were never compared, and the semantic invariants of 𝑎 and 𝑏 were not used.

Rule pi, inferencewhitepaper/Fragment/Sound.lean:L283-L297283theorem pi_sound {Γ : List Expr} {A B s t : Expr} {u v : Level}
284 (hA : InferSem m φ Γ A s) (hu : RedSem m φ Γ s (.sort u))
285 (hB : InferSem m φ (A :: Γ) B t) (hv : RedSem m φ (A :: Γ) t (.sort v)) :
286 InferSem m φ Γ (.pi A B) (.sort (.imax u v)) := by
287 intro ρ hs
288 obtain ⟨hwA, hmemA⟩ := mem_typeU_of hA hu hs
289 have hTA := IsTy_of_mem_typeU hmemA
290 have hbody : ∀ x, x ∈ˢ interp m.M φ ρ A →
291 WellDenoted m.M φ (cons x ρ) B ∧ interp m.M φ (cons x ρ) B ∈ˢ typeU (Level.eval φ v) :=
292 fun x hx => mem_typeU_of hB hv ((Sat_cons m.M φ).mpr ⟨hs, hwA, hTA, hx⟩)
293 refine ⟨?_, trivial, Or.inr (strict_typeU _), ?_⟩
294 · rw [WellDenoted_pi]
295 exact ⟨hwA, hTA, fun x hx => (hbody x hx).1, fun x hx => IsTy_of_mem_typeU (hbody x hx).2⟩
296 · rw [interp_pi, interp_sort, Level.eval_imax]
297 exact piV_mem_typeU hmemA fun x hx => (hbody x hx).2
, Γ⊢∀𝑥:𝐴.𝐵⇒𝖲𝗈𝗋𝗍(imax(𝑢,𝑣)) when Γ⊢𝐴⇒𝑆⇝𝖲𝗈𝗋𝗍𝑢 and Γ,𝑥:𝐴⊢𝐵⇒𝑇⇝𝖲𝗈𝗋𝗍𝑣:
The third claim for 𝐴 and the first for 𝑆 put ⟦𝐴⟧𝜌 in 𝒯︀𝜑(𝑢), so it is a type, and for every 𝑣′∈⟦𝐴⟧𝜌 the environment 𝜌,𝑥↦𝑣′ satisfies Γ,𝑥:𝐴; the same claims for 𝐵 put every fibre in 𝒯︀𝜑(𝑣). That is the pi rule of the semantic invariant, and Π𝗏(𝐴,𝐵) lies in 𝒯︀𝜑(imax(𝑢,𝑣))whitepaper/Fragment/Lib.lean:L646-L652646/-- **`∀`-formation in the sorts' sets `typeU`**, with no regime
647premise: over fibres in `Sort 0` the function space is a truth value; over
648fibres in a positive sort it is a truth value or a strict function
649space, a type either way. -/
650theorem piV_mem_typeU {u v : Nat} {A : V} {B : V → V}
651 (hA : A ∈ˢ typeU u) (hB : ∀ x, x ∈ˢ A → B x ∈ˢ typeU v) :
652 piV A B ∈ˢ typeU (Level.imaxNat u v) := by
. If 𝜑(𝑣)=0, every fibre is a truth value, so is Π𝗏(𝐴,𝐵), and 𝜑(imax(𝑢,𝑣))=0. Otherwise Π𝗏(𝐴,𝐵) is a truth value or a function space in 𝒰︀max(𝜑(𝑢),𝜑(𝑣)) by cumulativity and closure, a type either way. Π𝗏(𝐴,𝐵) need not be a function space when 𝜑(𝑣)≠0: over an empty domain it is {𝗉𝗍}, and 𝒯︀ admits it.

Rule lam, inferencewhitepaper/Fragment/Sound.lean:L299-L319299/-- **Lambda**: Lean's rule. The body's type is a type (`InferSem`), which
300is all `lamV_mem` asks of the fibres. -/
301theorem lam_sound {Γ : List Expr} {A b s bt : Expr} {u : Level}
302 (hA : InferSem m φ Γ A s) (hu : RedSem m φ Γ s (.sort u))
303 (hb : InferSem m φ (A :: Γ) b bt) :
304 InferSem m φ Γ (.lam A b) (.pi A bt) := by
305 intro ρ hs
306 obtain ⟨hwA, hmemA⟩ := mem_typeU_of hA hu hs
307 have hTA := IsTy_of_mem_typeU hmemA
308 have hbody : ∀ x, x ∈ˢ interp m.M φ ρ A →
309 WellDenoted m.M φ (cons x ρ) b ∧ WellDenoted m.M φ (cons x ρ) bt ∧
310 IsTy (interp m.M φ (cons x ρ) bt) ∧
311 interp m.M φ (cons x ρ) b ∈ˢ interp m.M φ (cons x ρ) bt :=
312 fun x hx => hb (cons x ρ) ((Sat_cons m.M φ).mpr ⟨hs, hwA, hTA, hx⟩)
313 refine ⟨?_, ?_, by rw [interp_pi]; exact IsTy_piV, ?_⟩
314 · rw [WellDenoted_lam]
315 exact ⟨hwA, hTA, fun x hx => (hbody x hx).1⟩
316 · rw [WellDenoted_pi]
317 exact ⟨hwA, hTA, fun x hx => (hbody x hx).2.1, fun x hx => (hbody x hx).2.2.1⟩
318 · rw [interp_lam, interp_pi]
319 exact lamV_mem (fun x hx => (hbody x hx).2.2.2) fun x hx => (hbody x hx).2.2.1
, Γ⊢𝜆𝑥:𝐴.𝑏⇒∀𝑥:𝐴.𝐵 when Γ⊢𝐴⇒𝑆⇝𝖲𝗈𝗋𝗍𝑢 and Γ,𝑥:𝐴⊢𝑏⇒𝐵:
The same argument one level down. The domain is a type, and for every 𝑣′ in it the third claim for 𝑏 gives 𝑏 and 𝐵 well-denoted, ⟦𝐵⟧ a type and ⟦𝑏⟧∈⟦𝐵⟧. That is the lambda rule, and the pi rule of the inferred type is met too; and as the ⟦𝐵⟧ are types holding the body’s values, the introduction law for values puts the abstraction into Π𝗏(𝐴,𝐵). Nothing about the sort of 𝐵 is needed, so the rule computes none.

Rule app, inferencewhitepaper/Fragment/Sound.lean:L321-L339321theorem app_sound {Γ : List Expr} {f a tf A B ta : Expr}
322 (hf : InferSem m φ Γ f tf) (hr : RedSem m φ Γ tf (.pi A B))
323 (ha : InferSem m φ Γ a ta) (hd : DefEqSem m φ Γ ta A) :
324 InferSem m φ Γ (.app f a) (B.inst a) := by
325 intro ρ hs
326 obtain ⟨hwf, hwtf, hTtf, hmemf⟩ := hf ρ hs
327 obtain ⟨hwpi, hepi⟩ := hr ρ hs hwtf hTtf.ne_pt
328 rw [hepi, interp_pi] at hmemf
329 have hwpi' := hwpi
330 rw [WellDenoted_pi] at hwpi'
331 obtain ⟨hwA, hTA, hwB, hfib⟩ := hwpi'
332 obtain ⟨hwa, hwta, hTta, hmema⟩ := ha ρ hs
333 rw [hd ρ hs hwta hwA hTta.ne_pt hTA.ne_pt] at hmema
334 refine ⟨?_, (WellDenoted_inst0 m.M φ hwa).mpr (hwB _ hmema), ?_, ?_⟩
335 · rw [WellDenoted_app]
336 exact ⟨hwf, hwa, appliesTo_of_mem_piR hmemf hTA hmema⟩
337 · rw [interp_inst0]; exact hfib _ hmema
338 · rw [interp_app, interp_inst0]
339 exact app_mem_piV hmemf hmema
, Γ⊢𝑓𝑎⇒𝐵[𝑥≔𝑎] when Γ⊢𝑓⇒𝑇⇝∀𝑥:𝐴.𝐵, Γ⊢𝑎⇒𝑇𝑎 and Γ⊢𝑇𝑎≡𝐴:
By the third claim, 𝑓 and 𝑇 are well-denoted and ⟦𝑓⟧𝜌∈⟦𝑇⟧𝜌; 𝑇 is a type, so by the first claim the Π-type is well-denoted and ⟦𝑇⟧𝜌=⟦∀𝑥:𝐴.𝐵⟧𝜌. By the third claim for 𝑎, 𝑎 and 𝑇𝑎 are well-denoted, ⟦𝑇𝑎⟧ is a type and ⟦𝑎⟧𝜌∈⟦𝑇𝑎⟧𝜌; 𝐴 is a type by the pi rule, so the second claim gives ⟦𝑇𝑎⟧𝜌=⟦𝐴⟧𝜌 and ⟦𝑎⟧𝜌∈⟦𝐴⟧𝜌. Now 𝑓𝑎 is well-denoted, by an app rule of Section 2.6: ⟦𝑓⟧𝜌 lies in Π𝗏(𝐴,𝐵) with 𝐴 a type holding the argument, so it is the point or a graph over ⟦𝐴⟧𝜌; 𝐵[𝑥≔𝑎] is well-denoted by the substitution transport; and the elimination law puts ⟦𝑓⟧𝜌⋅⟦𝑎⟧𝜌 into the fibre at ⟦𝑎⟧𝜌, which is ⟦𝐵[𝑥≔𝑎]⟧𝜌 by the substitution lemma.

A syntactic proof would here invert a derivation of 𝑓:𝑇 to learn the domain and the codomain, using the Π-injectivity that Section 2.3 discussed. Our proof inverts nothing. The checker itself reduced 𝑇 to a syntactic Π-type, the first claim says that the reduction did not change the set, and that set is Π𝗏(𝐴,𝐵) by the interpretation’s rule.

Rule let, inferencewhitepaper/Fragment/Sound.lean:L341-L357341/-- **`let`, by substitution**: the body with the value
342substituted carries the claim, and the `let` denotes what it denotes
343(`interp_zeta`); its invariant is the `let`'s (`WellDenoted_letE`
344against `WellDenoted_inst0`). The type checks on the value (`hT`,
345`hu`, `hv`, `hd`) are not used: `interp` reads no type, and the body
346is inferred at the value itself, not at a variable of the type. -/
347theorem letE_sound {Γ : List Expr} {T v b s tv B : Expr} {u : Level}
348 (_hT : InferSem m φ Γ T s) (_hu : RedSem m φ Γ s (.sort u))
349 (hv : InferSem m φ Γ v tv) (_hd : DefEqSem m φ Γ tv T)
350 (hb : InferSem m φ Γ (b.inst v) B) :
351 InferSem m φ Γ (.letE T v b) B := by
352 intro ρ hs
353 obtain ⟨hwv, -⟩ := hv ρ hs
354 obtain ⟨hwb, hwB, hTB, hmem⟩ := hb ρ hs
355 refine ⟨?_, hwB, hTB, ?_⟩
356 · rw [WellDenoted_letE]; exact ⟨hwv, (WellDenoted_inst0 m.M φ hwv).mp hwb⟩
357 · rw [interp_zeta]; exact hmem
, Γ⊢𝗅𝖾𝗍𝑥:𝑇≔𝑣;𝑏⇒𝐵 when Γ⊢𝑏[𝑥≔𝑣]⇒𝐵 and the checks on the value:
The claim for the substituted body is the claim for the let: the two denote the same set, and the let’s semantic invariant is the substituted body’s, by the transport. The two checks on the value are not used. They would be if the body were inferred at a variable of type 𝑇 instead: then the value must lie in the typewhitepaper/Fragment/Sound.lean:L359-L375359/-- **What the value checks give**: the value's value is
360a member of the type's, so the value extends a satisfying environment
361to one satisfying the context extended by the type. The substitution
362version does not need it (`letE_sound`); a version that opens the body
363at a let-variable of type `T` would (the body's claim is then stated at
364`T :: Γ`). The type and the value's inferred type are both types,
365never the point, so `DefEq`'s conditional claim applies to them. -/
366theorem letE_sat {Γ : List Expr} {T v s tv : Expr} {u : Level}
367 (hT : InferSem m φ Γ T s) (hu : RedSem m φ Γ s (.sort u))
368 (hv : InferSem m φ Γ v tv) (hd : DefEqSem m φ Γ tv T) {ρ : Nat → V}
369 (hs : Sat m.M φ Γ ρ) :
370 Sat m.M φ (T :: Γ) (cons (interp m.M φ ρ v) ρ) := by
371 obtain ⟨hwT, hmemT⟩ := mem_typeU_of hT hu hs
372 have hTT := IsTy_of_mem_typeU hmemT
373 obtain ⟨-, hwtv, hTtv, hmem⟩ := hv ρ hs
374 rw [hd ρ hs hwtv hwT hTtv.ne_pt hTT.ne_pt] at hmem
375 exact (Sat_cons m.M φ).mpr ⟨hs, hwT, hTT, hmem⟩
to extend a satisfying environment, and the checks give that.

The rest, by induction on the derivation.

  • Reductionwhitepaper/Fragment/Sound.lean:L87-L105 87theorem refl_sound {Γ : List Expr} {e : Expr} : RedSem m φ Γ e e :=
    88 fun _ _ h _ => ⟨h, rfl⟩
    89
    90theorem trans_sound {Γ : List Expr} {e₁ e₂ e₃ : Expr}
    91 (h₁ : RedSem m φ Γ e₁ e₂) (h₂ : RedSem m φ Γ e₂ e₃) : RedSem m φ Γ e₁ e₃ := by
    92 intro ρ hs hw hn
    93 obtain ⟨hw₁, he₁⟩ := h₁ ρ hs hw hn
    94 obtain ⟨hw₂, he₂⟩ := h₂ ρ hs hw₁ (he₁ ▸ hn)
    95 exact ⟨hw₂, he₁.trans he₂⟩
    96
    97theorem appFn_sound {Γ : List Expr} {f f' a : Expr} (h : RedSem m φ Γ f f') :
    98 RedSem m φ Γ (.app f a) (.app f' a) := by
    99 intro ρ hs hw hn
    100 rw [WellDenoted_app] at hw
    101 obtain ⟨hf, ha, hap⟩ := hw
    102 obtain ⟨hf', he⟩ := h ρ hs hf (fn_ne_pt hn)
    103 refine ⟨?_, by simp [he]⟩
    104 rw [WellDenoted_app]
    105 exact ⟨hf', ha, by rw [← he]; exact hap⟩
    : the no-step reduction is ⟦𝑒⟧𝜌=⟦𝑒⟧𝜌; trans chains two reductions, passing the semantic invariant along; head reduces the head of an application that is not the point, which is not the point either, and keeps the application’s rule, because the head’s set did not change.
  • Equalitywhitepaper/Fragment/Sound.lean:L151-L156151theorem refl_sound {Γ : List Expr} {a : Expr} : DefEqSem m φ Γ a a :=
    152 fun _ _ _ _ _ _ => rfl
    153
    154theorem symm_sound {Γ : List Expr} {a b : Expr} (h : DefEqSem m φ Γ a b) :
    155 DefEqSem m φ Γ b a :=
    156 fun ρ hs hb ha hnb hna => (h ρ hs ha hb hna hnb).symm
    : refl is again ⟦𝑒⟧𝜌=⟦𝑒⟧𝜌, and sym swaps the two sides.
  • Inferencewhitepaper/Fragment/Sound.lean:L253-L265253theorem bvar_sound {Γ : List Expr} {i : Nat} {A : Expr} (h : Γ[i]? = some A) :
    254 InferSem m φ Γ (.bvar i) (A.liftN (i + 1)) := by
    255 intro ρ hs
    256 obtain ⟨hw, hT, hmem⟩ := Sat_get m.M φ hs h
    257 refine ⟨trivial, ?_, ?_, ?_⟩
    258 · rw [WellDenoted_liftN]; exact hw
    259 · rw [interp_liftN]; exact hT
    260 · rw [interp_bvar, interp_liftN]; exact hmem
    261
    262theorem sort_sound {Γ : List Expr} {u : Level} :
    263 InferSem m φ Γ (.sort u) (.sort (.succ u)) :=
    264 fun _ _ => ⟨trivial, trivial, Or.inr (strict_typeU _), by
    265 simp only [interp_sort, Level.eval_succ]; exact typeU_mem_typeU_succ _⟩
    : a variable’s type is read off the satisfied context; a sort’s type is the next sort, which contains it.

□

Why there is no transitivity. The proof above shows why the rule “𝑎≡𝑏 and 𝑏≡𝑐 give 𝑎≡𝑐” cannot be added. The second claim assumes both sides well-denoted. In a transitivity case the induction would have to apply the hypothesis to 𝑎≡𝑏, and for that it needs 𝑏 well-denoted. But 𝑏 is neither a subterm of 𝑎 or 𝑐 nor produced by a premise, so nothing supplies its semantic invariant. Every other rulewhitepaper/Fragment/Rules.lean:L529-L546529/-- **Definitional equality**: the verdict `true` of the checker's
530`isDefEq`.
531
532**There is no `trans` rule, deliberately** (`Rel.lean:334-357`).
533The relation is the checker's verdict on two terms that are
534well-formed *together*, a fact no rule states because well-formedness
535is semantic (`WellDenoted`) and may not enter this inductive. Every
536rule respects one discipline instead: **the subject of each `DefEq`
537premise is a subterm of the conclusion or is produced by a `Red` or
538`Infer` premise** (a reduct, an inferred type), so the soundness proof
539always has the premise's terms — and their invariant — in hand. A
540`trans` rule is the unique rule that would break it: its middle term
541comes from nowhere, so nothing supplies its invariant, and the
542induction has nothing to apply the hypothesis to. Nor does the
543checker chain through an arbitrary middle term: every comparison it
544makes is one of the rules below, and its one way to chain is
545"reduce, then continue": `redL`.
546-/
keeps one discipline: each term of an equality premise is either a subterm of the conclusion (the congruences, the 𝜂 body) or a term that another premise produced, a reduct (red-l) or an inferred type (lam, 𝜂), and the corresponding claim delivers the semantic invariant of every produced term. The one way to chain is therefore “reduce, then continue”, and that is how the checker’s equality test is structured: it head-normalises a side and compares again.

2.8. The certification tax

The checker makes two kinds of check that other checkers for Lean (the official kernel, Lean4Lean, nanoda) skip. Both come from one fact: the semantic invariant admits terms that are well-denoted but not well-typed. A typing judgement would exclude them, and with them the need for the checks. The semantic proof has no typing judgement, so the checker verifies the one property the proof would otherwise take from typing. The two kinds are:

  1. The bodies’ types at lambda congruence and 𝜂: inferred by full inference and compared, at the innermost level of two lambda telescopes only. This subsection explains them.
  2. The constructor application in one case of ι-reduction: when the family of the major premise may be a proposition at the instance and the rule is not K-like (one constructor, no fields, in Prop; Section 4.2.8), the checker compares the constructor’s levels, parameters and index expressions with the recursor’s, and type-checks every parameter and field of the constructor application against the constructor’s type. The official kernel makes none of these checks at an ι step; Section 4.2.7 and Section 4.2.8 explain them.
In con-leche The checks are the checker’s innermost lambda levelConLeche/Kernel/Core.lean:L1451-L14571451/-- The innermost level of `defeqBinders`: the opened bodies, and for
1452two λ-telescopes at the verified mode their FULL-grade types. -/
1453def defeqBindersInner (r : CoreFns m) (lam : Bool) (depth : Nat) (b₁ b₂ : Expr) : m Bool := do
1454 unless ← r.defeq (depth + 1) b₁ b₂ do return false
1455 if lam && mode.verifiedChecks then
1456 unless ← r.defeq (depth + 1) (← r.infer (depth + 1) b₁)
1457 (← r.infer (depth + 1) b₂) do return false
, its 𝜂ConLeche/Kernel/Core.lean:L515-L520515 -- Task #342 S0: the λ/η tax (T2)
516 if mode.verifiedChecks then
517 unless ← r.defeq (depth + 1)
518 (← r.infer (depth + 1)
519 (body₁.instantiate1 (.fvar depth ty₁)))
520 (cod₂.instantiate1 (.fvar depth ty₁)) do return false
and the case of ιConLeche/Kernel/Core.lean:L899-L913899 | some (.recInfo cv mI rP isK rules) =>
900 let args := e.getAppArgs
901 -- checker change #9: the recursor's level arity, guarded as
902 -- `unfoldDefinition` guards it (`Core.lean:174`). The official
903 -- kernel tests this immediately before instantiating the rule's
904 -- RHS (`src/kernel/inductive.h:105`, present since v4.0.0);
905 -- lean4lean does the same (`Inductive/Reduce.lean:98`) and
906 -- nanoda's `subst_expr_levels` asserts it. Without it
907 -- `rl.rhs.instantiateLevelParams cv.levelParams us` can leak a
908 -- level parameter the subject never had. Ungated: the reference has it
909 -- unconditionally, so a mode gate would break parity.
910 -- task #342 L18: the stored type's syntactic arity, which the
911 -- uncertified recursor spine is read against
912 if args.length = mI + 1 ∧ us.length = cv.levelParams.length ∧
913 (Expr.peelPis (mI + 1) cv.type).isSome = true then
. On real input neither kind ever fails: they never change a verdict on a stream the official kernel accepts. Both run at --verified only; --trusted skips them.

Why lambda congruence needs the bodies’ types. The claim on the bodies says nothing where a body is the point, and whether a body is the point can vary with the variable. Without a common type of the two bodies the rule is unsound in the model. Take the two lambdaswhitepaper/Fragment/ValueReading.lean:L175-L182175/-- **Untyped lambda congruence is unsound** in the value-driven model: the
176rule's two premises are checker derivations — the domains by `refl`,
177the bodies by β then `refl` — yet in a model of the empty environment
178the two lambdas are well-denoted, neither is the point, and they differ. -/
179theorem lam_congr_untyped_unsound [LevelOracle] (φ : Name → Nat) (ρ : Nat → V) :
180 DefEq Env.empty [] (.sort .zero) (.sort .zero) ∧
181 DefEq Env.empty [.sort .zero] mixedBody (.const nName []) ∧
182 ¬ DefEqSem (EnvModel.empty (mixedM (V := V))) φ [] lamMixed lamConst := by

𝜆(𝑥:𝖯𝗋𝗈𝗉).(𝜆(ℎ:𝐸𝑥).ℎ)𝑛and𝜆(𝑥:𝖯𝗋𝗈𝗉).𝑛,

with 𝐸 sending True to Prop and False to False, and 𝑛 denoting True. They have equal domains, and their bodies are equal by β then refl; both premises are derivations of the checker. Yet at 𝑥≔𝖥𝖺𝗅𝗌𝖾 the left body is an abstraction over an empty domain, applied, hence the point, while the right body is True. The two lambdas are well-denoted, neither is the point, and they differ. The left body is ill-typed (𝑛 is no member of 𝐸𝑥), but it is well-denoted, because the abstraction over 𝐸𝖥𝖺𝗅𝗌𝖾 is the point and constrains nothing.

Why other checkers do without it. Their argument only ever compares two terms of one type: the caller compared the types, or knows them, and lambda inversion gives the two bodies a common type, by subject reduction and uniqueness of types. The model has neither, and the semantic invariant is satisfied by terms no typing judgement derives, so the common type is recomputed.

Innermost only. The checker compares two lambda telescopes level by levelwhitepaper/Fragment/Rules.lean:L670-L714670/-- **Lambda telescope congruence, typed at the innermost level only**.
671Two lambda telescopes are compared level by level: the domains
672at every level, the bodies' types only where the comparison stops
673descending through two lambdas.
674
675*Why the outer levels need no type comparison.* Syntactically: the
676type of `fun x : A => fun y : B => c` is `∀ x : A, ∀ y : B, T` where
677`T` is `c`'s type, so for two telescopes compared with equal domains,
678each outer level's bodies' types are `∀`s over the domain the next
679level compares, with the next level's bodies' types as codomains; equal
680innermost bodies' types give equal bodies' types at every level, by
681`∀`-congruence. Semantically (`Sound.lean`, `DefEqLams.outer_sound`):
682the type comparison is what makes lambda congruence's claim
683**unconditional** — `DefEq`'s claim says nothing where a side is the
684point, and two bodies in one type are both the point or neither — and
685an unconditional equality of the bodies at every value of the variable
686is an equality of the lambdas, with no type at all. So the claim of this
687relation, `LamsSem`, is unconditional, and it propagates outward
688through any number of levels.
689
690*Unequal depth, and reduction between levels.* The descent continues
691only through two **syntactic** lambdas (`outer`'s premise is this relation
692itself, which has no reduction rule). Where one body is not a lambda — the
693comparison ends in η, or in any other rule, possibly after δ or whnf
694steps — that level is the innermost one (`inner`), and its bodies'
695types are inferred and compared at the full grade. A δ or whnf step
696between levels therefore resets the accounting: the δ-witness `d :=
697fun x => (fun h => h) n` (`Probe.lean`, `lam_congr_sorts_unsound`)
698puts the reduction inside `inner`'s untyped premise `DefEq … b₁ b₂`,
699where the type comparison is still required. Syntactically equal
700lambdas (`refl`) are equal outright. -/
701inductive DefEqLams (env : Env) : List Expr → Expr → Expr → Prop where
702 /-- Syntactically equal sides (the checker's `a == b` fast path). -/
703 | refl {Γ : List Expr} {a : Expr} : DefEqLams env Γ a a
704 /-- The innermost level: `DefEq.lam`'s premises — domains, bodies,
705 and the bodies' inferred types. -/
706 | inner {Γ : List Expr} {A₁ b₁ A₂ b₂ t₁ t₂ : Expr} :
707 DefEq env Γ A₁ A₂ → DefEq env (A₂ :: Γ) b₁ b₂ →
708 Infer env (A₂ :: Γ) b₁ t₁ → Infer env (A₂ :: Γ) b₂ t₂ → DefEq env (A₂ :: Γ) t₁ t₂ →
709 DefEqLams env Γ (lam A₁ b₁) (lam A₂ b₂)
… 5 more lines
, and infers and compares the bodies’ types only at the innermost level, where the descent through two syntactic lambdas stops (the next comparison is 𝜂, or a reduction, or any other rule). At the outer levels the domains are compared and nothing else. This is sound because the type comparison makes the claim at the innermost level unconditional: two bodies in one type are equal at every value of the variable, the point included. An unconditional equality of the bodies at every value is an equality of the abstractions, with no type at all, so the claim propagates outwardswhitepaper/Fragment/Sound.lean:L706-L723706/-- **An outer level needs no type**: the bodies are equal
707at every value of the variable, unconditionally, so the lambdas are; the
708domains are types, never the point, so their conditional claim
709applies. This is why the type comparison is owed only at the
710innermost level of a lambda telescope pair. -/
711theorem outer_sound {Γ : List Expr} {A₁ b₁ A₂ b₂ : Expr}
712 (hA : DefEqSem m φ Γ A₁ A₂) (hb : LamsSem m φ (A₂ :: Γ) b₁ b₂) :
713 LamsSem m φ Γ (.lam A₁ b₁) (.lam A₂ b₂) := by
714 intro ρ hs h₁ h₂
715 rw [WellDenoted_lam] at h₁ h₂
716 have heA := hA ρ hs h₁.1 h₂.1 h₁.2.1.ne_pt h₂.2.1.ne_pt
717 simp only [interp_lam]
718 rw [heA]
719 apply lamV_congr
720 intro x hx
721 have hx₁ : x ∈ˢ interp m.M φ ρ A₁ := by rw [heA]; exact hx
722 exact hb (cons x ρ) ((Sat_cons m.M φ).mpr ⟨hs, h₂.1, h₂.2.1, hx⟩) (h₁.2.2 x hx₁)
723 (h₂.2.2 x hx)
through any number of levels. A δ step or a reduction between two levels ends the telescope, and the level below it is an innermost level again.

Where the comparison could be skipped. The fragment also proves three weaker forms of the ruleswhitepaper/Fragment/Rules.lean:L591-L635591 /-- **Lambda congruence over a propositional domain**: no
592 comparison of the bodies' types. The domain is a truth value, so it
593 has at most one member, and a body's point-ness cannot vary with
594 the variable: a lambda that is not the point has its one body value not
595 the point, and the bodies' claim applies there (`Sound.lean`,
596 `DefEq.lamProp_sound`). The checker infers the domain's sort, not
597 the bodies' types. -/
598 | lamProp {Γ : List Expr} {A₁ b₁ A₂ b₂ s : Expr} {u : Level} :
599 DefEq env Γ A₁ A₂ → DefEq env (A₂ :: Γ) b₁ b₂ →
600 Infer env Γ A₂ s → Red env Γ s (sort u) → LevelOracle.eq u .zero = true →
601 DefEq env Γ (lam A₁ b₁) (lam A₂ b₂)
602 /-- **Lambda congruence of two constant bodies**: neither body
603 uses the bound variable, so each body's value, and its point-ness,
604 is the same at every value of the variable; a lambda that is not the
605 point has a body that is not the point anywhere (`Sound.lean`,
606 `DefEq.lamConst_sound`). One constant body is not enough: the right
607 body of `lam_congr_untyped_unsound` is the constant `n`. -/
608 | lamConst {Γ : List Expr} {A₁ b₁ A₂ b₂ : Expr} :
609 DefEq env Γ A₁ A₂ → DefEq env (A₂ :: Γ) b₁ b₂ →
610 b₁.usesVar 0 = false → b₂.usesVar 0 = false →
611 DefEq env Γ (lam A₁ b₁) (lam A₂ b₂)
612 /-- **η over a propositional domain**: `DefEq.eta`
613 without the lambda's body's type, for the reason of `lamProp`: over a
614 domain with at most one member, the lambda and `b` that are not the point
615 have their one body value not the point (`Sound.lean`,
616 `DefEq.etaProp_sound`). -/
617 | etaProp {Γ : List Expr} {A₁ b₁ b tb A₂ B s : Expr} {u : Level} :
618 Infer env Γ b tb → Red env Γ tb (pi A₂ B) →
619 DefEq env Γ A₂ A₁ →
620 DefEq env (A₁ :: Γ) b₁ (app (b.liftN 1) (bvar 0)) →
621 Infer env Γ A₁ s → Red env Γ s (sort u) → LevelOracle.eq u .zero = true →
622 DefEq env Γ (lam A₁ b₁) b
623 /-- **Application congruence at the head's type**: the
624 heads are equal and the head's type reduces to a `∀` whose domain
625 `S` is the arguments' common type, so the arguments are compared
626 *at* `S` (`DefEqIn`) — lambda congruence and η between them need neither
627 the bodies' types nor a domain comparison (`Sound.lean`,
628 `DefEq.appIn_sound`). The checker has the head's type for free when
629 the head is a constant or a variable (con-leche's arguments of a
630 constant-headed spine: the stored type instantiated along the
… 5 more lines
sound; con-leche does not use them. Each drops the coloured premises where something else makes the bodies both the point or neither at every value of the variable:

Full inference. The bodies’ types are inferred by full inference (Section 2.3.3), not by infer_only (Section 2.9). With infer_only there is a typed definition at which every premise of lambda congruence holdswhitepaper/Fragment/IOWitness.lean:L433-L445433/-- **Lambda congruence with io-inferred bodies' types is unsound.** In a
434model of `ioEnv` (both definitions typed): the domains by `refl`, the
435bodies `g x n` and `n` by δ, β, β and `refl`, both bodies io-infer
436`Prop`, `Prop ≡ Prop` by `refl` — every premise of `DefEq.lam` with
437`InferIO` in place of `Infer`; the lambdas are well-denoted, not the point,
438and different. -/
439theorem lam_congr_io_unsound [LevelOracle] (φ : Name → Nat) :
440 DefEq ioEnv [] (.sort .zero) (.sort .zero) ∧
441 DefEq ioEnv [.sort .zero] gxn (.const nName []) ∧
442 InferIO ioEnv [.sort .zero] gxn (.sort .zero) ∧
443 InferIO ioEnv [.sort .zero] (.const nName []) (.sort .zero) ∧
444 DefEq ioEnv [.sort .zero] (.sort .zero) (.sort .zero) ∧
445 ¬ DefEqSem (ioModel (V := V)) φ [] lamG lamConst := by
while the two lambdas differ. Every premise is a derivation of the relations, so the rule itself is unsound, whatever claim infer_only makes.

2.9. The cheaper mode of inference

The official kernel infers the type of a term it has already checked by a cheaper mode, infer_only. The fragment has that modewhitepaper/Fragment/IOGrade.lean:L61-L9661/-- **The fast-inference grade** (Lean's `infer_only`): the rules of
62`Infer` without the application's argument check and without the lambda's
63domain check. `∀`-formation still infers the sorts, which its result
64needs. -/
65inductive InferIO [LevelOracle] (env : Env) : List Expr → Expr → Expr → Prop where
66 /-- A bound variable: its context entry. -/
67 | bvar {Γ : List Expr} {i : Nat} {A : Expr} :
68 Γ[i]? = some A → InferIO env Γ (bvar i) (A.liftN (i + 1))
69 /-- `Sort u : Sort (u + 1)`. -/
70 | sort {Γ : List Expr} {u : Level} : InferIO env Γ (sort u) (sort (.succ u))
71 /-- A stored constant: its declared type. -/
72 | const {Γ : List Expr} {c : Name} {ls : List Level} {ci : ConstInfo} :
73 env.find? c = some ci → ls.length = ci.lparams.length →
74 InferIO env Γ (const c ls) (ci.type.instL ci.lparams ls)
75 /-- `∀`-formation: the sorts of the domain and the body. -/
76 | pi {Γ : List Expr} {A B s t : Expr} {u v : Level} :
77 InferIO env Γ A s → Red env Γ s (sort u) →
78 InferIO env (A :: Γ) B t → Red env (A :: Γ) t (sort v) →
79 InferIO env Γ (pi A B) (sort (.imax u v))
80 /-- Lambda: the `∀` of the body's type; the domain is not checked. -/
81 | lam {Γ : List Expr} {A b bt : Expr} :
82 InferIO env (A :: Γ) b bt → InferIO env Γ (lam A b) (pi A bt)
83 /-- **Application without a certificate**: the head's type reduces
84 to a `∀`, and the result is its body at the argument. The
85 argument's type is not inferred. -/
86 | app {Γ : List Expr} {f a tf A B : Expr} :
87 InferIO env Γ f tf → Red env Γ tf (pi A B) →
88 InferIO env Γ (app f a) (B.inst a)
89 /-- **`let`, by substitution**:
90 as official `infer_only`, the value is not checked
91 against the type — the full grade (`Infer.letE`) checks it — and the
92 body with the value substituted is inferred at the io grade. The
93 soundness proof needs no check on the value (`InferIO.letE_sound`). -/
94 | letE {Γ : List Expr} {T v b B : Expr} :
95 InferIO env Γ (b.inst v) B →
96 InferIO env Γ (letE T v b) B
: the rules of Section 2.3.3 without app’s comparison of the argument’s type with the domain, without the lambda’s check of its domain, and without the check of a let-binding’s value against its type.

Its result is not always a type of the term: (𝜆ℎ:𝖥𝖺𝗅𝗌𝖾.(ℎ.𝖾𝗅𝗂𝗆:𝖭𝖺𝗍))0 gets the type Nat, is well-denoted, and denotes the point (the lambda is an abstraction over an empty domain), which is no member of the set Nat denotes. What holds is a hereditary claimwhitepaper/Fragment/IOGrade.lean:L149-L173149/-- **Membership with the type's invariant.** -/
150def IOMem (T : Expr) (ρ : Nat → V) (v : V) : Prop :=
151 WellDenoted M φ ρ T ∧ IsTy (interp M φ ρ T) ∧ v ∈ˢ interp M φ ρ T
152
153/-- **The hereditary part**, by recursion on the type's syntax: at a
154`∀`, a graph over its domain that is not everywhere the point, whose
155applications satisfy the claim at the body. Nothing at any other
156type. -/
157def IOHered : Expr → (Nat → V) → V → Prop
158 | .pi A B, ρ, v =>
159 WellDenoted M φ ρ A ∧ IsTy (interp M φ ρ A) ∧
160 (∃ F : V → V, v = graph F (interp M φ ρ A)) ∧
161 (∃ x, x ∈ˢ interp M φ ρ A ∧ app v x ≠ pt) ∧
162 ∀ x, x ∈ˢ interp M φ ρ A →
163 app v x = pt ∨ IOMem M φ B (cons x ρ) (app v x) ∨ IOHered B (cons x ρ) (app v x)
164 | .bvar _, _, _ => False
165 | .sort _, _, _ => False
166 | .const _ _, _, _ => False
167 | .app _ _, _, _ => False
168 | .lam _ _, _, _ => False
169 | .letE _ _ _, _, _ => False
170
171/-- **The io claim**: the point, a member, or hereditarily a member. -/
172def IORel (T : Expr) (ρ : Nat → V) (v : V) : Prop :=
173 v = pt ∨ IOMem M φ T ρ v ∨ IOHered M φ T ρ v
𝐻𝜌(𝑇,𝑤) about the inferred type 𝑇 and the value 𝑤=⟦𝑒⟧𝜌: the value is the point, or a member of the type, or, when the type is syntactically a Π-type, a graph over its domain whose applications satisfy the claim at the Π-type’s body. For a term 𝑇, an environment 𝜌 and a set 𝑤,

𝐻𝜌(𝑇,𝑤)⟺𝑤=𝗉𝗍∨(𝜌⊧𝑇,⟦𝑇⟧𝜌a type,𝑤∈⟦𝑇⟧𝜌)∨𝐻𝜌′(𝑇,𝑤),

where 𝐻𝜌′(𝑇,𝑤) holds only when 𝑇 is a Π-type ∀𝑥:𝐴.𝐵, ⟦𝐴⟧𝜌 is a type, 𝑤 is a graph over ⟦𝐴⟧𝜌 with 𝑤⋅𝑣′≠𝗉𝗍 for some 𝑣′∈⟦𝐴⟧𝜌, and 𝐻𝜌,𝑥↦𝑣(𝐵,𝑤⋅𝑣) for every 𝑣∈⟦𝐴⟧𝜌. It is proved for every rulewhitepaper/Fragment/IOGrade.lean:L362-L363362theorem inferIO_sound : ∀ {Γ : List Expr} {e T : Expr},
363 InferIO env Γ e T → InferIOSem m φ Γ e T
of infer_only.

The claim serves two consumers. One is proof irrelevance with both types inferred by infer_only (the rule’s casewhitepaper/Fragment/IOGrade.lean:L419-L422419theorem proofIrrelIO_sound {Γ : List Expr} {a ta tta b : Expr} {u : Level}
420 (hta : InferIO env Γ a ta) (htta : InferIO env Γ ta tta) (hu : Red env Γ tta (.sort u))
421 (hu0 : LevelOracle.eq u .zero = true) :
422 DefEqSem m φ Γ a b := by
): a value whose type has sort Prop is the point, the hereditary case included, because the body of a Π-type of sort Prop has sort Prop. The other is 𝜂 against a term whose head is a variable or a constant, whose claim is never the hereditary onewhitepaper/Fragment/IOGrade.lean:L440-L443440theorem IORel_neutral : ∀ {Γ : List Expr} {e T : Expr},
441 InferIO env Γ e T → e.atomHead →
442 ∀ ρ, Sat m.M φ Γ ρ → WellDenoted m.M φ ρ e →
443 interp m.M φ ρ e = pt ∨ IOMem m.M φ T ρ (interp m.M φ ρ e)
(the rule’s casewhitepaper/Fragment/IOGrade.lean:L467-L470467theorem etaIO_sound {Γ : List Expr} {A₁ b₁ b tb A₂ B t₁ : Expr}
468 (htb : InferIO env Γ b tb) (hb : b.atomHead) (hr : Red env Γ tb (.pi A₂ B))
469 (hA : DefEqSem m φ Γ A₂ A₁)
470 (hbody : DefEqSem m φ (A₁ :: Γ) b₁ (.app (b.liftN 1) (.bvar 0)))
). The bodies’ types at lambda congruence and 𝜂 are not among them, as Section 2.8 showed, so the checker infers those by full inference and keeps the results of the two modes apart.

In con-leche The checker’s cheaper mode is infer_only exactlyConLeche/Kernel/Core.lean:L1327-L13321327/-- **The io inference body** (tasks #161, #170, #346): official's
1328`infer_type_core` with `infer_only = true`. It differs from
1329`inferBody` at three clauses: an application's argument is not
1330checked against the domain, a λ's domain is not checked to be a type,
1331and a `let`'s type and value are not checked (the body is inferred at
1332the value). The computed types and the "function expected" rejection
. Like it, the mode does not check a let-binding’s value against its type (full inference does, Section 2.3.3); the soundness proof needs no such check, since the value is substituted.

2.10. The argument in brief

Three points of this section run through the rest of the paper. The claims of reduction and equality are conditional: they say nothing about a term that denotes the point. The checks of the certification tax are exactly what a typing judgement would otherwise supply: a common type for the two bodies at lambda congruence and 𝜂, and, at the certified case of ι, the typing of the constructor application. And the proof uses no subject reduction, no confluence, no injectivity of Π-types and no unique typing; it needs only the laws of the set theory and the derivations of the checker’s three relations.

3. Adding definitions

§2 had no environment. This section adds one: the constants that refer to its entries, the rule 𝛿 that unfolds a definition, and the model of the environment, from which the interpretation reads a constant. The environment grows one declaration at a time, each checked by the relations of §2 extended by the rules below. For each step we say what the checker checks, what it stores, and how the model grows so that its laws keep holding. This section covers definitions; inductive types, the rule 𝜄 and the consistency corollary follow in Section 4.

The environment 𝐸, fixed throughout like the valuation, is a list of the constantswhitepaper/Fragment/Env.lean:L115-L131115/-- **The environment**: the accepted constants, most recent first. A
116name is stored at most once; `find?` reads the first entry. -/
117structure Env where
118 /-- The stored constants. -/
119 consts : List (Name × ConstInfo)
120 deriving DecidableEq
121
122namespace Env
123
124/-- Look a name up. -/
125def find? (env : Env) (n : Name) : Option ConstInfo := env.consts.lookup n
126
127/-- The empty environment. -/
128def empty : Env := ⟨[]⟩
129
130/-- Store one more constant. -/
131def add (env : Env) (n : Name) (ci : ConstInfo) : Env := ⟨(n, ci) :: env.consts⟩
accepted so far, most recent firstConLeche/Kernel/Env.lean:L464464structure Env where
. A stored constantwhitepaper/Fragment/Env.lean:L66-L106 66inductive ConstKind where
67 /-- A definition: its value unfolds (δ). -/
68 | defn (value : Expr)
69 /-- An inductive type former with `numParams` parameters,
70 `numIndices` indices and these constructors — and the block's
71 specification it was generated from (`Spec.lean`), which a later
72 block nesting through this one reads back (con-leche stores the
73 block's shape with the former likewise, `IndCaps`). -/
74 | induct (numParams numIndices : Nat) (ctors : List Name) (spec : IndSpec)
75 /-- A constructor of the inductive `induct`, with `numParams`
76 parameters (the inductive's) and `nfields` fields. -/
77 | ctor (induct : Name) (numParams nfields : Nat)
78 /-- A recursor with the given telescope shape — `numParams`
79 parameters, `numMotives` motives, `numMinors` minor premises,
80 `numIndices` indices, then the major premise — and its rules. -/
81 | recursor (numParams numMotives numMinors numIndices : Nat) (rules : List RecRule)
82 /-- **An assumption**: a constant known by its type alone — a
83 theorem's statement, a hole, or a definition whose value is left
84 out (`Modular.lean`). It never unfolds. -/
85 | assumed
86 deriving DecidableEq
87
88namespace ConstKind
89
90/-- The value a definition unfolds to. -/
91def value? : ConstKind → Option Expr
92 | defn v => some v
93 | _ => none
94
95end ConstKind
96
97/-- A stored constant: its level parameters, its type (closed, over
98those parameters) and its kind. -/
99structure ConstInfo where
100 /-- The level parameters. -/
101 lparams : List Name
102 /-- The declared type, a closed term over `lparams`. -/
103 type : Expr
104 /-- The kind. -/
105 kind : ConstKind
… 1 more lines
has its level parameters 𝑝⃗, its type (a closed term over 𝑝⃗) and its kindConLeche/Kernel/Env.lean:L291-L314291inductive ConstantInfo where
292 | axiomInfo (val : ConstantVal)
293 | defnInfo (val : ConstantVal) (value : Expr) (hint : ReducibilityHint)
294 | thmInfo (val : ConstantVal)
295 /-- An inductive type former (whnf-stuck) with its capabilities. -/
296 | indInfo (val : ConstantVal) (caps : IndCaps)
297 /-- A constructor (whnf-stuck; the iota target), with its family's name
298 (official's `ConstructorVal.induct`): the head constant of its declared
299 type's result, which its install reads off the member it is checked
300 against (an environment invariant, `CtorWF`). The readers that need the
301 family (the ι case split, the rescues, η) look it up by this name instead
302 of walking the type. -/
303 | ctorInfo (val : ConstantVal) (numParams numFields : Nat) (induct : Name)
304 /-- A recursor with its iota rules and the record's K flag (official's
305 `recursor_val::is_k`, read off the stream's record; the block's job
306 checks it). Only the two sums the
307 firing path reads are stored: `majorIdx` (= numParams + numMotives +
308 numMinors + numIndices, the major premise's argument position) and
309 `rulePrefix` (= numParams + numMotives + numMinors, the length of the
310 argument prefix a rule's rhs is applied to). The individual counts
311 are consumed at its check only and are not stored. -/
312 | recInfo (val : ConstantVal) (majorIdx rulePrefix : Nat)
313 (isK : Bool) (rules : List RecRule)
314 deriving DecidableEq, Repr, Inhabited
. We write (𝑐.{𝑝⃗}:𝑇)∈𝐸 for “𝑐 is stored with parameters 𝑝⃗ and type 𝑇”, and (𝑐.{𝑝⃗}:𝑇≔𝑣)∈𝐸 when it is a definition with value 𝑣. A definition carries a value. The other kinds are the type former, constructor and recursor that an inductive block stores (Section 4.1), and the assumption, a type without a value, which Section 7 uses for a theorem and for a definition whose value is not shown. A name is stored at most once.

Constants. The grammar of Section 2.1 gains one form: a constant 𝑐whitepaper/Fragment/Syntax.lean:L35-L3635 /-- A constant of the environment at a level instantiation. -/
36 | const (c : Name) (ls : List Level)
of the environment, used at a list of levels ℓ⃗, one per level parameterConLeche/Kernel/Expr.lean:L428-L438428inductive Expr where
429 | bvar (i : Nat)
430 | fvar (idx : Nat) (type : Expr)
431 | sort (u : Level)
432 | const (n : Name) (us : List Level)
433 | app (f a : Expr)
434 | lam (type body : Expr)
435 | forallE (type body : Expr)
436 | letE (type value body : Expr)
437 | lit (l : Literal)
438 | proj (structName : Name) (idx : Nat) (e : Expr)
of its declaration.

𝑒⩴…|𝑐.{ℓ⃗}

Level instantiationwhitepaper/Fragment/Syntax.lean:L112-L121112/-- Instantiate the level parameters `ps` at the levels `ls`, in
113sorts and constants. -/
114def instL (ps : List Name) (ls : List Level) : Expr → Expr
115 | bvar i => bvar i
116 | sort u => sort (u.subst ps ls)
117 | const c us => const c (us.map (Level.subst ps ls))
118 | app f a => app (instL ps ls f) (instL ps ls a)
119 | lam A b => lam (instL ps ls A) (instL ps ls b)
120 | pi A B => pi (instL ps ls A) (instL ps ls B)
121 | letE T v b => letE (instL ps ls T) (instL ps ls v) (instL ps ls b)
𝑒[𝑝⃗≔ℓ⃗], used when a constant declared with level parameters 𝑝⃗ is taken at the levels ℓ⃗, replaces the parameters in sorts and in the level lists of constants (as in con-lecheConLeche/Kernel/Level.lean:L234-L247234def Expr.instantiateLevelParams (ks : List Name) (us : List Level) : Expr → Expr
235 | .bvar i => .bvar i
236 | .fvar idx ty => .fvar idx (ty.instantiateLevelParams ks us)
237 | .sort u => .sort (Level.subst ks us u)
238 | .const n vs => .const n (vs.map (Level.subst ks us))
239 | .app f a => .app (f.instantiateLevelParams ks us) (a.instantiateLevelParams ks us)
240 | .lam ty body =>
241 .lam (ty.instantiateLevelParams ks us) (body.instantiateLevelParams ks us)
242 | .forallE ty body =>
243 .forallE (ty.instantiateLevelParams ks us) (body.instantiateLevelParams ks us)
244 | .letE ty val body => .letE (ty.instantiateLevelParams ks us)
245 (val.instantiateLevelParams ks us) (body.instantiateLevelParams ks us)
246 | .lit l => .lit l
247 | .proj s i e => .proj s i (e.instantiateLevelParams ks us)
).

The rules for constants. A constant has its declared typewhitepaper/Fragment/Rules.lean:L749-L753749 /-- A stored constant at the right number of levels has its
750 declared type, instantiated (`Infer.const`, `Rel.lean:559`). -/
751 | const {Γ : List Expr} {c : Name} {ls : List Level} {ci : ConstInfo} :
752 env.find? c = some ci → ls.length = ci.lparams.length →
753 Infer env Γ (const c ls) (ci.type.instL ci.lparams ls)
at the levels it is used at, and two constants of the same name are comparedwhitepaper/Fragment/Rules.lean:L563-L566563 /-- Two constants of the same name at oracle-equal levels
564 (`DefEq.const`, `Rel.lean:384`). -/
565 | const {Γ : List Expr} {c : Name} {ls ls' : List Level} :
566 Level.eqList ls ls' = true → DefEq env Γ (const c ls) (const c ls')
through the level oracle (in con-leche: inferenceConLeche/Rules/Rel.lean:L599-L605599 | const {g : Grade} {d : Nat} {n : Name} {us : List Level}
600 {ci : ConstantInfo} :
601 env.find? n = some ci →
602 us.length = ci.toConstantVal.levelParams.length →
603 Infer env g d (.const n us)
604 (ci.toConstantVal.type.instantiateLevelParams
605 ci.toConstantVal.levelParams us)
and equalityConLeche/Rules/Rel.lean:L371-L376371 DefEq env d (.fvar i ty₁) (.fvar i ty₂)
372 /-- Two constants of the same name at equivalent levels
373 (`Kernel/Core.lean`). -/
374 | const {d : Nat} {n : Name} {us us' : List Level} :
375 Level.isEquivList us us' = some true →
376 DefEq env d (.const n us) (.const n us')
).

(𝑐.{𝑝⃗}:𝑇)∈𝐸|ℓ⃗|=|𝑝⃗|Γ⊢𝑐.{ℓ⃗}⇒𝑇[𝑝⃗≔ℓ⃗]constℓ⃗≐ℓ⃗′Γ⊢𝑐.{ℓ⃗}≡𝑐.{ℓ⃗′}const

The 𝛿 rule. A definition unfolds to its valuewhitepaper/Fragment/Rules.lean:L88-L9488 /-- **δ** (`Red.delta`, `Rel.lean:140`): a definition unfolds to its
89 value, at the use's level instantiation. (With `appFn`, an applied
90 definition unfolds at its head.) -/
91 | delta {Γ : List Expr} {c : Name} {ls : List Level} {ci : ConstInfo} {v : Expr} :
92 env.find? c = some ci → ci.value? = some v →
93 ls.length = ci.lparams.length →
94 Red env Γ (const c ls) (v.instL ci.lparams ls)
at the levels it is used at (as in con-lecheConLeche/Rules/Rel.lean:L142-L146142 /-- **δ** (`whnfStep`, `Kernel/Core.lean`; also every unfolding of
143 `lazyDeltaStep`): one definition unfolded
144 at the head. A theorem never unfolds (`unfoldDefinition`). -/
145 | delta {d : Nat} {e e' : Expr} :
146 unfoldDefinition env e = some e' → Red env d e e'
). With the head rule of Section 2.3, an applied definition unfolds at its head.

(𝑐.{𝑝⃗}:𝑇≔𝑣)∈𝐸|ℓ⃗|=|𝑝⃗|Γ⊢𝑐.{ℓ⃗}⇝𝑣[𝑝⃗≔ℓ⃗]delta

What a definition must satisfy. Before the checker stores a definition 𝑐 with parameters 𝑝⃗, type 𝑇 and value 𝑣, it checks four thingswhitepaper/Fragment/Decl.lean:L592-L606592/-- **A definition is accepted** (con-leche's `checkDefnVal`): the
593name is fresh, the declared type's type reduces to a sort, the
594value's inferred type is definitionally equal to the declared type,
595and both terms use only the declared level parameters. That is the
596one scope condition the typing derivations do not give (the sort rule
597accepts `Sort u` at any level `u`); closedness and stored constants
598they do give (`Infer.closedAt`, `Infer.consts`,
599`ScopeOfInfer.lean`), so the environment section recovers the full
600scope of both terms (`DefOk.type_scoped`, `DefOk.value_scoped`). -/
601def DefOk (env : Env) (c : Name) (ci : ConstInfo) : Prop :=
602 env.find? c = none ∧
603 (∃ s u, Infer env [] ci.type s ∧ Red env [] s (.sort u)) ∧
604 (∃ v T, ci.kind = .defn v ∧ Infer env [] v T ∧ DefEq env [] T ci.type ∧
605 v.lparamsIn ci.lparams = true) ∧
606 ci.type.lparamsIn ci.lparams = true
(in con-leche: the common checksConLeche/Kernel/CheckerBase.lean:L106-L130106def checkConstantVal (ops : CheckerOps m) (env : Env) (cv : ConstantVal)
107 (allowOp : Bool := false) (allowReduce : Bool := false) (allowSorry : Bool := false) :
108 m Unit := do
109 if (env.find? cv.name).isSome then
110 throw (.invalid s!"duplicate declaration {cv.name}")
111 if natOpName cv.name && !allowOp then
112 throw (.invalid s!"a certified Nat operation's name, not a definition: {cv.name}")
113 if reduceOpNames.contains cv.name && !allowReduce then
114 throw (.invalid s!"a compiler-trust name, not an opaque constant: {cv.name}")
115 if sorryAxNameAt cv.name && !allowSorry then
116 throw (.invalid s!"the tolerated axiom's name, not an axiom: {cv.name}")
117 unless litShapeOk (.axiomInfo cv) do
118 throw (.notImplemented s!"a declaration at a literal's name with another shape ({cv.name})")
119 unless Name.nodup cv.levelParams do
120 throw (.invalid s!"duplicate universe parameters in {cv.name}")
121 unless cv.type.looseBVarsBounded 0 do
122 throw (.invalid s!"loose bound variable in type of {cv.name}")
123 if cv.type.hasFvar then
124 throw (.invalid s!"unexpected free variable in type of {cv.name}")
125 unless cv.type.allLevelParamsDefined cv.levelParams do
126 throw (.invalid s!"undeclared universe parameter in type of {cv.name}")
127 unless cv.type.constsResolve env do
128 throw (unresolvedConstsErrorL (strLitStored env) s!"type of {cv.name}" cv.type)
129 let stype ← ops.inferType env 0 cv.type
130 let _u ← ops.ensureSort env 0 stype
and the value checkConLeche/Kernel/Checker.lean:L34-L4734def checkDefnVal (ops : CheckerOps m) (env : Env) (cv : ConstantVal)
35 (value : Expr) (hint : ReducibilityHint) : m Env := do
36 unless value.looseBVarsBounded 0 do
37 throw (.invalid s!"loose bound variable in value of {cv.name}")
38 if value.hasFvar then
39 throw (.invalid s!"unexpected free variable in value of {cv.name}")
40 unless value.allLevelParamsDefined cv.levelParams do
41 throw (.invalid s!"undeclared universe parameter in value of {cv.name}")
42 unless value.constsResolve env do
43 throw (unresolvedConstsErrorL (strLitStored env) s!"value of {cv.name}" value)
44 let vtype ← ops.inferType env 0 value
45 unless ← ops.isDefEq env 0 vtype cv.type do
46 throw (.invalid s!"type mismatch in definition {cv.name}")
47 pure ⟨.defnInfo cv value hint :: env.consts, env.tables⟩
):

The type and value of an accepted definition are therefore closed, mention only constants stored before it and use only its declared level parameters: the first two follow from the inference derivations in the empty context (shown below), the third is checked. These three facts let the model read a stored term without looking at anything added later, because the interpretation of a term depends only on the constants and the free variables it mentions and the level parameters it uses (constantswhitepaper/Fragment/Hygiene.lean:L585-L587585theorem interp_consts {e : Expr} (h : ∀ c ∈ e.consts, ∀ ls, M c ls = M' c ls) {ρ : Nat → V} :
586 interp M φ ρ e = interp M' φ ρ e := by
587 induction e generalizing ρ with
, variableswhitepaper/Fragment/Hygiene.lean:L466-L468466theorem interp_closedAt {k : Nat} {e : Expr} (he : e.closedAt k = true) {ρ ρ' : Nat → V}
467 (h : ∀ i, i < k → ρ i = ρ' i) : interp M φ ρ e = interp M φ ρ' e := by
468 induction e generalizing k ρ ρ' with
, parameterswhitepaper/Fragment/Hygiene.lean:L644-L646644theorem interp_lparams {ps : List Name} {e : Expr} (he : e.lparamsIn ps = true)
645 (h : ∀ n ∈ ps, φ n = φ' n) {ρ : Nat → V} : interp M φ ρ e = interp M φ' ρ e := by
646 induction e generalizing ρ with
).

The interpretation, extended. The interpretation of Section 2.5 gains one parameter, an assignment 𝑀 of a set to every constant at every list of concrete levels, and one clause: a constant denotes what the assignment sayswhitepaper/Fragment/Interp.lean:L142142 | _, .const c ls => M c (ls.map (Level.eval φ))
,

⟦𝑐.{ℓ⃗}⟧𝜌=𝑀(𝑐,𝜑(ℓ⃗))

with 𝜑(ℓ⃗) the list of the levels’ values. Like 𝜑, the assignment stays implicit in ⟦𝑒⟧𝜌 and in 𝜌⊧𝑒. The interpretation stays term-directed: 𝑀 is consulted at a constant the way 𝜌 is at a variable, and the environment 𝐸 itself, with its stored types and values, is never read. The semantic invariant gains the clause that a constant, like a variable or a sort, is always well-denoted. A fourth lemma joins those of Section 2.5, by the same induction: instantiating level parameters is changing the valuationwhitepaper/Fragment/Interp.lean:L256-L258256theorem interp_instL (ps : List Name) (ls : List Level) :
257 ∀ (e : Expr) (ρ : Nat → V),
258 interp M φ ρ (e.instL ps ls) = interp M (Level.substVal φ ps ls) ρ e := by
,

⟦𝑒[𝑝⃗≔ℓ⃗]⟧𝜌𝜑=⟦𝑒⟧𝜌𝜑[𝑝⃗↦𝜑(ℓ⃗)],

where the superscript shows the valuation and 𝜑[𝑝⃗↦𝑛⃗] sends the parameters 𝑝⃗ to the numbers 𝑛⃗ and agrees with 𝜑 elsewhere.

The contract. What the soundness theorem, extended below, assumes of the environment is a modelwhitepaper/Fragment/EnvModel.lean:L300-L364300/-- **A model of an environment**: the assignment and the laws. -/
301structure EnvModel (V : Type u) [SetLib V] (env : Env) where
302 /-- The set of every constant at every list of concrete levels. -/
303 M : Name → List Nat → V
304 /-- Every stored constant's type, instantiated, is well-denoted and a
305 type, and the constant is a member of it — at every valuation and every
306 environment (the types are closed, so `ρ` is irrelevant, and stating
307 it for all `ρ` saves a closedness lemma). -/
308 type_ok : ∀ (c : Name) (ci : ConstInfo), env.find? c = some ci →
309 ∀ (φ : Name → Nat) (ρ : Nat → V) (ls : List Level), ls.length = ci.lparams.length →
310 WellDenoted M φ ρ (ci.type.instL ci.lparams ls) ∧
311 IsTy (interp M φ ρ (ci.type.instL ci.lparams ls)) ∧
312 M c (ls.map (Level.eval φ)) ∈ˢ interp M φ ρ (ci.type.instL ci.lparams ls)
313 /-- A definition's value, instantiated, is well-denoted and denotes
314 the constant. -/
315 unfold : ∀ (c : Name) (ci : ConstInfo) (v : Expr), env.find? c = some ci →
316 ci.value? = some v →
317 ∀ (φ : Name → Nat) (ρ : Nat → V) (ls : List Level), ls.length = ci.lparams.length →
318 WellDenoted M φ ρ (v.instL ci.lparams ls) ∧
319 interp M φ ρ (v.instL ci.lparams ls) = M c (ls.map (Level.eval φ))
320 /-- Every plain rule of every stored recursor satisfies its ι law. -/
321 rec_rules : ∀ (c : Name) (ci : ConstInfo) (numParams numMotives numMinors numIndices : Nat)
322 (rules : List RecRule),
323 env.find? c = some ci →
324 ci.kind = .recursor numParams numMotives numMinors numIndices rules →
325 ∀ rl ∈ rules, rl.inst = none → ∀ cij : ConstInfo, env.find? rl.ctor = some cij →
326 RecRuleLaw M c ci numParams (numParams + numMotives + numMinors)
327 (numParams + numMotives + numMinors + numIndices) rl cij
328 /-- Every nested rule of every stored recursor satisfies its ι law,
329 at its constructor's own parameter count. -/
330 rec_rules_nested : ∀ (c : Name) (ci : ConstInfo) (numParams numMotives numMinors numIndices : Nat)
331 (rules : List RecRule),
332 env.find? c = some ci →
333 ci.kind = .recursor numParams numMotives numMinors numIndices rules →
334 ∀ rl ∈ rules, ∀ (lvs : List Level) (pinst : List Expr), rl.inst = some (lvs, pinst) →
335 ∀ (cij : ConstInfo) (I : Name) (nPc nf : Nat), env.find? rl.ctor = some cij →
336 cij.kind = .ctor I nPc nf →
337 RecRuleLawN M c ci nPc (numParams + numMotives + numMinors)
338 (numParams + numMotives + numMinors + numIndices) rl cij
339 /-- Every stored inductive family's fibres are truth values where its
… 25 more lines
: an assignment 𝑀(𝑐,𝑛⃗) of a set to every constant 𝑐 and every list of natural numbers 𝑛⃗ (the values of its level parameters), satisfying two laws (four more, for inductive types, join in Section 4). Throughout, ℓ⃗ ranges over level lists with |ℓ⃗|=|𝑝⃗|, 𝜑 over valuations and 𝜌 over variable environments, and 𝜌⊧𝑒 is the semantic invariant of Section 2.6.

Definition 4 (Model of an environment).

  1. Typingwhitepaper/Fragment/EnvModel.lean:L304-L312304 /-- Every stored constant's type, instantiated, is well-denoted and a
    305 type, and the constant is a member of it — at every valuation and every
    306 environment (the types are closed, so `ρ` is irrelevant, and stating
    307 it for all `ρ` saves a closedness lemma). -/
    308 type_ok : ∀ (c : Name) (ci : ConstInfo), env.find? c = some ci →
    309 ∀ (φ : Name → Nat) (ρ : Nat → V) (ls : List Level), ls.length = ci.lparams.length →
    310 WellDenoted M φ ρ (ci.type.instL ci.lparams ls) ∧
    311 IsTy (interp M φ ρ (ci.type.instL ci.lparams ls)) ∧
    312 M c (ls.map (Level.eval φ)) ∈ˢ interp M φ ρ (ci.type.instL ci.lparams ls)
    : for every (𝑐.{𝑝⃗}:𝑇)∈𝐸,

    𝜌⊧𝑇[𝑝⃗≔ℓ⃗],⟦𝑇[𝑝⃗≔ℓ⃗]⟧𝜌is a type,and𝑀(𝑐,𝜑(ℓ⃗))∈⟦𝑇[𝑝⃗≔ℓ⃗]⟧𝜌.
  2. Unfoldingwhitepaper/Fragment/EnvModel.lean:L313-L319313 /-- A definition's value, instantiated, is well-denoted and denotes
    314 the constant. -/
    315 unfold : ∀ (c : Name) (ci : ConstInfo) (v : Expr), env.find? c = some ci →
    316 ci.value? = some v →
    317 ∀ (φ : Name → Nat) (ρ : Nat → V) (ls : List Level), ls.length = ci.lparams.length →
    318 WellDenoted M φ ρ (v.instL ci.lparams ls) ∧
    319 interp M φ ρ (v.instL ci.lparams ls) = M c (ls.map (Level.eval φ))
    : for every (𝑐.{𝑝⃗}:𝑇≔𝑣)∈𝐸,

    𝜌⊧𝑣[𝑝⃗≔ℓ⃗]and⟦𝑣[𝑝⃗≔ℓ⃗]⟧𝜌=𝑀(𝑐,𝜑(ℓ⃗)).

In words: at every instantiation of the declared level parameters, every stored constant is a member of its type, which is well-denoted and a type in the sense of Section 2.5, and a definition’s value is well-denoted and denotes the constant. The semantic invariant is part of the laws because the soundness induction needs it of every term it reads, stored ones included. The main theorem is stated over the input itself, each declared constant holding on its own (Definition 11); a model of the environment gives one (Theorem 12).

In con-leche The real proof’s model carries the same two laws among others (the carrier’s invariantConLeche/Model/Env/EnvModelM.lean:L229-L252229structure EnvModelM (env : Env) where
230 /-- the environment carrier, contained -/
231 base2 : EnvModel V env
232 /-- every stored type reads, at every ground assignment -/
233 type_reads : ∀ c ∈ env.consts, ∀ ψ : Name → Nat,
234 ∃ ta : Term,
235 denote base2.acval env ψ 0 c.toConstantVal.type = some ta
236 /-- the stored types' readings are graded types -/
237 type_wellDenotedTy : ∀ c ∈ env.consts, ∀ (ψ : Name → Nat) (ta : Term),
238 denote base2.acval env ψ 0 c.toConstantVal.type = some ta →
239 ∀ ρ : Nat → V, WellDenotedTy V ρ ta
240 /-- stored constants inhabit their types' readings (a projection
241 table's constant type is the closed dummy `Sort 1` and its leaf is
242 `Sort 0`, so the row holds of tables too; that a table is not a term
243 is `inferTypeCore`'s own rejection of a `.const` naming one) -/
244 mem_type : ∀ c ∈ env.consts,
245 ∀ (ψ : Name → Nat) (ta : Term),
246 denote base2.acval env ψ 0 c.toConstantVal.type = some ta →
247 ∀ ρ : Nat → V,
248 interp V ρ (base2.acval c.name ψ) ∈ˢ interp V ρ ta
249 /-- stored definition and theorem values read, to the constant's own
250 leaf (existence) -/
251 defn_reads : AcvalDefnInst base2
252 /-- the two `Nat`-literal head facts, at every assignment -/
).

The empty environment has a modelwhitepaper/Fragment/EnvModel.lean:L366-L375366/-- The empty environment has a model: any assignment, vacuous laws. -/
367def EnvModel.empty (M : Name → List Nat → V) : EnvModel V Env.empty where
368 M := M
369 type_ok := fun _ _ h => by simp at h
370 unfold := fun _ _ _ h => by simp at h
371 rec_rules := fun _ _ _ _ _ _ _ h => by simp at h
372 rec_rules_nested := fun _ _ _ _ _ _ _ h => by simp at h
373 ind_fib := fun _ _ _ _ _ _ h => by simp at h
374 rec_rules_k := fun _ _ _ _ _ _ _ h => by simp at h
375 rec_rules_slot := fun _ _ _ _ _ _ _ h => by simp at h
: every assignment is one, since both laws quantify over stored constants.

Soundness, extended. Theorem 2 holds for the relations extended by the three rules above, with one more hypothesis: fix a model of the environment, a valuation 𝜑, and let 𝜌 satisfy Γ; then the three claims hold as statedwhitepaper/Fragment/Sound.lean:L2293-L22972293theorem soundness [LevelOracle] (m : EnvModel V env) (φ : Name → Nat) :
2294 (∀ {Γ : List Expr} {e e' : Expr}, Red env Γ e e' → RedSem m φ Γ e e') ∧
2295 (∀ {Γ : List Expr} {a b : Expr}, DefEq env Γ a b → DefEqSem m φ Γ a b) ∧
2296 (∀ {Γ : List Expr} {e T : Expr}, Infer env Γ e T → InferSem m φ Γ e T) :=
2297 ⟨red_sound, defeq_sound, infer_sound⟩
, and Corollary 3 holds under every model. The induction of Section 2.7 gains three cases, one per rule.

Proof. Rule deltawhitepaper/Fragment/Sound.lean:L137-L143137theorem delta_sound {Γ : List Expr} {c : Name} {ls : List Level} {ci : ConstInfo} {v : Expr}
138 (hfind : env.find? c = some ci) (hv : ci.value? = some v)
139 (hls : ls.length = ci.lparams.length) :
140 RedSem m φ Γ (.const c ls) (v.instL ci.lparams ls) := by
141 intro ρ _ _ _
142 obtain ⟨hw, he⟩ := m.unfold c ci v hfind hv φ ρ ls hls
143 exact ⟨hw, by rw [interp_const, he]⟩
, 𝑐.{ℓ⃗}⇝𝑣[𝑝⃗≔ℓ⃗] for a definition 𝑐 with parameters 𝑝⃗ and value 𝑣, at |ℓ⃗|=|𝑝⃗| levels:
Law 2 says the instantiated value is well-denoted and denotes 𝑀(𝑐,𝜑(ℓ⃗)), which is what the constant denotesConLeche/Model/Rules/RedSound.lean:L252-L253252theorem Red.delta_soundU (hin : RulesInputs V m φ) {d : Nat} {e e' : Expr}
253 (h : ConLeche.unfoldDefinition env e = some e') : RedSemU m φ d e e' := by
. The redex’s semantic invariant is not used. Theorem 5 shows the law holds when a definition is added.

Rule const, equalitywhitepaper/Fragment/Sound.lean:L170-L172170theorem const_sound [LevelOracle] {Γ : List Expr} {c : Name} {ls ls' : List Level}
171 (h : Level.eqList ls ls' = true) : DefEqSem m φ Γ (.const c ls) (.const c ls') :=
172 fun _ _ _ _ _ _ => by simp [(Level.eqList_iff ls ls').mp h φ]
, 𝑐.{ℓ⃗}≡𝑐.{ℓ⃗′} when ℓ⃗≐ℓ⃗′ pointwise:
The oracle answers yes only if the levels agree at every valuation (Section 2.2), so the two constants read the same entry of 𝑀ConLeche/Model/Rules/DefEqSound.lean:L70-L7270theorem DefEq.const_soundU {d : Nat} {n : Name} {us us' : List Level}
71 (h : Level.isEquivList us us' = some true) :
72 DefEqSemU m φ d (.const n us) (.const n us') := by
.

Rule const, inferencewhitepaper/Fragment/Sound.lean:L267-L272267theorem const_sound {Γ : List Expr} {c : Name} {ls : List Level} {ci : ConstInfo}
268 (hfind : env.find? c = some ci) (hls : ls.length = ci.lparams.length) :
269 InferSem m φ Γ (.const c ls) (ci.type.instL ci.lparams ls) := by
270 intro ρ _
271 obtain ⟨hw, hT, hmem⟩ := m.type_ok c ci hfind φ ρ ls hls
272 exact ⟨trivial, hw, hT, hmem⟩
, 𝑐.{ℓ⃗}⇒𝑇[𝑝⃗≔ℓ⃗]:
The constant is well-denoted, and law 1 says its instantiated type is well-denoted, a type, and contains the constant’s setConLeche/Model/Rules/InferSound.lean:L210-L215210theorem Infer.const_sound (hin : RulesInputs V m φ) {g : Grade} {d : Nat}
211 {n : Name} {us : List Level} {ci : ConLeche.ConstantInfo}
212 (hf : env.find? n = some ci)
213 (hus : us.length = ci.toConstantVal.levelParams.length) :
214 InferSem m φ g d (.const n us)
215 (ci.toConstantVal.type.instantiateLevelParams ci.toConstantVal.levelParams us) := by
. □

Theorem 5 (Installing a definition). Let 𝑀 be a model of 𝐸, and let the definition 𝑐 with parameters 𝑝⃗, type 𝑇 and value 𝑣 pass the four checks above. Then the environment extended with 𝑐 has a modelwhitepaper/Fragment/InstallDef.lean:L351-L356351/-- **Installing a definition preserves having a model.** The new
352constant's set is its value's (`defVal`); every stored constant keeps
353its set. -/
354theorem install_def {env : Env} {c : Name} {ci : ConstInfo} (hs : Env.Scoped env)
355 (m : EnvModel V env) (hok : DefOk env c ci) :
356 ∃ m' : EnvModel V (env.add c ci), (∀ n, (env.find? n).isSome → ∀ ls, m'.M n ls = m.M n ls) ∧
𝑀′ (as in con-lecheConLeche/Model/Install.lean:L353-L355353theorem declStep_preserves_of_cons (mp : EnvModelM V env)
354 {c₀ : ConstantInfo} {A : (Name → Nat) → Term}
355 (hfresh : env.find? c₀.name = none)
) that agrees with 𝑀 on every constant of 𝐸 and gives 𝑐 its value’s set: for every list 𝑛⃗ of natural numbers of the length of 𝑝⃗, every valuation 𝜑 and every variable environment 𝜌,

𝑀′(𝑐,𝑛⃗)=⟦𝑣⟧𝜌𝜑[𝑝⃗↦𝑛⃗],

where 𝑣, which mentions no constant but old ones, is read under 𝑀 (equivalently, under 𝑀′).

Proof. Since 𝑣 is closed and uses no level parameter outside 𝑝⃗, neither the variable environment nor the rest of 𝜑 enters the right-hand side, so 𝑀′ is well defined. The old laws hold for 𝑀′ because no stored term mentions 𝑐whitepaper/Fragment/InstallDef.lean:L267-L270267
268/-- A model's laws survive changing the assignment away from the
269stored names: every stored term mentions only stored constants. -/
270def EnvModel.transport {env : Env} (m : EnvModel V env) (hs : Env.Scoped env)
. For the new constant we use Corollary 3 and the second claim of Theorem 2. From ⊢𝑣⇒𝑇′ the value and 𝑇′ are well-denoted and ⟦𝑣⟧∈⟦𝑇′⟧, a type; from ⊢𝑇⇒𝑆⇝𝖲𝗈𝗋𝗍𝑢 the type 𝑇 is well-denoted and a type. The second claim holds only of sides that are not the point, and a type is never the point (Section 2.5), so it applies to ⊢𝑇′≡𝑇 and gives ⟦𝑇′⟧=⟦𝑇⟧, hence ⟦𝑣⟧∈⟦𝑇⟧. This holds at every valuation, and instantiating the level parameters is the same as changing the valuation (above), so it holds at every ℓ⃗. Finally, 𝑣 and 𝑇 are closed and mention no constant but old ones, because the derivations are in the empty context, where no rule types a variablewhitepaper/Fragment/ScopeOfInfer.lean:L37-L3837theorem Infer.closedAt : ∀ {Γ : List Expr} {e T : Expr}, Infer env Γ e T →
38 e.closedAt Γ.length = true
and the constant rule requires the constant storedwhitepaper/Fragment/ScopeOfInfer.lean:L60-L6160theorem Infer.consts : ∀ {Γ : List Expr} {e T : Expr}, Infer env Γ e T →
61 ∀ c ∈ e.consts, (env.find? c).isSome
. So the two sets are the same under 𝑀′ as under 𝑀. That is law 1, and law 2 is the definition of 𝑀′ at 𝑐. □

In our proof the value’s inference supplies the premise of Corollary 3, the type’s sort and the equality ⊢𝑇′≡𝑇 carry its conclusion from 𝑇′ to 𝑇, which gives law 1, and law 2 holds by the choice of 𝑀′.

4. Adding inductive types

The second kind of declaration is an inductive block: a type former with its constructors and its recursor. It is checked and installed by the same shape of argument as a definition (Section 3), and its reduction rule 𝜄 reads the environment as 𝛿 does. What is new is the model. The family, the constructors and the recursor need sets that lie in their generated types (the typing law, law 1 of Definition 4), and the recursor’s set must compute by its rules: the 𝜄 law, a third law of the contract.

The construction is one chain. Strict positivity makes the block’s operator on families accessible (Section 4.2); an accessible operator has a closed family in the universe (Theorem 8); below a closed family the least fixed point is a set construction, and the family is that fixed point. Read backwards, its fixed-point equation says that every member of the family is built by a constructor; this inversion and the fixed point’s induction give the recursor, and with it the 𝜄 law (Theorem 10). Three further laws let most 𝜄 steps go without checking the constructor application (Section 4.2.8). The section ends with the main theorem and the consistency corollary (Section 4.3).

4.1. What is checked

An inductive block declares an indexed family by its constructors: one type, or one proposition, per choice of indices. At a valuation the family is type-valued or proposition-valued, as its result sort evaluates to a positive number or to 0. These are the two interpretations of a binder from §2, decided for a whole family at once. The fragment takes a block with one type former, neither mutual nor nested; nested blocks are the subject of Section 5. The block is given by a specificationwhitepaper/Fragment/Spec.lean:L80-L103 80/-- **The data of a single inductive block** without its class
81(con-leche's `MemberShape`/`InductiveShape`, `BlockShape.lean:62`,
82`SumParts.lean:36`). -/
83structure IndBase where
84 /-- The type former's name. -/
85 name : Name
86 /-- The block's level parameters. -/
87 lparams : List Name
88 /-- The parameter telescope (a context, innermost first). -/
89 params : List Expr
90 /-- The index telescope (a context under the parameters). -/
91 indices : List Expr
92 /-- The result sort `Sort u`. -/
93 sort : Level
94 /-- The constructors, in order. -/
95 ctors : List CtorSpec
96 /-- The recursor's name. -/
97 recName : Name
98 /-- Large elimination: the recursor eliminates into `Sort ℓ` for a
99 fresh level parameter `ℓ`; otherwise into `Prop`. -/
100 large : Bool
101 /-- The fresh elimination level parameter (read only if `large`). -/
102 elim : Name
103 deriving DecidableEq
(as in con-lecheConLeche/Kernel/Inductives/BlockShape.lean:L116-L134116structure BlockShape where
117 /-- the members in block order -/
118 members : List MemberShape
119 /-- the block's recursors, in the order the stream exports them (any
120 number, assigned to their members by their majors) -/
121 recs : List RecShape
122 /-- the shared parameter count -/
123 nP : Nat
124 /-- the recursors' fresh elimination level parameter (`large` only;
125 `.anonymous` for a small eliminator) -/
126 elim : Name
127 /-- the result sort (member 0's; the others are `Level.isEquiv` to it) -/
128 resSort : Level
129 /-- large eliminator (a fresh elimination level parameter in front) -/
130 large : Bool
131 /-- the result sort is provably `Prop` -/
132 isProp : Bool
133 deriving Repr, Inhabited
134
):

A field is one of two kindswhitepaper/Fragment/Spec.lean:L28-L4228/-- A constructor field, as the positivity check classifies it
29(con-leche's `RecFieldKind`, `FieldTele.lean:29`). Its domain is an
30expression under the parameters and the earlier fields. -/
31inductive Field where
32 /-- An ordinary field: any domain that does not mention the block. -/
33 | ordinary (A : Expr)
34 /-- A reflexive field: `∀ tele, I params es` — a function space into
35 the family at the block's parameters and the index expressions `es`;
36 `tele` is a context (innermost first) under the parameters and the
37 earlier fields, `es` a spine (outermost first) under `tele` too.
38 With an empty telescope the field is simply **recursive**: the
39 family itself (`reflexive [] es`) — one kind covers both, as the
40 generated terms and the model treat them alike. (Con-leche keeps
41 them apart: `RecFieldKind.recursive`/`.reflexive`, `FieldTele.lean`.) -/
42 | reflexive (tele : List Expr) (es : List Expr)
(as in con-lecheConLeche/Kernel/Inductives/Positivity.lean:L331-L341331/-- The field's kind as the run found it: hole-free, a member hole
332(finitary or under `Π` binders), an instantiation IN PROGRESS (a `Y`
333hole — only inside a container's constructors), or an accepted
334instantiation (under `Π` binders when `refl`). -/
335inductive NestFieldKind where
336 | ordinary
337 | recursive (tgt : Nat)
338 | reflexive (tgt : Nat)
339 | inProgress
340 | nested (refl : Bool)
341 deriving DecidableEq, Inhabited
):

Two conditions of shape come with the kinds. No field’s domain mentions 𝐼 anywhere else; this is strict positivitywhitepaper/Fragment/Decl.lean:L641-L655641/-- The scope of a field's pieces: with `k` earlier fields, an
642ordinary domain is in scope under the parameters and them; a
643reflexive field's telescope entries under the earlier telescope
644entries as well, and its index expressions under the whole telescope
645(under the parameters and the earlier fields alone when the telescope
646is empty); a reflexive field's index expressions are as many as the
647indices. No piece
648mentions the block (it is not stored in `env`): that is **strict
649positivity** in the shape the fragment admits (con-leche's
650`nestPos`, `ConLeche/Kernel/Inductives/Positivity.lean:1453`). -/
651def fieldScoped (env : Env) (k : Nat) : Field → Prop
652 | .ordinary A => Expr.Scoped env S.lparams (S.nP + k) A
653 | .reflexive tele es =>
654 (∀ t T, tele[t]? = some T → Expr.Scoped env S.lparams (S.nP + k + (tele.length - 1 - t)) T) ∧
655 es.length = S.nI ∧ (∀ e ∈ es, Expr.Scoped env S.lparams (S.nP + k + tele.length) e)
. And nothing after a reflexive field may depend on its valuewhitepaper/Fragment/Decl.lean:L658-L663658/-- **No field reads an earlier recursive field**: an ordinary domain
659and a reflexive field's telescope entries and index expressions do not
660use the variable of any earlier reflexive field (con-leche's `structUsedLater`
661guard, `StructParts.lean:393`, run by `nestCtors`, `Positivity.lean:1247`:
662the model reads the domains at a frame with arbitrary recursive slots). -/
663def fieldNoRecDep (earlier : List Field) : Field → Prop
(as in con-lecheConLeche/Kernel/Inductives/Positivity.lean:L721-L724721 if (List.range nF).any (fun i => ks.getD i .ordinary != .ordinary &&
722 structUsedLater (closeTelescope nds hi cur) 0 i) then
723 throw (.invalid "nested positivity: non valid occurrence of the datatypes being \
724 declared (a later field or the result depends on a recursive or nested field)")
and the official kernel), so that the model can read a constructor’s domains without knowing the values of its reflexive fields.

In con-leche Simple, mutual and nested blocks are checked uniformly (§5 of OVERVIEW.md); this section describes that check on a block of the fragment’s shape. Its positivity check classifies each field’s domain after weak head normal form, with 𝐼 at the block’s parameters replaced by a variable standing for the family being defined; Section 5 uses the same check (positivityConLeche/Kernel/Inductives/Positivity.lean:L910-L911910def nestPos (ops : CheckerOps m) (env : Env) (ctx : NestCtx) :
911 Nat → List NestHole → Nat → Nat → Expr → NestState → m (NestFieldKind × Expr × NestState)
).

Reflexive fields with a non-empty telescope matter to the model. A tree type with a constructor 𝗇𝗈𝖽𝖾:(𝖭𝖺𝗍→𝖳𝗋𝖾𝖾)→𝖳𝗋𝖾𝖾 has nodes with countably many children, so a node may have children of every finite depth, and the set of all trees is larger than the union of the sets of trees of depth 𝑘. Iterating the constructors 𝜔 times, which reaches every member of 𝖭𝖺𝗍, does not reach every tree, and a model must obtain the least fixed point some other way (Section 4.2).

4.1.1. The generated declarations

From the specification the checker generates the types of the type former, the constructors and the recursor, and the recursor’s rules. The type former’s type is the one displayed above; a constructor’s type is

∀𝑥⃗:𝑃⃗.∀𝑓⃗:𝐹⃗.𝐼𝑥⃗𝑒⃗𝑗

(the two generatorswhitepaper/Fragment/Decl.lean:L210-L217210/-- **The type former's type** `∀ params indices, Sort u`; no binder is
211a proposition. -/
212def indType : Expr := mkPis (S.indices ++ S.params) (.sort S.sort)
213
214/-- **A constructor's type** `∀ params fields, I params idx`; every
215binder is a proposition exactly when the family is. -/
216def ctorType (c : CtorSpec) : Expr :=
217 mkPis (S.fieldCtx c.fields ++ S.params) (S.famAt c.fields.length c.idx)
). The recursor eliminates into 𝖲𝗈𝗋𝗍ℓ, where the elimination level ℓ is either a fresh level parameter (large elimination) or 0 (small elimination); the elimination rule below says which.

In con-leche The input is a stream of raw declarations: the type former, the constructors and the recursor as the exporting toolchain stated them. The checker recovers the specification from the type former’s and the constructors’ types, and checks and stores those two as the stream declares them (a constructorConLeche/Kernel/Inductives/SumInstall.lean:L67-L6867/-- Stage 2, one constructor's type: the ordinary constant check (the
68constructor is stored AS DECLARED), the result
). The recursor it generates, as the official kernel does. From the stream’s recursor record it takes only the name, the level parameters and the type, which must be definitionally equal to the generated one, and the record’s two layout counts, which must equal the generated ones (the comparisonConLeche/Kernel/Inductives/GenRec.lean:L384-L406384only output a verdict): checked as a constant (`classConstOk`) and
385`isDefEq` to the stream's checked type `cvRi`. -/
386def classRecTyCheck (ops : CheckerOps m) (fe : FEnv) (cvRi cvG : ConstantVal) : m Unit := do
387 classConstOk ops fe cvG
388 unless ← ops.isDefEq fe.env 0 cvRi.type cvG.type do
389 throw (.invalid s!"generated recursor: the type of {cvG.name} is not the generated one \
390 (official: invalid recursor)")
391
392/-- **One recursor's generated type, checked and compared**: the record's
393member, rule prefix and major index are the generated ones; the generated
394type is checked as a constant under the record's name and level
395parameters (`checkConstantValF`) and must be `isDefEq` to the stream's
396checked type `cvRi`. Returns the generated constant (what is stored). -/
397def classRecTyOk (ops : CheckerOps m) (fe : FEnv) (g : ClassGen)
398 (k : Nat) (rc : RecShape) (cvRi : ConstantVal) (c : Nat) : m ConstantVal := do
399 let ci := g.cls.getD c default
400 unless rc.tgt == ci.member.getD k do
401 throw (.invalid "generated recursor: the recursor record's member is not its class's")
402 unless rc.rP == g.nP + g.slots.length && rc.mI == rc.rP + ci.nIdx do
403 throw (.invalid "generated recursor: the recursor record's rule prefix or major index is \
404 not the generated one")
405 let gty ← unwrapOr (classGenRecTy g c) (.internal "generated recursor: recursor type")
406 let cvG := { rc.cvR with type := gty }
). An unverified pre-pass reads off that type which type the recursor eliminates and how its motive and minor premises are laid out (the arguments named on 𝖭𝖺𝗍 in Example 6); a wrong reading can only make the comparison fail (the pre-passConLeche/Kernel/Inductives/ClassRead.lean:L24-L3224This file READS that data off the recursor types, syntactically, and
25checks nothing. Everything it returns is re-established by the stage:
26every class is checked like a major (`targetMajorOf`), the inductive
27hypotheses read here must be exactly the positivity check's recursive
28fields, and every recursor TYPE is generated from the classes and the
29positivity check's recorded constructors and compared by `isDefEq` with
30the stream's. What the stage installs is the generated family, never
31anything read here: a wrong reading can only make the generated type
32differ from the stream's, i.e. reject.
). What is stored is the record’s own recursor, its type and its rules, once they agree with the generated ones: the type binder by binder up to the major premise, each rule up to definitional equality, at the generated recursor’s firing data (the comparisonConLeche/Kernel/Inductives/StreamRecs.lean:L187-L193187def streamRecsCheck (ops : CheckerOps m) (fe : FEnv) :
188 List RecShape → List (ConstantVal × TargetMajor × List Expr) → m Unit
189 | rc :: rcs, g :: gs => do
190 streamRecCheck ops fe rc g
191 streamRecsCheck ops fe rcs gs
192 | [], [] => pure ()
193 | _, _ => throw (.internal "stored recursors: the generated family is not the records'")
).

Here is the recursor of the natural numbers.

Example 6 (𝖭𝖺𝗍). The block 𝖭𝖺𝗍 has no parameters, no indices, sort 𝖲𝗈𝗋𝗍1, and two constructors: 𝗓𝖾𝗋𝗈 with no field and 𝗌𝗎𝖼𝖼 with one recursive field (reflexive with the empty telescope). The generated constructor types are 𝗓𝖾𝗋𝗈:𝖭𝖺𝗍 and 𝗌𝗎𝖼𝖼:∀(𝑛:𝖭𝖺𝗍).𝖭𝖺𝗍. The recursor eliminates into 𝖲𝗈𝗋𝗍ℓ for a fresh level parameter ℓ (large elimination, see below), and its generated type is

𝖭𝖺𝗍.𝗋𝖾𝖼.{ℓ}:∀(𝐶:∀(𝑡:𝖭𝖺𝗍).𝖲𝗈𝗋𝗍ℓ).∀(𝑧:𝐶𝗓𝖾𝗋𝗈).∀(𝑠:∀(𝑛:𝖭𝖺𝗍).∀(ℎ:𝐶𝑛).𝐶(𝗌𝗎𝖼𝖼𝑛)).∀(𝑡:𝖭𝖺𝗍).𝐶𝑡

𝐶 is the motive; 𝑧 and 𝑠 are the minor premises, one per constructor, each taking the constructor’s fields and, for every recursive field, an inductive hypothesis ℎ, the motive at that field; 𝑡 is the major premise. The recursor has two rules, one per constructor: the major premise built by the constructor reduces to the minor premise applied to the fields and to the recursor’s own value at each recursive field,

𝖭𝖺𝗍.𝗋𝖾𝖼.{ℓ}𝐶𝑧𝑠𝗓𝖾𝗋𝗈⇝𝑧𝖭𝖺𝗍.𝗋𝖾𝖼.{ℓ}𝐶𝑧𝑠(𝗌𝗎𝖼𝖼𝑛)⇝𝑠𝑛(𝖭𝖺𝗍.𝗋𝖾𝖼.{ℓ}𝐶𝑧𝑠𝑛).

What the checker stores as the second rule’s right-hand side is the closed term (the binders’ domains omitted)

𝜆𝐶.𝜆𝑧.𝜆𝑠.𝜆𝑛.𝑠𝑛(𝖭𝖺𝗍.𝗋𝖾𝖼.{ℓ}𝐶𝑧𝑠𝑛);

the 𝜄 rule applies it to the recursor’s arguments and the constructor’s fields, and 𝛽 does the rest.

The general shape is the same with parameters, indices and telescopes added. The motive takes the indices and a member of the family:

𝐶:∀𝑦⃗:𝐽⃗.∀(𝑡:𝐼𝑥⃗𝑦⃗).𝖲𝗈𝗋𝗍ℓ.

A minor premise for 𝑐𝑗 takes the fields, then one inductive hypothesis per reflexive field. At a field

𝑓:∀𝑧⃗:𝐴⃗.𝐼𝑥⃗𝑒⃗

the hypothesis is

∀𝑧⃗:𝐴⃗.𝐶𝑒⃗(𝑓𝑧⃗),

which at the empty telescope is the 𝐶𝑛 of Example 6. The minor premise ends in

𝐶𝑒⃗𝑗(𝑐𝑗𝑥⃗𝑓⃗).

The recursor takes the parameters, the motive, the minors, the indices and the major, and ends in 𝐶𝑦⃗𝑡. (Generated: the motivewhitepaper/Fragment/Decl.lean:L219-L221219/-- The motive's type, under the parameters:
220`∀ indices (t : I params indices), Sort ℓ`. -/
221def motiveTy : Expr := mkPis (S.famVars 0 :: S.indices) (.sort S.ℓ)
, an inductive hypothesiswhitepaper/Fragment/Decl.lean:L232-L244232/-- **An inductive hypothesis' type** for the field with `k` earlier
233fields, `l` earlier hypotheses, `o` binders between the parameters
234and the fields (the motive sits `nF + l + o - 1` binders above):
235`∀ tele, motive es (f tele)` at a reflexive field (`motive es f` when
236the telescope is empty). -/
237def ihTy (nF k l o : Nat) : Field → Expr
238 | .ordinary _ => .sort .zero
239 | .reflexive tele es =>
240 let m := tele.length
241 mkPis (liftCtx (fun t T => atCtx nF k l o t T) tele)
242 (mkAppN (.bvar (nF + l + o - 1 + m))
243 (es.map (atCtx nF k l o m) ++ [mkAppN (.bvar (nF - 1 - k + l + m)) (varsAt 0 m)]))
244 | .container => mkAppN (.bvar (nF + l + o - 2)) [.bvar (nF - 1 - k + l)]
, a minor premisewhitepaper/Fragment/Decl.lean:L257-L266257/-- **A minor premise** for constructor `j`, under the parameters, the
258motive and the `j` earlier minors:
259`∀ fields ihs, motive idx (C params fields)`. -/
260def minorTy (c : CtorSpec) (j : Nat) : Expr :=
261 let nF := c.fields.length
262 let nIh := c.recFields.length
263 mkPis (IndSpec.ihCtx c j ++ S.fieldCtxAt c (j + 1))
264 (mkAppN (.bvar (nIh + nF + j))
265 (c.idx.map (atCtx nF nF nIh (j + 1) 0) ++
266 [mkAppN (.const c.name S.lvls) (varsAt (nIh + nF + j + 1) S.nP ++ varsAt nIh nF)]))
, the recursor’s typewhitepaper/Fragment/Decl.lean:L273-L278273/-- **The recursor's type**
274`∀ params (motive : motiveTy) minors indices (t : I params indices), motive indices t`
275(con-leche's `classGenRecTy`, `GenRec.lean:181`). -/
276def recType : Expr :=
277 mkPis (S.famVars (S.n + 1) :: S.indicesAt (S.n + 1) ++ S.minorsCtx ++ [S.motiveTy] ++ S.params)
278 (mkAppN (.bvar (1 + S.nI + S.n)) (varsAt 1 S.nI ++ [.bvar 0]))
and a rule’s right-hand sidewhitepaper/Fragment/Decl.lean:L315-L322315/-- **A rule's right-hand side** for constructor `j`:
316`fun params motive minors fields => minor_j fields ihs`
317(con-leche's `classGenRule`, `GenRec.lean:193`). -/
318def ruleRhs (c : CtorSpec) (j : Nat) : Expr :=
319 let nF := c.fields.length
320 mkLams (S.ruleCtx c)
321 (mkAppN (.bvar (nF + S.n - 1 - j))
322 (varsAt 0 nF ++ c.recFields.map fun kf => S.ihVal nF kf.1 kf.2))
; in con-leche: the typeConLeche/Kernel/Inductives/GenRec.lean:L176-L183176/-- **The generated recursor type** at class `c`. -/
177def classGenRecTy (g : ClassGen) (c : Nat) : Option Expr := do
178 let pre := g.pre
179 let rP := pre.length
180 let (ifs, maj) ← g.major c rP
181 let t : Expr := .fvar (rP + ifs.length) maj
182 pure (closeTelescope (pre ++ ifs.map g.binder ++ [maj]) 0
183 (Expr.mkAppN (g.motVar c) (ifs ++ [t])))
, a ruleConLeche/Kernel/Inductives/GenRec.lean:L189-L208189def classGenRule (g : ClassGen) (recOf : Nat → Option Name) (rlvls : List Level) (c : Nat)
190 (x : ClassCtor) : Option Expr := do
191 let pre := g.pre
192 let rP := pre.length
193 let (s, _) ← (List.range g.slots.length).zip g.slots |>.find? fun (_, sl) =>
194 match sl with | .minor c' C _ => c' == c && C == x.cv.name | _ => false
195 let (fvs, _) ← openPisAtFvars x.nF x.tyD rP
196 let ws ← targetPiDomsWith fvs x.tyN
197 let pvars := (List.range rP).map fun i => if i < g.nP then g.params.getD i default else
198 g.slotVar (i - g.nP)
199 let ihs ← (List.range x.nF).filterMapM fun i =>
200 match x.kinds.getD i .ordinary with
201 | .ordinary => some none
202 | .recursive t tele => do
203 let f := fvs.getD i default
204 let (xs, idx) ← g.ihParts t tele (ws.getD i default) (rP + x.nF)
205 let r ← recOf t
206 pure (some (closeLams (xs.map g.binder) (rP + x.nF)
207 (Expr.mkAppN (.const r rlvls) (pvars ++ idx ++ [Expr.mkAppN f xs]))))
208 pure (closeLams (pre ++ fvs.map g.binder) 0 (Expr.mkAppN (g.slotVar s) (fvs ++ ihs)))
.)

4.1.2. The elimination rule

For a type-valued family, in 𝖲𝗈𝗋𝗍𝑢 with 𝑢 never zero, the recursor eliminates into any 𝖲𝗈𝗋𝗍ℓ, ℓ a fresh level parameter: large elimination. For a proposition-valued family the rule is stricter. In the model every proof is the point, so a recursor applied to a proof cannot see which constructor built it or with which fields, and a recursor with a type-valued motive would have to return one value for all of them. The official kernel allows large elimination out of a proposition only under the subsingleton criterion: the block has at most one constructor, and every field of that constructor is either itself a proposition or occurs among the constructor’s result indices. Then a proof of 𝐼𝑥⃗𝑒⃗ determines every field: the propositional ones are all the same proof, and the others can be read off the indices. Otherwise the motive lands in 𝖯𝗋𝗈𝗉, ℓ=0 (small elimination). In the fragment the criterion is a condition per fieldwhitepaper/Fragment/Decl.lean:L723-L730723/-- **The subsingleton criterion** for a field of sort `v` at
724position `i` (innermost first) of a constructor with index
725expressions `idx`: the field is a proposition, or it is one of the
726result's indices (official's `elim_only_at_universe_zero` at one
727constructor; con-leche's `checkStructFieldSortsI`). Required only of a
728large eliminator on a block whose sort may be `Prop`. -/
729def SubsingletonField (v : Level) (i : Nat) (idx : List Expr) : Prop :=
730 S.large = true → ¬ S.NeverProp → (LevelOracle.eq v .zero = true ∨ Expr.bvar i ∈ idx)
plus the constructor countwhitepaper/Fragment/Decl.lean:L776776 (S.large = true → ¬ S.NeverProp → S.ctors.length ≤ 1) ∧
, required of a large eliminator on a family whose sort may be zero (never zero: 1≤𝑢 at every valuationwhitepaper/Fragment/Decl.lean:L719-L721719/-- "The result sort is never `Prop`": `1 ≤ u` at every valuation
720(con-leche's `Level.isNeverZero`). -/
721def NeverProp : Prop := LevelOracle.le (.succ .zero) S.sort = true
).

In con-leche The checker asks the constructor count of every family whose sort may be zero (the guardConLeche/Kernel/Inductives/BlockRec.lean:L82-L8482def blockLargeElimAllowed (p : BlockShape) (nested : Bool) : Bool :=
83 p.resSort.isNeverZero ||
84 (p.large && p.k == 1 && !nested && (p.numCtors == 0 || p.numCtors == 1))
, appliedConLeche/Kernel/Inductives/GenRec.lean:L560-L562560 unless 0 < p.k do
561 throw (.invalid "generated recursor: the block declares no family")
562 if p.large && !blockLargeElimAllowed p (nestedBit || Ms.any (·.member.isNone)) then
) but the per-field conditionConLeche/Kernel/Inductives/SumInstall.lean:L51-L6551def checkStructFieldSortsI (ops : CheckerOps m) (env : Env) (isProp large : Bool)
52 (s : Level) (nP : Nat) (fvs idxArgs : List Expr) : Nat → m Unit
53 | 0 => pure ()
54 | j + 1 => do
55 let fv ← unwrapOr fvs[j]? (.internal "direct sum: field index")
56 let ty ← ops.inferType env (nP + j) fv.fvarTypeD
57 let u ← ops.ensureSort env (nP + j) ty
58 if !isProp then
59 unless ← liftFueled "level comparison" (Level.leq u s) do
60 throw (.invalid "direct sum: field universe too large")
61 else if large then
62 unless Level.isEquiv u .zero == some true || idxArgs.contains fv do
63 throw (.invalid "direct sum: large eliminator with a non-propositional \
64 field outside the indices")
65 checkStructFieldSortsI ops env isProp large s nP fvs idxArgs j
only of a family whose sort is provably zero, which is sound because the universe bound (the third check below) makes every field a proposition at any valuation that sends the result sort to zero.

Three of the checks listed below ask whether a sort is 𝖯𝗋𝗈𝗉, and the checker answers each with the level oracle:

Example 7 (an indexed proposition with large elimination). Let

𝑃:∀(𝑛:𝖭𝖺𝗍).𝖯𝗋𝗈𝗉

have one constructor

𝗆𝗄:∀(𝑛:𝖭𝖺𝗍).𝑃𝑛.

It is a proposition-valued family, indexed by a number, with one ordinary field 𝑛 that is not a proposition and occurs in the result’s index. The subsingleton criterion holds, so the recursor may eliminate into 𝖲𝗈𝗋𝗍ℓ:

𝖯.𝗋𝖾𝖼.{ℓ}:∀(𝐶:∀(𝑛:𝖭𝖺𝗍).∀(𝑡:𝑃𝑛).𝖲𝗈𝗋𝗍ℓ).∀(ℎ:∀(𝑛:𝖭𝖺𝗍).𝐶𝑛(𝗆𝗄𝑛)).∀(𝑛:𝖭𝖺𝗍).∀(𝑡:𝑃𝑛).𝐶𝑛𝑡

with one rule,

𝖯.𝗋𝖾𝖼.{ℓ}𝐶ℎ𝑛(𝗆𝗄𝑛′)⇝ℎ𝑛′.

The index occurs twice: 𝑛 is the recursor’s index argument, 𝑛′ the constructor’s field. Section 4.2.7 uses this example.

4.1.3. When a block is accepted

A block is acceptedwhitepaper/Fragment/Decl.lean:L732-L777732/-- **The block is accepted** (con-leche's `checkBlock`,
733`ConLeche/Kernel/Inductives/BlockTail.lean:143`):
734
735* the block's names are distinct and fresh;
736* the specification is in scope (closed, stored constants, declared
737 level parameters — positivity included);
738* the generated type former's type has a sort in the current
739 environment;
740* each generated constructor's type has a sort in the environment
741 holding the former, every field's domain has a sort respecting the
742 universe bound and, where a large eliminator asks it, the
743 subsingleton criterion, and so does every binder of a reflexive
744 field's telescope (the domain's sort implies it; the fragment lists
745 it, as the checker infers it);
746* each rule's type (`ruleType`, the recursor's binder prefix with the
747 constructor's fields in place of the indices and the major) has a
748 sort in the environment holding the former and the constructors;
749* a large eliminator on a block whose sort may be `Prop` has at most
750 one constructor (official's `elim_only_at_universe_zero`);
751* the generated recursor's type has a sort in the environment holding
752 the former and the constructors.
753
754The recursor's rules are generated and stored, not checked: they
755mention the recursor. Con-leche does type its generated rules, in
756the environment holding the recursors without their rules
757(`classRuleOk`, `GenRec.lean:427`); the fragment stores them as is. -/
758def Ok (env : Env) : Prop :=
759 (S.name :: S.recName :: S.ctors.map (·.name)).Nodup ∧
760 (∀ m ∈ S.name :: S.recName :: S.ctors.map (·.name), env.find? m = none) ∧
761 S.Scoped env ∧
762 (∃ T, Infer env [] S.indType T) ∧
763 (∀ c ∈ S.ctors,
764 (∃ T u, Infer (S.envInd env) [] (S.ctorType c) T ∧ Red (S.envInd env) [] T (.sort u)) ∧
765 (∀ i A, (S.fieldCtx c.fields)[i]? = some A →
766 ∃ s v, Infer (S.envInd env) ((S.fieldCtx c.fields).drop (i + 1) ++ S.params) A s ∧
767 Red (S.envInd env) ((S.fieldCtx c.fields).drop (i + 1) ++ S.params) s (.sort v) ∧
768 S.FieldBound v ∧ S.SubsingletonField v i c.idx) ∧
769 (∀ i tele es, c.fields[i]? = some (.reflexive tele es) → ∀ t T, tele[t]? = some T →
770 ∃ s w, Infer (S.envInd env)
771 (tele.drop (t + 1) ++ (S.fieldCtx c.fields).drop (i + 1) ++ S.params) T s ∧
… 6 more lines
when (as in con-lecheConLeche/Kernel/Inductives/BlockTail.lean:L153-L163153def checkBlock (ops : CheckerOps m) (env : Env) (block : List ConstantInfo) (p₀ : BlockShape) :
154 m Env := do
155 unless (p₀.allCtors.map (·.1.name)).Nodup ∧ p₀.memberNames.Nodup do
156 throw (.invalid "direct rec: duplicate constructor")
157 unless boolTrueName ∉ p₀.memberNames ∧ boolFalseName ∉ p₀.memberNames do
158 throw (.invalid "direct rec: a family at a `Bool` constructor's name")
159 let ms ← reduceMembers ops env p₀.nP p₀.members
160 let q ← checkBlockPass ops env { p₀ with members := ms } (blockIsRec p₀)
161 let Q ← unwrapOr (blockTables p₀ p₀.members) (.internal "direct structure: projection bodies")
162 checkBlockTail ops block q Q
163 pure (env.pushDelta (blockConstants p₀) Q)
):

Each “has a type” is an inference ⊢𝑇⇒𝑆 of §2, in the empty context, and each “has a sort” one whose result 𝑆 reduces to a sort. So the generated types are checked like a definition’s. The model needs only the inferences: the third claim of Theorem 2 makes every generated type a well-denoted type.

In con-leche The same steps run in this order, and each generated rule is type-checked in the environment holding the rule-less recursor (a generated ruleConLeche/Kernel/Inductives/GenRec.lean:L425-L447425resolving at the constructors' environment `feT`. -/
426def classRuleCheck (ops : CheckerOps m) (feT feR : FEnv)
427 (cvR : ConstantVal) (n : Nat) (gen : Expr) : m Unit := do
428 unless gen.looseBVarsBounded 0 && !gen.hasFvar do
429 throw (.internal s!"generated recursor: a rule of {cvR.name} is not closed")
430 unless gen.allLevelParamsDefined cvR.levelParams do
431 throw (.internal s!"generated recursor: a rule of {cvR.name} names an undeclared universe \
432 parameter")
433 unless gen.constsResolveF feR do
434 throw (unresolvedConstsError s!"generated rule of {cvR.name}" gen)
435 let _ ← ops.inferType feR.env 0 gen
436 let (rbs, _) ← unwrapOr (gen.stripLams n)
437 (.internal s!"generated recursor: a rule of {cvR.name} is not a λ-telescope over the \
438 recursor's prefix and the constructor's fields")
439 unless rbs.all (fun b => b.constsResolveF feT) do
440 throw (unresolvedConstsError s!"the domains of a generated rule of {cvR.name}" gen)
441
442/-- **One generated rule, installed** (as generated), after its check
443(`classRuleCheck`). Returns the rule (stored). -/
444def classRuleOk (ops : CheckerOps m) (feT feR : FEnv)
445 (cvR : ConstantVal) (n : Nat) (gen : Expr) : m Expr := do
446 classRuleCheck ops feT feR cvR n gen
447 pure gen
).

4.1.4. What is stored

The block adds three kinds of constantwhitepaper/Fragment/Decl.lean:L532-L573532/-! ### What is stored -/
533
534/-- The type former's constant. -/
535def indInfo : ConstInfo := ⟨S.lparams, S.indType, .induct S.nP S.nI (S.ctors.map (·.name)) S⟩
536
537/-- A constructor's constant. -/
538def ctorInfo (c : CtorSpec) : ConstInfo :=
539 ⟨S.lparams, S.ctorType c, .ctor S.name S.nP c.fields.length⟩
540
541/-- The recursor's constant: `nP` parameters, one motive, `n` minors,
542`nI` indices, the generated rules. -/
543def recInfo : ConstInfo := ⟨S.recLparams, S.recType, .recursor S.nP 1 S.n S.nI S.rules⟩
544
545/-- The environment with the type former added. -/
546def envInd (env : Env) : Env := env.add S.name S.indInfo
547
548/-- The environment with the type former and the constructors added,
549in order. -/
550def envCtors (env : Env) : Env :=
551 S.ctors.foldl (fun e c => e.add c.name (S.ctorInfo c)) (S.envInd env)
552
553/-- `T.rec`'s constant in a nested block: `nP` parameters, two
554motives, `n + nK` minors, `nI` indices. -/
555def recInfoN (N : NestInfo) : ConstInfo :=
556 ⟨S.recLparams, S.recTypeN N, .recursor S.nP 2 (S.n + N.nK) S.nI (S.rulesN N)⟩
557
558/-- `T.rec_1`'s constant: the same prefix, no indices. -/
559def rec1Info (N : NestInfo) : ConstInfo :=
560 ⟨S.recLparams, S.rec1Type N, .recursor S.nP 2 (S.n + N.nK) 0 (S.rules1 N)⟩
561
562/-- **The installed nested block**: former, constructors, the two
563recursors. -/
564def installN (N : NestInfo) (env : Env) : Env :=
565 ((S.envCtors env).add S.recName (S.recInfoN N)).add N.aux (S.rec1Info N)
566
567/-- **The installed block**: former, constructors, recursor — and the
568auxiliary recursor for a nested block. -/
569def install (env : Env) : Env :=
570 match S.nest with
571 | none => (S.envCtors env).add S.recName S.recInfo
… 2 more lines
to the environment, the ones Section 3 left to this section (the kindswhitepaper/Fragment/Env.lean:L65-L8165/-- What kind of constant a name is stored as. -/
66inductive ConstKind where
67 /-- A definition: its value unfolds (δ). -/
68 | defn (value : Expr)
69 /-- An inductive type former with `numParams` parameters,
70 `numIndices` indices and these constructors — and the block's
71 specification it was generated from (`Spec.lean`), which a later
72 block nesting through this one reads back (con-leche stores the
73 block's shape with the former likewise, `IndCaps`). -/
74 | induct (numParams numIndices : Nat) (ctors : List Name) (spec : IndSpec)
75 /-- A constructor of the inductive `induct`, with `numParams`
76 parameters (the inductive's) and `nfields` fields. -/
77 | ctor (induct : Name) (numParams nfields : Nat)
78 /-- A recursor with the given telescope shape — `numParams`
79 parameters, `numMotives` motives, `numMinors` minor premises,
80 `numIndices` indices, then the major premise — and its rules. -/
81 | recursor (numParams numMotives numMinors numIndices : Nat) (rules : List RecRule)
, as in con-lecheConLeche/Kernel/Env.lean:L134-L142134structure RecRule where
135 ctor : Name
136 nfields : Nat
137 /-- The firing mode (install-computed, parse placeholder `.plain`):
138 `.plain` at a member major, `.nested` at an outside one. -/
139 fire : RecRuleFire
140 rhs : Expr
141 deriving DecidableEq, Repr, Inhabited
142
). Written with the notation of Section 3, a stored declaration is one of

The counts are the sizes of the argument groups (Example 6 shows them on 𝖭𝖺𝗍). A rule 𝑅𝑗 is a closed right-hand side over the recursor’s level parameters, one per constructor. The rules are generated and stored without an inferred type: they mention the recursor itself, and the official kernel infers no rule either.

4.2. The model

The model of a block has three parts: the set the type former denotes at each choice of indices, the sets the constructors denote, and the set the recursor denotes. With the recursor, the contract of Section 3 gains its third lawwhitepaper/Fragment/EnvModel.lean:L320-L327320 /-- Every plain rule of every stored recursor satisfies its ι law. -/
321 rec_rules : ∀ (c : Name) (ci : ConstInfo) (numParams numMotives numMinors numIndices : Nat)
322 (rules : List RecRule),
323 env.find? c = some ci →
324 ci.kind = .recursor numParams numMotives numMinors numIndices rules →
325 ∀ rl ∈ rules, rl.inst = none → ∀ cij : ConstInfo, env.find? rl.ctor = some cij →
326 RecRuleLaw M c ci numParams (numParams + numMotives + numMinors)
327 (numParams + numMotives + numMinors + numIndices) rl cij
: every rule of every stored recursor satisfies its 𝜄 law (Definition 9), which this subsection proves. Section 4.2.8 adds three more laws, facts about the model that let most 𝜄 steps go without a certificate. All of it is stated against an extension of §2′s axioms.

4.2.1. The axioms, extended

Beyond the laws of Section 2.4 this section assumes that the positive universes 𝒰︀𝑛, 𝑛≥1, are Grothendieck universeswhitepaper/Fragment/Univ.lean:L43-L8843/-- **The positive universes are Grothendieck universes.** `SetLib`
44with pairing, union, power set and replacement (the image of a set
45under any function of the ambient logic), the numerals and `ω`, and
46the laws: every `univ n` with `n ≠ 0` is transitive and closed under
47the four operations, and contains `ω`. -/
48class UnivLib (V : Type u) extends SetLib V where
49 /-- The unordered pair. -/
50 upair : V → V → V
51 /-- The members of a pair. -/
52 mem_upair : ∀ {z a b : V}, Mem z (upair a b) ↔ z = a ∨ z = b
53 /-- The union of the members. -/
54 sUnion : V → V
55 /-- The members of a union. -/
56 mem_sUnion : ∀ {z x : V}, Mem z (sUnion x) ↔ ∃ y, Mem y x ∧ Mem z y
57 /-- The power set. -/
58 power : V → V
59 /-- The members of a power set: the subsets. -/
60 mem_power : ∀ {z x : V}, Mem z (power x) ↔ ∀ w, Mem w z → Mem w x
61 /-- Replacement: the image of a set under a function. -/
62 image : (V → V) → V → V
63 /-- The members of an image. -/
64 mem_image : ∀ {f : V → V} {A z : V}, Mem z (image f A) ↔ ∃ w, Mem w A ∧ z = f w
65 /-- The numerals. -/
66 nat : Nat → V
67 /-- Distinct numbers have distinct numerals. -/
68 nat_inj : ∀ {k l : Nat}, nat k = nat l → k = l
69 /-- `ω`: the set of numerals. -/
70 omega : V
71 /-- The members of `ω`. -/
72 mem_omega : ∀ {z : V}, Mem z omega ↔ ∃ k, z = nat k
73 /-- A positive universe is transitive: a member of a member is a
74 member. -/
75 univ_trans : ∀ {n : Nat} {A x : V}, n ≠ 0 → Mem A (univ n) → Mem x A → Mem x (univ n)
76 /-- A positive universe is closed under pairing. -/
77 upair_mem_univ : ∀ {n : Nat} {a b : V}, n ≠ 0 →
78 Mem a (univ n) → Mem b (univ n) → Mem (upair a b) (univ n)
79 /-- A positive universe is closed under union. -/
80 sUnion_mem_univ : ∀ {n : Nat} {x : V}, n ≠ 0 → Mem x (univ n) → Mem (sUnion x) (univ n)
81 /-- A positive universe is closed under power set. -/
82 power_mem_univ : ∀ {n : Nat} {x : V}, n ≠ 0 → Mem x (univ n) → Mem (power x) (univ n)
… 6 more lines
, and that there are tagged tupleswhitepaper/Fragment/IndLib.lean:L47-L6447/-- **The library for inductive types**: the universes with tuples and
48tags. -/
49class IndLib (V : Type u) extends UnivLib V where
50 /-- The n-ary tuple of a list of sets. -/
51 tuple : List V → V
52 /-- Tuples are injective. -/
53 tuple_inj : ∀ {xs ys : List V}, tuple xs = tuple ys → xs = ys
54 /-- A tuple of members of a positive universe is a member of it. -/
55 tuple_mem_univ : ∀ {n : Nat} {xs : List V}, n ≠ 0 →
56 (∀ x ∈ xs, Mem x (univ n)) → Mem (tuple xs) (univ n)
57 /-- A value tagged with a number. -/
58 tag : Nat → V → V
59 /-- Tags are injective. -/
60 tag_inj : ∀ {i j : Nat} {x y : V}, tag i x = tag j y → i = j ∧ x = y
61 /-- A tagged member of a positive universe is a member of it. -/
62 tag_mem_univ : ∀ {n i : Nat} {x : V}, n ≠ 0 → Mem x (univ n) → Mem (tag i x) (univ n)
63 /-- A tagged value is never the point. -/
64 tag_ne_pt : ∀ {i : Nat} {x : V}, tag i x ≠ pt
:

  1. Pairing, union, power set, replacementwhitepaper/Fragment/Univ.lean:L49-L6449 /-- The unordered pair. -/
    50 upair : V → V → V
    51 /-- The members of a pair. -/
    52 mem_upair : ∀ {z a b : V}, Mem z (upair a b) ↔ z = a ∨ z = b
    53 /-- The union of the members. -/
    54 sUnion : V → V
    55 /-- The members of a union. -/
    56 mem_sUnion : ∀ {z x : V}, Mem z (sUnion x) ↔ ∃ y, Mem y x ∧ Mem z y
    57 /-- The power set. -/
    58 power : V → V
    59 /-- The members of a power set: the subsets. -/
    60 mem_power : ∀ {z x : V}, Mem z (power x) ↔ ∀ w, Mem w z → Mem w x
    61 /-- Replacement: the image of a set under a function. -/
    62 image : (V → V) → V → V
    63 /-- The members of an image. -/
    64 mem_image : ∀ {f : V → V} {A z : V}, Mem z (image f A) ↔ ∃ w, Mem w A ∧ z = f w
    , on all sets: for sets 𝑎,𝑏,𝑥,𝐴 and a function 𝐹 (of the meta-theory) from sets to sets, the sets {𝑎,𝑏}, ⋃𝑥, 𝒫︀(𝑥) and 𝐹[𝐴] with

    𝑧∈{𝑎,𝑏}⟺𝑧=𝑎∨𝑧=𝑏,𝑧∈⋃𝑥⟺𝑧∈𝑦for some𝑦∈𝑥,𝑧∈𝒫︀(𝑥)⟺𝑧⊆𝑥,𝑧∈𝐹[𝐴]⟺𝑧=𝐹(𝑤)for some𝑤∈𝐴.
  2. The numerals and 𝜔whitepaper/Fragment/Univ.lean:L65-L7265 /-- The numerals. -/
    66 nat : Nat → V
    67 /-- Distinct numbers have distinct numerals. -/
    68 nat_inj : ∀ {k l : Nat}, nat k = nat l → k = l
    69 /-- `ω`: the set of numerals. -/
    70 omega : V
    71 /-- The members of `ω`. -/
    72 mem_omega : ∀ {z : V}, Mem z omega ↔ ∃ k, z = nat k
    : a set 𝗇𝗎𝗆(𝑘) for every natural number 𝑘, distinct for distinct numbers, and the set 𝜔 of all numerals.
  3. Grothendieck universeswhitepaper/Fragment/Univ.lean:L73-L8873 /-- A positive universe is transitive: a member of a member is a
    74 member. -/
    75 univ_trans : ∀ {n : Nat} {A x : V}, n ≠ 0 → Mem A (univ n) → Mem x A → Mem x (univ n)
    76 /-- A positive universe is closed under pairing. -/
    77 upair_mem_univ : ∀ {n : Nat} {a b : V}, n ≠ 0 →
    78 Mem a (univ n) → Mem b (univ n) → Mem (upair a b) (univ n)
    79 /-- A positive universe is closed under union. -/
    80 sUnion_mem_univ : ∀ {n : Nat} {x : V}, n ≠ 0 → Mem x (univ n) → Mem (sUnion x) (univ n)
    81 /-- A positive universe is closed under power set. -/
    82 power_mem_univ : ∀ {n : Nat} {x : V}, n ≠ 0 → Mem x (univ n) → Mem (power x) (univ n)
    83 /-- A positive universe is closed under replacement: the image of a
    84 member under a function into the universe is a member. -/
    85 image_mem_univ : ∀ {n : Nat} {f : V → V} {A : V}, n ≠ 0 → Mem A (univ n) →
    86 (∀ a, Mem a A → Mem (f a) (univ n)) → Mem (image f A) (univ n)
    87 /-- A positive universe contains `ω`. -/
    88 omega_mem_univ : ∀ {n : Nat}, n ≠ 0 → Mem omega (univ n)
    : for 𝑛≥1, 𝒰︀𝑛 is transitive (if 𝐴∈𝒰︀𝑛 and 𝑥∈𝐴 then 𝑥∈𝒰︀𝑛), closed under the four operations,

    {𝑎,𝑏},⋃𝑥,𝒫︀(𝑥)∈𝒰︀𝑛for𝑎,𝑏,𝑥∈𝒰︀𝑛,𝐹[𝐴]∈𝒰︀𝑛for𝐴∈𝒰︀𝑛with𝐹(𝑎)∈𝒰︀𝑛for every𝑎∈𝐴,

    and contains 𝜔.

  4. Tagged tupleswhitepaper/Fragment/IndLib.lean:L50-L6450 /-- The n-ary tuple of a list of sets. -/
    51 tuple : List V → V
    52 /-- Tuples are injective. -/
    53 tuple_inj : ∀ {xs ys : List V}, tuple xs = tuple ys → xs = ys
    54 /-- A tuple of members of a positive universe is a member of it. -/
    55 tuple_mem_univ : ∀ {n : Nat} {xs : List V}, n ≠ 0 →
    56 (∀ x ∈ xs, Mem x (univ n)) → Mem (tuple xs) (univ n)
    57 /-- A value tagged with a number. -/
    58 tag : Nat → V → V
    59 /-- Tags are injective. -/
    60 tag_inj : ∀ {i j : Nat} {x y : V}, tag i x = tag j y → i = j ∧ x = y
    61 /-- A tagged member of a positive universe is a member of it. -/
    62 tag_mem_univ : ∀ {n i : Nat} {x : V}, n ≠ 0 → Mem x (univ n) → Mem (tag i x) (univ n)
    63 /-- A tagged value is never the point. -/
    64 tag_ne_pt : ∀ {i : Nat} {x : V}, tag i x ≠ pt
    tag(𝑗,𝑥1,…,𝑥𝑘), a list of sets with a number 𝑗 attached: injective (equal tagged tuples have equal numbers and equal components), in 𝒰︀𝑛 when every component is, never 𝗉𝗍, and never a member of 𝗉𝗍whitepaper/Fragment/IndLib.lean:L65-L6865 /-- No tagged value is a member of the point. (With `pt := {{∅}}`
    66and Kuratowski tags: `{∅}` is not a pair `{{i}, {i, x}}`.) Together
    67 with `tag_ne_pt` it makes every set of tagged values strict. -/
    68 tag_not_mem_pt : ∀ {i : Nat} {x : V}, ¬ Mem (tag i x) pt
    , so that a set of tagged tuples is strict.

Nothing else is assumed. There is no law about least fixed points and none about the size of an inductive family; both are theorems below. What the construction uses of the universes follows at once. A subset of a member is a memberwhitepaper/Fragment/Univ.lean:L115-L120115/-- A subset of a member of a universe is a member: at a positive
116universe it is a member of the power set, which is a member; at
117`univ 0` it is a subset of `{pt}`. Con-leche:
118`univ_mem_of_subset_mem`, `ConLeche/SetTheory/Derive/Universe.lean`. -/
119theorem mem_univ_of_sub {n : Nat} {A B : V} (hA : A ∈ˢ univ n) (h : B ⊆ˢ A) :
120 B ∈ˢ (univ n : V) := by
(it is in the power set, and the universe is transitive), so a separation from a member is a member; the union ⋃𝑎∈𝐴𝐹(𝑎) of a family indexed by a memberwhitepaper/Fragment/Univ.lean:L177-L194177/-- **The union of an indexed family** `⋃ a ∈ A, F a`: replacement,
178then union. Con-leche: `IsTGUniverse.famUnion_mem`,
179`ConLeche/SetTheory/Derive/Universe.lean`. -/
180def famUnion (A : V) (F : V → V) : V := sUnion (image F A)
181
182theorem mem_famUnion {A z : V} {F : V → V} : z ∈ˢ famUnion A F ↔ ∃ a, a ∈ˢ A ∧ z ∈ˢ F a := by
183 unfold famUnion
184 rw [mem_sUnion]
185 constructor
186 · rintro ⟨y, hy, hz⟩
187 obtain ⟨a, ha, rfl⟩ := mem_image.mp hy
188 exact ⟨a, ha, hz⟩
189 · rintro ⟨a, ha, hz⟩
190 exact ⟨F a, mem_image.mpr ⟨a, ha, rfl⟩, hz⟩
191
192theorem famUnion_mem_univ {n : Nat} {A : V} {F : V → V} (hn : n ≠ 0) (hA : A ∈ˢ univ n)
193 (hF : ∀ a, a ∈ˢ A → F a ∈ˢ univ n) : famUnion A F ∈ˢ (univ n : V) :=
194 sUnion_mem_univ hn (image_mem_univ hn hA hF)
is a member, by replacement then union; and so is the countable union ⋃𝑘𝐹(𝑘)whitepaper/Fragment/Univ.lean:L212-L231212/-- **The countable union** `F 0 ∪ F 1 ∪ …`: the union over `ω`, each
213numeral read back as its number. Con-leche: `Tower.natUnion`,
214`ConLeche/SetModel/Iter.lean`. -/
215noncomputable def natUnion (F : Nat → V) : V := famUnion omega fun z => F (idx z)
216
217theorem mem_natUnion {F : Nat → V} {z : V} : z ∈ˢ natUnion F ↔ ∃ k, z ∈ˢ F k := by
218 unfold natUnion
219 rw [mem_famUnion]
220 constructor
221 · rintro ⟨w, -, hz⟩
222 exact ⟨idx w, hz⟩
223 · rintro ⟨k, hk⟩
224 exact ⟨nat k, mem_omega.mpr ⟨k, rfl⟩, by rw [idx_nat]; exact hk⟩
225
226/-- A countable union of members of a positive universe is a member —
227the one use of `ω`. Con-leche: `Tower.natUnion_mem_univ_pos`,
228`ConLeche/SetModel/Iter.lean`. -/
229theorem natUnion_mem_univ {n : Nat} {F : Nat → V} (hn : n ≠ 0) (h : ∀ k, F k ∈ˢ univ n) :
230 natUnion F ∈ˢ (univ n : V) :=
231 famUnion_mem_univ hn (omega_mem_univ hn) fun _ _ => h _
, the union over 𝜔. This is the one use of 𝜔whitepaper/Fragment/Univ.lean:L29-L3529**Infinity is not a convenience.** `V_ω`, the hereditarily finite
30sets, is transitive and closed under pairing, union, power set and
31replacement, and the least fixed point of `X ↦ {∅} ∪ {x ∪ {x} | x ∈ X}`
32— accessible with a one-element bound — is `ω ∉ V_ω`. So the theorem
33`closed_of_acc` (`Access.lean`) needs `ω ∈ univ n`, and uses it
34exactly once: the set of finite paths over the bound is a countable
35union (`natUnion`).
, and it is needed: the hereditarily finite sets satisfy every other law in this list.

In con-leche The set theory is one class: ZF without infinity, plus a chain of universes each of which is a Grothendieck universe stated as the matrix of Tarski’s Axiom A with transitivity (the universe propertyConLeche/SetTheory/Core.lean:L89-L9389def IsTGUniverse {V : Type u} (mem : V → V → Prop) (u : V) : Prop :=
90 (∀ y z, mem y u → mem z y → mem z u) ∧
91 (∀ y z, mem y u → (∀ w, mem w z → mem w y) → mem z u) ∧
92 (∀ y, mem y u → ∃ p, mem p u ∧ ∀ z, (∀ w, mem w z → mem w y) → mem z p) ∧
93 (∀ y, (∀ w, mem w y → mem w u) → Equinumerous mem y u ∨ mem y u)
, the classConLeche/SetTheory/Core.lean:L95-L100 95/-- A model of set theory of exactly the strength the checker needs:
96membership, the six ZF⁻ axioms (extensionality, pairing, union, power
97set, regularity, Lean-level replacement), and an ω-chain of
98Grothendieck universes. Infinity is derivable; choice is inherited
99from the meta-logic (`Classical.choice`); see the module docstring. -/
100class SetTheory (V : Type u) where
). The closure laws of the list, and infinity, are derived from it; the fragment takes the derived laws as its interface, as it does for the rest of §2′s laws.

4.2.2. The operator

Fix a block as in Section 4.1, a valuation 𝜑, and values 𝑋⃗ for the parameters. A family is a function 𝑊 that assigns a set 𝑊(𝑌⃗), its fibre, to every list of index values 𝑌⃗. The block’s operator Φ sends a family to a family: its fibre at 𝑌⃗ is the set of constructor values tag(𝑗,𝐹⃗), for a constructor 𝑐𝑗 and values 𝐹⃗ for its fields, whose fields fit 𝑐𝑗 relative to 𝑊 and whose index expressions read as 𝑌⃗,

Φ(𝑊)(𝑌⃗)={tag(𝑗,𝐹⃗)|𝐹⃗fit the fields of𝑐𝑗relative to𝑊,and𝑌⃗=𝑒⃗𝑗(𝐹⃗)},

where 𝑒⃗𝑗 are the index expressions of 𝑐𝑗’s result 𝐼𝑥⃗𝑒⃗𝑗 (Section 4.1), and 𝑒⃗𝑗(𝐹⃗) their denotations with the parameters at 𝑋⃗ and the fields at 𝐹⃗. Values 𝐹⃗ fit a constructor’s fields relative to 𝑊 when each is a member of its field’s set at the earlier values: the set of an ordinary field is its domain’s denotation, read without 𝑊; the set of a reflexive field 𝑓:∀𝑧⃗:𝐴⃗.𝐼𝑥⃗𝑒⃗ is the function space, read as in §2, over its telescope into fibres of 𝑊 at the field’s own index expressions 𝑒⃗,

Π𝗏(𝑧⃗∈𝐴⃗,adm(𝑊(𝑒⃗(𝑧⃗)))),

and the fibre 𝑊(𝑒⃗) itself when the telescope is empty (a field’s setwhitepaper/Fragment/IndSem.lean:L282-L303282/-- **The set a field ranges over**, relative to a family `W` (index
283values to sets), at parameters `ps` and the earlier field values `fs`
284(innermost first): an ordinary field's domain; for a reflexive field
285the function space over its telescope into the fibres of `W` at the field's
286index expressions read under the telescope's values — the fibre
287itself when the telescope is empty; for a container field the class
288at the fibre of `W` at the nested occurrence's index expressions
289(`classSet`: the container's family, read at the class's arguments
290with that fibre in the nested position; a plain block has no
291container field, and the clause is empty). Con-leche: a field's
292reading with holes, `LfpDatum.fields`, read at the hole frame of the
293tuple (`HFits`, `BlockLfp.lean`); the container clause `contApp`
294through the container's lfp clause (`BlockLfpMono.lean`). -/
295noncomputable def fieldSet (W : List V → V) (ps fs : List V) : Field → V
296 | .ordinary A => interp M (S.ψ ls) (consList fs (envP ps)) A
297 | .reflexive tele es =>
298 piCtx M (S.ψ ls) (consList fs (envP ps)) tele fun ρ' => S.reflBody ls tele (W (S.idxVals M ls ρ' es))
299 | .container =>
300 match S.nest with
301 | some N => S.classSet M ls N ps (W (S.memberIdx M ls N ps))
302 | none => empty
303
, a fitting listwhitepaper/Fragment/IndSem.lean:L315-L320315first) relative to a family: each value a member of its field's set
316at the earlier values. Con-leche: `SpineFit` at the hole frame. -/
317def FitsFields (W : List V → V) (ps : List V) : List Field → List V → Prop
318 | [], [] => True
319 | f :: fs, v :: vs => FitsFields W ps fs vs ∧ v ∈ˢ S.fieldSet M ls W ps vs f
320 | _, _ => False
). Here adm(𝑋)whitepaper/Fragment/IndCommon.lean:L182-L189182/-- **The admissible part of a set**: at a proposition the set itself;
183above it the members that are neither the point nor a member of it —
184a strict set (`adm_mem_typeU`), so a member of the nested parameter's
185domain `Sort u`, a set of types, and the set itself on a
186set of tagged values (`adm_eq_self`), such as a fibre of the family.
187The class reads the container's set at admissible sets only: there it
188is a graph applied inside its domain. -/
189def adm (X : V) : V := if S.z ls then X else sep X fun x => x ≠ pt ∧ ¬ x ∈ˢ pt
, the admissible part of 𝑋, is 𝑋 itself when the family is proposition-valued; when it is type-valued, it is the members of 𝑋 that neither are the point nor contain it. On the family the construction ends with, adm changes nothing, since there a type-valued fibre is a set of tagged tuples. It is needed for the arbitrary families the operator is also applied to. A fibre {𝗉𝗍} would make the field’s function space a truth value, and then the field’s set would not grow with the family (the function space’s bodywhitepaper/Fragment/IndCommon.lean:L272-L280272/-- **The body of a reflexive field's function space**: the family's fibre —
273its admissible part under at least one binder. The
274function space is read by values (`SetLib.piV`), and over an arbitrary family
275in the universe a fibre `{pt}` would put a Type-sorted field's function space
276in the propositional regime; the admissible part, a strict set above a
277proposition, keeps it a function space wherever its domain is
278inhabited, so the field's set grows with the family (`piCtx_retype`).
279On the block's own family the fibres are admissible already. -/
280def reflBody (tele : List Expr) (X : V) : V := if tele = [] then X else S.adm ls X
). The fibre is a set, built by replacement, union and separation from the fields’ sets (the constructionwhitepaper/Fragment/IndSem.lean:L501-L550501replacement and union along the fields (innermost first).
502Con-leche builds the fibre the same way, by replacement over the
503spines (`BlockLfp.lean`, `fibre`). -/
504noncomputable def fitsSet (W : List V → V) (ps : List V) : List Field → V
505 | [] => sing (tuple [])
506 | f :: fs => famUnion (fitsSet W ps fs) fun t =>
507 famUnion (S.fieldSet M ls W ps (untuple t) f) fun v => sing (tuple (v :: untuple t))
508
509theorem mem_fitsSet {W : List V → V} {ps : List V} :
510 ∀ {fields : List Field} {x : V},
511 x ∈ˢ S.fitsSet M ls W ps fields ↔ ∃ fs, S.FitsFields M ls W ps fields fs ∧ x = tuple fs
512 | [], x => by
513 simp only [fitsSet, mem_sing]
514 constructor
515 · rintro rfl; exact ⟨[], trivial, rfl⟩
516 · rintro ⟨fs, hfs, rfl⟩
517 cases fs with
518 | nil => rfl
519 | cons _ _ => exact hfs.elim
520 | f :: fields, x => by
521 simp only [fitsSet, mem_famUnion, mem_sing]
522 constructor
523 · rintro ⟨t, ht, v, hv, rfl⟩
524 obtain ⟨fs, hfs, rfl⟩ := mem_fitsSet.mp ht
525 rw [untuple_tuple] at hv ⊢
526 exact ⟨v :: fs, ⟨hfs, hv⟩, rfl⟩
527 · rintro ⟨fs, hfs, rfl⟩
528 cases fs with
529 | nil => exact hfs.elim
530 | cons v fs =>
531 refine ⟨tuple fs, mem_fitsSet.mpr ⟨fs, hfs.1, rfl⟩, v, ?_, ?_⟩
532 · rw [untuple_tuple]; exact hfs.2
533 · rw [untuple_tuple]
534
535/-- **The fibre of constructor `j`** at the family `W` and the index
536values `is`: the constructor values of the fitting lists whose index
537expressions read as `is`. -/
538noncomputable def ctorFibre (W : List V → V) (ps is : List V) (j : Nat) (c : CtorSpec) : V :=
539 open Classical in
540 image (fun t => S.ctorVal ls j (untuple t))
… 10 more lines
, its members are as displayedwhitepaper/Fragment/IndSem.lean:L561-L565561constructor instances over the input family at `is`. Con-leche:
562`LfpClause.fibre`. -/
563theorem mem_famOp {ps : List V} {W : List V → V} {is : List V} {x : V} :
564 x ∈ˢ S.famOp M ls ps W is ↔ S.Inst M ls W ps is x := by
565 unfold famOp Inst
). When the family is proposition-valued (𝑢 evaluates to 0 at 𝜑) a constructor value is the pointwhitepaper/Fragment/IndCommon.lean:L330-L332330/-- **A constructor's value** at its fields: the point at a
331proposition, the tagged tuple above. -/
332def ctorVal (j : Nat) (fs : List V) : V := if S.z ls then pt else tag (S.tagOf j) (tuple fs.reverse)
instead of the tagged tuple, so every fibre of Φ(𝑊) is a subset of {𝗉𝗍}: the truth value “some constructor reaches these indices”.

4.2.3. Accessibility

Theorem 8 below, which supplies the closed family the least fixed point needs, asks for accessibility. An occurrence in a family 𝑊 is a pair (𝑌⃗,𝑣) of index values and a member 𝑣∈𝑊(𝑌⃗) of the fibre there; write (𝑌⃗,𝑣)∈𝑊. For 𝑛≥1 write 𝑊∈𝒰︀𝑛 when every fibre of 𝑊 is a member of 𝒰︀𝑛. Call Φ accessible with the bound 𝐴whitepaper/Fragment/Access.lean:L68-L7868/-- **Accessibility with the bound `A`** of an operator from families
69over `ι` to families over `κ`: every element `x` the operator
70produces at `j` from a family `W` in the universe has a support — a
71subset `B` of `A` and occurrences `g a ∈ W` for `a ∈ B` — such that
72`x` is produced at `j` from every family `W'` in the universe
73containing the support. Con-leche: `AccTuple`,
74`ConLeche/SetModel/Access.lean`. -/
75def AccFam (n : Nat) (Φ : (ι → V) → κ → V) (A : V) : Prop :=
76 ∀ W, InUniv n W → ∀ j x, x ∈ˢ Φ W j →
77 ∃ (B : V) (g : V → ι × V), B ⊆ˢ A ∧ (∀ a, a ∈ˢ B → InFam W (g a)) ∧
78 ∀ W', InUniv n W' → (∀ a, a ∈ˢ B → InFam W' (g a)) → x ∈ˢ Φ W' j
, a set, when every element 𝑥 of a fibre of Φ(𝑊) has a support: a subset 𝐵⊆𝐴 together with a map 𝑔 that names, for each 𝑎∈𝐵, an occurrence 𝑔(𝑎) in 𝑊, such that 𝑥 is produced from every family in the universe that contains those occurrences:

∀𝑊∈𝒰︀𝑛,𝑌⃗,𝑥∈Φ(𝑊)(𝑌⃗).∃𝐵⊆𝐴,𝑔.(∀𝑎∈𝐵.𝑔(𝑎)∈𝑊)∧∀𝑊′∈𝒰︀𝑛.(∀𝑎∈𝐵.𝑔(𝑎)∈𝑊′)⇒𝑥∈Φ(𝑊′)(𝑌⃗).

Whether an element is produced depends on at most 𝐴-many elements of the input and on nothing else, for the one set 𝐴. The fixed-point equation below also needs a monotone operator; accessibility implies it, on families in the universe: the support in 𝑊 lies in any larger 𝑊′whitepaper/Fragment/Access.lean:L80-L8580/-- **Accessible operators are monotone**: the support in `W` is in
81the larger `W'`. Con-leche: `AccTuple.monoTuple`. -/
82theorem AccFam.mono {n : Nat} {Φ : (ι → V) → ι → V} {A : V} (h : AccFam n Φ A) : MonoFam n Φ := by
83 intro W W' hW hW' hle i x hx
84 obtain ⟨B, g, -, hg, hs⟩ := h W hW i x hx
85 exact hs W' hW' fun a ha => hle _ _ (hg a ha)
.

The block’s operator is accessible. Take as an example the tree type with a constructor 𝗇𝗈𝖽𝖾:(𝖭𝖺𝗍→𝖳𝗋𝖾𝖾)→𝖳𝗋𝖾𝖾 and an element 𝑥=tag(𝑗,𝑓) of Φ(𝑊): the field 𝑓 is a function from the naturals into a fibre of 𝑊. Three things have to be shown.

  1. The support. The value 𝑥 depends on 𝑊 only through the children 𝑓⋅0,𝑓⋅1,…, so its support is those childrenwhitepaper/Fragment/IndSem.lean:L1158-L11831158own supports `Bk` (by position). -/
    1159noncomputable def instSupp (ps : List V) (c : CtorSpec) (fs : List V) (Bk : Nat → V) : V :=
    1160 listUnion ((List.range c.fields.length).map fun k =>
    1161 match c.fields[c.fields.length - 1 - k]? with
    1162 | some (.reflexive tele _) =>
    1163 image (pcons (nat k)) (ctxSet M (S.ψ ls) (consList (earlier fs k) (envP ps)) tele)
    1164 | some .container => image (pcons (nat k)) (Bk k)
    1165 | _ => empty)
    1166
    1167/-- The occurrence a code stands for: at a reflexive field, the field
    1168at the code's position applied to the code's argument tuple, at the
    1169field's index expressions there; at a container field, the container
    1170value's own occurrence `gk` at the code, at the nested occurrence's
    1171index expressions. -/
    1172noncomputable def instOcc (ps : List V) (c : CtorSpec) (fs : List V) (gk : Nat → V → V) (b : V) :
    1173 List V × V :=
    1174 match c.fields[c.fields.length - 1 - idx (pfst b)]? with
    1175 | some (.reflexive _ es) =>
    1176 (S.idxVals M ls (consList (untuple (psnd b)) (consList (earlier fs (idx (pfst b))) (envP ps))) es,
    1177 appList (fieldVal fs (idx (pfst b))) (untuple (psnd b)).reverse)
    1178 | some .container =>
    1179 match S.nest with
    1180 | some N => (S.memberIdx M ls N ps, gk (idx (pfst b)) (psnd b))
    1181 | none => ([], pt)
    1182 | _ => ([], pt)
    1183
    : one occurrence for each argument 𝑧 of the field, (𝑒⃗(𝑧),𝑓⋅𝑧), where 𝑒⃗(𝑧) are the field’s index expressions. In general a reflexive field with telescope 𝑧⃗ contributes one occurrence per 𝑧⃗ fitting the telescope (a recursive field, with the empty telescope, exactly one), and an ordinary field contributes nothing. Each occurrence is named by the field’s position and the tuple 𝑧⃗.
  2. A family holding the support produces 𝑥. If every child lies in the matching fibre of 𝑊′, then 𝑓, a function whose applications all lie in fibres of 𝑊′, is a member of the function spacewhitepaper/Fragment/IndSem.lean:L1237-L12501237/-- **A fitting list fits every family holding its support** — the
    1238re-typing of each reflexive field's value, and the container's clause
    1239at each container value. -/
    1240theorem FitsFields_retype {ps : List V} (hco : S.ContOk M ls ps) {W W' : List V → V}
    1241 (hW : InUniv (S.u₀ ls) W) (hW' : InUniv (S.u₀ ls) W') :
    1242 ∀ {fields : List Field} {fs : List V}, S.FitsFields M ls W ps fields fs →
    1243 (∀ k tele es, fields[fields.length - 1 - k]? = some (.reflexive tele es) → k < fields.length →
    1244 ∀ ys, FitsVals M (S.ψ ls) (consList (earlier fs k) (envP ps)) tele ys →
    1245 appList (fieldVal fs k) ys.reverse ∈ˢ
    1246 W' (S.idxVals M ls (consList ys (consList (earlier fs k) (envP ps))) es)) →
    1247 (∀ k, fields[fields.length - 1 - k]? = some .container → k < fields.length →
    1248 ∀ N, S.nest = some N →
    1249 fieldVal fs k ∈ˢ S.classSet M ls N ps (W' (S.memberIdx M ls N ps))) →
    1250 S.FitsFields M ls W' ps fields fs
    into those fibres (by η), and ordinary fields do not mention the family; so 𝑥∈Φ(𝑊′).
  3. One bound for every family. The names of the occurrences (field position and argument tuple) must come from one set 𝐴, the same whatever 𝑊 is. For 𝗇𝗈𝖽𝖾 that is the naturals. In general 𝐴 collects, per constructor and reflexive field, the tuples fitting the field’s telescopewhitepaper/Fragment/IndSem.lean:L1080-L10971080/-- **A constructor's support bound**: for each reflexive field, the
    1081tuples of its telescope at every list fitting the fields before it
    1082relative to the one-fibre family, each coded by the field's position
    1083(a numeral in a path step, `pcons`); for each container field, the
    1084class's bound, coded likewise. An ordinary field contributes
    1085nothing; a recursive field, whose telescope is empty, contributes the
    1086one tuple `tuple []` per prefix. Con-leche: `piBound` glued along the
    1087telescope (`HoleAcc.lean`), made uniform along the fields
    1088(`TeleAcc.lean`); the container's bound `accPaths` of
    1089`ContAccFrame.lean`. -/
    1090noncomputable def ctorBound (ps : List V) (c : CtorSpec) : V :=
    1091 listUnion ((List.range c.fields.length).map fun k =>
    1092 match c.fields[c.fields.length - 1 - k]? with
    1093 | some (.reflexive tele _) =>
    1094 famUnion (S.fitsSet M ls (S.oneFam ls) ps (c.fields.drop (c.fields.length - k))) fun t =>
    1095 image (pcons (nat k)) (ctxSet M (S.ψ ls) (consList (untuple t) (envP ps)) tele)
    1096 | some .container => image (pcons (nat k)) S.classBound
    1097 | _ => empty)
    . A telescope may mention earlier fields, but by the second shape condition of Section 4.1 never a reflexive field’s value, so the telescopes do not depend on 𝑊; the bound reads them at the one-fibre family, every fibre the same one-element typewhitepaper/Fragment/IndSem.lean:L819-L822819/-- **The one-fibre set**: `{pt}` at a proposition; above it a
    820singleton of a tagged value — a type of the result universe either
    821way, with an admissible member (`oneVal`). -/
    822noncomputable def oneSet : V := if S.z ls then one else sing (tag 0 empty)
    : {𝗉𝗍} when the family is proposition-valued, the singleton of a tagged tuple when it is type-valued (the replacementwhitepaper/Fragment/IndSem.lean:L885-L896885/-- An instance's values with every recursive value replaced by the
    886constant family `Y`'s canonical member of its field's set (the value
    887`y` abstracted over the telescope), and every container value by its
    888stand-in. (`toFam one pt` is the one-fibre family's.) -/
    889noncomputable def toFam (Y y : V) (ps : List V) : List Field → List V → List V
    890 | f :: fields, v :: vs =>
    891 (match f with
    892 | .reflexive tele _ =>
    893 lamCtx M (S.ψ ls) (consList (toFam Y y ps fields vs) (envP ps)) tele fun _ => y
    894 | .container => S.contAt M ls Y ps
    895 | _ => v) :: toFam Y y ps fields vs
    896 | _, vs => vs
    , the telescope reads alikewhitepaper/Fragment/IndSem.lean:L1007-L10121007/-- A reflexive field's telescope has the same tuples at the values
    1008and at the replaced values. -/
    1009theorem ctxSet_toFam (Y y : V) (ps : List V) {L : List Field} {tele es : List Expr} {fs : List V}
    1010 (hnr : fieldNoRecDep L (.reflexive tele es)) :
    1011 ctxSet M (S.ψ ls) (consList fs (envP ps)) tele
    1012 = ctxSet M (S.ψ ls) (consList (S.toFam M ls Y y ps L fs) (envP ps)) tele := by
    ).

Hence the operator is accessible with this boundwhitepaper/Fragment/IndSem.lean:L1304-L13111304every constructor value's support is coded inside the bound, lies in
1305the input family, and carries the value to every family of the
1306universe holding it; at a container field by the container's clause.
1307Con-leche: `blockAcc_of_run`, the `AccTuple` `closed_of_acc`
1308consumes. -/
1309theorem famOp_acc {ps : List V} (hnr : S.NoRecDep) (hco : S.ContOk M ls ps) :
1310 AccFam (S.u₀ ls) (S.famOp M ls ps) (S.bound M ls ps) := by
1311 intro W hW is x hx
, and so monotonewhitepaper/Fragment/IndSem.lean:L1418-L14231418accessibility's support carries over (`AccFam.mono`). Con-leche:
1419`LfpClause.functor`'s first conjunct; `AccTuple.monoTuple`. -/
1420theorem famOp_mono {ps : List V} (hnr : S.NoRecDep) (hco : S.ContOk M ls ps) :
1421 MonoFam (S.u₀ ls) (S.famOp M ls ps) :=
1422 (S.famOp_acc M ls hnr hco).mono
1423
.

For a type-valued family, Theorem 8 below needs two more facts besides accessibility, at 𝑛=𝜑(𝑢):

𝐴∈𝒰︀𝜑(𝑢)andΦ(𝑊)∈𝒰︀𝜑(𝑢)for every𝑊∈𝒰︀𝜑(𝑢).

Both follow from the semantic form of the checker’s universe bound, the universe bound on the fieldswhitepaper/Fragment/IndSem.lean:L601-L622601/-- **The universe bound on the fields, at every family in the
602universe**: above a proposition, along any list fitting the fields
603before a position relative to a family of members of the result
604universe, an ordinary field's domain is a member of the result
605universe, and so is every entry of a reflexive field's telescope at
606every fitting prefix of the telescope. Con-leche: the constructors'
607fields are small at every hole frame of the tuple space
608(`LfpClause.fieldsOk`, `ConLeche/Model/Env/BlockLfp.lean`, the
609install's `FieldsOkB`); the installation derives it from the checker's
610field-sort check read in a model in which the former denotes the
611one-fibre family (`domsBounded_of`, `InstallInd.lean`), whence every
612family by `domsBounded_of_fam`. -/
613def DomsBounded (ps : List V) : Prop :=
614 S.z ls = false → ∀ W, InUniv (S.u₀ ls) W → ∀ c ∈ S.ctors, ∀ k f,
615 c.fields[c.fields.length - 1 - k]? = some f → k < c.fields.length →
616 ∀ fs, S.FitsFields M ls W ps (c.fields.drop (c.fields.length - k)) fs →
617 match f with
618 | .ordinary A => interp M (S.ψ ls) (consList fs (envP ps)) A ∈ˢ (univ (S.u₀ ls) : V)
619 | .reflexive tele _ => ∀ t T, tele[t]? = some T → ∀ ys,
620 FitsVals M (S.ψ ls) (consList fs (envP ps)) (tele.drop (t + 1)) ys →
621 interp M (S.ψ ls) (consList ys (consList fs (envP ps))) T ∈ˢ (univ (S.u₀ ls) : V)
622 | .container => True
: along any instance of any family in the universe, every ordinary domain and every entry of a reflexive field’s telescope is a member of 𝒰︀𝜑(𝑢) (the bound is a memberwhitepaper/Fragment/IndSem.lean:L1105-L11091105proposition), by the universe bound on the fields at the one-fibre
1106family. -/
1107theorem bound_mem_univ {ps : List V} (hz : S.z ls = false) (hb : S.DomsBounded M ls ps)
1108 (hco : S.ContOk M ls ps) : S.bound M ls ps ∈ˢ (univ (S.u₀ ls) : V) := by
1109 have hn := S.u₀_ne_zero ls hz
, the operator maps the universe to itselfwhitepaper/Fragment/IndSem.lean:L768-L775768universe**: at a proposition its fibres are truth values; above one
769they are sets of tagged tuples of members, built by replacement and
770union from sets of the universe (the class's membership in the
771universe from the container's clause). Con-leche: `LfpClause.functor`'s
772second conjunct, from `fieldsOk`. -/
773theorem famOp_maps {ps : List V} (hb : S.DomsBounded M ls ps) (hco : S.ContOk M ls ps) :
774 MapsFam (S.u₀ ls) (S.famOp M ls ps) := by
775 intro W hW is
). The universe bound on the fields comes from the checker’s field-sort check, 𝑣≤𝑢, read in a model in which the type former denotes the one-fibre family: the type former’s type

∀𝑥⃗:𝑃⃗.∀𝑦⃗:𝐽⃗.𝖲𝗈𝗋𝗍𝑢

is inhabited by the graph of any admissible family of types of the universe, so the environment holding the type former has a model for each onewhitepaper/Fragment/InstallInd.lean:L243-L247243/-- **The environment with the former has a model for every family of
244the universe**, the former its graph. -/
245noncomputable def mIndF (F : List Nat → List V → List V → V)
246 (hF : ∀ ls' ps is, F ls' ps is ∈ˢ (typeU (S.u₀ ls') : V)) (hFa : ∀ ls' ps is, S.adm ls' (F ls' ps is) = F ls' ps is) :
247 EnvModel V (S.envInd env) where
, and Theorem 2 read in the one for the one-fibre family puts every field’s domain in 𝒯︀𝜑(𝑣), and so, since 𝑣≤𝑢 and the universes are cumulative, in 𝒰︀𝜑(𝑢). No field reads an earlier reflexive field’s value, so the domains met along an instance of any family are those met along an instance of the one-fibre family (the universe bound, at every familywhitepaper/Fragment/InstallInd.lean:L429-L439429/-- **The universe bound on the fields, at every family of the result
430universe**: the one-fibre family (`oneSet`, a family of types) is the
431former's denotation in the model `mIndF`; the checker's sort facts on
432every field and every binder of a reflexive field's telescope, read
433there at the values fitting the earlier fields, bound the field's set
434at that family, hence at every family (`domsBounded_of_fam`: no field
435reads an earlier recursive field). Con-leche:
436`FieldsOkB` at every hole frame, from the holes-in-context check. -/
437theorem domsBounded_of (φ : Name → Nat) (ρ : Nat → V) {ps : List V} (hps : ps.length = S.nP)
438 (hp : FitsVals m.M (S.ψ (S.lparams.map φ)) base S.params ps) :
439 S.DomsBounded m.M (S.lparams.map φ) ps := by
).

For a proposition-valued family none of this is needed. Every constructor value is the point, so every fibre of Φ(𝑊) is a subset of {𝗉𝗍}, and the constant family {𝗉𝗍} is closedwhitepaper/Fragment/LfpSet.lean:L170-L174170/-- **At a proposition no bound is needed**: every member of `univ 0`
171is a subset of `{pt}`, so the constant family `{pt}` is closed under
172any operator into `univ 0`. Con-leche: `closedTuple_zero`,
173`ConLeche/SetModel/Access.lean`. -/
174theorem closedFam_zero {Φ : (ι → V) → ι → V} (hmaps : MapsFam 0 Φ) : ∃ L, IsClosedFam 0 Φ L := by
under Φ and lies in 𝒰︀0. This closed family needs no bound in the universe and no universe bound on the fields. Accessibility, which holds in both cases, is used here only for monotonicity.

In con-leche The operator is read off the stored constructor types with the positivity check’s variable (a hole) standing for the family (the hole operatorConLeche/Model/Env/LfpHoleOp.lean:L104-L106104/-- **The hole operator**: the block operator at the hole chains. -/
105@[expose] noncomputable def holeOp (ψ : Name → Nat) (ρp : Nat → V) : (Nat → V) → Nat → V :=
106 blockPhiG D.N (D.w ψ) ρp (fun c => D.u c ψ) (fun c => D.ids c ψ) (D.holeChains ψ)
), and monotonicity and accessibility are read off the positivity check’s run, case by case. A reading that mentions no hole is constantConLeche/Semantics/Inductives/HoleMono.lean:L71-L7371/-- **Hole-free**: the reading is the same at related frames. -/
72def ConstOn (R : FrameRel V) (a : Term) : Prop :=
73 ∀ ρ ρ', R ρ ρ' → interp V ρ a = interp V ρ' a
(the ordinary field); a function space over a hole-free domain, its fibres types, is positive when its body isConLeche/Semantics/Inductives/HoleMono.lean:L130-L139130/-- **`pi`**: a Π-type with a hole-free domain and a positive codomain
131is positive, as soon as its fibres are types at both frames (the
132grading of the walked field: "not pt" source (1)) — `piV` is monotone in
133fibres that are types (`piV_subset_mono`: a truth value included in a
134type is a truth value, and a type with a fibre that is not one is
135strict there). -/
136theorem MonoOn.pi {R : FrameRel V} {A B : Term} (hA : ConstOn R A)
137 (hB : MonoOn (R.under A) B)
138 (hT : ∀ ρ ρ', R ρ ρ' → (∀ x, x ∈ˢ interp V ρ A → IsTy (interp V (cons x ρ) B)) ∧
139 (∀ x, x ∈ˢ interp V ρ' A → IsTy (interp V (cons x ρ') B))) :
and accessible with its body’s bound glued over the domainConLeche/Semantics/Inductives/HoleAcc.lean:L233-L243233/-- **Π over a hole-free domain**: the support of a member over a small
234domain is the glued supports of its values, the body's items one binder
235down (the bound variable is no admissible position); a member over a
236domain that is not small (`w ≠ 0`) is the point, whose membership needs
237no item (`PtOn`). At the target frame the member lies in the Π by
238`mem_piV_of_app`, the fibres at both frames being types (`hT`, the
239grading: "not pt" source (1)). -/
240theorem AccOn.pi {w : Nat} {Q : Nat → Nat → Prop} {R : FrameRel V} {D B : Term}
241 (hD : ConstOn R D)
242 {Bb : (Nat → V) → V} (hB : AccOn w (shiftQ Q) (R.underBoth D) Bb B)
243 (hT : FibTyOn R D B) (hP : w ≠ 0 → PtOn (R.underBoth D) B) :
(the reflexive field); a hole applied to hole-free arguments is positiveConLeche/Semantics/Inductives/HoleMono.lean:L158-L162158/-- **`holeApp`**: a hole applied to hole-free arguments, at its full
159arity, is positive. -/
160theorem MonoOn.holeApp {R : FrameRel V} {h : Nat} {es : List Term}
161 (hh : HoleOn R h es.length) (hes : ∀ e ∈ es, ConstOn R e) :
162 MonoOn R (Term.mkAppN (.bvar h) es) := by
and accessible with the bound {𝗉𝗍}ConLeche/Semantics/Inductives/HoleAcc.lean:L321-L324321/-- **A member hole at its full arity, at hole-free arguments.** -/
322theorem AccOn.holeApp {w : Nat} {Q : Nat → Nat → Prop} {R : FrameRel V} {h : Nat}
323 {es : List Term} (hQ : Q h es.length) (hes : ∀ e ∈ es, ConstOn R e) :
324 AccOn w Q R (fun _ => unitSet) (Term.mkAppN (.bvar h) es) := by
(the recursive field). Assembled along the fields, that is the fit’s accessibility, for both kinds of family, with a bound in the universe for a type-valued oneConLeche/Model/Inductives/BlockAccRunCont.lean:L311-L316311frame**, with a bound that is a set of the level at a `Type`-valued one
312— whence the operator's accessibility, (W) and monotonicity: the block theorem with the
313container rules read at the walk's carrier (coverage) and the walk
314context's sort (the block's level). -/
315theorem blockAcc_of_run {F : Nat}
316 {env : Env} (mp : EnvModelM V env) {d : BlockData V} {lps : List Name} {p₁ : BlockShape} {isRec : Bool} {p : BlockShape}
(the notion aboveConLeche/SetModel/Access.lean:L56-L6356/-- **`A`-accessibility** of an operator from `kI`-tuples over `IsI` to
57`kO`-tuples over `IsO`. -/
58def AccTuple (w kI : Nat) (IsI : Nat → V) (kO : Nat) (IsO : Nat → V)
59 (Φ : (Nat → V) → Nat → V) (A : V) : Prop :=
60 ∀ X, InTupleSpace w kI IsI X → ∀ m, m < kO → ∀ i, i ∈ˢ IsO m → ∀ x, x ∈ˢ app (Φ X m) i →
61 ∃ (B : V) (g : V → Nat × V × V), B ⊆ˢ A ∧ (∀ a, a ∈ˢ B → InTup kI IsI X (g a)) ∧
62 ∀ X', InTupleSpace w kI IsI X' → (∀ a, a ∈ˢ B → InTup kI IsI X' (g a)) →
63 x ∈ˢ app (Φ X' m) i
), and the operator’s monotonicityConLeche/Model/Env/BlockLfp.lean:L527-L531527/-- **The operator is monotone**, from its accessibility (`AccW.mono`). -/
528theorem mono (h : LfpClause acval D) {ψ : Name → Nat} {ρp : Nat → V}
529 (hsat : Sat V (D.params ψ).reverse ρp) :
530 MonoTuple (D.w ψ) D.N (D.idx ψ ρp) (D.Φ ψ ρp) :=
531 (h.acc ψ ρp hsat).mono
follows from it, as in the fragment. The fragment’s simplification is to take the field kinds from the specification instead of the run. The universe bound on the fields the real proof records from a check made for the proof alone, the constructor type-checked with the holes in context (the recorded boundConLeche/Model/Env/BlockLfp.lean:L466-L472466 /-- **the constructors' fields are small** at a `Type`-valued block, at
467 every hole frame of the tuple space (the frame walk of a container reads its constructors' fields along the
468 accessibility relation, which supports small elements only — the
469 install's own `FieldsOkB`, recorded) -/
470 fieldsOk : ∀ (ψ : Name → Nat) (ρp : Nat → V), Sat V (D.params ψ).reverse ρp → D.w ψ ≠ 0 →
471 ∀ X, InTupleSpace (D.w ψ) D.N (D.idx ψ ρp) X → ∀ c, c < D.N → ∀ j, j < D.nctors c →
472 FieldsOkB (D.w ψ) (D.frame ψ ρp X) (D.fields ψ c j)
); the fragment reads it off the constructor’s ordinary typing.

4.2.4. The least fixed point

A family 𝐿 is closed under Φwhitepaper/Fragment/LfpSet.lean:L64-L6764/-- A **closed family** of `Φ`: in the universe, and a pre-fixed point.
65Con-leche: `IsClosedTuple`. -/
66def IsClosedFam (n : Nat) (Φ : (ι → V) → ι → V) (W : ι → V) : Prop :=
67 InUniv n W ∧ FamLe (Φ W) W
, in 𝒰︀𝑛, when every fibre of 𝐿 is a member of 𝒰︀𝑛 and Φ(𝐿)⊆𝐿 fibrewise.

Theorem 8 (A closed family from accessibility). Let 𝑛≥1. An operator Φ on families that maps families in 𝒰︀𝑛 to families in 𝒰︀𝑛 and is accessible with a bound 𝐴∈𝒰︀𝑛 has a closed familywhitepaper/Fragment/Access.lean:L292-L303292/-- **A closed family from accessibility.** At a positive universe,
293an operator that maps families in the universe to families in the
294universe and is accessible with a bound `A` in the universe has a
295closed family in the universe: the limit family. An element `Φ`
296produces from it has a support, each occurrence in some stage; the
297node whose subtree at `a` is a tree of the occurrence `g a`'s stage
298has that support in the union of its subtrees' stages, so its stage
299produces the element, which is therefore in the limit. No
300monotonicity is used. Con-leche: `closed_of_acc`,
301`ConLeche/SetModel/Access.lean`. -/
302theorem closed_of_acc (hn : n ≠ 0) (hA : A ∈ˢ (univ n : V)) (hmaps : MapsFam n Φ)
303 (hacc : AccFam n Φ A) : ∃ L, IsClosedFam n Φ L := by
in 𝒰︀𝑛 (as in con-lecheConLeche/SetModel/Access.lean:L240-L244240/-- **(W) from accessibility.** At a positive level, an operator that
241maps the tuple space into itself and is `A`-accessible for a set `A` of
242the level has a closed tuple. No monotonicity is used. -/
243theorem closed_of_acc (hw : w ≠ 0) (hA : A ∈ˢ (tg w : V)) (hmaps : MapsTuple w k Is Φ)
244 (hacc : AccTuple w k Is k Is Φ A) : ∃ L, IsClosedTuple w k Is Φ L := by
):

∃𝐿∈𝒰︀𝑛.Φ(𝐿)⊆𝐿.
Proof. Iterate Φ along well-founded treeswhitepaper/Fragment/Access.lean:L163-L198163/-- Lean-level well-founded trees branching over the sets: a leaf, or
164a node with a subtree for every set. Con-leche: `BT`. -/
165inductive BT (V : Type u) : Type u
166 | leaf : BT V
167 | node : (V → BT V) → BT V
168
169namespace AccIter
170
171variable (Φ : (ι → V) → ι → V) (A : V)
172
173/-- The fibrewise union of an `A`-indexed family of families.
174Con-leche: `unionTup`. -/
175noncomputable def unionFam (F : V → ι → V) : ι → V := fun i => famUnion A fun a => F a i
176
177/-- **The stage at a tree**: the empty family at a leaf, `Φ` of the
178union of the subtrees' stages at a node. Con-leche: `stage`. -/
179noncomputable def stage : BT V → ι → V
180 | .leaf => fun _ => empty
181 | .node f => Φ (unionFam A fun a => stage (f a))
182
183/-- **A tree's code**: its set of paths over `A` — the empty path at a
184node, and a step `a` onto every path of the subtree at `a`.
185Con-leche: `code`. -/
186noncomputable def code : BT V → V
187 | .leaf => empty
188 | .node f => binUnion one (famUnion A fun a => image (pcons a) (code (f a)))
189
190open Classical in
191/-- A tree with the given code, if any. Con-leche: `pick`. -/
192noncomputable def pick (c : V) : BT V :=
193 if h : ∃ T, code A T = c then Classical.choose h else .leaf
194
195/-- **The limit family**: the union of the stages over all codes.
196Con-leche: `limTup`. -/
197noncomputable def limFam : ι → V :=
198 fun i => famUnion (power (accPaths A)) fun c => stage Φ A (pick A c) i
branching over all sets (a tree is a leaf, or a node with a subtree for every set). The stage at a leaf is the empty family, the stage at a node is Φ of the union over 𝑎∈𝐴 of its subtrees’ stages, and the closed family is the union of the stages over all trees. It is closed by accessibilitywhitepaper/Fragment/Access.lean:L304-L320304 refine ⟨limFam Φ A, limFam_mem hn hA hmaps, ?_⟩
305 intro i x hx
306 obtain ⟨B, g, hBA, hgL, hsupp⟩ := hacc _ (limFam_mem hn hA hmaps) i x hx
307 -- every occurrence of the support lies in some stage: choose its tree
308 have hT : ∀ a, a ∈ˢ B → ∃ T : BT V, (g a).2 ∈ˢ stage Φ A T (g a).1 :=
309 fun a ha => mem_limFam.mp (hgL a ha)
310 classical
311 let f : V → BT V := fun a => if h : a ∈ˢ B then Classical.choose (hT a h) else .leaf
312 have hstage : x ∈ˢ stage Φ A (.node f) i := by
313 simp only [stage]
314 refine hsupp _ (fun i' => famUnion_mem_univ hn hA fun a _ => stage_mem hn hA hmaps (f a) i') ?_
315 intro a ha
316 refine mem_unionFam.mpr ⟨a, hBA a ha, ?_⟩
317 have : f a = Classical.choose (hT a ha) := dite_eq_left ha
318 rw [this]
319 exact Classical.choose_spec (hT a ha)
320 exact mem_limFam.mpr ⟨_, hstage⟩
: an element Φ produces from it has a support of at most 𝐴-many occurrences, each in some stage, and the node whose subtree at 𝑎 is a tree of the occurrence 𝑔(𝑎)‘s stage produces the element at its own stage. It is in the universe because every stage is (Φ preserves the universe, which is closed under 𝐴-indexed unions), and because the union over all trees is a union over a set. A stage depends on its tree only through the tree’s code, its set of finite paths over 𝐴, and the codes are members of the power set of all finite paths over 𝐴, itself a countable union of members of the universe (the codewhitepaper/Fragment/Access.lean:L183-L188183/-- **A tree's code**: its set of paths over `A` — the empty path at a
184node, and a step `a` onto every path of the subtree at `a`.
185Con-leche: `code`. -/
186noncomputable def code : BT V → V
187 | .leaf => empty
188 | .node f => binUnion one (famUnion A fun a => image (pcons a) (code (f a)))
, the stage depends on the code onlywhitepaper/Fragment/Access.lean:L221-L223221/-- **The stage depends on the tree only through its code.**
222Con-leche: `stage_eq_of_code`. -/
223theorem stage_eq_of_code : ∀ T T' : BT V, code A T = code A T' → stage Φ A T = stage Φ A T'
, the limit is in the universewhitepaper/Fragment/Access.lean:L284-L290284/-- The limit family is in the universe: a union over the codes, a
285member of the universe as the power set of the paths. Con-leche:
286`limTup_mem`. -/
287theorem limFam_mem (hn : n ≠ 0) (hA : A ∈ˢ (univ n : V)) (hmaps : MapsFam n Φ) :
288 InUniv n (limFam Φ A) := fun i =>
289 famUnion_mem_univ hn (power_mem_univ hn (accPaths_mem_univ hn hA)) fun _ _ =>
290 stage_mem hn hA hmaps _ i
). □

With a closed family 𝐿0 in hand, the least fixed point is a set construction, inside the set theory: fibrewise the intersection of the closed familieswhitepaper/Fragment/LfpSet.lean:L82-L8982/-- **The least fixed point of `Φ` inside the set theory**: fibrewise
83the intersection of the closed families when there is one, separated
84from a chosen closed family `L₀`; the empty family otherwise.
85Con-leche: `lfpTuple`, `ConLeche/SetTheory/Derive/LfpTuple.lean`. -/
86noncomputable def lfpFamSet (n : Nat) (Φ : (ι → V) → ι → V) : ι → V :=
87 if h : ∃ L, IsClosedFam n Φ L then
88 fun i => sep (Classical.choose h i) fun x => ∀ X, IsClosedFam n Φ X → x ∈ˢ X i
89 else fun _ => empty
, separated from 𝐿0,

lfp(Φ)(𝑌⃗)={𝑥∈𝐿0(𝑌⃗)|𝑥∈𝐿(𝑌⃗)for every closed family𝐿}.

Its fibres are members of 𝒰︀𝑛whitepaper/Fragment/LfpSet.lean:L111-L113111/-- **Formation, unconditional**: the fibres of the least fixed point
112are members of the universe. Con-leche: `lfpTuple_mem`. -/
113theorem lfpFamSet_mem (n : Nat) (Φ : (ι → V) → ι → V) : InUniv n (lfpFamSet n Φ) := by
, as separations from members; it lies below every closed familywhitepaper/Fragment/LfpSet.lean:L106-L108106/-- **Leastness**: the least fixed point lies below every closed
107family. Con-leche: `lfpTuple_le`. -/
108theorem lfpFamSet_least {X : ι → V} (hX : IsClosedFam n Φ X) : FamLe (lfpFamSet n Φ) X :=
; and when Φ is monotone and maps 𝒰︀𝑛 to itself it is a fixed pointwhitepaper/Fragment/LfpSet.lean:L137-L141137/-- **The fixed-point equation**, fibrewise. Con-leche:
138`lfpTuple_eq`. -/
139theorem lfpFamSet_eq (h : ∃ L, IsClosedFam n Φ L) (hmono : MonoFam n Φ) (hmaps : MapsFam n Φ)
140 (i : ι) : Φ (lfpFamSet n Φ) i = lfpFamSet n Φ i :=
141 Sub.antisymm (lfpFamSet_closed h hmono i) (lfpFamSet_fixed h hmono hmaps i)
, Φ(lfp(Φ))=lfp(Φ), and supports inductionwhitepaper/Fragment/LfpSet.lean:L154-L160154/-- **Induction**: a property closed under `Φ` on the family's
155separation by it holds on the whole family — the separation is a
156closed family, so the least fixed point lies below it. Con-leche:
157`lfpTuple_induction`. -/
158theorem lfpFamSet_induction (h : ∃ L, IsClosedFam n Φ L) (hmono : MonoFam n Φ) (P : ι → V → Prop)
159 (hP : ∀ i x, x ∈ˢ Φ (sepFam n Φ P) i → P i x) :
160 ∀ i x, x ∈ˢ lfpFamSet n Φ i → P i x := by
: a property that holds of every element Φ produces from the family’s separation by it holds on the whole family, because the separation is a closed family and the least one lies below it.

4.2.5. The family and the constructors

The block’s operator has a closed family in 𝒰︀𝜑(𝑢): for a type-valued family by Theorem 8, for a proposition-valued one the constant family {𝗉𝗍} (the closed familywhitepaper/Fragment/IndSem.lean:L1443-L14491443/-- **A closed family in the universe**: at a proposition the family
1444of truth values `{pt}` (`closedFam_zero`); above one, from
1445accessibility (`closed_of_acc`). Con-leche: `LfpClause.functor`'s
1446third conjunct, `closedTuple_zero` and `closed_of_acc`. -/
1447theorem closedFam {ps : List V} (hnr : S.NoRecDep) (hb : S.DomsBounded M ls ps)
1448 (hco : S.ContOk M ls ps) : ∃ L, IsClosedFam (S.u₀ ls) (S.famOp M ls ps) L := by
1449 cases hz : S.z ls with
). The family of the block is its least fixed point,

⟦𝐼⟧⋅𝑋⃗⋅𝑌⃗=lfp(Φ)(𝑌⃗)

(the familywhitepaper/Fragment/IndSem.lean:L1458-L14611458/-- **The family**: the fibre at the index values `is` is the least
1459fixed point of the block's operator inside the set theory.
1460Con-leche: `LfpDatum.carrier`, `lfpTuple` of the hole operator. -/
1461noncomputable def Fam (ps is : List V) : V := lfpFamSet (S.u₀ ls) (S.famOp M ls ps) is
, the type former’s setwhitepaper/Fragment/IndSem.lean:L1641-L16431641/-- **The type former's set** at `ls`: the graph over the index and
1642parameter contexts whose value is the fibre. -/
1643noncomputable def famSet : V := S.famSetF M ls (S.Fam M)
, its graph over the parameters and indices). Its fibres are typeswhitepaper/Fragment/IndSem.lean:L1561-L15651561/-- **The fibre is a type of the result sort** (`typeU`): at a
1562proposition a truth value; above it a set of tagged values, which is
1563strict (no tagged value is the point or a member of it). -/
1564theorem Fam_mem_typeU {ps : List V} (hnr : S.NoRecDep) (hb : S.DomsBounded M ls ps)
1565 (hco : S.ContOk M ls ps) (is : List V) : S.Fam M ls ps is ∈ˢ (typeU (S.u₀ ls) : V) := by
of 𝒯︀𝜑(𝑢) (above), which is law 1 for the type formerwhitepaper/Fragment/InstallInd.lean:L555-L562555/-- **The former's type law**: its type is a well-denoted type and its
556set is a member — the fibres are types (`Fam_mem_typeU`). -/
557theorem type_ok_ind (φ : Name → Nat) (ρ : Nat → V) {ls : List Level}
558 (hls : ls.length = S.indInfo.lparams.length) :
559 WellDenoted (S.M₃ m.M) φ ρ (S.indInfo.type.instL S.indInfo.lparams ls) ∧
560 IsTy (interp (S.M₃ m.M) φ ρ (S.indInfo.type.instL S.indInfo.lparams ls)) ∧
561 S.M₃ m.M S.name (ls.map (Level.eval φ)) ∈ˢ
562 interp (S.M₃ m.M) φ ρ (S.indInfo.type.instL S.indInfo.lparams ls) := by
. A type-valued fibre is a set of tagged tuples, hence strict, and a proposition-valued fibre is a truth value, so either way the fibre is a type of the result sortwhitepaper/Fragment/IndSem.lean:L1561-L15641561/-- **The fibre is a type of the result sort** (`typeU`): at a
1562proposition a truth value; above it a set of tagged values, which is
1563strict (no tagged value is the point or a member of it). -/
1564theorem Fam_mem_typeU {ps : List V} (hnr : S.NoRecDep) (hb : S.DomsBounded M ls ps)
. A member of a type-valued fibre is a tagged tuple and carries its constructor and its fields; a member of a proposition-valued fibre is the point and carries nothing.

The rest of this section rests on the fixed-point equationwhitepaper/Fragment/IndSem.lean:L1471-L14771471/-- **The fixed-point equation**: the operator at the family is the
1472family. Con-leche: `LfpClause.carrier_eq`. -/
1473theorem famOp_Fam {ps : List V} (hnr : S.NoRecDep) (hb : S.DomsBounded M ls ps)
1474 (hco : S.ContOk M ls ps) (is : List V) :
1475 S.famOp M ls ps (S.Fam M ls ps) is = S.Fam M ls ps is :=
1476 lfpFamSet_eq (S.closedFam M ls hnr hb hco) (S.famOp_mono M ls hnr hco) (S.famOp_maps M ls hb hco) is
1477
, read in both directions. A member of the fibre at 𝑌⃗ is a constructor valuewhitepaper/Fragment/IndSem.lean:L1478-L14861478/-- **The family's case analysis**: a member of the fibre at `is` is
1479a constructor instance over the family at `is`, and conversely.
1480Con-leche: `LfpClause.carrier_case`. -/
1481theorem mem_Fam {ps : List V} (hnr : S.NoRecDep) (hb : S.DomsBounded M ls ps)
1482 (hco : S.ContOk M ls ps) {is : List V} {t : V} :
1483 t ∈ˢ S.Fam M ls ps is ↔ S.Inst M ls (S.Fam M ls ps) ps is t := by
1484 rw [← S.famOp_Fam M ls hnr hb hco]
1485 exact S.mem_famOp M ls
1486
whose fields fit the family and whose index expressions read as 𝑌⃗, and conversely. The converse is law 1 for the constructors: 𝑐𝑗 denotes the function that takes the parameters and the fields and returns tag(𝑗,𝐹⃗) (a constructor’s setwhitepaper/Fragment/IndSem.lean:L1656-L16611656/-- **A constructor's set**: the abstraction over the parameters and
1657fields (read in the model with the former) of the constructor's
1658value. -/
1659noncomputable def ctorSet (j : Nat) (c : CtorSpec) : V :=
1660 lamCtx (S.M₁ M) (S.ψ ls) base (S.fieldCtx c.fields ++ S.params) fun ρ' =>
1661 S.ctorVal ls j (readEnv c.fields.length ρ')
), a value in the fibrewhitepaper/Fragment/IndSem.lean:L1487-L14961487/-- **A constructor's value is in the fibre** at its index expressions
1488when its fields fit the family. Con-leche: `LfpClause.ctor` with the
1489carrier's closure. -/
1490theorem ctorVal_mem_Fam {ps : List V} (hnr : S.NoRecDep) (hb : S.DomsBounded M ls ps)
1491 (hco : S.ContOk M ls ps) {j : Nat}
1492 {c : CtorSpec} (hc : S.ctors[j]? = some c) {fs : List V}
1493 (hfit : S.FitsFields M ls (S.Fam M ls ps) ps c.fields fs) :
1494 S.ctorVal ls j fs ∈ˢ S.Fam M ls ps (S.idxVals M ls (consList fs (envP ps)) c.idx) :=
1495 (S.mem_Fam M ls hnr hb hco).mpr ⟨j, c, fs, hc, hfit, rfl, rfl⟩
1496
at its index expressions whenever its fields fit (the lawwhitepaper/Fragment/InstallInd.lean:L779-L785779/-- **A constructor's type law.** -/
780theorem type_ok_ctor {j : Nat} {c : CtorSpec} (hc : S.ctors[j]? = some c) (φ : Name → Nat)
781 (ρ : Nat → V) {ls : List Level} (hls : ls.length = (S.ctorInfo c).lparams.length) :
782 WellDenoted (S.M₃ m.M) φ ρ ((S.ctorInfo c).type.instL (S.ctorInfo c).lparams ls) ∧
783 IsTy (interp (S.M₃ m.M) φ ρ ((S.ctorInfo c).type.instL (S.ctorInfo c).lparams ls)) ∧
784 S.M₃ m.M c.name (ls.map (Level.eval φ)) ∈ˢ
785 interp (S.M₃ m.M) φ ρ ((S.ctorInfo c).type.instL (S.ctorInfo c).lparams ls) := by
). The forward direction is the inversion the 𝜄 law needs. The least fixed point’s induction principle is induction over the familywhitepaper/Fragment/IndSem.lean:L1497-L15071497/-- **Induction over the family**: a property that holds of every
1498constructor instance over the family's separation by it holds on the
1499family. Con-leche: `lfpTuple_induction`, the block's induction the
1500recursor's graph is built with. -/
1501theorem Fam_induction {ps : List V} (hnr : S.NoRecDep) (hb : S.DomsBounded M ls ps)
1502 (hco : S.ContOk M ls ps) (P : List V → V → Prop)
1503 (h : ∀ is x, S.Inst M ls (fun is' => sep (S.Fam M ls ps is') (P is')) ps is x → P is x) :
1504 ∀ is x, x ∈ˢ S.Fam M ls ps is → P is x :=
1505 lfpFamSet_induction (S.closedFam M ls hnr hb hco) (S.famOp_mono M ls hnr hco) P fun is x hx =>
1506 h is x ((S.mem_famOp M ls).mp hx)
1507
, on which the recursor is built. For a proposition-valued family every constructor value is the point, so the fibre is the truth valuewhitepaper/Fragment/IndSem.lean:L1539-L15431539/-- At a proposition a member of the fibre is the point and some
1540decoding exists. -/
1541theorem mem_Fam_true {ps : List V} (hnr : S.NoRecDep) (hb : S.DomsBounded M ls ps)
1542 (hco : S.ContOk M ls ps) (hz : S.z ls = true) {is : List V} {t : V} :
1543 t ∈ˢ S.Fam M ls ps is ↔ t = pt ∧ ∃ x, S.Mem M ls ps is x := by
of “some constructor reaches these indices”, and every constructor denotes the point.

In con-leche The least fixed point is the same constructionConLeche/SetTheory/Derive/LfpTuple.lean:L78-L8778/-- **The least pre-fixed tuple of `Φ`** — componentwise, fibrewise the
79intersection of the closed tuples when there is one (separated from a
80chosen closed tuple), dropped to `∅` if it left `strictU w`; the empty
81tuple otherwise. -/
82noncomputable def lfpTuple (w k : Nat) (Is : Nat → V) (Φ : (Nat → V) → Nat → V) : Nat → V :=
83 fun m =>
84 if h : ∃ L, IsClosedTuple w k Is Φ L then
85 famOf (fun i => dropTo (strictU w) (sep (app (Classical.choose h m) i)
86 (fun x => ∀ X, IsClosedTuple w k Is Φ X → x ∈ˢ app (X m) i))) (Is m)
87 else famOf (fun _ => empty) (Is m)
over a tuple of families, one per type former of the block, each a graph over an index set. What the model records of an installed block is one clause: the operator maps the universe to itself and its fit is accessible, for both kinds of family (the operatorConLeche/Model/Env/BlockLfp.lean:L404-L411404 /-- **`Φ` maps the tuple space into itself** -/
405 maps : ∀ (ψ : Name → Nat) (ρp : Nat → V), Sat V (D.params ψ).reverse ρp →
406 MapsTuple (D.w ψ) D.N (D.idx ψ ρp) (D.Φ ψ ρp)
407 /-- **the hole fit is accessible**, with a bound of the level at a
408 `Type`-valued block (task #327): the operator's accessibility, (W) and
409 monotonicity, and the fit's growth follow at every level -/
410 fitAcc : ∀ (ψ : Name → Nat) (ρp : Nat → V), Sat V (D.params ψ).reverse ρp →
411 ∃ A, (D.w ψ ≠ 0 → A ∈ˢ (tg (D.w ψ) : V)) ∧ D.FitAcc ψ ρp A
). So it has a closed family (the constant family at a proposition, and from accessibility for a type-valued familyConLeche/SetModel/Access.lean:L298-L303298theorem AccW.closed {w k : Nat} {Is : Nat → V} {Φ : (Nat → V) → Nat → V}
299 (h : AccW w k Is Φ) (hmaps : MapsTuple w k Is Φ) : ∃ L, IsClosedTuple w k Is Φ L := by
300 by_cases hw : w = 0
301 · subst hw; exact closedTuple_zero hmaps
302 · obtain ⟨A, hA, hacc⟩ := h
303 exact closed_of_acc hw (hA hw) hmaps hacc
) and is monotoneConLeche/Model/Env/BlockLfp.lean:L527-L531527/-- **The operator is monotone**, from its accessibility (`AccW.mono`). -/
528theorem mono (h : LfpClause acval D) {ψ : Name → Nat} {ρp : Nat → V}
529 (hsat : Sat V (D.params ψ).reverse ρp) :
530 MonoTuple (D.w ψ) D.N (D.idx ψ ρp) (D.Φ ψ ρp) :=
531 (h.acc ψ ρp hsat).mono
; its fibres are the tagged tuples of fitting fields (the fibresConLeche/Model/Env/BlockLfp.lean:L412-L417412 /-- **what `Φ` is**: component `c`'s fibre at `(X, t)` is the set of
413 injections of the spines fitting one of `c`'s constructors -/
414 fibre : ∀ (ψ : Name → Nat) (ρp : Nat → V), Sat V (D.params ψ).reverse ρp →
415 ∀ X, InTupleSpace (D.w ψ) D.N (D.idx ψ ρp) X → ∀ c, c < D.N →
416 ∀ t, t ∈ˢ D.idx ψ ρp c → ∀ x,
417 x ∈ˢ app (D.Φ ψ ρp X c) t ↔ ∃ j fs, D.HFits ψ ρp X t c j fs ∧ x = D.inj ψ c j fs
), and the type former denotes the least fixed pointConLeche/Model/Env/BlockLfp.lean:L188-L190188/-- **The carrier**: the least pre-fixed tuple of the operator. -/
189@[expose] noncomputable def carrier (ψ : Name → Nat) (ρp : Nat → V) : Nat → V :=
190 lfpTuple (D.w ψ) D.N (D.idx ψ ρp) (D.Φ ψ ρp)
(the fixed-point equationConLeche/Model/Env/BlockLfp.lean:L533-L536533/-- **The carrier is a fixed point**, componentwise. -/
534theorem carrier_eq (h : LfpClause acval D) {ψ : Name → Nat} {ρp : Nat → V}
535 (hsat : Sat V (D.params ψ).reverse ρp) {c : Nat} (hc : c < D.N) :
536 D.Φ ψ ρp (D.carrier ψ ρp) c = D.carrier ψ ρp c :=
). Its constructors are tagged pairsConLeche/SetModel/TaggedSum.lean:L6565noncomputable def inj (i : Nat) (a : V) : V := spair (vnat i) a
of nested pairsConLeche/SetModel/TupleTower.lean:L9393noncomputable def mkTower : List V → V
, the two kinds of family in one carrierConLeche/SetModel/TaggedSum.lean:L61-L6261noncomputable def sumSet (w : Nat) (f : Nat → V) : V :=
62 sigmaSet w omega (natFibre f)
.

4.2.6. The recursor

Fix values 𝐶 for the motive and 𝑆⃗ for the minor premises, fitting the recursor’s telescope. The rules determine the recursor’s value 𝜓(𝑌⃗,𝑥)∈𝐶⋅𝑌⃗⋅𝑥 on every member 𝑥 of the family’s fibre at index values 𝑌⃗. On a constructor value it must be the minor premise applied to the fields and to the inductive hypotheses,

𝜓(𝑌⃗,tag(𝑗,𝐹⃗))=𝑆𝑗⋅𝐹⃗⋅ℎ⃗,

where ℎ⃗ has one entry per reflexive field 𝑓 of 𝑐𝑗, with index expressions 𝑒⃗: the function 𝑧⃗↦𝜓(𝑒⃗(𝑧⃗),𝑓⋅𝑧⃗) over the field’s telescope, and simply 𝜓(𝑒⃗,𝑓) when the telescope is empty. That this equation has exactly one solution is the recursion theorem. In the fragment it is proved by the same device as the family. The recursor’s graph, the relation “the value at (𝑌⃗,𝑥) is 𝑣”, is the least fixed pointwhitepaper/Fragment/IndRec.lean:L89-L9289/-- **The recursor's graph**: the least fixed point of `rstep`.
90Con-leche: `gGraph`. -/
91noncomputable def RecGraph (ps : List V) (m : V) (mins is : List V) (t v : V) : Prop :=
92 Lfp (S.rstepT M ls) (ps, m, mins, is, t, v)
of the operator that reads the equation as a stepwhitepaper/Fragment/IndRec.lean:L73-L8173/-- **The operator** whose least fixed point is the recursor's graph:
74at the constructor value of fitting fields, the value is the
75constructor's minor at the fields and the inductive hypotheses.
76Con-leche: the graph functor `gStep` (`GraphRec.lean`). -/
77noncomputable def rstep (R : RecP V) (ps : List V) (m : V) (mins is : List V) (t v : V) : Prop :=
78 ∃ j c fs ihs, S.ctors[j]? = some c ∧ S.FitsFields M ls (S.Fam M ls ps) ps c.fields fs ∧
79 is = S.idxVals M ls (consList fs (envP ps)) c.idx ∧ t = S.ctorVal ls j fs ∧
80 ListRel (S.IhOk M ls R ps m mins fs) c.recFields ihs ∧
81 v = appList (S.minorAt mins j) (fs.reverse ++ ihs)
, a least fixed point on predicates this time, which the ambient logic’s impredicative 𝖯𝗋𝗈𝗉 provides outrightwhitepaper/Fragment/IndLib.lean:L101-L104101/-- **The least fixed point** of an operator on predicates: the
102intersection of every predicate closed under it. -/
103def Lfp {α : Sort _} (Φ : (α → Prop) → (α → Prop)) : α → Prop :=
104 fun a => ∀ P : α → Prop, (∀ b, Φ P b → P b) → P a
. It is single-valuedwhitepaper/Fragment/IndRec.lean:L155-L159155/-- **Single-valuedness of the graph**: two values at one major come
156from one decoding, and their inductive hypotheses agree by induction
157over the graph. Con-leche: the uniqueness half of `GraphRecKit.exu`. -/
158theorem RecGraph_fun (hu : S.Uniq M ls) {ps : List V} (hp : FitsVals M (S.ψ ls) base S.params ps)
159 {m : V} {mins is : List V} {t v v' : V}
by induction over the graph, using that tagged tuples are injective, and totalwhitepaper/Fragment/IndRec.lean:L213-L219213/-- **Totality of the graph on the family** (with single-valuedness,
214the recursion theorem): by induction over the family — at a
215constructor instance over the family's separation by "the graph has a
216value", every application of a reflexive field has one, and the
217inductive hypotheses' semantic values build the instance's.
218Con-leche: the existence half of `GraphRecKit.exu`, by `ind`. -/
219theorem RecGraph_total {ps : List V} (hpl : S.nest = none) (hnr : S.NoRecDep)
by induction over the family.

When the family is proposition-valued and the motive is not, the major is the point and carries no fields. A major decodes as a constructor 𝑐𝑗 with fields 𝐹⃗ when it is the value of 𝑐𝑗 applied to fields 𝐹⃗ that fit 𝑐𝑗 and whose index expressions read as the indices 𝑌⃗; the pair is a decoding of the major. The point may have several decodings, and the equation has one instance per decoding. The graph is single-valued only because any two decodings agreewhitepaper/Fragment/IndRec.lean:L131-L141131/-- **Two decodings of one value agree**: above a proposition the
132value is the tagged tuple of either (tags and tuples are injective);
133at a proposition by uniqueness of decodings. -/
134theorem decode_unique (hu : S.Uniq M ls) {ps : List V} (hp : FitsVals M (S.ψ ls) base S.params ps)
135 {is : List V} {j j' : Nat} {c c' : CtorSpec} {fs fs' : List V}
136 (hc : S.ctors[j]? = some c) (hc' : S.ctors[j']? = some c')
137 (hfit : S.FitsFields M ls (S.Fam M ls ps) ps c.fields fs)
138 (hfit' : S.FitsFields M ls (S.Fam M ls ps) ps c'.fields fs')
139 (his : is = S.idxVals M ls (consList fs (envP ps)) c.idx)
140 (his' : is = S.idxVals M ls (consList fs' (envP ps)) c'.idx)
141 (ht : S.ctorVal ls j fs = S.ctorVal ls j' fs') : j = j' ∧ fs = fs' := by
: under a large eliminator the subsingleton criterion as the checker states itwhitepaper/Fragment/InstallInd.lean:L733-L738733/-- **Uniqueness of decodings** under the subsingleton
734criterion: at a proposition with a large eliminator the checker admits
735at most one constructor, every field of which is a proposition or one
736of the indices. -/
737theorem uniq_of (φ : Name → Nat) (hz : S.z (S.lparams.map φ) = true) (hlarge : S.large = true) :
738 S.Uniq m.M (S.lparams.map φ) := by
reads semanticallywhitepaper/Fragment/Uniq.lean:L40-L5040/-- **The subsingleton criterion, semantically**: at a proposition,
41at most one constructor, and every field of a fitting instance is
42the point (its domain is a proposition) or is read off the
43constructor's index expressions (the field's variable is one of
44them). -/
45def Subsingleton : Prop :=
46 S.ctors.length ≤ 1 ∧
47 ∀ c ∈ S.ctors, ∀ ps : List V, FitsVals M (S.ψ ls) base S.params ps → ∀ fs : List V,
48 S.FitsFields M ls (S.Fam M ls ps) ps c.fields fs →
49 ∀ k, k < c.fields.length →
50 fieldVal fs k = pt ∨ Expr.bvar (c.fields.length - 1 - k) ∈ c.idx
as uniqueness of decodingswhitepaper/Fragment/Uniq.lean:L60-L6460/-- **Uniqueness from the subsingleton criterion**: two decodings
61at one index are equal — each is the tagged tuple of
62fields every one of which is the point or one of the (shared) index
63values. -/
64theorem uniq_of_subsingleton (hsub : S.Subsingleton M ls) : S.Uniq M ls := by
, as Theorem 10′s proof shows.

The recursor denotes the graph of the resulting functionwhitepaper/Fragment/IndRec.lean:L394-L408394/-- **The recursor's set** at its own levels `lsr` (the elimination
395level in front, if large): the abstraction over its context — the
396parameters, the motive, the minors, the indices, the major — of the
397recursor's semantic value, the family read at the block's levels.
398Into `Prop` (`qv`) the body is the point outright: the motive's fibres
399are truth values, and the abstraction is read by its values,
400so a body that is not the point would make it a graph. -/
401noncomputable def recSet (lsr : List Nat) : V :=
402 let ψr := valOf S.recLparams lsr
403 let ls := S.lparams.map ψr
404 lamCtx (S.M₂ M) ψr base
405 (S.famVars (S.n + 1) :: S.indicesAt (S.n + 1) ++ S.minorsCtx ++ [S.motiveTy] ++ S.params)
406 fun ρ' => if S.qv ψr then pt else
407 S.recSem M ls (readEnv S.nP (shiftE (1 + S.nI + S.n + 1) 0 ρ')) (ρ' (1 + S.nI + S.n))
408 (readEnv S.n (shiftE (1 + S.nI) 0 ρ')) (readEnv S.nI (shiftE 1 0 ρ')) (ρ' 0)
(its valuewhitepaper/Fragment/IndRec.lean:L181-L185181/-- **The recursor's semantic value** at parameters, motive, minors,
182indices and the major: the one the graph relates, if any.
183Con-leche: `recSel`, the graph's selector. -/
184noncomputable def recSem (ps : List V) (m : V) (mins is : List V) (t : V) : V :=
185 open Classical in
), curried over the parameters, the motive, the minors, the indices and the major. It is a member of its generated typewhitepaper/Fragment/InstallInd.lean:L1054-L10571054theorem recSet_mem (φ : Name → Nat) (ρ : Nat → V) {lsr : List Level}
1055 (hlsr : lsr.length = S.recLparams.length) :
1056 S.recSet m.M (lsr.map (Level.eval φ)) ∈ˢ
1057 interp (S.M₃ m.M) (Level.substVal φ S.recLparams lsr) ρ S.recType := by
, which is law 1 for the recursor (the recursor’s typingwhitepaper/Fragment/IndRec.lean:L316-L325316/-- **The recursor's typing**: at a member of the fibre, the
317recursor's value lies in the motive at the indices and the member —
318by induction over the family, from the minors' typing. -/
319theorem recSem_mem {ps : List V} (hpl : S.nest = none) (hnr : S.NoRecDep) (hb : S.DomsBounded M ls ps)
320 (hu : S.Uniq M ls)
321 (hp : FitsVals M (S.ψ ls) base S.params ps) (m : V) (mins : List V)
322 (hmin : ∀ j c, S.ctors[j]? = some c → S.MinorOk M ls ps m mins j c)
323 (hmo : ∀ is t, t ∈ˢ S.Fam M ls ps is → IsTy (appList m (is.reverse ++ [t])))
324 {is : List V} {t : V} (ht : t ∈ˢ S.Fam M ls ps is) :
325 S.recSem M ls ps m mins is t ∈ˢ appList m (is.reverse ++ [t]) := by
, by induction over the family from the minors’). When the elimination level ℓ is zero at the valuation, the motive’s values are truth values and the recursor’s value is the point at every argument. Then so is the recursor’s set, since an abstraction is read by its values, and there is nothing to construct.

In con-leche The recursor is built the same way, except that its graph is also a least fixed point inside the set theory (the proof calls this the graph route), and one construction serves every sort. Over the set of majors, the graph is the least relationConLeche/SetModel/GraphRec.lean:L100-L104100/-- **The recursor family's graph**: the least fixed point of the graph
101functor, over families of the axiomatic level `tg ℓ` — a relation,
102whose fibres are sets of values, not types (no drop ever fires: the
103level is closed under subsets). -/
104noncomputable def gGraph : V := lfpFamIn (tg ℓ) U (gStep ℓ U Dec pred B st)
closed under the rules, each read over the decodings of a major. The graph has exactly one value at every majorConLeche/SetModel/GraphRec.lean:L232-L234232/-- **The recursion theorem, from induction**: the graph has exactly
233one value at every major. -/
234theorem exu : ∀ u, u ∈ˢ U → Single K.G u := by
by the family’s own induction, and the equation at any decoding is the 𝜄 lawConLeche/SetModel/GraphRec.lean:L270-L274270/-- **The ι law, at ANY decoding**: the recursor at a major is the
271step at that decoding, the `ih`s being the recursor at the
272predecessors. -/
273theorem rec_eq {u : V} {d : R} (hu : u ∈ˢ U) (hd : K.Dec u d) :
274 K.recAt u = K.st d (graph (fun j => K.recAt j) (K.pred d)) := by
. The one fact about sorts it asks is a premise: at every major, two decodings are equal, or the motive’s value there has at most one memberConLeche/SetModel/GraphRec.lean:L190-L192190 /-- **the sort-dependent fact**: decodings are unique, or the bound is a subsingleton -/
191 huniq : ∀ u, u ∈ˢ U → ∀ d d', Dec u d → Dec u d' →
192 d = d' ∨ ∀ v v', v ∈ˢ B u → v' ∈ˢ B u → v = v'
. This is the elimination rule of Section 4.1, read three ways (the three casesConLeche/Model/Inductives/ClassGenUniq.lean:L13-L1913* **`huniq`** (`genUniq`): two decodings of a major are equal, or the
14 motive's value at it is a subsingleton. At `ℓ = 0` the bound is a truth
15 value (from `hconclTy`); at a nonzero width the class's recorded clause
16 injection is injective (`LfpClause.mkInj`), given the class's fit is the
17 clause's hole fit at its carrier and its injection the clause's; at a
18 `Prop`-valued class under a large eliminator a per-major PREMISE (fits at
19 one index tuple coincide — the elimination guard's criterion).
, the theoremConLeche/Model/Inductives/ClassGenUniq.lean:L5757theorem genUniq (D : Nat → LfpDatum V) (ψ : Nat → Name → Nat) (fr : Nat → Nat → V)
). At ℓ=0 the motive’s values are truth values; at a type-valued family, tagged tuples are injective; at a proposition-valued family with a large eliminator, the subsingleton criterion makes the decoding a function of the index, which is the fragment’s uniqueness of decodings as one premise.

4.2.7. The 𝜄 rule

The rule fireswhitepaper/Fragment/Rules.lean:L95-L174 95 /-- **ι** (`Red.iota`, `Rel.lean:200`): a stored recursor applied to
96 exactly its telescope — `numParams` parameters, `numMotives` motives,
97 `numMinors` minor premises, `numIndices` indices and the major
98 premise — whose major reduces to a constructor application with a
99 rule, fires the rule: the rule's right-hand side, at the use's
100 levels, applied to the parameters, motives and minors, then to the
101 constructor's fields (its arguments after the parameters). The rule
102 is one of the block's own constructors' (no stored instantiation,
103 `RecRule.inst`); an auxiliary recursor's rule fires by
104 `Red.iotaNested`.
105
106 The **certificates** are the fragment's form of `Rel.lean`'s `CertsF`
107 and `piResidual` premises (`:227-236`). The recursor's spine before the
108 major needs none: a reduction claims nothing of a redex that is the
109 point, and a redex that is not the point fits the recursor's telescope
110 by the invariant's application slots (`teleFit_of_ne_pt`). The reduced
111 major's slot is certified — its type inferred and found definitionally
112 equal to the domain the recursor's telescope leaves after the spine
113 (`Expr.piResidual`) — and so is the constructor's argument spine against
114 its stored type's `Π`-telescope (`Expr.piDomains`; the stored types have
115 the spine's length of syntactic binders, `Expr.hasPis`). Both are
116 needed only where the major may denote the point (a family that may be a
117 proposition): where the major's domain is strict, `iota_core_strict`
118 (`Sound.lean`) needs neither; where the constructor's family is a
119 proposition at every valuation, `Red.iotaProp` needs no slot
120 certificate. They make the environment's ι law (`EnvModel.lean`,
121 `RecRuleLaw`) applicable: they put every argument in its domain.
122
123 The **three comparisons** after them are `Rel.lean`'s too (`:213-241`,
124 there in the certified case only): the constructor's levels are the
125 recursor's (its last `usj.length` ones — a large eliminator carries
126 one extra level in front), the constructor's parameters are
127 definitionally the recursor's, and the constructor's residual type
128 (`Expr.piResidual`: the family at the constructor's own parameters and
129 index expressions, with the fields substituted in) has index
130 expressions definitionally equal to the recursor's index arguments. In
131 the model they matter exactly when the family is a proposition: there
132 the major denotes the one point, the certificates say only that the
133 fibre is inhabited, and the fields the rule's right-hand side receives
134 can be related to the recursor's own parameters and indices through
… 40 more lines
on 𝑟.{ℓ⃗}𝑎⃗𝑡 where 𝑟 is a stored recursor, 𝑎⃗ are its parameters, motive, minors and indices, and the major 𝑡 reduces to a constructor application 𝑐𝑗.{ℓ⃗′}𝑎⃗′𝑓⃗ for which 𝑟 has a rule with right-hand side 𝑅𝑗. The reduct is 𝑅𝑗[𝑝⃗≔ℓ⃗] applied to the parameters, motive and minors from 𝑎⃗ and to the fields 𝑓⃗. Besides finding 𝑟, 𝑐𝑗 and the rule in the environment, the fragment’s rule has three comparisons as premises:

In one case it also has a certificate on the constructor application (Section 4.2.8). The official kernel makes none of these checks. The fragment’s rules make the comparisons in every case except K, and its proof of the 𝜄 law uses them. The checker makes them only in the certified case of Section 4.2.8, together with the certificate; there they belong to the certification tax (Section 2.8).

Nothing checks the recursor’s own arguments against its type, and nothing needs to. The reduction claim is asked only of a redex that is not the point, and such a redex fits the recursor’s telescopewhitepaper/Fragment/Sound.lean:L805-L819805/-- **A spine that is not the point fits its head's telescope, with no
806certificate** (the argument of the paper's ι rule, iterated). At each step
807the application is not the point, so neither is its head
808(`app_pt`); the invariant's application clause (`AppliesTo`) then puts
809the argument in the domain of the head's graph, and the head's membership
810in its type — a function space, not the point — makes that the type's
811domain (`AppliesTo.mem`), the binder's.
812This is why `Red.iota` carries no certificate on the recursor's
813telescope: the reduction claims nothing of a redex that is the point. -/
814theorem teleFit_of_ne_pt {ρ : Nat → V} :
815 ∀ {xs : List Expr} {f T : Expr},
816 WellDenoted m.M φ ρ T → interp m.M φ ρ f ∈ˢ interp m.M φ ρ T →
817 T.hasPis xs.length = true →
818 WellDenoted m.M φ ρ (Expr.mkAppN f xs) → interp m.M φ ρ (Expr.mkAppN f xs) ≠ pt →
819 TeleFit m.M φ ρ T xs
as it stands. Call the arguments of an application its spine. Each prefix of the redex’s spine is not the point either (𝗉𝗍⋅𝑎=𝗉𝗍), hence a graph. The semantic invariant’s app-graph rule puts the next argument in that graph’s domain. The prefix’s membership in its own type puts the graph in a function space, and as a graph determines its domain, that is the function space’s domain, which therefore holds the argument.

In con-leche The checker substitutes the arguments and fields into 𝑅𝑗’s body under its leading lambdas at once, the application’s β steps (the rule thereConLeche/Rules/Rel.lean:L190-L242190 /-- **ι** (`iotaRec`, `Kernel/Core.lean`): a stored recursor
191 applied to exactly its telescope, whose prepared major (the `Red`
192 premise: `prepareMajor`'s whnf / literal / rescue chain) is a
193 constructor application with a firing rule; the reduct is the rule's
194 right-hand side's body under its `rP + nfields` λs (lean4 PR #10565's
195 shape, no β-redex built), the leading arguments and the fields
196 substituted. The recursor
197 telescope's syntactic arity over the redex's own spine, and (case 3
198 only) the level and parameter comparisons with the rule's comparands,
199 the constructor's full-grade telescope certificate and the index
200 comparison are the checker's, in its order.
201
202 **The ι case split** (task #342 L10, S5c): `IotaCaseS` at the comparand
203 levels is the checker's test, the stored facts first (task #573). A K rule, and a rule whose
204 constructor's family is never `Prop` at the comparand levels (case 2),
205 carry no premise about the constructor application; case 3 carries
206 all four. -/
207 | iota {d : Nat} {e : Expr} {c : Name} {us : List Level} {cv : ConstantVal}
208 {mI rP : Nat} {isK : Bool} {rules : List RecRule} {major : Expr} {cj : Name}
209 {usj : List Level} {cvj : ConstantVal} {cnP cnF : Nat} {induct : Name} {rl : RecRule}
210 {residual : Expr} {c3 : Bool} :
211 e.getAppFn = .const c us →
212 env.find? c = some (.recInfo cv mI rP isK rules) →
213 e.getAppArgs.length = mI + 1 →
214 us.length = cv.levelParams.length →
215 Red env d (e.getAppArgs.getD mI (.bvar 0)) major →
216 major.getAppFn = .const cj usj →
217 env.find? cj = some (.ctorInfo cvj cnP cnF induct) →
218 rules.find? (fun r' => r'.ctor == cj) = some rl →
219 major.getAppArgs.length = cnP + rl.nfields →
220 IotaCaseS env isK induct (recFireComparands rl cnP cv.levelParams us cvj.levelParams
221 e.getAppArgs rP).1 c3 →
222 (c3 = true →
223 Level.isEquivList usj
224 (recFireComparands rl cnP cv.levelParams us cvj.levelParams
225 e.getAppArgs rP).1 = some true) →
226 (c3 = true →
227 DefEqList env d (major.getAppArgs.take cnP)
228 (recFireComparands rl cnP cv.levelParams us cvj.levelParams
229 e.getAppArgs rP).2) →
… 13 more lines
). In the checker’s rule every premise on the constructor application is conditional on the certified case. A K rule, and a family that is never a proposition, fire comparing nothing, as in the official kernel. The law there is proved without the comparisons: when the redex is not the point, the major is a tagged tuple, which ties the constructor application to the recursor’s levels and parameters (what the law provides insteadConLeche/Model/Env/Laws.lean:L516-L548516/-- **The ι case split's environment facts, one rule**.
517`RecRuleLaw`'s main clause takes the levels, parameters and index
518comparisons as equations; under the conditional claims the ι step has
519them only where neither side is the point, and at a K rule or a family
520that is never `Prop` at the comparand levels it runs no check of the
521constructor application at all. What the step consumes instead, at the
522recursor's levels:
523
524* **K** (the recursor's K flag): the rule's law at the recursor's own
525 parameters, for any major value in the major's domain (the
526 fragment's `RecRuleLawK`: inversion of the family's least
527 fixed point) — the reduct, the minor, does not mention the major;
528* **the constructor's arity**: its stored type binds the spine
529 syntactically, so a graded application of it that is not the point
530 fits its telescope;
531* **(S) case 2**: where the family is never `Prop` at the comparand
532 levels (`FamNZ`, what the checker's test establishes), the recursor's
533 major domain holds no point;
534* **(T) case 2, the constructor's levels**: there a fired application
535 that is not the point, at the constructor's own levels and spine, is
536 also an application of the constructor at the comparand levels, to a
537 graded spine with the same fields that fits its telescope there —
538 the major's membership in the family at the comparands ties the
539 injection's fields (the same argument as for the parameters), so the
540 main law applies at the comparand levels;
541* **(P) the slot at the point**: where the major domain holds the
542 point, every fitting constructor application is the point (the
543 family is `Prop` there; the fragment's slot law);
544* **(U) coherence**: at a fired spine where the constructor application
545 is the point (case 3, where the step compares the levels and
546 parameters with the rule's comparands and the indices), the
547 conditional index comparison is an equation (read off the
548 parameters' conditional comparison).
).

By Theorem 2 each comparison becomes an equality of sets wherever neither side is the point. So the 𝜄 lawwhitepaper/Fragment/EnvModel.lean:L121-L188121/-- **The ι law of one recursor rule** (con-leche's `RecRuleLaw`,
122`ConLeche/Model/Env/Laws.lean`), stated on **values**. For the
123recursor `c` (stored as `ci`, with `numParams` parameters,
124`numBefore = numParams + numMotives + numMinors` arguments before the
125indices, the major at `majorIdx`) and its rule `rl` for the
126constructor stored as `cij`: whenever values `xs` up to the major,
127together with the constructor's set applied to values `ys` as the
128major, fit the recursor's telescope, `ys` fit the constructor's
129telescope, and the three comparisons of `Red.iota` hold in their
130semantic form — the constructor's levels evaluate as the recursor's
131last `usj.length` ones, its parameters equal the recursor's and the
132index expressions of its residual type (`piBodyV`: the family at the
133constructor's parameters and index expressions, read under the fields)
134denote the recursor's index arguments, **each where neither side is
135the point** (as `DefEq` claims them) — and the recursor's application
136is **not the point** (as `Red` claims ι), then the recursor's set
137applied to the spine is the rule's right-hand side's set applied to
138the parameters, motives, minors and the fields; and the right-hand
139side is well-denoted, with a well-formed application chain along
140those values (which is what makes the reduct well-denoted,
141`WellDenoted_mkAppN_of_spineOk`).
142
143Values rather than terms so that the law mentions the model only at
144the STORED terms (the two types and the right-hand side): extending
145the environment by a fresh constant then leaves every old law intact
146(`Install.lean`), where a law over arbitrary argument terms would have
147to be re-proved for the terms that mention the new name. The ι rule's
148soundness converts its term-level certificates to this form
149(`Tele.lean`).
150
151**The installation's obligation, named.** The conditional comparisons
152become the equalities the recursion equation needs because the
153recursor's and the constructor's telescopes are generated from one
154parameter and index context: under equal earlier values the two sides
155of each comparison lie in one type, whose members are all the point or
156none (`IsTy.eq_of_ne_pt`). Where the family is a *type*, the law then
157follows from the **fixpoint's inversion**: the recursor's fit puts the
158major — a tagged tuple of the fields — in the family at the RECURSOR's
159parameters and indices, and a member of the family built by `rl.ctor`
160has its fields in the constructor's field telescope at THOSE
… 28 more lines
is stated on values, with the fits and these conditional equalities as premises:

Definition 9 (the 𝜄 law of a rule). Let 𝑟 be a stored recursor and 𝑅𝑗 the right-hand side of its rule for the constructor 𝑐𝑗. Take a valuation, levels ℓ⃗ for 𝑟’s level parameters and ℓ⃗′ for 𝑐𝑗’s, values for the recursor’s arguments before the major (parameters 𝑋⃗, motive 𝐶, minors 𝑀⃗, indices 𝑌⃗), and values for the constructor’s arguments (parameters 𝑋⃗′ and fields 𝐹⃗). Suppose

  • 𝑋⃗,𝐶,𝑀⃗,𝑌⃗ followed by ⟦𝑐𝑗.{ℓ⃗′}⟧⋅𝑋⃗′⋅𝐹⃗ fit the recursor’s type at ℓ⃗, and 𝑋⃗′,𝐹⃗ fit the constructor’s type at ℓ⃗′;
  • ℓ⃗′ evaluates as the last levels of ℓ⃗;
  • 𝑋𝑖′=𝑋𝑖 at every position where neither is the point;
  • the constructor’s index expressions read at its arguments equal 𝑌⃗ at every position where neither side is the point; and
  • the recursor applied to all these values is not the point.

Then

⟦𝑟.{ℓ⃗}⟧⋅𝑋⃗⋅𝐶⋅𝑀⃗⋅𝑌⃗⋅(⟦𝑐𝑗.{ℓ⃗′}⟧⋅𝑋⃗′⋅𝐹⃗)=⟦𝑅𝑗[𝑝⃗≔ℓ⃗]⟧⋅𝑋⃗⋅𝐶⋅𝑀⃗⋅𝐹⃗,

and 𝑅𝑗 is well-denoted, and each of its partial applications to 𝑋⃗,𝐶,𝑀⃗,𝐹⃗ is the point or a graph over a type that holds the next value, as app-pt and app-graph of Section 2.6 ask along the spine.

The second conjunct makes the reduct well-denoted, as the first claim of Theorem 2 demands; the first is the equation. The 𝜄 case of Theorem 2 is then a translationwhitepaper/Fragment/Sound.lean:L1028-L10381028/-- **ι, the semantic core** of `iota_core` and
1029`iota_core_strict`, at the constructor's parameter count `nP` and a
1030right-hand side `rhs`, given the environment's law in the form both ι
1031laws take once instantiated (`hlaw`), and — at every valuation where
1032the redex is well-denoted and not the point — the invariant of the
1033reduced major and the two telescope fits (`hcore`), however obtained:
1034from certificates (`iota_core`) or from the major's domain being strict
1035(`iota_core_strict`). The index comparisons are passed on in their
1036conditional form; the major's denotation is its reduct's with no β
1037certificate (`major_eq`). -/
1038theorem iota_core_sem {Γ : List Expr} {c : Name} {us : List Level} {ci : ConstInfo}
. The comparisons become conditional equalities; the redex’s own fit is as above; the constructor’s fit comes from its certificate or from the arguments of Section 4.2.8; the reduced major’s value replaces the argument’s; and the lawConLeche/Model/Rules/IotaSound.lean:L646646theorem Red.iota_sound (hin : RulesInputs V m φ) {d : Nat} {e : Expr} {c : Name}
gives the rest.

Theorem 10 (the 𝜄 law holds). Every rule of the recursor of an accepted block satisfies its 𝜄 lawwhitepaper/Fragment/InstallIota.lean:L827-L833827/-- **The ι law of a generated rule** (`RecRuleLaw`, `EnvModel.lean`)
828for the recursor's constant and the constructor's, at the recursor's
829`nP` parameters, `nP + 1 + n` arguments before the indices and the
830major at `nP + 1 + n + nI`. -/
831theorem rec_rule_law {j : Nat} {c : CtorSpec} (hc : S.ctors[j]? = some c) :
832 RecRuleLaw (S.M₃ m.M) S.recName S.recInfo S.nP (S.nP + 1 + S.n) (S.nP + 1 + S.n + S.nI)
833 ⟨c.name, c.fields.length, S.ruleRhs c j, none, S.isK⟩ (S.ctorInfo c) := by
in the model of Section 4.2. (Via the equation on the semantic recursorwhitepaper/Fragment/IndRec.lean:L280-L290280/-- **The ι equation**: at a constructor value whose fields fit the
281family, the recursor is the minor at the fields and the inductive
282hypotheses' values. Con-leche: `GraphRecKit.rec_eq`. -/
283theorem recSem_eq {ps : List V} (hpl : S.nest = none) (hnr : S.NoRecDep) (hb : S.DomsBounded M ls ps)
284 (hu : S.Uniq M ls)
285 (hp : FitsVals M (S.ψ ls) base S.params ps) {j : Nat} {c : CtorSpec} {fs : List V}
286 (hc : S.ctors[j]? = some c) (hfit : S.FitsFields M ls (S.Fam M ls ps) ps c.fields fs)
287 (m : V) (mins : List V) :
288 S.recSem M ls ps m mins (S.idxVals M ls (consList fs (envP ps)) c.idx) (S.ctorVal ls j fs)
289 = appList (S.minorAt mins j)
290 (fs.reverse ++ c.recFields.map (S.ihSem M ls ps m mins fs)) :=
; in con-leche, the graph’s equationConLeche/Model/Inductives/BlockRecLaw.lean:L940-L946940/-- **A new block recursor's rule law, at either firing**. `hpins` is
941`RecRuleLaw`'s outer `.nested` conjunct — the pins'
942open readings and their context-guarded grading — vacuous at a `.plain`
943rule; `hrhs` receives no parameter comparison at either firing: the
944major's membership in the family at the comparands identifies the fired
945spine with the rule's own (`BlockRuleDataAt`'s `mk` conjunct). -/
946theorem blockRecRuleLaw_gen {env : Env} {m₃ : EnvModel V env} {φ : Name → Nat}
, lifted to the law of Definition 9.)

Proof. First the conditional comparisons become equalities. The recursor’s and the constructor’s telescopes are generated from one parameter context and one index context, and both spines fit them. Under equal earlier values, two values compared at one position lie in one type, whose members are all the point or none, so where the comparison says nothing they are both the point (a conditional comparison of fitting values is an equalitywhitepaper/Fragment/Ctx.lean:L161-L167161/-- **Fitting values compared where neither is the point are equal**:
162the two lists fit one context of types, so position by position, under
163equal earlier values, the two values lie in one type — whose members
164are all the point or none of them (`IsTy.eq_of_ne_pt`). -/
165theorem FitsVals_eq_of_cond : ∀ {ρ : Nat → V} {Γ : List Expr} {vs ws : List V},
166 CtxTy M φ ρ Γ → FitsVals M φ ρ Γ vs → FitsVals M φ ρ Γ ws →
167 (∀ p ∈ vs.zip ws, p.1 ≠ pt → p.2 ≠ pt → p.1 = p.2) → vs = ws
). So 𝑋⃗′=𝑋⃗, and the constructor’s index values are 𝑌⃗.

The type-valued family. The recursor’s fit puts the major’s value ⟦𝑐𝑗⟧⋅𝑋⃗⋅𝐹⃗ in the family at the recursor’s parameters 𝑋⃗ and indices 𝑌⃗, and by the constructor’s fit that value computes to tag(𝑗,𝐹⃗). A member of the fibre is a constructor value of fitting fields (the fixed-point equation, read forwardswhitepaper/Fragment/IndSem.lean:L1478-L14861478/-- **The family's case analysis**: a member of the fibre at `is` is
1479a constructor instance over the family at `is`, and conversely.
1480Con-leche: `LfpClause.carrier_case`. -/
1481theorem mem_Fam {ps : List V} (hnr : S.NoRecDep) (hb : S.DomsBounded M ls ps)
1482 (hco : S.ContOk M ls ps) {is : List V} {t : V} :
1483 t ∈ˢ S.Fam M ls ps is ↔ S.Inst M ls (S.Fam M ls ps) ps is t := by
1484 rw [← S.famOp_Fam M ls hnr hb hco]
1485 exact S.mem_famOp M ls
1486
), and tagged tuples are injective, so the fields fit 𝑐𝑗’s field telescope at the recursor’s parameters, which is what the 𝛽 steps inside 𝑅𝑗 require. The recursion theorem’s equation at tag(𝑗,𝐹⃗) is the rule’s equation.

The proposition-valued family. Here the major’s value is the point, and the recursor’s fit says only that the fibre at the recursor’s indices is inhabited. The point carries no constructor, no fields, no parameters and no indices. When the elimination level is zero the recursor’s application is the point, and the law asks nothing. Otherwise the block passed the subsingleton criterion. It has one constructor, so every decoding of the point is by 𝑐𝑗, and each field is a proposition or occurs among the constructor’s result indices. A propositional field is the point in both decodings, provided both read its domain at one valuation of the block’s level parameters; the level comparison secures that. The index equality identifies an index field’s value with the recursor’s index argument. So the two decodings of the point agree, and the recursion theorem’s equation is again the rule’s. □

Why the index comparison is needed. Take the recursor of Example 7 on the spine 𝐶,ℎ,7,𝗆𝗄5. Every 𝑃𝑛 is inhabited, by 𝗆𝗄𝑛, so ⟦𝑃7⟧={𝗉𝗍}, and the recursor’s fit asks only that ⟦𝗆𝗄5⟧=𝗉𝗍 lie in it, which it does. The fit holds equally for 𝗆𝗄7. Without the index comparison the 𝜄 law would therefore have to give both

⟦𝖯.𝗋𝖾𝖼⟧⋅𝐶⋅ℎ⋅7⋅𝗉𝗍=ℎ⋅5and⟦𝖯.𝗋𝖾𝖼⟧⋅𝐶⋅ℎ⋅7⋅𝗉𝗍=ℎ⋅7,

so ℎ⋅5=ℎ⋅7 for every ℎ, which is false. The recursor’s set is a function of its arguments and has one value at index 7. On values the types 𝑃5 and 𝑃7 are both {𝗉𝗍}, so no comparison of types could tell them apart; the index comparison, 5≡7, is what the model can use. For a type-valued family the comparison is redundant, because the tagged tuple carries its indices. The official kernel never makes it: at an 𝜄 step it compares nothing and relies on the term being well-typed, which its typing judgement guarantees. Our proof has no typing judgement, so where the major may be the point the comparison has to be a premise of the rule.

4.2.8. When 𝜄 needs a certificate

The official kernel checks nothing at an 𝜄 step: the term is well-typed, so the constructor application it reduces to and that application’s fields are well-typed too. The semantic proof needs the reduct to be well-denoted and the constructor’s arguments to fit its type wherever the redex is not the point. What supplies that depends on the major’s family at the instance, in three cases: a family that is never a proposition needs nothing (the fibre law), a family that may be one needs the certificate (with the major-premise law), and a K-like block needs neither (the K law). The three laws are facts about the model, each proved when the block is installed.

A family that is never a proposition. If the family’s sort is at least 1 at every valuation (one oracle test on the levels at the use), then the step needs no certificatewhitepaper/Fragment/Rules.lean:L394-L445394 /-- **ι, case 2** (the checker's ι case test): `Red.iota`
395 with **no certificate at all** — no major slot, no constructor
396 telescope — where the major's domain (what the recursor's telescope
397 leaves after the spine, `Expr.piResidual`) is a stored inductive
398 family applied to its parameters and indices whose stored sort is
399 **never `Prop`** at the use: one level test, `1 ≤ u` at every
400 valuation (`LevelOracle.le`, con-leche's `sortZ` read as `never`).
401 The environment law `EnvModel.ind_fib` makes that domain strict,
402 so a redex that is not the point has a major that is not the point;
403 its reduction claim then applies, and the reduced constructor
404 application fits the constructor's telescope with no certificate
405 (`Sound.lean`, `iota_core_strict`). The three comparisons are
406 `Red.iota`'s, unchanged. -/
407 | iotaStrict {Γ : List Expr} {c : Name} {us : List Level} {ci : ConstInfo}
408 {numParams numMotives numMinors numIndices : Nat} {rules : List RecRule}
409 {args : List Expr} {major : Expr} {cj : Name} {usj : List Level}
410 {cij : ConstInfo} {margs : List Expr} {rl : RecRule}
411 {dM bM : Expr} {I₀ : Name} {ls₀ : List Level} {dargs : List Expr} {ci₀ : ConstInfo}
412 {nP₀ nI₀ : Nat} {cs₀ : List Name} {S₀ : IndSpec}
413 {residual : Expr} {I : Name} {lsI : List Level} {rps ridx : List Expr} :
414 env.find? c = some ci →
415 ci.kind = .recursor numParams numMotives numMinors numIndices rules →
416 us.length = ci.lparams.length →
417 args.length = numParams + numMotives + numMinors + numIndices + 1 →
418 ci.type.hasPis (numParams + numMotives + numMinors + numIndices + 1) = true →
419 Red env Γ (args.getD (numParams + numMotives + numMinors + numIndices) (bvar 0))
420 major →
421 major = mkAppN (const cj usj) margs →
422 rl ∈ rules → rl.ctor = cj → rl.inst = none →
423 env.find? cj = some cij →
424 usj.length = cij.lparams.length →
425 margs.length = numParams + rl.nfields →
426 cij.type.hasPis (numParams + rl.nfields) = true →
427 -- case 2: the major's domain is a stored family whose sort is never `Prop` at the use
428 piResidual (ci.type.instL ci.lparams us)
429 (args.take (numParams + numMotives + numMinors + numIndices)) = some (pi dM bM) →
430 dM = mkAppN (const I₀ ls₀) dargs →
431 env.find? I₀ = some ci₀ → ci₀.kind = .induct nP₀ nI₀ cs₀ S₀ →
432 ls₀.length = ci₀.lparams.length → dargs.length = nP₀ + nI₀ →
433 ci₀.type.hasPis (nP₀ + nI₀) = true →
… 12 more lines
. The model’s fibre lawwhitepaper/Fragment/EnvModel.lean:L280-L298280/-- **The fibres' regime follows the stored sort** (used by
281the ι case test): for a stored inductive type former
282`I` (stored as `ci`, with `nP` parameters and `nI` indices and its
283block's specification `S`), the family applied to any values fitting
284its telescope is a **truth value** where the family's stored sort
285`S.sort`, instantiated at the use's levels, evaluates to zero, and a
286**strict** set — not the point, and without the point as a member —
287where it does not (`Fib`). Every `Sort (n+1)` holds truth values as
288well (`typeU`), so the universe does not say the second; the
289inductive model does: above a proposition a fibre is a set of tagged
290values (`IndSem.Fam_mem_typeU`), and a family read through a former's
291graph is admissible (`IndCommon.adm`), so strict
292(`IndCommon.strict_adm`). Stated on values, like `RecRuleLaw`. -/
293def IndFibLaw (M : Name → List Nat → V) (I : Name) (ci : ConstInfo) (nP nI : Nat) (S : IndSpec) :
294 Prop :=
295 ∀ (φ : Name → Nat) (ρ : Nat → V) (ls : List Level) (vs : List V),
296 ls.length = ci.lparams.length → vs.length = nP + nI →
297 TeleFitV M φ ρ (ci.type.instL ci.lparams ls) vs →
298 Fib (Level.eval φ (S.sort.subst ci.lparams ls) == 0) (appList (M I (ls.map (Level.eval φ))) vs)
says that a stored family’s fibres are truth values where its stored sort evaluates to zero and strict sets where it does not; the installation proves itwhitepaper/Fragment/InstallInd.lean:L150-L163150/-- **The fibre law of a former read by readers**: an
151assignment that reads the block at every valuation, with a family in
152the result universe (`Reader.adm` makes it admissible), satisfies
153`IndFibLaw` at the former — at the use's levels the reader's valuation
154evaluates the stored sort as the use does (`Level.eval_subst`), and the
155family applied has the fibres that sort says (`Reader.fib_app`).
156Every installation stage that stores the former reads it so (`mIndF`,
157`mInd`, and the nested stages). -/
158theorem indFib_of_readers {M M' : Name → List Nat → V} {F : List Nat → List V → List V → V}
159 (hS : S.Scoped env) (hR : ∀ φ, S.Reader (env := env) M φ F M' φ)
160 (hF : ∀ φ ps is, FitsVals M (S.ψ (S.lparams.map φ)) base S.params ps →
161 FitsVals M (S.ψ (S.lparams.map φ)) (envP ps) S.indices is →
162 F (S.lparams.map φ) ps is ∈ˢ (typeU (S.u₀ (S.lparams.map φ)) : V)) :
163 IndFibLaw M' S.name S.indInfo S.nP S.nI S := by
from the construction of Section 4.2. The redex is not the point, so the major lies in its domain, a strict fibre. So the major is not the point, its own reduction claim applies, and the constructor application it reduces to is not the point and lies in the same fibre. Hence it fits the constructor’s telescope by the argument of Section 4.2.7 (the case’s proofwhitepaper/Fragment/Sound.lean:L1280-L12941280/-- **ι with no telescope certificate at all, where the major's domain
1281is strict** (the case of a family that is never a proposition). If the
1282domain the major meets holds no point at the valuation — the case of an
1283inductive family whose sort is never `Prop` at the instance, whose
1284fibres are sets of tagged tuples — then a redex that is not the point
1285has a major that is not the point (the major lies in that domain,
1286`teleFit_of_ne_pt`), so the major's reduction claim applies; the
1287reduced major, a constructor application that is not the point, fits
1288the constructor's telescope by the same argument. No certificate is
1289needed for the recursor's spine, the major or the constructor's
1290spine. The strictness is a semantic hypothesis here (a sort above
1291`Prop` also holds truth values, so the universe does not give it);
1292`strict_dom` supplies it from the environment law
1293`EnvModel.ind_fib` and one level test (`Red.iotaStrict`). -/
1294theorem iota_core_strict {Γ : List Expr} {c : Name} {us : List Level} {ci : ConstInfo}
). This covers every redex on Nat, List, Bool and the like.

A family that may be a proposition. This is the certified case. The rulewhitepaper/Fragment/Rules.lean:L292-L347292 /-- **ι with no major-slot certificate and no level test** (the
293 checker's certified case of ι). `Red.iota`
294 without the reduced major's slot certificate, for any family: the
295 constructor's telescope certificate stays at the full grade (every
296 parameter and field), and so do the three comparisons; nothing
297 else is tested. Why the slot needs nothing: where the unreduced
298 major is not the point its reduction claim gives the reduct; where it
299 is, the environment's slot law (`EnvModel.rec_rules_slot`) makes
300 the constructor application the point too, given the redex is not
301 (`Sound.lean`, `slot_of_law`, `iota_core_slot`). On the generated
302 recursors that law holds because the major's domain is the
303 constructor's own family at the recursor's levels, a fibre holding the
304 point is a truth value there, and the constructor of a family in
305 `Prop` is the point (`IndSpec.rec_rule_slot`). No premise links the
306 major's domain to the constructor's family: the installation proves
307 the slot law of every generated rule (`InstallIota.lean`). This
308 is the rule for a family that is a proposition at some valuations
309 only (`Quot.{u}`, `PUnit.{u}`). -/
310 | iotaSlot {Γ : List Expr} {c : Name} {us : List Level} {ci : ConstInfo}
311 {numParams numMotives numMinors numIndices : Nat} {rules : List RecRule}
312 {args : List Expr} {major : Expr} {cj : Name} {usj : List Level}
313 {cij : ConstInfo} {margs : List Expr} {rl : RecRule}
314 {dM bM : Expr} {doms' tys' : List Expr}
315 {residual : Expr} {I : Name} {lsI : List Level} {rps ridx : List Expr} :
316 env.find? c = some ci →
317 ci.kind = .recursor numParams numMotives numMinors numIndices rules →
318 us.length = ci.lparams.length →
319 args.length = numParams + numMotives + numMinors + numIndices + 1 →
320 ci.type.hasPis (numParams + numMotives + numMinors + numIndices + 1) = true →
321 Red env Γ (args.getD (numParams + numMotives + numMinors + numIndices) (bvar 0))
322 major →
323 major = mkAppN (const cj usj) margs →
324 rl ∈ rules → rl.ctor = cj → rl.inst = none →
325 env.find? cj = some cij →
326 usj.length = cij.lparams.length →
327 margs.length = numParams + rl.nfields →
328 cij.type.hasPis (numParams + rl.nfields) = true →
329 -- the major's slot, located but not certified
330 piResidual (ci.type.instL ci.lparams us)
331 (args.take (numParams + numMotives + numMinors + numIndices)) = some (pi dM bM) →
… 16 more lines
makes the three comparisons of Section 4.2.7 and checks the constructor application: the constructor’s levels, parameters and index expressions are compared with the recursor’s, and every parameter and field of the constructor application is inferred by full inference and compared with the constructor’s domain. At a valuation where the family is a proposition the constructor’s value is the point (a constructor of a family in Propwhitepaper/Fragment/Sound.lean:L974-L983974/-- **A constructor of a family whose sort evaluates to zero denotes the
975point**. The
976constructor applied to arguments that fit its stored type, whose
977residual is the family `I` at some parameters and indices, at a level
978where `I`'s sort evaluates to zero: the application lies in that
979residual, a type of `Sort 0`, so it is the point
980(`eq_pt_of_mem_sortZero`). No argument of the application is read
981beyond its fit: at such a level the constructor's arguments are not
982constrained by its value. -/
983theorem ctorApp_eq_pt_of_sortZero {ρ : Nat → V} {cj : Name} {usj : List Level} {cij : ConstInfo}
), and an application whose head is the point constrains none of its arguments. So a field can lie outside its domain in a well-denoted major. The reduct applies the minor premise to that field, and is then not well-denoted although the redex is (a witnesswhitepaper/Fragment/EtaIota.lean:L671-L682671/-- **The field counterexample, on values, and the eta path's answer to
672it**. At a valuation where the structure is a
673proposition, the redex `rec minor (mk n)` with an ill-slotted field
674`n` is well-denoted and not the point. Plain ι's reduct `minor n` is
675not well-denoted, so plain ι without a certificate on the field
676breaks the reduction claim; the eta reduct `minor (p0 (mk n))` is
677well-denoted and denotes what the redex does, so the step through the
678projections satisfies it with no certificate. -/
679theorem plainIota_literal_witness (φ : Name → Nat) :
680 (∀ ρ : Nat → V, WellDenoted (witM (V := V)) φ ρ redex1 ∧ interp witM φ ρ redex1 ≠ pt) ∧
681 ¬ RedSem (EnvModel.empty (witM (V := V))) φ [] redex1 plain1 ∧
682 RedSem (EnvModel.empty (witM (V := V))) φ [] redex1 eta1 := by
, in which the minor is a graph over {𝗉𝗍} and the field is not the point). This is the second kind of check of the certification tax (Section 2.8). Other checkers skip it for the reason they skip the first: in a well-typed major the fields are well-typed. The major premise itself needs no check. By the model’s major-premise lawwhitepaper/Fragment/EnvModel.lean:L252-L278252/-- **The point in the major's slot** (the installer fact
253behind `Red.iotaSlot`/`Red.iotaNestedSlot`): for a recursor `c` and its
254rule `rl` firing on the constructor stored as `cij`, wherever the
255recursor's telescope holds the point as the major (after values `xs`
256fitting it), either the recursor's application there is the point or
257the rule's constructor, applied to anything, is — provided, for a rule
258of the block's own constructors (`rl.inst = none`), that the
259constructor's levels evaluate as the recursor's last ones (the level
260comparison ι runs). On generated recursors: the major's domain is the
261family at the recursor's own levels; where its sort evaluates to zero
262the constructor (of the same family, at the same levels) is the point,
263and where it does not the domain is strict and holds no point. On a
264nested block the family is `Prop` only where the eliminator is
265(`blockLargeElimAllowed`), so there the recursor's application is the
266point. This is what lets the ι rules with no slot certificate go
267without a premise linking the major's domain to the constructor's
268family. -/
269def RecRuleSlotLaw (M : Name → List Nat → V) (c : Name) (ci : ConstInfo) (majorIdx : Nat)
270 (rl : RecRule) (cij : ConstInfo) : Prop :=
271 ∀ (φ : Name → Nat) (ρ : Nat → V) (us usj : List Level) (xs ys : List V),
272 us.length = ci.lparams.length → usj.length = cij.lparams.length →
273 xs.length = majorIdx →
274 TeleFitV M φ ρ (ci.type.instL ci.lparams us) (xs ++ [pt]) →
275 (rl.inst = none →
276 usj.map (Level.eval φ) = (us.drop (us.length - usj.length)).map (Level.eval φ)) →
277 appList (M c (us.map (Level.eval φ))) (xs ++ [pt]) = pt ∨
278 appList (M rl.ctor (usj.map (Level.eval φ))) ys = pt
, wherever the recursor’s domain holds the point as the major, the redex or the constructor is the point (its proofwhitepaper/Fragment/InstallIota.lean:L1051-L10611051/-- **The slot law of a generated rule** (`RecRuleSlotLaw`):
1052where the recursor's telescope holds the point as the major, the
1053fibre it lies in — the family at the recursor's own parameters,
1054indices and levels (`fits_recCtx_iff`) — holds the point, so the
1055family's sort is zero there (above it the fibre is a set of tagged
1056values, `mem_Fam_false`); the constructor, at levels that evaluate as
1057the recursor's (the level comparison), is then the point
1058(`ctorSet` at a proposition). -/
1059theorem rec_rule_slot {j : Nat} {c : CtorSpec} (hc : S.ctors[j]? = some c) :
1060 RecRuleSlotLaw (S.M₃ m.M) S.recName S.recInfo (S.nP + 1 + S.n + S.nI)
1061 ⟨c.name, c.fields.length, S.ruleRhs c j, none, S.isK⟩ (S.ctorInfo c) := by
: a fibre holding the point is a truth value, so the family is a proposition there). In that case the reduced constructor application is the point, as the major is.

K. A block whose sort is Prop, with one constructor, which has no fields (Eq, HEq, True), is K-like, and its rule is flagged. Its stepwhitepaper/Fragment/Rules.lean:L493-L527493 /-- **ι by K** (Lean's
494 `to_cnstr_when_K`): a recursor whose rule is flagged K
495 (`RecRule.k`: one family, always a proposition, one constructor
496 with no fields — `Eq`, `HEq`, `True`) reduces on its major **as it
497 stands**, with no constructor in sight, to the rule's right-hand
498 side at the recursor's parameters, motives and minors. There is no
499 certificate, no level, parameter or index comparison, and the major
500 is not reduced. What stays is K's **type check**, as in Lean: the
501 major's inferred type reduces to a family application
502 `I.{lsI} targs`, the constructor fabricated at its parameters
503 `rl.ctor.{lsI} (targs.take numParams)` has a type `tF`, and
504 `tF ≡ I.{lsI} targs`. That check decides whether the step is taken
505 (a verdict test); no claim consumes it. Soundness is the
506 environment's K law (`EnvModel.rec_rules_k`, proved in the
507 installer by inversion of the least fixed point) with
508 `Red.iotaK_core_sem`: a redex that is not the point fits the
509 recursor's telescope, the major included, and the law needs nothing
510 more. -/
511 | iotaK {Γ : List Expr} {c : Name} {us : List Level} {ci : ConstInfo}
512 {numParams numMotives numMinors numIndices : Nat} {rules : List RecRule}
513 {args : List Expr} {rl : RecRule} {tM : Expr} {I : Name} {lsI : List Level}
514 {targs : List Expr} {tF : Expr} :
515 env.find? c = some ci →
516 ci.kind = .recursor numParams numMotives numMinors numIndices rules →
517 us.length = ci.lparams.length →
518 args.length = numParams + numMotives + numMinors + numIndices + 1 →
519 ci.type.hasPis (numParams + numMotives + numMinors + numIndices + 1) = true →
520 rl ∈ rules → rl.k = true →
521 -- K's type check on the major as it stands (a verdict test, consumed by no claim)
522 Infer env Γ (args.getD (numParams + numMotives + numMinors + numIndices) (bvar 0)) tM →
523 Red env Γ tM (mkAppN (const I lsI) targs) →
524 Infer env Γ (mkAppN (const rl.ctor lsI) (targs.take numParams)) tF →
525 DefEq env Γ tF (mkAppN (const I lsI) targs) →
526 Red env Γ (mkAppN (const c us) args)
527 (mkAppN (rl.rhs.instL ci.lparams us) (args.take (numParams + numMotives + numMinors)))
fires on any major whose type is right, with no constructor in sight. The reduct is the rule’s right-hand side at the recursor’s parameters, motive and minors alone. There is no certificate and no comparison, and the major is not reduced. What remains is Lean’s type check: the major’s inferred type reduces to the family at some arguments, and the constructor fabricated at their parameters has a type definitionally equal to it. That check decides whether the step is taken; no claim consumes it. The model’s K lawwhitepaper/Fragment/EnvModel.lean:L190-L216190/-- **The ι law of a K rule** (the `EnvModel` field
191`rec_rules_k`, proved by the installer as
192`IndSpec.rec_rule_lawK`).
193For a recursor `c` whose one rule `rl` fires on a constructor with no
194fields of a family of sort `Prop` (Lean's K: `Eq`, `HEq`, `True`): at
195**any** values `vs` fitting the recursor's whole telescope — the
196major's value included, whatever term produced it — an application
197that is not the point equals the rule's right-hand side applied to the
198parameters, motives and minors alone. In the inductive model this is
199the plain law at the recursor's own parameters plus **inversion of the
200least fixed point**: the major's value lies in the fibre at the
201recursor's indices, a fibre is inhabited only at the indices of the
202unique constructor applied to those parameters (the family "inhabited
203exactly there" is closed under the constructor, so it contains the
204least one), and the constructor's value there is the point, as the
205major's is. The constructor application the checker fabricates (or
206finds) is not mentioned: the reduct does not contain it. -/
207def RecRuleLawK (M : Name → List Nat → V) (c : Name) (ci : ConstInfo)
208 (numBefore majorIdx : Nat) (rl : RecRule) : Prop :=
209 ∀ (φ : Name → Nat) (ρ : Nat → V) (us : List Level) (vs : List V),
210 us.length = ci.lparams.length → vs.length = majorIdx + 1 →
211 TeleFitV M φ ρ (ci.type.instL ci.lparams us) vs →
212 appList (M c (us.map (Level.eval φ))) vs ≠ pt →
213 appList (M c (us.map (Level.eval φ))) vs
214 = appList (interp M φ ρ (rl.rhs.instL ci.lparams us)) (vs.take numBefore) ∧
215 WellDenoted M φ ρ (rl.rhs.instL ci.lparams us) ∧
216 SpineOk (interp M φ ρ (rl.rhs.instL ci.lparams us)) (vs.take numBefore)
says that at any values fitting the recursor’s whole telescope, the major’s included, an application that is not the point equals the right-hand side at the values before the indices. The installation proves itwhitepaper/Fragment/InstallIota.lean:L986-L1007 986/-- **The K law of a generated rule** (`RecRuleLawK`):
987for a block with one constructor `c`, which has no fields, at ANY
988values fitting the recursor's telescope — the major's value whatever
989term produced it — the recursor is the rule's right-hand side at the
990parameters, motive and minor alone. The proof is **inversion of the
991least fixed point**: the recursor's fit puts the major's value `t` in
992the fibre at the recursor's own parameters and indices
993(`fits_recCtx_iff`), and a member of a fibre is a constructor instance
994over the family (`IndSpec.mem_Fam`, the fixed-point equation); with
995one constructor and no fields that instance is `c` at the recursor's
996parameters, its index values are the indices, and `t` is its value
997(at a proposition the point, above it the empty tagged tuple). The
998plain law's second half (`rec_rule_core`) then applies at the
999recursor's own parameters. So the constructor's parameter telescope
1000needs no comparison with the recursor's: the inversion is read off the
1001recursor's fit, in the block's own parameter context. Neither the
1002family's sort nor the elimination level is used: the law holds for
1003every one-constructor, fieldless block (Lean's K adds "is `Prop`",
1004`isK`, and so does the flag). -/
1005theorem rec_rule_lawK {c : CtorSpec} (hK : S.ctors = [c]) (hnf : c.fields = []) :
1006 RecRuleLawK (S.M₃ m.M) S.recName S.recInfo (S.nP + 1 + S.n) (S.nP + 1 + S.n + S.nI)
1007 ⟨c.name, c.fields.length, S.ruleRhs c 0, none, S.isK⟩ := by
by inversion of the least fixed point. The major’s value lies in the fibre at the recursor’s parameters and indices, a member of a fibre is a constructor value reaching those indices, and with one constructor and no fields that value and those indices are determined. The proof uses neither the family’s sort nor the elimination level, so the law holds for every one-constructor block without fields; the Prop condition is Lean’s.

For a structure, Section 6.2 shows a further way to fire 𝜄 without a certificate, through the projections of the major.

In con-leche The checker decides the case with one level test per redex: whether the constructor’s family is never a propositionConLeche/Kernel/CoreDefs.lean:L91-L9991rescue mirrors it (`Sort u` at a concrete level such as `Unit`'s `1` passes, the
92parameter `u` itself does not). The instantiated zero-ness datum is
93unsatisfiable exactly where the instantiated sort is never zero. -/
94def formerNeverZero (cvT : ConstantVal) (us : List Level) : Bool :=
95 (Level.substPW cvT.levelParams us (formerZ cvT)).isNever
96
97/-- **A constructor's family**: the former and the capabilities stored at
98the constructor's `induct` (the head of its type's result, `CtorWF`).
99`none` where no inductive is stored there. -/
at the levels the rule compares with, read off the family’s type where the question is asked. A K rule and a family that is never a proposition fire with no check; every other ruleConLeche/Kernel/CoreDefs.lean:L106-L108106/-- Unfold the (application of a) definition at the head, one step.
107`none` when the head is not an unfoldable constant. **Theorems are
108opaque to reduction**: a stored `thmInfo` never unfolds, so whether a
is the certified case, as in the fragment.

4.3. Consistency

The input is a list of declarations: definitions, inductive blocks, and theorems (Section 7). The checker acceptswhitepaper/Fragment/Modular.lean:L224-L228224inductive Checks : Env → List Decl → Prop
225 | nil {E : Env} : Checks E []
226 | cons {E : Env} {d : Decl} {ds : List Decl} : d.Ok E → Checks (d.apply E) ds → Checks E (d :: ds)
227
228/-- The environment with a list of declarations stored. -/
it when each declaration passes its check against the environment of those before it, from the empty environment. An accepted list ends in a closed environment: every stored term mentions only stored constantswhitepaper/Fragment/Compare.lean:L439-L440439theorem Checks.scoped {E : Env} {ds : List Decl} (hc : Checks E ds) (hs : Env.Scoped E) :
440 Env.Scoped (applyAll ds E) := by
. This is what Theorem 5 and the construction of Section 4.2 assumed of the environment they extend.

The models of §3 and of Section 4.2 are the proof’s own: models of the environment the checker builds, with laws shaped for the soundness induction. The main theorem is stated over the input instead, one constant at a time. A declaration contributes the constants it storeswhitepaper/Fragment/Modular.lean:L219-L220219def constantsOf (ds : List Decl) (n : Name) (ci : ConstInfo) : Prop :=
220 ∃ d ∈ ds, (n, ci) ∈ d.stores
: a definition itself, a theorem its statement, a block its type former, constructors and recursor. Write 𝜑𝑛⃗ for the valuation that sends the level parameters 𝑝⃗ of a constant to the values 𝑛⃗.

Definition 11 (Model of the input). An assignment 𝑀, a set 𝑀(𝑐,𝑛⃗) for every constant name 𝑐 and list of natural numbers 𝑛⃗, is a model of a set of constantswhitepaper/Fragment/IsModel.lean:L189-L190189def IsModel (M : Name → List Nat → V) (C : Name → ConstInfo → Prop) : Prop :=
190 ∀ c ci, C c ci → ModelOf M c ci
when every one of them holds in 𝑀whitepaper/Fragment/IsModel.lean:L176-L183176def ModelOf (M : Name → List Nat → V) (c : Name) (ci : ConstInfo) : Prop :=
177 ∀ vals : List Nat, vals.length = ci.lparams.length →
178 M c vals ∈ˢ interp M (valOf ci.lparams vals) base ci.type ∧
179 match ci.kind with
180 | .defn v => M c vals = interp M (valOf ci.lparams vals) base v
181 | .recursor nP nMot nMin _ rules => ∀ i rl, rules[i]? = some rl →
182 RuleHolds M (valOf ci.lparams vals) (M c vals) ci.type (nP + nMot + nMin) i rl
183 | _ => True
, each on its own: for (𝑐.{𝑝⃗}:𝑇) and every list of values 𝑛⃗ with |𝑛⃗|=|𝑝⃗|,

  1. 𝑀(𝑐,𝑛⃗)∈⟦𝑇⟧ at 𝜑𝑛⃗;
  2. if 𝑐 is a definition with value 𝑣, then 𝑀(𝑐,𝑛⃗)=⟦𝑣⟧ at 𝜑𝑛⃗;
  3. if 𝑐 is a recursor, each of its rules holds, read off the recursor’s own typewhitepaper/Fragment/IsModel.lean:L156-L164156def RuleHolds (M : Name → List Nat → V) (φ : Name → Nat) (r : V) (T : Expr)
    157 (numBefore i : Nat) (rl : RecRule) : Prop :=
    158 ∀ (mot q : Nat), T.motivePos = some mot → (minorsOf T numBefore mot)[i]? = some q →
    159 ∀ (xs ys : List V) (D B C : Expr) (ρq ρc : Nat → V),
    160 xs.length = numBefore → TeleFitV M φ base T xs →
    161 piBodyV base T (xs.take q) = some (.pi D B, ρq) →
    162 ys.length = rl.nfields → TeleFitV M φ ρq D ys →
    163 (piBodyV ρq D ys).map (fun p => conclV p.2 p.1) = some (C, ρc) →
    164 appList r (xs ++ C.args.map (interp M φ ρc)) = appList (interp M φ base rl.rhs) (xs ++ ys)
    : rule 𝑗 reads the 𝑗-th minor premise of the motive that 𝑇 concludes with. For all values 𝑋⃗,𝐶⃗,𝐻⃗ fitting the parameters, motives and minors of 𝑇, and all values 𝐹⃗ fitting the first 𝑘 binders of that minor premise (𝑘 the rule’s field count), let the minor premise conclude with 𝐶′𝑌⃗𝑡 behind its fields and its inductive hypotheses (which the conclusion does not mention). Then

    𝑀(𝑐,𝑛⃗)⋅𝑋⃗⋅𝐶⃗⋅𝐻⃗⋅⟦𝑌⃗⟧⋅⟦𝑡⟧=⟦𝑅𝑗⟧⋅𝑋⃗⋅𝐶⃗⋅𝐻⃗⋅𝐹⃗.

A theorem’s statement, and a hole (Section 8), only the first clause.

The clauses read the constant alone: no constructor is looked up, no level or parameter is compared, and the rule’s equation holds at every fit, the point included. For a generated recursor the reading is a computation on the generated type: the minor premise’s fields are the constructor’s fields at the recursor’s parameters, and its conclusion is the motive at the constructor’s index expressions and the constructor applied to the parameters and the fields. (A nested block’s auxiliary recursor reads the minor premises of its own motive, Section 5.3.)

Theorem 12 (Every accepted input has a model). For every model of the extended theory and every list of declarations 𝐷 that the checker accepts from the empty environment, the constants of 𝐷 have a model in itwhitepaper/Fragment/Main.lean:L46-L4746theorem model_exists {ds : List Decl} (h : Checks Env.empty ds) :
47 ∃ M : Name → List Nat → V, IsModel V M (constantsOf ds) := by
:

∃𝑀.𝑀is a model of the constants of𝐷

(con-leche’s main theoremConLeche/Model/PureChecker.lean:L31-L3431theorem model_exists (V : Type w) [SetTheory V]
32 (pins : List NatOpPinSet) (maxNatSize : Nat) (ds : Array Declaration)
33 (accepted : (checkDecls .verified pins maxNatSize ds).isOk) :
34 ∃ model, IsModel V model (· ∈ constantsOf ds.toList) := by
).

Proof. By induction on the acceptance, the environment the list ends in has a model in the sense of §3 and Section 4.2. The empty environment has one; a definition step is Theorem 5; a block step is the construction of Section 4.2, assembledwhitepaper/Fragment/Holds.lean:L247-L250247theorem install_ind_holds {env : Env} {S : IndSpec} (hs : Env.Scoped env) (m : BlockModel V env)
248 (hok : IndOk env S) :
249 ∃ m' : BlockModel V (S.install env), (∀ n, (env.find? n).isSome → ∀ ls, m'.M n ls = m.M n ls) ∧
250 ∀ n ci, (Decl.ind S).stores.lookup n = some ci → ModelOf m'.M n ci := by
: law 1 is its membership claims, law 2 has no new instance, and law 3 is Theorem 10. The model of each step keeps every earlier constant’s set, and a declaration stores only fresh names, so every constant of the input is stored in the final environment as it was declared. Its first two clauses are laws 1 and 2 at the levels that evaluate to 𝑛⃗. For a rule, the values 𝐹⃗ fitting the minor premise’s fields fit the constructor’s fields at the parameters 𝑋⃗, so the constructor’s value at them is in the family at the indices ⟦𝑌⃗⟧, and the whole spine fits the recursor’s type. With the constructor’s own levels and parameters the three comparisons of Definition 9 are equalities, so where the recursor’s application is not the point the law gives the equation (the rule read off the typewhitepaper/Fragment/IotaRead.lean:L254-L257254theorem rule_holds (vals : List Nat) (hvals : vals.length = S.recLparams.length)
255 {i : Nat} {rl : RecRule} (hrl : S.rules[i]? = some rl) :
256 RuleHolds (S.M₃ m.M) (valOf S.recLparams vals) (S.M₃ m.M S.recName vals) S.recType
257 (S.nP + 1 + S.n) i rl := by
). Where it is the point, the motive’s fibre is a truth value; the right-hand side lies in the same fibre by the rule’s typing, so it is the point too. □
In con-leche The block step is one theorem, the install of a blockConLeche/Model/Inductives/DeclBlockStep.lean:L72-L7672`BlockCtorsCore` → (at the recursors) `BlockTablesCore`. -/
73theorem declBlockAt {F : Nat} {env env₂ : Env}
74 {block : List ConstantInfo} {p₀ : BlockShape}
75 (mp : EnvModelM V env)
76 (hlps₀ : ∀ ms ∈ p₀.members, ms.cvT.levelParams = p₀.lps)
, read off the checker’s run stage by stage. The rules of a stored recursor are read off its type there as here, and the checker accepts a recursor only where that reading is the one through its constructors (Section 9.2).
Corollary 13 (No proof of an empty proposition). Let 𝐼 be an inductive type with no constructors, no parameters, no indices and no level parameters, declared by an accepted input with large elimination. Then no constant of the input has type 𝐼whitepaper/Fragment/Main.lean:L76-L7976theorem no_false_constant {ds : List Decl} (h : Checks Env.empty ds) {name recName elim : Name}
77 (hrec : constantsOf ds recName (IndSpec.falseSpec name recName elim).recInfo)
78 {t : Name} {ci : ConstInfo} (ht : constantsOf ds t ci) (hty : ci.type = .const name []) :
79 False := by
, a theorem among them; this follows from any model of constants that include 𝐼’s recursorwhitepaper/Fragment/Main.lean:L59-L6259theorem IsModel.no_false {M : Name → List Nat → V} {C : Name → ConstInfo → Prop}
60 (h : IsModel V M C) {name recName elim : Name}
61 (hrec : C recName (IndSpec.falseSpec name recName elim).recInfo)
62 {t : Name} {ci : ConstInfo} (ht : C t ci) (hty : ci.type = .const name []) : False := by
(as in con-lecheConLeche/Semantics/IsModelBasis.lean:L136-L137136theorem IsModel.no_false_record (h : IsModel V model R) (hF : DeclaresFalse R) {t : Name}
137 {ps : List LevelParam} (ht : HasConstant R t ps (.const falseName [])) : False := by
). In the environment the input ends in, no closed term 𝑒 haswhitepaper/Fragment/Main.lean:L89-L9189theorem no_empty_prop_inhabitant {ds : List Decl} (h : Checks Env.empty ds) {name recName elim : Name}
90 (hrec : (applyAll ds Env.empty).find? recName = some (IndSpec.falseSpec name recName elim).recInfo)
91 (e : Expr) : ¬ Infer (applyAll ds Env.empty) [] e (.const name []) := by
⊢𝑒⇒𝐼.

Proof. Take a model 𝑀 of the input, by Theorem 12, and read the first clause for 𝐼’s recursor at the values 0. Its type is then

∀(𝐶:∀(𝑡:𝐼).𝖯𝗋𝗈𝗉).∀(𝑡:𝐼).𝐶𝑡,

the elimination principle of an empty type, read as a proposition, and the clause puts the recursor’s set in what it denotes. A constant of type 𝐼 is, by its own first clause, a member of ⟦𝐼⟧. Take for 𝐶 the abstraction over ⟦𝐼⟧ that is constantly the empty truth value: it lies in the motive’s domain, so the recursor applied to 𝐶 and that member lies in the empty truth value: a member of the empty set. The proof uses only that a model of the input exists, not how it was built. For a closed term 𝑒 with ⊢𝑒⇒𝐼, the same argument runs in the environment’s model, where Corollary 3 puts ⟦𝑒⟧ into ⟦𝐼⟧. (The construction of Section 4.2 also makes ⟦𝐼⟧ empty outright, as the least fixed point of an operator with no step.) □

In con-leche The real theorem differs in two ways. Its checker rejects a stream that declares False other than as the toolchain’s prelude does (likewise Eq, Nat and a few others, Section 9), so a corollary can read off the declarations’ own clauses that False denotes the empty set and Eq equality, in every model of the input (§1 of OVERVIEW.md); and its acceptance is the run of a program, the declaration foldConLeche/Model/Fold.lean:L493-L495493/-- **The P fold**: the declaration fold's recursion at the P invariant. -/
494theorem foldPM {F : Nat} :
495 ∀ (ds : List Declaration) (env : Env) {env' : Env},
, rather than a relation, so a bridge theorem turns each accepting run into the derivations §3 and §4 consume (Section 9). The argument in between is the one above.

5. Nested inductive types

This section changes tack. The previous sections present a fragment of the checker and prove it sound. This one describes in full con-leche’s check for nested blocks, which mention the type being defined inside another inductive type (mutual blocks aside), and then only sketches how the construction and the proofs of Section 4.2 extend to them. The details are in the linked con-leche proof. A restricted case, with one container instantiation at depth one and not under a binder, is verified in the paper’s Lean fragment: installing such a block keeps a model of the environmentwhitepaper/Fragment/NestInstall.lean:L259-L262259theorem install_nest {env : Env} {S : IndSpec} {N : NestInfo} (hs : Env.Scoped env)
260 (m : BlockModel V env) (hok : S.OkN N env) :
261 ∃ m' : BlockModel V (S.install env), (∀ n, (env.find? n).isSome → ∀ ls, m'.M n ls = m.M n ls) ∧
262 m'.M = S.M₃N m.M N := by
.

5.1. Nested blocks

A block of Section 4 mentions the type being defined only directly: a recursive field’s domain is the family itself, a reflexive field’s a function type into it. The standard example of such a nested block is a tree whose children form a list of treestests/e2e/src/nested_rec.lean:L17-L1817inductive Tree (α : Type) where
18 | node : α → List (Tree α) → Tree α
:

inductive Tree (α : Type) where
  | node : α → List (Tree α) → Tree α

The domain of the field List (Tree α) is the block List, installed earlier and called the container, applied to the type being defined. The type Tree α there is the nested occurrence, and List (Tree α), the container at given levels and parameters, is an instantiation of the container.

The container may also sit under a binder, as intests/e2e/src/nested_p01.lean:L4-L54inductive P1 where
5 | mk : (Nat → List P1) → P1

inductive P where
  | mk : (Nat → List P) → P

and nesting may go deeper. With lists, rose trees andtests/e2e/src/nest_rose_tree.lean:L15-L2415inductive L (α : Type u) : Type u where
16 | nil : L α
17 | cons : α → L α → L α
18
19inductive R (α : Type u) : Type u where
20 | node : α → L (R α) → R α
21
22inductive T : Type where
23 | leaf : T
24 | mk : R T → T

inductive L (α : Type) where
  | nil : L α
  | cons : α → L α → L α
inductive R (α : Type) where
  | node : α → L (R α) → R α
inductive T where
  | leaf : T
  | mk : R T → T

the block T is nested through R, a container that is itself nested: inside R T, the constructor R.node holds an L (R T), so T occurs at depth two. Containers with indices are allowed too, as intests/e2e/src/indexed_nested_aux.lean:L13-L1813inductive Vec (α : Type) : Nat → Type where
14 | nil : Vec α 0
15 | cons {n : Nat} : α → Vec α n → Vec α (n + 1)
16
17inductive TV (α : Type) where
18 | node : α → {n : Nat} → Vec (TV α) n → TV α

inductive TV (α : Type) where
  | node : α → {n : Nat} → Vec (TV α) n → TV α

with Vec α n the vectors of length n.

5.2. The positivity check

Section 4.1 classifies each field by the shape of its domain as ordinary or reflexive. The checker does this with one walk over the constructorsConLeche/Kernel/Inductives/Positivity.lean:L910-L953910def nestPos (ops : CheckerOps m) (env : Env) (ctx : NestCtx) :
911 Nat → List NestHole → Nat → Nat → Expr → NestState → m (NestFieldKind × Expr × NestState)
912 | 0, _, _, _, _, _ => throw (.notImplemented "nested positivity: fuel")
913 | fuel + 1, prog, dep, kb, e, st => do
914 let hi := ctx.hiAt prog.length
915 let w ← ops.whnf env dep e
916 -- `const`: the reduct mentions no member and no hole; the normal
917 -- form is the input when it mentions none either, else the reduct
918 if !w.nestOcc ctx.names ctx.nP hi then
919 return (.ordinary, (if e.nestOcc ctx.names ctx.nP hi then w else e), st)
920 match w with
921 | .forallE a b =>
922 -- `pi`: the domain hole-free, the codomain positive
923 if a.nestOcc ctx.names ctx.nP hi then
924 throw (.invalid "nested positivity: non positive occurrence of the datatypes \
925 being declared")
926 let (k, nb, st) ←
927 nestPos ops env ctx fuel prog (dep + 1) (kb + 1) (b.instantiate1 (.fvar dep a)) st
928 pure (k, .forallE a (nb.abstract1 dep), st)
929 | _ =>
930 let args := w.getAppArgs
931 match w.getAppFn with
932 | .fvar i _ =>
933 -- `holeApp`: a hole (`nestHoleAt`) — a member's, the ROOT frame's,
934 -- or a container frame's, its instantiation in progress — standing
935 -- for its entry's whole application to the parameters, applied to
936 -- hole-free indices, at its full arity (official
937 -- `is_valid_ind_app`, :338–341)
938 match nestHoleAt ctx prog i with
939 | some h =>
940 if args.all (fun x => !x.nestOcc ctx.names ctx.nP hi) && args.length == h.nIdx then
941 return (if i < ctx.hiAt 0 then
942 (if kb == 0 then .recursive (i - ctx.nP) else .reflexive (i - ctx.nP))
943 else .inProgress, w, st)
944 else throw nestNonValid
945 | none => throw nestNonValid
946 | .const n us =>
947 -- a member constant left after the abstraction (other levels)
948 if ctx.names.contains n then throw nestNonValid
949 -- `contApp`: a stored inductive at a concrete instantiation
… 4 more lines
, the same for every block, which also looks through containers. On a block of §4′s shape only the first three cases below apply, and they give exactly §4′s classification.

Holes and frames. The walk works on variables in place of types. Write 𝐼 for the block’s type former and 𝑥⃗ for its parameters. Before a constructor is examined, every application 𝐼𝑥⃗ of the type being defined to the block’s parameters is replaced by a variable 𝑋, a hole, standing for that whole application (a family over the indices). For this to catch every occurrence, the walk is preceded by a uniformity checkConLeche/Kernel/Inductives/Positivity.lean:L1010-L10241010def nestUniformOk (ctx : NestCtx) (cv : ConstantVal) : Bool :=
1011 !cv.type.piDomsOcc ctx.names ctx.nP (ctx.hiAt 0) ctx.nP &&
1012 match nestRootCanon ctx cv with
1013 | some crest => !crest.nestOcc ctx.names 0 0
1014 | none => false
1015
1016/-- `nestUniformOk` at every stored constructor of every member, before
1017the walk (official runs it before anything else): a REJECT with
1018official's wording. -/
1019def nestUniform (ctx : NestCtx) (ctorss : List (List (ConstantVal × Nat))) : m Unit :=
1020 match ctorss.findSome? (·.find? (!nestUniformOk ctx ·.1)) with
1021 | some c => throw (.invalid s!"invalid occurrence of a datatype being declared in the \
1022 type of {c.1.name}: it must be applied to the parameters and universe levels of the \
1023 mutual declaration")
1024 | none => pure ()
: the type being defined occurs in a constructor only applied to exactly the block’s parameters, at the block’s own levels, and in no parameter’s domain. A frame is one type whose constructors are being walked, at one instantiation. It is either the block itself (the root frame) or a container instantiation met in a field, such as 𝖫𝗂𝗌𝗍 at 𝖳𝗋𝖾𝖾𝛼. A container’s frame has holes of its own: in 𝖫𝗂𝗌𝗍’s constructors the application 𝖫𝗂𝗌𝗍𝛼 of the container to its own parameter is replaced by a hole 𝑌 before 𝛼 is instantiatedConLeche/Kernel/Inductives/Positivity.lean:L583-L589583/-- **A stored constructor type at a key** (see the section header): its
584canonical abstraction (`nestCanonCrest`, the group `names` at the key's
585levels `us`), then the key's parameters `ds` and the frame's holes
586`holes` (one per member of `names`, in order) put in. -/
587def nestCrest (names : List Name) (us : List Level) (ds holes : List Expr) (cty : Expr) :
588 Option Expr :=
589 (nestCanonCrest names us ds.length cty).map (·.replaceFVars (nestKeyMap ds holes))
, so it is not confused with an application at another instantiation. Frames nest: walking one may meet another container, whose frame is walked inside it. At any point the types in progress are the type being defined and every instantiation whose frame is open, each present as its hole. On 𝖳𝗋𝖾𝖾, the field 𝖫𝗂𝗌𝗍(𝖳𝗋𝖾𝖾𝛼) opens 𝖫𝗂𝗌𝗍’s frame at the parameter 𝑋, and in that frame the fields of 𝖫𝗂𝗌𝗍.𝖼𝗈𝗇𝗌 are 𝑋, standing for 𝖳𝗋𝖾𝖾𝛼, and 𝑌, standing for 𝖫𝗂𝗌𝗍(𝖳𝗋𝖾𝖾𝛼).

The cases. The walk first puts a field’s domain in weak head normal formConLeche/Kernel/Inductives/Positivity.lean:L915915 let w ← ops.whnf env dep e
𝑤, and every case reads 𝑤, never the domain’s syntax, so a container reached only by unfolding a definition counts as one. Inside the current frame, the cases are these.

  1. Ordinary. If 𝑤 mentions no type in progress, the field is ordinaryConLeche/Kernel/Inductives/Positivity.lean:L918-L919918 if !w.nestOcc ctx.names ctx.nP hi then
    919 return (.ordinary, (if e.nestOcc ctx.names ctx.nP hi then w else e), st)
    .
  2. A Π-type. If 𝑤 is ∀(𝑧:𝐴).𝐵, the domain 𝐴 must not mention a type in progress, or the block is rejected as not positive, and the walk continues with 𝐵ConLeche/Kernel/Inductives/Positivity.lean:L921-L928921 | .forallE a b =>
    922 -- `pi`: the domain hole-free, the codomain positive
    923 if a.nestOcc ctx.names ctx.nP hi then
    924 throw (.invalid "nested positivity: non positive occurrence of the datatypes \
    925 being declared")
    926 let (k, nb, st) ←
    927 nestPos ops env ctx fuel prog (dep + 1) (kb + 1) (b.instantiate1 (.fvar dep a)) st
    928 pure (k, .forallE a (nb.abstract1 dep), st)
    , 𝑧 a new variable. The binders passed form the field’s telescope.
  3. A hole. If 𝑤 is a hole applied to arguments, the arguments (the indices of the type the hole stands for) must all be present and must not mention a type in progress, or the block is rejected. The root frame’s hole makes the field recursive (reflexive when a Π-type was passed). The hole of a container frame, this one or an enclosing one, stands for an instantiation in progress, such as the tail of a 𝖫𝗂𝗌𝗍.𝖼𝗈𝗇𝗌, and is acceptedConLeche/Kernel/Inductives/Positivity.lean:L932-L946932 | .fvar i _ =>
    933 -- `holeApp`: a hole (`nestHoleAt`) — a member's, the ROOT frame's,
    934 -- or a container frame's, its instantiation in progress — standing
    935 -- for its entry's whole application to the parameters, applied to
    936 -- hole-free indices, at its full arity (official
    937 -- `is_valid_ind_app`, :338–341)
    938 match nestHoleAt ctx prog i with
    939 | some h =>
    940 if args.all (fun x => !x.nestOcc ctx.names ctx.nP hi) && args.length == h.nIdx then
    941 return (if i < ctx.hiAt 0 then
    942 (if kb == 0 then .recursive (i - ctx.nP) else .reflexive (i - ctx.nP))
    943 else .inProgress, w, st)
    944 else throw nestNonValid
    945 | none => throw nestNonValid
    946 | .const n us =>
    .
  4. A container. If 𝑤 is a stored inductive type 𝐶 at levels 𝑢⃗ applied to arguments, where 𝐶 is neither one of the block’s types nor the quotient type, the first 𝑘𝐶 arguments (𝐶’s parameter count) are its parameters 𝐷⃗, the rest its indices. It is requiredConLeche/Kernel/Inductives/Positivity.lean:L872-L897872def nestCont (ctx : NestCtx) (ops : CheckerOps m) (env : Env)
    873 (rec : List NestHole → Nat → Nat → Expr → NestState → m (NestFieldKind × Expr × NestState))
    874 (prog : List NestHole) (kb : Nat) (n : Name) (us : List Level) (args : List Expr)
    875 (st : NestState) : m (NestFieldKind × NestState) := do
    876 let q ← unwrapOr (nestContainer ctx n) nestNonValid
    877 if args.length < q.1 ||
    878 !(args.drop q.1).all (fun x => !x.nestOcc ctx.names ctx.nP (ctx.hiAt prog.length)) then
    879 throw nestNonValid
    880 -- `Quot` is stored as an `.indInfo` but is no inductive for
    881 -- official (`is_nested_inductive_app` asks `is_inductive()`):
    882 -- the one name read here. Every other basis type (`Eq`, `Nat`,
    883 -- `Empty`, `False`, and `And`) is a container like any stored
    884 -- inductive.
    885 if n == quotName then throw nestNonValid
    886 unless (args.take q.1).all (fun x => x.bvarB == 0 && x.fvarB ≤ ctx.hiAt prog.length) do
    887 throw (.invalid "nested positivity: nested inductive datatypes parameters \
    888 cannot contain local variables")
    889 -- the instance is FULLY applied: the container case
    890 -- compares the container's family at the index tuple, and a partial
    891 -- application is a function, whose graph does not grow with its values.
    892 -- A field's domain is a type, so a checked constructor never has one.
    893 let ni ← nestInstType ctx ops env (ctx.hiAt prog.length) ⟨n, us, args.take q.1⟩
    894 unless args.length == q.1 + ni.1 do
    895 throw (.invalid "nested positivity: type expected (a container instance that is not \
    896 fully applied)")
    897 nestContKey ctx ops env rec prog kb n us (args.take q.1) q.1 ni.2 st
    that

    • the indices mention no type in progress (they may mention earlier fields, as the 𝑛 of 𝖵𝖾𝖼(𝖳𝖵𝛼)𝑛 does);
    • the parameters mention no variable but the block’s parameters and the holes, so no field and no variable bound in the field’s telescope;
    • 𝑢⃗ has 𝐶’s number of levels, and every index of 𝐶 is supplied;
    • 𝐶’s index telescope at 𝐷⃗ConLeche/Kernel/Inductives/Positivity.lean:L597-L633597def nestInstType (ctx : NestCtx) (ops : CheckerOps m) (env : Env) (hi : Nat) (key : NestKey) :
      598 m (Nat × Expr) := do
      599 let (cvC, capsC) ← unwrapOr (match ctx.find? key.cname with
      600 | some (.indInfo cv caps) => some (cv, caps)
      601 | _ => none)
      602 (.internal "nested positivity: container vanished")
      603 -- the container is applied at its own level count (official:
      604 -- `infer_constant`'s "incorrect number of universe levels", which every
      605 -- constant of a checked constructor type — and of every
      606 -- reduct of it — passed; the model reads the key's constants at it)
      607 unless key.lvls.length = cvC.levelParams.length do
      608 throw (.invalid "nested positivity: incorrect number of universe levels for a nested \
      609 inductive datatype (official: incorrect number of universe levels)")
      610 -- the container's parameters are a SYNTACTIC telescope (its canonical
      611 -- instantiation exists, so the N2 check below reads
      612 -- against the container's recorded index telescope; every stored
      613 -- inductive's parameters are binders of its type, as official checks)
      614 let tyC ← familyTelescope ops env cvC capsC
      615 unless (tyC.stripPis key.ds.length).isSome do
      616 throw (.invalid "nested positivity: invalid nested inductive datatype, its type does \
      617 not bind its parameters (official: ill-formed inductive type)")
      618 let ty ← unwrapOr (instPisWith key.ds
      619 (tyC.instantiateLevelParams cvC.levelParams key.lvls))
      620 (.invalid "nested positivity: invalid nested inductive datatype, its type does not bind \
      621 its parameters (official: ill-formed inductive type)")
      622 let s ← unwrapOr (match ty.piBinders.2 with
      623 | .sort s => some s
      624 | _ => none)
      625 (.invalid "nested positivity: invalid nested inductive datatype, its type is not a \
      626 telescope ending in a sort (official: type expected)")
      627 if ty.piBinders.1.any (fun b => b.nestOcc ctx.names ctx.nP hi) then
      628 throw (.invalid "nested positivity: a container's index telescope mentions the block \
      629 (official: unknown constant)")
      630 unless ← liftFueled "level comparison" (Level.isEquiv s ctx.sort) do
      631 throw (.invalid "nested positivity: mutually inductive types must live in the \
      632 same universe")
      633 pure (ty.piBinders.1.length, ty)
      mentions no type in progress, and 𝐶’s sort is equivalent to the block’s.

    The parameters may mention the types in progress anywhere, as in 𝖫𝗂𝗌𝗍(𝖭𝖺𝗍→𝖳𝗋𝖾𝖾𝛼); the frame decides whether that is positive. Then the instantiation 𝐶.{𝑢⃗}𝐷⃗ is looked upConLeche/Kernel/Inductives/Positivity.lean:L852-L861852def nestContKey (ctx : NestCtx) (ops : CheckerOps m) (env : Env)
    853 (rec : List NestHole → Nat → Nat → Expr → NestState → m (NestFieldKind × Expr × NestState))
    854 (prog : List NestHole) (kb : Nat) (n : Name) (us : List Level) (ds : List Expr) (nPc : Nat)
    855 (cty : Expr) (st : NestState) : m (NestFieldKind × NestState) :=
    856 if st.active.contains ⟨n, us, ds⟩ then
    857 throw (.invalid "nested positivity: non valid occurrence of the datatypes being \
    858 declared (an instantiation in progress, reached through reduction)")
    859 else if ds.all (fun x => x.fvarB ≤ ctx.hiAt 0) && st.keys.contains ⟨n, us, ds⟩ then
    860 pure (.nested (kb != 0), st)
    861 else nestContNew ctx ops env rec prog kb n us ds nPc cty st
    . If it is in progress, it is rejected: its syntactic occurrences have become its hole, so meeting it as a type here means reduction produced it. Otherwise its frame is walked, as described next, unless the same instantiation was accepted before. The field is then nested, under the binders it passed.

  5. Anything else, such as the type being defined at other levels, a variable that is not a hole, or a quotient, is rejectedConLeche/Kernel/Inductives/Positivity.lean:L944-L952944 else throw nestNonValid
    945 | none => throw nestNonValid
    946 | .const n us =>
    947 -- a member constant left after the abstraction (other levels)
    948 if ctx.names.contains n then throw nestNonValid
    949 -- `contApp`: a stored inductive at a concrete instantiation
    950 let (k, st) ← nestCont ctx ops env (nestPos ops env ctx fuel) prog kb n us args st
    951 pure (k, w, st)
    952 | _ => throw nestNonValid
    .

Walking a frame. At an instantiation 𝐶.{𝑢⃗}𝐷⃗, the walk checks that 𝐶.{𝑢⃗}𝐷⃗ has a type, and introduces a hole for itConLeche/Kernel/Inductives/Positivity.lean:L792-L811792def nestFrame (ctx : NestCtx) (ops : CheckerOps m) (env : Env)
793 (rec : List NestHole → Nat → Nat → Expr → NestState → m (NestFieldKind × Expr × NestState))
794 (prog : List NestHole) (hi : Nat) (us : List Level) (ds : List Expr) (nPc : Nat)
795 (grp : List (Name × Expr)) (st : NestState) : m NestState := do
796 -- K.52: the instantiation `C.{us} ds` is TYPED at the frame's own depth (its holes typed by
797 -- their containers' formers, as the constants they stand for). Official imposes it: after the
798 -- nested elimination, `add_inductive` type-checks every replaced nested application, and a
799 -- reduct of a typed term is typed. The model grades the key's parameters in the frame's stack
800 -- context by it. Every group-mate's family is typed at the key too (`familyKeyChecks`): each
801 -- hole's type is its own member's former instantiated at the key
802 familyKeyChecks ops env ctx.find? hi us ds (grp.map (·.1))
803 let prog' := (grp.mapIdx fun _ (c, ty) =>
804 ({ key := ⟨c, us, ds⟩, base := hi, nIdx := ty.piBinders.1.length } : NestHole)).reverse ++ prog
805 let ctors ← nestGroupCtors ctx nPc (grp.map (·.1))
806 let (_, st) ← nestCtors ctx ops env (fun _ => rec) prog' (hi + grp.length) us ds (grp.map (·.1))
807 (grp.mapIdx fun i (_, ty) => Expr.fvar (hi + i) ty) ctors st
808 pure st
809
810/-- **The frame stack an instantiation is walked under**: the EMPTY one
811when its parameters mention no frame hole (they then read only the
: a variable standing for the container’s type former applied at this instantiation. It then takes each of 𝐶’s constructors in turnConLeche/Kernel/Inductives/Positivity.lean:L688-L737688def nestCtors (ctx : NestCtx) (ops : CheckerOps m) (env : Env)
689 (rec : Expr → List NestHole → Nat → Nat → Expr → NestState →
690 m (NestFieldKind × Expr × NestState))
691 (prog : List NestHole) (hi : Nat) (us : List Level) (ds : List Expr) (names : List Name)
692 (holes : List Expr) :
693 List (ConstantVal × Nat) → NestState → m (List (List NestFieldKind × Expr) × NestState)
694 | [], st => pure ([], st)
695 | (cv, nF) :: cs, st => do
696 -- the constructor's level parameters are distinct (the substitution law
697 -- instantiates them as the recorded reading does;
698 -- every stored constant passed `checkConstantVal`'s own check)
699 unless Name.nodup cv.levelParams do
700 throw (.invalid "nested positivity: invalid nested inductive datatype, its constructor \
701 has a duplicate universe level parameter (official: duplicate universe level \
702 parameter)")
703 -- the container's constructor at the key, its group's WHOLE
704 -- applications replaced by the holes BEFORE its parameters are
705 -- instantiated (`nestCrest`), WITHOUT a β-step (official's
706 -- `instantiate_pi_params`, `inductive.cpp` v4.34.0)
707 let crest ← unwrapOr
708 (nestCrest names us ds holes (cv.type.instantiateLevelParams cv.levelParams us))
709 (.invalid "nested positivity: invalid nested inductive datatype, its constructor type \
710 does not bind the parameters (official: ill-formed constructor)")
711 let ty ← ops.inferType env hi crest
712 let _ ← ops.ensureSort env hi ty
713 let (ks, nds, cur, st) ← nestFields (rec crest) prog hi
714 (.invalid "nested positivity: invalid nested inductive datatype, its constructor type \
715 does not bind its fields (official: ill-formed constructor)") nF 0 crest st
716 -- U4 on the instantiated constructor: no later field and not the result
717 -- reads a field that is
718 -- not ordinary (recursive, reflexive, nested or in progress) — on the
719 -- walked (whnf'd) telescope. Official rejects every instance
720 -- (charter item 9)
721 if (List.range nF).any (fun i => ks.getD i .ordinary != .ordinary &&
722 structUsedLater (closeTelescope nds hi cur) 0 i) then
723 throw (.invalid "nested positivity: non valid occurrence of the datatypes being \
724 declared (a later field or the result depends on a recursive or nested field)")
725 -- official's "invalid return type" on the instantiated constructor; its
726 -- result is headed by its hole, applied to its indices alone (never
727 -- fires: a stored constructor's result is its inductive applied to
… 10 more lines
:

The root frameConLeche/Kernel/Inductives/Positivity.lean:L1047-L10551047def nestRoot (ops : CheckerOps m) (env : Env) (ctx : NestCtx) (holes : List Expr) :
1048 List (List (ConstantVal × Nat)) → NestState →
1049 m (List (List (List NestFieldKind × Expr)) × NestState)
1050 | [], st => pure ([], st)
1051 | cs :: css, st => do
1052 let (o, st) ← nestCtors ctx ops env (fun crest => nestPos ops env ctx (whnfWalkFuel crest)) []
1053 (ctx.hiAt 0) (ctx.lps.map .param) ctx.params ctx.names holes cs st
1054 let (os, st) ← nestRoot ops env ctx holes css st
1055 pure (o :: os, st)
is the same loop over the block’s own constructors.

On 𝖳𝗋𝖾𝖾, the field of type 𝖫𝗂𝗌𝗍(𝖳𝗋𝖾𝖾𝛼) meets the container case at 𝖫𝗂𝗌𝗍 with the parameter 𝑋. In 𝖫𝗂𝗌𝗍’s frame, 𝖫𝗂𝗌𝗍.𝗇𝗂𝗅 has no field, and 𝖫𝗂𝗌𝗍.𝖼𝗈𝗇𝗌 has the fields ℎ:𝑋, the root’s hole, which is recursive, and 𝑡:𝑌, the frame’s own hole, which is accepted. In 𝖯.𝗆𝗄:(𝖭𝖺𝗍→𝖫𝗂𝗌𝗍𝑃)→𝑃 the walk passes a Π-type over 𝖭𝖺𝗍 and meets 𝖫𝗂𝗌𝗍 at 𝑋 the same way. For the rose trees, 𝖳.𝗆𝗄’s field meets 𝑅 at 𝑋; in 𝑅’s frame, with its hole 𝑌𝑅, 𝖱.𝗇𝗈𝖽𝖾’s fields are 𝑋 and 𝐿𝑌𝑅, so 𝐿’s frame opens inside 𝑅’s, with its hole 𝑌𝐿, and there 𝖫.𝖼𝗈𝗇𝗌’s fields are 𝑌𝑅 and 𝑌𝐿, both accepted. A container that uses its parameter to the left of an arrow, such as 𝐶𝛼 with a constructor of type (𝛼→𝖭𝖺𝗍)→𝐶𝛼, fails at the instantiation: in its frame that field’s domain is 𝑋→𝖭𝖺𝗍, a Π-type whose domain mentions the hole. Whether a container is positive in its parameter is thus decided at the instantiation, by walking it; nothing about it is recorded when the container is installed.

In con-leche The official kernel translates a nested block into an auxiliary mutual block, with a copy of the container per instantiation; con-leche builds no auxiliary type, walks the container at the instantiation (§5 of OVERVIEW.md), and records the instantiations it acceptedConLeche/Kernel/Inductives/Positivity.lean:L393-L399393structure NestState where
394 keys : Array NestKey := #[]
395 /-- the instantiations whose frames are being walked (every group
396 member at the key), outermost last: an instantiation walked at the
397 EMPTY stack (`nestWalkStack`) is still in progress for the cycle check
398 (`nestContKey`) -/
399 active : List NestKey := []
and, where it can, does not walk an accepted one again.

5.3. Classes and their recursors

A recursion over a tree has to pass through the list of its children. So a nested block’s recursors eliminate several types, its classes. They are the type being defined and the container instantiations the recursion passes through: when a field of the block or of a walked container has a container instantiation as its type, that instantiation, its holes read back as the types they stand for, is a class. For 𝖳𝗋𝖾𝖾 the classes are 𝖳𝗋𝖾𝖾𝛼 and 𝖫𝗂𝗌𝗍(𝖳𝗋𝖾𝖾𝛼); for the rose trees, 𝑇, 𝑅𝑇 and 𝐿(𝑅𝑇). Each class gets a motive and a recursor (𝑇.𝗋𝖾𝖼 for the type being defined, 𝑇.𝗋𝖾𝖼1,𝑇.𝗋𝖾𝖼2,… for the others), and each constructor of each class a minor premise. All recursors share one prefix, made of the parameters, the motives and the minor premises. A minor premiseConLeche/Kernel/Inductives/GenRec.lean:L139-L159139/-- Constructor `x`'s minor premise type at depth `d`, of class `c`: its
140declared fields, then per recursive field `f` (walked type `w`) the
141inductive hypothesis `∀ a⃗, motive_t e⃗ (f a⃗)`, over the motive at the
142declared result indices and the constructor applied. -/
143def ClassGen.minorTy (g : ClassGen) (c : Nat) (x : ClassCtor) (d : Nat) : Option Expr := do
144 let ci := g.cls.getD c default
145 let (fvs, res) ← openPisAtFvars x.nF x.tyD d
146 let ws ← targetPiDomsWith fvs x.tyN
147 let recs := (List.range x.nF).filterMap fun i =>
148 match x.kinds.getD i .ordinary with
149 | .recursive t tele => some (i, t, tele)
150 | .ordinary => none
151 let ihs ← (List.range recs.length).mapM fun l => do
152 let (i, t, tele) := recs.getD l default
153 let e := d + x.nF + l
154 let (xs, idx) ← g.ihParts t tele (ws.getD i default) e
155 pure (closeTelescope (xs.map g.binder) e
156 (Expr.mkAppN (g.motVar t) (idx ++ [Expr.mkAppN (fvs.getD i default) xs])))
157 let concl := Expr.mkAppN (g.motVar c)
158 (res.getAppArgs.drop ci.nPc ++ [Expr.mkAppN (.const x.cv.name ci.lvls) (ci.ds ++ fvs)])
159 pure (closeTelescope (fvs.map g.binder ++ ihs) d concl)
is generated as in Section 4.1 from the constructor’s fields at the instantiation, with one inductive hypothesis per recursive or nested field: the motive of the class where the field lands, under the field’s telescope, read off the walk’s recorded type (a recursor’s typeConLeche/Kernel/Inductives/GenRec.lean:L176-L183176/-- **The generated recursor type** at class `c`. -/
177def classGenRecTy (g : ClassGen) (c : Nat) : Option Expr := do
178 let pre := g.pre
179 let rP := pre.length
180 let (ifs, maj) ← g.major c rP
181 let t : Expr := .fvar (rP + ifs.length) maj
182 pure (closeTelescope (pre ++ ifs.map g.binder ++ [maj]) 0
183 (Expr.mkAppN (g.motVar c) (ifs ++ [t])))
, a ruleConLeche/Kernel/Inductives/GenRec.lean:L185-L208185/-- **The generated rule** of a recursor at class `c` for its constructor
186`x`: `λ p⃗ (prefix) f⃗, minor f⃗ (λ a⃗, rec_t p⃗ (prefix) e⃗ (f a⃗))…`, the
187callee `rec_t` the family's recursor at the landing class `t`
188(`recOf`). -/
189def classGenRule (g : ClassGen) (recOf : Nat → Option Name) (rlvls : List Level) (c : Nat)
190 (x : ClassCtor) : Option Expr := do
191 let pre := g.pre
192 let rP := pre.length
193 let (s, _) ← (List.range g.slots.length).zip g.slots |>.find? fun (_, sl) =>
194 match sl with | .minor c' C _ => c' == c && C == x.cv.name | _ => false
195 let (fvs, _) ← openPisAtFvars x.nF x.tyD rP
196 let ws ← targetPiDomsWith fvs x.tyN
197 let pvars := (List.range rP).map fun i => if i < g.nP then g.params.getD i default else
198 g.slotVar (i - g.nP)
199 let ihs ← (List.range x.nF).filterMapM fun i =>
200 match x.kinds.getD i .ordinary with
201 | .ordinary => some none
202 | .recursive t tele => do
203 let f := fvs.getD i default
204 let (xs, idx) ← g.ihParts t tele (ws.getD i default) (rP + x.nF)
205 let r ← recOf t
206 pure (some (closeLams (xs.map g.binder) (rP + x.nF)
207 (Expr.mkAppN (.const r rlvls) (pvars ++ idx ++ [Expr.mkAppN f xs]))))
208 pure (closeLams (pre ++ fvs.map g.binder) 0 (Expr.mkAppN (g.slotVar s) (fvs ++ ihs)))
).

Example 14 (𝖳𝗋𝖾𝖾’s recursors). At an elimination level ℓ, with 𝐶 the motive for 𝖳𝗋𝖾𝖾𝛼 and 𝐶1 the motive for 𝖫𝗂𝗌𝗍(𝖳𝗋𝖾𝖾𝛼), the shared prefix is the parameter, the two motives, a minor premise for 𝖳𝗋𝖾𝖾.𝗇𝗈𝖽𝖾 and one for each of 𝖫𝗂𝗌𝗍’s constructors at the instantiation:

𝖳𝗋𝖾𝖾.𝗋𝖾𝖼.{ℓ}:∀(𝛼:𝖲𝗈𝗋𝗍1).∀(𝐶:∀(𝑡:𝖳𝗋𝖾𝖾𝛼).𝖲𝗈𝗋𝗍ℓ).∀(𝐶1:∀(𝑡𝑠:𝖫𝗂𝗌𝗍(𝖳𝗋𝖾𝖾𝛼)).𝖲𝗈𝗋𝗍ℓ).∀(𝑠:∀(𝑎:𝛼).∀(𝑡𝑠:𝖫𝗂𝗌𝗍(𝖳𝗋𝖾𝖾𝛼)).∀(ℎ:𝐶1𝑡𝑠).𝐶(𝖳𝗋𝖾𝖾.𝗇𝗈𝖽𝖾𝑎𝑡𝑠)).∀(𝑛:𝐶1𝖫𝗂𝗌𝗍.𝗇𝗂𝗅).∀(𝑐:∀(𝑡:𝖳𝗋𝖾𝖾𝛼).∀(𝑡𝑠:𝖫𝗂𝗌𝗍(𝖳𝗋𝖾𝖾𝛼)).∀(ℎ:𝐶𝑡).∀(ℎ1:𝐶1𝑡𝑠).𝐶1(𝖫𝗂𝗌𝗍.𝖼𝗈𝗇𝗌𝑡𝑡𝑠)).∀(𝑡:𝖳𝗋𝖾𝖾𝛼).𝐶𝑡𝖳𝗋𝖾𝖾.𝗋𝖾𝖼1.{ℓ}:⋯∀(𝑡𝑠:𝖫𝗂𝗌𝗍(𝖳𝗋𝖾𝖾𝛼)).𝐶1𝑡𝑠

(the ⋯ is the same prefix; the constructors’ own parameter arguments are left implicit). The minor for 𝖳𝗋𝖾𝖾.𝗇𝗈𝖽𝖾 has one inductive hypothesis, 𝐶1 at the nested field; the minor for 𝖫𝗂𝗌𝗍.𝖼𝗈𝗇𝗌 has two, 𝐶 at the field that held the hole 𝑋 and 𝐶1 at the one that held 𝑌. With 𝑟⃗ for the prefix 𝛼𝐶𝐶1𝑠𝑛𝑐, and for 𝑎:𝛼, 𝑡:𝖳𝗋𝖾𝖾𝛼 and 𝑡𝑠:𝖫𝗂𝗌𝗍(𝖳𝗋𝖾𝖾𝛼), the three rules are

𝖳𝗋𝖾𝖾.𝗋𝖾𝖼𝑟⃗(𝖳𝗋𝖾𝖾.𝗇𝗈𝖽𝖾𝑎𝑡𝑠)⇝𝑠𝑎𝑡𝑠(𝖳𝗋𝖾𝖾.𝗋𝖾𝖼1𝑟⃗𝑡𝑠)𝖳𝗋𝖾𝖾.𝗋𝖾𝖼1𝑟⃗𝖫𝗂𝗌𝗍.𝗇𝗂𝗅⇝𝑛𝖳𝗋𝖾𝖾.𝗋𝖾𝖼1𝑟⃗(𝖫𝗂𝗌𝗍.𝖼𝗈𝗇𝗌𝑡𝑡𝑠)⇝𝑐𝑡𝑡𝑠(𝖳𝗋𝖾𝖾.𝗋𝖾𝖼𝑟⃗𝑡)(𝖳𝗋𝖾𝖾.𝗋𝖾𝖼1𝑟⃗𝑡𝑠).

A nested field under binders gets its hypothesis under the same binders: for 𝖯.𝗆𝗄:(𝖭𝖺𝗍→𝖫𝗂𝗌𝗍𝑃)→𝑃, with 𝐶 and 𝐶1 the motives for 𝑃 and 𝖫𝗂𝗌𝗍𝑃, the minor premise is

∀(𝑓:𝖭𝖺𝗍→𝖫𝗂𝗌𝗍𝑃).∀(ℎ:∀(𝑛:𝖭𝖺𝗍).𝐶1(𝑓𝑛)).𝐶(𝖯.𝗆𝗄𝑓).

Where a rule of 𝑇.𝗋𝖾𝖼1 fires. A rule of Section 4.2 takes the constructor’s levels and parameters to be the recursor’s own. At a container class they are not: 𝖫𝗂𝗌𝗍.𝖼𝗈𝗇𝗌 in the class 𝖫𝗂𝗌𝗍(𝖳𝗋𝖾𝖾𝛼) has the parameter 𝖳𝗋𝖾𝖾𝛼, not the recursor’s 𝛼, and 𝖫𝗂𝗌𝗍’s level names, not 𝖳𝗋𝖾𝖾’s. So each rule of a recursor at a container class stores the instantiationConLeche/Kernel/Env.lean:L106-L112106* `.nested lvls pins` — an auxiliary recursor's rule at an outside
107 major (a nested block): the comparands are fixed instantiations,
108 the class's levels and parameters the generated recursor type's major
109 domain applies the container to (`auxRuleFire`) — `lvls` are levels
110 over the recursor's level parameters, `pins` expressions in the
111 recursor's rule-prefix context, instantiated at the redex's levels and
112 leading arguments.
, that is, the class’s levels and parameters as terms in the recursor’s level parameters and parameters (the stored rules at a container classConLeche/Kernel/Inductives/RecCheck.lean:L444-L455444/-- **One checked recursor's stored rules, at its major**: `sumRules` at the
445MAJOR's parameter count and constructors;
446at an OUTSIDE major (a nested block's auxiliary recursor) every rule
447fires `auxRuleFire` (`.nested` at the major's instantiation), at a
448member major as `sumRules` builds it. -/
449def generatedRules (rP : Nat) (M : TargetMajor) (rhss : List Expr) : List RecRule :=
450 let rules := sumRules M.ctors rhss
451 match M.member with
452 | none =>
453 let fire := auxRuleFire M rP
454 rules.map fun rl => { rl with fire := fire }
455 | some _ => rules
). In the certified case of 𝜄 (Section 4.2.8), the constructor application’s levels and parameters are compared with the stored ones, instantiated at the recursor’s levels and parameter argumentsConLeche/Kernel/CoreDefs.lean:L1005-L10151005 (rP : Nat) : List Level × List Expr :=
1006 match rl.fire with
1007 | .nested lvls pins =>
1008 (lvls.map (Level.subst lps us),
1009 pins.map fun p => Expr.instSpine (args.take rP) (rP - 1)
1010 (p.instantiateLevelParams lps us))
1011 | .plain =>
1012 (cvjLps.map fun p => Level.subst lps us (.param p),
1013 args.take cnP)
1014 | .levels lvls =>
1015 (lvls.map (Level.subst lps us), args.take cnP)
(the levels by the level oracle, the parameters definitionallyConLeche/Rules/Rel.lean:L220-L231220 IotaCaseS env isK induct (recFireComparands rl cnP cv.levelParams us cvj.levelParams
221 e.getAppArgs rP).1 c3 →
222 (c3 = true →
223 Level.isEquivList usj
224 (recFireComparands rl cnP cv.levelParams us cvj.levelParams
225 e.getAppArgs rP).1 = some true) →
226 (c3 = true →
227 DefEqList env d (major.getAppArgs.take cnP)
228 (recFireComparands rl cnP cv.levelParams us cvj.levelParams
229 e.getAppArgs rP).2) →
230 (Expr.peelPis e.getAppArgs.length
231 (cv.type.instantiateLevelParams cv.levelParams us)).isSome = true →
), and the index comparison is as before. In the other cases the rule fires comparing nothing, as for a simple block. The constructor’s fields are what follows its own parameters.

Large elimination. A nested block may eliminate into every sort only if its sort is never zeroConLeche/Kernel/Inductives/BlockRec.lean:L82-L8482def blockLargeElimAllowed (p : BlockShape) (nested : Bool) : Bool :=
83 p.resSort.isNeverZero ||
84 (p.large && p.k == 1 && !nested && (p.numCtors == 0 || p.numCtors == 1))
(where the checker enforces itConLeche/Kernel/Inductives/GenRec.lean:L558-L562558 let cvRis ← classStreamRecs ops fe p.recs
559 -- the elimination guard
560 unless 0 < p.k do
561 throw (.invalid "generated recursor: the block declares no family")
562 if p.large && !blockLargeElimAllowed p (nestedBit || Ms.any (·.member.isNone)) then
), as in the official kernel. A nested proposition eliminates only into 𝖯𝗋𝗈𝗉, and the subsingleton criterion is never asked of a nested block.

In con-leche As for a simple block (Section 4.1), the classes and the layout of the prefix are read off the stream’s recursor types by an unverified pre-passConLeche/Kernel/Inductives/ClassRead.lean:L15-L3215* the CLASSES — the types the family eliminates, one per MOTIVE of the
16 shared rule prefix (a motive `∀ ı⃗ (t : I.{us} D⃗ ı⃗), Sort ℓ` names the
17 class `I.{us} D⃗`);
18* the LAYOUT of the prefix — which binder after the parameters is which
19 motive, which is the minor premise of which constructor of which class;
20* per minor premise, which fields have an inductive hypothesis and at
21 which class (`∀ a⃗, motive_t e⃗ (f_i a⃗)`), and per recursor the class its
22 conclusion eliminates.
23
24This file READS that data off the recursor types, syntactically, and
25checks nothing. Everything it returns is re-established by the stage:
26every class is checked like a major (`targetMajorOf`), the inductive
27hypotheses read here must be exactly the positivity check's recursive
28fields, and every recursor TYPE is generated from the classes and the
29positivity check's recorded constructors and compared by `isDefEq` with
30the stream's. What the stage installs is the generated family, never
31anything read here: a wrong reading can only make the generated type
32differ from the stream's, i.e. reject.
, and each class is then checked: the type being defined at the block’s levels and parameters, or a stored inductive type, not the quotient, whose parameters mention the type being defined and nothing but the block’s parameters, in the block’s sortConLeche/Kernel/Inductives/RecCheck.lean:L253-L290253 | none => do
254 -- an OUTSIDE inductive (a nested block's container)
255 if I == quotName then
256 throw (.invalid "target rec: the recursor's major is Quot, which is no inductive")
257 let some (nPc, ctors) := targetCtorsOf fe I
258 | throw (.invalid "target rec: the recursor's major is not a stored inductive")
259 let ds := args.take nPc
260 unless ds.length == nPc &&
261 ds.all (fun x => x.bvarB == 0 && x.fvarB ≤ p.nP) do
262 throw (.invalid "target rec: the major's parameters mention more than the \
263 recursor's parameters")
264 -- **An auxiliary type of the block**, official's `is_nested`: some
265 -- parameter `Dᵢ` names a member of the block (`inductive.cpp` v4.34.0
266 -- :1033–1049: `find` over each of the `nparams` arguments for a
267 -- constant of `m_new_types`; every auxiliary type is such an
268 -- application, restored verbatim by `restore_nested`, and official
269 -- accepts an auxiliary recursor exactly at an auxiliary type). The
270 -- calls' proof reads it: a call on a field whose walked type names no
271 -- member and no hole targets no class. Read without whnf and without
272 -- entering a free variable's annotation (`nestOcc` at an empty hole
273 -- range). Every class resolved here SEEDS the positivity walk
274 -- (`classSeeds`, `GenRec.lean`), so it is a node of the walk by
275 -- construction: nothing ties it to a node here.
276 unless ds.any (fun x => x.nestOcc p.memberNames 0 0) do
277 throw (.invalid "target rec: the recursor's major is an outside inductive at an \
278 instantiation that is no auxiliary type of the block (official generates no such \
279 auxiliary recursor: `elim_nested_inductive`, `is_nested`)")
280 let (nIdx, sI) ← targetOutsideInst ops fe I us ds
281 -- **Q1**: an outside major in ANOTHER
282 -- universe than the block (a Type block's family eliminating a
283 -- Prop inductive, or the converse) is refused here: the
284 -- elimination guard is the BLOCK's (`blockLargeElimAllowed`),
285 -- and it says nothing about another universe's inductive
286 unless ← liftFueled "level comparison" (Level.isEquiv sI p.resSort) do
287 throw (.invalid "target rec: the recursor's major lives in another universe than \
288 the block (Q1)")
289 pure { ind := I, lvls := us, ds := ds, nPc := nPc, nIdx := nIdx, ctors := ctors,
290 member := none, pfvs := pfvs }
. Every class other than the type being defined is walkedConLeche/Kernel/Inductives/Positivity.lean:L1101-L11091101def nestSeeds (ops : CheckerOps m) (env : Env) (ctx : NestCtx) :
1102 List (NestKey × Nat) → NestState → m NestState
1103 | [], st => pure st
1104 | (key, nPc) :: ks, st => do
1105 let F := key.ds.foldl (fun a d => max a (whnfWalkFuel d)) fuelSlack
1106 let (_, cty) ← nestInstType ctx ops env (ctx.hiAt 0) key
1107 let (_, st) ← nestContKey ctx ops env (nestPos ops env ctx F) [] 0 key.cname key.lvls
1108 key.ds nPc cty st
1109 nestSeeds ops env ctx ks st
as a container met at the root, so every class is an instantiation the walk visited. A field landing at a class for which the stream gives no recursorConLeche/Kernel/Inductives/GenRec.lean:L452-L455452 List ClassCtor → m (List Expr)
453 | [] => pure []
454 | x :: xs => do
455 let gen ← unwrapOr (classGenRule g recOf (cvR.levelParams.map .param) c x)
is rejected. One class may be visited at several places. In a block with a field of type 𝖫𝗂𝗌𝗍(𝖱𝖫𝖳𝖫)tests/e2e/src/corner_nestind_f13_listrose.lean:L12-L1512inductive RL (α : Type) : Type where
13 | node (a : α) (cs : List (RL α)) : RL α
14inductive TL : Type where
15 | node (l : List (RL TL)) : TL
, with 𝖱𝖫𝛼 a rose tree over lists, that instantiation is met at the block’s field and again inside 𝖱𝖫𝖳𝖫, and the generator checks that every visit gives each field the same inductive hypothesisConLeche/Kernel/Inductives/GenRec.lean:L252-L266252/-- **Node agreement at one recursive field** (K.53′): at every entry
253`E` of the constructor, field `i` (opened at the datum's variables `fvs`)
254has the datum's telescope `tele`, the datum's leaf head and indices, and
255a leaf class matching the inductive hypothesis's class `Mc` per component
256(`targetK53`). -/
257def classNodesAgree (ops : CheckerOps m) (env : Env) (p : BlockShape) (formerTys : List Expr)
258 (Mc : TargetMajor) (tele : List Expr) (leaf : Expr) (fvs : List Expr)
259 (i : Nat) (ctor : Name) : List NestCtorNf → m Unit
260 | [] => pure ()
261 | e :: es => do
262 let some f := ((targetPiDomsWith fvs e.ty).getD [])[i]?
263 | throw (.invalid s!"generated recursor: a recorded normal form of {ctor} is too short")
264 unless ← targetK53 ops env p formerTys Mc tele leaf f do
265 throw (.invalid s!"generated recursor: field {i} of {ctor} does not land at its inductive \
266 hypothesis's class at every node of the positivity check (official: invalid recursor)")
.

5.4. The model, as a sketch

What follows is intuition for how the construction of Section 4.2 carries over. The details are in the linked con-leche proof.

The operator. Fix the parameters, and let 𝑊 be the approximant, a family over the indices to which the operator is applied, as in Section 4.2. A container field ranges over the container’s own family at the instantiation, with 𝑊 in place of the type being defined: for Tree, the field List (Tree α) of 𝖳𝗋𝖾𝖾.𝗇𝗈𝖽𝖾 ranges over the lists whose entries all lie in 𝑊. That family is known, because every installed block leaves a clause in the modelConLeche/Model/Env/BlockLfp.lean:L33-L4433**The clause** (`LfpClause`), at every level assignment `ψ` and every
34parameter frame `ρp` satisfying the parameter telescope (exactly the
35quantification `BlockModelAt` has, which is what the install proves):
36
37* `maps` — `Φ` maps the tuple space into itself;
38* `fitAcc` — the hole fit is ACCESSIBLE (`LfpDatum.FitAcc`), with a
39 bound of the level at a `Type`-valued block;
40* `fibre` — component `c`'s fibre at `(X, t)` is the set of injections
41 of the spines fitting one of `c`'s constructors at `(X, t)`;
42* `leaf` — a member's former, at fitting parameters and its own
43 indices, is the least pre-fixed tuple's component at the index
44 tuple.
: its type former denotes, at all parameter values, the least fixed point of its operator. So the container’s least fixed point is reused, at each approximant, and nothing new is constructed for it. At depth two the same holds one level down: an element of 𝑅𝑊 holds a list from 𝐿’s family at the parameter 𝑅𝑊.

Accessibility. The block’s operator stays accessible, because the walk that checked positivity also bounds the support. An element of the container’s family at 𝑊 depends on 𝑊 only through the positions the walk found: the fields that held the root’s hole, such as the entries of a list, and, through the fields that held the frame’s own hole, the same positions of its sub-values. Write 𝐻𝑊 for the container’s operator at the instantiation, with the root’s hole read as 𝑊 and the frame’s own hole as its argument, the container’s own family; the field ranges over its least fixed point lfp(𝐻𝑊). Read as an operator of the two arguments, the container’s operator is accessible by the same case-by-case argument as §4′sConLeche/Semantics/Inductives/HoleAcc.lean:L50-L5550| case | accessibility | bound | the point |
51|---|---|---|---|
52| a hole-free reading | `ConstOn.accOn` | `∅` | `ConstOn.ptOn` |
53| the `whnf` step | `AccOn.of_eqOn` | the reduct's | `PtOn.of_eqOn` |
54| Π, hole-free domain | `AccOn.pi` | `piBound` | `PtOn.pi` |
55| a hole at hole-free arguments | `AccOn.holeApp` | `{pt}` | `PtOn.holeApp` |
, run on the frameConLeche/Model/Inductives/ContAcc.lean:L14-L3314/-!
15# A container instance is accessible
16
17The container pieces of the accessibility induction on the positivity
18derivation (`posD_acc`, `PosDerivAcc.lean`):
19
20* the leaf (`accConcl_of_frameAccOut`, over `keyLeaf`): a frame's
21 accessibility at the key frames makes the container instance
22 accessible along the enclosing relation;
23* a frame's accessibility at EMPTY enclosing frames, read back at the
24 frameless relation (`frameAccOut_unextend`, with
25 `HoleRelA.extendEmpty`);
26* a key accessible at the block's own depth (`KeyAcc`) makes a cache
27 hit's instance accessible (`contHit_acc`, at the enclosing relation
28 seen at that depth, `HoleRelA.dropBase`).
29
30The TYPE REGIME of a container instance: the container lives at the
31block's level at every pair fitting it (`grp_sort`, the kernel's N3), so a truth-valued fibre of a
32container is empty (`LfpClause.injNePt`).
33-/
; and the least fixed point of such an operator is accessible in its first argumentConLeche/SetModel/Access.lean:L530-L540530/-- **THE NESTED CASE: the least tuple is accessible in its parameter.**
531If the joint operator `Θ` (parameter components first, then its own) is
532`A`-accessible and maps the space into itself, then `X ↦ lfp_Y Θ(X, Y)`
533is `accPaths A`-accessible — no key, no wide operator, no container
534presentation. (W) of each section and its monotonicity come from
535`closed_of_acc` / `AccTuple.monoTuple`. -/
536theorem lfpP_acc {Θ : (Nat → V) → Nat → V} {A : V} (hA : w ≠ 0 → A ∈ˢ (tg w : V))
537 (hmaps : ∀ X Y, InTupleSpace w kX IsX X → InTupleSpace w kY IsY Y →
538 InTupleSpace w kY IsY (Θ (catT kX X Y)))
539 (hacc : AccTuple w (kX + kY) (catT kX IsX IsY) kY IsY Θ A) :
540 AccTuple w kX IsX kY IsY (lfpP w kX kY IsY Θ) (accPaths A) := by
: the supports of an element’s sub-values are collected along paths into one support, so 𝑊↦lfp(𝐻𝑊) is accessible. Monotonicity follows from accessibility as in §4. Nothing about the container’s parameter is recorded when it is installed: the walk at the instantiation is what makes the argument go through.

In con-leche For the recursor, con-leche also proves the walk’s readings monotone case by caseConLeche/Semantics/Inductives/HoleMono.lean:L17-L2317| `nestPos` case | lemma |
18|---|---|
19| the `whnf` step before every case | `MonoOn.of_eqOn` (the reading of the reduct is the reading of the term — `WhnfClaim`'s conclusion shape) |
20| `const`: the reduct mentions no hole | `ConstOn.of_noBVar`, `ConstOn.monoOn` |
21| `pi`: hole-free domain, positive codomain, fibres types | `MonoOn.pi` |
22| `holeApp`: a hole applied to hole-free arguments | `MonoOn.holeApp` |
23| `contApp`: a container instance | `Model/Env/BlockLfpMono.lean`'s container case, through the container's lfp clause |
; at a container that compares the container’s least fixed points at two instantiations, by leastnessConLeche/SetModel/HoleClose.lean:L17-L2017* `lfpTuple_le_on` — the least tuple lies below `B` on a group `G` of
18 its components as soon as the operator, at the least tuple with its
19 `G`-components replaced by `B`'s, does: a container frame abstracts
20 only the reached part of its group, the rest is read concretely.
.

The family. The container lives in the block’s sort (the container case of Section 5.2 requires it), so its family at an approximant in the universe is in the universe, and the operator maps the universe to itself. With accessibility, Theorem 8 gives a closed family, and the block’s family is the least fixed point as in Section 4.2.4, with its fixed-point equation and its induction principle: a property that holds of every element the operator produces from elements having it holds of the whole family.

The recursors. For a simple block, Section 4.2 defines the recursor’s value by the recursion equation and obtains it as a graph in the set-theoretic sense: a relation between elements of the family and values, the least one closed under the equation, which is then shown to be a function. A nested block has several recursors, one per class, and they call each other: the 𝜄 rules of Section 5.3, read as equations, define 𝖳𝗋𝖾𝖾.𝗋𝖾𝖼 on 𝖳𝗋𝖾𝖾.𝗇𝗈𝖽𝖾 in terms of 𝖳𝗋𝖾𝖾.𝗋𝖾𝖼1 at the list of children, and 𝖳𝗋𝖾𝖾.𝗋𝖾𝖼1 on 𝖫𝗂𝗌𝗍.𝖼𝗈𝗇𝗌 in terms of 𝖳𝗋𝖾𝖾.𝗋𝖾𝖼 at the head. So the two are defined together, by one relation. It is the least relation between a class (here Tree α or List (Tree α)), an element of that class, and a value, closed under all these equations at once. As in Section 4.2 it is single-valued, because tagged tuples are injective. At the elimination level zero both sides of every equation are proofs, hence the point, and a large eliminator out of a proposition is refused for nested blocks, so the decodings argument of Section 4.2 is not needed. It is total (every element of every class has a value) by one induction over all the classes together: the induction principle of Tree’s family, which at the nested field List (Tree α) hands over to the induction principle of List’s family at that instantiation, and so on as deep as the walk went (the induction over the classesConLeche/SetModel/NestRec.lean:L8-L46 8/-!
9# The nested recursor's graph kit: majors over several CLASSES
10
11The graph kit (`SetModel/GraphRec.lean`, `GraphRecKit`) asks ONE thing of
12the majors: an induction principle (`ind`). At a flat block the majors
13are the members' carriers and `ind` is the block's lfp induction. At a
14NESTED block the recursor family also ranges over the CONTAINER CLASSES
15— `List Tree`, `Rose T`, `List (Rose T)` — each the least fixed point of
16its OWN operator, at its OWN instantiation (the container's lfp clause at
17the parameter frame the instantiation reads). This module builds the
18kit over such a family of classes and proves `ind` from the classes'
19own clauses, by a STRENGTHENED PREDICATE:
20
21* a class is a clause (`SClause`: an operator per parameter frame, its
22 fit relation and injections) at its TRUE frame `fr b`;
23* its container fields' classes are reached, during the induction, at
24 SEPARATED frames — the instantiation read at the enclosing class's
25 separated tuple; which frames count is the kit's `Adm` (admissible:
26 "a frame whose parameter positions hold elements satisfying `G`");
27* at such a frame the class's own induction runs with the predicate
28 "lies in the TRUE class ∧ the property"; membership in the true class
29 is re-established at each constructor by the class's clause at the
30 TRUE frame (the fibre law, backwards, and closure), after moving the
31 constructor's fit from the separated frame and tuple to the true ones
32 (`trans`). The only inclusion the induction itself produces is the
33 separation `sep ⊆ carrier`.
34
35**What is used of a class** (charter items 2, 4): its clause at each
36frame the induction visits (`OkAt`: monotone in its own holes, a closed
37tuple, the fibre law) and ONE fact per class tying a frame to the true
38one, `trans`: a constructor fitting at an admissible frame, at holes
39below the true carrier, fits at the true frame and the true carrier. At
40the term level `trans` is `LfpDatum.hfits_mono` along the relation
41between the instantiation's two hole frames (the constructor's
42positivity AT THE INSTANTIATION, `CtorPos` — what `nestPos`'s container
43descent certifies, keyed by the instantiation) followed by the clause's
44own `fitsMono` at the true frame. Nothing is asked of a container "in
45its parameter": no monotonicity of its value or carrier, no Bekić, no
46joint (wide) operator.
, read at the recursors’ classesConLeche/SetModel/NestRecCls.lean:L6-L29 6/-!
7# The nested kit's induction at the RECURSOR's classes
8
9The nested kit `NestKit` (`SetModel/NestRec.lean`: `trans` at every
10admissible frame) proves the induction principle of its majors,
11the tagged elements `nenc b m t x` of every CLAUSE class `b` (a member
12block, or a container at an instantiation — a positivity NODE),
13component `m`. `NestNodeInd` is that principle, DECODED (a major's
14predecessors are the kit's `pred` at a decoding at the true frame and
15carrier), and the one interface the recursor side reads; `NestKit.toNodeInd`
16is its instance.
17
18The recursor model's graph kit (`graphKitG`,
19`Model/Inductives/BlockRecGraph.lean`) is stated over the RECURSOR's
20classes: recursor `c`'s majors are `tagged c t x`, its decodings are the
21rule data's, and its predecessors are the rule's call targets (`predR`).
22`NestNodeInd.ind_recNodesOn` transports the one to the other, with
23SEVERAL nodes per class (`Rel c b`: node `b` visits recursor `c`'s class
24at component `mOf c b`; one instantiation may be visited at several
25nodes), on a set `S` of classes that have nodes.
26The property is read back along every node of a class: `P'` holds at the
27node major `nenc b (mOf c b) t x` when `P` holds at `tagged c t x`
28for every related recursor `c`; the kit's predecessors must contain every
29related recursor's call targets (`hpredR`).
). Each recursor is then this relation restricted to its class, curried over its arguments.

The 𝜄 laws. They follow as in Section 4.2. For a rule of 𝖳𝗋𝖾𝖾.𝗋𝖾𝖼1 the major is an application of a constructor of List. The recursor’s fit puts its value in the class at the recursor’s parameters, and List’s fixed-point equation at that instantiation identifies its constructor and fields with the rule’s (the graph’s equation, lifted to the lawConLeche/Model/Inductives/BlockRecLaw.lean:L940-L946940/-- **A new block recursor's rule law, at either firing**. `hpins` is
941`RecRuleLaw`'s outer `.nested` conjunct — the pins'
942open readings and their context-guarded grading — vacuous at a `.plain`
943rule; `hrhs` receives no parameter comparison at either firing: the
944major's membership in the family at the comparands identifies the fired
945spine with the rule's own (`BlockRuleDataAt`'s `mk` conjunct). -/
946theorem blockRecRuleLaw_gen {env : Env} {m₃ : EnvModel V env} {φ : Name → Nat}
).

The family, the recursors and their 𝜄 laws are what the installation argument of Section 4.2 reads, so a nested block extends the model of the environment as a simple block does.

6. Consequences of extensionality

The official kernel has two rules of definitional equality that the fragment does not have: η for structures, and unit-likeness. Section 9 lists them among the omissions. This section shows that either could be added as one more case of the induction of Section 2.7, proved from laws the model already has: each rule follows from what the values are. A proof is the point, a function is the graph of its applications, a constructor value is a tagged tuple of its fields, and a member of an inductive family is a value that one constructor step produces. Each of these says that a set is determined by its parts, and each is an extensionality law of the assumed set theory or follows directly from one. η for functions, which the fragment has, is the same law at graphs: a member of a function space is the graph of its applicationswhitepaper/Fragment/Lib.lean:L110110 graph_app_eq : ∀ {A f : V} {B : V → V}, Mem f (piSet A B) → graph (fun x => app f x) A = f
, and §2 proved its case. The K rule of Section 4.2.8, which the fragment also has, rests on a law of the same kind, inversion of the least fixed point.

Recall what Section 4 sets up. Fix a valuation 𝜑. A constructor application 𝑐𝑝⃗𝑓⃗, with parameters 𝑝⃗ and fields 𝑓1,…,𝑓𝑛, of a block whose family is type-valued denotes a tagged tuplewhitepaper/Fragment/IndLib.lean:L50-L6450 /-- The n-ary tuple of a list of sets. -/
51 tuple : List V → V
52 /-- Tuples are injective. -/
53 tuple_inj : ∀ {xs ys : List V}, tuple xs = tuple ys → xs = ys
54 /-- A tuple of members of a positive universe is a member of it. -/
55 tuple_mem_univ : ∀ {n : Nat} {xs : List V}, n ≠ 0 →
56 (∀ x ∈ xs, Mem x (univ n)) → Mem (tuple xs) (univ n)
57 /-- A value tagged with a number. -/
58 tag : Nat → V → V
59 /-- Tags are injective. -/
60 tag_inj : ∀ {i j : Nat} {x y : V}, tag i x = tag j y → i = j ∧ x = y
61 /-- A tagged member of a positive universe is a member of it. -/
62 tag_mem_univ : ∀ {n i : Nat} {x : V}, n ≠ 0 → Mem x (univ n) → Mem (tag i x) (univ n)
63 /-- A tagged value is never the point. -/
64 tag_ne_pt : ∀ {i : Nat} {x : V}, tag i x ≠ pt
tag(𝑖,⟦𝑓1⟧,…,⟦𝑓𝑛⟧), the constructor’s number 𝑖whitepaper/Fragment/IndCommon.lean:L330-L332330/-- **A constructor's value** at its fields: the point at a
331proposition, the tagged tuple above. -/
332def ctorVal (j : Nat) (fs : List V) : V := if S.z ls then pt else tag (S.tagOf j) (tuple fs.reverse)
followed by its fields. The family at parameters and indices denotes the least set closed under the constructor stepswhitepaper/Fragment/IndSem.lean:L1458-L14611458/-- **The family**: the fibre at the index values `is` is the least
1459fixed point of the block's operator inside the set theory.
1460Con-leche: `LfpDatum.carrier`, `lfpTuple` of the hole operator. -/
1461noncomputable def Fam (ps is : List V) : V := lfpFamSet (S.u₀ ls) (S.famOp M ls ps) is
, so that a member of the family is a tagged tuple that one constructor step produceswhitepaper/Fragment/IndSem.lean:L1478-L14861478/-- **The family's case analysis**: a member of the fibre at `is` is
1479a constructor instance over the family at `is`, and conversely.
1480Con-leche: `LfpClause.carrier_case`. -/
1481theorem mem_Fam {ps : List V} (hnr : S.NoRecDep) (hb : S.DomsBounded M ls ps)
1482 (hco : S.ContOk M ls ps) {is : List V} {t : V} :
1483 t ∈ˢ S.Fam M ls ps is ↔ S.Inst M ls (S.Fam M ls ps) ps is t := by
1484 rw [← S.famOp_Fam M ls hnr hb hco]
1485 exact S.mem_famOp M ls
1486
from members of the field domains. This is the fixed-point equation of §4, read from left to rightwhitepaper/Fragment/LfpSet.lean:L137-L141137/-- **The fixed-point equation**, fibrewise. Con-leche:
138`lfpTuple_eq`. -/
139theorem lfpFamSet_eq (h : ∃ L, IsClosedFam n Φ L) (hmono : MonoFam n Φ) (hmaps : MapsFam n Φ)
140 (i : ι) : Φ (lfpFamSet n Φ) i = lfpFamSet n Φ i :=
141 Sub.antisymm (lfpFamSet_closed h hmono i) (lfpFamSet_fixed h hmono hmaps i)
.

When the family is proposition-valued (its result sort 𝖲𝗈𝗋𝗍𝑢 has 𝑢 evaluating to 0 at 𝜑), the family denotes a truth valuewhitepaper/Fragment/IndSem.lean:L592-L595592/-- A fibre of a family in the universe at a proposition is a truth
593value. -/
594theorem fibre_mem_univ_zero {W : List V → V} (hW : InUniv (S.u₀ ls) W) (hz : S.z ls = true) (is : List V) :
595 W is ∈ˢ (univ 0 : V) := by
instead. The constructor step’s tuple is not stored, only whether some such tuple exists, and a member of the family, like a constructor application, is the pointwhitepaper/Fragment/IndSem.lean:L1539-L15431539/-- At a proposition a member of the fibre is the point and some
1540decoding exists. -/
1541theorem mem_Fam_true {ps : List V} (hnr : S.NoRecDep) (hb : S.DomsBounded M ls ps)
1542 (hco : S.ContOk M ls ps) (hz : S.z ls = true) {is : List V} {t : V} :
1543 t ∈ˢ S.Fam M ls ps is ↔ t = pt ∧ ∃ x, S.Mem M ls ps is x := by
. Tagged tuples are injective (tupleswhitepaper/Fragment/IndLib.lean:L5353 tuple_inj : ∀ {xs ys : List V}, tuple xs = tuple ys → xs = ys
, tagswhitepaper/Fragment/IndLib.lean:L6060 tag_inj : ∀ {i j : Nat} {x y : V}, tag i x = tag j y → i = j ∧ x = y
) and a tagged tuple is ≠𝗉𝗍whitepaper/Fragment/IndLib.lean:L6464 tag_ne_pt : ∀ {i : Nat} {x : V}, tag i x ≠ pt
.

6.1. Proof irrelevance and propositional extensionality

These two need no rule; they are built into the model, and §2 used the first already. A proposition denotes a truth valuewhitepaper/Fragment/Lib.lean:L141-L147141/-- The truth value of a proposition: `{pt}` if it holds, `∅` if
142not. -/
143def truthVal (P : Prop) : V := sep one (fun _ => P)
144
145/-- The members of a truth value. -/
146theorem mem_truthVal {p : Prop} {z : V} : z ∈ˢ truthVal p ↔ z = pt ∧ p := by
147 unfold truthVal; rw [mem_sep, mem_one]
, a subset of {𝗉𝗍}, so any two proofs of any two propositions denote the same set, the point. That is the proof-irrel case of Theorem 2, which never compared the two propositionsConLeche/Model/Rules/DefEqSound.lean:L265-L267265theorem DefEq.proofIrrel_sound {d : Nat} {a ta b : Expr}
266 (hta : InferSemIO m φ d a ta) (hpt : PropPt m φ d ta) :
267 DefEqSem m φ d a b := by
. And two propositions that imply each other have the same truth valuewhitepaper/Fragment/Lib.lean:L172-L173172theorem truthVal_congr {p q : Prop} (h : p ↔ q) : (truthVal p : V) = truthVal q :=
173 ext fun z => by rw [mem_truthVal, mem_truthVal, h]
, by extensionality of sets. This is Lean’s axiom propext, which therefore holds in the modelConLeche/Model/AxiomMem.lean:L261-L268261/-- **`propext` inhabits its stored type's reading.** -/
262theorem propext_mem (mp : EnvModelM V env)
263 {cv : ConstantVal} (hok : ConLeche.stdAxiomOk env cv = true)
264 (hn : cv.name = propextName)
265 (ψ : Name → Nat) (ta : Term)
266 (hta : denote mp.base2.acval env ψ 0 cv.type = some ta)
267 (ρ : Nat → V) :
268 interp V ρ (.const .propext []) ∈ˢ interp V ρ ta := by
.

6.2. η for structures

The rule. A structure is a block with one constructor mk, no indices, no recursive field, and a type-valued family; let 𝑛 be the number of its fields. The official kernel equates any term 𝑠 of the structure type with the constructor applied to 𝑠’s projections,

𝑠≡𝚖𝚔𝑝⃗𝑠.1…𝑠.𝑛.

The check is that 𝑠’s type reduces to the structure at some parameters 𝑝⃗, and it compares each field of the constructor application with the corresponding projection of 𝑠. The fragment has no projection terms (Section 9). Read 𝑠.𝑖 below as the projection defined through the recursor, S.rec (𝜆𝑓⃗.𝑓𝑖)𝑠, whose value is the 𝑖-th component of the tuple by the ι law, or as a primitive projection, whose interpretation reads the component directly. The argument is the same either way.

Lemma 15 (structure η). Let the term 𝑠 denote a member of the structure’s family at the parameters 𝑝⃗, and for each 𝑖∈{1,…,𝑛} let the term 𝑓𝑖 denote the 𝑖-th component of that member’s tuple. Then

⟦𝚖𝚔𝑝⃗𝑓1…𝑓𝑛⟧=⟦𝑠⟧.
Proof. By the fixed-point equation, the member ⟦𝑠⟧ is a value one constructor step produces: ⟦𝑠⟧=tag(0,𝑥1,…,𝑥𝑛) for some sets 𝑥1,…,𝑥𝑛 in the field domains (there is only one constructor, so the tag is 0). Tagged tuples are injective, so these components are unique: the 𝑖-th component of ⟦𝑠⟧ is 𝑥𝑖, and that is what 𝑓𝑖 denotes. The constructor application denotes tag(0,⟦𝑓1⟧,…,⟦𝑓𝑛⟧)=tag(0,𝑥1,…,𝑥𝑛), the same set. □

The lemma proves nothing specific to the structure. The equation is what membership in the family means, read from left to right, plus the fact that a tuple determines its components. In the soundness case the rule’s field comparisons deliver ⟦𝑎𝑖⟧=⟦𝑠.𝑖⟧ for each 𝑖∈{1,…,𝑛}, where 𝑎𝑖 is the field the constructor was actually applied to, and the lemma does the rest. A block declared in Prop is never granted the rule. Where an instance of a Sort u structure happens to be a proposition, both sides are the point, and the law’s proposition case covers it.

ι through the projections. The same law on values, that a member is the constructor at its projections, gives a second way to fire 𝜄 on a block of a structure’s shape (one constructor, no indices, no recursive field). For such a block whose instances may be propositions, 𝜄 can go through the projections of the major premise 𝑥 instead of a constructor application. With 𝑆 the block’s type, 𝑝⃗ its parameters, 𝐶 the motive, 𝑚 the minor premise and 𝑆.𝑝1,…,𝑆.𝑝𝑘 the projections of its 𝑘 fields, the step is

𝑆.𝗋𝖾𝖼𝑝⃗𝐶𝑚𝑥⇝𝑚(𝑆.𝑝1𝑝⃗𝑥)…(𝑆.𝑝𝑘𝑝⃗𝑥).

This step is soundwhitepaper/Fragment/EtaIota.lean:L242-L260242/-- **ι through the projections, the semantic core**: given
243the plain ι law and the structure-η law, the redex
244`rec ps motive minor x` reduces to `minor (p₀ ps x) … (pₖ ps x)` with
245no certificate — no slot certificate on the major, no constructor
246telescope, no level, parameter or index comparison, and no reduction
247of the major. The redex is not the point, so its whole spine fits
248the recursor's telescope (`teleFit_of_ne_pt`); everything else is the
249laws'. -/
250theorem iotaEta_core_sem {Γ : List Expr} {c : Name} {us : List Level} {ci : ConstInfo}
251 {args : List Expr} {numParams numBefore d : Nat} {rl : RecRule} {cij : ConstInfo}
252 {projs : List Name}
253 (hfind : env.find? c = some ci)
254 (hus : us.length = ci.lparams.length)
255 (hlen : args.length = numBefore + 1)
256 (hpis : ci.type.hasPis (numBefore + 1) = true)
257 (hlaw : RecRuleLaw m.M c ci numParams numBefore numBefore rl cij)
258 (heta : StructEtaLaw m.M ci numParams numBefore d rl.ctor cij projs)
259 (hnP : numParams ≤ numBefore) (hnf : projs.length = rl.nfields)
260 (hd : d + cij.lparams.length = ci.lparams.length) :
with no certificate, no comparison and no reduction of the major, given the plain 𝜄 law and the structure-η law on values. The reduction claim assumes a well-denoted redex that is not the point, so the whole spine, the major included, fits the recursor’s telescope (Section 4.2.7). Where the structure is a proposition the major is the point, and so are its projectionswhitepaper/Fragment/EtaIota.lean:L402-L410402/-- **The projection of the point is the point**, from the field's
403sort: if the projection's type, walked along the parameters, is
404`(x : D) → B` and `B` is a proposition at every member of `D` whenever
405`D` holds the point — the field's sort is at most the structure's, so
406it is `Prop` wherever the structure is (non-impredicativity) — then the
407projection at the point is the point. This is what fails for an
408impredicative structure (a data field of a `Prop` structure), which
409after the renovation has no projections. -/
410theorem projPt_of_fieldSort {M : Name → List Nat → V} {T : Expr} {ρ : Nat → V} {f : V}
when every field’s sort is Prop wherever the structure’s is; the reduct is then the minor at the point, which is the recursor’s value there. The step must expand the major as found, before any reduction of it, and also when it already is a constructor application. A major that denotes the point may reduce to a term that is not well-denoted, and the projections of that reduct break the reduction claim (the witnesswhitepaper/Fragment/EtaIota.lean:L697-L714697open EtaWit in
698/-- **Eta on the reduct of the major is outside the claims**.
699The major `maj := (fun x : A => g (k x)) a` is well-denoted
700and the point (a lambda that is the point constrains nothing, so `a` may
701lie outside `A`), and it β-reduces to `maj' := g (k a)`, which is not
702well-denoted (`k` is a graph over `A`). The redex `rec minor maj` is
703well-denoted and not the point. Eta-expanding the major's reduct,
704`minor (p0 maj')`, breaks the reduction claim; eta-expanding the major
705as it stands, `minor (p0 maj)`, satisfies it. So the checker's eta
706path must not reduce the major first (lean4#15371 expands before the
707major's `whnf`). -/
708theorem etaIota_reduced_major_witness [LevelOracle] (φ : Name → Nat) (env : Env)
709 (Γ : List Expr) :
710 Red env Γ maj maj' ∧
711 (∀ ρ : Nat → V, WellDenoted (witM (V := V)) φ ρ redex2 ∧ interp witM φ ρ redex2 ≠ pt ∧
712 interp witM φ ρ maj = pt) ∧
713 ¬ RedSem (EnvModel.empty (witM (V := V))) φ [] redex2 etaRed2 ∧
714 RedSem (EnvModel.empty (witM (V := V))) φ [] redex2 eta2 := by
). For a structure without fields the step is K’s step (the reducts coincidewhitepaper/Fragment/EtaIota.lean:L349-L356349/-- **A structure with no fields: the eta reduct is the K reduct**,
350syntactically — the minor at the recursor's parameters, motives and
351minors (`True`, `PUnit`). -/
352theorem iotaEta_noFields (rhs : Expr) (args : List Expr) (numBefore numParams : Nat)
353 (ls : List Level) (x : Expr) :
354 Expr.mkAppN rhs (args.take numBefore ++ projApps [] ls (args.take numParams) x)
355 = Expr.mkAppN rhs (args.take numBefore) := by
356 simp [projApps]
). The fragment has no projections, so this step is a theorem about the claims, and not a rule of its relations.

In con-leche The checker has the rule as Lean has it, the constructor’s fields compared with the projections of the other sideConLeche/Rules/Rel.lean:L449-L460449 /-- **Structure η** (`structEtaCert` → `structEtaCertWith`,
450 `Kernel/Core.lean`): `a` is a fully applied constructor of an
451 η-capable stored structure, its projection table's constructor, `b`'s
452 io-inferred type head-normalises to that structure at agreeing levels
453 and the table's parameter count, the parameters agree pairwise, and
454 every field is the corresponding projection of `b`.
455 The type application is not certified: the type is a type, so its
456 spine fits the former's telescope (task #342 L11b). -/
457 | structEta {d : Nat} {a b tb wtb : Expr} {c : Name} {us : List Level}
458 {cvc : ConstantVal} {cnP cnF : Nat} {cT T : Name} {us' : List Level}
459 {cvT : ConstantVal} {caps : IndCaps} {tbl : ProjTable} :
460 Infer env .io d b tb → Red env d tb wtb →
, with its soundness caseConLeche/Model/Rules/DefEqSound.lean:L554-L556554theorem DefEq.structEta_sound (hin : RulesInputs V m φ) {d : Nat}
555 {a b tb wtb : Expr} {c : Name} {us : List Level} {cvc : ConstantVal}
556 {cnP cnF : Nat} {cT T : Name} {us' : List Level} {cvT : ConstantVal}
. It uses the same law when it prepares the major premise of a recursor on a structure that is never a proposition at the instance. The major is taken as found, before any head normalisation, and the constructor is applied to its projections, with no further check (the ruleConLeche/Rules/Rel.lean:L272-L281272 /-- **The structure-η rescue** (`majorToCtor`'s η branch,
273 `Kernel/Core.lean`; official `to_cnstr_when_structure`): at an
274 η-flagged single-rule recursor whose major's type is a never-`Prop`
275 instance of the structure, the constructor of the major's
276 projections is fabricated and scope-guarded. No certificate: the
277 major is the fabrication by the family's η law, and the fabrication
278 is graded by the η constructor's telescope coherence (task #342
279 L11b, `EtaCoherent`). The constructor and the counts are the
280 family's projection table's, which the η law is keyed on. -/
281 | rescueEta {d : Nat} {major tm tmaj fab : Expr} {recName : Name}
, its soundness caseConLeche/Model/Rules/IotaSound.lean:L763-L764763theorem Red.rescueEta_sound (hin : RulesInputs V m φ) {d : Nat}
764 {major tm tmaj fab : Expr} {recName : Name} {cv : ConstantVal}
). Only if that does not give a constructor application is the major head-normalised, and the same expansion is tried once more on the result. Whether a type has the rule at all is decided once, when it is installed, from its shape (one constructor, no index, in a block where no constructor is recursive), and recorded with the typeConLeche/Kernel/Inductives/BlockInstall.lean:L71-L7771def blockCapsAt (p : BlockShape) (mi : Nat) (isRec : Bool) : IndCaps :=
72 match (p.members.getD mi default).ctors, (p.members.getD mi default).nIdx with
73 | [c], nIdx =>
74 { eta := nIdx == 0 && !isRec
75 all := p.memberNames
76 nparams := p.nP
77 nIdx := nIdx
; the law itself is established there too, not at the use. It is the η law of the structure’s projection table, the record of its fields’ types that the checker stores for every one-constructor, index-free type (Section 9, “Projections”) (a member is the constructor at the parameters and its own projectionsConLeche/Model/Inductives/FixKit.lean:L673-L674673 (`sumMkAV_fold`: the application folds to the tagged tuple);
674* **(C) the η law** (`fixEntryEtaCore`): a member is the constructor at
). It is proved when the checker stores the tableConLeche/Model/Inductives/BlockStageTables.lean:L10-L1210`stageBlockTables`: the loop `checkBlockTables` runs — a table at
11every member with ONE constructor and no index, nothing at any other
12member — with `stageFixTable` at each table (abstract in the former's
, by the argument above on the tagged tuple.

6.3. Unit-likeness

The rule. A block with one constructor, no indices and no fields, such as PUnit or, at Prop, the proposition True, has one element up to definitional equality: the checker equates any two terms whose types reduce to it. The lemma below covers these nullary blocks; the checker’s rule reaches further (see the block after it), by the same laws applied field by field.

Lemma 16 (unit-likeness). If the terms 𝑠 and 𝑡 denote members of the family of such a block, at the same parameters, then ⟦𝑠⟧=⟦𝑡⟧.
Proof. When the family is type-valued, Lemma 15 with 𝑛=0: each member is tag(0), the one tagged empty tuple. When it is proposition-valued, the family is a truth value and both members are the point. □

So at given parameters the family of such a block has at most one member in either case: it is {tag(0)} when the family is type-valued, and a truth value when it is proposition-valued.

In con-leche The checker has the rule for any unit-like typeConLeche/Rules/Rel.lean:L485485 UnitLike env d wta →
(Lean’s: a Π-type whose codomain is unit-like, or a structure whose fields are propositions or unit-like), with its soundness caseConLeche/Model/Rules/UnitSound.lean:L487487theorem DefEq.unitLike_sound {d : Nat} {a ta wta b tb wtb : Expr}
. A structure is unit-like by its η law and its fields’ unit-likeness; a structure without fields has no field to check. The η law is its projection table’s, which every structure-like block member has, whatever its field count, and it is established at installation from the fixed point (the table’s η law, at every field countConLeche/Model/Inductives/FixKit.lean:L13311331 · -- the table's η law, at every field count
). Neither PUnit nor True is special to the checker: both are installed like any other block.

7. Checking module by module

A module is checked against the views its imports present. These may hide definition values or theorem proofs, so the environment used to check an imported declaration can differ from the environment in which it is used. We show how local checks nevertheless give each module a model, in which every name a module reads has the value it has where it is read from. The argument first uses an abstract interface; we then supply it from the set-theoretic models of §3 and §4.

7.1. Environment models in the abstract

Let 𝐶 be the context of the module we are checking, an environment built from a family of imported views (𝐸𝑥)𝑥∈𝑋, environments indexed by a set 𝑋. To check the declarations, we need a model of 𝐶 that preserves the values already assigned by the imports’ models. This requires agreement wherever two imported views store a name of 𝐶.

In general, write 𝑐∈𝐸whitepaper/Fragment/ModularSemantics.lean:L112-L113112 /-- the names an environment stores (`c ∈ E`) -/
113 Stores : Env → Name → Prop
when an environment 𝐸 stores a name 𝑐, and Mod(𝐸) for its models. A model 𝑚∈Mod(𝐸) assigns each name 𝑐∈𝐸 a value 𝑚(𝑐)∈Val; all proofs will receive one distinguished value 𝜋∈Val. Models 𝑚∈Mod(𝐸) and 𝑚′∈Mod(𝐸′) agree onwhitepaper/Fragment/ModularSemantics.lean:L97-L103 97/-- **Agreement on `C`** (`m ≍_C m'` in the paper): models `m` of `E`
98and `m'` of `E'` give the same value to every name of `C` that `E` and
99`E'` both store. -/
100def ModelsAgree {Env Name : Type u} {Mod : Env → Type w} {Val : Type w}
101 (Stores : Env → Name → Prop) (val : ∀ {E : Env}, Mod E → Name → Val)
102 (C : Env) {E E' : Env} (m : Mod E) (m' : Mod E') : Prop :=
103 ∀ n, Stores C n → Stores E n → Stores E' n → val m n = val m' n
an environment 𝐶 when they give the same value to every name of 𝐶 that both 𝐸 and 𝐸′ store:

𝑚≍𝐶𝑚′:⟺∀𝑐∈𝐶.𝑐∈𝐸∧𝑐∈𝐸′⟹𝑚(𝑐)=𝑚′(𝑐).

A family of models (𝑚𝑥∈Mod(𝐸𝑥))𝑥∈𝑋 is compatible for 𝐶 when 𝑚𝑥≍𝐶𝑚𝑦 for all 𝑥,𝑦∈𝑋.

Definition 17 (The model interface). A consistency proof must provide four lawswhitepaper/Fragment/ModularSemantics.lean:L122-L154122 /-- **assembly**: `C` is made of constants of the family `E` -/
123 Assembled : Env → ∀ {ι : Type u}, (ι → Env) → Prop
124 /-- every constant of an assembled environment comes from a member
125 that stores it -/
126 assembled_src : ∀ {C : Env} {ι : Type u} {E : ι → Env},
127 Assembled C E → ∀ n, Stores C n → ∃ i, Stores (E i) n
128 /-- **amalgamation** of a family that pairwise agrees on `C` -/
129 amalgamate : ∀ {C : Env} {ι : Type u} {E : ι → Env},
130 Assembled C E → ∀ m : (i : ι) → Mod (E i),
131 (∀ i i', ModelsAgree Stores @val C (m i) (m i')) →
132 ∃ mC : Mod C, ∀ i, ModelsAgree Stores @val C mC (m i)
133 /-- **`C` proves `E`'s `n` a proof** -/
134 ProofIn : Env → Env → Name → Prop
135 /-- a proof by `C` gets the proofs' value in every model agreeing on
136 `C` with one of `C` -/
137 proof_val : ∀ {C E : Env} {n : Name}, ProofIn C E n → ∀ (mC : Mod C) (m : Mod E),
138 ModelsAgree Stores @val C mC m → val m n = proofVal
139 /-- **`E`'s `n` is a proof by `E'`'s theorem**, read alike over `C`
140 (in the fragment: a statement `E'` itself infers to be a proposition) -/
141 ProofBy : Env → Env → Env → Name → Prop
142 /-- a copy of a theorem's statement gets the proofs' value in every
143 model agreeing on `C` with a model of `C` that agrees on `C` with one
144 of the theorem's environment -/
145 proofBy_val : ∀ {C E E' : Env} {n : Name}, ProofBy C E E' n →
146 ∀ (mC : Mod C) (m : Mod E) (m' : Mod E'), ModelsAgree Stores @val C mC m →
147 ModelsAgree Stores @val C mC m' → val m n = proofVal
148 /-- declarations -/
149 Decls : Type u
150 /-- **acceptance**: the checker accepts `D` over `Γ`, giving `Γ'` -/
151 Accepts : Env → Decls → Env → Prop
152 /-- **the conservative step** -/
153 step : ∀ {Γ Γ' : Env} {D : Decls}, Accepts Γ D Γ' → ∀ m : Mod Γ,
154 ∃ m' : Mod Γ', ∀ n, Stores Γ n → Stores Γ' n ∧ val m' n = val m n
. An assembly relation identifies contexts built from a family of environments, with every stored name supplied by a member:

Asm(𝐶,(𝐸𝑥))⟹∀𝑐∈𝐶.∃𝑥∈𝑋.𝑐∈𝐸𝑥.

Amalgamation turns models of the family compatible for 𝐶 into a model of 𝐶 that agrees on 𝐶 with each of them:

Asm(𝐶,(𝐸𝑥))∧(∀𝑥,𝑦∈𝑋.𝑚𝑥≍𝐶𝑚𝑦)⟹∃𝑚𝐶∈Mod(𝐶).∀𝑥∈𝑋.𝑚𝐶≍𝐶𝑚𝑥.

Proofs are recognised in two ways. Prf(𝐶,𝐸,𝑐) says that 𝐶 shows 𝐸’s entry at 𝑐 to be a proof (in the instance: its type is inferred over 𝐶 to be a proposition), and a model of 𝐸 agreeing on 𝐶 with a model of 𝐶 gives it 𝜋. By(𝐶,𝐸,𝐸′,𝑐) says that 𝐸’s 𝑐 has the statement of a theorem 𝐸′ stores under 𝑐, which 𝐶, 𝐸 and 𝐸′ read alike, and a model of 𝐸 agreeing on 𝐶 with a model of 𝐶 that agrees on 𝐶 with a model of 𝐸′ gives it 𝜋:

Prf(𝐶,𝐸,𝑐)∧𝑚𝐶≍𝐶𝑚⟹𝑚(𝑐)=𝜋,By(𝐶,𝐸,𝐸′,𝑐)∧𝑚𝐶≍𝐶𝑚∧𝑚𝐶≍𝐶𝑚′⟹𝑚(𝑐)=𝜋,

for all 𝑚𝐶∈Mod(𝐶), 𝑚∈Mod(𝐸) and 𝑚′∈Mod(𝐸′). Finally, for environments Γ, Γ′ and declaration data 𝐷, acceptance of 𝐷 over Γ, producing Γ′, must give a conservative step:

Acc(Γ,𝐷,Γ′)⟹∀𝑚∈Mod(Γ).∃𝑚′∈Mod(Γ′).∀𝑐∈Γ.𝑐∈Γ′∧𝑚′(𝑐)=𝑚(𝑐).

The step must extend every context model. For example, a context assuming a name 𝑐:𝖭𝖺𝗍 can receive 𝑐’s value 5 from an import. Adding an axiom 𝑐=0 would leave some model, but none preserving that imported value. The conservative step excludes this extension.

An environment 𝑉 refineswhitepaper/Fragment/ModularSemantics.lean:L160-L161160/-- **Refinement**: `Γ` is assembled from `E` alone. -/
161def Refines (Γ E : S.Env) : Prop := S.Assembled Γ fun _ : PUnit.{u + 1} => E
an environment 𝐸, written 𝑉⪯𝐸, when it is assembled from 𝐸 alone. Amalgamation of the one-member family then restrictswhitepaper/Fragment/ModularSemantics.lean:L170-L175170/-- **Restriction**: a model of `E` gives one of every refinement of
171`E`, with the same values. -/
172theorem restrict {Γ E : S.Env} (h : S.Refines Γ E) (m : S.Mod E) :
173 ∃ m' : S.Mod Γ, ∀ n, S.Stores Γ n → S.val m' n = S.val m n := by
174 obtain ⟨m', hm'⟩ := S.amalgamate h (fun _ => m) fun _ _ _ _ _ _ => rfl
175 exact ⟨m', fun n hn => hm' ⟨⟩ n hn hn (h.stores hn)⟩
any model 𝑚∈Mod(𝐸) to a model of 𝑉, preserving the value 𝑚(𝑐) at every 𝑐∈𝑉 (and assembly ensures 𝑐∈𝐸). Amalgamation of the empty family supplies a model for any context assembled from no environments.

7.2. Developments

Number modules by natural numbers. For module 𝑖∈ℕwhitepaper/Fragment/ModularSemantics.lean:L181-L193181/-- **A development** over `S`: per module its context, declarations,
182own environment, its sources (the views it reads, each with the module
183that presents it), for each context name the module it is read from,
184the order among its context names, and the part of its context below
185each name. -/
186structure Development (S : ModularSemantics.{u, w}) where
187 ctx : Nat → S.Env
188 decls : Nat → S.Decls
189 own : Nat → S.Env
190 sources : Nat → List (Nat × S.Env)
191 src : Nat → S.Name → Nat
192 rank : Nat → S.Name → Nat
193 part : Nat → S.Name → S.Env
, write Γ𝑖 for its context, 𝐷𝑖 for its declarations and 𝐸𝑖 for its own environment, which is to be validated. Module 𝑖 reads a list 𝑋𝑖 of imported views: pairs (𝑗,𝑉) of an earlier module 𝑗∈ℕ and a view 𝑉 that 𝑗 presents. A module may present several views, such as an exported and a private one, and 𝑋𝑖 holds the views 𝑖 reads of every module whose declarations it can see, including modules reached through re-exports, not only its direct imports. In Lean, these are the modules loaded for 𝑖, each at the level at which it is loaded (Section 7.8). The context of 𝑖 is assembled from its imported views. Each must refine the own environment of the module presenting it, so that the model can be restricted to what the importer reads. Module numbers will place imports before importers.

For each name 𝑐∈Γ𝑖, module 𝑖 names the module src𝑖(𝑐) it reads 𝑐 from, orders its context names by a rank rk𝑖(𝑐), and gives the part below 𝑐: an environment 𝑃𝑖(𝑐) of context names of smaller rank. Two modules may hold copies of one name, and nothing relates copies no module reads together. What the theory asks is that the copies a module reads agree: get one value in the models.

7.3. Agreement and validity

Module 𝑖 checks, for each name 𝑐∈Γ𝑖 and each imported view (𝑗,𝑉)∈𝑋𝑖 that stores 𝑐, that 𝑗’s copy agrees with the one 𝑖 reads. A copy is a proof for 𝑖, Pf𝑖(𝑐,(𝑗,𝑉))whitepaper/Fragment/ModularSemantics.lean:L205-L209205/-- **Source `x`'s copy of `n` is a proof** for module `i`: proved one
206over the part below `n`, or a copy of the statement of a source's
207theorem, read alike over the part. -/
208def ProofSide (i : Nat) (n : S.Name) (x : Nat × S.Env) : Prop :=
209 S.ProofIn (dev.part i n) x.2 n ∨ ∃ w ∈ dev.sources i, S.ProofBy (dev.part i n) x.2 w.2 n
, when 𝑖 proves it one over the part below 𝑐, or it has the statement of a theorem an imported view stores, read alike over that part:

Pf𝑖(𝑐,(𝑗,𝑉)):⟺Prf(𝑃𝑖(𝑐),𝑉,𝑐)∨∃(ℎ,𝑊)∈𝑋𝑖.By(𝑃𝑖(𝑐),𝑉,𝑊,𝑐).

One theorem among the copies of a statement is enough: a theorem’s type is a proposition, and every copy of its statement reads that type alike. The copy agreeswhitepaper/Fragment/ModularSemantics.lean:L211-L221211/-- **Source `x` agrees with the module `n` is read from** (see the
212module docstring): it is that module; or it reads `n` with a source
213of some module among its own, and module `i` has a source of that same,
214earlier module storing `n` (one record, loaded through two paths); or it
215and every source of the read module are proofs at `n`. -/
216def Agrees (i : Nat) (n : S.Name) (x : Nat × S.Env) : Prop :=
217 x.1 = dev.src i n ∨
218 (S.Stores (dev.ctx x.1) n ∧ ∃ z ∈ dev.sources x.1, S.Stores z.2 n ∧
219 ∃ w ∈ dev.sources i, w.1 = z.1 ∧ S.Stores w.2 n ∧ w.1 < x.1) ∨
220 dev.ProofSide i n x ∧
221 ∀ y ∈ dev.sources i, y.1 = dev.src i n → S.Stores y.2 n → dev.ProofSide i n y
, written Ag𝑖(𝑐,(𝑗,𝑉)), when one of three cases holds:

  1. 𝑗=src𝑖(𝑐): it is the module 𝑐 is read from;
  2. 𝑐∈Γ𝑗, some (ℎ,𝑊)∈𝑋𝑗 stores 𝑐, and some (ℎ,𝑊′)∈𝑋𝑖 with ℎ<𝑗 stores it too: one copy of an earlier module ℎ, loaded through two paths;
  3. Pf𝑖(𝑐,(𝑗,𝑉)), and Pf𝑖(𝑐,(ℎ,𝑊)) for every (ℎ,𝑊)∈𝑋𝑖 with ℎ=src𝑖(𝑐) and 𝑐∈𝑊: two proofs.

Module 𝑖 reads 𝑐whitepaper/Fragment/ModularSemantics.lean:L223-L230223/-- **How module `i` reads a context name `n`**: from a source of the
224module it is read from, with an assembled part below it, every source
225storing it agreeing. -/
226structure Reads (i : Nat) (n : S.Name) : Prop where
227 read : ∃ x ∈ dev.sources i, x.1 = dev.src i n ∧ S.Stores x.2 n
228 part : dev.Assembled i (dev.part i n)
229 below : ∀ c, S.Stores (dev.part i n) c → S.Stores (dev.ctx i) c ∧ dev.rank i c < dev.rank i n
230 agree : ∀ x ∈ dev.sources i, S.Stores x.2 n → dev.Agrees i n x
when some view of src𝑖(𝑐) in 𝑋𝑖 stores 𝑐, the part 𝑃𝑖(𝑐) is assembled from the views in 𝑋𝑖, its names are names of Γ𝑖 of smaller rank, and every view in 𝑋𝑖 storing 𝑐 agrees; write Rd𝑖(𝑐). For an environment 𝐸, abbreviate assembly of 𝐸 from the views in 𝑋𝑖 by Asm𝑖(𝐸).

Definition 18 (Valid module). The validity conditionswhitepaper/Fragment/ModularSemantics.lean:L234-L242234
235/-- **A valid module**: each source is a view of an earlier module that
236refines its own environment, its context is assembled from the sources
237and read from them, and the module is checked. -/
238structure Valid (i : Nat) : Prop where
239 sources : ∀ x ∈ dev.sources i, x.1 < i ∧ S.Refines x.2 (dev.own x.1)
240 assembled : dev.Assembled i (dev.ctx i)
241 reads : ∀ n, S.Stores (dev.ctx i) n → dev.Reads i n
242 checked : dev.Checked i
are

Valid𝑖:⟺(∀(𝑗,𝑉)∈𝑋𝑖.𝑗<𝑖∧𝑉⪯𝐸𝑗)∧Asm𝑖(Γ𝑖)∧(∀𝑐∈Γ𝑖.Rd𝑖(𝑐))∧Acc(Γ𝑖,𝐷𝑖,𝐸𝑖).

The condition on imported views makes induction and restriction possible. The rank orders the agreements. Whether a copy’s type is a proposition is inferred over the part below the name, which holds only names of smaller rank. Their copies agree by the time those of 𝑐 are compared, so the part below 𝑐 has a model amalgamated from the views’ models, and the proof law applies to every copy of 𝑐.

7.4. Compatible models and the theorem

The induction must construct models together with their agreement. For 𝑘∈ℕ, a family 𝑚𝑖∈Mod(𝐸𝑖), for 𝑖<𝑘, is compatiblewhitepaper/Fragment/ModularSemantics.lean:L244-L251244/-- **A compatible family** of models below `k`: each module gives every
245context name the value the module it is read from gives it, and so does
246every source of the module storing it. -/
247def Compatible (k : Nat) (m : (i : Nat) → i < k → S.Mod (dev.own i)) : Prop :=
248 ∀ j (hj : j < k) n, S.Stores (dev.ctx j) n →
249 ∃ h : dev.src j n < k, S.val (m j hj) n = S.val (m (dev.src j n) h) n ∧
250 ∀ y ∈ dev.sources j, ∀ hy : y.1 < k, S.Stores y.2 n →
251 S.val (m y.1 hy) n = S.val (m (dev.src j n) h) n
when every module gives each name of its context the value the module it is read from gives it, and so does every imported view storing it:

Cmp𝑘((𝑚𝑖)):⟺∀𝑖<𝑘.∀𝑐∈Γ𝑖.(src𝑖(𝑐)<𝑘∧𝑚𝑖(𝑐)=𝑚src𝑖(𝑐)(𝑐)∧∀(𝑗,𝑉)∈𝑋𝑖.𝑐∈𝑉⟹𝑚𝑗(𝑐)=𝑚src𝑖(𝑐)(𝑐)).

Two proofs of one statement under one name agree without comparing their bodies, since both get 𝜋.

Compatibility concerns values because hidden bodies can refer to names that have a different meaning in the importer. Take four modules 𝑗, 𝑘, 𝑙 and 𝑖:

𝑗:𝑑≔0,𝑐≔𝑑,presenting𝑐:𝖭𝖺𝗍𝑘:reads all of𝑗,𝑒:𝑐=0(by unfolding),presenting𝑐:𝖭𝖺𝗍,𝑒:𝑐=0𝑙:𝑑≔1𝑖:imports𝑘and𝑙,reading𝑐:𝖭𝖺𝗍,𝑒:𝑐=0,𝑑≔1.

The two copies of 𝑑 have different values, 0 and 1, but never meet in a context, so nothing asks them to agree. Restoring 𝑐≔𝑑 in 𝑖 would make 𝑐 unfold to 1, contradicting 𝑒; a model of 𝑖 instead takes 𝑐’s value from 𝑗 and 𝑑’s from 𝑙. A module that did read both copies of 𝑑 would have to show that they agree: they come from different modules, are not one copy loaded twice, and are not proofs, so the check rejects it. There is no combined environment of bodies and no renaming of names.

Theorem 19 (Modular checking). For every 𝑘∈ℕ, if the modules 𝑖<𝑘 are valid, they have a compatible family of modelswhitepaper/Fragment/ModularSemantics.lean:L272-L279272/-- **The modular theorem, over the interface**: if every module below
273`k` is valid, there is a compatible family of models, one of each
274module's own environment. -/
275theorem modular : ∀ k, (∀ i < k, dev.Valid i) →
276 ∃ m : (i : Nat) → i < k → S.Mod (dev.own i), dev.Compatible k m
277 | 0, _ => ⟨fun _ h => absurd h (Nat.not_lt_zero _), fun _ h => absurd h (Nat.not_lt_zero _)⟩
278 | k + 1, hv => by
279 obtain ⟨m, hc⟩ := modular k fun i hi => hv i (Nat.lt_succ_of_lt hi)
:

(∀𝑖<𝑘.Valid𝑖)⟹∃(𝑚𝑖∈Mod(𝐸𝑖))𝑖<𝑘.Cmp𝑘((𝑚𝑖)).

Proof. Induct on 𝑘, starting with the empty family. For each imported view (𝑗,𝑉)∈𝑋𝑘, restrict the earlier model 𝑚𝑗 to 𝑉. By induction on the rank, every view storing a name 𝑐∈Γ𝑘 gives it the value of 𝑚src𝑘(𝑐). In the first case of agreement this is the restriction. In the second, 𝑗’s copy is the value 𝑚𝑗 gives 𝑐, which by compatibility of the earlier family is the value of the view (ℎ,𝑊) that 𝑗 reads, and so of (ℎ,𝑊′), by an inner induction on the presenting module, as ℎ<𝑗. In the third, the names of the part below 𝑐 have smaller rank, so the restricted models agree there and amalgamate to a model of 𝑃𝑘(𝑐), which agrees there with every restricted model, a theorem’s view’s among them; the proof laws give 𝜋 to 𝑗’s copy and to the copies of src𝑘(𝑐).

The restricted models are thus compatible for Γ𝑘, and amalgamate to a model of Γ𝑘. The conservative step extends it to a model of 𝐸𝑘, in which every name of Γ𝑘 keeps the value of the module it is read from, giving Cmp𝑘+1. □

Forgetting compatibility gives the statement one usually needs.

Corollary 20 (Every module has a model). For every 𝑖∈ℕ, validity of the modules up to 𝑖 gives a model of 𝐸𝑖whitepaper/Fragment/ModularSemantics.lean:L367-L371367/-- **Every valid module's own environment has a model.** -/
368theorem own_model (k : Nat) (hv : ∀ i < k, dev.Valid i) :
369 ∀ i < k, Nonempty (S.Mod (dev.own i)) := by
370 obtain ⟨m, -⟩ := dev.modular k hv
371 exact fun i hi => ⟨m i hi⟩
:

(∀𝑗≤𝑖.Valid𝑗)⟹∃𝑚∈Mod(𝐸𝑖).
Proof. Apply Theorem 19 with 𝑘=𝑖+1 and take the member 𝑚𝑖 of the compatible family. □

7.5. The set-theoretic instance

We now supply Definition 17 using the models of §3 and §4. Write 𝐸(𝑐) for the entry an environment 𝐸 stores under a name 𝑐∈𝐸; it has level parameters 𝑝⃗, a type 𝑇 and a kind. An assumptionwhitepaper/Fragment/Env.lean:L82-L8582 /-- **An assumption**: a constant known by its type alone — a
83 theorem's statement, a hole, or a definition whose value is left
84 out (`Modular.lean`). It never unfolds. -/
85 | assumed
retains just the parameters and type. Its model obligation is the typing law of Definition 4, with no unfolding law. The instance’s value 𝑚(𝑐)whitepaper/Fragment/ModularInstance.lean:L107-L115107@[reducible] noncomputable def fragmentSemantics : ModularSemantics.{0, u} where
108 Env := Env
109 Name := Name
110 Stores E n := (E.find? n).isSome = true
111 Mod E := { m : BlockModel V E // ProofsPt E m.M ∧ Holds E m.M }
112 Val := List Nat → V
113 val m n := m.1.M n
114 proofVal := dflt
115 Assembled C _ E := Assembled C E
of a model 𝑚 at a name 𝑐 is the function assigning 𝑐 its set at every list of concrete levels; 𝜋 is the constant function with value 𝗉𝗍.

Models. A model of 𝐸 is a model in the sense of §3 and §4 in which proofs are the pointwhitepaper/Fragment/ModularModel.lean:L82-L8682/-- **Proofs denote the point**: every constant of a statement kind
83whose type reads as a truth value has the point as its set. The models
84the modular argument builds keep it. -/
85def ProofsPt (E : Env) (M : Name → List Nat → V) : Prop :=
86 ∀ n ci, E.find? n = some ci → ci.IsStmt → PropType M ci → M n = dflt
: every definition or assumption of 𝐸 whose type reads as a truth valuewhitepaper/Fragment/ModularModel.lean:L73-L7573/-- **A type read as a truth value** under `M`, at every list of levels. -/
74def PropType (M : Name → List Nat → V) (ci : ConstInfo) : Prop :=
75 ∀ ls, interp M (valOf ci.lparams ls) base ci.type ∈ˢ univ 0
has the point as its set, at every list of levels, and in which every stored constant holdswhitepaper/Fragment/Holds.lean:L39-L4039def Holds (E : Env) (M : Name → List Nat → V) : Prop :=
40 ∀ n ci, E.find? n = some ci → ModelOf M n ci
in the sense of Definition 11. Both survive amalgamation, since a constant’s clauses read only the constants its entry mentions, and the step.

Proofs. Prf(𝐶,𝐸,𝑐) holdswhitepaper/Fragment/ModularModel.lean:L710-L716710/-- **`C` proves `E`'s `n` a proof**: `E` stores `n` as a statement kind,
711of a type in scope of `C` and of `E` that the checker infers at `C` to
712be a proposition. -/
713def ProofIn (C E : Env) (n : Name) : Prop :=
714 ∃ ci, E.find? n = some ci ∧ ci.IsStmt ∧ Expr.Scoped C ci.lparams 0 ci.type ∧
715 Expr.Scoped E ci.lparams 0 ci.type ∧
716 ∃ s u, Infer C [] ci.type s ∧ Red C [] s (.sort u) ∧ LevelOracle.eq u .zero = true
when 𝐸 stores 𝑐 as a definition or an assumption whose type, in scope in both 𝐶 and 𝐸, has ⊢𝑇⇒𝑆⇝𝖲𝗈𝗋𝗍𝑢 over 𝐶 with 𝑢≐0. In a model of 𝐶, soundness makes the type a truth value; a model of 𝐸 agreeing on 𝐶 reads the type alike, since interpretation depends only on the mentioned constants; so the copy gets 𝜋whitepaper/Fragment/ModularModel.lean:L718-L731718/-- **A proof by `C` is the point** in every model of `E` that keeps
719proofs the point and agrees with a model of `C` on the constants both
720store. -/
721theorem ProofIn.eq_dflt {C E : Env} {n : Name} (h : ProofIn C E n) (mC : EnvModel V C)
722 (M : Name → List Nat → V) (hp : ProofsPt E M)
723 (hag : ∀ c, (C.find? c).isSome → (E.find? c).isSome → mC.M c = M c) : M n = dflt := by
724 obtain ⟨ci, hf, hk, hsC, hsE, s, u, hT, hr, hu⟩ := h
725 have hc : ∀ c ∈ ci.type.consts, ∀ ls, mC.M c ls = M c ls := fun c hc ls => by
726 rw [hag c (hsC.2.1 c hc) (hsE.2.1 c hc)]
727 have hpt : PropType M ci := by
728 intro ls
729 rw [← interp_consts hc]
730 exact PropType.of_infer mC hT hr hu ls
731 exact hp n ci hf hk hpt
. The fragment’s theorems are the statements their own environment infers to be propositions: By(𝐶,𝐸,𝐸′,𝑐)whitepaper/Fragment/ModularModel.lean:L733-L739733/-- **`E`'s `n` is a proof by `E'`'s**: `E` stores `n` as a statement
734kind of the type of `E'`'s `n`, which `E'` proves a proof itself (the
735fragment's theorems), the type in scope of `C` and of `E`. -/
736def ProofBy (C E E' : Env) (n : Name) : Prop :=
737 ∃ ci ci', E.find? n = some ci ∧ ci.IsStmt ∧ E'.find? n = some ci' ∧
738 ci'.lparams = ci.lparams ∧ ci'.type = ci.type ∧ Expr.Scoped C ci.lparams 0 ci.type ∧
739 Expr.Scoped E ci.lparams 0 ci.type ∧ ProofIn E' E' n
holds when 𝐸 stores 𝑐 as a definition or an assumption of the type of 𝐸′‘s 𝑐, in scope in 𝐶 and 𝐸, and Prf(𝐸′,𝐸′,𝑐). A model of 𝐸′ reads the type as a truth value, and the agreeing models of 𝐶 and 𝐸 read it alike, so the copy gets 𝜋whitepaper/Fragment/ModularModel.lean:L741-L758741/-- **A proof by `E'`'s is the point** in every model of `E` that keeps
742proofs the point and agrees with a model of `C` on the constants both
743store, that model agreeing so with one of `E'`. -/
744theorem ProofBy.eq_dflt {C E E' : Env} {n : Name} (h : ProofBy C E E' n)
745 (MC : Name → List Nat → V) (M : Name → List Nat → V) (m' : EnvModel V E') (hp : ProofsPt E M)
746 (hag : ∀ c, (C.find? c).isSome → (E.find? c).isSome → MC c = M c)
747 (hag' : ∀ c, (C.find? c).isSome → (E'.find? c).isSome → MC c = m'.M c) : M n = dflt := by
748 obtain ⟨ci, ci', hf, hk, hf', hlp, hty, hsC, hsE, ci'', hf'', -, -, hsE', s, u, hT, hr, hu⟩ := h
749 rw [hf'] at hf''
750 obtain rfl := Option.some.inj hf''
751 -- the theorem's type reads as a truth value in `E'`'s model, so in `E`'s
752 have hpt' := PropType.of_infer m' hT hr hu
753 have hc : ∀ c ∈ ci.type.consts, ∀ ls, m'.M c ls = M c ls := fun c hc ls => by
754 have hc' : c ∈ ci'.type.consts := by rw [hty]; exact hc
755 rw [← hag' c (hsC.2.1 c hc) (hsE'.2.1 c hc'), hag c (hsC.2.1 c hc) (hsE.2.1 c hc)]
756 refine hp n ci hf hk fun ls => ?_
757 rw [← interp_consts hc, ← hty, ← hlp]
758 exact hpt' ls
too.

Assembly. An entry’s laws transfer when everything they read is read alike. Accordingly, assemblywhitepaper/Fragment/ModularModel.lean:L426-L439426/-- **`C` is assembled from the family `E`**: every constant of `C` is,
427at the same name, the constant of a member or an assumption of its
428type, and lies within the part of that member that `C` stores too; a
429type former stored as such comes with its constructors. An assumption
430stands for statements only: every member's copy of its name is a
431definition or an assumption (`ConstInfo.IsStmt`). -/
432structure Assembled (C : Env) {ι : Type} (E : ι → Env) : Prop where
433 le : ∀ n ci, C.find? n = some ci → ∃ i,
434 ∃ ci', (E i).find? n = some ci' ∧ ci.Le ci' ∧ EntryScoped (common C (E i)) C ci
435 blocks : ∀ n ci nP nI cs S, C.find? n = some ci → ci.kind = .induct nP nI cs S →
436 S.nest = none → C.find? S.name = some S.indInfo ∧
437 ∀ (j : Nat) (c : CtorSpec), S.ctors[j]? = some c → C.find? c.name = some (S.ctorInfo c)
438 stmt : ∀ n ci, C.find? n = some ci → ci.kind = .assumed → ∀ i ci', (E i).find? n = some ci' →
439 ci'.IsStmt
requires each 𝐶(𝑐), for 𝑐∈𝐶, to come from some member 𝐸𝑥 of the family at the same name, either unchanged or as an assumption of the same parameters and type (entry refinementwhitepaper/Fragment/Modular.lean:L26-L2926/-- **One constant refines another**: it is the other, or an
27assumption with the other's level parameters and type. -/
28def ConstInfo.Le (ci ci' : ConstInfo) : Prop :=
29 ci = ci' ∨ (ci.kind = .assumed ∧ ∃ k, ci' = { ci with kind := k })
). An assumption stands for statements only: every member’s copy of its name is a definition or an assumption. The common partwhitepaper/Fragment/ModularModel.lean:L392-L396392open Classical in
393/-- **The part of `E` that `C` stores too**: `E`'s constants at the
394names `C` stores. -/
395noncomputable def common (C E : Env) : Env :=
396 ⟨E.consts.filter fun x => decide ((C.find? x.1).isSome = true)⟩
𝐸𝑥𝐶 consists of 𝐸𝑥’s entries at names also stored by 𝐶.

The retained entry must be in scope in this common partwhitepaper/Fragment/ModularModel.lean:L411-L424411/-- **A constant within an environment**: what its laws read — its
412type, its value, its rules with their constructors, its block — is in
413scope there, and the constructors a recursor's rules name are stored
414there as in `E'`. -/
415def EntryScoped (C E' : Env) (ci : ConstInfo) : Prop :=
416 Expr.Scoped C ci.lparams 0 ci.type ∧
417 (∀ v, ci.value? = some v → Expr.Scoped C ci.lparams 0 v) ∧
418 (∀ nP nM nMin nI rules, ci.kind = .recursor nP nM nMin nI rules → ∀ rl ∈ rules,
419 Expr.Scoped C ci.lparams 0 rl.rhs ∧
420 ∃ cij, C.find? rl.ctor = some cij ∧ E'.find? rl.ctor = some cij ∧
421 Expr.Scoped C cij.lparams 0 cij.type) ∧
422 (∀ nP nI cs S, ci.kind = .induct nP nI cs S → S.nest = none →
423 S.Scoped C ∧ (C.find? S.name).isSome ∧
424 ∀ (j : Nat) (c : CtorSpec), S.ctors[j]? = some c → (C.find? c.name).isSome)
: its type and any retained value or rule body are closed, mention only constants in the common part and use only the entry’s declared level parameters, as in §3 and §4. A recursor’s rules must also read the same constructor entries in 𝐸𝑥 and 𝐶, with their types in scope. Hiding a value removes its unfolding law and therefore its value dependencies; an assumption needs only its type’s dependencies.

For a retained plain type former (one without nesting), assembly also requires the block’s specification scopewhitepaper/Fragment/Decl.lean:L699-L710699def Scoped (env : Env) : Prop :=
700 (∀ i A, S.params[i]? = some A → Expr.Scoped env S.lparams (S.nP - 1 - i) A) ∧
701 (∀ t T, S.indices[t]? = some T → Expr.Scoped env S.lparams (S.nP + (S.nI - 1 - t)) T) ∧
702 S.sort.paramsIn S.lparams = true ∧
703 (∀ c ∈ S.ctors,
704 (∀ i f, c.fields[i]? = some f → S.fieldScoped env (c.fields.length - 1 - i) f) ∧
705 (∀ i f, c.fields[i]? = some f → fieldNoRecDep (c.fields.drop (i + 1)) f) ∧
706 c.idx.length = S.nI ∧
707 (∀ e ∈ c.idx, Expr.Scoped env S.lparams (S.nP + c.fields.length) e)) ∧
708 (S.large = true → S.elim ∉ S.lparams) ∧
709 S.lparams.Nodup ∧
710 S.NestScoped env
from Section 4.1 in the common part, with the type former and its constructors present there, and their exact generated entries in 𝐶. The models retain the block factswhitepaper/Fragment/BlockModel.lean:L46-L6646/-- **The block's law** in a model: for a plain block, its scope, its
47constants stored, its former's set the family's graph, its
48constructors' sets their graphs, and the universe bound on its fields
49at fitting parameters. Vacuous for a nested block. -/
50def BlockLaw (env : Env) (M : Name → List Nat → V) : Prop :=
51 S.nest = none →
52 S.Scoped env ∧ S.NoCont ∧
53 env.find? S.name = some S.indInfo ∧
54 (∀ (j : Nat) (c : CtorSpec), S.ctors[j]? = some c → env.find? c.name = some (S.ctorInfo c)) ∧
55 (∀ ls, M S.name ls = S.famSet M ls) ∧
56 (∀ (j : Nat) (c : CtorSpec), S.ctors[j]? = some c → ∀ ls, M c.name ls = S.ctorSet M ls j c) ∧
57 (∀ ls ps, FitsVals M (S.ψ ls) base S.params ps → S.DomsBounded M ls ps)
58
59end IndSpec
60
61/-- **A model of an environment that remembers its blocks**: an
62`EnvModel` with the block law of every stored block. -/
63structure BlockModel (V : Type u) [IndLib V] (env : Env) extends EnvModel V env where
64 /-- Every stored block's law. -/
65 blocks : ∀ (K : Name) (ci : ConstInfo) (nP nI : Nat) (cs : List Name) (spec : IndSpec),
66 env.find? K = some ci → ci.kind = .induct nP nI cs spec → spec.BlockLaw env M
from Section 4.2: scope, generated entries, the constructed family and constructor sets, and the field universe boundwhitepaper/Fragment/IndSem.lean:L601-L622601/-- **The universe bound on the fields, at every family in the
602universe**: above a proposition, along any list fitting the fields
603before a position relative to a family of members of the result
604universe, an ordinary field's domain is a member of the result
605universe, and so is every entry of a reflexive field's telescope at
606every fitting prefix of the telescope. Con-leche: the constructors'
607fields are small at every hole frame of the tuple space
608(`LfpClause.fieldsOk`, `ConLeche/Model/Env/BlockLfp.lean`, the
609install's `FieldsOkB`); the installation derives it from the checker's
610field-sort check read in a model in which the former denotes the
611one-fibre family (`domsBounded_of`, `InstallInd.lean`), whence every
612family by `domsBounded_of_fam`. -/
613def DomsBounded (ps : List V) : Prop :=
614 S.z ls = false → ∀ W, InUniv (S.u₀ ls) W → ∀ c ∈ S.ctors, ∀ k f,
615 c.fields[c.fields.length - 1 - k]? = some f → k < c.fields.length →
616 ∀ fs, S.FitsFields M ls W ps (c.fields.drop (c.fields.length - k)) fs →
617 match f with
618 | .ordinary A => interp M (S.ψ ls) (consList fs (envP ps)) A ∈ˢ (univ (S.u₀ ls) : V)
619 | .reflexive tele _ => ∀ t T, tele[t]? = some T → ∀ ys,
620 FitsVals M (S.ψ ls) (consList fs (envP ps)) (tele.drop (t + 1)) ys →
621 interp M (S.ψ ls) (consList ys (consList fs (envP ps))) T ∈ˢ (univ (S.u₀ ls) : V)
622 | .container => True
at every fitting parameter list, for every family in the result universe. These facts are needed when a later block uses this one as a container.

Amalgamation. Choose each name’s value from any member storing it, and use 𝜋 if no member does. On names of 𝐶, compatibility makes this assignment agree with every such member. Interpretation depends only on mentioned constantswhitepaper/Fragment/Hygiene.lean:L585-L587585theorem interp_consts {e : Expr} (h : ∀ c ∈ e.consts, ∀ ls, M c ls = M' c ls) {ρ : Nat → V} :
586 interp M φ ρ e = interp M' φ ρ e := by
587 induction e generalizing ρ with
, so scope in the common part transfers the typing, unfolding and recursor laws. The block facts transfer for the same reason, with assembly supplying the generated entries in 𝐶. This proves amalgamationwhitepaper/Fragment/ModularModel.lean:L452-L459452omit [LevelOracle] in
453/-- **Amalgamation**: models of the family that agree on every name of
454`C` two members store give a model of `C`, with each member's sets. -/
455theorem Assembled.model {C : Env} {ι : Type} {E : ι → Env}
456 (h : Assembled C E) (m : (i : ι) → BlockModel V (E i))
457 (hcomp : ∀ n i i', (C.find? n).isSome →
458 ((E i).find? n).isSome → ((E i').find? n).isSome → (m i).M n = (m i').M n) :
459 ∃ mC : BlockModel V C, ∀ n i, (C.find? n).isSome → ((E i).find? n).isSome →
. Proofs stay the point: a definition or an assumption of 𝐶 is a definition or an assumption of a member, of the same type, read alike (the amalgam keeps proofs the pointwhitepaper/Fragment/ModularModel.lean:L573-L577573omit [LevelOracle] in
574/-- **The amalgam keeps proofs the point**: a constant of a statement kind
575of `C` is one of a member's, of the same type, read alike. -/
576theorem Assembled.proofsPt {C : Env} {ι : Type} {E : ι → Env} (h : Assembled C E)
577 (m : (i : ι) → BlockModel V (E i)) (hp : ∀ i, ProofsPt (E i) (m i).M) (MC : Name → List Nat → V)
). Assembly also makes 𝐶 closedwhitepaper/Fragment/ModularModel.lean:L693-L695693omit [IndLib V] [LevelOracle] in
694/-- **An assembled environment is closed.** -/
695theorem Assembled.scoped {C : Env} {ι : Type} {E : ι → Env}
: its stored terms are in scope and its rules name stored constructors, because each common part is contained in 𝐶.

The conservative step. Definitions and blocks use the installation results of §3 and §4. A theorem 𝑐:𝑇≔𝑣whitepaper/Fragment/Decl.lean:L608-L618608/-- **A theorem is accepted** (con-leche's theorem check): its
609statement `ci.type` and a proof `v` pass the definition check, and the
610statement is a proposition. What is stored is the statement alone, as
611an assumption (`ConstKind.assumed`, `ci.kind`): a theorem never
612unfolds, in the checker (`Rules/Rel.lean`, only a definition unfolds)
613as in the fragment. So two proofs of one statement store the same
614constant. -/
615def ThmOk (env : Env) (c : Name) (ci : ConstInfo) (v : Expr) : Prop :=
616 ci.kind = .assumed ∧
617 DefOk env c { ci with kind := .defn v } ∧
618 (∃ s u, Infer env [] ci.type s ∧ Red env [] s (.sort u) ∧ LevelOracle.eq u .zero = true)
passes the definition check and additionally has a propositional type: ⊢𝑇⇒𝑆⇝𝖲𝗈𝗋𝗍𝑢 for some type 𝑆 and level 𝑢 with 𝑢≐0. It is stored as an assumption of 𝑇. Installing the checked definition and then forgetting its value extends every modelwhitepaper/Fragment/InstallThm.lean:L249-L255249/-- **Installing a theorem preserves having a model**: install its
250proof as a definition, then hide the value. Every stored constant
251keeps its set, and the theorem's is its proof's (`defVal`). -/
252theorem install_thm {env : Env} {c : Name} {ci : ConstInfo} {v : Expr}
253 (hs : Env.Scoped env) (m : BlockModel V env) (hok : ThmOk env c ci v) :
254 ∃ m' : BlockModel V (env.add c ci), (∀ n, (env.find? n).isSome → ∀ ls, m'.M n ls = m.M n ls) ∧
255 ∀ ls, m'.M c ls = defVal m.M { ci with kind := .defn v } v ls := by
, assigning the theorem the set of its proof.

Declaration data are a sequential list. Acceptancewhitepaper/Fragment/ModularInstance.lean:L54-L5654/-- **Acceptance**: the checked list over a closed context. -/
55def FAccepts (Γ : Env) (D : List Decl) (Γ' : Env) : Prop :=
56 Γ' = applyAll D Γ ∧ Checks Γ D ∧ Env.Scoped Γ
requires a closed context and the checks of §3 and §4 (or the theorem check) at each successive declaration. A definition’s or theorem’s set is its value’s, at every list of levelswhitepaper/Fragment/ModularModel.lean:L110-L113110/-- **A definition's set is the point** where its type reads as a truth
111value: the value lies in the type. -/
112theorem defVal_eq_pt {env : Env} (m : EnvModel V env) {c : Name} {ci : ConstInfo} {v : Expr}
113 (hok : DefOk env c ci) (hk : ci.kind = .defn v) (hp : PropType m.M ci)
, even those of the wrong length; the typing law alone constrains only correctly sized lists. Where its type reads as a truth value, the value lies in it, so the set is the point. Sequential installation therefore gives the conservative stepwhitepaper/Fragment/ModularModel.lean:L261-L265261theorem Checks.blockModel {E : Env} {ds : List Decl} (hc : Checks E ds) :
262 Env.Scoped E → ∀ m : BlockModel V E, ProofsPt E m.M → Holds E m.M →
263 ∃ m' : BlockModel V (applyAll ds E),
264 (∀ n, (E.find? n).isSome → ∀ ls, m'.M n ls = m.M n ls) ∧
265 ProofsPt (applyAll ds E) m'.M ∧ Holds (applyAll ds E) m'.M := by
, preserving old values and keeping proofs the point.

Remark 21 (A syntactic illustration). The modelswhitepaper/Fragment/ModularSyntactic.lean:L89-L9289/-- **A model of an environment**: a realisation. -/
90structure Real (T : SubstSystem N) (E : SEnv T) where
91 σ : N → T.Tm
92 real : Realises σ E.1
may instead be realisations by terms of a fixed ground theory: each constant is assigned a term of its realised type, equal to its realised value when a definition. Compatible realisations amalgamatewhitepaper/Fragment/ModularSyntactic.lean:L188-L195188/-- **Amalgamation**: the union of realisations that agree on every name
189of `C` two members store. -/
190theorem amalgamate {C : SEnv T} {ι : Type u} {E : ι → SEnv T}
191 (h : Assembled C E) (m : (i : ι) → Real T (E i))
192 (hcomp : ∀ c i i', (C.1 c).isSome → ((E i).1 c).isSome →
193 ((E i').1 c).isSome → some ((m i).σ c) = some ((m i').σ c)) :
194 ∃ mC : Real T C, ∀ c i, (C.1 c).isSome → ((E i).1 c).isSome →
195 some (mC.σ c) = some ((m i).σ c) := by
by choosing, for each name, the term of a member storing it. The stepwhitepaper/Fragment/ModularSyntactic.lean:L131-L134131/-- **The step for one definition**: realised by its realised value,
132by the substitution lemma. -/
133theorem addDef_step {Γ : SEnv T} {c : N} {A t : T.Tm} {hd : T.Der Γ.1 t A} (hc : Γ.1 c = none)
134 (m : Real T Γ) : ∃ m' : Real T (addDef Γ c A t hd), ∀ d, (Γ.1 d).isSome → m'.σ d = m.σ d := by
realises a fresh definition by its value under the old realisation; a substitution lemma gives its typing. This instancewhitepaper/Fragment/ModularSyntactic.lean:L223-L249223variable (T) in
224/-- **A syntactic consistency proof as a modular semantics.** -/
225noncomputable def syntacticSemantics : ModularSemantics.{u, u} where
226 Env := SEnv T
227 Name := N
228 Stores E c := (E.1 c).isSome = true
229 Mod := Real T
230 Val := Option T.Tm
231 val m c := some (m.σ c)
232 proofVal := none
233 Assembled C _ E := Assembled C E
234 assembled_src h c hc := by
235 obtain ⟨⟨A, v⟩, hA⟩ := Option.isSome_iff_exists.mp hc
236 obtain ⟨i, v', hE, -⟩ := h c A v hA
237 exact ⟨i, by rw [hE]; rfl⟩
238 amalgamate h m hc := by
239 obtain ⟨mC, hmC⟩ := amalgamate h m fun c i i' => hc i i' c
240 exact ⟨mC, fun i c hc _ hs => hmC c i hc hs⟩
241 ProofIn _ _ _ := False
242 proof_val h := h.elim
243 ProofBy _ _ _ _ := False
244 proofBy_val h := h.elim
245 Decls := List (N × T.Tm × T.Tm)
246 Accepts := Accepts
247 step h m := by
248 obtain ⟨m', hm'⟩ := h.step m
249 exact ⟨m', fun c hc => ⟨h.stores c hc, by rw [hm' c hc]⟩⟩
handles definitions only, and recognises no proofs, so copies agree only by being read from one module. It illustrates the interface; connecting a syntactic consistency proof of Lean would require a separate argument, including the shared proof value.

7.6. The local checks

For this instance, 𝐸𝑖=Γ𝑖+𝐷𝑖whitepaper/Fragment/ModularModel.lean:L776-L777776/-- **A module's own environment**: its context with its declarations. -/
777def Module.own (m : Module) : Env := applyAll m.decls m.context
, the context extended by the declaration list. Each module 𝑖 presents a set of views 𝒱︀𝑖, imports earlier modules, and names for each context name the module it is read from, its rank and the part below it; its imported views are every view of every importwhitepaper/Fragment/ModularModel.lean:L779-L782779/-- **The sources module `i` reads**: every view of each of its
780imports, with the import. -/
781def sources (dev : Nat → Module) (i : Nat) : List (Nat × Env) :=
782 (dev i).imports.flatMap fun j => (dev j).views.map fun E => (j, E)
, paired with the module presenting it. The checks divide by who runs themwhitepaper/Fragment/ModularModel.lean:L829-L847829/-- **The check per home**: every view a module presents refines its
830own environment. It reads the module alone, and runs once, however
831many modules import it. -/
832def InterfaceOk (dev : Nat → Module) (j : Nat) : Prop := ∀ E ∈ (dev j).views, Refines E (dev j).own
833
834/-- **The check per importer**: the module imports earlier modules, and
835its context is assembled from their views, by agreement. It reads the
836module, its imports' views and how they read their own names, never an
837import's own environment. -/
838structure ImportOk (dev : Nat → Module) (i : Nat) : Prop where
839 imports : ∀ j ∈ (dev i).imports, j < i
840 reads : FromViews dev i (dev i).context
841
842/-- **The local checks at module `i`**: its interface, its imports, and
843its declarations accepted against its context. -/
844structure LocalOk (dev : Nat → Module) (i : Nat) : Prop where
845 iface : InterfaceOk dev i
846 importOk : ImportOk dev i
847 checks : Checks (dev i).context (dev i).decls
:

Write Pass𝑖 for the three checks together. These concrete checks imply abstract validitywhitepaper/Fragment/ModularInstance.lean:L148-L159148/-- **A module that passes its local checks, as its imports do, is
149valid over the instance.** -/
150theorem toDev_valid (dev : Nat → Module) (i : Nat) (hv' : ∀ j ≤ i, LocalOk dev j) :
151 (toDev V dev).Valid i := by
152 have hv := hv' i (Nat.le_refl i)
153 have hi := hv.importOk
154 refine ⟨fun x hx => ?_, hi.reads.1, fun n hn => ?_, ?_⟩
155 · obtain ⟨hj, hE⟩ := mem_sources.mp hx
156 exact ⟨hi.imports _ hj, (hv' _ (Nat.le_of_lt (hi.imports _ hj))).iface _ hE⟩
157 · have r := hi.reads.2 n hn
158 exact ⟨r.read, r.part, r.below, r.agree⟩
159 · exact ⟨rfl, hv.checks, hi.reads.1.scoped⟩
:

(∀𝑗≤𝑖.Pass𝑗)⟹Valid𝑖.

The imports’ view checks supply the refinement of imported views, and context assembly supplies closure. Thus Definition 18 applies, and Theorem 19 gives compatible modelswhitepaper/Fragment/ModularInstance.lean:L178-L181178theorem modular_holds (dev : Nat → Module) (k : Nat) (h : ∀ i < k, LocalOk dev i) :
179 ∃ model : Nat → Name → List Nat → V,
180 (∀ j < k, Holds (dev j).own (model j)) ∧
181 (∀ j < k, ∀ n j', Sees dev j n j' → model j n = model j' n) := by
: every module gives each context name the set of the module it is read from, and every proof the point.

The theorem is stated over the input, as Theorem 12 is. A module 𝑗 sees a name 𝑐 as module 𝑗′‘s when 𝑐 is a context name of 𝑗 and a view of 𝑗′ that 𝑗 imports stores 𝑐whitepaper/Fragment/ModularInstance.lean:L170-L171170def Sees (dev : Nat → Module) (j : Nat) (n : Name) (j' : Nat) : Prop :=
171 ((dev j).context.find? n).isSome = true ∧ ∃ E, (j', E) ∈ sources dev j ∧ (E.find? n).isSome = true
:

𝑐∈Γ𝑗∧∃𝑉.(𝑗′,𝑉)∈𝑋𝑗∧𝑐∈𝑉.

The fragment has no import rules: 𝑋𝑗 is given, and the local checks say what it must satisfy. So seeing is read off the imported views, which are the parts of other modules that 𝑗 loads, and it covers both agreements a module’s reading needs: the module src𝑗(𝑐) a name is read from is seen, and so is every other module whose view holds a copy of it.

Theorem 22 (Every module has a model of its constants). For every 𝑘∈ℕ, assume Pass𝑗 for every module 𝑗<𝑘. Then there are assignments 𝑀𝑗, for 𝑗<𝑘, such that 𝑀𝑗 is a model of the constants of 𝐷𝑗whitepaper/Fragment/ModularInstance.lean:L204-L207204theorem modular (dev : Nat → Module) (k : Nat) (h : ∀ i < k, LocalOk dev i) :
205 ∃ model : Nat → Name → List Nat → V,
206 (∀ j < k, IsModel V (model j) (constantsOf (dev j).decls)) ∧
207 (∀ j < k, ∀ n j', Sees dev j n j' → model j n = model j' n) := by
(Definition 11), and every name 𝑐 that 𝑗 sees as 𝑗′‘s, for 𝑗,𝑗′<𝑘, has one value in both:

𝑐∈Γ𝑗∧(∃𝑉.(𝑗′,𝑉)∈𝑋𝑗∧𝑐∈𝑉)⟹𝑀𝑗(𝑐)=𝑀𝑗′(𝑐).
Proof. Take the compatible family of Theorem 19 and let 𝑀𝑗 be the assignment of 𝑚𝑗. The step installs 𝐷𝑗 as §3 and §4 do, and its models carry the clauses of Definition 11whitepaper/Fragment/ModularInstance.lean:L178-L181178theorem modular_holds (dev : Nat → Module) (k : Nat) (h : ∀ i < k, LocalOk dev i) :
179 ∃ model : Nat → Name → List Nat → V,
180 (∀ j < k, Holds (dev j).own (model j)) ∧
181 (∀ j < k, ∀ n j', Sees dev j n j' → model j n = model j' n) := by
for every stored constant, amalgamation and restriction included, so every constant of 𝐷𝑗, stored in 𝐸𝑗 as declared, holds in 𝑀𝑗. Compatibility gives 𝑚𝑗(𝑐)=𝑚src𝑗(𝑐)(𝑐), and the same value at every imported view storing 𝑐. □

Let 𝐵 be the empty Prop block of Corollary 13, with no level parameters, parameters, indices or constructors, and with large elimination. Let the modules up to 𝑖 pass their checks, so that Theorem 22 with 𝑘=𝑖+1 gives the constants of 𝐷𝑖 a model. If they include 𝐵’s recursor, then, by the argument of Corollary 13 over any model of such constantswhitepaper/Fragment/Main.lean:L59-L6259theorem IsModel.no_false {M : Name → List Nat → V} {C : Name → ConstInfo → Prop}
60 (h : IsModel V M C) {name recName elim : Name}
61 (hrec : C recName (IndSpec.falseSpec name recName elim).recInfo)
62 {t : Name} {ci : ConstInfo} (ht : C t ci) (hty : ci.type = .const name []) : False := by
, none of them has type 𝐼𝐵: no theorem of 𝐷𝑖 proves the empty proposition.

A context need not be everything a module loads. Let Γ′ store some of Γ𝑖’s entries, each as Γ𝑖 does, and let what the laws of each read lie in Γ′ itself. Then Γ′ is assembled from the same viewswhitepaper/Fragment/ModularModel.lean:L648-L651648omit [IndLib V] [LevelOracle] in
649/-- **A closed part of an assembled environment is assembled from the same family**: `C'` stores
650some of `C`'s constants, each as `C` does, and what their laws read lies in `C'`
651(`EntryScoped C' C'`). -/
, and its names are read as Γ𝑖’s are; so a closed part of the contextwhitepaper/Fragment/ModularModel.lean:L851-L854851/-- **The reach's lemma for a module**: a closed part of a context assembled from the imports'
852views, each constant as the context has it, is assembled from them too, by agreement. -/
853theorem FromViews.restrict {dev : Nat → Module} {i : Nat} {C C' : Env} (h : FromViews dev i C)
854 (hsub : ∀ n ci, C'.find? n = some ci → C.find? n = some ci)
may stand for the context in Pass𝑖. A checker may therefore check a module over the part of its context its own declarations reach, following types, the values a view retains and the rules of reached recursors, and stopping at every assumption.

7.7. What runs in parallel

The local checks read a module, its imports’ views and how they read their context names, so modules can be checked together once those data are available. Acceptance still requires every relevant module to pass. The model constructionwhitepaper/Fragment/ModularSemantics.lean:L280-L344280 have hk := hv k (Nat.lt_succ_self k)
281 have hlt : ∀ x : dev.Src k, x.1.1 < k := fun x => (hk.sources _ x.2).1
282 -- the earlier modules' models, restricted to the sources' views
283 have hview : ∀ x : dev.Src k, ∃ mv : S.Mod x.1.2, ∀ n, S.Stores x.1.2 n →
284 S.Stores (dev.own x.1.1) n ∧ S.val mv n = S.val (m x.1.1 (hlt x)) n := by
285 intro x
286 have hr := (hk.sources _ x.2).2
287 obtain ⟨mv, hmv⟩ := ModularSemantics.restrict hr (m x.1.1 (hlt x))
288 exact ⟨mv, fun n hn => ⟨hr.stores hn, hmv n hn⟩⟩
289 obtain ⟨fam, hfam⟩ := Classical.axiomOfChoice hview
290 have hsrc : ∀ n, S.Stores (dev.ctx k) n → dev.src k n < k := fun n hn => by
291 obtain ⟨x, hx, hx1, -⟩ := (hk.reads n hn).read
292 exact hx1 ▸ hlt ⟨x, hx⟩
293 -- every source storing a context name gives it the value of the
294 -- module it is read from, in rank order
295 have hread : ∀ r, ∀ n (hn : S.Stores (dev.ctx k) n), dev.rank k n = r →
296 ∀ x : dev.Src k, S.Stores x.1.2 n →
297 S.val (fam x) n = S.val (m (dev.src k n) (hsrc n hn)) n := by
298 intro r
299 induction r using Nat.strongRecOn with
300 | _ r ih =>
301 intro n hn hr x hs
302 have hR := hk.reads n hn
303 -- a proof's copy, by the model of the part below it, which the
304 -- names below make an amalgam of the sources
305 have hag : ∀ y y' : dev.Src k,
306 ModelsAgree S.Stores @S.val (dev.part k n) (fam y) (fam y') := by
307 intro y y' c hc' hy hy'
308 obtain ⟨hcC, hlt'⟩ := hR.below c hc'
309 rw [ih _ (hr ▸ hlt') c hcC rfl y hy, ih _ (hr ▸ hlt') c hcC rfl y' hy']
310 obtain ⟨mP, hmP⟩ := S.amalgamate hR.part fam hag
311 have hside : ∀ z : dev.Src k, dev.ProofSide k n z.1 → S.val (fam z) n = S.proofVal := by
312 intro z hp
313 rcases hp with hp | ⟨w, hw, hp⟩
314 · exact S.proof_val hp mP (fam z) (hmP z)
315 · exact S.proofBy_val hp mP (fam z) (fam ⟨w, hw⟩) (hmP z) (hmP ⟨w, hw⟩)
316 -- source by source, an earlier source's module first
317 suffices h : ∀ t, ∀ x : dev.Src k, x.1.1 = t → S.Stores x.1.2 n →
318 S.val (fam x) n = S.val (m (dev.src k n) (hsrc n hn)) n from h _ x rfl hs
319 intro t
… 25 more lines
has the same dependencies: restrict the imports’ models, amalgamate, and extend for checked declarations. Its compatibility proof uses the earlier family too, but the numbering adds no inputs to the construction of a module’s model.

7.8. Lean’s module system in these terms

The table maps Lean’s module system to the notions above. An exported level need not be self-contained; a view used in assembly must satisfy the scope conditions.

LeanHere
An exported level, with the imported dependencies of retained types and valuesA view retaining entries whose laws have the required dependencies; a value may be hidden while its type is kept
The private level, available under import allFull own declarations; with their context, they can supply the own environment as a view
The language server’s levelNo role in the argument
Imports and modules reached through public import re-exportsThe modules supplying the imported views
The environment built from the loaded levelsThe context Γ𝑖
An unavailable theorem proof or hidden definition valueAn assumption of the same type
A module loaded through two importsOne copy, read through two paths
Copies merged on import, allowed for theorems of the same statementCopies that agree as proofs of one statement
Declarations of one name never loaded togetherCopies no module reads together; nothing asks them to agree
A private name _private.…An ordinary name, read from the module that declares it
An exported entry mentioning a constant that neither its module’s exported level nor a module of that module’s public import closure holdsThe export completed where it was made: the importer reads, in addition, the view of the module the exporting module loads first holding that constant, as an assumption (an inductive type with its block), and that copy is read like a loaded one
backward.privateInPublic, which exports private constants with their valuesEntries like any other
In con-leche The checks are stated over con-leche’s own records (the local checksConLeche/Modular.lean:L213-L231213structure ImportOk (pins : List NatOpPinSet) (dev : Nat → Module) (i : Nat) : Prop where
214 below : ∀ b ∈ (dev i).imports, b < i
215 src_lt : ∀ n, ((dev i).context.find? n).isSome = true → (dev i).src n < i
216 nodup : ((dev i).context.consts.map (·.toConstantVal.name)).Nodup
217 /-- every context record is a presentation of the module its names are read from -/
218 presented : ∀ d ∈ (dev i).ctx, ∀ n ∈ declNames d, d ∈ (dev ((dev i).src n)).iface
219 /-- a context record is read from one module: its names have one source -/
220 one_src : ∀ d ∈ (dev i).ctx, ∀ n ∈ declNames d, ∀ n' ∈ declNames d,
221 (dev i).src n = (dev i).src n'
222 /-- what a context record reads is stored in the context, and agrees with its source's copy -/
223 reads : ∀ d ∈ (dev i).ctx, ∀ n ∈ declNames d, RecordScoped (readsAlike dev i ((dev i).src n)) d
224 /-- a context record reads only itself and the records before it -/
225 ordered : ∀ k (h : k < (dev i).ctx.length),
226 RecordScoped (streamEnv ((dev i).ctx.take (k + 1))) (dev i).ctx[k]
227 /-- the own records, accepted from the context by the pure fold's step -/
228 accepted : ∃ E, PureRun pins (dev i).decls (dev i).context E
229
230/-- **The local checks at module `i`**: its own interface's, and its checks as an importer. A
231development every module of which passes them is the hypothesis of the modular theorem. -/
): a context is a list of records each of which an earlier module presentsConLeche/Modular.lean:L86-L9686and the same tables (a theorem record, whatever value it carries, installs its statement), or the
87record's statement. The order is free because a record installs its constants as a set, its
88names distinct: an inductive group read from its home's exported part lists its recursors in that
89part's order, which is sorted by name, where the home's own record lists them in declaration
90order. A record at a `reduce*` name is presented as itself: the compiler-trust axioms
91(`ofReduceNat`, `ofReduceBool`) are accepted at an importer by that name's pinned statement, which
92is true only of the identity its home's opaque install certified. -/
93def Presents (e p : Declaration) : Prop :=
94 ((declConstants e).Perm (declConstants p) ∧ declTables e = declTables p) ∨
95 (e = stmtOf p ∧ ∀ n ∈ (declConstants p).map (·.toConstantVal.name), n ∉ reduceOpNames)
96
, as itself or as its statement, so an inductive type reaches an importer with its whole block; every context name is read from one module; what a context record reads is stored in the context. A record of module ℎ means by a name it reads the copy ℎ’s export holds: ℎ’s own, or that of a module of ℎ’s public import closure exporting it; a name neither holds is completed from ℎ’s view, on demand, for the names the context reads and every copy of every clashing name it stores. The importer’s check is that rule: a read passes when the context’s copy is that one, and otherwise the copy ℎ’s view locates must agree with the context’s. So the copy ℎ’s view locates for each such name agreesConLeche/Modular.lean:L172-L196172inductive Agree (dev : Nat → Module) : Nat → Nat → Name → Prop
173 /-- `b` is the module `i` reads `n` from -/
174 | same {i b : Nat} {n : Name} : b = (dev i).src n → Agree dev i b n
175 /-- `b` reads `n`, and an earlier module's copy agrees both with `b`'s and with `i`'s: one
176 record, loaded through two paths -/
177 | via {i b t : Nat} {n : Name} : ((dev b).context.find? n).isSome = true → t < b →
178 Agree dev b t n → Agree dev i t n → Agree dev i b n
179 /-- two proofs of one statement, whose names agree: `i` infers it to be a proposition over the
180 part of its context below `n` -/
181 | proof {i b : Nat} {n : Name} {ci ci' : ConstantInfo} :
182 (dev i).context.find? n = some ci → (dev b).own.find? n = some ci' →
183 ci'.toConstantVal = ci.toConstantVal → ci.isStmtKind = true → ci'.isStmtKind = true →
184 (∀ c ∈ ci.toConstantVal.type.readNames, Agree dev i b c) →
185 ci.toConstantVal.type.constsResolve ((dev i).part n) = true →
186 TypeIsProp .verified ((dev i).part n) ci.toConstantVal.type → Agree dev i b n
187 /-- two proofs of one statement, whose names agree: an earlier module `t` stores it as a
188 theorem, whose names agree too (a theorem's type is a proposition) -/
189 | thm {i b t : Nat} {n : Name} {ci ci' : ConstantInfo} {cv : ConstantVal} :
190 (dev i).context.find? n = some ci → (dev b).own.find? n = some ci' →
191 ci'.toConstantVal = ci.toConstantVal → ci.isStmtKind = true → ci'.isStmtKind = true →
192 (∀ c ∈ ci.toConstantVal.type.readNames, Agree dev i b c) →
193 ci.toConstantVal.type.constsResolve ((dev i).part n) = true →
194 t < i → (dev t).own.find? n = some (.thmInfo cv) → cv = ci.toConstantVal →
195 (∀ c ∈ ci.toConstantVal.type.readNames, Agree dev i t c) → Agree dev i b n
196
with the context’s: it is the copy of the module the name is read from, or one record loaded through two paths, or both are proofs of one statement whose names agree: an earlier module’s copy of it, its names agreeing too, is a theorem, or else its type is inferred to be a proposition over the records before the name’s; every record reads only itself and earlier records; and the module’s own records are accepted from the context by the pure declaration fold’s steps, which the cached fold the executable runs is proved to give. The theorem over the interface, for any instanceConLeche/Modular/Generic.lean:L278-L279278theorem modular : ∀ k, (∀ i < k, dev.Valid i) →
279 ∃ m : (i : Nat) → i < k → S.Mod (dev.own i), dev.Compatible k m
, is Theorem 19.

8. Comparing a challenge with a solution

A challenge states what is asked: statements whose proofs, or values, are left open. A solution supplies them. The checker checks the solution as it checks any input. It then checks the challenge as any input, with one exception: an open statement of the challenge is accepted when the solution justifies it. This section states the rule, shows that the constants of an accepted challenge have a model, and shows why the rule compares more than the open statement itself. Section 8.4 compares module by module: there the challenge is one more module, which imports the solution, and its declarations that the solution already holds are read from the solution instead of being checked.

8.1. Holes and justification

Definition 23 (Challenge, hole, solution). A challenge is an input that the checker checks declaration by declaration, as in Section 3 and Section 4; write 𝐸𝑐 for its environment. A hole of the challenge is an assumption it declares: a name 𝑛 with level parameters 𝑝⃗ and a type 𝑇, and no value,

(𝑛.{𝑝⃗}:𝑇).

A solution is an environment 𝐸𝑠 that the checker has accepted.

An assumption can state anything, an empty proposition included, so the checker does not accept a hole on its own. With a solution, a hole is accepted when the solution stores a constant of the same name that states the same, and everything the statement reads means the same in both environments. The second condition is a closure condition on names: a name the statement reads must itself be stored alike, and so must every name that this name’s entry reads, and so on.

Definition 24 (Shared names, justified hole). A set Sh of names is sharedwhitepaper/Fragment/Compare.lean:L361-L365361def Shared (EC ES : Env) (Sh : Name → Prop) : Prop :=
362 ∀ d, Sh d → ∃ ci ciS, EC.find? d = some ci ∧ ES.find? d = some ciS ∧ ci.IsStmt ∧
363 (ci = ciS ∨ (ci.kind = .assumed ∧ ci.lparams.Nodup ∧ ci.lparams.length = ciS.lparams.length ∧
364 ci.type = ciS.type.instL ciS.lparams (ci.lparams.map .param))) ∧
365 (∀ c ∈ ci.type.consts, Sh c) ∧ (∀ v, ci.value? = some v → ∀ c ∈ v.consts, Sh c)
between 𝐸𝑐 and 𝐸𝑠 when every 𝑑∈Sh satisfies two conditions. First, 𝐸𝑠 stores 𝑑, and 𝐸𝑐 stores 𝑑 as a definition or an assumption, in one of two ways:

  1. 𝐸𝑐 stores 𝑑 with the same entry as 𝐸𝑠, or
  2. 𝐸𝑐 stores 𝑑 as an assumption (𝑑.{𝑝⃗}:𝑇) with distinct level parameters 𝑝⃗, and 𝐸𝑠 stores 𝑑, of any kind, with level parameters 𝑞⃗, as many as 𝑝⃗, and a type 𝑇𝑠 such that

    𝑇=𝑇𝑠[𝑞⃗≔𝑝⃗].

Second, every constant that the type or the value of 𝑑’s entry in 𝐸𝑐 reads is in Sh again. A hole of the challenge is justifiedwhitepaper/Fragment/Compare.lean:L369369def Justified (EC ES : Env) (n : Name) : Prop := ∃ Sh, Shared EC ES Sh ∧ Sh n
by 𝐸𝑠 when its name lies in a shared set. The challenge checkwhitepaper/Fragment/Compare.lean:L376-L385376inductive ChallengeChecks (ES EC : Env) : Env → List Decl → Prop
377 | nil {E : Env} : ChallengeChecks ES EC E []
378 | cons {E : Env} {d : Decl} {ds : List Decl} : d.Ok E → ChallengeChecks ES EC (d.apply E) ds →
379 ChallengeChecks ES EC E (d :: ds)
380 | hole {E : Env} {c : Name} {ps : List Name} {T : Expr} {ds : List Decl} :
381 E.find? c = none → Expr.Scoped E ps 0 T → Justified EC ES c →
382 ChallengeChecks ES EC ((Decl.hole c ps T).apply E) ds →
383 ChallengeChecks ES EC E (.hole c ps T :: ds)
384
385omit [IndLib V] [LevelOracle] in
is the check of §3 and §4, with one more step: a fresh hole whose type is in scope and which 𝐸𝑠 justifies is stored as an assumption.

The level parameters are compared by position. A declaration’s level parameters are bound by the declaration, and a model reads a constant’s set off a list of levels by position (Definition 4). Renaming them changes none of the constant’s instances:

Lemma 25 (Renaming level parameters). Let 𝑇 use only the level parameters 𝑞⃗, and let 𝑝⃗ be distinct names, as many as 𝑞⃗. Then for every level list ℓ⃗ with |ℓ⃗|=|𝑞⃗|, renaming does not change the instanceswhitepaper/Fragment/Compare.lean:L124-L127124theorem Expr.instL_rename {ps ps' : List Name} {ls : List Level}
125 (hnd : ps'.Nodup) (hl' : ps'.length = ps.length) (hl : ls.length = ps.length) :
126 ∀ e : Expr, e.lparamsIn ps = true →
127 (e.instL ps (ps'.map .param)).instL ps' ls = e.instL ps ls
:

𝑇[𝑞⃗≔𝑝⃗][𝑝⃗≔ℓ⃗]=𝑇[𝑞⃗≔ℓ⃗].

So a hole and the solution’s constant it is justified by have the same instances: at every level list, they have the same type.

8.2. The challenge has a model

Let 𝑀𝑠 be a model of the solution’s environment 𝐸𝑠. The model 𝑀𝑐 of the challenge is built along the challenge’s check, as in Section 3 and Section 4, and it keeps one more fact: on every shared name stored so far it agrees with the solution’s model,

∀𝑑∈Sh.𝑀𝑐(𝑑)=𝑀𝑠(𝑑),

where, for two assignments 𝑀 and 𝑀′ and a name 𝑑, 𝑀(𝑑)=𝑀′(𝑑) means agreement at every list of natural numbers: 𝑀(𝑑,𝑘⃗)=𝑀′(𝑑,𝑘⃗) for all 𝑘⃗. Here Sh is a shared set read in the challenge’s final environment, holding the names of all justified holes. Three facts carry the construction. The first says that a denotation reads the model only at the constants the term reads:

Lemma 26 (Denotation is local). Let 𝑀 and 𝑀′ be assignments and 𝑒 a term, and write consts(𝑒) for the constants 𝑒 reads. If 𝑀 and 𝑀′ agree on consts(𝑒), then at every valuation and every variable environment 𝜌 𝑒 denotes the same in both, and is well-denoted in both alikewhitepaper/Fragment/Compare.lean:L161-L163161theorem denote_agree {M M' : Name → List Nat → V} {e : Expr}
162 (h : ∀ c ∈ e.consts, ∀ ls, M c ls = M' c ls) (φ : Name → Nat) (ρ : Nat → V) :
163 interp M φ ρ e = interp M' φ ρ e ∧ (WellDenoted M φ ρ e ↔ WellDenoted M' φ ρ e) :=
:

(∀𝑑∈consts(𝑒).𝑀(𝑑)=𝑀′(𝑑))⟹⟦𝑒⟧𝜌in𝑀=⟦𝑒⟧𝜌in𝑀′∧(𝜌⊧𝑒in𝑀⟺𝜌⊧𝑒in𝑀′).

The second gives a justified hole the solution model’s set:

Lemma 27 (A justified hole). Let 𝐸𝑐 be closed, with a model 𝑀𝑐, and let (𝑛.{𝑝⃗}:𝑇) be a fresh assumption, with distinct level parameters 𝑝⃗ and a type in scope of 𝐸𝑐. Let 𝐸𝑠, with a model 𝑀𝑠, store 𝑛 with level parameters 𝑞⃗, as many as 𝑝⃗, and a type 𝑇𝑠 that uses only 𝑞⃗, with 𝑇=𝑇𝑠[𝑞⃗≔𝑝⃗], and let 𝑀𝑐 and 𝑀𝑠 agree on every constant 𝑇 reads. Then 𝑀𝑐 extends to a model of the environment with the hole, with the solution model’s set at 𝑛whitepaper/Fragment/Compare.lean:L284-L293284theorem install_justified {E ES : Env} (hs : Env.Scoped E) (m : EnvModel V E)
285 (mS : EnvModel V ES) {a : Name} {ci ciS : ConstInfo}
286 (hfresh : E.find? a = none) (hk : ci.kind = .assumed)
287 (hty : Expr.Scoped E ci.lparams 0 ci.type)
288 (hS : ES.find? a = some ciS) (hnd : ci.lparams.Nodup)
289 (hlen : ci.lparams.length = ciS.lparams.length) (hSty : ciS.type.lparamsIn ciS.lparams = true)
290 (hren : ci.type = ciS.type.instL ciS.lparams (ci.lparams.map .param))
291 (hagree : ∀ d ∈ ci.type.consts, ∀ ls, m.M d ls = mS.M d ls) :
292 ∃ m' : EnvModel V (E.add a ci), (∀ n, (E.find? n).isSome → ∀ ls, m'.M n ls = m.M n ls) ∧
293 ∀ ls, m'.M a ls = mS.M a ls := by
:

∃𝑀𝑐′∈Mod(𝐸𝑐,(𝑛.{𝑝⃗}:𝑇)).𝑀𝑐′(𝑛)=𝑀𝑠(𝑛)∧∀𝑑∈𝐸𝑐.𝑀𝑐′(𝑑)=𝑀𝑐(𝑑).
Proof. Old laws survive the new set at 𝑛, because no stored term reads the fresh name (Section 3). For the new typing law, fix ℓ⃗ and 𝜑. By Lemma 25, 𝑇[𝑝⃗≔ℓ⃗] is 𝑇𝑠[𝑞⃗≔ℓ⃗]. It reads the constants 𝑇 reads, on which the two models agree, so by Lemma 26 it denotes the same set in both and is well-denoted in both alike. The typing law of 𝑀𝑠 puts 𝑀𝑠(𝑛,𝜑(ℓ⃗)) in that set. A hole has no value, so there is no unfolding law to show. □

The third gives a constant that both environments store alike the solution model’s set:

Lemma 28 (A shared constant). Let 𝐸𝑐 be closed, with a model 𝑀𝑐, and let 𝐸𝑠, with a model 𝑀𝑠, store an entry 𝐷 at a name 𝑑 fresh in 𝐸𝑐, a definition or an assumption whose type and value are in scope of 𝐸𝑐. If 𝑀𝑐 and 𝑀𝑠 agree on every constant that the type and the value read, then 𝑀𝑐 extends to a model of the environment with 𝑑’s entry, with the solution model’s set at 𝑑whitepaper/Fragment/Compare.lean:L319-L328319theorem install_shared {E ES : Env} (hs : Env.Scoped E) (m : EnvModel V E)
320 (mS : EnvModel V ES) {a : Name} {ci : ConstInfo}
321 (hfresh : E.find? a = none) (hk : ci.IsStmt)
322 (hty : Expr.Scoped E ci.lparams 0 ci.type)
323 (hvs : ∀ v, ci.value? = some v → Expr.Scoped E ci.lparams 0 v)
324 (hS : ES.find? a = some ci)
325 (hagree : ∀ d, (d ∈ ci.type.consts ∨ ∃ v, ci.value? = some v ∧ d ∈ v.consts) →
326 ∀ ls, m.M d ls = mS.M d ls) :
327 ∃ m' : EnvModel V (E.add a ci), (∀ n, (E.find? n).isSome → ∀ ls, m'.M n ls = m.M n ls) ∧
328 ∀ ls, m'.M a ls = mS.M a ls := by
:

∃𝑀𝑐′∈Mod(𝐸𝑐,𝐷).𝑀𝑐′(𝑑)=𝑀𝑠(𝑑)∧∀𝑑′∈𝐸𝑐.𝑀𝑐′(𝑑′)=𝑀𝑐(𝑑′).

The typing and unfolding laws of the new constant are those of 𝑀𝑠, carried over by Lemma 26. Both lemmas extend a model at a given setwhitepaper/Fragment/Compare.lean:L179-L192179theorem EnvModel.extend_stmt {E : Env} (hs : Env.Scoped E) (m : EnvModel V E) {a : Name}
180 {ci : ConstInfo} (hfresh : E.find? a = none) (hk : ci.IsStmt)
181 (hty : Expr.Scoped E ci.lparams 0 ci.type)
182 (hvs : ∀ v, ci.value? = some v → Expr.Scoped E ci.lparams 0 v) (A : List Nat → V)
183 (htype : ∀ (φ : Name → Nat) (ρ : Nat → V) (ls : List Level), ls.length = ci.lparams.length →
184 WellDenoted m.M φ ρ (ci.type.instL ci.lparams ls) ∧
185 IsTy (interp m.M φ ρ (ci.type.instL ci.lparams ls)) ∧
186 A (ls.map (Level.eval φ)) ∈ˢ interp m.M φ ρ (ci.type.instL ci.lparams ls))
187 (hunfold : ∀ v, ci.value? = some v →
188 ∀ (φ : Name → Nat) (ρ : Nat → V) (ls : List Level), ls.length = ci.lparams.length →
189 WellDenoted m.M φ ρ (v.instL ci.lparams ls) ∧
190 interp m.M φ ρ (v.instL ci.lparams ls) = A (ls.map (Level.eval φ))) :
191 ∃ m' : EnvModel V (E.add a ci), (∀ n, (E.find? n).isSome → ∀ ls, m'.M n ls = m.M n ls) ∧
192 ∀ ls, m'.M a ls = A ls := by
, as Section 3 extends it at a definition’s value.

Theorem 29 (The challenge has a model). Let the checker accept the solution, and accept the challenge with its holes justified by the solution’s environment 𝐸𝑠. Then the constants of the challenge have a modelwhitepaper/Fragment/Compare.lean:L675-L677675theorem solution_model_exists {dsS dsC : List Decl} (hS : Checks Env.empty dsS)
676 (hC : ChallengeChecks (applyAll dsS Env.empty) (applyAll dsC Env.empty) Env.empty dsC) :
677 ∃ M : Name → List Nat → V, IsModel V M (constantsOf dsC) := by
(Definition 11), a hole holding as the assumption of its statement: for the challenge’s declarations 𝐷𝑐,

∃𝑀.𝑀is a model of the constants of𝐷𝑐.

The statement does not mention the solution. Its model is a device of the proof, the source of the holes’ sets.

Proof. Take a model 𝑀𝑠 of 𝐸𝑠, as in the proof of Theorem 12. Induction along the challenge’s checkwhitepaper/Fragment/Compare.lean:L548-L552548theorem ChallengeChecks.model {ES EC : Env} (mS : EnvModel V ES) (hSs : Env.Scoped ES)
549 {E : Env} {ds : List Decl} (hc : ChallengeChecks ES EC E ds)
550 (hEC : ∀ n ci, (applyAll ds E).find? n = some ci → EC.find? n = some ci) :
551 Env.Scoped E → ∀ m : BlockModel V E, Holds E m.M →
552 (∀ d, Justified EC ES d → (E.find? d).isSome → m.M d = mS.M d) →
builds a model 𝑀𝑐 of the challenge’s environment that agrees with 𝑀𝑠 on the shared names stored so far. A declaration none of whose names is shared takes its own step (Section 3, Section 4), which keeps every stored constant’s set. A shared definition or assumption takes Lemma 28: everything it reads is shared and stored before it, so the agreement so far is the agreement the lemma asks for. A justified hole takes Lemma 27, with the agreement on its type’s constants in the same way. Both give the new name the solution model’s set, so the agreement extends to it. Every constant of the challenge is stored in its final environment as declared, so it holds in 𝑀𝑐, as in Theorem 12. □

A hole whose statement is an empty proposition is never justified: by the typing law of 𝑀𝑠, as in the proof of Lemma 27, the solution model’s set at the hole would be a member of the statement’s set, which is empty.

8.3. Why the statement’s reads must be shared

The closure condition is needed. Let the challenge declare a definition and a hole that reads it,

𝑓:𝖭𝖺𝗍≔3,𝑡:𝑓=5.

A solution declares its own 𝑓:𝖭𝖺𝗍≔5, and proves 𝑡 by unfolding it. The solution’s 𝑡 has the name of the hole and, as a term, the hole’s statement. But the statement reads 𝑓, and the two environments store 𝑓 with different values. So 𝑓 is in no shared set, 𝑡 is not justified, and the checker rejects the challenge.

Without the closure condition, Theorem 29 would fail at this hole. The solution model’s set at 𝑡 lies in ⟦𝑓=5⟧ in 𝑀𝑠, where 𝑓 is 5. In every model of 𝐸𝑐 the unfolding law makes 𝑓 the set 3, so ⟦𝑓=5⟧ is empty there, and the environment with 𝑡 has no model at all.

In con-leche con-leche compares two lean4export files, con-leche --compare CHALLENGE.ndjson SOLUTION.ndjson. It checks the solution’s file in full, then the challenge’s file with the solution’s environment justifying its holesConLeche/Cached/Decls.lean:L110-L116110/-- **A challenge checked with its axioms justified by a solution**: the fold over the
111challenge's records `ds`, with the environment of the solution's records `dsS` justifying its
112axioms (`checkDeclsWith`). The solution itself is not checked here: the main theorem asks for
113`checkDecls` on `dsS` too. -/
114def checkChallenge (mode : CheckMode) (pins : List NatOpPinSet) (maxNatSize : Nat)
115 (dsS ds : Array Declaration) : Except (CheckError × Nat) Env :=
116 checkDeclsWith mode pins maxNatSize ds (some (streamEnv dsS.toList))
. It compares compiled modules by the same rule, con-leche --olean --compare CHALLENGE SOLUTION: the solution’s closure is checked in full, then the challenge’s closure, read from the trusted directories alone, is checked in full with its holes justified by the solution’s environment; what that closure holds depends only on the files under the trusted directoriesConLeche/Verify/CompareInput.lean:L140-L142140theorem closureConstants_local {dirs : SearchPath} {fs₁ fs₂ : FS}
141 (h : FS.AgreeUnder dirs fs₁ fs₂) (roots : Array Name) :
142 closureConstants (dirs : Roots) fs₁ roots = closureConstants (dirs : Roots) fs₂ roots := by
, so an accepted run speaks of the trusted files alone. In both modes, everything the challenge imports is part of what is checked.

A hole is an axiom other than the built-in ones (propext, Classical.choice, Quot.sound, the compiler-trust family), or a definition, theorem or opaque constant whose value uses sorryConLeche/Cached/Justify.lean:L52-L6152
53/-- **A definition, theorem or opaque constant whose value uses a hole is the axiom of its
54statement**, where a solution may justify it (`IsModel` reads it so: `Declaration.records` reads
55such a definition, every theorem and every opaque constant by its statement). A record at a
56built-in axiom's name keeps its own check. -/
57def sideRecord : Declaration → Declaration
58 | d@(.defnDecl cv v _) | d@(.thmDecl cv v) | d@(.opaqueDecl cv v) =>
59 if !builtinAxiomName cv.name && Expr.mentionsAnyConstC [sorryAxName] v then .axiomDecl cv
60 else d
61 | d => d
, read as the axiom of its statement; an axiom at the name of a constant the checker computes withConLeche/Cached/Justify.lean:L69-L7769/-- **The statement a record offers to a solution**: an axiom's, other than a built-in one (a
70record whose value uses a hole is an axiom by then, `sideRecord`), and not at a name whose
71constant the checker computes with (a certified `Nat` operation, a compiler-trust operation):
72those are installed only by their own checks. -/
73def justifiable : Declaration → Option ConstantVal
74 | .axiomDecl cv =>
75 if builtinAxiomName cv.name || natOpName cv.name || reduceOpNames.contains cv.name then none
76 else some cv
77 | _ => none
(a certified Nat operation, a compiler-trust operation) takes its own check instead. The check of a holeConLeche/Cached/Justify.lean:L200-L216200/-- **The check of one record**, with a solution's index `J` or none. A record that offers a
201statement (`justifiable`) takes the justification route where there is a solution: the
202statement justified (`justifyWhy`), its type checked (`checkConstantValC`), the reserved names'
203check, and its constant installed. Every other record, and every record without a solution,
204takes its own check (`checkDeclStepC`). -/
205def checkRecordC (mode : CheckMode) (pins : List NatOpPinSet) (J : Option Solution) (fe : FEnv)
206 (pd : Declaration) : CheckCM FEnv :=
207 match J, justifiable pd with
208 | some J, some cv => do
209 flushC
210 if let some why := justifyWhy J fe cv then
211 throw (.invalid s!"{declCLabel pd} is not justified by the solution: {why}")
212 checkConstantValC mode fe cv
213 unless basisNamesOk pd do
214 throw (basisNamesError pd)
215 pure (fe.push (.axiomInfo cv))
216 | _, _ => checkDeclStepC mode pins fe pd
asks for the justification, then checks the hole’s type as any axiom’s, and installs the axiom. The justificationConLeche/Cached/Justify.lean:L185-L196185/-- **Is the statement `cv` justified by the solution `J`**, at the input's index `fe`: `none`,
186or why not. -/
187def justifyWhy (J : Solution) (fe : FEnv) (cv : ConstantVal) : Option String :=
188 match J.idx.find? cv.name with
189 | none => some s!"the solution has no constant {cv.name}"
190 | some cS =>
191 if !sameCvUpToLevels cv cS.toConstantVal then
192 some s!"the solution's {cv.name} has another type"
193 else
194 match coneGo J fe.find? fe.findTable? (J.idx.idx.size + 1) {} (needsGo {} #[] cv.type).2.toList with
195 | none => none
196 | some n => some s!"its type reads {n}, which the solution does not declare alike"
looks the name up in the solution, compares the statements up to the names of the level parameters, and walks everything the statement reads: each name reached must be the same constant in bothConLeche/Cached/Justify.lean:L117-L126117/-- **The input's copy is the solution's**: a copy of it (`copyB`: the same, or at other
118level-parameter names), or a copy of the statement (an axiom of the same name and type) of a
119solution definition, theorem or axiom — but not at a compiler-trust operation's name, whose
120constant the checker computes with and reads only as itself. -/
121def refinesB (ci ci' : ConstantInfo) : Bool :=
122 copyB ci' ci ||
123 match ci with
124 | .axiomInfo _ => ci'.isStmtKind && !reduceOpNames.contains ci'.toConstantVal.name &&
125 copyB (.axiomInfo ci'.toConstantVal) ci
126 | _ => false
, where a definition, theorem or axiom may be the solution’s at the challenge’s level-parameter names, and a hole the statement of the solution’s constant. The walk follows a constant’s laws, and from a type former its constructors and its block’s recursors, and every name of the same recordConLeche/Cached/Justify.lean:L148-L162148/-- **What the justification follows from a constant**: its laws' names (`NeedsSt.const`), a
149type former's constructors and its block's recursors (`T.rec` at every member, the names
150`blockRecNameSetOk` gives them), the names of its projection table, and its record's mates
151(`recordMates`). So a block is shared whole or not at all. -/
152def entryNeeds (mates : Std.HashMap Name (Array Name)) (findT : Name → Option ProjTable)
153 (ci : ConstantInfo) : Array Name :=
154 let x := NeedsSt.const ({}, #[]) ci
155 let x := match ci with
156 | .indInfo _ caps => x.names (caps.ctors ++ caps.all.map (fun m : Name => m.str "rec"))
157 | _ => x
158 let x := x.names (mates.getD ci.toConstantVal.name #[]).toList
159 match findT ci.toConstantVal.name with
160 | some t => (x.table t).2
161 | none => x.2
162
, so an inductive block is shared whole, at the same level-parameter names, or not at all.

The proof takes a shared inductive block whole: every constant of the block gets the solution model’s set, and the block’s laws read only shared constants. It renames the solution’s model to the challenge’s level-parameter namesConLeche/Model/Solution.lean:L16-L2416/-!
17# A stream checked with a solution has a model
18
19The solution's accepted fold carries a covered model with the canonical proofs' leaves
20(`declsRun_proofs`); renamed to the input's level-parameter names (`renEnv`), it is a model of the
21renamed solution (`EnvModelM.copyStmt`). The input's fold with the solution then carries a model
22(`sideFold`), and the records the fold checked have a model (`isModel_of_envModelM`), which is a
23model of the input (`isModel_sideRecords`).
24-/
and follows the challenge’s check: a shared record takes the solution’s sets, a justified hole the solution’s value, any other record its own stepConLeche/Model/Solution/Fold.lean:L17-L2517/-!
18# The input's fold, with a solution
19
20The input's accepted fold with the solution `JS` carries a covered model whose leaves on every
21shared name (`Shared`) are the renamed solution model's: a record whose names are shared takes
22the solution's leaves (`sharedStep`), a justified axiom the solution's value (`justStep`), any other
23record its own step (`declStep_agrees`). A record has all its names shared or none: its names
24are each other's mates (`recordMates`), and the justification's cone follows a name's mates.
25-/
. The capstone statesConLeche/Model/PureChecker.lean:L41-L4741/-- **A challenge stream accepted with its axioms justified by an accepted solution stream has
42a model in every set theory.** -/
43theorem solution_model_exists (V : Type w) [SetTheory V]
44 (pins : List NatOpPinSet) (maxNatSize : Nat) (dsS ds : Array Declaration)
45 (solution : (checkDecls .verified pins maxNatSize dsS).isOk)
46 (challenge : (checkChallenge .verified pins maxNatSize dsS ds).isOk) :
47 ∃ model, IsModel V model (· ∈ constantsOf ds.toList) :=
Theorem 29 for the checker’s functions: if checkDecls accepts the solution’s records and checkChallenge accepts the challenge’s with them, the challenge’s own constants have a model. Its corollary for the command lineConLeche/MainTheorem.lean:L61-L6661/-- **An accepted comparison's challenge file has a model**: an exit 0 of `--compare -- <c> <s>`
62read the file `c` as records that have a model in every set theory. -/
63theorem main_compare_json_model (V : Type w) [SetTheory V] {c s : String} {fs : FS}
64 (h : ModelIO.CanGive (Driver.runArgs ["--compare", "--", c, s]) fs 0) :
65 ∃ bC rC, fs.file c = some bC ∧ parseChunks [bC] = .ok rC ∧
66 ∃ model, IsModel V model (· ∈ constantsOf rC.decls.toList) :=
says the same of an exit 0 of --compare CHALLENGE.ndjson SOLUTION.ndjson. A model of the challenge holds no hole of type False, since False denotes the empty set.

The rule is a design choice, and another tool chooses differently: lake comparator makes the same kind of check with a stricter rule. A theorem must be a theorem on both sides, and a definition a definition; every other constant the statements reach is compared with Lean’s own equality on declarations, level-parameter names, binder names and annotations included. con-leche accepts as the justification of a hole a constant of any kind that states the same, compares only what the statement reads, closed under reads, and compares definitions, theorems and axioms up to the names of their level parameters.

8.4. Comparing modules

When a development is checked module by module (Section 7), the challenge 𝑐 is one more module, and it passes the local checks of Section 7.6 like any other module. It imports the imported views of its own imports and one more, the solution 𝑠 with the solution’s full own environment. So its context Γ𝑐 is assembled from these imported views, and every two copies of a context name in them agree (Definition 18).

A declaration of the challenge is a copy when one of its names is already stored by an imported view. A copy is not one of the challenge’s declarations 𝐷𝑐. Each name 𝑛 of a copy is a name of the context Γ𝑐, read from the module src𝑐(𝑛) like any imported name, and its entry in 𝐸𝑐 is the context’s entry. The checker compares the copy with that entry. Let the entry have level parameters 𝑞⃗ and type 𝑇, and let the copy have level parameters 𝑝⃗, distinct and as many as 𝑞⃗, and type 𝑇𝑐. A hole, a theorem or an opaque constant is a copy when it states the entry’s statement,

𝑇𝑐=𝑇[𝑞⃗≔𝑝⃗];

a definition has the entry’s value too, renamed in the same way, and an inductive block is the same block. Every other declaration of the challenge is its own, in 𝐷𝑐, and is checked. A hole among them is rejected: no imported view supplies its value.

The closure condition of Section 8.1 has no counterpart here. The challenge and the solution are read in one context. A name that a copy’s statement reads is one entry of Γ𝑐, whichever imported views store it, and the agreement of copies gives every copy of it one value in the models.

Theorem 30 (The challenge has a model, module by module). Let the modules 𝑗≤𝑐 pass their local checks. Then there are assignments 𝑀𝑗, for 𝑗≤𝑐, such that

  1. every module 𝑗≤𝑐 has a model 𝑀𝑗 of the constants of 𝐷𝑗whitepaper/Fragment/Compare.lean:L771-L776771theorem compare_solves (dev : Nat → Module) (c : Nat) (h : ∀ j ≤ c, LocalOk dev j) :
    772 ∃ model : Nat → Name → List Nat → V,
    773 (∀ j ≤ c, IsModel V (model j) (constantsOf (dev j).decls)) ∧
    774 (∀ j ≤ c, ∀ n j', Sees dev j n j' → model j n = model j' n) ∧
    775 ∀ n ci ps, (dev c).context.find? n = some ci → ps.Nodup → ps.length = ci.lparams.length →
    776 ModelOf (model c) n (ci.copyAt ps) := by
    (Definition 11);
  2. 𝑀𝑗(𝑛)=𝑀𝑗′(𝑛) whenever 𝑗 sees 𝑛 as 𝑗′‘s, for 𝑗,𝑗′≤𝑐, as in Theorem 22;
  3. every copy holds in the challenge’s model: for every entry (𝑛.{𝑞⃗}:𝑇) of Γ𝑐 and distinct level parameters 𝑝⃗ with |𝑝⃗|=|𝑞⃗|, the entry renamed to 𝑝⃗whitepaper/Fragment/Compare.lean:L715-L720715def ConstInfo.copyAt (ci : ConstInfo) (ps : List Name) : ConstInfo :=
    716 match ci.kind with
    717 | .defn v => ⟨ps, ci.type.instL ci.lparams (ps.map .param),
    718 .defn (v.instL ci.lparams (ps.map .param))⟩
    719 | .assumed => ⟨ps, ci.type.instL ci.lparams (ps.map .param), .assumed⟩
    720 | _ => ci
    (its type, and a definition’s value, renamed; an inductive block’s entry unchanged) holds in 𝑀𝑐.
Proof. Theorem 22, through the local checks (Section 7.6), gives the models and their agreement. A checked declaration stores only fresh names, so every entry of Γ𝑐 is an entry of 𝐸𝑐whitepaper/Fragment/ModularModel.lean:L167-L168167theorem Checks.find?_context {E : Env} {ds : List Decl} (hc : Checks E ds) {n : Name}
168 {ci : ConstInfo} (h : E.find? n = some ci) : (applyAll ds E).find? n = some ci := by
, and it holds in 𝑀𝑐 as every constant of 𝐸𝑐 does. A model reads a constant’s level parameters by position, so by Lemma 25 a copy holds where the constant doeswhitepaper/Fragment/Compare.lean:L743-L744743theorem ModelOf.copyAt {M : Name → List Nat → V} {n : Name} {ci : ConstInfo} (h : ModelOf M n ci)
744 (hT : ci.type.lparamsIn ci.lparams = true)
. The challenge sees each copy’s name as the module it is read from, so 𝑀𝑐 gives it that module’s value, the solution’s for a hole the solution fills. □

The copies take the place of the justified holes of Section 8.2: the value at a copy is the value of the module it is read from, the solution’s for a hole the solution fills. The model of the challenge needs no construction of its own, since Theorem 19 builds it as it builds every module’s.

The attack of Section 8.3 fails here in two ways. If the challenge declares 𝑓:𝖭𝖺𝗍≔3 itself and the solution declares 𝑓:𝖭𝖺𝗍≔5, the challenge’s 𝑓 is a copy of the solution’s, and a definition is a copy only with the entry’s value; the checker rejects it.

In the second way, a module 𝑎 declares 𝑓:𝖭𝖺𝗍≔3, and the challenge imports 𝑎 and has the hole 𝑡:𝑓=5. A solution that does not import 𝑎 declares its own 𝑓:𝖭𝖺𝗍≔5 and proves 𝑡 by unfolding it. The challenge’s imported views then store two copies of 𝑓, 𝑎’s and the solution’s. Whichever of them the challenge reads 𝑓 from, the other copy comes from a module that declares 𝑓 itself, not from an earlier module both import. Of the cases of agreement that Definition 18 asks for, only the last is left for it, and such a copy agrees only as a proofwhitepaper/Fragment/Compare.lean:L695-L701695theorem LocalOk.redeclared_is_proof {dev : Nat → Module} {i : Nat} (hv : LocalOk dev i)
696 {n : Name} (hn : ((dev i).context.find? n).isSome = true) {x : Nat × Env}
697 (hx : x ∈ sources dev i) (hs : (x.2.find? n).isSome = true)
698 (hne : x.1 ≠ (dev i).src n) (hctx : ((dev x.1).context.find? n).isSome = false) :
699 ProofSide dev i n x ∧
700 ∀ y ∈ sources dev i, y.1 = (dev i).src n → (y.2.find? n).isSome = true →
701 ProofSide dev i n y := by
: both copies would have to be proofs, and a definition of 𝑓 as 3 or 5 is none. So the challenge does not pass its local checks. In an accepted challenge that imports 𝑎, 𝑓 is 𝑎’s 𝑓, and it is 3 in every model of the compatible family.

In con-leche The modular modes compare by this rule: --olean --compare with --module, --modular or --schedule, and --check-graph --compare. The challenge is one more module of a modular runConLeche/Driver/CompareModule.lean:L11-L2311`con-leche --olean --module --compare [--trusted-search-path=T] --search-path=DIRS -- C S` is the
12worker of the challenge `C` in a modular run over the closures of `C` and of its solution `S`
13(`--check-graph --compare`, `--schedule --compare`): the worker of `C` (`checkModuleG`) with
14`import all S` added to `C`'s header (`Graph.solutionImport`), every module read through the
15trusted path, then the search path. It loads what Lean loads for a module importing both `C`'s
16imports and the whole of `S`, under Lean's clash rule over every loaded name. A record of `C` some
17name of which a loaded module stores is a copy of that constant (`copyRecs`, `copyCheck`): a hole
18of `C` (an axiom, a definition or opaque constant whose value uses `sorryAx`) or a theorem of `C`,
19of the loaded constant's statement up to the names of its level parameters; its names are read
20from the loads into the context, as any name `C` imports. Every other record of `C` is its own,
21checked against that context as any worker checks its module's. So `C`'s holes are justified by
22the solution's checked constants, and a name a hole's statement reads means one constant on both
23sides: there is one context.
over the closures of the challenge and the solution, with import all of the solution added to its header. It loads what Lean loads for such a module, under Lean’s rule for two loaded copies of one name, applied to every loaded name: two copies of a name are one constant, or the module is rejected. So a solution that declares its own 𝑓 beside the challenge’s import of 𝑎 is rejected as the attack above is. A record of the challenge some name of which a loaded module stores is a copyConLeche/Driver/Worker.lean:L106-L123106/-! ## A compared challenge's copies (task #619)
107
108At a compared challenge (`x`, the imports a run adds to its header: `import all` of its solution,
109`Graph.solutionImport`), the worker loads the solution with the challenge's own imports, under
110Lean's clash rule over every loaded name. A record of the challenge some name of which a loaded
111module stores is a **copy**: not the challenge's own record, its names read from the loads into
112the context, as any name the challenge imports. A copy must be what the loaded constant is
113(`copyCheck`), up to the names of its level parameters (ruling B of #619):
114
115* a hole (an axiom; a definition whose value uses `sorryAx`), a theorem or an opaque constant: one
116 constant that only its statement describes (`IsModel` reads it so), of the loaded constant's
117 statement. For a theorem, Lean's own rule for two loaded copies of one name (`subsumesInfo`);
118* a definition: the loaded definition, its value too;
119* an inductive block: the context's record of its names, the same record, one the kernel's reader
120 reads (`BlockRead`); a quotient record never.
121
122Every other record is the challenge's own, checked as any module's; a hole among them is one the
123solution does not fill (`ownHoleOk`). -/
, and its names are read into the context like any imported name. The check of a copyConLeche/Driver/Worker.lean:L209-L241209/-- **A copy against the loaded constants of its names** (see above; `r`, the context; `owner`,
210the record of each of its names). -/
211def copyCheck (m : Name) (ld : HeaderLoads) (ix : NameIndex) (r : Reach)
212 (owner : Std.HashMap Name Nat) (d : Declaration) : Except CheckError Unit :=
213 let n := recKey d
214 let src := ((ix.first[n]?).map fun c => ld.nameAt c.mod).getD .anonymous
215 if n == quotSoundName || n == sorryAxName then
216 let what := if n == quotSoundName then "the quotient's axiom" else "the placeholder axiom"
217 .error (.notImplemented s!"{n}: a hole at {what}, which installs no axiom of its own; \
218 con-leche cannot fill it")
219 else if !basisNamesOk d then
220 .error (.invalid s!"module {m} declares {n}, a name the checker reserves")
221 else
222 match owner[n]? with
223 | none => .error (.internal s!"{n}: the context does not hold the loaded constant")
224 | some k =>
225 let e := r.ctx.getD k default
226 let h := r.homes.getD k .anonymous
227 let ci? := (declConstants e).find? (·.toConstantVal.name == n)
228 match copyStmt? d, d, ci? with
229 | some cv, _, some ci =>
230 if Cached.sameCvUpToLevels cv ci.toConstantVal then .ok ()
231 else .error (.invalid s!"{n}: the constant of {h} is not of the statement of {m}'s \
232 {recKind d}")
233 | none, .defnDecl cv v hint, some ci =>
234 if sameDefUpToLevels (.defnInfo cv v hint) ci then .ok ()
235 else .error (.invalid s!"{n}: the constant of {h} is not {m}'s definition")
236 | none, .indDecl .., _ =>
237 if copyRecEq d e && blockReadB d && copyReadsB owner r d then .ok ()
238 else .error (.invalid s!"{n}: the constants of {h} are not {m}'s inductive type")
239 | _, _, none => .error (.internal s!"{n}: the context's record does not declare it")
240 | none, _, _ => .error (.invalid s!"module {m} declares {n}, which the module {src} it \
241 loads stores")
asks a hole (an axiom, or a definition whose value uses sorry), a theorem or an opaque constant to have the loaded constant’s statement, a definition its value too, both up to the names of the level parameters, and an inductive block to be the same record, its recursors reading their ι equations off their own types. A model reads a constant’s level parameters by position, so a renamed copy has the laws of the loaded constant. Every other record is checked as any module’s, and a hole among them is rejectedConLeche/Driver/Worker.lean:L251-L258251/-- **A hole of the challenge's own records** (an axiom other than a built-in one, a definition,
252opaque constant or theorem whose value uses `sorryAx`; `uses`, what a theorem's value read off the
253file): the solution does not fill it. -/
254def ownHoleOk (m : Name) (uses : Declaration → Array Name) (d : Declaration) :
255 Except CheckError Unit :=
256 if isHoleRec uses d then .error (.invalid s!"{recKey d}: a hole of {m} no loaded module fills (the \
257 solution has no constant of this name)")
258 else .ok ()
. Each module of the challenge’s closure is read from the trusted directories alone.

The modular capstonesConLeche/MainTheorem.lean:L138-L175138/-- **An accepted modular comparison's challenge closure has a family of models**: on a
139snapshot where every command `--schedule-commands --compare` prints for the challenge `C` and
140its solution `S` exits 0 (the graph check, a worker at every module of the headers' closure of
141`C` and `S` but `C`, the compare worker at `C`), on every snapshot that agrees with it under the
142challenge's directories, the family of `main_modular` for the closure of `C`. -/
143theorem main_modular_compare (V : Type w) [SetTheory V] {T D c s : String} {C S : Name}
144 {fs : FS} (hc : Olean.parseModName c = some C) (hs : Olean.parseModName s = some S)
145 (hgraph : ModelIO.CanGive (Driver.runArgs ["--check-graph", "--compare",
146 "--trusted-search-path=" ++ T, "--search-path=" ++ D, "--", c, s]) fs 0)
147 (hwork : ∀ m, Olean.HdrClosure
148 (⟨C, S, Driver.searchPathOf T, Driver.searchPathOf D, none⟩ : Driver.CmpReq).solRoots fs
149 [C, S] m → m ≠ C →
150 ∃ root', Olean.parseModName root' = some m ∧ ModelIO.CanGive (Driver.runArgs
151 ["--olean", "--module", "--trusted-search-path=" ++ T, "--search-path=" ++ D, "--",
152 root']) fs 0)
153 (hcmp : ModelIO.CanGive (Driver.runArgs ["--olean", "--module", "--compare",
154 "--trusted-search-path=" ++ T, "--search-path=" ++ D, "--", c, s]) fs 0) :
155 let sp := Driver.trustedOr (Driver.searchPathOf T) (Driver.searchPathOf D)
156 ∀ fs', FS.AgreeUnder sp fs fs' →
157 ∃ model : Name → (Name → List Nat → V),
158 (∀ m, Olean.InClosure sp fs' #[C] m → IsModel V (model m) (Olean.moduleConstants sp fs' m)) ∧
159 (∀ m n m', Olean.InClosure sp fs' #[C] m → Olean.Sees sp fs' m n m' →
160 model m n = model m' n) :=
161 Driver.Compose.modular_compare_graph V hc hs hgraph hwork hcmp
162
163open Frontend in
164/-- **The same, in one process**: every exit 0 of `--olean --modular --compare` has the family
165of `main_modular_compare`. -/
166theorem main_modular_compare_one (V : Type w) [SetTheory V] {T D c s : String} {C S : Name}
167 {fs : FS} (hc : Olean.parseModName c = some C) (hs : Olean.parseModName s = some S)
168 (h : ModelIO.CanGive (Driver.runArgs ["--olean", "--modular", "--compare",
169 "--trusted-search-path=" ++ T, "--search-path=" ++ D, "--", c, s]) fs 0) :
170 let sp := Driver.trustedOr (Driver.searchPathOf T) (Driver.searchPathOf D)
171 ∀ fs', FS.AgreeUnder sp fs fs' →
172 ∃ model : Name → (Name → List Nat → V),
173 (∀ m, Olean.InClosure sp fs' #[C] m → IsModel V (model m) (Olean.moduleConstants sp fs' m)) ∧
174 (∀ m n m', Olean.InClosure sp fs' #[C] m → Olean.Sees sp fs' m n m' →
175 model m n = model m' n) :=
state Theorem 30 for an exit 0 of every command of such a run, and of the run in one process: on every snapshot that agrees with the run’s under the challenge’s directories, every module of the challenge’s closure, the challenge with its copies among them, has a model of its constants, and a name a module sees as another module’s has the value that module’s model gives it. In particular, a challenge module with a constant of type False, a hole x : False among them, is never solvedConLeche/MainTheorem.lean:L179-L198179/-- **No accepted modular comparison's challenge module holds a constant of type `False`**: no
180snapshot where every command of `main_modular_compare` exits 0 has a constant of type `False` in
181the challenge module `C`, read through the challenge's directories. This covers what `C` sees
182through its solution too, which the family of `main_modular_compare` does not. -/
183theorem main_modular_compare_no_False (V : Type w) [SetTheory V] {T D c s : String}
184 {C S : Name} {fs : FS} {ci : ConstantInfo}
185 (hc : Olean.parseModName c = some C) (hs : Olean.parseModName s = some S)
186 (hgraph : ModelIO.CanGive (Driver.runArgs ["--check-graph", "--compare",
187 "--trusted-search-path=" ++ T, "--search-path=" ++ D, "--", c, s]) fs 0)
188 (hwork : ∀ m, Olean.HdrClosure
189 (⟨C, S, Driver.searchPathOf T, Driver.searchPathOf D, none⟩ : Driver.CmpReq).solRoots fs
190 [C, S] m → m ≠ C →
191 ∃ root', Olean.parseModName root' = some m ∧ ModelIO.CanGive (Driver.runArgs
192 ["--olean", "--module", "--trusted-search-path=" ++ T, "--search-path=" ++ D, "--",
193 root']) fs 0)
194 (hcmp : ModelIO.CanGive (Driver.runArgs ["--olean", "--module", "--compare",
195 "--trusted-search-path=" ++ T, "--search-path=" ++ D, "--", c, s]) fs 0)
196 (hci : Olean.InModulePart (Driver.trustedOr (Driver.searchPathOf T) (Driver.searchPathOf D))
197 fs C .private ci)
198 (hty : ci.type = .const falseName []) : False :=
.

9. What we left out

The fragment of §2–§4 is the real checker with everything removed that does not change the shape of the argument. This section lists what was removed, each with a short account of what the real proof does about it and links to the code. Then it describes where the real proof’s architecture differs from the fragment’s on the features they share.

9.1. Dropped features

Projections — Lean’s primitive projection e.i, the i-th field of a structure value e. For every inductive type with one constructor and no index the checker stores a projection tableConLeche/Kernel/Install.lean:L63-L7063def blockTables (p : BlockShape) : List MemberShape → Option (List ProjTable)
64 | [] => some []
65 | ms :: rest =>
66 match ms.structCtor? with
67 | some c =>
68 (structProjBodies ms.declared.name p.nP c.2 c.1.type).bind fun bodies =>
69 (blockTables p rest).map (⟨ms.declared.name, p.lps, p.nP, c.1.name, c.2, bodies⟩ :: ·)
70 | none => blockTables p rest
, the fields’ types read off the constructor. The real checker reduces a projection of a constructor application to that fieldConLeche/Rules/Rel.lean:L174-L189174 /-- **The structural projection** `proj_i (ctor p⃗ x⃗) ↦ x_i`
175 (`whnfCoreBody`'s `.proj` clause, `Kernel/Core.lean`), driven by
176 the projection table, with the
177 constructor telescope's syntactic arity (`projCertAt`,
178 `teleArityOk`). -/
179 | proj {d : Nat} {sn : Name} {i : Nat} {e : Expr} {entry : ProjEntry}
180 {us : List Level} {cvC : ConstantVal} {nP nF : Nat} {induct : Name} :
181 env.findProj? sn i = some entry →
182 e.getAppFn = .const entry.ctor us →
183 i < entry.numFields →
184 e.getAppArgs.length = entry.numParams + entry.numFields →
185 us.length = entry.levelParams.length →
186 env.find? entry.ctor = some (.ctorInfo cvC nP nF induct) →
187 (Expr.peelPis e.getAppArgs.length
188 (cvC.type.instantiateLevelParams cvC.levelParams us)).isSome = true →
189 Red env d (.proj sn i e) (e.getAppArgs.getD (entry.numParams + i) (.bvar 0))
and infers its type from the tableConLeche/Rules/Rel.lean:L676-L684676
677/-- **Official's walk to a family's sort** (`formerSortLoop`): the binders, each
678reached by reduction, and then a sort. -/
679inductive FormerSort (env : Env) : Nat → Nat → Expr → Level → Prop where
680 | sort {d : Nat} {e : Expr} {s : Level} :
681 Red env d e (.sort s) → FormerSort env d 0 e s
682 | pi {d n : Nat} {e dom b : Expr} {s : Level} :
683 Red env d e (.forallE dom b) →
684 FormerSort env (d + 1) n (b.instantiate1 (.fvar d dom)) s →
; in the model a structure value is the tagged tuple of Section 6.2 and a projection reads a component, which the install of the tableConLeche/Model/Inductives/BlockStageTables.lean:L10-L1210`stageBlockTables`: the loop `checkBlockTables` runs — a table at
11every member with ONE constructor and no index, nothing at any other
12member — with `stageFixTable` at each table (abstract in the former's
establishes (its typing and ι lawsConLeche/Model/Inductives/FixKit.lean:L667-L672667
668* **(A) the typing law** (`fixEntryTypingCore`): a member projects at
669 `i + 1` into the body's residual — the graph regime by the tower's
670 projection membership below the tag, the squash regime by the point;
671* **(B) the iota law** (`fixEntryIotaCore`/`fixEntryIotaZeroPt`): the
672 projection of a graded constructor application is the selected field
).

Mutual inductive types — Several types declared together, each constructor free to mention any of them. The real checker checks such a block the same way as a single type, with a tuple of operators, one per type of the block, and each type’s family is a component of their simultaneous least fixed pointConLeche/SetTheory/Derive/LfpTuple.lean:L8-L12 8
9The carrier of a block of `k` inductive families `T₀ … T_{k-1}` is the
10simultaneous least pre-fixed point of its constructor-tower functor
11acting on **tuples of families** — a meta-level tuple `X : Nat → V`
12whose `m`-th component (`m < k`) is a family over member `m`'s own
. The argument is the one for a single type, with more indices, so this document skips it.

Nat and String literals, and the fast Nat path — Numerals and strings are terms of their own; the checker expands a literal to its constructor form when reduction needs it (natLitConLeche/Rules/Rel.lean:L149-L151149 | natLit {d : Nat} {n : Nat} :
150 natLitStored env = true →
151 Red env d (.lit (.natVal n)) (natLitToConstructor n)
, strLitConLeche/Rules/Rel.lean:L156-L158156 | strLit {d : Nat} {s : String} :
157 strLitStored env = true →
158 Red env d (.lit (.strVal s)) (strLitToConstructor s)
) and folds Nat.succConLeche/Rules/Rel.lean:L161-L164161 | natSucc {d : Nat} {a w : Expr} {n : Nat} :
162 natLitStored env = true →
163 Red env d a w → rawNatLit? w = some n →
164 Red env d (.app (.const natSuccName []) a) (.lit (.natVal (n + 1)))
and the binary Nat operationsConLeche/Rules/Rel.lean:L168-L173168 | natOp {d : Nat} {c : Name} {a wa b wb r : Expr} {n₁ n₂ : Nat} :
169 c ∈ natBinOpNames →
170 Red env d a wa → rawNatLit? wa = some n₁ →
171 Red env d b wb → rawNatLit? wb = some n₂ →
172 natOpResult c n₁ n₂ = some r →
173 Red env d (.app (.app (.const c []) a) b) r
on literals with machine arithmetic. The folding is sound only for the operations as the toolchain defines them, so the checker compares each stream’s definition against a pinned copyConLeche/Kernel/NatOpPins.lean:L8-L21 8`#load_natop_pins` below splices, per **committed dump** listed —
9`pins/<toolchain>.json`, the repository's top-level `pins/` directory,
10see `pins/README.md` — one **pin variant** `natOpPinSet_v<i> :
11NatOpPinSet` (`ConLeche/Kernel/NatOpPinSet.lean`): per pin-certified
12operation (`Nat.div`, `Nat.mod`, …) that toolchain's pinned defining
13expression, certificate proof blobs and type pins, as constants
14`nat…DeclPin_v<i> : Expr` / `nat…CertProofs_v<i> : List Expr`. The
15variants are listed in `natOpPinSets` in the order below. That list is
16what the shipped binary hands the fold as its PIN-LIST PARAMETER (task
17#304), and the order is the order the install gate tries them in
18(`checkDivModPinLoop`, `ConLeche/Kernel/Checker.lean`): the first
19whose guards pass, whose type pins (task #364) and pin are
20definitionally equal to the stream's stored types and value, and whose
21certificates check enables the operation's fast path. The hand-pinned certificate *statements* the proofs are checked against
and the model establishes the operations’ recurrencesConLeche/Model/NatEqs.lean:L1046-L10501046theorem natOps_install (mp : EnvModelM V env) {φ : Name → Nat}
1047 {F : Nat} (hde : DefEqClaim mp.base2 φ F)
1048 (hprev : NatOps mp.base2 φ)
1049 {c : Name} {lps : List Name} {type' value' : Expr}
1050 {hint : ReducibilityHint}
from that comparison.

Quotients — Quot, Quot.mk, Quot.lift, Quot.ind and the axiom Quot.sound have a built-in pinConLeche/Kernel/Basis/Quot.lean:L8-L14 8# The pinned `Quot` basis block
9
10Lean's kernel quotient bundle, pinned as an installed basis block:
11`Quot` as a stored inductive with the single constructor `Quot.mk`,
12the eliminators `Quot.lift`/`Quot.ind` as stored recursors with one
13synthetic rule each (applying the lift/ind slot to the packed
14element), and `Quot.sound` as a stored axiom (true in the set model).
and are modelled by the set-theoretic quotient of a set by a relationConLeche/SetTheory/Derive/Quot.lean:L65-L6765/-- The quotient (see module docs). -/
66noncomputable def quotSet (u : Nat) (A R : V) : V :=
67 if u = 0 then image (fun _ => pt) A else image (fun a => kpair empty (qclass A R a)) A
, for which the pinned constants are shown to be members of their typesConLeche/Model/BasisQuot.lean:L2772-L27782772theorem extendQuotLift (mp : EnvModelM V env)
2773 (hQ : env.find? quotName = some (quotA.atLps [q]))
2774 (hM : env.find? quotMkName = some (quotMkA.atLps [x]))
2775 (hE : EqStored env)
2776 (hfresh : env.find? quotLiftA.name = none)
2777 (hwf : EnvWF ⟨quotLiftA :: env.consts, env.tables⟩) {ex : List Name} :
2778 CoverTo mp ex ⟨quotLiftA :: env.consts, env.tables⟩ ex := by
.

Pinned blocks — In the fragment False is whatever empty proposition the stream declares. The real checker has hand-written copies of the toolchain’s Eq, Nat, Empty, False and the quotient Quot (False, for instanceConLeche/Kernel/Basis/False.lean:L37-L3937/-- `False : Prop`. -/
38def falseA : ConstantInfo :=
39 .indInfo ⟨falseName, [], prop⟩ {}
, the builderConLeche/Kernel/Basis/Builder.lean:L8-L17 8# A tiny builder for the hand-written raw pins
9
10The pinned basis blocks, the standard-axiom prerequisite families and
11the compiler-trust pins are all *raw* `ConstantInfo`s: exactly what an
12export carries for them, which is exactly the toolchain's own
13`Init.Prelude` declaration — binder names and infos
14are not part of an `Expr` (task #205; `piI`/`lmI` mark where the
15signature says `{…}`, for the reader) — with the recursor-rule firing mode at its parse placeholder
16(`fire := .plain`).
17
). A stream block that carries a pin’s names is checked and stored like any other block, and then compared with the pinConLeche/Kernel/Basis.lean:L144-L151144def basisNamesOk : Declaration → Bool
145 | .indDecl block _ =>
146 match basisNameHit block with
147 | some kind => pinListOk block kind.decls
148 | none => block.all fun c => !reservedBasisNames.contains c.name
149 | .axiomDecl cv => cv.name == quotSoundName || !reservedBasisNames.contains cv.name
150 | .quotDecl _ _ => true
151 | .defnDecl cv .. | .thmDecl cv .. | .opaqueDecl cv .. => !reservedBasisNames.contains cv.name
up to the universe parameters it declares; a block that disagrees, or any other declaration that takes a pinned name, is rejected. A quotient record stores its pin, at the universe parameters it declares, and one that disagrees with the pin is declined. The main theorem names neither False nor Eq: their declarations’ own clauses make them the empty set and equality in every model. The pins let a corollary read those clauses off a stream that declares the names.

Axioms — The fragment has none outside the holes of Section 8, which a solution fills. Checked on its own, the real checker accepts exactly Lean’s three standard axioms: propext and Classical.choice, each pinned to the toolchain’s statementConLeche/Kernel/StdAxioms.lean:L8-L15 8# Recognized standard axioms and their prerequisite shapes
9
10A stream may use the standard axioms `propext` and `Classical.choice`.
11Both are true in the set-theoretic model — `propext` by extensionality
12of propositions (derived through the stored `Iff` recursor),
13`Classical.choice` by global choice (through the stored `Nonempty`
14recursor) — so the checker accepts exactly these two axioms, after
15pinning their types and the *shapes of the inductives they quantify
and each true in the modelConLeche/Model/AxiomMem.lean:L600-L606600theorem choice_mem (mp : EnvModelM V env)
601 {cv : ConstantVal} (hok : ConLeche.stdAxiomOk env cv = true)
602 (hn : cv.name = choiceName)
603 (ψ : Name → Nat) (ta : Term)
604 (hta : denote mp.base2.acval env ψ 0 cv.type = some ta)
605 (ρ : Nat → V) :
606 interp V ρ (.const .choice [ψ uN]) ∈ˢ interp V ρ ta := by
(propext by the extensionality of truth values, choice by choice in the meta-logic), and Quot.sound as part of the pinned Quot block above. Any other axiom record declines the stream, with two tolerated exceptions: a declared but unused sorryAx installs nothing, and Lean’s deprecated compiler-trust axioms are accepted as pinned definitions of their own types.

Opaques — The fragment has definitions and theorems (Section 7), the latter stored as their statements. The real checker never unfolds a theorem or an opaque: only a definition unfoldsConLeche/Rules/Rel.lean:L143-L146143 `lazyDeltaStep`): one definition unfolded
144 at the head. A theorem never unfolds (`unfoldDefinition`). -/
145 | delta {d : Nat} {e e' : Expr} :
146 unfoldDefinition env e = some e' → Red env d e e'
.

Structure η and unit-likeness — The checker has structure ηConLeche/Rules/Rel.lean:L457-L460457 | structEta {d : Nat} {a b tb wtb : Expr} {c : Name} {us : List Level}
458 {cvc : ConstantVal} {cnP cnF : Nat} {cT T : Name} {us' : List Level}
459 {cvT : ConstantVal} {caps : IndCaps} {tbl : ProjTable} :
460 Infer env .io d b tb → Red env d tb wtb →
and unit-likenessConLeche/Rules/Rel.lean:L524524 UnitLike env (d + 1) (body.instantiate1 (.fvar d dom)) →
as Lean has them; Section 6.2 and Section 6.3 derive both from extensionality.

Recursors on stuck proofs of A ∧ B — The checker never unfolds a theorem, while the official kernel does. Some elaborated terms rely on that, with a case split on a stuck proof h of A ∧ B. There the recursor fires on And.intro h.1 h.2ConLeche/Rules/Rel.lean:L298-L322298 /-- **The `And` rescue** (`majorToCtor`'s `And` branch,
299 `Kernel/Core.lean`; `And` only, by ruling): `And.intro a b
300 (.proj And 0 h) (.proj And 1 h)` is fabricated for a stuck proof
301 `h`, certified the K branch's way; the last four premises are the
302 major's half of the `proofIrrel` run, as in the K branch. -/
303 | rescueAnd {d : Nat} {major tm tmaj fab tf tp ttp : Expr} {v : Level} {recName : Name}
304 {cv : ConstantVal} {mI rP : Nat} {isK : Bool} {rl : RecRule} {cvj : ConstantVal}
305 {cnP cnF : Nat} {ust : List Level} {cvT : ConstantVal}
306 {caps : IndCaps} :
307 env.find? recName = some (.recInfo cv mI rP isK [rl]) →
308 env.find? rl.ctor = some (.ctorInfo cvj cnP cnF andName) →
309 env.find? andName = some (.indInfo cvT caps) →
310 Infer env .io d major tm → Red env d tm tmaj →
311 tmaj.getAppFn = .const andName ust →
312 tmaj.getAppArgs.length = cnP →
313 cvj.levelParams.length = ust.length →
314 andRescueSlots env rl.ctor cnP = true →
315 fab = Expr.mkAppN (.const rl.ctor ust)
316 (tmaj.getAppArgs ++ [.proj andName 0 major, .proj andName 1 major]) →
317 fab.wscopedB d = true → fab.looseBVarsBounded 0 = true →
318 fab.fvarLeaves.all (fun l => major.fvarLeaves.contains l) = true →
319 Infer env .io d fab tf → DefEq env d tmaj tf →
320 Infer env .io d major tp → Infer env .io d tp ttp →
321 Red env d ttp (.sort v) → Level.isEquiv v .zero = some true →
322 Red env d major fab
, the constructor applied to h’s two projections, built from h’s type.

Fuel, memo tables, the executable checker and its bridge theorem — In the fragment the relations are the checker. The real checker is a program, connected to the relations by further theorems (Section 9.2).

The parallel check — The foldConLeche/Cached/Decls.lean:L86-L8786/-- **The declaration fold, with or without a solution** (the two checkers below).
87
checks the declarations one by one, each against the environment of those before it. The executable instead builds one index of the whole streamConLeche/Cached/StreamIndex.lean:L6565def buildIndex (ds : Array Declaration) : StreamIndex :=
from the declarations alone and checks them in parallel, each against the index’s view of the declarations before it; every check passing is an accept of the foldConLeche/Verify/Cached/StreamIndex.lean:L527-L531527theorem checkDecls_of_jobs {ds : Array Declaration} {justify : Option Env}
528 (hds : sideRecords justify ds = ds)
529 (h : ∀ k (hk : k < ds.size), recordJob mode pins maxNatSize (solutionOf justify ds)
530 (buildIndex ds).freeze k ds[k] = .ok ()) :
531 checkDeclsWith mode pins maxNatSize ds justify = .ok (streamEnv ds.toList) := by
, which is what the one-declaration-at-a-time argument of §3 and §4 needs.

9.2. How the real proof differs from the fragment

The differences run from the terms outwards: how variables and terms are represented, how the relations are organised, how the executable checker is connected to them, how the main theorem is stated, and what surrounds the declaration fold.

Free variables carry their types. The paper uses named variables and a context. The real checker keeps no context at all. When it opens a binder it substitutes a free variable that carries its own type, fvar idx typeConLeche/Kernel/Expr.lean:L428-L430428inductive Expr where
429 | bvar (i : Nat)
430 | fvar (idx : Nat) (type : Expr)
, identified by the depth at which it was opened; so a variable is never looked up, the relations are indexed by the opening depth in place of a context, and two free variables are compared by depth aloneConLeche/Rules/Rel.lean:L370-L371370 | fvar {d i : Nat} {ty₁ ty₂ : Expr} :
371 DefEq env d (.fvar i ty₁) (.fvar i ty₂)
. Stored types are closed terms, and Expr.eval, the reading the main theorem is stated over (below), reads them with de Bruijn indices under binders, with no opening at all.

An intermediate term language. The real proof does not interpret the checker’s terms directly. It first reads a term into a smaller language, TermConLeche/Term/Syntax.lean:L188-L219188inductive Term where
189 /-- de Bruijn index -/
190 | bvar (i : Nat)
191 /-- `Sort u` at a concrete level -/
192 | sort (u : Nat)
193 /-- a built-in constant at a concrete level instantiation -/
194 | const (c : BConst) (us : List Nat)
195 /-- application -/
196 | app (f a : Term)
197 /-- `fun (_ : ty) => body` -/
198 | lam (ty body : Term)
199 /-- `(_ : ty) → body` -/
200 | pi (ty body : Term)
201 /-- `let _ := val; body`, **without the type**: the body is under one
202 binder, read at the value -/
203 | letE (val body : Term)
204 /-- `@Eq _ lhs rhs`, **without the type**: the interpretation is
205 `⟦eqE a b⟧ = eqv ⟦a⟧ ⟦b⟧`, so soundness never constrains the type,
206 and no definition and no theorem in any tier reads the type, so
207 the constructor does not carry it; a producer that knows the type
208 simply drops it. -/
209 | eqE (lhs rhs : Term)
210 /-- First field of a pair. Carries **only** the subject: the pair's
211 type arguments come from the typing premise `Γ ⊢ p : Σ A B`,
212 not from the term — see the module docstring. Interpreted by
213 `sfst`, i.e. literally `interp`'s clause. -/
214 | fst (e : Term)
215 /-- Second field of a pair; the `fst` twin, interpreted by `ssnd`. -/
216 | snd (e : Term)
217 /-- the canonical (irrelevant) proof of a derivable equation -/
218 | prf
219 deriving Repr, Inhabited
: de Bruijn indices, sorts at concrete numbers (the level valuation already applied), and built-in constants at concrete levels. That reading, denoteConLeche/Verify/Denote.lean:L153-L154153@[expose] def denote (cval : Name → (Name → Nat) → Term) (env : Env)
154 (φ : Name → Nat) : (d : Nat) → Expr → Option Term
, is partial only for syntactic reasons: an unknown constant, a wrong number of levels, or a projection with no table. The interpretation interpConLeche/Semantics/Interp.lean:L134-L145134noncomputable def interp : (Nat → V) → Term → V
135 | ρ, .bvar i => ρ i
136 | _, .sort u => univ u
137 | _, .const c us => bval V c us
138 | ρ, .app f a => SetTheory.app (interp ρ f) (interp ρ a)
139 | ρ, .lam A b => lamV (interp ρ A) fun x => interp (cons x ρ) b
140 | ρ, .pi A B => piV (interp ρ A) fun x => interp (cons x ρ) B
141 | ρ, .letE v b => interp (cons (interp ρ v) ρ) b
142 | ρ, .eqE a b => eqv (interp ρ a) (interp ρ b)
143 | ρ, .fst e => sfst (interp ρ e)
144 | ρ, .snd e => ssnd (interp ρ e)
145 | _, .prf => pt
then maps the term to a set, interpreting each Π-type and lambda-expression from the values, as Section 2.5 does. The paper folds the two steps into one denotation on the terms themselves.

Six relations, and a mode index. Beside reduction, definitional equality and inference the real description has three more: the certification of an argument spine against a binder telescopeConLeche/Rules/Rel.lean:L754-L763754/-- **The full-grade telescope certificate** (`iotaCertsFull`,
755`Kernel/Core.lean`; ι's case 3, task #342 L10): each argument's
756FULL-grade type is definitionally equal to its binder domain, the
757domains instantiated along the spine; no slot is skipped. -/
758inductive CertsF (env : Env) : Nat → Expr → List Expr → Prop where
759 | nil {d : Nat} {T : Expr} : CertsF env d T []
760 | cert {d : Nat} {ty body arg ta : Expr} {rest : List Expr} :
761 Infer env .full d arg ta → DefEq env d ta ty →
762 CertsF env d (body.instantiate1 arg) rest →
763 CertsF env d (.forallE ty body) (arg :: rest)
(the certified case of 𝜄), pairwise definitional equalityConLeche/Rules/Rel.lean:L765-L770765/-- **Pairwise definitional equality** (`defEqList`, `Kernel/Core.lean`). -/
766inductive DefEqList (env : Env) : Nat → List Expr → List Expr → Prop where
767 | nil {d : Nat} : DefEqList env d [] []
768 | cons {d : Nat} {a b : Expr} {as bs : List Expr} :
769 DefEq env d a b → DefEqList env d as bs →
770 DefEqList env d (a :: as) (b :: bs)
, and the congruence of two lambda telescopesConLeche/Rules/Rel.lean:L547-L586547/-- **λ-telescope congruence, typed at the innermost level only**
548(task #349; the fragment's `DefEqLams`). Two λ-telescopes are compared
549level by level: the domains at every level, the opened bodies' FULL-grade
550types only where the comparison stops descending through two λs — where
551the checker's `Expr.binderPair?` fails (`defeqBinders`, `Kernel/Core.lean`).
552
553*Why the outer levels need no type comparison.* The type comparison is
554what makes λ-congruence's claim **unconditional** — `DefEq`'s claim says
555nothing where a side is the point, and two bodies in one type are both
556the point or neither — and an unconditional equality of the bodies at
557every value of the variable is an equality of the λs, with no type at
558all; so the claim propagates outward through any number of levels.
559
560*Unequal depth, and reduction between levels.* The descent continues
561only through two **syntactic** λs (`outer`'s premise is this relation
562itself, which has no reduction rule). Where one body is not a λ — the
563comparison ends in η or any other rule, possibly after δ or whnf steps —
564that level is the innermost one (`inner`), and its bodies' types are
565inferred and compared at the full grade. Syntactically equal λs
566(`refl`) are equal outright. -/
567inductive DefEqLams (env : Env) : Nat → Expr → Expr → Prop where
568 /-- Syntactically equal sides (the checker's `a == b` fast path). -/
569 | refl {d : Nat} {a : Expr} : DefEqLams env d a a
570 /-- The innermost level: domains, bodies opened with the RIGHT
571 domain, and the opened bodies' full-grade types. -/
572 | inner {d : Nat} {ty₁ body₁ ty₂ body₂ t₁ t₂ : Expr} :
573 DefEq env d ty₁ ty₂ →
574 DefEq env (d + 1) (body₁.instantiate1 (.fvar d ty₂))
575 (body₂.instantiate1 (.fvar d ty₂)) →
576 Infer env .full (d + 1) (body₁.instantiate1 (.fvar d ty₂)) t₁ →
577 Infer env .full (d + 1) (body₂.instantiate1 (.fvar d ty₂)) t₂ →
578 DefEq env (d + 1) t₁ t₂ →
579 DefEqLams env d (.lam ty₁ body₁) (.lam ty₂ body₂)
580 /-- An outer level: the domains, and the opened bodies by this
581 relation — no inference, no type comparison. -/
582 | outer {d : Nat} {ty₁ body₁ ty₂ body₂ : Expr} :
583 DefEq env d ty₁ ty₂ →
584 DefEqLams env (d + 1) (body₁.instantiate1 (.fvar d ty₂))
585 (body₂.instantiate1 (.fvar d ty₂)) →
586 DefEqLams env d (.lam ty₁ body₁) (.lam ty₂ body₂)
(Section 2.8). A rule with a premise about a list or a telescope needs a relation of its own in a mutual block; the paper inlines them into the rules that use them. Inference also carries a mode index, for infer_only (Section 2.9), which the fragment states as a relation of its own.

The bridge and the recomposition. Because the real checker is a program, its proof has three parts where the paper has one. The bridgeConLeche/Verify/Rules/Bridge.lean:L29-L3229theorem bridgeAt (env : Env) :
30 ∀ (fuel : Nat) (eager : Bool),
31 WhnfCoreBridge .verified eager env fuel ∧ WhnfBridge .verified eager env fuel ∧
32 DefEqBridge .verified eager env fuel ∧ InferBridge .verified eager env fuel ∧
turns an accepting run at any fuel into a derivation, by one induction on fuel in which each step of the checker lands on one rule. The soundnessConLeche/Model/Rules/Sound.lean:L77-L7877theorem red_sound (hin : RulesInputs V m φ) :
78 ∀ {d : Nat} {e e' : Expr}, Red env d e e' → RedSem m φ d e e'
is the paper’s induction: one structural induction over the six relations, each case a lemma about one rule, never mentioning the implementation. The recompositionConLeche/Model/Rules/Recompose.lean:L50-L5550 {m : EnvModel V env} (h : RulesInputs V m φ) :
51 ∀ fuel : Nat,
52 WhnfCoreClaim m φ fuel ∧ WhnfClaim m φ fuel ∧
53 DefEqClaim m φ fuel ∧ InferClaim m φ fuel ∧
54 InferClaimIO m φ fuel := by
55 have hin : RulesInputs V m φ := h
puts them together, claim by claim. It bridges the run, applies the soundness, and hands the result to the declaration fold.

The statement over Expr.eval. The main theorem is stated over IsModelConLeche/IsModel.lean:L212-L213212def IsModel (V : Type w) [SetTheory V] (model : Name → List Nat → V)
213 (C : ConstantInfo → Prop) : Prop :=
, a notion of model of the input stream itself: a model gives every constant a set at the values of its universe levels, and every constant of every declaration holds in it, each on its own. Its terms are read by Expr.evalConLeche/IsModel.lean:L128-L129128noncomputable def Expr.eval (model : Name → List Nat → V) (φ : LevelParam → Nat) :
129 (BVarIdx → V) → Expr → V
, a total function on the checker’s own terms with one equation per syntax form. A constant is a member of what its type denotes, a definition is what its value denotes, and every recursor rule’s ι equation holds.

The ι equationConLeche/Kernel/Inductives/IotaEq.lean:L119119def iotaEqOf (cv : ConstantVal) (mI rP i : Nat) (rl : RecRule) : Option Expr := do
is read off the recursor’s own type, as a closed Eq between the recursor applied to a constructor and the rule’s right-hand side, and what it denotes is inhabited. The rule’s minor premise gives the fields and the indices, its major premise’s type the constructor’s levels and parameters; no constructor is looked up. The checker accepts a recursor only where this reading is the one through its constructors, up to equivalent levels and the type annotations the official kernel consumes, which mean the identity on a type by their own definitions. So a constant behind an import still means what its declaration says. Nothing is fixed by name: False is empty and Eq is equality because of their declarations’ own clauses, and the checker accepts a stream declaring them only as the prelude does, which the corollaries use.

The proofs’ own model is of the environment the checker builds, read by a relation Denotes; a theoremConLeche/Model/IsModelBridge.lean:L116-L118116theorem eval_of_Denotes {cval : Name → (LevelParam → Nat) → V} {env : Env}
117 (hloc : CvalLocal cval env) {model : Name → List Nat → V} (hag : AgreesOn model cval env)
118 {φ : LevelParam → Nat} {ρ : BVarIdx → V} {e : Expr} {v : V}
says that Expr.eval agrees with it wherever it reads, and the bridgeConLeche/Model/IsModelBridge.lean:L665-L668665theorem isModel_of_agree {R : ConstantInfo → Prop} {env : Env} (m : Model.EnvModelM V env)
666 (hrec : RecordsStored R env) {model : Name → List Nat → V}
667 (hag : AgreesOn model (Model.cvalOf m.base2.acval) env) (heq : EqReads model) :
668 IsModel V model R := by
carries that model to one of the input, and to every model agreeing with it on the stored names. The paper’s theorem has the same shape over the fragment’s terms (Definition 11), with the rules of the fragment’s generated recursors read off their types; its proofs’ model is of the environment too (§3), and the step from one to the other is the proof of Theorem 12.

The cached checker and its simulation. The core the executable runs is a copy of the pure oneConLeche/Cached/CoreC.lean:L8-L11 8# The cached checker core
9
10The core over the computed-field representation: `whnfCore`, `whnf`,
11`infer`, `inferIO` and `defeq`, each memoized in `CState`; a
over a term representation that carries a precomputed hash in every node, with memo tables for reduction, equality and inference. A simulation proofConLeche/Verify/Cached/SimC.lean:L10-L1510# The cached-core faithfulness kit (task #163, batch 5)
11
12The relation and combinators for proving that the cached clone core
13(`ConLeche/Cached/CoreC.lean`) simulates the pure fueled families. The
14cached and pure sides are *the same terms*, so the value relation is
15equality.
shows that every successful run of the cached core is a successful run of the pure fuelled core at some fuel, with the memo tables’ invariant preserved; the main theorem composes it with the fold’s soundnessConLeche/Verify/Cached/MainC.lean:L32-L3532
33/-- **Acceptance**: what the fold accepts carries the model. -/
34theorem checkDecls_sound
35 {ds : Array Declaration} {env' : Env}
.

Modular checking. In the fragment, a module’s context, its imported views, and the module each context name is read from are given, and the local checks of Section 7.6 say what they must satisfy. con-leche states the same checksConLeche/Modular.lean:L213-L231213structure ImportOk (pins : List NatOpPinSet) (dev : Nat → Module) (i : Nat) : Prop where
214 below : ∀ b ∈ (dev i).imports, b < i
215 src_lt : ∀ n, ((dev i).context.find? n).isSome = true → (dev i).src n < i
216 nodup : ((dev i).context.consts.map (·.toConstantVal.name)).Nodup
217 /-- every context record is a presentation of the module its names are read from -/
218 presented : ∀ d ∈ (dev i).ctx, ∀ n ∈ declNames d, d ∈ (dev ((dev i).src n)).iface
219 /-- a context record is read from one module: its names have one source -/
220 one_src : ∀ d ∈ (dev i).ctx, ∀ n ∈ declNames d, ∀ n' ∈ declNames d,
221 (dev i).src n = (dev i).src n'
222 /-- what a context record reads is stored in the context, and agrees with its source's copy -/
223 reads : ∀ d ∈ (dev i).ctx, ∀ n ∈ declNames d, RecordScoped (readsAlike dev i ((dev i).src n)) d
224 /-- a context record reads only itself and the records before it -/
225 ordered : ∀ k (h : k < (dev i).ctx.length),
226 RecordScoped (streamEnv ((dev i).ctx.take (k + 1))) (dev i).ctx[k]
227 /-- the own records, accepted from the context by the pure fold's step -/
228 accepted : ∃ E, PureRun pins (dev i).decls (dev i).context E
229
230/-- **The local checks at module `i`**: its own interface's, and its checks as an importer. A
231development every module of which passes them is the hypothesis of the modular theorem. -/
over its own records. A context there is a list of the records its imports present, in an order in which every record reads only itself and earlier records. con-leche proves the theoremConLeche/Modular/Generic.lean:L278-L279278theorem modular : ∀ k, (∀ i < k, dev.Valid i) →
279 ∃ m : (i : Nat) → i < k → S.Mod (dev.own i), dev.Compatible k m
over the interface of Section 7.1, and its instance for con-leche’s models gives the modular theoremConLeche/Model/Modular/IsModel.lean:L55-L6155theorem modular_isModel (V : Type w) [SetTheory V]
56 (pins : List NatOpPinSet) (dev : Nat → Module) (i : Nat)
57 (hok : ∀ j ≤ i, LocalOk pins dev j) :
58 ∃ model : Nat → Name → List Nat → V,
59 (∀ j ≤ i, IsModel V (model j) (· ∈ constantsOf (dev j).decls)) ∧
60 ∀ j ≤ i, ∀ n, ((dev j).context.find? n).isSome = true →
61 (dev j).src n ≤ i ∧ model j n = model ((dev j).src n) n := by
. The executable computes a module’s context from the .olean files and checks the module’s own records against it, one module per run, and the runs at every module of an import closure together give the local checksConLeche/Verify/Driver/Routes.lean:L346-L347346theorem localOk (j : Nat) : LocalOk pins R.dev j :=
347 R.localOk_of (fun _ hM _ _ hh => R.home_rank hM hh) R.reads_ok j
.

Over the files themselves, the modular theoremConLeche/MainTheorem.lean:L109-L120109theorem main_modular (V : Type w) [SetTheory V] {dirs root : String} {r : Name} {fs : FS}
110 (hr : Olean.parseModName root = some r)
111 (h : ModelIO.CanGive (Driver.runArgs ["--check-graph", "--search-path=" ++ dirs, "--", root])
112 fs 0)
113 (hwork : ∀ m', Olean.HdrClosure (Driver.searchPathOf dirs) fs [r] m' → ∃ root',
114 Olean.parseModName root' = some m' ∧ ModelIO.CanGive
115 (Driver.runArgs ["--olean", "--module", "--search-path=" ++ dirs, "--", root']) fs 0) :
116 ∃ model : Name → (Name → List Nat → V),
117 (∀ m, Olean.InClosure (Driver.searchPathOf dirs) fs #[r] m →
118 IsModel V (model m) (Olean.moduleConstants (Driver.searchPathOf dirs) fs m)) ∧
119 (∀ m n m', Olean.InClosure (Driver.searchPathOf dirs) fs #[r] m →
120 Olean.Sees (Driver.searchPathOf dirs) fs m n m' → model m n = model m' n) :=
gives one model per module of the closure, each a model of its module’s constants as the .olean files hold them, and a name a module sees as another module’s (its header loads a part of that module holding a constant of that name: Sees, over Loads, Lean’s import lattice) has the value that module’s model gives it. A name a module never reads is seen from one module only, because every name two loaded modules store is read into the context and checked there: two copies of one name with different statements would make this agreement false. The fragment’s Theorem 22 is the same statement, with seeing read off the imported views. A module’s model has no constant of type False where the module declares the prelude’s False or sees it as a module that does, since False then denotes the empty set.

The frontend. Between the export file and the declaration fold sit a decoder and one transformation of the decoded list, preparePreludeConLeche/Frontend/Prepare.lean:L173-L174173def preparePrelude (pre : PreludeIx) (ds : Array Declaration) : Array Declaration :=
174 (prepareD pre ds).decls
. It moves the declarations of a built-in copy of the toolchain’s prelude (Eq, Nat, Bool and their kin) to the front, the stream’s own record where it has one and the copy’s where it has none, and it moves the structural Nat operations that a pinned Nat operation is defined from ahead of it. A theorem states that it does nothing elseConLeche/Verify/Frontend/Prepare.lean:L174-L175174theorem preparePrelude_perm (pre : PreludeIx) (ds : Array Declaration) :
175 ∃ extra : List Declaration, (∀ d ∈ extra, d ∈ pre.decls.toList) ∧
: the fold’s input is a permutation of the decoded list plus records of the built-in prelude, and nothing is rewritten or generated. No theorem relates the decoded list to the meaning of the export file: that the decoder preserves meaning is established by review, not by proof. The fragment has no frontend: its stream is its environment.

10. Related work

This section compares our proof with a small selection of the most closely related work.

Carneiro, “The Type Theory of Lean”. The thesis [1] presents Lean’s type theory in full by a typing judgement, studies its metatheory, and builds a set-theoretic model, from which Lean’s consistency follows relative to ZFC together with, for each 𝑛, the existence of 𝑛 inaccessible cardinals. It is the starting point of our model, whose interpretation follows the thesis’s. A proof is one point, a proposition ∀𝑥:𝛼.𝛽 is the intersection of its fibres with the singleton of that point (our propositional function space Π0, Section 2.5), and a ∀ into a higher universe is the full dependent function space. To decide which reading applies, the thesis first translates every well-typed term into a language in which the propositional and the non-propositional ∀ and lambda are separate constructs, using the sort of each body, which is well defined given the thesis’s unique typing theorem. Our interpretation reads the choice off the values instead (Section 2.5): a function space is a proposition when all its fibres are truth values. So it consults no typing information, and our proof does not need unique typing. The thesis models a fixed basis of eight inductive types, the W-type among them, to which it reduces the others (parts of the reduction left as future work); here every inductive block the checker accepts is interpreted by its own least fixed point (Section 4.2). The statements also differ in form. There, each derivation of a formal typing judgement is sound in the model once a number of inaccessible cardinals depending on the derivation is assumed; here the theorem is about the verdicts of the checker’s own rules, and assumes the whole chain of universes 𝒰︀0,𝒰︀1,… at once (Section 2.4).

Lean4Lean. Lean4Lean [2] is a checker for Lean 4 written in Lean, closely following the official kernel and able to check all of Mathlib. The paper also formalises a typing judgement, a slight variation of the thesis’s, and proves the main body of the checker correct against it: an equality test that answers yes yields a definitional equality of the judgement, an inferred type a typing; inductive types and additions to the environment are listed as unfinished. The paper notes that this correctness proof needs, in some form, unique typing and the inversion of definitional equality on sorts and ∀-types for its judgement. Our proof relates the checker’s verdicts to the model directly, with no typing judgement in between, and uses no such property (Section 2.7). The Lean development lean4lean-model [3], built on Lean4Lean’s judgement, states as its target theorem the consistency of that judgement assuming 𝜔 inaccessible cardinals, a proof still to be supplied at the time of writing; the set theory con-leche assumes follows from that hypothesisbridge/lean4lean-model/ConLecheBridge/Carneiro.lean:L200-L202200theorem carneiro_implies_conleche :
201 OmegaInaccessibles.{u} → Nonempty (Σ V : Type (u + 1), ConLeche.SetTheory V) :=
202 fun h => ⟨⟨ZFSet.{u}, setTheoryOfCarneiro h⟩⟩
.

Werner, “Sets in types, types in sets”. Werner [4] interprets the Calculus of Inductive Constructions in ZFC with an increasing sequence of inaccessible cardinals, one for each universe, and conversely encodes ZFC in the type theory, so that the two hierarchies interleave in strength. The interpretation is proof irrelevant: a proposition denotes 0 or 1={0}, a proof denotes 0, a ∀ into propositions denotes 1 exactly when every fibre does, and a function type of the predicative levels denotes the full set of set-theoretic functions. These are the two readings of a ∀ in Section 2.5. It is defined on a term in its context, by structural induction on the term, and partially: whether the clause for proofs or for propositions applies to a term is a matter of its type. It is shown defined and sound on every derivable judgement by induction on the derivation, and the case of the conversion rule uses subject reduction and confluence of reduction. Our interpretation is total and term-directed, reads the choice off the values, and Theorem 2 is an induction over the checker’s three relations that uses neither. Werner interprets an inductive type of a universe as the least fixed point, in that universe, of the monotone operator that strict positivity provides, and his calculus has no inductive propositions; here proposition-valued families are least fixed points too, in 𝒰︀0 (Section 4.2).

Barras, “Sets in Coq, Coq in Sets”. Barras [5] axiomatises intuitionistic ZF, possibly with inaccessible cardinals, inside Coq, develops functions, ordinals and fixpoint theory over the axioms, and proves set-theoretic models of the Calculus of Constructions sound, as well as its extension with a hierarchy of universes (interpreted by Grothendieck universes) and an extension with the natural numbers. The set theory is given by axioms, as ours is (Section 2.4). Π-types are interpreted by one clause: with Aczel’s encoding of a function as the set of pairs (𝑥,𝑦) with 𝑦 in its value at 𝑥, a function into propositions collapses to a proposition, so the interpretation, like ours, consults no typing information. In our set theory a graph is never the point (Section 2.4), so that a graph determines its domain; the two readings of a ∀ or a lambda are then different sets, and the values choose between them (Section 2.5). Soundness there is stated for semantic judgements Γ⊨𝑀:𝑇 and Γ⊨𝑀=𝑀′ over valuations, close to our three claims, and the typing derivations of the calculus, in a presentation with judgemental equality, are shown to imply them; our claims are proved of the checker’s verdicts instead. Barras observes that set-theoretic 𝛽 holds only for arguments in the function’s domain, so his semantic 𝛽 rule has a typing premise; in our proof 𝛽 has no premise, because the reduction claim is asked only of a redex that is not the point, whose function is then a graph that determines its domain (Lemma 1).

Dybjer, “Inductive families”. Dybjer [6] gives a general scheme for inductive definitions of families of sets in Martin-Löf’s type theory: formal criteria for the formation and introduction rules of a new set former (parameters, indices, non-recursive premises and recursive premises), and an inversion principle that derives the elimination and equality rules from them. A recursive premise may be a function over a sequence of types that does not mention the set former being defined (strictly positive, generalised induction). Our blocks follow this scheme (Section 4.1): ordinary fields are his non-recursive premises, reflexive fields his recursive premises with the field’s telescope as that sequence, and recursive fields the case of an empty one. His order, non-recursive premises before recursive ones, appears here as the condition that nothing after a reflexive field depends on its value. The recursor’s type and its 𝜄 laws are generated from the constructors as his elimination and equality rules are. In our proof they are statements about the model, where the recursor’s set is constructed and the 𝜄 law proved (Theorem 10). Proposition-valued families, and the subsingleton criterion for their large elimination, belong to the impredicative setting, which his scheme, for a predicative theory, does not have.

Abbott, Altenkirch and Ghani, “Containers”. Abbott, Altenkirch and Ghani [7] represent strictly positive types as containers: a set of shapes and, for each shape, a set of positions, an element being a shape with an element of the argument at each of its positions. They show that nested strictly positive inductive and coinductive types exist in any Martin-Löf category (locally cartesian closed, with disjoint coproducts and W-types) by representing them as containers and constructing them from W-types. In these terms an element’s support (Section 4.2) is the set of its positions with the occurrences that fill them, and the bound 𝐴 is one set that holds the positions of every shape. Our proof represents no operator as a container: the support and the bound are read off the block’s fields, and a nested occurrence is handled by checking the container’s own constructors at the given instantiation (Section 5.2) rather than by composing containers. Coinductive types are outside our proof, and indexed families outside the paper’s containers.

Traytel, Popescu and Blanchette, “Foundational, compositional (co)datatypes for higher-order logic”. Traytel, Popescu and Blanchette [8] build datatypes and codatatypes in Isabelle/HOL, with mutual and nested recursion and corecursion, from bounded natural functors: type constructors equipped with a map function, set functions returning the elements an argument holds, and an infinite cardinal bounding those sets, subject to conditions including naturality and the bound. The class of these functors is closed under composition, initial algebras and final coalgebras, so a datatype nested through list uses the fact, proved once, that list is a bounded natural functor; it includes non-free type constructors such as finite sets. The bound is what lets the initial algebra be constructed inside HOL. Our proof uses no map function and records nothing per type former: the operator’s accessibility, a support bound in the same role, is read off the checker’s positivity check for each block, and a container’s positivity in its parameter is decided at each instantiation by walking its constructors (Section 5.2), never stored. Coverage differs as well: their framework has codatatypes and nesting through non-free type constructors; ours has indexed, universe-polymorphic families and proposition-valued ones, and no codatatypes.

Aczel, “An introduction to inductive definitions”. Aczel’s chapter [9] treats inductive definitions by rule sets and by monotone operators on the subsets of a set: the set inductively defined is the least set closed under the rules, which is the least fixed point of the operator and is reached by iterating it. It calls an operator 𝜅-based when every element it produces from a set 𝑋 it already produces from a subset of 𝑋 of cardinality less than 𝜅 (as when every rule has fewer than 𝜅 premises), and shows that for regular 𝜅 such an operator’s iteration closes by stage 𝜅. Accessibility (Section 4.2) is this idea of rules with a bound on their premises, the bound being a set 𝐴 indexing the support rather than a cardinal. What is specific to our proof is where the bound comes from. It is read off the checker’s positivity check for each block, with one occurrence per reflexive field and tuple of its telescope, and, for a nested block, at each instantiation of a container (Section 5.2).

References

  • [1] M. Carneiro, “The Type Theory of Lean,” Master's thesis, Carnegie Mellon University, 2019. [Online]. Available: https://github.com/digama0/lean-type-theory/releases/tag/v1.0
  • [2] M. Carneiro, “Lean4Lean: Verifying a Typechecker for Lean, in Lean,” in 31st International Conference on Types for Proofs and Programs (TYPES 2025), in Leibniz International Proceedings in Informatics (LIPIcs), vol. 384. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2026, p. 2:1–2:23. doi: 10.4230/LIPIcs.TYPES.2025.2.
  • [3] M. Carneiro, “lean4lean-model.” [Online]. Available: https://github.com/digama0/lean4lean-model
  • [4] B. Werner, “Sets in Types, Types in Sets,” in Theoretical Aspects of Computer Software (TACS '97), in Lecture Notes in Computer Science, vol. 1281. Springer, 1997, pp. 530–546. doi: 10.1007/BFb0014566.
  • [5] B. Barras, “Sets in Coq, Coq in Sets,” Journal of Formalized Reasoning, vol. 3, no. 1, pp. 29–48, 2010, doi: 10.6092/issn.1972-5787/1695.
  • [6] P. Dybjer, “Inductive Families,” Formal Aspects of Computing, vol. 6, no. 4, pp. 440–465, 1994, doi: 10.1007/BF01211308.
  • [7] M. Abbott, T. Altenkirch, and N. Ghani, “Containers: Constructing Strictly Positive Types,” Theoretical Computer Science, vol. 342, no. 1, pp. 3–27, 2005, doi: 10.1016/j.tcs.2005.06.002.
  • [8] D. Traytel, A. Popescu, and J. C. Blanchette, “Foundational, Compositional (Co)datatypes for Higher-Order Logic: Category Theory Applied to Theorem Proving,” in 27th Annual IEEE Symposium on Logic in Computer Science (LICS 2012), IEEE, 2012, pp. 596–605. doi: 10.1109/LICS.2012.75.
  • [9] P. Aczel, “An Introduction to Inductive Definitions,” in Handbook of Mathematical Logic, J. Barwise, Ed., North-Holland, 1977, pp. 739–782. doi: 10.1016/S0049-237X(08)71120-0.