Expand description
R2 — auto-derived recursors (dependent eliminators) for inductive types.
Today a user who declares an inductive must hand-write the match/fix to recurse
over it. Lean/Coq instead AUTO-GENERATE the recursor I.rec (the dependent
eliminator) from the declaration, so “declare ℕ, get induction for free.” This
module is that derivation: from an inductive’s registered constructors it synthesizes
I_rec : Π(P : I → Type). minor₀ → … → minorₖ → Π(x : I). P x
I_rec := λP. λf₀ … λfₖ. fix rec. λx. match x return (λx. P x) with
| Cᵢ a… => fᵢ a… (rec aⱼ)… -- one rec-call per recursive argumentwhere each minor premise is Π(args). Π(IH : P aⱼ for each recursive arg). P (Cᵢ args).
The synthesized term is an ordinary kernel Term, so it is re-checked by infer_type
for coverage + termination — and (the point of building it now) independently
re-derived by the recheck second kernel. A Prop motive may be
passed wherever the Type motive is expected, by cumulativity (Prop ≤ Type 0), so
the single derived recursor serves BOTH computation and induction.
Scope: parametric AND indexed inductive families. Beyond the uniform PARAMETERS of a
type like List A, an indexed family has INDICES that vary per constructor — Eq A x : A → Prop with refl : Eq A x x. Their eliminator’s motive abstracts over the indices,
so derive_recursor("Eq") synthesizes FULL Paulin-Mohring J:
Π(A). Π(x:A). Π(P : Π(y:A). Eq A x y → Sort). P x (refl A x) → Π(y). Π(h:Eq A x y). P y h
— the identity eliminator as a kernel-checked term, not an axiom.
Structs§
- Derived
Aux - One derived auxiliary: the name Lean gives it, the type the kernel certified for it, and the term it certified.
Functions§
- derive_
auxiliaries - Everything the declaration of
indshould bring with it, in DEPENDENCY ORDER, for a caller to register verbatim: - derive_
below I_below : Π(A…). Π(motive : I A… → Type 0). I A… → Type 0- derive_
brec_ on I_brecOn : Π(A…). Π(motive : I A… → Type 0). Π(t : I A…). Π(F : Π(s). I_below A… motive s → motive s). motive t- derive_
cases_ on I_casesOn—recOnwith the INDUCTION HYPOTHESES dropped from every minor premise.- derive_
ctor_ inj C_inj : Π(A…). Π(x⃗). Π(y⃗). Eq (I A…) (C A… x⃗) (C A… y⃗) → (x₀ = y₀ ∧ … ∧ x_{m-1} = y_{m-1})- derive_
dec_ eq decEqI : Π(A…). Π(dA_i : Π(u v : A_i). Decidable (Eq A_i u v))…. Π(a b : I A…). Decidable (Eq (I A…) a b)- derive_
no_ confusion I_noConfusion : Π(A…). Π(P : Type 0). Π(a b : I A…). Eq (I A…) a b → I_noConfusionType A… P a b- derive_
no_ confusion_ type I_noConfusionType : Π(A…). Π(P : Type 0). I A… → I A… → Type 0- derive_
quot_ rec Quot_rec— the DEPENDENT quotient eliminator, built from the four quotient primitives rather than taken as a fifth one. The prelude registers exactly this body asQuot_rec.- derive_
rec_ on I_recOn— the eliminator with the MAJOR PREMISE moved in front of the minors, which is the argument orderinduction/matchelaboration wants and the one every Lean development writes by hand.- derive_
recursor - Build
I_rec’s term and type for the inductiveind. Returns(recursor_type, recursor_term)whererecursor_typeis exactlyinfer_type(recursor_term)— so the type is, by construction, the one the kernel certifies the term against. - derive_
recursor_ universe_ poly - Build
I_rec.{u}— the UNIVERSE-POLYMORPHIC eliminator,Π(P : I → Sort u). … → Π(x). P xwithuan explicit level PARAMETER. Returns(level_params, recursor_type, recursor_term).