Lecture. Dependent types I [01CO]
- August 11, 2025
- Jon Sterling
We aim to get familiar with the basic structure of dependent types. We will not treat dependent type theory as a formal system, but instead as a system of notations for a particular style of informal mathematics built up from a few basic forms of judgement.
Forms of judgement describe kinds of construction [01CP]
- August 11, 2025
- Jon Sterling
In a programming language like OCaml or Haskell, there are places in the grammar where you need to place a type, and there are other places where you need to place an element of a particular type. For example, when you write
let square : int -> int = fun x -> x * xin OCaml, you are asserting two things:
- You are asserting that the code
int -> intdescribes a type. A theoretician might write this as \mathsf {int}\to \mathsf {int}~\mathit {type}. - Moreover, you are asserting that the code
fun x -> x * xdescribes an element of the type described byint -> int. A theoretician might write this as \lambda x\mathpunct {.}x*x:\mathsf {int}\to \mathsf {int}.
The second assertion only makes sense when the first assertion obtains. Indeed, if I had changed int -> int to a bogus piece of code that does not describe a type, then it would not be meaningful to ask whether some other code describes an “element” of this non-type! That’s because only types can have elements.
Per Martin-Löf came up with some terminology that keeps all of this straight. Inspired by him, we define the following:
Informal definition Judgements and their assertion [01CQ]
- August 11, 2025
- Jon Sterling
A judgement is a specific thing that you can assert. For example “int -> int describes a type” is a judgement in OCaml.
Informal definition Forms of judgement [01CR]
- August 11, 2025
- Jon Sterling
A form of judgement is the general concept of which a specific judgement is an instance. For example, “describing a type” is a form of judgement whose instances include \mathsf {int}\to \mathsf {int}~\mathit {type} and \mathsf {int}~\mathit {type}, and many more. Theoreticians will write “A~\mathit {type}” to indicate the form of judgement, where A is understood schematically.
Informal definition Presuppositions [01CS]
- August 11, 2025
- Jon Sterling
Sometimes a form of judgement involves a parameter that is described by a different judgement; the latter is called its presupposition (of which there can be several). For example, the form of judgement for describing elements of a given type presupposes the given type. A theoretician may say something like “The form of judgement ‘a:A’ presupposes ‘A~\mathit {type}’.”.
Formal vs. informal mathematics [01CT]
- August 11, 2025
- Jon Sterling
In a formal language like OCaml or Java, the forms of judgement concern the description of various entities by means of code. The same holds for dependently typed systems like Agda, Lean, and Rocq. It is important to distinguish the code from the thing that it describes; to put it crudely, code is text whereas a function is a process that exists in the intellect of a human being.
Everyday mathematicians describe and communicate about mathematical objects not usually in terms of code in a formal language, but rather using an everyday language (like English or French or Chinese). Unlike with code, this kind of informal communication is not automatically precise or unambiguous; instead, mathematicians use empathy (their awareness of a conversation partner’s point of view or shared frame of reference) to tailor their description of ideas that so that they may successfully denote a definite entity in the shared intellectual context of the conversation.
The same ideas of mathematical judgement that we encountered above in the formal context also apply in the world of informal mathematics. In the formal setting, it is usually a computer who evaluates a claim like “fun x -> x * x describes an element of int -> int” by first checking that int -> int describes a definite type and then checking that fun x -> x * x describes an element of that type. In an informal mathematical interaction, code is replaced by speech or conventional written mathematical notations, and it is the human participants who are carrying out the denoted processes collectively—only proceeding forward after everyone has been convinced that they have described by means of these assertions a definite and agreed-upon entity.
Some of you may be more comfortable with code, and others may be more comfortable with informal mathematics. It will be OK for you to come from whichever perspective you prefer, keeping in mind the common principles that underlie both kinds of mathematical reasoning.
Judgemental structure of dependent types [01CV]
- August 11, 2025
- Jon Sterling
Dependent type theory has two main forms of judgement: describing types and describing elements of a given type.
Form of judgement Describing a type [01CW]
- August 11, 2025
- Jon Sterling
We will write A~\mathit {type} for the judgement that A describes a type.
When we have assumed or presupposed A~\mathit {type}, we will also write A for the type so-described, so we may avoid the wordy phrase “the type described by A”.
Form of judgement Describing an element of a type [01CX]
- August 11, 2025
- Jon Sterling
Presupposing A~\mathit {type}, we will write u:A for the judgement that u describes an element of the type A.
Judgemental equality [01CY]
- August 11, 2025
- Jon Sterling
For both basic forms of judgement, there is an auxiliary form of judgement governing equality.
- Presupposing A~\mathit {type} and B~\mathit {type}, we will write A\equiv B~\mathit {type} for the judgement that A and B are the same description of a type.
- Presupposing A~\mathit {type} and u:A and v:A, we will write u\equiv v:A for the judgement that u and v are the same description of an element of type A.
(Look at the presuppositions carefully: it does not make sense to speak of two elements being equal unless they are elements of the same type!)
Judgemental equality has the following property: if two things are equal, then we are justified in replacing one by the other at any time.
Parameterised and hypothetical judgements [01D3]
- August 11, 2025
- Jon Sterling
Sometimes we will describe a family of judgements by writing a judgement with a placeholder or a parameter in it. In this case we may wish to speak of the judgement holding for all instantiations of this parameter; for example, to describe the body of a function \mathsf {int}\to \mathsf {string} in OCaml we must parameterise a term u[x]:\mathsf {string} in a variable x:\mathsf {int} to obtain the function \lambda {x}\mathpunct {.}u[x]:\mathsf {int}\to \mathsf {string}. The judgement that u[x] describes a string assuming x describes an integer is called a hypothetical judgement, and it is written x:\mathsf {int}\vdash u[x]:\mathsf {string}.
Many formal presentations of type theory make explicit the context \Gamma of parameters that are in scope. This is a perfectly valid, but one of the overarching principles of type theory is that all constructs are arranged so as to be invariant under substitution of paramters; the up-shot is that we can allow the ambient parameters to be implicit, explicitly introducing scopes only when we wish to bind a new parameter.
Rules of inference [01CZ]
- August 11, 2025
- Jon Sterling
In § [01CV] we have outlined the “parts of speech” of dependent type theory in terms of forms of judgement governing types and elements, but we have not yet actually described what the types and elements actually “are”—in other words, we lack vocabulary. Instead of giving a definition of what the types and elements are, type theorists instead describe them indirectly by means of rules of inference—which specify valid processes by which one may describe types and terms. For the programmers in the room, these rules of inference constitute an abstract Application Programming Interface or API against which type theorists agree to work. This API is organised into two main classes of rules: structural rules and rules governing type formers; the former are required to make the judgemental structure behave correctly, whereas the latter give us actual concrete types to work with.
Structural rules [01D0]
- August 11, 2025
- Jon Sterling
In type theory, the structural rules mainly ensure that judgemental equality behaves correctly. From a certain point of view, these rules are redundant (because without them, judgemental “equality” it wouldn’t be equality, etc.!), but we include them for the sake of explicitness. Recalling our warning, note and do not fear the fact that different presentations of type theory will organise these rules differently or may even choose different sets of rules. There are many roads to Rome.
Judgemental equality is an equivalence relation [01D1]
- August 11, 2025
- Jon Sterling
We have the following rules of inference witnessing that judgemental equality is an equivalence relation:
- Reflexivity.
- Given A~\mathit {type} we may assert A\equiv A~\mathit {type}.
- Given A~\mathit {type} and u:A, we may assert u\equiv u:A.
- Transitivity.
- Given A,B,C~\mathit {type} such that A\equiv B~\mathit {type} and B\equiv C~\mathit {type}, we may assert A\equiv C~\mathit {type}.
- Given A~\mathit {type} and u,v,w:A such that u\equiv v:A and v\equiv w:A, we may assert u\equiv w:A.
- Symmetry.
- Given A,B~\mathit {type} such that A\equiv B~\mathit {type}, we may assert B\equiv A~\mathit {type}.
- Given A~\mathit {type} and u,v:A such that u\equiv v:A, we may assert v\equiv u:A.
Typing respects equality [01D2]
- August 11, 2025
- Jon Sterling
Another important rule of equality is that equal types have the same elements; this is sometimes called the “conversion rule”. In particular:
- Given A,B~\mathit {type} and u:A such that A\equiv B~\mathit {type}, we may assert u:B.
- Given A,B~\mathit {type} and u,v:A such that A\equiv B~\mathit {type} and u\equiv v:A, we may assert u\equiv v:B.
This is rendered like so in short-hand:
\frac { A\equiv B~\mathit {type} \quad u:A }{ u:B } \qquad \frac { A\equiv B~\mathit {type} \quad u\equiv v:A }{ u\equiv v:B }Substitutivity of judgemental equality [01D6]
- August 11, 2025
- Jon Sterling
The following rules express the sense in which hypothetical judgments respect judgemental equality.
- Given A~\mathit {type} and x:A\vdash B[x]~\mathit {type} and u,v:A such that u\equiv v:A, we may assert B[u]\equiv B[v]~\mathit {type}.
- Given A~\mathit {type} and x:A\vdash B[x]~\mathit {type} and x:A\vdash w[x]:B[x] and u,v:A such that u\equiv v:A, we may assert w[u]\equiv w[v]:B[u].
We have written the rules “long-hand”, but a theoretician may write these in the following short-hand notation:
\frac { x:A\vdash B[x]~\mathit {type} \quad u\equiv v:A }{ B[u]\equiv B[v]~\mathit {type} } \frac { x:A\vdash B[x]~\mathit {type} \quad x:A\vdash w[x]:B[x] \quad u\equiv v:A }{ w[u]\equiv w[v]:B[u] }As you can see, it is common when in a hurry to leave out all some of the obvious premises (for example, the premises A~\mathit {type} and u,v:A in the first rule). From the perspective of this course, these premises are “actually” secretly present; when someone writes a rule like this, they are relying on a shared expectation of good faith—that they would never intentionally write down a judgement that is meaningless, and so if the necessary presuppositions are omitted, these are intended to be filled in by the reader.
Note: we could have added a rule coverning hypothetical judgements of the form X~\mathit {type}\vdash B[x]~\mathit {type}, etc., such judgements do not usually arise in dependent type theory, so we ignore it.
Exercise Rule golf [01D7]
- August 11, 2025
- Jon Sterling
Imagine that we had omitted the transitivity and symmetry rules for judgemental equality. Devise a single rule that handles both transitivity and symmetry simultaneously.
The usual schema for type formers [01D8]
- August 11, 2025
- Jon Sterling
A type former is something like “the booleans” or “the function space”; type formers are described by rules of inference that govern how they and their elements can be formed and used.
The rules of a type former \mathbf {T} to be arranged into a few groups:
- The formation rules specify how to describe an instance of the type former \mathbf {T}.
- The introduction rules specify how to describe elements of instances of \mathbf {T}.
- The elimination rules specify how to describe elements of other types that depend on elements of instances of \mathbf {T}.
- The large elimination rule specifies how to define a type that depends on an element of an instance of \mathbf {T}.
- The computation rules describe what happens when an elimination rule is applied to the result of an introduction rule.
- The uniqueness rules describe either a strategy to equate the result of the introduction rule to other elements, or (more rarely) a strategy to equate the result of the elimination rule to other elements.
Large elimination rules are often omitted (or redundant). We won’t take a position either way, but some examples might involve them.
Not all type formers come with uniqueness rules; there are both practical and semantic reasons to omit them at times, but we will not get into that. We will not consider any types that have uniqueness rules on the elimination side, but many of the type formers that we look at will have uniqueness rules on the introduction side.
The unit type [01DA]
- August 11, 2025
- Jon Sterling
One of the simplest types is the unit type, which has exactly one element.
Rule Formation [01DK]
- August 11, 2025
- Jon Sterling
The formation rule states that we may assert \mathsf {unit}~\mathit {type}.
\frac {}{\mathsf {unit}~\mathit {type}}Rule Introduction [01DL]
- August 11, 2025
- Jon Sterling
The introduction rule states that we may assert ():\mathsf {unit}.
\frac {}{():\mathsf {unit}}No elimination rule is needed, and therefore no computation rule either.
Rule Uniqueness [01DM]
- August 11, 2025
- Jon Sterling
The uniqueness rule states that every element of the unit type is equal to the distinguished element:
\frac {u:\mathsf {unit}}{u\equiv ():\mathsf {unit}}Exercise Extensionality [01DN]
- August 11, 2025
- Jon Sterling
Show that the uniqueness rule is equivalent to the following extensionality rule that equates any two elements:
\frac {u,v:\mathsf {unit}}{u\equiv v:\mathsf {unit}}The empty type [01D9]
- August 11, 2025
- Jon Sterling
Another very simple type is the empty type, which has no elements at all.
Rule Formation [01DP]
- August 11, 2025
- Jon Sterling
The formation rule states that we may assert \mathsf {empty}~\mathit {type}.
\frac {}{\mathsf {empty}~\mathit {type}}Because there are no elements, there is naturally no introduction rule.
Rule Elimination [01DO]
- August 11, 2025
- Jon Sterling
We do include an elimination rule: this should allow us to construct, by contradiction, an element of any type whatsoever when we have an element of the empty type. The elimination rule states that when we have C~\mathit {type} and u:\mathsf {empty}, we may deduce \mathsf {abort}_C(u):C.
\frac { C~\mathit {type} \quad u:\mathsf {empty} }{ \mathsf {abort}_C(u):C }Because there is no introduction rule, there can be no computation rule. We could include a uniqueness rule on the elimination side, but this is usually omitted.
Exercise Dependent elimination [01DC]
- August 11, 2025
- Jon Sterling
We can also consider a dependent elimination rule for the empty type, where we allow C to depend on an element of the empty type; show that the following can be derived from the simple elimination rule, filling in the question marks:
\frac { x:\mathsf {empty}\vdash C[x]~\mathit {type} \quad u:\mathsf {empty} }{ ???:C[u] }The boolean type [01D5]
- August 11, 2025
- Jon Sterling
Rule Formation [01DQ]
- August 11, 2025
- Jon Sterling
The formation rule for the booleans states that we may assert \mathsf {bool}~\mathit {type}:
\frac {}{\mathsf {bool}~\mathit {type}}Rule Introduction [01DR]
- August 11, 2025
- Jon Sterling
We have two introduction rules; one states that we may assert \mathsf {true}:\mathsf {bool} and the other states that we may assert \mathsf {false}:\mathsf {bool}.
\frac {}{\mathsf {true}:\mathsf {bool}} \qquad \frac {}{\mathsf {false}:\mathsf {bool}}Rule Elimination [01DS]
- August 11, 2025
- Jon Sterling
The elimination rule is where things start to get interesting; this will be a dependently typed version of the classical if-expression. Given a family of types x:\mathsf {bool}\vdash C[x]~\mathit {type} and elements u:\mathsf {bool} and v:C[\mathsf {true}] and w:C[\mathsf {false}], we may assert \mathsf {if}_{x\mathpunct {.}C[x]}(u;v;w):C[u].
Rule Computation [01DT]
- August 11, 2025
- Jon Sterling
The computation rules corresponding to the above elimination rule correspond to the way that when an if-expression is applied to a concrete boolean (i.e. true or false) the whole expression reduces to the corresponding branch.
- Given x:\mathsf {bool}\vdash C[x]~\mathit {type} and u:C[\mathsf {true}] and v:C[\mathsf {false}], we may assert \mathsf {if}_{x\mathpunct {.}C[x]}(\mathsf {true};v;w)\equiv v:C[\mathsf {true}]. \frac { x:\mathsf {bool}\vdash C[x]~\mathit {type} \quad v:C[\mathsf {true}] \quad w:C[\mathsf {false}] }{ \mathsf {if}_{x\mathpunct {.}C[x]}(\mathsf {true};v;w)\equiv v:C[\mathsf {true}] }
- Given x:\mathsf {bool}\vdash C[x]~\mathit {type} and u:C[\mathsf {true}] and v:C[\mathsf {false}], we may assert \mathsf {if}_{x\mathpunct {.}C[x]}(\mathsf {false};v;w)\equiv w:C[\mathsf {false}]. \frac { x:\mathsf {bool}\vdash C[x]~\mathit {type} \quad v:C[\mathsf {true}] \quad w:C[\mathsf {false}] }{ \mathsf {if}_{x\mathpunct {.}C[x]}(\mathsf {false};v;w)\equiv w:C[\mathsf {false}] }
We could include a uniqueness rule on the elimination side, but this is typically omitted.
Aside Type-level if-expressions [01DB]
- August 11, 2025
- Jon Sterling
This is all well and good, but how can we get an actually interesting dependent type x:\mathsf {bool}\vdash C[x]~\mathit {type}? Later on we will introduce type formers that will readily provide examples, but to get an idea of what is possible, we consider the optional large elimination rule with its corresponding computation rules:
- Given A,B~\mathit {type} and u:\mathsf {bool} we may assert \mathsf {If}(u;A;B)~\mathit {type}. \frac { A,B~\mathit {type} \quad u:\mathsf {bool} }{ \mathsf {If}(u;A;B)~\mathit {type} }
- Given A,B~\mathit {type}, we may assert \mathsf {If}(\mathsf {true};A;B)\equiv A~\mathit {type}. \frac { A,B~\mathit {type} }{ \mathsf {If}(\mathsf {true};A;B)\equiv A~\mathit {type} }
- Given A,B~\mathit {type}, we may assert \mathsf {If}(\mathsf {false};A;B)\equiv B~\mathit {type}. \frac { A,B~\mathit {type} }{ \mathsf {If}(\mathsf {true};A;B)\equiv B~\mathit {type} }
With the above it is therefore possible to define types like \mathsf {If}(u;\mathsf {unit};\mathsf {empty}) whose behaviour differs wildly depending on the value of u. Once we introduce universes (types whose elements describe types), we will be able to construct examples like this without using the large elimination.
Aside Products and dependent functions in set theory [01DE]
- August 11, 2025
- Jon Sterling
In set theory, the set of functions A\to B can be alternatively described as the product of A-many copies of B. This would be written as follows:
\prod _{x\in A} BSo we might say that the product of A-many copies of B is the set of functions from A to B, because we must assign an element of B to each x\in A. It is also possible to consider products where instead of having a bunch of copies of the same set, we can match a different set to each element of A. For example, if we have a family of sets (B_x)_{(x\in A)}, then we may consider the product of this family:
\prod _{x\in A} B_xThe above product \prod _{x\in A}B_x of the family (B_x)_{(x\in A)} is then the set of dependent functions from A to the family B. The same set theoretic ideas work in type theory, as we shall see.
We shall now see how to describe the product of a family of types by means of inference rules.
The product of a family of types [01DD]
- August 11, 2025
- Jon Sterling
Rule Formation [01DU]
- August 11, 2025
- Jon Sterling
The formation rule states that given A~\mathit {type} and a family x:A\vdash B[x]~\mathit {type}, then we may form {\mathop {\mathchoice {\textstyle \prod }{\textstyle \prod }{\scriptstyle \prod }{\scriptscriptstyle \prod } }_{(x:A)}}{B[x]}~\mathit {type}.
\frac { A~\mathit {type}\quad x:A\vdash B[x]~\mathit {type} }{ {\mathop {\mathchoice {\textstyle \prod }{\textstyle \prod }{\scriptstyle \prod }{\scriptscriptstyle \prod } }_{(x:A)}}B[x]~\mathit {type} }Rule Introduction [01DV]
- August 11, 2025
- Jon Sterling
The introduction rule states that given A and B as above and x:A\vdash u[x]:B[x], we may form \lambda x\mathpunct {.}{u[x]}:{\mathop {\mathchoice {\textstyle \prod }{\textstyle \prod }{\scriptstyle \prod }{\scriptscriptstyle \prod } }_{(x:A)}}{B[x]}:
\frac { x:A\vdash u[x]:B[x] }{ \lambda x\mathpunct {.}{u[x]}:{\mathop {\mathchoice {\textstyle \prod }{\textstyle \prod }{\scriptstyle \prod }{\scriptscriptstyle \prod } }_{(x:A)}}{B[x]} }Recall that the premises concerning A and B are implicitly part of the rule above, and omitted only by convention. A further notational convention that we are already employing is to omit A and B from the \lambda -term itself; the most explicit notation for the rule above, which is how you should read it(!), would be something like the following:
\frac { A~\mathit {type}\quad x:A\vdash B[x]~\mathit {type}\quad x:A\vdash u[x]:B[x] }{ \mathsf {lam}(A; x\mathpunct {.}B[x]; x\mathpunct {.}u[x]) :{\mathop {\mathchoice {\textstyle \prod }{\textstyle \prod }{\scriptstyle \prod }{\scriptscriptstyle \prod } }_{(x:A)}}{B[x]} }Rule Elimination [01DW]
- August 11, 2025
- Jon Sterling
The elimination rule states that given A and B as above and u:{\mathop {\mathchoice {\textstyle \prod }{\textstyle \prod }{\scriptstyle \prod }{\scriptscriptstyle \prod } }_{(x:A)}}{B[x]} and v:A, we may form the application uv:B[v].
\frac { u:{\mathop {\mathchoice {\textstyle \prod }{\textstyle \prod }{\scriptstyle \prod }{\scriptscriptstyle \prod } }_{(x:A)}}{B[x]}\quad v:A }{ uv:B[v] }Rule Computation [01DX]
- August 11, 2025
- Jon Sterling
The computation rule says that applying a \lambda -expression to an element is equal to the corresponding instantiation of its body:
\frac { x:A\vdash u[x]:B[x]\quad v:A }{ (\lambda x\mathpunct {.}{u[x]})v \equiv u[v]:B[v] }Rule Uniqueness [01DY]
- August 11, 2025
- Jon Sterling
The uniqueness rule says that every element of the product {\mathop {\mathchoice {\textstyle \prod }{\textstyle \prod }{\scriptstyle \prod }{\scriptscriptstyle \prod } }_{(x:A)}}{B[x]} is equal to a \lambda -abstraction obtained from it by application to the bound variable.
\frac { u:{\mathop {\mathchoice {\textstyle \prod }{\textstyle \prod }{\scriptstyle \prod }{\scriptscriptstyle \prod } }_{(x:A)}}{B[x]} }{ u\equiv \lambda x\mathpunct {.}{ux}:{\mathop {\mathchoice {\textstyle \prod }{\textstyle \prod }{\scriptstyle \prod }{\scriptscriptstyle \prod } }_{(x:A)}}{B[x]} }Exercise Extensionality [01DJ]
- August 11, 2025
- Jon Sterling
Show that the uniqueness rule for the product {\mathop {\mathchoice {\textstyle \prod }{\textstyle \prod }{\scriptstyle \prod }{\scriptscriptstyle \prod } }_{(x:A)}}{B[x]} is equivalent to the following extensionality rule:
\frac { u,v:{\mathop {\mathchoice {\textstyle \prod }{\textstyle \prod }{\scriptstyle \prod }{\scriptscriptstyle \prod } }_{(x:A)}}{B[x]} \quad x:A\vdash ux\equiv vx:B[x] }{ u\equiv v:{\mathop {\mathchoice {\textstyle \prod }{\textstyle \prod }{\scriptstyle \prod }{\scriptscriptstyle \prod } }_{(x:A)}}{B[x]} }Notation Non-dependent function types [01EG]
- August 11, 2025
- Jon Sterling
We can of course talk about non-dependent functions from a type A to a type B; these the elements of the product {\mathop {\mathchoice {\textstyle \prod }{\textstyle \prod }{\scriptstyle \prod }{\scriptscriptstyle \prod } }_{(x:A)}}{B} of A many copies of B. For clarity, we introduce the following notation:
A\to B :\equiv {\mathop {\mathchoice {\textstyle \prod }{\textstyle \prod }{\scriptstyle \prod }{\scriptscriptstyle \prod } }_{(x:A)}}{B}Aside Sums and dependent pairs in set theory [01DZ]
- August 11, 2025
- Jon Sterling
In set theory, the set of pairs A\times B can alternatively be described as the sum or disjoint union of A-many copies of B:
\sum _{x\in A} B= \coprod _{x\in A} BSo an element of the sum of A-many copies of B would be a pair (u,v) with u\in A and v\in B. If we instead have a different set B_x associated to each x\in A, we can consider the sum of the family (B_x)_{(x\in A)}:
\sum _{x\in A} B_x = \coprod _{x\in A} B_xThen an element of the sum is a dependent pair (u,v) with u\in A and v\in B_u. In this sense, the sum of a family of sets is the set of dependent pairs in that family.
The sum of a family of types [01E0]
- August 11, 2025
- Jon Sterling
Rule Formation [01E1]
- August 11, 2025
- Jon Sterling
The formation rule states that given A~\mathit {type} and a family x:A\vdash B[x]~\mathit {type}, we may form {\mathop {\mathchoice {\textstyle \sum }{\textstyle \sum }{\scriptstyle \sum }{\scriptscriptstyle \sum } }_{(x:A)}}{B[x]}~\mathit {type}.
\frac { A~\mathit {type}\quad x:A\vdash B[x]~\mathit {type} }{{\mathop {\mathchoice {\textstyle \sum }{\textstyle \sum }{\scriptstyle \sum }{\scriptscriptstyle \sum } }_{(x:A)}}{B[x]}~\mathit {type}}Rule Introduction [01E2]
- August 11, 2025
- Jon Sterling
The introduction rule states that given A and B as above and u:A and v:B[u] we may form \left \langle u,v\right \rangle :{\mathop {\mathchoice {\textstyle \sum }{\textstyle \sum }{\scriptstyle \sum }{\scriptscriptstyle \sum } }_{(x:A)}}{B[x]}.
\frac { u:A \quad v:B[u] }{ \left \langle u,v\right \rangle :{\mathop {\mathchoice {\textstyle \sum }{\textstyle \sum }{\scriptstyle \sum }{\scriptscriptstyle \sum } }_{(x:A)}}{B[x]} }Rule Elimination [01E3]
- August 11, 2025
- Jon Sterling
Given A and B as above, there two elimination rules for {\mathop {\mathchoice {\textstyle \sum }{\textstyle \sum }{\scriptstyle \sum }{\scriptscriptstyle \sum } }_{(x:A)}}{B[x]} corresponding to the two components of a pair.
- Given u:{\mathop {\mathchoice {\textstyle \sum }{\textstyle \sum }{\scriptstyle \sum }{\scriptscriptstyle \sum } }_{(x:A)}}{B[x]}, we may form u.1:A. \frac { u:{\mathop {\mathchoice {\textstyle \sum }{\textstyle \sum }{\scriptstyle \sum }{\scriptscriptstyle \sum } }_{(x:A)}}{B[x]} }{ u.1:A }
- Given u:{\mathop {\mathchoice {\textstyle \sum }{\textstyle \sum }{\scriptstyle \sum }{\scriptscriptstyle \sum } }_{(x:A)}}{B[x]}, we may form u.2:B[u.1]. \frac { u:{\mathop {\mathchoice {\textstyle \sum }{\textstyle \sum }{\scriptstyle \sum }{\scriptscriptstyle \sum } }_{(x:A)}}{B[x]} }{ u.2:B[u.1] }
Rule Computation [01E4]
- August 11, 2025
- Jon Sterling
The computation rules express what happens when you project the first and second components of a pair.
\frac { u:A\quad v:B[u] }{ \left \langle u,v\right \rangle .1 \equiv u:A } \qquad \frac { u:A\quad v:B[u] }{ \left \langle u,v\right \rangle .2 \equiv v:B[u] }Rule Uniqueness [01E5]
- August 11, 2025
- Jon Sterling
The uniqueness rule states that any element of the sum {\mathop {\mathchoice {\textstyle \sum }{\textstyle \sum }{\scriptstyle \sum }{\scriptscriptstyle \sum } }_{(x:A)}}{B[x]} is equal to a dependent pair whose components are obtained by projection.
\frac { u:{\mathop {\mathchoice {\textstyle \sum }{\textstyle \sum }{\scriptstyle \sum }{\scriptscriptstyle \sum } }_{(x:A)}}{B[x]} }{ u\equiv \left \langle u.1,u.2\right \rangle :{\mathop {\mathchoice {\textstyle \sum }{\textstyle \sum }{\scriptstyle \sum }{\scriptscriptstyle \sum } }_{(x:A)}}{B[x]} }Exercise Extensionality [01E6]
- August 11, 2025
- Jon Sterling
Show that the uniqueness rule for the sum {\mathop {\mathchoice {\textstyle \sum }{\textstyle \sum }{\scriptstyle \sum }{\scriptscriptstyle \sum } }_{(x:A)}}{B[x]} is equivalent to the following extensionality rule:
\frac { u,v:{\mathop {\mathchoice {\textstyle \sum }{\textstyle \sum }{\scriptstyle \sum }{\scriptscriptstyle \sum } }_{(x:A)}}{B[x]} \quad u.1\equiv v.1:A \quad u.2\equiv v.2:B[u.1] }{ u\equiv v:{\mathop {\mathchoice {\textstyle \sum }{\textstyle \sum }{\scriptstyle \sum }{\scriptscriptstyle \sum } }_{(x:A)}}{B[x]} }Binary products [01FS]
- August 11, 2025
- Jon Sterling
There is a bit of a terminological snafu here, if we consider the binary product A\times B of types A,B~\mathit {type} which ought to consist of pairs of an element of A with an element of B. We have seen already that the binary product A\times B can be decribed by a special case of a sum:
A\times B :\equiv {\mathop {\mathchoice {\textstyle \sum }{\textstyle \sum }{\scriptstyle \sum }{\scriptscriptstyle \sum } }_{(x:A)}}{B}This is confusing (if you don’t think about it!) because products and sums are supposed to be different. But it really does make sense, because the product A\times B is indeed the sum of A-many copies of B. So why is it called a (binary) product? Because it is the product of the family x:\mathsf {bool} \vdash \mathsf {If}(x;A;B) that we may form using large elimination. A dependent function f: {\mathop {\mathchoice {\textstyle \prod }{\textstyle \prod }{\scriptstyle \prod }{\scriptscriptstyle \prod } }_{(x:\mathsf {bool})}} \mathsf {If}(x;A;B) must assign values to the two booleans \mathsf {true} and \mathsf {false}. So a dependent function like f could consist of an element f~\mathsf {true}:\mathsf {If}(\mathsf {true};A;B) \equiv A and an element f~\mathsf {false}:\mathsf {If}(\mathsf {false};A;B)\equiv B\text {.}
It is in practice easier to work with the definition of A\times B in terms of the sum, because this representation satisfies a judgemental extensionality law that is not enjoyed by the version defined using the booleans. Nonetheless, once we learn to say what it means for two types to be mathematically equivalent, the two repressentations will indeed be equivalent.
Some philosophy about equality [01E9]
- August 11, 2025
- Jon Sterling
So far we have seen just one way to say that two things are the same: judgemental equality. Judgemental equality pertains to the expressions of the language; when two expressions are judgemental equally, then they unavoidably describe the same mathematical object, but we might consider the converse: if two expressions describe the “same” mathematical object, are the expressions themselves judgementally equal?
One way to test this proposition is to consider the extension of our type theory with identification types u=_A v for u,v:A whose elements represent evidence that u and v describe the same mathematical object. This is subtly different from the equality judgement u\equiv v:A in an important way, putting aside the fact that one is a judgement and other is a type:
- The equality judgement u\equiv v:A asserts that u and v are the same description of an element of A.
- An element w:u=_Av witnesses that u and v describe the same mathematical object, rather than that they are the same description.
In real life, it can happen that two different expressions describe the same thing; for example, it is often pointed out that the “morning star” and the “evening star” both describe the planet Venus—although examples like this can be troublesome since one can always force the referents to be distinct again by arguing that (e.g.) one expression describes Venus in the morning, and the other describes Venus in the evening, etc.
In much of mathematics, it was considered that the converse proposition (that any two descriptions of the same object are themselves the same) was perfectly natural and could therefore be included as a formal rule of dependent type theory that relates judgmental equality with identification types. This rule was called equality reflection. But in the final two decades of the 20th Century, three different objections to equality reflection emerged:
- A philosophical objection. Around 1986, Per Martin-Löf re-analysed the philosophical foundations of dependent type theory and came to the conclusion that equality reflection was not justified in a philosophical sense. Martin-Löf’s philosophical objection to equality reflection did not rise to the level of a mathematical objection: indeed, equality reflection is consistent with traditional mathematics.
- A practical objection. During the 1980s and 1990s, efficient algorithms for automatically checking the judgements of dependent type theory were developed (including those underlying Rocq, Agda, and Lean), but these algorithms rely on the omission of equality reflection; indeed, the judgements of type theory with equality reflection are known to be undecidable.
- A mathematical objection. Toward the end of the 1990s, the late Martin Hofmann and Thomas Streicher discovered a mathematical objection to equality reflection: a model of type theory based on groupoids in which there can be multiple mathematically distinct ways to identify two objects as “the same”, which contradicts equality reflection; moreover, the notion of sameness that interpreted the identification type in this model was closer to everyday mathematical usage than that of the standard model in set theory. Although equality reflection remains consistent, there was finally compelling evidence that equality reflection was warping our perception of mathematics in a harmful way.
The three objections above are not insurmountable, but they are strong enough together that intensional type theory (which is type theory without equality reflection) has become a leading point of view. Intensional type theory alone does not, however, take advantage of the possibilities suggested by Hofmann and Streicher’s groupoid interpretation; in this module, we consider an extension of intensional type theory called homotopy type theory that solves these problems and more.
Identification types [01E8]
- August 11, 2025
- Jon Sterling
Rule Formation [01EA]
- August 11, 2025
- Jon Sterling
Given A~\mathit {type} and u,v:A we may form the identification type u=_Av~\mathit {type}.
\frac { A~\mathit {type}\quad u,v:A }{ u=_Av~\mathit {type} }Rule Introduction [01EB]
- August 11, 2025
- Jon Sterling
Given A~\mathit {type} and u:A, we may form \mathsf {refl}_u:u=_Au.
\frac { A~\mathit {type}\quad u:A }{ \mathsf {refl}_u:u=_Au }The idea of the identity type on A is that for each u:A, the family x:A\vdash u=x~\mathit {type} is the smallest family of types equipped with an element \mathsf {refl}_u:u=_Au. We witness this by means of an elimination rule below.
Rule Elimination [01EC]
- August 11, 2025
- Jon Sterling
Fix A~\mathit {type} and u,v:A and w:u=_Av. Given a family y:A,z:u=_Ay\vdash C[y,z]~\mathit {type} and an element c:C[u,\mathsf {refl}_u], we may form \mathsf {J}_{y,z\mathpunct {.} C[y,z]}(w; c) :C[v,w].
\frac { w:u=_Av\quad y:A,z:u=_Ay\vdash C[y,z]~\mathit {type}\quad c:C[u,\mathsf {refl}_u] }{ \mathsf {J}_{y,z\mathpunct {.} C[y,z]}(w; c) :C[v,w] }The elimination rule provides an induction principle for identifications whose left end-point is u. It says that if you want to prove something for all such identifications starting with u, it suffices to prove it for the trivial one given by \mathsf {refl}_u:u=_Au.
Formally, the \mathsf {J} term secretly must mention u,v; we omit these because they can always be deduced from context. We may even write \mathsf {J}_C rather than \mathsf {J}_{y,z\mathpunct {.} C[y,z]} when our meaning is clear.
Rule Computation [01ED]
- August 11, 2025
- Jon Sterling
The computation rule for the identification type explains what the elimination rule does when applied to the trivial identification.
\frac { u:A\quad y:A,z:u=_Ay\vdash C[y,z]~\mathit {type}\quad c:C[u,\mathsf {refl}_u] }{ \mathsf {J}_{y,z\mathpunct {.} C[y,z]}(\mathsf {refl}_u; c) \equiv c :C[u,\mathsf {refl}_u] }Exercise Unicity of self-identifications [01EQ]
- August 11, 2025
- Jon Sterling
Using the elimination rule above, try to construct elements of the following types:
{\mathop {\mathchoice {\textstyle \prod }{\textstyle \prod }{\scriptstyle \prod }{\scriptscriptstyle \prod } }_{(u:A)}} {\mathop {\mathchoice {\textstyle \prod }{\textstyle \prod }{\scriptstyle \prod }{\scriptscriptstyle \prod } }_{(p:u=_Au)}} p=_{u=_Au}\mathsf {refl}_u {\mathop {\mathchoice {\textstyle \prod }{\textstyle \prod }{\scriptstyle \prod }{\scriptscriptstyle \prod } }_{(u,v:A)}} {\mathop {\mathchoice {\textstyle \prod }{\textstyle \prod }{\scriptstyle \prod }{\scriptscriptstyle \prod } }_{(p,q:u=_Av)}} p=_{u=_Av}qWhat goes wrong? What do you think this implies about the notion of “sameness” that we get from identification types?
Definition Transport [01EO]
- August 11, 2025
- Jon Sterling
A special case of the identification elimination rule is transport. Where the elimination rule allows the family C to depend on the identification being eliminated, sometimes we only need to depend on one of its endpoints.
Given x:A\vdash B[x]~\mathit {type}, p:u=_Av, and b:B[u] we may define \begin {aligned} & \mathsf {transport}_{x\mathpunct {.}{B[x]}}(p;b) : B[v] \end {aligned} satisfying \mathsf {transport}_{x\mathpunct {.}{B[x]}}(\mathsf {refl}_u;b) \equiv b :B[u] using identification elimination: \mathsf {transport}_{x\mathpunct {.}B[x]}(p;b) :\equiv \mathsf {J}_{y,z\mathpunct {.}B[y]}(p; b)
We may write p_*^Bb for \mathsf {transport}_{x\mathpunct {.}{B[x]}}(p;b) or even p_*b when B is understood in context.
Warning A warning about transport [01EP]
- August 11, 2025
- Jon Sterling
If you find yourself using transport a lot, you are in for a world of trouble later. It is often a good sign that a different or more streamlined approach to the problem is needed. We will learn some methods for avoiding transports in later lectures.
The action of a function on identifications [01GN]
- August 11, 2025
- Jon Sterling
Given a function f:A\to B and an identification p:u=_Av we should be able to obtain an identification \mathsf {act}_fp:fu=_B fv. This should satisfy the judgemental equation \mathsf {act}_f(\mathsf {refl}_u)\equiv \mathsf {refl}_{fu}\text {.}
We can define the action using transport, where the family is a function space:
\mathsf {act}_fp :\equiv \bigl (\mathsf {transport}_{z\mathpunct {.} fz=_Bfx \to fz=_Bfy} (p; \lambda q\mathpunct {.}q)\bigr ) (\mathsf {refl}_{fu})Make sure you understand why the definition above work!
In many texts, this operation may be written \mathsf {ap}_fp; this stands for “action on paths”. In this course we prefer the word “identification” to “path”, but we might slip up sometimes. It is important to be flexible and find peace with a variety of different terminologies that may appear in different books and papers.
Exercise Unbiased elimination rule (extremely hard!) [01EE]
- August 11, 2025
- Jon Sterling
Prove that the elimination and computation rules for the identification type are equivalent to the following “unbiased” ones that do not fix u outside of the family C:
\frac { w:u=_A v\quad x:A,y:A,z:x=_Ay\vdash C[x,y,z]~\mathit {type}\quad x:A\vdash c[x]:C[x,x,\mathsf {refl}_u] \quad }{ \mathsf {J}'_{x,y,z\mathpunct {.}C[x,y,z]}(w; x\mathpunct {.} c[x]) : C[u,v,w] } \frac { u:A\quad x:A,y:A,z:x=_Ay\vdash C[x,y,z]~\mathit {type}\quad x:A\vdash c[x]:C[x,x,\mathsf {refl}_x] \quad }{ \mathsf {J}'_{x,y,z\mathpunct {.}C[x,y,z]}(\mathsf {refl}_u; x\mathpunct {.}{c[x]}) \equiv c[u] :C[u,u,\mathsf {refl}_u] }Explicitly, you are being asked to use \mathsf {J} to define \mathsf {J}' and vice versa. This exercise is extremely difficult, so don’t waste too much time on it.
Explicit vs. implicit definitions of functions [01EF]
- August 11, 2025
- Jon Sterling
Suppose we wanted to define a function like \mathsf {not}:\mathsf {bool}\to \mathsf {bool} that swaps the two booleans. Using the rules of function types and booleans, we would write:
\begin {aligned} &\mathsf {not} : \mathsf {bool}\to \mathsf {bool}\\ &\mathsf {not} :\equiv \lambda x\mathpunct {.} \mathsf {if}_{\_\mathpunct {.}\mathsf {bool}}( x; \mathsf {false}; \mathsf {true} ) \end {aligned}We can use the computation rules to see that the following equations hold judgementally:
- \mathsf {not}~\mathsf {true} \equiv \mathsf {false}:\mathsf {bool}
- \mathsf {not}~\mathsf {false}\equiv \mathsf {true}:\mathsf {bool}
These equations uniquely determine the value of \mathsf {not}~x for any x:\mathsf {bool} in the sense that if we have f:\mathsf {bool}\to \mathsf {bool} such that f~\mathsf {true}\equiv \mathsf {false}:\mathsf {bool} and f~\mathsf {false}\equiv \mathsf {true}:\mathsf {bool}\text {,} then we may construct some H_f:{\mathop {\mathchoice {\textstyle \prod }{\textstyle \prod }{\scriptstyle \prod }{\scriptscriptstyle \prod } }_{(x:\mathsf {bool})}} fx =_{\mathsf {bool}} \mathsf {not}~x\text {.}
Indeed, we define H_f using a dependent if-statement:
Note that we do not have x:\mathsf {bool}\vdash fx \equiv _{\mathsf {bool}}\mathsf {not}~x:\mathsf {bool}; based on our previous explanation of the difference between judgemental equality and the identification type, this reflects that we know fx describes the same boolean as \mathsf {not}~x, but we don’t know that it is the same description of this boolean.
Because of the uniqueness of the values of \mathsf {not} that we have seen, it is very common to define such a function implicitly by just stating the equations that it is meant to satisfy. For example, you might see a definition like the following:
\begin {aligned} &\mathsf {not}:\mathsf {bool}\to \mathsf {bool} \\ &\mathsf {not}~\mathsf {true} :\equiv \mathsf {false} \\ &\mathsf {not}~\mathsf {false} :\equiv \mathsf {true} \end {aligned}Part of interpreting (reading) such a definition is convincing yourself that there really is a unique function that satisfies these equations, where uniqueness is taken as above in the sense of the identification type. If you can’t prove this to yourself when you see such a definition, then you must conclude that either you have not understood the definition or that the author of the definition has made a mistake.
Many computerised proof assistants, including Agda and Lean, support implicit definitions like the one above directly. Lean attempts to “understand” such a definition by converting it into an explicit one in terms of the elimination rules, and if it cannot do that, it reports an error. Agda, on the other hand, has implicit definitions primitively and does not deal with explicit definitions at all; Agda includes complicated heuristics to check whether an implicit definition is meaningful (e.g. terminating), but these heuristics have repeatedly been shown to be unsound over the years, leading to many small tweaks to the algorithm. Although there are practical trade-offs when deciding between designing a system around explicit vs. implicit definitions, we will take the position that the explicit definitions are the “real” ones and that a given implicit definition is always intended to carry an assertion that the reader may construct an explicit definition satisfying the same equations.
By the way, now that we have fixed the convention of implicit definitions, we could have written H_f implicitly too:
\begin {aligned} &H_f:{\mathop {\mathchoice {\textstyle \prod }{\textstyle \prod }{\scriptstyle \prod }{\scriptscriptstyle \prod } }_{(x:\mathsf {bool})}} fx=_{\mathsf {bool}} \mathsf {not}~x\\ &H_f~\mathsf {true} :\equiv \mathsf {refl}_{\mathsf {false}}\\ &H_f~\mathsf {false} :\equiv \mathsf {refl}_{\mathsf {true}}\\ \end {aligned}Exercises [01E7]
- August 11, 2025
- Jon Sterling
Exercise. Dependent types I › Rules of inference › Structural rules › Rule golf [01D7]
- August 11, 2025
- Jon Sterling
Imagine that we had omitted the transitivity and symmetry rules for judgemental equality. Devise a single rule that handles both transitivity and symmetry simultaneously.
Exercise. Dependent types I › The unit type › Extensionality [01DN]
- August 11, 2025
- Jon Sterling
Show that the uniqueness rule is equivalent to the following extensionality rule that equates any two elements:
\frac {u,v:\mathsf {unit}}{u\equiv v:\mathsf {unit}}Exercise. Dependent types I › The empty type › Dependent elimination [01DC]
- August 11, 2025
- Jon Sterling
We can also consider a dependent elimination rule for the empty type, where we allow C to depend on an element of the empty type; show that the following can be derived from the simple elimination rule, filling in the question marks:
\frac { x:\mathsf {empty}\vdash C[x]~\mathit {type} \quad u:\mathsf {empty} }{ ???:C[u] }Exercise. Dependent types I › The product of a family of types › Extensionality [01DJ]
- August 11, 2025
- Jon Sterling
Show that the uniqueness rule for the product {\mathop {\mathchoice {\textstyle \prod }{\textstyle \prod }{\scriptstyle \prod }{\scriptscriptstyle \prod } }_{(x:A)}}{B[x]} is equivalent to the following extensionality rule:
\frac { u,v:{\mathop {\mathchoice {\textstyle \prod }{\textstyle \prod }{\scriptstyle \prod }{\scriptscriptstyle \prod } }_{(x:A)}}{B[x]} \quad x:A\vdash ux\equiv vx:B[x] }{ u\equiv v:{\mathop {\mathchoice {\textstyle \prod }{\textstyle \prod }{\scriptstyle \prod }{\scriptscriptstyle \prod } }_{(x:A)}}{B[x]} }Exercise. Dependent types I › The sum of a family of types › Extensionality [01E6]
- August 11, 2025
- Jon Sterling
Show that the uniqueness rule for the sum {\mathop {\mathchoice {\textstyle \sum }{\textstyle \sum }{\scriptstyle \sum }{\scriptscriptstyle \sum } }_{(x:A)}}{B[x]} is equivalent to the following extensionality rule:
\frac { u,v:{\mathop {\mathchoice {\textstyle \sum }{\textstyle \sum }{\scriptstyle \sum }{\scriptscriptstyle \sum } }_{(x:A)}}{B[x]} \quad u.1\equiv v.1:A \quad u.2\equiv v.2:B[u.1] }{ u\equiv v:{\mathop {\mathchoice {\textstyle \sum }{\textstyle \sum }{\scriptstyle \sum }{\scriptscriptstyle \sum } }_{(x:A)}}{B[x]} }Exercise. Dependent types I › Identification types › Unicity of self-identifications [01EQ]
- August 11, 2025
- Jon Sterling
Using the elimination rule above, try to construct elements of the following types:
{\mathop {\mathchoice {\textstyle \prod }{\textstyle \prod }{\scriptstyle \prod }{\scriptscriptstyle \prod } }_{(u:A)}} {\mathop {\mathchoice {\textstyle \prod }{\textstyle \prod }{\scriptstyle \prod }{\scriptscriptstyle \prod } }_{(p:u=_Au)}} p=_{u=_Au}\mathsf {refl}_u {\mathop {\mathchoice {\textstyle \prod }{\textstyle \prod }{\scriptstyle \prod }{\scriptscriptstyle \prod } }_{(u,v:A)}} {\mathop {\mathchoice {\textstyle \prod }{\textstyle \prod }{\scriptstyle \prod }{\scriptscriptstyle \prod } }_{(p,q:u=_Av)}} p=_{u=_Av}qWhat goes wrong? What do you think this implies about the notion of “sameness” that we get from identification types?
Exercise. Dependent types I › Identification types › Unbiased elimination rule (extremely hard!) [01EE]
- August 11, 2025
- Jon Sterling
Prove that the elimination and computation rules for the identification type are equivalent to the following “unbiased” ones that do not fix u outside of the family C:
\frac { w:u=_A v\quad x:A,y:A,z:x=_Ay\vdash C[x,y,z]~\mathit {type}\quad x:A\vdash c[x]:C[x,x,\mathsf {refl}_u] \quad }{ \mathsf {J}'_{x,y,z\mathpunct {.}C[x,y,z]}(w; x\mathpunct {.} c[x]) : C[u,v,w] } \frac { u:A\quad x:A,y:A,z:x=_Ay\vdash C[x,y,z]~\mathit {type}\quad x:A\vdash c[x]:C[x,x,\mathsf {refl}_x] \quad }{ \mathsf {J}'_{x,y,z\mathpunct {.}C[x,y,z]}(\mathsf {refl}_u; x\mathpunct {.}{c[x]}) \equiv c[u] :C[u,u,\mathsf {refl}_u] }Explicitly, you are being asked to use \mathsf {J} to define \mathsf {J}' and vice versa. This exercise is extremely difficult, so don’t waste too much time on it.