skip to main content
research-article
Open access

Gradualizing the Calculus of Inductive Constructions

Published: 06 April 2022 Publication History

Abstract

We investigate gradual variations on the Calculus of Inductive Construction (CIC) for swifter prototyping with imprecise types and terms. We observe, with a no-go theorem, a crucial trade-off between graduality and the key properties of normalization and closure of universes under dependent product that CIC enjoys. Beyond this Fire Triangle of Graduality, we explore the gradualization of CIC with three different compromises, each relaxing one edge of the Fire Triangle. We develop a parametrized presentation of Gradual CIC (GCIC) that encompasses all three variations, and develop their metatheory. We first present a bidirectional elaboration of GCIC to a dependently-typed cast calculus, CastCIC, which elucidates the interrelation between typing, conversion, and the gradual guarantees. We use a syntactic model of CastCIC to inform the design of a safe, confluent reduction, and establish, when applicable, normalization. We study the static and dynamic gradual guarantees as well as the stronger notion of graduality with embedding-projection pairs formulated by New and Ahmed, using appropriate semantic model constructions. This work informs and paves the way towards the development of malleable proof assistants and dependently-typed programming languages.

1 Introduction

Gradual typing arose as an approach to selectively and soundly relax static type checking by endowing programmers with imprecise types Siek and Taha 2006 Siek et al. 2015. Optimistically well-typed programs are safeguarded by runtime checks that detect violations of statically-expressed assumptions. A gradual version of the simply-typed lambda calculus (STLC) enjoys such expressiveness that it can embed the untyped lambda calculus. This means that gradually-typed languages tend to accommodate at least two kinds of effects, non-termination and runtime errors. The smoothness of the static-to-dynamic checking spectrum afforded by gradual languages is usually captured by (static and dynamic) gradual guarantees, which stipulate that typing and reduction are monotone with respect to precision Siek et al. 2015.
Originally formulated in terms of simple types, the extension of gradual typing to a wide variety of typing disciplines has been an extremely active topic of research, both in theory and in practice. As part of this quest towards more sophisticated type disciplines, gradual typing was bound to meet with full-blown dependent types. This encounter saw various premises in a variety of approaches to integrate (some form of) dynamic checking with (some form of) dependent types Dagand et al. 2018 Knowles and Flanagan 2010 Lehmann and Tanter 2017 Ou et al. 2004 Tanter and Tabareau 2015 Wadler and Findler 2009. Naturally, the highly-expressive setting of dependent types, in which terms and types are not distinct and computation happens as part of typing, raises a lot of subtle challenges for gradualization. In the most elaborate effort to date, Eremondi et al. 2019 present a gradual dependently-typed programming language (GDTL), which can be seen as an effort to gradualize a two-phase programming language such as Idris Brady 2013. A key idea of GDTL is to adopt an approximate form of computation at compile-time, called approximate normalization, which ensures termination and totality of typing, while adopting a standard gradual reduction semantics with errors and non-termination at runtime. The metatheory of GDTL however still needs to be extended to account for inductive types.
This article addresses the open challenge of gradualizing a full-blown dependent type theory, namely the Calculus of Inductive Constructions ( \(\boldsymbol \mathsf {CIC}\) ) hereafter, Coquand and Huet 1988 Paulin-Mohring 2015, identifying and addressing the corresponding metatheoretic challenges. In doing so, we build upon several threads of prior work in the type theory and gradual typing literature: syntactic models of type theories to justify extensions of \(\mathsf {CIC}\) Boulier et al. 2017, in particular, the exceptional type theory of Pédrot and Tabareau 2018, an effective re-characterization of the dynamic gradual guarantee as graduality with embedding-projection pairs New and Ahmed 2018, as well as the work on GDTL Eremondi et al. 2019.
Motivation. We believe that studying the gradualization of a full-blown dependent type theory like \(\mathsf {CIC}\) is in and of itself an important scientific endeavor, which is very likely to inform the gradual typing research community in its drive towards supporting ever more challenging typing disciplines. In this light, the aim of this article is not to put forth a unique design or solution, but to explore the space of possibilities. Nor is this article about a concrete implementation of gradual \(\mathsf {CIC}\) and an evaluation of its applicability; these are challenging perspectives of their own, which first require the theoretical landscape to be unveiled.
This being said, as Eremondi et al. 2019, we can highlight a number of practical motivating scenarios for gradualizing \(\mathsf {CIC}\) , anticipating what could be achieved in a hypothetical gradual version of \(\mathrm{Coq}\) , for instance.
Example 1 (Smoother Development with Indexed Types).
\(\mathsf {CIC}\) , which underpins languages and proof assistants such as \(\mathrm{Coq}\) , Agda and Idris, among others, is a very powerful system to program in, but at the same time extremely demanding. Mixing programs and their specifications is attractive but challenging.
Consider the classical example of length-indexed lists, of type \(\mathsf {vec\ A\ n}\) as defined in \(\mathrm{Coq}\) :1
Indexing the inductive type by its length allows us to define a total \(\mathsf{head}\) function, which can only be applied to non-empty lists:
\(\mathsf{head : forall A n, vec A (S n) -\gt A}\) .
Developing functions over such structures can be tricky. For instance, what type should the \(\mathsf{filter}\) function be given?
\(\mathsf{filter : forall A n (f : A -\gt bool), vec A n -\gt vec A \hole }\)
The size of the resulting list depends on how many elements in the list actually match the given predicate \(\mathsf{f}\) ! Dealing with this level of intricate specification can (and does) scare programmers away from mixing programs and specifications. The truth is that many libraries, such as MathComp Mahboubi and Tassi 2008, give up on mixing programs and specifications even for simple structures such as these, which are instead dealt with as ML-like lists with extrinsically-established properties. This tells a lot about the current intricacies of dependently-typed programming.
Instead of avoiding the obstacle altogether, gradual dependent types provide a uniform and flexible mechanism to a tailored adoption of dependencies. For instance, one could give \(\mathsf{filter}\) the following gradual type, which makes use of the unknown term \(?\) in an index position:
\(\mathsf{filter : forall A n (f : A -\gt bool), vec A n -\gt vec A ?}\)
This imprecise type means that uses of \(\mathsf{filter}\) will be optimistically accepted by the typechecker, although subject to associated checks during reduction. For instance:
\(\mathsf{head nat ? (filter nat 4 even [ 0 ; 1 ; 2 ; 3 ])}\) ,
typechecks, and is successfully convertible to 0, while:
\(\mathsf{head nat ? (filter nat 2 even [ 1 ; 3 ])}\) ,
typechecks but fails upon reduction, when discovering that the assumption that the argument to head is non-empty is in fact incorrect.
Example 2 (Defining General Recursive Functions).
Another challenge of working in \(\mathsf {CIC}\) is to convince the type checker that recursive definitions are well founded. This can either require tight syntactic restrictions, or sophisticated arguments involving accessibility predicates. At any given stage of a development, one might not be in a position to follow any of these. In such cases, a workaround is to adopt the “fuel pattern”, i.e., parametrizing a function with a clearly syntactically decreasing argument in order to please the typechecker, and to use an arbitrary initial fuel value. In practice, one sometimes requires a simpler way to unplug termination checking, and for that purpose, many proof assistants support external commands or parameters to deactivate termination checking.2
Because the use of the unknown type allows the definition of fix-point combinators Siek and Taha 2006 Eremondi et al. 2019, one can use this added expressiveness to bypass termination checking locally. This just means that the external facilities provided by specific proof assistant implementations now become internalized in the language.
Example 3 (Large Elimination, Gradually).
One of the argued benefit of dynamically-typed languages, which is accommodated by gradual typing, is the ability to define functions that can return values of different types depending on their inputs, such as
In a gradually-typed language, one can give this function the type \(?\) , or even \(\mathbb {N}-\gt \mathbb {N}-\gt ?\) in order to enforce proper argument types, and remain flexible in the treatment of the returned value. Of course, one knows very well that in a dependently-typed language, with large elimination, we can simply give foo the dependent type:
\(\mathsf{foo : forall (n m : nat), if (n \gt m) then nat else bool}\) .
Lifting the term-level comparison \(\mathsf{n \gt m}\) to the type level is extremely expressive, but hard to work with as well, both for the implementer of the function and its clients.
In a gradual dependently-typed setting, one can explore the whole spectrum of type-level precision for such a function, starting from the least precise to the most precise, for instance:
At each stage from top to bottom, there is less flexibility (but more guarantees!) for both the implementer of \(\mathsf{foo}\) and its clients. The gradual guarantee ensures that if the function is actually faithful to the most precise type then giving it any of the less precise types above does not introduce any new failure Siek et al. 2015.
Example 4 (Gradually Refining Specifications).
Let us come back to the \(\mathsf{filter}\) function from Example 1. Its fully-precise type requires appealing to a type-level function that counts the number of elements in the list that satisfy the predicate (notice the dependency to the input vector \(\mathsf{v}\) ):
\(\mathsf{filter : forall A n (f : A -\gt bool) (v : vec A n), vec A (count\_if A n f v).}\)
Anticipating the need for this function, a gradual specification could adopt the above signature for \(\mathsf{filter}\) but leave \(\mathsf{count\_if}\) unspecified:
This situation does not affect the behavior of the program compared to leaving the return type index unknown. More interestingly, one could immediately define the base case, which trivially specifies that there are no matching elements in an empty vector:
This slight increment in precision provides a little more static checking, for instance:
\(\mathsf{head nat ? (filter nat 4 even [])}\) ,
does not typecheck, instead of failing during reduction.
Again, the gradual guarantee ensures that such incremental refinements in precision towards the proper fully-precise version do not introduce spurious errors. Note that this is in stark contrast with the use of axioms (which will be discussed in more depth in Section 2). Indeed, replacing correct code with an axiom can simply break typing! For instance, with the following definitions:
the definition of \(\mathsf{filter}\) does not typecheck anymore, as the axiom at the type-level is not convertible to any given value.
Note: Gradual programs or proofs?. When adapting the ideas of gradual typing to a dependent type theory, one might expect to deal with programs rather than proofs. This observation is however misleading: from the point of view of the Curry–Howard correspondence, proofs and programs are intrinsically related, so that gradualizing the latter begs for a gradualization of the former. The examples above illustrate mixed programs and specifications, which naturally also appeal to proofs: dealing with indexed types typically requires exhibiting equality proofs to rewrite terms. Moreover, there are settings in which one must consider computationally-relevant proofs, such as constructive algebra and analysis, homotopy type theory, and so on. In such settings, using axioms to bypass unwanted proofs breaks reduction, and because typing requires reduction, the use of axioms can simply prevent typing, as illustrated in Example 4.
Contribution. This article reports on the following contributions:
We analyze, from a type theoretic point of view, the fundamental trade-offs involved in gradualizing a dependent type theory such as \(\mathsf {CIC}\) (Section 2), and establish a no-go theorem, the Fire Triangle of Graduality, which does apply to \(\mathsf {CIC}\) . In essence, this result tells us that a gradual type theory3 cannot satisfy at the same time normalization, graduality, and conservativity with respect to \(\mathsf {CIC}\) . We explain each property and carefully analyze what it means in the type theoretic setting.
We present an approach to gradualizing \(\mathsf {CIC}\) (Section 3), parametrized by two knobs for controlling universe constraints on the dependent function space, resulting in three meaningful variants of Gradual \(\mathsf {CIC}\) ( \(\boldsymbol \mathsf {GCIC}\) ), that reflect distinct resolutions of the Fire Triangle of Graduality. Each variant sacrifices one key property.
We give a bidirectional and mutually-recursive elaboration of \(\mathsf {GCIC}\) to a dependently-typed cast calculus \(\mathsf {CastCIC}\) (Section 5). This elaboration is based on a bidirectional presentation of \(\mathsf {CIC}\) , which has been recently studied in details by Lennon-Bertrand 2021, and of which we give a comprehensive summary in Section 4. Like \(\mathsf {GCIC}\) , \(\mathsf {CastCIC}\) is parametrized, and encompasses three variants. We develop the metatheory of \(\mathsf {GCIC}\) , \(\mathsf {CastCIC}\) , and elaboration. In particular, we prove type safety for all variants, as well as the gradual guarantees and normalization, each for two of the three variants.
To further develop the metatheory of \(\mathsf {CastCIC}\) , we appeal to various models (Section 6). First, to prove strong normalization of two \(\mathsf {CastCIC}\) variants, we provide a syntactic model of \(\mathsf {CastCIC}\) with a translation to \(\mathsf {CIC}\) extended with induction-recursion Martin-Löf 1996 Dybjer and Setzer 2003 Ghani et al. 2015. Second, to prove the stronger notion of graduality with embedding-projection pairs New and Ahmed 2018 for a normalizing variant, we provide a model of \(\mathsf {CastCIC}\) that captures the notion of monotonicity with respect to precision. Finally, we present an extension of Scott’s model based on \(\omega\) -complete partial orders Scott 1976 to prove graduality for the variant with divergence.
We describe how to handle indexed inductive types in \(\mathsf {GCIC}\) , either directly or via different encodings, under some constraints on indices (Section 7).
We then elucidate the current limitations of this work regarding three important features of \(\mathsf {CIC}\) —impredicativity, \(\eta\) -equality and propositional equality (Section 8). We finally discuss related work (Section 9) and conclude (Section 10). Some detailed proofs are omitted from the main text and can be found in appendix.

2 Fundamental Tradeoffs in Gradual Dependent Type Theory

Before exposing a specific approach to gradualizing \(\mathsf {CIC}\) , we present a general analysis of the main properties at stake and tensions that arise when gradualizing a dependent type theory.
We start by recalling two cornerstones of type theory, namely, progress and normalization, and allude to the need to reconsider them carefully in a gradual setting (Section 2.1). We explain why the obvious approach based on axioms is unsatisfying (Section 2.2), as well as why simply using a type theory with exceptions Pédrot and Tabareau 2018 is not enough either (Section 2.3). We then turn to the gradual approach, recalling its essential properties in the simply-typed setting (Section 2.4), and revisiting them in the context of a dependent type theory (Section 2.5). This finally leads us to establish a fundamental impossibility in the gradualization of \(\mathsf {CIC}\) , which means that at least one of the desired properties has to be sacrificed (Section 2.6).

2.1 Safety and Normalization, Endangered

As a well-behaved typed programming language, \(\mathsf {CIC}\) enjoys (type) Safety ( \(\mathcal {S}\) ), meaning that well-typed closed terms cannot get stuck, i.e., the normal forms of closed terms of a given type are exactly the canonical forms of that type. In \(\mathsf {CIC}\) , a closed canonical form is a term whose typing derivation ends with an introduction rule, i.e., an \(\lambda\) -abstraction for a function type, and a constructor for an inductive type. For instance, any closed term of type \(\mathsf{bool}\) is convertible (and reduces) to either \(\mathsf{true}\) or \(\mathsf{false}\) . Note that an open term can reduce to an open canonical form called a neutral term, such as \(\mathsf{not x}\) .
As a logically consistent type theory, \(\mathsf {CIC}\) enjoys (strong) Normalization ( \(\mathcal {N}\) ), meaning that any term is convertible to its (unique) normal form. \(\mathcal {N}\) together with \(\mathcal {S}\) imply canonicity: any closed term of a given type must reduce to a canonical form of that type. When applied to the empty type \(\mathsf{False}\) , canonicity ensures logical consistency: Because there is no canonical form for \(\mathsf{False}\) , there is no closed proof of \(\mathsf{False}\) . Note that \(\mathcal {N}\) also has an important consequence in \(\mathsf {CIC}\) . Indeed, in this system, conversion—which coarsely means syntactic equality up-to reduction—is used in the type-checking algorithm. \(\mathcal {N}\) ensures that one can devise a sound and complete decision procedure (a.k.a. a reduction strategy) in order to decide conversion, and hence, typing.
In the gradual setting, the two cornerstones \(\mathcal {S}\) and \(\mathcal {N}\) must be considered with care. First, any closed term can be ascribed the unknown type \(\mathsf{?}\) first and then any other type: For instance, \(\mathsf{0::?::bool}\) is a well-typed closed term of type \(\mathsf{bool}\) . 4 However, such a term cannot possibly reduce to either \(\mathsf{true}\) or \(\mathsf{false}\) , so some concessions must be made with respect to safety—at least, the notion of canonical forms must be extended.
Second, \(\mathcal {N}\) is endangered. The quintessential example of non-termination in the untyped lambda calculus is the term \(\Omega := \delta ~\delta\) where \(\delta := (\lambda ~ x.~x~x)\) . In the simply-typed lambda calculus (hereafter \(\mathsf {STLC}\) ), as in \(\mathsf {CIC}\) , self-applications like \(\delta ~\delta\) and \(x~x\) are ill-typed. However, when introducing gradual types, one usually expects to accommodate such idioms, and therefore in a standard gradually-typed calculus such as \(\mathsf {GTLC}\) Siek and Taha 2006, a variant of \(\Omega\) that uses \((\lambda ~ x : ?.~x~x)\) for \(\delta\) is well-typed and diverges, that is, admits no normal form. The reason is that the argument type of \(\delta\) , the unknown type \(?\) , is consistent with the type of \(\delta\) itself, \(? \rightarrow ?\) , and at runtime, nothing prevents reduction from going on forever. Therefore, if one aims at ensuring \(\mathcal {N}\) in a gradual setting, some care must be taken to restrict expressiveness.

2.2 The Axiomatic Approach

Let us first address the elephant in the room: Why would one want to gradualize \(\mathsf {CIC}\) instead of simply postulating an axiom for any term (be it a program or a proof) that one does not feel like providing (yet)?
Indeed, we can augment \(\mathsf {CIC}\) with a general-purpose wildcard axiom \(\texttt {ax}\) :
\(\mathsf{Axiom _st : forall A, A.}\)
The resulting theory, called \(\mathsf {CIC}\!+\!{ \texttt {ax}}\) , has an obvious practical benefit: we can use \(\mathsf{(_st A)}\) , hereafter noted \(\mathsf{_st_A}\) , as a wildcard whenever we are asked to exhibit an inhabitant of some type \(\mathsf{A}\) and we do not (yet) want to. This is exactly what admitted definitions are in \(\mathrm{Coq}\) , for instance, and they do play an important practical role at some stages of any \(\mathrm{Coq}\) development.
However, we cannot use the axiom \(\mathsf{_st_A}\) in any meaningful way as a value at the type level. For instance, going back to Example 1, one might be tempted to give to the \(\mathsf{filter}\) function on vectors the type \(\mathsf{forall A n (f : A -\gt bool), vec A n -\gt vec A _st_nat}\) , in order to avoid the complications related to specifying the size of the vector produced by \(\mathsf{filter}\) . The problem is that the term:
\(\mathsf{head nat _st_nat (filter nat 4 even [0; 1; 2; 3])}\) ,
does not typecheck because the type of the filtering expression, \(\mathsf{vec A _st_nat}\) , is not convertible to \(\mathsf{vec A (S _st_nat)}\) , as required by the domain type of \(\mathsf{head nat _st_nat}\) .
So the axiomatic approach is not useful for making dependently-typed programming any more pleasing. That is, using axioms goes in total opposition to the gradual typing criteria Siek et al. 2015 when it comes to the smoothness of the static-to-dynamic checking spectrum: given a well-typed term, making it “less precise” by using axioms for some subterms actually results in programs that do not typecheck or reduce anymore.
Because \(\mathsf {CIC}\!+\!{\texttt {ax}}\) amounts to working in \(\mathsf {CIC}\) with an initial context extended with \(\texttt {ax}\) , this theory satisfies normalization ( \(\mathcal {N}\) ) as much as \(\mathsf {CIC}\) , so conversion remains decidable. However, \(\mathsf {CIC}\!+\!{\texttt {ax}}\) lacks a satisfying notion of safety because there is an infinite number of open canonical normal forms (more adequately called stuck terms) that inhabit any type \(\mathsf{A}\) . For instance, in \(\mathsf{bool}\) , we not only have the normal forms \(\mathsf{true}\) , \(\mathsf{false}\) , and \(\mathsf{_st_bool}\) , but an infinite number of terms stuck on eliminations of \(\texttt {ax}\) , such as \(\mathsf{match _st_A with ...}\) or \(\texttt {ax}_{\mathbb {N}\rightarrow \mathbb {B}}\;1\) .

2.3 The Exceptional Approach

Pédrot and Tabareau 2018 present the exceptional type theory \(\mathsf {ExTT}\) , demonstrating that it is possible to extend a type theory with a wildcard term while enjoying a satisfying notion of safety, which coincides with that of programming languages with exceptions.
\(\mathsf {ExTT}\) is essentially \(\mathsf {CIC}\!+\!{{\rm \mathtt {err}}}\) , that is, it extends \(\mathsf {CIC}\) with an indexed error term \(\mathsf{raise_A}\) that can inhabit any type \(\mathsf{A}\) . But instead of being treated as a computational black box like \(\mathsf{_st_A}\) , \(\mathsf{raise_A}\) is endowed with computational content emulating exceptions in programming languages, which propagate instead of being stuck. For instance, in \(\mathsf {ExTT}\) we have the following conversion:
\(\mathsf{match raise_bool return nat with | true -\gt O | false -\gt 1 end}\) \(\equiv\) \(\mathsf{raise_nat}\) .
Notably, such exceptions are call-by-name exceptions, so one can only discriminate exceptions on positive types (i.e., inductive types), not on negative types (i.e., function types). In particular, in \(\mathsf {ExTT}\) , \(\mathsf{raise_A{}_-\gt {}_B }\) and \(\mathsf{fun _ : A =\gt raise_B}\) are convertible, and the latter is considered to be in normal form. So \(\mathsf{raise_A}\) is a normal form of \(\mathsf{A}\) only if \(\mathsf{A}\) is a positive type.
\(\mathsf {ExTT}\) has a number of interesting properties: It is normalizing ( \(\mathcal {N}\) ) and safe ( \(\mathcal {S}\) ), taking \(\mathsf{raise_A}\) into account as usual in programming languages where exceptions are possible outcomes of computation: The normal forms of closed terms of a positive type (e.g., \(\mathsf{bool}\) ) are either the constructors of that type (e.g., \(\mathsf{true}\) and \(\mathsf{false}\) ) or \(\mathsf{raise}\) at that type (e.g., \(\mathsf{err_bool}\) ). As a consequence, \(\mathsf {ExTT}\) does not satisfy full canonicity, but it does satisfy a weaker form of it. In particular, \(\mathsf {ExTT}\) enjoys (weak) logical consistency: Any closed proof of \(\mathsf{False}\) is convertible to \(\mathsf{raise_False}\) , which is discriminable at \(\mathsf{False}\) . It has been shown that we can still reason soundly in an exceptional type theory, either using a parametricity requirement Pédrot and Tabareau 2018, or more flexibly, using different universe hierarchies Pédrot et al. 2019.
It is also important to highlight that this weak form of logical consistency is the most one can expect in a theory with effects. Indeed, Pédrot and Tabareau 2020 have shown that it is not possible to define a type theory with full dependent elimination that has observable effects (from which exceptions are a particular case) and at the same time validates traditional canonicity. Settling for less, as explained in Section 2.2 for the axiomatic approach, leads to an infinite number of stuck terms, even in the case of booleans, which is in opposition to the type safety criterion of gradual languages, which only accounts for runtime type errors.
Unfortunately, while \(\mathsf {ExTT}\) solves the safety issue of the axiomatic approach, it still suffers from the same limitation as the axiomatic approach regarding type-level computation. Indeed, even though we can use \(\mathsf{raise_A}\) to inhabit any type, we cannot use it in any meaningful way as a value at the type level. The term:
\(\mathsf{head nat err_nat (filter nat 4 even [ 0 ; 1 ; 2 ; 3 ])}\) ,
does not typecheck, because \(\mathsf{vec A raise_nat}\) is still not convertible to \(\mathsf{vec A (S raise_nat)}\) . The reason is that \(\mathsf{raise_nat}\) behaves like an extra constructor to \(\mathsf{nat}\) , so \(\mathsf{S raise_nat}\) is itself a normal form, and normal forms with different head constructors ( \(\mathsf{S}\) and \(\mathsf{raise_nat}\) ) are not convertible.

2.4 The Gradual Approach: Simple Types

Before going on with our exploration of the fundamental challenges in gradual dependent type theory, we review some key concepts and expected properties in the context of simple types Siek et al. 2015 New and Ahmed 2018 Garcia et al. 2016.
Static semantics. Gradually-typed languages introduce the unknown type, written ?, which is used to indicate the lack of static typing information Siek and Taha 2006. One can understand such an unknown type in terms of an abstraction of the set of possible types that it stands for Garcia et al. 2016. This interpretation provides a naive but natural understanding of the meaning of partially-specified types, for instance, \(\mathbb {B}\rightarrow ?\) denotes the set of all function types with \(\mathbb {B}\) as domain. Given imprecise types, a gradual type system relaxes all type predicates and functions in order to optimistically account for occurrences of ?. In a simple type system, the predicate on types is equality, whose relaxed counterpart is called consistency.5 For instance, given a function \(\mathsf{f}\) of type \(\mathbb {B}\rightarrow ?\) , the expression \(\mathsf{(f true) + 1}\) is well-typed because \(\mathsf{f}\) could plausibly return a number, given that its codomain is ?, which is consistent with \(\mathsf{nat}\) .
Note that there are other ways to consider imprecise types, for instance by restricting the unknown type to denote base types (in which case \(?\) would not be consistent with any function type), or to only allow imprecision in certain parts of the syntax of types, such as effects Bañados Schwerter et al. 2016, security labels Fennell and Thiemann 2013 Toro et al. 2018, annotations Thiemann and Fennell 2014, or only at the top-level Bierman et al. 2010. Here, we do not consider these specialized approaches, which have benefits and challenges of their own, and stick to the mainstream setting of gradual typing in which the unknown type is consistent with any type and can occur anywhere in the syntax of types.
Dynamic semantics. Having optimistically relaxed typing based on consistency, a gradual language must detect inconsistencies at runtime if it is to satisfy safety ( \(\mathcal {S}\) ), which therefore has to be formulated in a way that encompasses runtime errors. For instance, if the function \(\mathsf{f}\) above returns \(\mathsf{false}\) , then an error must be raised to avoid reducing to \(\mathsf{false + 1}\) —a closed stuck term, denoting a violation of safety. The traditional approach to do so is to avoid giving a direct reduction semantics to gradual programs, and instead, to elaborate them to an intermediate language with runtime casts, in which casts between inconsistent types raise errors Siek and Taha 2006. Alternatively—and equivalently from a semantics point of view—one can define the reduction of gradual programs directly on gradual typing derivations augmented with evidence about consistency judgments, and report errors when transitivity of such judgments is unjustified Garcia et al. 2016. There are many ways to realize each of these approaches, which vary in terms of efficiency and eagerness of checking Herman et al. 2010 Tobin-Hochstadt and Felleisen 2008 Siek and Wadler 2010 Siek et al. 2009 Toro and Tanter 2020 Bañados Schwerter et al. 2021.
Conservativity. A first important property of a gradual language is that it is a conservative extension of a related static typing discipline: The gradual and static systems should coincide on static terms. This property is hereafter called Conservativity ( \(\mathcal {C}\) ), and parametrized with the considered static system. For instance, we write that \(\mathsf {GTLC}\) satisfies \(\mathcal {C}_{/{\mathsf {STLC}}}\) . Technically, Siek and Taha 2006 prove that typing and reduction of \(\mathsf {GTLC}\) and \(\mathsf {STLC}\) coincide on their common set of terms (i.e., terms that are fully precise). An important aspect of \(\mathcal {C}\) is that the type formation rules and typing rules themselves are also preserved, modulo the presence of ? as a new type and the adequate lifting of predicates and functions Garcia et al. 2016. While this aspect is often left implicit, it ensures that the gradual type system does not behave in ad hoc ways on imprecise terms.
Note that, despite its many issues, \(\mathsf {CIC}\!+\!{ \texttt {ax}}\) (Section 2.2) satisfies \(\mathcal {C}_{/{\mathsf {CIC}}}\) : All pure (i.e., axiom-free) \(\mathsf {CIC}\) terms behave as they would in \(\mathsf {CIC}\) . More precisely, two \(\mathsf {CIC}\) terms are convertible in \(\mathsf {CIC}\!+\!{\texttt {ax}}\) iff they are convertible in \(\mathsf {CIC}\) . Importantly, this does not mean that \(\mathsf {CIC}\!+\!{\texttt {ax}}\) is a conservative extension of \(\mathsf {CIC}\) as a logic—which it clearly is not!
Gradual guarantees. The early accounts of gradual typing emphasized consistency as the central idea. However, Siek et al. 2015 observed that this characterization left too many possibilities for the impact of type information on program behavior, compared to what was originally intended Siek and Taha 2006. Consequently, Siek et al. 2015 brought forth type precision (denoted \(\mathsf{precise}\) ) as the key notion, from which consistency can be derived: Two types \(\mathsf{A}\) and \(\mathsf{B}\) are consistent if and only if there exists \(\mathsf{T}\) such that \(\mathsf{T precise A}\) and \(\mathsf{T precise B}\) . The unknown type ? is the most imprecise type of all, i.e., \(\mathsf{T precise ?}\) for any \(\mathsf{T}\) . Precision is a preorder that can be used to capture the intended monotonicity of the static-to-dynamic spectrum afforded by gradual typing. The static and dynamic gradual guarantees specify that typing and reduction should be monotone with respect to precision: losing precision should not introduce new static or dynamic errors. These properties require precision to be extended from types to terms. Siek et al. 2015 present a natural extension that is purely syntactic: A term is more precise than another if they are syntactically equal except for their type annotations, which can be more precise in the former.
The static gradual guarantee (SGG) ensures that imprecision does not break typeability:
Definition 1 (SGG).
If \(\mathsf{t precise u}\) and \(\mathsf{t : T}\) , then \(\mathsf{u : U}\) for some \(\mathsf{U}\) such that \(\mathsf{T precise U}\) .
The SGG captures the intuition that “sprinkling ? over a term” maintains its typeability. As such, the notion of precision \(\mathsf{precise}\) used to formulate the SGG is inherently syntactic, over as-yet-untyped terms: typeability is the consequence of the SGG theorem.
The dynamic gradual guarantee (DGG) is the key result that bridges the syntactic notion of precision to reduction: If \(\mathsf{t precise u}\) and \(\mathsf{t}\) reduce to some value \(\mathsf{v}\) , then \(\mathsf{u}\) reduces to some value \(\mathsf{v^{\prime }}\) such that \(\mathsf{v precise v^{\prime }}\) ; and if \(\mathsf{t}\) diverges, then so does \(\mathsf{u}\) . This property entails that \(\mathsf{t precise u}\) means that \(\mathsf{t}\) may error more than \(\mathsf{u}\) , but otherwise they should behave the same. Instead of the original formulation of the DGG by Siek et al. 2015, New and Ahmed 2018 appeal to the semantic notion of observational error-approximation to capture the relation between two terms that are contextually equivalent except that the left-hand side term may fail more.6
Definition 2 (Observational Error-approximation).
A term \(\Gamma \vdash t : A\) observationally error-approximates a term \(\Gamma \vdash u : A\) , noted \(t \preccurlyeq ^{obs}u\) , if for all Boolean-valued observation contexts \(\mathcal {C} : (\Gamma \vdash A) \Rightarrow (\vdash \mathbb {B}{})\) closing over all free variables, either
\(\mathcal {C}[t]\) and \(\mathcal {C}[u]\) both diverge;
Otherwise if \(\mathcal {C}[u] {\rm {\leadsto }^\ast }{\rm \mathtt {err}}_{\mathbb {B}}\) , then \(\mathcal {C}[t] {\rm {\leadsto }^\ast }{\rm \mathtt {err}}_{\mathbb {B}}\) .
Using this semantic notion, the DGG simply states that term precision implies observational error-approximation:
Definition 3 (DGG).
If \(\mathsf{t precise u}\) then \(\mathsf{t obsApprox u}\) .
While often implicit, it is important to highlight that the DGG is relative to both the notion of precision \(\mathsf{precise}\) and the notion of observations \(\mathsf{obsApprox}\) . Indeed, it is possible to study alternative notions of precisions beyond the natural definition stated by Siek et al. 2015. For instance, following the Abstracting Gradual Typing methodology Garcia et al. 2016, precision follows from the definition of gradual types as a concretization to sets of static types. This opens the door to justifying alternative precisions, e.g., by considering that the unknown type only stands for specific static types, such as base types. Additionally, variants of precision have been studied in more challenging typing disciplines where the natural definition seems incompatible with the DGG, see e.g., Igarashi et al. 2017. As we will soon see below, it can also be necessary in certain situations to consider another notion of observations.
Graduality. As we have seen, the DGG is relative to a notion of precision, but what should this relation be? To go beyond a syntactic axiomatic definition of precision, New and Ahmed 2018 characterize the good dynamic behavior of precision: The runtime checking mechanism used to define a gradual language, such as casting, should only perform type checking, and not otherwise affect behavior. Specifically, they mandate that precision gives rise to embedding-projection pairs (ep-pairs): The cast induced by two types related by precision forms an adjunction, which induces a retraction. In particular, going to a less precise type and back is the identity: For any term \(\mathsf{a}\) of type \(\mathsf{A}\) , and given \(\mathsf{A precise B}\) , then \(\mathsf{a::B::A}\) should be observationally equivalent to \(\mathsf{a}\) (recall from Footnote 4 that \(\mathsf{::}\) is a type ascription). For instance, \(\mathsf{1::?::nat}\) should be equivalent to \(\mathsf{1}\) . Dually, when gaining precision, there is the potential for errors: given a term \(\mathsf{b}\) of type \(\mathsf{B}\) , \(\mathsf{b::A::B}\) may fail. By considering error as the least precise term, this can be stated as \(\mathsf{b::A::B precise b}\) . For instance, with the imprecise successor function \(\mathsf{f := fun n:? =\gt (S n)::?}\) of type \(\mathsf{?-\gt ?}\) , we have \(\mathsf{f::nat-\gt bool::?-\gt ? precise f}\) , because the ascribed function will fail when applied.
Technically, the adjunction part states that if we have \(\mathsf{A precise B}\) , a term \(\mathsf{a}\) of type \(\mathsf{A}\) , and a term \(\mathsf{b}\) of type \(\mathsf{B}\) , then \(\mathsf{a precise b::A \lt =\gt a::B precise b}\) . The retraction part further states that \(\mathsf{t}\) is not only more precise than \(\mathsf{t::B::A}\) (which is given by the unit of the adjunction) but is equi-precise to it, noted \(\mathsf{t equiprecise t::B::A}\) . Because the DGG dictates that precision implies observational error-approximation, equi-precision implies observational equivalence, and so losing and recovering precision must produce a term that is observationally equivalent to the original one.
A couple of additional observations need to be made here, as they will play a major role in the development of this article:
These two approaches to characterizing gradual typing highlight the need to distinguish syntactic from semantic notions of precision. Indeed, with the usual syntactic precision from Siek et al. 2015, one cannot derive the ep-pair property, in particular, the equi-precision stated above. This is why New and Ahmed 2018 introduce a semantic precision, defined on well-typed terms. This semantic precision serves as a proxy between the syntactic precision and the desired observational error-approximation.
A type-based semantic precision cannot be used for the SGG. Indeed, this theorem (not addressed by New and Ahmed 2018) requires a syntactic notion of precision that predates typing: Well-typedness of the less precise term is the consequence of the theorem. Therefore, a full study of a gradual language that covers SGG, DGG, and embedding-projection pairs needs to consider both syntactic and semantic notions of precision.
The embedding-projection property does not per se imply the DGG: One could pick precision to be the universal relation, which trivially induces ep-pairs, but does not imply observational error-approximation. It appears that, in the simply-typed setting considered in prior work, the DGG implies the embedding-projection property. In fact, New and Ahmed 2018 essentially advocate ep-pairs as an elegant and compositional proof technique to establish the DGG. But as we uncover later in this article, it turns out that in certain settings—and, in particular, dependent types—the embedding-projection property imposes more desirable constraints on the behavior of casts than the DGG alone.
In this article, we use the term Graduality ( \(\mathcal {G}\) ) for the DGG established with respect to a notion of precision that also induces embedding-projection pairs.

2.5 The Gradual Approach: Dependent Types

Extending the gradual approach to a setting with full dependent types requires reconsidering several aspects.
Newcomers: the unknown term and the error type. In the simply-typed setting, there is a clear stratification: \(?\) is at the type level, \(\mathsf{raise}\) is at the term level. Likewise, type precision, with ? as greatest element, is separate from term precision, with \(\mathsf{raise}\) as least element. In the absence of a type/term syntactic distinction as in \(\mathsf {CIC}\) , this stratification is untenable:
Because types permeate terms, ? is no longer only the unknown type, but it also acts as the “unknown term”. In particular, this makes it possible to consider unknown indices for types, as in Example 1. More precisely, there is a family of unknown terms \(\mathsf{?_A}\) , indexed by their type \(\mathsf{A}\) . The traditional unknown type is just \(\mathsf{?_Type}\) , the unknown of the universe \(\mathsf{Type}\) .
Dually, because terms permeate types, we also have the “error type”, \(\mathsf{raise_Type}\) . We have to deal with errors in types.
Precision must be unified as a single preorder, with \(?\) at the top and \(\mathsf{raise}\) at the bottom. The most imprecise term of all is \(\mathtt {?_{?_\square }}\) ( \(?\) for short)—more exactly, there is one such term per type universe. At the bottom, \(\mathsf{raise_A}\) is the most precise term of type \(\mathsf{A}\) .
Revisiting safety. The notion of closed canonical forms used to characterize legitimate normal forms via safety ( \(\mathcal {S}\) ) needs to be extended not only with errors as in the simply-typed setting, but also with unknown terms. Indeed, as there is an unknown term \(\mathsf{?_A}\) inhabiting any type \(\mathsf{A}\) , we have one new canonical form for each type \(\mathsf{A}\) . In particular, \(\mathsf{?_bool}\) cannot possibly reduce to either \(\mathsf{true}\) or \(\mathsf{false}\) or \(\mathsf{raise_bool}\) , because doing so would collapse the precision order. Therefore, \(\mathsf{?_A}\) should propagate computationally, like \(\mathsf{raise_A}\) (Section 2.3).
The difference between errors and unknown terms is rather on their static interpretation. In essence, the unknown term \(\mathsf{?_A}\) is a dual form of exceptions: It propagates, but is optimistically comparable, i.e., consistent with, any other term of type \(\mathsf{A}\) . Conversely, \(\mathsf{raise_A}\) should not be consistent with any term of type \(\mathsf{A}\) . Going back to the issues we identified with the axiomatic (Section 2.2) and exceptional (Section 2.3) approaches when dealing with type-level computation, the term:
\(\mathsf{head nat ?_nat (filter nat 4 even [ 0 ; 1 ; 2 ; 3 ])}\) ,
now typechecks: \(\mathsf{vec A ?_nat}\) can be deemed consistent with \(\mathsf{vec A (S ?_nat)}\) , because \(\mathsf{S ?_nat}\) is consistent with \(\mathsf{?_nat}\) . This newly-brought flexibility is the key to support the different scenarios from the introduction. So let us now turn to the question of how to integrate consistency in a dependently-typed setting.
Relaxing conversion. In the simply-typed setting, consistency is a relaxing of syntactic type equality to account for imprecision. In a dependent type theory, there is a more powerful notion than syntactic equality to compare types, namely, conversion (Section 2.1): if \(\mathsf{t:T}\) and \(\mathsf{T == U}\) , then \(\mathsf{t:U}\) . For instance, a term of type \(\mathsf{T}\) can be used as a function as soon as \(\mathsf{T}\) is convertible to the type \(\mathsf{forall (a:A),B}\) for some types \(\mathsf{A}\) and \(\mathsf{B}\) . The proper notion to relax in the gradual dependently-typed setting is therefore conversion, not syntactic equality.
Garcia et al. 2016 give a general framework for gradual typing that explains how to relax any static type predicate to account for imprecision: for a binary type predicate \(\mathsf{P}\) , its consistent lifting \(\mathsf{Q(A,B)}\) holds iff there exist static types \(\mathsf{A^{\prime }}\) and \(\mathsf{B^{\prime }}\) in the denotation (concretization in abstract interpretation parlance) of \(\mathsf{A}\) and \(\mathsf{B}\) , respectively, such that \(\mathsf{P(A^{\prime },B^{\prime })}\) . As observed by Castagna et al. 2019, when applied to equality, this defines consistency as a unification problem. Therefore, the consistent lifting of conversion ought to be that two terms \(\mathsf{t}\) and \(\mathsf{u}\) are consistently convertible iff they denote some static terms \(\mathsf{t^{\prime }}\) and \(\mathsf{u^{\prime }}\) such that \(\mathsf{t^{\prime } == u^{\prime }}\) . This property is essentially higher-order unification, which is undecidable.
It is therefore necessary to adopt some approximation of consistent conversion (hereafter called consistency for short) in order to be able to implement a gradual dependent type theory. And there lies a great challenge: because of the absence of stratification between typing and reduction, the SGG already demands monotonicity for conversion, a demand very close to that of the DGG.7
Dealing with neutrals. Prior work on gradual typing usually only considers reduction on closed terms in order to establish results about the dynamics, such as the DGG. But in dependent type theory, conversion must operate on open terms, yielding neutral terms such as \(\mathsf{1::X::nat}\) where \(\mathsf{X}\) is a type variable, or \(\mathsf{x+1}\) where \(\mathsf{x}\) is of type \(\mathsf{nat}\) or \(\mathsf{?_Type}\) . Such neutral terms cannot reduce further, and can occur in both terms and types. Depending on the upcoming substitutions, neutrals can fail or not. For instance, in \(\mathsf{1::X::nat}\) , if \(\mathsf{?_Type}\) is substituted for \(\mathsf{X}\) , the term reduces to \(\mathsf{1}\) , but fails if \(\mathsf{bool}\) is substituted instead.
Importantly, less precise variants of neutrals can reduce more. For instance, both \(\mathsf{1::?_Type::nat}\) and \(\mathsf{?_nat+1}\) are less precise than the neutrals above, but do evaluate further (typically, to \(\mathsf{1}\) and to \(\mathsf{?_nat}\) , respectively). This interaction between neutrals, reduction, and precision spices up the goal of establishing DGG and \(\mathcal {G}\) . In particular, this re-enforces the need to consider semantic precision, because a syntactic precision is likely not to be stable by reduction: \(\mathsf{1::X::nat precise 1::?::nat}\) is obvious syntactically, but \(\mathsf{1::X::nat precise 1}\) is not.
DGG vs Graduality. In a dependently-typed setting, it is possible to satisfy the DGG while not satisfying the embedding-projection pairs requirement of \(\mathcal {G}\) . To see why, consider a system in which any term of type \(\mathsf{A}\) that is not fully-precise immediately reduces to \(\mathsf{?_A}\) . This system would satisfy \(\mathcal {C}\) , \(\mathcal {S}\) , \(\mathcal {N}\) , and ...the DGG. Recall that the DGG only requires reduction to be monotone with respect to precision, so using the most imprecise term \(\mathsf{?_A}\) as a universal redux is surely valid. This collapse of the DGG is impossible in the simply-typed setting because there is no unknown term: it is only possible when \(\mathsf{?_A}\) exists as a term. It is therefore possible to satisfy the DGG while being useless when computing with imprecise terms. Conversely, the degenerate system breaks the embedding-projection requirement of graduality stated by New and Ahmed 2018. For instance, \(\mathsf{1::?_Type::nat}\) would be convertible to \(\mathsf{?_nat}\) , which is not observationally equivalent to \(\mathsf{1}\) . Therefore, the embedding-projection requirement of graduality goes beyond the DGG in a way that is critical in a dependent type theory, where it captures both the smoothness of the static-to-dynamic checking spectrum, and the proper computational content of valid uses of imprecision.
Observational refinement. Let us come back to the notion of observational error-approximation used in the simply-typed setting to state the DGG. New and Ahmed 2018 justify this notion because in “gradual typing we are not particularly interested in when one program diverges more than another, but rather when it produces more type errors.” This point of view is adequate in the simply-typed setting because the addition of casts may only produce more type errors; in particular, adding casts can never lead to divergence when the original term does not diverge itself. Therefore, in that setting, the definition of error-approximation includes equi-divergence. The situation in the dependent setting is however more complicated, if the theory admits divergence. There exist non-gradual dependently-typed programming languages that admit divergence (e.g., Dependent Haskell Eisenberg 2016, Idris Brady 2013); we will also present one such theory in this article.
In a gradual dependent type theory that admits divergence, a diverging term is more precise than the unknown term \(?\) . Because the unknown term in itself does not diverge, this breaks the left-to-right implication of equi-divergence. Note that this argument does not rely on any specific definition of precision, just on the fact that the unknown term is the most imprecise term (at its type). Additionally, an error at a diverging type \(X\) may be ascribed to \(?_{[]}\) then back to \(X\) . Evaluating this roundtrip requires evaluating \(X\) itself, which makes the less precise term diverge. This breaks the right-to-left implication of equi-divergence.
To summarize, the way to understand these counterexamples is that in a dependent and non-terminating setting, the motto of graduality ought to be adjusted: More precise programs produce more type errors or diverge more. This leads to the following definition of observational refinement.
Definition 4 (Observational Refinement).
A term \(\Gamma \vdash t : A\) observationally refines a term \(\Gamma \vdash u : A\) , noted \(t \sqsubseteq ^{obs}u\) if for all Boolean-valued observation context \(\mathcal {C} : (\Gamma \vdash A) \Rightarrow (\vdash \mathbb {B}{})\) closing over all free variables, if \(\mathcal {C}[u] {\rm {\leadsto }^\ast }{\rm \mathtt {err}}_{\mathbb {B}}\) or diverges, then either \(\mathcal {C}[t] {\rm {\leadsto }^\ast }{\rm \mathtt {err}}_{\mathbb {B}}\) or \(\mathcal {C}[t]\) diverges.
In this definition, errors and divergence are collapsed. Thus, in a gradual dependent theory that admits divergence, equi-refinement does not imply observational equivalence, because one term might diverge, while the other reduces to an error. Of course, if the gradual dependent theory is strongly normalizing, then both notions \(\preccurlyeq ^{obs}\) (Definition 2) and \(\sqsubseteq ^{obs}\) (Definition 4) coincide.

2.6 The Fire Triangle of Graduality

To sum up, we have seen four important properties that can be expected from a gradual type theory: safety ( \(\mathcal {S}\) ), conservativity with respect to a theory \(X\) ( \(\mathcal {C}_{/{X}}\) ), graduality ( \(\mathcal {G}\) ), and normalization ( \(\mathcal {N}\) ). Any type theory ought to satisfy at least \(\mathcal {S}\) . Unfortunately, we now show that mixing the three other properties \(\mathcal {C}\) , \(\mathcal {G}\) , and \(\mathcal {N}\) is impossible for \(\mathsf {STLC}\) , as well as for \(\mathsf {CIC}\) .
Preliminary: regular reduction. To derive this general impossibility result, by relying only on the properties and without committing to a specific language or theory, we need to assume that the reduction system used to decide conversion is regular, in that it only looks at the weak head normal form of subterms for reduction rules, and does not magically shortcut reduction, for instance based on the specific syntax of inner terms. As an example, \(\beta\) -reduction is not allowed to look into the body of the lambda term to decide how to proceed.
This property is satisfied in all actual systems we know of, but formally stating it in full generality, in particular without devoting to a particular syntax, is beyond the scope of this article. Fortunately, in the following, we need only rely on a much weaker hypothesis, which is a slight strengthening of the retraction hypothesis of \(\mathcal {G}\) . Recall that retraction says that when \(\mathsf{A precise B}\) , any term \(\mathsf{t}\) of type \(\mathsf{A}\) is equi-precise to \(\mathsf{t::B::A}\) . We additionally require that for any context \(\mathsf{C}\) , if \(\mathsf{C[t]}\) reduces at least \(k\) steps, then \(\mathsf{C[t::B::A]}\) also reduces at least \(k\) steps. Intuitively, this means that the reduction of \(\mathsf{C[t::B::A]}\) , while free to decide when to get rid of the embedding-to- \(\mathsf{B}\) -projection-to- \(\mathsf{A}\) , cannot use it to avoid reducing \(\mathsf{t}\) . This property is true in all gradual languages, where type information at runtime is used only as a monitor.
Gradualizing \(\mathsf {STLC}\) . Let us first consider the case of \(\mathsf {STLC}\) . We show that \(\Omega\) is necessarily a well-typed diverging term in any gradualization of \(\mathsf {STLC}\) that satisfies the other properties.
Theorem 5 (Fire Triangle of Graduality for \(\mathsf {STLC}\) )
Suppose a gradual type theory that satisfies properties \(\mathcal {C}_{/{\mathsf {STLC}}}\) and \(\mathcal {G}\) . Then \(\mathcal {N}\) cannot hold.
Proof.
We pose \(\Omega := \delta ~(\delta \mathrel {::}?)\) with \(\delta := \lambda ~ x : ?.~(x\mathrel {::}? \rightarrow ?)~x\) and show that it must necessarily be a well-typed diverging term. Because the unknown type ? is consistent with any type (Section 2.4) and \(? \rightarrow ?\) is a valid type (by \(\mathcal {C}_{/{\mathsf {STLC}}}\) ), the self-applications in \(\Omega\) are well-typed, \(\delta\) has type \(? \rightarrow ?\) , and \(\Omega\) has type \(?\) . Now, we remark that \(\Omega = C[\delta ]\) with \(C[\cdot ] = [\cdot ]~(\delta \mathrel {::}?)\) .
We show by induction on \(k\) that \(\Omega\) reduces at least \(k\) steps, the initial case being trivial. Suppose that \(\Omega\) reduces at least \(k\) steps. By maximality of \(?\) with respect to precision, we have that \(? \rightarrow ? \sqsubseteq ?\) , so we can apply the strengthening of \(\mathcal {G}\) applied to \(\delta\) , which tells us that \(C[\delta \mathrel {::}?\mathrel {::}?\rightarrow ?]\) reduces at least \(k\) steps because \(C[\delta ]\) reduces at least \(k\) steps. But by \(\beta\) -reduction, we have that \(\Omega\) reduces in one step to \(C[\delta \mathrel {::}?\mathrel {::}?\rightarrow ?]\) . So \(\Omega\) reduces at least \(k+1\) steps.
This means that \(\Omega\) diverges, which is a violation of \(\mathcal {N}\) .□
This result could be extended to all terms of the untyped lambda calculus, not only \(\Omega\) , in order to obtain the embedding theorem of \(\mathsf {GTLC}\) Siek et al. 2015. Therefore, the embedding theorem is not an independent property, but rather a consequence of \(\mathcal {C}\) and \(\mathcal {G}\) —that is why we have not included it as such in our overview of the gradual approach (Section 2.4).
Gradualizing \(\mathsf {CIC}\) . We can now prove the same impossibility theorem for \(\mathsf {CIC}\) , by reducing it to the case of \(\mathsf {STLC}\) . Therefore, this theorem can be proven for type theories others than \(\mathsf {CIC}\) , as soon as they faithfully embed \(\mathsf {STLC}\) .
Theorem 6 (Fire Triangle of Graduality for \(\mathsf {CIC}\) )
A gradual dependent type theory cannot simultaneously satisfy properties \(\mathcal {C}_{/{\mathsf {CIC}}}\) , \(\mathcal {G}\) and \(\mathcal {N}\) .
Proof.
We show that a gradual dependent type theory satisfying \(\mathcal {C}_{/{\mathsf {CIC}}}\) and \(\mathcal {G}\) must contain a diverging term, thus contravening \(\mathcal {N}\) . The typing rules of \(\mathsf {CIC}\) contain the typing rules of \(\mathsf {STLC}\) , using only one universe \([]_0\) , where the function type is interpreted using the dependent product and the notions of reduction coincide, so \(\mathsf {CIC}\) embeds \(\mathsf {STLC}\) ; a well-known result on PTS Barendregt 1991. This means that \(\mathcal {C}_{/{\mathsf {CIC}}}\) implies \(\mathcal {C}_{/{\mathsf {STLC}}}\) . Additionally, \(\mathcal {G}\) can be specialized to the simply-typed fragment of the theory, by setting the unknown type \(?\) to be \(?_{[]_0}\) . Therefore, we can apply Theorem 5 and we get a well-typed term that diverges, finishing the proof.□
The Fire Triangle in practice. In non-dependent settings, all gradual languages where ? is universal admit non-termination and therefore compromise \(\mathcal {N}\) . Garcia and Tanter 2020 discuss the possibility to gradualize \(\mathsf {STLC}\) without admitting non-termination, for instance, by considering that ? is not universal and denotes only base types (in such a system, \(\mathsf{? -\gt ? nprecise ?}\) , so the argument with \(\Omega\) is invalid). Without sacrificing the universal unknown type, one could design a variant of \(\mathsf {GTLC}\) that uses some mechanism to detect divergence, such as termination contracts Nguyen et al. 2019. This would yield a language that certainly satisfies \(\mathcal {N}\) , but it would break \(\mathcal {G}\) . Indeed, because the contract system is necessarily over-approximating in order to be sound (and actually imply \(\mathcal {N}\) ), there are effectively-terminating programs with imprecise variants that yield termination contract errors.
To date, the only related work that considers the gradualization of full dependent types with ? as both a term and a type, is the work on GDTL Eremondi et al. 2019. GDTL is a programming language with a clear separation between the typing and execution phases, like Idris Brady 2013. GDTL adopts a different strategy in each phase: for typing, it uses Approximate Normalization (AN), which always produces \(\mathsf{?_A}\) as a result of going through imprecision and back. This means that conversion is both total and decidable (satisfies \(\mathcal {N}\) ), but it breaks \(\mathcal {G}\) for the same reason as the degenerate system we discussed in Section 2.5 (notice that the example uses a gain of precision from the unknown type to \(\mathsf{nat}\) , so the example behaves just the same with AN). In such a phased setting, the lack of computational content of AN is not critical, because it only means that typing becomes overly optimistic. To execute programs, GDTL relies on standard \(\mathsf {GTLC}\) -like reduction semantics, which is computationally precise, but does not satisfy \(\mathcal {N}\) .

3 \(\mathsf {GCIC}\) : Overall Approach, Main Challenges and Results

Given the Fire Triangle of Graduality (Theorem 6), we know that gradualizing \(\mathsf {CIC}\) implies making some compromise. Instead of focusing on one possible compromise, this work develops three novel solutions, each compromising one specific property ( \(\mathcal {N}\) , \(\mathcal {G}\) , or \(\mathcal {C}_{/{\mathsf {CIC}}}\) ), and does so in a common parametrized framework, \(\mathsf {GCIC}\) .
This section gives an informal, non-technical overview of our approach to gradualizing \(\mathsf {CIC}\) , highlighting the main challenges and results. As such, it serves as a gentle roadmap to the following sections, which are rather dense and technical.

3.1 \(\mathsf {GCIC}\) : 3-in-1

To explore the spectrum of possibilities enabled by the Fire Triangle of Graduality, we develop a general approach to gradualizing \(\mathsf {CIC}\) , and use it to define three theories, corresponding to different resolutions of the triangular tension between normalization ( \(\mathcal {N}\) ), graduality ( \(\mathcal {G}\) ), and conservativity with respect to \(\mathsf {CIC}\) ( \(\mathcal {C}_{/{\mathsf {CIC}}}\) ).
The crux of our approach is to recognize that, while there is not much to vary within \(\mathsf {STLC}\) itself to address the tension of the Fire Triangle of Graduality, there are several variants of \(\mathsf {CIC}\) that can be considered by changing the hierarchy of universes and its impact on typing—after all, \(\mathsf {CIC}\) is but a particular Pure Type System (PTS) Barendregt 1991.
In particular, we consider a parametrized version of a gradual \(\mathsf {CIC}\) , called \(\mathsf {GCIC}\) , with two parameters (Figure 3):
The first parameter characterizes how the universe level of a \(\Pi\) type is determined in typing rules: either as taking the maximum of the levels of the involved types, as in standard \(\mathsf {CIC}\) , or as the successor of that maximum. The latter option yields a variant of \(\mathsf {CIC}\) that we call \(\mathsf {CIC}^{\uparrow }\) (read “ \(\mathsf {CIC}\) -shift”). \(\mathsf {CIC}^{\uparrow }\) is a subset of \(\mathsf {CIC}\) , with a stricter constraint on universe levels. In particular, \(\mathsf {CIC}^{\uparrow }\) loses the closure of universes under dependent product that CIC enjoys. As a consequence, some well-typed \(\mathsf {CIC}\) terms are not well-typed in \(\mathsf {CIC}^{\uparrow }\) .8
The second parameter is the dynamic counterpart of the first parameter: Its role is to enforce that universe levels are coherent through type casts during the reduction of casts. Note that we only allow this reduction parameter to be loose (i.e., using maximum); if the typing parameter is also loose. Indeed, letting the typing parameter be strict (i.e., using successor), while the reduction parameter is loose breaks subject reduction, and hence \(\mathcal {S}\) .
Based on these parameters, this work develops the following three variants of \(\mathsf {GCIC}\) , whose properties are summarized in Table 1 with pointers to the respective theorems—because \(\mathsf {GCIC}\) is one common parametrized framework, we are able to establish most properties for all variants at once:
Table 1.
Table 1. \(\mathsf {GCIC}\) Variants and their Properties
(1)
\(\mathsf {GCIC} ^{\mathcal {G}}\) : A theory that satisfies both \(\mathcal {C}_{/{\mathsf {CIC}}}\) and \(\mathcal {G}\) , but sacrifices \(\mathcal {N}\) . This theory is a rather direct application of the principles discussed in Section 2 by extending \(\mathsf {CIC}\) with errors and unknown terms, and changing conversion with consistency. This results in a theory that is not normalizing.
(2)
\(\mathsf {GCIC} ^{\uparrow }\) : A theory that satisfies both \(\mathcal {N}\) and \(\mathcal {G}\) , and supports \(\mathcal {C}\) with respect to \(\mathsf {CIC}^{\uparrow }\) . This theory uses the universe hierarchy at the typing level to detect the potential non-termination induced by the use of consistency instead of conversion. This theory simultaneously satisfies \(\mathcal {G}\) , \(\mathcal {N}\) and \(\mathcal {C}_{/{\mathsf {CIC}^{\uparrow }}}\) .
(3)
\(\mathsf {GCIC} ^{\mathcal {N}}\) : A theory that satisfies both \(\mathcal {C}_{/{\mathsf {CIC}}}\) and \(\mathcal {N}\) , but does not fully validate \(\mathcal {G}\) . This theory uses the universe hierarchy at the computational level to detect potential divergence. Such runtime check failures invalidate the DGG for some terms, and hence \(\mathcal {G}\) , as well as the SGG.
Practical implications of \(\mathsf {GCIC}\) variants. Regarding the examples from Section 1, all three variants of \(\mathsf {GCIC}\) support the exploration of the type-level precision spectrum for the functions described in Examples 1, 3, and 4. In particular, we can define \(\mathsf{filter}\) by giving it the imprecise type \(\mathsf{forall A n (f : A -\gt bool), vec A n -\gt vec A ?_nat}\) in order to bypass the difficulty of precisely characterizing the size of the output vector. Any invalid optimistic assumption is detected during reduction and reported as an error.
Unsurprisingly, the semantic differences between the three \(\mathsf {GCIC}\) variants crisply manifest in the treatment of potential non-termination (Example 2), more specifically, self application. Let us come back to the term \(\Omega\) used in the proof of Theorem 6. In all three variants, this term is well-typed. In \(\mathsf {GCIC} ^{\mathcal {G}}\) , it reduces forever, as it would in the untyped lambda calculus. In that sense, \(\mathsf {GCIC} ^{\mathcal {G}}\) can embed the untyped lambda calculus just as GTLC Siek et al. 2015. In \(\mathsf {GCIC} ^{\mathcal {N}}\) , this term fails at runtime because of the strict universe check in the reduction of casts, which breaks graduality because \(\mathsf{?_Typei -\gt ? _Typei precise ?_Typei}\) tells us that the upcast-downcast coming from an ep-pair should not fail. A description of the reductions in \(\mathsf {GCIC} ^{\mathcal {G}}\) and in \(\mathsf {GCIC} ^{\mathcal {N}}\) is given in full details in Section 5.3. In \(\mathsf {GCIC} ^{\uparrow }\) , \(\mathsf{Omega}\) fails in the same way as in \(\mathsf {GCIC} ^{\mathcal {N}}\) , but this does not break graduality because of the shifted universe level on \(\Pi\) types. A consequence of this stricter typing rule is that in \(\mathsf {GCIC} ^{\uparrow }\) , \(\mathsf{?_Typei -\gt ?_Typei precise ?_Typej}\) for any \(j \gt i\) , but \(\mathsf{?_Typei -\gt ?_Typei nprecise ?_Typei}\) . Therefore, the casts performed in \(\Omega\) do not come from an ep-pair anymore and can legitimately fail.
Another scenario where the differences in semantics manifest is functions with dependent arities. For instance, the well-known C function \(\mathsf{printf}\) can be embedded in a well-typed fashion in \(\mathsf {CIC}\) : It takes as first argument a format string and computes from it both the type and number of later arguments. This function brings out the limitation of \(\mathsf {GCIC} ^{\uparrow }\) : Since the format string can specify an arbitrary number of arguments, we need as many \(\rightarrow\) , and \(\mathsf{printf}\) cannot typecheck in a theory where universes are not closed under function spaces. In \(\mathsf {GCIC} ^{\mathcal {N}}\) , \(\mathsf{printf}\) typechecks but the same problem will appear dynamically when casting \(\mathsf{printf}\) to \(?\) and back to its original type: The result will be a function that works only on format strings specifying no more arguments than the universe level at which it has been typechecked. Note that this constitutes an example of violation of graduality for \(\mathsf {GCIC} ^{\mathcal {N}}\) , even of the dynamic gradual guarantee. Finally, in \(\mathsf {GCIC} ^{\mathcal {G}}\) the function can be gradualized as much as one wants, without surprises.
Which variant to pick?. As explained in the introduction, the aim of this article is to shed light on the design space of gradual dependent type theories, not to advocate for one specific design. We believe the appropriate choice depends on the specific goals of the language designer, or perhaps more pertinently, on the specific goals of a given project, at a specific point in time.
The key characteristics of each variant are:
\(\mathsf {GCIC} ^{\mathcal {G}}\) favors flexibility over decidability of type-checking. While this might appear heretical in the context of proof assistants, this choice has been embraced by practical languages such as Dependent Haskell Eisenberg 2016, a dependently-typed Haskell where both divergence and runtime errors can happen at the type level. The pragmatic argument is simplicity: by letting programmers be responsible, there is no need for termination checking techniques and other restrictions.
\(\mathsf {GCIC} ^{\uparrow }\) is theoretically pleasing as it enjoys both normalization and graduality. In practice, though, the fact that it is not conservative wrt full \(\mathsf {CIC}\) means that one would not be able to simply import existing libraries as soon as they fall outside of the \(\mathsf {CIC}^{\uparrow }\) subset. In \(\mathsf {GCIC} ^{\uparrow }\) , the introduction of ? should be done with an appropriate understanding of universe levels. This might not be a problem for advanced programmers, but would surely be harder to grasp for beginners.
\(\mathsf {GCIC} ^{\mathcal {N}}\) is normalizing and able to import existing libraries without restrictions, at the expense of some surprises on the graduality front. Programmers would have to be willing to accept that they cannot just sprinkle ? as they see fit without further consideration, as any dangerous usage of imprecision will be flagged during conversion.
In the same way that systems like \(\mathrm{Coq}\) , Agda, or Idris support different ways to customize their semantics (such as allowing Type-in-Type, switching off termination checking, using the partial/total compiler flags)—and of course, many programming languages implementations supporting some sort of customization, GHC being a salient representative—one can imagine a flexible realization of \(\mathsf {GCIC}\) that give users the control over the two parameters we identify in this work, and therefore have access to all three \(\mathsf {GCIC}\) variants. Considering the inherent tension captured by the Fire Triangle of Graduality, such a pragmatic approach might be the most judicious choice, making it possible to gather experience and empirical evidence about the pros and cons of each in a variety of concrete scenarios.

3.2 Typing, Cast Insertion, and Conversion

As explained in Section 2.4, in a gradual language, whenever we reclaim precision, we might be wrong and need to fail in order to preserve safety ( \(\mathcal {S}\) ). In a simply-typed setting, the standard approach is to define typing on the gradual source language, and then to translate terms via a type-directed cast insertion to a target cast calculus, i.e., a language with explicit runtime type checks, needed for a well-behaved reduction Siek and Taha 2006 . For instance, in a call-by-value language, the upcast (loss of precision) \(\langle {?} {\ \Leftarrow \ } {\mathbb {N}} \rangle \,{10}\) is considered a (tagged) value, and the downcast (gain of precision) \(\langle {\mathbb {N}} {\ \Leftarrow \ } {?} \rangle \,{v}\) reduces successfully if \(v\) is such a tagged natural number, or to an error otherwise.
We follow a similar approach for \(\mathsf {GCIC}\) , which is elaborated in a type-directed manner to a second calculus, named, \(\mathsf {CastCIC}\) (Section 5.1). The interplay between typing and cast insertion is however more subtle in the context of a dependent type theory. Because typing needs computation, and reduction is only meaningful in the target language, \(\mathsf {CastCIC}\) is used as part of the typed elaboration in order to compare types (Section 5.2). This means that \(\mathsf {GCIC}\) has no typing on its own, independent of its elaboration to the cast calculus. 9
In order to satisfy conservativity with respect to \(\mathsf {CIC}\) ( \(\mathcal {C}_{/{\mathsf {CIC}}}\) ), ascriptions in \(\mathsf {GCIC}\) are required to satisfy consistency: For instance, \(\mathsf{true::?::nat}\) is well-typed by consistency (twice), but \(\mathsf{true::nat}\) is ill typed. Such ascriptions in \(\mathsf {CastCIC}\) are realized by casts. For instance \(0\mathrel {::}?\mathrel {::}\mathbb {B}\) in \(\mathsf {GCIC}\) elaborates (modulo sugar and reduction) to \(\langle {\mathbb {B}} {\ \Leftarrow \ } {?_{[]}} \rangle \,{\langle {?_{[]}} {\ \Leftarrow \ } {\mathbb {N}} \rangle \,{0}}\) in \(\mathsf {CastCIC}\) . A major difference between ascriptions in \(\mathsf {GCIC}\) and casts in \(\mathsf {CastCIC}\) is that casts are not required to satisfy consistency: A cast between any two types is well-typed, although of course it might produce an error.
Finally, standard presentations of \(\mathsf {CIC}\) use a standalone conversion rule, as usual in declarative presentations of type systems. To gradualize \(\mathsf {CIC}\) , we have to move to a more algorithmic presentation in order to forbid transitivity, otherwise all terms would be well-typed by way of a transitive step through \(\mathsf{?}\) . But \(\mathcal {C}_{/{\mathsf {CIC}}}\) demands that only terms with explicitly-ascribed imprecision enjoy its flexibility. This observation is standard in the gradual typing literature Siek and Taha 2006 2007 Garcia et al. 2016. As in prior work on gradual dependent types Eremondi et al. 2019, we adopt a bidirectional presentation of typing for \(\mathsf {CIC}\) (Section 4), which allows us to avoid accidental transitivity and directly derive a deterministic typing algorithm for \(\mathsf {GCIC}\) .

3.3 Realizing a Dependent Cast Calculus: \(\mathsf {CastCIC}\)

To inform the design and justify the reduction rules provided for \(\mathsf {CastCIC}\) , we build a syntactic model of \(\mathsf {CastCIC}\) by translation to \(\mathsf {CIC}\) augmented with induction-recursion Martin-Löf 1996 Dybjer and Setzer 2003 Ghani et al. 2015 (Section 6.1). From a type theory point of view, what makes \(\mathsf {CastCIC}\) peculiar is first of all the possibility of having errors (both “pessimistic” as \(\mathsf{raise}\) and “optimistic” as \(\mathsf{?}\) ), and the necessity to do intensional type analysis in order to resolve casts. For the former, we build upon the work of Pédrot and Tabareau 2018 on the exceptional type theory \(\mathsf {ExTT}\) . For the latter, we reuse the technique of Boulier et al. 2017 to account for \(\mathsf{typerec}\) , an elimination principle for the universe \(\mathsf{Type}\) , which requires induction-recursion to be implemented.
We call the syntactic model of \(\mathsf {CastCIC}\) the discrete model, in contrast with a semantic model motivated in the next subsection. The discrete model of \(\mathsf {CastCIC}\) captures the intuition that the unknown type is inhabited by “hiding” the underlying type of the injected term. In other words, \(\mathsf{?_Typei}\) behaves as a dependent sum \(\mathsf{Sigma A:Typei. A}\) . Projecting out of the unknown type is realized through type analysis ( \(\mathsf{typerec}\) ), and may fail (with an error in the \(\mathsf {ExTT}\) sense). Note that here, we provide a particular interpretation of the unknown term in the universe, which is legitimized by an observation made by Pédrot and Tabareau 2018: \(\mathsf {ExTT}\) does not constrain in any way the definition of exceptions in the universe. The syntactic model of \(\mathsf {CastCIC}\) allows us to establish that the reduction semantics enjoys strong normalization ( \(\mathcal {N}\) ), for the two variants \(\mathsf {CastCIC} ^{\mathcal {N}}\) and \(\mathsf {CastCIC} ^{\uparrow }\) . Together with safety ( \(\mathcal {S}\) ), this gives us weak logical consistency for \(\mathsf {CastCIC} ^{\mathcal {N}}\) and \(\mathsf {CastCIC} ^{\uparrow }\) .

3.4 Precisions and Properties

As explained earlier (Section 2.5), we need two different notions of precision to deal with SGG and \(\mathcal {G}\) . At the source level ( \(\mathsf {GCIC}\) ), we introduce a notion of syntactic precision that captures the intuition of a more imprecise term as “the same term with subterms and/or annotated types replaced by ?”, and is defined without any assumption of typing. In \(\mathsf {CastCIC}\) , we define a notion of structural precision, which is mostly syntactic except that, in order to account for cast insertion during elaboration, it tolerates precision-preserving casts (for instance, \(\langle {A} {\ \Leftarrow \ } {A} \rangle \,{t}\) is related to \(t\) by structural precision). Armed with these two notions of precision, we prove elaboration graduality (Theorem 24), which is the equivalent of SGG in our setting: If a term \(t\) of \(\mathsf {GCIC}\) elaborates to a term \(t^{\prime }\) of \(\mathsf {CastCIC}\) , then a term \(u\) less syntactically precise than \(t\) in \(\mathsf {GCIC}\) elaborates to a term \(u^{\prime }\) less structurally precise than \(t^{\prime }\) in \(\mathsf {CastCIC}\) .
Because DGG is about the behavior of terms, it is technically stated and proven for \(\mathsf {CastCIC}\) . We show in Section 5.5 that DGG can be proven for \(\mathsf {CastCIC}\) (in its variants \(\mathsf {CastCIC} ^{\mathcal {G}}\) and \(\mathsf {CastCIC} ^{\uparrow }\) ) on the structural precision. However, as explained in Section 2.4, we cannot expect to prove \(\mathcal {G}\) for these \(\mathsf {CastCIC}\) variants with respect to structural precision directly. In order to overcome this problem, we build an alternative model of \(\mathsf {CastCIC}\) called the monotone model (Sections 6.26.5). This model endows types with the structure of an ordered set, or poset. In the monotone model, we can reason about the semantic notion of propositional precision and prove that it gives rise to embedding-projection pairs New and Ahmed 2018, thereby establishing \(\mathcal {G}\) for \(\mathsf {CastCIC} ^{\uparrow }\) (Theorem 32). The monotone model only works for a normalizing gradual type theory, thus we then establish \(\mathcal {G}\) for \(\mathsf {CastCIC} ^{\mathcal {G}}\) using a variant of the monotone model based on Scott’s model Scott 1976 of the untyped \(\lambda\) -calculus using \(\omega\) -complete partial orders (Section 6.7).

4 Preliminaries: Bidirectional \(\mathsf {CIC}\)

We develop \(\mathsf {GCIC}\) on top of a bidirectional version of \(\mathsf {CIC}\) , whose presentation was folklore among type theory specialists McBride 2019, and that has recently been studied in details by Lennon-Bertrand 2021. As explained before, this bidirectional presentation is mainly useful to avoid multiple uses of a standalone conversion rule during typing, which becomes crucial to preserve \(\mathcal {C}_{/{\mathsf {CIC}}}\) in a gradual setting where conversion is replaced by consistency, which is not transitive. We give here a comprehensive summary of the bidirectional version of \(\mathsf {CIC}\) that will help the reader follow the presentation of \(\mathsf {GCIC}\) in Section 5.
Syntax. Our syntax for \(\mathsf {CIC}\) terms, featuring a predicative universe hierarchy \([]_i\) , is the following (in Backus-Naur form):
\begin{align} {\rm Term}_{\mathsf {CIC}} \ni t ::= x \mid \square {}_i \mid t~t \mid {\rm \lambda }x : t . t \mid {\rm \Pi }x : t . t \mid I@\lbrace i\rbrace (\mathbf {t}) \mid c@\lbrace i\rbrace (\mathbf {t},\mathbf {t}) \mid {\rm \mathtt {ind}}_{I}(t,z.t,f.\mathbf {y}.\mathbf {t}).\qquad {Syntax of \mathsf {CIC}} \end{align}
(1)
We reserve letters \(x,y, \rm and z\) to denote variables. Other lower-case and upper-case Roman letters are used to represent terms, with the latter used to emphasize that the considered terms should be thought of as types (although the difference does not occur at a syntactic level in this presentation). Finally Greek capital letters are for contexts (lists of declarations of the form \(x : T\) ). We also use bold letters \(\mathbf {X}\) to denote sequences of objects \(X_1,\ldots ,X_n\) and \(t[\mathbf {a} / \mathbf {y}]\) for the simultaneous substitution of \(\mathbf {a}\) for \(\mathbf {y}\) . We present generic inductive types \(I\) with constructors \(c\) , although we restrict to well-formed (and, in particular, strictly positive) ones to preserve normalization, following Giménez 1998. At this point we consider only inductive types without indices; we consider indexed inductive types in Section 7. Inductive types are formally annotated with a universe level \(@\lbrace i\rbrace\) , controlling the level of its parameters: for instance \({\rm List}@\lbrace i\rbrace (A)\) expects \(A\) to be a type in \([]_i\) . This level is omitted when inessential.
An inductive type at level \(i\) with parameters \(\mathbf {a}\) is noted \(I@\lbrace i\rbrace (\mathbf {a})\) , and we use \({\rm \mathbf {Params}}(I,i)\) to denote the types of those parameters. The well-formedness condition on inductives in, particular, enforces that the \(k\) th parameter \({\rm \mathbf {Params}}_k(I,i)\) only contains \(k-1\) variables, corresponding to the previous \(k-1\) parameters. Thus, if \(\mathbf {a}\) is a list of terms of the same length as \({\rm \mathbf {Params}}(I,i),\) we denote as \({\rm \mathbf {Params}}(I,i)[\mathbf {a}]\) the list where in parameter type \({\rm \mathbf {Params}}_k(I,i)\) , the \(k-1\) first elements of \(\mathbf {a}\) have been substituted for the \(k-1\) free variables. Similarly \(c_k^I@\lbrace i\rbrace (\mathbf {a},\mathbf {b})\) denotes the \(k\) th constructor of the inductive \(I\) , taking parameters \(\mathbf {a}\) and arguments \(\mathbf {b}\) . Again, the type of parameters is denoted \({\rm \mathbf {Params}}(I,i)\) , and the type of the arguments \({\rm \mathbf {Args}}(I,i,c_k)\) . Similarly as for parameters, we also use \({\rm \mathbf {Args}}(I,i,c_k)[\mathbf {a},\mathbf {b}]\) for the list where in the \(m\) th argument type \(\mathbf {a}\) have been substituted for parameter variables, and the first \(m-1\) elements of \(\mathbf {b}\) for argument variables.
The inductive eliminator \({\rm \mathtt {ind}}_{I}(s,z.P,f.\mathbf {y.t})\) corresponds to a fixpoint immediately followed by a match. In \(\mathrm{Coq}\) , one would write it
In particular, the return predicate \(P\) has access to an extra bound variable \(z\) for the scrutinee, and similarly the branches \(t_k\) are given access to variables \(f\) and \(\mathbf {y}\) , corresponding respectively to the recursive function and the arguments of the corresponding constructor. Describing the exact guard condition to ensure termination is outside the scope of this presentation, again see Giménez 1998. We implicitly assume in the rest of this article that every fixpoint is guarded.
Bidirectional Typing. In the usual, declarative, presentation of \(\mathsf {CIC}\) , conversion between types is allowed at any stage of a typing derivation through a free-standing conversion rule. However, when conversion is replaced by a non-transitive relation of consistency, this free-standing rule is much too permissive and would violate \(\mathcal {C}_{/{\mathsf {CIC}}}\) . Indeed, as every type should be consistent with the unknown type \(?_{\square {}}\) , using such a rule twice in a row makes it possible to change the type of a typable term to any arbitrary type: If \(\Gamma \vdash t : T\) , because \(T \sim ?_{[]}\) and \(?_{[]} \sim S\) , we could derive \(\Gamma \vdash t : S\) . This in turn would allow typeability of any term, including fully-precise terms, which is in contradiction with \(\mathcal {C}_{/{\mathsf {CIC}}}\) .
Thus, we rely on a bidirectional presentation of \(\mathsf {CIC}\) typing, presented in Figure 1, where the usual judgment \(\Gamma \vdash t : T\) is decomposed into several mutually-defined judgments. The difference between the judgments lies in the role of the type: In the inference judgment \(\Gamma \vdash t {\rm \triangleright }T\) , the type is considered an output, whereas in the checking judgment \(\Gamma \vdash t {\rm \triangleleft }T\) , the type is instead seen as an input. Conversion can then be restricted to specific positions, namely, to mediate between inference and checking judgments (see Check), and can thus never appear twice in a row.
Fig. 1.
Fig. 1. \(\mathsf {CIC}\) : Bidirectional typing.
Additionally, in the framework of an elaboration procedure, it is interesting to make a clear distinction between the subject of the rule (i.e., the object that is to be elaborated), inputs that can be used for this elaboration, and outputs that must be constructed during the elaboration. In the context checking judgment \(\vdash \Gamma\) , \(\Gamma\) is the subject of the judgment. In all the other judgments, the subject is the term, the context is an input, and the type is either an input or an output, as we just explained.
An important discipline, that goes with this distinction, is that judgments should ensure that outputs are well-formed, under the hypothesis that the inputs are. All rules are built to ensure this invariant. This distinction between inputs, subject, and output, and the associated discipline, are inspired by McBride 2018 2019. This is also the reason why no rule for term elaboration re-checks the context, as it is an input that is assumed to be well-formed. Hence, most properties we state in an open context involve an explicit hypothesis that the involved context is well-formed.
Constrained Inference. Apart from inference and checking, we also use a set of constrained inference judgments \(\Gamma \vdash t \blacktriangleright {\bullet } T\) , with the same modes as inference. These judgments infer the type \(T\) but under some constraint \(\bullet\) : for instance that it should be a universe at some level ( \(\bullet =\square {}\) ), a \(\Pi\) -type ( \(\bullet ={\rm \Pi }\) ), or an instance of an inductive \(I\) ( \(\bullet =\text{I}\) ). Constrained inference judgments come from a close analysis of typing algorithms, such as the one of \(\mathrm{Coq}\) , where in some places, an intermediate judgment between inference and checking happens: inference is performed, but then the type is reduced to expose its head constructor, which is imposed to be a specific one. A stereotypical example is App: One starts by inferring a type for \(t\) , but want it to be a \(\Pi\) -type so that its domain can be used to check \(u\) . To the best of our knowledge, these judgments have never been formally described elsewhere. Instead, in the rare bidirectional presentations of \(\mathsf {CIC}\) , they are inlined in some way, as they only amount to some reduction. However, this is no longer true in a gradual setting: \(?\) introduces an alternative, valid solution to the constrained inference, as a term of type \(?\) can be used where a term with a \(\Pi\) -type is expected. Thus, we will need multiple rules for constrained inference, which is why we make it explicit already at this stage.
Reduction. From here on, we impose no reduction strategy by default, and use \(\leadsto\) and the unqualified word “reduction” for full reduction, i.e., reduction that can be performed at an arbitrary place in a term, and \({\rm {\leadsto }^\ast }\) for its reflexive, transitive closure. Most of the properties would however carry over if we fixed weak-head reduction instead, and we sketch at the end of some proofs how they would carry over to such a fixed strategy. As uniqueness of inferred types and elaborated terms becomes stronger with a deterministic reduction strategy, we discuss weak-head reduction specifically in that case.
Finally, we observe that the equivalence of this bidirectional formulation with standard \(\mathsf {CIC}\) relies on the transitivity of conversion; This has been very recently spelled out in details and formalized by Lennon-Bertrand 2021. However, in the gradual setting, this property does not hold. This is precisely the point of using a bidirectional formulation: since consistency is not a transitive relation, a standard presentation of typing is not appropriate.

5 From \(\mathsf {GCIC}\) to \(\mathsf {CastCIC}\)

We now present the elaboration from the source gradual system \(\mathsf {GCIC}\) to the cast calculus \(\mathsf {CastCIC}\) . We start with \(\mathsf {CastCIC}\) , describing its typing, reduction, and metatheoretical properties (Section 5.1). We next describe \(\mathsf {GCIC}\) and its elaboration to \(\mathsf {CastCIC}\) , along with few direct properties (Section 5.2). This elaboration is mainly an extension of the bidirectional \(\mathsf {CIC}\) presented in the previous section. We illustrate the semantics of the different \(\mathsf {GCIC}\) variants by considering the \(\Omega\) term (Section 5.3). We finally expose technical properties of the reduction of \(\mathsf {CastCIC}\) (Section 5.4) used to prove the most important theorems on elaboration: conservativity over \(\mathsf {CIC}\) or \(\mathsf {CIC}^{\uparrow }\) , as well as the gradual guarantees (Section 5.5).

5.1 \(\mathsf {CastCIC}\)

Syntax. The syntax of \(\mathsf {CastCIC}\) 10 extends that of \(\mathsf {CIC}\) (Section 4) with three new term constructors: the unknown term \({?_T}\) and dynamic error \({{\rm \mathtt {err}}_T}\) of type \({T}\) , as well as the cast \({\langle {T} {\ \Leftarrow \ } {S} \rangle \,{t}}\) of a term \({t}\) of type \({S}\) to type \({T}\)
\begin{align} {{\rm Term}_{\mathsf {CastCIC}}} \ni {t} ::= \cdots \mid {?_t} \mid {{\rm \mathtt {err}}_t} \mid {\langle {t} {\ \Leftarrow \ } {t} \rangle \,{t}}, \qquad {Syntax of \mathsf {CastCIC}} \end{align}
(2)
with casts associating to the right: \({\langle {S^{\prime }} {\ \Leftarrow \ } {S} \rangle \,{\langle {T} {\ \Leftarrow \ } {T^{\prime }} \rangle \,{t}}}\) is \({\langle {S^{\prime }} {\ \Leftarrow \ } {S} \rangle \,{\left(\langle {T^{\prime }} {\ \Leftarrow \ } {T} \rangle \,{t}\right)}}\) . We also compress successive ones in the following way: \({\langle {T^{\prime \prime } \Leftarrow T^{\prime }} {\ \Leftarrow \ } {T} \rangle \,{t}}\) is shorthand for \({\langle {T^{\prime \prime }} {\ \Leftarrow \ } {T^{\prime }} \rangle \,{\langle {T^{\prime }} {\ \Leftarrow \ } {T} \rangle \,{t}}}\) . The unknown term and dynamic error both behave as exceptions as defined in \(\mathsf {ExTT}\) Pédrot and Tabareau 2018. Casts keep track of the use of consistency during elaboration, implementing a form of runtime type-checking, raising the error \({{\rm \mathtt {err}}_T}\) in case of a type mismatch. We call static the terms of \(\mathsf {CastCIC}\) that do not use any of these new constructors—static \(\mathsf {CastCIC}\) terms correspond to \(\mathsf {CIC}\) terms.
Universe parameters. \(\mathsf {CastCIC}\) is parametrized by two functions, described in Figure 2, to account for the three different variants of \(\mathsf {GCIC}\) we consider (Section 3.1). The first function \(s_\Pi\) computes the level of the universe of a dependent product, given the levels of its domain and codomain (see the updated Prod rule in Figure 3). The second function \(c_\Pi\) controls the universe level in the reduction of a cast between \(? \rightarrow ?\) and \(?\) (see Figure 5).
Fig. 2.
Fig. 2. Universe parameters.
Fig. 3.
Fig. 3. \(\mathsf {CastCIC}\) : Bidirectional typing (extending \(\mathsf {CIC}\) Figure 1, replacing Prod).
Typing. Figure 3 gives the typing rules for the three new primitives of \(\mathsf {CastCIC}\) . Apart from the modified Prod rule, which uses the \(s_\Pi\) parameter, all other typing rules are exactly the same as in \(\mathsf {CIC}\) . When disambiguation is needed, we note this typing judgment as \(\vdash _{{\rm \mathtt {cast}}}\) . The typing rules Unk and Err say that both \({?_T}\) and \({{\rm \mathtt {err}}_T}\) infer \({T}\) when \({T}\) is a type. Note that in \(\mathsf {CastCIC}\) , as is sometimes the case in cast calculi Siek and Wadler 2010 New and Ahmed 2018, no consistency premise is required for a cast to be well-typed. Here, consistency only plays a role in \(\mathsf {GCIC}\) , but disappears after elaboration. Instead, we rely on the usual conversion, defined as in \(\mathsf {CIC}\) as the existence of \(\alpha\) -equal reducts for the reduction described hereafter. The Case rule only ensures that both the source and target of the cast are indeed types, and that the casted term indeed has the source type.
Reduction. The typing rules provide little insight on the new primitives; the interesting part really lie in their reduction behavior. The reduction rules of \(\mathsf {CastCIC}\) are given in Figure 5 (congruence rules omitted). Reduction relies on two auxiliary functions relating head constructors \(h \in {\rm Head}\) (Figure 4) to those terms that start with either \(\Pi\) , \([]\) or \(I\) , the set of which we call \({\rm Type}_{\mathsf {CastCIC}}\) . The first is the function \(\mathrm{head}\,\) , which returns the head constructor of a type. In the other direction, the germ11 function \({\rm germ}_{i}\,h\) constructs the least precise type with head \(h\) at level \(i\) . In the case, where no such type exists (e.g., when \(c_\Pi (i) \lt 0\) ), this least precise type is the error.
Fig. 4.
Fig. 4. Head constructor and germ.
The design of the reduction rules is mostly dictated by the discrete and monotone models of \(\mathsf {CastCIC}\) presented later in Section 6. Nevertheless, we now provide some intuition about their meaning. Let us start with rules Prod-Unk, Prod-Err, Match-Unk, and Match-Err. These rules specify the exception-like propagation behavior of both \({?}\) and \({{\rm \mathtt {err}}}\) at product and inductive types. Rules Ind-Unk and Ind-Err similarly propagate \({?}\) and \({{\rm \mathtt {err}}}\) when cast between the same inductive type, and rules Down-Unk and Down-Err do the same from the unknown type to any type \({X}\) .
Next are rules Prod-Prod, Ind-Ind, and Univ-Univ, which correspond to success cases of dynamic checks, where the cast is between types with the same head. In that case, casts are either completely erased when possible, or propagated. As usual in gradual typing, directly inspired by higher-order contracts Findler and Felleisen 2002, Prod-Prod distributes the function cast in two casts, one for the argument and one for the body; note the substitution in the source codomain in order to account for dependency. Also, because constructors and inductives are fully-applied, this Prod-Prod rule cannot be blocked on a partially-applied constructor or inductive. Regarding inductive types, the restriction to reduce only on constructors means that a cast between \({\mathbb {N}}\) and \({\mathbb {N}}\) is blocked until its argument term is a constructor, rather than disappearing right away as for the universe. We follow this somewhat non-optimal strategy to be consistent between inductive types, because for more complex inductive types such as lists, the propagation of casts on subterms cannot be avoided.
On the contrary, rule Head-Err specifies failure of a dynamic check when the considered types have different heads. Similarly, rules Dom-Err, Codom-Err specify that cast to or from the error type is always an error.
Finally, there are specific rules pertaining to casts to and from \({?}\) , showcasing its behavior as a universal type. Rules Prod-Germ and Ind-Germ decompose an upcast into \({?}\) as an upcast to a germ followed by an upcast from the germ to \({?}\) . This decomposition of an upcast to \({?}\) into a series of “atomic” upcasts from a germ to \({?}\) is a consequence of the way the cast operation is implemented in Section 6, but similar decompositions appear, e.g., in Siek et al. 2015, where the equivalent of our germs are called ground types. The side conditions guarantee that this rule is used when no other applies. Rule Up-Down erases the succession of an upcast to \({?}\) and a downcast from it. Note that in this rule the upcast \({\langle {?_{[]_i}} {\ \Leftarrow \ } {{\rm germ}_{h}\,i} \rangle \,{t}}\) works like a constructor for \({?_{[]_i}}\) and \({\langle {X} {\ \Leftarrow \ } {?_{[]_i}} \rangle \,{}}\) as a destructor—a view reflected by the canonical and neutral forms of Figure 7 for \({?_{[]}}\) .12 Finally, rule Size-Err corresponds to a peculiar kind of error, which only happens due to the presence of a type hierarchy: \({?_{[]_i}}\) is only universal with respect to types at level \(i\) , and so a type might be of a level too high to fit into it. To detect such a case, we check whether \(A\) is a germ for a level that is below \(i\) , and when not throw an error.
Meta-Theoretical Properties. The typing and reduction rules just given ensure two of the meta-theoretical properties introduced in Section 2: \(\mathcal {S}\) for the three variants of \(\mathsf {CastCIC}\) , as well as \(\mathcal {N}\) for \(\mathsf {CastCIC} ^{\mathcal {N}}\) and \(\mathsf {CastCIC} ^{\uparrow }\) . Before turning to these properties, let us establish a crucial lemma, namely, the confluence of the rewriting system induced by reduction.
Lemma 7 (Confluence of \(\mathsf {CastCIC}\) )
If \({t}\) and \({u}\) are related by the symmetric, reflexive, transitive closure of \(\leadsto\) , then there exists \(s\) such that \({t} {\rm {\leadsto }^\ast }{s}\) and \({u} {\rm {\leadsto }^\ast }{s}\) .
Proof.
We extend the notion of parallel reduction ( \(\Rrightarrow\) ) for \(\mathsf {CIC}\) from Sozeau et al. 2020 to account for our additional reduction rules and show that the triangle property—the existence, for any term \(t\) , of an optimal reduced term \({\rho (t)}\) in one step (Figure 6(a))—still holds. From the triangle property, it is easy to deduce confluence of parallel reduction in one step (Figure 6(b)), which implies confluence because parallel reduction is between one-step reduction and iterated reductions. This proof method is basically an extension of the Tait-Martin Löf criterion on parallel reduction Barendregt 1984 Takahashi 1995.□
Let us now turn to \(\mathcal {S}\) , which we prove using the standard progress and subject reduction properties Wright and Felleisen 1994. Progress describes a set of canonical forms, asserting that all terms that do not belong to such canonical forms are not in normal form, i.e., can take at least one reduction step. Figure 7 provides the definition of canonical forms, considering head reduction.
As standard in dependent type theories, we distinguish between canonical forms and neutral terms. Neutral terms correspond to (blocked) destructors, waiting for a substitution to happen, while other canonical forms correspond to constructors. Additionally, the notion of neutral terms naturally induces a weak-head reduction strategy that consists of either applying a top-level reduction or reducing the (only) argument of the top-level destructor that is in a neutral position.
The canonical forms for plain \(\mathsf {CIC}\) are given by the first three lines of Figure 7. The added rules deal with errors, unknown terms, and casts. First, an error \({{\rm \mathtt {err}}_t}\) or an unknown term \({?_t}\) is neutral when \({t}\) is neutral, and is canonical only when \({t}\) is \({[]}\) or \({I(\mathbf {a})}\) , but not a \(\Pi\) -type. This is because exception-like terms reduce on \(\Pi\) -types Pédrot and Tabareau 2018. Second, there is an additional specific form of canonical inhabitants of \({?_{[]}}\) : These are upcasts from a germ, which can be seen as a term tagged with the head constructor of its type, in a matter reminiscent of actual implementations of dynamic typing using type tags. As we explained when presenting Figure 5, these canonical forms work as constructors for \({?_{[]}}\) . Finally, the cast operation behaves as a destructor on the universe \({[]}\) —as if it were an inductive type of usual \(\mathsf {CIC}\) . This destructor first scrutinizes the source type of the cast. This is why the cast is neutral as soon as its source type is neutral. When the source type reduces to a head constructor, there are two possibilities. Either that constructor is \({?_{[]}}\) , in which case the cast scrutinizes its argument to be a canonical form \({\langle {?_{[]}} {\ \Leftarrow \ } {t} \rangle \,{{\rm germ}_{i}\,h}}\) and is neutral when this is not the case. In all other cases, it first scrutinizes the target type, so the cast is neutral when the target type is neutral. Finally, when both types have head constructors, the cast might still need its argument to be either a \(\lambda\) -abstraction or an inductive constructor to reduce.
Fig. 5.
Fig. 5. \(\mathsf {CastCIC}\) : Reduction rules (extending Figure 1, congruence rules omitted).
Fig. 6.
Fig. 6. Representation of the triangle property (left) and its consequence on confluence (right).
Equipped with the notion of canonical forms, we can state \(\mathcal {S}\) for \(\mathsf {CastCIC}\) :
Theorem 8 (Safety of the Three Variants of \(\mathsf {CastCIC}\)
( \(\mathcal {S}\) )) \(\mathsf {CastCIC}\) enjoys:
lsquarersquare Progress:If \({t}\) is a well-typed term of \(\mathsf {CastCIC}\) , then either \({\rm canonical}{t}\) or there is some \({t^{\prime }}\) such that \({t} \leadsto {t^{\prime }}\) .
lsquarersquare Subject reduction: if \({\Gamma } \vdash _{{\rm \mathtt {cast}}}{t} {\rm \triangleright }{A}\) and \({t} \leadsto {} {t^{\prime }}\) then \({\Gamma } \vdash _{{\rm \mathtt {cast}}}{t^{\prime }} {\rm \triangleleft }{A}\) .
Thus, \(\mathsf {CastCIC}\) enjoys \(\mathcal {S}\) .
Proof.
The proof is by induction on the typing derivation of \({t}\) . As standard, we show that in all cases, either a reduction on a subterm happens, \({t}\) itself reduces because some canonical form was not neutral and creates a redex, or \({t}\) is neutral.
lsquarersquare Subject reduction: Subject reduction can be derived from the injectivity of type constructors, which is a direct consequence of confluence. See Sozeau et al. 2020 for a detailed account of this result in the simpler setting of \(\mathsf {CIC}\) .  
We now establish normalization of \(\mathsf {CastCIC} ^{\mathcal {N}}\) and \(\mathsf {CastCIC} ^{\uparrow }\) , although the proof below relies on the discrete model defined in Section 6.1.
Theorem 9 (Normalization of \(\mathsf {CastCIC} ^{\mathcal {N}}\) and \(\mathsf {CastCIC} ^{\uparrow }\)
( \(\mathcal {N}\) )) Every reduction path for a well-typed term in \(\mathsf {CastCIC} ^{\mathcal {N}}\) or \(\mathsf {CastCIC} ^{\uparrow }\) is finite.
Proof.
The translation induced by the discrete model presented in Section 6.1 maps each reduction step to at least one step (Theorem 26). So strong normalization holds because the target calculus of the translation is normalizing.□

5.2 Elaboration from \(\mathsf {GCIC}\) to \(\mathsf {CastCIC}\)

Now that \(\mathsf {CastCIC}\) has been described, we move on to \(\mathsf {GCIC}\) . The typing judgment of \(\mathsf {GCIC}\) is defined by an elaboration judgment from \(\mathsf {GCIC}\) to \(\mathsf {CastCIC}\) , based upon Figure 1, augmenting all judgments with an extra output: the elaborated \(\mathsf {CastCIC}\) term. This definition of typing using elaboration is required because of the intricate interdependency between typing and reduction exposed in Section 3.
Syntax. The syntax of \(\mathsf {GCIC}\) 13 extends that of \(\mathsf {CIC}\) with a single new term constructor \({?@\lbrace i\rbrace }\) , where \(i\) is a universe level. From a user perspective, one is not given direct access to the failure and cast primitives, those only arise through uses of \({?}\) .
Consistent conversion. Before we can describe typing, we should focus on conversion. Indeed, to account for the imprecision introduced by \({?}\) , elaboration employs consistent conversion to compare \(\mathsf {CastCIC}\) terms rather than usual conversion relation.
Definition 5 (Consistent Conversion).
Two \(\mathsf {CastCIC}\) terms are \(\alpha\) -consistent, written \(\sim _{\alpha }\) , if they are in the relation defined by the inductive rules of Figure 8.
Two terms are consistently convertible, or simply consistent, noted \({s} \sim {t}\) , if and only if there exists \({s^{\prime }}\) and \({t^{\prime }}\) such that \({s} {\rm {\leadsto }^\ast }{s^{\prime }}\) , \({t} {\rm {\leadsto }^\ast }{t^{\prime }}\) and \({s^{\prime }} \sim _{\alpha }{t^{\prime }}\) .
Thus \(\alpha\) -consistency is an extension of \(\alpha\) -equality that takes imprecision into account. Apart from the standard rules making \({?}\) consistent with any term, \(\alpha\) -consistency optimistically ignores casts, and does not consider errors to be consistent with themselves. The first point is to prevent casts inserted by the elaboration from disrupting valid conversions, typically between static terms. The second is guided by the idea that if errors are encountered at elaboration already, the term cannot be well behaved, so it must be rejected as early as possible and we should avoid typing it. The consistency relation is then built upon \(\alpha\) -consistency in a way totally similar to how conversion in Figures 1 and 5 is built upon \(\alpha\) -equality. Also note that this formulation of consistent conversion makes no assumption of normalization, and is therefore usable as such in the non-normalizing \(\mathsf {GCIC} ^{\mathcal {G}}\) .
An important property of consistent conversion, and a necessary condition for the conservativity of \(\mathsf {GCIC}\) with respect to \(\mathsf {CIC}\) ( \(\mathcal {C}_{/{\mathsf {CIC}}}\) ), is that it corresponds to conversion on static terms.
Proposition 10 (Properties of Consistent Conversion).
(1)
Two static terms are consistently convertible if and only if they are convertible in \(\mathsf {CIC}\) .
(2)
If \({s}\) and \({t}\) have a normal form, then \({s} \sim {t}\) is decidable.
Proof.
(1) First remark that \(\alpha\) -consistency between static terms corresponds to \(\alpha\) -equality of terms. Thus, and because the reduction of static terms in \(\mathsf {CastCIC}\) is the same as the reduction of \(\mathsf {CIC}\) , two consistent static terms must reduce to \(\alpha\) -equal terms, which, in turn, implies that they are convertible. Conversely two convertible terms of \(\mathsf {CIC}\) have a common reduct, which is \(\alpha\) -consistent with itself.
(2) If \({s}\) and \({t}\) are normalizing, they have a finite number of reducts, thus to decide their consistency it is sufficient to check each pair of reducts for the decidable \(\alpha\) -consistency. Comparing normal forms is not enough, because a term \({t}\) might be stuck because of a cast, while another one \({s}\) can be \(\alpha\) -consistent with it and reduce further, so that the normal form of \({t}\) and \({s}\) are not \(\alpha\) -consistent while \({t}\) and \({s}\) are consistent.□
Elaboration. Elaboration from \(\mathsf {GCIC}\) to \(\mathsf {CastCIC}\) is given in Figure 9, closely following the bidirectional presentation of \(\mathsf {CIC}\) (Figure 1) for most rules, simply carrying around the extra elaborated terms. Note that only the subject of the judgment is a source term in \(\mathsf {GCIC}\) ; other inputs (that have already been elaborated), as well as outputs (that are to be constructed), are target terms in \(\mathsf {CastCIC}\) . Let us comment a bit on the specific modifications and additions compared to Figure 1.
The most salient feature of elaboration is the insertion of casts that mediate between merely consistent but not convertible types. They of course are needed in the rule Check where the terms are compared using consistency. But this is not enough: Casts also appear in the newly-introduced rules Inf-Univ? Inf-Prod? and Inf-Ind? for constrained inference, where the type \({?_{[]_i}}\) is replaced by the least precise type of the appropriate universe level having the constrained head constructor, which is exactly what the \({\rm germ}\) function gives us. Note that in the case of Inf-Univ? we could have replaced \({[]_i}\) with \({{\rm germ}_{i+1}\,[]_i}\) to make for a presentation similar to the other two rules. The role of these three rules is to ensure that a term of type \({?_{[]_i}}\) can be used as a function, or as a scrutinee of a match, by giving a way to derive constrained inference for such a term.
It is interesting to observe that the rules for constrained elaboration in a gradual setting bear a close resemblance with those described by Cimini and Siek 2016Section 3.3, where a matching operator is introduced to verify that an output type can fit into a certain type constructor—either by having that type constructor as head symbol or by virtue of being \(?\) . Such a form of matching was already present in our static, bidirectional system, because of the presence of reduction in types. In a way, both Cimini and Siek 2016 and Lennon-Bertrand 2021 have the same need of separating the inferred type from operations on it to recover its head constructor, and our mixing of both computation and gradual typing makes that need even clearer.
Rule Unk also deserves some explanation: \({?@\lbrace i\rbrace }\) is elaborated to \({?_{?_{[]_i}}}\) , the least precise term of the least precise type of the whole universe \({[]_i}\) . This avoids unneeded type annotations on \({?}\) in \(\mathsf {GCIC}\) . Instead, the context is responsible for inserting the appropriate cast, e.g., \({?\mathrel {::}T}\) elaborates to a term reducing to \({?_T}\) . We do not drop annotations altogether because of an important property on which bidirectional \(\mathsf {CIC}\) is built: any well-formed term should infer a type, not just check. Thus, we must be able to infer a type for \({?}\) . The obvious choice is to have \({?}\) infer \({?}\) , but this \({?}\) is a term of \(\mathsf {CastCIC}\) , and thus needs a type index. Because this \({?}\) is used as a type, this index must be \({[]}\) , and the universe level of the source \({?}\) is there to give us the level of this \({[]}\) . In a real system, this should be handled by typical ambiguity,14 alleviating the user from the need to give any annotations when using \({?}\) .
Direct properties. As the elaboration rules are completely syntax-directed, they immediately translate to an algorithm for elaboration. Coupled with decidability of consistency (Proposition 10), this makes elaboration decidable whenever \({\rm {\leadsto }^\ast }\) is normalizing; when \({\rm {\leadsto }^\ast }\) is not normalizing, the elaboration algorithm might diverge, resulting in only semi-decidability of typing (as in, for instance, Dependent Haskell Eisenberg 2016).
Theorem 11 (Decidability of Elaboration).
The relations of inference, checking and partial inference of Figure 9 are decidable in \(\mathsf {GCIC} ^{\mathcal {N}}\) and \(\mathsf {GCIC} ^{\uparrow }\) . They are semi-decidable in \(\mathsf {GCIC} ^{\mathcal {G}}\) .
Let us now establish two important properties of elaboration that we can prove at this stage: elaboration is correct, insofar as it produces well-typed \(\mathsf {CastCIC}\) terms, and functional, in the sense that a given \(\mathsf {GCIC}\) term can be elaborated to at most one \(\mathsf {CastCIC}\) term up to conversion.
Theorem 12 (Correctness of Elaboration).
The elaboration produces well-typed terms in a well-formed context. Namely, given \({\Gamma }\) such that \(\vdash _{{\rm \mathtt {cast}}}{\Gamma }\) , we have that
if \({\Gamma } \vdash {\tilde{t}} {\rm \rightsquigarrow }{t} {\rm \triangleright }{T}\) , then \({\Gamma } \vdash _{{\rm \mathtt {cast}}}{t} {\rm \triangleright }{T}\) ;
if \({\Gamma } \vdash {\tilde{t}} {\rm \rightsquigarrow }{t} \blacktriangleright {\bullet } {T}\) then \({\Gamma } \vdash _{{\rm \mathtt {cast}}}{t} \blacktriangleright {\bullet } {T}\) (with \(\bullet\) denoting the same index in both derivations);
if \({\Gamma } \vdash {\tilde{t}} {\rm \triangleleft }{T} {\rm \rightsquigarrow }{t}\) and \({\Gamma } \vdash _{{\rm \mathtt {cast}}}{T} \blacktriangleright {[]} {[]_i}\) , then \({\Gamma } \vdash _{{\rm \mathtt {cast}}}{t} {\rm \triangleleft }{T}\) .
Proof.
The proof is by induction on the elaboration derivation, mutually with similar properties for all typing judgments. In particular, for checking, we have an extra hypothesis that the given type is well-formed, as it is an input that should already have been typed.
Because the bidirectional typing rules of \(\mathsf {CIC}\) are very similar to the \(\mathsf {GCIC}\) -to- \(\mathsf {CastCIC}\) elaboration rules, the induction is mostly routine. Let us point however that the careful design of the bidirectional rules already in \(\mathsf {CIC}\) regarding the input/output separation is important here. Indeed, we have that inputs to the successive premises of a rule are always well-formed, either as inputs to the conclusion, or thanks to previous premises. In particular, all context extensions are valid, i.e., \({\Gamma , x : A}\) is used only when \({\Gamma } \vdash {A} \blacktriangleright {[]} {[]_i}\) , and similarly only well-formed types are used for checking. This ensures that we can always use the induction hypothesis.
The only novel points to consider are the rules where a cast is inserted. For these, we rely on the validity property (an inferred type is always well-typed itself) to ensure that the domain of inserted casts is well-typed, and thus that the casts can be typed.□
Because of the absence of a fixed, deterministic reduction strategy, the elaborated term is not unique. Indeed, since a type can be reduced to multiple product types in rule Section Prod, a term can infer multiple, different types, and since those appear later on in casts, the elaborated terms can differ by having different, albeit convertible, types in their casts. We thus state two theorems: One is uniqueness up to conversion, in case full reduction is used. The second is a strengthening if a weak-head reduction strategy is imposed for reduction.
Theorem 13 (Uniqueness of Elaboration—Full Reduction).
Elaborated terms are convertible
if \({\Gamma } \vdash {\tilde{t}} {\rm \rightsquigarrow }{t} {\rm \triangleright }{T}\) and \({\Gamma } \vdash {\tilde{t}} {\rm \rightsquigarrow }{t^{\prime }} {\rm \triangleright }{T^{\prime }}\) , then \({t} \equiv {t^{\prime }}\) and \({T} \equiv {T^{\prime }}\) ;
if \({\Gamma } \vdash {\tilde{t}} {\rm \rightsquigarrow }{t} \blacktriangleright {\bullet } {T}\) and \({\Gamma } \vdash {\tilde{t}} {\rm \rightsquigarrow }{t^{\prime }} \blacktriangleright {\bullet } {T^{\prime }}\) then \({t} \equiv {t^{\prime }}\) and \({T} \equiv {T^{\prime }}\) ;
if \({\Gamma } \vdash {\tilde{t}} {\rm \triangleleft }{T} {\rm \rightsquigarrow }{t}\) and \({\Gamma } \vdash {\tilde{t}} {\rm \triangleleft }{T} {\rm \rightsquigarrow }{t^{\prime }}\) then \({t} \equiv {t^{\prime }}\) .
(Recall that conversion \(\equiv\) in \(\mathsf {CastCIC}\) is defined (similarly as in \(\mathsf {CIC}\) ) as the existence of \(\alpha\) -equal reducts for the reduction given in Figure 5.)
Theorem 14 (Uniqueness of Elaboration—Weak-head Reduction).
If in Figure 9, \({\rm {\leadsto }^\ast }\) is replaced by weak-head reduction, then elaborated terms are unique
Given \({\Gamma }\) and \({\tilde{t}}\) , there is at most one \({t}\) and one \({T}\) such that \({\Gamma } \vdash {\tilde{t}} {\rm \rightsquigarrow }{t} {\rm \triangleright }{T}\) .
Given \({\Gamma }\) and \({\tilde{t}}\) , there is at most one \({t}\) and one \({T}\) such that \({\Gamma } \vdash {\tilde{t}} {\rm \rightsquigarrow }{t} \blacktriangleright {\bullet } {T}\) .
Given \({\Gamma }\) , \({\tilde{t}}\) and \({T}\) , there is at most one \({t}\) such that \({\Gamma } \vdash {\tilde{t}} {\rm \triangleleft }{T} {\rm \rightsquigarrow }{t}\) .
Proof.
Like for Theorem 12, those are proven mutually by induction on the typing derivation.
The main argument is that there is always at most one rule that can apply to get a typing conclusion for a given term. This is true for all inference statements because there is exactly one inference rule for each term constructor, and for checking because there is only one rule to derive checking. In those cases simply combining the hypothesis of uniqueness is enough.
For \(\blacktriangleright {\Pi }\) , by confluence of \(\mathsf {CastCIC}\) the inferred type cannot at the same time reduce to \({?_{\square {}}}\) and \({{\rm \Pi }x : A . B}\) , because those do not have a common reduct. Thus, only one of the two rules Inf-Prod and Inf-Prod? can apply. It is enough to conclude for Theorem 13, because reducts of convertible types are still convertible. For Theorem 14 the deterministic reduction strategy ensures that the inferred type is indeed unique, rather than unique up to conversion. The reasoning is similar for the other constrained inference judgments.□

5.3 Illustration: Back to Omega

Now that \(\mathsf {GCIC}\) has been entirely presented, let us come back to the important example of \({\Omega }\) , and explain in detail the behavior described in Section 3.1 for the three \(\mathsf {GCIC}\) variants.
Recall that \({\Omega }\) is the term \({\delta ~\delta }\) , with \({\delta } := {{\rm \lambda }x : ?@\lbrace i+1\rbrace . x~x}\) . We leave out the casts present in Sections 2 and 3, knowing that they will be introduced by elaboration. We also use \({?}\) at level \(i + 1\) , because \({?@\lbrace i+1\rbrace }\) , when elaborated as a type, becomes \({T} := {\langle {[]_i} {\ \Leftarrow \ } {?_{[]_{i+1}}} \rangle \,{?_{?_{[]_{i+1}}}}}\) , such that \({T} {\rm {\leadsto }^\ast }{?_{[]_i}}\) . For the rest of this section, we write \({?_{j}}\) instead of \({?_{[]_j}}\) to avoid stacked indices and ease readability.
If \(i = 0\) the elaboration of \({\delta }\) (and thus of \({\Omega }\) ) fails in \(\mathsf {GCIC} ^{\uparrow }\) and \(\mathsf {GCIC} ^{\mathcal {N}}\) , because the inferred type for \(x\) is \({T}\) , which reduces to \({?_0}\) . Then, because \(c_\Pi (0) = -1 \lt 0\) in both \(\mathsf {GCIC} ^{\uparrow }\) and \(\mathsf {GCIC} ^{\mathcal {N}}\) , rule Inf-Prod? does not apply and \({\delta }\) is deemed ill-typed, as is \({\Omega }\) .
Otherwise, if \(i \gt 0\) or we are considering \(\mathsf {GCIC} ^{\mathcal {G}}\) , \({\delta }\) can be elaborated, and we have
\begin{equation*} {\cdot } \vdash {\delta } {\rm \rightsquigarrow }{{{\rm \lambda }x : T . \left(\langle {{\rm germ}_{i}\,\Pi } {\ \Leftarrow \ } {T} \rangle \,{x} \right)~\left(\langle {?_{c_\Pi (i)}} {\ \Leftarrow \ } {T} \rangle \,{x} \right)}} {\rm \triangleright }{T \rightarrow ?_{c_\Pi (i)}}. \end{equation*}
From this, we get that \({\Omega }\) also elaborates, namely (with \({\delta ^{\prime }}\) the elaboration of \({\delta }\) above)
\begin{equation*} {\cdot } \vdash {\Omega } {\rm \rightsquigarrow }{\delta ^{\prime }~\left(\langle {T} {\ \Leftarrow \ } {T \rightarrow ?_{c_\Pi (i)}} \rangle \,{\delta ^{\prime }}\right)} {\rm \triangleright }{?_{c_\Pi (i)}}. \end{equation*}
Let us now look at the reduction behavior of this elaborated term \({\Omega ^{\prime }}\) in the three systems: It reduces seamlessly when \(c_\Pi (i) = i\) ( \(\mathsf {GCIC} ^{\mathcal {G}}\) / \(\mathsf {CastCIC} ^{\mathcal {G}}\) ), while having \(c_\Pi (i) \lt i\) makes it fail ( \(\mathsf {GCIC} ^{\uparrow }\) / \(\mathsf {CastCIC} ^{\uparrow }\) and \(\mathsf {GCIC} ^{\mathcal {N}}\) / \(\mathsf {CastCIC} ^{\mathcal {N}}\) ). The reduction of \({\Omega ^{\prime }}\) in \(\mathsf {CastCIC} ^{\mathcal {G}}\) is as follows:
The first step is the identity, simply replacing \({\Omega ^{\prime }}, c_\Pi (i),\) and the first occurrence of \({\delta ^{\prime }}\) by their definitions. The second reduces \({T}\) to \({?_i}\) . In the third, the casted \({\delta {}^{\prime }}\) is substituted for \({x}\) by a \(\beta\) step. Casts are finally simplified using Up-Down and Prod-Prod. At that point, the reduction has almost looped back to the second step, apart from the casts \({\langle {?_i} \Leftarrow {?_i}\rangle }\) in the first occurrence of \({\delta ^{\prime }}\) , which will simply accumulate through reduction, but without hindering divergence.
On the contrary, the normalizing variants have \(c_\Pi (i) \lt i\) , and thus share the following reduction path:
The first step corresponds to the first three above, the only difference being the value of \(c_\Pi (i)\) . The reductions however differ in the next step because \({?_i \rightarrow ?_{i-1}} \ne {{\rm germ}_{i}\,\Pi }\) , so Prod-Germ applies before Up-Down. For the third step, note that \({?_{i-1} \rightarrow ?_{i-1}} = {{\rm germ}_{i}\,\Pi }\) , so that Down-Err applies in the rightmost sequence of casts. The last three steps of reduction then propagate the error by first using Prod-Germ, Up-Down, and Prod-Prod, then the \(\beta\) rule, and finally Down-Err, Err and a last \(\beta\) step. At a high-level, the error can be seen as a dynamic universe inconsistency, triggered by the invalid downcast highlighted on the first line.

5.4 Precision is a Simulation for Reduction

Establishing the graduality of elaboration—the formulation of the SGG in our setting—is no small feat, as it requires properties about computations in \(\mathsf {CastCIC}\) that amount to the DGG. Indeed, to handle the typing rules for checking and constrained inference, it is necessary to know how consistency and reduction evolve as a type becomes less precise. As already explained in Section 3.4, we cannot directly prove graduality for a syntactic notion of precision. However, we can still show that this relation is a simulation for reduction. While weaker than graduality, this property implies the DGG and suffices to conclude that graduality of elaboration holds. The purpose of this section is to establish it. Our proof is partly inspired by the proof of DGG by Siek et al. 2015.15 We however had to adapt to the much higher complexity of \(\mathsf {CIC}\) compared to \(\mathsf {STLC}\) . In particular, the presence of computation in the domain and codomain of casts is quite subtle to tame, as we must in general reduce types in a cast before we can reduce the cast itself.16
Technically, we need to distinguish between two notions of precision, one for \(\mathsf {GCIC}\) and one for \(\mathsf {CastCIC}\) : (i) syntactic precision on terms in \(\mathsf {GCIC}\) , which corresponds to the usual syntactic precision of gradual typing Siek et al. 2015, (ii) structural precision on terms in \(\mathsf {CastCIC}\) , which corresponds to syntactic precision together with a proper account of casts. In this section, we concentrate on properties of structural precision in \(\mathsf {CastCIC}\) . We only state and discuss the various lemmas and theorems on a high level, and refer the reader to Appendix B.2 for the detailed proofs.
Structural precision for \(\mathsf {CastCIC}\) . As emphasized already, the key property we want to establish is that precision is a simulation for reduction, i.e., that less precise terms reduce at least as well as more precise ones. This property guides the quite involved definition we are about to give for structural precision: It is rigid enough to give the induction hypotheses needed to prove simulation, while being lax enough to be a consequence of syntactic precision after elaboration, which is the key point to establish elaboration graduality (Theorem 24), our equivalent of the static gradual guarantee.
Similarly to \(\sim _{\alpha }\) , precision can ignore some casts, in order to handle casts that might appear or disappear in one term but not the other during reduction. But in order to control what casts can be ignored, we impose some restriction on the types involved. In particular, we want to ensure that ignored casts would not have raised an error: e.g., We want to prevent \({0} \sqsubseteq _{\alpha }{\langle {\mathbb {B}} {\ \Leftarrow \ } {\mathbb {N}} \rangle \,{0}}\) . Thus, the definition of structural precision relies on typing, and to do this we need to record the contexts of the two compared terms. We do so by using double-struck letters to denote contexts where each variable is given two types, writing \({\mathbb {\Gamma }, x : A \mid A^{\prime }}\) for context extensions. We use \({\mathbb {\Gamma }_i}\) for projections, i.e., \({(\mathbb {\Gamma }, x : A \mid A^{\prime })_{1}} := {\mathbb {\Gamma }_{1}, x : A}\) , and write \({\Gamma \mid \Gamma ^{\prime }}\) for the converse pairing operation.
Definition 6 (Structural and Definitional Precision in \(\mathsf {CastCIC}\) )
Structural precision, denoted \({\mathbb {\Gamma }} \vdash {t} \sqsubseteq _{\alpha }{t^{\prime }}\) , is defined in Figure 10, mutually with definitional precision, denoted \({\mathbb {\Gamma }} \vdash {t} \sqsubseteq _{\leadsto }{t^{\prime }}\) , which is its closure by reduction. We write \({\Gamma } \sqsubseteq _{\alpha }{\Gamma ^{\prime }}\) and \({\Gamma } \sqsubseteq _{\leadsto }{\Gamma ^{\prime }}\) for the pointwise extensions of those to contexts.
Although \({\mathbb {\Gamma }} \vdash {t}\sqsubseteq _{\leadsto }{t^{\prime }}\) is defined in a stepwise way, it is equivalent to the existence of \({s}\) and \({s^{\prime }}\) such that \({t} {\rm {\leadsto }^\ast }{s}\) , \({t^{\prime }} {\rm {\leadsto }^\ast }{s^{\prime }}\) and \({\mathbb {\Gamma }} \vdash {s} \sqsubseteq _{\alpha }{s^{\prime }}\) . The situation is the same as for consistency (respectively, conversion), which is the closure by reduction of \(\alpha\) -consistency (respectively, \(\alpha\) -equality). However, here definitional precision is also used in the definition of structural precision, in order to permit computation in types—recall that in a dependently-typed setting the two types involved in a cast may need to reduce before the cast itself can reduce—and thus the two notions are mutually defined.
Let us now explain the rules defining structural precision. Diagonal rules are completely structural, apart from the Diag-Fix rule, where typing assumptions provide us with the contexts needed to compare the predicates. More interesting are the non-diagonal rules. First, \({?_{T}}\) is greater than any term of the “right type”. This incorporates loss of precision (rule Unk), and accommodates for a small bit of cumulativity (rule Unk-Univ). This is needed because of technical reasons linked with possibility to form products between types at different levels. On the contrary, the error is smaller than any term (rule Err), even in its extended form on \(\Pi\) -types (rule Err-Lambda), with a typing premise similar to that of rule Unk. Finally, casts on the right-hand side can be ignored as long as they are performed on types that are less precise than the type of the term on the left (rule Case-R). Dually, casts on the left-hand side can be ignored as long as they are performed on types that are more precise than the type of the term on the right (rule Case-L).
Catch-up lemmas. The fact that structural precision is a simulation relies on a series of lemmas that all have the same form: under the assumption that a term \({t^{\prime }}\) is less precise than a term \({t}\) with a known head ( \({[]}\) , \({{\rm \Pi }}\) , \({I}\) , \({\lambda ,}\) or \({c}\) ), the term \({t^{\prime }}\) can be reduced to a term that either has the same head, or is some \({?}\) . We call these catch-up lemmas, as they enable the less precise term to catch up to the more precise one whose head is already known. Their aim is to ensure that casts appearing in a less precise term never block reduction, as they can always be reduced away.
The lemmas are established in a descending fashion: First, on the universe in Lemma 15, then on other types in Lemma 16, and finally on terms, namely, on \(\lambda\) -abstractions in Lemma 17 and inductive constructors in Lemma 18. Each time, the previously proven catch-up lemmas are used to reduce types in casts appearing in the less precise term, apart from Lemma 15, where the induction hypothesis of the lemma being proven is used instead.
Lemma 15 (Universe Catch-up).
Under the hypothesis that \({\mathbb {\Gamma }_{1}} \sqsubseteq _{\alpha }{\mathbb {\Gamma }_{2}}\) , if \({\mathbb {\Gamma }} \vdash {[]_i} \sqsubseteq _{\leadsto }{T^{\prime }}\) and \({\mathbb {\Gamma }_{2}} \vdash {T^{\prime }} \blacktriangleright {[]} {[]_{j}}\) , either \({T^{\prime }} {\rm {\leadsto }^\ast }{?_{[]_{j}}}\) with \(i \lt j\) , or \({T^{\prime }} {\rm {\leadsto }^\ast }{[]_i}\) .
Lemma 16 (Types Catchup).
Under the hypothesis that \({\mathbb {\Gamma }_{1}} \sqsubseteq _{\alpha }{\mathbb {\Gamma }_{2}}\) , we have the following:
if \({\mathbb {\Gamma }} \vdash {?_{[]_i}} \sqsubseteq _{\alpha }{T^{\prime }}\) and \({\mathbb {\Gamma }_{2}} \vdash {T^{\prime }} \blacktriangleright {[]} {[]_{j}}\) , then \({T^{\prime }} {\rm {\leadsto }^\ast }{?_{[]_{j}}}\) and \(i \le j\) ;
if \({\mathbb {\Gamma }} \vdash {{\rm \Pi }x : A.B} \sqsubseteq _{\alpha }{T^{\prime }}\) , \({\mathbb {\Gamma }_{1}} \vdash {{\rm \Pi }x : A. B} {\rm \triangleright }{[]_i}\) and \({\mathbb {\Gamma }_{2}} \vdash {T^{\prime }} \blacktriangleright {[]} {[]_j}\) then either \({T^{\prime }} {\rm {\leadsto }^\ast }{?_{[]_j}}\) and \(i \le j\) , or \({T^{\prime }} {\rm {\leadsto }^\ast }{{\rm \Pi }x : A^{\prime } . B^{\prime }}\) for some \({A^{\prime }}\) and \({B^{\prime }}\) such that \({\mathbb {\Gamma }} \vdash {{\rm \Pi }x : A . B} \sqsubseteq _{\alpha }{{\rm \Pi }x :A^{\prime } . B^{\prime }}\) ;
if \({\mathbb {\Gamma }} \vdash {I(\mathbf {a})} \sqsubseteq _{\alpha }{T^{\prime }}\) , \({\mathbb {\Gamma }_{1}} \vdash {I(\mathbf {a})} {\rm \triangleright }{[]_i}\) and \({\mathbb {\Gamma }_{2}} \vdash {T^{\prime }} \blacktriangleright {[]} {[]_j}\) then either \({T^{\prime }} {\rm {\leadsto }^\ast }{?_{[]_j}}\) and \(i \le j\) , or \({T^{\prime }} {\rm {\leadsto }^\ast }{I(\mathbf {a^{\prime }})}\) for some \({a^{\prime }}\) such that \({\mathbb {\Gamma }} \vdash {I(\mathbf {a})} \sqsubseteq _{\alpha }{I(\mathbf {a^{\prime }})}\) .
Lemma 17 ( \(\lambda\) -abstraction Catch-up)
If \({\mathbb {\Gamma }} \vdash {{\rm \lambda }x : A . t} \sqsubseteq _{\alpha }{s^{\prime }}\) , where \({t}\) is not an error, \({\mathbb {\Gamma }_{1}} \vdash {{\rm \lambda }x : A. t} {\rm \triangleright }{{\rm \Pi }x : A.B}\) and \({\mathbb {\Gamma }_{2}} \vdash {s^{\prime }} \blacktriangleright {\Pi } {{\rm \Pi }x : A^{\prime }. B^{\prime }}\) , then \({s^{\prime }} {\rm {\leadsto }^\ast }{{\rm \lambda }x : A^{\prime }.t^{\prime }}\) with \({\mathbb {\Gamma }} \vdash {{\rm \lambda }x : A . t} \sqsubseteq _{\alpha }{{\rm \lambda }x : A^{\prime }. t^{\prime }}\) .
This holds in \(\mathsf {CastCIC} ^{\mathcal {G}}\) , \(\mathsf {CastCIC} ^{\uparrow }\) , and for terms without \({?}\) in \(\mathsf {CastCIC} ^{\mathcal {N}}\) .
Lemma 18 (Constructors and Inductive Error Catch-up).
If \({\mathbb {\Gamma }} \vdash {c(\mathbf {a},\mathbf {b})} \sqsubseteq _{\alpha }{s^{\prime }}\) , \({\mathbb {\Gamma }_{1}} \vdash {c(\mathbf {a},\mathbf {b})} {\rm \triangleright }{I(\mathbf {a})}\) and \({\mathbb {\Gamma }_{2}} \vdash {s^{\prime }} \blacktriangleright {I} {I(\mathbf {a^{\prime }})}\) , then either \({s^{\prime }} {\rm {\leadsto }^\ast }{?_{I(\mathbf {a^{\prime }})}}\) or \({s^{\prime }} {\rm {\leadsto }^\ast }{c(\mathbf {a^{\prime }},\mathbf {b^{\prime }})}\) with \({\mathbb {\Gamma }} \vdash {c(\mathbf {a},\mathbf {b})} \sqsubseteq _{\alpha }{c(\mathbf {a^{\prime }},\mathbf {b^{\prime }})}\) .
Similarly, if \({\mathbb {\Gamma }} \vdash {?_{I(\mathbf {a})}} \sqsubseteq _{\alpha }{s^{\prime }}\) , \({\mathbb {\Gamma }_{1}} \vdash {?_{I(\mathbf {a})}} {\rm \triangleright }{I(\mathbf {a})}\) and \({\mathbb {\Gamma }_{2}} \vdash {s^{\prime }} \blacktriangleright {I} {I(\mathbf {a^{\prime }})}\) , then \({s^{\prime }} {\rm {\leadsto }^\ast }{?_{I(\mathbf {a^{\prime }})}}\) with \({\mathbb {\Gamma }} \vdash {I(\mathbf {a})} \sqsubseteq _{\leadsto }{I(\mathbf {a^{\prime }})}\) .
Note that for Lemma 18, we need to deal with unknown terms specifically, which is not necessary for Lemma 17 because the unknown term in a \(\Pi\) -type reduces to a \(\lambda\) -abstraction.
Lemma 17 deserves a more extensive discussion, because it is the critical point where the difference between the three variants of \(\mathsf {CastCIC}\) manifests. In fact, it does not hold in full generality for \(\mathsf {CastCIC} ^{\mathcal {N}}\) . Indeed, the fact that \(i \le c_\Pi (s_\Pi (i,j))\) and \(j \le c_\Pi (s_\Pi (i,j))\) is used crucially to ensure that casting from a \(\Pi\) -type into \({?}\) and back does not reduce to an error, given the restrictions on types in Case-R. This is the manifestation in the reduction of the embedding-projection property New and Ahmed 2018. In \(\mathsf {CastCIC} ^{\mathcal {N}}\) , it holds only if one restricts to terms without \({?}\) , where such casts never happen. This is important with regard to conservativity, as elaboration produces terms with casts but without \({?}\) , and Lemma 17 ensures that for those precision is still a simulation, even in \(\mathsf {CastCIC} ^{\mathcal {N}}\) .
Example 19 (Catch-up of \(\lambda\) -abstraction)
The following term \({t_i}\) illustrates these differences
\begin{equation*} {t_i} := {\langle {\mathbb {N}\rightarrow \mathbb {N}\Leftarrow ?_{[]_i}} {\ \Leftarrow \ } {\mathbb {N}\rightarrow \mathbb {N}} \rangle \,{{\rm \lambda }x : \mathbb {N}. \texttt {suc}(x)}}, \end{equation*}
where \({\mathbb {N}}\) is taken at the lowest level, i.e., to mean \({\mathbb {N}@\lbrace 0\rbrace }\) . Such terms appear naturally whenever a loss of precision happens on a function, for instance when elaborating a term like \({\left(({\rm \lambda }x : \mathbb {N}. \texttt {suc}(x))\mathrel {::}?\right)~0}\) . Now this term \({t_i}\) always reduces to
\begin{equation*} {\langle {\mathbb {N}\rightarrow \mathbb {N}} {\ \Leftarrow \ } {{\rm germ}_{i}\,\Pi \Leftarrow ?_{[]_i} \Leftarrow {\rm germ}_{i}\,\Pi \Leftarrow \mathbb {N}\rightarrow \mathbb {N}} \rangle \,{{\rm \lambda }x : \mathbb {N}. \texttt {suc}(x),}} \end{equation*}
and at this point the difference kicks in: if \({{\rm germ}_{i}\,\Pi }\) is \({{\rm \mathtt {err}}_{?_{[]_i}}}\) (i.e., if \(c_\Pi (i) \lt 0\) ) then the whole term reduces to \({{\rm \mathtt {err}}_{\mathbb {N}\rightarrow \mathbb {N}}}\) . Otherwise, further reductions finally give
\begin{equation*} {{\rm \lambda }x : \mathbb {N}. \texttt {suc}\left(\langle {\mathbb {N}} {\ \Leftarrow \ } {\mathbb {N}\Leftarrow \mathbb {N}} \rangle \,{x}\right). } \end{equation*}
Although the body is blocked by the variable \({x}\) , applying the function to 0 would reduce to 1 as expected. Let us compare what happens in the three systems.
In all of them, if \(i \ge 1\) , we have \(\vdash {{\rm \lambda }x : \mathbb {N}. \texttt {suc}(x)} \sqsubseteq _{\alpha }{t_i}\) via repeated uses of Case-R since \({} \vdash {\mathbb {N}} {\rm \rightsquigarrow }{\mathbb {N}} {\rm \triangleright }{[]_{s_\Pi (0,0)}}\) and \(s_\Pi (0,0) \le 1 \le i\) . Moreover, also \(0 \le i - 1 \le c_\Pi (i)\) and so the reduction is errorless. Thus Lemma 17 holds in all three systems when \(i \ge 1\) .
The difference appears in the specific case where \(i = 0\) . In \(\mathsf {CastCIC} ^{\mathcal {G}}\) and \(\mathsf {CastCIC} ^{\mathcal {N}}\) , we still have \(\vdash {{\rm \lambda }x : \mathbb {N}. \texttt {suc}(x)} \sqsubseteq _{\alpha }{t_0}\) , since \(s_\Pi (0,0) = 0 \le i\) . In the former, \(c_\Pi (0) = 0\) so \({t_0}\) reduces safely and Lemma 17 holds. In the latter; however, \(c_\Pi (0) = -1\) , and so \({t_0}\) errors even if it is less precise than an errorless term—Lemma 17 does not hold in that case. Finally, in \(\mathsf {CastCIC} ^{\uparrow }\) , \({t_0}\) errors since again \(c_\Pi (0) = -1\) . However, because \(s_{\Pi }(0,0) = 1\) , \({t_0}\) is not less precise than \({{\rm \lambda }x : \mathbb {N}. \texttt {suc}(x)}\) thanks to the typing restriction in Case-R, so this error does not contradict Lemma 17.
Note that in an actual implementation with typical ambiguity (Footnote 14), the case where \(i = 0\) would most likely not manifest: elaborating \({\left(({\rm \lambda }x : \mathbb {N}. \texttt {suc}(x))\mathrel {::}?\right)~0}\) would produce a fresh level that could be chosen high enough so as to prevent the error we just described. Only more involved situations like that of \({\Omega }\) (Section 5.3) would actually exhibit failures due to universe levels, which are precisely those unavoidable to ensure normalization.
Simulation. We finally come to the main property of this section, the advertised simulation. Remark that the simulation property needs to be stated (and proven) mutually for structural and definitional precision, but it is really informative only for structural precision (definitional precision is somehow a simulation by construction).
Theorem 20 (Precision is a Simulation for Reduction).
Let \({\mathbb {\Gamma }_{1}} \sqsubseteq _{\leadsto }{\mathbb {\Gamma }_{2}}\) , \({\mathbb {\Gamma }_{1}} \vdash {t} {\rm \triangleright }{T}\) , \({\mathbb {\Gamma }_{2}} \vdash {u} {\rm \triangleright }{U}\) and \({t} {\rm {\leadsto }^\ast }{t^{\prime }}\) . Then
if \({\mathbb {\Gamma }} \vdash {t} \sqsubseteq _{\alpha }{u}\) then there exists \({u^{\prime }}\) such that \({u} {\rm {\leadsto }^\ast }{u^{\prime }}\) and \({\mathbb {\Gamma }} \vdash {t^{\prime }} \sqsubseteq _{\alpha }{u^{\prime }}\) ;
if \({\mathbb {\Gamma }} \vdash {t} \sqsubseteq _{\leadsto }{u}\) then \({\mathbb {\Gamma }} \vdash {t^{\prime }} \sqsubseteq _{\leadsto }{u}\) .
This holds in \(\mathsf {CastCIC} ^{\mathcal {G}}\) , \(\mathsf {CastCIC} ^{\uparrow }\) , and for terms without \({?}\) in \(\mathsf {CastCIC} ^{\mathcal {N}}\) .
Proof Sketch
The case of definitional precision follows by confluence of reduction. For the case of structural precision, the hardest point is to simulate \(\beta\) and \(\iota\) redexes—terms of the shape \({\rm \mathtt {ind}}_{I}(c(\mathbf {a}),z.P,f.\mathbf {y}.\mathbf {t})\) . This is where we use Lemmas 17 and 18, to show that similar reductions can also happen in \({t^{\prime }}\) . We must also put some care into handling the premises of precision where typing is involved. In particular, subject reduction is needed to relate the types inferred after reduction to the type inferred before, and the mutual induction hypothesis on \(\sqsubseteq _{\leadsto }\) is used to conclude that the premises holding on \({t}\) still hold on \({t^{\prime }}\) . Finally, the restriction to terms without \({?}\) in \(\mathsf {CastCIC} ^{\mathcal {N}}\) similar to Lemma 17 appears again when treating Up-Down, where having \(c_\Pi (s_\Pi (i,i)) = i\) is required.□
From this theorem, we get as direct corollaries the following properties, that are required to handle reduction (Corollary 21) and consistency (Corollary 22) in elaboration. Again those corollaries hold in \(\mathsf {GCIC} ^{\mathcal {G}}\) , \(\mathsf {GCIC} ^{\uparrow }\) , and for terms in \(\mathsf {GCIC} ^{\mathcal {N}}\) containing no \({?}\) .
Corollary 21 (Monotonicity of Reduction to Type Constructor).
Let \({\mathbb {\Gamma }}\) , \({T,}\) and \({T^{\prime }}\) be such that \({\mathbb {\Gamma }_{1}} \vdash {T} \blacktriangleright {[]} {\square {}_i}\) , \({\mathbb {\Gamma }_{2}} \vdash {T^{\prime }} \blacktriangleright {[]} {\square {}_j}\) , \({\mathbb {\Gamma }} \vdash {T} \sqsubseteq _{\alpha }{T^{\prime }}\) . Then
if \({T} {\rm {\leadsto }^\ast }{?_{[]_i}}\) then \({T^{\prime }} {\rm {\leadsto }^\ast }{?_{[]_j}}\) with \(i \le j\) ;
if \({T} {\rm {\leadsto }^\ast }{\square {}_{i-1}}\) then either \({T^{\prime }} {\rm {\leadsto }^\ast }{?_{\square {}_j}}\) with \(i \le j\) , or \({T^{\prime }} {\rm {\leadsto }^\ast }{\square {}_{i-1}}\) ;
if \({T} {\rm {\leadsto }^\ast }{{\rm \Pi }x : A. B}\) then either \({T^{\prime }} {\rm {\leadsto }^\ast }{?_{[]_j}}\) with \(i \le j\) , or \({T^{\prime }} {\rm {\leadsto }^\ast }{{\rm \Pi }x : A^{\prime }. B^{\prime }}\) and
\(\mathbb {\Gamma }\vdash {{\rm \Pi }x : A.B} \sqsubseteq _{\alpha }{{\rm \Pi }x : A^{\prime }.B^{\prime }}\) ;
if \({T} {\rm {\leadsto }^\ast }{I(\mathbf {a})}\) then either \({T^{\prime }} {\rm {\leadsto }^\ast }{?_{[]_j}}\) with \(i \le j\) , or \({T^{\prime }} {\rm {\leadsto }^\ast }{I(\mathbf {a^{\prime }})}\) and \(\mathbb {\Gamma }\vdash {I(\mathbf {a})} \sqsubseteq _{\alpha }{I(\mathbf {a^{\prime }})}\) .
Proof.
It suffices to simulate the reductions of \({T}\) by using Theorem 20, and then use Lemmas 15 and 16 to conclude. Note that head reductions are simulated using head reductions in Theorem 20, and the reductions of Lemmas 15 and 16 are also head reductions. Thus the corollary still holds when fixing weak-head reduction as a reduction strategy.□
Corollary 22 (Monotonicity of Consistency).
If \({\mathbb {\Gamma }} \vdash {T} \sqsubseteq _{\alpha }{T^{\prime }}\) , \({\mathbb {\Gamma }} \vdash {S} \sqsubseteq _{\alpha }{S^{\prime }}\) and \({T} \sim {S}\) then \({T^{\prime }} \sim {S^{\prime }}\) .
Proof.
By definition of \(\sim\) , we get some \({U}\) and \({V}\) such that \({T} {\rm {\leadsto }^\ast }{U}\) and \({S} {\rm {\leadsto }^\ast }{V}\) , and \({U} \sim _{\alpha }{V}\) . By Theorem 20, we can simulate these reductions to get some \({U^{\prime }}\) and \({V^{\prime }}\) such that \({T^{\prime }} {\rm {\leadsto }^\ast }{U^{\prime }}\) and \({S^{\prime }} {\rm {\leadsto }^\ast }{V^{\prime }}\) , and also \({\mathbb {\Gamma }_{1}} \vdash {U} \sqsubseteq _{\alpha }{U^{\prime }}\) and \({\mathbb {\Gamma }_{1}} \vdash {V} \sqsubseteq _{\alpha }{V^{\prime }}\) . Thus, we only need to show that \(\alpha\) -consistency is monotone with respect to structural precision, which is direct by induction on structural precision.□

5.5 Properties of \(\mathsf {GCIC}\)

We now have enough technical tools to prove most of the properties of \(\mathsf {GCIC}\) . We state those theorems in an empty context in this section to make them more readable, but they are of course corollaries of similar statements including contexts, proven by mutual induction. The complete statements and proofs can be found in Appendix B.3.
Conservativity with respect to \(\mathsf {CIC}\) . Elaboration systematically inserts casts during checking, thus even static terms are not elaborated to themselves. Therefore, we use a (partial) erasure function \(\varepsilon\) that translates terms of \(\mathsf {CastCIC}\) to terms of \(\mathsf {CIC}\) by erasing all casts. We also introduce the notion of erasability, characterizing terms that contain “harmless” casts, such that in particular the elaboration of a static term is always erasable.
Definition 7 (Equiprecision).
Two terms \({s}\) and \({t}\) are equiprecise in a context \({\mathbb {\Gamma }}\) , denoted \({\mathbb {\Gamma }} \vdash {s} \sqsupseteq \sqsubseteq _{\alpha }{t}\) if both \({\mathbb {\Gamma }} \vdash {s} \sqsubseteq _{\alpha }{t}\) and \({\mathbb {\Gamma }} \vdash {t} \sqsubseteq _{\alpha }{s}\) .
Definition 8 (Erasure, Erasability).
Erasure \(\varepsilon\) is a partial function from the syntax of \(\mathsf {CastCIC}\) to the syntax of \(\mathsf {CIC}\) , which is undefined on \({?}\) and \({{\rm \mathtt {err}}}\) , is such that \(\varepsilon ({\langle {B} {\ \Leftarrow \ } {A} \rangle \,{t}}) = \varepsilon ({t})\) , and is a congruence for all other term constructors.
Given a context \({\mathbb {\Gamma }}\) we say that a term well-typed in \({\mathbb {\Gamma }_1}\) \({t}\) is erasable if \(\varepsilon ({t})\) is defined, well-typed in \({\mathbb {\Gamma }_2}\) , and equiprecise to \({t}\) in \({\mathbb {\Gamma }}\) . Similarly a context \({\Gamma }\) is called erasable if it is pointwise erasable. When \({\Gamma }\) is erasable, we say that a term \({t}\) is erasable in \({\Gamma }\) to mean that it is erasable in \({\Gamma } \mid \varepsilon ({\Gamma })\) .
Conservativity holds in all three systems, typeability being of course taken into the corresponding variant of \(\mathsf {CIC}\) : full \(\mathsf {CIC}\) for \(\mathsf {GCIC} ^{\mathcal {G}}\) and \(\mathsf {GCIC} ^{\mathcal {N}}\) , and \(\mathsf {CIC}^{\uparrow }\) for \(\mathsf {GCIC} ^{\uparrow }\) .
Theorem 23 (Conservativity).
Let \({\tilde{t}}\) be a static term (i.e., is a term of \(\mathsf {GCIC}\) that is also a term of \(\mathsf {CIC}\) ). If \(\vdash _{\mathsf {CIC}}{\tilde{t}} {\rm \triangleright }T\) for some type \(T\) , then there exists \({t}\) and \({T^{\prime }}\) such that \({} \vdash {\tilde{t}} {\rm \rightsquigarrow }{t} {\rm \triangleright }{T^{\prime }}\) , and moreover \(\varepsilon ({t}) = {\tilde{t}}\) and \(\varepsilon ({T^{\prime }}) = T\) . Conversely if \({} \vdash {\tilde{t}} {\rm \rightsquigarrow }{t} {\rm \triangleright }{T}\) for some \({t}\) and \({T}\) , then \(\vdash _{\mathsf {CIC}}{\tilde{t}} {\rm \triangleright }\varepsilon ({T})\) .
Proof Sketch
Because \({t}\) is static, its typing derivation in \(\mathsf {GCIC}\) can only use rules that have a counterpart in \(\mathsf {CIC}\) , and conversely all rules of \(\mathsf {CIC}\) have a counterpart in \(\mathsf {GCIC}\) . The only difference is about the reduction/conversion side conditions, which are used on elaborated types in \(\mathsf {GCIC}\) , rather than their non-elaborated counterparts in \(\mathsf {CIC}\) .
Thus, the main difficulty is to ensure that the extra casts inserted by elaboration do not alter reduction. For this we maintain the property that all terms \({t}\) considered in \(\mathsf {CastCIC}\) are erasable, and in particular that any static term \({{t}}\) that elaborates to some \({t}\) is such that \(\varepsilon ({t}) = {{t}}\) . From the simulation property of structural precision (Theorem 20), we get that an erasable term \({t}\) has the same reduction behavior as its erasure, i.e., if \({t} {\rm {\leadsto }^\ast }{s}\) then \(\varepsilon ({t}) {\rm {\leadsto }^\ast }s^{\prime }\) with \(s^{\prime }\) and \({s}\) equiprecise, and conversely if \(\varepsilon ({t}) {\rm {\leadsto }^\ast }s^{\prime }\) then \({t} {\rm {\leadsto }^\ast }{s}\) with \(s^{\prime }\) and \({s}\) equiprecise. Using that property, we prove that constraint reductions ( \(\blacktriangleright {\Pi }\) , \(\blacktriangleright {[],}\) and \(\blacktriangleright {I}\) ) in \(\mathsf {CastCIC}\) and \(\mathsf {CIC}\) behave the same on static terms.□
Elaboration Graduality. Next, we turn to elaboration graduality, the equivalent of the SGG of Siek et al. 2015 in our setting. We state it with respect to a notion of precision for terms in \(\mathsf {GCIC}\) , syntactic precision \(\sqsubseteq ^{\mathrm{G}}_{\alpha }\) , defined in Figure 11. Syntactic precision is the usual and expected source-level notion of precision in gradual languages: It is generated by a single non-trivial rule \({t} \sqsubseteq ^{\mathrm{G}}_{\alpha }{?@\lbrace i\rbrace }\) , and congruence rules for all term formers.
In contrast with the simply-typed setting, the presence of multiple unknown types \({?}\) , one for each universe level \({i}\) , requires an additional hypothesis relating elaboration and precision. We say that two judgments \({\tilde{t}} \sqsubseteq ^{\mathrm{G}}_{\alpha }{?@\lbrace i\rbrace }\) and \({\Gamma } \vdash {\tilde{t}} {\rm \rightsquigarrow }{t} {\rm \triangleright }{T}\) are universe adequate if the universe level \(j\) given by the well-formedness judgment \({\Gamma } \vdash {T} \blacktriangleright {\square } {\square _j}\) induced by correction of the elaboration satisfies \(i = j\) . More generally, \({\tilde{t}} \sqsubseteq ^{\mathrm{G}}_{\alpha }{\tilde{s}}\) and \({} \vdash {\tilde{t}} {\rm \rightsquigarrow }{t} {\rm \triangleright }{T}\) are universe adequate if for any subterm \({\tilde{t}_0}\) of \({\tilde{t}}\) inducing judgments \({\tilde{t}_0} \sqsubseteq ^{\mathrm{G}}_{\alpha }{?@\lbrace i\rbrace }\) and \({\Gamma _0} \vdash {\tilde{t}_0} {\rm \rightsquigarrow }{t} {\rm \triangleright }{T}\) , those are universe adequate. Note that this extraneous technical assumption on universe levels is not needed if we use typical ambiguity (Footnote 14), since universe levels are not given explicitly.
Theorem 24 (Elaboration Graduality/Static Gradual Guarantee).
In \(\mathsf {GCIC} ^{\mathcal {G}}\) and \(\mathsf {GCIC} ^{\uparrow }\) , if \({\tilde{t}} \sqsubseteq ^{\mathrm{G}}_{\alpha }{\tilde{s}}\) and \({} \vdash {\tilde{t}} {\rm \rightsquigarrow }{t} {\rm \triangleright }{T}\) are universe adequate, then \({} \vdash {\tilde{s}} {\rm \rightsquigarrow }{s} {\rm \triangleright }{S}\) for some \({s}\) and \({S}\) such that \(\vdash {t} \sqsubseteq _{\alpha }{s}\) and \(\vdash {T} \sqsubseteq _{\alpha }{S}\) .
Proof Sketch
The proof is by induction on the elaboration derivation for \({\tilde{t}}\) . All cases for inference consist in a straightforward combination of the hypotheses, with the universe adequacy hypothesis used in the case where \({\tilde{s}}\) is \({?@\lbrace i\rbrace }\) . Here, again the technical difficulties arise in the rules involving reduction. This is where Corollary 21 is useful, proving that the less structurally precise term obtained by induction in a constrained inference reduces to a less precise type. Thus, either the same rule can still be used, or one has to trade a Inf-Unk, Inf-Prod, or Inf-Ind rule, respectively, for a Inf-Univ?, Inf-Prod?, or Inf-Ind? rule in case the less precise type is some \({?_{[]_i}}\) and the more precise type is not. Similarly, Corollary 22 proves that in the checking rule the less precise types are still consistent. Note that again, because Corollary 21 holds when restricted to weak-head reduction, elaboration graduality also holds when fixing a weak-head strategy in Figure 9.□
Dynamic Gradual Guarantee. Following Siek et al. 2015, using the fact that structural precision is a simulation (Theorem 20), we can prove the DGG for \(\mathsf {CastCIC} ^{\mathcal {G}}\) and \(\mathsf {CastCIC} ^{\uparrow }\) (stated using the notion of observational refinement \(\sqsubseteq ^{obs}\) from Definition 4).
Theorem 25 (Dynamic Gradual Guarantee for \(\mathsf {CastCIC} ^{\mathcal {G}}\) and \(\mathsf {CastCIC} ^{\uparrow }\) )
Suppose that \({\Gamma } \vdash {t} {\rm \triangleright }{A}\) and \({\Gamma } \vdash {u} {\rm \triangleright }{A}\) . If moreover \({\Gamma \mid \Gamma } \vdash {t} \sqsubseteq _{\alpha }{u}\) then \({t} \sqsubseteq ^{obs}{u}\) .
Proof.
Let \({\mathcal {C}} : ({\Gamma } \vdash {A}) \Rightarrow (\vdash {\mathbb {B}})\) closing over all free variables. By the diagonal rules of structural precision, we have \({\Gamma \mid \Gamma } \vdash {\mathcal {C}[t]} \sqsubseteq _{\alpha }{\mathcal {C}[u]}\) . By progress (Theorem 8), \({\mathcal {C}[t]}\) either reduces to \({\mathtt {true}}\) , \({\mathtt {false}}\) , \({?_{\mathbb {B}}}\) , \({{\rm \mathtt {err}}_{\mathbb {B},}}\) or diverges, and similarly for \({\mathcal {C}[u]}\) . If \({\mathcal {C}[t]}\) diverges or reduces to \({{\rm \mathtt {err}}_\mathbb {B}}\) , we are done. If it reduces to either \({\mathtt {true}}\) , \({\mathtt {false},}\) or \({?_\mathbb {B}}\) , then by the catch-up Lemma 18, \({\mathcal {C}[u]}\) either reduces to the same value, or to \({?_\mathbb {B}}\) . In particular, it cannot diverge or reduce to an error.□
Note that Example 19 provides a counter-example to this theorem for \(\mathsf {CastCIC} ^{\mathcal {N}}\) , by choosing the context \({{\rm \mathtt {ind}}_{\mathbb {N}}(\bullet ~0,z.\mathbb {B},f.\mathtt {true},f.n.\mathtt {true})}\) , because in that context the function \({{\rm \lambda }x : \mathbb {N}. \texttt {suc}(x)}\) reduces to \({\mathtt {true}}\) while the less precise casted function reduces to \({{\rm \mathtt {err}}_{\mathbb {B}}}\) .
As observed in Section 2.4, graduality—and in particular the fact that precision induces ep-pair s —is inherently semantic, and thus cannot rely on the syntactic precision \(\sqsubseteq ^{\mathrm{G}}_{\alpha }\) introduced in this section. Therefore, we defer the proof of \(\mathcal {G}\) for \(\mathsf {CastCIC} ^{\uparrow }\) and \(\mathsf {CastCIC} ^{\mathcal {G}}\) to the next section, where the semantic notion of propositional precision is introduced.

6 Realizing \(\mathsf {CastCIC}\) and Graduality

To prove normalization of \(\mathsf {CastCIC} ^{\mathcal {N}}\) and \(\mathsf {CastCIC} ^{\uparrow }\) , we now build a model of both theories with a simple implementation of casts using case-analysis on types as well as exceptions, yielding the discrete model, allowing us to reduce the normalization of both theories to the normalization of the target theory (Section 6.1).
Then, to prove graduality of \(\mathsf {CastCIC} ^{\uparrow }\) , we build a more elaborate monotone model inducing a precision relation well-behaved with respect to conversion. Following generalities about the interpretation of \(\mathsf {CIC}\) ’s types as posets in Section 6.2, we describe the construction of a monotone unknown type \(\ddot{?}_{}\) in Section 6.3 and a hierarchy of universes in Section 6.4 and put these pieces together in Section 6.5, culminating in a proof of graduality for \(\mathsf {CastCIC} ^{\uparrow }\) (Section 6.6). In both the discrete and monotone case, the parameters \(c_\Pi (-)\) and \(s_\Pi (-,-)\) appear when building the hierarchy of universes and tying the knot with the unknown type.
Finally, to deduce graduality for the non-terminating variant, \(\mathsf {CastCIC} ^{\mathcal {G}}\) , we describe at the end of this section a model based on \(\omega\) -complete partial orders, extending the seminal model of Scott 1976 for \(\lambda\) -calulus to \(\mathsf {CastCIC} ^{\mathcal {G}}\) (Section 6.7).
The discrete model embeds into a variant of \(\mathsf {CIC}\) extended with induction-recursion Dybjer and Setzer 2003, noted \(\mathsf {CIC^{IR}}\) , and the monotone model into a variant that additionally features quotients (and hence also function extensionality Shulman 2011), noted \(\mathsf {CIC^{IR}_{QIT}}\) .
Formalization in Agda. We use Agda Norell 2009 as a practical tool to typecheck the components of the models and assume that Agda satisfies standard metatheoretical properties, namely, subject reduction and strong normalization.
The correspondence between the notions developed in the following sections and the formal development in Agda Lennon-Bertrand et al. 2020 is as follows. The formalization covers most component of the discrete (DiscreteModelPartial.agda) and monotone model (UnivPartial.agda) in a partial (non-normalizing) setting and only the discrete model is proved to be normalizing assuming normalization of the type theory implemented by Agda (no escape hatch to termination checking is used in DiscreteModelTotal). The main definitions surrounding posets can be found in Poset.agda: top and bottom elements (called Initial and Final in the formalization), embedding-projection pairs (called Distr) as well as the notions corresponding to indexed families of posets (IndexedPoset, together with IndexedDistr). It is then proved that we endow can the translation of each type formers from \(\mathsf {CastCIC}\) with a poset structure: natural numbers in nat.agda, booleans in bool.agda, dependent product in pi.agda. The definition of the monotone unknown type \(\ddot{?}_{}\) is defined in the subdirectory Unknown/. It is more involved since we need to use a quotient (that we axiomatize together with a rewriting rule in Unknown/Quotient.agda). Finally, all these building blocks are put together when assembling the inductive-recursive hierarchies of universes (UnivPartial.agda, DiscreteModelPartial.agda and DiscreteModelTotal.agda).

6.1 Discrete Model of \(\mathsf {CastCIC}\)

The discrete model explains away the new term formers of \(\mathsf {CastCIC}\) (2) by a translation into \(\mathsf {CIC}\) using two important ingredients from the literature:
Exceptions, following the approach of \(\mathsf {ExTT}\) Pédrot and Tabareau 2018: Each inductive type is extended with two new constructors, one for \(?\) and one for \({\rm \mathtt {err}}\) . As alluded to early on (Section 2.5), both \(?\) and \({\rm \mathtt {err}}\) are exceptional terms in their propagation semantics, and only differ in their static interpretation: \(\mathsf{?_A}\) is consistent with any other term of type \(\mathsf{A}\) , while \(\mathsf{err_A}\) is not consistent with any such term.
Case analysis on types Boulier et al. 2017 to define the cast operator. The essence of the translation is to interpret types as codes when they are seen as terms, and as the semantics of those codes when they are seen as types. This allows us to get the standard interpretation for a term inhabiting a type, but at the same time, it allows functions taking terms in the universe \(\square \!\!\!\! \square {}_i\) to perform a case analysis on the code of the type, because this time, the type is seen as a term in \(\square \!\!\!\! \square {}_i\) .
The latter ingredient for intensional type analysis requires the target theory of the translation to be an extension of \(\mathsf {CIC}\) with induction-recursion Dybjer and Setzer 2003, noted \(\mathsf {CIC^{IR}}\) . We write \(\leadsto _{\mathrm{IR}}\) and \({\vdash _{\mathrm{IR}}}\) to denote the reduction and typing judgments of \(\mathsf {CIC^{IR}}\) , respectively.
Inductive types. Following the general pattern of \(\mathsf {ExTT}\) , we interpret each inductive type \(I\) by an inductive type \(\ddot{I}\) featuring all constructors of \(I\) and extended with two new constructors \(\top _{\ddot{I}}\) and \(\bot _{\ddot{I}}\) , corresponding respectively to \(?_{I}\) and \({\rm \mathtt {err}}_I\) of \(\mathsf {CastCIC}\) . The constructors \(\top _{\ddot{I}}\) and \(\bot _{\ddot{I}}\) of \(\ddot{I}\) are called exceptional by opposition to the other constructors that we call non-exceptional. For instance, the inductive type used to interpret natural numbers, \(\ddot{\mathbb {N}}{}\) , thus has four constructors: The non-exceptional constructors 0 and \(\texttt {suc}\) , and the exceptional constructors \(\top _{\ddot{\mathbb {N}}}\) , \(\bot _{\ddot{\mathbb {N}}}\) . In the rest of this section, we only illustrate inductive types on natural numbers.
Universe and type-case. Case analysis on types is obtained through an explicit inductive-recursive description of the universes Martin-Löf 1984 McBride 2010 to build a type of codes \(\square \!\!\!\! \square _i\) described in Figure 12. Codes are noted with \(\widehat{\cdot }\) and the universe type contains codes for dependent product ( \(\widehat{\Pi }\) ), universes ( \(\widehat{\square \!\!\!\! \square }_j\) ), inductive types (e.g., \(\widehat{\mathbb {N}}\) ) as well as \(\widehat{?}_{}\) for the unknown type and \(\widehat{{\rm \mathtt {err}}_{}}\) for the error type. The main subtlety here is that the code \(\widehat{\Pi }\,A\,B\) is at level \(s_\Pi (i,j)\) when \(A\) is at \(i\) and \(B\) is a family at \(j\) , emulating the rule of Figure 3. Accompanying the inductive definition of \(\square \!\!\!\! \square _i\) , the recursively defined decoding function \(\mathrm{El}\) provides a semantics for these codes. The semantics of \(\widehat{\Pi }\) is given by the dependent product in the target theory, applying \(\mathrm{El}\) on the domain and the codomain of the code. The semantics of \(\widehat{\square \!\!\!\! \square }_j\) is precisely the type of codes \(\square \!\!\!\! \square _j\) . The semantics of \(\widehat{\mathbb {N}}\) is given by the extended natural numbers \(\ddot{\mathbb {N}}\) , explained above.
Intuitively, the semantics of \(\widehat{?}_{i}\) is that an inhabitant of the unknown type corresponds to a pair of a type and an inhabitant of that type. More precisely, we first define a notion of germ for codes where we stratify the head constructors \({\rm Head}\) (see Figure 4) according to the universe level \(i\) , e.g., \(\widehat{{\rm germ}}_{i}\,\Pi := \widehat{\Pi }\,\widehat{\square \!\!\!\! \square }_{c_\Pi (i)}\,(\lambda (x : \square \!\!\!\! \square _{c_\Pi (i)}).\widehat{\square \!\!\!\! \square }_{c_\Pi (i)})\) when \(c_\Pi (i) \ge 0\) , and its decoding to types \({\rm germ}_{i}\,h := \mathrm{El}\,(\widehat{{\rm germ}}_{i}\,h)\) . The unknown type \(\widehat{?}_{i}\) is then decoded to the extended dependent sum \({\ddot{\Sigma }}\, {\rm Head}_i \, {\rm germ}_{i}\,\) whose elements are either
one of the two freely added constructors \(\top _{{\ddot{\Sigma }}}, \bot _{{\ddot{\Sigma }}}\) following the interpretation scheme of inductive types;
or a dependent pair \(({h};{t})\) of a head constructor \(h \in {\rm Head}_i\) together with an element \(t \in {\rm germ}_{i}\,h\) .
Finally, the error type \(\widehat{{\rm \mathtt {err}}_{i}}\) is decoded to the unit type \(\mathtt {unit}\) containing a unique element \(\mathtt {()}\) .
Variants of \(\mathsf {CastCIC}\) . Crucially, the code for \(\Pi\) -types (Figure 12) depends on the choice made for \(s_\Pi (i,j)\) . Observe that for the choice of parameters corresponding to \(\mathsf {CastCIC} ^{\mathcal {G}}\) , the inductive-recursive definition of \(\square \!\!\!\! \square _i\) is ill-founded since \(c_\Pi (s_\Pi (i,i)) = s_\Pi (i,i)\) . We can thus inject \({\rm germ}{}_{s_\Pi (i,i)}\Pi = \mathrm{El}\,\widehat{?}_{}{s_\Pi (i,i)} \rightarrow \mathrm{El}\,\widehat{?}_{}{s_\Pi (i,i)}\) into \(\mathrm{El}\,\widehat{?}_{}{s_\Pi (i,i)}\) and project back in the other direction, exhibiting an embedding-retraction suitable to interpret the untyped \(\lambda\) -calculus and hence \(\Omega\) . 17
In order to maintain normalization, the construction of the unknown type and the universe therefore needs to be stratified, which is possible when \(c_\Pi (s_\Pi (i,i)) \lt s_\Pi (i,i)\) . This strict inequality occurs for both \(\mathsf {CastCIC} ^{\mathcal {N}}\) and \(\mathsf {CastCIC} ^{\uparrow }\) . We then proceed by strong induction on the universe level, and note that thanks to the level gap, the decoding \(\mathrm{El}\,\widehat{?}_{i}\) of the unknown type at a level \(i\) can be defined solely from the data of smaller universes available by inductive hypothesis, without any reference to \(\square \!\!\!\! \square _i\) . We can then define the rest of the universe \(\square \!\!\!\! \square _i\) and the decoding function \(\mathrm{El}\) at level \(i\) in a well-founded manner, validating the strict positivity criterion of Agda’s termination checker.
Exceptions. The definition of exceptions \(?_{A}, {\rm \mathtt {err}}_{A} : \mathrm{El}~A\) at an arbitrary code \(A\) then follows by case analysis on the code, as shown in Figure 13. On the code for the universe, \(\widehat{\square \!\!\!\! \square }_j\) , we directly use the code for the unknown and the error types respectively. On codes that have an inductive interpretation— \(\widehat{\mathbb {N}}\) , \(\widehat{?}_{i}\) —we use the two added constructors. On the code for dependent functions, exceptions are defined by re-raising the exception at the codomain in a pointwise fashion. Finally, on the error type \(\widehat{{\rm \mathtt {err}}_{}}\) , exceptions are degenerated and forced to take the only value \(\mathtt {()}:\mathtt {unit}\) 18 of its interpretation as a type.
Casts. Equipped with exceptions and type analysis, we define \({\rm \mathtt {cast}}: {\rm \Pi }(A : \square \!\!\!\! \square _i)(B : \square \!\!\!\! \square _j). A \rightarrow B\) by induction on the universe levels and case analysis on the codes of the types \(A\) and \(B\) (Figure 14). In the total setting (when \(c_\Pi (s_\Pi (i,i)) \lt s_\Pi (i,i)\) ), the definition of \({\rm \mathtt {cast}}\) is well-founded: each recursive call happens either at a strictly smaller universe (the two cases for \(\widehat{\Pi }\) ) or on a strict subterm of the term being cast (case of inductives, i.e., \(\widehat{\mathbb {N}}\) and \(\widehat{?}_{}\) ). Note that each of the defining equations of \({\rm \mathtt {cast}}\) corresponds straightforwardly to a reduction rule of Figure 5.
Discrete translation. We can finally define the discrete syntactic model of \(\mathsf {CastCIC}\) in \(\mathsf {CIC^{IR}}\) (Figure 15). The translations \([{{-}}]\) and \([\![ {}{{-}}]\!] {}\) are defined by induction on the syntax of terms and types. A type \(A\) is translated to its corresponding code \([{{A}}]\) in \(\square \!\!\!\! \square _i\) when seen as a term, and is translated to the interpretation of this code \([\![ {}{{A}}]\!] {} := \mathrm{El}\,[{{A}}]\) when seen as a type. \(?_A\) and \({\rm \mathtt {err}}_A\) are directly translated using the exceptions defined in Figure 13. The following theorem shows that the translation is a syntactic model in the sense of Boulier et al. 2017.
Theorem 26 (Discrete Syntactic Model).
The translation defined in Figure 15 preserves conversion and typing derivations
(1)
if \({\Gamma } \vdash _{{\rm \mathtt {cast}}}{t} \leadsto {} {u}\) then \([\![ {}{{\Gamma }}]\!] {} {\vdash _{\mathrm{IR}}}[{{t}}] \leadsto ^{+}_{\mathrm{IR}}[{{u}}]\) , in particular \([\![ {}{{\Gamma }}]\!] {} {\vdash _{\mathrm{IR}}}[{{t}}] \equiv [{{u}}]\) ;
(2)
if \({\Gamma } \vdash _{{\rm \mathtt {cast}}}{t} : {A}\) then \([\![ {}{{\Gamma }}]\!] {} {\vdash _{\mathrm{IR}}}[{{t}}] : [\![ {}{{A}}]\!] {}\) .
Proof.
(1) All reduction rules from \(\mathsf {CIC}\) are preserved without a change so that we only need to be concerned with the reduction rules involving exceptions or casts. A careful inspection shows that these reductions are preserved too once we observe that the terms of the shape \({\langle {?_{\square _i}} {\ \Leftarrow \ } {{\rm germ}_{i}\,h} \rangle \,{t}}\) that are stuck in \(\mathsf {CastCIC}\) are in one-to-one correspondence with the one-step reduced form of its translation \(({h};{[{{t}}]}) : {\ddot{\Sigma }}\, {\rm Head}_i \, {\rm germ}_{i}\,\) . (2) Proved by a direct induction on the typing derivation of \({\Gamma }\vdash _{{\rm \mathtt {cast}}} {t} : {A}\) , using the fact that exceptions and casts are well-typed—that is \({\vdash _{\mathrm{IR}}}? : {\rm \Pi }(A : \square \!\!\!\! \square _i)\,\mathrm{El}\,A\) , \({\vdash _{\mathrm{IR}}}{\rm \mathtt {err}}: {\rm \Pi }(A : \square \!\!\!\! \square _i)\,\mathrm{El}\,A\) , and \({\vdash _{\mathrm{IR}}}{\rm \mathtt {cast}}: {\rm \Pi }(A : \square \!\!\!\! \square _i)(B : \square \!\!\!\! \square _i) \mathrm{El}\,A {\rightarrow } \mathrm{El}\,B\) —and relying on assertion \((1)\) to handle the conversion rule.□
As explained in Theorem 9, Theorem 26 implies in particular that \(\mathsf {CastCIC} ^{\uparrow }\) and \(\mathsf {CastCIC} ^{\mathcal {N}}\) are strongly normalizing.

6.2 Poset-Based Models of Dependent Type Theory

The simplicity of the discrete model comes at the price of an inherent inability to characterize which casts are guaranteed to succeed, i.e., a graduality theorem. To overcome this limitation, we develop a monotone model on top of the discrete model where, by construction, each type \(A\) comes equipped with an order structure \(\sqsubseteq ^A\) —a reflexive, transitive, antisymmetric, and proof-irrelevant relation—modeling precision between terms. In particular, the exceptions \({\rm \mathtt {err}}_A\) and \(?_A\) correspond respectively to the smallest and greatest element of \(A\) for this order. We note \(\square ^\le\) for a universe of types equipped with the structure of a poset together with smallest and greatest elements. Each term and type constructor is enforced to be monotone with respect to these orders, providing a strong form of graduality. This implies in particular that such a model cannot be defined for \(\mathsf {CastCIC} ^{\mathcal {N}}\) because this type theory lacks graduality, as shown by Example 19.
As an illustration, the order on extended natural numbers (Figure 16) makes \(\bot _{\ddot{\mathbb {N}}}\) the smallest element and \(\top _{\ddot{\mathbb {N}}}\) the biggest element.19 The standard natural numbers – 0 or \(\texttt {suc}~n\) for a standard natural number \(n\) —then stand between failure and indeterminacy, but are never related to each other by precision. Indeed, in order to ensure conservativity with respect to \(\mathsf {CIC}\) , \(\sqsubseteq ^{\widehat{\mathbb {N}}{}}\) must coincide with \(\mathsf {CIC}\) ’s conversion on static closed natural numbers.
Beyond the precision order on types, the nature of dependency forces us to spell out what the precision between types entails. Following the analysis of New and Ahmed 2018, a relation \(A \sqsubseteq B\) between types should induce an ep-pair : A pair of an upcast \({\uparrow {} : A {\rightarrow } B}\) and a downcast \({\downarrow {} : B {\rightarrow } A}\) satisfying a handful of properties with gradual guarantees as a corollary.
Definition 9 (Embedding-projection Pairs).
An ep-pair \(d : A \vartriangleleft {} B\) between posets \(A,B : \square ^\le\) consists of
an underlying relation \(d \subseteq A \times B\) such that
\begin{equation*} a^{\prime } \sqsubseteq ^A a \:\wedge \: d(a,b) \:\wedge \: b \sqsubseteq ^B b^{\prime } \quad \Rightarrow \quad d(a^{\prime },b^{\prime }), \end{equation*}
that is bi-represented by \(\uparrow _d~ : A \rightarrow B\) , \(\downarrow {}_d : B \rightarrow A\) , i.e.,
\begin{equation*} \uparrow _d a \sqsubseteq ^B b \quad \Leftrightarrow \quad d(a,b) \quad \Leftrightarrow \quad a \sqsubseteq ^A \;\downarrow _d b, \end{equation*}
such that the equality \(\downarrow _d \circ \uparrow _d~ = \mathrm{id}_A\) holds.
Note, that here equiprecision of the retraction becomes an equality because of antisymmetry. Under these conditions, \(\uparrow _d : A \hookrightarrow B\) is injective, \(\downarrow _d : B \twoheadrightarrow A\) is surjective and both preserve bottom elements, explaining that we call \(d : A \vartriangleleft {} B\) an embedding-projection pair. The definition of ep-pair s is based on a relation rather than just its pair of representing functions to highlight the connection between ep-pair s and parametricity New et al. 2020. Assuming function extensionality, being an ep-pair is a property of the underlying relation: There is at most one pair \((\uparrow {}_d, \downarrow _d)\) representing the underlying relation of \(d\) . An ep-pair straightforwardly induces the following relations that will be used in later proofs.
Lemma 27 (Properties of ep-pair s).
Let \(d : A \vartriangleleft {} B\) be an ep-pair between posets.
(1)
If \(a : A\) then \(d\,(a, \uparrow _d a)\) and \(a \sqsubseteq ^A \downarrow _d\uparrow _d a\) ;
(2)
If \(b : B\) then \(d\,(\downarrow _d b, b)\) and \(\uparrow _d\downarrow _d b \sqsubseteq ^B b\) .
Posetal families. By monotonicity, a family \(B : A \rightarrow \square ^\le\) over a poset \(A\) gives rise not only to a poset \(B\,a\) for each \(a \in A\) , but also to ep-pair s \(B_{a,a^{\prime }} : B\,a \vartriangleleft {} B\,a^{\prime }\) for each \(a \sqsubseteq ^A a^{\prime }\) . These ep-pair s need to satisfy functoriality conditions:
\begin{equation*} B_{a,a} = {\sqsubseteq ^{B\,a}} \qquad \text{and}\qquad B_{a,a^{\prime \prime }} = B_{a^{\prime },a^{\prime \prime }} \circ B_{a,a^{\prime }}\quad \text{whenever}\quad a \sqsubseteq ^A a^{\prime } \sqsubseteq ^A a^{\prime \prime }. \end{equation*}
In particular, this ensures that heterogeneous transitivity is well defined:
\begin{equation*} B_{a,a^{\prime }}(b,b^{\prime }) \wedge B_{a^{\prime },a^{\prime \prime }}(b^{\prime },b^{\prime \prime }) \Rightarrow B_{a,a^{\prime \prime }}(b,b^{\prime \prime }). \end{equation*}
Dependent products. Given a poset \(A\) and a posetal family \(B\) over \(A\) , we can form the poset \({\rm \Pi }^{\text{mon}}{}\,A\,B\) of monotone dependent functions from \(A\) to \(B\) , equipped with the pointwise order. Its inhabitants are dependent functions \(f : {\rm \Pi }(a : A). B\,a\) such that \(a \sqsubseteq ^A a^{\prime } {\Rightarrow } B_{a,a^{\prime }}\,(f\,a, f\,a^{\prime })\) . Moreover, given ep-pair s \(d_A : A \vartriangleleft {} A^{\prime }\) and \(d_B : B \vartriangleleft {} B^{\prime }\) , we can build an induced ep-pair \(d_\Pi : {\rm \Pi }^{\text{mon}}{}\,A\,B \vartriangleleft {} {\rm \Pi }^{\text{mon}}{}\,A^{\prime }\,B^{\prime }\) with underlying relation
\begin{align*} d_\Pi (f,f^{\prime }) &:= d_A(a,a^{\prime }) \Rightarrow d_B(f\,a,f^{\prime }\,a^{\prime }),\\ \uparrow {}_{d_\Pi }f := {\uparrow _{d_B}}\circ f \circ \downarrow {}_{d_A} &\qquad \text{ and }\qquad \downarrow {}_{d_\Pi }f := {\downarrow _{d_B}} \circ f \circ \uparrow {}_{d_A}. \end{align*}
The general case where \(B\) and \(B^{\prime }\) actually depend on \(A, A^{\prime }\) is obtained with similar formulas, but a larger amount of data is required to handle the dependency: we refer to the accompanying Agda development for details.
Inductive types. Generalizing the case of natural numbers, the order on an arbitrary extended inductive type \(\ddot{I}\) uses the following scheme:
(1)
\(\bot _{\ddot{I}}\) is the least element;
(2)
\(\top _{\ddot{I}} \sqsubseteq ^{\ddot{I}} \top _{\ddot{I}}\) ;
(3)
\(c~\mathbf {t} \sqsubseteq ^{\ddot{I}} \top _{\ddot{I}}\) whenever \(t_i \sqsubseteq ^{X_i} \top _{X_i}\) for all \(i;\)
(4)
each constructor \(c\) is monotone with respect to the order on its arguments.
The precondition on subterms in the third case is unnecessary in simple cases and is kept to be uniform with definition of order on the monotone unknown type in the following section.
Similarly to dependent product, an ep-pair \(\mathbf {X} \vartriangleleft {} \mathbf {X^{\prime }}\) between the parameters of an extended inductive type \(\ddot{I}\) induces an ep-pair \(\ddot{I}\,\mathbf {X} \vartriangleleft {} \ddot{I}\,\mathbf {X^{\prime }}\) . For instance, ep-pair s \(d_A : A \vartriangleleft {} A^{\prime }\) and \(d_B : B \vartriangleleft {} B^{\prime }\) induce an ep-pair \(d_{{\ddot{\Sigma }}} : {\ddot{\Sigma }}\,A\,B \vartriangleleft {} {\ddot{\Sigma }}\,A^{\prime }\,B^{\prime }\) defined by \(d_{{\ddot{\Sigma }}}((a,b),(a^{\prime },b^{\prime })) := d_A(a,a^{\prime }) \wedge d_B(b,b^{\prime })\) .

6.3 Microcosm: The Monotone Unknown Type \(\ddot{?}_{}\)

The interpretation \(\ddot{?}_{i}\) of the unknown type in the monotone model should morally group together approximations of every type at the same universe level. Working in (bi)pointed orders, \(\ddot{?}_{i}\) can be realized as a coalesced sum Abramsky and Jung 1995Section 3.2.3 of the family \({\rm germ}_{i}\,h\) indexed by head constructors \(h \in {\rm Head}_i\) . A concrete presentation of \(\ddot{?}_{i}\) is obtained as the quotient of \({\ddot{\Sigma }}\, {\rm Head}_i \, {\rm germ}_{i}\,\) identifying \(\bot _{{\ddot{\Sigma }}\, {\rm Head}_i \, {\rm germ}_{i}\,}\) with any pair \(({h};{{\rm \mathtt {err}}_{\widehat{{\rm germ}}_{i}\,h}})\) . The equivalence classes of \(({h};{x})\) is noted as \([{h};{x}]\) , \(\bot _{{\ddot{\Sigma }}\, {\rm Head}_i \, {\rm germ}_{i}\,}\) as \(\bot _{\ddot{?}_{i}}\) and \(\top _{{\ddot{\Sigma }}\, {\rm Head}_i \, {\rm germ}_{i}\,}\) as \(\top _{\ddot{?}_{i}}\) . The obtained type \(\ddot{?}_{i}\) is then equipped with a precision relation defined by the rules:
(1)
These rules ensure that the exceptions \(\bot _{\ddot{?}_{i}}\) and \(\top _{\ddot{?}_{i}}\) are respectively the smallest and biggest elements of \(\ddot{?}_{i}\) . Non-exceptional elements are comparable only if they have the same head constructor \(h\) and if so are compared according to the interpretation of that head constructor as an ordered type \({\rm germ}_{i}\,h\) . Because of the quotient, it is not immediate that this presentation of \(\sqsubseteq ^{\ddot{?}_{i}}\) is independent of the choice of representatives in equivalence classes and that it forms a proof-irrelevant relation. In the formal development, we define the relation by quotient-induction on each argument, thus verifying that it respects the quotient, and also show that it is irrelevant. This relies crucially on equality being decidable on head constructors when comparing \([{h};{x}]\) and \([{h^{\prime }};{x^{\prime }}]\) .
In order to globally satisfy \(\mathcal {G}\) , \(\ddot{?}_{i}\) should admit an ep-pair \({d_h : {\rm germ}_{i}\,h \vartriangleleft {} \ddot{?}_{i}}\) whenever we have a head constructor \(h \in {\rm Head}_i\) such that \(\widehat{{\rm germ}}_{i}\,h \sqsubseteq \widehat{?}_{i}\) (we return to that point in the next Section 6.4). Embedding an element \(x \in {\rm germ}_{i}\,h\) by \(\uparrow _{d_h}x = [{h};{x}]\) and projecting out of \({\rm germ}_{i}\,h\) by the following equations form a reasonable candidate:
\begin{align*} \downarrow _{d_h}[{h^{\prime }};{x}] &= \begin{array}{cc} x & if\ h = h^{\prime } \\ {\rm \mathtt {err}}_{{\rm germ}_{i}\,h} & otherwise \end{array}& \downarrow _{d_h} \top _{\ddot{?}_{i}} &= ?_{{\rm germ}_{i}\,h} & \downarrow _{d_h} \bot _{\ddot{?}_{i}} &= {\rm \mathtt {err}}_{{\rm germ}_{i}\,h}\!. \end{align*}
Note that we rely again on \({\rm Head}\) having decidable equality to compute the \(\downarrow {}_{d_h}\) . Moreover, \(\uparrow _{d_h} \dashv \downarrow _{d_h}\) should be adjoints; in particular, the following precision relation needs to hold:
\begin{align*} {\rm \mathtt {err}}_{{\rm germ}_{i}\,h} \sqsubseteq ^{{\rm germ}_{i}\,h} {\downarrow {}_{d_h}\bot _{\ddot{?}_{i}}}\quad \iff \quad [{h};{{\rm \mathtt {err}}_{{\rm germ}_{i}\,h}}] = {\uparrow _{d_h}{\rm \mathtt {err}}_{{\rm germ}_{i}\,h}} \sqsubseteq ^{\ddot{?}_{i}} \bot _{\ddot{?}_{i}} \end{align*}
Since \(\sqsubseteq ^{\ddot{?}_{i}}\) should be antisymmetric, this is possible only if \([{h};{{\rm \mathtt {err}}_{{\rm germ}_{i}\,h}}]\) and \(\bot _{\ddot{?}_{i}}\) are identified in \(\ddot{?}_{i}\) , explaining why we have to quotient in the first place.

6.4 Realization of the Monotone Universe Hierarchy

Following the discrete model, the monotone universe hierarchy is also implemented through an inductive-recursive datatype of codes \(\square \!\!\!\! \square _i\) together with a decoding function \(\mathrm{El}: \square \!\!\!\! \square _i \rightarrow \square\) , both presented in Figure 17. The precision relation \({\sqsubseteq } : \square \!\!\!\! \square _i \rightarrow \square \!\!\!\! \square _j \rightarrow \square\) presented below is an order (Theorem 28) on this universe hierarchy. The “diagonal” inference rules, providing evidence for relating type constructors from \(\mathsf {CIC}\) , coincide with those of binary parametricity Bernardy et al. 2012. Outside the diagonal, \(\widehat{{\rm \mathtt {err}}_{}}\) is placed at the bottom. More interestingly, the derivation of a precision proof \(A \sqsubseteq \widehat{?}_{}\) provides a unique decomposition of \(A\) through iterated germs directed by the relevant head constructors. For instance, in the gradual systems \(\mathsf {CastCIC} ^{\mathcal {G}}\) and \(\mathsf {CastCIC} ^{\uparrow }\) where the equation \(c_\Pi (s_\Pi (i,j)) = \max (i,j)\) holds for any universe levels \(i,j\) , the derivation of \((\widehat{\mathbb {N}}{} {\rightarrow } \widehat{\mathbb {N}}{}) {\rightarrow } \widehat{\mathbb {N}}{} \sqsubseteq \widehat{?}_{}\) canonically decomposes as
\begin{equation*} (\widehat{\mathbb {N}}{} {\rightarrow } \widehat{\mathbb {N}}{}) {\rightarrow } \widehat{\mathbb {N}}{} \quad \sqsubseteq \quad (\widehat{?}_{}{\rightarrow } \widehat{?}_{}) {\rightarrow } \widehat{\mathbb {N}}{} \quad \sqsubseteq \quad \widehat{?}_{}{\rightarrow } \widehat{?}_{}\quad \sqsubseteq \quad \widehat{?}_{}. \end{equation*}
This unique decomposition is at the heart of the reduction of the cast operator given in Figure 5, and it can be described informally as taking the path of maximal length between two related types.20 Such a derivation of precision \(A \sqsubseteq B\) gives rise through decoding to ep-pair s \(\mathrm{El}{}_\varepsilon \,(A {\sqsubseteq }B) : \mathrm{El}\,A \vartriangleleft {}\mathrm{El}\,B\) , with underlying relation noted \({ [_{A}]{\sqsubseteq }{_{B}}} : \mathrm{El}\,A \rightarrow \mathrm{El}\,B \rightarrow \square\) . This decoding function \(\mathrm{El}{}_\varepsilon\) is described on generators of \(\sqsubseteq\) at the bottom of Figure 17. \(\mathrm{El}{}_\varepsilon (\widehat{{\rm \mathtt {err}}_{}}\text{-}{\sqsubseteq })\) states that the unique value \(\mathtt {()}\) of \(\mathrm{El}\,\widehat{{\rm \mathtt {err}}_{}}= \mathtt {unit}\) is smaller than any other value. The diagonal cases \(\mathrm{El}{}_\varepsilon (\widehat{\mathbb {N}}\text{-}{\sqsubseteq })\) and \(\mathrm{El}{}_\varepsilon (\widehat{\square \!\!\!\! \square }\text{-}\sqsubseteq)\) reuse the order specified on the carrier. The ep-pair \(\mathrm{El}{}_\varepsilon (\widehat{?}_{}\text{-}{\sqsubseteq })\) between two unknown types \(\ddot{?}_{i} \vartriangleleft {} \ddot{?}_{j}\) at potentially distinct universe levels \(i \le j\) stipulate that \({\rm \mathtt {err}}_{\widehat{?}_{i}}\) and \(?_{\widehat{?}_{j}}\) are respectively smaller and greater than any other value, and that the comparison between two injected terms with same head is induced by their second component. Note that these rules are redundant since \(\ddot{?}_{}\) is obtained through a quotient. Functions \(f,f^{\prime }\) are related by \(\mathrm{El}{}_\varepsilon (\widehat{\Pi }\text{-}{\sqsubseteq })\) when they map related elements \(a [_{A}]{\sqsubseteq }{_{A^{\prime }}} a^{\prime }\) to related elements \(f\,a [_{B\,a}]{\sqsubseteq }{_{B^{\prime }\,a^{\prime }}}f^{\prime }\,a^{\prime }\) . Finally, \(\mathrm{El}{}_\varepsilon ({\rm Head}\text{-}{\sqsubseteq })\) embeds a type \(A\) into \(\ddot{?}_{}\) through its \(\mathrm{head}\,\) .
It is interesting to observe what happens in \(\mathsf {CastCIC} ^{\mathcal {N}}\) , where \(c_\Pi (s_\Pi (i,j)) \ne \max (i,j)\) , for instance on the previous example:
\begin{equation*} \widehat{\mathbb {N}}{} {\rightarrow } \widehat{\mathbb {N}}{} \quad \not\sqsubseteq \quad \widehat{{\rm \mathtt {err}}_{}}= \widehat{{\rm germ}}_{0}\,\Pi \quad \sqsubseteq \quad \widehat{?}_{}. \end{equation*}
So \(\widehat{\mathbb {N}}{} {\rightarrow } \widehat{\mathbb {N}}{}\) is not lower than \(\widehat{?}_{}\) in that setting.
One crucial point of the monotone model is the mutual definition of codes \(\square \!\!\!\! \square _i\) together with the precision relation, particularly salient on codes for \(\Pi\) -types: in \(\widehat{\Pi }\,A\,B\) , \(B : \mathrm{El}\,A \rightarrow \square \!\!\!\! \square _i\) is a monotone function with respect to the order on \(\mathrm{El}\,A\) and the precision on \(\square \!\!\!\! \square _i\) . This intertwining happens because the order is required to be reflexive, a fact observed previously by Atkey et al. 2014 in the similar setting of reflexive graphs. Indeed, a dependent function \(f : \Pi (a : \mathrm{El}\,A).\, \mathrm{El}\,(B\,a)\) is related to itself \(f [_{\widehat{\Pi }{}\,A\,B}]{\sqsubseteq }{_{\widehat{\Pi }{}\,A\,B}} f\) if and only if \(f\) is monotone.
Theorem 28 (Properties of the Universe Hierarchy).
(1)
\(\sqsubseteq\) is reflexive, transitive, antisymmetric and irrelevant so that \((\square \!\!\!\! \square _i, \sqsubseteq)\) is a poset.
(2)
\(\square \!\!\!\! \square _i\) has a bottom element \(\widehat{{\rm \mathtt {err}}_{i}}\) and a top element \(\widehat{?}_{i}\) ; in particular, \(A \sqsubseteq \widehat{?}_{i}\) for any \(A : \square \!\!\!\! \square _i\) .
(3)
\(\mathrm{El}: \square \!\!\!\! \square _i \rightarrow \square\) is a family of posets over \(\square \!\!\!\! \square _i\) with underlying relation \([_{A}]{\sqsubseteq }{_{B}}\) whenever \(A \sqsubseteq B\) .
(4)
\(\square \!\!\!\! \square _i\) and \(\mathrm{El}\;A\) for any \(A : \square \!\!\!\! \square _i\) verify UIP21: the equality on these types is irrelevant.
Proof Sketch
All these properties are proved mutually, first by strong induction on the universe levels, then by induction on the codes of the universe or the derivation of precision. Here, we only sketch the proof of point \((1)\) and refer to the Agda development (cf. UnivPartial.agda) for detailed formal proofs.
For reflexivity, all cases are immediate but for \(\widehat{\Pi }\,A\,B\) : the induction hypothesis provides \(A \sqsubseteq A\) and by point \((3)\) \(\mathrm{El}{}_\varepsilon {}(A \sqsubseteq A) = {\sqsubseteq ^A}\) so we can apply the monotonicity of \(B\) .
For anti-symmetry, assuming \(A \sqsubseteq B\) and \(B \sqsubseteq A\) , we prove by induction on the derivation of \(A \sqsubseteq B\) and case analysis on the other derivation that \(A \equiv B\) . Note that we never need to consider the rule \({\rm Head}\) - \(\sqsubseteq\) . The case \(\Pi\) - \(\sqsubseteq\) holds by induction hypothesis and because the relation \({}_A\sqsubseteq _A\) is reflexive. All the other cases follow from antisymmetry of the order on universe levels.
For transitivity, assuming \(AB : A \sqsubseteq B\) and \(BC : B \sqsubseteq C\) , we prove by induction on the (lexicographic) pair \((AB,BC)\) that \(A \sqsubseteq C\) :
necessarily \(BC = \widehat{?}_{}\text{-}{\sqsubseteq }\) , we conclude by \(\widehat{?}_{}\text{-}{\sqsubseteq }\) .
necessarily \(BC = \widehat{?}_{}\text{-}{\sqsubseteq } , \widehat{?}_{j} \sqsubseteq \widehat{?}_{j^{\prime }}\) , we can thus apply the inductive hypothesis to \({A \sqsubseteq \widehat{{\rm germ}}_{j}\,(\mathrm{head}\,A)}\) and \({\widehat{{\rm germ}}_{j}\,(\mathrm{head}\,A) \sqsubseteq \widehat{{\rm germ}}_{j}\,(\mathrm{head}\,A)}\) in order to conclude with \({\rm Head}\text{-}{\sqsubseteq }\) .
we conclude immediately by \(\widehat{{\rm \mathtt {err}}_{}}\text{-}{\sqsubseteq }\) .
we conclude with \(\widehat{\mathbb {N}}\text{-}{\sqsubseteq }\) .
immediate by \(\widehat{\square \!\!\!\! \square }\text{-}{\sqsubseteq }\) .
by hypothesis we have
By induction hypothesis applied to \(A^\text{d}\sqsubseteq B^\text{d}\) and \(B^\text{d}\sqsubseteq C^\text{d}\) , the domains of the dependent product are related \(A^\text{d}\sqsubseteq C^\text{d}\) . For the codomains, we need to show that for any \(a : A^\text{d}, c : C^\text{d}\) such that \(a [_{A^\text{d}}]{\sqsubseteq }{_{C^\text{d}}} c\) we have \(A^\text{c}\,a \sqsubseteq C^\text{c}\,c\) . By induction hypothesis, it is enough to prove that \(A^\text{c}\,a \sqsubseteq B^\text{c}\,(\uparrow _{A^\text{d}\sqsubseteq B^\text{d}}a)\) and \(B^\text{c}\,(\uparrow _{A^\text{d}\sqsubseteq B^\text{d}}a) \sqsubseteq C^\text{c}\,c\) . The former follows from \(AB^\text{c}\) applied to \(a [_{A^\text{d}}]{\sqsubseteq }{_{B^\text{d}}} \uparrow _{A^\text{d}\sqsubseteq B^\text{d}} a \Leftrightarrow a \sqsubseteq ^{A^\text{d}} { \downarrow {} }{ \uparrow {} } a \Leftrightarrow a \sqsubseteq ^{A^\text{d}} a\) which holds by reflexivity, and the latter follows from \(BC^\text{c}\) applied to \(\uparrow _{A^\text{d}\sqsubseteq B^\text{d}} a [_{B^\text{d}}]{\sqsubseteq }{_{C^\text{d}}} c \Leftrightarrow a [_{A^\text{d}}]{\sqsubseteq }{_{C^\text{d}}} c\) .
we are left with the cases where \(AB = \widehat{\mathbb {N}}\text{-}{\sqsubseteq }, \widehat{\Pi }\text{-}{\sqsubseteq }\) or \(\widehat{\square \!\!\!\! \square }\text{-}{\sqsubseteq }\) and \(BC = {\rm Head}\text{-}{\sqsubseteq }\) , we apply the inductive hypothesis to \(AB\) and \(B \sqsubseteq \widehat{{\rm germ}}_{j}\,(\mathrm{head}\,B)\) in order to conclude with \({\rm Head}\text{-}{\sqsubseteq }\) .
Finally, we show proof-irrelevance, i.e., that for any \(A,B\) there is at most one derivation of \(A \sqsubseteq B\) . Since the conclusions of the rules do not overlap, we only have to prove that the premises of each rules are uniquely determined by the conclusion. This is immediate for \(\widehat{\Pi }\text{-}{\sqsubseteq }\) . For \({\rm Head}\text{-}{\sqsubseteq }\) , \(h = \mathrm{head}\,A \in {\rm Head}_i\) with \(i = \mathrm{pred}\,\,j\) are uniquely determined by the conclusion so it holds too.□

6.5 Monotone Model of \(\mathsf {CastCIC} ^{\uparrow }\)

The monotone translation \(\lbrace {{-}}\rbrace _{}\) presented in Figure 18 brings together the monotone interpretation of inductive types (e.g., \(\ddot{\mathbb {N}}\) ), dependent products, the unknown type \(\ddot{?}_{}\) as well as the universe hierarchy. Following the approach of New and Ahmed 2018, casts are derived out of the canonical decomposition through the unknown type using the property \((2)\) from Theorem 28:
Note that this definition formally depends on a chosen universe level \(j\) for \(\widehat{?}_{}: \square \!\!\!\! \square _{j}\) , but the resulting operation is independent of this choice thanks to the section-retraction properties of ep-pair s . The difficult part of the model, the monotonicity of \({\rm \mathtt {cast}}\) , thus holds by design. However, the translation of some terms do not reduce as in \(\mathsf {CastCIC}\) : \({\rm \mathtt {cast}}\) can get stuck on type variables eagerly, e.g., on a Down-Err step.22 These reduction rules still hold propositionally though so that we have at least a model in an extensional variant of the target theory (i.e., in which two terms are definitionally equal whenever they are propositionally so).
Lemma 29.
If \({\Gamma } \vdash _{{\rm \mathtt {cast}}}{t} \leadsto {} {u}\) then there exists a \(\mathsf {CIC^{IR}_{QIT}}\) term \(e\) such that \(\lbrace {{\Gamma }}\rbrace _{} {\vdash _{\mathrm{IR}}}e : \lbrace {{t}}\rbrace _{} = \lbrace {{u}}\rbrace _{}\) .
We can further enhance this result using the fact that we assume functional extensionality in our target and can prove that the translation of all our types satisfy UIP. Under these assumptions, the conservativity results of Hofmann 1995 and Winterhalter et al. 2019 apply, so we can recover a translation targeting \(\mathsf {CIC^{IR}_{QIT}}\) .
Theorem 30 (Monotone Model).
The translation \(\lbrace {{-}}\rbrace _{}\) of Figure 18 extends to a model of \(\mathsf {CastCIC}\) into \(\mathsf {CIC}\) extended with induction-recursion and functional extensionality: if \({\Gamma }\vdash _{{\rm \mathtt {cast}}} {t} : {A}\) then \(\lbrace \!\mid \!{{\Gamma }}\!\mid \!\rbrace _{} {\vdash _{\mathrm{IR}}}\lbrace {{t}}\rbrace _{} : \lbrace \!\mid \!{{A}}\!\mid \!\rbrace _{}\) .
It is unlikely that the principle that we demand in the target calculus \(\mathsf {CIC^{IR}_{QIT}}\) are optimal. We conjecture that a variation of the translation described here could be developed in \(\mathsf {CIC}\) extended only with induction-induction to describe the intensional content of the codes \(\square \!\!\!\! \square\) in the universe, and strict propositions Gilbert et al. 2019 following the construction of the setoid models of type theory Altenkirch 1999 Altenkirch et al. 2019 2021.

6.6 Back to Graduality

The precision order equipping each types of the monotone model can be reflected back to \(\mathsf {CastCIC}\) , giving rise to the propositional precision judgment:
(2)
By the properties of the monotone model (Theorem 28), there is at most one witness up to propositional equality in the target that this judgment holds. This precision relation bears a similar relationship to the structural precision \(\sqsubseteq _{\alpha }\) as propositional equality with definitional equality in \(\mathsf {CIC}\) . On the one hand, propositional precision can be used to prove precision statements inside the target type theory, for instance we can show by a straightforward case analysis on \({b} : {\mathbb {B}}\) that \({b} : {\mathbb {B}} \vdash _{{\rm \mathtt {cast}}}{\texttt {if } b \texttt { then } A \texttt { else } A} [_{{\square }}]{\sqsubseteq }{_{{\square }}} {A}\) , a judgment that does not hold for syntactic precision. In particular, propositional precision is compatible with propositional equality, and a fortiori it is invariant by conversion in \(\mathsf {CastCIC}\) : if \({t} \equiv {t^{\prime }}\) , \({u} \equiv {u^{\prime }}\) and \({\Gamma } \vdash _{{\rm \mathtt {cast}}}{t} [_{{T}}]{\sqsubseteq }{_{{U}}} {u}\) then \({\Gamma } \vdash _{{\rm \mathtt {cast}}}{t^{\prime }} [_{{T}}]{\sqsubseteq }{_{{U}}} {u^{\prime }}\) . On the other hand, propositional precision is not decidable, thus not suited for typechecking, where structural precision has to be used instead.
Lemma 31 (Compatibility of Structural and Propositional Precision).
(1)
If \({}\vdash _{{\rm \mathtt {cast}}} {t} : {T}\) , \({}\vdash _{{\rm \mathtt {cast}}} {u} : {U}\) and \(\vdash {t} \sqsubseteq _{\alpha }{u}\) then \(\vdash _{{\rm \mathtt {cast}}}{t} [_{{T}}]{\sqsubseteq }{_{{U}}} {u}\) .
(2)
Conversely, if the target of the translation \(\mathsf {CIC^{IR}_{QIT}}\) is logically consistent and \(\vdash _{{\rm \mathtt {cast}}}{v_1} [_{{\mathbb {B}}}]{\sqsubseteq }{_{{\mathbb {B}}}} {v_2}\) for normal forms \({v_1}, {v_2}\) , then \(\vdash {v_1} \sqsubseteq _{\alpha }{v_2}\) .
Proof.
For the first statement, we strengthen the inductive hypothesis, proving by induction on the derivation of structural precision the stronger statement:
If \({\mathbb {\Gamma }} \vdash {t} \sqsubseteq _{\alpha }{u}\) , \({\mathbb {\Gamma }_1} \vdash _{{\rm \mathtt {cast}}}{t} : T\) and \({\mathbb {\Gamma }_2} \vdash _{{\rm \mathtt {cast}}}{u} : {U}\) then there exists a term \(e\) such that .
The cases for variables (Diag-Var) and universes (Diag-Univ) hold by reflexivity. The cases involving \(?\) (Unk, Unk-Univ) and \({\rm \mathtt {err}}\) (Err, Err-Lambda) amount to \(\lbrace {{?}}\rbrace _{}\) and \(\lbrace {{{\rm \mathtt {err}}}}\rbrace _{}\) being respectively interpreted as top and bottom elements at each type. For Case-R, we have \({u} = {\langle {B^{\prime }} {\ \Leftarrow \ } {A^{\prime }} \rangle \,{t^{\prime }}}\) , \({B^{\prime }} = {U}\) , and by induction hypothesis and \(\lbrace \!\mid \!{{\mathbb {\Gamma }}}\!\mid \!\rbrace _{} \vdash \lbrace {{T}}\rbrace _{} \sqsubseteq \lbrace {{B^{\prime }}}\rbrace _{}\) . Let \(j\) be a universe level such that \(\lbrace {{A^{\prime }}}\rbrace _{} \sqsubseteq \widehat{?}_{j}\) , \(\lbrace {{B^{\prime }}}\rbrace _{} \sqsubseteq \widehat{?}_{j}\) . By (heterogeneous) transitivity of precision applied to \(e\) and a witness of (Lemma 27), we obtain a proof \(e^{\prime }\) of and finally, using the adjunction property, a proof \(e^{\prime \prime }\) of
The case Case-L proceeds in an entirely symmetric fashion since we only use the adjunction laws. All the other cases, being congruence rules with respect to some term constructor, are consequences of the monotonicity of said term constructor with a direct application of the inductive hypothesis and inversion of the typing judgments.
For the second statement, by progress (Theorem 8), both \({v_1}\) and \({v_2}\) are canonical booleans, so we can proceed by case analysis on the canonical forms \({v_1}\) and \({v_2}\) that are either \({\mathtt {true}}, {\mathtt {false}}, {{\rm \mathtt {err}}_\mathbb {B}}\) or \({?_\mathbb {B}}\) , ruling out the impossible cases by inversion of the premise \(\vdash _{{\rm \mathtt {cast}}}{v_1} [_{{\mathbb {B}}}]{\sqsubseteq }{_{{\mathbb {B}}}}{v_2}\) and logical consistency of \({\vdash _{\mathrm{IR}}}\) . Out of the 16 cases, we obtain that only the following 9 cases are possible:
\begin{equation*} \begin{array}{lrclrrclrrcl} \vdash _{{\rm \mathtt {cast}}}& {{\rm \mathtt {err}}_\mathbb {B}} & \hspace{-10.0pt} _{{\mathbb {B}}}{\sqsubseteq }{_{{\mathbb {B}}}}\hspace{-10.0pt} & {{\rm \mathtt {err}}_\mathbb {B}} & \qquad \vdash _{{\rm \mathtt {cast}}}& {{\rm \mathtt {err}}_\mathbb {B}} &\hspace{-10.0pt} _{{\mathbb {B}}}{\sqsubseteq }{_{{\mathbb {B}}}}\hspace{-10.0pt} & {\mathtt {true}} & \qquad \vdash _{{\rm \mathtt {cast}}}& {{\rm \mathtt {err}}_\mathbb {B}} &\hspace{-10.0pt} _{{\mathbb {B}}}{\sqsubseteq }{_{{\mathbb {B}}}}\hspace{-10.0pt} & {\mathtt {false}} ,\\ \vdash _{{\rm \mathtt {cast}}}& {{\rm \mathtt {err}}_\mathbb {B}} & \hspace{-10.0pt} _{{\mathbb {B}}}{\sqsubseteq }{_{{\mathbb {B}}}}\hspace{-10.0pt} & {?_\mathbb {B}} & \vdash _{{\rm \mathtt {cast}}}& {\mathtt {true}} &\hspace{-10.0pt} _{{\mathbb {B}}}{\sqsubseteq }{_{{\mathbb {B}}}}\hspace{-10.0pt} & {\mathtt {true}} & \vdash _{{\rm \mathtt {cast}}}& {\mathtt {true}} &\hspace{-10.0pt} _{{\mathbb {B}}}{\sqsubseteq }{_{{\mathbb {B}}}}\hspace{-10.0pt} & {?_\mathbb {B}}, \\ \vdash _{{\rm \mathtt {cast}}}& \hspace{-10.0pt} {\mathtt {false}} &\hspace{-10.0pt} _{{\mathbb {B}}}{\sqsubseteq }{_{{\mathbb {B}}}}\hspace{-10.0pt} & {\mathtt {false}} & \vdash _{{\rm \mathtt {cast}}}& \hspace{-10.0pt} {\mathtt {false}} &\hspace{-10.0pt} _{{\mathbb {B}}}{\sqsubseteq }{_{{\mathbb {B}}}}\hspace{-10.0pt} &{?_\mathbb {B}} &\vdash _{{\rm \mathtt {cast}}}& {?_\mathbb {B}} &\hspace{-10.0pt} _{{\mathbb {B}}}{\sqsubseteq }{_{{\mathbb {B}}}}\hspace{-10.0pt} & {?_\mathbb {B}}. \end{array} \end{equation*}
For each case, a corresponding rule exists for the structural precision, proving that \(\vdash v_1 \sqsubseteq _{\alpha }v_2\) .□
With a similar method, we show that \(\mathsf {CastCIC} ^{\uparrow }\) satisfies graduality, which is the key missing point of Section 5 and the raison d’etre of the monotone model.
Theorem 32 (Graduality for \(\mathsf {CastCIC} ^{\uparrow }\) )
For \({\Gamma }\vdash _{{\rm \mathtt {cast}}}{t} : {T}, {\Gamma } \vdash _{{\rm \mathtt {cast}}}{t^{\prime }} : {T,}\) and \({\Gamma } \vdash _{{\rm \mathtt {cast}}}{u} : {U}\) , we have
(DGG) If \({\Gamma } \vdash _{{\rm \mathtt {cast}}}{t} [_{{T}}]{\sqsubseteq }{_{{T}}} {t^{\prime }}\) then \({t} \sqsubseteq ^{obs}{t^{\prime }}\) ;
(Ep-pairs) If \({\Gamma } \vdash _{{\rm \mathtt {cast}}}{T} [_{{\square }}]{\sqsubseteq }{_{{\square }}} {U}\) then
\begin{equation*} {\Gamma } \vdash _{{\rm \mathtt {cast}}}{\langle {U} {\ \Leftarrow \ } {T} \rangle \,{t}} [_{{U}}]{\sqsubseteq }{_{{U}}} {u} \Leftrightarrow {\Gamma } \vdash _{{\rm \mathtt {cast}}}{t} [_{{T}}]{\sqsubseteq }{_{{U}}} {u} \Leftrightarrow {\Gamma } \vdash _{{\rm \mathtt {cast}}}{t} [_{{T}}]{\sqsubseteq }{_{{T}}} {\langle {T} {\ \Leftarrow \ } {U} \rangle \,{u}}. \end{equation*}
Furthermore, \({\Gamma } \vdash _{{\rm \mathtt {cast}}}{{\langle {T} {\ \Leftarrow \ } {U} \rangle \,{\langle {U} {\ \Leftarrow \ } {T} \rangle \,{t}}} \sqsupseteq \sqsubseteq {t}}\) .
Proof.
DGG) Let \({\mathcal {C}[ - ]} : ({\Gamma } \vdash {T}) \Rightarrow (\vdash {\mathbb {B}})\) be an observation context, by monotonicity of the translation \(\vdash _{{\rm \mathtt {cast}}}{\mathcal {C}[t]} [_{{\mathbb {B}}}]{\sqsubseteq }{_{{\mathbb {B}}}}{\mathcal {C}[t^{\prime }]}\) . By progress, subject reduction (Theorem 8) and strong normalization (Theorem 9) of \(\mathsf {CastCIC} ^{\uparrow }\) , there exists canonical forms \(\vdash _{{\rm \mathtt {cast}}}{v},{v^{\prime }} : {\mathbb {B}}\) such that \({\mathcal {C}[t]} \equiv {v}\) and \({\mathcal {C}[t^{\prime }]} \equiv {v^{\prime }}\) . Since propositional precision is stable by conversion in \(\mathsf {CastCIC}\) , \(\vdash _{{\rm \mathtt {cast}}}{v^{\prime }} \sqsupseteq \sqsubseteq {v}\) . Finally, we conclude that \({v} \equiv {v^{\prime }}\) by a case analysis on the boolean normal forms \({v}\) and \({v^{\prime }}\) , that are either \({\mathtt {true}}, {\mathtt {false}}, {{\rm \mathtt {err}}_\mathbb {B}}\) or \({?_\mathbb {B}}\) : if \({v}\) and \({v^{\prime }}\) are distinct normal forms then \(\vdash _{{\rm \mathtt {cast}}}{v^{\prime }} \sqsupseteq \sqsubseteq {v}\) is a closed proof of an empty type, contradicting the consistency of the target.
(Ep-pairs) The fact that propositional precision induces an adjunction is a direct reformulation of the fact that the relation \([_{\lbrace {{T}}\rbrace _{}}]{\sqsubseteq }{_{\lbrace {{U}}\rbrace _{}}}\) underlies an ep-pair (Theorem 28. Equation (3)), using the fact that there is at most one upcast and downcast between two types. Similarly, the equi-precision statement is an application of the first point to the proofs
which holds because \(\downarrow {}_{\lbrace {{T}}\rbrace _{}\sqsubseteq \lbrace {{U}}\rbrace _{}} \circ \uparrow {}_{\lbrace {{T}}\rbrace _{}\sqsubseteq \lbrace {{U}}\rbrace _{}} = \mathrm{id}{}\) in the monotone model.
We conjecture that the target \(\mathsf {CIC^{IR}_{QIT}}\) mentioned in the above theorem and propositions is consistent relative to a strong enough metatheory,23 that is the assumed inductive-recursive definition for the universe does not endanger consistency. As can be seen from the proof, this hypothesis allows to move from a contradiction internal to \(\mathsf {CIC^{IR}_{QIT}}\) to a contradiction in the ambient metatheory.

6.7 Graduality of \(\mathsf {CastCIC} ^{\mathcal {G}}\)

To prove graduality of \(\mathsf {CastCIC} ^{\mathcal {G}}\) , we need to provide a model accounting for both monotony and non-termination. The monotone model presented in the previous sections, which gives us graduality for \(\mathsf {CastCIC} ^{\uparrow }\) and can be related to the pointed model of New and Licata 2020Section 6.1, only accounts for terminating functions. In order to capture also non-termination, we can adapt the Scott model of New and Licata 2020Section 6.2 based on pointed \(\omega\) -cpo to our setting. We now explain the construction of the main type formers, overloading the notations from the previous sections.
Types are interpreted as bipointed \(\omega\) -cpos, that is as orders \((A, \sqsubseteq)\) equipped with a smallest element \({\rm \mathtt {err}}_A \in A\) , a largest element \(?_A \in A\) and an operation \(\sup _{i}\,a_i\) computing the suprema of countable ascending chains, i.e., sequences \((a_i)_{i\in \omega } \in A^\omega\) indexed by the ordinal \(\omega = \lbrace 0 \lt 1 \lt \cdots \rbrace\) such that \(a_i \sqsubseteq ^A a_j\) whenever \(i \lt j\) . A monotone function \(f : A \rightarrow B\) between \(\omega\) -cpos is called \(\omega\) -continuous if for any ascending chain \((a_k)_{k\in \omega }\) , \(\sup _k f\,a_k = f (\sup _k a_k)\) ; we write \(d : A \vartriangleleft ^\omega {} B\) for an ep-pair between \(\omega\) -cpos where \(\uparrow _d\) preserves suprema (the left adjoint \(\downarrow _d\) automatically preserves suprema).
A type-theoretical construction of the free \(\omega\) -cpo on a set is described in Bidlingmaier et al. 2019 Chapman et al. 2019 using quotient-inductive-inductive types (QIIT) Altenkirch et al. 2018 Kaposi et al. 2019. We can adapt this technique to provide an interpretation for inductive types, and in particular natural numbers, throwing in freely a new constructor \(\sup\) denoting the suprema of any chain of elements and quotienting by the appropriate (in)equations: the suprema of a chain is greater than any of its parts \(a_i \sqsubseteq \sup \,a_i\) and an element \(b\) that is greater than a chain \(\forall i, a_i \sqsubseteq b\) is greater than its suprema \(\sup a_i \sqsubseteq b\) . Functions \(f : A \rightarrow B\) between types are interpreted as continuous monotone maps, and the type \(A \rightarrow ^\omega B\) of continuous monotone functions is an \(\omega\) -cpo with suprema computed pointwise. As in Section 6.3, the construction of the \(\omega\) -cpo corresponding to the unknown type is intertwined with the universe hierarchy. Assuming by induction that we have \(\omega\) -cpos \(\square \!\!\!\! \square _0, \ldots , \square \!\!\!\! \square _i\) for universes at level lower than \(i\) , we follow the seminal work of Scott 1976 on domains and we take the unknown type \(\ddot{?}_{i+1}\) to be a solution to the recursive equation:
\begin{equation*} \ddot{?}_{i+1} \quad \cong \quad \ddot{\mathbb {N}}+ (\ddot{?}_{i+1} \rightarrow ^\omega \ddot{?}_{i+1}) + \square \!\!\!\! \square _0 + \cdots + \square \!\!\!\! \square _i . \end{equation*}
The key techniques to build a solution to this equation in the setting of \(\omega\) -cpos are detailed in Smyth and Plotkin 1977 Wand 1979. In a nutshell, this construction amounts to iterate the assignment \(F(X) := \ddot{\mathbb {N}}+ (X \rightarrow ^\omega X) + \square \!\!\!\! \square _0 + \cdots + \square \!\!\!\! \square _i\) starting from the initial bipointed \(\omega\) -cpo \(\ddot{\mathbb {0}}\) —the free bipointed \(\omega\) -cpo on an empty type, consisting just of \(\bot _{\ddot{\mathbb {0}}} \sqsubseteq \top _{\ddot{\mathbb {0}}}\) —and to take the colimit of the induced sequence:
\begin{align} \ddot{\mathbb {0}}\vartriangleleft ^\omega F(\ddot{\mathbb {0}}) \vartriangleleft ^\omega \ldots \: F^k(\ddot{\mathbb {0}})\: \ldots \: \vartriangleleft ^\omega \mathrm{colim}_k\,F^k(\ddot{\mathbb {0}}) =: \ddot{?}_{i+1}. \end{align}
(5)
For this construction to succeed, \(F\) should extend to an \(\omega\) -continuous functor on the category of \(\omega\) -cpos and \(\omega\) -continuous ep-pair s that moreover preserves countable sequential colimits as above so that the following hold:
\begin{equation*} \ddot{?}_{i+1} = \mathrm{colim}_k\,F^k(\ddot{\mathbb {0}}) \cong \mathrm{colim}_k\,F^{k+1}(\ddot{\mathbb {0}}) \cong F(\mathrm{colim}_k\,F^k(\ddot{\mathbb {0}})) = F(\ddot{?}_{i+1}). \end{equation*}
The construction of \(\ddot{?}_{i+1}\) as a fixpoint for \(F\) should be contrasted with the construction from Section 6.3 where we essentially describe explicitly a construction of \(\ddot{?}_{i+1} := F(\ddot{?}_{i})\) in the setting of bipointed posets. The existence of countable sequential colimits in the category of \(\omega\) -cpos and ep-pair s, as employed in Equation (5), is an interesting fact proved in Wand 1979Theorem 3.1, which we also use to equip the next universe of codes \(\square \!\!\!\! \square _{i+1}\) with an \(\omega\) -cpo structure. In brief, we adapt the inductive description of the universe of codes \(\square \!\!\!\! \square _i\) given in Figure 17 with an additional code \(\sup \,(A_k)_{k \in \omega } : \square \!\!\!\! \square _i\) for suprema of chains of codes \(A_k : \square \!\!\!\! \square _i\) , and decode it with the function \(\mathrm{El}\) satisfying \(\mathrm{El}\,(\sup \,(A_k)_{k \in \omega }) \cong \mathrm{colim}_k\, (\mathrm{El}~A_k)\) . However, the isomorphism above cannot be used as a definition because the definition of \(\mathrm{El}\) has to respect the quotiented nature of \(\square \!\!\!\! \square _i\) . In particular, when the chain is the constant chain \((\widehat{\mathbb {N}})_{k \in \omega }\) , \(\sup \,(\widehat{\mathbb {N}})_{k \in \omega } = \widehat{\mathbb {N}}\) and thus \(\mathrm{El}\,(\sup \,(\widehat{\mathbb {N}})_{k \in \omega })\) must also be equal to \(\ddot{\mathbb {N}}\) , which is different from \(\mathrm{colim}_k\, \ddot{\mathbb {N}}\) . Technically, we define \(\mathrm{El}\,A\) as its isomorphic image onto \(\ddot{?}_{i}\) , recovering a canonical choice for the inhabitants of \(\mathrm{El}\,(\sup \,(A_k)_{k \in \omega })\) .
Note that in contrast with the construction from Section 6.3 that depended on \({\rm germ}_{i}\,\) and hence \(\mathrm{El}_{i}\) , the present construction of \(\ddot{?}_{i}\) does not depend on the construction of \(\square \!\!\!\! \square _{i}\) and \(\mathrm{El}_i\) , cutting the non-wellfounded loop observed in Section 6.1.
The components that we describe assemble as a model of \(\mathsf {CastCIC} ^{\mathcal {G}}\) into \(\mathsf {CIC^{IR}_{QIT}}\) . In order to be able to prove DGG for \(\mathsf {CastCIC} ^{\mathcal {G}}\) , we first need to characterize the semantic interpretation of diverging terms of type \(\mathbb {B}\) in the model.
Lemma 33.
If \({\Gamma } \vdash _{{\rm \mathtt {cast}}}{t} {\rm \triangleright }{\mathbb {B}}\) and \({t}\) has no weak head normal form, then \(\lbrace {{{t}}}\rbrace _{} = {\rm \mathtt {err}}_{\lbrace {{{{\mathbb {B}}}}}\rbrace _{}}\) .
Proof.
The proof of this lemma is based on the definition of a logical relation, which is shown to relate \({t}\) to its translation \(\lbrace {{{t}}}\rbrace _{}\) in the model (a.k.a. the fundamental lemma). The precise definition of the logical and proof of the fundamental lemma is given in Appendix D.□
Relativizing the notion of precision \({\Gamma } \vdash _{{\rm \mathtt {cast}}}{t} [_{{T}}]{\sqsubseteq }{_{{S}}} {u}\) of the monotone model to use the order induced by this \(\omega\) -cpo model instead of the monotone model, we can replay the steps of Theorem 32 and derive graduality for \(\mathsf {CastCIC} ^{\mathcal {G}}\) .
Theorem 34 (Graduality for \(\mathsf {CastCIC} ^{\mathcal {G}}\) )
For \({\Gamma }\vdash _{{\rm \mathtt {cast}}}{t} : {T}, {\Gamma } \vdash _{{\rm \mathtt {cast}}}{t^{\prime }} : {T}\) and \({\Gamma } \vdash _{{\rm \mathtt {cast}}}{u} : {U}\) , we have
(DGG) If \({\Gamma } \vdash _{{\rm \mathtt {cast}}}{t} [_{{T}}]{\sqsubseteq }{_{{T}}} {t^{\prime }}\) then \({t} \sqsubseteq ^{obs}{t^{\prime }}\) ;
(Ep-pairs) If \({\Gamma } \vdash _{{\rm \mathtt {cast}}}{T} [_{{\square }}]{\sqsubseteq }{_{{\square }}} {U}\) then
\begin{equation*} {\Gamma } \vdash _{{\rm \mathtt {cast}}}{\langle {U} {\ \Leftarrow \ } {T} \rangle \,{t}} [_{{U}}]{\sqsubseteq }{_{{U}}} {u} \Leftrightarrow {\Gamma } \vdash _{{\rm \mathtt {cast}}}{t} [_{{T}}]{\sqsubseteq }{_{{U}}} {u} \Leftrightarrow {\Gamma } \vdash _{{\rm \mathtt {cast}}}{t} [_{{T}}]{\sqsubseteq }{_{{T}}} {\langle {T} {\ \Leftarrow \ } {U} \rangle \,{u}}, \end{equation*}
Furthermore, \({\Gamma } \vdash _{{\rm \mathtt {cast}}}{{\langle {T} {\ \Leftarrow \ } {U} \rangle \,{\langle {U} {\ \Leftarrow \ } {T} \rangle \,{t}}} \sqsupseteq \sqsubseteq {t}}\) .
Proof.
(DGG) Similarly to the proof of Theorem 32, we consider a context \({\mathcal {C}[ - ]} : ({\Gamma } \vdash {T}) \Rightarrow (\vdash {\mathbb {B}})\) . We know by monotonicity of the translation that \(\vdash _{{\rm \mathtt {cast}}}{\mathcal {C}[t]} [_{{\mathbb {B}}}]{\sqsubseteq }{_{{\mathbb {B}}}}{\mathcal {C}[t^{\prime }]}\) . We need to distinguish whether the evaluation of \({\mathcal {C}[t]}\) and \({\mathcal {C}[t^{\prime }]}\) terminates or not. If \({\mathcal {C}[t]}\) diverges, we are done. If \({\mathcal {C}[t]}\) terminates and \({\mathcal {C}[t^{\prime }]}\) diverges, by progress, \({\mathcal {C}[t]}\) reduces to a value \({v}\) and by Lemma 33, \(\lbrace {{{\mathcal {C}[t^{\prime }]}}}\rbrace _{} = {\rm \mathtt {err}}_{\lbrace {{{{\mathbb {B}}}}}\rbrace _{}}\) . This means that \(\lbrace {{{\mathcal {C}[t]}}}\rbrace _{} = {\rm \mathtt {err}}_{\lbrace {{{{\mathbb {B}}}}}\rbrace _{}}\) because \({\rm \mathtt {err}}_{\lbrace {{{{\mathbb {B}}}}}\rbrace _{}}\) is the smallest element of \(\ddot{\mathbb {B}}\) . Since \(\lbrace {{-}}\rbrace _{}\) is stable by conversion, \(\lbrace {{{v}}}\rbrace _{} = \lbrace {{{\mathcal {C}[t]}}}\rbrace _{} = {\rm \mathtt {err}}_{\lbrace {{{{\mathbb {B}}}}}\rbrace _{}}\) , and so \({v} = {\rm \mathtt {err}}_{{\mathbb {B}}}\) by case analysis of the possible values for \({v}\) . If both terminates, then the reasoning is the same as in the proof of Theorem 32.
(Ep-pairs) As for Theorem 32, this fact derives directly from the interpretation of the precision order as ep-pair s in the \(\omega\) -cpo model.

7 Gradual Indexed Inductive Types

We now explore how indexed inductive types, as used in the introduction (Example 1), can be handled in \(\mathsf {GCIC}\) . Recall the definition of \(\mathsf{vec}\) :
and recall the difference between parameters (here, \(\mathsf{A}\) ), which are common to all constructors, and indices (here, \(\mathsf{n}\) ), which can differ between constructors. Also recall from Section 4 that our formal development does not consider indexed inductive types, only parametrized ones.
This section first explains two alternatives to indexed inductive types that can directly be expressed in \(\mathsf {GCIC}\) (Section 7.1). We then describe how these alternatives actually behave in the gradual setting (Sections 7.2 and 7.3). Finally, we present an extension of \(\mathsf {CastCIC}\) to directly support indexed inductive types, focusing on the specific case of vectors (Section 7.4), showing that it combines the advantages of the other approaches. Section 7.5 summarizes our findings.

7.1 Alternatives to Indexed Inductive Types

Indexed inductive types make it possible to define structures that are intrinsically characterized by some property, which holds by construction, as opposed to extrinsically establishing such properties after the fact. There are two well-known alternatives to indexed inductive types for capturing properties intrinsically: type-level fixpoints, and “forded” inductive types.
The vector can be defined as a recursive function on the index, at the type level. For instance, the following formulation represents sized lists as nested pairs:
Type-level fixpoints can be used as soon as the indices are concretely forceable Brady et al. 2004. Intuitively, concretely forceable indices are those that can be matched upon (like \(\mathsf{n}\) in this example definition). See Gilbert et al. 2019 for a description of a general translation.
Instead of using an indexed inductive type, one can use a parametrized inductive type, with explicit equalities as arguments to constructors. 24 For instance, vectors can be defined in this style as follows:
Note that this definition uses \(\mathsf{eq_nat}\) , the type of decidable equality proofs over natural numbers, for expressing the constraints on \(\mathsf{n}\) instead of propositional equalities (e.g., \(\mathsf{0=n}\) ), because propositional equality is not available in \(\mathsf {GCIC}\) (Section 8.3).
In \(\mathsf {CIC}\) , these two alternative presentations of an indexed inductive type can be shown internally to be equivalent. But each of these presentations has advantages and drawbacks depending on the considered system and scenarios of use, so practitioners have different preferences in that respect. More important to us here, these presentations are not equivalent in \(\mathsf {GCIC}\) .

7.2 Type-level Fixpoints

Constructors. The definition of \(\mathsf{FVec}\) above can directly be written in \(\mathsf {GCIC}\) , as it uses only inductive types with parameters (here the unit and product types and natural numbers). The vector constructors can be defined as
whose definitions typecheck because \(\mathsf{FVec}\) computes on its indices.
Behavior. Let us now look at the type computed at \(?_\mathbb {N}\) . Because \(?_\mathbb {N}\) is an exceptional term, the fixpoint has to return unknown in the universe: \(\mathsf{FVec A ?_nat ==* ?_Type}\) . This means that the mechanism for casting a vector into a vector with the unknown index is directly inherited from the generic mechanism for casting to the unknown type. Therefore, we get for free the following computation rules, because they involve embedding-projection pairs:
Similarly, the eliminator \(\mathsf{FVec_rect}\) can be defined by first matching on the index, and then on the vector and satisfies the computation rule of vectors when the index is non-exceptional. The only drawback of this encoding is that the behavior of the eliminator is not satisfactory when the index is unknown. Consider for instance the following term from Example 1, which unfortunately reduces to \(\mathsf{?_nat}\) :
This behavior occurs because the eliminator starts by matching on the index, which is unknown, and thus has to return the unknown itself.

7.3 Fording with Decidable Equalities

Constructors. With the definition of the forded inductive type \(\mathsf{vec_eqdec}\) , the \(\mathsf{nil_eqdec}\) constructor can legitimately be used to inhabit \(\mathsf{vec_eqdec A ?_nat}\) , provided we have an inhabitant (possibly ?) of \(\mathsf{eq_nat 0 n}\) .
Note that we can provide the same vector interface as that of the indexed inductive type by defining the following constructor wrappers, using the term \(\mathsf{refl n}\) of reflexivity on \(\mathsf{eq_nat}\) :
and define the corresponding eliminator \(\mathsf{vec_rect^{\prime }}\) accordingly.
Behavior. The computational content of the eliminator on \(\mathsf{vec_eqdec A ?_nat}\) is more precise than with \(\mathsf{FVec}\) : the eliminator never matches on the proof of equality to produce a term, but only to guarantee that a branch is not accessible. Concretely, this means that we observe the expected reduction:
Again, the fact that upcasting to \(\mathsf{vec_eqdec A ?_nat}\) and then downcasting back is the identity relies on the \(\mathsf {CastCIC}\) mechanism on the unknown for the universe, but this time only for the type representing the decidable equality. Likewise, the example of \(\mathsf{filter}\) (Example 1) computes as expected:
On the other hand, an invalid assertion does not produce an error, but a term with an error in place of the equality proof:
where \(\mathsf{raise}\) is at type \(\mathsf{eq_nat 1 0}\) . Consequently, we have \(\mathsf{Dhead ?_nat (Dfilter nat 2 even [ 1 ; 3 ]) ==*}\) \(\mathsf{raise}\) , because the branch of \(\mathsf{Dhead}\) that deals with the \(\mathsf{nil}\) case matches on the (erroneous) equality proof. Invalid assertions are therefore very lazily observed, if at all, which is not satisfactory.
Finally, there is a drawback of using decidable equalities, which only manifests when working with the original vector interface ( \(\mathsf{nil^{\prime }}\) / \(\mathsf{cons^{\prime }}\) / \(\mathsf{vec_rect^{\prime }}\) ). In that case, the eliminator does not enjoy the expected computational rule on the constructor \(\mathsf{cons^{\prime }}\) . Because the eliminator is defined by induction on natural numbers, therefore it only reduces when the index is a concrete natural number, not a variable.

7.4 Direct Support for Indexed Inductive Types: The Case of Vectors

Extending \(\mathsf {GCIC}\) / \(\mathsf {CastCIC}\) with direct support for indexed inductive types can provide a fully satisfactory solution, in contrast to the two previously-exposed encodings that both have serious shortcomings. The idea is to reason about indices directly in the reduction of casts. Here, we expose this approach for the specific case of length-indexed vectors and leave a generalization to future work. Appendix E describes the extension for vectors in full details; here, we only present selected rules (Figure 19) and illustrate how reduction works.
Constructors. We add two new canonical forms, corresponding to the casts of \(\mathsf{nil}\) and \(\mathsf{cons}\) to \(\mathtt {vec}~A~?_{\mathbb {N}}\) : namely, \(\mathtt {nil}_?~A\) and \(\mathtt {cons}_?~A~a~n~v\) (Figure 19). Note that we cannot simply declare casts such as \(\langle {\mathtt {vec}~A~?_{\mathbb {N}}} {\ \Leftarrow \ } {\mathtt {vec}~A~n} \rangle \,{t}\) to be canonical, because they involve non-linear occurrences of types (here, \(A\) ).
Reduction rules. We add reduction rules to conduct casts between vectors in canonical forms. Figure 19 presents these rules when the argument of the cast is a \(\mathsf{cons}\) . Rule V-cons-? propagates the cast on the arguments, but using the newly-introduced \(\mathtt {cons}_?\) , effectively converting precise information to less precise information. Rule V-cons applies when both source and target indices are successors, and propagates the cast of the arguments, just like the standard rule for casting a constructor. As expected, Rule V-cons-nil raises an error when the indices do not match.
For the eliminator, there are two new computation rules, one for each new constructor: v-rectnilu and v-rect-consu. They both apply the eliminator to the underlying non-exceptional constructor, and then cast the result back to \(P~?_\mathbb {N}\) . Intuitively, these rules transfer the cast on vectors to a cast on the returned type of the predicate.
Behavior. Given these rules, we can actually realize the behavior described in Example 1. For instance, we have both
and coming back to Example 1, in all three \(\mathsf {GCIC}\) variants the term:
\(\mathsf{head ?_nat (filter nat 4 even [0; 1; 2; 3]),}\)
typechecks and reduces to \(\mathsf{0}\) . Additionally, as expected:
\(\mathsf{head ?_nat (filter nat 2 even [1; 3]),}\)
typechecks and fails at runtime. And similarly for Example 4.
Note that to be able to define the action of casts on vectors, we have crucially used the fact that it is possible to discriminate between \(\mathsf{0}\) , \(\mathsf{S n}\) , and \(?_\mathbb {N}\) in the reduction rule.

7.5 Summary

To summarize, the different approaches to define structures with intrinsic properties in \(\mathsf {GCIC}\) compare as follows:
The type-level fixpoint coincides with the indexed inductive presentation on non-exceptional terms, but is extremely imprecise in presence of unknown indices.
The forded inductive is more accurate when dealing with unknown indices, but is arguably too permissive with invalid index assertions.
The direct support of the indexed inductive type with additional constructors and reduction rules yields a satisfactory solution. We conjecture that this presentation can be generalized to support arbitrary indexed inductive types as long as they have concretely forceable indices; we leave such a general construction for future work.
Recall that fording is only an option in \(\mathsf {GCIC}\) when the indices pertain to a type with decidable equality; properly handling general propositional equality in a gradual type theory is an open question (Section 8.3). The constraint of indices being concretely forceable (for type-level fixpoints, direct support) are intuitively understandable and expected: gradual typing requires synthesizing dynamic checks; therefore, these checks need to be somehow computable.

8 Limitations and Perspectives

Up to now, we have left aside three important aspects of \(\mathsf {CIC}\) , namely, impredicativity, \(\eta\) -equality and propositional equality. This section explains the challenges induced by each feature, and possibly, venues to explore.

8.1 Impredicativity

In this work, we do not deal with the impredicative sort Prop, for multiple reasons. The models used in Section 6 to justify termination and graduality crucially rely on the predicativity of the universe hierarchy for the inductive-recursive definition of codes to be well-founded. Moreover, the results of Palmgren 1998Theorem 6.1 show that it is not possible to endow an impredicative universe with an inductive-recursive structure in a consistent and strongly-normalizing theory, hinting that it may be difficult to devise an inductively-defined cast function between types that belong to an impredicative universe. Additionally, it seems difficult to avoid the divergence of \(\Omega\) with an impredicative sort, as no universe levels can be used to prevent a self-application from being well-typed.

8.2 \(\eta\) -equality

In most presentations of \(\mathsf {CIC}\) , and, in particular, its \(\mathrm{Coq}\) implementation, conversion satisfies an additional rule, called \(\eta\) -equality, which corresponds to an extensional property for functions:
\begin{equation*} \Gamma \vdash f \equiv {\rm \lambda }x : A . f~x \quad \mbox{when} \quad \Gamma \vdash f:\Pi x:A . B. \end{equation*}
The difficulty of integrating \(\eta\) -equality in the setting of \(\mathsf {GCIC}\) is that the conversion we consider in \(\mathsf {CastCIC}\) is entirely induced by a notion of reduction: Two terms are convertible exactly when they have a common reduct up to \(\alpha\) -equivalence. It is well-known that \(\eta\) -equality cannot be easily modeled using a rewrite rule, as both \(\eta\) -expansion and \(\eta\) -reduction have significant drawbacks Goguen 2005, and so we would have to consider another approach to the one we took if we were to integrate \(\eta\) -equality. The most prominent alternative way is to define conversion as an alternation of reduction steps (for instance using a weak-head reduction strategy) not containing \(\eta\) and comparison of terms up to congruence and \(\eta\) -equality.
This approach has been recently formalized by Abel et al. 2018 in a fully-typed setting. That is, types participate crucially in the conversion relation: They are maintained during conversion, so that for instance comparison of terms at a \(\Pi\) -type systematically \(\eta\) -expands them before recursively calling conversion at the domain types. Defining a gradual variant of such a typed conversion might be quite interesting, but would require a significant amount of work.
On the contrary, a precise, formalized, account is still missing for \(\eta\) -equality for an untyped conversion as used in practice in the \(\mathrm{Coq}\) proof assistant and in \(\mathsf {GCIC}\) . The MetaCoq project, which aims at such a formalized account, leaves the treatment of \(\eta\) -equality to future work Sozeau et al. 2020. While we envision no specific issues to the adaptation to this approach to gradual typing once a clear and precise solution for \(\mathsf {CIC}\) itself has been reached, solving the issue in a satisfactory way for \(\mathsf {CIC}\) is obviously out of scope for this article. Thus, while it should in principle be possible to add \(\eta\) -equality to \(\mathsf {GCIC}\) , either via typed or untyped conversion, we leave this for future work.

8.3 Propositional Equality

In \(\mathsf {CIC}\) , propositional equality \(\mathsf{eq A x y}\) , corresponds to the Martin-Löf identity type Martin-Löf 1975, with a single constructor \(\mathsf{refl}\) for reflexivity, and the elimination principle known as \(\mathsf{J}\)
together with the conversion rule:
\(\mathsf{J A P x t x (refl A x) equiv t.}\)
For the sake of exposing the problem, suppose that we can define this identity type in \(\mathsf {GCIC}\) , while still satisfying canonicity, conservativity with respect to \(\mathsf {CIC}\) and graduality. This means that for an equality \(\mathsf{t = u}\) involving closed terms \(\mathsf{t}\) and \(\mathsf{u}\) of \(\mathsf {CIC}\) , there should only be three possible canonical forms: \(\mathsf{refl A t}\) whenever \(\mathsf{t}\) and \(\mathsf{u}\) are convertible terms (of type \(\mathsf{A}\) ), as well as \(\mathsf{raise}\) and \(\mathsf{?}\) .
Just under these assumptions, we can show that there exist two functions that are pointwise equal in \(\mathsf {CIC}\) , and hence equal by extensionality, but are no longer equivalent in \(\mathsf {GCIC}\) / \(\mathsf {CastCIC}\) . Consider the two functions \(\mathsf{id_nat}\) and \(\mathsf{add0}\) below:
In \(\mathsf {CIC}\) , these functions are not convertible, but they are observationally equivalent. However, they would not be observationally equivalent in \(\mathsf {GCIC}\) . To see why, consider the following term:
We have \(\mathsf{test id_nat ==* true}\) because, by \(\mathcal {G}\) , \(\mathsf{refl id_nat::?_Type::id_nat = id_nat ==* refl id_nat}\) . However, because \(\mathsf{add0}\) is not convertible to \(\mathsf{id_nat}\) , \(\mathsf{refl id_nat::id_nat = add0}\) cannot possibly reduce to \(\mathsf{refl}\) , and thus would need to reduce either to \({\rm \mathtt {err}}\) or ?; and so does \(\mathsf{test add0}\) .
This means that a model for such a gradual type theory would need to be intensional, conversely to the extensional models usually used to justify type theories. Studying such a model as well as exploring alternatives approaches to propositional equality in a gradual type theory are interesting venues for future work.

9 Related Work

Bidirectional typing and unification. Our framework uses a bidirectional version of the type system of \(\mathsf {CIC}\) . Although this presentation is folklore among type theory specialists McBride 2019, the type system of \(\mathsf {CIC}\) is rarely presented in this way on article and has been studied in details only recently Lennon-Bertrand 2021. However, the bidirectional approach becomes necessary when dealing with unification and elaboration of implicit arguments. Bidirectional elaboration is a common feature of proof assistant implementations, for instance Asperti et al. 2012, as it clearly delineates what information is available to the elaboration system in the different typing modes. In a context with missing information due to implicit arguments, those implementations face the undecidable higher-order unification Dowek 2001. In this error-less context, the solution must be a form of under-approximation, using complex heuristics Ziliani and Sozeau 2017. Deciding consistency is very close to unification, as observed by Castagna et al. 2019, but our notion of consistency over-approximates unification, making sure that unifiable terms are always consistent, relying on errors to catch invalid over-approximations at runtime.
Dependent types with effects. As explained in this article, introducing the unknown type of gradual typing also require, in a dependently-typed setting, to introduce unknown terms at any type. This means that a gradual dependent type theory naturally endorses an effectful mechanism, which is similar to having exceptions. This connects \(\mathsf {GCIC}\) to the literature on dependent types and effects. Several programming languages mix dependent types with effectful computation, either giving up on metatheoretical properties, such as Dependent Haskell Eisenberg 2016, or by restricting the dependent fragment to pure expressions Xi and Pfenning 1998 Swamy et al. 2016. In the context of dependent type theories, Pédrot and Tabareau 2017 2018 have leveraged the monadic approach to type theory, at the price of a weaker form of dependent large elimination for inductive types. The only way to recover full elimination is to accept a weaker form of logical consistency, as crystallized by the fire triangle between observable effects, substitution and logical consistency Pédrot and Tabareau 2020.
Ordered and directed type theories. The monotone model of \(\mathsf {CastCIC}\) interpret types as posets in order to give meaning to the notion of precision. Interpretations of dependent type theories in ordered structures goes back to various works on domain theoretic and realizability interpretations of (partial) Martin-Löf Type Theory Palmgren and Stoltenberg-Hansen 1990 Ehrhard 1988. More recently, Licata and Harper 2011 and North 2019 extend type theory with directed structures corresponding to a categorical interpretation of types, a higher version of the monotone model we consider.
Hybrid typing. Ou et al. 2004 present a programming language with separate dependently- and simply-typed fragments, using arbitrary runtime checks at the boundary. Knowles and Flanagan 2010 support runtime checking of refinements. In a similar manner, Tanter and Tabareau 2015 introduce casts for subset types with decidable properties in \(\mathrm{Coq}\) . They use an axiom to denote failure, which breaks weak canonicity. Dependent interoperability Osera et al. 2012 Dagand et al. 2018 supports the combination of dependent and non-dependent typing through deep conversions. All these approaches are more intended as programming languages than as type theories, and none support the notion of (im)precision that is at the heart of gradual typing.
Dependent contracts. Greenberg et al. 2010 relates hybrid typing to dependent contracts, which are dynamically-checked assertions that can relate the result of a function application to its argument Findler and Felleisen 2002. The semantics of dependent contracts are subtle because contracts include arbitrary code, and in particular one must be careful not to violate the precondition on the argument in the definition of the postcondition contract Blume and McAllester 2006. Also, blame assignment when the result and/or argument are themselves higher-order is subtle. Different variants of dependent contracts have been studied in the literature, which differ in terms of the violations they report and the way they assign blame Greenberg et al. 2010 Dimoulas et al. 2011. An in-depth exploration of blame assignment for gradual dependent type theories such as \(\mathsf {GCIC}\) is an important perspective for future work.
Gradual typing. The blame calculus of Wadler and Findler 2009 considers subset types on base types, where the refinement is an arbitrary term, as in hybrid type checking Knowles and Flanagan 2010. It however lacks the dependent function types found in other works. Lehmann and Tanter 2017 exploit the Abstracting Gradual Typing (AGT) methodology Garcia et al. 2016 to design a language with imprecise formulas and implication. They support dependent function types, but gradual refinements are only on base types refined with decidable logical predicates. Eremondi et al. 2019 also use AGT to develop approximate normalization and GDTL. While being a clear initial inspiration for this work, the technique of approximate normalization cannot yield a computationally-relevant gradual type theory (nor was its intent, as clearly stated by the authors). We hope that the results in our work can prove useful in the design and formalization of such gradual dependently-typed programming languages. Eremondi et al. 2019 study the dynamic gradual guarantee, but not its reformulation as graduality New and Ahmed 2018, which as we explain is strictly stronger in the full dependent setting. Finally, while AGT provided valuable intuitions for this work, graduality as embedding-projection pairs was the key technical driver in the design of \(\mathsf {CastCIC}\) .

10 Conclusion

We have unveiled a fundamental tension in the design of gradual dependent type theories between conservativity with respect to a dependent type theory such as \(\mathsf {CIC}\) , normalization, and graduality. We explore several resolutions of this Fire Triangle of Graduality, yielding three different gradual counterparts of \(\mathsf {CIC}\) , each compromising with one edge of the Triangle. We develop the metatheory of all three variants of \(\mathsf {GCIC}\) thanks to a common formalization, parametrized by two knobs controlling universe constraints on dependent product types in typing and reduction.
This work opens a number of perspectives for future work, in addition to addressing the limitations discussed in Section 8. The delicate interplay between universe levels and computational behavior of casts begs for a more flexible approach to the normalizing \(\mathsf {GCIC} ^{\mathcal {N}}\) , for instance using gradual universes. The approach based on multiple universe hierarchies to support logically consistent reasoning about exceptional programs Pédrot et al. 2019 could be adapted to our setting in order to provide a seamless integration inside a single theory of gradual features together with standard \(\mathsf {CIC}\) without compromising normalization. This could also open the door to supporting consistent reasoning about gradual programs in the context of \(\mathsf {GCIC}\) . On the more practical side, there is still a lot of challenges ahead in order to implement a gradual incarnation of \(\mathsf {GCIC}\) in \(\mathrm{Coq}\) or Agda, possibly parametrized in order to support the three variants presented in this work.

Footnotes

1
We use the notation \(\square _i\) for the predicative universe of types Type \(_i\) , and omit the universe level \(i\) when not required.
2
such as Unset Guard Checking in \(\mathrm{Coq}\) , or {-# TERMINATING #-} in Agda.
3
Note that we sometimes use “dependent type theory” in order to differentiate from the Gradual Type Theory of New et al. 2019, which is simply typed. But by default, in this article, the expression “type theory” is used to refer to a type theory with full dependent types, such as \(\mathsf {CIC}\) .
4
We write \(a :: A\) for a type ascription, which is syntactic sugar for \((\lambda x:A.x)\;a\) Siek and Taha 2006; in other systems, it can be taken as a primitive notion Garcia et al. 2016.
5
Not to be confused with logical consistency!
6
Observational error-approximation does not mention the case where \(\mathcal {C}[t]\) reduces to \(\mathtt {true}\) or \(\mathtt {false}\) but the quantification over all contexts ensures that, in that case, \(\mathcal {C}[u]\) must reduce to the same value.
7
In a dependently-typed programming language with separate typing and execution phases, this demand of the SGG is called the normalization gradual guarantee by Eremondi et al. 2019.
8
A minimal example of a well-typed \(\mathsf {CIC}\) term that is ill typed in \(\mathsf {CIC}^{\uparrow }\) is narrow : \(\mathbb {N}-\gt \square\) , where narrow n is the type of functions that accept n arguments. Such dependent arities violate the universe constraint of \(\mathsf {CIC}^{\uparrow }\) .
9
This is similar to what happens in practice in proof assistants such as \(\mathrm{Coq}\) The Coq Development Team 2020Core language, where terms input by the user in the Gallina language are first elaborated in order to add implicit arguments, coercions, and so on. The computation steps required by conversion are performed on the elaborated terms, never on the raw input syntax.
10
Written using a blue color.
11
The germ function corresponds to an abstraction function as in AGT Garcia et al. 2016, if one interprets the head \(h\) as the set of all types whose head type constructor is \(h\) . Wadler and Findler 2009 christened the corresponding notion a ground type, later reused in the gradual typing literature. This terminology however clashes with its prior use in denotational semantics Levy 2004: There a ground type is a first-order datatype. Note that Siek and Taha 2006 also call ground types the base types of the language, such as \(\mathbb {B}\) and \(\mathbb {N}\) . We therefore prefer the less overloaded term germ, used by analogy with the geometrical notion of the germ of a section MacLane and Moerdijk 1992: The germ of a head constructor represents an equivalence class of types that are locally the same.
12
In a simply-typed language such as GTLC Siek et al. 2015, where there are no neutrals at the type level, casts from a germ/ground type to the unknown type are usually interpreted as tagged values Siek and Taha 2006. Here, these correspond exactly to the canonical forms of \({?_{[]}}\) , but we also have to account for the many neutral forms that appear in open contexts.
13
We use green for terms of \(\mathsf {GCIC}\) . To maintain a distinction in the absence of colors, we also use tildes ( \({\tilde{t}}\) ) for terms in \(\mathsf {GCIC}\) in expressions mixing both source and target terms.
14
Typical ambiguity Harper and Pollack 1991 is the possibility to avoid giving explicit universe levels, letting the system decide whether a consistent assignment of levels can be found. In \(\mathrm{Coq}\) , for instance, one almost never has to be explicit about universe levels when writing Type.
15
Lemma 7 in Siek et al. 2015 is similar to our Theorem 20, and Figure 10 draws from their Figure 9, especially for Case-R and Case-L. Also, while we do not make them explicit here, Lemmas 8, 10, and 11 also appear in our proofs.
16
Thus, while Lemmas 17 and 18 correspond roughly to Lemma 9 in Siek et al. 2015, Lemmas 15 and 16 are completely novel.
17
In the Agda implementation, we deactivate the termination checker on the definition of the universe for the model interpreting \(\mathsf {CastCIC} ^{\mathcal {G}}\) ; thus, effectively working in a partial, inconsistent type theory.
18
This definition is indeed uniform if \(\mathtt {unit}\) is seen as the record type with no projection.
19
We abusively note \(\ddot{\mathbb {N}}\) for both the poset and its carrier to avoid introducing too many notations.
20
This decomposition is already present in New and Ahmed 2018 and to be contrasted with the AGT approach Garcia et al. 2016, which tends to pair a value with the most precise witness of its type, i.e., canonical path of minimal length.
21
Uniqueness of Identity Proofs; in HoTT parlance, \(\square \!\!\!\! \square _i\) , and \(\mathrm{El}\,A\) are hSets.
22
An analysis of the correspondence between the discrete and monotone models can be found in Appendix C.
23
For instance, \(\mathcal {ZFC}\) + the existence of Mahlo cardinals Setzer 2000 Forsberg 2013 Dybjer and Setzer 2003.
24
This technique has reportedly been coined “fording” by McBride 1999Section 3.5. Fording is in allusion to the Henry Ford quote “Any customer can have a car painted any color that he wants, so long as it is black.”
25
For instance the function swapping \({\rm \mathtt {err}}_{ \ddot{\mathbb {N}}{} }\) and \(?_{ \ddot{\mathbb {N}}{} }\) is not monotone.

A Index of Notations

DescriptionSymbolRefRemark
Section 4
Universe \([]_i\) Page 19At level \(i\)
Inductive type \(I@\lbrace i\rbrace (\mathbf {a})\) Page 19At level \(i\) with parameters \(\mathbf {a}\)
Inductive constructor \(c_k^I@\lbrace i\rbrace (\mathbf {a},\mathbf {b})\) Page 19 \(k\) th constructor of \(I\) at level \(i\) with parameters \(\mathbf {a}\) and arguments \(\mathbf {b}\)
Inductive destructor \({\rm \mathtt {ind}}_{I}(s,z.P,f.\mathbf {y}.\mathbf {b})\) Page 19corresponds to fix + match in Coq
Substitution \(t[u / x]\) Page 19extended to parallel substitution
Types of parameters \({\rm \mathbf {Params}}(I,i)\) Page 20of inductive \(I\) at level \(i\)
Types of arguments \({\rm \mathbf {Args}}(I,i,c_k)\) Page 20of constructor \(k\) of inductive \(I\) at level \(i\)
Substitution in parameters \({\rm \mathbf {Params}}(I,i)[\mathbf {a}]\) Page 20 
Substitution in arguments \({\rm \mathbf {Args}}(I,i,c_k)[\mathbf {a}, \mathbf {b}]\) Page 20 
Context checking \(\vdash \Gamma\) Figure 1 
Type inference \(\Gamma \vdash t {\rm \triangleright }T\) Figure 1 
Type checking \(\Gamma \vdash t {\rm \triangleleft }T\) Figure 1 
Constrained inference \(\Gamma \vdash t \blacktriangleright {\bullet }\) Figure 1 \(\bullet\) is either \(\Pi\) , \(I\) or \([]\)
One-step reduction \(\leadsto\) Figure 1full, i.e., with all congruences
Reduction \({\rm {\leadsto }^\ast }\) Figure 1reflexive, transitive closure of \(\leadsto\)
Conversion \(\equiv\) Figure 1 
Section 5
Unknown type \({?_{T}}\) Page 22in \(\mathsf {CastCIC}\)
Error \({{\rm \mathtt {err}}_{T}}\) Page 22 
Cast \(\langle {{T^{\prime }}} {\ \Leftarrow \ } {{T}} \rangle \,{{t}}\) Page 22 
Level of product type \(s_\Pi (i,j)\) Figure 2 
Level of product germ \(c_\Pi (i)\) Figure 2 
Type heads \({\rm Head}\) Figure 4 
Head of a type \(\mathrm{head}\,({T})\) Figure 4 
Germ \({\rm germ}_{i}\,h\) Figure 4Least precise type with head \(h\) at level \(i\)
Parallel reduction \(\Rrightarrow\) Lemma 7 
Canonical term \({\rm canonical}{t}\) Figure 7inductive caracterization
Neutral term \({\rm neutral}{t}\) Figure 7inductive caracterization
DescriptionSymbolRefRemark
Section 5
\(\alpha\) -consistency \({t} \sim _{\alpha }{t^{\prime }}\) Figure 8 
Consistent conversion \({t} \sim {t^{\prime }}\) Definition 5Also called consistency
Unknown type \({?@\lbrace i\rbrace }\) Page 28in \(\mathsf {GCIC}\) , at level \(i\)
Elaboration (inference) \({\Gamma } \vdash {t} {\rm \rightsquigarrow }{t^{\prime }} {\rm \triangleright }{T}\) Figure 9 
Elaboration (checking) \({\Gamma } \vdash {t} {\rm \triangleleft }{T} {\rm \rightsquigarrow }{t^{\prime }}\) Figure 9 
Elaboration (constrained) \({\Gamma } \vdash {t} {\rm \rightsquigarrow }{t^{\prime }} \blacktriangleright {\bullet } {T}\) Figure 9 
Structural precision \({\mathbb {\Gamma }} \vdash {t} \sqsubseteq _{\alpha }{t^{\prime }}\) Figure 10extended to contexts pointwise
Definitional precision \({\mathbb {\Gamma }} \vdash {t} \sqsubseteq _{\leadsto }{t^{\prime }}\) Figure 10extended to contexts pointwise
Typing in \(\mathsf {CIC}\) / \(\mathsf {CastCIC}\) \(\vdash _{\mathsf {CIC}}\) / \(\vdash _{{\rm \mathtt {cast}}}\) Section 5.5to differentiate between systems
Equiprecision \({\mathbb {\Gamma }} \vdash {t} \sqsupseteq \sqsubseteq _{\alpha }{t^{\prime }}\) Definition 7 
Erasure \(\varepsilon ({t})\) Definition 8 
Syntactic precision \({t} \sqsubseteq ^{\mathrm{G}}_{\alpha }{t^{\prime }}\) Figure 11 
Section 6
\(\mathsf {CIC}\) + Induction-Recursion \(\mathsf {CIC^{IR}}\) Section 6.1Target for the discrete model
Judgements for \(\mathsf {CIC^{IR}}\) \({\vdash _{\mathrm{IR}}}\)   
\(\mathsf {CIC^{IR}}\) + quotients \(\mathsf {CIC^{IR}_{QIT}}\)  Target for the monotone models
Universe of codes \(\square \!\!\!\! \square\) Figure 12 
Bipointed poset on inductive I \(\ddot{I}\) Section 6.1 
Top element in \(\ddot{I}\) \(\top _{\ddot{I}}\) Section 6.1 
Bottom element in \(\ddot{I}\) \(\bot _{\ddot{I}}\) Section 6.1 
Bipointed poset on \(\mathbb {N}\) \(\ddot{\mathbb {N}}{}\) Section 6.1 
Bipointed poset on \(\Sigma\) \({\ddot{\Sigma }}{}\) Section 6.1 
Code for nat \(\widehat{\mathbb {N}}\) Section 6.1 
Code for dependent product \(\widehat{\Pi }\) Section 6.1 
Code for universes \(\widehat{\square \!\!\!\! \square }_i\) Section 6.1 
Code for unknown types \(\widehat{?}_{i}\) Section 6.1 
Code for error type \(\widehat{{\rm \mathtt {err}}_{}}\) Section 6.1 
Decoding function to types \(\mathrm{El}\) Figures 12 and 17 \(\mathrm{El}: \square \!\!\!\! \square \rightarrow \square ^\le\)
Type heads \({\rm Head}_i\) Figure 4 
Head of a type \(\mathrm{head}\,(T)\) Figure 4 
Germ as a code \(\widehat{{\rm germ}}_{i}\,h\) Section 6.1 
Germ \({\rm germ}_{i}\,h\) Figure 4Least precise type with head \({h \in {\rm Head}_i}\) at level \(i\)
Cast in discrete model \({\rm \mathtt {cast}}\) Figure 14 
Discrete translation of types \([\![ {}{{\cdot }}]\!] {}\) Figure 15 
Discrete translation of terms \([{{\cdot }}]\) Figure 15 
Order on type \(A\) \(\sqsubseteq ^{A}\) Section 6.2 
Type of posets \(\square ^\le\) Section 6.2 
Monotone dependent product \({\rm \Pi }^{\text{mon}}{}\,A\,B\) Section 6.2 
Ep-pairs \(A \vartriangleleft {} B\) Definition 9 
Upcast \(\uparrow _d\) Definition 9Embedding part of an ep-pair \(d\)
Downcast \(\downarrow _d\) Definition 9Projection part of an ep-pair \(d\)
Monotone unknown type \(\ddot{?}_{i}\) Section 6.3 
Quotiented pairs in \(\ddot{?}_{i}\) \([{h};{x}]\) Section 6.3 
DescriptionSymbolRefRemark
Section 6
Top element in \(\ddot{?}_{i}\) \(\top _{\ddot{?}_{i}}\) Section 6.3 
Bottom element in \(\ddot{?}_{i}\) \(\bot _{\ddot{?}_{i}}\) Section 6.3 
Decoding function to ep-pair s \(\mathrm{El}{}_\varepsilon\) Figure 17 \(\mathrm{El}{}_\varepsilon (A{\sqsubseteq }B) : \mathrm{El}\,A \vartriangleleft {} \mathrm{El}\,B\)
Precision on terms \([_{A}]{\sqsubseteq }{_{B}}\) Figure 17 
Monotone translation of types \(\lbrace \!\mid \!{{\cdot }}\!\mid \!\rbrace _{}\) Figure 18 
Monotone translation of terms \(\lbrace {{\cdot }}\rbrace _{}\) Figure 18 
Propositional precision \({\Gamma } \vdash _{{\rm \mathtt {cast}}}{t} [_{{T}}]{\sqsubseteq }{_{{U}}} {u}\) Definition 4 
\(\omega\) -continuous maps \(A \rightarrow ^\omega B\) Section 6.7 \(A,B\) \(\omega\) -cpos
\(\omega\) -continuous ep-pair \(A \vartriangleleft ^\omega {} B\) Section 6.7 
Fig. 7.
Fig. 7. Head neutral and canonical forms for \(\mathsf {CastCIC}\) .
Fig. 8.
Fig. 8. \(\mathsf {CastCIC}\) : \(\alpha\) -consistency.
Fig. 9.
Fig. 9. Type-directed elaboration from \(\mathsf {GCIC}\) to \(\mathsf {CastCIC}\) .
Fig. 10.
Fig. 10. Structural precision in \(\mathsf {CastCIC}\) .
Fig. 11.
Fig. 11. Syntactic precision for \(\mathsf {GCIC}\) .
Fig. 12.
Fig. 12. Inductive-recursive encoding of the discrete universe hierarchy.
Fig. 13.
Fig. 13. Realization of exceptions.
Fig. 14.
Fig. 14. Definition of \({\rm \mathtt {cast}}\) (discrete model).
Fig. 15.
Fig. 15. Discrete translation from \(\mathsf {CastCIC}\) to \(\mathsf {CIC^{IR}}\) .
Fig. 16.
Fig. 16. Order structure on extended natural numbers.
Fig. 17.
Fig. 17. Monotone universe of codes and precision.
Fig. 18.
Fig. 18. Translation of the monotone model.
Fig. 19.
Fig. 19. New canonical forms and reduction rules for vectors in \(\mathsf {CastCIC}\) (excerpt).

B Complements on Elaboration and \(\mathsf {CastCIC}\)

This section gives an extended account of Section 5. The structure is the same, and we refer to the main section when things are already spelled out there.

B.1 \(\mathsf {CastCIC}\)

We state and prove a handful of standard, technical properties of \(\mathsf {CastCIC}\) , that are useful in the next sections. They should not be very surprising, the main specific point here is their formulation in the bidirectional setting.
Property 1 (Weakening).
If \({\Gamma } \vdash {t} {\rm \triangleright }{T}\) then \({\Gamma , \Delta } \vdash {t} {\rm \triangleright }{T}\) , and similarly for the other typing judgments.
Proof.
We show by (mutual) induction on the typing derivation the more general statement that if \({\Gamma , \Gamma ^{\prime }} \vdash {t} {\rm \triangleright }{T}\) then \({\Gamma , \Delta , \Gamma ^{\prime }} \vdash {t} {\rm \triangleright }{T}\) . It is true for the base cases (including the variable), and we can check that all rules preserve it.□
Property 2 (Substitution).
If \({\Gamma , x : A, \Delta } \vdash {t} {\rm \triangleright }{T}\) and \({\Gamma } \vdash {u} {\rm \triangleleft }{A}\) then \({\Gamma , \Delta [u / x]} \vdash {t[u / x]} {\rm \triangleright }{S}\) with \({S} \equiv {T[u / x]}\) .
Proof.
Again, the proof is by mutual induction on the derivation. In the checking judgment, we use the transitivity of conversion to conclude. In the constrained inference, we need injectivity of type constructors, which is a consequence of confluence.□
Property 3 (Validity).
If \({\Gamma } \vdash {t} {\rm \triangleright }{T}\) and \(\vdash {\Gamma }\) , then \({\Gamma } \vdash {T} \blacktriangleright {[]} {[]_i}\) for some \(i\) .
Proof.
Once again, this is a routine induction on the inference derivation, using subject reduction to handle the reductions in the constrained inference rules, to ensure that the reduced type is still well-formed. The hypothesis of context well-formedness is needed for the base case of a variable, to get that the type obtained from the context is indeed well-typed.□

B.2 Precision and Reduction

Structural lemmas. Let us start our lemmas by counterparts to the weakening and substitution lemmas for precision.
Lemma 35 (Weakening of Precision).
If \({\mathbb {\Gamma }} \vdash {t} \sqsubseteq _{\alpha }{t^{\prime }}\) , then \({\mathbb {\Gamma }, \mathbb {\Delta }} \vdash {t} \sqsubseteq _{\alpha }{t^{\prime }}\) for any \({\mathbb {\Delta }}\) .
Proof.
This is by induction on the precision derivation, using weakening of \(\mathsf {CastCIC}\) to handle the uses of typing.□
Lemma 36 (Substitution and Precision).
If \({\mathbb {\Gamma }, x : S \mid S^{\prime }, \mathbb {\Delta }} \vdash {t} \sqsubseteq _{\alpha }{t^{\prime }}\) , \({\mathbb {\Gamma }} \vdash {u} \sqsubseteq _{\alpha }{u^{\prime }}\) , \({\mathbb {\Gamma }_{1}} \vdash {u} {\rm \triangleleft }{S}\) and \({\mathbb {\Gamma }_{2}} \vdash {u^{\prime }} {\rm \triangleleft }{S^{\prime }}\) then \({\mathbb {\Gamma }, \mathbb {\Delta }[u \mid u^{\prime } / x]} \vdash {t[u / x]} \sqsubseteq _{\alpha }{t^{\prime }[u^{\prime } / x]}\) .
Proof.
The substitution property follows from weakening, again by induction on the precision derivation. Weakening is used in the variable case where \(x\) is replaced by \(u\) and \(u^{\prime }\) , and the substitution property of \(\mathsf {CastCIC}\) appears to handle the uses of typing.□
Catch-up lemmas. With these structural lemmas at hand, let us turn to the proofs of the catch-up lemmas.
Proof of Lemma 15
We want to prove the following: under the hypothesis that \({\mathbb {\Gamma }_{1}} \sqsubseteq _{\alpha }{\mathbb {\Gamma }_{2}}\) , if \({\mathbb {\Gamma }} \vdash {[]_i} \sqsubseteq _{\leadsto }{T^{\prime }}\) and \({\mathbb {\Gamma }_{2}} \vdash {T^{\prime }} \blacktriangleright {[]} {[]_{j}}\) , then either \({T^{\prime }} {\rm {\leadsto }^\ast }{?_{[]_{j}}}\) with \(i + 1 \le j\) , or \({T^{\prime }} {\rm {\leadsto }^\ast }{[]_i}\) .
The proof is by induction on the precision derivation, mutually with the same property where \(\sqsubseteq _{\leadsto }\) is replaced by \(\sqsubseteq _{\alpha }\) .
Let us start with the proof for \(\sqsubseteq _{\alpha }\) . Using the precision derivation, we can decompose \({T^{\prime }}\) into \({\langle {S_n} {\ \Leftarrow \ } {U_{n-1}} \rangle \,{\dots \langle {S_2} {\ \Leftarrow \ } {U_1} \rangle \,{T^{\prime \prime }}}}\) , where the casts come from Case-R rules, and \({T^{\prime \prime }}\) is either \({[]_i}\) (rule Diag-Univ) or \({?_{S}}\) for some \({S}\) (rule Unk), and we have \({\mathbb {\Gamma }} \vdash {[]_{i+1}} \sqsubseteq _{\leadsto }{S_k}\) , \({\mathbb {\Gamma }} \vdash {[]_{i+1}} \sqsubseteq _{\leadsto }{T_k}\) and \({\mathbb {\Gamma }} \vdash {[]_{i+1}} \sqsubseteq _{\leadsto }{S}\) . By induction hypothesis, all of \({S_k}\) , \({T_k}\) and \({S}\) reduce either to \({[]_{i+1}}\) or some \({?_{[]_l}}\) with \(i + 1 \le l\) . Moreover, because \({T^{\prime }}\) type-checks against \({[]_j}\) , we must have \({S_n} \equiv {[]_j}\) . This implies that \({S_n}\) cannot reduce to \({?_{[]_{l}}}\) by confluence, and thus it must reduce to \({[]_{i+1}}\) .
Using that \(i+1 \le l\) and rules Down-Unk, Univ-Univ, and Up-Down giving, respectively
\begin{align*} {\langle {X} {\ \Leftarrow \ } {?_{[]_l}} \rangle \,{?_{?_{[]_l}}}} &\leadsto {?_X,} \\ {\langle {[]_{i+1}} {\ \Leftarrow \ } {[]_{i+1}} \rangle \,{t}} &\leadsto {t,} \\ {\langle {X} {\ \Leftarrow \ } {?_{[]_{l}}} \rangle \,{\langle {?_{[]_{l}}} {\ \Leftarrow \ } {[]_{i+1}} \rangle \,{t}}} &\leadsto {\langle {X} {\ \Leftarrow \ } {[]_{i+1}} \rangle \,{t,}} \end{align*}
we can reduce away all casts. We thus get \({T^{\prime }} {\rm {\leadsto }^\ast }{[]_i}\) or \({T^{\prime }} {\rm {\leadsto }^\ast }{?_{[]_{i+1}}}\) , as expected.
For \(\sqsubseteq _{\leadsto }\) , if \({\mathbb {\Gamma }} \vdash {[]_i} \sqsubseteq _{\leadsto }{T^{\prime }}\) then by decomposing the precision derivation there is an \({S^{\prime }}\) such that \({T^{\prime }} {\rm {\leadsto }^\ast }{S^{\prime }}\) , \({\mathbb {\Gamma }} \vdash {[]_i} \sqsubseteq _{\alpha }{S^{\prime }}\) , and by subject reduction \({\mathbb {\Gamma }_{1}} \vdash {S^{\prime }} \blacktriangleright {[]} {[]_j}\) . By induction hypothesis, either \({S^{\prime }} {\rm {\leadsto }^\ast }{[]_i}\) or \({S^{\prime }} {\rm {\leadsto }^\ast }{?_{[]_{i+1}}}\) , and composing both reductions we get the desired result.□
Proof of Lemma 16
The proof of those catch-up lemmas is very similar to the previous one for structural precision, but this time without the need for induction—we use Lemma 15 instead. We show the one for product types, the others are identical.
First, let us show the property for \(\sqsubseteq _{\alpha }\) . Decompose \({T^{\prime }}\) into \({\langle {S_n} {\ \Leftarrow \ } {U_{n-1}} \rangle \,{\dots \langle {S_2} {\ \Leftarrow \ } {U_1} \rangle \,{T^{\prime \prime }}}}\) , where \({T^{\prime \prime }}\) is not a cast, but either some \({?_{S}}\) or a product type structurally less precise than \({{\rm \Pi }x : A.B}\) . Now by Lemma 15, \({U_k}\) , \({T_k}\) and possibly \({S}\) all reduce to \({[]}\) or \({?_{[]}}\) . Using the same reduction rules as before, all casts can be reduced away, leaving us with either \({?_{[]}}\) or a product type structurally less precise than \({{\rm \Pi }x : A.B}\) , as stated.□
Proof of Lemma 17
The proof still follows the same idea: decompose the less precise term as a series of casts, and show that all those casts can be reduced, using Lemma 16 for product types. However it is somewhat more complex, because the reduction of a cast between product types does a substitution, which we need to handle using the previous substitution lemma for precision.
Let us now detail the reasoning. First, decompose \({s^{\prime }}\) into \({\langle {S_n} {\ \Leftarrow \ } {U_{n-1}} \rangle \,{\dots \langle {S_2} {\ \Leftarrow \ } {U_1} \rangle \,{u^{\prime }}}}\) , where \({u^{\prime }}\) is either \({{\rm \lambda }x : A^{\prime \prime }. t^{\prime \prime }}\) or \({?_{S}}\) for some \({S}\) . All of the \({S_k}\) , \({U_k}\) and possibly \({S}\) are definitionally less precise than \({{\rm \Pi }x : A. B}\) . By definition of \(\sqsubseteq _{\leadsto }\) they all reduce to a term structurally less precise than a reduct of \({{\rm \Pi }x : A . B}\) , which must be a product type, and thus by Lemma 16 they all reduce to either some \({?_{[]_{j}}}\) or some product type. Moreover, given the typing hypothesis and confluence \({S_n}\) can only be in the second case. By rule Down-Unk, we get
\begin{equation*} {\langle {X} {\ \Leftarrow \ } {?_{[]}} \rangle \,{?_{?_{[]}}} \leadsto ?_{X,}} \end{equation*}
so if \({S}\) is \({?_{[]}}\) we can reduce the innermost casts until it is (knowing that we will encounter one because \({S_n}\) is a product type), then use rule Unk on \({u^{\prime }}\) if it applies, so that without loss of generality we can suppose that \({u^{\prime }}\) is an abstraction.
Now we show that all casts reduce, and that this reduction preserves precision, starting with the innermost one. There are three possibilities for that innermost cast.
If it is \({\langle {?_{[]_j}} {\ \Leftarrow \ } {{\rm germ}_{j}\,\Pi } \rangle \,{u^{\prime }}}\) , then by typing this cannot be the outermost cast, and thus rule Up-Down applies to get
\begin{equation*} { \langle {X} {\ \Leftarrow \ } {?_{[]_j}} \rangle \,{\langle {?_{[]_j}} {\ \Leftarrow \ } {{\rm germ}_{j}\,\Pi } \rangle \,{u^{\prime }}} \leadsto \langle {X} {\ \Leftarrow \ } {{\rm germ}_{j}\,\Pi } \rangle \,{u^{\prime }} }. \end{equation*}
In the second case, the cast is some \({\langle {{\rm \Pi }x : A_2. B_2} {\ \Leftarrow \ } {{\rm \Pi }x : A_1. B_1} \rangle \,{{\rm \lambda }x : A^{\prime \prime }. t^{\prime \prime }}}\) , and rule Prod-Prod applies to give
\begin{equation*} \begin{array}{r} {\langle {{\rm \Pi }x : A_2. B_2} {\ \Leftarrow \ } {{\rm \Pi }x : A_1. B_1} \rangle \,{{\rm \lambda }x : A^{\prime \prime }. t^{\prime \prime }}} \leadsto \hspace{120.0pt} \\ {{\rm \lambda }x : A^{\prime \prime } . \langle {B_2} {\ \Leftarrow \ } {B_1[\langle {A_1} {\ \Leftarrow \ } {A_2} \rangle \,{x} / x]} \rangle \,{t^{\prime \prime }[\langle {A^{\prime \prime }} {\ \Leftarrow \ } {A_2} \rangle \,{x} / x].}} \end{array} \end{equation*}
Moreover, using the precision hypothesis of Case-R, we know that \({\mathbb {\Gamma }} \vdash {{\rm \Pi }x : A . B} \sqsubseteq _{\leadsto }{{\rm \Pi }x : A_1 . B_2}\) and \({\mathbb {\Gamma }} \vdash {{\rm \Pi }x : A . B} \sqsubseteq _{\leadsto }{{\rm \Pi }x : A_2 . B_2}\) . From the first one, using substitution and rule Case-R, we get that \({\mathbb {\Gamma }, x : A \mid A_2} \vdash {B} \sqsubseteq _{\leadsto }{B_1[\langle {A_1} {\ \Leftarrow \ } {A_2} \rangle \,{x} / x]}\) . The second gives in particular that \({\mathbb {\Gamma }} \vdash {A} \sqsubseteq _{\leadsto }{A_2}\) . Finally, inverting the proof of \({\mathbb {\Gamma }} \vdash {{\rm \lambda }x : A . t} \sqsubseteq _{\alpha }{{\rm \lambda }x : A^{\prime \prime } . t^{\prime \prime }}\) we also have \({\mathbb {\Gamma }} \vdash {A} \sqsubseteq _{\alpha }{A^{\prime \prime }}\) and \({\mathbb {\Gamma }, x : A \mid A^{\prime \prime }} \vdash {t} \sqsubseteq _{\alpha }{t^{\prime \prime }}\) . From this, again by substitution, we can derive \({\mathbb {\Gamma }, x : A \mid A^{\prime \prime }} \vdash {t} \sqsubseteq _{\alpha }{t^{\prime \prime }[\langle {A^{\prime \prime }} {\ \Leftarrow \ } {A_2} \rangle \,{x} / x]}\) . Combining all of those, we can construct a derivation of
\begin{equation*} {\mathbb {\Gamma }} \vdash {{\rm \lambda }x : A . t} \sqsubseteq _{\alpha }{{\rm \lambda }x : A_2 . \langle {B_2} {\ \Leftarrow \ } {B_1[\langle {A_1} {\ \Leftarrow \ } {A_2} \rangle \,{x} / x]} \rangle \,{t^{\prime }[\langle {A^{\prime \prime }} {\ \Leftarrow \ } {A_2} \rangle \,{x} / x]}}, \end{equation*}
by a use of Diag-Abs followed by one of Case-R.
The last case corresponds to \({\langle {?_{[]_j}} {\ \Leftarrow \ } {{\rm \Pi }x : A^{\prime \prime } . B^{\prime \prime }} \rangle \,{u^{\prime }}}\) when \({{\rm \Pi }x : A^{\prime \prime } . B^{\prime \prime }}\) is not \({{\rm germ}_{j}\,h}\) , in which case the reduction that applies is Prod-Germ, giving
\begin{equation*} {\langle {?_{[]_j}} {\ \Leftarrow \ } {{\rm \Pi }x : A^{\prime \prime } . B^{\prime \prime }} \rangle \,{u^{\prime }}} \leadsto {\langle {?_{[]_j}} {\ \Leftarrow \ } {?_{[]_{c_\Pi (j)}} \rightarrow ?_{[]_{c_\Pi (j)}}} \rangle \,{\langle {?_{[]_{c_\Pi (j)}} \rightarrow ?_{[]_{c_\Pi (j)}}} {\ \Leftarrow \ } {{\rm \Pi }x : A^{\prime \prime } . B^{\prime \prime }} \rangle \,{u^{\prime }}}}. \end{equation*}
For this reduct to be less precise that \({{\rm \lambda }x : A. t}\) , we need that all types involved in the casts are definitionally precise than \({{\rm \Pi }x : A . B}\) , as we already have that \({\mathbb {\Gamma }} \vdash {{\rm \lambda }x : A . t } \sqsubseteq _{\alpha }{u^{\prime }}\) . For \({?_{[]_j}}\) and \({{\rm \Pi }x : A^{\prime \prime }. B^{\prime \prime }}\) it is direct, as they were obtained using Lemma 16 with a reduct of \({{\rm \Pi }x : A . B}\) . Thus only the germ remains, for which it suffices to show that both \({A}\) and \({B}\) are less precise than \({?_{[]_{c_\Pi (j)}}}\) . Because \({{\rm \Pi }x : A. B}\) is typable and less precise than \({?_{[]_j}}\) , we know that \({\mathbb {\Gamma }_{1}} \vdash {A} \blacktriangleright {[]} {[]_k}\) and \({\mathbb {\Gamma }_{1}, x : A} \vdash {B} \blacktriangleright {[]} {[]_l}\) with \(s_\Pi (k,l) \le j\) , thus \(k \le c_\Pi (j)\) and \(l \le c_\Pi (j)\) . Therefore \({\mathbb {\Gamma }} \vdash {A} \sqsubseteq _{\alpha }{?_{[]_{c_\Pi (j)}}}\) using rule Unk-Univ, and similarly for \({B}\) .
Note that this last reduction is the point where the system under consideration plays a role: in \(\mathsf {CastCIC} ^{\mathcal {N}}\) , the reasoning does not hold. However, when considering only terms without \({?}\) , this case never happens, and thus the rest of the proof still applies.
Thus, all casts must reduce, and each of those reductions preserves precision, so we end up with a term \({{\rm \lambda }x : A^{\prime } . t^{\prime }}\) such that \({\mathbb {\Gamma }} \vdash {{\rm \lambda }x : A . t} \sqsubseteq _{\alpha }{{\rm \lambda }x : A^{\prime } . t^{\prime }}\) , as expected.□
Proof of Lemma 18
We start by the proof of the second property. We have a hypothesis that \({\mathbb {\Gamma }} \vdash {?_{I(\mathbf {a})}} \sqsubseteq _{\alpha }{s^{\prime }}\) , \({\mathbb {\Gamma }_{1}} \vdash {?_{I(\mathbf {a})}} {\rm \triangleright }{I(\mathbf {a})}\) and \({\mathbb {\Gamma }_{2}} \vdash {s^{\prime }} \blacktriangleright {I} {I(\mathbf {a^{\prime }})}\) , and wish to prove that \({s^{\prime }} {\rm {\leadsto }^\ast }{?_{I(\mathbf {a^{\prime }})}}\) with \({\mathbb {\Gamma }} \vdash {I(\mathbf {a})} \sqsubseteq _{\alpha }{I(\mathbf {a^{\prime }})}\) .
As previously, decompose \({s^{\prime }}\) as \({\langle {S_n} {\ \Leftarrow \ } {U_{n-1}} \rangle \,{\dots \langle {S_2} {\ \Leftarrow \ } {U_1} \rangle \,{?_{I(\mathbf {a^{\prime \prime }})}}}}\) , where all \({U_k}\) , \({S_k}\) and \({I(\mathbf {a^{\prime \prime }})}\) are definitionally less precise than \({I(\mathbf {a})}\) , and thus reduce to either \({?_{[]_l}}\) for some \(l\) , or \({I(\mathbf {c})}\) for some \({\mathbf {c}}\) , and \({S_n}\) can only be the second by typing. Using the three rules Ind-Unk, Up-Down and Ind-Germ, we respectively get
\begin{align*} {\langle {I(\mathbf {c^{\prime }})} {\ \Leftarrow \ } {I(\mathbf {c})} \rangle \,{?_{I(\mathbf {c^{\prime \prime }})}}} &\leadsto {?_{I(\mathbf {c^{\prime }}),}} \\ { \langle {X} {\ \Leftarrow \ } {?_{[]_j}} \rangle \,{\langle {?_{[]_j}} {\ \Leftarrow \ } {{\rm germ}_{j}\,I} \rangle \,{u^{\prime }}}} &\leadsto {\langle {X} {\ \Leftarrow \ } {{\rm germ}_{j}\,I} \rangle \,{u^{\prime }}}, \\ {\langle {?_{[]_j}} {\ \Leftarrow \ } {I(\mathbf {c})} \rangle \,{u^{\prime }}} & \leadsto {\langle {?_{[]_j}} {\ \Leftarrow \ } {{\rm germ}_{j}\,I} \rangle \,{\langle {{\rm germ}_{j}\,I} {\ \Leftarrow \ } {I(\mathbf {c})} \rangle \,{u^{\prime }}},} \end{align*}
we can reduce all casts: Up-Down (possibly using Section refredrule:ind-germ first) removes all casts through \(?_{[]}\) ; we can then use Ind-Unk to propagate \(?_{I(\mathbf {a^{\prime \prime }})}\) all the way through the casts, ending up with \({?_{S_n}}\) , which is the term we sought.
For the first property, again decompose \({s^{\prime }}\) as \({\langle {S_n} {\ \Leftarrow \ } {U_{n-1}} \rangle \,{\dots \langle {S_2} {\ \Leftarrow \ } {U_1} \rangle \,{u^{\prime }}}}\) where \({u^{\prime }}\) does not start with a cast. If \({u^{\prime }}\) is some \({?_{I(\mathbf {a^{\prime \prime }})}}\) , we can re-use the proof above and are finished. Otherwise \({u^{\prime }}\) must be of the form \({c(\mathbf {a^{\prime \prime }},\mathbf {b^{\prime \prime }})}\) . Again we reduce the casts starting with the innermost, using rules Up-Down and Ind-Germ to remove the occurrences of \({?_{[]}}\) . The last case to handle is \({\langle {I(\mathbf {c^{\prime }})} {\ \Leftarrow \ } {I(\mathbf {c})} \rangle \,{c(\mathbf {a_3},\mathbf {b_3})}}\) . Then rule Ind-Ind applies, and it preserves precision by repeated uses of the substitution property, and giving a term with \({c}\) as a head constructor. Thus, we get the desired term with \({c}\) as a head constructor and arguments less precise than \({\mathbf {a}}\) and \({\mathbf {b}}\) , respectively.□
Simulation.
Proof of Theorem 20
Both are shown by mutual induction on the precision derivation. We use a stronger induction principle that the one given by the induction rules. Indeed, we need extra induction hypothesis on the inferred type for a term. Proving this stronger principle is done by making the proof of Property 3 slightly more general: instead of proving that an inferred type is always well-formed, we prove that any property consequence of typing is true of all inferred types. Let us now detail the most important cases of the inductive proof.
Definitional precision. We start with the easier second point. The proof is summarized by the following diagram:
By definition of \(\sqsubseteq _{\leadsto }\) , there exists \({u}\) and \({u^{\prime }}\) , reducts, respectively of \({t}\) and \({t^{\prime }}\) , and such that \({\mathbb {\Gamma }} \vdash {u} \sqsubseteq _{\alpha }{u^{\prime }}\) . By confluence, there exists some \({v}\) that is a reduct of both \({u}\) and \({s}\) . By subject reduction, \({u}\) and \({u^{\prime }}\) are both well-typed, and thus by induction hypothesis there exists \({v^{\prime }}\) such that \({u^{\prime }} {\rm {\leadsto }^\ast }{v^{\prime }}\) and \({\mathbb {\Gamma }} \vdash {v} \sqsubseteq _{\alpha }{v^{\prime }}\) . But then \({v}\) is a reduct of \({s}\) and \({v^{\prime }}\) is a reduct of \({t^{\prime }}\) , and so \({\mathbb {\Gamma }} \vdash {s} \sqsubseteq _{\leadsto }{t^{\prime }}\) .
This implies in particular that if \({\mathbb {\Gamma }} \vdash {t} {\rm \triangleright }{T}\) , \({\mathbb {\Gamma }} \vdash {T} \sqsubseteq _{\leadsto }{T^{\prime }}\) , \({t} {\rm {\leadsto }^\ast }{s}\) and \({\mathbb {\Gamma }_{1}} \vdash {s} {\rm \triangleright }{S}\) , then \({\mathbb {\Gamma }} \vdash {S} \sqsubseteq _{\leadsto }{T^{\prime }}\) . Indeed \({\mathbb {\Gamma }_{1}} \vdash {s} {\rm \triangleleft }{T}\) by subject reduction, thus \({S}\) and \({T}\) are convertible, and have a common reduct \({U}\) by confluence. The property just stated then gives \({\mathbb {\Gamma }} \vdash {U} \sqsubseteq _{\leadsto }{T^{\prime }}\) ; hence, \({\mathbb {\Gamma }} \vdash {S} \sqsubseteq _{\leadsto }{T^{\prime }}\) .
Syntactic precision—Non-diagonal precision rules. Let us now turn to \(\sqsubseteq _{\alpha }\) . It is enough to show that one step of reduction can be simulated, by induction on the path \({t} {\rm {\leadsto }^\ast }{s}\) .
First, we get rid of most cases where the last rule used for \({\mathbb {\Gamma }} \vdash {t} \sqsubseteq _{\alpha }{t^{\prime }}\) is not a diagonal rule. For Unk, we must handle the side-condition involving the type of \({t}\) . However, by the previous property, the inferred type of \({s}\) is also definitionally less precise than \({T^{\prime }}\) . Thus, the reduction in \({t}\) can be simulated by zero reduction steps. The reasoning for rules Err and Err-Lambda is similar. As for rule Diag-Univ, subject reduction is enough to get what we seek, without even resorting to the previous property. Rule Case-R is treated in the same way as Unk, as the typing side-conditions are similar. Thus the only non-diagonal rule left for \(\sqsubseteq _{\alpha }\) is Case-L.
Syntactic precision—Non-top-level reduction. Next, we can get rid of reductions that do not happen at top level. Indeed, if the last rule used was Case-L, and the reduction happens in one of the types of the cast, the same reasoning as for Case-R applies. If it happens in the term, we can use the induction hypothesis on this term to conclude. Also, if the last rule used was a diagonal rule, then the reduction in \({t}\) can be simulated by a similar congruence rules in \({t^{\prime }}\) .
So we are left with the simulation of a reduction that happens at the top-level in \({t}\) , and where the last precision rule used is either Case-L or a diagonal one, and this is the real core of the proof.
Syntactic precision—non-diagonal cast. Let us first turn to the case where the last precision rule is Case-L, and that cast reduces. More precisely, \({t}\) is some \({\langle {T} {\ \Leftarrow \ } {S} \rangle \,{u}}\) , with \({\mathbb {\Gamma }} \vdash {u} \sqsubseteq _{\alpha }{t^{\prime }}\) . There are four possibilities for the reduction.
The cast fails. When it does, whatever the rule, it always reduces to \({{\rm \mathtt {err}}_{T}}\) . But then we know that \({\mathbb {\Gamma }_{2}} \vdash {t^{\prime }} {\rm \triangleright }{T^{\prime }}\) and \({\mathbb {\Gamma }} \vdash {T} \sqsubseteq _{\leadsto }{T^{\prime }}\) . Thus \({\mathbb {\Gamma }} \vdash {{\rm \mathtt {err}}_{T}} \sqsubseteq _{\alpha }{t^{\prime }}\) by rule Err, and the reduction is simulated by zero reductions.
The cast disappears (Univ-Univ) or expands into two casts without changing \({u}\) (Ind-Germ, Prod-Germ). In those cases the reduct of \({t}\) is still smaller than \({t^{\prime }}\) . In the case of cast expansion, we must use Case-L twice, and thus prove that the type of \({t^{\prime }}\) is less precise than the introduced germ. But by the Case-L rule that was used to prove \({\mathbb {\Gamma }} \vdash {t} \sqsubseteq _{\alpha }{t^{\prime }}\) , we know that \({t^{\prime }}\) infers a type \({T^{\prime }}\) , which is definitionally less precise than some \({?_{[]_i}}\) . Thus, \({T^{\prime }}\) reduces to some \({S^{\prime }}\) such that \({\mathbb {\Gamma }} \vdash {?_{[]_i}} \sqsubseteq _{\alpha }{S^{\prime }}\) , and this implies that also \({\mathbb {\Gamma }} \vdash {{\rm germ}_{i}\,h} \sqsubseteq _{\alpha }{S^{\prime }}\) , i.e., what we sought.
Both \({T}\) and \({S}\) are either product types or inductive types, and \({u}\) starts with an abstraction or an inductive constructor. In that case, by Lemmas 17 and 18, \({t^{\prime }}\) reduces to a term \({u^{\prime }}\) with the same head constructor as \({u}\) or some \({?_{I(\mathbf {a})}}\) . In the first case, by the substitution property of precision we have \({\mathbb {\Gamma }} \vdash {s} \sqsubseteq _{\alpha }{u^{\prime }}\) . In the second, we can use Unk to conclude.
The reduction rule is Up-Down, that is \({t}\) is \({\langle {T} {\ \Leftarrow \ } {?_{[]_i}} \rangle \,{\langle {?_{[]_i}} {\ \Leftarrow \ } {{\rm germ}_{i}\,h} \rangle \,{u}}}\) which reduces to \({\langle {T} {\ \Leftarrow \ } {{\rm germ}_{i}\,h} \rangle \,{u}}\) . If rule Case-L was used twice in a row then we directly have \({\mathbb {\Gamma }} \vdash {u} \sqsubseteq _{\alpha }{t^{\prime }}\) and so \({\mathbb {\Gamma }} \vdash {\langle {X} {\ \Leftarrow \ } {{\rm germ}_{i}\,h} \rangle \,{u}} \sqsubseteq _{\alpha }{t^{\prime }}\) . Otherwise, rule Diag-Cast was used, \({t^{\prime }}\) is some \({\langle {T^{\prime }} {\ \Leftarrow \ } {S^{\prime }} \rangle \,{u^{\prime }}}\) and we have \({\mathbb {\Gamma }} \vdash {u} \sqsubseteq _{\alpha }{u^{\prime }}\) and \({\mathbb {\Gamma }_{1}} \vdash {{\rm germ}_{i}\,h} \sqsubseteq _{\leadsto }{S^{\prime }}\) . Moreover, Case-L also gives \({\mathbb {\Gamma }_{1}} \vdash {X} \sqsubseteq _{\leadsto }{B^{\prime }}\) , since \({\mathbb {\Gamma }_{2}} \vdash {\langle {B^{\prime }} {\ \Leftarrow \ } {A^{\prime }} \rangle \,{u^{\prime }}} {\rm \triangleright }{B^{\prime }}\) . Thus \({\mathbb {\Gamma }} \vdash {\langle {X} {\ \Leftarrow \ } {{\rm germ}_{i}\,h} \rangle \,{u}} \sqsubseteq _{\alpha }{\langle {B^{\prime }} {\ \Leftarrow \ } {A^{\prime }} \rangle \,{u^{\prime }}}\) by a use of Diag-Cast.
Syntactic precision— \(\beta\) redex. Next, we consider the case where \({t}\) is a \(\beta\) redex \({({\rm \lambda }x : A . t_1)~t_2}\) . Because the last applied precision rule is diagonal, \({t^{\prime }}\) must also decompose as \({t_1^{\prime \prime }~t_2^{\prime }}\) . If \({t_1}\) is some \({{\rm \mathtt {err}}_{T}}\) , then the reduct is \({{\rm \mathtt {err}}_{T}}\) and must be still smaller that \({t^{\prime }}\) . Otherwise, Lemma 17 applies; thus, \({t_1^{\prime \prime }}\) reduces to some \({{\rm \lambda }x : A^{\prime } . t_1^{\prime }}\) that is syntactically less precise than \({{\rm \lambda }x : A . t_1}\) . Then the \(\beta\) reduction of \(t\) can be simulated with a \(\beta\) reduction in \({t^{\prime }}\) , and using the substitution property we conclude that the redexes are still related by precision.
Syntactic precision— \(\iota\) redex. If \({t}\) is a \(\iota\) redex \({{\rm \mathtt {ind}}_{c(\mathbf {a},\mathbf {b})}(I,z.P,\mathbf {f.\mathbf {y}.t})}\) , the reasoning is similar. Because the last precision rule is diagonal, \({t^{\prime }}\) must also be a fixpoint. We thus can use Lemma 18 to ensure that its scrutinee reduces either to \({c(\mathbf {a^{\prime }},\mathbf {b^{\prime }})}\) or \({?_{I(\mathbf {a^{\prime }})}}\) . In the first case, a \(\iota\) reduction of \({t^{\prime }}\) and the substitution property is enough to conclude. In the second case, \({t^{\prime }}\) reduces to a term \({s^{\prime }} := {?_{P^{\prime }[?_{I(\mathbf {a^{\prime }})} / z]}}\) , and we must show this term to be less precise than \({s}\) , which is \({t_k[ {\rm \lambda }x : I(\mathbf {a}) . {\rm \mathtt {ind}}_{I}(x,z.P,\mathbf {f.\mathbf {y}.t}) / z][\mathbf {b} / \mathbf {y}]}\) . Let \({S}\) be the type inferred for \({s}\) , by rule Unk, it is enough to show \({\mathbb {\Gamma }} \vdash {S} \sqsubseteq _{\leadsto }{P^{\prime }[?{}_{I(\mathbf {a^{\prime }})} / z]}\) . By subject reduction, \({S}\) and \({P[c_k(\mathbf {a},\mathbf {b}) / z]}\) (the type of \({t}\) ) are convertible, thus they have a common reduct \({U}\) . Now we also have by substitution that \({\mathbb {\Gamma }} \vdash {P[c_k(\mathbf {a},\mathbf {b}) / z]} \sqsubseteq _{\alpha }{P^{\prime }[?_{I(\mathbf {a^{\prime }})} / z]}\) . Because \({P[c_k(\mathbf {a},\mathbf {b}) / z]}\) is the inferred type for \({t}\) , the induction hypothesis applies to it, and thus there is some \({U^{\prime }}\) such that \(P^{\prime }{[}? _{I(a^{\prime })}z/ {]} {\rm {\leadsto }^\ast }{U^{\prime }}\) and also \({\mathbb {\Gamma }} \vdash {U} \sqsubseteq _{\alpha }{U^{\prime }}\) .
Syntactic precision— \({\rm \mathtt {err}}\) and \(?\) reductions. For reductions Err, i.e., when \({{\rm \mathtt {err}}_{{\rm \Pi }x : A.B}} \leadsto {{\rm \lambda }x : A . {\rm \mathtt {err}}_B}\) , we can replace the use of Err by a use of Err-Lambda. For reduction Prod-Err, i.e., when \({t}\) is \({{\rm \mathtt {ind}}_{I}({\rm \mathtt {err}}_{I(\mathbf {a})},z.P,\mathbf {f.y.t})}\) we distinguish three cases depending on \({t^{\prime }}\) . If \({t^{\prime }}\) is \({?_{T^{\prime }}}\) (the precision rule between \({t}\) and \({t^{\prime }}\) was Unk) or \({\langle {T^{\prime }} {\ \Leftarrow \ } {S^{\prime }} \rangle \,{t^{\prime }}}\) , then \({\mathbb {\Gamma }} \vdash {P[{\rm \mathtt {err}}_{I(\mathbf {a})} / z] \sqsubseteq _{\leadsto }T^{\prime }}\) , and thus \({\mathbb {\Gamma }} \vdash {{\rm \mathtt {err}}_{P[{\rm \mathtt {err}}{_{I(\mathbf {a})}} / z]}} \sqsubseteq _{\alpha }{t^{\prime }}\) by using Err. Otherwise, the last rule was Diag-Fix, and again we can conclude using Err and the substitution property of \(\sqsubseteq _{\alpha }\) .
Conversely, let us consider the reduction rules for \({?}\) . If \({t}\) is \({?_{{\rm \Pi }x : A.B}}\) and reduces to \({{\rm \lambda }x : A. ?_{B}}\) , then \({t^{\prime }}\) must be \({?_{T}}\) , possibly surrounded by casts. If there are casts, they can all be reduced away until we are left with \({?_{T^{\prime }}}\) for some \({T^{\prime }}\) such that \({\mathbb {\Gamma }} \vdash {{\rm \Pi }x : A. B} \sqsubseteq _{\leadsto }{T}\) . By Lemma 16, \({T} {\rm {\leadsto }^\ast }{?_{?_{[]}}}\) or \({T} {\rm {\leadsto }^\ast }{T_{{\rm \Pi }x : A^{\prime }. B^{\prime }}}\) . In the first case, \({?_{?_{[]}}}\) is still less precise than \({{\rm \lambda }x : A. B}\) , and in the second case, \({?_{{\rm \Pi }x : A^{\prime }. B^{\prime }}}\) can reduce to \({{\rm \lambda }x : A^{\prime } . ?_{B^{\prime }}}\) , which is less precise than \({s^{\prime }}\) . If \({t}\) is \({{\rm \mathtt {ind}}_{I}(?_{I(\mathbf {a})},P,\mathbf {b})}\) , reducing to \({?_{P[?_{I(\mathbf {(}a))} / z]}}\) , we use the second part of Lemma 18 to conclude that also \({t^{\prime }}\) reduces to some \({{\rm \mathtt {ind}}_{I}(?_{I(\mathbf {a^{\prime }})},P^{\prime },\mathbf {b^{\prime }})}\) that is less precise than \({t}\) . From this, \({t^{\prime }} \leadsto {?_{P^{\prime }[?_{I(\mathbf {(}a^{\prime }))} / z]}}\) , which is less precise than \({s}\) .
Syntactic precision—diagonal cast reduction. This only leaves us with the reduction of a cast when the precision rule is Diag-Cast: We have some \({\langle {T} {\ \Leftarrow \ } {S} \rangle \,{u}}\) and \({\langle {T^{\prime }} {\ \Leftarrow \ } {S^{\prime }} \rangle \,{u^{\prime }}}\) that are pointwise related by precision, such that \({\langle {T} {\ \Leftarrow \ } {S} \rangle \,{t}} {\rm {\leadsto }^\ast }{s}\) by a head reduction, and we must show that \({\langle {T} {\ \Leftarrow \ } {S} \rangle \,{u}}\) simulates that reduction.
First, if the reduction for \({\langle {T} {\ \Leftarrow \ } {S} \rangle \,{t}}\) is any reduction to an error, then the reduct is \({{\rm \mathtt {err}}_{T}}\) , and since \({\mathbb {\Gamma }_{2}} \vdash {\langle {T^{\prime }} {\ \Leftarrow \ } {S^{\prime }} \rangle \,{u^{\prime }}} {\rm \triangleright }{T^{\prime }}\) and \({\mathbb {\Gamma }} \vdash {T} \sqsubseteq _{\leadsto }{T^{\prime }}\) we can use rule Err to conclude.
Next, consider Prod-Prod. We are in the situation where \({t}\) is \({\langle {{\rm \Pi }x : A_2.B_2} {\ \Leftarrow \ } {{\rm \Pi }x : A_1 . B_1} \rangle \,{{\rm \lambda }x : A. v}}\) . If \({v}\) is \({{\rm \mathtt {err}}_{B_1}}\) then the reduct is more precise than any term. Otherwise, by Lemma 16, \({S^{\prime }}\) reduces either to \({?_{[]}}\) or to a product type. In the first case, \({u^{\prime }}\) must reduce to \({?_{?_{[]}}}\) by Lemma 17, since it is less precise than \({{\rm \lambda }x : A.v}\) and by typing it cannot start with a \({\lambda }\) . In that case, \({\langle {T^{\prime }} {\ \Leftarrow \ } {S^{\prime }} \rangle \,{u^{\prime }}} \leadsto {?_{T^{\prime }}}\) , and since \({\mathbb {\Gamma }} \vdash {{\rm \Pi }x : A_2. B_2} \sqsubseteq _{\leadsto }{T^{\prime }}\) , we have that \({\mathbb {\Gamma }} \vdash {s} \sqsubseteq _{\alpha }{?_{T^{\prime }}}\) . Otherwise \({S^{\prime }}\) reduces to some \({{\rm \Pi }x : A_1^{\prime }. B_1^{\prime }}\) . By Lemma 17, \({t^{\prime }}\) reduces either to some \({?}\) or to an abstraction. In the first case, the previous reasoning still applies. Otherwise, \({t^{\prime }}\) reduces to some \({{\rm \lambda }x : A^{\prime } . v^{\prime }}\) . Again, by Lemma 16, \({T^{\prime }}\) reduces either to a product type or to \({?}\) . In the first case \({t^{\prime }}\) can simply do the same cast reduction as \({t}\) , and the substitution property of precision enables us to conclude. Thus, the only case left is that where \({t^{\prime }}\) is \({\langle {?_{[]_i}} {\ \Leftarrow \ } {{\rm \Pi }x : A_1^{\prime }. B_1^{\prime }} \rangle \,{{\rm \lambda }x : A^{\prime } . v^{\prime }}}\) . If \({{\rm \Pi }x : A_1^{\prime } . B_1^{\prime }}\) is \({{\rm germ}_{i}\,{\rm \Pi }}\) , then all of \({A}\) , \({A_1}\) , \({A_2}\) , \({B_1}\) and \({B_2}\) are more precise than \({?_{[]_{c_\Pi (i)}}}\) , and this is enough to conclude that \({s}\) is less precise than \({\langle {{\rm germ}_{i}\,{\rm \Pi }} {\ \Leftarrow \ } {?_{[]_i}} \rangle \,{{\rm \lambda }x : ?_{[]_{c_\Pi (i)}}.u^{\prime }}}\) , using the substitution property of precision to relate \({u^{\prime }}\) with the substituted \({u}\) , and the Diag-Abs, Case-L and Case-R rules. The last case is when \({{\rm \Pi }x : A_1^{\prime } . B_1^{\prime }}\) is not a germ. Then the reduction of \({t^{\prime }}\) first does a cast expansion through \({{\rm germ}_{i}\,\Pi }\) , followed by a reduction of the cast between \({{\rm \Pi }x : A_1^{\prime } . B_1^{\prime }}\) and \({{\rm germ}_{i}\,\Pi }\) . The reasoning of the two previous cases can be used again to conclude. The proof is similar for rule Ind-Ind.
Next, let us consider Prod-Germ, that is, when \({t}\) is \({\langle {?_{[]_i}} {\ \Leftarrow \ } {{\rm \Pi }x : A_1 . B_1} \rangle \,{f}}\) . We have that \({T^{\prime } \leadsto ?_{[]_j}}\) by Lemma 16 with \(i \le j\) , and thus \({\mathbb {\Gamma }} \vdash {{\rm germ}_{i}\,\Pi } \sqsubseteq _{\leadsto }{T^{\prime }}\) . Thus, using Diag-Cast for the innermost cast in \({s}\) , and Case-L for the outermost one, we conclude \({\mathbb {\Gamma }} \vdash {s} \sqsubseteq _{\alpha }{\langle {T^{\prime }} {\ \Leftarrow \ } {S^{\prime }} \rangle \,{u^{\prime }}}\) . Again, the reasoning is similar for Ind-Germ.
As for Univ-Univ, \({t}\) is \({\langle {[]_i} {\ \Leftarrow \ } {[]_i} \rangle \,{A}}\) , and we can replace rule Diag-Cast by rule Case-R. Indeed \({\mathbb {\Gamma }_{1}} \vdash {A} {\rm \triangleleft }{[]_i}\) by typing, thus \({\mathbb {\Gamma }_{1}} \vdash {A} {\rm \triangleright }{T}\) for some \({T}\) such that \({T} \leadsto {[]_i}\) . Therefore, since \({\mathbb {\Gamma }} \vdash {[]_i} \sqsubseteq _{\leadsto }{T^{\prime }}\) , we have \({\mathbb {\Gamma }} \vdash {T} \sqsubseteq _{\leadsto }{T^{\prime }}\) and similarly \({\mathbb {\Gamma }} \vdash {T} \sqsubseteq _{\leadsto }{S^{\prime }}\) . Thus, rule Case-R gives \({\mathbb {\Gamma }} \vdash {A} \sqsubseteq _{\alpha }{t^{\prime }}\) .
The last case left is the one of Up-Down, where \({t}\) is \({\langle {X} {\ \Leftarrow \ } {?_{[]_i}} \rangle \,{\langle {?_{[]_i}} {\ \Leftarrow \ } {{\rm germ}_{i}\,h} \rangle \,{v}}}\) . We distinguish on the rule used to prove \({\mathbb {\Gamma }} \vdash {\langle {?_{[]_i}} {\ \Leftarrow \ } {{\rm germ}_{i}\,h} \rangle \,{v}} \sqsubseteq _{\alpha }{u^{\prime }}\) . If it is Case-L, then we simply have \({\mathbb {\Gamma }} \vdash {\langle {X} {\ \Leftarrow \ } {{\rm germ}_{i}\,h} \rangle \,{t}} \sqsubseteq _{\alpha }{\langle {T^{\prime }} {\ \Leftarrow \ } {S^{\prime }} \rangle \,{u^{\prime }}}\) using rule Diag-Cast, as \({\mathbb {\Gamma }} \vdash {{\rm germ}_{i}\,h} \sqsubseteq _{\leadsto }{S^{\prime }}\) since \({\mathbb {\Gamma }} \vdash {?_{[]_i}} \sqsubseteq _{\leadsto }{S^{\prime }}\) . Otherwise the rule is Diag-Cast, \({t^{\prime }}\) reduces to \({\langle {T^{\prime }} {\ \Leftarrow \ } {?_{[]_j}} \rangle \,{\langle {?_{[]_j}} {\ \Leftarrow \ } {U^{\prime }} \rangle \,{u^{\prime }}}}\) , using Lemma 16 to reduce types less precise than \({?_{[]_i}}\) to some \({?_{[]_j}}\) with \(i \le j\) . We can use Diag-Cast on the outermost cast, and Case-R on the innermost to prove that this term is less precise than \({s}\) , as \({\mathbb {\Gamma }} \vdash {{\rm germ}_{i}\,h} \sqsubseteq _{\leadsto }{?_{[]_j}}\) since \(i \le j\) .□

B.3 Properties of \(\mathsf {GCIC}\)

Conservativity is an equivalence, so to prove it we break it down into two implications. We now state and prove those in an open context and for the three different judgments.
Theorem 37 ( \(\mathsf {GCIC}\) is Weaker than \(\mathsf {CIC}\) —Open Context)
Let \({\tilde{t}}\) be a static term and \({\Gamma }\) an erasable context. Then
if \(\varepsilon ({\Gamma }) \vdash _{\mathsf {CIC}}{t} {\rm \triangleright }T\) then \({\Gamma } \vdash {\tilde{t}} {\rm \rightsquigarrow }{t} {\rm \triangleright }{T^{\prime }}\) for some erasable \({t}\) and \({T^{\prime }}\) such that \(\varepsilon ({t}) = {\tilde{t}}\) and \(\varepsilon ({T^{\prime }}) = T\) ;
if \({T^{\prime }}\) is an erasable term of \(\mathsf {CastCIC}\) , and \(\varepsilon ({\Gamma }) \vdash _{\mathsf {CIC}}{\tilde{t}} {\rm \triangleleft }\varepsilon ({T^{\prime }})\) then \({\Gamma } \vdash {\tilde{t}} {\rm \triangleleft }{T^{\prime }} {\rm \rightsquigarrow }{t}\) for some erasable \({t}\) such that \(\varepsilon ({t}) = {\tilde{t}}\) ;
if \(\varepsilon ({\Gamma }) \vdash _{\mathsf {CIC}}{\tilde{t}} \blacktriangleright {h} T\) then \({\Gamma } \vdash {\tilde{t}} {\rm \rightsquigarrow }{t} \blacktriangleright {h} {T^{\prime }}\) for some erasable \({t}\) and \({T^{\prime }}\) such that \(\varepsilon ({t}) = {\tilde{t}}\) and \(\varepsilon ({T^{\prime }}) = T\) .
Proof.
Once again, the proof is by mutual induction, on the typing derivation of \({\tilde{t}}\) in \(\mathsf {CIC}\) .
All inference rules are direct: one needs to combine the induction hypothesis together, using the substitution property of precision and the fact that erasure commutes with substitution to handle the cases of substitution in the inferred types.
Let us consider the case of Prod-Inf next. We are given \({\Gamma }\) erasable, and suppose \(\varepsilon ({\Gamma }) \vdash _{\mathsf {CIC}}{\tilde{t}} {\rm \triangleright }T\) and \(T {\rm {\leadsto }^\ast }{\rm \Pi }x : A .B\) . By induction hypothesis there exists \({t}\) and \({T^{\prime }}\) erasable such that \({\Gamma } \vdash {{t}} {\rm \rightsquigarrow }{{\tilde{t}}} {\rm \triangleright }{T^{\prime }}\) and \(\varepsilon ({t}) = {\tilde{t}}\) , \(\varepsilon ({T^{\prime }}) = T\) . Because \({T^{\prime }}\) is erasable, it is less precise than \(T\) . By Corollary 21, it must reduce to either \({?_{[]}}\) or a product type. The first case is impossible because \({T^{\prime }}\) does not contain any \({?}\) as it is erasable. Thus, there are some \({A^{\prime }}\) and \({B^{\prime }}\) such that \({T^{\prime }} {\rm {\leadsto }^\ast }{{\rm \Pi }x : A^{\prime } . B^{\prime }}\) and \({\Gamma } \vdash {\rm \Pi }x : A.B \sqsubseteq _{\alpha }{{\rm \Pi }x : A^{\prime }. B^{\prime }}\) . Since also \({\Gamma } \vdash {T^{\prime }} \sqsubseteq _{\alpha }T\) , by the same reasoning there are also some \(A^{\prime \prime }\) and \(B^{\prime \prime }\) such that \(T {\rm {\leadsto }^\ast }{\rm \Pi }x : A^{\prime \prime }. B^{\prime \prime }\) and \({\Gamma } \vdash {{\rm \Pi }x : A^{\prime } . B^{\prime }} \sqsubseteq _{\alpha }{\rm \Pi }x : A^{\prime \prime } . B^{\prime \prime }\) . Now because \(T\) is static, so are \({\rm \Pi }x : A . B\) and \({\rm \Pi }x : A^{\prime \prime }. B^{\prime \prime }\) , and because of the comparisons with \({\rm \Pi }x : A^{\prime } . B^{\prime }\) we must have \(\varepsilon (\Gamma) \vdash {\rm \Pi }x : A . B \sqsubseteq _{\alpha }{\rm \Pi }x : A^{\prime \prime } . B^{\prime \prime }\) . Since both are static, this means they must be \(\alpha\) -equal, since no non-diagonal rule can be used on static terms. Hence, \({\rm \Pi }x : A . B = {\rm \Pi }x : A^{\prime \prime } . B^{\prime \prime } = \varepsilon ({{\rm \Pi }x : A^{\prime }. B ^{\prime }})\) , implying that \({{\rm \Pi }x : A^{\prime } . B^{\prime }}\) is erasable. Thus, \({\Gamma } \vdash {\tilde{t}} {\rm \rightsquigarrow }{t} \blacktriangleright {\Pi } {{\rm \Pi }x : A^{\prime }.B^{\prime }}\) , both \({t}\) and \({{\rm \Pi }x : A^{\prime } . B^{\prime }}\) are erasable, and moreover \(\varepsilon ({t}) = {\tilde{t}}\) and \(\varepsilon ({{\rm \Pi }x : A^{\prime } . B^{\prime }}) = {\rm \Pi }x : A.B\) , which is what had to be proven.
The other constrained inference rules being very similar, let us turn to Check. We are given \({\Gamma }\) and \({T^{\prime }}\) erasable, and suppose that \(\varepsilon ({\Gamma }) \vdash _{\mathsf {CIC}}{\tilde{t}} {\rm \triangleright }S\) such that \(S \equiv \varepsilon ({T^{\prime }})\) . By induction hypothesis, \({\Gamma ^{\prime }} \vdash {\tilde{t}} {\rm \rightsquigarrow }{t} {\rm \triangleright }{S^{\prime }}\) with \({t}\) and \({S^{\prime }}\) erasable, \(\varepsilon ({t}) = {\tilde{t}}\) and \(\varepsilon ({S^{\prime }}) = S\) . But convertibility implies consistency, so \(S \sim \varepsilon ({T^{\prime }})\) . By monotonicity of consistency, this implies \({S^{\prime }} \sim {T^{\prime }}\) . Thus \({\Gamma } \vdash {\tilde{t}} {\rm \triangleleft }{T^{\prime }} {\rm \rightsquigarrow }{\langle {T^{\prime }} {\ \Leftarrow \ } {S^{\prime }} \rangle \,{t}}\) . We have \(\varepsilon ({\langle {T^{\prime }} {\ \Leftarrow \ } {S^{\prime }} \rangle \,{t}}) = \varepsilon ({t}) = {\tilde{t}}\) , so we are left with showing that \({\Gamma } \vdash {\langle {T^{\prime }} {\ \Leftarrow \ } {S^{\prime }} \rangle \,{t}} \sqsupseteq \sqsubseteq _{\alpha }{\tilde{t}}\) . Using rules Case-L and Case-R, and knowing already that \({\Gamma } \vdash {S^{\prime }} \sqsupseteq \sqsubseteq _{\alpha }S\) , it remains to show that \({\Gamma } \vdash {T^{\prime }} \sqsubseteq _{\leadsto }S\) and \(\Gamma \vdash S \sqsubseteq _{\leadsto }{T^{\prime }}\) . As \(S\) and \(\varepsilon ({T^{\prime }})\) are convertible, let \(U\) be a common reduct. Using Theorem 20, \({T^{\prime }} {\rm {\leadsto }^\ast }{U^{\prime }}\) with \({\Gamma } \vdash U \sqsubseteq _{\alpha }{U^{\prime }}\) . Simulating that reduction again, we get \(\varepsilon ({T^{\prime }}) {\rm {\leadsto }^\ast }U^{\prime \prime }\) with \({\Gamma } \vdash U^{\prime \prime } \sqsubseteq _{\alpha }{U^{\prime }}\) . As before, this implies \(U = U^{\prime \prime } = \varepsilon ({U^{\prime }})\) . Thus, using the reduct \({U^{\prime }}\) of \({T^{\prime }}\) that is equiprecise with \({U}\) , we can conclude \({\Gamma } \vdash S \sqsubseteq _{\leadsto }{T^{\prime }}\) and \({\Gamma } \vdash {T^{\prime }} \sqsubseteq _{\leadsto }S\) .□
Theorem 38 ( \(\mathsf {CIC}\) is Weaker than \(\mathsf {GCIC}\) —Open Context)
Let \({\tilde{t}}\) be a static term and \({\Gamma }\) an erasable context of \(\mathsf {CastCIC}\) . Then,
if \({\Gamma } \vdash {\tilde{t}} {\rm \rightsquigarrow }{t} {\rm \triangleright }{T}\) , then \({t}\) and \({T}\) are erasable, \(\varepsilon ({t^{\prime }}) = {\tilde{t}}\) and \(\varepsilon ({\Gamma }) \vdash {\tilde{t}} {\rm \triangleright }\varepsilon ({T^{\prime }})\) ;
if \({T^{\prime }}\) is an erasable term of \(\mathsf {CastCIC}\) such that \({\Gamma ^{\prime }} \vdash {\tilde{t}} {\rm \triangleleft }{T^{\prime }} {\rm \rightsquigarrow }{t^{\prime }}\) , then \({t^{\prime }}\) is erasable, \(\varepsilon (t^{\prime }) = {\tilde{t}}\) and \(\varepsilon ({\Gamma }) \vdash {\tilde{t}} {\rm \triangleleft }\varepsilon ({T^{\prime }})\) ;
if \({\Gamma ^{\prime }} \vdash {\tilde{t}} {\rm \rightsquigarrow }{t^{\prime }} \blacktriangleright {h} {T^{\prime }}\) , then \({t^{\prime }}\) and \({T^{\prime }}\) are erasable, \(\varepsilon ({t^{\prime }}) = {\tilde{t}}\) and \(\varepsilon ({\Gamma }) \vdash {\tilde{t}} \blacktriangleright {h} \varepsilon ({T^{\prime }})\) .
Proof.
The proof is similar to the previous one. Again, the tricky part is to handle reduction steps, and we use equiprecision in the same way to conclude in those.□
As a direct corollary of those propositions in an empty context, we get conservativity Theorem 23.
Elaboration graduality. Now for the elaboration graduality: again, we state it in an open context for all three typing judgments.
Theorem 39 (Elaboration Graduality—Open Context).
Let \({\mathbb {\Gamma }}\) be a context such that \({\mathbb {\Gamma }_{1}} \sqsubseteq _{\alpha }{\mathbb {\Gamma }_{2}}\) , and \({\tilde{t}}\) and \({\tilde{t}^{\prime }}\) be two \(\mathsf {GCIC}\) terms such that \({\tilde{t}} \sqsubseteq ^{\mathrm{G}}_{\alpha }{\tilde{t}^{\prime }}\) . Then,
If \({\mathbb {\Gamma }_{1}} \vdash {\tilde{t}} {\rm \rightsquigarrow }{t} {\rm \triangleright }{T}\) is universe adequate, then there exists \({t^{\prime }}\) and \({T^{\prime }}\) such that \({\mathbb {\Gamma }_{2}} \vdash {\tilde{t}^{\prime }} {\rm \rightsquigarrow }{t^{\prime }} {\rm \triangleright }{T^{\prime }}\) , \({\mathbb {\Gamma }} \vdash {t} \sqsubseteq _{\alpha }{t^{\prime }}\) and \({\mathbb {\Gamma }} \vdash {T} \sqsubseteq _{\alpha }{T^{\prime }}\) ;
If \({{\mathbb {\Gamma }}_{1}} \vdash {t} {\rm \triangleleft }{T} {\rm \rightsquigarrow }{t^{\prime }}\) is universe adequate, then for all \({T^{\prime }}\) such that \({\mathbb {\Gamma }} \vdash {T} \sqsubseteq _{\alpha }{T^{\prime }}\) , there exists \({t^{\prime }}\) such that \({\mathbb {\Gamma }_{2}} \vdash {\tilde{t}^{\prime }} {\rm \triangleleft }{T^{\prime }} {\rm \rightsquigarrow }{t^{\prime }}\) and \({\mathbb {\Gamma }} \vdash {t} \sqsubseteq _{\alpha }{t^{\prime }}\) ;
If \({{\mathbb {\Gamma }}_{1}} \vdash {t} {\rm \rightsquigarrow }{t^{\prime }} \blacktriangleright {h} {T}\) is universe adequate, then there exists \({t^{\prime }}\) and \({T^{\prime }}\) such that \({\mathbb {\Gamma }_{2}} \vdash {\tilde{t}^{\prime }} {\rm \rightsquigarrow }{t^{\prime }} \blacktriangleright {h} {T^{\prime }}\) , \({\mathbb {\Gamma }} \vdash {t} \sqsubseteq _{\alpha }{t^{\prime }}\) and \({\mathbb {\Gamma }} \vdash {T} \sqsubseteq _{\alpha }{T^{\prime }}\) .
Proof.
Once again, we use our favorite tool: induction on the typing derivation of \({\tilde{t}}\) .
Inference—Non-diagonal precision. For inference, we have to make a distinction on the rule used to prove \({tilde{t}} \sqsubseteq ^{\mathrm{G}}_{\alpha }{\tilde{t}^{\prime }}\) : We have to handle specifically the non-diagonal one, where \({\tilde{t}^{\prime }}\) is some \({?}\) . We start with this, and treat the ones where the rule is diagonal (i.e., when \({\tilde{t}}\) and \({\tilde{t}^{\prime }}\) have the same head) next.
We have \({\mathbb {\Gamma }_{1}} \vdash {\tilde{t}} {\rm \rightsquigarrow }{t^{\prime }} {\rm \triangleright }{T^{\prime }}\) and \({\mathbb {\Gamma }_{2}} \vdash {?@\lbrace i\rbrace } {\rm \rightsquigarrow }{?_{?_{[]_i}}} {\rm \triangleright }{?_{[]_i}}\) . Correctness of elaboration gives \({\mathbb {\Gamma }_{1}} \vdash {t^{\prime }} {\rm \triangleright }{T^{\prime }}\) , and by validity \({\Gamma _{1}} \vdash {T^{\prime }} {\rm \triangleright }{[]_i}\) , universe adequacy ensuring us that this \(i\) is the same as the one in \({\tilde{t}^{\prime }}\) . Thus, we have \({\mathbb {\Gamma }} \vdash {T^{\prime }} \sqsubseteq _{\alpha }{?_{[]_i}}\) by rule Unk, and in turn \({\mathbb {\Gamma }} \vdash {t^{\prime }} \sqsubseteq _{\alpha }{?_{?_{[]_i}}}\) by a second use of the same rule, giving us the required conclusions.
Inference—Variable. Rule Var gives us \((x : {T}) \in {\mathbb {\Gamma }_{1}}\) . Because \(\vdash {\mathbb {\Gamma }_{1}} \sqsubseteq _{\alpha }{\mathbb {\Gamma }_{2}}\) , there exists some \({T^{\prime }}\) such that \((x : {T^{\prime }}) \in {\mathbb {\Gamma }_{2}}\) , and \({\mathbb {\Gamma }} \vdash {T} \sqsubseteq _{\alpha }{T^{\prime }}\) using weakening. Thus, \({\mathbb {\Gamma }_{2}} \vdash {x} {\rm \rightsquigarrow }{x} {\rm \triangleright }{T^{\prime }}\) , and of course \({\mathbb {\Gamma }} \vdash {x} \sqsubseteq _{\alpha }{x}\) .
Inference—Product. Premises of rule Prod give \({\mathbb {\Gamma }_{1}} \vdash {\tilde{A}} {\rm \rightsquigarrow }{A} \blacktriangleright {[]} {[]_i}\) and \({\mathbb {\Gamma }_{1}, x : A} \vdash {\tilde{B}} {\rm \rightsquigarrow }{B} \blacktriangleright {[]} {[]_j}\) , and the diagonal precision one gives \({\tilde{A}} \sqsubseteq ^{\mathrm{G}}_{\alpha }{\tilde{A}^{\prime }}\) and \({\tilde{B}} \sqsubseteq ^{\mathrm{G}}_{\alpha }{\tilde{B}^{\prime }}\) . Applying the induction hypothesis, we get some \({A^{\prime }}\) such that \({\mathbb {\Gamma }_{2}} \vdash {\tilde{A}^{\prime }} {\rm \rightsquigarrow }{A^{\prime }} \blacktriangleright {[]} {[]_i}\) and \({\mathbb {\Gamma }} \vdash {A} \sqsubseteq _{\alpha }{A^{\prime }}\) . The inferred type for \({\tilde{A}^{\prime }}\) must be \({[]_i}\) as it is some \({[]_j}\) because of the constrained elaboration, and it is less precise than \({[]_i}\) by the induction hypothesis. From this, we also deduce that \({\mathbb {\Gamma }_{1}, x : A} \sqsubseteq _{\alpha }{\mathbb {\Gamma }_{2}, x : A^{\prime }}\) . Hence, the induction hypothesis can be applied to \({\tilde{B}}\) , giving \({\mathbb {\Gamma }_{2}} \vdash {\tilde{B}^{\prime }} {\rm \rightsquigarrow }{B^{\prime }} \blacktriangleright {[]} {[]_j}\) . Combining this with the elaboration for \({\tilde{A}^{\prime }}\) , we obtain \({\mathbb {\Gamma }_{2}} \vdash {{\rm \Pi }x : \tilde{A}^{\prime }. \tilde{B}^{\prime }} {\rm \rightsquigarrow }{{\rm \Pi }x : A^{\prime } . B^{\prime }} {\rm \triangleright }{[]_{s_\Pi (i,j)}}\) . Moreover, \({\mathbb {\Gamma }} \vdash {{\rm \Pi }x : A. B} \sqsubseteq _{\alpha }{{\rm \Pi }x : A^{\prime } . B^{\prime }}\) by combining the precision hypothesis on \(A\) and \(B\) , and also \({\mathbb {\Gamma }} \vdash {[]_{s_\Pi (i,j)}} \sqsubseteq _{\alpha }{[]_{s_\Pi (i,j)}}\) .
Inference—Application. From rule App, we have \({\mathbb {\Gamma }_{1}} \vdash {\tilde{t}} {\rm \rightsquigarrow }{t} \blacktriangleright {\Pi } {{\rm \Pi }x : A . B}\) and \({\mathbb {\Gamma }_{1}} \vdash {\tilde{u}} {\rm \triangleleft }{A} {\rm \rightsquigarrow }{u}\) , and the diagonal precision gives \({\tilde{t}} \sqsubseteq ^{\mathrm{G}}_{\alpha }{\tilde{t}^{\prime }}\) and \({\tilde{u}} \sqsubseteq ^{\mathrm{G}}_{\alpha }{\tilde{u}^{\prime }}\) . By induction, we have \({\mathbb {\Gamma }_{1}} \vdash {\tilde{t}^{\prime }} {\rm \rightsquigarrow }{t^{\prime }} \blacktriangleright {\Pi } {{\rm \Pi }x : A^{\prime } . B^{\prime }}\) for some \({t^{\prime }}\) , \({A^{\prime }}\) , and \({B^{\prime }}\) such that \({\mathbb {\Gamma }} \vdash {t} \sqsubseteq _{\alpha }{t^{\prime }}\) , \({\mathbb {\Gamma }} \vdash {A} \sqsubseteq _{\alpha }{A^{\prime }}\) and \({\mathbb {\Gamma }, x : A \mid A^{\prime }} \vdash {B} \sqsubseteq _{\alpha }{B^{\prime }}\) . Using the induction hypothesis again with that precision property on \({A}\) and \({A^{\prime }}\) gives \({\mathbb {\Gamma }_{2}} \vdash {\tilde{u}^{\prime }} {\rm \triangleleft }{A^{\prime }} {\rm \rightsquigarrow }{u^{\prime }}\) with \({\mathbb {\Gamma }} \vdash {u} \sqsubseteq _{\alpha }{u^{\prime }}\) . Therefore, combining those we get \({\mathbb {\Gamma }_{2}} \vdash {\tilde{t}^{\prime }~\tilde{u}^{\prime }} {\rm \rightsquigarrow }{t^{\prime }~u^{\prime }} {\rm \triangleright }{B^{\prime }[u^{\prime } / x]}\) , \({\mathbb {\Gamma }} \vdash {t~u} \sqsubseteq _{\alpha }{t^{\prime }~u^{\prime }}\) and, by substitution property of precision, \({\mathbb {\Gamma }} \vdash {B[u / x]} \sqsubseteq _{\alpha }{B^{\prime }[u^{\prime } / x]}\) .
Inference—Other diagonal cases. All other cases are similar to those: combining the induction hypothesis directly leads to the desired result, handling the binders in a similar way to that of products when needed.
Checking. For Check, we have that \({\mathbb {\Gamma }_{1}} \vdash {\tilde{t}} {\rm \rightsquigarrow }{t} {\rm \triangleright }{S}\) , with \({S} \sim {T}\) . By induction hypothesis, \({\mathbb {\Gamma }_{2}} \vdash {\tilde{t}^{\prime }} {\rm \rightsquigarrow }{\tilde{t}^{\prime }} {\rm \triangleright }{S^{\prime }}\) with \({\mathbb {\Gamma }} \vdash {t} \sqsubseteq _{\alpha }{t^{\prime }}\) and \({\mathbb {\Gamma }} \vdash {S} \sqsubseteq _{\alpha }{S^{\prime }}\) . But we also have as an hypothesis that \({\mathbb {\Gamma }} \vdash {T} \sqsubseteq _{\alpha }{T^{\prime }}\) . By monotonicity of consistency, we conclude that \({S^{\prime }} \sim {T^{\prime }}\) , and thus \({\mathbb {\Gamma }_{2}} \vdash {\tilde{t}^{\prime }} {\rm \triangleleft }{T^{\prime }} {\rm \rightsquigarrow }{\langle {T^{\prime }} {\ \Leftarrow \ } {S^{\prime }} \rangle \,{t^{\prime }}}\) . A use of Diag-Cast then ensures that \({\mathbb {\Gamma }} \vdash {\langle {T} {\ \Leftarrow \ } {S} \rangle \,{t}} \sqsubseteq _{\alpha }{\langle {T^{\prime }} {\ \Leftarrow \ } {S^{\prime }} \rangle \,{t^{\prime }}}\) , as desired.
Constrained inference— Inf-Prod rule. We are in the situation where \({\mathbb {\Gamma }_{1}} \vdash {\tilde{t}} {\rm \rightsquigarrow }{t} {\rm \triangleright }{S}\) and \({S} {\rm {\leadsto }^\ast }{{\rm \Pi }x : A. B}\) . By induction hypothesis, \({\mathbb {\Gamma }_{2}} \vdash {\tilde{t}^{\prime }} {\rm \rightsquigarrow }{t^{\prime }} {\rm \triangleright }{S^{\prime }}\) with \({\mathbb {\Gamma }} \vdash {S} \sqsubseteq _{\alpha }{S^{\prime }}\) . Using Corollary 21, we get that \({S^{\prime }} {\rm {\leadsto }^\ast }{{\rm \Pi }x : A^{\prime } . B^{\prime }}\) such that \({\mathbb {\Gamma }} \vdash {{\rm \Pi }x : A . B} \sqsubseteq _{\alpha }{{\rm \Pi }x : A^{\prime } . B^{\prime }}\) , or \({S^{\prime }} {\rm {\leadsto }^\ast }{?_{[]_i}}\) . In the first case, by rule Inf-Prod we get \({\mathbb {\Gamma }_{2}} \vdash {\tilde{t}^{\prime }} {\rm \rightsquigarrow }{t^{\prime }} \blacktriangleright {\Pi } {{\rm \Pi }x : A^{\prime } . B^{\prime }}\) together with the precision inequalities for \({t^{\prime }}\) and \({{\rm \Pi }x : A^{\prime }. B^{\prime }}\) . In the second case, we can use rule Inf-Prod? instead, and get \({\mathbb {\Gamma }_{2}} \vdash {\tilde{t}^{\prime }} {\rm \rightsquigarrow }{\langle {{\rm germ}_{i}\,\Pi } {\ \Leftarrow \ } {S^{\prime }} \rangle \,{t^{\prime }}} \blacktriangleright {\Pi } {{\rm germ}_{i}\,\Pi }\) , and \(c_\Pi (i)\) is larger than the universe levels of both \({A^{\prime }}\) and \({B^{\prime }}\) . A use of Case-R, together with the fact that \({\mathbb {\Gamma }} \vdash {A} \sqsubseteq _{\alpha }{?_{[]_{c_\Pi (i)}}}\) by Unk-Univ and similarly for \({B}\) , gives that \({\mathbb {\Gamma }} \vdash {t^{\prime }} \sqsubseteq _{\alpha }{\langle {{\rm germ}_{i}\,\Pi } {\ \Leftarrow \ } {S^{\prime }} \rangle \,{t^{\prime }}}\) , and the precision between types has been established already.
Constrained inference— Inf-Prod ?. This time, \({\mathbb {\Gamma }_{1}} \vdash {\tilde{t}} {\rm \rightsquigarrow }{t} {\rm \triangleright }{S}\) , but \({S} {\rm {\leadsto }^\ast }{?_{[]_i}}\) . By induction hypothesis, \({\mathbb {\Gamma }_{2}} \vdash {\tilde{t}^{\prime }} {\rm \rightsquigarrow }{t^{\prime }} {\rm \triangleright }{S^{\prime }}\) with \({\mathbb {\Gamma }} \vdash {S} \sqsubseteq _{\alpha }{S^{\prime }}\) . By Corollary 21, we get that \({S^{\prime }} {\rm {\leadsto }^\ast }{?_{[]_i}}\) . Thus, \({\mathbb {\Gamma }_{2}} \vdash {\tilde{t}^{\prime }} {\rm \rightsquigarrow }{\langle {{\rm germ}_{i}\,\Pi } {\ \Leftarrow \ } {S^{\prime }} \rangle \,{t^{\prime }}} \blacktriangleright {\Pi } {{\rm germ}_{i}\,\Pi }\) . A use of Diag-Cast is enough to conclude.
Constrained inference—Other rules. All other cases are similar to the previous ones, albeit with a simpler handling of universe levels (since \(c_\Pi\) does not appear).□

C Connecting the Discrete and Monotone Models

Comparing the discrete and the monotone translations, we can see that they coincide on ground types such as \(\mathbb {N}\) . On functions over ground types, for instance \(\mathbb {N}{\rightarrow } \mathbb {N}\) , the monotone interpretation is more conservative: any monotone function \(f : \lbrace \!\mid \!{{\mathbb {N}{\rightarrow }\mathbb {N}}}\!\mid \!\rbrace _{}\) induces a function \(\tilde{f} : [\![ {}{{\mathbb {N}{\rightarrow }\mathbb {N}}}]\!] {}\) by forgetting the monotonicity, but not all functions from \([\![ {}{{\mathbb {N}{\rightarrow }\mathbb {N}}}]\!] {}\) are monotone.25
Extending the sketched correspondence at higher types, we obtain a (binary) logical relation \(\lbag{-}\rbag\) between terms of the discrete and monotone translations described in Figure 20, that forgets the monotonicity information on ground types. More precisely we define for each types \(A\) in the source a relation \(\binlogrelTy {A} : [\![ {}{{A}}]\!] {} \rightarrow \lbrace \!\mid \!{{A}}\!\mid \!\rbrace _{} \rightarrow \square {}\) and for each term \(t : A\) a witness \(\lbag {t}\rbag : \binlogrelTy {A}~[{{t}}]~\lbrace {{t}}\rbrace _{}\) .
Fig. 20.
Fig. 20. Logical relation between the discrete and monotone models.
The logical relation employs an inductively defined relation \(\square \!\!\!\! \square _{\text{rel},i}\) between \(\square \!\!\!\! \square _i^\text{dis}:= [\![ {}{{\square _i}}]\!] {}\) and \(\square \!\!\!\! \square _i^\text{mon}:= \lbrace \!\mid \!{{\square _i}}\!\mid \!\rbrace _{}\) whose constructors are relational codes relating codes of discrete and monotone types. These relational codes are then decoded to relations between the corresponding decoded types thanks to \({ \mathrm{El}{} }_{\text{rel}}\) . The main difficult case in establishing the logical relation lie in relating the \({\rm \mathtt {cast}}\) s, since that’s the main point of divergence of the two models.
Lemma 40 (Basis Lemma).
(1)
There exists a term \({\rm \mathtt {cast}}_\text{rel}: \binlogrelTy {{\rm \Pi }(A\, B : \square \!\!\!\! \square).A \rightarrow B}~[{{{\rm \mathtt {cast}}}}]~\lbrace {{{\rm \mathtt {cast}}}}\rbrace _{}\) .
(2)
More generally, if \(\Gamma \vdash _{{\rm \mathtt {cast}}}t : A\) then \(\binlogrelTy {\Gamma } {\vdash _{\mathrm{IR}}}\lbag {t}\rbag : \lbag {A}\rbag~[{{t}}]~\lbrace {{t}}\rbrace _{}\) .
In particular \(\mathsf {CastCIC}\) terms of ground types behave similarly in both models.
Proof.
Expanding the type of \({\rm \mathtt {cast}}_\text{rel}\) , we need to provide a term
\begin{equation*} c_\text{rel}= {\rm \mathtt {cast}}_\text{rel}\,A\,A^{\prime }\,A_\text{rel}\,B\,B^{\prime }\,B_\text{rel}\,a\,a^{\prime }\,a_\text{rel}: \mathrm{El}_\text{rel}\,B_\text{rel}~([{{{\rm \mathtt {cast}}}}]\,A\,B\,a)~(\lbrace {{{\rm \mathtt {cast}}}}\rbrace _{}\,A^{\prime }\,B^{\prime }\,a^{\prime }), \end{equation*}
where
\begin{align*} A &: [\![ {}{{\square {}_i}}]\!] {},& A^{\prime } &: \lbrace \!\mid \!{{\square {}_i}}\!\mid \!\rbrace _{},& A_\text{rel}&: \square \!\!\!\! \square _\text{rel}\,A\,A^{\prime },\\ B &: [\![ {}{{\square {}_i}}]\!] {},& B^{\prime } &: \lbrace \!\mid \!{{\square {}_i}}\!\mid \!\rbrace _{},& B_\text{rel}&: \square \!\!\!\! \square _\text{rel}\,B\,B^{\prime },\\ a &: \mathrm{El}\,A,& a^{\prime } &: \mathrm{El}\,A^{\prime },& a_\text{rel}&: \mathrm{El}_\text{rel}\,A_\text{rel}~a~a^{\prime }. \end{align*}
We proceed by induction on \(A_\text{rel}, B_\text{rel}\) , following the defining cases for \([{{{\rm \mathtt {cast}}}}]\) (see Figure 14).
Case \(A_\text{rel}= \widehat{\Pi }_\text{rel}\,A^\text{d}_\text{rel}\,A^\text{c}_\text{rel}\) and \(B_\text{rel}= \widehat{\Pi }_\text{rel}\,B^\text{d}_\text{rel}\,B^\text{c}_\text{rel}\) : we pose \({A^{\prime } = \widehat{\Pi }\,A^{\prime \text{d}}\,A^{\prime \text{c}}}\) and \({B^{\prime } = \widehat{\Pi }\,B^{\prime \text{d}}\,B^{\prime \text{c}}}\)
\begin{align*} \lbrace {{{\rm \mathtt {cast}}}}\rbrace _{}~A^{\prime }~B^{\prime }~f^{\prime } &= ~\downarrow ^{\widehat{?}_{}}_{B^{\prime }}(\uparrow ^{\widehat{?}_{}}_{A^{\prime }} f^{\prime }) \qquad {by definition of \lbrace {{{\rm \mathtt {cast}}}}\rbrace _{}}\\ &= ~\downarrow ^{\widehat{?}_{}\rightarrow \widehat{?}_{}}_{B^{\prime }}\circ \downarrow ^{\widehat{?}_{}}_{\widehat{?}_{}\rightarrow \widehat{?}_{}} \circ \uparrow ^{\widehat{?}_{}}_{\widehat{?}_{}\rightarrow \widehat{?}_{}} \circ \uparrow ^{\widehat{?}_{}\rightarrow \widehat{?}_{}}_{A^{\prime }} (f)\qquad {by decomposition of \widehat{\Pi }\sqsubseteq \widehat{?}_{}}\\ &= ~\downarrow ^{\widehat{?}_{}\rightarrow \widehat{?}_{}}_{B^{\prime }}\circ \uparrow ^{\widehat{?}_{}\rightarrow \widehat{?}_{}}_{A^{\prime }} (f) \qquad {by section-retraction identity}\\ &= {\rm \lambda }(b^{\prime } : \mathrm{El}\,A^{\prime \text{d}}). ~\text{let}\,a^{\prime }=~\downarrow ^{\widehat{?}_{}}_{B^{\prime \text{d}}}\circ \uparrow ^{\widehat{?}_{}}_{A^{\prime \text{d}}} (b)\,\text{in}\,\qquad {by definition of} ep-pair {} on {\Pi }\\ &\hspace{71.13188pt}\downarrow ^{\widehat{?}_{}}_{B^{\prime \text{c}}\,b^{\prime }}\circ \uparrow ^{\widehat{?}_{}}_{A^{\prime \text{c}}\,a^{\prime }}(f\,a^{\prime })\\ &= {\rm \lambda }(b^{\prime } : \mathrm{El}\,A^{\prime \text{d}}). ~\text{let}\,a^{\prime }=\lbrace {{{\rm \mathtt {cast}}}}\rbrace _{}~B^{\prime \text{d}}~A^{\prime \text{d}}~b^{\prime }\,\text{in}\, \qquad {by definition of}\ \lbrace {{{\rm \mathtt {cast}}}}\rbrace _{}\\ &\hspace{71.13188pt}\lbrace {{{\rm \mathtt {cast}}}}\rbrace _{}\,(A^{\prime \text{c}}\,a^{\prime })~(B^{\prime \text{c}}\,b^{\prime })~(f\,a^{\prime }). \end{align*}
For any \(b : \mathrm{El}\,B^\text{d}\) and \(b^{\prime } : \mathrm{El}\,B^{\prime \text{d}}\) , \(b_\text{rel}: \mathrm{El}_\text{rel}\,B^\text{d}_\text{rel}\,b\,b^{\prime }\) , we have by inductive hypothesis
\begin{equation*} a_\text{rel}:= \lbag {{\rm \mathtt {cast}}}\rbag\,B^\text{d}_\text{rel}\,A^\text{d}_\text{rel}\,b_\text{rel}: \mathrm{El}_\text{rel}~{A_\text{rel}}~([{{{\rm \mathtt {cast}}}}]\,B^\text{d}\,A^\text{d}\,b)~(\lbrace {{{\rm \mathtt {cast}}}}\rbrace _{}\,B^{\prime \text{d}}\,A^{\prime \text{d}}\,b^{\prime }), \end{equation*}
so that, posing \(a = [{{{\rm \mathtt {cast}}}}]\,B^\text{d}\,A^\text{d}\,b\) and \(a^{\prime } = \lbrace {{{\rm \mathtt {cast}}}}\rbrace _{}\,B^{\prime \text{d}}\,A^{\prime \text{d}}\,b^{\prime }\) ,
\begin{equation*} f_\text{rel}\,a\,a^{\prime }\,a_\text{rel}: \mathrm{El}_\text{rel}~(A^\text{c}_\text{rel}\,a\,a^{\prime }\,a_\text{rel})~(f\,a)~(f^{\prime }\,a^{\prime }), \end{equation*}
and by another application of the inductive hypothesis
\begin{equation*} \lbag {{\rm \mathtt {cast}}}\rbag~(B^\text{c}_\text{rel}\,b\,b^{\prime }\,b_\text{rel})~(A^\text{c}_\text{rel}\,a\,a^{\prime }\,a_\text{rel})~(f_\text{rel}\,a\,a^{\prime }\,a_\text{rel}) : \binlogrelTy {B^\text{c}_\text{rel}\,b\,b^{\prime }\,b_\text{rel}}~([{{{\rm \mathtt {cast}}}}]~A~B~f~a)~(\lbrace {{{\rm \mathtt {cast}}}}\rbrace _{}~A^{\prime }~B^{\prime }~f^{\prime }~a^{\prime }). \end{equation*}
Packing these together, we obtain a term
\begin{equation*} \lbag {{\rm \mathtt {cast}}}\rbag~A_\text{rel}~B_\text{rel}~f_\text{rel}: \mathrm{El}_\text{rel}~(\widehat{\Pi }~B^\text{d}_\text{rel}~B^\text{c}_\text{rel})~([{{{\rm \mathtt {cast}}}}]~A~B~f)~(\lbrace {{{\rm \mathtt {cast}}}}\rbrace _{}~A^{\prime }~B^{\prime }~f^{\prime }). \end{equation*}
Case \(A_\text{rel}= \widehat{\Pi }_\text{rel}\,A^\text{d}_\text{rel}\,A^\text{c}_\text{rel}\) and \(B_\text{rel}= \widehat{?}_{\text{rel}}\) : By definition of the logical relation at \(\widehat{?}_{\text{rel}}\) , we need to build a witness of type
\begin{equation*} \mathrm{El}_\text{rel}~(\widehat{?}_{}^{c_\Pi (i)} \rightarrow \widehat{?}_{}^{c_\Pi (i)})~([{{{\rm \mathtt {cast}}}}]~A~(\widehat{?}_{}\rightarrow \widehat{?}_{})~f)~(\downarrow ^{\widehat{?}_{}}_{\widehat{?}_{}\rightarrow \widehat{?}_{}}(\lbrace {{{\rm \mathtt {cast}}}}\rbrace _{}~A^{\prime }~\widehat{?}_{}~f^{\prime })). \end{equation*}
We compute that
\begin{equation*} \downarrow ^{\widehat{?}_{}}_{\widehat{?}_{}\rightarrow \widehat{?}_{}} (\lbrace {{{\rm \mathtt {cast}}}}\rbrace _{}\,A^{\prime }\,\widehat{?}_{}\,f^{\prime }) = ~\downarrow ^{\widehat{?}_{}}_{\widehat{?}_{}\rightarrow \widehat{?}_{}} \circ \downarrow ^{\widehat{?}_{}}_{\widehat{?}_{}} \circ \uparrow ^{\widehat{?}_{}}_{A^{\prime }}f^{\prime } = ~\downarrow ^{\widehat{?}_{}}_{\widehat{?}_{}\rightarrow \widehat{?}_{}} \circ \uparrow ^{\widehat{?}_{}}_{A^{\prime }}f^{\prime } = \lbrace {{{\rm \mathtt {cast}}}}\rbrace _{}\,A^{\prime }\,(\widehat{?}_{}\rightarrow \widehat{?}_{})\,f^{\prime }. \end{equation*}
So the result holds by induction hypothesis.
Other cases with \(A_\text{rel}= \widehat{\Pi }_\text{rel}\,A^\text{d}_\text{rel}\,A^\text{c}_\text{rel}\) : It is enough to show that \(\lbrace {{{\rm \mathtt {cast}}}}\rbrace _{}\,A^{\prime }\,B^{\prime }\,f^{\prime } = \maltese _{B^{\prime }}\) when \(B^{\prime } = \maltese\) (trivial) or \(\mathrm{head}\,\,B^{\prime } \ne \texttt {pi}\) . The latter case holds because \(\downarrow ^{\widehat{?}_{}}_{{\rm germ}_{}\,c} \uparrow ^{\widehat{?}_{}}_{{\rm germ}_{}\,c^{\prime }} x = \maltese _{\mathrm{El}_{{\rm Head}}\,c}\) whenever \(c \ne c^{\prime }\) and downcasts preserve \(\maltese\) .
Case \(A_\text{rel}= \widehat{?}_{\text{rel}}\) , \(B_\text{rel}= \widehat{\Pi }_\text{rel}\,B^\text{d}_\text{rel}\,B^\text{c}_\text{rel}\) and \(a = (\texttt {pi} ; f)\) : By hypothesis, \(a_\text{rel}: \mathrm{El}_\text{rel}~(\widehat{?}_{}\rightarrow \widehat{?}_{})~f~(\downarrow ^{\widehat{?}_{}}_{\widehat{?}_{}\rightarrow \widehat{?}_{}}a^{\prime })\) and \(\lbrace {{{\rm \mathtt {cast}}}}\rbrace _{}~\widehat{?}_{}~B^{\prime }~a^{\prime } = \lbrace {{{\rm \mathtt {cast}}}}\rbrace _{}~(\widehat{?}_{}\rightarrow \widehat{?}_{})~B^{\prime }~(\downarrow ^{\widehat{?}_{}}_{\widehat{?}_{}\rightarrow \widehat{?}_{}}a^{\prime })\) so by induction hypothesis
\begin{equation*} \lbag {{\rm \mathtt {cast}}}\rbag~(\widehat{?}_{\text{rel}} \rightarrow _\text{rel}\widehat{?}_{\text{rel}})~B_\text{rel}~f~(\downarrow ^{\widehat{?}_{}}_{\widehat{?}_{}\rightarrow \widehat{?}_{}}a^{\prime })~a_\text{rel}: \mathrm{El}_\text{rel}\,B_\text{rel}~([{{{\rm \mathtt {cast}}}}]\,\widehat{?}_{}\,B\,(\texttt {pi};f))~(\lbrace {{{\rm \mathtt {cast}}}}\rbrace _{}\,\widehat{?}_{}\,B^{\prime }\,a^{\prime }). \end{equation*}
The others cases with \(A_\text{rel}= \widehat{?}_{\text{rel}}\) proceed in a similarly fashion. All cases with \(A_\text{rel}= \maltese _\text{rel}{}\) are immediate since \(\maltese ^\text{dis}\) and \(\maltese ^\text{mon}\) are related at any related types. Finally, the cases with \(A_\text{rel}{} = \widehat{\mathbb {N}}_\text{rel}\) follow the same pattern as for \(\widehat{\Pi }_\text{rel}\) .□

D Diverging Terms Denote as Errors in \(\omega\) -cpos

In this section we define a logical relation between \(\mathsf {CastCIC} ^{\mathcal {G}}\) and \(\mathsf {CIC^{IR}_{QIT}}\) and prove a fundamental lemma, obtaining Lemma 33 as a corollary. The logical relation is presented in Figures 2123 and relates types \(A\) in \(\mathsf {CastCIC} ^{\mathcal {G}}\) with sub- \(\omega\) -cpos of \(\ddot{?}_{}\) , following the description of \(\mathrm{El}\) in that model. A type \(A\) related to an \(\omega\) -cpo \(A^{\prime }\) by the logical relation, noted \(A \sim A^{\prime }\) , induces a relation between terms of type \(A\) and elements of \(A^{\prime }\) . We use variables with \(\varepsilon\) subscript to name proof witnesses of relatedness between two objects, for instance \(A_\varepsilon : A \sim A^{\prime }\) , and bold variables such as \(\mathbb {\Gamma }, \mathbb {\Delta }\) for the corresponding double contexts consisting of variable bindings \({a} \sim a^{\prime } : A_\varepsilon\) . The projections \({\mathbb {\Gamma }_{1}}\) and \(\mathbb {\Gamma }_{2}\) are then respectively contexts in \(\mathsf {CastCIC} ^{\mathcal {G}}\) and \(\mathsf {CIC^{IR}_{QIT}}\) .
Fig. 21.
Fig. 21. Logical relation between \(\mathsf {CastCIC} ^{\mathcal {G}}\) and \(\omega\) -cpos.
Fig. 22.
Fig. 22. Logical relation between \(\mathsf {CastCIC} ^{\mathcal {G}}\) and \(\omega\) -cpos.
Fig. 23.
Fig. 23. Logical relation between \(\mathsf {CastCIC} ^{\mathcal {G}}\) and \(\omega\) -cpos.
The logical relation uses weak head reduction to characterize divergence. We note \({t} \twoheadrightarrow _{\mathrm{wh}}{u}\) when a \(\mathsf {CastCIC}\) term \({t}\) reduces to a weak head normal form, that is a term \({u}\) such that \({\rm canonical}{u}\) hold (see Figure 7), using only weak head reduction steps. We note \({t} \not\twoheadrightarrow _{\mathrm{wh}}\) when weak head reduction paths from \({t}\) never reach a weak head normal form, that is \({t}\) is unsolvable.
We first state a lemma making explicit how divergence is accounted for by the logical relation.
Lemma 41 (Diverging Terms Relate to Errors).
(1)
If \({\mathbb {\Gamma }_{1}} \vdash {t} : {T}\) , \(T_\varepsilon : \mathbb {\Gamma } \Vdash {T} \sim T^{\prime }\) and \({t} \not\twoheadrightarrow _{\mathrm{wh}}\) then \(\mathbb {\Gamma } \Vdash {t} \sim {\rm \mathtt {err}}_{T^{\prime }} : T_\varepsilon\) .
(2)
Conversely, if \({\Gamma } \vdash {t} : {T}\) , \(T_\varepsilon : \mathbb {\Gamma } \Vdash {T} \sim T^{\prime }\) , \(\mathbb {\Gamma } \Vdash {t} \sim t^{\prime } : T_\varepsilon\) and \({t} \not\twoheadrightarrow _{\mathrm{wh}}\) then \(t^{\prime } = {\rm \mathtt {err}}_{T^{\prime }}\) .
Proof.
In the two parts of the lemma, we proceed by induction on \(T_\varepsilon\) . For the first part, the cases \(T_\varepsilon = \square _\varepsilon , \mathbb {N}_\varepsilon , \mathbb {B}_\varepsilon\) and \(?_\varepsilon\) are immediate because in each case a rule apply for diverging terms. If \(T_\varepsilon = {\rm \mathtt {err}}_\varepsilon\) , then \(\mathbb {\Gamma } \Vdash {t} \sim \mathtt {()} : T_\varepsilon\) which is enough because \(\mathtt {()}= {\rm \mathtt {err}}_{\mathtt {unit}} = {\rm \mathtt {err}}_{\mathrm{El}\,\widehat{{\rm \mathtt {err}}_{}}} = {\rm \mathtt {err}}_{\mathrm{El}\,T^{\prime }}\) . Finally, if \(T_\varepsilon = {\rm \Pi }_\varepsilon \,A_\varepsilon \,B_\varepsilon\) , then for any \(\rho : \mathbb {\Delta }\subset \mathbb {\Gamma }\) and \(a_\varepsilon : \mathbb {\Delta } \Vdash {a} \sim a^{\prime } : A_\varepsilon \,\rho\) we have that \({\mathbb {\Gamma }_{1}} \vdash {t[\rho _{1}]~a} : {B[\rho _{1},a]}\) , \(B_\varepsilon \,\rho \,a_\varepsilon : \mathbb {\Delta } \Vdash {B[\rho _{1},a]} \sim B^{\prime }[\rho _{2}, a^{\prime }]\) and \({t~a} \not\twoheadrightarrow _{\mathrm{wh}}\) , so by induction hypothesis \(\mathbb {\Delta } \Vdash {t[\rho _{1}]~a} \sim {\rm \mathtt {err}}_{B^{\prime }[\rho _{2},a^{\prime }]} : B_\varepsilon \,\rho \,a_\varepsilon\) , hence \(\mathbb {\Gamma } \Vdash {t} \sim {\rm \mathtt {err}}_{\widehat{\Pi }\,A^{\prime }\,B^{\prime }} : T_\varepsilon\) .
We now turn to the second part of the lemma. When \(T_\varepsilon = \square _\varepsilon , \mathbb {N}_\varepsilon , \mathbb {B}_\varepsilon , ?_\varepsilon ,\) and \({\rm \mathtt {err}}_\varepsilon\) , there is exactly one rule that apply to relate to a term without weak head normal form \({t}\) so that necessarily \(t^{\prime } = {\rm \mathtt {err}}_{T^{\prime }}\) . When \(T_\varepsilon = {\rm \Pi }_\varepsilon \,A_\varepsilon \,B_\varepsilon\) , any \(\rho : \mathbb {\Delta }\subset \mathbb {\Gamma }\) and \(a_\varepsilon : \mathbb {\Delta } \Vdash {a} \sim a^{\prime } : A_\varepsilon \,\rho ,\) we have that \(B_\varepsilon \,\rho \,a_\varepsilon : \mathbb {\Delta } \Vdash {B[\rho _{1},a]} \sim B^{\prime }[\rho _{2}, a^{\prime }]\) , \(\mathbb {\Delta } \Vdash {t[\rho _{1}]~a} \sim t^{\prime }[\rho _{2}]~a^{\prime } : B_\varepsilon \,\rho \,a_\varepsilon\) and \({t~a} \not\twoheadrightarrow _{\mathrm{wh}}\) , so by induction hypothesis \(t^{\prime }\,a^{\prime } = {\rm \mathtt {err}}_{B^{\prime }[\rho _{2}, a^{\prime }]}\) . Taking \(\rho\) to be the weakening \(\mathbb {\Gamma }, {a} \sim a^{\prime } : A_\varepsilon \subset \mathbb {\Gamma }\) , we have by function extensionality that \(t^{\prime } = \lambda (a^{\prime }:A^{\prime }). {\rm \mathtt {err}}_{B^{\prime }} = {\rm \mathtt {err}}_{\widehat{\Pi }\,A^{\prime }\,B^{\prime }}\) .□
Lemma 42 (Fundamental Lemma).
If \({\Gamma } \vdash\) then there exists \(\mathbb {\Gamma }\) such that \(\mathbb {\Gamma } \Vdash\) , \({\mathbb {\Gamma }_{1}} = {\Gamma }\) and \(\mathbb {\Gamma }_{2} = \lbrace \!\mid \!{{{\Gamma }}}\!\mid \!\rbrace _{}\) ;
If \({\Gamma } \vdash {T} {\rm \triangleright }{\square _i}\) there exists a derivation \(T_\varepsilon : \mathbb {\Gamma } \Vdash {T} \sim \lbrace \!\mid \!{{{T}}}\!\mid \!\rbrace _{}\)
If \({\Gamma } \vdash {t} {\rm \triangleright }{T}\) then there exists a derivation \(t_\varepsilon : \mathbb {\Gamma } \Vdash {t} \sim \lbrace {{{t}}}\rbrace _{} : T_\varepsilon\)
If \({\Gamma } \vdash {T} {\rm \triangleright }{\square _i}\) , \({\Gamma } \vdash {T^{\prime }} {\rm \triangleright }{\square _i}\) and \({T} \equiv {T^{\prime }}\) then \(\lbrace \!\mid \!{{{T}}}\!\mid \!\rbrace _{} = \lbrace \!\mid \!{{{T}^{\prime }}}\!\mid \!\rbrace _{}\) and \(T_\varepsilon = T^{\prime }_\varepsilon : \mathbb {\Gamma } \Vdash {T} \sim \lbrace \!\mid \!{{{T}}}\!\mid \!\rbrace _{}\) .
Proof.
Since the translation \(\lbrace \!\mid \!{{-}}\!\mid \!\rbrace _{}\) underly a model of \(\mathsf {CastCIC} ^{\mathcal {N}}\) , it sends convertible types \({T}, {T^{\prime }}\) in the source to provably equal types in the target \(\lbrace \!\mid \!{{{T}}}\!\mid \!\rbrace _{} = \lbrace \!\mid \!{{{T}^{\prime }}}\!\mid \!\rbrace _{}\) , proving the last claim.
The three other claims are proved by mutual induction on the input derivation, assuming an undirected variant of the rules in Figures 1 and 3, which is possible by Lennon-Bertrand 2021. Concretely, this modification means that we assume additional well-formedness premises in the derivations, e.g., for contexts and types, and do not show that input well-formedness is preserved. Moreover, the induction hypothesis needs to be strengthened to quantify over an arbitrary context \(\mathbb {\Delta }\) with a substitution \(\sigma : \mathbb {\Delta }\rightarrow \mathbb {\Gamma }\) whose components are related according to the logical relation.
For contexts, if the derivation ends with a rule Empty, it is enough to take \(\mathbb {\Gamma }= \cdot\) . If it ends with Concat, then by induction hypothesis there exists \(\mathbb {\Gamma }\) and \(A_\varepsilon\) such that \({\mathbb {\Gamma }_{1}} = {\Gamma }\) , \(\mathbb {\Gamma }_{2} = \lbrace \!\mid \!{{{\Gamma }}}\!\mid \!\rbrace _{}\) , \(\mathbb {\Gamma } \Vdash\) and \(A_\varepsilon : \mathbb {\Gamma } \Vdash {A} \sim \lbrace \!\mid \!{{{A}}}\!\mid \!\rbrace _{}\) , so taking \(\mathbb {\Gamma }, {a} \sim a^{\prime } : A_\varepsilon\) suffices.
For Univ by induction hypothesis \(\mathbb {\Gamma } \Vdash\) with \({\mathbb {\Gamma }_{1}} = {\Gamma }\) . Moreover, \({\Gamma }\vdash {\square _i} {\rm \triangleright }{\square _{i+1}}\) and \(\lbrace {{{\square _i}}}\rbrace _{} = \widehat{\square \!\!\!\! \square }_i\) so \(\mathbb {\Gamma } \Vdash {\square _i} \sim \lbrace {{{\square _i}}}\rbrace _{} : \square _\varepsilon \,(i+1)\) and \(\mathbb {\Gamma } \Vdash {\square _i} \sim \lbrace {{{\square _i}}}\rbrace _{}\) . The rules Ind (for \(\mathbb {N}, \mathbb {B}\) ) and Cons (for \(0, \texttt {suc}, \mathtt {true}, \mathtt {false}\) ), introducing types and terms that are already in weak head normal form follow the same pattern as Univ. In the case of the rules Prod and Abs, the context needs to be extended, and we need to take advantage of the full induction hypothesis strengthened under arbitrary reducible substitutions.
Dually, the rule App is immediate by induction hypothesis and the definition the logical relation at function types. A bit more work is needed for the rule Fix for \(\mathtt {ind}_\mathbb {B}\) and \(\mathtt {ind}_\mathbb {N}\) , doing a case analysis on the proof of relatedness of their main argument. If the main argument diverges, then the applied eliminator diverges too so it is related to \({\rm \mathtt {err}},\) which is its translation because eliminators send errors at an inductive type to errors at the adequate type in \(\omega\) -cpos. Otherwise the main argument weak head reduces to a normal form and we can conclude by induction hypothesis and closure by anti-reduction.
For the variable case, rule Var, we can show by induction on the proof of relatedness of its type that it is related to its \(\eta\) -expansion at \(\Pi\) types an to itself at any other type using the rules for neutrals. We conclude by extensionality of the \(\omega\) -cpo model.
Conversion rules Check, Prod-Inf, Ind-Inf, and Univ-Inf satisfy the fundamental lemma because convertible types induce the same relation on their term.
For Err, we have by induction hypothesis that \(T_\varepsilon : \mathbb {\Gamma } \Vdash {T} \sim \lbrace {{{T}}}\rbrace _{} : \square _\varepsilon\) . By case analysis, \(T_\varepsilon\) is necessarily one of \({\rm \mathtt {err}}_\varepsilon ,{\rm \Pi }_\varepsilon , ?_\varepsilon , \mathbb {B}_\varepsilon , \mathbb {N}_\varepsilon\) or \(\square _\varepsilon\) . If \(T_\varepsilon = {\rm \mathtt {err}}_\varepsilon \,{T}\) then \(\mathbb {\Gamma } \Vdash {{\rm \mathtt {err}}_T} \sim \mathtt {()} : {\rm \mathtt {err}}_\varepsilon \,{T}\) since \({\mathbb {\Gamma }_{1}} \vdash {{\rm \mathtt {err}}_T} {\rm \triangleright }{T}\) , and we can conclude using extensionality of \(\mathtt {unit}= \lbrace \!\mid \!{{{T}}}\!\mid \!\rbrace _{}\) , that is \(\lbrace {{{{\rm \mathtt {err}}_T}}}\rbrace _{} = \mathtt {()}\) . If \(T_\varepsilon = {\rm \Pi }_\varepsilon \,A_\varepsilon \,B_\varepsilon\) , then for any \(\rho : \mathbb {\Delta }\subset \mathbb {\Gamma }\) and \(a_\varepsilon : \mathbb {\Delta } \Vdash {a} \sim a^{\prime } : A_\varepsilon \,\rho\) we have that \({T[\rho _{1}]} \twoheadrightarrow _{\mathrm{wh}}{\Pi (a:A)B}\) and \({{\rm \mathtt {err}}_{T}~a} \twoheadrightarrow _{\mathrm{wh}}{{\rm \mathtt {err}}_{B[a]}}\) , so we conclude this case by induction hypothesis \(\mathbb {\Delta } \Vdash {{\rm \mathtt {err}}_{B[a]}} \sim \lbrace {{{{\rm \mathtt {err}}_{B[a]}}}}\rbrace _{} : B_\varepsilon \,a_\varepsilon\) , closure by anti-reduction and the fact that \(\lbrace {{{{\rm \mathtt {err}}_{B[a]}}}}\rbrace _{} = {\rm \mathtt {err}}_{\lbrace {{B[a]}}\rbrace _{}} = {\rm \mathtt {err}}_{\lbrace {{B}}\rbrace _{}[a^{\prime }]}\) .
In all the other cases \({T}\) weak head reduces to a type in weak head normal form \({?_\square }, {\square _i}, {\mathbb {N},}\) or \({\mathbb {B}}\) , and a corresponding rule is present in the logical relation to conclude directly. A similar proof apply for the rule Unk.
Finally, for the rule Case with conclusion \({\Gamma } \vdash {\langle {B} {\ \Leftarrow \ } {A} \rangle \,{t}} {\rm \triangleright }{B}\) , we have by induction hypothesis we have that \(\mathbb {\Gamma } \Vdash , {A_\varepsilon : \mathbb {\Gamma } \Vdash {A} \sim \lbrace \!\mid \!{{{A}}}\!\mid \!\rbrace _{}}, B_\varepsilon : \mathbb {\Gamma } \Vdash {B} \sim \lbrace \!\mid \!{{{B}}}\!\mid \!\rbrace _{}\) and \(\mathbb {\Gamma } \Vdash {t} \sim \lbrace {{{t}}}\rbrace _{} : A_\varepsilon\) . By analyzing all possible weak head reduction paths from \({\langle {B} {\ \Leftarrow \ } {A} \rangle \,{t}}\) , either:
\({\langle {B} {\ \Leftarrow \ } {A} \rangle \,{t}} \twoheadrightarrow _{\mathrm{wh}}{u}\) such that \(\mathbb {\Gamma } \Vdash {u} \sim \lbrace {{{u}}}\rbrace _{} : B_\varepsilon\) using inversions on \(A_\varepsilon , B_\varepsilon ,\) and \(t_\varepsilon\) , or
one of \({A}\) , \({B,}\) or \({t}\) never reduces to a weak head normal form.
In case (a), we conclude that \(\mathbb {\Gamma } \Vdash {\langle {B} {\ \Leftarrow \ } {A} \rangle \,{t}} \sim \lbrace {{{\langle {B} {\ \Leftarrow \ } {A} \rangle \,{t}}}}\rbrace _{} : B_\varepsilon\) by closure under anti-reduction and using the fact that \(\lbrace {{{\langle {B} {\ \Leftarrow \ } {A} \rangle \,{t}}}}\rbrace _{} = \lbrace {{{u}}}\rbrace _{}\) (because \(\lbrace {{-}}\rbrace _{}\) maps convertible terms to equal terms in the model). In case (b), we have that \(\mathbb {\Gamma } \Vdash {\langle {B} {\ \Leftarrow \ } {A} \rangle \,{t}} \sim {\rm \mathtt {err}}_{\lbrace {{{B}}}\rbrace _{}} : B_\varepsilon\) by the first part of Lemma 41 and the second part of that lemma ensures that one of \(\lbrace {{{A}}}\rbrace _{}\) , \(\lbrace {{{B}}}\rbrace _{},\) or \(\lbrace {{{t}}}\rbrace _{}\) is an error at the adequate type so that \(\lbrace {{{\langle {B} {\ \Leftarrow \ } {A} \rangle \,{t}}}}\rbrace _{} = \downarrow ^{\widehat{?}_{}}_{\lbrace {{{B}}}\rbrace _{}}\uparrow ^{\widehat{?}_{}}_{\lbrace {{{A}}}\rbrace _{}}\lbrace {{{t}}}\rbrace _{} = {\rm \mathtt {err}}_{\lbrace {{{B}}}\rbrace _{}}\) .□
Corollary 43.
If \({\Gamma } \vdash {t} {\rm \triangleright }{T}\) and \({t} \not\twoheadrightarrow _{\mathrm{wh}}\) then \(\lbrace {{{t}}}\rbrace _{} = {\rm \mathtt {err}}_{\lbrace {{{T}}}\rbrace _{}}\) .
Proof.
By the fundamental lemma, \(\mathbb {\Gamma } \Vdash {t} \sim \lbrace {{{t}}}\rbrace _{} : T_\varepsilon\) with \(T_\varepsilon : \mathbb {\Gamma } \Vdash {T} \sim \lbrace {{{T}}}\rbrace _{} : \square _\varepsilon\) and by the second part of Lemma 41, \(\lbrace {{{t}}}\rbrace _{} = {\rm \mathtt {err}}_{\lbrace {{{T}}}\rbrace _{}}\) .□

E A Direct Presentation of Vectors

Vectors have two new normal forms, corresponding to cast of \(\mathsf{nil}\) and \(\mathsf{cons}\) to \(\mathtt {vec}~A~?_{\mathbb {N}}\) . The difference with the treatment of the universe is that the corresponding term, for instance \(\langle {\mathtt {vec}~A~?_{\mathbb {N}}} {\ \Leftarrow \ } {\mathtt {vec}~A~n} \rangle \,{t}\) for the case of \(\mathsf{nil}\) , can not be considered as a canonical form because they involve a non-linear occurrence of \(A\) . To remedy this issue, we add two new canonical forms ( \(\mathtt {nil}_?~A\) and \(\mathtt {cons}_?~A~a~n~v\) ) to vectors with introduction typing rules defined in Figure 24.
Fig. 24.
Fig. 24. Canonical forms and reduction rule for vectors.
Regarding cast on vectors, it does not only compute in the argument of the cast as it is the case for inductive types without indices, but it also computes on the indices. That is, a cast on vectors is neutral when either one of the indices is neutral or the argument is neutral (see Figure 24). Other kind of neutral can be derived from one of the inductive types without indices and are omitted here.
Similarly, we do not detail the other typing rules for vectors as they are similar to the one for inductive types without indices, and focus on explaining the new reduction rules, presented also in Figure 24.
The two first reduction rules v-rect-nil and v-rect-cons are standard reduction rules in \(\mathsf {CIC}\) for the recursor vect_rect on vectors. The rules v-rect-err and v-rect-unk are the standard rules dealing with exceptions. Additionally, there are two computation rules for the eliminator on the two new constructors v-rectnilu and v-rect-consu, which basically consist in the underlying non-exceptional constructor to the eliminator and cast the result back to \(P~?_\mathbb {N}\) . This rule somehow transfers the cast on vectors to a cast on the returned type of the predicate.
Finally, there are rules to conduct casts between vectors in canonical forms. The last three rules (V-unk, V-err, and V-to-err) are simply propagation of errors. Then, there remains 12 rules, 3 by constructors of vectors. We just explain the one on \(\mathsf{cons}\) . Rule V-cons applies when both indices of the form \(S\) of something and propagates the cast of the arguments, as does the standard rule for casting a constructor. Rule V-cons-nil detects that the indices do not match and raise an error. Finally, Rule V-cons-? propagates the cast on the arguments, but this time applied to \(\mathtt {cons}_?\) , thus converting precise information to a less precise information.

F Leftovers

F.1 Optimized Cast

The last definition corresponds to a usual optimization of elaboration to a cast calculus: why insert a run-time check when you know at typing time already that the check will always succeed? Thus, a \({\rm \mathtt {cast}}\) operator should only be inserted by elaboration when the types are not the same (i.e., convertible). Although with closed types this is merely for performance purposes, it becomes crucial for us, as types can contain variables that block reduction of the \({\rm \mathtt {cast}}\) operator: \(\langle {A} {\ \Leftarrow \ } {A} \rangle \,{t}\) does not reduce, because \({\rm \mathtt {cast}}\) waits for the head constructor of \(A\) to appear. Even though one could prove that \(\langle {A} {\ \Leftarrow \ } {A} \rangle \,{t} = t\) in the models we consider, the fact that this equality is not definitional is enough to threaten theoretical properties, such as conservativity, because it blocks reduction.
Definition 10 (Optimized Cast).
Define the optimized cast \(t::A \Rightarrow B\) to be \(t\) if \(A \equiv B\) , and \(\langle {B} {\ \Leftarrow \ } {A} \rangle \,{t}\) otherwise.
Note that this cast can only be defined in a setting where conversion is decidable. If both \(A\) and \(B\) are well-typed, this depends on the normalization properties of the system: if the system normalizes, conversion is decidable (using normal forms), but if it does not then it is not. Thus, when considering the non-normalizing variants of \(\mathsf {CastCIC}\) , we restrict this optimized cast to the \(\mathsf {CIC}\) fragment, that still normalizes. In other words, a cast is always inserted between gradual types, even if it is not needed.
It is really an optimization, in the following sense.
Proposition 44 (Correction of the Optimized Cast).
If \(\Gamma \vdash A : \square {}\) and \(\Gamma \vdash B : \square {}\) one has \(\Gamma \vdash t::A \Rightarrow B : B\) if and only if \(\Gamma \vdash \langle {B} {\ \Leftarrow \ } {A} \rangle \,{t} : B\) .
Lemma 45 (Syntactic Precision Respects Optimized Cast).
If \(\Gamma .1 \vdash t : A\) , \(\Gamma .1 \vdash B : \square\) , \(\Gamma .2 \vdash t^{\prime } : A^{\prime }\) , \(\Gamma .2 \vdash B^{\prime } : \square\) and we have the precision relations \(\Gamma \vdash A \sqsubseteq _{\alpha }A^{\prime }\) , \(\Gamma \vdash B \sqsubseteq _{\alpha }B^{\prime }\) and \(\Gamma \vdash t \sqsubseteq _{\alpha }t^{\prime }\) , then \(t^{\prime }::A^{\prime } \Rightarrow B^{\prime } {\rm {\leadsto }^\ast }s^{\prime }\) for some \(s^{\prime }\) such that \(\Gamma \vdash s \sqsubseteq _{\alpha }s^{\prime }\) .
Proof.
If both casts optimize or do not optimize, no reduction is needed and the pointwise precision suffice. If the cast on the left is not optimized, and the one on the right is, we use the corresponding non-diagonal rule for the cast, and also no reduction is needed. The hard case is when the cast on the left is optimized, but not the one on the right. Then we can take \(T\) to be the normal form of both \(A\) and \(B\) , and we have \(\Gamma \vdash t : T\) . We can simulate this reduction, and thus get \(A^{\prime } {\rm {\leadsto }^\ast }A^{\prime \prime }\) and \(B^{\prime } {\rm {\leadsto }^\ast }B^{\prime \prime }\) for some \(A^{\prime \prime }\) and \(B^{\prime \prime }\) such that \(\Gamma \vdash T \sqsubseteq _{\alpha }A^{\prime \prime }\) and \(\Gamma \vdash T \sqsubseteq _{\alpha }B^{\prime \prime }\) . Thus, \(\langle {B^{\prime }} {\ \Leftarrow \ } {A^{\prime }} \rangle \,{t^{\prime }} {\rm {\leadsto }^\ast }\langle {B^{\prime \prime }} {\ \Leftarrow \ } {A^{\prime \prime }} \rangle \,{t^{\prime }}\) , and now we can conclude with the non-diagonal rule for the cast.□

References

[1]
Andreas Abel, Joakim Öhman, and Andrea Vezzosi. 2018. Decidability of conversion for type theory in type theory. Proceedings of the ACM on Programming Languages 2, POPL, (Jan. 2018), 29 pages. DOI:
[2]
Samson Abramsky and Achim Jung. 1995. Domain Theory. Oxford University Press, Inc., 1–168.
[3]
Thorsten Altenkirch. 1999. Extensional equality in intensional type theory. In Proceedings of the 14th Symposium on Logic in Computer Science. IEEE Computer Society Press, Trento, Italy, 412–420. DOI:
[4]
Thorsten Altenkirch, Simon Boulier, Ambrus Kaposi, Christian Sattler, and Filippo Sestini. 2021. Constructing a universe for the setoid model., Stefan Kiefer and Christine Tasson (Eds.), Lecture Notes in Computer Science, Vol. 12650, Springer, 1–21. DOI:
[5]
Thorsten Altenkirch, Simon Boulier, Ambrus Kaposi, and Nicolas Tabareau. 2019. Setoid type theory - A syntactic translation.Graham Hutton (Ed.), Lecture Notes in Computer Science, Vol. 11825, Springer, 155–196. DOI:
[6]
Thorsten Altenkirch, Paolo Capriotti, Gabe Dijkstra, Nicolai Kraus, and Fredrik Nordvall Forsberg. 2018. Quotient inductive-inductive types, Christel Baier and Ugo Dal Lago (Eds.), Lecture Notes in Computer Science, Vol. 10803, Springer, 293–310. DOI:
[7]
Andrea Asperti, Wilmer Ricciotti, Claudio Sacerdoti Coen, and Enrico Tassi. 2012. A bi-directional refinement algorithm for the calculus of (Co)inductive constructions. Volume 8, Issue 1 (2012), 1–18. DOI:
[8]
Robert Atkey, Neil Ghani, and Patricia Johann. 2014. A relationally parametric model of dependent type theory. In Proceedings of the 41st ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages,Suresh Jagannathan and Peter Sewell (Eds.), ACM, 503–516. DOI:
[9]
Felipe Bañados Schwerter, Alison M. Clark, Khurram A. Jafery, and Ronald Garcia. 2021. Abstracting gradual typing moving forward: precise and space-efficient. Proc. ACM Program. Lang. Volume 5, issue POPL, pages 1-28, 2021.
[10]
Felipe Bañados Schwerter, Ronald Garcia, and Éric Tanter. 2016. Gradual type-and-effect systems. Journal of Functional Programming 26 (Sept. 2016), 19:1–19:69.
[11]
Henk Barendregt. 1991. Introduction to generalized type systems. Journal of Functional Programming 1, 2 (April 1991), 125–154.
[12]
Henk P. Barendregt. 1984. The Lambda Calculus: Its Syntax and Semantics. North-Holland.
[13]
Jean-Philippe Bernardy, Patrik Jansson, and Ross Paterson. 2012. Proofs for free: Parametricity for dependent types. Journal of Functional Programming 22, 2 (March 2012), 107–152.
[14]
Martin E. Bidlingmaier, Florian Faissole, and Bas Spitters. 2019. Synthetic Topology in Homotopy Type Theory for Probabilistic Programming. (2019). arxiv:1912.07339. Retrieved from http://arxiv.org/abs/1912.07339.
[15]
Gavin Bierman, Erik Meijer, and Mads Torgersen. 2010. Adding dynamic types to C \(^{\#}\) . In Proceedings of the 24th European Conference on Object-oriented Programming.Theo D’Hondt (Ed.), Lecture Notes in Computer Science, 6183, Springer-Verlag, Maribor, Slovenia, 76–100.
[16]
M. Blume and D. McAllester. 2006. Sound and complete models of contracts. Journal of Functional Programming 16, 4–5 (2006), 375–414.
[17]
Simon Boulier, Pierre-Marie Pédrot, and Nicolas Tabareau. 2017. The next 700 syntactical models of type theory. In Proceedings of the 6th ACM SIGPLAN Conference on Certified Programs and Proofs. 182–194. DOI:
[18]
Edwin Brady. 2013. Idris, a general purpose dependently typed programming language: Design and implementation. Journal of Functional Programming 23, 5 (Sept. 2013), 552–593.
[19]
Edwin Brady, Conor McBride, and James McKinna. 2004. Inductive families need not store their indices. In Proceedings of the Types for Proofs and ProgramsLecture Notes in Computer Science, Vol. 3085, Springer-Verlag, 115–129.
[20]
Giuseppe Castagna, Victor Lanvin, Tommaso Petrucciani, and Jeremy G. Siek. 2019. Gradual typing: A new perspective. Proceedings of the ACM on Programming Languages3, POPL (2019), 16:1–16:32 (see [POPL 2019 2019]).
[21]
James Chapman, Tarmo Uustalu, and Niccolò Veltri. 2019. Quotienting the delay monad by weak bisimilarity. Mathematical Structures in Computer Science 29, 1 (2019), 67–92. DOI:
[22]
Matteo Cimini and Jeremy Siek. 2016. The gradualizer: A methodology and algorithm for generating gradual type systems, In Proceedings of the 43rd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages.443–455 (see [Bodík and Majumdar 2016]).
[23]
Thierry Coquand and Gérard Huet. 1988. The calculus of constructions. Information and Computation 76, 2–3 (Feb. 1988), 95–120.
[24]
Pierre-Évariste Dagand, Nicolas Tabareau, and Éric Tanter. 2018. Foundations of dependent interoperability. Journal of Functional Programming 28 (2018), 9:1–9:44.
[25]
Christos Dimoulas, Robert Bruce Findler, Cormac Flanagan, and Matthias Felleisen. 2011. Correct blame for contracts: No more scapegoating. In Proceedings of the 38th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages. ACM, Austin, Texas, 215–226.
[26]
Gilles Dowek. 2001. Chapter 16 - higher-order unification and matching. In Handbook of Automated Reasoning, Alan Robinson and Andrei Voronkov (Eds.), Vol. 2, North-Holland, 1009–1062. DOI:
[27]
Peter Dybjer and Anton Setzer. 2003. Induction-recursion and initial algebras. Annals of Pure and Applied Logic 124, 1–3 (2003), 1–47. DOI:
[28]
Thomas Ehrhard. 1988. A categorical semantics of constructions. In Proceedings of the 3rd Annual Symposium on Logic in Computer Science. IEEE Computer Society, 264–273. DOI:
[29]
Richard A. Eisenberg. 2016. Dependent Types in Haskell: Theory and Practice. arxiv:1610.07978 Retrieved from https://arxiv.org/abs/1610.07978.
[30]
Joseph Eremondi, Éric Tanter, and Ronald Garcia. 2019. Approximate normalization for gradual dependent types. Proceedings of the ACM on Programming Languages 3, ICFP (2019), 88:1–88:30 (see [ICFP 2019 2019]).
[31]
Luminous Fennell and Peter Thiemann. 2013. Gradual security typing with references. In Proceedings of the 26th Computer Security Foundations Symposium. 224–239.
[32]
Robert Bruce Findler and Matthias Felleisen. 2002. Contracts for higher-order functions. In Proceedings of the 7th ACM SIGPLAN Conference on Functional Programming. ACM, Pittsburgh, PA, 48–59.
[33]
Fredrik Nordvall Forsberg. 2013. Inductive-inductive definitions. Ph.D. Dissertation. Swansea University, UK. Retrieved Jan 2021 from http://ethos.bl.uk/OrderDetails.do?uin=uk.bl.ethos.752308.
[34]
Ronald Garcia, Alison M. Clark, and Éric Tanter. 2016. Abstracting gradual typing. In Proceedings of the 43rd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages.429–442. See erratum: Retrieved from https://www.cs.ubc.ca/rxg/agt-erratum.pdf. (see Bodík and Majumdar 2016).
[35]
Ronald Garcia and Éric Tanter. 2020. Gradual typing as if types mattered. In Proceedings of the 1st ACM SIGPLAN Workshop on Gradual Typing.
[36]
Neil Ghani, Lorenzo Malatesta, and Fredrik Nordvall Forsberg. 2015. Positive inductive-recursive definitions. Logical Methods in Computer Science 11, 1 (2015), 1–21. DOI:
[37]
Gaëtan Gilbert, Jesper Cockx, Matthieu Sozeau, and Nicolas Tabareau. 2019. Definitional proof-irrelevance without K. Proceedings of the ACM on Programming Languages3, POPL (2019), 3:1–3:28. DOI: (see [POPL 2019 2019]).
[38]
Eduardo Giménez. 1998. Structural recursive definitions in type theory. In Proceedings of the 25th International Colloquium on Automata, Languages and Programming. 397–408.
[39]
Healfdene Goguen. 2005. A syntactic approach to eta equality in type theory. ACM SIGPLAN Notices 40, 1 (Jan. 2005), 75–84. DOI:
[40]
Michael Greenberg, Benjamin C. Pierce, and Stephanie Weirich. 2010. Contracts made manifest. ACM SIGPLAN Notices 45, 1 (2010), 353–364 (see [POPL 2010 2010]).
[41]
Robert Harper and Robert Pollack. 1991. Type checking with universes. Theoretical Computer Science 89, 1 (1991), 107–136. DOI:
[42]
David Herman, Aaron Tomb, and Cormac Flanagan. 2010. Space-efficient gradual typing. Higher-Order and Sympolic Computation 23, 2 (June 2010), 167–189.
[43]
Martin Hofmann. 1995. Conservativity of equality reflection over intensional type theory. In Proceedings of the Selected Papers from the International Workshop on Types for Proofs and Programs. 153–164. DOI:
[44]
Yuu Igarashi, Taro Sekiyama, and Atsushi Igarashi. 2017. On polymorphic gradual typing. In Proceedings of the ACM on Programming Languages 1, ICFP (Sept. 2017), 40:1–40:29.
[45]
Ambrus Kaposi, András Kovács, and Thorsten Altenkirch. 2019. Constructing quotient inductive-inductive types. Proceedings of the ACM on Programming Languages 3, POPL (2019), 2:1–2:24. DOI: (see [POPL 2019 2019]).
[46]
Kenneth Knowles and Cormac Flanagan. 2010. Hybrid type checking. ACM Transactions on Programming Languages and Systems 32, 2 (Jan. 2010), 1–34.
[47]
Nico Lehmann and Éric Tanter. 2017. Gradual refinement types. In Proceedings of the 44th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages. ACM, Paris, France, 775–788.
[48]
Meven Lennon-Bertrand. 2021. Complete bidirectional typing for the calculus of inductive constructions. In Proceedings of the 12th International Conference on Interactive Theorem Proving.Liron Cohen and Cezary Kaliszyk (Eds.), Leibniz International Proceedings in Informatics, Vol. 193, Schloss Dagstuhl – Leibniz-Zentrum für Informatik. DOI:
[49]
Meven Lennon-Bertrand, Kenji Maillard, Éric Tanter, and Nicolas Tabareau. 2020. Retrieved jan 2021 from https://github.com/pleiad/GradualizingCIC.
[50]
Paul Blain Levy. 2004. Call-By-Push-Value: A Functional/Imperative Synthesis. Semantics Structures in Computation, Vol. 2. Springer.
[51]
Daniel R. Licata and Robert Harper. 2011. 2-dimensional directed type theory. In 27th Conference on the Mathematical Foundations of Programming Semantics.Michael W. Mislove and Joël Ouaknine (Eds.), Electronic Notes in Theoretical Computer Science, Vol. 276, 263–289. DOI:
[52]
Saunders MacLane and Ieke Moerdijk. 1992. Sheaves in Geometry and Logic: A First Introduction to Topos Theory. Springer-Verlag. lc91033709
[53]
Assia Mahboubi and Enrico Tassi. 2008. Mathematical Components. Zenodo. https://zenodo.org/record/4457887#.YecBlljMLns.
[54]
Per Martin-Löf. 1975. An intuitionistic theory of types: Predicative part. In Proceedings of the Logic Colloquium’73, Proceedings of the Logic Colloquium, H. E. Rose and J. C. Shepherdson (Eds.), Studies in Logic and the Foundations of Mathematics, Vol. 80. North-Holland, 73–118.
[55]
Per Martin-Löf. 1984. Intuitionistic Type Theory. Studies in proof theory, Vol. 1. Bibliopolis.
[56]
Per Martin-Löf. 1996. On the meanings of the logical constants and the justifications of the logical laws. Nordic Journal of Philosophical Logic 1, 1 (1996), 11–60.
[57]
Conor McBride. 1999. Dependently Typed Functional Programs and their Proofs. Ph.D. Dissertation. University of Edinburgh.
[58]
Conor McBride. 2010. Outrageous but meaningful coincidences: Dependent type-safe syntax and evaluation, Bruno C. d. S. Oliveira and Marcin Zalewski (Eds.), ACM, 1–12. DOI:
[59]
Conor McBride. 2018. Basics of Bidirectionalism. Retrieved Jan 2021 from https://pigworker.wordpress.com/2018/08/06/basics-of-bidirectionalism/.
[60]
Conor McBride. 2019. Check the box!. In Proceedings of the 25th International Conference on Types for Proofs and Programs. Invited presentation.
[61]
Max S. New and Amal Ahmed. 2018. Graduality from embedding-projection pairs. Proceedings of the ACM on Programming Languages 2,ICFP (2018), 73:1–73:30 pages.
[62]
Max S. New, Dustin Jamner, and Amal Ahmed. 2020. Graduality and parametricity: Together again for the first time. Proceedings of the ACM on Programming Languages 4, POPL (2020), 46:1–46:32 (see [POPL 2020 2020]).
[63]
Max S. New and Daniel R. Licata. 2020. Call-by-name gradual type theory. Logical Methods in Computer Science Volume 16, Issue 1 (Jan. 2020). DOI:
[64]
Max S. New, Daniel R. Licata, and Amal Ahmed. 2019. Gradual type theory. Proceedings of the ACM on Programming Languages 3, POPL (2019), 15:1–15:31 (see [POPL 2019 2019]).
[65]
Phuc C. Nguyen, Thomas Gilray, and Sam Tobin-Hochstadt. 2019. Size-change termination as a contract: Dynamically and statically enforcing termination for higher-order programs. In Proceedings of the 40th ACM SIGPLAN Conference on Programming Language Design and Implementation. ACM, Phoenix, AZ, 845–859.
[66]
Ulf Norell. 2009. Dependently typed programming in agda. In Proceedings of the Advanced Functional Programming.Lecture Notes in Computer Science, Vol. 5832, Springer-Verlag, 230–266.
[67]
Paige Randall North. 2019. Towards a directed homotopy type theory. In Proceedings of the 35th Conference on the Mathematical Foundations of Programming Semantics.Barbara König (Ed.), Electronic Notes in Theoretical Computer Science, Vol. 347, 223–239. DOI:
[68]
Peter-Michael Osera, Vilhelm Sjöberg, and Steve Zdancewic. 2012. Dependent interoperability. In Proceedings of the 6th Workshop on Programming Languages Meets Program Verification. ACM, 3–14.
[69]
Xinming Ou, Gang Tan, Yitzhak Mandelbaum, and David Walker. 2004. Dynamic typing with dependent types. In Proceedings of the IFIP International Conference on Theoretical Computer Science. 437–450.
[70]
Erik Palmgren. 1998. On universes in type theory. In Proceedings of the Twenty Five Years of Constructive Type Theory., G. Sambin and J. Smith (Eds.), Oxford University Press, 191–204.
[71]
Erik Palmgren and Viggo Stoltenberg-Hansen. 1990. Domain interpretations of Martin-Löf’s partial type theory. Annals of Pure and Applied Logic 48, 2 (1990), 135–196. DOI:
[72]
Christine Paulin-Mohring. 2015. Introduction to the calculus of inductive constructions. In Proceedings of the All About Proofs, Proofs for All, Bruno Woltzenlogel Paleo and David Delahaye (Eds.), College Publications.
[73]
Pierre-Marie Pédrot and Nicolas Tabareau. 2017. An effectful way to eliminate addiction to dependence. In Proceedings of the 32nd Annual ACM/IEEE Symposium on Logic in Computer Science. IEEE Computer Society, 1–12. DOI:
[74]
Pierre-Marie Pédrot and Nicolas Tabareau. 2018. Failure is not an option - an exceptional type theory. In Proceedings of the 27th European Symposium on Programming Languages and Systems .Amal Ahmed (Ed.), Lecture Notes in Computer Science, Vol. 10801, Springer-Verlag, Thessaloniki, Greece, 245–271.
[75]
Pierre-Marie Pédrot and Nicolas Tabareau. 2020. The fire triangle: How to mix substitution, dependent elimination, and effects. Proceedings of the ACM on Programming Languages 4, POPL (2020), 58:1–58:28 (see [POPL 2020 2020]).
[76]
Pierre-Marie Pédrot, Nicolas Tabareau, Hans Fehrmann, and Éric Tanter. 2019. A reasonably exceptional type theory. Proceedings of the ACM on Programming Languages3, ICFP (2019), 108:1–108:29 (see [ICFP 2019 2019]).
[77]
Dana Scott. 1976. Data types as lattices. SIAM Journal on Computing 5, 3 (1976), 522–587.
[78]
Anton Setzer. 2000. Extending Martin-Löf type theory by one mahlo-universe. Archive for Mathematical Logic 39, 3 (2000), 155–181. DOI:
[79]
Michael Shulman. 2011. An Interval Type Implies Function Extensionality. Blog article. Retrieved Jan 2021 from https://homotopytypetheory.org/2011/04/04/an-interval-type-implies-function-extensionality/.
[80]
Jeremy Siek, Ronald Garcia, and Walid Taha. 2009. Exploring the design space of higher-order casts, 17–31 (see [Castagna 2009]).
[81]
Jeremy Siek and Walid Taha. 2006. Gradual typing for functional languages. In Proceedings of the Scheme and Functional Programming Workshop. 81–92.
[82]
Jeremy Siek and Walid Taha. 2007. Gradual typing for objects. In Proceedings of the 21st European Conference on Object-oriented Programming.Erik Ernst (Ed.), Lecture Notes in Computer Science, 4609, Springer-Verlag, Berlin, Germany, 2–27.
[83]
Jeremy Siek and Philip Wadler. 2010. Threesomes, with and without blame. ACM SIGPLAN Notices 45, 1 (2010), 365–376 (see [POPL 2010 2010]).
[84]
Jeremy G. Siek, Michael M. Vitousek, Matteo Cimini, and John Tang Boyland. 2015. Refined criteria for gradual typing. In Proceedings of the 1st Summit on Advances in Programming Languages(Leibniz International Proceedings in Informatics, Vol. 32). Schloss Dagstuhl–Leibniz-Zentrum fuer Informatik, Asilomar, California, 274–293.
[85]
Michael B. Smyth and Gordon D. Plotkin. 1977. The category-theoretic solution of recursive domain equations (extended abstract). In 18th Annual Symposium on Foundations of Computer Science (SFCS 1977), Oct/Nov 1977. IEEE Computer Society, 13–17. DOI:
[86]
Matthieu Sozeau, Simon Boulier, Yannick Forster, Nicolas Tabareau, and Théo Winterhalter. 2020. Coq Coq correct! verification of type checking and erasure for Coq, in Coq. InProceedings of the ACM on Programming Languages 4, POPL (2020), 8:1–8:28. DOI:
[87]
Nikhil Swamy, Catalin Hritcu, Chantal Keller, Aseem Rastogi, Antoine Delignat-Lavaud, Simon Forest, Karthikeyan Bhargavan, Cédric Fournet, Pierre-Yves Strub, Markulf Kohlweiss, Jean Karim Zinzindohoue, and Santiago Zanella Béguelin. 2016. Dependent types and multi-effects in F \(^\star\) . Proceedings of the 43rd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages. 256–270 (see [Bodík and Majumdar 2016]).
[88]
M. Takahashi. 1995. Parallel reductions in \(\lambda\) -calculus. Information and Computation 118, 1 (1995), 120–127. DOI:
[89]
Éric Tanter and Nicolas Tabareau. 2015. Gradual certified programming in Coq. In Proceedings of the 11th ACM Dynamic Languages Symposium. ACM, Pittsburgh, PA, 26–40.
[90]
The Coq Development Team. 2020. The Coq Proof Assistant Reference Manual. Retrieved Jan 2021 from https://coq.inria.fr/refman/.Version 8.12.
[91]
Peter Thiemann and Luminous Fennell. 2014. Gradual typing for annotated type systems. In Proceedings of the 23rd European Symposium on Programming Languages and Systems.Zhong Shao (Ed.), Lecture Notes in Computer Science, Vol. 8410, Springer-Verlag, Grenoble, France, 47–66.
[92]
Sam Tobin-Hochstadt and Matthias Felleisen. 2008. The design and implementation of typed scheme. In Proceedings of the 35th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages. ACM, San Francisco, CA, 395–406.
[93]
Matías Toro, Ronald Garcia, and Éric Tanter. 2018. Type-driven gradual security with references. ACM Transactions on Programming Languages and Systems 40, 4 (Nov. 2018), 16:1–16:55.
[94]
Matías Toro and Éric Tanter. 2020. Abstracting gradual references. Science of Computer Programming 197 (Oct. 2020), 1–65. https://www.sciencedirect.com/science/article/abs/pii/S0167642320301052?via%3Dihub.
[95]
Philip Wadler and Robert Bruce Findler. 2009. Well-typed programs can’t be blamed. In Proceedings of the 18th European Symposium on Programming Languages and Systems: Held as Part of the Joint European Conferences on Theory and Practice of Software. 1–16 (see [Castagna 2009]).
[96]
Mitchell Wand. 1979. Fixed-point constructions in order-enriched categories. Theoretical Computer Science 8, 1 (1979), 13–30. DOI:
[97]
Théo Winterhalter, Matthieu Sozeau, and Nicolas Tabareau. 2019. Eliminating reflection from type theory. In Proceedings of the 8th ACM SIGPLAN International Conference on Certified Programs and Proofs,Assia Mahboubi and Magnus O. Myreen (Eds.), ACM, 91–103. DOI:
[98]
Andrew K. Wright and Matthias Felleisen. 1994. A syntactic approach to type soundness. Journal of Information and Computation 115, 1 (Nov. 1994), 38–94.
[99]
Hongwei Xi and Frank Pfenning. 1998. Eliminating array bound checking through dependent types. In Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation. ACM, 249–257.
[100]
Beta Ziliani and Matthieu Sozeau. 2017. A comprehensible guide to a new unifier for CIC including universe polymorphism and overloading. 27 (2017), 1–63. DOI:

Cited By

View all
  • (2024)Gradual Indexed Inductive TypesProceedings of the ACM on Programming Languages10.1145/36746448:ICFP(544-572)Online publication date: 15-Aug-2024
  • (2023)A Dependently Typed Language with Dynamic EqualityProceedings of the 8th ACM SIGPLAN International Workshop on Type-Driven Development10.1145/3609027.3609407(44-57)Online publication date: 30-Aug-2023
  • (2023)Live Pattern Matching with Typed HolesProceedings of the ACM on Programming Languages10.1145/35860487:OOPSLA1(609-635)Online publication date: 6-Apr-2023
  • Show More Cited By

Recommendations

Comments

Information & Contributors

Information

Published In

cover image ACM Transactions on Programming Languages and Systems
ACM Transactions on Programming Languages and Systems  Volume 44, Issue 2
June 2022
295 pages
ISSN:0164-0925
EISSN:1558-4593
DOI:10.1145/3514176
Issue’s Table of Contents

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 06 April 2022
Accepted: 01 November 2021
Revised: 01 September 2021
Received: 01 November 2020
Published in TOPLAS Volume 44, Issue 2

Permissions

Request permissions for this article.

Check for updates

Author Tags

  1. Gradual typing
  2. proof assistants
  3. dependent types

Qualifiers

  • Research-article
  • Refereed

Funding Sources

  • ANID FONDECYT Regular Project
  • Inria Équipe Associée GECO

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)568
  • Downloads (Last 6 weeks)95
Reflects downloads up to 21 Sep 2024

Other Metrics

Citations

Cited By

View all
  • (2024)Gradual Indexed Inductive TypesProceedings of the ACM on Programming Languages10.1145/36746448:ICFP(544-572)Online publication date: 15-Aug-2024
  • (2023)A Dependently Typed Language with Dynamic EqualityProceedings of the 8th ACM SIGPLAN International Workshop on Type-Driven Development10.1145/3609027.3609407(44-57)Online publication date: 30-Aug-2023
  • (2023)Live Pattern Matching with Typed HolesProceedings of the ACM on Programming Languages10.1145/35860487:OOPSLA1(609-635)Online publication date: 6-Apr-2023
  • (2023)A Gradual Probabilistic Lambda CalculusProceedings of the ACM on Programming Languages10.1145/35860367:OOPSLA1(256-285)Online publication date: 6-Apr-2023
  • (2022)A reasonably gradual type theoryProceedings of the ACM on Programming Languages10.1145/35476556:ICFP(931-959)Online publication date: 31-Aug-2022
  • (2022)Propositional equality for gradual dependently typed programmingProceedings of the ACM on Programming Languages10.1145/35476276:ICFP(165-193)Online publication date: 31-Aug-2022
  • (2022)ANF preserves dependent types up to extensional equalityJournal of Functional Programming10.1017/S095679682200009032Online publication date: 16-Sep-2022

View Options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

HTML Format

View this article in HTML Format.

HTML Format

Get Access

Login options

Full Access

Media

Figures

Other

Tables

Share

Share

Share this Publication link

Share on social media