Abstract 1 Introduction 2 Level Representation 3 A Canonical Form for levels 4 A Canonical Form for Extended Levels 5 Conclusion References Appendix A Computation Algorithm

A Canonical Form for Universe Levels in Impredicative Type Theory

Yoan Géran ORCID Mines Paris PSL, Centre de Recherche en Informatique, France
Université Paris-Saclay, Laboratoire Méthodes Formelles, ENS Paris-Saclay, France
Lab. ICube UMR 7357 CNRS Université de Strasbourg, France
Abstract

The 0-imax-successor algebra, where imax:× is the function defined by imax(n,0)=0 and imax(n,S(m))=max(n,S(m)), is used to represent universe levels in impredicative type theory, in particular with universe polymorphism which introduces level variables, so it is present in proof systems such as Rocq and Lean. In particular, we need to know when two elements of this algebra are equivalent, and we may also want to decide the inequality. In this article, we introduce a canonical form for the terms of this algebra, and we provide a canonization algorithm. It permits deciding level equivalence by checking the canonical form equality, and also permits easily checking if a level is smaller than another one.

Keywords and phrases:
universe levels, canonical form, impredicativity, imax algebra
Copyright and License:
[Uncaptioned image] © Yoan Géran; licensed under Creative Commons License CC-BY 4.0
2012 ACM Subject Classification:
Theory of computation Type theory
; Theory of computation Equational logic and rewriting
Supplementary Material:
Software  (Rock formalisation): https://gitlab.crans.org/geran/level_formalisation
  archived at Software Heritage Logo swh:1:dir:79df183835f26e788d568780b46e800bf0d0cfc6
Acknowledgements:
I want to thank my PhD advisors Olivier Hermant and Gilles Dowek for the helpful discussions and comments.
Editors:
Stefano Guerrini and Barbara König

1 Introduction

The formalization of mathematical theorems and the verification of software lead to the development of many logical systems. Predicate Logic is a quite general theory but does not allow for instance to quantify over predicates, preventing the expression of some propositions. Then, more expressive logic have been introduced through the years. This paper being motivated by the universe polymorphism in impredicative type theory, the introduction will briefly remind the history of these theories, to understand what they bring.

Pure Type Systems

A lot of type theories are based on extensions of Church’s simply-typed λ-calculus which does not permit expressing terms over arbitrary types (preventing for instance to talk about all the groups). To address this, Martin-Löf introduced a dependent type theory with a type of all types [25], and later, to avoid paradoxes such as Girard’s one [12, 20], introduced a distinction between small types and large types (which are types containing types, and are also called universes) [27].

In the same years, Girard and Reynolds independently invented System F, an extension of Church’s simply-typed λ-calculus with type polymorphism, and even later, Girard presented System Fω which adds type operators i.e. the ability to quantify over terms to create types.

The Calculus of Constructions [13] introduced by Coquand in his PhD thesis combined features from both Martin-Löf Type Theory and System Fω. This system allows quantifying on types or terms to build new types and new terms, and it is the pinnacle of the λ-cube of Barendregt [4], which classifies type systems depending on the quantification possibilities.

The Calculus of Constructions is an elegant system with strong properties such as normalization and logical consistency. However, quantification over Type is not possible since it makes the system incoherent. This led Coquand to generalize the system with a predicative hierarchy of universes [12], in the same way as predicative Martin-Löf type theory [26]. This new system, which we will call CC, contains a countable sequence of universes Type0:Type1:, where Type0 is the universe of the propositions, the indices being referred to as universes levels.

These logical systems are generalized under the name of Pure Type Systems [5, 6].

Definition 1.

A Pure Type System (PTS) is defined by a set of sorts 𝒮 (that corresponds to universes), a set of axioms 𝒜𝒮2 and a set of rules 𝒮3.

𝒜 describes the sorts typing (s1 has the type s2 when (s1,s2)𝒜), and describes the possible quantifications and their typing rules. The terms are the following, where s𝒮 and x ranges an infinite set of variables.

tsxΠx:ttλx:tttt.

Both CC and predicative Martin-Löf type theory have a set of sorts indexed over the natural numbers, with for all i, Typei:Typei+1. Their difference resides in their set of rules. These rules permit to type products, so we recall the typing rule for products.

Impredicativity

With the aim of building a consistent system, paradoxes such as Girard’s one should be avoided. When Coquand analysed it, he found that a product from Type to Type could not live in Type: it should live in a greater type (hence the distinction between small and large types).

With an infinite hierarchy of universes, this principle remains: a product from Typei to Typej should live in a greater universe. Therefore, in the predicative Martin-Löf type theory, the set of rules is {Typei,Typej,Typemax(i,j)}. The choice of CC is different (and does not break the consistency either): a product from Typei to Type0 lives in Type0, so it follows the rules {Typei,Typej,Typeimax(i,j)} where imax: is defined for all i,j by imax(i,0)=0 and imax(i,j+1)=max(i,j+1).

This corresponds to the so-called impredicativity of Prop (hence the name imax for impredicative max) which notably permits to say that we can quantify over all the propositions and still get a new proposition. Accepting or rejecting impredicativity is a philosophical questioning: some consider that ΠP:PropPP should be a proposition (which is of course true), while others think that a proposition cannot be created by quantifying over all the propositions.

Universe Polymorphism

A PTS can be enriched with universe polymorphism which allows the user to quantify over universes [28, 23, 14]. For instance, it permits declaring simultaneously the identity for all the types of any universes with λs:𝒮λA:sλx:Ax. This feature adds universe variables to the language of a PTS. In the case of CC, it is equivalent to extend the syntax of the levels with level variables.

Definition 2 (Levels).

A level is a term of the grammar

0S()max(,)imax(,)x

where x is an element of a countable set of variables 𝐗. We denote by 𝐋 the set of levels, and we say that a level is ground if it does not contain any variable.

Definition 3.

We call CC the extension of CC with prenex universe polymorphism.

The universe polymorphic identity of CC is the term

idλi:𝐋λA:Typeiλx:Ax.

We can use it by instantiating the level variable. For instance, id 1Prop is the identity of Prop while id 2Type1 is Type1’s one. This instantiation is done throughout substitution functions, which replace a level variable by a level, and valuation functions which replace level variables by integers.

