Zulip Chat Archive
Stream: new members
Topic: Primitive built-ins
Lauri Oksanen (May 02 2025 at 04:14):
Can I find somewhere a list of primitives that are not constructed using inductive types or other means? I would like to have this on an informal level. Something like
- Universes (
Sort u) - Function types (
→) - Lambda abstraction (
λ x ↦ ...) - Inductive type mechanism (
inductive)
Eric Wieser (May 02 2025 at 04:17):
Does the list of constructors for docs#Lean.Expr help? That covers your first three items, and I think after that only inductive types and Quot are the remaining primitives
Niels Voss (May 02 2025 at 05:44):
In that list, note that .mvar and .fvar only exists for terms that are currently being constructed, once a proof is finished it won't contain any .mvar or .fvar expressions. Also, .mdata, .lit, and .proj aren't really that important.
So, if you just care about what Lean's expressions are made of, all that's left is
- Universes (
Sort u) - Dependent function types, aka forall types, aka pi types. Function types (
→) are a special case - Function application (i.e. if
fis a function andxis a term thenf xis a term) - Lambda abstractions
- References to the variables bound by lambda abstractions (these use de Bruijn indices)
- References to constants, i.e. terms previously defined with
def,theorem,inductive,structure,axiom, etc. - Let expressions (i.e.
let x := a; b)
Lauri Oksanen (May 02 2025 at 06:00):
Thanks a lot!
A slightly tangential follow-up question: I am thinking theorem as a special case of def, and structure as a special case of inductive. Is there any reason not to?
Louis Cabarion (May 02 2025 at 06:34):
Structures are a special case of inductive types, distinguished by having exactly one constructor.
Robin Arnez (May 02 2025 at 12:34):
theorem is basically a def and structure and inductive, yes. But you could still argue that non-recursive inductive types with exactly one are actually special cased in that they have the eta rule:
inductive Example where
| mk (a : Nat) (b : Int)
example (x : Example) : ⟨x.1, x.2⟩ = x := rfl
Because of this the recursor can also be reduced:
Example.rec mk t ≡ Example.rec mk ⟨t.1, t.2⟩ ≡ mk t.1 t.2
In this sense you can also think of projections to be the primitive instead of the recursor for "structure" inductives.
Robin Arnez (May 02 2025 at 12:56):
So these are all builtins:
- Universes (
Sort u : Sort (u + 1)) - Pi types (
(a : α) → β(a) : Sort (imax u v)forα : Sort uandβ(a) : Sort v) - Function application (
f x : β(a)forf : (a : α) → β(a)andx : α) - Lambda abstractions (
fun x : α => f(x) : (a : α) → β(a)forf(x) : β(x)) - Let expressions (
let x : α := a; b(x) : βforb(a) : β) (optional because equivalent to substitution) - References to bound variables from
lets and lambda abstractions and pi types - Inductive types (e.g.
Nat : Sort (0 + 1)) - Constructors of inductive types (e.g.
Nat.zero : Nat/Nat.succ : Nat → Nat) - Projections for non-recursive inductive types with one constructor (e.g.
x.1 : αforx : Prod α β) - Recursors of other inductive types (e.g.
Nat.rec.{u} : {motive : Nat → Sort u} → motive Nat.zero → ((n : Nat) → motive n → motive (Nat.succ n)) → (n : Nat) → motive n) - Definitions (e.g.
Nat.add : Nat → Nat → Nat) (optional because equivalent to substitution) - Quotient primitives (
Quot.{u} : {α : Sort u} → (α → α → Sort 0) → Sort u,Quot.mk.{u} : {α : Sort u} → (r : α → α → Sort 0) → α → Quot r,Quot.ind.{u} : {α : Sort u} → {r : α → α → Sort 0} → {β : Quot r → Sort 0} → ((a : α) → β (Quot.mk r a)) → (q : Quot r) → β q,Quot.lift.{u, v} : {α : Sort u} → {r : α → α → Sort 0} → {β : Sort v} → (f : α → β) → ((a : α) → (b : α) → r a b → Eq (f a) (f b)) → Quot r → β) - Axioms (e.g.
propext : {p : Sort 0} → {q : Sort 0} → Iff p q → Eq p q)
And then Prop ≡ Sort 0, Type u ≡ Sort (u + 1), "theorem ≡ def", "structure ≡ inductive" and so on
Lauri Oksanen (May 03 2025 at 02:24):
Thanks a lot! This is very helpful. I would have two questions.
- When you say "optional because equivalent to substitution" what do you mean more precisely?
- Dependent Type Theory section of Theorem Proving in Lean 4 mentions dependent function types and dependent Cartesian product types (or sigma types). What is the relation between these and Pi types?
Aaron Liu (May 03 2025 at 02:32):
Lauri Oksanen said:
- Dependent Type Theory section of Theorem Proving in Lean 4 mentions dependent function types and dependent Cartesian product types (or sigma types). What is the relation between these and Pi types?
In Lean, Pi types are a built-in primitive, and Sigma types (docs#Sigma) are an inductive. "dependent function type" is another name for Pi type.
Last updated: Dec 20 2025 at 21:32 UTC