# Definitional Proof-Irrelevance without K

Gaëtan Gilbert, Jesper Cockx, Matthieu Sozeau, Nicolas Tabareau

► To cite this version:

Gaëtan Gilbert, Jesper Cockx, Matthieu Sozeau, Nicolas Tabareau. Definitional Proof-Irrelevance without K. Proceedings of the ACM on Programming Languages, 2019, POPL'19, pp.1-28. 10.1145/3290316. hal-01859964v2

HAL Id: hal-01859964

https://inria.hal.science/hal-01859964v2

Submitted on 16 Oct 2018

HAL is a multi-disciplinary open access
archive for the deposit and dissemination of sci-
entific research documents, whether they are pub-
lished or not. The documents may come from
teaching and research institutions in France or
abroad, or from public or private research centers.

L'archive ouverte pluridisciplinaire HAL, est
destinée au dépôt et à la diffusion de documents
scientifiques de niveau recherche, publiés ou non,
émanant des établissements d'enseignement et de
recherche français ou étrangers, des laboratoires
publics ou privés.

<figure><img src="image_1.png" /></figure>

Distributed under a Creative Commons Attribution 4.0 International License
# Definitional Proof-Irrelevance without K*

GAËTAN GILBERT, Gallinette Project-Team, Inria, France

JESPER COCKX, Chalmers / Gothenburg University, Sweden

MATTHIEU SOZEAU, Pi.R2 Project-Team, Inria and IRIF, France

NICOLAS TABAREAU, Gallinette Project-Team, Inria, France

Definitional equality—or conversion—for a type theory with a decidable type checking is the simplest tool to prove that two objects are the same, letting the system decide just using computation. Therefore, the more things are equal by conversion, the simpler it is to use a language based on type theory. Proof-Irrelevance, stating that any two proofs of the same proposition are equal, is a possible way to extend conversion to make a type theory more powerful. However, this new power comes at a price if we integrate it naively, either by making type checking undecidable or by realizing new axioms—such as uniqueness of identity proofs (UIP)—that are incompatible with other extensions, such as univalence. In this paper, taking inspiration from homotopy type theory, we propose a general way to extend a type theory with definitional proof irrelevance, in a way that keeps type checking decidable and is compatible with univalence. We provide a new criterion to decide whether a proposition can be eliminated over a type (correcting and improving the so-called singleton elimination of Coq) by using techniques coming from recent development on dependent pattern matching without UIP. We show the generality of our approach by providing implementations for both Coq and Agda, both of which are planned to be integrated in future versions of those proof assistants.

## 1 INTRODUCTION

Proof-Irrelevance, the principle that any two proofs of the same proposition are equal, is at the heart of the Coq extraction mechanism [Letouzey 2004]. In the Calculus of Inductive Constructions (CIC), the underlying theory of the Coq proof assistant, there is an (impredicative) sort PROP that is used to characterize types that can be seen as propositions—as opposed to types whose inhabitants have a computational meaning, which live in the predicative sort TYPE. This static piece of information is used to extract a Coq formalization to a purely functional program, erasing safely all the parts involving terms that inhabit propositions, because a program can not use those terms in computationally relevant ways.

In order to concretely guarantee that no computation can leak from propositions to types, Coq uses a restriction of the dependent elimination from inductive types in PROP into predicates in TYPE. This restriction, called the *singleton elimination condition*, checks that an inductive proposition can be eliminated into a type only when:

(1) the inductive proposition has at most one constructor,

(2) all the arguments of the constructor are themselves non-computational, i.e. are in PROP.

However, in the current version of Coq, singleton elimination is the price to pay to be compatible with proof irrelevance, but there is no payback. This means that although two proofs of the same proposition can not be relevantly distinguished in the system, one can not use the fact that they are equal in the logic.

Consider for instance a working mathematician or computer scientist who defines bounded integers in the following way:

<footnote>*This work is supported by the CoqHoTT ERC Grant 64399.</footnote>

<footnote>Authors' addresses: Gaëtan Gilbert, Gallinette Project-Team, Inria, Nantes, France; Jesper Cockx, Chalmers / Gothenburg University, Gothenburg, Sweden; Matthieu Sozeau, Pi.R2 Project-Team, Inria and IRIF, Paris, France; Nicolas Tabareau, Gallinette Project-Team, Inria, Nantes, France.</footnote>
**Definition boundedN (k : N) : Type := { n : N & n ≤ k } .**

Here boundedN k is the dependent sum of an integer n together with a proof (in PROP ) that n is
below k, using the inductive definition

Inductive ≤ : N → N → Prop :=
≤0 : ∀ n, 0 ≤ n
| ≤S : ∀ m n, m ≤ n → S m ≤ S n.

Then, our user defines an implicit coercion from boundedN to N so that she can work with bounded
integers almost as if they were integers, apart from additional proofs of boundedness.

Coercion boundedN_to_N : boundedN → N.

For instance, she can define the addition of bounded integers by simply relying on the addition of
integers, modulo a proof that the result is still bounded:

**Definition** add {k} (n m : boundedN k) (e : n + m ≤ k) : boundedN k := (n + m ; e).

Unfortunately, when it comes to reasoning on bounded integers, the situation becomes more dif-
ficult. For instance, the fact that addition of bounded natural numbers is associative

