Manuscript Offprint
arXiv:2609.08578Erased Postulates, Identity Types and Quotients
NILS ANDERS DANIELSSON, University of Gothenburg and Chalmers University of Technology, Sweden
This text is concerned with the question of whether, in type theory with erasure annotations, one can postulate that some type is inhabited and still have a guarantee that a program will not get stuck. Previous work has provided such guarantees for consistent erased postulates, i.e. postulates that are restricted to be used in erased contexts. Here those guarantees are extended to type theory with identity types.
Similar ideas provide a simple way to support quotient types: it is shown that one can let things like “the equivalence classes for two related values are equal” be erased postulates and have an eliminator that only computes for the equivalence class constructor, and still get a guarantee that programs will compute correctly.
Another question is whether programs compute correctly if one is allowed to transport (cast) using erased identity proofs. It is shown that this is safe in the absence of quotients and postulates, and in the presence of quotients and erased postulates that can be implemented using equality reflection. However, unrestricted transports of this kind are not compatible with erased, postulated univalence. For that reason the text includes a study of the function []-cong, which encapsulates a limited form of transport for erased identity proofs.
The text is accompanied by machine-checked Agda proofs.
1 Introduction
Dependent type theories/programming languages like Agda [59], Idris [14], Lean [60] and Rocq [61] support identity types. A key feature of identity types is the ability to substitute equals for equals, as witnessed by the following Agda function:
In any context expressible as a function from some type to the universe (the type of types with universe level ) one can replace with , given that the identity type is inhabited. Note that subst is implemented by matching on the constructor refl : .
A potential drawback of identity types in plain, intensional Martin-Löf type theory is that one cannot prove certain properties, like function extensionality – extensionally equal functions are equal [6] – or univalence – which implies that types that are in bijective correspondence are equal [62]. A workaround is to postulate the properties that one needs (assuming that they are consistent). However, if the type theory is used as a programming language, then a postulate could lead to programs becoming stuck during execution.
This problem was addressed by Abel et al. [1], who study a family of type theories with support for erasure inspired by the work of McBride [43] and Atkey [9], and similar to the support for erasure in Agda and Idris 2. The idea is basically that erased data will be removed by compilers, and that the type system ensures that no run-time decision is made based on erased data. Abel et al. [1, Theorem 8.3] show that, for a program of type that only uses postulates in erased contexts, if the postulates are mutually consistent, then will reduce to a numeral, and the corresponding compiled program will reduce to the same numeral.
Abel et al. did not support identity types. One contribution of this work is to add support for identity types (see Theorem 10.1), thus establishing that a postulate like the following one is “safe”:
Author's Contact Information: Nils Anders Danielsson, Department of Computer Science and Engineering, University of Gothenburg and Chalmers University of Technology, Gothenburg, Sweden, nad@cse.gu.se.

