Skip to main content

Module recursor

Module recursor 

Source
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 argument

where 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§

DerivedAux
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 ind should 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 — recOn with 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 as Quot_rec.
derive_rec_on
I_recOn — the eliminator with the MAJOR PREMISE moved in front of the minors, which is the argument order induction/match elaboration wants and the one every Lean development writes by hand.
derive_recursor
Build I_rec’s term and type for the inductive ind. Returns (recursor_type, recursor_term) where recursor_type is exactly infer_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 x with u an explicit level PARAMETER. Returns (level_params, recursor_type, recursor_term).