4th March 2019, version of 17 August 2020, 22:21.

Martín Hötzel Escardó, School of Computer Science, University of Birmingham, UK.

Table of contents ⇓

Abstract. We introduce Voevodsky’s univalent foundations and univalent mathematics, and explain how to develop them with the computer system Agda, which is based on Martin-Löf type theory. Agda allows us to write mathematical definitions, constructions, theorems and proofs, for example in number theory, analysis, group theory, topology, category theory or programming language theory, checking them for logical and mathematical correctness.

Agda is a constructive mathematical system by default, which amounts to saying that it can also be considered as a programming language for manipulating mathematical objects. But we can assume the axiom of choice or the principle of excluded middle for pieces of mathematics that require them, at the cost of losing the implicit programming-language character of the system. For a fully constructive development of univalent mathematics in Agda, we would need to use its new cubical flavour, and we hope these notes provide a base for researchers interested in learning cubical type theory and cubical Agda as the next step.

Compared to most expositions of the subject, we work with explicit universe levels.

We also fully discuss and emphasize that non-constructive classical axioms can be assumed consistently in univalent mathematics.

Keywords. Univalent mathematics. Univalent foundations. Univalent type theory. Univalence axiom. ∞ -Groupoid. Homotopy type. Type theory. Homotopy type theory. HoTT/UF. Intensional Martin-Löf type theory. Dependent type theory. Identity type. Type universe. Constructive mathematics. Agda. Cubical type theory. Cubical Agda. Computer-verified mathematics.

About this document. This is a set of so-called literate Agda files, with the formal, verified, mathematical development within code environments, and the usual mathematical discussion outside them. Most of this file is not Agda code, and is in markdown format, and the html web page is generated automatically from it using Agda and other tools. Github issues or pull requests by students to fix typos or mistakes and clarify ambiguities are welcome. There is also a pdf version with internal links to sections and Agda definitions, which is automatically generated from the html version. And a pdf version is also available at the arxiv, updated from time to time.

These notes were originally developed for the Midlands Graduate School 2019. They will evolve for a while.

Table of contents ⇓

Introduction

A univalent type theory is the underlying formal system for a foundation of univalent mathematics as conceived by Voevodsky.

In the same way as there isn’t just one set theory (we have e.g. ZFC and NBG among others), there isn’t just one univalent type theory (we have e.g. the underlying type theory used in UniMath, HoTT-book type theory, and cubical type theory, among others, and more are expected to come in the foreseeable future before the foundations of univalent mathematics stabilize).

The salient differences between univalent mathematics and traditional, set-based mathematics may be shocking at first sight:

The kinds of objects we take as basic. Certain things called types, or higher groupoids, rather than sets, are the primitive objects.

Sets, also called 0-groupoids, are particular kinds of types.

So we have more general objects as a starting point.

E.g. the type ℕ of natural numbers is a set, and this is a theorem, not a definition.

of natural numbers is a set, and this is a theorem, not a definition. E.g. the type of monoids is not a set, but instead a 1 -groupoid, automatically.

-groupoid, automatically. E.g. the type of categories is a 2 -groupoid, again automatically. The treatment of logic. Mathematical statements are interpreted as types rather than truth values.

Truth values are particular kinds of types, called -1 -groupoids, with at most one element.

-groupoids, with at most one element. Logical operations are particular cases of mathematical operations on types.

The mathematics comes first, with logic as a derived concept.

E.g. when we say “and”, we are taking the cartesian product of two types, which may or may not be truth values. The treatment of equality. The value of an equality x ≡ y is a type, called the identity type, which is not necessarily a truth value.

is a type, called the identity type, which is not necessarily a truth value. It collects the ways in which the mathematical objects x and y are identified.

and are identified. E.g. it is a truth value for elements of ℕ , as there is at most one way for two natural numbers to be equal.

, as there is at most one way for two natural numbers to be equal. E.g. for the type of monoids, it is a set, amounting to the type of monoid isomorphisms, automatically.

E.g. for the type of categories, it is a 1 -groupoid, amounting to the type of equivalences of categories, again automatically.

The important word in the above description of univalent foundations is automatic. For example, we don’t define equality of monoids to be isomorphism. Instead, we define the collection of monoids as the large type of small types that are sets, equipped with a binary multiplication operation and a unit satisfying associativity of multiplication and neutrality of the unit in the usual way, and then we prove that the native notion of equality that comes with univalent type theory (inherited from Martin-Löf type theory) happens to coincide with the notion of monoid isomorphism. Largeness and smallness are taken as relative concepts, with type universes incorporated in the theory to account for the size distinction.

In particular, properties of monoids are automatically invariant under isomorphism, properties of categories are automatically invariant under equivalence, and so on.

Voevodsky’s way to achieve this is to start with a Martin-Löf type theory (MLTT), including identity types and type universes, and postulate a single axiom, named univalence. This axiom stipulates a canonical bijection between type equivalences (in a suitable sense defined by Voevodsky in type theory) and type identifications (in the original sense of Martin-Löf’s identity type). Voevodsky’s notion of type equivalence, formulated in MLTT, is a refinement of the notion of isomorphism, which works uniformly for all higher groupoids, i.e. types.

In particular, Voevodsky didn’t design a new type theory, but instead gave an axiom for an existing type theory (or any of a family of possible type theories, to be more precise).

The main technical contributions in type theory by Voevodsky are:

The definition of type levels in MLTT, classifying them as n-groupoids including the possibility n=∞. The (simple and elegant) definition of type equivalence that works uniformly for all type levels in MLTT. The formulation of the univalence axiom in MLTT.

Univalent mathematics begins within MLTT with (4) and (5) before we postulate univalence. In fact, as the reader will see, we will do a fair amount of univalent mathematics before we formulate or assume the univalence axiom.

All of (4)-(6) crucially rely on Martin-Löf’s identity type. Initially, Voevodsky thought that a new concept would be needed in the type theory to achieve (4)-(6) and hence (1) and (3) above. But he eventually discovered that Martin-Löf’s identity type is precisely what he needed.

It may be considered somewhat miraculous that the addition of the univalence axiom alone to MLTT can achieve (1) and (3). Martin-Löf type theory was designed to achieve (2), and, regarding (1), types were imagined/conceived as sets (and even named sets in some of the original expositions by Martin-Löf), and, regarding (3), the identity type was imagined/conceived as having at most one element, even if MLTT cannot prove or disprove this statement, as was eventually shown by Hofmann and Streicher with their groupoid model of types in the early 1990’s.

Another important aspect of univalent mathematics is the presence of explicit mechanisms for distinguishing

property (e.g. an unspecified thing exists), data or structure (e.g. a designated thing exists or is given),

which are common place in current mathematical practice (e.g. cartesian closedness of a category is a property in some sense (up to isomorphism), whereas monoidal closedness is given structure).

In summary, univalent mathematics is characterized by (1)-(8) and not by the univalence axiom alone. In fact, half of these notes begin without the univalence axiom.

Lastly, univalent type theories don’t assume the axiom of choice or the principle of excluded middle, and so in some sense they are constructive by default. But we emphasize that these two axioms are consistent and hence can be safely used as assumptions. However, virtually all theorems of univalent mathematics, e.g. in UniMath, have been proved without assuming them, with natural mathematical arguments. The formulations of these principles in univalent mathematics differ from their traditional formulations in MLTT, and hence we sometimes refer to them as the univalent principle of excluded middle and the univalent axiom of choice.

In these notes we will explore the above ideas, using Agda to write MLTT definitions, constructions, theorems and proofs, with univalence as an explicit assumption each time it is needed. We will have a further assumption, the existence of certain subsingleton (or propositional, or truth-value) truncations in order to be able to deal with the distinction between property and data, and in particular with the distinction between designated and unspecified existence (for example to be able to define the notions of image of a function and of surjective function).

We will not assume univalence and truncation globally, so that the students can see clearly when they are or are not needed. In fact, the foundational definitions, constructions, theorems and proofs of univalent mathematics don’t require univalence or propositional truncation, and so can be developed in a version of the original Martin-Löf type theories, and this is what happens in these notes, and what Voevodsky did in his brilliant original development in the computer system Coq. Our use of Agda, rather than Coq, is a personal matter of taste only, and the students are encouraged to learn Coq, too.

Table of contents ⇓

Homotopy type theory

Univalent type theory is often called homotopy type theory. Here we are following Voevodsky, who coined the phrases univalent foundations and univalent mathematics. We regard the terminology homotopy type theory as probably more appropriate for referring to the synthetic development of homotopy theory within univalent mathematics, for which we refer the reader to the HoTT book.

However, the terminology homotopy type theory is also used as a synonym for univalent type theory, not only because univalent type theory has a model in homotopy types (as defined in homotopy theory), but also because, without considering models, types do behave like homotopy types, automatically. We will not discuss how to do homotopy theory using univalent type theory in these notes. We refer the reader to the HoTT book as a starting point.

A common compromise is to refer to the subject as HoTT/UF.

Table of contents ⇓

General references

Papers by Martin-Löf.

Homotopy type theory website references.

HoTT book.

ncatlab references.

In particular, it is recommended to read the concluding notes for each chapter in the HoTT book for discussion of original sources. Moreover, the whole HoTT book is a recommended complementary reading for this course.

And, after the reader has gained enough experience:

Regarding the computer language Agda, we recommend the following as starting points:

Regarding the genesis of the subject:

Voevodsky says that he was influenced by Makkai’s thinking:

An important foundational reference, by Steve Awodey and Michael A. Warren, is

Additional expository material:

More references as clickable links are given in the course of the notes.

We also have an Agda development of univalent foundations which is applied to work on injective types, compact (or searchable) types, compact ordinals and more.

Table of contents ⇓

Choice of material

This is intended as an introductory graduate course. We include what we regard as the essence of univalent foundations and univalent mathematics, but we are certainly omitting important material that is needed to do univalent mathematics in practice, and the readers who wish to practice univalent mathematics should consult the above references.

Table of contents

Table of contents ⇑

MLTT in Agda

What is Agda?

There are two views:

Agda is a dependently-typed functional programming language. Agda is a language for defining mathematical notions (e.g. group or topological space), formulating constructions to be performed (e.g. a type of real numbers, a group structure on the integers, a topology on the reals), formulating theorems (e.g. a certain construction is indeed a group structure, there are infinitely many primes), and proving theorems (e.g. the infinitude of the collection of primes with Euclid’s argument).

This doesn’t mean that Agda has two sets of features, one for (1) and the other for (2). The same set of features account simultaneously for (1) and (2). Programs are mathematical constructions that happen not to use non-constructive principles such as excluded middle.

In these notes we study a minimal univalent type theory and do mathematics with it using a minimal subset of the computer language Agda as a vehicle.

