Path: blob/main/course-contents/notes-formal-01.md
908 views
------\newcommand{\type}{\ \text{type}}
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[@avigadTheoremProvingLean] 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 [@rijkeIntroductionHomotopyType]; 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 [@rijkeIntroductionHomotopyType].
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: Above the horizontal line is a finite list of judgments for the premises, and below the horizontal line is a single judgment for the conclusion.
When we later introduce function types, we'll see the following inference rule appear:
This means: "in a context (more on the notion of context below!) given an element [^1] of type and a function , we obtain an element of type ."
[^1]: Rijke reads "" as " is an element of type ". Some other authors read this as " is a term of type ."
Here the judgments include and .
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 where is the context and is the judgment thesis. It remains to explain the context .
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 , so long as no variable is declared more than once.
Examples : - the empty context has length 0 and declares no variables. Examples of well-formed types in an empty context include the natural numbers ℕ.
Type families
Definition : Consider a type in context . A family of types over in context is a type in context .
Examples:
Vec ℤ nis a type indexed by .For ,
x = ais 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 . An example of a section is the term where and for ,
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 .
ParseError: KaTeX parse error: Undefined control sequence: \type at position 30: …x:A \vdash B(x)\̲t̲y̲p̲e̲}{\Gamma \vdash…ParseError: KaTeX parse error: Undefined control sequence: \type at position 25: …amma \vdash a:A\̲t̲y̲p̲e̲}{\Gamma \vdash…Judgmental equality is an equivalence relation
We have to require this for types: ParseError: KaTeX parse error: Undefined control sequence: \type at position 24: …Gamma \vdash A \̲t̲y̲p̲e̲}{\Gamma\vdash …
and for terms:
variable conversion rules
One example of such a rule is:
ParseError: KaTeX parse error: Undefined control sequence: \type at position 54: …ash A \doteq A'\̲t̲y̲p̲e̲ ̲\quad …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 then
substitution
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
ParseError: KaTeX parse error: Undefined control sequence: \type at position 54: …n:B_n \vdash C \̲t̲y̲p̲e̲and a term , we can substitute to obtain the judgment ParseError: KaTeX parse error: Undefined control sequence: \type at position 55: … \vdash C[a/x] \̲t̲y̲p̲e̲
Note 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 .
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 have
ParseError: KaTeX parse error: Undefined control sequence: \type at position 24: …Gamma \vdash A \̲t̲y̲p̲e̲ ̲\quad \Gamma,\D…The 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 ParseError: KaTeX parse error: Undefined control sequence: \type at position 24: …Gamma \vdash A \̲t̲y̲p̲e̲ ̲\quad \Gamm… 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. ParseError: KaTeX parse error: Undefined control sequence: \type at position 17: …dfrac{\Gamma:A \̲t̲y̲p̲e̲}{\Gamma,x:A \v…
Bibliography
::: {.refs} :::