This work is licensed under a Creative Commons Attribution 4.0 International License.
This code uses Agda notation: the annotation @0 means that the postulate is erased, and may only be used in erased contexts, for instance in erased function arguments.
This work also goes further:
-
It is shown how erased postulates make it easy to implement a form of quotient types ( ). As an aside, the associated proofs of normalisation, canonicity, consistency, etc. are possibly the first mechanised proofs of that kind for type theory with quotients ( ).
-
It is shown that in some cases erased postulates can be supported even in the presence of erased matches [1], in particular variants of subst that take erased identity proofs ( ).
-
Some forms of erased matches are incompatible with univalence, and for that reason this text includes a study of the function []-cong, which provides a restricted form of erased match for identity proofs ( ).
-
This work provides a first step towards Computational Book HoTT: a variant of Book HoTT [62] with erased univalence, higher inductive types with erased higher constructors, and a guarantee that programs will compute properly ( ).
-
The technique of fording [18, 51] – encoding inductive families using regular inductive types and identity proofs – is adapted for use with erased identity proofs. (The text only treats the case of vectors.) The technique uses erased matches for identity types ( ).
Formalisation. All results have been formalised in Agda, and the code has been made available to download [25]. The results in §§ 8-12 have been proved in the context of a formalisation of graded type theory [1, 2], while those in §§ 3-7 and §§ 13-16 are proved for Agda. Note that there are minor differences between the code and the presentation in the text.
The graded type theory formalisation of Abel et al. [1] builds on earlier work for non-graded type theory by Abel et al. [4], extended by Oskar Eriksson, Gaëtan Gilbert and Wojciech Nawrocki. The graded type theory formalisation has in turn been extended with a weak unit type (Eriksson), top-level, possibly opaque definitions [27], and universe polymorphism [26].
Erased arguments are marked with @0 (or @erased), and the idea is that no run-time decision should be made based on an erased argument. The following definition of ok is OK, because the result of the function can be computed without making use of the (implicit) type argument
However, not-ok is not OK (in a non-erased context), because the argument of type A is marked as erased. Erased arguments and definitions can always be used in erased contexts, which include type signatures and erased function arguments (for instance the subexpression e of the expression f e, if the first explicit argument of f is erased).
One key type in this text is Erased [45]. The data type Erased A has a single constructor [ ] (“box”) that takes a single, erased argument of type A - it is basically a type-level variant of @0:
I sometimes omit declarations of implicit arguments, but not erased ones.
Erased comes with the projection function erased, which is erased. Erased definitions like erased can only be used in erased contexts, but their bodies can make use of anything that is erased.
Note that the type argument A of Erased is erased. This means that Erased, seen as a function from types to types, takes an erased argument. This is not necessarily OK for all types and arguments, see the discussion of in § 5; Abel et al. [3] provide more examples.
This text is mainly focused on a variant of Erased without -equality, like the one above. Initially I investigated a variant with -equality. However, in a setting with linear types such a type may not work very well [1]: the -long normal form of the linear identity function on Erased is basically , which is arguably not a linear function because the argument of the box operator is erased. For that reason I have chosen to focus on a variant of Erased without -equality.
Pattern matching on erased arguments is not allowed in non-erased contexts for data types with two or more constructors. However, such erased matches [1] are allowed for the empty type, a data type with zero constructors. Agda optionally allows erased matches for non-indexed, single-constructor data types. If such a match is allowed, then all the constructor's arguments are treated as erased in the right-hand side. For instance, is disallowed, but is allowed:
3 Quotient Types
Higher inductive types [62] are inductive types that can have higher constructors imposing equalities on the values of the type (or equalities between equalities of values, and so on). One example is given by quotient types [36, 62]. Quotient types are used in mathematics, but can also be used for programming. For instance, efficient data structures often allow a single logical value to be represented in multiple ways. Quotients allow one to make all representations that stand for the same logical value propositionally equal (if "standing for the same logical value" can be defined in a suitable way), and an advantage of propositional equality over custom equivalence relations is that propositional equality is necessarily preserved by all functions.
Erased postulates can be used to provide a simple implementation of quotient types. The technique presented below should work for more higher inductive types, but the type theories presented in § 8 only have one data type with higher constructors, that of quotients. However, note that propositional truncation, which is used prominently in homotopy type theory [62], can be implemented as a quotient with the trivial relation.
The following interface, along with a specific computation rule, is shown to be safe (the interface is based on the set quotient HIT, due to Qian and Mörtberg, in the cubical library):
\begin{array}{ll} /_/_ & : (A : Type a) \to @0 (A \to A \to Type a) \to Type a \\ [] & : (@0 R : A \to A \to Type a) \to A \to A / R \\ @0 resp : R x y \to Id (A / R) [x] [y] \\ @0 set : Is-set (A / R) \\ qrec : (@0 R : A \to A \to Type a) \to (P : A / R \to Type p) \to (f : \forall x \to P [x]) \to \\ & @0 (\forall \{x y\} (r : R x y) \to Id (P [y])) (subst P (resp r) (f x)) (f y)) \to \\ & @0 (\forall x \to Is-set (P x)) \to (x : A / R) \to P x \end{array}The type is A quotiented by the relation . The point constructor [ ] takes a value to its equivalence class. The higher constructor resp ensures that the equivalence classes of related values are equal, and the higher constructor set ensures that the quotients are set-truncated, following The Univalent Foundations Program [62]: Is-set states that is a set, i.e. a type for which all identity proofs are equal. (If one chooses to work in a setting with uniqueness of identity proofs, where every type is a set, then one can ignore this truncation constructor and the corresponding argument of the eliminator.)
The higher constructors are erased. In turn the corresponding arguments of the eliminator qrec are also erased. The eliminator computes in the usual way when applied to the point constructor (qrec _ f _ _ [ x ] = f x), but no computation rules are associated to the higher constructors, unlike quotient types implemented in cubical type theory [65]. However, cubical type theory is arguably rather complicated. This interface – a variant of Licata's trick [62] – should be comparatively easy to implement given a type theory with suitable erasure annotations.
A drawback of this simple interface is that terms can get stuck. However, the fact that the higher constructors are erased ensures that programs of type will compute to the correct numeral, and this is true also in the presence of consistent erased postulates (see Theorem 10.1).
One postulate that one may in particular want to use is that of propositional extensionality:
A type is a proposition if all its elements are equal [62]: Is-prop . Propositional extensionality, which follows from univalence, ensures that any logically equivalent propositions in the same universe are equal. Using erased propositional extensionality and erased function extensionality (sometimes abbreviated to propext and funext) one can prove that certain quotient relations are effective [36, 62, 17], formulated in the following way: . In erased contexts all propositional equivalence relations are effective, and one can even prove something that holds in non-erased contexts:
As an example of what effectiveness can be used for, let us try to decide erased equality for . What does “decide erased equality” mean? This can be formulated using the type . A value of this type gives you either an erased proof that is inhabited, or an erased proof that is not inhabited. Now let us try to prove . We use qrec to match on and : the arguments corresponding to the higher constructors can be filled in using the fact that, in erased contexts, erased funext implies that is a proposition (note that every proposition is a set). We get and , and check whether holds. If it does, then we use resp to conclude that is equal to . If not, then we can conclude that is not equal to if is effective in erased contexts.
In order to demonstrate that the quotient interface presented here works in practice I have implemented finite sets as red-black trees quotiented by set equivalence. (I implemented the empty set, insertion, deletion, the membership relation, and a membership test, along with proofs of correctness.)
The red-black trees are implemented following Okasaki [48], using a technique due to McBride [42] to handle ordering constraints. They are parametrised by a strict total order with a comparison function of type , and the tree invariants are erased.
The finite sets are defined by . Let me explain how tree membership ( : ) can be lifted to set membership. One cannot simply define , because the eliminator qrec requires that the motive is a family of sets (in erased contexts), and in the presence of univalence is not a set. However, in erased contexts one can use propext and funext to prove that the -type is a set, so one can use qrec to define types that are propositions, and it suffices that one can prove that they are propositions in erased contexts. Such a proof is possible for tree membership. If tree membership were not propositional, then one could have used propositional truncation to turn the type into a proposition – and as mentioned above propositional truncation can be implemented as a quotient.
The use of qrec in the implementation of _∈_ also requires that the “point function” respects the relation (in erased contexts): in the non-dependent case where is the third explicit argument of qrec can be simplified to . Again one can use propxet, which ensures that implies . Using funext one can prove that is a proposition, which allows us to conclude.
4 Erased Postulates and Erased Matches
The previous section illustrates one way of working with erasure: “Proofs”, like the higher quotient constructors or the invariants of the red-black tree data structure, are marked as erased. “Programs” are not erased, but can contain erased parts, like some arguments of qrec or the results of the comparison function used for the red-black trees. This separation allows postulates like funext and propxet to be used in proofs, without affecting the computational behaviour of the non-erased parts of a program. However, sometimes one may wish to use an erased proof to show that something non-erased is type-correct.
In order to illustrate this, let us discuss two definitions of vectors (length-indexed lists):
is an indexed data type. Note that the (implicit) natural number argument of the cons constructor is erased. A goal here is to ensure that there is no need to keep the numbers representing the vectors' lengths around at run-time, so all natural numbers are erased in this example. uses plain lists, but pairs them up with erased proofs showing that the lists have correct lengths.
It is easy to convert a list to a vector. Can we convert from to ?
In the nil case we should return something of type , given an erased proof that shows that is equal to zero. Can we return [?]? That constructor has the index zero, not . Can we use the function above to substitute for zero? That function does not take an erased identity proof (the penultimate argument is not annotated with @0). Is the following variant of , with an erased identity proof, OK?
Maybe. Note that this code involves a match on an erased argument: an erased match. It should not be possible to make run-time decisions based on erased data, but in this case there is only one constructor – refl – so this might still make sense. In the presence of (erased) univalence this code is not safe: it allows one to construct two provably distinct booleans that only differ in their erased parts (see Abel et al. [3] or § 5). However, there are settings in which it does make sense.
The soundness theorem presented by Abel et al. [1, Theorem 8.3] supports erased matches for single-constructor data types if there are no postulates: given a program t of type IN with erased
It is important for the discussion that the argument n is erased: an erased identity proof between two non-erased natural numbers can be turned into a non-erased identity proof because equality of natural numbers is decidable.
matches but no postulates, will reduce to a numeral, and the corresponding compiled program will reduce to the same numeral. However, the following statement does not hold in general: “given a program of type with erased matches and erased postulates, if the postulates are mutually consistent, then will reduce to a numeral, and the corresponding compiled program will reduce to the same numeral”. In particular, the part “ will reduce to a numeral” can fail if an erased match gets stuck on a postulate.
One contribution of this work is a proof of soundness of erasure for a class of programs with both erased matches and erased postulates (Theorem 11.3). There are no restrictions on the erased matches, but the types of the erased postulates must be inhabited in an extension of the type theory with equality reflection. Under equality reflection, if there is some term of type , then and are judgementally equal. Type-checking is not decidable for Martin-Löf type theory with equality reflection, and systems like Agda do not support this feature. However, it allows one to prove properties like function extensionality and uniqueness of identity proofs (UIP: every type is a set). The statement of Theorem 11.3 is (roughly) that, given a program of type that uses erased matches and erased postulates, if the postulates can be implemented in the type theory extended with equality reflection, then there is a numeral such that the compiled program corresponding to reduces to , and furthermore with the implementations substituted for the postulates is judgementally equal to in the extended type theory.
5 Box-Cong
As mentioned above, if unrestricted erased matches are allowed for the identity type, then the theory becomes incompatible with (erased, postulated) univalence [3]. (A similar problem affects Rocq with identity types in Prop [54].) Using univalence one can turn bijections into equalities. In particular, one can turn the not function into a proof that Bool is equal to Bool. Let us use swap to denote such a proof, constructed using erased univalence, and therefore only available in erased contexts. Now consider the following code, which uses the function subst from § 4:
The definition of should-be-false is “OK” because the penultimate argument of subst' is erased. The definition of should-be-true reduces to true. Using properties of univalence one can also construct an erased proof that shows that should-be-false is equal to false (and because equality is decidable for Bool one can turn this into a non-erased proof). However, the only difference between should-be-true and should-be-false is the erased argument, and Agda compiles these definitions to basically identical code, even though they are provably distinct.
So, the function subst' is not safe in the presence of erased univalence. Univalence is also inconsistent in the presence of UIP, and thus also in the presence of equality reflection, so Theorem 11.3 which was discussed above does not apply in the presence of erased, postulated univalence. Is any kind of erased match compatible with that postulate?
Theorem 10.1, which was mentioned above, supports one kind of erased match (following Abel et al. [1]). As long as the erased postulates are mutually consistent it is the case that erased matches for the empty type are allowed, as in . This allows one to, for instance, use erased information to discard impossible branches. However, the theorem does not support erased matches for single-constructor data types (except if there are no erased postulates).
And perhaps details of how the implicit arguments are instantiated, but one could write them out in full. Similar comments apply below as well.
Fortunately there may be a way forward. One contribution of this work is an investigation of a function called []-cong ("box-cong"), which encapsulates limited forms of erased matches for identity types. The work of Abel et al. [3] suggests to me that the following definition, with an erased match, might be safe in the presence of erased univalence (more about this in § 6):
Using []-cong – as well as the erased projection function erased – one can define :
Note that the identity proof argument is erased, but in turn takes an erased argument: this makes the use of erased in the right-hand side OK. The type function also takes an erased argument, so one can use to implement .
The implementation of is just a simple example, but it should illustrate that erased matches for identity types can sometimes be useful. The text also contains other examples of the utility of []-cong:
-
Fording is a method for encoding indexed data types using regular data types and identity proofs [18, 51]. Does fording work if the identity proofs are erased? In § 7 it is shown that fording with erased identity proofs works for if []-cong is available, and also that such fording does not work (in a certain sense) unless a limited variant of []-cong can be defined.
-
In the absence of erased matches for single-constructor data types, and the absence of equality reflection, []-cong cannot be defined, and the limited variant of []-cong discussed above also cannot be defined (see Theorem 12.6).
-
A number of statements are logically equivalent to “[]-cong can be defined”, see § 14. One of these statements is that a specific function is an equivalence – basically a bijection – from to . Note that this provides a characterisation of equality for Another statement is that and the constructor [ ] (-expanded) form a modality in the sense of Rijke et al. [53] (see § 13). This modality is left exact, which for instance implies that if is a proposition, then is a proposition (for a stronger statement, see § 15).
It turns out that, in the presence of (non-erased) function extensionality, []-cong can be implemented. This is discussed in § 16.
Above it was shown that is incompatible with erased univalence. In the presence of []-cong a variant of with the type signature is also problematic [3]. This function allows us to construct the following variants of should-be-true and should-be-false:
These booleans are provably equal to true and false, respectively, but are equal except for the erased proofs refl and swap.
Let me end this section by discussing a variant of the identity type with three erased arguments:
⁴In Martin-Löf type theory identity types can be underspecified. A classic example is provided by identity for -types. One formulation of function extensionality is that a certain function is an equivalence from to [62].
In the presence of []-cong⁵ this type is incompatible with erased, postulated univalence. Using the fact that the last argument of is erased we can define the following function that takes an erased identity proof to a non-erased identity proof:
\begin{aligned} \text{resurrect} : \@0 Id_0 A x y \rightarrow Id_0 A x y \\ \text{resurrect} \{A\} \{x\} eq = \text{subst} (\lambda y \rightarrow Id_0 A x (\text{erased } y)) ($$]-cong eq) \text{refl} \end{aligned}Using resurrect it is easy to define variants of should-be-true and should-be-false:
Again these booleans are provably equal to true and false, respectively, but are equal except for the erased proofs refl and swap.
6 Towards Computational Book HoTT
The work presented in this text gives us a fairly simple way to support univalence and computation in the same theory, without having to implement cubical type theory [22], which is arguably rather complicated. In the absence of erased matches for single-constructor data types one is free to use univalence in the erased fragment of the theory. Univalence does not compute, just like in “Book HoTT” [62], but that does not affect compiled programs (here restricted to programs of type N), which compute properly. Book HoTT also supports higher inductive types (HITs). In Book HoTT the eliminators for HITs only compute for the point constructors, just like for the quotient types presented in § 3.
Thus this work provides a first step towards Computational Book HoTT. One thing that is left for future work is to investigate if the technique employed for quotient types works for all HITs supported by Book HoTT. If one wants to use []-cong, then it would also make sense to prove that the combination of []-cong and postulated, erased univalence is safe. I have not done this, but I have tried to pave the way for such a proof. That is another contribution of this work.
Theorem 11.3, discussed above, is proved using a meta-theorem (Theorem 11.2) instantiated with type theories with equality reflection. If that meta-theorem can be instantiated with cubical type theories [22] that support identity types with J and []-cong in addition to path types, then one may obtain the following result: given a program of type N that uses erased postulates and []-cong (and perhaps certain other forms of erased matches), if the postulates can be implemented in the type theory extended with certain cubical features, then there is a numeral such that the compiled program corresponding to reduces to , and furthermore with the implementations substituted for the postulates is judgementally equal to in the cubical type theory. Note that univalence can be proved in cubical type theory.
Abel et al. [3] sketch a proof, with some unproved assumptions, of soundness of erasure for a variant of cubical type theory with erasure and erased univalence (but without identity types with the J rule). In that system []-cong can be implemented for the path type, like in the following Cubical Agda code:
\begin{aligned} [$$-cong-Path : \{\@0 A : \text{Type } a\} \{\@0 x y : A\} \rightarrow \@0 \text{Path } A x y \rightarrow \text{Path} (\text{Erased } A) [x] [y] \\ [$$-cong-Path eq = \lambda i \rightarrow [eq i] \end{aligned}⁵Either for this type, or for the identity type presented earlier. The code presented here assumes that []-cong, univalence, swap and subst are stated using this variant of the identity type.
A path in Path A x y is basically a function from “the interval” to A that is equal to x and y at the interval’s two endpoints. Note that the erased path eq is used in the erased argument of []. The work of Abel et al. may be incomplete, but it makes me hopeful that one could instantiate the meta-theorem in the way described above. ## 7 Fording with Erased Identity Proofs Let us now return to the type $Vec^D$ from § 4. This is an inductive family, where the two constructors have different codomains. In the absence of primitive inductive families one can try to encode them using the technique of fording, i.e. using regular data types and identity proofs [18, 51]. Let us encode $Vec^D$ in this way, but using erased identity proofs: data Vec^{F} (A : Type a) (@0 n : N) : Type a where nil : @0 Id N zero $n \to Vec^{F} A n$ cons : {@0 m : N} $\rightarrow$ A $\rightarrow$ Vec $^{\mathrm{F}}$ A m $\rightarrow$ @0 Id N (suc m) n $\rightarrow$ Vec $^{\mathrm{F}}$ A n For $Vec^{F}$ we get the following eliminator (recursion principle):\begin{aligned}Vec^{\mathrm{F}}-elim&:{\textcircled{@}0A:Type a}\left(\textcircled{@}0P:{n:\mathbb{N}}\rightarrow Vec^{\mathrm{F}}A n\rightarrow Type p\right)\rightarrow\&\left{\textcircled{@}0n:\mathbb{N}\right}\left(\textcircled{@}0eq:Id N zero n\right)\rightarrow P\left(\text{nil}eq\right)\right)\rightarrow\&\left{\textcircled{@}0m n:\mathbb{N}\right}\left(x:A\right)\left(xs:Vec^{\mathrm{F}}A m\right)\left(\textcircled{@}0eq:Id N\left(suc m\right)n\right)\rightarrow P xs\rightarrow\&\quad P\left(\text{cons}x xs eq\right)\rightarrow\&\left{\textcircled{@}0n:\mathbb{N}\right}\left(xs:Vec^{\mathrm{F}}A n\right)\rightarrow P xs\Vec^{\mathrm{F}}-elim P n c\left(\text{nil}eq\right)&=n eq\Vec^{\mathrm{F}}-elim P n c\left(\text{cons}x xs eq\right)&=c x xs eq\left(Vec^{\mathrm{F}}-elim P n c xs\right)\end{aligned}
This eliminator is somewhat low-level, in the sense that the arguments corresponding to nil and cons take explicit identity proofs. Can we define a more high-level eliminator, closer to what one might expect for $Vec^{D}$? Let us first define variants of nil and cons that do not take identity proofs as arguments:\begin{aligned}\left[\right]:\left{\textcircled{@}0A:Type a\right}\rightarrow Vec^{\mathrm{F}}A zero\\left[\right]=nil refl\end{aligned}
\begin{array}{r l}{\ddots:}&{{\textcircled{@}0A:Type a}{\textcircled{@}0n:\mathbb{N}}\rightarrow}\ &{A\rightarrow V e c^{\mathrm{F}}A n\rightarrow V e c^{\mathrm{F}}A\left(\mathrm{s u c}\right)}\ &{x::x s=\mathrm{c o n s}x x s\mathrm{r e f l}}\end{array}
\begin{aligned}Vec^{\mathrm{F}}-elim^{\prime}:{\textcircled{@}0A:Type a}\left(P:{\textcircled{@}0n:\mathbb{N}}\rightarrow Vec^{\mathrm{F}}A n\rightarrow Type p\right)\rightarrow\P\left[\right]\rightarrow{{\textcircled{@}0n:\mathbb{N}}\left(x:A\right)\left(xs:Vec^{\mathrm{F}}A n\right)\rightarrow Pxs\rightarrow P\left(x::xs\right)}\rightarrow\{\textcircled{@}0n:\mathbb{N}}\left(xs:Vec^{\mathrm{F}}A n\right)\rightarrow Pxs\Vec^{\mathrm{F}}-elim^{\prime}P n c=Vec^{\mathrm{F}}-elim P\left(\lambda eq\rightarrow\mathcal{J}^{\mathrm{E}}\left(\lambda eq\rightarrow P\left(\mathrm{nil}eq\right)\right)n eq\right)\ \left(\lambda x xs eq p\rightarrow\mathcal{J}^{\mathrm{E}}\left(\lambda eq\rightarrow P\left(\mathrm{cons}x xs eq\right)\right)\left(c x xs p\right)eq\right)\end{aligned}
\begin{aligned}\mathcal{J}^{\mathrm{E}}&:{\textcircled{@}0A:Type a}{\textcircled{@}0x y:A}\left(P:{\textcircled{@}0y:A}\rightarrow\textcircled{@}0IdA x y\rightarrow Type p\right)\rightarrow\&P refl\rightarrow(\textcircled{@}0eq:IdA x y)\rightarrow P eq\end{aligned}
For instance, in the nil case we should return something of type $P(\text{nil eq})$, but $n$ has type $P(\text{nil refl})$, and $\mathcal{J}^{\mathrm{E}}$ is used to cast from the latter type to the former. The identity proof $eq$ is erased, so it is important that the final argument of $\mathcal{J}^{\mathrm{E}}$ is erased. Note that the motive $P$ of $Vec^{\mathrm{F}}-elim'$ is not erased, but takes an erased natural number argument: this ensures that the two uses of $\mathcal{J}^{\mathrm{E}}$ are well-formed. The function $\mathcal{J}^{\mathrm{E}}$ is implemented using the function $subst^{\mathrm{E}}$ from § 5:\mathcal{J}^{\mathrm{E}} {A} {x} P p eq =
subst^{\mathrm{E}}(\lambda p \to P(\text{snd } p)) (\mathcal{J}(\lambda {y} eq \to Id((y:A) \times Id A x y)(x, \text{refl})(y, eq)) \text{refl } eq) p
This code uses $\mathcal{J} : (P : \{y : A\} \to Id A x y \to \text{Type } p) \to \text{refl} \to (eq : Id A x y) \to P eq$. The implicit argument $A$ of $subst^{\mathrm{E}}$ is here the pair type $(y : A) \times Id A x y$, and the second explicit argument has type $Id((y : A) \times Id A x y)(x, \text{refl})(y, eq)$. The function $Vec^{\mathrm{F}-elim'}$ computes "as expected": $Vec^{\mathrm{F}-elim'} P n c$ is definitionally equal to $n$, and $Vec^{\mathrm{F}-elim'} P n c(x::xs)$ is definitionally equal to $c x xs$ ($Vec^{\mathrm{F}-elim'} P n c xs$). Thus $Vec^{\mathrm{F}}$, [], _::_ and $Vec^{\mathrm{F}-elim'}$ provide an encoding of $Vec^{\mathrm{D}}$ that is, in some sense, reasonable. If unrestricted erased matches are allowed for identity types, then one can implement a variant of $Vec^{\mathrm{F}-elim'}$ with an erased motive $P$. On the other hand, if no erased matches are allowed, then $Vec^{\mathrm{F}-elim'}$ cannot be implemented (in certain type theories) – using $Vec^{\mathrm{F}-elim'}$ one can implement a limited variant of []-cong that, for certain type theories, cannot be implemented in the absence of erased matches (see Theorem 12.6):[\text{-cong}_0 : {@0 n : N} \to @0 Id N \text{zero } n \to Id (\text{Erased } N) [\text{zero}] [n]
[\text{-cong}_0 eq = Vec^{\mathrm{F}-elim'}
(\text{Vec}^{\mathrm{F}-elim}(\lambda _ \rightarrow \text{Type}) (\lambda {n}_ \rightarrow Id (\text{Erased } N) [\text{zero}] [n]) (\lambda _ _ _ _ _ \rightarrow \top))
\text{refl} (\lambda _ _ _ _ \rightarrow \text{tt}) (\text{nil} {A = \top} eq)
(Here $\top$ is a unit type with constructor tt. The notation nil $\{A = B\}$ means "nil, with the implicit argument $A$ instantiated to $B$"). One could try to use the type $Vec^L$ from § 4 instead of $Vec^F$, but we get a similar situation: $Vec^L - elim'$ can be implemented (with propositional "computation" rules) using []-cong, and []-cong$_0$ can be implemented using $Vec^L - elim'$. Thus, if a designer of a dependently typed programming language wants to support $Vec^D$ in the surface language, but only more basic data types in the core language, then it may make sense to allow erased matches (of some kind) for identity types in the core language. Here we have only looked at implementations of vectors: I expect that similar ideas work for a larger class of inductive families, but that remains to be investigated. ## 8 Type Theory with Identity Types, Quotients and Erasure Let me now present a family of type theories with support for erasure. The Agda formalisation supports identity types, set quotients, $\Pi$-types, $\Sigma$-types with and without $\eta$-equality, unit types with and without $\eta$-equality, an empty type, natural numbers, an infinite hierarchy of universes, optional first-class universe levels, lift types, and top-level, possibly opaque definitions. However, here I will focus on identity types, quotients and $\Pi$-types. Full typing rules (excluding rules for first-class universe levels and top-level definitions) can be found in Appendix A. The formalisation also supports various modality semirings, following McBride [43], Atkey [9], Abel et al. [1] and others. However, here I present the type system specialised to the erasure semiring,⁶ with the two grades 0 and $\omega$: 0 stands for "not used", and $\omega$ for "used an arbitrary number of times". The semiring comes with a multiplication operator with 0 as a zero and $\omega$ as an identity. There is also a total order with $\omega \leq 0$. The formalisation uses well-scoped syntax, but such details have been omitted here: the definitions should be read as if everything were well-scoped. (There are also other, minor differences ⁶The definition of the general rules for identity types, with support for arbitrary modality semirings, was influenced by input from Oskar Eriksson. Those rules are not presented here. between the text and the formalisation.) There are a number of judgements that are defined using mutual induction: * Well-typed and well-resourced terms: $\gamma \triangleright \Gamma \vdash t :^p A$. Here $\gamma$ is a grade context, $\Gamma$ a type context of equal length, and $p$ a grade. One can think of $\gamma$ as specifying how each variable is allowed to be used: variables with grade 0 must only be used in erased contexts, i.e. when the mode $p$ is 0. The notation $\Gamma \vdash t : A$ is an abbreviation for $\mathbf{0} \triangleright \Gamma \vdash t :^0 A$, where $\mathbf{0}$ is a grade context where every entry is $0$ ($\gamma \triangleright \Gamma \vdash t :^p A$ provably implies $\Gamma \vdash t : A$). * Well-formed and well-resourced types: $\gamma \triangleright \Gamma \vdash^p A$. The notation $\Gamma \vdash A$ is an abbreviation for $\mathbf{0} \triangleright \Gamma \vdash^0 A$ (and $\gamma \triangleright \Gamma \vdash^p A$ implies $\Gamma \vdash A$). * Well-formed contexts, $\vdash \Gamma$, judgemental equality of types, $\Gamma \vdash A \equiv B$, and judgemental equality of terms, $\Gamma \vdash t \equiv u : A$. These relations are not defined with reference to grade contexts or modes. Here are the conversion rule and the typing rule for variables (de Bruijn indices):\frac{\gamma \triangleright \Gamma \vdash t :^p A \qquad \Gamma \vdash A \equiv B}{\gamma \triangleright \Gamma \vdash t :^p B} \qquad \frac{\vdash \Gamma \qquad x : A \in \Gamma \qquad \gamma(x) \leq p}{\gamma \triangleright \Gamma \vdash x :^p A}
The judgemental equality rules have mostly been relegated to Appendix A. They are rather standard, and include references to $\Gamma \vdash A$ and $\Gamma \vdash t : A$, but not other instances of $\gamma \triangleright \Gamma \vdash^p A$ and $\gamma \triangleright \Gamma \vdash t :^p A$. For the variable rule, if the mode is $p$, then the variable $x$ is well-resourced if its grade is at most $p$: if the mode is $\omega$, then the grade of the variable must be $\omega$, but in erased contexts the grade can be anything. (The definition of $x : A \in \Gamma$ can be found in Appendix A.) For $\Pi$-types we have the following rules, following Abel et al. [3] and Danielsson et al. [26]:\begin{aligned}\frac{\gamma \triangleright \Gamma \vdash ^{qp} A \qquad \gamma, p \triangleright \Gamma, A \vdash ^{q} B}{\gamma \triangleright \Gamma \vdash ^{q} \Pi_{p} A B} & \qquad \frac{\gamma \triangleright \Gamma \vdash A :^{qp} \cup_{l} \qquad \gamma, p \triangleright \Gamma, A \vdash B :^{q} \cup_{l}}{\gamma \triangleright \Gamma \vdash \Pi_{p} A B :^{q} \cup_{l}} \ \frac{\gamma, p \triangleright \Gamma, A \vdash t :^{q} B}{\gamma \triangleright \Gamma \vdash \lambda^{p} t :^{q} \Pi_{p} A B} & \qquad \frac{\gamma \triangleright \Gamma \vdash t :^{q} \Pi_{p} A B \qquad \gamma \triangleright \Gamma \vdash u :^{qp} A}{\gamma \triangleright \Gamma \vdash t^{p} u :^{q} B[u/0]} \end{aligned}
The $\Pi$-type $\Pi_p A B$ comes with a grade $p$. If this grade is 0, then the argument may only be used in erased contexts in the codomain $B$, and furthermore the mode is 0 for the antecedents $\gamma \triangleright \Gamma \vdash ^{qp} A$ and $\gamma \triangleright \Gamma \vdash A :^{qp} \cup_l$. The first rule gives a condition for $\Pi_p A B$ being a type, and the second rule gives a condition for $\Pi_p A B$ being a code in the universe $\cup_l$. Lambdas and applications are annotated with grades, and these grades have to match the grade of the $\Pi$-type. If the grade is 0, then the bound variable may only be used in erased contexts in the bodies of lambdas, and correspondingly the argument of an application is in an erased context. In some previous work introduction rules for the universe are only given for the case where the mode is 0 [43, 9]. Here I use rules based on those given by Abel et al. [3]. As mentioned above I do not prove correctness of erasure in the presence of both erased, postulated univalence and []-cong, but I base the design on that of Abel et al. in the hope that such a proof will be possible. This design is also used by Agda. The rules for $\Sigma$ and unit types are omitted, but note that one can choose whether or not to allow erased matches for the weak variants of those types (i.e. the variants with pattern matching instead of projections and $\eta$-equality). The rules for the empty type are also omitted. Again one can choose whether or not to allow erased matches for this type. The statement of Theorem 10.1 below contains assumptions related to erased matches for these types. Let us now consider identity types. One can choose between the following two formation rules (and corresponding rules for type formation):\begin{array}{r l r}{\frac{\gamma\blacktriangleright\Gamma\vdash t:P A}{\gamma\blacktriangleright\Gamma\vdash\mathsf{l d}A t u:P\cup_{l}}}&{{}}&{\frac{\Gamma\vdash A:\mathsf{U}{l}\qquad\Gamma\vdash t:A\qquad\Gamma\vdash u:A}{\gamma\blacktriangleright\Gamma\vdash\mathsf{l d}A t u:P\cup{l}}}\end{array}
Cubical Agda allows something akin to the first rule with $\Gamma \vdash A : \cup_l$ instead of $\gamma \blacktriangleright \Gamma \vdash A :^p \cup_l$. Here I have instead chosen a rule based on the one given for paths by Abel et al. [3]. The second rule above is not compatible with erased univalence in the presence of $[]$-cong (see § 5). However, all results presented below hold with either rule. The following rules are used for reflexivity and equality reflection:\frac{\Gamma\vdash t:A}{\gamma\blacktriangleright\Gamma\vdash\mathsf{refl}:^{p}\mathsf{ld}At t}\quad\frac{\Gamma\vdash v:\mathsf{ld}At u}{\Gamma\vdash t\equiv u:A}
The reflexivity constructor does not take any arguments. Equality reflection, which makes univalence inconsistent, is optional. For the J rule – the main eliminator for the identity type – one can choose between three different sets of rules. In all cases the same rule, presented below, is used when the mode is 0. If no erased matches are allowed for J, then the following rule is used when the mode is $\omega$:\begin{array}{r l r}{\frac{\Gamma\vdash A\qquad\gamma\blacktriangleright\Gamma\vdash t:\omega A}{\gamma\blacktriangleright\Gamma\vdash u:\omega B[t/1,\mathsf{r e f l}/0]}}&{{}\qquad\gamma,p,q\blacktriangleright\Gamma,A,\mathsf{l d}\left(A\uparrow\right)\left(t\uparrow\right)0\vdash^{\omega}B}\ &{}&{\gamma\blacktriangleright\Gamma\vdash v:\omega A\qquad\gamma\blacktriangleright\Gamma\vdash w:\omega\mathsf{l d}A t v}\ &{}&{\gamma\blacktriangleright\Gamma\vdash\mathsf{J}_{p,q}A t B u v w:\omega B[v/1,w/0]}\end{array}
The eliminator J is annotated with two grades. Those specify how the bound arguments are allowed to be used in the motive B. (The notation $A\uparrow$ stands for A, weakened one step.) Note that the grade context $\gamma$ and the mode $\omega$ are used for all antecedents except for the first one. One can also allow limited forms of erased matches. In that case there are two rules for the mode $\omega$ – the one above, restricted to the case where at least one of p and q is $\omega$, and the following one:\begin{array}{r l r}{\frac{\Gamma\vdash A\qquad\Gamma\vdash t:A\qquad\gamma,0,0\blacktriangleright\Gamma,A,\mathsf{l d}\left(A\uparrow\right)\left(t\uparrow\right)0\vdash^{\omega}B}{\gamma\blacktriangleright\Gamma\vdash u:\omega B[t/1,\mathsf{r e f l}/0]}}&{{}\qquad\Gamma\vdash v:A\qquad\Gamma\vdash w:\mathsf{l d}A t v}\ &{}&{\gamma\blacktriangleright\Gamma\vdash\mathsf{J}_{0,0}A t B u v w:\omega B[v/1,w/0]}\end{array}
Note that the grade context $\gamma$ and the mode $\omega$ are now only used for two antecedents, those for B and u. This set of rules is equally expressive as the previous one plus $[]$-cong, see § 12. Finally one can allow unrestricted erased matches for J. This rule is also used, in all cases, when the mode r is 0:\begin{array}{r l r}{\frac{\Gamma\vdash A\qquad\Gamma\vdash t:A}{\Gamma,A,\mathsf{l d}\left(A\uparrow\right)\left(t\uparrow\right)0\vdash B\qquad\gamma\blacktriangleright\Gamma\vdash u:\mathcal{r}B[t/1,\mathsf{r e f l}/0]}}&{{}}&{\Gamma\vdash v:A\qquad\Gamma\vdash w:\mathsf{l d}A t v}\ &{}&{\gamma\blacktriangleright\Gamma\vdash\mathsf{J}_{p,q}A t B u v w:\mathcal{r}B[v/1,w/0]}\end{array}
Here $\gamma$ and $r$ are only used for one antecedent, the one for $u$, and $p$ and $q$ are ignored (for simplicity the same syntax is used for all the rules). The intuition here is that, because we have a judgemental equality between $\mathsf{J}_{p,q} A t B u t \mathsf{refl}$ and $u$, the only computationally relevant argument is $u$. However, this rule allows one to implement functions like $\mathsf{subst}'$ and $\mathsf{subst}''$ from § 4 and § 5, so the type theory we get with this rule is not compatible with erased, postulated univalence. The formalisation also has optional support for the K rule – optional because the K rule makes univalence inconsistent – with three sets of typing rules akin to the ones presented for J above. Those rules can be found in Appendix A. The formalisation supports the definition of a type like Erased using a graded $\Sigma$-type [1], a unit type and a lift type. Instead of presenting rules for $\Sigma$, unit and lift types I present some admissible typing rules for a type Erased. In the formalisation one can choose between two variants of Erased, with or without $\eta$-equality; the following rules are admissible in either case:\frac{\Gamma \vdash A : \mathsf{U}_l}{\gamma \blacktriangleright \Gamma \vdash \mathrm{Erased}_l A :^p \mathsf{U}_l} \qquad \frac{\Gamma \vdash t : A}{\gamma \blacktriangleright \Gamma \vdash [t] :^p \mathrm{Erased}_l A} \qquad \frac{\Gamma \vdash t : \mathrm{Erased}_l A}{\Gamma \vdash \mathrm{erased} A t : A}
Note that the projection erased can only be used in erased contexts, and that the argument $t$ of $[t]$ is in an erased context. The application erased $A[t]$ is judgementally equal to $t$ (given $\Gamma \vdash t : A$). The type theory has optional support for []-cong. The typing rules for []-cong refer to Erased (in the formalisation one can choose to support one or both of two variants of []-cong, one for Erased without $\eta$-equality, and one for Erased with $\eta$-equality):\frac{\Gamma \vdash A \qquad \Gamma \vdash t : A \qquad \Gamma \vdash u : A \qquad \Gamma \vdash v : \mathsf{Id} A t u}{\gamma \blacktriangleright \Gamma \vdash [{}]-cong_{l} A t u v :^{p} \mathsf{Id} (\mathrm{Erased}_{l} A)[t][u]}
\frac{\Gamma \vdash t : A}{\Gamma \vdash [{}]-cong_{l} A t t \operatorname{refl} \equiv \operatorname{refl} : \mathsf{Id} (\mathrm{Erased}_{l} A)[t][t]}
The congruence rule has been omitted. Note that all arguments of []-cong $_{l}$ are in erased contexts. The rules for quotients are based on the interface presented in § 3 and omitted; these rules can be found in Appendix A. However, note that quotient types are optional, and that the rules use binders instead of $\Pi$-types. The point constructor class only takes one argument. The erased higher constructors are included as term formers (resp $A R t u v$ and set $A R t u v w$). In the absence of equality reflection they are treated as neutral, but in the presence of equality reflection well-typed applications of these constructors reduce to refl: note that, in the presence of equality reflection, every identity proof is judgementally equal to refl. There are six reduction judgements: - First weak head reduction for terms is defined: $\Gamma \vdash t \Rightarrow u : A$ means that, under the context $\Gamma, t$ reduces in a single step to $u$ at type $A$. The rules of this judgement can be found in Appendix A. It is deterministic, and compatible with judgemental equality: $\Gamma \vdash t \Rightarrow u : A$ implies $\Gamma \vdash t \equiv u : A$. A corresponding relation allowing zero or more steps is denoted by $\Gamma \vdash t \Rightarrow^* u : A$. • Then weak head reduction for types is defined: $\Gamma \vdash A \Rightarrow B$ holds if $\Gamma \vdash A \Rightarrow B : \mathsf{U}_l$, and $\Gamma \vdash A \Rightarrow^* B$ is the corresponding multi-step relation. • There is also a reduction relation that allows evaluation under successor constructors:\begin{array}{r l}{\frac{\Gamma\vdash t\Rightarrow u:\mathrm{N a t}}{\Gamma\vdash t\Rightarrow^{\mathrm{s u c}}u:\mathrm{N a t}}}&{{}\frac{\Gamma\vdash t\Rightarrow^{\mathrm{s u c}}u:\mathrm{N a t}}{\Gamma\vdash\mathrm{s u c}t\Rightarrow^{\mathrm{s u c}}\mathrm{s u c}u:\mathrm{N a t}}}\end{array}
The corresponding multi-step relation is denoted by $\Gamma \vdash t \Rightarrow^{\mathrm{suc}} u : \mathrm{Nat}$. This relation is used in the statement of Theorem 10.1 below. In § 11 and § 12 a well-formed substitution relation is used: $\delta \blacktriangleright \Delta \vdash \sigma :^p \Gamma$ means that $\sigma$ is a well-formed parallel substitution from $\Gamma$ to $\Delta$, where all terms in $\sigma$ are well-resourced with respect to $\delta$ and $p$. The notation $\Delta \vdash \sigma : \Gamma$ stands for $\mathbf{0} \blacktriangleright \Delta \vdash \sigma :^0 \Gamma$. In § 12 weakenings are also used. $\Delta \vdash \rho : \Gamma$ means that $\rho$ is a well-formed weakening from $\Gamma$ to $\Delta$. The family of type theories presented above includes a number of options. Some of them affect results presented below. They are summarised here: * Equality reflection, K, []-cong, and quotient types are optional. * Erased matches for the empty type, weak $\Sigma$-types, and the weak unit type are optional. * For J one can choose between no erased matches, limited erased matches, and unrestricted erased matches, and similarly for K. ## 9 Basic Meta-Theory Let us now look at some basic meta-theory for this family of type theories. (I do not claim that the results about identity types are particularly novel. See, for instance, Adjedj et al. [5] for formalised meta-theory of Martin-Löf type theory with intensional identity types.) Abel et al. [4, 1] prove normalisation, consistency etc. using a logical relations argument. Extending this argument to support identity types is straightforward (in the absence of equality reflection). I do not present a full argument here, but a key part of the formalised proof is to define two terms as reducibly equal at a type that reduces to $Id At u$ if (roughly) they both reduce to refl and $t$ and $u$ are reducibly equal at type $A$, or if both reduce to neutral, judgementally equal terms.⁷ In the absence of equality reflection the higher quotient constructors are treated as neutral, and two terms are reducibly equal at a type that reduces to a quotient type if (roughly) they both reduce to neutral, judgementally equal terms, or if they both reduce to applications of the point constructor and the arguments are reducibly equal (Pujet and Tabareau [52] use a similar definition). The formalisation also supports type theories with equality reflection. For such theories the logical relations omit cases for neutral terms. For quotients the point constructor case mentioned above is extended with an option for the point constructor arguments to be related by the symmetric, transitive closure of (roughly) “two terms are related if they are reducible and there is a reducible proof showing that they are related by the quotient relation”. If the quotient relation had been required to be an equivalence relation, then one could presumably have skipped taking the symmetric, transitive closure. We obtain a number of meta-theoretical properties, including the following ones related to empty contexts ($\varepsilon$): * Canonicity for $Id$ does not hold in the presence of the “postulated” higher quotient constructors, unless equality reflection is allowed, in which case well-typed applications of these constructors reduce to refl. We have that, if quotient types are not allowed or equality reflection is allowed, and $\varepsilon \vdash v : Id At u$, then $\varepsilon \vdash v \Rightarrow^* \text{refl} : Id At u$ and $\varepsilon \vdash t \equiv u : A$. * Similarly, if quotient types are not allowed or equality reflection is allowed, and $\varepsilon \vdash t : \text{Nat}$, then there is a natural number $n$ such that $\varepsilon \vdash t \equiv \underline{n} : \text{Nat}$, where $\underline{n}$ stands for $\text{suc}^n$ zero. * Consistency: there is no term $t$ such that $\varepsilon \vdash t : \bot$. From the logical relation we get that such a term must reduce to a closed, neutral term. In the absence of quotient types there are no closed, neutral terms, but if quotient types are allowed and equality reflection is disallowed, then the higher quotient constructors are treated as neutral. However, if $\varepsilon \vdash t : \bot$ holds in the absence of equality reflection, then it holds also when equality reflection is turned on, so consistency holds unconditionally. The following properties hold in the absence of equality reflection, or if the context $\Gamma$ is empty: * Weak head normalisation for types and terms: if $\Gamma \vdash A$ then there is some weak head normal form (WHNF) $B$ such that $\Gamma \vdash A \Rightarrow^* B$, and if $\Gamma \vdash t : A$ then there is some WHNF ⁷This definition is based on a suggestion from Andreas Abel. $u$ such that $\Gamma \vdash t \Rightarrow^* u : A$. If $\Gamma \vdash v : \mathsf{Id} At u$ then $\Gamma \vdash v \Rightarrow^* w : \mathsf{Id} At u$ for some $w$ that is either refl (in which case $\Gamma \vdash t \equiv u : A$) or neutral. * If $\Gamma \vdash \mathsf{Id} At u \equiv B$, then $B$ is not neutral and not $\cup_l$, a lift type, the empty type, a unit type, a $\Pi$-type, a $\Sigma$-type, Nat, or a quotient type. A corresponding property holds for $A/B$. * Injectivity of $\mathsf{Id}$: If $\Gamma \vdash \mathsf{Id} A_1 t_1 u_1 \equiv \mathsf{Id} A_2 t_2 u_2$, then $\Gamma \vdash A_1 \equiv A_2, \Gamma \vdash t_1 \equiv t_2 : A_1$ and $\Gamma \vdash u_1 \equiv u_2 : A_1$. The following properties hold in the absence of equality reflection: * Injectivity of $\neg /_-$: if $\Gamma \vdash A_1/B_1 \equiv A_2/B_2$, then $\Gamma \vdash A_1 \equiv A_2$ and $\Gamma, A_1, A_1 \uparrow \vdash B_1 \equiv B_2$. * Decidability of judgemental equality of types and terms: if $\Gamma \vdash A$ and $\Gamma \vdash B$, then it is decidable whether $\Gamma \vdash A \equiv B$ holds, and if $\Gamma \vdash t : A$ and $\Gamma \vdash u : A$, then it is decidable whether $\Gamma \vdash t \equiv u : A$ holds. * Type-checking is decidable for a fragment of the language that excludes, for instance, $\beta$-redexes (because lambdas and applications are not annotated with types). ## 10 Soundness of Erasure Abel et al. [1] define a translation to an untyped target language. This translation replaces erased arguments with a dummy value, and this dummy value is also used for some other things. Abel et al. prove that the translation is correct in the following sense: given certain assumptions a term $t$ of type Nat reduces to a numeral $n$, and the translated term reduces to the same numeral. Danielsson et al. [26] extend the translation with support for call-by-value in addition to call-by-name, and in the case of call-by-name erased arguments are removed entirely instead of being replaced by a dummy value. Here the translation of Danielsson et al. is extended with support for identity types and quotients. For simplicity only the call-by-value translation is presented in the text: the call-by-name translation can be found in the formalisation. Note that the soundness theorem is stated in a slightly different way when the call-by-name translation is used [26]. The target language does not have any term formers directly related to identity types or quotients. The syntax of the target language is defined in the following way: $t, u ::= \varphi \mid \text{var } x \mid \text{lam } t \mid \text{app } t u \mid \text{zero} \mid \text{suc } t \mid \dots$ (one of the term formers related to Nat, and all of the term formers related to $\Sigma$ and unit types, have been omitted; they can be found in Appendix B). The formalisation uses well-scoped syntax, but details related to that are omitted here. Variables $x$ are natural number literals (de Bruijn indices). The target language comes with an inductively defined call-by-value small-step semantics, $t \Rightarrow u$, without evaluation under constructors (the relation can be found in Appendix B). The statement of the soundness theorem below (Theorem 10.1) uses the reflexive, transitive closure of this relation, denoted by $\Rightarrow^*$. For a natural number $n$ the notation $n$ stands for the corresponding term, $\text{suc}^n$ zero (in the source language as well as the target language). Let me now present the extraction function. It is defined recursively in Figure 1 (some cases have been omitted, see Appendix B for more details). All type constructors are replaced by the dummy term $\varphi$, as are erased function arguments. The identity type primitives refl and []-cong are also replaced by $\varphi$: no attempt is made to compute the values of identity proofs. The higher quotient constructors are instead replaced by loop – which is a non-terminating term – to illustrate that their extracted terms will not be reduced to WHNF. For J all arguments except for one are thrown away (and K is treated similarly). There is no representation of class in the target language, and applications of qrec are turned into $\beta$-redexes. The application $\text{suc } t$ is translated to\begin{array}{r l r l r l r l r l}&{\mathrm{e r a s e~}x}&{}&{=\mathrm{v a r~}x}&{}&{\mathrm{e r a s e~}(\mathrm{s e t~}A B t u v w)=\mathrm{l o o p}}&\ &{\mathrm{e r a s e~}(\mathrm{l d~}A t u)}&{}&{=\mathbb{d}}&{}&{\mathrm{e r a s e~}(\mathrm{q r e c~}C t u v w)=\mathrm{a p p~}(\mathrm{l a m~}(\mathrm{e r a s e~}t))(\mathrm{e r a s e~}w)}&\ &{\mathrm{e r a s e~}\mathrm{r e f l}}&{}&{=\mathbb{d}}&{}&{\mathrm{e r a s e~}(\Pi_{p}A B)}&{=\mathbb{d}}&\ &{\mathrm{e r a s e~}(\mathrm{J}{p,q}A t B u v w)}&{=\mathrm{e r a s e~}u}&{}&{\mathrm{e r a s e~}(\lambda^{p}t)}&{=\mathrm{l a m~}(\mathrm{e r a s e~}t)}&\ &{\mathrm{e r a s e~}([\mathbb{-}]\mathrm{-c o n g}{l}A t u v)}&{=\mathbb{d}}&{}&{\mathrm{e r a s e~}(t^{\omega}u)}&{=\mathrm{a p p~}(\mathrm{e r a s e~}t)(\mathrm{e r a s e~}u)}&\ &{\mathrm{e r a s e~}(A/B)}&{=\mathbb{d}}&{}&{\mathrm{e r a s e~}(t^{0}u)}&{=\mathrm{a p p~}(\mathrm{e r a s e~}t)\mathbb{d}}&\ &{\mathrm{e r a s e~}(\mathrm{c l a s s}t)}&{=\mathrm{e r a s e~}t}&{}&{\mathrm{e r a s e~}\mathrm{z e r o}}&{=\mathrm{z e r o}}&\ &{\mathrm{e r a s e~}(\mathrm{r e s p~}A B t u v)}&{=\mathrm{l o o p}}&{}&{\mathrm{e r a s e~}(\mathrm{s u c~}t)}&{=\mathrm{a p p~}(\mathrm{l a m~}(\mathrm{s u c~}(\mathrm{v a r~}0)))(\mathrm{e r a s e~}t)}\end{array}
Fig. 1. The extraction function. “(λx.suc x)(erase t)”: as mentioned above the semantics does not include evaluation under constructors, and this construction ensures that erase t is reduced before the successor constructor is applied to the term. Abel et al. [1] and Danielsson et al. [26] prove soundness of erasure using logical relations. Adapting this kind of argument to the present setting is straightforward. A key step in my proof is to define the logical relation in the following way for identity types and quotients: - A source term and a target term are related at a type that reduces to Id At u if the source term reduces to refl and the target term reduces to $\mathbb{d}$. - A source term t and a target term v are related at a type that reduces to A/B if t reduces to class $t'$ and $t'$ is related to v at type A. We obtain the following theorem (“Γ is consistent” means that there is no $t$ such that $\Gamma \vdash t : \bot$): THEOREM 10.1 (SOUNDNESS OF ERASURE). If $\mathbf{0} \blacktriangleright \Gamma \vdash t : ^{\omega}$ Nat; $\Gamma$ is consistent or erased matches are disallowed for the empty type; and either • $\Gamma$ is empty and either quotient types are disallowed or equality reflection is allowed, or - []-cong is disallowed, erased matches are disallowed for J and K as well as weak $\Sigma$ and unit types, and equality reflection is disallowed, then there is a natural number $n$ such that $\Gamma \vdash t \Rightarrow ^{suc*} \underline{n} : \mathrm{Nat}$ and erase $t \Rightarrow ^{*} \underline{n}$. The theorem would fail, even for closed terms, if quotient types were allowed, equality reflection were disallowed, and (say) limited erased matches were allowed for J, because then one could construct a term t for which source-level reduction gets stuck. However, $\varepsilon \blacktriangleright \varepsilon \vdash t : ^{\omega}$ Nat suffices to ensure that the extracted term does not get stuck: this follows from Theorem 11.3. The soundness theorem allows open terms, as long as all free variables are erased (have grade 0), erased matches are disallowed for identity types and weak $\Sigma$ and unit types, []-cong is disallowed, equality reflection is disallowed, and either erased matches are disallowed for the empty type or the context is consistent. The free variables can be seen as erased postulates. One could for instance postulate function extensionality, univalence, excluded middle and a choice principle, and use these assumptions in erased contexts. If one can prove that these postulates are mutually consistent (or if erased matches for the empty type are disallowed), then one gets a guarantee that programs of type Nat reduce to numerals, and that the corresponding extracted terms reduce to equal numerals. However, this guarantee does not hold if for instance []-cong is allowed: the term []-cong $_{l}$ At u x is stuck, and it is well-resourced even if x has grade 0 (and it is easy to construct a similar example of type Nat). Before we leave this section, let me present a result about how it is not in general possible to “resurrect” erased data, i.e. produce a value that is equal to an erased value. In the interest of readability the following definition uses a notation with names instead of de Bruijn indices (such a notation is also sometimes used below): Definition 10.2. The type $A$ is resurrectable at universe level $l$ if there is a term $t$ such that $\varepsilon \blacktriangleright \varepsilon \vdash t :^{\omega} \Pi_0(x : A)(\Sigma_{\mathbf{s},\omega}(y : A)(\text{Erased}_l(\text{Id } A y x)))$, where $\Sigma_{\mathbf{s},\omega}$ stands for a $\Sigma$-type with $\eta$-equality (a strong $\Sigma$-type) and a non-erased first component. PROPOSITION 10.3. Unit types are resurrectable at level 0, and if erased matches are allowed for the empty type, then it is also resurrectable at level 0. However, the type of natural numbers is not resurrectable at any level $l$. PROOF SKETCH. The first two cases are easy to prove. For the last case one can use the fundamental lemma of the logical relation used to prove Theorem 10.1. $\square$ ## 11 Soundness of Erasure in the Presence of Erased Postulates and Erased Matches Theorem 10.1 does not allow erased postulates (i.e. a non-empty context) and erased matches at the same time, with the exception of erased matches for the empty type. If any of the conditions related to erased matches were removed, then the theorem would not hold: in those cases one can construct terms $t$ for which it is not the case that $t$ reduces to a numeral. Would it be possible to prove the theorem without some or all of the restrictions related to erased matches if “$\Gamma \vdash t \Rightarrow^{\text{succ}} \underline{n} : \text{Nat}$” in the theorem’s conclusion were replaced by something else? One idea is to replace the reduction with the statement that there is a term $u$ such that $\Gamma \vdash u : \text{Id Nat } t \underline{n}$. If one also included suitable extensionality assumptions, then there is perhaps some hope that the theorem could be proved without any restrictions on []-cong. However, I have found it hard to prove something like this. If $t$ reduces to $u$, or if $t$ is judgementally equal to $u$, then one can freely replace $t$ with $u$: the type $Pt$ is interchangeable with $Pu$. This does not follow if the identity type $\text{Id } At u$ is inhabited (in the absence of something like equality reflection): one can use $\mathcal{J}$ to replace $t$ with $u$, but a term that has type $Pt$ might not also have type $Pu$. Because I find it easier to work with judgemental equality than with identity types I have taken a different approach: I replace $\Gamma \vdash t \Rightarrow^{\text{succ}} \underline{n} : \text{Nat}$ with a judgemental equality in an extended type theory, in which the postulates can be implemented. For that type theory it suffices to prove soundness of erasure for closed terms. Note that, for closed terms, Theorem 10.1 does not impose any restrictions related to erased matches or quotient types if equality reflection is allowed. Let us fix one type theory from the family of type theories from § 8. Definition 11.1. An extension of the type theory is a type of terms $T^8$ closed under application of parallel substitutions $\sigma$ containing terms from $T$ (application is denoted by $t\sigma$), a translation $tr$ taking regular terms to terms in $T$, an extraction function $erase_E$ from $T$ to the target language from § 10, a typing relation $\gamma \blacktriangleright \Gamma \vdash_E t :^p A$ (where $t, A : T$ and $\Gamma$ uses types from $T$), a judgemental equality relation $\Gamma \vdash_E t \equiv u : A$, and a well-formed substitution relation $\delta \blacktriangleright \Delta \vdash_E \sigma :^p \Gamma$, satisfying the following properties: * Translation is type-preserving: $\gamma \blacktriangleright \Gamma \vdash t :^p A$ implies $\gamma \blacktriangleright tr \Gamma \vdash_E tr t :^p tr A$ (where $tr \Gamma$ is the pointwise application of $tr$ to the types in $\Gamma$). * A substitution lemma: $\mathbf{0} \blacktriangleright \Gamma \vdash_E t :^p A$ and $\varepsilon \blacktriangleright \varepsilon \vdash_E \sigma :^0 \Gamma$ imply $\varepsilon \blacktriangleright \varepsilon \vdash_E t \sigma :^p A \sigma$. * $\mathbf{0} \blacktriangleright \Gamma \vdash_E t :^{\omega} A$ implies that $erase_E(t\sigma)$ is equal to $erase_E t$ for closing substitutions $\sigma$. * The target term $erase_E(tr t)$ is equal to $erase t$, and $(tr \text{Nat}) \sigma$ is equal to $tr \text{Nat}$. * Soundness of erasure for closed terms: if $\varepsilon \blacktriangleright \varepsilon \vdash_E t :^{\omega} tr \text{Nat}$, then there is a natural number $n$ such that $\varepsilon \vdash_E t \equiv tr \underline{n} : tr \text{Nat}$ and $erase_E t \Rightarrow^* \underline{n}$. $^8$The formalisation uses well-scoped syntax. Those details are elided here. Given an extension of the type theory it is easy to prove the following theorem: THEOREM 11.2. Let $\sigma$ be a closing substitution satisfying $\varepsilon \blacktriangleright \varepsilon \vdash_E \sigma :^0 \text{ tr } \Gamma$. If $\mathbf{0} \blacktriangleright \Gamma \vdash t :^\omega \text{ Nat}$, then there is a natural number $n$ such that $\varepsilon \vdash_E (tr t) \sigma \equiv tr \underline{n} : tr \text{ Nat and erase } t \Rightarrow^* \underline{n}$. Let us now instantiate the theorem. Every type theory from § 8 can be extended by turning on equality reflection and making no other changes, letting $tr$ be the identity function. Thus we obtain the following theorem, where the relations marked with R refer to the extended type theory with equality reflection: THEOREM 11.3. Let $\sigma$ be a closing substitution satisfying $\varepsilon \blacktriangleright \varepsilon \vdash_R \sigma :^0 \Gamma$. If $\mathbf{0} \blacktriangleright \Gamma \vdash t :^\omega \text{ Nat}$, then there is a natural number $n$ such that $\varepsilon \vdash_R t \sigma \equiv \underline{n} : \text{Nat and erase } t \Rightarrow^* \underline{n}$. This theorem can for instance be used to show that a program that uses (only) postulated erased function extensionality will not get stuck, even if erased matches and quotient types are used. It is my hope that (some variant of) Theorem 11.2 can also be instantiated with a suitable cubical type theory, thus showing that Computational Book HoTT is well-behaved even in the presence of []-cong, as discussed in § 6. However, that is left for future work. Note that propositional extensionality cannot be implemented as a closed term in the type theories with equality reflection presented here: propext would allow one to construct a closed term that does not reduce to WHNF, contradicting the weak head normalisation result from § 9. However, propext can be implemented in cubical type theory (it follows from univalence). One might think that another way to show that erased propext is safe is to instantiate Theorem 11.2 with some kind of observational type theory with support for quotients and propext. Pujet and Tabareau [52] discuss such a type theory. However, their notion of propext is restricted to strict propositions in a specific definitionally proof-irrelevant universe, unlike the notion of propext discussed here, which works for all types that are propositions semantically (as specified by Is-prop). The semantic notion of propext is presumably $^9$ inconsistent with the type theory of Pujet and Tabareau: observationally equal proof-relevant $\Pi$-types necessarily have equal domains, so I expect that this variant of propext could be used to prove that the unit type is observationally equal to the empty type. One can discuss which variant is “better”: Sterling et al. [57] state that ‘short of adding equality reflection, we must conclude that the weak notion of proposition is the “correct” one, and the strict one is not particularly useful for mathematics in an environment without equality reflection’ (“the weak notion” refers to the semantic one). ## 12 Box-Cong Can Sometimes, but Not Always, Be Defined Let us now investigate under what circumstances one can define something like []-cong. “Something like” is made precise in the following way: Definition 12.1. []-cong is supported for the context $\Gamma$, the level $l$, the mode $p$, and the grades $q_1, q_2$ and $q_3$ if $\mathbf{0} \blacktriangleright \Gamma \vdash bc :^p \Pi_{q_1} (A : \cup_l) \Pi_{q_2} (x : A) \Pi_{q_3} (y : A) \Pi_0 (\mathsf{Id} A x y) (\mathsf{Id} (\mathsf{E}rased_l A) [x] [y])$ holds for some term bc. []-cong is supported computationally for the context $\Gamma$, the level $l$, the mode $p$, and the grades $q_1, q_2$ and $q_3$ if additionally the following equality rule is admissible (note that $\rho$ is a weakening):\begin{aligned}\Delta \vdash \rho : \Gamma \qquad \Delta \vdash A : \cup_l \qquad \Delta \vdash t : A\\hline \Delta \vdash (bc \rho)^{q_1} A^{q_2} t^{q_3} t^0 \text{refl} \equiv \text{refl} : \mathsf{Id} \left( \mathsf{E}rased_l A \right) [t] [t]\end{aligned}
It may appear as if bc is more useful if $q_1$, $q_2$ and $q_3$ are all 0, but such a variant of bc can be defined using any other variant: $^{9}$The presentation of one of the reduction rules (EQ-II) appears to contain some typos [52, Figure 4]. Eased Postulates, Identity Types and Quotients 19 PROPOSITION 12.2. []-cong is supported (respectively supported computationally) for the context $\Gamma$, the level $l$, the mode $p$, and the grades 0, 0 and 0 if and only if []-cong is supported (respectively supported computationally) for the context $\Gamma$, the level $l$, the mode $p$, and the grades $q_1, q_2$ and $q_3$. PROOF SKETCH. For the left-to-right direction this should be easy to see. For the other direction one can define []-cong with erased arguments in terms of the other variant of []-cong using code that is similar to the following Agda code:\begin{array}{l}{[\mathbf{\textsf{}}]-c o n g^{\prime}:(@0A:T y p ea)(@0x y:A)\to@0I d A x y\to I d(E r a s e d A)[x][y]}\ {[\mathbf{\textsf{}}]-c o n g^{\prime}A x y e q=}\ {\quad c o n g\left(\lambda x\to[\mathbf{\textsf{}}]e r a s e d\left(e r a s e d x\right)\right)([\mathbf{\textsf{}}]-c o n g\left(E r a s e d A\right)[x][y]\left(c o n g\left(\lambda x\to[x]\right)e q\right))}\end{array}
\begin{array}{l}{[\mathbf{\textsf{}}]-c o n g:(@0A:T y p ea)(@0x y:A)\to@0I d A x y\to I d(E r a s e d A)[x][y]}\ {[\mathbf{\textsf{}}]-c o n g A x y e q=s u b s t^{\mathbb{E}^{\prime}}(\lambda y\to I d(E r a s e d A)[x][y])e q r e f l}\end{array}
\begin{array}{c}\gamma,0,0\blacktriangleright\Gamma,A,\mathrm{Id}\left(A\uparrow\right)\left(t\uparrow\right)0\vdash^{P}B\quad\gamma\blacktriangleright\Gamma\vdash u:^{P}B[t/1,\mathrm{refl}/0]\quad\Gamma\vdash w:\mathrm{Id}At v\\frac{\gamma\blacktriangleright\Gamma\vdash J^{\mathrm{E}}AtBu v w:^{P}B[v/1,w/0]}{}\end{array}
This term former also satisfies the substitution equation, the congruence rule, and the $\beta$ rule of $J_{0,0}$ (those equations/rules were omitted above). Using ideas from Propositions 12.3 and 12.4 one can show that limited erased matches for J have the same expressive power as []-cong by constructing two type-preserving translations: one that replaces []-cong with a term former implemented using J, and one that replaces $J_{0,0}$ with a term former implemented using []-cong. (The translations do not affect extraction.) Even if something like []-cong can sometimes be defined, this is not always the case. Before we prove this, let me state a lemma that can be proved by induction. Let “erased matches are disallowed for $\Gamma$” mean that the []-cong primitive is disallowed, erased matches are disallowed for J and K as well as weak $\Sigma$ and unit types, and either erased matches are disallowed for the empty type or $\Gamma$ is consistent: LEMMA 12.5 (NO NEUTRAL TERMS). If erased matches are disallowed for $\Gamma$ and $t$ is neutral, then it is not the case that $\mathbf{0} \blacktriangleright \Gamma \vdash t : ^{\omega} A$. THEOREM 12.6 ([]-cong CANNOT BE DEFINED). If erased matches are disallowed for $\Gamma$ and equality reflection is disallowed, then []-cong is not supported for $\Gamma$, $l$ and $\omega$, and there is no term $bc_0$ such that $\mathbf{0} \blacktriangleright \Gamma \vdash bc_0 : ^{\omega} \Pi_0 (n : \text{Nat}) \Pi_0 (\text{Id Nat zero } n) (\text{Id (Erased}_0 \text{ Nat}) [zero] [n])$. Note that the empty context is consistent. I do not see why []-cong would be supported if erased matches were allowed for weak $\Sigma$ or unit types, but my proof makes use of Lemma 12.5. The second part of the conclusion establishes that functions like []-cong$_0$ from § 7 cannot be implemented. PROOF SKETCH. Let us focus on the first part of the conclusion: the second part can be proved in a similar way. If []-cong is supported for $\Gamma$, $l$ and $\omega$, then there is some term bc such that $\mathbf{0} \blacktriangleright \Gamma \vdash bc : ^{\omega} \Pi_0 (A : \cup_l) \Pi_0 (x : A) \Pi_0 (y : A) \Pi_0 (\text{Id } A x y) (\text{Id (Erased}_l A) [x] [y])$. We get that $\mathbf{0} \blacktriangleright \Delta \vdash t : ^{\omega} \text{Id (Erased}_l A) [x] [y]$ holds for $\Delta = \Gamma, A : \cup_l, x : A, y : A, eq : \text{Id } A x y$ and $t = (bc \rho)^0 A^0 x^0 y^0 eq$ (for a suitable weakening $\rho$). Equality reflection is disallowed, so the term $t$ must have a WHNF, and that WHNF must be either refl or a neutral term (see § 9): * If it is refl, then we must have $\Delta \vdash [x] \equiv [y] : \text{Erased}_l A$, and thus $\Delta \vdash x \equiv y : A$, but two distinct variables are not judgementally equal at a neutral type (this can be proved using the formalisation's algorithmic equality judgement [4]). * The WHNF cannot be neutral by Lemma 12.5: if $\Gamma$ is consistent, then $\Delta$ is consistent because there is a substitution $\sigma$ satisfying $\Gamma \vdash \sigma : \Delta$. $\square$ []-cong can be defined using function extensionality (see § 16). However, []-cong cannot be defined using (only) postulated erased function extensionality: a context with a single variable with the type of function extensionality is consistent, so the theorem above applies. ## 13 Modalities Let us now discuss idempotent, monadic modalities in the style of Rijke et al. [53]. This discussion is included because $\lambda A \to \text{Erased} A$ and $\lambda x \to [x]$ form a modality if and only if []-cong can be defined,$^{10}$ and furthermore Rijke et al. [53] present a number of properties that hold for all modalities: thus, if []-cong can be defined, then these properties hold for Erased as well (with the caveat that Rijke et al. make use of function extensionality, univalence and higher inductive types). In this and the following sections I switch from the type theory of the formalisation to Agda (with the K rule turned off). I also mostly write $x \equiv y$ instead of $\text{Id} A x y$. Some definitions from homotopy type theory [62] are used. A type is contractible if there is one element that is equal to every other: $\text{Contractible} A = (x : A) \times ((y : A) \to x \equiv y)$. A function $f : A \to B$ is an equivalence if and only if it is bijective, and the type $Is-equivalence f$ is – given funext – necessarily a proposition. If there is an equivalence from $A$ to $B$, then the types are equivalent, written $A \simeq B$. Funext $a p$ is funext for functions of type $(x : A) \to P x$, where $A : \text{Type} a$ and $P : A \to \text{Type} p$, expressed as “certain functions of type $f \equiv g \to (\forall x \to f x \equiv g x)$ are equivalences”. The definition of modality that I use is not taken from the text of Rijke et al. [53], but is based on a definition in the associated formalisation. The definition is aimed at being usable also in the absence of funext. One property is stated in the form “if funext holds, then...”, because the “then” part is often proved using funext.$^{11}$ Another part uses the notion of being $\infty$-extendable along a $^{10}$The functions are $\eta$-expanded to give them suitable types: @0 Type $a \to \text{Type} a$ is not the same type as Type $a \to \text{Type} a$. $^{11}$See Mike Shulman's commit https://github.com/HoTT/Coq-HoTT/commit/a4ac2269f389be21f2c2385b99b3be467c0c4484. function [55]. This definition is rather technical and omitted. In the presence of funext "P is ∞-extendable along f" is equivalent to "precomposition with f for functions of type ∀ x → P x is an equivalence": Is-∞-extendable-along-[f] P ≈ Is-equivalence (λ (g : ∀ x → P x) → g ∘ f). Now we can define what a modality is: Definition 13.1. The functions ○ : Type a → Type a and η : {A : Type a} → A → ○ A form a modality for the level a if they satisfy Is-modality a ○ η, a type with the following components: * A function Modal : Type a → Type a that classifies modal types. * Funext (for a) implies that Modal is propositional: Funext a a → Is-prop (Modal A). * Modal (○ A) always holds. * Modal respects equivalences: A ≃ B → Modal A → Modal B. * Every pointwise modal family of type ○ A → Type a is ∞-extendable along η:{P : \circ A \to \mathrm{Type } a} \to (\forall x \to \mathrm{Modal} (P x)) \to \mathrm{Is-}\infty\text{-extendable-along-}[\eta] P
\begin{array}{ll}Modal^{\mathrm{E}}:Type a\to Type a&Separated^{\mathrm{E}}:Type a\to Type a\ Modal^{\mathrm{E}}A=Is-equivalence\left(\lambda\left(x:A\right)\rightarrow\left[x\right]\right)&Separated^{\mathrm{E}}A=\left(x y:A\right)\rightarrow Modal^{\mathrm{E}}\left(x\equiv y\right)\end{array}
I also use Stable $^{\mathrm{E}}$ A = Erased A → A and Stable-equality $^{\mathrm{E}}$ A = (x y : A) → Stable $^{\mathrm{E}}$ (x ≡ y). Note that if Stable $^{\mathrm{E}}$ A holds, then one can convert from Erased A to A, and if Modal $^{\mathrm{E}}$ A holds, then there is an equivalence between Erased A and A: for modal types one can resurrect erased values. ## 14 Characterisations of “Box-Cong Can Be Defined” Let me now present a number of logically equivalent characterisations of “[]-cong can be defined for the universe level $a$”. Due to lack of space the proof is omitted, but note that it employs a technique used by Altenkirch et al. [7]. The proof can be found in the accompanying code, along with even more equivalent characterisations. THEOREM 14.1. For a universe level a the following definitions are logically equivalent. In the presence of function extensionality they are propositions, and thus equivalent, and in light of Theorem 16.2 even contractible. Every definition given below has the type Type (lsuc a). The first definitions are variations of Definition 12.1, using propositional instead of judgemental equality (there are also variants with Erased $(x \equiv y)$ instead of @0 $x \equiv y$; refl $\{x = x\}$ has type $x \equiv x$): (1) ([]-cong : {@0 A : Type a} {@0 x y : A} → @0 x ≡ y → [x] ≡ [y]) ×\left(\left{@0A:Type a\right}\left{@0x:A\right}\rightarrow\left[\right]-cong\left(refl\left{x=x\right}\right)\equiv refl\right)
\left(\left{A:Type a\right}\left{x:A\right}\rightarrow\left[\right]-cong\left(refl\left{x=x\right}\right)\equiv refl\right)
We also have the following variant, stated using Stable-equality $^{E}$: (3) $(f : \{@0 A : \text{Type } a\} \to \text{Stable-equality}^{\text{E}}(\text{Eased } A))$ $\times$ $\{(@0 A : \text{Type } a\} \{x : \text{Eased } A\} \to f x x [\text{refl}] \equiv \text{refl})$ Then we have some definitions of the form “certain functions are equivalences”: (4) $\{@0 A : \text{Type } a\} \{@0 x y : A\} \rightarrow$ Is-equivalence $(\lambda (eq : [x] \equiv [y]) \rightarrow [\text{cong erased eq}])$ (5) $\{@0 A : \text{Type } a\} \{x y : \text{Eased } A\} \to \text{Is-equivalence} (\lambda (eq : x \equiv y) \to [\text{cong erased eq}])$ (6) $\{@0 A : \text{Type } a\} \rightarrow \text{Separated}^{\text{E}}(\text{Eased } A)$ (7) $\{(@0 A : \text{Type } a\} \to \text{Modal}^{\text{E}}(\text{Eased } A)) \times (\{A : \text{Type } a\} \to \text{Modal}^{\text{E}} A \to \text{Separated}^{\text{E}} A)$ The next batch are of the form “subst $^{E}$/j $^{E}$ can be defined”: (8) $(subst^{\mathrm{E}} : \{@0 A : \text{Type } a\} \{@0 x y : A\} (P : @0 A \to \text{Type } a) \to$ @0 $x \equiv y \to P x \to P y) \times$\left({@0A:Type a}{@0x:A}{P:@0A\to Type a}{p:P x}\to subst^{E}P refl p\equiv p\right)
(9) $(\mathcal{J}^{\mathrm{E}} : \{@0 A : \text{Type } a\} \{@0 x y : A\} (P : \{@0 y : A\} \to @0 x \equiv y \to \text{Type } a) \to$P\operatorname{refl}\to(@0;eq:x\equiv y)\to P;eq)\times
\begin{array}{r l}&{({@0A:Type a}{@0x:A}{P:{@0y:A}\to@0x\equiv y\to Type a}}\ &{\quad(r:P\operatorname{refl})\to\mathcal{J}^{\mathrm{E}}P r\operatorname{refl}\equiv r)}\end{array}
Finally we have a definition involving extendability: (10) $\{A B : \text{Type } a\} \to \text{Is-}\infty\text{-extendable-along}[\left( \lambda x \to [x] \right)] (\lambda \left( \_\right : \text{Eased } A) \to \text{Eased } B)$ Let []-cong-axiomatisation a denote any of the logically equivalent definitions from Theorem 14.1. If one of these definitions is inhabited for a given universe level, then it is also inhabited for smaller universe levels, and all definitions are inhabited in erased contexts. Another definition is given in the following theorem: THEOREM 14.2. []-cong-axiomatisation a is logically equivalent to Is-modality a ( $\lambda A \to \text{Eased } A$) ( $\lambda x \to [x]$). In the presence of funext and propxet this type is a proposition, and thus equivalent to the other definitions. PROOF SKETCH. Let us start with the last part. Using funext one can prove that, with Modal fixed, the remaining parts of the type form a proposition. Thus it suffices to prove that any two implementations of Modal are equal. In the presence of funext and propxet this follows because Modal A is a proposition that is logically equivalent to Is-equivalence ( $\lambda(x:A) \to [x]$), see § 13. If Erased and $[\_](\eta$-expanded) form a modality, then $[\_]$-cong can be defined (see § 13). For the other direction we can proceed in the following way: Let Modal be $Modal^E$. Given funext this definition is propositional. Erased A is modal in the presence of $[\_]$-cong, see Theorem 14.1. $Modal^E$ also respects equivalences: this can be proved using $[\_]$-cong. Finally $\infty$-extendability holds (this part of the proof is omitted). ## 15 The Erasure Modality Let us call the modality defined in (the proof of) Theorem 14.2 the erasure modality. This modality, which is defined under the assumption that $[\text{]-cong-axiomatisation a}$ holds, is left exact, and thereby satisfies all properties that left exact modalities satisfy [53]. There are also properties that hold for Erased that do not hold for every left exact modality. $Modal^{E} \perp$ holds (also in the absence of $[\text{-cong}$), but the empty type is not modal for every left exact (or even “topological” [53]) modality: it is not modal for the (left exact and topological) zero modality, for which the modal operator $\circ$ maps every type to a unit type. For every modality for which the empty type is modal one can prove properties like the following ones:\begin{array}{l} SeparatedA\to SeparatedB\to Separated~(A\uplus B)\ SeparatedA\to Separated(List~A)\end{array}
\begin{array}{l}\circ\left(A\rightarrow B\right)\Leftrightarrow\left(\circ A\rightarrow\circ B\right)\\circ\left(A\cong B\right)\Leftrightarrow\left(\circ A\simeq\circ B\right)\end{array}
\begin{array}{l}\circ(Is-equivalence f)\Leftrightarrow Is-equivalence\left(\circ-map f\right)\\circ(H-level n A)\quad\Leftrightarrow H-level n\left(\circ A\right)\end{array}
H-level generalises Contractible, Is-prop and Is-set, so we get that Erased A is a proposition (or set) if there is an erased proof showing that A is a proposition (set). We also get that an erased equivalence between A and B can be turned into a non-erased equivalence between Erased A and Erased B. ## 16 Box-Cong Can Be Defined Using Function Extensionality Let us now see how one can use function extensionality to define $[]$-cong. First we have a lemma: LEMMA 16.1. If function extensionality holds, then a certain form of precomposition with $[\_]$ is an equivalence (the notation @ω ensures that the argument is non-erased):\begin{aligned}&{A:Type a}{\circ@0P:E r a s e d A\to Type p}\to Funext a p\to\&Is-equivalence(\lambda(f:(x:E r a s e d A)\to Er a s e d(P x))\to\lambda(@\omega x:A)\to f[x])\end{aligned}
undefined\overline{\vdash \varepsilon} \qquad \frac{\Gamma \vdash A}{\vdash \Gamma,A}
\frac{\gamma \blacktriangleright \Gamma \vdash t :^{p} A \qquad \Gamma \vdash A \equiv B}{\gamma \blacktriangleright \Gamma \vdash t :^{p} B}
\frac{\Gamma \vdash A}{\Gamma \vdash A \equiv A} \qquad \frac{\Gamma \vdash A_{1} \equiv A_{2}}{\Gamma \vdash A_{2} \equiv A_{1}} \qquad \frac{\Gamma \vdash A_{1} \equiv A_{2} \qquad \Gamma \vdash A_{2} \equiv A_{3}}{\Gamma \vdash A_{1} \equiv A_{3}}
\frac{\Gamma \vdash t : A}{\Gamma \vdash t \equiv t : A} \qquad \frac{\Gamma \vdash t_{1} \equiv t_{2} : A}{\Gamma \vdash t_{2} \equiv t_{1} : A} \qquad \frac{\Gamma \vdash t_{1} \equiv t_{2} : A \qquad \Gamma \vdash t_{2} \equiv t_{3} : A}{\Gamma \vdash t_{1} \equiv t_{3} : A}
\frac{x : A \in \Gamma}{0 : A \uparrow \in \Gamma, A} \qquad \frac{x + 1 : A \uparrow \in \Gamma, B}{\vdash \Gamma \qquad x : A \in \Gamma \qquad \gamma(x) \leq p}{\gamma \blacktriangleright \Gamma \vdash x :^{p} A}
\frac{\gamma \blacktriangleright \Gamma \vdash A :^{p} \cup_{l}}{\gamma \blacktriangleright \Gamma \vdash ^{p} A} \qquad \frac{\Gamma \vdash A_{1} \equiv A_{2} : \cup_{l}}{\Gamma \vdash A_{1} \equiv A_{2}} \qquad \frac{\vdash \Gamma}{\gamma \blacktriangleright \Gamma \vdash \cup_{l} :^{p} \cup_{l+1}}
Rules for lift types. The type constructor $\text{Lift}_l_2$ lifts types in $\text{U}_{l_1}$ to $\text{U}_{l_1 \sqcup l_2}$, where $l_1 \sqcup l_2$ is the maximum of $l_1$ and $l_2$:\frac{\gamma\blacktriangleright\Gamma\vdash^{p}A}{\gamma\blacktriangleright\Gamma\vdash^{p}\operatorname{Lift}{l}A}\quad\frac{\Gamma\vdash A{1}\equiv A_{2}}{\Gamma\vdash\operatorname{Lift}{l}A{1}\equiv\operatorname{Lift}{l}A{2}}
\frac{\gamma\blacktriangleright\Gamma\vdash A:p\cup l_{1}}{\gamma\blacktriangleright\Gamma\vdash\operatorname{Lift}{l{2}}A:p\cup l_{1}\sqcup l_{2}}\quad\frac{\Gamma\vdash A_{1}\equiv A_{2}:\cup l_{1}}{\Gamma\vdash\operatorname{Lift}{l{2}}A_{1}\equiv\operatorname{Lift}{l{2}}A_{2}:\cup_{l_{1}\sqcup l_{2}}}
\frac{\gamma\blacktriangleright\Gamma\vdash t:p\operatorname{Lift}{l}A}{\gamma\blacktriangleright\Gamma\vdash\operatorname{lower}t:p A}\quad\frac{\Gamma\vdash t{1}\equiv t_{2}:\operatorname{Lift}{l}A}{\Gamma\vdash\operatorname{lower}t{1}\equiv\operatorname{lower}t_{2}:A}\quad\frac{\Gamma\vdash t:A}{\Gamma\vdash\operatorname{lower}(\operatorname{lift}t)\equiv t:A}
\frac{\Gamma\vdash t_{1}:\operatorname{Lift}{l}A}{\Gamma\vdash t{1}\equiv t_{2}:A}\quad\frac{\Gamma\vdash t_{2}:\operatorname{Lift}{l}A}{\Gamma\vdash\operatorname{lower}t{1}\equiv\operatorname{lower}t_{2}:A}
Rules for the empty type. An application of $\text{emptyrec}_p$ is an erased match if $p$ is 0 and the mode is $\omega$:\begin{array}{r l r}{\frac{\vdash\Gamma}{\gamma\blacktriangleright\Gamma\vdash\bot:p\cup_{0}}}&{{}}&{\frac{\mathrm{e m p t y r e c}{p}\mathrm{i sa l l o w e dw h e nt h em o d ei s~}q}{\Gamma\vdash A\qquad\gamma\blacktriangleright\Gamma\vdash t:^{q p}\bot}}\ &{{}}&{\frac{\gamma\blacktriangleright\Gamma\vdash\mathrm{e m p t y r e c}{p}A t:^{q}A}{\Gamma\vdash t_{1}:\mathrm{L i f t}_{l}A}}\end{array}
\frac{\Gamma\vdash A_{1}\equiv A_{2}\qquad\Gamma\vdash t_{1}\equiv t_{2}:\bot}{\Gamma\vdash\operatorname{emptyrec}{p}A{1}t_{1}\equiv\operatorname{emptyrec}{p}A{2}t_{2}:A_{1}}
Rules for unit types. An application of unitrec $_{p}$ is an erased match if p is 0 and the mode is $\omega$. The parameter s is a strength: s (“strong”) for the unit type with $\eta$-equality, and w (“weak”) for the unit type without $\eta$-equality:\frac{\vdash\Gamma}{\gamma\blacktriangleright\Gamma\vdash\top_{s}:^{p}\cup_{0}}\quad\frac{\vdash\Gamma}{\gamma\blacktriangleright\Gamma\vdash\star_{s}:^{p}\top_{s}}\quad\frac{\Gamma\vdash t_{1}:\top_{s}\quad\Gamma\vdash t_{2}:\top_{s}}{\Gamma\vdash t_{1}\equiv t_{2}:\top_{s}}
\begin{aligned}unitrec_{p}is allowed when the mode is q\\frac{\Gamma,\top_{\mathbf{w}}\vdash A\qquad\gamma\blacktriangleright\Gamma\vdash t:^{qp}\top_{\mathbf{w}}\qquad\gamma\blacktriangleright\Gamma\vdash u:^{q}A[\star_{\mathbf{w}}/0]}{\gamma\blacktriangleright\Gamma\vdash unitrec_{p}At u:^{q}A[t/0]}\end{aligned}
\frac{\Gamma,\top_{\mathbf{w}}\vdash A_{1}\equiv A_{2}\qquad\Gamma\vdash t_{1}\equiv t_{2}:\top_{\mathbf{w}}\qquad\Gamma\vdash u_{1}\equiv u_{2}:A_{1}[\star_{\mathbf{w}}/0]}{\Gamma\vdash unitrec_{p}A_{1}t_{1}u_{1}\equiv unitrec_{p}A_{2}t_{2}u_{2}:A_{1}[t_{1}/0]}
\frac{\Gamma,\top_{\mathbf{w}}\vdash A\qquad\Gamma\vdash t:A[\star_{\mathbf{w}}/0]}{\Gamma\vdash unitrec_{p}A\star_{\mathbf{w}}t\equiv t:A[\star_{\mathbf{w}}/0]}
Rules for $\Pi$-types:\frac{\gamma\blacktriangleright\Gamma\vdash^{qp}A\qquad\gamma,p\blacktriangleright\Gamma,A\vdash^{q}B}{\gamma\blacktriangleright\Gamma\vdash^{q}\Pi_{p}AB}
\frac{\Gamma\vdash A_{1}\equiv A_{2}\qquad\Gamma,A_{1}\vdash B_{1}\equiv B_{2}}{\Gamma\vdash\Pi_{p}A_{1}B_{1}\equiv\Pi_{p}A_{2}B_{2}}
\begin{aligned}\frac{\gamma\blacktriangleright\Gamma\vdash A:^{qp}\cup_{l}\quad\gamma,p\blacktriangleright\Gamma,A\vdash B:^{q}\cup_{l}}{\gamma\blacktriangleright\Gamma\vdash\Pi_{p}AB:^{q}\cup_{l}}&\quad\frac{\Gamma\vdash A_{1}\equiv A_{2}:\cup_{l}\quad\Gamma,A_{1}\vdash B_{1}\equiv B_{2}:\cup_{l}}{\Gamma\vdash\Pi_{p}A_{1}B_{1}\equiv\Pi_{p}A_{2}B_{2}:\cup_{l}}\ \frac{\gamma,p\blacktriangleright\Gamma,A\vdash t:^{q}B}{\gamma\blacktriangleright\Gamma\vdash\lambda^{p}t:^{q}\Pi_{p}AB}&\quad\frac{\gamma\blacktriangleright\Gamma\vdash t:^{q}\Pi_{p}AB\quad\gamma\blacktriangleright\Gamma\vdash u:^{qp}A}{\gamma\blacktriangleright\Gamma\vdash t^{p}u:^{q}B[u/0]}\ \frac{\Gamma\vdash t_{1}\equiv t_{2}:\Pi_{p}AB\quad\Gamma\vdash u_{1}\equiv u_{2}:A}{\Gamma\vdash t_{1}^{p}u_{1}\equiv t_{2}^{p}u_{2}:B[u_{1}/0]}&\quad\frac{\Gamma,A\vdash t:B\quad\Gamma\vdash u:A}{\Gamma\vdash(\lambda^{p}t)^{p}u\equiv t[u/0]:B[u/0]}\ \frac{\Gamma\vdash t_{1}:\Pi_{p}AB\quad\Gamma\vdash t_{2}:\Pi_{p}AB\quad\Gamma,A\vdash(t_{1}\uparrow)^{p}0\equiv(t_{2}\uparrow)^{p}0:B}{\Gamma\vdash t_{1}\equiv t_{2}:\Pi_{p}AB}&\end{aligned}
Rules for graded $\Sigma$-types. The first component of a value of type $\Sigma_{s,p} A B$ is erased if p is 0. An application of prodrec $_{p,q}$ is an erased match if q is 0 and the mode is $\omega$. Note that $fst_p$ can only be used if $p \leq q$, where q is the mode – erased first components can only be accessed in erased contexts:\begin{aligned}\frac{\gamma\blacktriangleright\Gamma\vdash^{qp}A\quad\gamma,p\blacktriangleright\Gamma,A\vdash^{q}B}{\gamma\blacktriangleright\Gamma\vdash^{q}\Sigma_{s,p}AB}&\quad\frac{\Gamma\vdash A_{1}\equiv A_{2}\quad\Gamma,A_{1}\vdash B_{1}\equiv B_{2}}{\Gamma\vdash\Sigma_{s,p}A_{1}B_{1}\equiv\Sigma_{s,p}A_{2}B_{2}}\ \frac{\gamma\blacktriangleright\Gamma\vdash A:^{qp}\cup_{l}\quad\gamma,p\blacktriangleright\Gamma,A\vdash B:^{q}\cup_{l}}{\gamma\blacktriangleright\Gamma\vdash\Sigma_{s,p}AB:^{q}\cup_{l}}&\quad\frac{\Gamma\vdash A_{1}\equiv A_{2}:\cup_{l}\quad\Gamma,A_{1}\vdash B_{1}\equiv B_{2}:\cup_{l}}{\Gamma\vdash\Sigma_{s,p}A_{1}B_{1}\equiv\Sigma_{s,p}A_{2}B_{2}:\cup_{l}}\ \frac{\gamma\blacktriangleright\Gamma\vdash t:^{qp}A\quad\gamma\blacktriangleright\Gamma\vdash u:^{q}B[t/0]}{\gamma\blacktriangleright\Gamma\vdash(t,u){s,p}:^{q}\Sigma{s,p}AB}&\quad\frac{\Gamma,A\vdash B}{\Gamma\vdash t_{1}\equiv t_{2}:A\quad\Gamma\vdash u_{1}\equiv u_{2}:B[t_{1}/0]}\ \frac{\Gamma\vdash(t_{1},u_{1}){s,p}\equiv(t{2},u_{2}){s,p}:\Sigma{s,p}AB}\end{aligned}
\begin{aligned}\frac{\gamma\blacktriangleright\Gamma\vdash t:^{q}\Sigma_{\mathbf{s},p}AB\quad p\leq q}{\gamma\blacktriangleright\Gamma\vdash\mathrm{fst}{p}t:^{q}A}&\quad\frac{\Gamma\vdash t{1}\equiv t_{2}:\Sigma_{\mathbf{s},p}AB}{\Gamma\vdash\mathrm{fst}{p}t{1}\equiv\mathrm{fst}{p}t{2}:A}&\quad\frac{\Gamma\vdash t:A\quad\Gamma\vdash u:B[t/0]}{\Gamma\vdash\mathrm{fst}{p}(t,u){\mathbf{s},p}\equiv t:A}\ &\frac{\gamma\blacktriangleright\Gamma\vdash t:^{q}\Sigma_{\mathbf{s},p}AB}{\gamma\blacktriangleright\Gamma\vdash\mathrm{snd}{p}t:^{q}B[\mathrm{fst}{p}t/0]}&\frac{\Gamma\vdash t_{1}\equiv t_{2}:\Sigma_{\mathbf{s},p}AB}{\Gamma\vdash\mathrm{snd}{p}t{1}\equiv\mathrm{snd}{p}t{2}:B[\mathrm{fst}{p}t{1}/0]}\ &\frac{\Gamma,A\vdash B}{\Gamma\vdash t:A\quad\Gamma\vdash u:B[t/0]}&\frac{\Gamma\vdash t_{1}:\Sigma_{\mathbf{s},p}AB\quad\Gamma\vdash t_{2}:\Sigma_{\mathbf{s},p}AB}{\Gamma\vdash\mathrm{fst}{p}t{1}\equiv\mathrm{fst}{p}t{2}:A}\ &\frac{\Gamma\vdash\mathrm{snd}{p}(t,u){\mathbf{s},p}\equiv u:B[t/0]}&\frac{\Gamma\vdash t_{1}\equiv t_{2}:\Sigma_{\mathbf{s},p}AB}{\Gamma\vdash t_{1}\equiv t_{2}:\Sigma_{\mathbf{s},p}AB}\end{aligned}
\begin{aligned}prodrec_{p,q}isallowedwhenthemodeisr\quad\Gamma,\Sigma_{\mathbf{w},p}AB\vdash C\\frac{\gamma\blacktriangleright\Gamma\vdash t:^{rq}\Sigma_{\mathbf{w},p}AB\quad\gamma,qp,q\blacktriangleright\Gamma,A,B\vdash u:^{r}C[id\uparrow^{2},(1,0){\mathbf{w},p}/0]}{\gamma\blacktriangleright\Gamma\vdash prodrec{p,q}Ctu:^{r}C[t/0]}\end{aligned}
\begin{aligned}\frac{\Gamma,\Sigma_{\mathbf{w},p}A B\vdash C_{1}\equiv C_{2}\qquad\Gamma\vdash t_{1}\equiv t_{2}:\Sigma_{\mathbf{w},p}A B\qquad\Gamma,A,B\vdash u_{1}\equiv u_{2}:C_{1}[\mathsf{id}\uparrow^{2},(1,0){\mathbf{w},p}/0]}{\Gamma\vdash\mathsf{prodrec}{p,q}C_{1}t_{1}u_{1}\equiv\mathsf{prodrec}{p,q}C{2}t_{2}u_{2}:C_{1}[t_{1}/0]}\ \frac{\Gamma,\Sigma_{\mathbf{w},p}A B\vdash C\qquad\Gamma\vdash t:A\qquad\Gamma\vdash u:B[t/0]\qquad\Gamma,A,B\vdash v:C[\mathsf{id}\uparrow^{2},(1,0){\mathbf{w},p}/0]}{\Gamma\vdash\mathsf{prodrec}{p,q}C(t,u){\mathbf{w},p}v\equiv v[t/1,u/0]:C[(t,u){\mathbf{w},p}/0]}\end{aligned}
One can use unit types and graded $\Sigma$-types to encode Erased. Erased and the box constructor, which are used in the typing rules for []-cong below, are encoded in the following way:\begin{array}{r l}{\mathrm{E r a s e d}{s,l}A=\Sigma{s,0}A\left(\mathsf{L i f t}{\top}s\right)}\ {[t]{\mathsf{s}}}&{=(t,\mathsf{l i f t}\star_{s})_{s,0}}\end{array}
Note that the first component of the $\Sigma$-type is erased. Unlike in the main body of the text the encoding is parametrised by a strength, so that one can choose whether or not to allow $\eta$-equality for Erased. (Note that $\eta$-equality is always allowed for lift types.) Rules for natural numbers:\begin{array}{ccc}\frac{\vdash\Gamma}{\gamma\triangleright\Gamma\vdash\mathsf{Nat}:^{p}\mathsf{U}_{0}}&\frac{\vdash\Gamma}{\gamma\triangleright\Gamma\vdash\mathsf{zero}:^{p}\mathsf{Nat}}&\frac{\gamma\triangleright\Gamma\vdash t:^{p}\mathsf{Nat}}{\gamma\triangleright\Gamma\vdash\mathsf{suc}t:^{p}\mathsf{Nat}}\end{array}
\frac{\Gamma\vdash t_{1}\equiv t_{2}:\mathsf{Nat}}{\Gamma\vdash\mathsf{suc}t_{1}\equiv\mathsf{suc}t_{2}:\mathsf{Nat}}\quad\frac{\begin{array}{c}\Gamma,\mathsf{Nat}\vdash A\quad\gamma\triangleright\Gamma\vdash t:^{r}A[\mathsf{zero}/0]\ \gamma,p,q\triangleright\Gamma,\mathsf{Nat},A\vdash u:^{r}A[\mathsf{id}\uparrow^{2},\mathsf{suc}1/0]\quad\gamma\triangleright\Gamma\vdash v:^{r}\mathsf{Nat}\end{array}}{\gamma\triangleright\Gamma\vdash\mathsf{natrec}_{p,q}Atu v:^{r}A[\nu/0]}
\begin{aligned}&\frac{\Gamma,\mathsf{Nat}\vdash A_{1}\equiv A_{2}\qquad\Gamma\vdash t_{1}\equiv t_{2}:A_{1}[\mathsf{zero}/0]}{\Gamma,\mathsf{Nat},A_{1}\vdash u_{1}\equiv u_{2}:A_{1}[\mathsf{id}\uparrow^{2},\mathsf{suc}1/0]}\quad\Gamma\vdash v_{1}\equiv v_{2}:\mathsf{Nat}\&\frac{\Gamma\vdash\mathsf{natrec}{p,q}A{1}t_{1}u_{1}v_{1}\equiv\mathsf{natrec}{p,q}A{2}t_{2}u_{2}v_{2}:A_{1}[v_{1}/0]}{\end{aligned}
\frac{\Gamma\vdash t:A[\mathsf{zero}/0]\qquad\Gamma,\mathsf{Nat},A\vdash u:A[\mathsf{id}\uparrow^{2},\mathsf{suc}1/0]}{\Gamma\vdash\mathsf{natrec}_{p,q}Atu\mathsf{zero}\equiv t:A[\mathsf{zero}/0]}
\frac{\Gamma\vdash t:A[\mathsf{zero}/0]\qquad\Gamma,\mathsf{Nat},A\vdash u:A[\mathsf{id}\uparrow^{2},\mathsf{suc}1/0]\qquad\Gamma\vdash v:\mathsf{Nat}}{\Gamma\vdash\mathsf{natrec}{p,q}Atu(\mathsf{suc}v)\equiv u[v/1,\mathsf{natrec}{p,q}Atu v/0]:A[\mathsf{suc}v/0]}
\begin{aligned}&\frac{\begin{array}{c}\mathsf{Id}1\\gamma\triangleright\Gamma\vdash t:^{p}A\\end{array}\quad\gamma\triangleright\Gamma\vdash u:^{p}A}{\gamma\triangleright\Gamma\vdash^{p}\mathsf{Id}Atu}\quad&\frac{\begin{array}{c}\mathsf{Id}1\\gamma\triangleright\Gamma\vdash t:^{p}A\\end{array}\quad\gamma\triangleright\Gamma\vdash u:^{p}A}{\gamma\triangleright\Gamma\vdash\mathsf{Id}Atu:^{p}\mathsf{U}{l}}\&\frac{\begin{array}{c}\mathsf{Id}2\\Gamma\vdash t:A\\end{array}\quad\Gamma\vdash u:A}{\gamma\triangleright\Gamma\vdash^{p}\mathsf{Id}Atu}\quad&\frac{\begin{array}{c}\mathsf{Id}2\\Gamma\vdash A:\mathsf{U}{l}\\end{array}}{\begin{array}{c}\Gamma\vdash t:A\\end{array}\quad\Gamma\vdash u:A}\&\frac{\gamma\triangleright\Gamma\vdash^{p}\mathsf{Id}Atu}{\gamma\triangleright\Gamma\vdash\mathsf{Id}Atu:^{p}\mathsf{U}_{l}}\end{aligned}
\begin{aligned}\frac{\Gamma\vdash A_{1}\equiv A_{2}}{\Gamma\vdash t_{1}\equiv t_{2}:A_{1}\qquad\Gamma\vdash u_{1}\equiv u_{2}:A_{1}}&\quad\frac{\Gamma\vdash A_{1}\equiv A_{2}:\mathsf{U}{l}}{\Gamma\vdash t{1}\equiv t_{2}:A_{1}\qquad\Gamma\vdash u_{1}\equiv u_{2}:A_{1}}\ \Gamma\vdash\mathsf{ld}A_{1}t_{1}u_{1}\equiv\mathsf{ld}A_{2}t_{2}u_{2}&\quad\Gamma\vdash\mathsf{ld}A_{1}t_{1}u_{1}\equiv\mathsf{ld}A_{2}t_{2}u_{2}:\mathsf{U}_{l}\end{aligned}
\frac{\Gamma\vdash t:A}{\gamma\blacktriangleright\Gamma\vdash\mathsf{refl}:^{p}\mathsf{ld}Att}
\begin{aligned}&\frac{\mathsf{J}1\text{or,if}p\text{or}q\text{is}\omega,\mathsf{J}2\quad\Gamma\vdash A\quad\gamma\blacktriangleright\Gamma\vdash t:\omega A\quad\gamma,p,q\blacktriangleright\Gamma,A,\mathsf{ld}\left(A\uparrow\right)\left(t\uparrow\right)0\vdash^{\omega}B}{\gamma\blacktriangleright\Gamma\vdash u:\omega B[t/1,\mathsf{refl}/0]\quad\gamma\blacktriangleright\Gamma\vdash v:\omega A\quad\gamma\blacktriangleright\Gamma\vdash w:\omega\mathsf{ld}Atv}\ &\quad\gamma\blacktriangleright\Gamma\vdash\mathsf{J}_{p,q}AtBuvv:\omega B[v/1,w/0]\ \end{aligned}
\begin{aligned}&\mathsf{J}2\quad\Gamma\vdash A\quad\Gamma\vdash t:A\quad\gamma,0,0\blacktriangleright\Gamma,A,\mathsf{ld}\left(A\uparrow\right)\left(t\uparrow\right)0\vdash^{\omega}B\&\quad\gamma\blacktriangleright\Gamma\vdash u:\omega B[t/1,\mathsf{refl}/0]\quad\Gamma\vdash v:A\quad\Gamma\vdash w:\mathsf{ld}Atv\&\quad\gamma\blacktriangleright\Gamma\vdash\mathsf{J}_{0,0}AtBuvv:\omega B[v/1,w/0]\ \end{aligned}
\begin{aligned}&If r=\omega,\mathsf{J}3\quad\Gamma\vdash A\quad\Gamma\vdash t:A\quad\Gamma,A,\mathsf{ld}\left(A\uparrow\right)\left(t\uparrow\right)0\vdash B\&\quad\gamma\blacktriangleright\Gamma\vdash u:\mathcal{r}B[t/1,\mathsf{refl}/0]\quad\Gamma\vdash v:A\quad\Gamma\vdash w:\mathsf{ld}Atv\&\quad\gamma\blacktriangleright\Gamma\vdash\mathsf{J}_{p,q}AtBuvv:\mathcal{r}B[v/1,w/0]\end{aligned}
\begin{aligned}&\Gamma\vdash A_{1}\equiv A_{2}\quad\Gamma\vdash t_{1}\equiv t_{2}:A_{1}\quad\Gamma,A_{1},\mathsf{ld}\left(A_{1}\uparrow\right)\left(t_{1}\uparrow\right)0\vdash B_{1}\equiv B_{2}\&\Gamma\vdash u_{1}\equiv u_{2}:B_{1}[t_{1}/1,\mathsf{refl}/0]\quad\Gamma\vdash v_{1}\equiv v_{2}:A_{1}\quad\Gamma\vdash w_{1}\equiv w_{2}:\mathsf{ld}A_{1}t_{1}v_{1}\&\quad\Gamma\vdash\mathsf{J}{p,q}A{1}t_{1}B_{1}u_{1}v_{1}w_{1}\equiv\mathsf{J}{p,q}A{2}t_{2}B_{2}u_{2}v_{2}w_{2}:B_{1}[v_{1}/1,w_{1}/0]\ \end{aligned}
\frac{\Gamma\vdash t:A\qquad\Gamma,A,\mathsf{ld}\left(A\uparrow\right)\left(t\uparrow\right)0\vdash B\qquad\Gamma\vdash u:B[t/1,\mathsf{refl}/0]}{\Gamma\vdash\mathsf{J}_{p,q}AtBut\mathsf{refl}\equiv u:B[t/1,\mathsf{refl}/0]}
\begin{aligned}&K is~allowed\quad K1or,if p is\omega,K2\quad\Gamma\vdash A\quad\gamma\blacktriangleright\Gamma\vdash t:\omega A\&\gamma,p\blacktriangleright\Gamma,\mathsf{ld}Att\vdash^{\omega}B\quad\gamma\blacktriangleright\Gamma\vdash u:\omega B[\mathsf{refl}/0]\quad\gamma\blacktriangleright\Gamma\vdash v:\omega\mathsf{ld}Att\&\quad\gamma\blacktriangleright\Gamma\vdash K_{p}AtBu v:\omega B[v/0]\ \end{aligned}
\begin{aligned}&K is~allowed\quad K2\quad\Gamma\vdash A\quad\Gamma\vdash t:A\&\gamma,0\blacktriangleright\Gamma,\mathsf{ld}Att\vdash^{\omega}B\quad\gamma\blacktriangleright\Gamma\vdash u:\omega B[\mathsf{refl}/0]\quad\Gamma\vdash v:\mathsf{ld}Att\&\quad\gamma\blacktriangleright\Gamma\vdash K_{0}AtBu v:\omega B[v/0]\ \end{aligned}
\begin{aligned}&K is~allowed\quad If q=\omega,K3\quad\Gamma\vdash A\quad\Gamma\vdash t:A\&\Gamma,\mathsf{ld}Att\vdash B\quad\gamma\blacktriangleright\Gamma\vdash u:\mathcal{q}B[\mathsf{refl}/0]\quad\Gamma\vdash v:\mathsf{ld}Att\&\quad\gamma\blacktriangleright\Gamma\vdash K_{p}AtBu v:\mathcal{q}B[v/0]\ \end{aligned}
\begin{aligned}&K is~allowed\quad\Gamma\vdash A_{1}\equiv A_{2}\quad\Gamma\vdash t_{1}\equiv t_{2}:A_{1}\&\Gamma,\mathsf{ld}A_{1}t_{1}t_{1}\vdash B_{1}\equiv B_{2}\quad\Gamma\vdash u_{1}\equiv u_{2}:B_{1}[\mathsf{refl}/0]\quad\Gamma\vdash v_{1}\equiv v_{2}:\mathsf{ld}A_{1}t_{1}t_{1}\&\quad\Gamma\vdash K_{p}A_{1}t_{1}B_{1}u_{1}v_{1}\equiv K_{p}A_{2}t_{2}B_{2}u_{2}v_{2}:B_{1}[v_{1}/0]\ \end{aligned}
\frac{\mathrm{Kisallowed}\quad\Gamma,\mathrm{ld};Att\vdash B\quad\Gamma\vdash u:B[\mathrm{refl}/0]}{\Gamma\vdash\mathrm{K}_{p}AtBu\mathrm{refl}\equiv u:B[\mathrm{refl}/0]}
\frac{[\mathrm{-cong}{s}\mathrm{isallowed}\quad\Gamma\vdash A\quad\Gamma\vdash t:A\quad\Gamma\vdash u:A\quad\Gamma\vdash v:\mathrm{ld}Atu}{\gamma\triangleright\Gamma\vdash[\mathrm{-cong}{s,l}Atuv:p\mathrm{ld}(\mathrm{E r a s e d}{s,l}A)[t]{s}[u]_{s}}
\frac{[\mathrm{-cong}{s}\mathrm{isallowed}}{\Gamma\vdash A{1}\equiv A_{2}\qquad\Gamma\vdash t_{1}\equiv t_{2}:A_{1}\qquad\Gamma\vdash u_{1}\equiv u_{2}:A_{1}\qquad\Gamma\vdash v_{1}\equiv v_{2}:\mathrm{ld}A_{1}t_{1}u_{1}}
\Gamma\vdash[\mathrm{-cong}{s,l}A{1}t_{1}u_{1}v_{1}\equiv[\mathrm{-cong}{s,l}A{2}t_{2}u_{2}v_{2}:\mathrm{ld}(\mathrm{E r a s e d}{s,l}A{1})[t_{1}]{s}[u{1}]_{s}
\begin{array}{r l r}{\frac{[\mathrm{-c o n g}{s}\mathrm{i sa l l o w e d}}{\Gamma\vdash[\mathrm{-c o n g}{s,l}A t t\mathrm{r e f l}\equiv\mathrm{r e f l}:\mathrm{l d}(\mathrm{E r a s e d}{s,l}A)[t]{s}[t]_{s}}}&{{}}&{\mathrm{E q u a l i t yr e f l e c t i o ni s~a l l o w e d}}\ &{{}}&{\frac{\Gamma\vdash v:\mathrm{l d}A t u}{\Gamma\vdash t\equiv u:A}}\end{array}
\begin{array}{r l}&{\mathrm{l d}\left(C[\mathrm{i d}\uparrow^{3},1/0]\right)}\ &{\quad(\mathrm{J}{\omega,0}\left((A/B)\uparrow^{3}\right)(\mathrm{c l a s s}2)\left((C[\mathrm{i d}\uparrow^{4},0/0]\right)\uparrow)\left(t\uparrow^{2}\right)(\mathrm{c l a s s}1)(\mathrm{r e s p}\left(A\uparrow^{3}\right)(B\uparrow{2}^{3})210))}\ &{\quad(t[\mathrm{i d}\uparrow^{3},1/0])}\end{array}
\begin{array}{r l r}{\frac{\mathrm{Q u o t i e n tt y p e sa r ea l l o w e d}}{\gamma\blacktriangleright\Gamma\vdash^{p}A\quad\Gamma,A,A\uparrow\vdash B}}&{}&{\mathrm{Q u o t i e n tt y p e sa r ea l l o w e d}}\ &{}&{\frac{\gamma\blacktriangleright\Gamma\vdash A:B\cup_{l}\quad\Gamma,A,A\uparrow\vdash B:\cup_{l}}{\gamma\blacktriangleright\Gamma\vdash A/B:p\cup_{l}}}\end{array}
\begin{array}{r l r}{\frac{\mathrm{Q u o t i e n tt y p e sa r ea l l o w e d}}{\Gamma\vdash A_{1}\equiv A_{2}\quad\Gamma,A_{1},A_{1}\uparrow\vdash B_{1}\equiv B_{2}}}&{}&{\frac{\mathrm{Q u o t i e n tt y p e sa r ea l l o w e d}}{\Gamma\vdash A_{1}/B_{1}\equiv A_{2}/B_{2}}}\end{array}
\begin{array}{r l r}{\frac{\mathrm{Q u o t i e n tt y p e sa r e~a l l o w e d}}{\Gamma\vdash A/B\quad\gamma\blacktriangleright\Gamma\vdash t:p A}}&{}&{\frac{\Gamma\vdash A/B\quad\Gamma\vdash t_{1}\equiv t_{2}:A}{\Gamma\vdash\mathrm{c l a s s}t_{1}\equiv\mathrm{c l a s s}t_{2}:A/B}}\end{array}
\frac{\Gamma\vdash A/B\qquad\Gamma\vdash t:A\qquad\Gamma\vdash u:A\qquad\Gamma\vdash v:B[t/1,u/0]}{\gamma\blacktriangleright\Gamma\vdash\operatorname{resp}A B t u v:^{0}\operatorname{ld}(A/B)(\operatorname{class}t)(\operatorname{class}u)}
\begin{array}{r l r}{\frac{\mathrm{Q u o t i e n tt y p e sa r e~a l l o w e d}}{\Gamma\vdash t_{1}\equiv t_{2}:A_{1}\quad\Gamma\vdash u_{1}\equiv u_{2}:A_{1}\quad\Gamma\vdash v_{1}\equiv v_{2}:B_{1}[t_{1}/1,u_{1}/0]}}&{}&{}\ {\frac{\Gamma\vdash\operatorname{r e s p}A_{1}B_{1}t_{1}u_{1}v_{1}\equiv\operatorname{r e s p}A_{2}B_{2}t_{2}u_{2}v_{2}:\operatorname{l d}\left(A_{1}/B_{1}\right)(\operatorname{c l a s s}t_{1})(\operatorname{c l a s s}u_{1})}{}}&{}&{}\end{array}
\begin{array}{r l r l r l r}{\Gamma\vdash A/B}&{\quad\Gamma\vdash t:A/B}&{\quad\Gamma\vdash u:A/B}&{\quad\Gamma\vdash v:\mathrm{l d}\left(A/B\right)t u}&{\quad\Gamma\vdash w:\mathrm{l d}\left(A/B\right)t u}&{}\ &{}&{}&{}&{}&{}\ &{}&{\gamma\blacktriangleright\Gamma\vdash\mathrm{s e t}A B t u v w:^{0}\mathrm{l d}\left(\mathrm{l d}\left(A/B\right)t u\right)v w}&{}&{}&{}\end{array}
\begin{aligned}\Gamma\vdash A_{1}&\equiv A_{2}\quad\Gamma,A_{1},A_{1}\uparrow\vdash B_{1}\equiv B_{2}\quad\Gamma\vdash t_{1}\equiv t_{2}:A_{1}/B_{1}\\Gamma\vdash u_{1}&\equiv u_{2}:A_{1}/B_{1}\quad\Gamma\vdash v_{1}\equiv v_{2}:\operatorname{Id}\left(A_{1}/B_{1}\right)t_{1}u_{1}\quad\Gamma\vdash w_{1}\equiv w_{2}:\operatorname{Id}\left(A_{1}/B_{1}\right)t_{1}u_{1}\\frac{\Gamma\vdash\operatorname{set}A_{1}B_{1}t_{1}u_{1}v_{1}w_{1}\equiv\operatorname{set}A_{2}B_{2}t_{2}u_{2}v_{2}w_{2}:\operatorname{Id}\left(\operatorname{Id}\left(A_{1}/B_{1}\right)t_{1}u_{1}\right)v_{1}w_{1}}{}\ \text{Quotient types are allowed}&\quad\gamma,\omega\blacktriangleright\Gamma,A/B\vdash^{p}C\\gamma,\omega\blacktriangleright\Gamma,A\vdash t:^{p}C[\operatorname{id}\uparrow,\operatorname{class}0/0]&\quad\Gamma,A,A\uparrow,B\vdash u:\operatorname{Resp-type}A B C t\\Gamma,A/B,C,C\uparrow,\operatorname{Id}\left(C\uparrow^{2}\right)10,\operatorname{Id}\left(C\uparrow^{3}\right)21\vdash v:\operatorname{Id}\left(\operatorname{Id}\left(C\uparrow^{4}\right)32\right)10&\quad\gamma\blacktriangleright\Gamma\vdash w:^{p}A/B\\frac{\gamma\blacktriangleright\Gamma\vdash\operatorname{qrec}C t u v w:^{p}C[w/0]}{}\\frac{\Gamma,A/B\vdash C_{1}\equiv C_{2}}{\Gamma,A\vdash t_{1}\equiv t_{2}:C_{1}[\operatorname{id}\uparrow,\operatorname{class}0/0]&\quad\Gamma,A,A\uparrow,B\vdash u_{1}\equiv u_{2}:\operatorname{Resp-type}A B C_{1}t_{1}\\Gamma,A/B,C_{1},C_{1}\uparrow,\operatorname{Id}\left(C_{1}\uparrow^{2}\right)10,\operatorname{Id}\left(C_{1}\uparrow^{3}\right)21\vdash v_{1}\equiv v_{2}:\operatorname{Id}\left(\operatorname{Id}\left(C_{1}\uparrow^{4}\right)32\right)10&\\frac{\Gamma\vdash w_{1}\equiv w_{2}:A/B}{\Gamma\vdash\operatorname{qrec}C_{1}t_{1}u_{1}v_{1}w_{1}\equiv\operatorname{qrec}C_{2}t_{2}u_{2}v_{2}w_{2}:C_{1}[w_{1}/0]}\\frac{\Gamma,A/B\vdash C}{\Gamma,A\vdash t:C[\operatorname{id}\uparrow,\operatorname{class}0/0]&\quad\Gamma,A,A\uparrow,B\vdash u:\operatorname{Resp-type}A B C t\\Gamma,A/B,C,C\uparrow,\operatorname{Id}\left(C\uparrow^{2}\right)10,\operatorname{Id}\left(C\uparrow^{3}\right)21\vdash v:\operatorname{Id}\left(\operatorname{Id}\left(C\uparrow^{4}\right)32\right)10&\quad\Gamma\vdash w:A\\frac{\Gamma\vdash\operatorname{qrec}C t u v(\operatorname{class}w)\equiv t[w/0]:C[\operatorname{class}w/0]}{}\\end{aligned}
### A.2 Substitutions The definition of parallel substitutions and the function applying a substitution to a term are not included here, but the following relation for well-formed substitutions is:\begin{array}{r l}{\frac{\vdash\Delta}{\delta\blacktriangleright\Delta\vdash\sigma:^{p}\varepsilon}}&{{}\frac{\delta\blacktriangleright\Delta\vdash t a i l\sigma:^{p}\Gamma\qquad\delta\blacktriangleright\Delta\vdash h e a d\sigma:^{p}A(t a i l\sigma)}{\delta\blacktriangleright\Delta\vdash\sigma:^{p}\Gamma,A}}\end{array}
For a substitution $\sigma$ from a non-empty context head $\sigma$ refers to the last term in the substitution, and tail $\sigma$ refers to the rest of the substitution. ### A.3 Reduction Single-step reduction for terms. Note that the $\beta$-rules for J and []-cong have assumptions that are judgemental equalities:\begin{aligned}\frac{\Gamma\vdash t\Rightarrow u:A\qquad\Gamma\vdash A\equiv B}{\Gamma\vdash t\Rightarrow u:B}\quad&\frac{\Gamma\vdash t_{1}\Rightarrow t_{2}:\operatorname{Lift}{l}A}{\Gamma\vdash lower t{1}\Rightarrow lower t_{2}:A}\quad&\frac{\Gamma\vdash A\qquad\Gamma\vdash t:A}{\Gamma\vdash lower\left(lift t\right)\Rightarrow t:A}\end{aligned}
\begin{aligned}\frac{\Gamma\vdash A\qquad\Gamma\vdash t_{1}\Rightarrow t_{2}:\bot}{\Gamma\vdash emptyrec_{p}A t_{1}\Rightarrow emptyrec_{p}A t_{2}:A}\quad&\frac{\Gamma,\tau_{\mathbf{w}}\vdash A\qquad\Gamma\vdash t_{1}\Rightarrow t_{2}:\tau_{\mathbf{w}}}{\Gamma\vdash u:A[\star_{\mathbf{w}}/0]}\ \frac{\Gamma\vdash unitrec_{p}A t_{1}u\Rightarrow unitrec_{p}A t_{2}u:A[t_{1}/0]}{\Gamma\vdash t_{1}\Rightarrow t_{2}:\Pi_{p}A B\qquad\Gamma\vdash u:A}\ \frac{\Gamma\vdash unitrec_{p}A\star_{\mathbf{w}}t\Rightarrow t:A[\star_{\mathbf{w}}/0]}{\Gamma\vdash t_{1}p u\Rightarrow t_{2}p u:B[u/0]}\end{aligned}
\frac{\begin{array}{c}\Gamma,A\vdash B\\Gamma,A\vdash t:B\quad\Gamma\vdash u:A\end{array}}{\Gamma\vdash(\lambda^{p}t)^{p}u\Rightarrow t[u/0]:B[u/0]}\quad\frac{\begin{array}{c}\Gamma,A\vdash B\\Gamma\vdash t_{1}\Rightarrow t_{2}:\Sigma_{\mathbf{s},p}A B\end{array}}{\Gamma\vdash\mathrm{fst}{p}t{1}\Rightarrow\mathrm{fst}{p}t{2}:A}
\frac{\begin{array}{c}\Gamma,A\vdash B\\Gamma\vdash t:A\quad\Gamma\vdash u:B[t/0]\end{array}}{\Gamma\vdash\mathrm{fst}{p}(t,u){\mathbf{s},p}\Rightarrow t:A}\quad\frac{\begin{array}{c}\Gamma,A\vdash B\\Gamma\vdash t_{1}\Rightarrow t_{2}:\Sigma_{\mathbf{s},p}A B\end{array}}{\Gamma\vdash\mathrm{snd}{p}t{1}\Rightarrow\mathrm{snd}{p}t{2}:B[\mathrm{fst}{p}t{1}/0]}
\begin{aligned}\Gamma,A\vdash B\\frac{\Gamma\vdash t:A\quad\Gamma\vdash u:B[t/0]}{\Gamma\vdash\mathrm{snd}{p}(t,u){\mathbf{s},p}\Rightarrow u:B[t/0]}\end{aligned}
\frac{\Gamma,\Sigma_{\mathbf{w},p}A B\vdash C\qquad\Gamma\vdash t_{1}\Rightarrow t_{2}:\Sigma_{\mathbf{w},p}A B\qquad\Gamma,A,B\vdash u:C[\mathrm{id}\uparrow^{2},(1,0){\mathbf{w},p}/0]}{\Gamma\vdash\mathrm{prodrec}{p,q}C t_{1}u\Rightarrow\mathrm{prodrec}{p,q}C t{2}u:C[t_{1}/0]}
\frac{\Gamma,\Sigma_{\mathbf{w},p}A B\vdash C\qquad\Gamma\vdash t:A\qquad\Gamma\vdash u:B[t/0]\qquad\Gamma,A,B\vdash v:C[\mathrm{id}\uparrow^{2},(1,0){\mathbf{w},p}/0]}{\Gamma\vdash\mathrm{prodrec}{p,q}C(t,u){\mathbf{w},p}v\Rightarrow v[t/1,u/0]:C[(t,u){\mathbf{w},p}/0]}
\begin{aligned}\frac{\Gamma\vdash t:A[zero/0]\quad\Gamma,Nat,A\vdash u:A[id\uparrow^{2},suc1/0]\quad\Gamma\vdash v_{1}\Rightarrow v_{2}:Nat}{\Gamma\vdash natrec_{p,q}Atu v_{1}\Rightarrow natrec_{p,q}Atu v_{2}:A[v_{1}/0]}\ \frac{\Gamma\vdash t:A[zero/0]\quad\Gamma,Nat,A\vdash u:A[id\uparrow^{2},suc1/0]}{\Gamma\vdash natrec_{p,q}Atu zero\Rightarrow t:A[zero/0]}\end{aligned}
\frac{\Gamma\vdash t:A[zero/0]\quad\Gamma,Nat,A\vdash u:A[id\uparrow^{2},suc1/0]\quad\Gamma\vdash v:Nat}{\Gamma\vdash natrec_{p,q}Atu(suc v)\Rightarrow u[v/1,natrec_{p,q}Atu v/0]:A[suc v/0]}
\begin{aligned}\frac{\Gamma\vdash t:A}{\Gamma,A,\mathrm{Id}(A\uparrow)(t\uparrow)0\vdash B}&\quad\Gamma\vdash u:B[t/1,\mathrm{refl}/0]\quad\Gamma\vdash v:A\quad\Gamma\vdash w_{1}\Rightarrow w_{2}:\mathrm{Id}At v\\frac{\Gamma\vdash\mathsf{J}{p,q}AtBu v w{1}\Rightarrow\mathsf{J}{p,q}AtBu v w{2}:B[v/1,w_{1}/0]}{\Gamma\vdash t_{1}:A\quad\Gamma\vdash t_{2}:A\quad\Gamma\vdash t_{1}\equiv t_{2}:A}\ \frac{\Gamma,A,\mathrm{Id}(A\uparrow)(t_{1}\uparrow)0\vdash B\quad\Gamma\vdash B[t_{1}/1,\mathrm{refl}/0]\equiv B[t_{2}/1,\mathrm{refl}/0]\quad\Gamma\vdash u:B[t_{1}/1,\mathrm{refl}/0]}{\Gamma\vdash\mathsf{J}{p,q}At t{1}Bu t_{2}\mathrm{refl}\Rightarrow u:B[t_{1}/1,\mathrm{refl}/0]}\end{aligned}
\begin{aligned}&\mathrm{Kisallowed}\quad\Gamma,\mathrm{Id}A t t\vdash B\&\frac{\Gamma\vdash u:B[\mathrm{refl}/0]}{\Gamma\vdash\mathrm{K}{p}A t B u v{1}\Rightarrow\mathrm{K}{p}A t B u v{2}:B[v_{1}/0]}\quad\frac{\mathrm{Kisallowed}\quad\Gamma,\mathrm{Id}A t t\vdash B}{\Gamma\vdash u:B[\mathrm{refl}/0]}\&\frac{\mathrm{Kisallowed}\quad\Gamma,\mathrm{Id}A t t\vdash B}{\Gamma\vdash\mathrm{K}_{p}A t B u\mathrm{refl}\Rightarrow u:B[\mathrm{refl}/0]}\end{aligned}
\begin{aligned}&\left[\right]-\mathrm{cong}{s}\mathrm{isallowed}\quad\Gamma\vdash v{1}\Rightarrow v_{2}:\mathrm{Id}At u\&\frac{\Gamma\vdash\left[\right]-\mathrm{cong}{s,l}At u v{1}\Rightarrow\left[\right]-\mathrm{cong}{s,l}At u v{2}:\mathrm{Id}\left(\mathrm{E r a s e d}{s,l}A\right)\left[t\right]{s}\left[u\right]_{s}}{\end{aligned}
\frac{[\rfloor\text{-cong}{s}\text{ is allowed}\qquad\Gamma\vdash t{1}\equiv t_{2}:A}{\Gamma\vdash[\rfloor\text{-cong}{s,l}A t{1}t_{2}\text{ refl}\Rightarrow\text{ refl}:\operatorname{Id}\left(\text{Erased}{s,l}A\right)[t{1}]{s}[t{2}]_{s}}
\begin{aligned}&Equalityreflectionisallowed\\frac{\Gamma\vdash A/B\qquad\Gamma\vdash t:A\qquad\Gamma\vdash u:A\qquad\Gamma\vdash v:B[t/1,u/0]}{\Gamma\vdash respA B t u v\Rightarrow refl:\operatorname{Id}\left(A/B\right)(class t)(class u)}\end{aligned}
\begin{aligned}&Equalityreflectionisallowed\\frac{\Gamma\vdash t:A/B\qquad\Gamma\vdash u:A/B\qquad\Gamma\vdash v:\operatorname{Id}\left(A/B\right)tu\qquad\Gamma\vdash w:\operatorname{Id}\left(A/B\right)tu}{\Gamma\vdash setA~B t u v w\Rightarrow refl:\operatorname{Id}\left(\operatorname{Id}\left(A/B\right)tu\right)v w}\end{aligned}
\begin{aligned}&\Gamma,A/B\vdash C\\frac{\Gamma,A\vdash t:C[\operatorname{id}\uparrow,\operatorname{class}0/0]\qquad\Gamma,A,A\uparrow,B\vdash u:\operatorname{Resp-type}A B C t}{\Gamma,A/B,C,C\uparrow,\operatorname{Id}\left(C\uparrow^{2}\right)10,\operatorname{Id}\left(C\uparrow^{3}\right)21\vdash v:\operatorname{Id}\left(\operatorname{Id}\left(C\uparrow^{4}\right)32\right)10\qquad\Gamma\vdash w_{1}\Rightarrow w_{2}:A/B}\&\frac{\Gamma\vdash\operatorname{qrec}C t u v w_{1}\Rightarrow\operatorname{qrec}C t u v w_{2}:C[w_{1}/0]}{\end{aligned}
\begin{aligned}&\Gamma,A/B\vdash C\\frac{\Gamma,A\vdash t:C[\operatorname{id}\uparrow,\operatorname{class}0/0]\qquad\Gamma,A,A\uparrow,B\vdash u:\operatorname{Resp-type}A B C t}{\Gamma,A/B,C,C\uparrow,\operatorname{Id}\left(C\uparrow^{2}\right)10,\operatorname{Id}\left(C\uparrow^{3}\right)21\vdash v:\operatorname{Id}\left(\operatorname{Id}\left(C\uparrow^{4}\right)32\right)10\qquad\Gamma\vdash w:A}\&\frac{\Gamma\vdash\operatorname{qrec}C t u v(\operatorname{class}w)\Rightarrow t[w/0]:C[\operatorname{class}w/0]}{\end{aligned}
\frac{\Gamma\vdash t:A}{\Gamma\vdash t\Rightarrow^{}t:A}\qquad\frac{\Gamma\vdash t\Rightarrow u:A\qquad\Gamma\vdash u\Rightarrow^{}v:A}{\Gamma\vdash t\Rightarrow^{*}v:A}
\frac{\Gamma\vdash A\Rightarrow B:\cup_{l}}{\Gamma\vdash A\Rightarrow B}
\frac{\Gamma\vdash A}{\Gamma\vdash A\Rightarrow^{}A}\qquad\frac{\Gamma\vdash A\Rightarrow B\qquad\Gamma\vdash B\Rightarrow^{}C}{\Gamma\vdash A\Rightarrow^{*}C}
\begin{aligned}&\frac{\Gamma\vdash t\Rightarrow u:\operatorname{Nat}}{\Gamma\vdash t\Rightarrow^{\operatorname{succ}}u:\operatorname{Nat}}&\frac{\Gamma\vdash t\Rightarrow^{\operatorname{succ}}u:\operatorname{Nat}}{\Gamma\vdash\operatorname{suct}\Rightarrow^{\operatorname{succ}}\operatorname{suc}u:\operatorname{Nat}}\end{aligned}
\begin{aligned}&\frac{\Gamma\vdash t:\operatorname{Nat}}{\Gamma\vdash t\Rightarrow^{\operatorname{succ}}t:\operatorname{Nat}}&\frac{\Gamma\vdash t\Rightarrow^{\operatorname{succ}}u:\operatorname{Nat}\qquad\Gamma\vdash u\Rightarrow^{\operatorname{succ}}v:\operatorname{Nat}}{\Gamma\vdash t\Rightarrow^{\operatorname{succ}*}v:\operatorname{Nat}}\end{aligned}
## B The Target Language This section contains more details about the target language and the extraction function presented in the main text. In addition to what is presented here the formalisation supports non-strict applications and top-level definitions. Syntax:\begin{array}{c} t,u,v::=\varnothing\mid\operatorname{var}x\mid\operatorname{star}\mid\operatorname{unitrec}t u\mid\operatorname{lam}t\mid\operatorname{app}t u\mid\operatorname{pair}t u\mid\operatorname{fst}t\mid\operatorname{snd}t\mid\operatorname{prodrec}t u\ \mid\operatorname{zero}\mid\operatorname{suct}\mid\operatorname{natrec}t u v\end{array}
The formalisation uses well-scoped syntax, but such details have been omitted here: just like in Appendix A the definitions should be read as if everything were well-scoped. Certain terms, including $\varnothing$, are classified as values: Value $\varnothing$ Value star Value (lam t) Value (pair t u) Value zero Value (suct t) Single-step reduction is then defined in the following way, using substitution:\begin{array}{c}t_{1}\Rightarrow t_{2}\\overline{\mathrm{unitrec}t_{1}u\Rightarrow\mathrm{unitrec}t_{2}u}\end{array}
\begin{array}{c}t_{1}\Rightarrow t_{2}\\overline{\mathrm{unitrec~star}t\Rightarrow t}\end{array}
\begin{array}{c}t_{1}\Rightarrow t_{2}\\overline{\mathrm{app}t_{1}u\Rightarrow\mathrm{app}t_{2}u}\end{array}
\begin{array}{c}Value t\quad u_{1}\Rightarrow u_{2}\\overline{app t u_{1}\Rightarrow app t u_{2}}\end{array}
\begin{array}{c} Value u\ \overline{app\left(lam t\right)u\Rightarrow t[u/0]}\end{array}
\begin{array}{c}t_{1}\Rightarrow t_{2}\\overline{\mathrm{fst}t_{1}\Rightarrow\mathrm{fst}t_{2}}\end{array}
\begin{array}{c}t_{1}\Rightarrow t_{2}\\overline{\mathrm{fst}\left(pair t u\right)\Rightarrow t}\end{array}
\begin{array}{c}t_{1}\Rightarrow t_{2}\\overline{\mathrm{snd}t_{1}\Rightarrow\mathrm{snd}t_{2}}\end{array}
\begin{array}{c}t_{1}\Rightarrow t_{2}\\overline{\mathrm{prodrec}t_{1}u\Rightarrow\mathrm{prodrec}t_{2}u}\end{array}
\begin{array}{c} \mathrm{prodrec}\left(\mathrm{pair}t u\right)v\Rightarrow v[t/1,u/0]\end{array}
\begin{array}{c}v_{1}\Rightarrow v_{2}\\overline{\mathrm{natrec}t u v_{1}\Rightarrow\mathrm{natrec}t u v_{2}}\end{array}
\begin{array}{c}natrec t u zero\Rightarrow t\end{array}
\begin{array}{c}natrec t u(suc v)\Rightarrow u[v/1,natrec t u v/0]\end{array}
\overline{t\Rightarrow^{*}t}
\frac{t\Rightarrow u\qquad u\Rightarrow^{}v}{t\Rightarrow^{}v}
\begin{array}{l}erase x\erase\cup_{l}\erase\left(Lift_{l}A\right)\erase\left(lift t\right)\erase\left(lower t\right)\erase\bot\erase\left(emptyrec_{p}At\right)\erase\top_{s}\erase\star_{s}\erase\left(unitrec_{0}At u\right)\erase\left(unitrec_{\omega}At u\right)\erase\left(\Pi_{p}AB\right)\erase\left(\lambda^{p}t\right)\end{array}=\begin{array}{l}var x\ \varnothing\ \varnothing\ erase t\ erase t\ \varnothing\ loop\ \varnothing\ star\ erase u\ unitrec\left(erase t\right)\left(erase u\right)\ \varnothing\ lam\left(erase t\right)\end{array}
\begin{array}{ll} erase\left(t^{\omega}u\right) & = app\left(erase,t\right)\left(erase,u\right) \ erase\left(t^{0}u\right) & = app\left(erase,t\right)\downarrow \ erase\left(\Sigma_{s,p}A B\right) & = \downarrow \ erase\left(t,u\right){s,0} & = erase,u \ erase\left(t,u\right){s,\omega} & = app\left(app\left(lam\left(lam\left(pair\left(var,1\right)\left(var,0\right)\right)\right)\right)\left(erase,t\right)\right)\left(erase,u\right) \ erase\left(fst_{0}t\right) & = loop \ erase\left(fst_{\omega}t\right) & = fst\left(erase,t\right) \ erase\left(snd_{0}t\right) & = erase,t \ erase\left(snd_{\omega}t\right) & = snd\left(erase,t\right) \ erase\left(prodrec_{p,0}At,u\right) &= \left(erase,u\right)[loop/1,loop/0] \ erase\left(prodrec_{0,\omega}At,u\right) &= app\left(\left(lam\left(erase,u\right)\right)[loop/0]\right)\left(erase,t\right) \ erase\left(prodrec_{\omega,\omega}At,u\right) &= prodrec\left(erase,t\right)\left(erase,u\right) \ erase\left(Id,At,u\right) & = \downarrow \ erase\ refl & = \downarrow \ erase\left(\mathsf{I}{p,q}At,Bu,v,w\right) &= erase,u \ erase\left(\mathsf{K}{p}At,Bu,v\right) &= erase,u \ erase\left(\left[\right]-cong_{s,l}At,u,v\right) &= \downarrow \ erase\ Nat & = \downarrow \ erase\ zero & = zero \ erase\left(suc,t\right) & = app\left(lam\left(suc\left(var,0\right)\right)\right)\left(erase,t\right) \ erase\left(natrec_{p,q}At,u,v\right) &= natrec\left(erase,t\right)\left(erase,u\right)\left(erase,v\right) \ erase\left(A/B\right) & = \downarrow \ erase\left(class,t\right) & = erase,t \ erase\left(resp,A,B,t,u,v\right) &= loop \ erase\left(set,A,B,t,u,v,w\right) &= loop \ erase\left(qrec,C,t,u,v,w\right) &= app\left(lam\left(erase,t\right)\right)\left(erase,w\right) \end{array}