Agda allows one to construct proofs interactively, but we will not discuss how to do this in these notes. Agda is not an automatic theorem prover. We have to come up with our own proofs, which Agda checks for correctness. We do get some form of interactive help to input our proofs and render them as formal objects.

Table of contents ⇑

A spartan Martin-Löf type theory (MLTT)

Before embarking into a full definition of our Martin-Löf type theory in Agda, we summarize the particular Martin-Löf type theory that we will consider, by naming the concepts that we will include. We will have:

An empty type 𝟘 .

A one-element type 𝟙 .

A type of ℕ natural numbers.

Type formers + (binary sum), Π (product), Σ (sum), Id (identity type).

Universes (types of types), ranged over by 𝓤,𝓥,𝓦 .

This is enough to do number theory, analysis, group theory, topology, category theory and more.

spartan /ˈspɑːt(ə)n/ adjective:

showing or characterized by austerity or a lack of comfort or luxury.

We will also be rather spartan with the subset of Agda that we choose to discuss. Many things we do here can be written in more concise ways using more advanced features. Here we introduce a minimal subset of Agda where everything in our spartan MLTT can be expressed.

Table of contents ⇑

Getting started with Agda

We don’t use any Agda library. For pedagogical purposes, we start from scratch, and here are our first two lines of code:

The option --without-K disables Streicher’s K axiom, which we don’t want for univalent mathematics.

The option --exact-split makes Agda to only accept definitions with the equality sign “ = ” that behave like so-called judgmental or definitional equalities.

The option --safe disables features that may make Agda inconsistent, such as --type-in-type , postulates and more.

Every Agda file is a module. These lecture notes are a set of Agda files, which are converted to html by Agda after it successfully checks the mathematical development for correctness.

The Agda code in these notes has syntax highlighting and links (in the html and pdf versions), so that we can navigate to the definition of a name or symbol by clicking at it.

Table of contents ⇑

Type universes

A universe 𝓤 is a type of types.

One use of universes is to define families of types indexed by a type X as functions X → 𝓤 . Such a function is sometimes seen as a property of elements of X . Another use of universes, as we shall see, is to define types of mathematical structures, such as monoids, groups, topological spaces, categories etc.

Sometimes we need more than one universe. For example, the type of groups in a universe lives in a bigger universe, and given a category in one universe, its presheaf category also lives in a larger universe.

We will work with a tower of type universes

𝓤₀, 𝓤₁, 𝓤₂, 𝓤₃, ...

In practice, the first one, two or three universes suffice, but it will be easier to formulate definitions, constructions and theorems in full generality, to avoid making universe choices before knowing how they are going to be applied.

These are actually universe names (also called levels, not to be confused with hlevels). We reference the universes themselves by a deliberately almost-invisible superscript dot. For example, we will have

𝟙 : 𝓤₀ ̇

where 𝟙 is the one-point type to be defined shortly. We will sometimes omit this superscript in our discussions, but are forced to write it in Agda code. We have that the universe 𝓤₀ is a type in the universe 𝓤₁ , which is a type in the universe 𝓤₂ and so on.

𝓤₀ ̇ : 𝓤₁ ̇

𝓤₁ ̇ : 𝓤₂ ̇

𝓤₂ ̇ : 𝓤₃ ̇

⋮

The assumption that 𝓤₀ : 𝓤₀ or that any universe is in itself or a smaller universe gives rise to a contradiction, similar to Russell’s Paradox.

Given a universe 𝓤 , we denote by

𝓤 ⁺

its successor universe. For example, if 𝓤 is 𝓤₀ then 𝓤 ⁺ is 𝓤₁ . According to the above discussion, we have

𝓤 ̇ : 𝓤 ⁺ ̇

The least upper bound of two universes 𝓤 and 𝓥 is written

𝓤 ⊔ 𝓥 .

For example, if 𝓤 is 𝓤₀ and 𝓥 is 𝓤₁ , then 𝓤 ⊔ 𝓥 is 𝓤₁ .

We now bring our notation for universes by importing our Agda file Universes . The Agda keyword open asks to make all definitions in the file Universe visible in our file here.

The keyword public makes the contents of the file Universes available to importers of our module HoTT-UF-Agda .

We will refer to universes by letters 𝓤,𝓥,𝓦,𝓣 :

In some type theories, the universes are cumulative “on the nose”, in the sense that from X : 𝓤 we derive that X : 𝓤 ⊔ 𝓥 . We will instead have an embedding 𝓤 → 𝓤 ⊔ 𝓥 of universes into larger universes.

Table of contents ⇑

The one-element type 𝟙

We place it in the first universe, and we name its unique element “ ⋆ ”. We use the data declaration in Agda to introduce it:

It is important that the point ⋆ lives in the type 𝟙 and in no other type. There isn’t dual citizenship in our type theory. When we create a type, we also create freshly new elements for it, in this case “ ⋆ ”. (However, Agda has a limited form of overloading, which allows us to sometimes use the same name for different things.)

Next we want to give a mechanism to prove that all points of the type 𝟙 satisfy a given property A .

The property is a function A : 𝟙 → 𝓤 for some universe 𝓤 . The type A(x) , which we will write simply A x , doesn’t need to be a truth value. It can be any type. We will meet examples shortly. In MLTT, mathematical statements are types, such as Π A : 𝟙 → 𝓤, A ⋆ → Π x : 𝟙, A x . We read this in natural language as “for any given property A of elements of the type 𝟙 , if A ⋆ holds, then it follows that A x holds for all x : 𝟙 ”. In Agda, the above type is written as (A : 𝟙 → 𝓤 ̇ ) → A ⋆ → (x : 𝟙) → A x . This is the type of functions with three arguments A : 𝟙 → 𝓤 ̇ and a : A ⋆ and x : 𝟙 , with values in the type A x . A proof of a mathematical statement rendered as a type is a construction of an element of the type. In our example, we have to construct a function, which we will name 𝟙-induction .

We do this as follows in Agda, where we first declare the type of the function 𝟙-induction with “ : ” and then define the function by an equation:

The universe 𝓤 is arbitrary, and Agda knows 𝓤 is a universe variable because we said so above.

Notice that we supply A and a as arbitrary arguments, but instead of an arbitrary x : 𝟙 we have written “ ⋆ ”. Agda accepts this because it knows from the definition of 𝟙 that “ ⋆ ” is the only element of the type 𝟙 . This mechanism is called pattern matching.

A particular case of 𝟙-induction occurs when the family A is constant with value B , which can be written variously as

A x = B

or

A = λ (x : 𝟙) → B ,

or

A = λ x → B

if we want Agda to figure out the type of x by itself, or

A = λ _ → B

if we don’t want to name the argument of A because it is not used. In usual mathematical practice, such a lambda expression is often written

x ↦ B ( x is mapped to B )

so that the above amount to A = (x ↦ B) .

Given a type B and a point b : B , we construct the function 𝟙 → B that maps any given x : 𝟙 to b .

The above expression B → (𝟙 → B) can be written as B → 𝟙 → B , omitting the brackets, as the function-type formation symbol → is taken to be right associative.

Not all types have to be seen as mathematical statements (for example the type ℕ of natural numbers defined below). But the above definition has a dual interpretation as a mathematical function, and as the statement “ B implies (true implies B )” where 𝟙 is the type encoding the truth value true.

The unique function to 𝟙 will be named !𝟙 . We define two versions to illustrate implicit arguments, which correspond in mathematics to “subscripts that are omitted when the reader can safely infer them”, as for example for the identity function of a set or the identity arrow of an object of a category.

This means that when we write

!𝟙 x

we have to recover the (uniquely determined) missing type X with x : X “from the context”. When Agda can’t figure it out, we need to supply it and write

!𝟙 {𝓤} {X} x .

This is because 𝓤 is also an implicit argument (all things declared with the Agda keyword variable as above are implicit arguments). There are other, non-positional, ways to indicate X without having to indicate 𝓤 too. Occasionally, people define variants of a function with different choices of “implicitness”, as above.

Table of contents ⇑

The empty type 𝟘

It is defined like 𝟙 , except that no elements are listed for it:

That’s the complete definition. This has a dual interpretation, mathematically as the empty set (we can actually prove that this type is a set, once we know the definition of set), and logically as the truth value false. To prove that a property of elements of the empty type holds for all elements of the empty type, we have to do nothing.

When we write the pattern () , Agda checks if there is any case we missed. If there is none, our definition is accepted. The expression () corresponds to the mathematical phrase vacuously true. The unique function from 𝟘 to any type is a particular case of 𝟘-induction .

We will use the following categorical notation for 𝟘-recursion :

We give the two names is-empty and ¬ to the same function now:

This says that a type is empty precisely when we have a function to the empty type. Assuming univalence, once we have defined the identity type former _≡_ , we will be able to prove that (is-empty X) ≡ (X ≃ 𝟘) , where X ≃ 𝟘 is the type of bijections, or equivalences, from X to 𝟘 . We will also be able to prove things like (2 + 2 ≡ 5) ≡ 𝟘 and (2 + 2 ≡ 4) ≡ 𝟙 .

This is for numbers. If we define types 𝟚 = 𝟙 + 𝟙 and 𝟜 = 𝟚 + 𝟚 with two and four elements respectively, where we are anticipating the definition of _+_ for types, then we will instead have that 𝟚 + 𝟚 ≡ 𝟜 is a type with 4! elements, which is the number of permutations of a set with four elements, rather than a truth value 𝟘 or 𝟙 , as a consequence of the univalence axiom. That is, we will have (𝟚 + 𝟚 ≡ 𝟜) ≃ (𝟜 + 𝟜 + 𝟜 + 𝟜 + 𝟜 + 𝟜) , so that the type identity 𝟚 + 𝟚 ≡ 𝟜 holds in many more ways than the numerical equation 2 + 2 ≡ 4 .

The above is possible only because universes are genuine types and hence their elements (that is, types) have identity types themselves, so that writing X ≡ Y for types X and Y (inhabiting the same universe) is allowed.

When we view 𝟘 as false, we can read the definition of the negation ¬ X as saying that “ X implies false”. With univalence we will be able to show that “(false → true) ≡ true”, which amounts to (𝟘 → 𝟙) ≡ 𝟙 , which in turn says that there is precisely one function 𝟘 → 𝟙 , namely the (vacuous) function.

Table of contents ⇑

The type ℕ of natural numbers

The definition is similar but not quite the same as the one via Peano Axioms.

We stipulate an element zero : ℕ and a successor function succ : ℕ → ℕ , and then define induction. Once we have defined the identity type former _≡_ , we will prove the other peano axioms.

In general, declarations with data are inductive definitions. To write the number 5 , we have to write