Definition 4 (Valuation).

A function σ:𝐗 is called a valuation. For all valuations σ, we define inductively the value of a level over σ, denoted as σ, with

0σ=0S()σ=S(σ)xσ=σ(x)
max(1,2)σ=max(1σ,2σ)imax(1,2)σ=imax(1σ,2σ)

This interpretation through the valuations explains why, even if levels are abstract terms, we defined them with the same symbols 0, s, max and imax that are used for the natural numbers. Indeed, the ground levels can clearly be identified as the natural numbers and the levels’ semantic, through the valuations, justifies to use the same symbol and permits to see the valuations as functions that realise levels, turning them into ground ones.

Besides, two levels can also be compared using these valuations. They are equivalent if they give the same ground levels through any valuation.

Definition 5 (Level comparison).

Let 1,2𝐋. We say that 12 if for all valuations σ, 1σ2σ. In the same way, we say that 12 if for all valuations σ, 1σ=2σ. Hence, 12 if and only if 12 and 21. And we say that 1 and 2 are incomparable if neither 12 nor 21.

This equivalence shows that universes such as Typex and Typemax(x,x) should be identified. However, it is not obvious to check. It is not syntactic, like it was without universe polymorphism, and the imax function makes it complicated.

The aim of this paper is to address this problem. Since it is a word problem, a direct solution consists in finding a canonical form and an algorithm which computes the canonical form of a given term. The level equivalence is then checked by syntactic comparison of the canonical form. We follow this path. To do this, we study the 0-imax-successor algebra, and we provide a canonical form for its terms. Besides, this equivalence is decidable by a reduction to Presburger arithmetic, and so we provide an additional motivation to our work.

Motivation

Our main motivation lies in the interoperability between proof systems. Indeed, it became a big challenge in the research on proof-checking, which aims to avoid the redevelopment of the same proof. Instead of developing translators from each system to another one, logical frameworks propose to define theories in a common language, which makes translation easier.

The λΠ-calculus modulo rewriting (λΠ/) [10] is a logical framework that extends λΠ (the simply-typed λ-calculus with dependent types) with higher-order rewrite rules [16, 29] that can be used to define functions, but also types; terms are then identified modulo β and these rewrite rules. The computational part of the type theories can then be represented using the expressiveness of rewrite systems.

The Calculus of Constructions and its subtheories can be expressed in λΠ/ [8], and, in [15], Cousineau and Dowek showed how to express some PTS. Therefore, several systems have been encoded in λΠ/: HOL-Light [30, 1], Agda [19], Matita [1], but also parts of Rocq [18, 9]. Besides, since there exist multiple implementations of λΠ/ such as Dedukti [2], Lambdapi [24], or Kontroli [17], these embeddings have been implemented, leading to effective translations [30, 21, 22].

To define CC in λΠ/, we need to define its levels. It can be done with a type nat together with functions max, and imax, and rewrite rules to define them. This permits to express CC in λΠ/, but the equivalence relation that comes with level variables adds some difficulties.

Indeed, for all term u of CC, let us note |u| its translation in λΠ/, and let us consider a function f:TypeiTypej and a term t:Typek where ki. Since ft is well-typed, then |ft| should be well-typed in λΠ/. Therefore, |t| should have the type |Typei|, whereas it has the type |Typek|. We deduce that |Typei| and |Typek| should be convertible types, and then that equivalent levels should be convertible terms.

Related Work

The 0-max-successor algebra is well-studied, and so, some solutions exist in the predicative case. In [31], Voevodsky represented each level as max(n,n1+x1,,nk+xk) where nmax(n1,,nk). Then, if there exists ij such that xj=xi, we simplify the term and keep only max(ni,nj)+xi. Therefore, we obtain a minimal representation for the 0-max-successor algebra.

In [19], Genestier encoded the universe polymorphism of Agda in λΠ/ using a similar idea and a representation modulo associativity and commutativity (for the max symbol). Blanqui gave another presentation of this algebra in [7], with an encoding without matching modulo associativity and commutativity.

The 0-imax-successor algebra is less studied. An encoding is proposed in [3], but it does not fully reflect the equalities; for instance, the levels max(imax(x,y),x) and max(x,y) are not convertible. Besides, Férey also worked on the encoding of universe polymorphism [18].

Finally, an algorithm to check level inequality, and so level equivalence, is presented in [11], but it does not rely on a canonical form.

Outline and Contributions

We use the same idea presented above in the predicative case: find a subset E of levels such that any level can be represented as maxU with UE, and such that maxU is a minimal representation that ensures uniqueness property for any other minimal representation maxV:

maxUmaxVU=V.

In the predicative case, E={n+x|n,x𝐗}; and the minimal representation consists in having one term n (the maximum of two integers can be simplified) and for all x𝐗 at most one term n+x since max(n+x,m+x)=max(n,m)+x. To obtain the canonical representation, we push the successor symbols inside the max, and we obtain maxU with UE. Then, U can be simplified by removing u if there exists vU such that vu and uv, leading to the minimal representation.

This gives us the intuition that we need. The elements of the subset should be very basic and simple in the sense that it is not equivalent to a maximum of other levels.

Section 2 studies the algebra and introduces 𝐒𝐂, a set of basic terms, called canonical sublevels. It turns out that these terms do not have the same expressive power than levels, hence we extend 𝐋 into 𝐄, the extended levels. But, each level can be represented as a maximum of elements of 𝐒𝐂; such a maximum is a representation, they will form the set of representations 𝐑.

Then, in Section 3 we introduce 𝐑𝐂, the set of minimal representations which are representations whose elements are incomparable, and we show that any representation has a unique minimal representation.

Moreover, we will see that 𝐑𝐂 is not stable by level substitution, which can generate extended levels. But, in order to have a correct translation of substitution in λΠ/, we should be able to identify |u{xv}| with |u|{x|v|}. That is why we generalize the canonical form to the extended levels in Section 4, showing that all extended levels have a minimal representation: its canonical form. Then , we present the canonization algorithm in Appendix A.

