Parallel to the course discussions of Lean usage, I want to give at least a bit of a description of the underlying dependent type theory.
I’m going to follow the first chapter of Egbert Rijke’s new text Homotopy Type Theory [arXiv: Homotopy Type Theory] – (though for now I ignore the potential homotopy in the type theory.)
The second section of Theorem Proving in
Lean
vi(Avigad et al. 2024)
is also
good - and Lean
specific! - but still comes across (to me) as more
of a guide to using Lean than an introduction to type theory (this is
not a criticism, of course!)
All of this really does bump up against an important pedagogical
question: how much type theory does one really need to know in order
to use Lean
to formalize mathematics?
I’m sure I don’t know the answer! In the limited time in this third-of-a-course, I’m hoping to say a little about “using Lean” as well as a little about the type theory than enables it.
Martin-Löf’s Type Theory
I’m mostly viewing these notes as a quick exposition of the first chapter of Rijke’s text (Rijke 2024); probably you should just read the text! But maybe these notes will encourage you to do so… At any rate, quotes below are taken from (Rijke 2024).
To the newcomer, one of the main questions one probably faces in this subject is: “what are the differences between type theory and the usual description of math via set theory?” The introduction to Rijke’s chapter tells us that in type theory:
- every element comes equipped with its type
- set theory is axiomatized in the formal system of first-order logic, while type theory is its own formal system.
“the expression
is not considered a proposition - i.e. something which one can assert about an arbitrary element and an arbitrary type – but is considered to be a judgment … that is part of the construction of the element .”
there is a greater emphasis in type theory on equality of elements than in set theory.
Unlike in set theory, where equality is a decidable proposition of first-order logic, the type
of identifications of two elements is itself a type.
By way of a general description, we have:
Dependent type theory is a system of inference rules that can be combined to make derivations … the goal is often to construct an element of a certain type.
Judgments and contexts in type theory
In type theory, an inference rule is represented symbolically as
follows:
When we later introduce function types, we’ll see the following inference rule appear:
This means: “in a context
Here the judgments include
In fact, there are just four sorts of judgments in Martin-Löf’s dependent type theory:
judgment that
is a well-formed type in context :judgment that
and are judgmentally equal (or definitionally equal) in context :judgment that
is an element of type in context :judgment that
and are judgmentally equal elements of type
Notice that any judgment has the form
The role of the context is to declare what hypothetical elements (variables) are assumed.
- Definition
-
A context is a finite list of variable declarations
such that for we can derive the judgment using inference rules of type theory.
Of course, in a context we may use other variable names than
- Examples
-
the empty context has length 0 and declares no variables. Examples of well-formed types in an empty context include the natural numbers ℕ.
a context of length 1 has the form
where is a well-formed type in the empty context.The type
Vec ℤ n
of vectors of integers of lengthn:ℕ
is a type in context . e.g. we have[8,22,-17] : Vec ℤ 3
For any type
in the empty context, and any term , the equality type is a type in context .(for a term
, the type has the termrefl:
if and are judgmentally equal; i.e. we have the judgment )a context of length 2 has the form
and we will explain what is meant by the notation in the next section on type families.
Type families
- Definition
-
Consider a type
in context . A family of types over in context is a type in context .In other words, we have the judgment
Terminology: we say that
is a family of types over in context , or that is a type indexed by .
Examples:
Vec ℤ n
is a type indexed by .For
,x = a
is a typed indexed by . More precisely, we have the inference rule
- Definition
-
Consider a family of type
over in context . A section of over in context is an element of type in context ; i.e. the judgment
For example, consider the type Vec ℤ n
indexed by
Inference Rules
Here are the inference rules “underlying” dependent type theory.
Rules for formation of contexts, types and elements
The following rules amount to “presuppositions”; for example, If we have the judgment that
is a well-formed type in context , then is already a well-formed type in context .Judgmental equality is an equivalence relation
We have to require this for types:
and for terms:
variable conversion rules
One example of such a rule is:
thus if
is a variable of type and if (in the given context), then we can replace by when describing families of types.Note that writing
just emphasizes the dependence on ; of course, depends on the whole context .We must give rules like
not only for judgments of well-formed types, but of judgments for type-equality, for elements, and for element-equality. We write for a generic judgment thesis; the general form of the variable conversion rule is thensubstitution
Consider a section
indexed by in context and suppose give .We can simultaneously substitute
for all occurrences of in and to obtain a new element .Somewhat more precisely, consider the following. Given the judgment
and a term , we can substitute to obtain the judgmentNote that in this latter judgment, the variables
are assigned new types after substitution.Similarly, given
as in , from a term , we obtain a new term .For a generic judgment
, we have the substitution rule- Definition
-
When
is a family of types over in context and when , we refer to the type as the fiber of at . It is often written .Similarly, given a section
of , we write for .
weakening
Given a type
in context , any judgment made in a longer context can be made in the context for a new variable . The weakening rule says that well-formed-ness and judgmental equality of types and elements are preserved by this operation: for a generic judgement we haveThe process of expanding the context by
is called weakening (by ).- Example
-
If we have two types
in context , then we can weaken by to obtain The type in context is called the constant (or trivial) family .
the generic element
The last general inference rule concerns the so-called generic element of a type family. Given a type
in context , we can weaken by itself to obtain that is a type in context . The rule then stipulates that the variable may be viewed as an element of in this context; i.e.
Bibliography
Rijke reads “
” as “ is an element of type ”. Some other authors read this as “ is a term of type .”↩︎