succ (succ (succ (succ (succ zero))))

We can use the following Agda built-in to be able to just write 5 as a shorthand:

Apart from this notational effect, the above declaration doesn’t play any role in the Agda development of these lecture notes.

In the following, the type family A can be seen as playing the role of a property of elements of ℕ , except that it doesn’t need to be necessarily subsingleton valued. When it is, the type of the function gives the familiar principle of mathematical induction for natural numbers, whereas, in general, its definition says how to compute with induction.

The definition of ℕ-induction is itself by induction. It says that given a point

a₀ : A 0

and a function

f : (n : ℕ) → A n → A (succ n) ,

in order to calculate an element of A n for a given n : ℕ , we just calculate h n , that is,

f n (f (n-1) (f (n-2) (... (f 0 a₀)...))) .

So the principle of induction is a construction that given a base case a₀ : A 0 , an induction step f : (n : ℕ) → A n → A (succ n) and a number n , says how to get an element of the type A n by primitive recursion.

Notice also that ℕ-induction is the dependently typed version of primitive recursion, where the non-dependently typed version is

The following special case occurs often (and is related to the fact that ℕ is the initial algebra of the functor 𝟙 + (-) ):

Agda checks that any recursive definition as above is well founded, with recursive invocations with structurally smaller arguments only. If it isn’t, the definition is not accepted.

In official Martin-Löf type theories, we have to use the ℕ-induction functional to define everything else with the natural numbers. But Agda allows us to define functions by structural recursion, like we defined ℕ-induction .

We now define addition and multiplication for the sake of illustration. We first do it in Peano style. We will create a local module so that the definitions are not globally visible, as we want to have the symbols + and × free for type operations of MLTT to be defined soon. The things in the module are indented and are visible outside the module only if we open the module or if we write them as e.g. Arithmetic._+_ in the following example.

The above “fixity” declarations allow us to indicate the precedences (multiplication has higher precedence than addition) and their associativity (here we take left-associativity as the convention, so that e.g. x+y+z parses as (x+y)+z ).

Equivalent definitions use ℕ-induction on the second argument y , via ℕ-iteration :

Here the expression “ x +_ ” stands for the function ℕ → ℕ that adds x to its argument. So to multiply x by y , we apply y times the function “ x +_ ” to 0 .

As another example, we define the less-than-or-equal relation by nested induction, on the first argument and then the second, but we use pattern matching for the sake of readability.

Exercise. Write it using ℕ-induction , recursion or iteration, as appropriate.

Exercise. After learning Σ and _≡_ explained below, prove that

x ≤ y if and only if Σ z ꞉ ℕ , x + z ≡ y .

Later, after learning univalence prove that in this case this implies

(x ≤ y) ≡ Σ z ꞉ ℕ , x + z ≡ y .

That bi-implication can be turned into equality only holds for types that are subsingletons (and this is called propositional extensionality).

If we are doing applied mathematics and want to actually compute, we can define a type for binary notation for the sake of efficiency, and of course people have done that. Here we are not concerned with efficiency but only with understanding how to codify mathematics in (univalent) type theory and in Agda.

Table of contents ⇑

The binary sum type constructor _+_

We now define the disjoint sum of two types X and Y . The elements of the type

X + Y

are stipulated to be of the forms

inl x and inr y

with x : X and y : Y . If X : 𝓤 and Y : 𝓥 , we stipulate that X + Y : 𝓤 ⊔ 𝓥 , where

𝓤 ⊔ 𝓥

is the least upper bound of the two universes 𝓤 and 𝓥 . In Agda we can define this as follows.

To prove that a property A of the sum holds for all z : X + Y , it is enough to prove that A (inl x) holds for all x : X and that A (inr y) holds for all y : Y . This amounts to definition by cases:

When the types A and B are understood as mathematical statements, the type A + B is understood as the statement “ A or B ”, because to prove “ A or B ” we have to prove one of A and B . When A and B are simultaneously possible, we have two proofs, but sometimes we want to deliberately ignore which one we get, when we want to get a truth value rather than a possibly more general type, and in this case we use the truncation ∥ A + B ∥ .

But also _+_ is used to construct mathematical objects. For example, we can define a two-point type:

We can name the left and right points as follows, using patterns, so that they can be used in pattern matching:

We can define induction on 𝟚 directly by pattern matching:

Or we can prove it by induction on _+_ and 𝟙 :

Table of contents ⇑

Σ types

Given universes 𝓤 and 𝓥 , a type

X : 𝓤

and a type family

Y : X → 𝓥 ,

we want to construct its sum, which is a type whose elements are of the form

(x , y)

with x : X and y : Y x . This sum type will live in the least upper bound

𝓤 ⊔ 𝓥

of the universes 𝓤 and 𝓥 . We will write this sum

Σ Y ,

with X , as well as the universes, implicit. Often Agda, and people, can figure out what the unwritten type X is, from the definition of Y . But sometimes there may be either lack of enough information, or of enough concentration power by people, or of sufficiently powerful inference algorithms in the implementation of Agda. In such cases we can write

Σ λ(x : X) → Y x ,

because Y = λ (x : X) → Y x by a so-called η-rule. However, we will define syntax to be able to write this in more familiar form as

Σ x ꞉ X , Y x .

In MLTT we can write this in other ways, for example with the indexing x : X written as a subscript of Σ or under it.

Or it may be that the name Y is not defined, and we work with a nameless family defined on the fly, as in the exercise proposed above:

Σ z ꞉ ℕ , x + z ≡ y ,

where Y z = (x + z ≡ y) in this case, and where we haven’t defined the identity type former _≡_ yet.

We can construct the Σ type former as follows in Agda:

This says we are defining a binary operator _,_ to construct the elements of this type as x , y . The brackets are not needed, but we will often write them to get the more familiar notation (x , y) . The definition says that an element of Σ Y has two fields , giving the types for them.

Remark. Beginners may safely ignore this remark: Normally people will call these two fields x and y something like pr₁ and pr₂ , or fst and snd , for first and second projection, rather than x and y , and then do open Σ public and have the projections available as functions automatically. But we will deliberately not do that, and instead define the projections ourselves, because this is confusing for beginners, no matter how mathematically or computationally versed they may be, in particular because it will not be immediately clear that the projections have the following types.

We now introduce syntax to be able to write Σ x ꞉ X , y instead of Σ λ(x ꞉ X) → y . For this purpose, we first define a version of Σ making the index type explicit.

For some reason, Agda has this kind of definition backwards: the definiendum and the definiens are swapped with respect to the normal convention of writing what is defined on the left-hand side of the equality sign.

Notice also that “꞉” in the above syntax definition is not the same as “:”, even though they may look the same. For the above notation Σ x ꞉ A , b , the symbol “꞉” has to be typed “\:4” in the emacs Agda mode.

To prove that A z holds for all z : Σ Y , for a given property A , we just prove that we have A (x , y) for all x : X and y : Y x . This is called Σ induction or Σ elimination, or uncurry , after Haskell Curry.

This function has an inverse:

An important particular case of the sum type is the binary cartesian product, when the type family doesn’t depend on the indexing type:

We have seen by way of examples that the function type symbol → represents logical implication, and that a dependent function type (x : X) → A x represents a universal quantification.

We have the following uses of Σ .

The binary cartesian product represents conjunction “and”. If the types A and B stand for mathematical statements, then the mathematical statement A and B is codified as A × B , because to establish “ A and B ”, we have to provide a pair (a , b) of proofs a : A and b : B . So notice that in type theory proofs are mathematical objects, rather than meta-mathematical entities like in set theory. They are just elements of types. The more general type Σ x : X , A x , if the type X stands for a mathematical object and A stands for a mathematical statement, represents designated existence there is a designated x : X with A x . To establish this, we have to provide a specific element x : X and a proof a : A x , together in a pair (x , a) . Later we will discuss unspecified existence ∃ x : X , A x , which will be obtained by a sort of quotient of Σ x : X , A x , written ∥ Σ x : X , A x ∥ , that identifies all the elements of the type Σ x : X , A x in a single equivalence class, called its subsingleton (or truth value or propositional) truncation. Another reading of Σ x : X , A x is as the type of x : X with A x , similar to set-theoretical notation { x ∈ X | A x } . But we have to be careful because if there is more than one element in the type A x , then x will occur more than once in this type. More precisely, for a₀ a₁ : A x we have inhabitants (x , a₀) and (x , a₁) of the type Σ x : X , A x . In such situations, if we don’t want that, we have to either ensure that the type A x has at most one element for every x : X , or instead consider the truncated type ∥ A x ∥ and write Σ x : X , ∥ A x ∥ . An example is the image of a function f : X → Y , which will be defined to be Σ y : Y , ∥ Σ x : X , f x ≡ y ∥ . This is the type of y : Y for which there is an unspecified x : X with f x ≡ y . (For constructively minded readers, we emphasize that this doesn’t erase the witness x : X .)

Table of contents ⇑

Π types

Π types are builtin with a different notation in Agda, as discussed above, but we can introduce the notation Π for them, similar to that for Σ :

Notice that the function type X → Y is the particular case of the Π type when the family A is constant with value Y .

We take the opportunity to define the identity function (in two versions with different implicit arguments) and function composition:

Usually the type of function composition _∘_ is given as simply

(Y → Z) → (X → Y) → (X → Z) .

With dependent functions, we can give it a more general type:

Notice that this type for the composition function can be read as a mathematical statement: If Z y holds for all y : Y , then for any given f : X → Y we have that Z (f x) holds for all x : X . And the non-dependent one is just the transitivity of implication.

The following functions are sometimes useful when we are using implicit arguments, in order to recover them explicitly without having to list them as given arguments:

Table of contents ⇑

The identity type former Id , also written _≡_

We now introduce the central type constructor of MLTT from the point of view of univalent mathematics. In Agda we can define Martin-Löf’s identity type as follows:

Intuitively, the above definition would say that the only element of the type Id X x x is something called refl x (for reflexivity). But, as we shall see in a moment, this intuition turns out to be incorrect.

Notice a crucial difference with the previous definitions using data or induction: In the previous cases, we defined types, namely 𝟘 , 𝟙 , ℕ , or a type depending on type parameters, namely _+_ , with 𝓤 and 𝓥 fixed,

_+_ : 𝓤 ̇ → 𝓥 ̇ → 𝓤 ⊔ 𝓥 ̇

But here we are defining a type family indexed by the elements of a given type, rather than a new type from old types. Given a type X in a universe 𝓤 , we define a function

Id X : X → X → 𝓤

by some mysterious sort of induction. It is this that prevents us from being able to prove that the only element of the type Id X x x would be refl x , or that the type Id X x y would have at most one element no matter what y : X is.

There is however, one interesting, and crucial, thing we can prove, namely that for any fixed element x : X , the type