**Definition** bounded_add_associativity k (n m p : boundedN k) e₁ e₂ e'₁ e'₂ :
add (add n m e₁) p e₂ = add n (add m p e'₁) e'₂.

does not directly follow from associativity of addition on integers, as it additionally requires a
proof that e₂ equals e'₂ (modulo the proof of associativity of addition of integers). This should
be true because they are two proofs of the same proposition, but it does not follow automatically.
Instead, the user has to prove proof-irrelevance for ≤ manually. This can be proven (using Agda
style pattern matching of the Equations plugin<fnref n="1" />) by induction on the proof of m ≤ n:

**Equations**
$$
\begin{align*}
\leq_hprop \{m\} (e e' : m \leq n) : e = e' &:= \\
\leq_hprop (\leq 0 \_ ) (\leq 0 \_ ) &:= eq_refl; \\
\leq_hprop (\leq S \_ \_ e) (\leq S \ m \ m \ e') &:= ap (\leq S \ m \ m) (\leq_hprop e \ e').
\end{align*}
$$

Note the use of functoriality of equality ap : ∀ f, x = y → f x = f y which requires some explicit reasoning on equality. Even if proving associativity of addition was more complicated than expected, our user is still quite lucky to deal with an inductive type that is actually a mere proposition, in the sense of Homotopy Type Theory (HoTT) [Univalent Foundations Program 2013]. Indeed, ≤ satisfies the propositional (as opposed to definitional, which holds by computation) version of proof irrelevance, as expressed by the ≤_hprop lemma. For an arbitrary inductive type in PROP , there is no reason anymore why it would be a mere proposition, and thus proof irrelevance, even in its propositional form, can not be proven and must be stated as an axiom .

In a setting where proof-irrelevance for PROP is built in, it becomes possible to define an op-
eration on types which turns any type into a definitionally proof irrelevant one and thus makes
explicit in the system the fact that a value in Squash T will never be used for computation.

**Definition** Squash (T : Type) : Prop := ∀ P : Prop, (T → P) → P.

This operator satisfies the following elimination principle (reduced to proposition) given by

∀ (T : Type) (P : Prop), (T → P) → Squash T → P.

<footnote n="1">¹http://mattam82.github.io/Coq-Equations/</footnote>
which means that it corresponds to the propositional truncation [Univalent Foundations Program 2013] of HoTT, originally introduced as the bracket type by Awodey and Bauer [Awodey and Bauer 2004].

The importance of (definitional) proof irrelevance to simplify reasoning has been noticed for a long time, and various works have tried to promote its implementation in a proof assistant based on type theory [Pfenning 2001; Werner 2008]. However, this has never been achieved, mainly because of the fundamental misunderstanding that singleton elimination was the right constraint on which propositions can be eliminated into a type. Indeed, one can think of singleton elimination as a syntactic approximation of which types are naturally mere propositions, and thus can be eliminated into an arbitrary type without leaking a piece of computation or without implying new axioms. But, singleton elimination does not work for indexed datatypes, as for instance it applies to the equality type of Coq

Inductive eq (A : Type) (x : A) : A → Prop ::= eq_refl : eq A x x

If proof irrelevance holds for the equality type, every equality has at most one proof, which is known as Uniqueness of Identity Proofs (UIP). Therefore, assuming proof irrelevance together with the singleton elimination enforces a new axiom in the theory, which is for instance incompatible with the univalence axiom from HoTT. This may not seem too problematic to some, but another consequence of singleton elimination in presence of definitional proof irrelevance is that it breaks decidability of conversion. For instance, the accessibility predicate:

Inductive Acc (A : Type) (R : A → A → Prop) (x : A) : Prop ::=

Acc_intro : ( ∀ y : A, R y x → Acc R y ) → Acc R x

satisfies the singleton elimination criterion but implementing definitional proof irrelevance for it leads to an undecidable conversion and thus an undecidable type checker (we come back to this point in more detail in Section 2).

An alternative approach is to do as in Lean, where they do have proof irrelevance with singleton elimination, but they only implement a partial version of proof irrelevance for recursive inductive types satisfying the singleton elimination, which is restricted to closed terms.<fnref n="2" /> But this partial implementation of the conversion algorithm breaks in particular subject reduction, which seems a desirable property for a proof assistant (see a concrete example in Appendix A). Finally, singleton elimination fails to capture inductive types with multiple constructors such as $\le$ which are perfectly valid mere propositions and could be eliminated into types.

Looking back, Coq and its impredicative sort PROP may not be the only way to implement proof irrelevance in a proof assistant. Agda, which only has a predicative hierarchy of universes and no PROP, instead uses a notion of irrelevant arguments [Abel and Scherer 2012]. The idea there is to mark in the function type which arguments can be considered as irrelevant. For instance, our user can encode bounded natural numbers in this setting, by specifying that the second argument of the dependent pair is irrelevant (as marked by the . in the definition of $(n \le k)$):

data boundedNat (k : N) : Set where
pair : (n : N) → .(n ≤ k) → boundedNat k

The fact that equality of the underlying natural numbers implies equality of the bounded natural numbers comes for free from irrelevance of the second component:

piBoundedNat : {k : N}(n m : N)(e : n ≤ k)(e' : m ≤ k) → n ≡ m → pair n e ≡ pair m e'
piBoundedNat n m _ _ refl = refl

<footnote n="2">²See a description of this issue in https://github.com/leanprover/lean/issues/654.</footnote>
However, in this approach proof irrelevance is not a property of the type being considered but rather a way to use the argument of a given function. To get closer to a real management of proof irrelevance, irrelevant fields were added to Agda.<fnref n="3" /> It becomes thus possible to define a variant of propositional truncation by defining a record with only one field which is proof irrelevant

record Squash (A : Set) : Set where

constructor sq

field .unsq : A

Squash A is proof-irrelevant, as shown by the following lemma:

piSquash : {A : Set}(x y : Squash A) → x ≡ y

piSquash x y = refl

However, together with irrelevant fields, there is a notion of irrelevant projections<fnref n="4" />, which, as observed recently by the Agda community<fnref n="5" />, gives rise to an inconsistency in the theory. Indeed, in Agda 2.5.3 it is possible to define a function from Squash Bool to Bool that can be shown to be definitionally the inverse of `sq` in an irrelevant context.

bizarre : Squash (Σ (Bool → Squash Bool)

(λi → Σ (Squash Bool → Bool) (λu → (a : Bool) → u (i a) ≡ a)))

bizarre = sq (sq, unsq, (λa → refl {x = a})))

This can be used to prove that Squash (`true` ≡ `false`) which directly leads to an inconsistency. We have worked with Agda developers since then and they have been able to correct this issue based on our explanation using a definitionally proof irrelevant universe. Thus, using a universe `sPROP`, of definitionally proof irrelevant propositions, is necessary to give a good theoretical justification of irrelevant fields, something that hasn't been done so far. Moreover, being an inhabitant of `sPROP` is a property of a *type* rather than the property of a particular *argument of a function*, which makes it much more flexible and easier to justify.

*Contributions.* In this paper, we propose the first general treatment of a dependent type theory with a proof irrelevant sort, with intuitions coming from the notion of homotopy levels of HoTT and propositional truncation. This extension of type theory does not add any additional axioms (apart from the existence of a proof irrelevant universe) and is in particular compatible with universal value. We prove both consistency and decidability of type checking of the resulting type theory. Then we show how to define an almost complete criterion to detect which proof-irrelevant inductive definitions can be eliminated into types, correcting and extending singleton elimination. This criterion uses the general methodology of proof-relevant unification and dependent pattern matching [Cockx and Devriese 2018; Cockx et al. 2014]. Our presentation is not specific to any particular type theory, which is shown by an implementation both in Coq, using an impredicative proof-irrelevant sort, and in Agda, using a hierarchy of predictive proof-irrelevant sorts.

Links to the source code of the Coq and Agda implementations together with examples can be found in https://github.com/CoqHoTT/sProp.

*Plan of the paper.* In Section 2, we give an overview of the main techniques and results developed in this paper. Section 3 presents the general dependent type theory with proof-irrelevant sorts, called sMLTT. We prove the main metatheoretical properties of sMLTT in Section 4. We then describe our criterion correcting and extending singleton elimination in Section 5. Finally, in

<footnote n="3">³Agda 2.2.8, see https://github.com/agda/agda/blob/master/CHANGELOG.md#release-notes-for-agda-2-version-228.</footnote>

<footnote n="4">⁴Added in Agda 2.2.10.</footnote>

<footnote n="5">⁵Issue #2170 at https://github.com/agda/agda/issues/2170.</footnote>
Section 6 we discuss our implementation of definitional proof irrelevance in Coq and in Agda, and show its usefulness on various examples (available as anonymous supplemental material), including a formalization of the setoid model in Coq.

## 2 LESSONS FROM HOMOTOPY TYPE THEORY

Before diving into the precise definition of a type theory with definitional proof irrelevance, let us explore what makes it difficult to introduce while keeping decidable type checking and avoiding to induce additional axioms such as UIP or functional extensionality.

### 2.1 sPROP as a Syntactical Approximation of Mere Propositions

The first lesson from HoTT is that each type in sPROP must be a mere proposition, i.e. have homotopy level $-1$. Formally, the universe of mere propositions HPROP is defined as

**Definition** hProp := { A : Type & ∀ x y : A , x = y }.

and thus it corresponds exactly to the universe of types satisfying propositional proof irrelevance. As we have mentioned in the introduction, the operator Squash which transforms any type into an inhabitant of sPROP, corresponds to the propositional truncation.

The existence of sPROP becomes interesting only when we can eliminate some inductive definitions in sPROP to arbitrary types. If not, sPROP constitutes an isolated logical layer corresponding to propositional logic, without any interaction with the rest of the type theory. The question is thus:

> "Which inductive types of a universe of definitionally proof irrelevant types can be eliminated over arbitrary types?"

Of course, to preserve consistency, this should be restricted to inductive types that can be proven to be mere propositions, but this is not enough to preserve decidability of type checking and independence from UIP.

### 2.2 Flirting with Extensionality

Let us first look at an apparently simple class of mere propositions, contractible types. They constitute the lowest level in the hierarchy of types, for which not only there is at most one inhabitant up to equality, but there is exactly one. Of course, the unit type in sPROP which corresponds to the true proposition

**Inductive** sUnit : sProp := tt : sUnit.

is contractible. We will say that the unit type can be eliminated to any type, and thus we get a unit type with a definitional $\eta$-law such that $u \equiv tt$ for any $u : sUnit$. But in general, it should not be expected that any contractible type in sPROP can be eliminated to an arbitrary type, as we can see below.

Singleton types. A prototypical example of a non-trivial contractible type is the so-called singleton type. For any type A and a:A, it is defined as the subset of points in A equal to a:

**Definition** Sing (A : Type) (a : A) := { b : A & a = b }.

If we include singleton types in sPROP, and hence permit its elimination over arbitrary types, we are led to an extensional type theory, in which propositional equality implies definitional equality. This would thus add UIP and undecidability of type checking to the theory.<fnref n="6" /> Indeed, assume that

<footnote n="6">⁶This remark is originally due to Peter LeFanu Lumsdaine.</footnote>
singleton types can be eliminated to arbitrary types, then there exists a projection $\pi_1 : \text{Sing A} \to A$ which recovers the point from the singleton. But then, for any proof of equality e: a = b between a and b in A, using congruence of definitional equality, there is the following chain of implications

$$ (a; \text{refl}) \equiv (b; e) : \text{Sing A} \Rightarrow \pi_1 (a; \text{refl}) \equiv \pi_1 (b; e) : A \Rightarrow a \equiv b : A $$

and hence $e : a = b$ implies $a \equiv b$. From this analysis, it is clear that sPROP cannot include all contractible types.

## 2.3 Flirting with Undecidability

Let us now look at other inductive types that are mere propositions without being contractible. The first canonical example is the empty type

$$ \text{Inductive } sEmpty : sProp := . $$

that has no inhabitant, together with an elimination principle which states that anything can be deduced from the empty type

$$ sEmpty\_rect : \forall T : \text{Type}, sEmpty \to T. $$

We will see that this type can be eliminated to any type, and this is actually the main way to make sPROP communicate with TYPE. In particular, it allows the construction of computational values by pattern matching and use a contraction in sPROP to deal with absurd branches.

The other kind of inductive definition in sPROP that can be eliminated into any type is a dependent sum of a type A in sPROP and a dependent family over A in sPROP, the nullary case being the unit type sUnit.

Let us now have a look at more complex inductive definitions.

*Accessibility predicate.* As mentioned in the introduction, the accessibility predicate is a mere proposition but it cannot be eliminated into any type while keeping conversion—and thus type-checking—decidable. Intuitively, this is because the accessibility predicate allows to define fixpoints with a *semantic guard* (the fact that every recursive call is on terms y such that R y x) rather than a *syntactic guard* (the fact that every recursive call is on a syntactic subterm). This is problematic in a definitionally proof irrelevant setting because a function that is defined by induction on an accessibility predicate could be unfolded infinitely many times. To understand why, consider the inversion lemma that we can define as soon as Acc can be eliminated into any type

$$ \text{Definition } \text{Acc\_inv A R} (x : A) (X : \text{Acc } x) : \forall y : A, R y x \to \text{Acc } y := $$

$$ \text{Acc\_rect} (\mathit{fun} x \Rightarrow \forall y, R y x \to \text{Acc } y) (\mathit{fun} x X \Rightarrow X) x X. $$

This inversion lemma makes use of the general eliminator on Acc:

$$ \text{Acc\_rect} : \forall P : A \to \text{Type}, (\forall x : A, (\forall y : A, R y x \to \text{Acc } y) \to (\forall y : A, R y x \to P y) \to P x) $$

$$ \to \forall x : A, \text{Acc } x \to P x $$

But then, from this inversion and using definitional proof irrelevance, the following definitional equality is derivable, for any predicate P : A → Type and function F : ∀ x, (∀ y, r y x → P y) → P x and X : Acc x

$$ \text{Acc\_rect P F x X} \equiv F x \ (\mathit{fun} y r \Rightarrow \text{Acc\_rect P F y} (\text{Acc\_inv A R x X y r})) $$

In an open context, it is undecidable to know how many time this unfolding must be done. Even the strategy that there is at most one unfolding may not terminate. Indeed, suppose that we are in a (possibly inconsistent) context where there is a proof R\_refl showing that R is reflexive. Then, applying the unfolding above once to F := fun x f ⇒ f x (R\_refl x) computes to
$$Acc\_rect P F \times X \equiv Acc\_rect P F \times (Acc\_intro \times (Acc\_inv A R \times X))$$

and the unfolding can start again for ever.

As mentioned above, if we analyze the source of this infinite unfolding, it is due to the recursive call to Acc in the argument of Acc_intro on an arbitrary variable y that is not syntactically smaller than the initial x variable, but semantically guarded by the R y x condition. This example shows that singleton elimination is not a sufficient criterion for when an inductive type in sPROP can be eliminated into any type, as one needs to introduce something similar to the syntactic guard condition on fixpoints.

Let us now see why this is not a necessary condition either.

**The Good and the Bad Less Than or Equal.** The definition of less than or equal given in introduction does not satisfy the singleton elimination criterion because it has two constructors. However, $m \le n$ can easily be shown to be a mere proposition for any natural numbers $m$ and $n$. Thus, it is a good candidate for an sPROP being eliminable into any type. The reason why it is a mere proposition is however more subtle than what singleton elimination usually requires, as not every argument of the constructors of $\le$ is in sPROP. To see why it is a mere proposition, one needs to distinguish between forced and non-forced constructor arguments<fnref n="7" />. A forced argument is an argument that can be deduced from the indices of the return type of the constructor, and that are not computationally relevant. Consider for instance the constructor $\le S : \forall m n, m \le n \rightarrow m \le S n$, its two first arguments $m$ and $n$ can be computed from the return type $S m \le S n$ and are thus forced. In contrast, the argument of type $m \le n$ cannot be deduced from the type and thus must be in sPROP.

However, being a mere proposition is not sufficient as we have seen with singleton types and the accessibility predicate. Here the situation is even more subtle. Consider the (propositionally) equivalent definition of $n \le m$ that is actually the one used in the Coq standard library:

$$ 
\begin{array}{l}
\text{Inductive } \le_{bad} : N \rightarrow N \rightarrow sProp := \\
\quad \le_{bad\_refl} : \forall n, n \le_{bad} n \\
\quad \le_{badS} : \forall m n, m \le_{bad} n \rightarrow m \le_{bad} S n.
\end{array}
$$

It can also be shown that $m \le_{bad} n$ is a mere proposition, but $\le$ and $\le_{bad}$ do not share the same inversion principle. Indeed, in the (absurd) context that $e : S n \le_{bad} n$, there are two ways to form a term of type $S n \le_{bad} S n$, either by using $\le_{bad\_refl} (S n)$ or by using $\le_{badS} (S n) n e$. This means that allowing $m \le_{bad} n$ to be eliminated into any type would require to decide whether the context is absurd or not, which is obviously not a decidable property of type theory. For $m \le n$ the situation is different, because the return type of the two constructors $\le 0$ and $\le S$ are orthogonal, in the sense they cannot be unified.

## 2.4 Dependent Pattern Matching to the Rescue

We propose a new criterion for when a type in sPROP can be eliminated to an arbitrary type, fixing and generalizing the singleton elimination criterion. This criterion is general enough to distinguish between the definitions of $\le$ and $\le_{bad}$. In general, an inductive type in sPROP may be eliminated if it satisfies three properties:

(1) Every non-forced argument must be in sPROP.

(2) The return types of constructors must be pairwise orthogonal.

(3) Every recursive call must satisfy a syntactic guard condition.

To justify this criterion, we provide a general translation from any inductive type satisfying this criterion to an equivalent type defined as a fixpoint, using ideas coming from dependent pattern

<footnote n="7">⁷This terminology has been introduced by [Brady et al. 2004].</footnote>
matching [Cockx and Devriese 2018; Cockx et al. 2014]. Indeed, looking at the inductive definition from right (its conclusion) to left (its arguments) allows us to construct a case tree similarly to what is done with a definition by pattern matching. Providing this translation also means we avoid the need to extend our core language, as all inductive types can be encoded using the existing primitives.

*Rejecting constructor arguments not in sPROP.* The first property is the most straightforward to understand: if a constructor of an inductive type can store some information that is computationally relevant, then it should not be in sPROP (or at least, we should never eliminate it into TYPE).

*Rejecting non-orthogonal definitions.* The idea of the second property is that the indices of the return type of each constructor should fix in which constructor we are, by using disjoint indices for the different constructors. This is a syntactical approximation of the orthogonality criterion. This is the property that fails to hold for $\le_{bad}$.

*Rejecting non terminating fixpoints.* In addition to the first two properties, we also require a syntactic guard condition on the recursive constructor arguments. This guard condition enforces that the resulting fixpoint definition is well-founded. We may thus use the exact same syntactic condition already used for fixpoints already implemented in the type theory (no matter which one it is, as long as it guarantees termination).

For instance, in the case of Acc, the case tree induces the following definition, which is automatically rejected by the termination checker because of the unguarded recursive call Acc' y

$$ \begin{array}{l} \text{Fail Equations} \quad \text{Acc}' (x: A) : \text{sProp} := \\ \quad \text{Acc}' x := (\forall y: A, R \ y \ x \to \text{Acc}' y). \end{array} $$

*Deriving fixpoints and eliminators automatically.* If all three properties are satisfied, we can automatically derive a fixpoint in sPROP that is equivalent to the inductive definition. Each constructor corresponds to a unique branch of a case tree, and the return type in each branch is the dependent sum of the non-forced arguments of the corresponding constructor (the zero case being sUnit). For instance, for $\le$, this is given by

$$ \begin{array}{l} \text{Equations} \quad \le_{fix} (n:m:N) : \text{sProp} := \\ \quad 0 \le_{fix} n := \text{sUnit}; \\ \quad S \ m \le_{fix} S \ n := m \le_{fix} n; \\ \quad S \_ \le_{fix} 0 := \text{sEmpty}. \end{array} $$

Note that branches corresponding to no constructor are given the value sEmpty. One can then also define functions corresponding to the constructors and the elimination principle (to TYPE) of the inductive type. Details of the algorithm and its correctness are given in Section 5.

## 3 ADDING DEFINITIONAL PROOF IRRELEVANCE TO MLTT

Most type theories describable by Pure Type Systems (PTS) can be extended with a notion of predicative or impredicative hierarchy of sorts sPROPᵢ which satisfies definitional proof irrelevance. This is illustrated in this paper by the fact that this extension can be applied to both Coq and Agda, which correspond to slightly different PTSs. However, to keep the theoretical presentation simple, we present this extension for a prototypical PTS-style type theory, namely Martin-Löf Type Theory [Martin-Löf 1975] (MLTT), and only go into the difference between the Coq and Agda implementations in Section 6. In this section, we first introduce MLTT and then explain how to add a proof irrelevant hierarchy of sorts, and various specific types and type constructors in it.
$$A, B, M, N ::= \text{TYPE}_i | x | M N | \lambda x : A. M | \Pi x : A. B | \Sigma x : A. B | \pi_1 M | \pi_2 M | (M, N)$$

$$\Gamma, \Delta ::= . \mid \Gamma, x : A$$

$$\begin{array}{ccc}
\frac{}{\vdash .} & \frac{\Gamma \vdash A : \text{TYPE}}{\vdash \Gamma, x : A} & \frac{\Gamma \vdash A : \text{TYPE}}{\Gamma, x : A \vdash x : A} \\
\frac{}{\vdash \Gamma} & \frac{\Gamma \vdash A : \text{TYPE}_i}{\Gamma \vdash \text{TYPE}_i : \text{TYPE}_{i+1}} & \frac{\Gamma \vdash A : \text{TYPE}_i}{\Gamma \vdash \Pi x : A. B : \text{TYPE}_{\max(i,j)}} \\
\frac{\Gamma, x : A \vdash M : B}{\Gamma \vdash \lambda x : A. B : \Pi x : A. B} & \frac{\Gamma \vdash \Pi x : A. B : \text{TYPE}}{\Gamma \vdash M : \Pi x : A. B} & \frac{\Gamma \vdash M : A}{\Gamma \vdash M N : B \{x := N\}} \\
\frac{\Gamma \vdash A : \text{TYPE}_i}{\Gamma \vdash \Sigma(x : A), B : \text{TYPE}_{\max(i,j)}} & \frac{\Gamma \vdash M : A}{\Gamma \vdash (M, N) : \Sigma(x : A).B} & \frac{\Gamma \vdash M : A}{\Gamma \vdash (M, N) : A} \\
\frac{\Gamma \vdash p : \Sigma(x : A).B}{\Gamma \vdash \pi_1 p : A} & \frac{\Gamma \vdash p : \Sigma(x : A).B}{\Gamma \vdash \pi_2 p : B[x := \pi_1 p]} & \frac{\Gamma \vdash M : B}{\Gamma \vdash M : A} \\
\frac{\Gamma \vdash (\lambda x : A. M) N \equiv M \{x := N\}}{\Gamma \vdash \pi_2 (M, N) \equiv N} & (\pi_1 M, \pi_2 M) \equiv M & \frac{\Gamma \vdash \pi_1 (M, N) \equiv M}{\Gamma \vdash M : A} \\
& \text{(congruence rules omitted)} &
\end{array}$$

<caption>Fig. 1. Syntax and typing rules of MLTT</caption>

## 3.1 MLTT

MLTT is the PTS-style type theory described in Figure 1, using, as usual, three statements mutually recursively defined. The statement $\vdash \Gamma$ means that the environment $\Gamma$ is well formed, while $\Gamma \vdash M : A$ means that the term $M$ has type $A$ in environment $\Gamma$ and the statement $\Gamma \vdash A \equiv B$ means $A$ is convertible to $B$ in context $\Gamma$.

MLTT features dependent products, a negative presentation of dependent sums (using projection instead of pattern-matching) and a predicative hierarchy of universes $\text{TYPE}_i$. The conversion judgment features $\beta$-reduction, traditional rules of computation for dependent sums (surjective pairing and projections), together with congruence rules for every constructor. As usual, we note $A \to B$ for $\Pi x : A. B$ when $B$ does not depend on $x$.

MLTT satisfies many good properties among which consistency and decidability of type-checking (see [Abel et al. 2018] for the first mechanized proof of those properties). In the sequel, we present an extension of MLTT with definitional proof irrelevance that preserves those two properties.

## 3.2 Adding sPROP to MLTT

MLTT can be extended with a predicative hierarchy of sorts $\text{sPROP}_i$ by adding the rule

$$\frac{}{\Gamma \vdash \text{sPROP}_i : \text{TYPE}_{i+1}} \vdash \Gamma$$
and extending the rule of creation of a dependent product to deal with sPROP

$$ \frac{\Gamma \vdash A : \mathit{sPROP}_i \qquad \Gamma, x : A \vdash B : \mathit{TYPE}_j}{\Gamma \vdash \Pi x : A. B : \mathit{TYPE}_{\max(i,j)}} $$

$$ \frac{\Gamma \vdash A : \mathit{UNIV}_i \qquad \Gamma, x : A \vdash B : \mathit{sPROP}_j}{\Gamma \vdash \Pi x : A. B : \mathit{sPROP}_{\max(i,j)}} $$

where UNIV is either sPROP or TYPE.

*An impredicative variant.* We will see in section 4 that we can also allow an impredicative version of sPROP, which amounts to just ignoring the indices on sPROP throughout.

The main feature of sPROP is that the types inhabiting it are definitionally proof-irrelevant, which is enforced by the following rule of conversion:

$$ \frac{\Gamma \vdash A : \mathit{sPROP}_i \qquad \Gamma \vdash x : A \qquad \Gamma \vdash y : A}{\Gamma \vdash x \equiv y : A} $$

So far the universe hierarchy of sPROP is mostly unconnected from the universe hierarchy of TYPE's. Therefore, we add several extensions to improve on this. Namely, we add the empty type, a squash operator, a box operator and dependent sums in sPROP. We call the resulting system sMLTT.

## 3.3 Empty Type

We add an empty type in sPROP, eliminable to any type (including those in TYPE which are proof relevant):

$$ \frac{\Gamma \vdash \mathit{sEmpty} : \mathit{sPROP}_i}{\Gamma \vdash \mathit{sEmpty}} \qquad \frac{\Gamma \vdash A : \mathit{UNIV}_i \qquad \Gamma \vdash e : \mathit{sEmpty}}{\Gamma \vdash \mathit{sEmpty\_rect} A e : A} $$

This is enough to define many other types in sPROP. For instance sUnit is just sEmpty $\rightarrow$ sEmpty (whose inhabitant $\lambda x : sEmpty$. $x$ is unique up to conversion due to proof irrelevance).

## 3.4 Squash

We can add a squash operator (a.k.a. bracket type) by the following rules:

$$ \frac{\Gamma \vdash A : \mathit{TYPE}_i}{\Gamma \vdash \|A\| : \mathit{sPROP}_i} $$

$$ \frac{\Gamma \vdash x : A}{\Gamma \vdash \mathit{sq} x : \|A\|} $$

$$ \frac{\Gamma \vdash A : \mathit{TYPE}_i \qquad \Gamma \vdash P : \mathit{sPROP}_j \qquad \Gamma \vdash f : A \rightarrow P \qquad \Gamma \vdash x : \|A\|}{\Gamma \vdash \mathit{unsq} P f x : P} $$

Note that thanks to definitional proof irrelevance, the non-dependent eliminator unsq $P f x$ is enough to define the dependent one.

In an impredicative setting, $\|A\|$, sq $x$ and unsq $P f x$ can be defined using a standard impredicative encoding:

$$ \|A\| \quad := \quad \Pi(P : \mathit{sPROP}), (A \rightarrow P) \rightarrow P $$

$$ \mathit{sq} x \quad := \quad \lambda P : \mathit{sPROP}. \lambda f : A \rightarrow P. f x $$

$$ \mathit{unsq} P f x \quad := \quad x P f $$
In a predicative setting, the situation is similar but the encoding only allows one to define the eliminator to lower universes as captured by the following rules

$$ \frac{\Gamma \vdash A : \mathit{TYPE}_i}{\Gamma \vdash \|A\|_{i,j} : \mathit{sPROP}_{\max(i,j+1)}} \qquad \frac{\Gamma \vdash P : \mathit{sPROP}_j}{\Gamma \vdash f : A \to P} \qquad \frac{\Gamma \vdash x : \|A\|_{i,j}}{j < i} \qquad \Gamma \vdash \mathit{unsq} P f x : P $$

If we want to eliminate the squash type to arbitrary types in a predicative setting, then we have to add it as a primitive.

## 3.5 Box

If we see sPROP as a sub-universe of TYPE there should be an inclusion from sPROP to TYPE, converse to the squash operator.

$$ \frac{\Gamma \vdash A : \mathit{PROP}_i}{\Gamma \vdash \Box A : \mathit{TYPE}_i} \qquad \frac{\Gamma \vdash x : A}{\Gamma \vdash \mathit{box} x : \Box A} \qquad \frac{\Gamma \vdash A : \mathit{sPROP}_i}{\Gamma \vdash P : \Box A \to \mathit{TYPE}_j \text{ or } \Gamma \vdash P : \Box A \to \mathit{sPROP}_j} \qquad \Gamma, x : A \vdash f : P (\mathit{box} x) \qquad \Gamma \vdash x : \Box A \qquad \frac{\Gamma \vdash \mathit{unbox} P f x : P x}{\Gamma \vdash \mathit{unbox} P f (\mathit{box} a) \equiv f a} $$

together with the conversion rule

$$ \Gamma \vdash \mathit{unbox} P f (\mathit{box} a) \equiv f a $$

This time, the dependent elimination can not be deduced from the non-dependent one, and the conversion rule is not automatic, because $\Box A$ lives in $\mathit{TYPE}_i$, not in $\mathit{sPROP}_i$.

Having the box operator is equivalent to allowing one of the sides of a pair to be in sPROP. Indeed, $\Box A$ is the same as $\Sigma(x : A)$.Unit or $\Sigma(x : \mathit{Unit})$.A, and instead of $\Sigma(x : A)$.B with A : sPROP we could use $\Sigma(y : \Box A)$.B[x := \mathit{unbox} A (\lambda z : A. z) y]$.

This is what we need to be able to talk about properties with both relevant and irrelevant parts. For instance the type of symmetric strict relations on some type A is

$$ \Sigma(R : A \to A \to \mathit{sPROP}) \cdot \Pi x y : A. R x y \to R y x $$

$A \to A \to \mathit{sPROP}$ is a large type, and the proof of symmetry is an sPROP.

Making the box a primitive construct and deriving from it the concept of relevant pairs with an irrelevant component allows for a better separation of concerns. For instance, if we allowed irrelevant components in pairs with eta we would have to take care that if all components were irrelevant, then the resulting type would be definitionally irrelevant and so should be in sPROP.

In the implementations for Coq and Agda the box is subsumed by inductive types, see Section 6.

## 3.6 Dependent Sums

If both components of a pair are in sPROP, we can allow the pair itself to be in sPROP too:

$$ \frac{\Gamma \vdash A : \mathit{sPROP}}{\Gamma \vdash \Sigma_s(x : A).B} \qquad \frac{\Gamma \vdash p : \Sigma_s(x : A).B}{\Gamma \vdash \pi_{s1} p : A} \qquad \frac{\Gamma \vdash p : \Sigma_s(x : A).B}{\Gamma \vdash \pi_{s2} p : B[x := \pi_{s1} p]} $$
Since we have definitional proof irrelevance, the expected computation rules for the projections and the surjective pairing conversion rule already hold and do not have to be added explicitly to the conversion.

In an impredicative setting, dependent sums can be encoded as follows:

$$ \Sigma_s(x : A).B \quad \coloneqq \quad \Pi P \text{ : sPROP. } (\Pi x : A. B x \to P) \to P $$

$$ (a, b) : \Sigma_s(x : A).B \quad \coloneqq \quad \lambda P \text{ : sPROP. } \lambda f : \_ . f a b $$

$$ \pi_{s1}(p : \Sigma_s(x : A).B) : A \quad \coloneqq \quad p A (\lambda x : A. \lambda y : B x. x) $$

$$ \pi_{s2}(p : \Sigma_s(x : A).B) : B(\pi_{s1} p) \quad \coloneqq \quad p (B(\pi_{s1} p)) (\lambda x : A. \lambda y : B x. y) $$

Note that $\pi_{s2}$ is well typed due to proof irrelevance of A.

Dependent sums can also be encoded in a predicative setting extended with primitive squash and box:

$$ \Sigma_s(x : A).B \quad \coloneqq \quad \|(x : \square A).\square B(\mathit{unbox} A \ id \ x)\| $$

$$ (a, b) : \Sigma_s(x : A).B \quad \coloneqq \quad \mathit{sq} (\mathit{box} a, \mathit{box} b) $$

$$ \pi_{s1}(p : \Sigma_s(x : A).B) : A \quad \coloneqq \quad \mathit{unsq} A (\lambda x : \_. \mathit{unbox}_\_ \ id (\pi_{s1} x)) p $$

$$ \pi_{s2}(p : \Sigma_s(x : A).B) : B(\pi_{s1} p) \quad \coloneqq \quad \mathit{unsq} (B(\pi_{s1} p)) (\lambda x : \_. \mathit{unbox}_\_ \ id (\pi_{s2} x)) p $$

where we have omitted some obvious type annotations and where id is the identity function.

## 3.7 Other Inductive Types

There is no need for other primitive inductive types in sPROP (assuming the corresponding proof relevant inductive types are available in TYPE).

Indeed, either an inductive should not be permitted in sPROP because it would introduce inconsistency (booleans) or undecidability (accessibility) and in that case, squashing the corresponding proof relevant inductive type is enough.

In the other case, if the inductive type satisfies the criteria for being in sPROP, we will see in section 5 that it can actually be encoded as a recursive definition using sEmpty, sUnit and proof irrelevant pairs. This translation comes with preconditions on the shape of the inductive type being translated, preventing it from working in cases where the inductive cannot be regarded as a strict proposition such as booleans (which would make the theory inconsistent) or the accessibility predicate (which would make conversion undecidable).

# 4 METATHEORETICAL PROPERTIES OF sMLTT

In this section, we prove the consistency of the predicative version of sMLTT by reducing it to the consistency of Extensional Type Theory (ETT). We then remark that the impredicative version is justified by the propositional resizing rule proposed by Vladimir Voevodsky [Voevodsky 2011]. We further show that sMLTT is either compatible with the univalence axiom or supports a computational version of UIP, depending on whether we authorize elimination of equality in sPROP or not. Finally, we show that type checking of sMLTT is decidable by modifying the proof by logical relations of Abel et al [Abel et al. 2018; Abel and Scherer 2012].

## 4.1 ETT

ETT is an extension of MLTT, presented in Figure 2, with a propositional equality $x =_A y$ that satisfies the reflection rule, that is every propositionally equal terms are convertible. We also assume that there is a type Unit with only one inhabitant tt.

It is well known that ETT has an undecidable type checking as deciding conversion requires to decide propositional equality, since it is possible to encode the halting problem with an equality in ETT. But ETT still satisfies some good properties: it has a decidable “derivation” checking and
$$A, B, M, N ::= \dots | M =_A N | \mathrm{refl}_M | J(y.q.M, e, u)$$

$$\frac{\Gamma \vdash A : \mathrm{TYPE}_i \qquad \Gamma \vdash x : A \qquad \Gamma \vdash y : A}{\Gamma \vdash x =_A y : \mathrm{TYPE}_i} \qquad \frac{\Gamma \vdash e : x =_A y}{\Gamma \vdash x \equiv y} \qquad \frac{\Gamma \vdash M : A}{\Gamma \vdash \mathrm{refl}_M : M =_A M}$$
$$\frac{\Gamma \vdash e : M =_A N \qquad \Gamma, y : A, q : M =_A y \vdash P : \mathrm{TYPE}_i \qquad \Gamma \vdash u : P\{y := M\}\{q := \mathrm{refl}_M\}}{\Gamma \vdash J(y.q.P, e, u) : P\{y := N\}\{q := e\}}$$
$$\Gamma \vdash J(y.q.P, \mathrm{refl}_M, u) \equiv u \qquad (+ \text{ other rules of MLTT})$$

<caption>Fig. 2. Syntax and typing rules of ETT</caption>

it is consistent as it is conservative over MLTT with an identity type (plus UIP and functional extensionality), as shown by Martin Hofmann [Hofmann 1995].

We should notice that using the reflection rule and $\eta$-law for functions, one can derive functional extensionality, that is given two functions $f, g : \Pi x : A. B$ there is a term

$$\mathrm{funext}_{f,g} : (\Pi a : A. f a =_{B(x := a)} g a) \rightarrow f =_{\Pi x : A. B} g$$

Also, the reflection rule allows deriving UIP. So adding the reflection rule to MLTT has additional consequences. We show in this section that for sMLTT, UIP can be safely added, but is independent from the theory, as we show in Section 4.3 that sMLTT is compatible with univalence.

## 4.2 Consistency of sMLTT

Following the notion of syntactical translations advocated in [Boulier et al. 2017], we prove consistency of sMLTT by a type preserving translation from sMLTT into ETT. The idea of the translation is to see inhabitant of sPROP as a pair of type in ETT together with a proof that it is a mere proposition. Therefore, sPROP is translated as the following dependent sum:

$$[sPROP_i] := \Sigma A : TYPE_i. \Pi x : A. x = y.$$

The rest of the translation is rather straightforward, but for the fact that we need to provide an additional proof that type constructors which end in sPROP build mere propositions. For instance, the fact that a dependent product whose codomain is a mere proposition is itself a mere proposition can be proven using functional extensionality in ETT. Definitional proof irrelevance is then modeled by the fact that every inhabitant of sPROP is a mere proposition together with the reflection rule of ETT.

The translation is described in Figure 3, where $eq_\Sigma$ is defined as the witness that equality between elements of a dependent sum is given by the equality of the corresponding projections (which is provable using $J$)

$$\mathrm{eq}_\Sigma : \Pi x : \Sigma a : A. B. \pi_1 x =_A \pi_1 y \rightarrow \pi_2 x =_{B\{a := \pi_1 x\}} \pi_2 y \rightarrow x =_{\Sigma a : A. B} y.$$

Note that this statement is slightly more involved in intentional type theory<fnref n="8" /> as the second equality does not type-check in MLTT, because $\pi_2 y$ does not have type $B\{a := \pi_1 x\}$. Here, the situation is simpler as we can use the reflection rule to convert $B\{a := \pi_1 y\}$ into $B\{a := \pi_1 x\}$ using the first equality.

<footnote n="8">⁸The precise statement and a proof of it can be found for instance in [Univalent Foundations Program 2013].</footnote>
<figure><img src="image_2.png" /><figcaption>Fig. 3. Syntactical Translation from sMLTT to ETT</figcaption></figure>

The following two properties are proved by mutual induction (although we state them separately for readability).

LEMMA 4.1 (PRESERVATION OF CONVERSION). For every term $t$ and $u$ of sMLTT, if $\Gamma \vdash t \equiv u : A$ then $[\Gamma] \vdash [t] \equiv [u]$ in ETT.

PROOF. By induction on the proof of congruence. The structure of the term is preserved by the translation, so $\beta$-reduction and congruence rules are automatically preserved. The only interesting case is the rule for definitional proof-irrelevance which says that when $\Gamma \vdash A : sPROP$, then $t$ and $u$ are convertible. But by correctness of the translation (Theorem 4.2), we know that $[\Gamma] \vdash [A] : \Sigma A : TYPE_i$. $\Pi x y : A. x = y$ and $[t]$, $[u]$ have type $[A]$. Thus we can form of proof of $[t] = [u]$ by $[A]_{pf} [t] [u]$. From which we deduce $[t] \equiv [u]$ by the reflection rule. $\square$

THEOREM 4.2 (CORRECTNESS OF THE SYNTACTICAL TRANSLATION). For every typing derivation of sMLTT $\Gamma \vdash M : A$, we have the corresponding derivation $[\Gamma] \vdash [M] : [A]$ in ETT.
$$
\begin{align*}
[TYPE_i] &:= \Sigma A : FTYPE_i. \text{Unit} \\
[sPROP_i] &:= \Sigma A : FTYPE_i. \Pi x y : A. x = y
\end{align*}
$$

<caption>Fig. 4. Syntactical Translation from sMLTT to HTS</caption>

PROOF. By induction on the typing derivation.

□

About impredicativity and resizing rules. ETT is not sufficient to interpret impredicativity of sPROP in sMLTT, because if we state [sPROP] := ΣA : TYPE₀. Πx y : A. x = y, where TYPE₀ is some fixed universe (let say the first one) in the hierarchy, then the typing rule for impredicativity of dependent product for sPROP can not be interpreted by the translation because for Γ ⊢ A : TYPEᵢ and Γ, x : A ⊢ B : sPROP, one has that

$$
[[\Gamma]] \vdash [\Pi x : A. B] : \Sigma A : TYPE_i. \Pi x y : A. x = y
$$

To remedy this situation, we can make use of the propositional resizing rule introduced by Vladimir
Voevodsky [Voevodsky 2011], which says that every mere proposition can be put in the universe
TYPE₀.

$$
\frac{\Gamma \vdash A : \mathbf{TYPE}_i \qquad \Gamma \vdash e : \Pi x y : A. x =_A y}{\Gamma \vdash \mathrm{rr}(A, e) : \mathbf{TYPE}_0}
$$

The propositional resizing is justified by any classical model of ETT, that is a model which satisfies the law of excluded middle, because in such a model, every mere proposition is either sEmpty or Unit and thus lives in the lowest universe.<fnref n="9" /> Using propositional resizing, it is thus possible to define the coercion<fnref n="10" />

$$
\begin{align*}
\mathrm{rr}_{\mathrm{sPROP}} & : & (\Sigma A : \mathrm{TYPE}_i . \Pi x y : A. x = y) & \rightarrow \Sigma A : \mathrm{TYPE}_0 . \Pi x y : A. x = y \\
& := & \lambda A : \_ . (\mathrm{rr}(\pi_1 A, \pi_2 A)), \lambda x y : \mathrm{rr}(\pi_1 A, \pi_2 A) . \pi_2 A x y)
\end{align*}
$$

which is enough to interpret impredicativity of sPROP.

4.3 sMLTT is Compatible with Univalence

We now show that sMLTT is compatible with univalence, and thus in particular, definitional proof irrelevance does not necessary imply UIP. To that end, we consider an extension of ETT with a second notion of equality, but restricted to *fibrant* types. This extension has first been proposed by Vladimir Voevodsky under the name Homotopy Type System (HTS) [Voevodsky 2013] and has later been reworked by Paolo Capriotti et. al. under the name two-level type theory [Altenkirch et al. 2016; Capriotti 2017] (which may or may not be extensional for the strict equality). Those two systems differ slightly. In particular, in HTS, there is only one type of integers which is fibrant, whereas two level type theory distinguishes between fibrant and non-fibrant types. However, those differences are not important for our purpose, so even though we refer to HTS, we could also have used an extensional two-level type theory.

The main idea of HTS is to distinguish between types which live in TYPEᵢ for which equality is strict, and fibrant types which live in FTYPEᵢ for which there are two notions of equality: strict equality a =ₐ b and homotopical equality a ~ₐ b. The rules for a ~ₐ b are the same as for

<footnote n="9">⁹Vladimir Voevodsky has also introduced other resizing rules involving type equivalences which are a bit more controver-
sial as their justifications have not been completely written up.</footnote>

<footnote n="10">¹⁰For simplicity, we assume that inhabitants of A and rrA are the same, but to keep type-checking decidable, we should use explicit wrapper from one to the other.</footnote>
$$ \frac{\Gamma \vdash A : \mathit{TYPE}_i \qquad \Gamma \vdash x : A \qquad \Gamma \vdash y : A \qquad \Gamma \vdash M : A}{\Gamma \vdash x =^s_A y : \mathit{sPROP}_i} \qquad \frac{\Gamma \vdash \mathit{refl}_M^s : M =^s_A M}{\Gamma \vdash u : P\{y := M\}\{q := \mathit{refl}_M^s\}} \\ \frac{\Gamma \vdash e : M =^s_A N \qquad \Gamma, y : A, q : M =^s_A y \vdash P : \mathit{TYPE}_i}{\Gamma \vdash J_s(y.q.P, e, u) : P\{y := N\}\{q := e\}} \qquad \Gamma \vdash J_s(y.q.P, \mathit{refl}_M, u) \equiv u $$

<caption>Fig. 5. Definition of a strict equality type.</caption>

propositional equality, except that the formation of $a \sim_A b$ is only possible when $A$ is fibrant, and the eliminator $J_\sim$ is restricted to fibrant predicates:

$$ \frac{\Gamma \vdash e : M \sim_A N \qquad \Gamma, y : A, q : M \sim_A y \vdash P : \mathit{FTYPE}_i \qquad \Gamma \vdash u : P\{y := M\}\{q := \mathit{refl}_M^\sim\}}{\Gamma \vdash J_\sim(y.q.P, e, u) : P\{y := N\}\{q := e\}} $$

Then, the type of propositional equality is not fibrant, so it is not possible to derive propositional equalities from homotopical ones.

We can modify the translation of Figure 3 to target the *fibrant fragment* of HTS. In this case, types and propositions are interpreted as fibrant types, as shown in Figure 4. Note that $[sPROP_i]$ is not by definition fibrant in HTS, so before stating the correctness of this modified translation, we need to introduce a new rule in HTS in order to have

$$ [sPROP_i] : \mathit{FTYPE}_i. $$

This rule is admissible as has been proven by Thierry Coquand in his note on the universes of Bishop sets and strict propositions [Coquand 2016]. Indeed, using the cubical model of type theory (which is a model of HTS), Thierry Coquand shows in particular that the universe of strict propositions is fibrant (Theorem 6.2).

It is now easy to replay the proof of Theorem 4.2 to show the correctness of the syntactical translation in HTS and conclude the following corollary.

**COROLLARY 4.3.** *sMLTT is compatible with univalence.*

**PROOF.** As the translation of $TYPE_i$ is isomorphic to $FTYPE_i$ and the translation of a dependent product in $TYPE_i$ is directly translated as a dependent product, we can add a univalent fibrant equality in $TYPE_i$ in sMLTT which is simply translated as the univalent equality in $FTYPE_i$. $\square$

## 4.4 Strict Identity and UIP

We now consider an optional extension, adding propositional equality in sPROP. Since this implies uniqueness of identity proofs, this extension is not always desired, in particular if we want to stay compatible with univalence, but we mention it because it provides a very simple and modular way to add UIP in the system.

In this context, the computation rule for equality in sPROP can equivalently be stated as $\Gamma \vdash J(x.q.P, e, u) \equiv u$ when $e : x =^s x$, as already noted by Benjamin Werner in [Werner 2008]. The consistency of this extension is direct as it is justified by the translation presented in Figure 3 by simply adding

$$ [x =^s_A y] := ([x] =_{[A]} [y], \mathrm{ui}p \llbracket A \rrbracket [x] [y]) $$
where uip $Ax y: Π e e' : x =_A y. e =_{x=y} e'$ is a proof of UIP in ETT. Then refl<sup>s</sup> and $J_s$ are directly translated using refl and $J$.

## 4.5 Relevance Marks and Decidability of Type Checking

A naïve implementation of type theory with sPROP requires to check during conversion if the terms we are comparing are relevant or not. To compute this information requires 2 rounds of typing: first to get its type, then to get the sort of the type, but this is not very efficient. There is another issue, this time on the theoretical side: conversion can not be defined independently from typing, and the standard technique to prove decidability of type checking developed by Andreas Abel and others [Abel et al. 2018; Abel and Scherer 2012] based on algorithmic equality and logical relations does not apply. We now introduce a notion of term annotation that allows to solve both issues at the same time, thus making it possible to decide irrelevance syntactically, without relying on type checking.

Specifically, we annotate lambdas and products according to the relevance of the bound type. The same is done for each variable in a context. When adding a variable to a context and when typing a function or product type we need to check the mark on the variable. The syntax with sPROP and the inference rules for adding a variable to a context are described in Figure 6. Adapting the other rules and adding extensions is straightforward and left as an exercise to the reader.

$$ 
\begin{array}{l}
\begin{array}{l}
\ast ::= \text{Relevant} \mid \text{Irrelevant} \\
A, B, M, N ::= sPROP_i \mid TYPE_i \mid x \mid M \mid N \mid \lambda x^* : A. M \\
\phantom{A, B, M, N} | \Pi x^* : A. B \mid \Sigma x : A. B \mid \pi_1 M \mid \pi_2 M \mid (M, N) \\
\Gamma, \Delta ::= . \mid \Gamma, x^* : A
\end{array}
\\[1em]
\frac{\Gamma \vdash A : TYPE_i}{\vdash \Gamma, x^{\text{Relevant}} : A} \qquad \frac{\Gamma \vdash A : sPROP_i}{\vdash \Gamma, x^{\text{Irrelevant}} : A}
\end{array}
$$

<caption>Fig. 6. sMLTT with relevance marks</caption>

The procedure to decide the relevance of a term in a context is defined by induction on the syntax:

* relevance<sub>Γ</sub>(x) := * when $x^* \in \Gamma$

* relevance<sub>Γ</sub>(M N) := relevance<sub>Γ</sub>(M)

* relevance<sub>Γ</sub>(λx* : A. M) := relevance<sub>Γ,x*:A</sub>(M)

* Everything else (sorts, product types, relevant sigma types, relevant pairs and relevant projections) is relevant.

As binders for product types are annotated, we can pass this annotation to the context when we go under the binder (for instance in a conversion procedure). Binders in Σ types need no annotation since they are always relevant.

**PROPOSITION 4.4.** For M well typed in Γ, relevance<sub>Γ</sub>(M) = Irrelevant if and only if there exists A such that Γ ⊢ M : A and Γ ⊢ A : sPROP.

**PROOF.** By induction on the typing derivation of M. Only the case for application is of interest. The crucial property is that relevance is stable by well-typed substitution: if Γ, x* : A ⊢ T : s,
$Γ ⊢ e : A$ and $Γ ⊢ T[x := e] : s'$ then $s$ is sPROP if and only if $s'$ is sPROP. This is given by uniqueness of typing and the fact that substitution is type preserving. □

In a setting with cumulativity, for instance in Coq, uniqueness of typing expresses that two types of the same term have a common upper bound, so for correctness of marks, implicit cumulativity from sPROP to TYPE must be forbidden, instead relying on explicit cumulativity through □.

Using relevance marks, we can replay the proof of decidability of type checking of Andreas Abel and Gabriel Scherer using algorithmic equality and logical relations [Abel and Scherer 2012]—for sMLTT without a strict equality, as the work of Abel et al. does not deal with identity types.

Their setting was designed to handle irrelevant arguments, where irrelevance was marked on the typing annotation $Γ ⊢ t \div A$ which says that $t$ is used irrelevantly. Here we replace this irrelevance annotation by $Γ ⊢ t : A \land relevance_Γ(t) = \text{Irrelevant}$. That is, the annotation is not on the typing judgment but directly on the term. Concretely, we replace the rule for dealing with irrelevance in the definition of structural equality on neutral terms by

$$ \frac{\Gamma \vdash n \leftrightarrow n' : A \quad \text{relevance}_\Gamma(n) = \text{Irrelevant} \quad \Gamma \vdash n' \leftrightarrow n' : A}{\Gamma \vdash n \leftrightarrow n' : A} $$

Once this change has been done, we can replay their proof directly to get:

**THEOREM 4.5 (FROM THEOREM 6.7, [ABEL AND SCHERER 2012])**. $Γ ⊢ t \equiv t' : T$ is decidable.

# 5 FROM INDUCTIVE TYPE TO A FIXPOINT

So far, we have described the type theory sMLTT with a universe sPROP consisting of function types, the empty type, the unit type, dependent sum types, and a squash type. But in general we also want to define arbitrary inductive types in sPROP. On one hand, we can always define an inductive type in TYPE and then apply the propositional squash to bring it into sPROP, but this restricts its elimination principle to target types in sPROP. On the other hand, we mentioned before that certain inductive types can be translated to fixpoints using just the empty type, unit type, and dependent sum as the basic building blocks in sPROP. This translation has already been intuitively sketched in Section 2.4. In this section, we give a formal criterion for when this translation is possible and show how it can be automated.

The algorithm described here is inspired by the elaboration of definitions by dependent pattern matching to a case tree described by Cockx and Abel [2018], and makes heavy use of much of the same machinery for case analysis and proof-relevant unification.

Note that there are other ways to define datatypes with a dependent elimination principle, as for instance by using an impredicative encoding in a type theory enriched with dependent intersections types as done in Cedille [Stump 2018].

## 5.1 Constructing the Case Tree

From a high-level view, the idea of the translation is to view the definition of the inductive type as a *function* that does some case analysis on the indices and returns the argument types of the appropriate constructor in each case. The types for which this translation succeeds are exactly the types in sPROP that can be eliminated into arbitrary types. For example, recall from Section 2.4 that we can view the definition of $\le$ as the following definition:

Equations $\le_{fix} (n m : \mathbb{N}) : sProp :=$
$0 \le_{fix} n := sUnit;$
$S m \le_{fix} S n := m \le_{fix} n;$
$S _ \le_{fix} 0 := sEmpty.$
One challenge in this translation is to determine which constructor arguments should appear on the right-hand side: for the constructor $\leq S$ (in the second equation), the argument of type $m \leq n$ makes an appearance but the first two arguments $m$ and $n$ do not. These disappearing arguments correspond exactly to the *forced arguments* of the constructor: their values can be uniquely determined from the type.

To tackle this problem in general, we choose not to translate the inductive definition to a list of clauses, but directly to a case tree. For example, we construct the following case tree for $\leq$:

$$ m \leq n := \mathbf{case}_m \left\{ \begin{array}{lcl} 0 & \mapsto & \leq 0 \\ S m' & \mapsto & \mathbf{case}_n \left\{ \begin{array}{lcl} 0 & \mapsto & \perp \\ S n' & \mapsto & \leq S (p : m' \leq n') \end{array} \right\} \end{array} \right\} $$

In general, a case tree representing an inductive datatype in sPROP is either a leaf node of the form $c \Delta$ where $c$ is a constructor name and $\Delta$ is a telescope of types in sPROP, an empty node $\perp$, or an internal node of the form

$$ \mathbf{case}_x \{c_1 \hat{\Delta}_1 \mapsto \tau_1 Q_1; \dots; c_n \hat{\Delta}_n \mapsto \tau_n Q_n\} $$

where $x$ is a variable, $c_i$ are constructors with fresh variables $\hat{\Delta}_i$ for arguments, $\tau_i$ are substitutions (these will be explained later), and $Q_i$ are again case trees.

For constructing a case tree from the declaration of the inductive type, we work on an elaboration problem $P$ of the form

$$ \Gamma \vdash \{c_1 \Delta_1 [\Phi_1]; \dots; c_k \Delta_k [\Phi_k]\} $$

where:

* $\Gamma$ is the 'outer' telescope of datatype indices,

* $c_1, \dots, c_k$ are the names of the constructors,

* $\Delta_i$ is the 'inner' telescope of arguments of $c_i$, and

* $\Phi_i$ is a set of constraints $\{w_{ij} / \rho v_{ij} : A_{ij} | j = 1 \dots l\}$.

To transform the definition of an inductive datatype $D$ to a case tree, the initial elaboration problem has for $\Gamma$ the index telescope of $D$, $c_1, \dots, c_k$ all constructors of $D$, $\Delta_i$ the argument telescope of $c_i$, and $\Phi_i = \{x_j / \rho v_{ij} : A_j | j = 1 \dots l\}$ where $\Gamma = (x_1 : A_1) \dots (x_l : A_l)$ and $v_{il}, \dots, v_{il}$ are the indices targeted by $c_i$, i.e. $c_i : \Delta_i \to D v_{il} \dots v_{il}$. For example, for $\leq$ we start with the following elaboration problem:

$$ (m n : \mathbb{N}) \vdash \left\{ \begin{array}{lcl} \leq 0 & (n' : \mathbb{N}) & [m / \rho 0 : \mathbb{N}, n / \rho n' : \mathbb{N}] \\ \leq S & (m' n' : \mathbb{N}) & (p : m' \leq n') [m / \rho S m' : \mathbb{N}, n / \rho S n' : \mathbb{N}] \end{array} \right\} $$

From this initial problem, the elaboration proceeds by successive case splitting on variables in $\Gamma$ and simplification of constraints in $\Phi_i$ until there are only zero or one constructors left and all constraints have been solved. More specifically, the elaboration algorithm may perform the following steps:

**EMPTY** If there are no constructors left, elaboration is done and returns the case tree $\perp$:

$$ \Gamma \vdash \{\} \rightsquigarrow \perp $$

**DONE** If there is a single constructor left and all constraints are solved, elaboration checks if all remaining arguments of the constructor are in sPROP. If this is the case, it returns a leaf node containing this constructor:

$$ \frac{\forall (x : A) \in \Delta. \ A : \mathrm{sPROP}}{\Gamma \vdash \{c \ \Delta \} \rightsquigarrow c \ \Delta} $$
**SOLVE CONSTRAINT** If there is a constraint of the form $y /? x$ where $x$ is bound in $\Delta$ and $y$ bound in $\Gamma$, we can instantiate the variable $x$ to $y$, removing it from $\Delta$ in the process:

$$ \frac{\Gamma \vdash \{c \Delta_1(\Delta_2[y/x]) [\Phi]\} \rightsquigarrow Q \quad (x: A) \in \Gamma}{\Gamma \vdash \{c \Delta_1(x: A) \Delta_2 [y /? x: A, \Phi]\} \rightsquigarrow Q} $$

**SIMPLIFY CONSTRAINT** If the left- and right-hand side of a constraint are applications of the same constructor, we can simplify the constraint:

$$ \frac{d : \Delta' \rightarrow D \bar{w}' \quad \Gamma \vdash \{c \Delta [\bar{v} /? \bar{u} : \Delta', \Phi]; P\} \rightsquigarrow Q}{\Gamma \vdash \{c \Delta [d \bar{v} /? d \bar{u} : D \bar{w}, \Phi]; P\} \rightsquigarrow Q} $$

**REMOVE CONSTRAINT** If a constraint is trivially satisfied, it can be removed:

$$ \frac{\Gamma \vdash u = v : A \quad \Gamma \vdash \{c \Delta [\Phi]; P\} \rightsquigarrow Q}{\Gamma \vdash \{c \Delta [v /? u : A, \Phi]; P\} \rightsquigarrow Q} $$

**REMOVE CONSTRUCTOR** If a constraint is unsolvable because the left- and right-hand side are applications of distinct constructors, the constructor does not contribute to this branch of the case tree and can be safely removed:

$$ \frac{\Gamma \vdash \{P\} \rightsquigarrow Q}{\Gamma \vdash \{c \Delta [d_2 \bar{v} /? d_1 \bar{u} : D \bar{w}, \Phi]; P\} \rightsquigarrow Q} $$

**SPLIT** Finally, if $(x : D \bar{w}) \in \Gamma$ and each constraint set $\Phi_i$ contains a constraint of the form $x /? d_j \bar{u}_j : D \bar{w}$ where $d_j$ is a constructor of the datatype $D$, elaboration continues by performing a case split on $x$. For each constructor $d_j : \Delta'_j \rightarrow D \bar{w}'_j$, we use proof-relevant unification [Cockx and Devriese 2018] to determine whether this constructor can be used at indices $\bar{w}$. For each of the constructors for which unification succeeds positively, elaboration continues to construct a subtree for that constructor.

$$ \frac{\begin{array}{l} (x:D\bar{w}) \in \Gamma \qquad D:\Psi \rightarrow \text{TYPE} \\ d_j : \Delta'_j \rightarrow D \bar{w}'_j \qquad \text{for } j=1 \dots l \\ \text{UNIFY}(\Gamma \Delta'_j \vdash \bar{w} = \bar{w}'_j : \Psi) \Rightarrow \text{YES}(\Gamma_j, \sigma_j, \tau_j) \qquad \text{for } j=1 \dots k \quad (k \le l) \\ \text{UNIFY}(\Gamma \Delta'_j \vdash \bar{w} = \bar{w}'_j : \Psi) \Rightarrow \text{NO} \qquad \text{for } j=k+1 \dots l \\ \Gamma_j \vdash \{c_i \Delta_i \sigma_j [\Phi_i \sigma_j] | i=1 \dots m\} \rightsquigarrow Q_j \qquad \text{for } j=1 \dots k \\ \Gamma \vdash \{c_i \Delta_i [\Phi_i] | i=1 \dots m\} \rightsquigarrow \text{case}_x \{d_j \Delta'_j \mapsto \tau_j : Q_j | j=1 \dots k\} \end{array}} $$

The elaboration algorithm repeats the steps above whenever they are applicable until it either produces a complete case tree, or gets stuck because no rules apply.

We can make the above elaboration algorithm more powerful in various places by introducing additional squash operators:

* If not all constructor arguments are in SPROP, we can squash the types of those that are not.

* If there are multiple constructors left but no unsolved constraints, we may take the disjoint sum of the constructor telescopes and squash the resulting type.

* If there are unsolved constraints but it is not possible to split on any variable, we may turn each remaining constraint $w /? v : A$ into a new constructor argument of type $||v =_A w||$.

However, each of these options may reduce the ways in which we can eliminate the resulting type, so they may not always be desirable.
## 5.2 Generating the Constructors and the Eliminator

To make practical use of the type constructed by the elaboration algorithm from the previous section, we also need terms representing the constructors and the eliminator for the translated type. For example, for $m \le n$ we can define terms $1z : (n : \mathbb{N}) \to 0 \le n$ and $1s : (m n : \mathbb{N}) \to m \le n \to S m \le S n$ by $1z = \lambda n. \tt and \ 1s = \lambda m n p. \ p$ respectively. Note that these terms are type-correct since $0 \le n = \text{sUnit}$ and $S m \le S n = m \le n$. We can also define the eliminator $\le\_rect$ by performing the same case splits as in the translation of the type $\le$:

$$ 
\begin{align*}
\le\_rect : (P : (m n : \mathbb{N}) \to m \le n \to \text{TYPE}) & (m_{\le 0} : (n : \mathbb{N}) \to P 0 n (1z n)) \\
& (m_{\le S} : (m n : \mathbb{N})(H : m \le n) \to P m n x \to P (S m) (S n) (1s m n x)) \\
& (m n : \mathbb{N})(x : m \le n) \to P m n x
\end{align*}
$$

$$ \le\_rect P m_{\le 0} m_{\le S} m n x $$

$$ = \text{case}_m \left\{ \begin{array}{ll} 0 & \mapsto m_{\le 0} n \\ S m' & \mapsto \text{case}_n \left\{ \begin{array}{ll} 0 & \mapsto \text{sEmpty\_rect } x \\ S n' & \mapsto m_{\le S} m' n' x (\le\_rect P m_{\le 0} m_{\le S} m' n' x) \end{array} \right\} \end{array} \right\} $$

Since the eliminator is the defining property of a datatype, being able to construct the eliminator shows the correctness of the translation. In particular, the eliminator can be used to show that the generated type is equivalent to its inductive version.

*Constructing the constructors.* Let $c : \Delta \to D \bar{w}$ be one of the constructors of $D$. By construction, the case tree of $D$ will have a leaf of the form $c \Delta'$ where the variables bound by $\Delta'$ form a subset of those bound in $\Delta$. We thus define the term $c$ as $\lambda x_1 \dots x_n (x_{i_1}, \dots, x_{i_m})$ where $\Delta = (x_1 : A_1) \dots (x_n : A_n)$ and $\Delta' = (x_{i_1} : A'_{i_1}) \dots (x_{i_m} : A'_{i_m})$.

Beware, as it is not immediately obvious that this term is type-correct: $A'_i$ is not necessarily equal to $A_i$, since the variables in $\Delta \setminus \Delta'$ have been substituted in the process. However, since the `SOLVE CONSTRAINT` step only applies when both sides of the constraint are variables, this substitution is just a renaming. We can apply the same renaming to $\Delta'$, thus ensuring that the term $c$ is indeed of type $\Delta \to D \bar{w}$.

*Constructing the eliminator.* The eliminator $D\_rect$ for the elaborated datatype $D : \Gamma \to \text{TYPE}$ with constructors $c_i : \Delta_i \to D \bar{v}_i$ for $i = 1 \dots k$ takes the following arguments:

* The motive $P : \Gamma \to D \hat{\Gamma} \to \text{TYPE}$

* The methods

$$ m_i : \begin{array}{l} \Delta_i \to (H_1 : \Psi_{i1} \to P \bar{w}_{i1} (x_{ij_1} \hat{\Psi}_{i1})) \to \dots \to \\ \qquad (H_{q_i} : \Psi_{iq_i} \to P \bar{w}_{iq_i} (x_{ij_{q_i}} \hat{\Psi}_{iq_i})) \to P \bar{v}_i (c_i \hat{\Delta}_i) \end{array} $$

where $(x_{ij_p} : \Psi_{ip} \to D \bar{w}_{ip}) \in \Delta_i$ for $p = 1 \dots q_i$ are the recursive arguments of the constructor $c_i$.

and produces a function of type $\Gamma \to (x : D \hat{\Gamma}) \to P \hat{\Gamma} x$.

To construct this eliminator, we proceed by induction on the case tree defining $D$: for each case split in the elaboration of $D$, we perform the same case split on the corresponding index in $\Gamma$. At each leaf, we are either in an empty node or a constructor node.

* In an empty node, we have $x : \text{sEmpty}$, hence we can conclude by `sEmpty\_rect`.

* In a constructor node for constructor $c_i$, $x$ is a nested tuple consisting of the non-forced arguments of $c_i$. Moreover, the remaining telescope of indices $\Gamma'$ contains the forced arguments of $c_i$. We thus apply the motive $m_i$ to arguments for $\Delta_i$ taken from $x$ and $\Gamma'$. For the induction hypotheses $H_p$ we call the eliminator recursively with arguments $\bar{w}_{ip} (x_{ij_p} \hat{\Psi}_{ip})$
where $x_{ij_p}$ is again taken from either $x$ or $\Gamma'$. Note that this recursion is well-founded if and only if the recursive definition of the datatype itself is so.

This finishes the construction of the eliminator. It can easily be checked that the eliminator we just constructed also has the appropriate computational behaviour: $D\_rect P m_1 ... m_k \bar{v}_i (c_i \hat{\Delta}_i)$ evaluates to $m_i \hat{\Delta}_i (\lambda \hat{\Psi}_{i1} . D\_rect \bar{w}_{i1} (x_{ij_1} \hat{\Psi}_{i1})) ... (\lambda \hat{\Psi}_{iq_i} . D\_rect \bar{w}_{iq_i} (x_{ij_{q_i}} \hat{\Psi}_{iq_i}))$.

# 6 IMPLEMENTATION IN Coq AND Agda

## 6.1 Implementation in Coq

*The universe hierarchy.* Coq comes with an infinite hierarchy of predicative universes $TYPE_i$ and an impredicative universe $PROP : TYPE_1$. Cumulativity makes each universe a subtype of the next, with $PROP$ a subtype of $TYPE_0$. We add to this $sPROP : TYPE_1$ but do not include $sPROP$ in the cumulativity relation. This lack of cumulativity is necessary to use relevance marks in the conversion (as already mentioned in Section 4.5).

The lack of cumulativity can cause issues during the elaboration phase, as the system assumes cumulativity throughout. For instance, consider the type of the dependent eliminator for $sEmpty$:

Definition sEmpty_rect_type := ∀ (P:sEmpty → Type) x, P x.

During elaboration an existential variable $?T : TYPE$ is generated for the type of $x$, then it must be unified with $sEmpty : sPROP$. For this to be well-typed we must have cumulativity.

The system works around this issue by allowing cumulativity of $sPROP$ during elaboration but not when checking definitions. In the above case the use of cumulativity disappears when the existential variable is instantiated so there is no error. When cumulativity is truly necessary the error is delayed until the kernel check.

### 6.1.1 Conversion.
Conversion in Coq is untyped so we use relevance marks as described in Section 4.5 to implement definitional proof irrelevance. Since Coq is a richer system than sMLTT there are a few additional cases. For instance, constants are annotated with their relevance as part of the context, and fixpoints are annotated as binders since they bind themselves in their bodies.

The change to the conversion algorithm is simple: without $sPROP$, we reduce terms to weak head normal form then if they have the same shape we recurse for each pair of subterms. With $sPROP$, we just insert a check for irrelevance before the reduction step.

Because we allow cumulativity during elaboration the generated relevance marks can be incorrect, leading to incompleteness of conversion during conversion. However the marks are fixed by the kernel.

### 6.1.2 Inductive types.
The extensions with $sEmpty$, squash, box and irrelevant pairs are substituted by restrictions on the inductive types which may be defined.

In the system without $sPROP$, an inductive type may be defined at any universe level greater than the universes of the arguments of its constructors. As a special case, any inductive type may be defined in $PROP$ but its elimination is restricted to $PROP$ unless it satisfies singleton elimination: 0 or 1 constructor with all arguments in $PROP$. Inductive types in $PROP$ with restricted elimination are called “squashed”.

Coq also provides “primitive records” with surjective pairing. They are inductive types with exactly one constructor which has at least one argument (such arguments are called fields of the record), and must not be squashed. We extend this to handle $sPROP$ by considering $sPROP$ as smaller than other universes when checking the level of an inductive type. This allows defining box types:

Inductive Box (A:SProp) : Prop := box : A → Box A.

Definition unbox A (x:Box A) : A := match x with box y ⇒ y end.
The level sPROP of the argument A is smaller than the level PROP of the inductive.

Like with PROP, any inductive type may be defined in sPROP but its elimination is restricted to sPROP when it is not the empty type. This amounts to implicitly using the squash (which can be already defined using the impredicative encoding). For primitive records in sPROP we allow fields in sPROP. This provides a generalization to the unit type and dependent sums. To get other inductive types in sPROP that can be eliminated into any type, the user has to use the automatic encoding described in Section 5, implemented on top of the Equations plugin (see Section 6.4).

## 6.2 Example 1: Prime Numbers

To illustrate a simple use of sPROP in Coq, together with the automatic translation of inductive types into fixpoints described in Section 5, let us consider the definition of primality.

First, we can define the $n \mid m$ predicate, which states that the natural number $n$ is a divisor of $m$.

**Inductive** Divide : $N \to N \to SProp :=$

$| divide_0 : \forall n, Divide n 0$

$| divide_S : \forall n m (e: S n \le S m), Divide (S n) (m - n) \to Divide (S n) (S m).$

**Infix** "|" : $Divide$.

This definition satisfies the conditions described in Section 5, so the corresponding fixpoint definition can be automatically generated, together with its eliminator into TYPE.

Although we have definitional proof irrelevance for $n \mid m$, we can still extract the natural number that witnesses the fact that $n$ is a divisor of $m$ out of the proof that $n \mid m$, which is precisely the goal of the criterion developed in Section 5.

**Definition** divide_to_N : $\forall n m, n \mid m \to N$.

together with the correctness of this definition.

**Lemma** divide_to_N correct n m (e:n | m) : divide_to_N n m e * n = m.

Note however that being an element of sPROP implies both proof irrelevance and computational irrelevance, so an element of $m \mid n$ is completely erased during compilation. It does not store the quotient, but the (mere) property that the euclidean division of $n$ by $m$ has no remainder. Thus, divide_to_N computes the quotient from $m$ and $n$. Essentially finding the quotient by deconstructing the proof of $n \mid m$ is no easier than by deconstructing $n$ and $m$. It can be seen as a side condition to guarantee we have no missing case.

Then, it is easy to define primality in sPROP in a way that satisfies the conditions described in Section 5.

**Inductive** is_gcd (a b g:N) : SProp :=

$is_gcd_intro : g | a \to g | b \to (\forall x, x | a \to x | b \to x | g) \to is_gcd a b g.$

**Inductive** prime (p:N) : SProp :=

$prime_intro : 1 < p \to (\forall n, 1 \le n \to n < p \to is_gcd n p 1) \to prime p.$

This definition gives us definitional proof irrelevance for prime, without paying the price of the definition of a decision procedure into booleans (for instance using the sieve of Eratosthenes) and a proof that it corresponds to primality. Here, we have a direct definition instead, and the decision procedure is only a useful addition to prove primality of a particular natural number and may be implemented as a tactic.
## 6.3 Example 2: The Setoid Model

The previous example shows the use of sPROP to define definitionally proof irrelevant predicates while still being able to extract relevant values out of them. We now turn to a more critical use of sPROP to avoid higher coherence issues in syntactical models of type theory. As an example, using sPROP, we can formally define in Coq the setoid translation presented on paper twenty years ago by Thorsten Altenkirch [Altenkirch 1999]. We define a setoid as a type carrier together with a notion of equality which is reflexive, symmetric, transitive, and definitionally proof irrelevant.

```
Record Setoid :=
  { carrier : Type;
   eq : carrier → carrier → SProp;
   refl : ∀ x, eq x x;
   sym : ∀ {x y}, eq x y → eq y x;
   trans : ∀ {x y z}, eq x y → eq y z → eq x z
  }.
```

This way, we can define a category with families (CwF), as introduced by Peter Dybjer [Dybjer 1996], where contexts are Setoid, types are setoid families (over a context) and terms are sections of setoid families. This CwF features dependent products Π, a universe, and identity types Eq. We can then prove that this CwF satisfies functional extensionality, thus providing a formal proof that functional extensionality is admissible in sMLTT.

## 6.4 Extension of the Equations Plugin

The Equations plugin of Coq [Mangin and Sozeau 2018] provides an implementation of dependent-pattern matching compilation. We reuse the tools of Equations to automatically derive the translation of inductive definitions that fit in sPROP to fixpoint definitions. Concretely, we have extended Equations with a new Derive Inversion command that tries to produce a case tree from an inductive definition and succeeds if and only if the resulting recursive definition can be typed in sPROP.

Using this tool, it is possible to automatically derive the definition of the recursive variants of ≤ and Divide, along with their constructors. Coming back to the example of $≤_{fix}$, our framework provides automatically the two definitions corresponding to the two constructor of ≤:

```
Definition ≤_{fix0} : ∀ n, 0 ≤_{fix} n := fun n ⇒ I.
```

```
Definition ≤_{fixS} : ∀ m n, m ≤_{fix} n → S m ≤_{fix} S n := fun n m e ⇒ e.
```

We are currently also working on implementing the automatic generation of the eliminator as described in Section 5.2.

## 6.5 Implementation in Agda

Aside from adding sPROP to Coq, we also implemented a variant of the same concept for Agda. Since previously there was no PROP universe, the sPROP universe is simply called Prop in Agda. This new universe has been integrated in the current development version of Agda on https://github.com/agda/agda and is planned to be released as part of Agda 2.6.0 in November 2018.

User perspective. On the syntactic level, the main change to Agda is the addition of the new sort Prop next to the old sort Set. Unlike sPROP in Coq, Prop in Agda is *predicative*. For example, $(A : Prop) \rightarrow A$ is not itself an element of Prop. Instead, there is a hierarchy of universes $Prop_0 (= Prop), Prop_1, Prop_2, \dots$ analogous to the hierarchy of $Set_i$. Like Set, Prop also supports universe
polymorphism, so for each $\ell$: Level we have the sort Prop $\ell$. As an example, we can define the
universe polymorphic squash type and its eliminator:

data Squash {$\ell$} (A : Set $\ell$) : Prop $\ell$ where

sq : A → Squash A

unsquash : ∀{ℓ'}{A : Set ℓ}(P : Prop ℓ')(A → P) → Squash A → P

unsquash P f (sq x) = f x

Note that this is more powerful than the predicative encoding of the squash type described in
Section 3.4 since we can eliminate it into any Propᵢ.

Like in the Coq implementation, there is no implicit conversion from Prop to Set. Instead, Prop
can be embedded through the definition of a record type Box (A : Prop) : Set with one field
unbox : A. More generally, when defining a record type in Setᵢ, the fields can be in both Propⱼ or
Setⱼ for any j ≤ i. On the other hand, for record types in Prop all fields must be in Prop themselves.

*Implementation details.* Since Agda uses a type-directed conversion check internally and types
are annotated with their sorts, adding the rule that any two elements of a type in PROP are equal
was straightforward. In particular, the relevance marks used in the Coq implementation are not
required here. In contrast, making Prop impredicative is currently problematic since Agda’s ter-
mination checker assumes predicativity. This was our main reason to implement the predicative
hierarchy Propᵢ instead.

*Interaction with irrelevant arguments.* As mentioned in the introduction, Agda has another an-
other facility for definitional proof irrelevance in the form of irrelevant function types [Abel and
Scherer 2012] and irrelevant fields. Prop can be used in situations where Agda’s pre-existing irrel-
evance cannot, for example:

* We can use Prop to give a function an irrelevant return type.

* We can define new datatypes and record types in Prop, such as Squash.

* We can construct new types in Prop by pattern matching, such as $\le$.

* We can quantify over all types in Prop.

In our implementation, it is allowed to use irrelevant arguments when constructing an element
of a type in Prop. This allows us to convert irrelevant arguments into elements of the squash type:

irrToSquash : {A : Set} → .A → Squash A

irrToSquash x = sq x

In fact, irrelevant functions and irrelevant fields can be encoded in terms of PROP by using the
squash type: each irrelevant argument or field of type .A is turned into a squashed argument
Squash A. This encoding uses the fact that Squash is an applicative functor with identity sq : A →
Squash A and sequential application

_<*>_ : {A B : Set} → Squash (A → B) → Squash A → Squash B

sq f <*> sq x = sq (f x)

For example, if $g : .B \to C$ then the expression $\lambda f x. g (f x)$ of type $(A \to B) \to A \to C$ is encoded by $\lambda f x. g (f <*> sq x)$ of type Squash $(A \to B) \to A \to C$.

In addition to irrelevant functions and fields, Agda also provides experimental support for irrel-
evant definitions and irrelevant projections, which were already mentioned in the introduction. In
contrast to irrelevant functions, not everything that’s possible with these features can be encoded
in terms of Squash, even after fixing the bug mentioned in the introduction. In particular, they can
be used to construct a function .choice : .A → A for any type A, but the corresponding statement
Squash (Squash $A \to A$) is not provable. If this were postulated as an axiom, we conjecture that these experimental ways of using irrelevance could be encoded in terms of Squash as well.

# 7 CONCLUSION AND FUTURE WORK

We have given a general way to extend a type theory with a predicative hierarchy of universes (or an impredicative universe) satisfying definitional proof irrelevance, while keeping decidability of type checking. We have shown various metatheoretical properties of our extension using syntactic translations into extensional type theories ETT and HTS. We have then described a new way to decide whether a proposition can be eliminated over a type using techniques coming from recent development on dependent pattern matching without UIP. We have implemented our approach both in Coq and in Agda, and illustrated its usefulness on several examples, in particular to formalize the setoid model of type theory, which can not be done without definitional proof irrelevance.

Regarding future work, the main extension of our framework that we would like to address in a near future is the definition of a strict equality that remains compatible with univalence. The idea is to detect syntactically which types are mere sets—using again ideas coming from dependent pattern matching—in order to allow elimination of strict equality on those types. This should require the addition of a hierarchy of universes of mere (strict) sets, and maybe other hierarchies for higher homotopy levels as well, but it is not clear how to do it in a good way at the moment.

# ACKNOWLEDGMENTS

The authors want to thank Simon Boulier for his implementation of the Setoid model.

# A LEAN SUBJECT REDUCTION FAILURE

axiom A : Type

axiom r : A A Prop

axiom C : A Type

axiom F : Pi x, (Pi y, r y x C y) C x

lemma fix_F_eq1 (x : A) (acx : acc r x) :

well_founded.fix_F F x acx =

well_founded.fix_F F x (acc.intro x (y, acc inv acx)) := eq.refl _

lemma fix_F_eq2 (x : A) (acx : acc r x) :

well_founded.fix_F F x (acc.intro x (y, acc inv acx)) =

F x ( (y : A) (p : r y x), well_founded.fix_F F y (acc inv acx p))

:= eq.refl _

lemma fix_F_eq3 (x:A) (acx : acc r x) :

well_founded.fix_F F x acx =

F x ( (y : A) (p : r y x), well_founded.fix_F F y (acc inv acx p))

:= eq.trans (fix_F_eq1 x acx) (fix_F_eq2 x acx)

lemma fix_F_eq4 (x:A) (acx : acc r x) :

well_founded.fix_F F x acx =

F x ( (y : A) (p : r y x), well_founded.fix_F F y (acc inv acx p))

:= eq.refl _ -- fails
B INCONSISTENCY OF IRRELEVANT FIELDS

data ⊥ : Set where

¬ : Set Set

¬ A = (A → ⊥)

true ≠ false : ¬ (true ≡ false)

true ≠ false ()

_- : {A : Set} {x y z : A} → x ≡ y → y ≡ z → x ≡ z

refl · q = q

!_ : {A : Set} {x y : A} → x ≡ y → y ≡ x

! refl = refl

record Squash (A : Set) : Set where

constructor sq

field .unsq : A

squash_pi : {A : Set} → (x y : Squash A) → x ≡ y

squash_pi x y = refl

squash_invol : {B : Set} → (Squash (Squash B)) → Squash B

squash_invol (sq (sq x)) = sq x

squashElim : {A B : Set} → (A → Squash B) → Squash A → Squash B

squashElim f (sq x) = squash_invol (sq (f x))

map-sq : {A B : Set} → (A → B) → Squash A → Squash B

map-sq f (sq x) = sq (f x)

factivity : Squash ⊥ → ⊥

factivity (sq())

bizarre : Squash (Σ (B → Squash B) (λ i → Σ (Squash B → B) (λ u → (a : B) → u (i a) ≡ a)))

bizarre = sq (sq, unsq, (λ a → refl {x = a})))

bad : Squash (true ≡ false)

bad = map-sq (λ { (i, u, s) → ! (s true) · s false } ) bizarre

boom : ⊥

boom = factivity (map-sq true ≠ false bad)
REFERENCES

Andreas Abel, Joakim Öhman, and Andrea Vezzosi. 2018. Decidability of Conversion for Type Theory in Type Theory. Proc. ACM Program. Lang. 2, POPL, Article 23 (Jan. 2018), 29 pages. DOI: http://dx.doi.org/10.1145/3158111

Andreas Abel and Gabriel Scherer. 2012. On Irrelevance and Algorithmic Equality in Predicative Type Theory. Logical Methods in Computer Science 8, 1 (03 2012). DOI: http://dx.doi.org/10.2168/lmcs-8(1:29)2012

T. Altenkirch. 1999. Extensional equality in intensional type theory. In Proceedings. 14th Symposium on Logic in Computer Science (Cat. No. PR00158). 412–420. DOI: http://dx.doi.org/10.1109/LICS.1999.782636

Thorsten Altenkirch, Paolo Capriotti, and Nicolai Kraus. 2016. Extending Homotopy Type Theory with Strict Equality. In CSL.

Steven Awodey and Andrej Bauer. 2004. Propositions As [Types]. J. Log. and Comput. 14, 4 (Aug. 2004), 447–471. DOI: http://dx.doi.org/10.1093/logcom/14.4.447

Simon Boulier, Pierre-Marie Pédrot, and Nicolas Tabareau. 2017. The Next 700 Syntactical Models of Type Theory. In Proceedings of Certified Programs and Proofs. ACM, 182–194.

Edwin Brady, Conor McBride, and James McKinna. 2004. Inductive Families Need Not Store Their Indices. In Types for Proofs and Programs, Stefano Berardi, Mario Coppo, and Ferruccio Damiani (Eds.). Springer Berlin Heidelberg, Berlin, Heidelberg, 115–129.

Paolo Capriotti. 2017. Models of type theory with strict equality. Ph.D. Dissertation. University of Nottingham.

Jesper Cockx and Andreas Abel. 2018. Elaborating Dependent (Co)pattern matching. In Proceedings of the 23rd ACM SIGPLAN Conference on Functional Programming (ICFP 2018). ACM Press, St. Louis, Missouri, United States.

Jesper Cockx and Dominique Devriese. 2018. Proof-relevant unification: Dependent pattern matching with only the axioms of your type theory. Journal of Functional Programming 28 (2018), e12. DOI: http://dx.doi.org/10.1017/S095679681800014X

Jesper Cockx, Dominique Devriese, and Frank Piessens. 2014. Pattern matching without K. In ACM SIGPLAN Notices, Vol. 49. ACM, 257–268.

Thierry Coquand. 2016. Universe of Bishop sets. (2016). www.cse.chalmers.se/~coquand/bishop.pdf.

Peter Dybjer. 1996. Internal type theory. In Types for Proofs and Programs, Stefano Berardi and Mario Coppo (Eds.). Springer Berlin Heidelberg, Berlin, Heidelberg, 120–134.

Martin Hofmann. 1995. Conservativity of equality reflection over intensional type theory. In International Workshop on Types for Proofs and Programs. Springer, 153–164.

P. Letouzey. 2004. Programmation fonctionnelle certifiée – L'extraction de programmes dans l'assistant Coq. Ph.D. Dissertation. Université Paris-Sud.

Cyprien Mangin and Matthieu Sozeau. 2018. Equations Reloaded. (2018). http://mattam82.github.io/Coq-Equations/

Per Martin-Löf. 1975. An Intuitionistic Theory of Types: Predicative Part. In Logic Colloquium '73, H.E. Rose and J.C. Shepherdson (Eds.). Studies in Logic and the Foundations of Mathematics, Vol. 80. Elsevier, 73 – 118. DOI: http://dx.doi.org/https://doi.org/10.1016/S0049-237X(08)71945-1

Frank Pfenning. 2001. Intensionality, Extensionality, and Proof Irrelevance in Modal Type Theory. In Proceedings of the 16th Annual IEEE Symposium on Logic in Computer Science (LICS '01). IEEE Computer Society, Washington, DC, USA, 221–. http://dl.acm.org/citation.cfm?id=871816.871845

Aaron Stump. 2018. From realizability to induction via dependent intersection. Ann. Pure Appl. Logic 169, 7 (2018), 637–655. DOI: http://dx.doi.org/10.1016/j.apal.2018.03.002

The Univalent Foundations Program. 2013. Homotopy Type Theory: Univalent Foundations of Mathematics. Institute for Advanced Study.

Vladimir Voevodsky. 2011. Resising Rules - their use and semantic justification. www.math.ias.edu/~vladimir/Site3/ Univalent_Foundations_files/2011_Bergen.pdf. (2011).

Vladimir Voevodsky. 2013. A simple type system with two identity types. (2013). https://ncatlab.org/homotopytypetheory/ files/HTS.pdf

Benjamin Werner. 2008. On the Strength of Proof-Irrelevant Type Theories. 4 (09 2008), 1–20.