Figure 1 summarises this. Besides, the proofs of the results are given in the full version of the paper, as well as a canonization algorithm. Finally, the existence and uniqueness are also proved in Rocq since we formalised the canonization algorithm for the levels 111https://gitlab.crans.org/geran/level_formalisation.

𝐋:levels𝐄:extended levels𝐒𝐂:canonical sublevels
𝐑:representations (maximum of canonical sublevels)
𝐑𝐂:minimal representations (elements are incomparable)
Figure 1: Outline.

2 Level Representation

As said in the introduction, in this section we find a set of sublevels that fit our objective of level representation. Before that, let us introduce a basic notion that improves the readability of the text.

Definition 6.

Let u be a level and σ be a valuation. We say that u is active (under the valuation σ) if uσ0. We also say that σ activates u.

The valuation σ will often be left implicit. For instance, we can say that imax(u,v) is max(u,v) if v is active and 0 otherwise in the sense that for all valuation σ, imax(u,v)σ is max(u,v)σ if v is active under σ and 0 otherwise.

2.1 Levels as Maximum

The very first step to simplify the terms is to express any level as a maximum of levels that do not contain any max, that is the principle of our idea. The successor can be distributed over max since for all u,v𝐋, S(max(u,v))max(S(u),S(v)), and the next two observations show how to distribute imax over max.

Observation 7.

For all u,v,w𝐋,

imax(u,max(v,w))max(imax(u,v),imax(u,w)).
Observation 8.

For all u,v,w𝐋,

imax(max(u,v),w)max(imax(u,w),imax(v,w)).

Then, any level can be expressed as a maximum of levels without max. Note that for this, we consider that max takes a finite set of levels as argument. We obtain the following theorem.

Theorem 9.

For all t𝐋, there exists u1,,un in the grammar

0S()imax(,)x

such that tmax(u1,,un). Moreover, the variables that appear in u1,,un are exactly the variables that appear in t.

2.2 Simplification of the Levels

We can now focus on levels without maximum. The uniqueness property sought for the representation requires the levels to be very basic, and then we search to simplify them.

The main issue in the grammar of Theorem 9 is imax because it is asymmetric. We aim to restrict the localisation of the imax symbol to specific parts of the levels in order to understand and control their influence on the levels semantic.

Firstly, we recall some equivalences that are direct consequences of the semantics of imax. They permit to deal with 0 and the successor.

Observation 10.

For all u,v𝐋,

imax(u,0)0imax(u,S(v))max(u,S(v))

And we show how to remove imax symbol in second argument of imax.

Observation 11.

For all u,v,w𝐋,

imax(u,imax(v,w))max(imax(u,w),imax(v,w)).

Thus, by applying the simplification suggested by observations 10 and 11, we can restrict the second argument of imax to be a variable. It is more complicated for its first argument. We can simplify the level when it is 0.

Observation 12.

For all v𝐋, imax(0,v)v.

Moreover, we can distribute S over imax, but this cannot be done as directly as we distribute the S over max, as shown in the next example.

Example 13.

We consider the levels t1=S(imax(y,x)) and t2=imax(S(y),S(x)). By considering a valuation σ such that σ(x)=0 and σ(y)=1, t1σt2σ, therefore t1t2.

Besides, we can observe that S(imax(u,v)) is at least S(v), but can also be S(u) when v is active. Therefore, the simplification rule has to take into account the two relevant cases depending on the value of v.

Observation 14.

For all u,v𝐋,

S(imax(u,v))max(S(v),imax(S(u),v)).

Finally, observations 11, 10, 12, and 14 lead to this grammar restriction.

Theorem 15.

For all t𝐋, there exists u1,,un in the grammar

Sk+1(0)Sk(x)imax(,x)

such that tmax(u1,,un). Moreover, the variables that appear in u1,,un are exactly the variables that appear in t.

 Remark 16.

For all t in the grammar of Theorem 15, there exists x1,,xn𝐗, and v=Sk+1(0) or v=Sk(x) such that

t=imax(imax(imax(imax(v,x1),x2))),xn1),xn).

Such a term t will be denoted by [v,x1,,xn]. Intuitively, this term is the maximum of

  • xn,

  • xn1 if xn is active,

  • xn2 if xn and xn1 are active,

  • etc.

  • v if all the xi are active.

2.3 Introducing New Levels

Here, we continue the simplification process in order to find simple enough terms to reach the uniqueness property. Indeed, the terms of the grammar of Theorem 15 are still not simple enough.

Example 17.

Let us consider t=max(imax(x,y),x). Then, tmax(x,y).

The problem is the following: if imax(x,y) permits to take x into account if y is active, it also takes y into account in all cases. Then, it is redundant with y and lead to the equivalence imax(x,y)max(y,imax(x,y)). We would like to obtain imax(x,y)=max(y,t) with some level t, but imax(x,y) cannot be simplified more.

In fact, the second argument of imax has too many responsibilities since it should be taken into account, but it is also a condition to take into account the first argument.

The second concern leads us to devise the introduction of a term ifythenx such that ifythenxσ is 0 if yσ=0 and xσ otherwise. This permits us to simplify imax(x,y) into max(y,ifythenx), and since ifythenxx, max(y,ifythenx,x) can be turned into max(y,x).

Since, the imax functions are nested in the grammar of Theorem 15, we may need to have multiple variables as conditions; we generalize this idea of new terms and extend the level’s grammar with two symbols 𝒱 and 𝒞.

Definition 18 (Extended levels).

An extended level is a term of the grammar

0 S()max(,)imax(,)x𝒱({,,},,k)𝒞({,,},k)

where k. We extend σ and the level comparison to the extended levels with