Σ y ꞉ Y , Id X x y

is always a singleton.

We will use the following alternative notation for the identity type former Id , where the symbol “ _ ” in the right-hand side of the definition indicates that we ask Agda to infer which type we are talking about (which is X , but this name is not available in the scope of the defining equation of the type former _≡_ ):

Another intuition for this type family _≡_ : X → X → 𝓤 is that it gives the least reflexive relation on the type X , as suggested by Martin-Löf’s induction principle J discussed below.

Whereas we can make the intuition that x ≡ x has precisely one element good by postulating a certain K axiom due to Thomas Streicher, which comes with Agda by default but we have disabled above, we cannot prove that refl x is the only element of x ≡ x for an arbitrary type X . This non-provability result was established by Hofmann and Streicher, by giving a model of type theory in which types are interpreted as 1 -groupoids. This is in spirit similar to the non-provability of the parallel postulate in Euclidean geometry, which also considers models, which in turn are interesting in their own right.

However, for the elements of some types, such as the type ℕ of natural numbers, it is possible to prove that any identity type x ≡ y has at most one element. Such types are called sets in univalent mathematics.

If instead of the axiom K we adopt Voevodsky’s univalence axiom, we get specific examples of objects x and y such that the type x ≡ y has multiple elements, within the type theory. It follows that the identity type x ≡ y is fairly under-specified in general, in that we can’t prove or disprove that it has at most one element.

There are two opposing ways to resolve the ambiguity or under-specification of the identity types: (1) We can consider the K axiom, which postulates that all types are sets, or (2) we can consider the univalence axiom, arriving at univalent mathematics, which gives rise to types that are more general than sets, the n -groupoids and ∞ -groupoids. In fact, the univalence axiom will say, in particular, that for some types X and elements x y : X , the identity type x ≡ y does have more than one element.

A possible way to understand the element refl x of the type x ≡ x is as the “generic identification” between the point x and itself, but which is by no means necessarily the only identitification in univalent foundations. It is generic in the sense that to explain what happens with all identifications p : x ≡ y between any two points x and y of a type X , it suffices to explain what happens with the identification refl x : x ≡ x for all points x : X . This is what the induction principle for identity given by Martin-Löf says, which he called J (we could have called it ≡-induction , but we prefer to honour MLTT tradition):

This is related to the Yoneda Lemma in category theory, for readers familiar with the subject, which says that certain natural transformations are uniquely determined by their action on the identity arrows, even if they are defined for all arrows. Similarly here, 𝕁 is uniquely determined by its action on reflexive identifications, but is defined for all identifications between any two points, not just reflexivities.

In summary, Martin-Löf’s identity type is given by the data

Id ,

, refl ,

, 𝕁 ,

, the above equation for 𝕁 .

However, we will not always use this induction principle, because we can instead work with the instances we need by pattern matching on refl (which is just what we did to define the principle itself) and there is a theorem by Jesper Cockx that says that with the Agda option without-K , pattern matching on refl can define/prove precisely what 𝕁 can.

Exercise. Define

Then we can define 𝕁 from ℍ as follows:

Similarly define ℍ' from 𝕁 without using pattern matching on refl and show that it coincides with ℍ (possibly using pattern matching on refl ). This is harder.

Notational remark. The symbols “ = ” and “ ≡ ” are swapped with respect to the HoTT book convention for definitional/judgemental equality and type valued equality, and there is nothing we can do about that because “ = ” is a reserved Agda symbol for definitional equality. Irrespectively of this, it does make sense to use “ ≡ ” with a triple bar, if we understand this as indicating that there are multiple ways of identifying two things in general.

With this, we have concluded the rendering of our spartan MLTT in Agda notation. Before embarking on the development of univalent mathematics within our spartan MLTT, we pause to discuss some basic examples of mathematics in Martin-Löf type theory.

Table of contents ⇑

Basic constructions with the identity type

Transport along an identification.

We can equivalently define transport using 𝕁 as follows:

In the same way ℕ -recursion can be seen as the non-dependent special case of ℕ -induction, the following transport function can be seen as the non-dependent special case of the ≡ -induction principle ℍ with some of the arguments permuted and made implicit:

All the above transports coincide:

The following is for use when we want to recover implicit arguments without mentioning them.

Composition of identifications. Given two identifications p : x ≡ y and q : y ≡ z , we can compose them to get an identification p ∙ q : x ≡ z . This can also be seen as transitivity of equality. Because the type of composition doesn’t mention p and q , we can use the non-dependent version of ≡ -induction.

Here we are considering the family A t = (x ≡ t) , and using the identification q : y ≡ z to transport A y to A z , that is x ≡ y to x ≡ z .

Exercise. Can you define an alternative version that uses p to transport. Do the two versions give equal results?

When writing p ∙ q , we lose information on the lhs and the rhs of the identifications p : x ≡ y and q : y ≡ z , which makes some definitions hard to read. We now introduce notation to be able to write e.g.

x ≡⟨ p ⟩

y ≡⟨ q ⟩

z ∎

as a synonym of the expression p ∙ q with some of the implicit arguments of _∙_ made explicit. We have one ternary mixfix operator _≡⟨_⟩_ and one unary postfix operator _∎ .

Inversion of identifications. Given an identification, we get an identification in the opposite direction:

We can define an alternative of identification composition with this:

This agrees with the previous one:

But refl y is a definitional neutral element for one of them on the right and for the other one on the left,

p ∙ refl y = p ,

, refl y ∙' q = q ,

which can be checked as follows

Exercise. The identification refl y is neutral on both sides of each of the two operations _∙_ and _∙'_ , although not definitionally. This has to be proved by induction on identifications, as in ∙-agreement .

Application of a function to an identification. Given an identification p : x ≡ x' we get an identification ap f p : f x ≡ f x' for any f : X → Y :

Here the symbol “ - ”, which is not to be confused with the symbol “ _ ”, is a variable. We will adopt the convention in these notes of using this variable name “ - ” to make clear which part of an expression we are replacing with transport .

Notice that we have so far used the recursion principle transport only. To reason about transport , _∙_ , _⁻¹ and ap , we will need to use the full induction principle 𝕁 (or equivalently pattern matching on refl ).

Pointwise equality of functions. We will work with pointwise equality of functions, defined as follows, which, using univalence, will be equivalent to equality of functions.

The symbol ∀ is a built-in notation for Π . We could equivalently write the definiens as

(x : _) → f x ≡ g x ,

or, with our domain notation

(x : domain f) → f x ≡ g x .

Table of contents ⇑

Reasoning with negation

We first introduce notation for double and triple negation to avoid the use of brackets.

To prove that A → ¬¬ A , that is, A → ((A → 𝟘) → 𝟘) , we start with a hypothetical element a : A and a hypothetical function u : A → 𝟘 and the goal is to get an element of 𝟘 . All we need to do is to apply the function u to a . This gives double-negation introduction:

Mathematically, this says that if we have a point of A (we say that A is pointed) then A is nonempty. There is no general procedure to implement the converse, that is, from a function (A → 𝟘) → 𝟘 to get a point of A . For truth values A , we can assume this as an axiom if we wish, because it is equivalent to the principle excluded middle. For arbitrary types A , this would be a form of global choice for type theory. However, global choice is inconsistent with univalence [HoTT book, Theorem 3.2.2], because there is no way to choose an element of every non-empty type in a way that is invariant under automorphisms. But the axiom of choice is consistent with univalent type theory, as stated in the introduction.

In the proof of the following, we are given hypothetical functions f : A → B and v : B → 𝟘 , and a hypothetical element a : A , and our goal is to get an element of 𝟘 . But this is easy, because f a : B and hence v (f a) : 𝟘 .

We have given a logical name to this function. Mathematically, this says that if we have a function A → B and B is empty, then A must be empty, too. The proof is by assuming that A would have an inhabitant a , to get a contradiction, namely that B would have an inhabitant, too, showing that there can’t be any such inhabitant a of A after all. See Bauer for a general discussion.

And from this we get that three negations imply one:

Hence, using dni once again, we get that ¬¬¬ A if and only if ¬ A . It is entertaining to see how Brouwer formulated and proved this fact in his Cambridge Lectures on Intuitionism:

Theorem. Absurdity of absurdity of absurdity is equivalent to absurdity.

Proof. Firstly, since implication of the assertion 𝑦 by the assertion 𝑥 implies implication of absurdity of 𝑥 by absurdity of 𝑦, the implication of absurdity of absurdity by truth (which is an established fact) implies the implication of absurdity of truth, that is to say of absurdity, by absurdity of absurdity of absurdity. Secondly, since truth of an assertion implies absurdity of its absurdity, in particular truth of absurdity implies absurdity of absurdity of absurdity.

If we define logical equivalence by

then we can render Brouwer’s argument in Agda as follows, where the “established fact” is dni :

But of course Brouwer, as is well known, was averse to formalism, and hence wouldn’t approve of such a sacrilege.

We now define a symbol for the negation of equality.

In the following proof, we have u : x ≡ y → 𝟘 and need to define a function y ≡ x → 𝟘 . So all we need to do is to compose the function that inverts identifications with u :

To show that the type 𝟙 is not equal to the type 𝟘 , we use that transport id gives 𝟙 ≡ 𝟘 → id 𝟙 → id 𝟘 where id is the identity function of the universe 𝓤₀ . More generally, we have the following conversion of type identifications into functions:

Here the identity function is that of the universe 𝓤 where the types X and Y live. An equivalent definition is the following, where this time the identity function is that of the type X :

So if we have a hypothetical identification p : 𝟙 ≡ 𝟘 , then we get a function 𝟙 → 𝟘 . We apply this function to ⋆ : 𝟙 to conclude the proof.

To show that the elements ₁ and ₀ of the two-point type 𝟚 are not equal, we reduce to the above case. We start with a hypothetical identification p : ₁ ≡ ₀ .

Remark. Agda allows us to use a pattern () to get the following quick proof. However, this method of proof doesn’t belong to the realm of MLTT. Hence we will use the pattern () only in the above definition of 𝟘-induction and nowhere else in these notes.

Perhaps the following is sufficiently self-explanatory given the above:

So we consider four cases. In the first and the last, we have equal things and so we give an answer in the left-hand side of the sum. In the middle two, we give an answer in the right-hand side, where we need functions ₀ ≡ ₁ → 𝟘 and ₁ ≡ ₀ → 𝟘 , which we can take to be ≢-sym ₁-is-not-₀ and ₁-is-not-₀ respectively.

