Inductive Types #
We see more precisely what are valid (and not valid) definitions for inductive types. We will also see the weak and strong generalizations: parametric inductive types and indexed inductive types.
We have constructed a few examples. We first see some more from Lean core.
In general, the construtors let us construct terms of the inductive type being introduced using terms of that type.
#check Nat.zero -- ℕ #check Nat.succ -- ℕ → ℕ
Two more inductive types:
Disallowed types #
- constructors should have resulting type the inductive type being introduced.
The above is disallowed because with a construction of the above form, we would have an injection (in this case a biection) from the power set on the Cantor set to itself.
If we had such an inductive type, we could define
diag (x :Cantor): Bool := match x with | Cantor.mk f => ¬ f x
Apply this to
x:= Cantor.mk diag to get
diag (Cantor.mk diag) = ¬ diag (Cantor.mk diag)
A non-trivial positive occurence, which is hence allowed, is in the following binary tree.
Parametrized inductive types #
Here we define a family of inductive types. However each member of the family is "separately defined", i.e., all constructors only involve that parameter.
Indexed inductive type #
αwill be a parameter.
nwill be an index.
Sometimes types include conditions
Conditions can be given by a subtype of the type.
When an (indexed) inductive type is introduced,
- the type (or family of types) is defined.
- the constructors are defined.
- a recursor is defined.
- a rule for simplification of applications of the recursor is introduced.
The recursor can be conveniently used by pattern matching.