𝒱(E,u,k)σ ={0if vE,vσ=0uσ+kotherwise.
𝒞(E,k)σ ={0if uE,uσ=0kotherwise.

We denote by 𝐄 the set of extended levels. Levels of the form 𝒱(E,u,k) or 𝒞(E,k) are called sublevels.

The symbols 𝒱 and 𝒞 stand for “variable sublevel” and “constant sublevel” in the sense that their semantic consists in taking into account a non-constant or a constant extended level u when a set of extended levels E only contain active ones.

Definition 19.

We denote by 𝐒 the set of sublevels. Let u𝐒, u=𝒱(E,v,k) or u=𝒞(E,k). We call E the verification conditions of u denoted by VC(u), and k is its constant part denoted by ω(u). We also define the variable part of u denoted by ν(u) which is 0 in the case of a constant sublevel and v in the case of a variable sublevel.

Besides, we say that a verification condition wE is checked (by a valuation σ) if wσ0 and we say that the verification condition E are checked if for all wE, wσ0.

The verification conditions and the parts of a sublevel determine its value and if it is active. Indeed, when u is active, its value is ω(u)σ+ν(u)σ. And for u to be active, the verification condition of u should be checked (otherwise the value of u is automatically 0), and on top of that ω(u)σ+ν(u)σ (which is then the value of u) should not be 0.

Proposition 20.

For all u𝐒 and for all valuations σ, uσ=ω(u)+ν(u)σ if u is active and 0 otherwise. Moreover, u is active if and only if its verifications conditions are checked and ω(u)+ν(u)σ0.

Keeping with our idea, we want to show that any level is equivalent to a maximum of sublevels, so we do it for the grammar presented in Theorem 15. Here is the intuition behind the replacement of a nested imax by a maximum of sublevels. In [Sk(y),x1,,xn],

  • xn is always considered, so we take 𝒱({},xn,0),

  • xn1 is considered if xn is active, so we take 𝒱({xn},xn1,0),

  • xn2 is considered if xn and xn1 are active, so we take 𝒱({xn,xn1},xn2,0),

  • Sk(y) is considered if all the xi are active, so we take 𝒱({xn,,x1},y,k).

The situation is similar in the case [Sk(0),x1,,xn], except that the last taken term is 𝒞({xn,,x1},k).

Proposition 21.

Let n, E={x1,,xn}𝐗, k, x0𝐗, and for all i{0,,n}, ui=𝒱({xi+1,,xn},xi,0). Then,

[Sk(x0),x1,,xn]max(𝒱(E,x0,k),u1,,un),
[Sk+1(0),x1,xn]max(𝒞(E,k+1),u1,,un).

One could note that since the grammar of 𝐄 is really permissive, for all u𝐄, we have the trivial equivalence u𝒱(,u,0) to express u as a sublevel. This shows that the sublevels are at least as expressive as the levels, but this equivalence is a nonsense in terms of level simplification. Proposition 21 is a much stronger and useful result since it states that the verification conditions and the variable part of variable sublevels can be restricted to variables to have a complete representation of levels of 𝐋. However, we made the choice of presenting extended levels without this restriction to facilitate the level instantiation (developed in Section 4). Indeed, a variable will then be replaced by any level, and we want to make this substitution transparent in our level representation.

2.4 An Appropriate Set of Sublevels

We have restrained our study to the sublevels whose verification conditions and the variable part (in the case of variable sublevels) are variables. Now, we show that some of them can be obtained as a maximum of other ones. The first restriction is related to the representation of 0. Indeed, for all E𝐗, 𝒞(E,0)0. Since we already have 0max(), we can remove all these sublevels. The second restriction is a little more subtle and is illustrated with this example.

Example 22.

With t1=𝒱(,x,0) and t2=𝒱({x},x,0), we have t1t2 since for all valuation σ, t1σ=σ(x)=t2σ.

The issue here is the fact that the variable part of a variable sublevel does not necessarily appear in its first argument. This is the key of the following equivalence.

Proposition 23.

Let x𝐗, E𝐗{x} and k. Then

𝒱(E,x,k)max(𝒱(E{x},x,k),𝒞(E,k)).

If k=0, the sublevel 𝒞(E,k) obtained with Proposition 23 is removed accordingly to the first restriction. We end up with the following set of sublevels which permits to express any level.

Definition 24 (Canonical sublevels).

A canonical sublevel is an element of the set

𝐒𝐂={𝒱(E,x,k)|E𝐗,xE}{𝒞(E,k)|E𝐗,k>0}.
Theorem 25.

Let t𝐋. Then there exists a finite U𝐒𝐂 such that tmaxU. Moreover, the variables that appear in the elements of U are exactly the variables that appear in t.

Definition 26.

Let U be a finite subset of 𝐒𝐂. We say that maxU is a representation, and we denote by 𝐑 the set of representations.

Besides, for all t𝐄, we say that maxU is a representation of t if tmaxU, and we say that the elements u of U are the elements of the representation.

The canonical sublevels correspond to the set of sublevels that we were searching for. We could try to merge the two types of sublevels by introducing a special variable 𝟏 such that for all valuation σ, σ(𝟏)=1. We can then see 𝒞(E,k+1) as 𝒱(E{𝟏},𝟏,k). This simplifies some results but makes the presentation less clear, and the distinction should still be done in a lot of cases.

 Remark 27.

Let u𝐒𝐂 and let σ be a valuation. Then u is active if and only if all its verification conditions are checked.

3 A Canonical Form for levels

The previous section defined 𝐑, the set of representations, and showed that any level is equivalent to one of its elements. The goal of this one is to show that any level has a minimal representation and that it is unique. This will be the canonical form.

Definition 28 (Minimal representation).

Let maxU𝐑. We say that maxU is minimal if and only if for all u,vU such that uv, u and v are incomparable. We denote by 𝐑𝐂 the set of the minimal representations.

By Theorem 25, any level has a representation. Since the set of representations is well-founded with the inclusion order, any level has a minimal representation. The challenging part is the uniqueness of minimal representations. To show it, we study the core of the definition of a minimal representation: the sublevel comparison.

3.1 Sublevel Comparison

The sublevels can be easily compared which is quite normal since we chose them to be very basic. To have uv, v should be active whenever u is active hence VC(v)VC(u). And when they are both active, the value of v should be greater than the one of u.

With two variable sublevels it means that their variable part is the same or else we can set a very large value to ν(u) in order to falsify the inequality. This also explains that we cannot have 𝒱(E,x,l)𝒞(F,k). And if u is a constant sublevel and v a variable sublevel, we should remember that when they are active, ν(v) is active (because it is included in VC(v)) and then ω(u)ω(v)+1 suffices.

Theorem 29 (Sublevels comparison).

The following equivalences permit to compare elements of 𝐒𝐂.

𝒱(E,x,l)⩽̸𝒞(F,k) (1)
𝒞(E,l)𝒞(F,k)FElk (2)
𝒞(E,l)𝒱(F,x,k)(FElk+1) (3)
𝒱(E,x,l)𝒱(F,y,k)FEx=ylk (4)

As a corollary, we get that the sublevel equivalence is a syntactic equality, which is expected to ease uniqueness.

Corollary 30.

Let t1,t2𝐒𝐂. Then t1t2t1=t2.

Figure 2 illustrates the comparison of the canonical sublevels on the set of variables {x,y} and with 0 or 1 as constant part. We see that we get a greater sublevel by increasing the constant part, reducing the set of verification conditions, or moving to a variable sublevel (in that case, the constant part can be reduced by one).

Figure 2: Sublevel comparison on {x,y}.

3.2 The Uniqueness Property

Now, we can show the uniqueness property. We have to show that two equivalent minimal representations maxU and maxV have the same sublevels. Here, we show a slightly different proof. It is more elegant, and it emphasises the property that ensures the uniqueness.

We will show that umaxV implies the existence of vV such that uv. This statement lead to the uniqueness property. Indeed, if maxU and maxV are two equivalent minimal representation, then for all uU there exists a vV such that uv, and similarly there exists uU such that vu. Minimality of maxU permits to conclude that u=u, and then uv and finally u=v by comparison of canonical sublevels.

To prove this statement, the idea is to find, for any sublevel u, a valuation σ such that the only way to have uσVσ is to have vV with uv. Such a valuation should only activate the verification condition of u. Moreover, uσ should be large enough to overtake the other sublevels of the representation. When u is a variable sublevel, it means to set its variable part to a large number.

Definition 31.

Let u𝐒𝐂 be a constant sublevel and V𝐒𝐂 be a set of canonical sublevel. The V-minimal over-valuation of u is the valuation defined by

σ(x)={0if xVC(u)1if xVC(u).
Definition 32.

Let u𝐒𝐂 be a variable sublevel and V𝐒𝐂 be a set of canonical sublevel. The V-minimal over-valuation of u is the valuation defined by

σ(x)={0if xVC(u)1if xVC(u)ν(u)2+max{ω(v)|vV}otherwise.
Proposition 33.

Let u𝐒𝐂 be a variable sublevel, V𝐒𝐂 be a set of canonical sublevel and σ be the V-minimal over-valuation of u. We have

uσmaxVσvV,uv.

This proposition is fundamental for the following theorem.

Theorem 34.

For all u𝐒𝐂 and maxV𝐑, umaxV if and only if there exists vV such that uv.

And we obtain that equivalence of minimal representations is set equality.

Proposition 35.

For all maxU,maxV𝐑𝐂, maxUmaxVU=V.

Finally, we obtain the main theorem: the existence and uniqueness of a minimal representation for each level, that is to say a canonical form. First, we show the intuitive property that the minimal representation of a maximum of sublevels is formed with some of them.

Proposition 36.

For all maxU𝐑, there exists a unique maxV𝐑𝐂 such that maxUmaxV. Moreover, V is a subset of U.

Theorem 37 (Minimal Representation).

For all t𝐋, there exists a unique maxU𝐑𝐂 such that tmaxU. We say that maxU is the canonical form of t.

This theorem states the existence of a canonical form function c for 𝐋, c being the function that associates any level to its minimal representation.

 Remark 38.

The key point of this result is Theorem 34. It should be understood as an independence property. Indeed, if we consider max(u1,,un) as a linear combination of u1,,un, then this theorem states that the only way to be smaller than a linear combination is to depend on and be smaller than one of the elements of this combination.

This analogy provides a new point of view on our work: 𝐒𝐂 is a “linearly independent” family (uniqueness of the minimal representation) which generates all the levels through “linear combinations”.

Moreover, Theorem 34 provides a method to compare two levels, by comparing each sublevel of the minimal representation of the first one to the second one. More generally, two representations are compared in the following way.

Theorem 39.

For all maxU,maxV𝐑, maxUmaxV if and only if for all uU, there exists vV such that uv.

4 A Canonical Form for Extended Levels

We are now interested in extending the representation theorem to the whole grammar of extended levels in order to have substitution. Indeed, if u=max(𝒱({x},x,0)) (the canonical form of x), then

v=u{xmax(y,1)}=max(𝒱({max(y,1)},max(y,1),0))

is not a representation. Since 𝐋 is stable by substitution, u{xmax(y,1)} is a level and then v has a minimal representation (which is max(𝒱({y},y,0),𝒞(,1))).

Here, we provide a way to find this representation by extending the representation to all extended levels, showing that they have representations.

Theorem 40.

For all u𝐄, there exists maxV𝐑 such that umaxV.

 Remark 41.

One could think that we do not have to deal with S and imax because we know that the successor and imax of representations are representations. But we do not yet have this result ; we only know that it is true for representations of levels (because levels can be represented). Moreover, the development of this section will be helpful to develop a recursive canonization algorithm.

4.1 The Successor

In order to define the successor of a canonical sublevel in terms of representation, we define inc:𝐒𝐂𝐒𝐂 such that for all E𝐗,k>0, inc(𝒞(E,k))=𝒞(E,k+1) and for all E𝐗,xE,k>0, inc(𝒱(E,x,k))=𝒱(E,x,k+1). This function nearly increments a canonical sublevel but does not fulfil that objective when some elements of E are not active (it will give 0 instead of 1). That’s why we take it in combination with 𝒞(,1) which is 1.

Proposition 42.

For all u𝐒𝐂,

S(u)max(inc(u),𝒞(,1)).

We immediately deduce the following result.

Proposition 43.

Let maxU𝐑. Then,

S(maxU)max{inc(u)|uU}{𝒞(,1)}.

4.2 The Impredicative Maximum

Following the equivalences imax(0,u)u and imax(u,0)0, and observations 7 and 8, we have the following equivalence.

Proposition 44.

Let maxU,maxV𝐑𝐂. We have

imax(maxU,maxV){max()0if V=maxVif U=maxuUvVimax(u,v)else. (5)

Then, it is sufficient to show that for all u,v𝐒𝐂, imax(u,v) has a representation. We will then obtain a representation of imax(maxU,maxV) by taking the elements of the ones of imax(u,v) for all uU and vV.

Proposition 45.

Let v𝐒𝐂, E𝐗, xE and k. Then,

imax(𝒞(E,k+1),v)max(𝒞(EVC(v),k+1),v)
imax(𝒱(E,x,k),v)max(𝒱(EVC(v),x,k),v)

4.3 The Sublevels

We now assume that the verification conditions of a sublevel are representations and that its variable part, in the case of a variable sublevel is a representation as well. First, we show how to transform a sublevel t into a maximum of sublevels whose verifications conditions are variable.

For the sublevel to be active, all its verification conditions should be checked. Since these verification conditions are representations, it means that each of them have an active sublevel. Then, we have to consider all the combinations obtained by taking one sublevel for each verification condition of t. Moreover, a sublevel is active when its verifications conditions are all checked. Then, we have to consider all the combinations of verification conditions of the verification conditions of t.

Definition 46.

For all t,u1,,un𝐒𝐂, we define

P(t,u1,,un)={𝒞(0inVC(ui),ω(t))if t is a constant sublevel𝒱(0inVC(ui),ν(t),ω(t))else.

The term P(t,u1,,un) means that if u1,,un are checked, then we can take into account the value of the sublevel that we want to simplify (which is then ν(t)+ω(t)). Then, we consider such terms when ui,,un are a combination of verification conditions taken from each verification conditions of t. This leads to sublevels whose verification conditions are variables.

Proposition 47.

Let maxU1,,maxUn𝐑 and t be a sublevel whose verifications conditions are maxU1,,maxUn. Then

tmax{P(t,u1,,un)|u1U1,,unUn}.
 Remark 48.

It is important to have maxU1,,maxUn𝐑 and not only maximum of (possibly not canonical) sublevels. Indeed, we use the fact that u𝐒𝐂 is active if and only if all its verification conditions are checked (Remark 27), which is not always true with non-canonical sublevels. Moreover, note that the result still holds if there exists an i such that Ui=, since both terms are equivalent to 0.

The Constant Sublevels

With Proposition 47, we have shown how to transform a constant sublevel u whose verification conditions are representations into a representation. Indeed, in the constant sublevel case, for all u1,,un𝐒𝐂, P(u1,,un)𝐒𝐂 if k>0 (hence we obtain a representation of t). Besides, if k=0, a representation of t is max.

The Variable Sublevels

However, in the variable sublevels, it is not the case; Proposition 47 only permits us to obtain variable sublevels where the verification conditions are variables. Besides, the variable part of P(u1,,un) is not necessarily a variable. That is why we have to take care of the variable part of variable sublevels.

In t=𝒱(V,U,k) with V𝐄 and U𝐑, the value of t when it is activated by σ is the maximum of the value of uσ+k with uU. Therefore, t can be easily split into a maximum.

Proposition 49.

Let maxU𝐑,V𝐄, and k. Then,

𝒱(V,maxU,k)max{𝒱(V,u,k)|uU}.

So, it results in sublevels as variable part of variable sublevels, and we handle these in the next proposition.

To transform the 𝒱(V,u,k) obtained with Proposition 49 into a canonical sublevel, we note that its value can be 0, or k, or ν(u)+ω(u)+k. Then, we need a canonical sublevel with ω(u)+k as constant part, and ν(u) as variable part (we will get a constant or a variable sublevel depending on the nature of its variable part ν(u)). Besides, u has to be active to obtain the value ν(u)+ω(u)+k, then the verification conditions of u have to be verification conditions of the targeted sublevel. However, when u is not active, 𝒱(V,u,k) is not necessarily evaluated to 0 since it can also be evaluated to k when V are checked. Therefore, we add a second sublevel 𝒞(V,k) to keep this behaviour.

Proposition 50.

Let V𝐄, u𝐒, and k. We note

f(u)={𝒞(VVC(u),k+ω(u))if u is a constant sublevel𝒱(VVC(u){u},ν(u),k+ω(u))else

Then 𝒱(V,u,k)max(𝒞(V,k),f(u)).

Note that when u𝐒𝐂, having VC(u) as verification conditions is equivalent to having u as verification condition which simplifies f(u) in the case where u is a variable sublevel.

We can apply these two propositions to the P(u1,,un) from Definition 46. For that, we define the following.

Definition 51.

Let k. For all v,u1,,un𝐒𝐂, we define (by noting u0=v),

f(v,u1,,un)={𝒞(0inVC(ui),k+ω(v))if v is a constant sublevel𝒱(0inVC(ui),ν(v),k+ω(v))else

and

Q(v,u1,,un)=max(𝒞(1inVC(ui),k),f(v,u1,,un)).

Here, f(v,u1,,un), corresponds to the case where all the verification conditions u1,,un are checked and v is active and 𝒞(1inVC(ui),k) corresponds to the case where u1,,un are checked but v is not active, hence they form Q(v,u1,,un). Finally, we get the following proposition.

Proposition 52.

Let k, maxU1,,maxUn𝐑, maxV𝐑, and let t be the variable sublevel 𝒱({maxU1,,maxUn},maxV,k). Then,

tmax{Q(v,u1,,un)|u1U1,,unUn,vV}
 Remark 53.

As for the constant sublevels case, we should take care to consider the sublevel f(u1,,un) only if its constant part is not 0. Otherwise, it is equivalent to 0, and it has to be removed from the max if you want a canonical form.

Besides, one could think that we should have the same consideration with the sublevel g(v,u1,,un) (whose constant part is k+ω(v)) when v is a constant sublevel, but since v𝐒𝐂 (because it is an element of a representation), then ω(v)>0.

After that, the case of the variable sublevel is solved. We have proved all the induction cases, which terminates the proof of Theorem 40.

General Representation Theorem

By Theorem 40 any level has a representation, and therefore a minimal one by Proposition 36.

Theorem 54.

For all u𝐄, there exists a unique v𝐑𝐂 such that uv.

With Theorem 54, we have shown that 𝐑𝐂 is as expressive as 𝐄 whereas 𝐑𝐂𝐄. To finish this section, we compare the expressiveness of the different shape of levels.

If 𝐋 is semantically, and even syntactically, a subset of 𝐄, one could note that some extended levels are not equivalent to any level. In fact, even some canonical sublevels are not equivalent to any level. For instance, for all x𝐗, there is no u𝐋 such that u𝒞({x},1).

In the same way we show that some levels are not expressible with just one canonical level. For instance, for all x,y𝐗, there is no u𝐒𝐂 such that umax(x,y).

We end up with the inclusion Hasse diagram displayed in Figure 3.

Figure 3: Hierarchy of levels.

5 Conclusion

We studied the 0-imax-successor and introduced a canonical form for its terms, which gives us an easy procedure decision for the equivalence problem. For that, we extended the grammar with new terms called sublevels, and we expressed any term as a maximum of sublevels, what we have called a representation. Since not all representations are actually terms of the algebra, a next step could be to characterize the representations that are. This could lead to an even better understanding of the 0-imax-successor algebra.

We only provide a naive canonization algorithm since level expressions are usually quite small. However, searching for a better algorithm and a good data structures for representations could be useful.

Finally, this representation can be expressed in λΠ/ with rewrite rules, which is our initial motivation, and it is used in a Work In Progress translator from Lean to Dedukti showing that it can indeed be used to express CC in λΠ/. The next step here, is to study how the expression of universe polymorphism, thanks to this level representation, behaves well together with other features such as inductive types or cumulativity.

References

  • [1] Ali Assaf. A framework for defining computational higher-order logics. Theses, École polytechnique, September 2015. URL: https://pastel.archives-ouvertes.fr/tel-01235303.
  • [2] Ali Assaf, Guillaume Burel, Raphaël Cauderlier, David Delahaye, Gilles Dowek, Catherine Dubois, Frédéric Gilbert, Pierre Halmagrand, Olivier Hermant, and Ronan Saillard. Dedukti : a Logical Framework based on the λΠ-Calculus Modulo Theory, 2016.
  • [3] Ali Assaf, Gilles Dowek, Jean-Pierre Jouannaud, and Jiaxiang Liu. Encoding Proofs in Dedukti: the case of Coq proofs. In Proceedings Hammers for Type Theories, Proc. Higher-Order rewriting Workshop, Coimbra, Portugal, July 2016. Easy Chair. URL: https://inria.hal.science/hal-01330980.
  • [4] Henk Barendregt. Introduction to generalized type systems. Journal of Functional Programming, 1(2):125–154, 1991. doi:10.1017/S0956796800020025.
  • [5] Henk Barendregt, S. Abramsky, D. Gabbay, T. Maibaum, and Henk (Hendrik) Barendregt. Lambda Calculi with Types, 2000.
  • [6] Stefano Berardi. Type dependence and Constructive mathematics. PhD thesis, PhD thesis, Dipartimento di Informatica, Torino, Italy, 1990.
  • [7] Frédéric Blanqui. Encoding Type Universes Without Using Matching Modulo Associativity and Commutativity. In Amy P. Felty, editor, 7th International Conference on Formal Structures for Computation and Deduction (FSCD 2022), volume 228 of Leibniz International Proceedings in Informatics (LIPIcs), pages 24:1–24:14, Dagstuhl, Germany, 2022. Schloss Dagstuhl – Leibniz-Zentrum für Informatik. doi:10.4230/LIPIcs.FSCD.2022.24.
  • [8] Frédéric Blanqui, Gilles Dowek, Émilie Grienenberger, Gabriel Hondet, and François Thiré. Some Axioms for Mathematics. In Naoki Kobayashi, editor, 6th International Conference on Formal Structures for Computation and Deduction (FSCD 2021), volume 195 of Leibniz International Proceedings in Informatics (LIPIcs), pages 20:1–20:19, Dagstuhl, Germany, 2021. Schloss Dagstuhl – Leibniz-Zentrum für Informatik. doi:10.4230/LIPIcs.FSCD.2021.20.
  • [9] Mathieu Boespflug and Guillaume Burel. CoqInE: Translating the Calculus of Inductive Constructions into the λΠ-calculus Modulo. In "Second International Workshop on Proof Exchange for Theorem Proving, 2012.
  • [10] Mathieu Boespflug, Quentin Carbonneaux, and Olivier Hermant. The λΠ-calculus Modulo as a Universal Proof Language. CEUR Workshop Proceedings, 878, June 2012. URL: https://ceur-ws.org/Vol-878/paper2.pdf.
  • [11] Mario Carneiro. The Type Theory of Lean. Master’s thesis, Carnegie Mellon University, 2019. URL: https://github.com/digama0/lean-type-theory/releases.
  • [12] Thierry Coquand. An Analysis of Girard’s Paradox. In Proceedings of the First Annual IEEE Symposium on Logic in Computer Science (LICS 1986), pages 227–236. IEEE Computer Society Press, June 1986.
  • [13] Thierry Coquand and Gérard Huet. The calculus of constructions. Information and Computation, 76(2):95–120, 1988. doi:10.1016/0890-5401(88)90005-3.
  • [14] Judicaël Courant. Explicit Universes for the Calculus of Constructions. In Victor A. Carreño, César A. Muñoz, and Sofiène Tahar, editors, Theorem Proving in Higher Order Logics, pages 115–130, Berlin, Heidelberg, 2002. Springer Berlin Heidelberg. doi:10.1007/3-540-45685-6_9.
  • [15] Denis Cousineau and Gilles Dowek. Embedding Pure Type Systems in the Lambda-Pi-Calculus Modulo. In Typed Lambda Calculi and Applications, 8th International Conference, TLCA 2007, Paris, France, June 26-28, 2007, Proceedings, pages 102–117, June 2007. doi:10.1007/978-3-540-73228-0_9.
  • [16] Nachum Dershowitz and Jean-Pierre Jouannaud. Rewrite Systems. In Jan van Leeuwen, editor, Handbook of Theoretical Computer Science, Volume B: Formal Models and Semantics, pages 243–320. Elsevier and MIT Press, 1990. doi:10.1016/b978-0-444-88074-1.50011-1.
  • [17] Michael Färber. Safe, Fast, Concurrent Proof Checking for the Lambda-Pi Calculus modulo Rewriting. In Proceedings of the 11th ACM SIGPLAN International Conference on Certified Programs and Proofs, CPP 2022, pages 225–238, New York, NY, USA, 2022. Association for Computing Machinery. doi:10.1145/3497775.3503683.
  • [18] Gaspard Férey. Higher-Order Confluence and Universe Embedding in the Logical Framework. (Confluence d’ordre supérieur et encodage d’univers dans le Logical Framework). PhD thesis, École normale supérieure Paris-Saclay, France, 2021. URL: https://lmf.cnrs.fr/downloads/Perso/Ferey-thesis.pdf.
  • [19] Guillaume Genestier. Encoding Agda Programs Using Rewriting. In Zena M. Ariola, editor, 5th International Conference on Formal Structures for Computation and Deduction (FSCD 2020), volume 167 of Leibniz International Proceedings in Informatics (LIPIcs), pages 31:1–31:17, Dagstuhl, Germany, 2020. Schloss Dagstuhl – Leibniz-Zentrum für Informatik. doi:10.4230/LIPIcs.FSCD.2020.31.
  • [20] Girard, Jean-Yves. Interprétation fonctionnelle et élimination des coupures dans l’arithmétique d’ordre supérieur, 1972.
  • [21] Yoan Géran. Mathématiques inversées de Coq. Master’s thesis, ENS Paris-Saclay, September 2021. URL: https://inria.hal.science/hal-04319183.
  • [22] Yoan Géran. STT GeoCoq, 2021. URL: https://github.com/Karnaj/sttfa_geocoq_euclid.
  • [23] Robert Harper and Robert Pollack. Type Checking with Universes. In 2nd International Joint Conference on Theory and Practice of Software Development, TAPSOFT ’89, pages 107–136, NLD, 1991. Elsevier Science Publishers B. V. doi:10.1016/0304-3975(90)90108-T.
  • [24] Gabriel Hondet and Frédéric Blanqui. The New Rewriting Engine of Dedukti (System Description). In Zena M. Ariola, editor, 5th International Conference on Formal Structures for Computation and Deduction (FSCD 2020), volume 167 of Leibniz International Proceedings in Informatics (LIPIcs), pages 35:1–35:16, Dagstuhl, Germany, 2020. Schloss Dagstuhl – Leibniz-Zentrum für Informatik. doi:10.4230/LIPIcs.FSCD.2020.35.
  • [25] Per Martin-Löf. A theory of types, 1971. Preprint, Stockholm University.
  • [26] Per Martin-Löf. An Intuitionistic Theory of Types: Predicative Part. Studies in logic and the foundations of mathematics, 80:73–118, 1975.
  • [27] Per Martin-Löf. An intuitionistic theory of types. In Giovanni Sambin and Jan M. Smith, editors, Twenty-five years of constructive type theory (Venice, 1995), volume 36 of Oxford Logic Guides, pages 127–172. Oxford University Press, 1998.
  • [28] Matthieu Sozeau and Nicolas Tabareau. Universe Polymorphism in Coq. In Gerwin Klein and Ruben Gamboa, editors, Interactive Theorem Proving, pages 499–514, Cham, 2014. Springer International Publishing. doi:10.1007/978-3-319-08970-6_32.
  • [29] Terese. Term rewriting systems, volume 55 of Cambridge tracts in theoretical computer science. Cambridge University Press, 2003.
  • [30] François Thiré. Sharing a Library between Proof Assistants: Reaching out to the HOL Family. In Frédéric Blanqui and Giselle Reis, editors, Proceedings of the 13th International Workshop on Logical Frameworks and Meta-Languages: Theory and Practice, LFMTP@FSCD 2018, Oxford, UK, 7th July 2018, volume 274 of EPTCS, pages 57–71, 2018. doi:10.4204/EPTCS.274.5.
  • [31] Vladimir Voevodsky. A universe polymorphic type system, October 2014. An unfinished unreleased manuscript. URL: https://www.math.ias.edu/Voevodsky/files/files-annotated/Dropbox/Unfinished_papers/Type_systems/UPTS_current/Universe_polymorphic_type_sytem.pdf.

Appendix A Computation Algorithm

We design a recursive algorithm suited to the inductive structure of 𝐄. It is presented in Algorithm 1 which already contains the code for the base cases 0 and x for which the canonical form are respectively max() and max(𝒱({x},x,0)).

Algorithm 1 Canonization algorithm.

We are now interested in the code to compute the canonical form in the other cases. The algorithm follows the induction performed in Section 4 to prove Theorem 54 since it gives us a representation for the different shapes of levels. Then, it is sufficient to minimize this representation to stick to Proposition 36. For that, we write Algorithm 2 which inserts a sublevel in an independent set of canonical sublevels.

Algorithm 2 Insertion algorithm.

The Maximum

To compute the canonical form of max(u,v), we use Algorithm 2 to insert the sublevels of v into the ones of u.

Algorithm 3 Case of the maximum.

The Successor

Thanks to Proposition 42, for all maxU𝐑𝐂, we know a representation of S(maxU). To obtain its canonical form, we could use insert to add its sublevels to an initially empty set. But, we have a simpler operation.

Proposition 55.

Let maxU𝐑𝐂 and E={inc(u)|uU}.

c(S(maxU))={maxEif uU,VC(u)=maxE{𝒞(,1)}else

We implement this strategy in Algorithm 4.

Algorithm 4 Case of the successor.

The Impredicative Maximum

For all u,v𝐒𝐂, Proposition 45 expresses imax(u,v) as a maximum of canonical sublevels, and for all maxU,maxV𝐑𝐂, Proposition 44 expresses imax(maxU,maxV) as a maximum of imax(u,v) with uU and vV (hence u,v𝐒𝐂). Using these two results, we design Algorithm 5.

Algorithm 5 Case of the impredicative maximum.

The Constant Sublevels

The computation of the canonical form of a constant sublevel relies on Proposition 47. Here, we immediately returns max() if some VC is 0, and we do not forget the case k=0 which results in 0.

Algorithm 6 Case of the constant sublevels.

The Variable Sublevels

The case of the variable sublevel is very similar and relies on Proposition 52.

Algorithm 7 Case of the variable sublevels.
Theorem 56 (Correction).

Let u𝐄. Then, normalize(u) computes c(u), the canonical form of u.