The following is more interesting. We consider the two possible cases for n . The first one assumes a hypothetical function f : ₀ ≡ ₀ → 𝟘 , from which we get f (refl ₀) : 𝟘 , and then, using !𝟘 , we get an element of any type we like, which we choose to be ₀ ≡ ₁ , and we are done. Of course, we will never be able to use the function not-zero-is-one with such outrageous arguments. The other case n = ₁ doesn’t need to use the hypothesis f : ₁ ≡ ₀ → 𝟘 , because the desired conclusion holds right away, as it is ₁ ≡ ₁ , which is proved by refl ₁ . But notice that there is nothing wrong with the hypothesis f : ₁ ≡ ₀ → 𝟘 . For example, we can use not-zero-is-one taking n to be ₀ and f to be ₁-is-not-₀ , so that the hypotheses can be fulfilled in the second equation.

The following generalizes ₁-is-not-₀ , both in its statement and its proof (so we could have formulated it first and then used it to deduce ₁-is-not-₀ ):

If P or Q holds and Q fails, then P holds:

Table of contents ⇑

Example: formulation of the twin-prime conjecture

We illustrate the above constructs of MLTT to formulate this conjecture.

Thus, not only can we write down definitions, constructions, theorems and proofs, but also conjectures. They are just definitions of types. Likewise, the univalence axiom, to be formulated in due course, is a type.

Table of contents ⇑

Remaining Peano axioms and basic arithmetic

We first prove the remaining Peano axioms.

To show that the successor function is left cancellable, we can use the following predecessor function.

With this we have proved all the Peano axioms.

Without assuming the principle of excluded middle, we can prove that ℕ has decidable equality:

Exercise. Students should do this kind of thing at least once in their academic life: rewrite the above proof of the decidability of equality of ℕ to use the ℕ-induction principle instead of pattern matching and recursion, to understand by themselves that this can be done.

We now move to basic arithmetic, and we use a module for that.

We can show that addition is associative as follows, by induction on z , where IH stands for “induction hypothesis”:

Notice that the proofs refl _ should be read as “by definition” or “by construction”. They are not necessary, because Agda knows the definitions and silently expands them when necessary, but we are writing them here for the sake of clarity. Here is the version with the silent expansion of definitions, for the sake of illustration (the author of these notes can write, but not read it the absence of the above verbose version):

We defined addition by induction on the second argument. Next we show that the base case and induction step of a definition by induction on the first argument hold (but of course not definitionally). We do this by induction on the second argument.

Using this, the commutativity of addition can be proved by induction on the first argument.

We now show that addition is cancellable in its left argument, by induction on the left argument:

Now we solve part of an exercise given above, namely that (x ≤ y) ⇔ Σ z ꞉ ℕ , x + z ≡ y .

First we name the alternative definition of ≤ :

Next we show that the two relations ≤ and ≼ imply each other.

In both cases, we proceed by induction on both arguments.

Later we will show that (x ≤ y) ≡ Σ z ꞉ ℕ , x + z ≡ y , using univalence.

We now develop some generally useful material regarding the order ≤ on natural numbers. First, it is reflexive, transitive and antisymmetric:

The type of roots of a function:

The type of minimal roots of a function:

Given any root, we can find a minimal root.

Table of contents ⇑

Univalent Mathematics in Agda

Our univalent type theory

A spartan MLTT as above.

Univalence axiom as below.

Subsingleton (or truth-value or propositional) truncations as below.

But, as discussed above, rather than postulating univalence and truncation, we will use them as explicit assumptions each time they are needed.

We emphasize that there are univalent type theories in which univalence and existence of truncations are theorems, for example cubical type theory, which has a version available in Agda, called cubical Agda.

Table of contents ⇑

Singletons, subsingletons and sets

Singleton (or contractible) types

Voevodsky defined a notion of contractible type, which we refer to here as singleton type.

Such an element c is called a center of contraction of X in connection with homotopy theory.

Once we have defined the notion of type equivalence, we will have that a type is a singleton if and only if it is equivalent to 𝟙 .

When working with singleton types, it will be convenient to have distinguished names for the two projections:

Subsingletons (or propositions or truth values)

A type is a subsingleton if it has at most one element, that is, any two of its elements are equal, or identified.

The terminology stands for subtype of a singleton and is justified by the fact that a type X is a subsingleton according to the above definition if and only if the map X → 𝟙 is an embedding, if and only if X is embedded into a singleton.

Under univalent excluded middle, the empty type 𝟘 and the singleton type 𝟙 are the only subsingletons, up to equivalence, or up to identity if we further assume univalence.

Subsingletons are also called propositions or truth values:

The terminology is-subsingleton is more mathematical and avoids the clash with the slogan propositions as types, which is based on the interpretation of mathematical statements as arbitrary types, rather than just subsingletons. In these notes we prefer the terminology subsingleton, but we occasionally use the terminologies proposition and truth value. When we wish to emphasize this notion of proposition adopted in univalent mathematics, as opposed to “propositions as (arbitrary) types”, we may say univalent proposition.

In some formal systems, for example set theory based on first-order logic, one can tell that something is a proposition by looking at its syntactical form, e.g. “there are infinitely many prime numbers” is a proposition, by construction, in such a theory.

In univalent mathematics, however, propositions are mathematical, rather than meta-mathematical, objects, and the fact that a type turns out to be a proposition requires mathematical proof. Moreover, such a proof may be subtle and not immediate and require significant preparation. An example is the proof that the univalence axiom is a proposition, which relies on the fact that univalence implies function extensionality, which in turn implies that the statement that a map is an equivalence is a proposition. Another non-trivial example, which again relies on univalence or at least function extensionality, is the proof that the statement that a type X is a proposition is itself a proposition, which can be written as is-prop (is-prop X) .

Singletons and subsingletons are also called -2-groupoids and -1-groupoids respectively.

Sets (or 0-groupoids)

A type is defined to be a set if there is at most one way for any two of its elements to be equal:

At this point, with the definition of these notions, we are entering the realm of univalent mathematics, but not yet needing the univalence axiom.

Table of contents ⇑

Univalent excluded middle

As mentioned above, under excluded middle, the only two subsingletons, up to equivalence, are 𝟘 and 𝟙 . In fact, excluded middle in univalent mathematics says precisely that.

Notice that the above two definitions don’t assert excluded middle, but instead say what excluded middle is (like when we said what the twin-prime conjecture is), in two logically equivalent ways:

We will not assume or deny excluded middle, which is an independent statement in our spartan univalent type theory - it can’t be proved or disproved, just as the parallel postulate in Euclidean geometry can’t be proved or disproved. We will deliberately keep it undecided, adopting a neutral approach to the constructive vs. non-constructive dichotomy. We will however prove a couple of consequences of excluded middle in discussions of foundational issues such as size and existence of subsingleton truncations. We will also prove that excluded middle is a consequence of the axiom of choice.

It should be emphasized that the potential failure of excluded middle doesn’t say that there may be mysterious subsingletons that fail to be singletons and also fail to be empty. No such things occur in mathematical nature:

Given this, what does the potential failure of excluded middle mean? That there is no general way, provided by our spartan univalent type theory, to determine which of the two cases is-singleton X and is-empty X applies for a given subsingleton X . This kind of phenomenon should be familiar even in classical, non-constructive mathematics: although we are entitled to believe that the Goldbach conjecture either holds or fails, we still don’t know which one is the case, despite efforts by the sharpest mathematical minds. A hypothetical element of the type EM would, in particular, be able to solve the Goldbach conjecture. There is nothing wrong or contradictory with assuming the existence of such a magic blackbox (EM stands for “there E xists such a M agic box”). There is only loss of generality and of the implicit algorithmic character of our spartan base type theory, both of which most mathematicians will be perfectly happy to live with.

In these notes we don’t advocate any particular philosophy for or against excluded middle and other non-constructive principles. We confine ourselves to discussing mathematical facts. Axioms that can be assumed consistently but reduce generality and/or break the implicit computational character of our base type theory are discussed at various parts of these lecture notes, and are summarized at the end.

Exercise. We also have that it is impossible for is-singleton X + is-empty X to fail for a given subsingleton X , which amounts to saying that

¬¬(is-singleton X + is-empty X)

always holds.

Occasionaly one hears people asserting that this says that the double negation of excluded middle holds. But this is incorrect. The above statement, when written in full, is

(X : 𝓤 ̇ ) → is-subsingleton X → ¬¬(is-singleton X + is-empty X) .

This is a theorem, which is quite different from the double negation of excluded middle, which is not a theorem and is

¬¬((X : 𝓤 ̇ ) → is-subsingleton X → is-singleton X + is-empty X) .

Just as excluded middle, this is an independent statement.

Exercise. Continued from the previous exercise. Also for any type R replacing the empty type, there is a function ((X + (X → R)) → R) → R , so that the kind of phenomenon illustrated in the previous exercise has little to do with the emptiness of the empty type.

Table of contents ⇑

The types of magmas and monoids

A magma is a set equipped with a binary operation subject to no laws [Bourbaki]. We can define the type of magmas in a universe 𝓤 as follows:

The type Magma 𝓤 collects all magmas in a universe 𝓤 , and lives in the successor universe 𝓤 ⁺ . Thus, this doesn’t define what a magma is as a property. It defines the type of magmas. A magma is an element of this type, that is, a triple (X , i , _·_) with X : 𝓤 and i : is-set X and _·_ : X → X → X .

Given a magma M = (X , i , _·_) we denote by ⟨ M ⟩ its underlying set X and by magma-operation M its multiplication _·_ :

The following syntax declaration allows us to write x ·⟨ M ⟩ y as an abbreviation of magma-operation M x y :

The point is that this time we need such a mechanism because in order to be able to mention arbitrary x and y , we first need to know their types, which is ⟨ M ⟩ and hence M has to occur before x and y in the definition of magma-operation . The syntax declaration circumvents this.

A function of the underlying sets of two magmas is a called a homomorphism when it commutes with the magma operations:

Any identification of magmas gives rise to a magma isomorphism by transport:

The isomorphisms can be collected in a type:

The following function will be a bijection in the presence of univalence, so that the identifications of magmas are in one-to-one correspondence with the magma isomorphisms:

If we omit the sethood condition in the definition of the type of magmas, we get the type of what we could call ∞ -magmas (then the type of magmas could be called 0-Magma ).

A monoid is a set equipped with an associative binary operation and with a two-sided neutral element, and so we get the type of monoids as follows.

We first define the three laws:

Then a monoid is a set equipped with such e and _·_ satisfying these three laws:

Remark. People are more likely to use records in Agda rather than iterated Σ s as above (recall that we defined Σ using a record). This is fine, because records amount to iterated Σ types (recall that also _×_ is a Σ type, by definition). Here, however, we are being deliberately spartan. Once we have defined our Agda notation for MLTT, we want to stick to it. This is for teaching purposes (of MLTT, encoded in Agda, not of Agda itself in its full glory).

We could drop the is-set X condition, but then we wouldn’t get ∞ -monoids in any reasonable sense. We would instead get “wild ∞ -monoids” or “incoherent ∞ -monoids”. The reason is that in monoids (with sets as carriers) the neutrality and associativity equations can hold in at most one way, by definition of set. But if we drop the sethood requirement, then the equations can hold in multiple ways. And then one is forced to consider equations between the identifications (all the way up in the ∞-case), which is what “coherence data” means. The wildness or incoherence amounts to the absence of such data.

Similarly to the situation with magmas, identifications of monoids are in bijection with monoid isomorphisms, assuming univalence. For this to be the case, it is absolutely necessary that the carrier of a monoid is a set rather than an arbitrary type, for otherwise the monoid equations can hold in many possible ways, and we would need to consider a notion of monoid isomorphism that in addition to preserving the neutral element and the multiplication, preserves the associativity identifications.

Exercise. Define the type of groups (with sets as carriers).

Exercise. Write down the various types of categories defined in the HoTT book in Agda.

Exercise. Try to define a type of topological spaces.

Table of contents ⇑

The identity type in univalent mathematics

We can view a type X as a sort of category with hom-types rather than hom-sets, with the identifications between points as the arrows.

We have that refl provides a neutral element for composition of identifications:

And composition is associative:

If we wanted to prove the above without pattern matching, this time we would need the dependent version 𝕁 of induction on _≡_ .

Exercise. Try to do this with 𝕁 and with ℍ .

But all arrows, the identifications, are invertible:

A category in which all arrows are invertible is called a groupoid. The above is the basis for the Hofmann–Streicher groupoid model of type theory.

But we actually get higher groupoids, because given identifications

p q : x ≡ y

we can consider the identity type p ≡ q , and given

u v : p ≡ q

we can consider the type u ≡ v , and so on. See [van den Berg and Garner] and [Lumsdaine].

For some types, such as the natural numbers, we can prove that this process trivializes after the first step, because the type x ≡ y has at most one element. Such types are the sets as defined above.

Voevodsky defined the notion of hlevel to measure how long it takes for the process to trivialize.

Here are some more constructions with identifications:

The application operation on identifications is functorial, in the sense that it preserves the neutral element and commutes with composition:

Notice that we also have

The above functions ap-refl and ap-∙ constitute functoriality in the second argument. We also have functoriality in the first argument, in the following sense:

Transport is also functorial with respect to identification composition and function composition. By construction, it maps the neutral element to the identity function. The apparent contravariance takes place because we have defined function composition in the usual order, but identification composition in the diagramatic order (as is customary in each case).

Functions of a type into a universe can be considered as generalized presheaves, which we could perhaps call ∞ -presheaves. Their morphisms are natural transformations:

We don’t need to specify the naturality condition, because it is automatic:

We will use the following constructions a number of times:

Table of contents ⇑

Identifications that depend on identifications

If we have an identification p : A ≡ B of two types A and B , and elements a : A and b : B , we cannot ask directly whether a ≡ b , because although the types are identified by p , they are not necessarily the same, in the sense of definitional equality. This is not merely a syntactical restriction of our formal system, but instead a fundamental fact that reflects the philosophy of univalent mathematics. For instance, consider the type

With univalence, we will have that Color ≡ 𝟚 where 𝟚 is the two-point type 𝟙 + 𝟙 with elements ₀ and ₁ . But there will be two identifications p₀ p₁ : Color ≡ 𝟚 , one that identifies Black with ₀ and White with ₁ , and another one that identifies Black with ₁ and White with ₀ . There is no preferred coding of binary colors as bits. And, precisely because of that, even if univalence does give inhabitants of the type Color ≡ 𝟚 , it doesn’t make sense to ask whether Black ≡ ₀ holds without specifying one of the possible inhabitants p₀ and p₁ .

What we will have is that the functions transport id p₀ and transport id p₁ are the two possible bijections Color → 𝟚 that identify colors with bits. So, it is not enough to have Color ≡ 𝟚 to be able to compare a color c : Color with a bit b : 𝟚 . We need to specify which identification p : Color ≡ 𝟚 we want to consider for the comparison. The same considerations apply when we consider identifications p : 𝟚 ≡ 𝟚 .

So the meaningful comparison in the more general situation is

transport id p a ≡ b

for a specific

p : A ≡ B ,

where id is the identity function of the universe where the types A and B live, and hence

transport id : A ≡ B → (A → B)

is the function that transforms identifications into functions, which has already occurred above.

More generally, we want to consider the situation in which we replace the identity function id of the universe where A and B live by an arbitrary type family, which is what we do now.

If we have a type

X : 𝓤 ̇ ,

and a type family

A : X → 𝓥 ̇

and points

x y : X

and an identification

p : x ≡ y ,

then we get the identification

ap A p : A x ≡ A y .

However, if we have

a : A x ,

b : A y ,

we again cannot write down the identity type

a ≡ b .

This is again a non-sensical mathematical statement, because the types A x and A y are not the same, but only identified, and in general there can be many identifications, not just ap A p , and so any identification between elements of A x and A y has to be with respect to a specific identification, as in the above particular case.

This time, the meaningful comparison, given p : x ≡ y , is

transport A p a ≡ b ,

For example, this idea applies when comparing the values of a dependent function:

Table of contents ⇑

Equality in Σ types

With the above notion of dependent equality, we can characterize equality in Σ types as follows.

For the sake of readability, the above two definitions can be equivalently written as follows.

The above gives the logical equivalence

(σ ≡ τ) ⇔ (Σ p ꞉ pr₁ σ ≡ pr₁ τ , transport A p (pr₂ σ) ≡ pr₂ τ) .

But this is a very weak statement when the left- and right-hand identity types have multiple elements, which is precisely the point of univalent mathematics.

What we want is the lhs and the rhs to be isomorphic, or more precisely, equivalent in the sense of Voevodsky.

Once we have defined this notion _≃_ of type equivalence, this characterization will become an equivalence

(σ ≡ τ) ≃ (Σ p ꞉ pr₁ σ ≡ pr₁ τ , transport A p pr₂ σ ≡ pr₂ τ) .

But even this is not sufficiently precise, because in general there are multiple equivalences between two types. For example, there are precisely two equivalences

𝟙 + 𝟙 ≃ 𝟙 + 𝟙 ,

namely the identity function and the function that flips left and right. What we want to say is that a specific map is an equivalence. In our case, it is the function from-Σ-≡ defined above.

Voevodsky came up with a definition of a type “ f is an equivalence” which is always a subsingleton: a given function f can be an equivalence in at most one way. In other words, being an equivalence is property of f , rather than data for f .

The following special case of to-Σ-≡ is often useful:

We take the opportunity to establish more equations for transport and to define a dependent version of transport:

Table of contents ⇑

Voevodsky’s notion of hlevel

Voevodsky’s hlevels 0,1,2,3,... are shifted by 2 with respect to the n -groupoid numbering convention, and correspond to -2 -groupoids (singletons), -1 -groupoids (subsingletons), 0 -groupoids (sets),…

The hlevel relation is defined by induction on ℕ , with the induction step working with the identity types of the elements of the type in question:

It is often convenient in practice to have equivalent formulations of the types of hlevel 1 (as subsingletons) and 2 (as sets), which we will develop soon.

Table of contents ⇑

Hedberg’s Theorem

To characterize sets as the types of hlevel 2, we first need to show that subsingletons are sets, and this is not easy. We use an argument due to Hedberg. This argument also shows that Voevodsky’s hlevels are upper closed.

We choose to present an alternative formulation of Hedberg’s Theorem, but we stress that the method of proof is essentially the same.

We first define a notion of constant map:

The prefix “ w ” officially stands for “weakly”. Perhaps incoherently constant or wildly constant would be better terminologies, with coherence understood in the ∞ -categorical sense. We prefer to stick to wildly rather than weakly, and luckily both start with the letter “ w ”.

We first define the type of constant endomaps of a given type:

The point is that a type is a set if and only if its identity types all have designated wconstant endomaps:

Table of contents ⇑

A characterization of sets

We consider types whose identity types all have designated constant endomaps:

The following is immediate from the definitions.

And the converse is the content of Hedberg’s Theorem.

Table of contents ⇑

Subsingletons are sets

In the following definition of the auxiliary function f , we ignore the argument p , using the fact that X is a subsingleton instead, to get a wconstant function:

And the corollary is that (sub)singleton types are sets.

In particular, the types 𝟘 and 𝟙 are sets.

Table of contents ⇑

The types of hlevel 1 are the subsingletons

Then with the above we get our desired characterization of the types of hlevel 1 as an immediate consequence:

This is an “if and only if” characterization, but, under univalence, it becomes an equality because the types under consideration are subsingletons.

Table of contents ⇑

The types of hlevel 2 are the sets

The same comments as for the previous section apply.

Table of contents ⇑

The hlevels are upper closed

A singleton is a subsingleton, a subsingleton is a set, … , a type of hlevel n is of hlevel n+1 too, …

Again we can conclude this almost immediately from the above development:

To be consistent with the above terminology, we have to stipulate that all types have hlevel ∞ . We don’t need a definition for this notion. But what may happen (and it does with univalence) is that there are types which don’t have any finite hlevel. We can say that such types then have minimal hlevel ∞ .

Exercise. Formulate and prove the following. The type 𝟙 has minimal hlevel 0 .

The type 𝟘 has minimal hlevel 1 , the type ℕ has minimal hlevel 2 . The solution to the fact that ℕ has hlevel 2 is given in the next section. More ambitiously, after univalence is available, show that the type of monoids has minimal hlevel 3 .

Table of contents ⇑

ℕ and 𝟚 are sets

If a type has decidable equality we can define a wconstant function x ≡ y → x ≡ y and hence conclude that it is a set. This argument is due to Hedberg.

Notice that excluded middle implies directly that all sets have decidable equality, so that in its presence a type is a set if and only if it has decidable equality.

Table of contents ⇑

Retracts

We use retracts as a mathematical technique to transfer properties between types. For instance, retracts of singletons are singletons. Showing that a particular type X is a singleton may be rather difficult to do directly by applying the definition of singleton and the definition of the particular type, but it may be easy to show that X is a retract of Y for a type Y that is already known to be a singleton. In these notes, a major application will be to get a simple proof of the known fact that invertible maps are equivalences in the sense of Voevodsky.

A section of a function is simply a right inverse, by definition:

Notice that has-section r is the type of all sections (s , η) of r , which may well be empty. So a point of this type is a designated section s of r , together with the datum η . Unless the domain of r is a set, this datum is not property, and we may well have an element (s , η') of the type has-section r with η' distinct from η for the same s .

We say that X is a retract of Y , written X ◁ Y , if we have a function Y → X which has a section:

This type actually collects all the ways in which the type X can be a retract of the type Y , and so is data or structure on X and Y , rather than a property of them.

A function that has a section is called a retraction. We use this terminology, ambiguously, also for the function that projects out the retraction:

We have an identity retraction:

Exercise. The identity retraction is by no means the only retraction of a type onto itself in general, of course. Prove that we have (that is, produce an element of the type) ℕ ◁ ℕ with the function pred : ℕ → ℕ defined above as the retraction. Try to produce more inhabitants of this type.

We can define the composition of two retractions as follows:

We also define composition with an implicit argument made explicit:

And we introduce the following postfix notation for the identity retraction:

These last two definitions are for notational convenience. See below for examples of their use.

We conclude this section with some facts about retracts of Σ types, which are of general use, in particular for dealing with equivalences in the sense of Voevosky in comparison with invertible maps.

A pointwise retraction gives a retraction of the total spaces:

We have that transport A (p ⁻¹) is a two-sided inverse of transport A p using the functoriality of transport A , or directly by induction on p :

Using this, we have the following reindexing retraction of Σ types:

We have defined the property of a type being a singleton. The singleton type Σ y ꞉ X , x ≡ y induced by a point x : X of a type X is denoted by singleton-type x . The terminology is justified by the fact that it is indeed a singleton in the sense defined above.

The following gives a technique for showing that some types are singletons:

Sometimes we need the following symmetric versions of the above:

Table of contents ⇑

Voevodsky’s notion of type equivalence

The main notions of univalent mathematics conceived by Voevodsky, with formulations in MLTT, are those of singleton type (or contractible type), hlevel (including the notions of subsingleton and set), and of type equivalence, which we define now.

We begin with a discussion of the notion of invertible function, whose only difference with the notion of equivalence is that it is data rather than property:

The situation is that we will have a logical equivalence between

data establishing invertibility of a given function, and

the property of the function being an equivalence.

Mathematically, what happens is that the type

f is an equivalence

is a retract of the type

f is invertible.

This retraction property is not easy to show, and there are many approaches. We discuss an approach we came up with while developing these lecture notes, which is intended to be relatively simple and direct, but the reader should consult other approaches, such as that of the HoTT book, which has a well-established categorical pedigree.

The problem with the notion of invertibility of f is that, while we have that the inverse g is unique when it exists, we cannot in general prove that the identification data g ∘ f ∼ id and f ∘ g ∼ id are also unique, and, indeed, they are not in general.

The following is Voevodsky’s proposed formulation of the notion of equivalence in MLTT, which relies on the concept of fiber :

So the type fiber f y collects the points x : X which are mapped to a point identified with y , including the identification datum. Voevodsky’s insight is that a general notion of equivalence can be formulated in MLTT by requiring the fibers to be singletons. It is important here that not only the x : X with f x ≡ y is unique, but also that the identification datum p : f x ≡ y is unique. This is similar to, or even a generalization of the categorical notion of “uniqueness up to a unique isomorphism”.

We can read this as saying that for every y : Y there is a unique x : X with f x ≡ y , where the uniqueness refers not only to x : X but also to the identification datum p : f x ≡ y . More precisely, the pair (x , p) is required to be unique. It is easy to see that equivalences are invertible:

The non-trivial direction derives the equivalence property from invertibility data, for which we use the retraction techniques explained above.

Suppose that invertibility data

g : Y → X ,

η : (x : X) → g (f x) ≡ x

ε : (y : Y) → f (g y) ≡ y

for a map f : X → Y is given, and that a point y₀ in the codomain of f is given.

We need to show that the fiber Σ x ꞉ X , f x ≡ y₀ of y₀ is a singleton.

We first use the assumption ε to show that the type f (g y) ≡ y₀ is a retract of the type y ≡ y₀ for any given y : Y . To get the section s : f (g y) ≡ y₀ → y ≡ y₀ , we transport along the identification ε y : f (g y) ≡ y over the family A - = (- ≡ y₀) , which can be abbreviated as _≡ y₀ . To get the retraction r in the opposite direction, we transport along the inverse of the identification ε y over the same family. We already know that this gives a section-retraction pair by transport-is-section . Next we have that the type Σ x ꞉ X , f x ≡ y₀ is a retract of the type Σ y ꞉ Y , f (g y) ≡ y₀ by Σ-reindexing-retract using the assumption that η exibits g as a section of f , which in turn is a retract of the type Σ y ꞉ Y , y ≡ y₀ by applying Σ to both sides of the retraction (f (g y) ≡ y₀) ◁ (y ≡ y₀) of the previous step. This amounts to saying that the type fiber f y₀ is a retract of singleton-type y₀ . But then we are done, because singleton types are singletons and retracts of singletons are singletons.

An immediate consequence is that inverses of equivalences are themselves equivalences:

Notice that inversion is involutive on the nose:

To see that the above procedures do exhibit the type “ f is an equivalence” as a retract of the type “ f is invertible”, it suffices to show that it is a subsingleton.

The identity function is invertible:

We can compose invertible maps:

There is an identity equivalence, and we get composition of equivalences by reduction to invertible maps:

An abstract definition is not expanded during type checking. One possible use of this is efficiency. In our case, it saves about half a minute in the checking of this file for correctness in the uses of ∘-is-equiv :

Because we have made the above definition abstract, we don’t have access to the given construction when proving things involving ∘-is-equiv , such as the contravariance of inversion:

The type of equivalences is defined as follows:

Notice that this doesn’t just say that X and Y are equivalent: the type X ≃ Y collects all the ways in which the types X and Y are equivalent. For example, the two-point type 𝟚 is equivalent to itself in two ways, by the identity map, and by the map that interchanges its two points, and hence the type 𝟚 ≃ 𝟚 has two elements.

Again it is convenient to have special names for its first and second projections:

Examples:

The identity equivalence and the composition of two equivalences:

We can use the following notation for equational reasoning with equivalences:

We conclude this section with some important examples. The function transport A p is an equivalence.

Alternatively, we could have used the fact that transport A (p ⁻¹) is an inverse of transport A p .

Here is the promised characterization of equality in Σ types:

Similarly we have:

The following are often useful:

Table of contents ⇑

Voevodsky’s univalence axiom

There is a canonical transformation (X Y : 𝓤 ̇ ) → X ≡ Y → X ≃ Y that sends the identity identification refl X : X ≡ X to the identity equivalence id-≃ X : X ≃ X . The univalence axiom, for the universe 𝓤 , says that this canonical map is itself an equivalence.

Thus, the univalence of the universe 𝓤 says that identifications X ≡ Y of types in 𝓤 are in canonical bijection with equivalences X ≃ Y , if by bijection we mean equivalence, where the canonical bijection is Id→Eq .

We emphasize that this doesn’t posit that univalence holds. It says what univalence is (like the type that says what the twin-prime conjecture is).

Here is a third way to convert a type identification into a function:

What characterizes univalent mathematics is not the univalence axiom. We have defined and studied the main concepts of univalent mathematics in a pure, spartan MLTT. It is the concepts of hlevel, including singleton, subsingleton and set, and the notion of equivalence that are at the heart of univalent mathematics. Univalence is a fundamental ingredient, but first we need the correct notion of equivalence to be able to formulate it.

Remark. If we formulate univalence with invertible maps instead of equivalences, we get a statement that is provably false in MLTT, and this is one of the reasons why Voevodsky’s notion of equivalence is important. This is Exercise 4.6 of the HoTT book. There is a solution in Coq by Mike Shulman.

Table of contents ⇑

Example of a type that is not a set under univalence

We have two automorphisms of 𝟚 , namely the identity function and the map that swaps ₀ and ₁:

That is, swap₂ is its own inverse and hence is an equivalence:

We now use a local module to assume univalence of the first universe in the construction of our example:

The above gives two distinct equivalences:

Using univalence, we get two different identifications of the type 𝟚 with itself:

If the universe 𝓤₀ were a set, then the identifications p₀ and p₁ defined above would be equal, and therefore it is not a set.

For more examples, see [Kraus and Sattler].

Table of contents ⇑

Exercises

Here are some facts whose proofs are left to the reader but that we will need from the next section onwards. Sample solutions are given below.

Table of contents ⇑

Formulations

Define functions for the following type declarations. As a matter of procedure, we suggest to import this file in a solutions file and add another declaration with the same type and new name e.g. sections-are-lc-solution , because we already have solutions in this file. It is important not to forget to include the option --without-K in the solutions file that imports (the Agda version of) this file.

An alternative notion of equivalence, equivalent to Voevodsky’s, has been given by André Joyal:

Provide definitions for the following type declarations:

Table of contents ⇑

Solutions

For the sake of readability, we re-state the formulations of the exercises in the type of sol in a where clause for each exercise.

Table of contents ⇑

A characterization of univalence

We begin with two general results, which will be placed in a more general context later.

With this we can characterize univalence as follows:

(Of course, this doesn’t say that there is only one type Y equivalent to X , or only one equivalence from X to Y , because equality of Σ types is given by transport in the second component along an identification in the first component.)

We can replace singleton by subsingleton and still have a logical equivalence, and we sometimes need the characterization in this form:

Table of contents ⇑

Equivalence induction

Under univalence, we get induction principles for type equivalences, corresponding to the induction principles ℍ and 𝕁 for identifications. To prove a property of equivalences, it is enough to prove it for the identity equivalence id-≃ X for all X .

Our objective is to get the induction principles ℍ-≃ and 𝕁-≃ below and their corresponding equations. As above, it is easy to define 𝕁-≃ from ℍ-≃ , and it is harder to define ℍ-≃ directly, and it is much harder to prove the desired equation for ℍ-≃ directly. In order to make this easy, we define an auxiliary induction principle 𝔾-≃ , from which we trivially derive ℍ-≃ , and whose equation is easy to prove.

The reason the induction principle 𝔾-≃ and its equation are easy to construct and prove is that the type Σ Y ꞉ 𝓤 ̇ , X ≃ Y is a singleton by univalence, which considerably simplifies reasoning about transport. For ℍ-≃ we consider Y : 𝓤 and e : X ≃ Y separately, whereas for G-≃ we treat them as a pair (Y , e) . The point is that the type of such pairs is a singleton by univalence.

The induction principle ℍ-≃ keeps X fixed and lets Y vary, while the induction principle 𝕁-≃ lets both vary:

A second set of equivalence induction principles refer to is-equiv rather than ≃ and are proved by reduction to the first version ℍ-≃ :

The above and the following say that to prove that a property of functions holds for all equivalences, it is enough to prove it for all identity functions:

And the following is an immediate consequence of the fact that invertible maps are equivalences:

For example, using ℍ-equiv we see that for any pair of functions

F : 𝓤 ̇ → 𝓤 ̇ ,

𝓕 : {X Y : 𝓤 ̇ } → (X → Y) → F X → F Y ,

if 𝓕 preserves identities then it automatically preserves composition of equivalences. More generally, it is enough that at least one of the factors is an equivalence:

Here is another example (see this for the terminology):

An unprimed version of this is given below, after we study half adjoint equivalences.

The above version using the inverse of f can be proved directly by induction, but the following version is perhaps more natural.

This particular proof works only because inversion is involutive on the nose.

As another example we have the following:

An annoying feature of the use of 𝕁 (rather than pattern matching on refl ) or 𝕁-≃ is that we have to repeat what we want to prove, as in the above examples.

Table of contents ⇑

Half adjoint equivalences

An often useful alternative formulation of the notion of equivalence is that of half adjoint equivalence. If we have a function

f : X → Y

with invertibility data

g : Y → X ,

η : g ∘ f ∼ id ,

ε : f ∘ g ∼ id ,

then for any x : X we have that

ap f (η x)

and

ε (f x)

are two identifications of type

f (g (f x)) ≡ f x .

The half adjoint condition says that these two identifications are themselves identified. The addition of the constraint

τ x : ap f (η x) ≡ ε (f x)

turns invertibility, which is data in general, into property of f .

The following just forgets the constraint τ :

Hence half adjoint equivalences are equivalences, because invertible maps are equivalences. But it is also easy to prove this directly, avoiding the detour via invertible maps. We begin with a construction which will be used a number of times in connection with half adjoint equivalences.

To recover the constraint for all equivalences, and hence for all invertible maps, under univalence, it is enough to give the constraint for identity maps:

The above can be proved without univalence as follows. This argument also allows us to have X and Y in different universes. An example of an equivalence of types in different universes is Id→Eq , as stated by univalence.

We wrote the above proof of equivs-are-haes in a deliberately verbose form to aid understanding. Here is the same proof in a perversely reduced form:

Notice that we have the following factorization, on the nose, of the construction of invertibility data from the equivalence property:

Instead of working with the notion of half adjoint equivalence, we can just work with Voevodsky’s notion of equivalence, and use the fact that it satisfies the half adjoint condition:

Here is an example, where, compared to Σ-change-of-variable' , we remove univalence from the hypothesis, generalize the universe of the type Y , and weaken equality to equivalence in the conclusion. Notice that the proof starts as that of Σ-reindexing-retract .

For the sake of completeness, we also include the proof from the HoTT book that invertible maps are half adjoint equivalences, which uses a standard argument coming from category theory.

We first need some naturality lemmas:

The idea of the following proof is to improve ε to be able to give the required τ :

Table of contents ⇑

Function extensionality from univalence

Function extensionality says that any two pointwise equal functions are equal. This is known to be not provable or disprovable in MLTT. It is an independent statement, which we abbreviate as funext .

There will be two seemingly stronger statements, namely the generalization to dependent functions, and the requirement that the canonical map f ≡ g → f ∼ g is an equivalence.

Exercise. Assuming funext , prove that if a function f : X → Y is an equivalence then so is the precomposition map _∘ f : (Y → Z) → (X → Z) .

The crucial step in Voevodsky’s proof that univalence implies funext is to establish the conclusion of the above exercise assuming univalence instead. We prove this by equivalence induction on f , which means that we only need to consider the case when f is an identity function, for which precomposition with f is itself an identity function (of a function type), and hence an equivalence:

With this we can prove the desired result as follows.

This definition of γ is probably too concise. Here are all the steps performed silently by Agda, by expanding judgmental equalities, indicated with refl here:

So notice that this relies on the so-called η-rule for judgmental equality of functions, namely

f = λ x → f x .

Without it, we would only get that

f₀ ∼ f₁ → (λ x → f₀ x) ≡ (λ x → f₁ x)

instead.

Table of contents ⇑

Variations of function extensionality and their logical equivalence

Dependent function extensionality:

The above says that there is some map f ~ g → f ≡ g . The following instead says that the canonical map happly in the other direction is an equivalence:

Voevodsky showed that all these notions of function extensionality are logically equivalent to saying that products of singletons are singletons:

We need some lemmas to get hfunext from vvfunext :

And finally the seemingly rather weak, non-dependent version funext implies the seemingly strongest version, which closes the circle of logical equivalences.

We have the following corollaries. We first formulate the types of some functions:

And then we give their definitions (Agda makes sure there are no circularities):

Table of contents ⇑

Universes are map classifiers

Under univalence, a universe 𝓤 becomes a map classifier, in the sense that maps from a type X in 𝓤 into a type Y in 𝓤 are in canonical bijection with functions Y → 𝓤 . Using the following slice notation, this amounts to a bijection between 𝓤 / Y and Y → 𝓤 :

We need the following lemma, which has other uses:

The function χ gives the characteristic function of a map into Y :

We say that a universe is a map classifier if the above function is an equivalence for every Y in the universe:

Any Y → 𝓤 is the characteristic function of some map into Y by taking its total space and the first projection:

Therefore we have the following canonical equivalence:

Table of contents ⇑

The univalence axiom is a (sub)singleton

If we use a type as an axiom, it should better have at most one element. We prove some generally useful lemmas first.

In passing, we fulfill a promise made above:

We now return to our main concern in this section.

So if all universes are univalent then “being univalent” is a subsingleton, and hence a singleton. This hypothesis of global univalence cannot be expressed in our MLTT that only has ω many universes, because global univalence would have to live in the first universe after them. Agda does have such a universe 𝓤ω, and so we can formulate it here. There would be no problem in extending our MLTT to have such a universe if we so wished, in which case we would be able to formulate and prove:

That the type Univalence would be a subsingleton can’t even be formulated in the absence of a successor 𝓤ω⁺ of 𝓤ω , and Agda doesn’t have such a successor universe (but there isn’t any fundamental reason why it couldn’t have it).

In the absence of a universe 𝓤ω in our MLTT, we can simply have an axiom schema, consisting of ω -many axioms, stating that each universe is univalent. Then we can prove in our MLTT that the univalence property for each universe is a (sub)singleton, with ω -many proofs (or just one schematic proof with a free variable for a universe 𝓤ₙ ).

It follows immediately from the above that global univalence gives global function extensionality.

vvfunext 𝓤 𝓥 and hfunext 𝓤 𝓥 are (sub)singletons

We need a version of Π-is-subsingleton for dependent functions with implicit arguments.

To show that vvfunext 𝓤 𝓥 and hfunext 𝓤 𝓥 are subsingletons, we need assumptions of function extensionality for higher universes:

Hence they are singletons assuming global univalence (or just global function extensionality, of any kind):

However, funext 𝓤 𝓤 and dfunext 𝓤 𝓤 are not subsingletons (see the HoTT book).

Table of contents ⇑

Unique existence in univalent mathematics

Unique existence of x : X with A x in univalent mathematics, written

∃! x ꞉ X , A x

or simply

∃! A ,

requires that not only the x : X but also the a : A x to be unique. More precisely, we require that there is a unique pair (x , a) : Σ A .

This is particularly important in the formulation of universal properties involving types that are not necessarily sets, where it generalizes the categorical notion of uniqueness up to unique isomorphism.

The converse holds if each A x is a subsingleton:

Exercise. Find a counter-example in the absence of the requirement that all types A x are subsingletons.

Similarly, the existence of at most one x : X with A x should be understood as

is-subsingleton (Σ A) ,

but we will not introduce special notation for this concept, although it will occur often.

Table of contents ⇑

Universal property of the natural numbers

The natural numbers have the following universal property. What is noteworthy here is that the type Y need not be a set, so that the two equations can hold in multiple ways, but nevertheless we have unique existence in the sense of the previous section. Moreover, univalence is not needed. Function extensionality suffices.

We apply the same retraction techniques we used in order to prove that invertible maps are equivalences. We first show that, for any h : ℕ → Y , the type

(h 0 ≡ y₀) × (h ∘ succ ∼ g ∘ h)

is a retract of the type

h ∼ ℕ-iteration Y y₀ g

and hence, by function extensionality, we also have a retraction if we replace pointwise equality ∼ by equality ≡ . Thus the type

Σ h ꞉ ℕ → Y , (h 0 ≡ y₀) × (h ∘ succ ≡ g ∘ h)

is a retract of the singleton type

Σ h ꞉ ℕ → Y , h ≡ ℕ-iteration Y y₀ g ,

and therefore is itself a singleton, as required.

Now we do this in Agda. We need both versions hfunext and dfunext of function extensionality, where we have taken the first as an assumption:

We first establish the following retraction (which is automatically an equivalence, but we don’t need this fact).

The above section s is defined by induction on natural numbers, but the following retraction r is defined directly. Above and below, the identifications refl _ are included for the sake of clarity. This adds some extra steps to the proof of the retraction property (some of which could be silent, but we choose to make explicit by further uses of refl _ ).

The retraction property doesn’t need induction on natural numbers:

This concludes the proof of ℕ-is-nno . We say that ℕ is a natural numbers object, or, more precisely, the triple (ℕ , 0 , succ) is a natural numbers object.

Here is an important example, which given any n : ℕ constructs a type with n elements (and decidable equality):

We could use the other projections to derive the following two equations, but they hold definitionally:

We also have

and the examples

Exercise. Assume univalence. The equation

Fin ∘ succ ≡ λ n → Fin n + 𝟙

holds in multiple ways, because Fin n has n! automorphisms. Construct an involutive fiberwise equivalence

mirror : (n : ℕ) → Fin n → Fin n

different from the identity and hence an identification Fin ≡ Fin different from refl Fin . Consider

∃! Fin' ꞉ ℕ → 𝓤₀ ̇ , (Fin' 0 ≡ 𝟘) × (Fin' ∘ succ ≡ λ n → 𝟙 + Fin' n)

and show that Fin' ∘ succ ≡ λ n → Fin' n + 𝟙 so that Fin' satisfies the defining equations of Fin , although not judgmentally, and hence Fin' ≡ Fin by the univeral property of Fin . But there are many equalities Fin' ≡ Fin . Which one do we get by the universal property? Show that the type Fin n has decidable equality and hence is a set.

Table of contents ⇑

More consequences of function extensionality

Here the version hfunext of function extensionality is what is needed:

More generally:

Composition of equivalences is associative:

Exercise. The hlevels are closed under Σ and, using hfunext , also under Π . Univalence is not needed, but makes the proof easier. (Without univalence, we need to show that the hlevels are closed under equivalence first.)

An application of Π-cong is hfunext₂-≃ :

We have already proved the following assuming univalence, in order to derive function extensionality from univalence. Now we prov