Higher-Order Rewriting with Dependent Types

Roberto Virga October 20, 1999

CMU-CS-99-167

School of Computer Science Carnegie Mellon University

Pittsburgh, PA 15213

Submitted in partial fulfillment of the requirements

for the degree of Doctor of Philosophy in the Department of Mathematical Sciences

Thesis Commitee: Frank Pfenning, Chair

Peter Andrews Robert Harper Richard Statman

Copyright \begin{matrix}c \\ ◯ \end{matrix} 1999 Roberto Virga

This research was sponsored in part by NSF Grant CCR-9619584 The views and conclusions contained in this document are those of the author and should not be interpreted as

representing the official policies, either expressed or implied, of NSF or the U.S. government

Keywords: meta logic, logical frameworks, lambda calculus, type theory, rewriting, equational logic

Abstract

Higher-order, typed logic programming languages such as lambda-Prolog and Twelf have emerged in this last decade as the solution to many of the shortcomings of first-order languages like Prolog. A stronglytyped system allows early detection of many common programming mistakes, and it accounts for smaller and faster runtime environments. Lambda abstraction provides proper representation to the concept of bound variable, ubiquitous in mathematics. Because of these features, these languages have found in the last few years applications in several interesting areas, such as security protocols for mobile code. Unfortunately, use of these tools also evidenced a few problems in these languages, mostly due to the inadequate representation of equality that they offer. Early development of Prolog faced similar problems, which were ultimately tackled through two different approaches. Both of these founded their roots in the theory of Term Rewriting Systems, but evolved along quite different paths. Constraint Logic Programming extended Prolog by integrating decision procedures for specific theories to the inference engine. Rewriting Logic offered a new approach to logic programming, where term rewriting, rather than proof search, was used as model of computation. We believe that the development of higher-order languages, in order to address their current inadequacies, should evolve along similar paths. For this reason, we study in this dissertation a theory of Higher-order Term Rewriting for the LF calculus, on which Twelf is based. The results presented here can be divided in two parts. In the first part,we analyze an extension to LF where types can also be converted modulo an equational theory. As the LF calculus is very sensitive to changes in the type conversion relation used, all the confluence properties of β-reduction and (restricted) η-expansion, and existence of normal forms have to re-examined. We show that our extension is conservative, and all the usual properties continue to hold, albeit in a weaker form. In the second part, we proceed in defining a notion of rewriting. Since in a dependently typed calculus terms are allowed to appear inside types, a naive definition, extending the one given by Nipkow for simply typed calculi, is inapplicable, as it may lead to situations where rewriting invalidates the type of an expression. Hence, we turn our attention to the study of special preorders, called dependence relations, that allow us to extract type information that is implicit in a LF signature, and use it to restrict rewriting to well-behaved instances. Dependence relations turn out also to be useful when studying confluence of rewriting, which, as usual, can be reduced to checking some special rewriting configurations known as critical pairs. Together with a general Critical Pair Criterion, we present a specialized version, where fewer critical pairs need to be checked thanks to the type information conveyed by these preorders. A few examples conclude the presentation, demonstrating some of the potential of the concepts introduced. We present applications to Milner’s Action and Process Calculi, Category Theory, and Proof Theory.

Acknowledgments

First and foremost, I would like to thank my advisor, Frank Pfenning, for his guidance, support, and encouragement during the development of this thesis. I feel I have matured during my stay here at Carnegie Mellon, both as a researcher and as a person, and much of this I owe to him.

I am also grateful to the other members of my thesis committee. To Rick Statman, who first introduced me to the fascinating subject of the lambda calculus. To Bob Harper, whose courses helped me get a better insight of the techniques and the ideas involved in the design and implementation of programming languages. To Peter Andrews, who taught me the importance of rigor and precision in doing mathematics.

I am thankful to all the professors and researchers who participate to the interdisciplinary program of Pure and Applied Logic. I’ve benefited a lot from this program, which, through their enthusiasm and dedication, keeps being one of the best offered in this country. Of particular mention here are Rami Grossberg, the aforementioned Peter Andrews, and Wilfried Sieg who, through frequently offered logic seminars, constantly stimulate independent research and exchange of ideas.

One big thanks goes to Carsten Schürmann and Alberto Momigliano, who have always been invaluable friends, as well as the source of many useful suggestions in writing this thesis.

Last, but certainly not least, I am grateful to my family, who waited patiently to see this work completed. I would also like to remember my grandmother, who I’m sure would be very happy for me right now; although she is not not with me in person, she is in spirit, as she’ll always have a special place in my heart. ii

Contents

Acknowledgments i

1 Introduction 1 1.1 Historical Background and Motivations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1.2 Some Preliminary Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 1.3 Outline of This Dissertation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

I Equational LF 7

2 Preliminaries 9 2.1 Equational LF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 2.2 Basic Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 2.3 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

3 Properties of β-Reduction 19 3.1 Marked LF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 3.2 Correspondence with the Unmarked Version . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 3.3 Behavior of β-Reduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 3.4 An Important Term Ordering Lemma . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 3.5 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31

4 Properties of η-Expansion 33 4.1 Canonical Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 4.2 Normality of Canonical Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 4.3 λ-Equivalence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 4.4 Confluence Modulo ≈ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 4.5 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51

II Rewriting 53

5 Dependence Relations 55 5.1 Main Ideas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 5.2 General Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 5.3 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59

6 Rewriting 61 6.1 Environments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 6.2 Rewriting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 6.3 Canonical Rewriting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 6.4 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 7 Confluence for Simpler Equational Theories 75

7.1 Simpler Equational Theories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 7.2 Generalized Patterns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 7.3 Confluence for Simpler Equational Theories . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80 7.4 Internal Rewriting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 7.5 Completion by Stages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 7.6 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90

8 Confluence for General Equational Theories 91 8.1 One-Step E-Conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 8.2 Canonical One-Step E-Conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 8.3 Confluence for General Equational Theories . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 8.4 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105

9 Directions of Future Research 107 9.1 Implementations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 9.2 Other Confluence Criteria . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 9.3 Narrowing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 9.4 Termination . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108

III Applications 109

10 A Change in Notation 111 10.1 Twelf Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111

11 Applications: Concurrent Processes 113 11.1 Action Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 11.2 Action structures for CCS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115 11.3 Process Calculus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116

12 Applications: Categories 119 12.1 Categories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 12.2 Functors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 12.3 Natural Transformations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 12.4 Adjunctions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122

13 Intuitionistic Natural Deduction and Sequent Calculus 125 13.1 Natural Deduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 13.2 Sequent Calculus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126 13.3 From Natural Deduction to Sequent Calculus . . . . . . . . . . . . . . . . . . . . . . . . . . . 128 13.4 From Sequent Calculus to Natural Deduction . . . . . . . . . . . . . . . . . . . . . . . . . . . 131 13.5 Cut Elimination . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133

List of Figures

1.1 List Concatenation - Equational . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 1.2 List Concatenation - Non-Equational Version . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 1.3 The Rewrite System SUBST . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 1.4 Adding a Terminal Object to SUBST . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

2.1 Typing Rules for the LF Calculus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

3.1 Typing Rules for the Marked LF Calculus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 3.2 Erasure Map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 3.3 The Type Embedding τ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 3.4 The Object Embedding | · | . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

4.1 Canonical and Atomic Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 4.2 Rules for η-Expansion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 4.3 Rules for E′λ-Equivalence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41

5.1 Even Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56

6.1 Environments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62

8.1 One-step E-conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92

10.1 Twelf/LF Syntax Conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 10.2 Signature and HTRS (New Notation) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112 10.3 Signature (Old Notation) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112

13.1 A Signature for Propositional Formulas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126 13.2 Natural Deduction Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127 13.3 Signature for Natural Deduction Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127 13.4 Sequent Calculus Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129 13.5 Signature for Sequent Calculus Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 13.6 Natural Deduction to Sequent Calculus HTRS . . . . . . . . . . . . . . . . . . . . . . . . . . 132 13.7 Sequent Calculus to Natural Deduction HTRS . . . . . . . . . . . . . . . . . . . . . . . . . . 133 13.8 Cut Elimination for Non-Initial Derivations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134 13.9 Cut Elimination - Initial Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136 13.10Cut Elimination - Essential Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136 13.11Cut Elimination - Left-commutative Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136 13.12Cut Elimination - Right-commutative Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 vi

Chapter 1

Introduction

1.1 Historical Background and Motivations

Mathematical logic is often the result of the synergistic combination of two distinct techniques: computation and deduction. Computation involves the symbolic manipulation of expressions, which are transformed according to some specified equivalences. Deduction is the process of deriving logical consequences from a set of initial postulates called axioms, through the application of some fixed rules of inference.

To see how these two processes interact, consider the following example. We define even numbers as integers that are multiples of two; this is formalized by the single axiom

∀n ∈ ℤ. even (2 · n)

Logical rules allow us to specialize this general statement to, say, the case n = 5:

\frac{∀n ∈ ℤ. even (2 · n)}{even (2 · 5)}

This gets us a proof that (2 · 5) is even; computing this latter expression, we conclude that 10 is even.

Unfortunately, early attempts to apply the principles of mathematical logic to programming language design failed to realize the importance of both processes, and leaned in favor of a purely deductive approach. Probably the most important byproduct of these attempts is the Prolog language [69], which based its syntax on a subset of prefix-quantified first-order logic (Horn clauses), and its semantics on depth-first proof search. As efficient compilation techniques emerged [73], and Prolog could finally be tested on real-life applications, some of the limitations of its design clearly emerged. Upon closer inspection, most of these drawbacks can be traced back, as expected, to the inadequate treatment of the equality predicate that the language provides. Integer and floating-point arithmetic, an essential feature in any general-purpose language, did not fit in the operational semantic of pure Prolog, and had to be implemented as extra-logical constructs. Also, the inability to treat cases of “don’t care” non-determinism (any choice leads to success, and therefore one can be picked at random) any differently from cases of “don’t know” non-determinism (only some of the possible choices lead to success, and backtrack points have to be introduced) made it difficult for programmers to generate efficient code, and motivated the introduction of yet another extra-logical construct (cut).

The proliferation of such extra-logical extensions led researchers to the search for paradigms that, while addressing these shortcomings, had a more logical underpinning, and therefore could be studied formally. Such search unfolded in all directions, concluding in two very different solutions.

The first, Constraint Logic Programming [15, 32], was evolutional, as it extended Prolog operational semantic rather than subverting it. Decision procedures for specific domains (e.g. floating-point numbers, sets, strings) were added to the Prolog engine in order to solve many commonly encountered equations. “Hard” equations, which could not be handled by these procedures, were deferred as constraints until they could be furtherly simplified. A natural evolution of this approach can be seen in Frühwirth’s Constraint Handling Rules (CHR) [18], that generalize this type of Prolog extensions by providing a general language for the manipulation of user-definable constraints. This language is based on conditional rewriting, and non-determinism stemming from the simultaneous applicability of more than one rule is resolved in a “don’t care” fashion.

Another approach was more revolutionary in nature, as it tried to look at the problem of using logic as a foundation of a programming language from a fresh new perspective. This led to Rewriting Logic [40], where the operational semantics of the language was chosen to be term rewriting rather than proof search. Many advantages stem from such choice: arithmetic and other equational theories are elegantly handled; the possibility of specifying different reduction strategies give the user more control over how non-deterministic choices are resolved during program execution.

Concurrently to these activities, the ground-breaking work of Martin Löf on constructive type theory [41, 42] influenced the development of many systems based on higher-order logic and type theory, with applications to several fields of computer science, from program synthesis [38, 11, 16] to automated theorem proving [57].

Martin Löf’s ideas eventually made their way into logic programming, producing a new generation of typed, higher-order languages, which finds its most illustrious representatives in lambda-Prolog [46] and Twelf [63]. These offer several advantages over their first-order counterparts. The use of a type system makes the task of isolating meaningless expressions easier, and therefore leads to earlier detection of many common programming mistakes. Lambda-abstraction provides a convenient way to represent the notion of bound variable, that is used pervasively in mathematics. Built-in β-reduction offers a computational component in an otherwise purely deductive programming paradigm.

In recent years, as implementations of these languages have matured, their full potential is finally beginning to be explored. This has brought applications of extreme significance; of these, we briefly describe here Necula’s proof-carrying code technique [51]. The main idea of this technique is to endow compiled code with a proof of its correctness. In a mobile code environment, where a program (applet) residing on a server is transmitted to a client for execution, carrying along these proofs in the transmission bears several advantages. On the one hand, it provides security, since the the proof and the code can be checked against each other, to make sure that the latter has not been tampered with. On the other hand, it translates into better performance, since proofs ensure that the code is well-behaved, making it unnecessary for it to be run in a secure environment (sandbox). The meta-representational capabilities of Twelf made it the ideal language to write these proofs in.

However, if this application outlined the strengths of the language, it also pointed out one of its weaknesses. Often, correctness proofs rely on equational properties about the machine data types (e.g. integers, floating-point numbers, booleans, strings). Since Twelf, like its first-order ancestor Prolog, does not provide primitives to deal with equality, all these properties must be stated (and proved) explicitly, increasing the size of the proofs.

It is our thesis that the proper way to address the current shortcomings of higher-order logic programming languages is to follow the example of what has been done at the first-order level, and to go through the development of a theory of rewriting for richly typed systems. Such development should certainly draw upon the seminal work done by Nipkow [54] and Prehofer [65] on higher-order rewriting for the simply-typed lambda calculus. However, an array of new issues arises when we consider the more complex type systems on which languages like Twelf are based, and these issues have hence to be analyzed and solved. In this dissertation we make a first step in this direction, by studying rewriting in the LF calculus, which provides the foundation for the Twelf language.

Once the theory of rewriting we advocate is in place, two new paths of development open up, mirroring at the higher-order level the evolution of Prolog we described before. One path, which goes through on the development of equational, constraint-based extensions to the host language, has already been partially investigated by us, through the development of a extension of Twelf [72]. The other direction, suggesting the definition of new languages based on higher-order versions of Rewriting Logic, has not yet been explored, to the best of our knowledge, but certainly looks promising and deserving of further study in the future.

item : type.
list : nat -> type.
nil : list 0.
,   : item -> list N -> list (1 + N). %infix right 50 ,.
append : list M -> list N -> list (M + N) -> type.
append_nil  : append nil L2 L2.
append_cons : append L1 L2 L3 -> append (X , L1) L2 (X , L3).

Figure 1.1: List Concatenation - Equational

1.2 Some Preliminary Examples

To give the flavor of how the equational theories and rewriting systems we propose could be used in practice, we present here a couple of preliminary examples, based on Twelf. More complex examples can be found in the final part of this dissertation.

Concatenation of lists is an operation which is traditionally represented as a relation rather than a function, and therefore fits well inside the programming paradigm offered by Twelf. Having dependent types at our disposal, however, it becomes possible for us to specify general invariants about this operation, that any (correct) implementation should satisfy. Moreover, it is desirable that, whenever one such implementation is provided, these invariants are automatically verified by the type-checking mechanism, without any user intervention. In this specific case, we observe that concatenating two lists, of length m and n respectively, should always produce a list of length (m + n). Using this observation as invariant, we have the Twelf signature of Figure 1.1.

The implementation of append we chose in this example is recursive on the first argument. In order verify it conforms to the invariant, we need the type-checking algorithm to automatically apply a few simple arithmetical equations. These are, as the reader can easily verify, the following:

0 + M = M  1 + (M + N) = (1 + M) + N

Unfortunately, before our results, such equational extensions of the type-check mechanism could not be theoretically justified, and were consequently not implemented. In Figure 1.2 we show how the same example has to be represented in the current version of Twelf. Note that equality needs to be expressed explicitly, and that the programmer is responsible for providing proofs (which are often long and complex) of all the equations he/she needs.

The second example we present is from Category Theory. As we will have the opportunity to show in Chapter 12, categorical notions have a very strong equational component, and therefore lend themselves naturally to be represented by term rewriting systems. In this section, we focus on SUBST, a fragment of the axioms of Cartesian Closed Category, that has been proved in [25] to be orientable into a stronglynormalizing (i.e. rewriting always terminates in a finite number of steps), confluent (i.e. normal forms are unique) system. A representation of SUBST in a Twelf-like syntax is given in Figure 1.3.

With dependent types, we can store information about the source and target of a morphism inside its type; a consequence of this is, for example, that composition of morphism is well-typed only in those cases when it is well-defined.

Since this formalization captures all and only well-formed entities, proving that rewriting is closed with respect to the set of terms representing valid morphisms is unnecessary, as this is automatically guaranteed by the calculus. Moreover, “catch-all” rules like the ones for the terminal object (see Figure 1.4) can be added to the system without causing it to collapse to the trivial one, equating all terms.

item : type.
eq : nat -> nat -> type.
eq_refl  : eq M M.
eq_symm  : eq M N -> eq N M.
eq_trans : eq M N -> eq N P -> eq M P.
eq_congl : {M : nat} eq N N' -> eq (M + N) (M + N').
eq_congr : {M : nat} eq N N' -> eq (N + M) (N' + M).
eq_idl   : eq (0 + M) M.
eq_idr   : eq (M + 0) M.
eq_assoc : eq ((M + N) + P) (M + (N + P)).
list : nat -> type.
nil : list 0.
,   : item -> list N -> list (1 + N). %infix right 50 ,.
append : list M -> list N -> list P -> eq (M + N) P -> type.
append_nil  : append nil L2 L2 eq_idl.
append_cons : append (X , L1) L2 (X , L3) (eq_trans (eq_congl 1 D) (eq_symm eq_assoc))
                <- append L1 L2 L3 D.

Figure 1.2: List Concatenation - Non-Equational Version

1.3 Outline of This Dissertation

The two examples presented in the previous sections correspond to the two parts in which the results contained in this dissertation are divided.

In the first part we investigate an equational extension to LF, where type conversion is performed modulo an equational theory E, as well as modulo the traditional β- and η-relations. This can be seen as the theoretical justification to the first example presented in Section 1.2. LF is very sensitive to changes in the type-conversion notion employed: the proofs presented in [67] for βη-conversion are more complex, and often quite different, from the one found in the original LF paper by Harper et al. [27], which uses only βconversion. Hence, results about confluence and existence of normal forms for our equational extension can not be reasonably assumed to hold, and have to be re-examined. We indeed show that the one proposed is a conservative extension, and in particular long-η β-normal forms (we will call these forms canonical) still exist, and are unique, modulo conversion of the types of the lambda-abstracted variables. Uniqueness in the absolute sense is not achievable, as one can easily see by considering the famous Nederpelt’s counterexample [52] in this context

\xymatrix{ & λx : A_{1}. (λx : A_{2}. M)x \ar[dl]^{β} \ar[dr]_{η} \\ λx : A_{1}. M &  & λx : A_{2}. M}

and observing that the types A_{1} and A_{2} may have been obtained one from the other through conversion modulo E. Hence our uniqueness result is the best that we could hope for, given the circumstances, and it proves to be enough to the development of the remaining of our dissertation.

Part I can be furtherly subdivided as follows. In Chapter 2, we introduce the type system and prove

obj   : type.
prod  : obj -> obj -> type.  %infix right 50 prod.
arrow : obj -> obj -> type.  %infix right 50 arrow.
morph : obj -> obj -> type.
id : {A : obj} morph A A.
o  : morph B C -> morph A B -> morph A C.  %infix right 50 o.
pair : morph C A -> morph C B -> morph C (A prod B).
pr1 : morph (A prod B) A.
pr2 : morph (A prod B) B.
lambda : morph (A prod B) C -> morph A (B prod C).
fst   : pr1 o (pair S T) => S.
snd   : pr2 o (pair S T) => T.
idl   : (id B) o T => T.
idr   : T o (id A) => T.
spair : pair (pr1 o T) (pr2 o T) => T.
assoc : (S o T) o U => S o (T o U).
dpair : (pair S T) o U => pair (S o U) (T o U).
dlam  : (lambda S) o T => lambda (S o (pair (T o pr1) pr2))
fsid  : pair pr1 pr2 => id C.

Figure 1.3: The Rewrite System SUBST

1 : obj.
t : {A : obj} morph A 1.
tall : F => (t A).

Figure 1.4: Adding a Terminal Object to SUBST its most basic properties; these will be extensively used throughout the thesis as the foundation over which most of the theory is constructed. In Chapter 3 we study β-reduction, showing it to be Church-Rosser (Theorem 3.3.2) and strong normalizing (Theorem 3.3.10) by using a modification of the proof found in [28]. We work in a slightly different (but easily seen equivalent) system (Definition 3.1.1, where some terms are marked with their type. This is necessary to carry out a construction, due to Dowek et al. [17] (Theorem 3.4.1, that will be instrumental in proving the existence of canonical forms. Chapter 4 wraps up this first part, by studying the behavior of η-conversion and by using all the machinery developed in the previous two to prove confluence of the system with respect to β-reduction and η-expansion (Theorem 4.4.20).

The second part tackles the problem of giving a definition of a Higher-order Term Rewriting System (HTRS) in this setting. This relies, as usual, on the notion of contextual replacement of expression, which however in this case, unlike the simply-typed one investigated by Nipkow [54], appears to be problematic. Replacing only expressions with equal type no longer suffice to ensure the well-typedness of the overall expression, as we demonstrate in Chapter 5. The search for conditions that guarantee the well-behavior properties we desire motivates us to study special preorders called dependence relations. Using these notions, we are able to formulate a sound theory of rewriting, and to prove a series of results about it, culminating in a higher-order version of the Knuth-Bendix’s Critical Pair Criterion [30].

Looking at the structure of Part II at a finer level of detail, we have the following divisions. In Chapter 5, dependence relations, already introduced in Part I, are thoroughly discussed. We explain the main ideas behind their introduction, and their defining properties. In Chapter 6 we define term rewriting. We provide, together with the natural definition (Definition 6.2.3), a second, more technical one(Definition 6.3.1), that we prove equivalent to the first(Theorem 6.3.14), and which will be more convenient to use when studying the properties of rewriting systems. Chapter 7 deals with those cases when the equational theory E is “simpler” than the HTRS R, i.e. it is defined on a class of types that lay below the type hierarchy than the one over which R is defined. Simpler equational theories can be easily detected by using dependence relations (Definition 7.1.2). We prove that in these cases no critical overlaps are possible between an equation in E and a rule in R. This leads to a simplified version of the Critical Pair Criterion (Theorem 7.4.3), where only critical pairs coming from overlaps of rules (Definition 7.3.2) need to be considered. Finally, in Chapter 8 we deal with the general case, where overlaps between equations and rewrite rules are possible. The Critical Pair Criterion in its general form is stated and proved (Theorem 8.3.7); we require here equations to have patterns on both sides, as now critical overlaps are possible (Definition 8.3.1).

These two parts, which contain the main theoretical results of this work, are followed by a third one, where we show some of the applications of the theory. The three examples we picked come from very different areas of theoretical computer science, thus demonstrating the wide range of applicability of higher-order rewriting techniques. The first of these, developed in Chapter 11, deals with concurrency, formalized by Milner’s action structures and process calculus. We show how the algebraic nature of action structures make them an ideal candidate for being represented by higher-order equational theories. We also show that weak head-normal form reduction in the process calculus can be modeled by a strongly normalizing, confluent system.

Our second example focuses on Category Theory. That categorical notions could be elegantly represented by dependent-type rewriting had already been shown by Gehrke in [19]. In Chapter 12, we give an alternative formulation to the one he adopted, which makes a better use of the type structure.

Finally, one of the strengths of LF is the ability to be used as a logical framework to describe different logical systems. In this context, rewriting can be used to express proof-transformation technique within a single object logic or between two different ones. In Chapter 13, we present term rewriting systems to convert between intuitionistic natural deduction and sequent calculus, as well as a cut-elimination system that produces cut-free sequent derivations.

Part I

Equational LF Preliminaries

In this chapter we present an equational version of the LF calculus. Type conversion is expressed explicitly, in the form of an equality judgment. An implicit representation, more common in LF literature, is usually better suited to systems where only β- or βη-conversions are used, and confluence is proven for the contractionary direction of these conversions. In these conditions, subject reduction holds, and therefore well-formed terms can be guaranteed to admit valid normal forms. In our case, however, the presence of E-conversion, which in general cannot be oriented, as well as the need to consider η-conversion in its expansionary direction (more about this will be said at the beginning of Chapter 4) make it necessary to express conversion as an equational judgement.

2.1 Equational LF

The equational version of the LF calculus, which we will concentrate upon in this dissertation, is described as follows:

Definition 2.1.1. The LF calculus is a three-level calculus for objects, type families, and kinds

Objects  M := c | x | λx : A. M | M N
Type Families A := a | Πx : A. B | A M
Kinds  K := type | Πx : A. K

Notation. We will use the letters M, N, U for objects, A, B, C, D for types, K, L for kinds. The letters c and a will range over object and type family constants, respectively; x, y, z, u, v will be used for object variables.

Terms of the calculus (i.e. objects, type families, and kinds) will always be be considered equal modulo α-conversion, i.e. renaming of the variables bounded by Π and λ.

By FV(M) (respectively: FV(A), FV(K)) we will denote the set of variables that are free in the object M (respectively: type family A, kind K).

The notation [N/x]M will be used to indicate the replacement of all the free occurrences of the variable x by N in the object M; replacement inside a type family ([N/x]A), or a kind ([N/x]K) is similarly defined.

We will assume the usual notions of β- and η-reduction, as the smallest relations containing all the pairs

(λx : A. M) N →_{β} [N/x]M
λx : A. (M x) →_{η} M, provided x ∉ FV(M)

and compatible with the term structure.

Given any binary relation R over terms of the calculus, we will denote by R^{=}, R^{+}, and R^{∗} its reflexive, transitive, and reflexive-transitive closures, respectively.

An object M will be said to be a λ if M = λx : A. N. Similarly, a type family A is a Π if A = Πx : B. C. A type A that is not a Π is said to be a base type. We will use the letter P to indicate base types.

In what follows, we will define well-formedness of terms of the calculus by assigning types to objects, and kinds to types. In order to do so, however we need to introduce the concepts of signatures, that map well-formed object and type constants to their type or kind, contexts, that will play a similar role for free variables, and equational theories, that tell us which types are to be considered equivalent.

Definition 2.1.2. We define signatures, equational theories, and contexts:

Signatures  Σ := · | Σ, c : A | Σ, a : K
Equational Theories E := · | E, (Γ ⊢ M = N : A)
Contexts  Γ := · | Γ, x : A

Notation. We will use Γ and Δ to range over contexts, E for equational theories, and Σ for signatures.

We will often see signatures and contexts as functions over sets, and borrow some of the traditional set-theoretic notation. For example, given a context

Γ = x_{1} : A_{1}, x_{2} : A_{2}, …, x_{n} : A_{n}

its domain will be, as usual,

dom(Γ) = x_{1}, x_{2}, …, x_{n}

Example 1. The following simple signature could be used to represent propositional logic formulas

dom(Σ) = {o, not, and, or, implies}

Σ(o) = type

Σ(not) = Πx : o. o

Σ(and) = Πx : o. Πy : o. o Σ(or) = Πx : o. Πy : o. o Σ(implies) = Πx : o. Πy : o. o

We can also define an equational theory over this signature, for example to describe some well known classical logic equivalences:

x : o ⊢ not (not x) = x : o
x : o, y : o ⊢ not (and x y) = or (not x) (not y) : o
x : o, y : o ⊢ not (or x y) = and (not x) (not y) : o
x : o, y : o ⊢ implies x y = or (not x) y : o

We will make use here of the definition of dependence relation introduced by us in [71].

Definition 2.1.3 (Dependence Relation). A dependence relation ≺ for a signature Σ is a pair of binary relations ≺^{τ} and ≺^{t} defined over the set of type family constants of Σ, and satisfying

• head(A_{i}) ≺^{τ} a if Σ(a) = Πx_{1} : A_{1}. Πx_{2} : A_{2}…. Πx_{n} : A_{n}. type

• a ≺^{τ} a′ if a ≺^{τ} b ≺^{t} a′ for some b

• a ≺^{τ} a′ if a ≺^{t} b ≺^{τ} a′ for some b

• a ≺^{t} a′ if a ≺^{t} b ≺^{t} a′ for some b

• a ≺^{t} a′ if a ≺^{τ} a′ where the head of a type family head(A) is defined as follows:

head(a) = a
head(Πx : A. B) = head(B)
head(A M) = head(A)

Notation. The definitions of the binary relations ≺^{τ} and ≺^{t} are extended to pairs of type families over Σ by letting

A ≺^{τ} B iff head(A) ≺^{τ} head(B)  A ≺^{t} B iff head(A) ≺^{t} head(B)

We will also use the notation

A ⪯^{τ} B iff A ≺^{τ} B or head(A) = head(B)
A ⪯^{t} B iff A ≺^{t} B or head(A) = head(B)

Dependence relations will be used when defining rewriting, in Chapter 6, to keep track of the types of objects that may appear inside LF expressions. Specifically, we will show that A ≺^{t} B only if it is possible for an object of type A to be contained inside an object of type B, and similarly A ≺^{τ} B only if objects of type A may appear inside the type family B.

As dependence relations will play no role in the results presented in Chapters 2-4, we will delay any further discussion of their motivations and formal properties to Chapter 5.

Definition 2.1.4. Well-formed objects, type families, and kinds are constructed using the judgments

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} K Kind K is a kind
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A : K  A is a type of kind K
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : A M is an object of type A

These, in turn, are formed by means of the auxiliary judgments

⊢\begin{matrix}≺ \\ E \end{matrix} Σ Sig Σ is a valid signature
⊢\begin{matrix}≺ \\ Σ \end{matrix} E Eq  E is a valid equational theory
⊢\begin{matrix}≺ \\ Σ,E \end{matrix} Γ Ctx Γ is a valid context

specifying how valid signatures, equational theories, and contexts are built.

Conversion between pairs of kinds, type families, and objects is defined making use of substitutions:

Substitutions θ := · | θ, x ↦ N

and expressed by the judgments

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} K =_{E′βη} K′ K and K′ are E′βη-convertible kinds
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A =_{E′βη} A′ A and A′ are E′βη-convertible type families
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M =_{E′βη} M′ M and M′ are E′βη-convertible objects

where E′ ⊆ E, and

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ : Δ θ is a valid substitution from Δ to Γ

The rules for the calculus are listed in Figure 2.1

\frac{Σ(c) = A}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} c : A}  \frac{Γ(x) = A}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} x : A}  \frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A : type Γ, x : A ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : B A ⪯^{t} B}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} λx : A. M : Πx : A. B}

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : Πx : A. B Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N : A}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M N : [N/x]B}  \frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : A Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A =_{Eβη} A′ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A′ : type}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : A′}

\frac{Σ(a) = K}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} a : K}  \frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A : type Γ, x : A ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} B : type A ⪯^{t} B}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} Πx : A. B : type}

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A : Πx : B. K Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : B}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A M : [M/x]K}  \frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A : K Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} K =_{Eβη} K′ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} K′ Kind}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A : K′}

\overline{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} type Kind}  \frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A : type Γ, x : A ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} K Kind}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} Πx : A. K Kind}

\overline{⊢\begin{matrix}≺ \\ E \end{matrix} · Sig}  \frac{⊢\begin{matrix}≺ \\ E \end{matrix} Σ Sig ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A : type}{⊢\begin{matrix}≺ \\ E \end{matrix} Σ, c : A Sig}  \frac{⊢\begin{matrix}≺ \\ E \end{matrix} Σ Sig ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} K Kind}{⊢\begin{matrix}≺ \\ E \end{matrix} Σ, a : K Sig}

\overline{⊢\begin{matrix}≺ \\ Σ \end{matrix} · Eq}  \frac{⊢\begin{matrix}≺ \\ Σ \end{matrix} E Eq Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : P Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N : P}{⊢\begin{matrix}≺ \\ Σ \end{matrix} E, (Γ ⊢ M = N : P) Eq}

\overline{⊢\begin{matrix}≺ \\ Σ,E \end{matrix} · Ctx}  \frac{⊢\begin{matrix}≺ \\ Σ,E \end{matrix} Γ Ctx Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A : type}{⊢\begin{matrix}≺ \\ Σ,E \end{matrix} Γ, x : A Ctx}

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} (λx : A. M) N : C}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} (λx : A. M) N =_{E′βη} [N/x]M}  \frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : Πx : A. B}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M =_{E′βη} λx : A. (M x)}

\frac{(Δ ⊢_{Σ,E} M = N : A) ∈ E′ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ : Δ}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θM =_{E′βη} θN}

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : A}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M =_{E′βη} M}  \frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M =_{E′βη} M′}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′ =_{E′βη} M}  \frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M =_{E′βη} M′ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′ =_{E′βη} M′′}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M =_{E′βη} M′′}

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A =_{E′βη} A′ Γ, x : A ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : B}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} λx : A. M =_{E′βη} λx : A′. M}  \frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A : type Γ, x : A ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M =_{E′βη} M′}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} λx : A. M =_{E′βη} λx : A. M′}

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M =_{E′βη} M′ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N : B}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M N =_{E′βη} M′ N}  \frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : Πx : A. B Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N =_{E′βη} N′}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M N =_{E′βη} M N′}

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A : K}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A =_{E′βη} A}  \frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A =_{E′βη} A′}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A′ =_{E′βη} A}  \frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A =_{E′βη} A′ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A′ =_{E′βη} A′′}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A =_{E′βη} A′′}

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A =_{E′βη} A′ Γ, x : A ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} B : type}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} Πx : A. B =_{E′βη} Πx : A′. B}  \frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A : type Γ, x : A ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} B =_{E′βη} B′}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} Πx : A. B =_{E′βη} Πx : A. B′}

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A =_{E′βη} A′ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : B}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A M =_{E′βη} A′ M}  \frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A : Πx : B. K Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M =_{E′βη} M′}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A M =_{E′βη} A M′}

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} K Kind}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} K =_{E′βη} K}  \frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} K =_{E′βη} K′}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} K′ =_{E′βη} K}  \frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} K =_{E′βη} K′ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} K′ =_{E′βη} K′′}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} K =_{E′βη} K′′}

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A =_{E′βη} A′ Γ, x : A ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} K Kind}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} Πx : A. K =_{E′βη} Πx : A′. K}  \frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A : type Γ, x : A ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} K =_{E′βη} K′}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} Πx : A. K =_{E′βη} Πx : A. K′}

\overline{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} · : ·}  \frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ : Δ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N : θA}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ, x ↦ N : Δ, x : A}

Figure 2.1: Typing Rules for the LF Calculus

Remark. A few observations about the introduced definitions are necessary.

First, we defined conversion as a parametric judgment over an equational theory E′ ⊆ E. This allows us to group under a common notation both βη-conversion (E′ = ∅) and full conversion modulo E and βη (E′ = E). Although we will occasionally prove results that apply only to one of these two conversion notions, most of the results presented hold for both, and this expedient allows us to greatly simplify and shorten our presentation.

A similar desire not to overburden the reader with unnecessary notation has led us to avoid tagging the conversion statement with the type of the expressions being converted. A small price we have to pay for this is to allow conversion on some classes of non-well-formed terms. In formulating our definitions, however, we were careful in requiring that the conversion steps we were mostly concerned about, namely βand η-expansions, were always performed on well-formed objects.

Finally, the LF calculus presented here differs from the one found in [59] in two important aspects. The first is that conversion is presented here as a judgment, rather than being defined on raw objects. In this respect, this presentation is more similar to [26]. The motivation behind this choice is twofold: we wanted to give a uniform description of both E- and βη-conversion, and we also needed a way to control η-expansion, so that Subject Reduction holds.

The second difference is that we do not allow abstraction over types. Being able to abstract over type families adds very little power to the calculus, and has the disadvantage of making the Uniqueness of Products property:

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} Πx : A. B =_{E′βη} Πx : A′. B′ implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A =_{E′βη} A′ and Γ, x : A ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} B =_{E′βη} B′

very hard to prove.

Notation. To simplify the notation, we stipulate, from now on, and throughout this thesis, that all the contexts, signatures, and equational theories mentioned are well-typed.

Example 1. The signature Σ presented before, where

dom(Σ) = {o, not, and, or, implies} can be proven to be well-formed for some choices of dependence relations ≺. The most obvious candidate for one such relation, in this case as well as in general, is the full one ≺_{F}:

≺_{F}^{τ} = ≺_{F}^{t} = {(a, a′) | a, a′ ∈ dom(Σ)}

This choice can be easily seen to always satisfy the conditions given in Definitions 2.1.3 and 2.1.4. This simple observation forms the basis of our decision of postpone the discussion of these relations to Chapter 5, where some other, less crude choices, where available, will become highly desirable.

At the other side of the spectrum, we might ask ourselves what are the minimal (with respect to inclusion) relations that make Σ well-formed. Definition 2.1.3 can be satisfied by ≺_{0}^{τ} = ≺_{0}^{t} = ∅. This seem to suffice in Definition 2.1.4, where for functional objects of type Πx : A. B we are required to check A ⪯^{t} B; since

o ⪯^{t} o  o ⪯^{t} Πx : o. o

in this special, fortunate case the empty dependence relation seems to work as well. Moreover, it is immediate to see that any dependence relation ≺_{0}⊆≺⊆≺_{F} that satisfies Definition 2.1.3 will also well-type Σ (this is formally proved in Proposition 2.2.1 below). Hence, for example, we have also

≺^{τ} = ∅  ≺^{t} = {(o, o)}

Notation. A special class of substitutions that will be used frequently are identity substitutions. We define a special notation for them: given a context Γ, we will denote by id_{Γ} the identity substitution over Γ

id_{Γ} = {x ↦ x | x : A ∈ Γ}

It is convenient in our presentation to extend the conversion judgment to substitutions:

Definition 2.1.5. We introduce the judgment

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ =_{E′βη} θ′ θ and θ′ are E′βη-convertible substitutions

constructed according to the following two rules

\overline{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} · =_{E′βη} ·}  \frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ =_{E′βη} θ′ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N =_{E′βη} N′}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ, x ↦ N =_{E′βη} θ′, x ↦ N′}

Finally, a concept introduced by D. Miller [47] that will play an important role in the theory we are going to develop is that of a (higher-order) pattern:

Definition 2.1.6. An object Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : A is said to be a pattern if every free occurrence of a variable x in Γ) appears enclosed in sub-objects of the form M_{∘} = x N_{1} N_{2} … N_{k} and the N_{i} are all βη-convertible to distinct bound variables. A sub-object M_{∘} of the above form is called a generalized variable.

2.2 Basic Properties

We list now a few basic properties of the judgments defined above. Unless specified otherwise, all the proofs are obtained by a simple (and somewhat tedious) induction on the derivation, and will be omitted.

Proposition 2.2.1 (Weakening). Let ≺⊆≺′, Σ ⊆ Σ′, E′′ ⊆ E ⊆ E′, E′′ ⊆ E′′′ ⊆ E′, Γ ⊆ Γ′,

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : A implies Γ′ ⊢\begin{matrix}≺′ \\ Σ′,E′ \end{matrix} M : A  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M =_{E′′βη} M′ implies Γ′ ⊢\begin{matrix}≺′ \\ Σ′,E′ \end{matrix} M =_{E′′′βη} M′
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A : K implies Γ′ ⊢\begin{matrix}≺′ \\ Σ′,E′ \end{matrix} A : K  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A =_{E′′βη} A′ implies Γ′ ⊢\begin{matrix}≺′ \\ Σ′,E′ \end{matrix} A =_{E′′′βη} A′
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} K Kind implies Γ′ ⊢\begin{matrix}≺′ \\ Σ′,E′ \end{matrix} K Kind  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} K =_{E′′βη} K′ implies Γ′ ⊢\begin{matrix}≺′ \\ Σ′,E′ \end{matrix} K =_{E′′′βη} K′

Proposition 2.2.2. Assume Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ : Δ, then

Δ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : A implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θM : θA  Δ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M =_{E′βη} M′ implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θM =_{E′βη} θM′
Δ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A : K implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θA : θK  Δ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A =_{E′βη} A′ implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θA =_{E′βη} θA′
Δ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} K Kind implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θK Kind  Δ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} K =_{E′βη} K′ implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θK =_{E′βη} θK′

Corollary 2.2.3 (Substitution). Let Γ_{1} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N : C,

Γ_{1}, x : C, Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : A implies Γ_{1}, [N/x]Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} [N/x]M : [N/x]A
Γ_{1}, x : C, Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A : K implies Γ_{1}, [N/x]Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} [N/x]A : [N/x]K
Γ_{1}, x : C, Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} K Kind implies Γ_{1}, [N/x]Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} [N/x]K Kind
Γ_{1}, x : C, Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M =_{E′βη} M′ implies Γ_{1}, [N/x]Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} [N/x]M =_{E′βη} [N/x]M′
Γ_{1}, x : C, Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A =_{E′βη} A′ implies Γ_{1}, [N/x]Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} [N/x]A =_{E′βη} [N/x]A′
Γ_{1}, x : C, Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} K =_{E′βη} K′ implies Γ_{1}, [N/x]Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} [N/x]K =_{E′βη} [N/x]K′

Proof. First, by using Proposition 2.2.2 repeatedly, we obtain from the assumptions a derivation of

Γ_{1}, [N/x]Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} (id_{Γ_{1}}, x ↦ N, id_{Γ_{2}}) : Γ_{1}, x : C, Γ_{2}

Then, one final application of Proposition 2.2.2 concludes the proof. Corollary 2.2.4. Let Γ_{1} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} C =_{E′βη} C′ : type,

Γ_{1}, x : C, Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : A implies Γ_{1}, x : C′, Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : A
Γ_{1}, x : C, Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A : K implies Γ_{1}, x : C′, Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A : K
Γ_{1}, x : C, Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} K Kind implies Γ_{1}, x : C′, Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} K Kind

Proof. We exploit the same strategy as in Corollary 2.2.3: using the type conversion rule, we show

Γ_{1}, x : C′, Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} id_{Γ_{1},x:C,Γ_{2}} : Γ_{1}, x : C, Γ_{2}

and then we apply Proposition 2.2.2. Lemma 2.2.5 (Type Uniqueness). Types of well-formed objects are unique up to conversion:

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : A and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : A′ implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A =_{Eβη} A′
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A : K and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A : K′ implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} K =_{Eβη} K′

Lemma 2.2.6 (Type Consistency).

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : A implies Γ ⊢\begin{matrix}≺ \\ Σ′ \end{matrix} A : type  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A : K implies Γ ⊢\begin{matrix}≺ \\ Σ′ \end{matrix} K Kind

Proposition 2.2.7.

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : A and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M =_{E′βη} M′ implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′ : A
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′ : A and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M =_{E′βη} M′ implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : A
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A : K and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A =_{E′βη} A′ implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A′ : K
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A′ : K and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A =_{E′βη} A′ implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A : K
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} K Kind and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} K =_{E′βη} K′ implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} K′ Kind
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} K′ Kind and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} K =_{E′βη} K′ implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} K Kind

Proof. By induction on the derivations of βη-equivalence, using inversion on the derivations of well-typedness. The cases of the three conversion rules might be of some interest:

• Case

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} (λx : A. M) N : C}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} (λx : A. M) N =_{E′βη} [N/x]M}

We want to prove Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} [N/x]M : C. By inversion on the derivation of Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} (λx : A. M) N : C, using type conversion if necessary, we can show

Γ, x : A ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : B

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N : A

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} [N/x]B =_{E′βη} C

Thus, the result follows from Substitution:

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} [N/x]M : [N/x]B

and type conversion.

• Case

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : Πx : A. B}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M =_{E′βη} λx : A. (M x)}

We want to show Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} λx : A. (M x) : Πx : A. B. By Type Consistency and inversion, Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A : type and A ⪯^{t} B; hence by Weakening

Γ, x : A ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : Πx : A. B

and the result follows by using the application and abstraction rules.

• Case

\frac{(Δ ⊢ M = N : A) ∈ E′ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ : Δ}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θM =_{E′βη} θN}

Immediate by Proposition 2.2.2.

Corollary 2.2.8. We have:

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ : Δ and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ =_{E′βη} θ′ implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ′ : Δ
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ′ : Δ and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ =_{E′βη} θ′ implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ : Δ

Proposition 2.2.9. Let E′ ⊆ E, the following are derived rules:

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ : Δ}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ =_{E′βη} θ}  \frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ =_{E′βη} θ′}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ′ =_{E′βη} θ}  \frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ =_{E′βη} θ′ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ′ =_{E′βη} θ′′}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ =_{E′βη} θ′′}

Proposition 2.2.10. Let Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ : Δ and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ =_{E′βη} θ′,

Δ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : A implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θM =_{E′βη} θ′M
Δ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A : K implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θA =_{E′βη} θ′A
Δ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} K Kind implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θK =_{E′βη} θ′K

Corollary 2.2.11. Let Γ_{1} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N : C and Γ_{1} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N =_{E′βη} N′,

Γ_{1}, x : C, Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : A implies Γ_{1}, [N/x]Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} [N/x]M =_{E′βη} [N′/x]M
Γ_{1}, x : C, Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A : K implies Γ_{1}, [N/x]Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} [N/x]A =_{E′βη} [N′/x]A
Γ_{1}, x : C, Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} K Kind implies Γ_{1}, [N/x]Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} [N/x]K =_{E′βη} [N′/x]K

Proof. The proof is very similar to the one of Corollary 2.2.3. Using Propositions 2.2.2 and 2.2.10 we show

Γ_{1}, [N/x]Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} (id_{Γ_{1}}, x ↦ N, id_{Γ_{2}}) : Γ_{1}, x : C, Γ_{2}

Γ_{1}, [N/x]Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} (id_{Γ_{1}}, x ↦ N, id_{Γ_{2}}) =_{E′βη} (id_{Γ_{1}}, x ↦ N′, id_{Γ_{2}})

and the result follows by one final application of Proposition 2.2.10.

2.3 Summary

In Section 2.1 we defined the rules of the calculus. This definition relies on several typing judgments, which have to be all introduce at once, since each is defined recursively in terms of (some of) the others.

The properties proven in Section 2.2 are those which are usually found in most presentations of LF. The fact that they continue to hold here, and that their proofs are, mutatis mutandis, the same as those found in the literature reassures us on the well-behaved nature of the extensions we propose.

18

Properties of β-Reduction

We start our study of βη-conversion by analyzing the behavior of β-reduction. We will show that it is confluent and strong-normalizing, and hence β-normal forms exist and are unique. Of course, this result alone does not suffice, since in general η-convertible expressions may have different β-normal forms, but it will turn out to be useful in the next chapter, where we will build upon the theory developed here to deal with full βη-conversion.

3.1 Marked LF

In this chapter we work with a slightly richer system than the one presented in Chapter 2, where some objects and type families are marked by their types and kinds, respectively.

Working in such system, as we will see, does not increase significantly the complexity of the proofs, and, on the other hand, it allows us to prove a result (Theorem 3.4.1) that will play a key role in showing the existence of long-η β-normal forms in Chapter 4.

Definition 3.1.1. Marked objects, type families, and kinds are constructed according the following syntax:

Marked Objects  M := c^{A} | x^{A} | (λx : A. M)^{B} | (M N)^{A}
Marked Type Families A := a^{K} | Πx : A. B | (A M)^{K}
Marked Kinds  K := type | Πx : A. K

Well-formed terms are built, as before, making use of marked signatures, equational theories, contexts, and substitutions:

Marked Signatures  Σ := · | Σ, c : A | Σ, a : K
Marked Equational Theories E := · | E, (Γ ⊩ M = N : A)
Marked Contexts  Γ := · | Γ, x : A
Marked Substitutions  θ := · | θ, x ↦ N

according to the inference system shown in Figure 3.1.

The intuition behind this marked extension is to embed the type of well-formed objects inside the object itself. Doing this will allow us to use more powerful inductive principles than the ones used so far, arguing by well-founded induction on both an object and its type.

Most of the remarks made about Definition 2.1.4 still hold here. In particular, the restrictions we impose on the conversion judgment are, again, just enough to guarantee that conversion of well-founded terms give rise to other well-founded terms (in the spirit of Proposition 2.2.7), but not sufficient to enforce conversion to be defined only on well-typed terms. This accounts for some apparent oddities in the conversion rules listed in Figure 3.1, where there seem no condition regarding the type used in the mark.

The only point of divergence between the definitions used here from the ones adopted in Chapter 2 involves the notion of replacement of a free variable x by an object N. Replacing inside marked terms

\frac{Σ(c) = A}{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} c^{A} : A}  \frac{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} c^{B} : A Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} B =_{Eβη} B′ Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} B′ : type}{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} c^{B′} : A}

\frac{Γ(x) = A}{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} x^{A} : A}  \frac{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} x^{B} : A Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} B =_{Eβη} B′ Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} B′ : type}{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} x^{B′} : A}

\frac{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A : type Γ, x : A ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} M : B A ⪯^{t} B}{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} (λx : A. M)^{Πx:A. B} : Πx : A. B}

\frac{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} (λx : C. M)^{B} : A Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} B =_{Eβη} B′ Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} B′ : type}{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} (λx : C. M)^{B′} : A}

\frac{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} M : Πx : A. B Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} N : A}{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} (M N)^{[N/x]B} : [N/x]B}  \frac{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} (M N)^{B} : A Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} B =_{Eβη} B′ Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} B′ : type}{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} (M N)^{B′} : A}

\frac{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} M : A Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A =_{Eβη} A′ Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A′ : type}{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} M : A′}

\frac{Σ(a) = K}{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} a^{K} : K}  \frac{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} a^{L} : K Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} L =_{Eβη} L′ Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} L′ Kind}{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} a^{L′} : K}

\frac{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A : Πx : B. K Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} M : B}{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} (A M)^{[M/x]K} : [M/x]K}  \frac{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} (A M)^{L} : K Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} L =_{Eβη} L′ Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} L′ Kind}{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} (A M)^{L′} : K}

\frac{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A : type Γ, x : A ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} B : type A ⪯^{t} B}{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} Πx : A. B : type}

\frac{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A : K Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} K =_{Eβη} K′ Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} K′ Kind}{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A : K′}

\overline{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} type Kind}  \frac{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A : type Γ, x : A ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} K Kind}{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} Πx : A. K Kind}

\overline{⊩\begin{matrix}≺ \\ E \end{matrix} · Sig}  \frac{⊩\begin{matrix}≺ \\ E \end{matrix} Σ Sig ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A : type}{⊩\begin{matrix}≺ \\ E \end{matrix} Σ, c : A Sig}  \frac{⊩\begin{matrix}≺ \\ E \end{matrix} Σ Sig ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} K Kind}{⊩\begin{matrix}≺ \\ E \end{matrix} Σ, a : K Sig}

\overline{⊩\begin{matrix}≺ \\ Σ \end{matrix} · Eq}  \frac{⊩\begin{matrix}≺ \\ Σ \end{matrix} E Eq Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} M : P Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N : P}{⊩\begin{matrix}≺ \\ Σ \end{matrix} E, (Γ ⊩ M = N : P) Eq}

\overline{⊩\begin{matrix}≺ \\ Σ,E \end{matrix} · Ctx}  \frac{⊩\begin{matrix}≺ \\ Σ,E \end{matrix} Γ Ctx Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A : type}{⊩\begin{matrix}≺ \\ Σ,E \end{matrix} Γ, x : A Ctx}

\frac{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} ((λx : A. M)^{C} N)^{B} : D}{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} ((λx : A. M)^{C} N)^{B} =_{E′βη} [N/x]M}  \frac{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} M : Πx : A. B}{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} M =_{E′βη} (λx : A. (M x)^{B})^{Πx:A. B}}

\frac{(Δ ⊩ M = N) ∈ E′ Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} θ : Δ}{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} θM =_{E′βη} θN}

\frac{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} M : A}{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} M =_{E′βη} M}  \frac{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} M =_{E′βη} M′}{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} M′ =_{E′βη} M}  \frac{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} M =_{E′βη} M′ Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} M′ =_{E′βη} M′′}{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} M =_{E′βη} M′′}

\frac{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} c^{A} : C Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A =_{E′βη} A′}{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} c^{A} =_{E′βη} c^{A′}}  \frac{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} x^{A} : C Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A =_{E′βη} A′}{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} x^{A} =_{E′βη} x^{A′}}

\frac{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} (λx : A. M)^{A} : C Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A =_{E′βη} A′}{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} (λx : A. M)^{A} =_{E′βη} (λx : A. M)^{A′}}  \frac{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} (M N)^{A} : C Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A =_{E′βη} A′}{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} (M N)^{A} =_{E′βη} (M N)^{A′}}

\frac{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A =_{E′βη} A′ Γ, x : A ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} M : B Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} C : type}{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} (λx : A. M)^{C} =_{E′βη} (λx : A′. M)^{C}}

\frac{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A : type Γ, x : A ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} M =_{E′βη} M′ Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} C : type}{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} (λx : A. M)^{C} =_{E′βη} (λx : A. M′)^{C}}

\frac{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} M =_{E′βη} M′ Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} N : B Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} C : type}{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} (M N)^{C} =_{E′βη} (M′ N)^{C}}

\frac{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} M : Πx : A. B Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} N =_{E′βη} N′ Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} C : type}{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} (M N)^{C} =_{E′βη} (M N′)^{C}}

\frac{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A : K}{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A =_{E′βη} A}  \frac{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A =_{E′βη} A′}{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A′ =_{E′βη} A}  \frac{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A =_{E′βη} A′ Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A′ =_{E′βη} A′′}{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A =_{E′βη} A′′}

\frac{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} a^{K} : L Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} K =_{E′βη} K′}{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} a^{K} =_{E′βη} a^{K′}}  \frac{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} (A N)^{K} : L Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} K =_{E′βη} K′}{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} (M N)^{K} =_{E′βη} (A N)^{K′}}

\frac{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A =_{E′βη} A′ Γ, x : A ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} B : type}{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} Πx : A. B =_{E′βη} Πx : A′. B}  \frac{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A : type Γ, x : A ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} B =_{E′βη} B′}{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} Πx : A. B =_{E′βη} Πx : A. B′}

\frac{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A =_{E′βη} A′ Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} M : B Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} L Kind}{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} (A M)^{L} =_{E′βη} (A′ M)^{L}}

\frac{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A : Πx : B. K Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} M =_{E′βη} M′ Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} L Kind}{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} (A M)^{L} =_{E′βη} (A M′)^{L}}

\frac{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} K Kind}{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} K =_{E′βη} K}  \frac{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} K =_{E′βη} K′}{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} K′ =_{E′βη} K}  \frac{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} K =_{E′βη} K′ Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} K′ =_{E′βη} K′′}{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} K =_{E′βη} K′′}

\frac{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A =_{E′βη} A′ Γ, x : A ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} K Kind}{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} Πx : A. K =_{E′βη} Πx : A′. K}  \frac{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A : type Γ, x : A ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} K =_{E′βη} K′}{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} Πx : A. K =_{E′βη} Πx : A. K′}

\overline{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} · : ·}  \frac{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} θ : Δ Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} N : θA}{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} θ, x ↦ N : Δ, x : A}

Figure 3.1: Typing Rules for the Marked LF Calculus

involves stripping each occurrence of the variable x from his mark. More formally, replacement can be defined by the following recursive rules:

[N/x]c^{A} = c^{[N/x]A}
[N/x]x^{A} = N
[N/x]y^{A} = y^{[N/x]A}
[N/x](λz : A_{1}. M)^{A_{2}} = (λz : [N/x]A_{1}. [N/x]M)^{[N/x]A_{2}}
[N/x](M_{1} M_{2})^{A} = ([N/x]M_{1} [N/x]M_{2})^{[N/x]A}

[N/x]a^{K} = a^{[N/x]K}
[N/x](Πz : A_{1}. A_{2}) = Πz : [N/x]A_{1}. [N/x]A_{2}
[N/x](A M)^{K} = ([N/x]A [N/x]M)^{[N/x]K}
[N/x] type = type
[N/x](Πz : A. K) = Πz : [N/x]A. [N/x]K

The properties we presented in Chapter 2 for the unmarked LF calculus continue to hold in this new setting, and have similar proofs.

Proposition 3.1.2 (Weakening). Let ≺⊆≺′, Σ ⊆ Σ′, E′′ ⊆ E ⊆ E′, E′′ ⊆ E′′′ ⊆ E′, Γ ⊆ Γ′,

Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} M : A implies Γ′ ⊩\begin{matrix}≺′ \\ Σ′,E′ \end{matrix} M : A  Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} M =_{E′′βη} M′ implies Γ′ ⊩\begin{matrix}≺′ \\ Σ′,E′ \end{matrix} M =_{E′′′βη} M′
Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A : K implies Γ′ ⊩\begin{matrix}≺′ \\ Σ′,E′ \end{matrix} A : K  Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A =_{E′′βη} A′ implies Γ′ ⊩\begin{matrix}≺′ \\ Σ′,E′′′ \end{matrix} A =_{E′βη} A′
Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} K Kind implies Γ′ ⊩\begin{matrix}≺′ \\ Σ′,E′ \end{matrix} K Kind  Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} K =_{E′′βη} K′ implies Γ′ ⊩\begin{matrix}≺′ \\ Σ′,E′ \end{matrix} K =_{E′′′βη} K′

Proposition 3.1.3 (Substitution). Let Γ_{1} ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} N : C,

Γ_{1}, x : C, Γ_{2} ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} M : A implies Γ_{1}, [N/x]Γ_{2} ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} [N/x]M : [N/x]A
Γ_{1}, x : C, Γ_{2} ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A : K implies Γ_{1}, [N/x]Γ_{2} ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} [N/x]A : [N/x]K
Γ_{1}, x : C, Γ_{2} ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} K Kind implies Γ_{1}, [N/x]Γ_{2} ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} [N/x]K Kind
Γ_{1}, x : C, Γ_{2} ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} M =_{E′βη} M′ implies Γ_{1}, [N/x]Γ_{2} ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} [N/x]M =_{E′βη} [N/x]M′
Γ_{1}, x : C, Γ_{2} ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A =_{E′βη} A′ implies Γ_{1}, [N/x]Γ_{2} ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} [N/x]A =_{E′βη} [N/x]A′
Γ_{1}, x : C, Γ_{2} ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} K =_{E′βη} K′ implies Γ_{1}, [N/x]Γ_{2} ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} [N/x]K =_{E′βη} [N/x]K′

Proposition 3.1.4. Let Γ_{1} ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} C =_{E′βη} C′ : type, the following holds:

Γ_{1}, x : C, Γ_{2} ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} M : A implies Γ_{1}, x : C′, Γ_{2} ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} M : A
Γ_{1}, x : C, Γ_{2} ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A : K implies Γ_{1}, x : C′Γ_{2} ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A : K
Γ_{1}, x : C, Γ_{2} ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} K Kind implies Γ_{1}, x : C′, Γ_{2} ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} K Kind

Lemma 3.1.5 (Type Uniqueness). Types of well-formed objects are unique up to conversions:

Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} M : A and Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} M : A′ implies Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A =_{E′βη} A′
Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A : K and Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A : K′ implies Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} K =_{E′βη} K′

Proposition 3.1.6.

Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} M : A and Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} M =_{E′βη} M′ implies Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} M′ : A
Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A : K and Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A =_{E′βη} A′ implies Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A′ : K
Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} K Kind and Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} K =_{E′βη} K′ implies Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} K′ Kind

Lemma 3.1.7 (Type Consistency).

Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} M : A implies Γ ⊩\begin{matrix}≺ \\ Σ,E′ \end{matrix} A : type  Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A : K implies Γ ⊩\begin{matrix}≺ \\ Σ,E′ \end{matrix} K Kind

Proposition 3.1.8. Let Γ_{1} ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} N : C and Γ_{1} ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} N =_{E′βη} N′,

Γ_{1}, x : C, Γ_{2} ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} M : A implies Γ_{1}, [N/x]Γ_{2} ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} [N/x]M =_{E′βη} [N′/x]M
Γ_{1}, x : C, Γ_{2} ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A : K implies Γ_{1}, [N/x]Γ_{2} ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} [N/x]A =_{E′βη} [N′/x]A
Γ_{1}, x : C, Γ_{2} ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} K Kind implies Γ_{1}, [N/x]Γ_{2} ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} [N/x]K =_{E′βη} [N′/x]K

Definition 3.1.9. We introduce the erasure map, which recursively strips an object of all its marks:

(c^{A})^{#} = c
(x^{A})^{#} = x
((λx : A. M)^{B})^{#} = λx : A^{#}. M^{#}
((M N)^{A})^{#} = M^{#} N^{#}
(a^{K})^{#} = a
(Πx : A. B)^{#} = Πx : A^{#}. B^{#}
((A M)^{A})^{#} = A^{#} M^{#}
type^{#} = type
(Πx : A. K)^{#} = Πx : A^{#}. K^{#}

Figure 3.2: Erasure Map

This map extends in the obvious away to signatures Σ, equational theories E, contexts Γ, and substitutions θ.

The following shows that, as observed earlier, marks are used to store the type of an object inside its structure:

Proposition 3.1.10.

Γ ⊩\begin{matrix}≺ \\ Σ \end{matrix} c^{B} : A implies Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} c^{B} : B
Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} x^{B} : A implies Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} x^{B} : B
Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} (M N)^{B} : A implies Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} (M N)^{B} : B
Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} (λx : C. M)^{B} : A implies Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} (λx : C. M)^{B} : B
Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} a^{L} : K implies Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} a^{L} : L
Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} (A M)^{L} : K implies Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} (A M)^{L} : L

Proof. The result follows easily arguing by induction on the derivation: the last inference rule must be either the rule that created the mark, or one of the two conversion rules (the one for marks or the one for the overall term).

3.2 Correspondence with the Unmarked Version

We present a sequence of results that link this marked version of LF to the usual one.

Proposition 3.2.1.

Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} M_{i} : A_{i} and (M_{i})^{#} = M (i = 1, 2), where Γ^{#} ⊢\begin{matrix}≺ \\ Σ^{#},E^{#} \end{matrix} M : B, implies Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} M_{1} =_{Eβη} M_{2}
Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A_{i} : K_{i} and (A_{i})^{#} = A (i = 1, 2), where Γ^{#} ⊢\begin{matrix}≺ \\ Σ^{#},E^{#} \end{matrix} A : L, implies Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A_{1} =_{Eβη} A_{2}
Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} K_{i} Kind and (K_{i})^{#} = K (i = 1, 2), where Γ^{#} ⊢\begin{matrix}≺ \\ Σ^{#},E^{#} \end{matrix} K Kind, implies Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} K_{1} =_{Eβη} K_{2}

Proof. The proof proceeds by induction on the unmarked derivation, arguing by inversion on the marked ones. All cases are dealt with by using the same technique. We show one:

• Case:

\frac{Γ^{#} ⊢\begin{matrix}≺ \\ Σ^{#},E^{#} \end{matrix} A′ : type Γ^{#}, x : A′ ⊢\begin{matrix}≺ \\ Σ^{#},E^{#} \end{matrix} M′ : B′ A′ ⪯^{t} B′}{Γ^{#} ⊢\begin{matrix}≺ \\ Σ^{#},E^{#} \end{matrix} λx : A′. M′ : Πx : A′. B′}

Then M_{i} = (λx : A′_{i}. M′_{i})^{D_{i}} (i = 1, 2) for some tagged objects M′_{i} and types A′_{i}. By inversion on the derivation, we show

Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A′_{i} : type

Γ, x : A′_{i} ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} M′_{i} : B′_{i}

Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} Πx : A′_{i}. B′_{i} =_{Eβη} D_{i}

By inductive hypothesis, Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A′_{1} =_{Eβη} A′_{2}, hence, using Proposition 3.1.4,

Γ, x : A′_{2} ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} M′_{1} : B_{1}

We can therefore apply the induction hypothesis once more to obtain Γ, x : A′_{2} ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} M′_{1} =_{Eβη} M′_{2}.

By Type Consistency,

Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} D_{i} : type (i = 1, 2)

hence we can derive

Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} (λx : A′_{1}. M′_{1})^{D_{2}} =_{Eβη} (λx : A′_{2}. M′_{1})^{D_{2}}

Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} (λx : A′_{2}. M′_{1})^{D_{2}} =_{Eβη} (λx : A′_{2}. M′_{2})^{D_{2}}

Moreover, using Proposition 3.1.6 and Type Uniqueness, we conclude Γ, x : A′_{2} ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} B_{1} =_{Eβη} B_{2}, that get us a derivation of

Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} D_{1} =_{Eβη} D_{2}

and finally one of

Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} (λx : A′_{1}. M′_{1})^{D_{1}} =_{Eβη} (λx : A′_{1}. M′_{1})^{D_{2}}

Two applications of the transitivity rule conclude this case.

Proposition 3.2.2. We have:

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : A implies Γ^{m} ⊩\begin{matrix}≺ \\ Σ^{m},E^{m} \end{matrix} M^{m} : A^{m}
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A : K implies Γ^{m} ⊩\begin{matrix}≺ \\ Σ^{m},E^{m} \end{matrix} A^{m} : K^{m}
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} K Kind implies Γ^{m} ⊩\begin{matrix}≺ \\ Σ^{m},E^{m} \end{matrix} K^{m} Kind
⊢\begin{matrix}≺ \\ E \end{matrix} Σ Sig implies ⊩\begin{matrix}≺ \\ E^{m} \end{matrix} Σ^{m} Sig
⊢\begin{matrix}≺ \\ Σ \end{matrix} E Eq implies ⊩\begin{matrix}≺ \\ Σ^{m} \end{matrix} E^{m} Eq
⊢\begin{matrix}≺ \\ Σ,E \end{matrix} Γ Ctx implies ⊩\begin{matrix}≺ \\ Σ^{m},E^{m} \end{matrix} Γ^{m} Ctx
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ : Δ implies Γ ⊩\begin{matrix}≺ \\ Σ^{m},E^{m} \end{matrix} θ^{m} : Δ^{m}

and

Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} (M_{i})^{m} : A (i = 1, 2) and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{1} =_{E′βη} M_{2} implies Γ^{m} ⊩\begin{matrix}≺ \\ Σ^{m},E^{m} \end{matrix} (M_{1})^{m} =_{(E′)^{m}βη} (M_{2})^{m}
Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} (A_{i})^{m} : K (i = 1, 2) and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A_{1} =_{E′βη} A_{2} implies Γ^{m} ⊩\begin{matrix}≺ \\ Σ^{m},E^{m} \end{matrix} (A_{1})^{m} =_{(E′)^{m}βη} (A_{2})^{m}
Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} (K_{i})^{m} Kind (i = 1, 2) and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} K_{1} =_{E′βη} K_{2} implies Γ^{m} ⊩\begin{matrix}≺ \\ Σ^{m},E^{m} \end{matrix} (K_{1})^{m} =_{(E′)^{m}βη} (K_{2})^{m}

for some (M^{m})^{#} = M, (A^{m})^{#} = A, (K^{m})^{#} = K, (Σ^{m})^{#} = Σ, (E^{m})^{#} = E, ((E′)^{m})^{#} = E′, (Γ^{m})^{#} = Γ, (Δ^{m})^{#} = Δ, and (θ^{m})^{#} = θ.

Proof. The proof proceeds by induction on the derivations. Proposition 3.2.1 is used when dealing with the conversion rules to make sure that the marks match up.

Proposition 3.2.3. The erasure map preserves well-typedness:

Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} M : A implies Γ^{#} ⊢\begin{matrix}≺ \\ Σ^{#},E^{#} \end{matrix} M^{#} : A^{#}
Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A : K implies Γ^{#} ⊢\begin{matrix}≺ \\ Σ^{#},E^{#} \end{matrix} A^{#} : K^{#}
Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} K Kind implies Γ^{#} ⊢\begin{matrix}≺ \\ Σ^{#},E^{#} \end{matrix} K^{#} Kind
⊩\begin{matrix}≺ \\ E \end{matrix} Σ Sig implies ⊢\begin{matrix}≺ \\ E^{#} \end{matrix} Σ^{#} Sig
⊩\begin{matrix}≺ \\ Σ \end{matrix} E Eq implies ⊢\begin{matrix}≺ \\ Σ^{#} \end{matrix} E^{#} Eq
⊩\begin{matrix}≺ \\ Σ,E \end{matrix} Γ Ctx implies ⊢\begin{matrix}≺ \\ Σ^{#},E^{#} \end{matrix} Γ^{#} Ctx
Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} M =_{E′βη} M′ implies Γ^{#} ⊢\begin{matrix}≺ \\ Σ^{#},E^{#} \end{matrix} M^{#} =_{E′βη} (M′)^{#}
Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A =_{E′βη} A′ implies Γ^{#} ⊢\begin{matrix}≺ \\ Σ^{#},E^{#} \end{matrix} A^{#} =_{E′βη} (A′)^{#}
Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} K =_{E′βη} K′ implies Γ^{#} ⊢\begin{matrix}≺ \\ Σ^{#},E^{#} \end{matrix} K^{#} =_{E′βη} (K′)^{#}
Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} θ : Δ implies Γ^{#} ⊢\begin{matrix}≺ \\ Σ^{#},E^{#} \end{matrix} θ^{#} : Δ^{#}

Proof. We argue by (simultaneous) induction on the derivations. The proof is straightforward.

Proposition 3.2.4. Let M, A, and K be marked objects, type families, and kinds, respectively, the following holds:

M^{#} →_{β} N implies ∃M′ s. t. M →_{β} M′ and (M′)^{#} = N
A^{#} →_{β} B implies ∃A′ s. t. A →_{β} A′ and (A′)^{#} = B
K^{#} →_{β} L implies ∃K′ s. t. K →_{β} K′ and (K′)^{#} = L

Proof. By induction on the structure of M^{#}, A^{#}, and K^{#}, we lift the β-reduction to marked terms.

Proposition 3.2.5. Let M, A, K marked terms, we have

M →_{β} N implies M^{#} →_{β}^{=} N^{#}
A →_{β} B implies A^{#} →_{β}^{=} B^{#}
K →_{β} L implies K^{#} →_{β}^{=} L^{#}

Proof. Immediate. Equality holds if the β-redex lies in one of the marks.

Notation. Since Propositions 3.2.2, 3.2.3, 3.2.4, and 3.2.5 above allow us to translate immediately all the results we are going to prove in this chapter (Subject Reduction, Strong Normalization, Church-Rosser Property) to the unmarked LF calculus, we will state these results only once, for the marked setting.

3.3 Behavior of β-Reduction

We have now most tools we need to examine the behavior of β-reduction.

Proposition 3.3.1 (β-Subject Reduction). β-reduction on raw objects preserves well-typedness:

Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} M : A and M →_{β} M′ implies Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} M′ : A
Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A : K and A →_{β} A′ implies Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A′ : K
Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} K Kind and K →_{β} K′ implies Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} K′ Kind

Proof. By induction on the derivations, we show:

Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} M : A and M →_{β} M′ implies Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} M =_{βη} M′
Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A : K and A →_{β} A′ implies Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A =_{βη} A′
Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} K Kind and K →_{β} K′ implies Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} K =_{βη} K′

and the result follows from Proposition 3.1.6.

Theorem 3.3.2 (CR_{β}). β-reduction is Church-Rosser on well-formed terms, i.e.

Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} M : A and M →_{β}^{∗} M_{i} (i = 1, 2) implies ∃N s. t. Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} N : A and M_{i} →_{β}^{∗} N (i = 1, 2)
Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A : K and A →_{β}^{∗} A_{i} (i = 1, 2) implies ∃B s. t. Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} B : K and A_{i} →_{β}^{∗} B (i = 1, 2)
Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} K Kind and K →_{β}^{∗} K_{i} (i = 1, 2) implies ∃L s. t. Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} L Kind and K_{i} →_{β}^{∗} L (i = 1, 2)

In pictures:

\xymatrix{M \ar[r]^{β^{∗}} \ar[d]_{β^{∗}} & M_{1} \ar@{-->}[d]^{β^{∗}} & A \ar[r]^{β^{∗}} \ar[d]_{β^{∗}} & A_{1} \ar@{-->}[d]^{β^{∗}} & K \ar[r]^{β^{∗}} \ar[d]_{β^{∗}} & K_{1} \ar@{-->}[d]^{β^{∗}} \\ M_{2} \ar@{-->}[r]_{β^{∗}} & N & A_{2} \ar@{-->}[r]_{β^{∗}} & B & K_{2} \ar@{-->}[r]_{β^{∗}} & L}

Proof. The proof is the usual one, by Martin-Löf and Tait, found, for example, in [7].

We are left to prove Strong Normalization of β-reduction (SN_{β}). We will prove this adapting the technique used in [28] for a version of LF with type conversion modulo β-reduction only. Definition 3.3.3. We define a map τ from type families and kinds to the set S of simple types constructed from the type constant ω.

τ(type) = ω
τ(Πx : A. K) = τ(A) → τ(K)
τ(a^{K}) = ω
τ((A M)^{K}) = τ(A)
τ(Πx : A. B) = τ(A) → τ(B)

Figure 3.3: The Type Embedding τ

Furthermore, let

C = {c | Σ(c) = A} ∪ {a | Σ(a) = K } ∪ {π_{s} | s ∈ S } ∪ {type} ,

we define another map | · | from LF terms to simply-typed objects constructed from the set of constants C.

|c^{A}| = (λy : ω. c) |A|
|x^{A}| = (λy : ω. x) |A| y ≠ x
|(λx : A. M)^{B}| = (λx : ω. (λx : ω. (λx : τ(A). |M|)) |A|) |B|
|(M N)^{A}| = (λx : ω. |M| |N|) |A| x ∉ FV(M N)
|a^{K}| = (λx : ω. a) |K|
|Πx : A. B| = π_{τ(A)} |A| (λx : τ(A). |B|)
|(A M)^{K}| = (λx : ω. |A| |M|) |K| x ∉ FV(A M)
| type | = type
|Πx : A. K| = π_{τ(A)} |A| (λx : τ(A). |K|)

Figure 3.4: The Object Embedding | · |

Proposition 3.3.4.

τ([N/x]A) = τ(A)
τ([N/x]K) = τ(K)

Proof. By an easy induction on A and K. Corollary 3.3.5.

Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A =_{E′βη} A′ implies τ(A) = τ(A′)
Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} K =_{E′βη} K′ implies τ(K) = τ(K′)

Proof. By induction on the derivations, using Proposition 3.3.4.

Proposition 3.3.6.

[|N|/x]|M| →_{β}^{∗} |[N/x]M|
[|N|/x]|A| →_{β}^{∗} |[N/x]A|
[|N|/x]|K| →_{β}^{∗} |[N/x]K|

Proof. By induction on the structure of M, A, and K. We examine a few cases in detail:

• Case M = x^{B}

By unraveling the definitions

[|N|/x]|M| = [|N|/x]((λy : ω. x) |B|) = (λy : ω. |N|) ([|N|/x]B) →_{β} |N| = |[N/x]M|, where the variable y above has been chosen so to satisfy y ∉ FV(N). As we see here, one β-reduction is necessary to “strip” the mark from the occurrence of x that is being replaced by the object N.

• Case M = (M_{1} M_{2})^{B}

By inductive hypothesis we have

[|N|/x]|M_{i}| →_{β}^{∗} |[N/x]M_{i}| (i = 1, 2)
[|N|/x]|B| →_{β}^{∗} |[N/x]B|,

hence

[|N|/x]|M| = [|N|/x]((λy : ω. |M_{1}| |M_{2}|) |B|) →_{β}^{∗} (λy. |[N/x]M_{1}| |[N/x]M_{2}|) |[N/x]B| = |[N/x]M|,

We now define a type assignment for the constants in C and show that, under this assignment, |.| maps well-formed LF objects to well-typed lambda objects. Definition 3.3.7. Given a signature Σ and a context Γ, we define

τ(Σ) = {c : τ(A) | Σ(c) = A} ∪ {a : τ(K) | Σ(a) = K } ∪ {π_{s} : ω → (s → ω) → ω | s ∈ S } ∪ {type : ω}
τ(Γ) = {x : τ(A) | Γ(x) = A}

Lemma 3.3.8.

Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} M : A implies τ(Γ) ⊢_{τ(Σ)} |M| : τ(A) and τ(Γ) ⊢_{τ(Σ)} |A| : ω
Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A : K implies τ(Γ) ⊢_{τ(Σ)} |A| : τ(K) and τ(Γ) ⊢_{τ(Σ)} |K| : ω
Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} K Kind implies τ(Γ) ⊢_{τ(Σ)} |K| : ω

Proof. By induction on the derivations. Subject Reduction of β-reduction for simply-typed objects is used extensively throughout the proof. We show some representative cases:

• Case

\frac{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} M : Πx : A. B Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} N : A}{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} (M N)^{[N/x]B} : [N/x]B}

By inductive hypothesis

τ(Γ) ⊢_{τ(Σ)} π_{τ(A)} |A| (λx : τ(A). |B|) : ω
τ(Γ) ⊢_{τ(Σ)} |N| : τ(A).

Hence

τ(Γ) ⊢_{τ(Σ)} (λx : τ(A). |B|) |N| : ω

and by Proposition 3.3.6 and Subject Reduction

τ(Γ) ⊢_{τ(Σ)} |[N/x]B| : ω

Similarly, using the inductive hypothesis, one shows

τ(Γ) ⊢_{τ(Σ)} |M| : τ(A) → τ(B)

and therefore, using Proposition 3.3.4,

τ(Γ) ⊢_{τ(Σ)} (λy : ω. |M| |N|)|[N/x]B| : τ([N/x]B)

• Case:

\frac{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} x^{A′} : A Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A′ =_{E′βη} A′′ Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A′′ : type}{Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} x^{A′′} : A}

By inductive hypothesis

τ(Γ) ⊢_{τ(Σ)} (λy : ω. x) |A′| : τ(A)
τ(Γ) ⊢_{τ(Σ)} |A| : ω
τ(Γ) ⊢_{τ(Σ)} |A′′| : ω

By subject reduction,

τ(Γ) ⊢_{τ(Σ)} x : τ(A)

and hence

τ(Γ) ⊢_{τ(Σ)} (λy : ω. x) |A′′| : τ(A)

as required. Proposition 3.3.9.

M →_{β} M′ implies |M| →_{β}^{+} |M′|
A →_{β} A′ implies |A| →_{β}^{+} |A′|
K →_{β} K′ implies |K| →_{β}^{+} |K′|

Proof. By a simple induction on the structure of M, A, and K. Most cases are immediately dealt with using the inductive hypothesis. The main case is:

((λx : A. M)^{C} N)^{B} →_{β} [N/x]M

which is easily proved using Proposition 3.3.6:

|((λx : A. M)^{C} N)^{B}| = λy : ω. ((λx : ω. (λx : ω. (λx : τ(A). |M|) |A|) |C|) |N|) |B|

→_{β}^{+} (λx : τ(A). |M|) |N| →_{β}^{+} [|N|/x]|M| →_{β}^{∗} |[N/x]M| Theorem 3.3.10 (SN_{β}). β-reduction of well-formed marked objects, type families, and kinds is strongly normalizing.

Proof. Assume, for sake of contradiction, that we have an infinite reduction sequence

M = M_{0} →_{β} M_{1} →_{β} M_{2} →_{β} … →_{β} M_{n} →_{β} M_{n+1} →_{β} …

starting from a well-formed object Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} M : A.

By Lemma 3.3.8, |M| is a well-typed object in the simply-typed lambda calculus:

τ(Γ) ⊢_{τ(Σ)} |M| : τ(A)

and, using Proposition 3.3.9 repeatedly, we can form an infinite β-reduction sequence starting from |M|:

|M| = |M_{0}| →_{β}^{+} |M_{1}| →_{β}^{+} |M_{2}| →_{β}^{+} … →_{β}^{+} |M_{n}| →_{β} |M_{n+1}| →_{β}^{+} …

a contradiction.

3.4 An Important Term Ordering Lemma

We are now ready to present Theorem 3.4.1, the raison d’être of the marked system presented in this chapter. However, before we can proceed, we still need some additional notation.

Notation. Given a derivation of Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} M : A (respectively Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A : K, Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} K Kind) witnessing the well-formedness of an object M (resp. A, K), this will also give us, for each occurrence of an object N or type family B inside M (resp. A, K), a proof that N and B are well-formed. We will call Γ(M, N) and Γ(M, B) (resp. Γ(A, N) and Γ(A, B), Γ(K, N) and Γ(K, B)) the contexts under which N and B are well-formed.

Note that these contexts do not depend on the particular derivation of Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} M : A (resp. Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} A : K, Γ ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} K Kind), and they can be easily computed by adding to Γ the variables of the λ-abstractions that enclose N and B.

Also, we will denote by type(Γ(M, N)) and kind(Γ(M, N)) (resp. type(Γ(A, N)) and kind(Γ(A, B)), type(Γ(K, N)) and kind(Γ(K, B))) one of the (pairwise convertible, by Type Uniqueness) types and kinds such that

Γ(M, N) ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} N : type(Γ(M, N)) (resp. Γ(A, N) ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} N : type(Γ(A, N)), Γ(K, N) ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} N : type(Γ(K, N)))
Γ(M, B) ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} B : kind(Γ(M, B)) (resp. Γ(A, B) ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} B : kind(Γ(A, B)), Γ(K, B) ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} B : kind(Γ(K, B)))

Similar definitions are given for unmarked objects too.

The following result is due to G. Dowek et al. [17]:

Theorem 3.4.1. Assume Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : A (respectively Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A : K, Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} K Kind). Then there is a wellfounded partial order <_{M} (resp. <_{A}, <_{K}) defined on the set of LF terms (i.e. objects, type families, and kinds) such that

1. on all terms appearing inside M (resp. A, K), <_{M} (resp. <_{A}, <_{K}) subsumes the strict containment order.

2. if N ≤_{M} M and B ≤_{M} M (resp. N ≤_{A} A and B ≤_{A} A, N ≤_{K} K and B ≤_{K} K), there are β-normal type families C and kinds L satisfying

(a) C <_{M} N and L <_{M} B (resp. C <_{A} N and L <_{A} B, C <_{K} N and L <_{K} B)

(b) Γ(M, N) ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N : C and Γ(M, B) ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} B : L (resp. Γ(A, N) ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N : C and Γ(A, B) ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} B : L,

Γ(K, N) ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N : C and Γ(K, B) ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} B : L)

(c) <_{C}⊆<_{M} and <_{L}⊆<_{M} (resp. <_{C}⊆<_{A} and <_{L}⊆<_{A}, <_{C}⊆<_{K} and <_{L}⊆<_{K})

Proof. We will prove the statement for Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : A; the other two cases are proved similarly.

From Proposition 3.2.2, there is a derivation D^{m} of Γ^{m} ⊩\begin{matrix}≺ \\ Σ,E \end{matrix} M^{m} : A^{m} such that (Γ^{m})^{#} = Γ, (M^{m})^{#} = M, (A^{m}). Using Theorem 3.3.10, we can furthermore assume that all the marks in M^{m} are β-normal.

We define, for all terms (i.e. objects, type families and kinds) X and Y appearing inside M^{m},

Y^{#} <_{M} X^{#} iff Y is properly contained inside X

The order <_{M} is as required: if two unmarked term are contained one inside the other, so are their marked correspondents; moreover each object contains its tag, which is by construction β-normal.

Remark. Although the usefulness of this result will become clear when we will present Lemma 4.2.3, it is beneficial to the curious reader to give here an intuition of its motivation.

Most of the proofs presented so far argued by induction on the structure of the expressions or the derivations involved. Such an approach becomes ineffective when proving the existence of long-η β-normal forms, as we are now going to show. Since we have proven existence and uniqueness of β-normal forms, we can ease our task by assuming that all the objects and types discussed are β-normal. The problem in constructing η-long normal forms by structural induction on the expressions lies in handling terms of the form

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : Πx_{1} : A_{1}…. Πx_{n} : A_{n}. B

where M is not a λ. We can η-expand it to

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} λx_{1} : A_{1}…. λx_{n} : A_{n}. M x_{1} … x_{n} : Πx_{1} : A_{1}…. Πx_{n} : A_{n}. B

However, in a dependently typed calculus like LF that alone does not suffice to obtain a η-long form. In general, the A_{i} may contain objects that in turn need to be expanded, and unfortunately our induction principle is not strong enough to ensure that they are. Hence we see we need a better form of induction, that allows us to argue not only on the structure of an object but also on that of its type, which is essentially what the well-founded ordering of Theorem 3.4.1 provides.

3.5 Summary

In this chapter we analyzed the properties of β-reduction. Our presentation followed the one used by Harper et al. in [28], but needed to be carried out in a more general system than they used. General not only because of the explicit nature of conversion, and the additional E-conversion rules we added to the calculus, but also because of the “marked” system we define in Section 3.1. While the notation became heavier because of this choice, the introduction of marks did not affect the development of the theory, since, as we proved in Section 3.2, the marked version is equivalent to the unmarked one.

In Section 3.3 we established strong normalization of β by projecting LF onto the simply-typed Lambda Calculus, and outlined how confluence can be proved by the well-known Martin-Löf and Tait technique of defining parallel reductions.

Finally, in Section 3.4 we use existence and uniqueness of β-normal forms, as well as the marked system, to carry a construction, due to Dowek et al., that gives us a more powerful induction principle than structural induction alone.

32

Properties of η-Expansion

In this chapter we analyze full βη-conversion. In doing so, our strategy will be to first concentrate on η-conversion alone, and then generalize to both conversion relations, integrating results from the previous chapter.

Unlike β-conversion, which is naturally oriented in the reductionary direction, in orienting η we can go both ways. And, while η-reduction is clearly a strongly normalizing relation, since it reduces the size of the overall expression, η-expansion, endowed with a few simple syntactic restrictions, can also be also shown to be well-founded. Since our interest lies in the study of higher-order rewriting, the latter reduction notion turns out to be the most convenient to use. To explain what makes η-reduction somewhat less palatable to us, we present the following:

Example 2. Consider the following signature representing the unit type and its unique inhabiting object:

dom(Σ) = {unit, 1}

Σ(unit) = type  Σ(1) = unit

To express that all the objects of type unit must be congruent to 1, we give the single rewriting rule:

x : unit ⊢\begin{matrix}≺ \\ Σ \end{matrix} x ⇒ 1 : unit

This rule interacts with η-reduction giving rise to a non-confluent system. Let M be an object of type Πx : unit. unit, and y ∉ FV(M), we have the following divergent pair:

\xymatrix{ & λy : unit. (M y) \ar[dl]_{η} \ar[dr]^{R} \\ M &  & λy : unit. (M 1)}

Unfortunately, until recently all the proofs in the literature [67, 22] used η in its reductionary direction. In this chapter, we adapt a proof presented by N. Ghani in [23] for the Calculus of Construction, that is, to our knowledge, the first to make use of η-expansion.

4.1 Canonical Forms

The main problem in using η-conversion in the expansionary direction is to ensure termination. For this reason, in the simply-typed lambda calculus we allow expansion of an object only if it is not an abstraction and it is not applied to some other object.

In the presence of dependent types, these two restrictions alone no longer suffice, as the following example shows.

Example 3. Let us add to the signature of Example 2 an additional constant p

dom(Σ) = {unit, 1, p}

Σ(unit) = type  Σ(1) = unit  Σ(p) = Πx : unit. type

and let

A = Πy : p 1. p 1  B(x) = p ((λy : A. 1) x)

we have the following infinite sequence of η-expansions:

x : A ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} x _{η}← λz : B(x). (x z) _{η}← λz : B(λz : B(x). (x z)). (x z) _{η}← …

To avoid these problems, in defining our η-expansionary rule, we will require, in addition to the two restrictions mentioned before, the type of the expansion to be in long-η β-normal form.

This may seem to introduce circularity in our definitions: we use the η-expansion rule to define long-η β-normal forms. Actually, our approach will be to first give a syntactical characterization of these forms, and use this to define the expansion rule. Later, we will show that the normal forms of this β-reducing/η-expanding rewriting relation are exactly those objects satisfying our syntactical definition.

Long-η β-normal forms in LF are traditionally called canonical forms:

Definition 4.1.1. Canonical forms are defined by the judgments

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇓ A M is a canonical object of type A
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇓ type A is a canonical type

defined in objects of the auxiliary ones

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ↓ A M is an atomic object of type A
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ↓ K A is an atomic type of kind K

by the inference system shown in Figure 4.1.

We list below a few simple properties of atomic and canonical forms, that will be used frequently in this section. All the proofs are obtained by a straightforward induction on the derivations and are omitted.

Proposition 4.1.2. Canonical and atomic terms are well-formed:

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇓ A implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : A  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇓ type implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A : type
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ↓ A implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : A  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ↓ K implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A : K

Proposition 4.1.3. Canonical and atomic terms are β-normal:

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇓ A implies M is β-normal  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇓ type implies A is β-normal
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ↓ A implies M is β-normal  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ↓ K implies A is β-normal

Proposition 4.1.4 (Weakening). Let Γ ⊆ Γ′, Σ ⊆ Σ′, E ⊆ E′, the following holds:

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇓ A implies Γ′ ⊢\begin{matrix}≺ \\ Σ′,E′ \end{matrix} M ⇓ A  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇓ type implies Γ′ ⊢\begin{matrix}≺ \\ Σ′,E′ \end{matrix} A ⇓ type
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ↓ A implies Γ′ ⊢\begin{matrix}≺ \\ Σ′,E′ \end{matrix} M ↓ A  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ↓ K implies Γ′ ⊢\begin{matrix}≺ \\ Σ′,E′ \end{matrix} A ↓ K

Proposition 4.1.5. Let Γ_{1} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} C =_{E′βη} C′,

Γ_{1}, x : C, Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇓ A implies Γ_{1}, x : C′, Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇓ A
Γ_{1}, x : C, Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇓ type implies Γ_{1}, x : C′, Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇓ type

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ↓ A Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ↓ type}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇓ A}  \frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇓ type Γ, x : A ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇓ B A ⪯^{t} B}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} λx : A. M ⇓ Πx : A. B}

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇓ A Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A =_{E′βη} A′ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A′ : type}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇓ A′}

\frac{Σ(c) = A}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} c ↓ A}  \frac{Γ(x) = A}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} x ↓ A}  \frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ↓ Πx : A. B Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N ⇓ A}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M N ↓ [N/x]B}

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ↓ A Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A =_{E′βη} A′ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A′ : type}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ↓ A′}

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ↓ type}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇓ type}  \frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇓ type Γ, x : A ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} B ⇓ type A ⪯^{t} B}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} Πx : A. B ⇓ type}

\frac{Σ(a) = K}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} a ↓ K}  \frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ↓ Πx : B. K Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N ⇓ B}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A N ↓ [N/x]K}

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ↓ K′ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} K′ =_{ζ} K Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} K Kind}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ↓ K}

Figure 4.1: Canonical and Atomic Forms

We use canonical forms to formulate our restricted version of η-expansion:

Definition 4.1.6. We define the judgments

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒_{η} M′ M η-expands to M′
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇒_{η} A′ A η-expands to A′

using the auxiliary ones

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒^{I}_{η} M′ M η-expands internally to M′
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇒^{I}_{η} A′ A η-expands internally to A′

according to the rules of Figure 4.2

Remark. It is not difficult to see that the definition of ⇒_{η} given above meets all the requirements we stated at the beginning of this section. In particular, the rule

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : Πx : A. B Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇓ type M not a λ}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒_{η} λx : A. (M x)}

requires, in order to be applicable, that the term M is not an abstraction, thereby avoiding creating new β-redexes. We also demand the abstracted type to be canonical, ruling out situations like the one presented in Example 3.

Also, we forbid η-expansion of the functional argument of an application by the use of the auxiliary judgment ⇒^{I}_{η}. It follows from our definitions that Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒^{I}_{η} M′ only if M′ is obtained from M by

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : Πx : A. B Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇓ type M not a λ}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒_{η} λx : A. (M x)}  \frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒^{I}_{η} M′}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒_{η} M′}
\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇒_{η} A′ Γ, x : A ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : B}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} λx : A. M ⇒^{I}_{η} λx : A′. M}  \frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A : type Γ, x : A ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒_{η} M′}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} λx : A. M ⇒^{I}_{η} λx : A. M′}
\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒^{I}_{η} M′ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N : B}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M N ⇒^{I}_{η} M′ N}  \frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : Πx : A. B Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N ⇒_{η} N′}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M N ⇒^{I}_{η} M N′}

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇒^{I}_{η} A′}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇒_{η} A′} \frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇒_{η} A′ Γ, x : A ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} B : type}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} Πx : A. B ⇒^{I}_{η} Πx : A′. B} \frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A : type Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} B ⇒_{η} B′}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} Πx : A. B ⇒^{I}_{η} Πx : A. B′}
\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇒^{I}_{η} A′ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : B}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A M ⇒^{I}_{η} A′ M}  \frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A : Πx : B. K Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒_{η} M′}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A M ⇒^{I}_{η} A M′}

Figure 4.2: Rules for η-Expansion

η-expanding at an internal (i.e. non-topmost) position. We use this fact in the rule

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒^{I}_{η} M′ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N : B}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M N ⇒^{I}_{η} M′ N}

to ensure that, again, no new β-redexes are created as a result of an η-expansion. Notation. For a more uniform treatment of β-reduction and η-expansion, it will be convenient to express the former as a judgment too. For this reason we define

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒_{β} M′ iff Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : A and M →_{β} M′
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇒_{β} A′ iff Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A : K and A →_{β} A′

Furthermore, we define

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒_{βη} M′ iff Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒_{η} M′ or Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒_{β} M′
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇒_{βη} A′ iff Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇒_{η} A′ or Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇒_{β} A′

and similarly

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒^{I}_{βη} M′ iff Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒^{I}_{η} M′ or Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒_{β} M′
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇒^{I}_{βη} A′ iff Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇒^{I}_{η} A′ or Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇒_{β} A′

Some basic properties of η-expansion are listed below. Proposition 4.1.7.

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒_{βη} M′ implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M =_{βη} M′  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇒_{βη} A′ implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A =_{βη} A′
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒^{I}_{βη} M′ implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M =_{βη} M′  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇒^{I}_{βη} A′ implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A =_{βη} A′

Proposition 4.1.8. η-expansion preserves β-normality:

M β-normal, and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒_{η} M′ implies M′ β-normal
M β-normal, and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒^{I}_{η} M′ implies M′ β-normal
A β-normal, and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇒_{η} A′ implies A′ β-normal
A β-normal, and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇒^{I}_{η} A′ implies A′ β-normal

4.2 Normality of Canonical Forms

The purpose of this section is to show that canonical objects coincide with the set (⇒_{βη})-normal forms. We will do so by proving that the two sets are included one in each other; the first of these two inclusions is trivial:

Lemma 4.2.1.

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇓ A implies M is a (⇒_{βη})-normal form
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇓ type implies A is a (⇒_{βη})-normal form
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ↓ A implies M is a (⇒^{I}_{βη})-normal form
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ↓ K implies A is a (⇒^{I}_{βη})-normal form

Proof. We already proved β-normality in Proposition 4.1.3. To prove normality with respect to η-expansion we proceed by induction on the derivations. The only challenge comes from the rule

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ↓ A Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ↓ type}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇓ A}

By inductive hypothesis we know M is ⇒^{I}_{βη}-normal. We are left to show that there is no type Πx : B. C that satisfies the requirements of the expansion rule:

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : Πx : B. C Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} B ⇓ type M not a λ}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒_{η} λx : B. (M x)}

By a simple induction on the Eβη-conversion judgment, we can prove the following result:

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} Πx : B. C =_{Eβη} D implies D = Πx : B′. C′

Using this, we see that the existence of a derivation Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ↓ A guarantees, by Type Uniqueness, that the expansion rule is not applicable on M. Hence M is (⇒_{βη})-normal, quod erat demostrandum.

Proving that (⇒_{βη})-normal forms are canonical requires some preliminary work. It will suffice to show that any term can be, by repeated use of ⇒_{βη}, transformed into a canonical one. This is proved using the machinery developed in the previous chapter, and in particular Theorem 3.4.1.

Proposition 4.2.2. Assume

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ↓ A

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇓ type

then there is an object M′ such that

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒_{η}^{∗} M′

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′ ⇓ A

Proof. By induction on the derivation of Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇓ type:

• Case:

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ↓ type}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇓ type}

In this case we let M′ = M, since

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ↓ A Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ↓ type}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇓ A}

• Case:

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} B ⇓ type Γ, x : B ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} C ⇓ type B ⪯^{t} C}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} Πx : B. C ⇓ type}

We can apply the inductive hypothesis to Γ, x : B ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} x ↓ B obtaining an object N_{x} such that

Γ, x : B ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} x ⇒_{η}^{∗} N_{x}

Γ, x : B ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N_{x} ⇓ B

From this, using Weakening:

Γ, x : B ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M N_{x} ↓ [N_{x}/x]C.

Using Proposition 4.1.7 and Corollary 2.2.11, we can show Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} [N_{x}/x]C =_{Eβη} C; hence

Γ, x : B ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M N_{x} ↓ C.

We apply the inductive hypothesis once again to get an object N such that

Γ, x : B ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M N_{x} ⇒_{η}^{∗} N

Γ, x : B ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N ⇓ C

Letting M′ = λx : B. N, we see M′ is as required, since

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} B ⇓ type Γ, x : B ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N ⇓ C B ⪯^{t} C}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} λx : B. N ⇓ Πx : B. C}

and

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒_{η} λx : B. (M x) ⇒_{η}^{∗} λx : B. (M N_{x}) ⇒_{η}^{∗} λx : B. N

Note that we can η-expand M since Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ↓ A, and therefore, in particular, M is not a λ. Lemma 4.2.3.

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : A implies ∃M_{⇓} s. t. Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒_{βη}^{∗} M_{⇓} and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{⇓} ⇓ A
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A : type implies ∃A_{⇓} s. t. Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇒_{βη}^{∗} A_{⇓} and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A_{⇓} ⇓ type

Proof. In the previous chapter, we have shown that β-reduction is strongly normalizing and Church-Rosser. Hence every object and type family reduces to its (unique) β-normal form. Since ⇒_{β} ⊆ ⇒_{βη}, without loss of generality, we will assume M and A in β-normal form.

We will prove the first of the two statements; the proof of the second is similar.

Let <_{M} the partial order defined by Theorem 3.4.1: we will show, by well-founded induction on <_{M}, that all well-formed objects N ≤_{M} M and types B <_{M} M have corresponding canonical objects N_{⇓} and B_{⇓}.

The only interesting case is with N application object. Since N is β-normal, N = c N_{1} … N_{m} or N = x N_{1} … N_{m}; we will assume, without loss of generality, the latter.

Γ(M, N) ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} x N_{1} … N_{m} : type(Γ(M, N))

Since N_{i} <_{M} N, by inductive hypothesis, there are canonical objects (N_{i})_{⇓} for every i = 1, …, m. We can therefore construct a derivation of

Γ(M, N) ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} x (N_{1})_{⇓} … (N_{m})_{⇓} ↓ type(Γ(M, N))

where

Γ(M, N) ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N ⇒_{η}^{∗} x (N_{1})_{⇓} … (N_{m})_{⇓}

By the properties of the partial order <_{M}, there is a β-normal type C such that C < N and

Γ(M, N) ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N : C

By inductive hypothesis, there is a type C_{⇓} such that

Γ(M, N) ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} C_{⇓} ⇓ type

Γ(M, N) ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} C ⇒_{η}^{∗} C_{⇓}

Hence, by type conversion

Γ(M, N) ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} x (N_{1})_{⇓} … (N_{m})_{⇓} ↓ C_{⇓}

and one application of Proposition 4.2.2 concludes the proof.

Corollary 4.2.4.

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : A, and M (⇒_{βη})-normal form implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇓ A
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A : type, and A (⇒_{βη})-normal form implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇓ type

Proof. Assume M as in the statement, by Lemma 4.2.3 there is M_{⇓} such that

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{⇓} ⇓ A

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒_{βη}^{∗} M_{⇓}

By normality of M we conclude M = M_{⇓}. The proof of the second statement is similar.

4.3 λ-Equivalence

Now we would like to prove that ⇒_{βη} is Church-Rosser, and ultimately that the canonical objects given by Lemma 4.2.3 are unique. Unfortunately, this is not the case, and it can be shown that Church-Rosser fails even on ⇒_{η} alone.

Consider, for example, the critical pair

\xymatrix{ & M \ar@{=>}[dl]_{η} \ar@{=>}[dr]^{η} \\ λx : A_{1}. (M x) &  & λx : A_{2}. (M x)}

Using the definitions and Type Uniqueness, we conclude in this case

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A_{i} ⇓ type

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A_{1} =_{Eβη} A_{2}

In converting from A_{1} to A_{2}, we may have used the equations in E several times, and thus it is possible that no common reduct of these two types can be found by using β-reduction and η-expansion alone.

From this example, we see that the best that we can hope to achieve is to prove the Church-Rosser Property modulo a relation ≈ that relates objects obtained one from the other by converting the types of the λ-abstracted variables. We will show that this is the case, and prove uniqueness of canonical forms modulo such a relation.

Definition 4.3.1. We define the following judgments:

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ≈_{E′} M′ M and M′ are E′λ-equivalent objects
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ≈_{E′} A′ A and A′ are E′λ-equivalent type families

formed according to the inference system shown in Figure 4.3.

We list below a few basic properties of these new judgments. The proofs are easily obtained arguing by induction on the derivations.

Proposition 4.3.2.

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ≈_{E′} M′ implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M =_{E′βη} M′
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ≈_{E′} A′ implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A =_{E′βη} A′

Proof. The proof is quite straightforward. The only interesting case is

• Case

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A =_{Eβη} A′ Γ, x : A ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : B}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} λx : A. M ≈_{E′} λx : A′. M}

Note that this case is not trivial, since in general E′ ⊊ E. We use a variant of the Nederpelt counterexample [52]. We show

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} λx : A. M =_{E′βη} λx : A′. (λx : A. M) x

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} λx : A′. (λx : A. M) x =_{E′βη} λx : A′. M

and the result follows by transitivity.

Proposition 4.3.3 (Weakening). Let Σ ⊆ Σ′, E′′ ⊆ E ⊆ E′, E′′ ⊆ E′′′ ⊆ E′, Γ ⊆ Γ′,

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ≈_{E′′} M′ implies Γ′ ⊢\begin{matrix}≺ \\ Σ′,E′ \end{matrix} M ≈_{E′′′} M′
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ≈_{E′′} A′ implies Γ′ ⊢\begin{matrix}≺ \\ Σ′,E′ \end{matrix} A ≈_{E′′′} A′

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : A}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ≈_{E′} M}  \frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ≈_{E′} M′}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′ ≈_{E′} M}  \frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ≈_{E′} M′ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′ ≈_{E′} M′′}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ≈_{E′} M′′}

\frac{(Δ ⊢\begin{matrix}≺ \\ Σ \end{matrix} M_{∘} = N_{∘} : A_{∘}) ∈ E′ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ : Δ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M =_{βη} θM_{∘} Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N =_{βη} θN_{∘}}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ≈_{E′} N}

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A =_{Eβη} A′ Γ, x : A ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : B}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} λx : A. M ≈_{E′} λx : A′. M}  \frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A : type Γ, x : A ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ≈_{E′} M′}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} λx : A. M ≈_{E′} λx : A. M′}
\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ≈_{E′} M′ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N : B}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M N ≈_{E′} M′ N}  \frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : Πx : A. B Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N ≈_{E′} N′}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M N ≈_{E′} M N′}
\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A : K}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ≈_{E′} A}  \frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ≈_{E′} A′}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A′ ≈_{E′} A}  \frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ≈_{E′} A′ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A′ ≈_{E′} A′′}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ≈_{E′} A′′}
\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ≈_{E′} A′ Γ, x : A ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} B : type}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} Πx : A. B ≈_{E′} Πx : A′. B}  \frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A : type Γ, x : A ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} B ≈_{E′} B′}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} Πx : A. B ≈_{E′} Πx : A. B′}
\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ≈_{E′} A′ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : B}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A M ≈_{E′} A′ M}  \frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A : Πx : B. K Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ≈_{E′} M′}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A M ≈_{E′} A M′}

Figure 4.3: Rules for E′λ-Equivalence

Proposition 4.3.4 (Substitution). Let Γ_{1} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N : C,

Γ_{1}, x : C, Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ≈_{E′} M′ implies Γ_{1}, [N/x]Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} [N/x]M ≈_{E′} [N/x]M′
Γ_{1}, x : C, Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ≈_{E′} A′ implies Γ_{1}, [N/x]Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} [N/x]A ≈_{E′} [N/x]A′

Proposition 4.3.5. Let Γ_{1} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} C =_{E′βη} C′ : type,

Γ_{1}, x : C, Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ≈_{E′} M′ implies Γ_{1}, x : C′, Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ≈_{E′} M′
Γ_{1}, x : C, Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ≈_{E′} A′ implies Γ_{1}, x : C′, Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ≈_{E′} A′

Proposition 4.3.6. Let Γ_{1} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N : C and Γ_{1} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N ≈_{E′} N′

Γ_{1}, x : C, Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : A implies Γ_{1}, [N/x]Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} [N/x]M ≈_{E′} [N′/x]M
Γ_{1}, x : C, Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A : K implies Γ_{1}, [N/x]Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} [N/x]A ≈_{E′} [N′/x]A

4.4 Confluence Modulo ≈

Finally, in this section we will show that ⇒_{βη} is confluent modulo this newly introduced equivalence relation. In order to do this, however, we have first to relativize all our reduction notions to ≈_{E′}: Definition 4.4.1. We define β-reduction and η-expansion modulo E′λ-equivalence by means of the judgments

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒_{β/≈_{E′}} M′ M β-reduces to M′ modulo E′λ-equivalence
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇒_{β/≈_{E′}} A′  A β-reduces to A′ modulo E′λ-equivalence
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒_{η/≈_{E′}} M′ M η-expands to M′ modulo E′λ-equivalence
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇒_{η/≈_{E′}} A′  A η-expands to A′ modulo E′λ-equivalence
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒^{I}_{η/≈_{E′}} M′ M η-expands internally to M′ modulo E′λ-equivalence
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇒^{I}_{η/≈_{E′}} A′  A η-expands internally to A′ modulo E′λ-equivalence

defined as

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒_{β/≈_{E′}} M′ iff ∃N, N′ s. t. \begin{cases}Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ≈_{E′} N \\ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N ⇒_{β} N′ \\ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N′ ≈_{E′} M′ \end{cases} and not Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ≈_{E′} M′

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇒_{β/≈_{E′}} A′ iff ∃B, B′ s. t. \begin{cases}Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ≈_{E′} B \\ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} B ⇒_{β} B′ \\ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} B′ ≈_{E′} A′ \end{cases} and not Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ≈_{E′} A′

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒_{η/≈_{E′}} M′ iff ∃N, N′ s. t. \begin{cases}Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ≈_{E′} N \\ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N ⇒_{η} N′ \\ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N′ ≈_{E′} M′ \end{cases} and not Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ≈_{E′} M′

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇒_{η/≈_{E′}} A′ iff ∃B, B′ s. t. \begin{cases}Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ≈_{E′} B \\ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} B ⇒_{η} B′ \\ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} B′ ≈_{E′} A′ \end{cases} and not Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ≈_{E′} A′

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒^{I}_{η/≈_{E′}} M′ iff ∃N, N′ s. t. \begin{cases}Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ≈_{E′} N \\ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N ⇒^{I}_{η} N′ \\ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N′ ≈_{E′} M′ \end{cases} and not Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ≈_{E′} M′

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇒^{I}_{η/≈_{E′}} A′ iff ∃B, B′ s. t. \begin{cases}Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ≈_{E′} B \\ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} B ⇒^{I}_{η} B′ \\ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} B′ ≈_{E′} A′ \end{cases} and not Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ≈_{E′} A′

Moreover, we let

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒_{βη/≈_{E′}} M′ iff Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒_{β/≈_{E′}} M′ or Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒_{η/≈_{E′}} M′
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇒_{βη/≈_{E′}} A′ iff Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇒_{β/≈_{E′}} A′ or Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇒_{η/≈_{E′}} A′

Finally, we define the judgments

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇔_{β/≈_{E′}} M′ M is (⇒_{βη/≈_{E′}})-convertible to M′
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇔_{β/≈_{E′}} A′  A is (⇒_{βη/≈_{E′}})-convertible to A′

constructed from the rules

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ≈_{E′} M′}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇔_{βη/≈_{E′}} M′}  \frac{Γ ⊢\begin{matrix}≺ \\ Σ \end{matrix} M ⇒_{β≈_{E′}} M′}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇔_{βη/≈_{E′}} M′}  \frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒_{η/≈_{E′}} M′}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇔_{βη/≈_{E′}} M′}

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇔_{βη/≈_{E′}} M′}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′ ⇔_{βη/≈_{E′}} M}  \frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇔_{βη/≈_{E′}} M′ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′ ⇔_{βη/≈_{E′}} M′′}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇔_{βη/≈_{E′}} M′′}

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ≈_{E′} A′}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇔_{βη/≈_{E′}} A′}  \frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇒_{β/≈_{E′}} A′}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇔_{βη/≈_{E′}} A′}  \frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇒_{η/≈_{E′}} A′}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇔_{βη/≈_{E′}} A′}

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇔_{βη/≈_{E′}} A′}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A′ ⇔_{βη/≈_{E′}} A}  \frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇔_{βη/≈_{E′}} A′ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A′ ⇔_{βη/≈_{E′}} A′′}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇔_{βη/≈_{E′}} A′′}

Not surprisingly, E′βη-conversion coincides with ⇔_{βη/≈_{E′}}, as the following sequence of results will show. Proposition 4.4.2. Let Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : Πx : A. B. Then

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇔_{βη/≈} λx : A. (M x)

Proof. We distinguish between two mutually disjoint cases:

• M is not a λ

By Type Consistency and inversion, Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A : type, and by Lemma 4.2.3, there is a type A_{⇓} such that

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A_{⇓} ⇓ type

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇒_{βη}^{∗} A_{⇓}

Using Proposition 4.1.7 and Corollary 2.2.4, by type conversion we show Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : Πx : A_{⇓}. B; hence

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒_{η} λx : A_{⇓}. (M x)

Also, notice that

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} λx : A. (M x) ≈ λx : A_{⇓}. (M x)

and, consequently,

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒_{η/≈} λx : A. (M x).

• M = λx : A′. M′ By inversion, from the derivation of Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : Πx : A. B we can extract a derivation of Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A =_{Eβη} A′. Hence

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} λx : A. (M x) ≈ λx : A′. (M x)

and the result follows since λx : A. (M x) →_{β} M.

Proposition 4.4.3.

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒_{η} M′ implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M N ⇒_{η} M′ N or M′ N →_{β} M N
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇒_{η} A′ implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A M ⇒_{η} A′ M or A′ M →_{β} A M

Proof. We will prove the first of the two statements; the proof of the second one is similar. If we can show Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒^{I}_{η} M′ we are done, since we have

\frac{\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒^{I}_{η} M′}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M N ⇒^{I}_{η} M′ N}}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M N ⇒_{η} M′ N}

The only case in which Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒^{I}_{η} M′ does not hold is when the last rule in the derivation is the restricted η-expansion:

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : Πx : A. B Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} Πx : A. B M not a λ}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒_{η} λx : A. (M x)}

In this case we see M′ = λx : A. (M x), and therefore M′ N →_{β} M N, which concludes the proof.

Theorem 4.4.4. Let M, M′ and A, A′ well-formed terms, then

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M =_{E′βη} M′ iff Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇔_{βη/≈_{E′}} M′
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A =_{E′βη} A′ iff Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇔_{βη/≈_{E′}} A′

Proof. Both directions are proved by induction on the derivations. One is trivial; in the other there are a few cases which deserve some attention:

• Case

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : Πx : A. B}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M =_{E′βη} λx : A. (M x)}

From Proposition 4.4.2 we have immediately Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇔_{βη/≈_{E′}} λx : A. (M x).

• Case

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M =_{E′βη} M′ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N : B}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M N =_{E′βη} M′ N}

By inductive hypothesis, we have a derivation of Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇔_{βη/≈_{E′}} M′. We recursively transform this into a derivation of Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M N ⇔_{βη/≈_{E′}} M′ N. The only non-trivial step is when we encounter an application of the rule

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} P ⇒_{η/≈_{E′}} P′}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} P ⇔_{βη/≈_{E′}} P′}

In this case, to obtain a derivation of Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} P N ⇔_{βη/≈_{E′}} P′ N we apply Proposition 4.4.3.

We now investigate the properties of β-reduction and η-expansion modulo E′λ-equivalence. For both, ≈_{E′}-postponement is easily shown:

Lemma 4.4.5. Let M and A be well-formed, the following holds:

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ≈_{E′} M_{1}, Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒_{β} M_{2} implies ∃N s. t. Γ ⊢^{≺} M_{2} ≈_{E′} N and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{1} ⇒_{β}^{=} N
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ≈_{E′} A_{1}, Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇒_{β} A_{2} implies ∃B s. t. Γ ⊢^{≺} A_{2} ≈_{E′} B and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A_{1} ⇒_{β}^{=} B

Moreover, M_{1} = N iff Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ≈_{E′} M_{2}, and A_{1} = B iff Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ≈_{E′} A_{2}.

Proof. By induction on the derivations, using Propositions 4.3.4 and 4.3.6.

This is the place where we use the assumption that the equations in E are all of base type, as we rule out situations where

M = (λx : C. M′) P →_{β} [P/x]M′ = M_{2},

and M_{1} = M′_{1} P, with

\frac{(Δ ⊢\begin{matrix}≺ \\ Σ \end{matrix} M_{∘} = N_{∘} : A_{∘}) ∈ E′ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ : Δ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} (λx : C. M′) =_{βη} θM_{∘} Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′_{1} =_{βη} θN_{∘}}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} (λx : C. M′) ≈_{E′} M′_{1}}

for which the statement may not hold.

Corollary 4.4.6. For all well-formed objects M and type families A, the following holds:

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒_{β/≈_{E′}} M′ implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒_{β} N and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N ≈_{E′} M′ for some N
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇒_{β/≈_{E′}} A′ implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇒_{β} B and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} B ≈_{E′} A′ for some B

In pictures:

[figure: M; β/≈_{E′}; β; M′; N; ≈_{E′}; A; β/≈_{E′}; β; A′; B; ≈_{E′}]

Proof. Immediate by the definitions and Lemma 4.4.5. Lemma 4.4.7. We have

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ≈_{E′} M_{1}, Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒_{η} M_{2} implies ∃N s. t. Γ ⊢^{≺} M_{2} ≈_{E′} N and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{1} ⇒_{η}^{=} N
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ≈_{E′} A_{1}, Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇒_{η} A_{2} implies ∃B s. t. Γ ⊢^{≺} A_{2} ≈_{E′} B and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A_{1} ⇒_{η}^{=} B

Moreover, M_{1} = N iff Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ≈_{E′} M_{2}, and A_{1} = B iff Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ≈_{E′} A_{2}.

Proof. By induction on the derivations, similar to the proof of Lemma 4.4.5. Corollary 4.4.8. The following holds:

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒_{η/≈_{E′}} M′ implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒_{η} N and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N ≈_{E′} M′ for some N
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇒_{η/≈_{E′}} A′ implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇒_{η} B and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} B ≈_{E′} A′ for some B

Graphically:

[figure: M; η/≈_{E′}; η; M′; N; ≈_{E′}; A; η/≈_{E′}; η; A′; B; ≈_{E′}]

Proof. Immediate by Lemma 4.4.7.

Corollary 4.4.6 allows us to lift immediately most of the results proved in the previous chapter for →_{β} to ⇒_{β/≈_{E′}}: Lemma 4.4.9. The relation ⇒_{β/≈_{E′}} is Church-Rosser on well-formed objects and type families, i.e.

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒_{β/≈_{E′}} M_{i} (i = 1, 2) implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{i} ⇒_{β/≈_{E′}} N for some N
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇒_{β/≈_{E′}} A_{i} (i = 1, 2) implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A_{i} ⇒_{β/≈_{E′}} B for some B

where Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : C and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A : K for some suitable C and K.

In pictures, the following diagrams hold:

\xymatrix{M \ar@{=>}[r]^{(β/≈_{E′})^{∗}} \ar@{=>}[d]_{(β/≈_{E′})^{∗}} & M_{1} \ar@{=>}[d]^{(β/≈_{E′})^{∗}} & A \ar@{=>}[r]^{(β/≈_{E′})^{∗}} \ar@{=>}[d]_{(β/≈_{E′})^{∗}} & A_{1} \ar@{=>}[d]^{(β/≈_{E′})^{∗}} \\ M_{2} \ar@{=>}[r]_{(β/≈_{E′})^{∗}} & N & A_{2} \ar@{=>}[r]_{(β/≈_{E′})^{∗}} & B}

Proof. The result is easily obtained from Theorem 3.3.2 and Corollary 4.4.6 by diagram chasing:

[figure: M; (β/≈_{E′})^{∗}; (β/≈_{E′})^{∗}; β^{∗}; β^{∗}; M_{1}; ≈_{E′}; (β/≈_{E′})^{∗}; M′_{1}; β^{∗}; M′_{2}; β^{∗}; M_{2}; ≈_{E′}; (β/≈_{E′})^{∗}; N; A; (β/≈_{E′})^{∗}; (β/≈_{E′})^{∗}; β^{∗}; β^{∗}; A_{1}; ≈_{E′}; (β/≈_{E′})^{∗}; A′_{1}; β^{∗}; A′_{2}; β^{∗}; A_{2}; ≈_{E′}; (β/≈_{E′})^{∗}; B]

Lemma 4.4.10. The relation ⇒_{β/≈_{E′}} is strongly normalizing on well-formed objects and type families. Proof. Assume Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : A and an infinite reduction sequence starting from M = M_{0}:

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{0} ⇒_{β/≈_{E′}} M_{1} ⇒_{β/≈_{E′}} M_{1} ⇒_{β/≈_{E′}} M_{1} ⇒_{β/≈_{E′}} … ⇒_{β/≈_{E′}} M_{n} ⇒_{β/≈_{E′}} M_{n+1} ⇒_{β/≈_{E′}} …

Using repeatedly Corollary 4.4.6 we construct an infinite β-reduction sequence

M = M′_{0} →_{β} M′_{1} →_{β} … →_{β} M′_{n} →_{β} M′_{n+1} →_{β} …,

a contradiction to Theorem 3.3.10.

When considering terms modulo λ-equivalence, η-expansions can be easily shown to be Church-Rosser: Lemma 4.4.11.

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒_{η} M_{i} (i = 1, 2) implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{i} ⇒_{η}^{=} N_{i} for some N_{i} (i = 1, 2) s. t. Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N_{1} ≈ N_{2}
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒^{I}_{η} M_{i} (i = 1, 2) implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{i} ⇒^{I}_{η}^{=} N_{i} for some N_{i} (i = 1, 2) s. t. Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N_{1} ≈ N_{2}
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇒_{η} A_{i} (i = 1, 2) implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A_{i} ⇒_{η}^{=} B_{i} for some B_{i} (i = 1, 2) s. t. Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} B_{1} ≈ B_{2}
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇒^{I}_{η} A_{i} (i = 1, 2) implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A_{i} ⇒^{I}_{η}^{=} B_{i} for some B_{i} (i = 1, 2) s. t. Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A_{1} ≈ A_{2}

Proof. By induction on the derivations, keeping track of where the η-expansions take place.

The main case is

Γ ⊢\begin{matrix}≺ \\ Σ \end{matrix} M ⇒_{η} λx : A_{i}. (M x) (i = 1, 2)

where, by Uniqueness of Types, we have Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A_{1} =_{Eβη} A_{2}, and therefore

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} λx : A_{1}. (M x) ≈ λx : A_{2}. (M x)

Corollary 4.4.12. Restricted η-expansion modulo E′λ-equivalence is Church-Rosser:

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒_{η/≈_{E′}} M_{i} (i = 1, 2) implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{i} ⇒_{η/≈_{E′}} N (i = 1, 2) for some N
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇒_{η/≈_{E′}} A_{i} (i = 1, 2) implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A_{i} ⇒_{η/≈_{E′}} B (i = 1, 2) for some B

In pictures:

\xymatrix{M \ar@{=>}[r]^{(η/≈_{E′})^{∗}} \ar@{=>}[d]_{(η/≈_{E′})^{∗}} & M_{1} \ar@{=>}[d]^{(η/≈_{E′})^{∗}} & A \ar@{=>}[r]^{(η/≈_{E′})^{∗}} \ar@{=>}[d]_{(η/≈_{E′})^{∗}} & A_{1} \ar@{=>}[d]^{(η/≈_{E′})^{∗}} \\ M_{2} \ar@{=>}[r]_{(η/≈_{E′})^{∗}} & N & A_{2} \ar@{=>}[r]_{(η/≈_{E′})^{∗}} & B}

Proof. We first show the following, using Lemma 4.4.11:

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒_{η/≈_{E′}} M_{i} (i = 1, 2) implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{i} ⇒_{η/≈_{E′}}^{=} N (i = 1, 2) for some N
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇒_{η/≈_{E′}} A_{i} (i = 1, 2) implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A_{i} ⇒_{η/≈_{E′}}^{=} B (i = 1, 2) for some B

that is, in pictures:

\xymatrix{M \ar@{=>}[r]^{η/≈_{E′}} \ar@{=>}[d]_{η/≈_{E′}} & M_{1} \ar@{=>}[d]^{(η/≈_{E′})^{=}} & A \ar@{=>}[r]^{η/≈_{E′}} \ar@{=>}[d]_{η/≈_{E′}} & A_{1} \ar@{=>}[d]^{(η/≈_{E′})^{=}} \\ M_{2} \ar@{=>}[r]_{(η/≈_{E′})^{=}} & N & A_{2} \ar@{=>}[r]_{(η/≈_{E′})^{=}} & B}

Then, using the above, we prove the statement by induction on the length of the expansion sequences. In order to prove the Church-Rosser Property for ⇒_{βη/≈_{E′}} we will make use of the following:

Lemma 4.4.13. Let →_{R} and →_{S} two relations that are both Church-Rosser. Assume, moreover, that →_{R} is strongly normalizing and that the following diagram holds:

\xymatrix{X \ar[r]^{R} \ar[d]_{S} & X_{1} \ar@{-->}[d]^{S^{∗}} \\ X_{2} \ar@{-->}[r]_{R^{+}} & Y}

Then the relation

→_{RS}=→_{R} ∪ →_{S}

is Church-Rosser:

\xymatrix{X \ar[r]^{(RS)^{∗}} \ar[d]_{(RS)^{∗}} & X_{1} \ar@{-->}[d]^{(RS)^{∗}} \\ X_{2} \ar@{-->}[r]_{(RS)^{∗}} & Y}

Proof. This fact can be proved in the very general setting of the Combinatory Reduction Systems (CRSs) defined by Klop in [36]. A proof is given by R. Di Cosmo in [12].

We want to instantiate R with ⇒_{β/≈_{E′}} and S with ⇒_{η/≈_{E′}} above. In order to do so, however, one final result, i.e. the commutativity of the diagram above, is left to prove.

Proposition 4.4.14. If Γ_{1} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N : C then

Γ_{1}, x : C, Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒_{η} M′ implies Γ_{1}, [N/x]Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} [N/x]M ⇒_{η/≈} [N/x]M′
Γ_{1}, x : C, Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒^{I}_{η} M′ implies Γ_{1}, [N/x]Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} [N/x]M ⇒^{I}_{η/≈} [N/x]M′
Γ_{1}, x : C, Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇒_{η} A′ implies Γ_{1}, [N/x]Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} [N/x]A ⇒_{η/≈} [N/x]A′
Γ_{1}, x : C, Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇒^{I}_{η} A′ implies Γ_{1}, [N/x]Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} [N/x]A ⇒^{I}_{η/≈} [N/x]A′

Proof. By simultaneous induction on the derivations. Non-internal expansions are using Lemma 4.2.3.

Proposition 4.4.15. Let Γ_{1} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N : C and Γ_{1} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N ⇒^{I}_{η} N′, then

Γ_{1}, x : C, Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : A implies Γ_{1}, [N/x]Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} [N/x]M ⇒^{I}_{η}^{∗} [N′/x]M
Γ_{1}, x : C, Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A : K implies Γ_{1}, [N/x]Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} [N/x]A ⇒^{I}_{η}^{∗} [N′/x]A

Proof. By a straightforward induction on the derivations.

Proposition 4.4.16. Let

Γ_{1} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N : Πz : A. B

Γ_{1} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} Πz : A. B ⇓ type,

then

Γ_{1}, x : Πz : A. B, Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : C implies ∃P s. t. \begin{cases}[(λz : A. (N z))/x]M →_{β}^{∗} P \\ Γ_{1}, [N/x]Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} [N/x]M ⇒^{I}_{η}^{∗} P \end{cases}

Γ_{1}, x : Πz : A. B, Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} C : K implies ∃D s. t. \begin{cases}[(λz : A. (N z))/x]C →_{β}^{∗} D \\ Γ_{1}, [N/x]Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} [N/x]C ⇒^{I}_{η}^{∗} D \end{cases}

Proof. By induction on the derivations of Γ_{1}, x : Πz : A. B, Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : C and Γ_{1}, x : Πz : A. B, Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} C : K. We show a few interesting cases:

• Case

\frac{Γ_{1}, x : Πz : A. B, Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} x : Πz : A′. B′ Γ_{1}, x : Πz : A. B, Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′ : B′}{Γ_{1}, x : Πz : A. B, Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} x M′ : [M′/x]B′}

By inductive hypothesis we have an object P′ such that

[(λz : A. (N z))/x]M′ →_{β}^{∗} P′

Γ_{1}, [N/x]Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} [N/x]M′ ⇒^{I}_{η}^{∗} P′

We see then P = N P′ is as required since

[(λz : A. (N z))/x]M = (λz : A. (N z)) M′ →_{β} N M′ →_{β}^{∗} N P′

and

Γ_{1}, [N/x]Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} [N/x]M ⇒^{I}_{η}^{∗} N P′

• Case

\frac{Γ_{1}, x : Πz : A. B, Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A′ : type Γ_{1}, x : Πz : A. B, Γ_{2}, y : A′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′ : B′ A′ ⪯^{t} B′}{Γ_{1}, x : Πz : A. B, Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} λy : A′. M′ : Πy : A′. B′}

Applying the inductive hypothesis twice we get D′ and P′ such that [(λz : A. (N z))/x]A′ →_{β}^{∗} D′ [(λz : A. (N z))/x]M′ →_{β}^{∗} P′

Γ_{1}, [N/x]Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} [N/x]A′ ⇒^{I}_{η}^{∗} D′

Γ_{1}, [N/x]Γ_{2}, y : [N/x]A′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} [N/x]M′ ⇒^{I}_{η}^{∗} P′

We observe that [(λz : A. (N z))/x](λy : A. M′) →_{β}^{∗} λy : D′. [(λz : A. (N z))/x]M′ →_{β}^{∗} λy : D′. P′

Γ_{1}, [N/x]Γ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} [N/x]M ⇒^{I}_{η}^{∗} λy : [N/x]A′. P′ ⇒^{I}_{η}^{∗} λy : D′. P′

Lemma 4.4.17. Let M and A well-formed objects and type families, respectively; then

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒_{η} M_{1} and M →_{β} M_{2} implies ∃N s. t. M_{1} →_{β}^{+} N and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{2} ⇒_{η/≈}^{∗} N
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒^{I}_{η} M_{1} and M →_{β} M_{2} implies ∃N s. t. M_{1} →_{β}^{+} N and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{2} ⇒^{I}_{η/≈}^{∗} N
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇒_{η} A_{1} and A →_{β} A_{2} implies ∃B s. t. A_{1} →_{β}^{+} B and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A_{2} ⇒_{η/≈}^{∗} B
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇒^{I}_{η} A_{1} and A →_{β} A_{2} implies ∃B s. t. A_{1} →_{β}^{+} B and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A_{2} ⇒^{I}_{η/≈}^{∗} B

Proof. By simultaneous induction on the derivations. The two main cases are: • Case:

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} λx : C. M ⇒^{I}_{η} λx : C. M′ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N : B}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} (λx : C. M) N ⇒^{I}_{η} (λx : C. M′) N}

By inversion, we get a derivation of Γ, x : C ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒_{η} M′, and the result follows from Proposition 4.4.14.

• Case:

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} λx : C. M : Πx : C′. D Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N ⇒_{η} N′}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} (λx : C. M) N ⇒^{I}_{η} (λx : C.M) N′}

We inspect the last rule used in the derivation of Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N ⇒_{η} N′. If it is the restricted η-expansion

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N : Πx : A. B Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇓ type N not a λ}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N ⇒_{η} λx : A. (N x)}

we use Proposition 4.4.15. Otherwise Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N ⇒^{I}_{η} N′ holds, and the result follows from Proposition 4.4.16.

Corollary 4.4.18. Let M and A well-formed, the following holds:

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒_{β/≈_{E′}} M_{1} and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒_{η/≈_{E′}} M_{2} implies ∃N s. t. \begin{cases}Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{1} ⇒_{η/≈_{E′}}^{∗} N \\ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{2} ⇒_{β/≈_{E′}}^{+} N \end{cases}
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇒_{β/≈_{E′}} A_{1} and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇒_{η/≈_{E′}} A_{2} implies ∃B s. t. \begin{cases}Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A_{1} ⇒_{η/≈_{E′}}^{∗} B \\ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A_{2} ⇒_{β/≈_{E′}}^{+} B \end{cases}

In pictures, the following diagrams hold:

\xymatrix{M \ar@{=>}[r]^{β/≈_{E′}} \ar@{=>}[d]_{η/≈_{E′}} & M_{1} \ar@{-->}[d]^{(η/≈_{E′})^{∗}} & A \ar@{=>}[r]^{β/≈_{E′}} \ar@{=>}[d]_{η/≈_{E′}} & A_{1} \ar@{=>}[d]^{(η/≈_{E′})^{∗}} \\ M_{2} \ar@{=>}[r]_{(β/≈_{E′})^{+}} & N & A_{2} \ar@{=>}[r]_{(β/≈_{E′})^{+}} & B}

Proof. It follows immediately from Lemmas 4.4.17, 4.4.5, and 4.4.7.

We have now all the tools needed to prove the most important results of this chapter: Theorem 4.4.19. On well-formed terms, the relation ⇒_{βη} is Church-Rosser modulo λ-equivalence, i.e.

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒_{βη}^{∗} M_{i} (i = 1, 2) implies ∃N_{1}, N_{2} s. t. Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{i} ⇒_{βη}^{∗} N_{i} (i = 1, 2) and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N_{1} ≈ N_{2}
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇒_{βη}^{∗} A_{i} (i = 1, 2) implies ∃B_{1}, B_{2} s. t. Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A_{i} ⇒_{βη}^{∗} B_{i} (i = 1, 2) and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} B_{1} ≈ B_{2}

Graphically:

[figure: M; (βη)^{∗}; (βη)^{∗}; M_{1}; (βη)^{∗}; N_{1}; ≈; M_{2}; (βη)^{∗}; N_{2}; A; (βη)^{∗}; (βη)^{∗}; A_{1}; (βη)^{∗}; B_{1}; ≈; A_{2}; (βη)^{∗}; B_{2}]

Proof. Applying Lemma 4.4.13 with R = (β/ ≈) and S = (η/ ≈) we conclude that ⇒_{βη/≈} is Church-Rosser. The result then follows from Corollaries 4.4.6 and 4.4.8. Theorem 4.4.20. For all well-formed types M_{i} (i = 1, 2), and type families A_{i} (i = 1, 2), the following holds:

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{1} =_{E′βη} M_{2} implies ∃N_{1}, N_{2} s. t. Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{i} ⇒_{βη}^{∗} N_{i} (i = 1, 2) and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N_{1} ≈_{E′} N_{2}
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A_{1} =_{E′βη} A_{2} implies ∃B_{1}, B_{2} s. t. Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A_{i} ⇒_{βη}^{∗} B_{i} (i = 1, 2) and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} B_{1} ≈_{E′} B_{2}

Proof. Using the assumption and Theorem 4.4.4, we construct derivations of

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{1} ⇔_{βη/≈_{E′}} M_{2}

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A_{1} ⇔_{βη/≈_{E′}} A_{2}

We argue by induction on these. The only interesting case is transitivity:

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{1} ⇔_{βη/≈_{E′}} M′ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′ ⇔_{βη/≈_{E′}} M_{2}}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{1} ⇔_{βη/≈_{E′}} M_{2}}

whose proof is given by the following diagram:

[figure: M_{1}; βη/≈_{E′}; (βη)^{∗}; M′; βη/≈_{E′}; (βη)^{∗}; (βη)^{∗}; M_{2}; (βη)^{∗}; P_{1}; (βη)^{∗}; ≈_{E′}; P_{2}; (βη)^{∗}; P_{3}; (βη)^{∗}; ≈_{E′}; P_{4}; (βη)^{∗}; N_{1}; ≈_{E′}; N_{2}; ≈; N_{3}; ≈_{E′}; N_{4}]

Existence of the P_{i} is ensured by the inductive hypothesis, while the N_{i} are given by Theorem 4.4.19 and ≈-postponement (Lemmas 4.4.5 and 4.4.7).

Corollary 4.4.21. Canonical forms are unique modulo ≈.

Proof. Let Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : A, and assume

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒_{βη} N_{i} (i = 1, 2)

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N_{i} ⇓ A (i = 1, 2)

By Proposition 4.1.7, we conclude

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N_{1} =_{βη} N_{2}

and the result follows from Theorem 4.4.20 and Lemma 4.2.1 by letting E′ = ·.

4.5 Summary

The study of η-expansion is more delicate in LF than it is in the simply-typed lambda calculus. As usual, new problems arise from having objects appearing inside types. Here, the type used in the η-expansion may contain unexpanded objects; expanding those, in turn, may introduce new expressions to be expanded, and so on. To ensure the well-founded character of expansion, we need to impose additional conditions; specifically, we require the types used in η-expansion to be normal. To avoid circularity in our definitions, we give two distinct characterizations of normality: one is syntactic, and defines as normal those terms that can be derived through a given typing judgment; the other is the traditional one, operational, that identifies normal forms as those expressions that cannot further expanded. Both of these were introduced in Section 4.1, and proved equivalent in Section 4.2.

As we started analyzing this newly introduced η-expansion relation, another feature of the language got in the way. Because of the presence of E-conversion of types, η-expansion is not confluent in general. The best we could hope for was to prove confluence modulo an equivalence relation ≈ that identifies those terms obtained by Eβη-converting the types of the λ-abstracted variables. We defined this equivalence relation in Section 4.3; confluence of β-reduction and η-expansion modulo ≈ was shown, not without substantial effort, in Section 4.4.

52

Part II Rewriting

53

Dependence Relations

Dependence relations, introduced in Chapter 2 as part of our calculus, will play an important role in defining rewriting in LF. We dedicate this chapter to an in-depth discussion of these relations, their motivation and fundamental properties.

5.1 Main Ideas

Central in the definition of a rewriting notion is the operation of replacement of a sub-term by another. For simply-typed theories, it can be easily shown that this operation preserves the well-typedness of the overall term, provided that the replaced sub-term has the same type as the original one.

This property unfortunately does not extend to dependent types, mainly because of the application rule

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : (Πx : A. B) Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N : A}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M N : [N/x]B}

that allows the argument N to be propagated inside the type. If we were to perform a replacement inside N, giving rise to a term N′, we would have to operate analogous replacements inside [N/x]B to transform it into [N′/x]B. Moreover, if this application term was part of a larger object U, its new type might turn out to be incompatible with its use inside U.

To illustrate concretely these problems, consider the following: Example 4. Consider the signature in Figure 5.1, representing a system to infer which natural numbers are even.

In this signature, the object

even_{+} 0 (0 + 0) even_{0} (even_{+} 0 0 even_{0} even_{0})

is well typed, but rewriting (0 + 0) → 0 : nat we get

even_{+} 0 0 even_{0} (even_{+} 0 0 even_{0} even_{0})

which is not.

We would like to therefore restrict replacement only to the cases where it is type-safe, and specifically in

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : Πx : A. B Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N : A}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M N : [N/x]B}

to allow replacement inside N only when we can guarantee x ∉ FV(B).

Of course, imposing the syntactic restriction x ∉ FV(B) would not work, since by Lemma 2.2.5, the type of an object is unique only modulo Eβη-conversion, and in most case we would able, through β-expansion, to “sneak in” the variable x. Restricting ourselves to canonical forms, i.e. requiring

x ∉ FV(B′) for all Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} B′ =_{Eβη} B such that Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} B′ ⇓ type

dom(Σ) = {nat, 0, s, +, o, even, proof, even_{0}, even_{ss}, even_{+}even_{s+}}

Σ(nat) = type Σ(0) = nat Σ(s) = Πx : nat. nat Σ(+) = Πx : nat. Πy : nat. nat

Σ(o) = type

Σ(even) = Πx : nat. o

Σ(proof) = Πx : o. type Σ(even_{0}) = proof (even 0) Σ(even_{ss}) = Πx : nat. Πp : proof(even x). proof(even (s (s x))) Σ(even_{+}) = Πx_{1} : nat. Πx_{2} : nat. Πp_{1} : proof(even x_{1}).

Πp_{2} : proof(even x_{2}). proof(even (x_{1} + x_{2}))

Σ(even_{s+}) = Πx_{1} : nat. Πx_{2} : nat. Πp_{1} : proof(even x_{1}). Πp_{2} : proof(even x_{2}). proof(even ((s x_{1}) + (s x_{2})))

Figure 5.1: Even Numbers

would not work either, since by Corollary 4.4.21 canonical forms are not unique, one obtainable from another by converting the types of the λ-abstracted variables.

Hence, we choose an approach more semantical in nature, making use of dependence relations. To explain the main ideas behind these, we refer back to Example 4. There, we define types o for formulas and nat for natural numbers. Objects of type o may contain some of type nat, as arguments of even. However, it would be “unnatural”, for our intended use of this signature, to have objects of type nat containing formulas on their inside. Dependence relations allow us to formally state “naturality” conditions for functional dependence, and enforce these using the typing judgments. Specifically, the relations ≺^{τ} and ≺^{t} are used with the following informal meaning

A ≺^{τ} B  objects of type A are allowed to appear inside type B
A ≺^{t} B  objects of type A are allowed to appear inside objects of type B

We enforce these requirements, for example, in the abstraction rule

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A : type Γ, x : A ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : B A ⪯^{t} B}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} λx : A. M : Πx : A. B}

by preventing functional objects violating our naturality conditions to be generated.

By Definition 2.1.3, dependence relations must be also be closed under some conditions. Informally, these ensure that some of the logical consequences of the naturality choices we decided to impose are also reflected in the dependence relation. We examine some of these conditions in detail:

• head(A_{i}) ≺^{τ} a if Σ(a) = Πx_{1} : A_{1}. Πx_{2} : A_{2}…. Πx_{n} : A_{n}. type

All base types P with head(P) = a are required to satisfy the naturality requirements:

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} a M_{1} M_{2} … M_{n} : type and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{i} : B_{i} implies B_{i} ≺^{τ} (a M_{1} M_{2} … M_{n})

• A ≺^{τ} A′ if A ≺^{t} B ≺^{τ} A′ for some B

This roughly corresponds to transitivity of containment. If objects of type B are allowed to appear inside A′, and objects of type A may appear inside objects of type B, in conclusion we allow objects of type A to appear inside type A′.

• A ≺^{t} A′ if A ≺^{t} B ≺^{t} A′ for some B

Also corresponding to transitivity of object containment.

5.2 General Properties

The informal discussion above is made precise by the following technical results:

Lemma 5.2.1.

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : A and N a sub-object of M, then type(Γ(M, N)) ⪯^{t} A
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A : K and N a sub-object of A, then type(Γ(A, N)) ≺^{τ} A

Proof. Both statement are proved simultaneously by induction on the derivations. We examine in detail a few interesting cases:

• Case

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A_{1} : Πx : B. K Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{2} : B}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A_{1} M_{2} : [M_{2}/x]K}

First, observe that head(A) = head(A_{1}), so it will suffice to show type(Γ(A, N)) ≺^{τ} A_{1}.

If N is a sub-object of A_{1}, the result follows by applying the inductive hypothesis to the derivation of

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A_{1} : Πx : B. K

If N is a sub-object of M_{2}, by inductive hypothesis on the derivation of

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{2} : B

we get type(Γ(A, N)) ⪯^{t} B.

Let a = head(A_{1}), and

Σ(a) = Πx_{1} : C_{1}. Πx_{2} : C_{2}. . . . . Πx_{n} : C_{n}. type

For some i, we see that it must be head(C_{i}) = head(B). We conclude B ≺^{τ} A_{1}, and from this the result follows, since

type(Γ(A, N)) ⪯^{t} B ≺^{τ} A_{1}

• Case

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A_{1} : type Γ, x : A_{1} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A_{2} : type A_{1} ⪯^{t} A_{2}}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} Πx : A_{1}. A_{2} : type}

Similarly to the previous case, if N is a sub-object of A_{2}, we are done by inductive hypothesis on the derivation of

Γ, x : A_{1} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A_{2} : type

since we observe head(Πx : A_{1}. A_{2}) = head(A_{2}).

Otherwise N is a sub-object of A_{1}, and we can apply the inductive hypothesis to

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A_{1} : type

to get type(Γ(A, N)) ≺^{τ} A_{1}, and hence the result:

type(Γ(A, N)) ≺^{τ} A_{1} ⪯^{t} A_{2}

• Case

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{1} : Πx : B. C Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{2} : B}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{1} M_{2} : [M_{2}/x]C}

If M = N, the result follows trivially. Also, if N is a sub-object of M_{1}, we are done by inductive hypothesis on the derivation of

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{1} : Πx : B. C

since head([M_{2}/x]C) = head(Πx : B. C). If N is contained into M_{2}, by the inductive hypothesis on

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{2} : B

we get type(Γ(M, N)) ⪯^{t} B. By Type Consistency, we get a derivation of

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} Πx : B. C : type

and by inversion on this derivation, we find B ⪯^{t} C. Hence

type(Γ(M, N)) ⪯^{t} B ⪯^{t} C

and we are done because head([M_{2}/x]C) = head(C).

• Case

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A_{1} : type Γx : A ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{2} : B A_{1} ⪯^{t} B}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} λx : A_{1}. M_{2} : Πx : A_{1}. B}

Notice that head(Πx : A_{1}. B) = head(B); hence, if N occurs inside M_{2} we are done by applying the inductive hypothesis on the derivation

Γ, x : A_{1} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{2} : B

On the other hand, if N occurs inside A_{1}, using the inductive assumptions on

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A_{1} : type

we conclude type(Γ(M, N)) ≺^{τ} A_{1}. Then type(Γ(M, N)) ≺^{t} A_{1}, and we conclude the proof of this case by applying transitivity of ≺^{t}:

type(Γ(M, N)) ≺^{t} A_{1} ⪯^{t} B

Corollary 5.2.2.

Γ, z : A_{∘}, Δ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : A, z ∈ FV(M) implies A_{∘} ⪯^{t} A

Γ, z : A_{∘}, Δ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A : K, z ∈ FV(A) implies A_{∘} ≺^{τ} A

Proof. Apply Lemma 5.2.1 to any of the free occurrences of z in the given terms.

5.3 Summary

Dependence relations were first introduced by us in [71] as a tool to define rewriting in a non-equational setting. They will used in a similar way here, but their role, as we will see, will be greatly expanded.

We gave in this chapter, first informally in Section 5.1 and then formally in Section 5.2, the intuition that lies behind their introduction.

60

Rewriting

In this chapter we will introduce our notion of rewriting. This is similar to the one employed in [71] for the non-equational calculus. Although, as we have seen in Chapter 4, uniqueness of canonical forms holds in a weaker form (i.e. modulo ≈), most of the results we proved in that paper lift to this equational version of LF.

6.1 Environments

Central in defining rewriting is the concept of contextual replacement of an expression with another. This is usually formalized in the literature by contexts, which are essentially “expression with a hole”: the hole indicates where the replacement takes place, while the rest of the expression is left unchanged. One little notational difficulty that we encounter here is that the name “context” is already used in standard LF literature to denote something different. Hence we are forced to choose a different name for these entities. We decided for “environment”, hoping that this choice will not confuse the reader too much.

Definition 6.1.1 (Environments). Environments are expressions defined by the following syntax:

Environments E := ∘ | E M | M E | λx : A. E

Well-formed environments are constructed using the judgment:

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[Γ_{∘} ⊢ ∘ : A_{∘}]] : A E is an environment of type A

formed according to the set of rules shown in Figure 6.1.

Remark. Our informal discussion of dependence relations in Chapter 5 motivates the side condition A_{∘} ⊀^{τ} B in the rule

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : Πx : A. B Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[Γ_{∘} ⊢ ∘ : A_{∘}]] : A A_{∘} ⊀^{τ} B}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M E[[Γ_{∘} ⊢ ∘ : A_{∘}]] : B}

above. This corresponds to restricting the realm of applicability of the rule to those cases where objects of type A_{∘} are not allowed to appear inside B. In particular, using the contrapositive of Corollary 5.2.2, x ∉ FV(B), and hence replacement of any object M_{∘} for the hole ∘ does not modify the type of the overall expression.

Notation. We will use the letter E for environments. Given an environment E and an object M_{∘} we will denote by E[[M_{∘}]] the object obtained by replacing the hole ∘ in E by the object M_{∘}.

E will be said an environment for M provided there is a sub-object M_{∘} of M such that M = E[[M_{∘}]]; in this case, the sub-object M_{∘} is said to be isolated by E.

Finally, we will write E_{1} · E_{2} to denote the environment obtained by composing the two environments E_{1} and E_{2}, i.e. by replacing the hole of E_{1} with E_{2}. Note that, even when both E_{1} and E_{2} are well-typed, E_{1} · E_{2} needs not to be.

\frac{Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A_{∘} : type Γ_{∘} ⊆ Γ}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} ∘[[Γ_{∘} ⊢ ∘ : A_{∘}]] : A_{∘}}  \frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A : type Γ, x : A ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[Γ_{∘} ⊢ ∘ : A_{∘}]] : B A ⪯^{t} B}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} λx : A. E[[Γ_{∘} ⊢ ∘ : A_{∘}]] : Πx : A. B}

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[Γ_{∘} ⊢ ∘ : A_{∘}]] : Πx : A. B Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : A}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[Γ_{∘} ⊢ ∘ : A_{∘}]] M : [M/x]B}

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : Πx : A. B Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[Γ_{∘} ⊢ ∘ : A_{∘}]] : A A_{∘} ⊀^{τ} B}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M E[[Γ_{∘} ⊢ ∘ : A_{∘}]] : B}

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[Γ_{∘} ⊢ ∘ : A_{∘}]] : A Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A =_{Eβη} A′}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[Γ_{∘} ⊢ ∘ : A_{∘}]] : A′}

Figure 6.1: Environments

We list below a few basic properties of environments. Proposition 6.1.2 (Weakening). Let Σ ⊆ Σ′, E′′ ⊆ E ⊆ E′, E′′ ⊆ E′′′ ⊆ E′, Γ ⊆ Γ′,

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[Γ_{∘} ⊢ ∘ : A_{∘}]] : A implies Γ′ ⊢\begin{matrix}≺ \\ Σ′,E′ \end{matrix} E[[Γ_{∘} ⊢ ∘ : A_{∘}]] : A

Proof. By induction on the derivation. Note that, unlike in Proposition 2.2.1, the statement may not hold if we increase ≺^{τ}. Proposition 6.1.3. If Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[Γ_{∘} ⊢ ∘ : A_{∘}]] : A, then Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A : type and A_{∘} ⪯^{t} A. Proof. Both properties are proved by induction on the derivation of Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[Γ_{∘} ⊢ ∘ : A_{∘}]] : A. For the second one, a non-trivial case is given by the abstraction rule:

• Case

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : Πx : A. B Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[Γ_{∘} ⊢ ∘ : A_{∘}]] : A A_{∘} ⊀^{τ} B}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M E[[Γ_{∘} ⊢ ∘ : A_{∘}]] : B}

By inductive hypothesis, we get A_{∘} ⪯^{t} A. Using Type Consistency, we conclude Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} Πx : A. B : type; by inversion we see A ⪯^{t} B, from which the result follows by transitivity of ≺^{t}.

Proposition 6.1.4. Let Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[Γ_{∘} ⊢ ∘ : A_{∘}]] : A, then

Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{∘} : A_{∘} implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[M_{∘}]] : A
Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{∘} =_{E′βη} M′_{∘} implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[M_{∘}]] =_{E′βη} E[[M′_{∘}]]

Proof. By induction on the derivation of Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[Γ_{∘} ⊢ ∘ : A_{∘}]] : A. There is one subtle point to consider when dealing with one of the application rules:

• Case

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{1} : Πx : B. C Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E_{2}[[Γ_{∘} ⊢ ∘ : A_{∘}]] : B A_{∘} ⊀^{τ} C}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{1} E_{2}[[Γ_{∘} ⊢ ∘ : A_{∘}]] : C}

The inductive hypothesis gives us Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E_{2}[[M_{∘}]] : Πx : B. C. Hence, using the application rule we conclude

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{1} : Πx : B. C Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E_{2}[[M_{∘}]] : B}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{1} E_{2}[[Γ_{∘} ⊢ ∘ : A_{∘}]] : [E_{2}[[M_{∘}]]/x]C}

We are left to show that x ∉ FV(B), so that [E_{2}[[M_{∘}]]/x]B = B. Assume otherwise, using Type Consistency and inversion, we get a derivation of

Γ, x : B ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} C : type

and from this, using Corollary 5.2.2 we conclude B ≺^{τ} C.

Using the derivation of Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E_{2}[[Γ_{∘} ⊢ ∘ : A_{∘}]] : A and Proposition 6.1.3, we also have A_{∘} ⪯^{t} B; hence

A_{∘} ⪯^{t} B ≺^{τ} C

and therefore A_{∘} ≺^{τ} C, a contradiction.

Notation. We will denote by θE the environment obtained by applying the substitution θ to all the expressions in E, i.e. the environment defined as

θ(∘) = ∘
θ(λx : A. E′) = λz : θA. θ([z/x]E′)  (z fresh)
θ(E′ N) = θE′ θN
θ(M E′) = θM θE′

Note that this definition basically extends the notion of applying a substitution to contexts; in particular, if M = E[[M_{∘}]] then θM = (θE)[[θM_{∘}]].

Proposition 6.1.5. Let Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ : Δ, then

Δ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[Δ, Γ_{∘} ⊢ ∘ : :]]A implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θE[[Γ, θΓ_{∘} ⊢ ∘ : θA_{∘}]] : θA

Proof. By a straightforward induction on the derivations, observing that, for each type C,

head(θC) = head(C)

and hence A_{∘} ⊀^{τ} B iff θA_{∘} ⊀^{τ} θB.

When M_{∘} is a sub-object of M isolated by an environment E, i.e. M = E[[M_{∘}]], if M is well-formed then M_{∘} is too; the same it is not true in general for E. The following gives sufficient conditions for this to happen:

Proposition 6.1.6. Let M = E[[M_{∘}]], where

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : A  Γ(M, M_{∘}) ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{∘} : A_{∘}

if A_{∘} ⊀^{τ} A then

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[Γ(M, M_{∘}) ⊢ ∘ : A_{∘}]] : A

Proof. By induction on the derivation of Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : A. We examine the case

• Case

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{1} : Πx : B. C Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E_{2}[[M_{∘}]] : B}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{1} E_{2}[[M_{∘}]] : [E_{2}[[M_{∘}]]/x]C}

By Type Consistency and inversion, B ⪯^{t} C. Hence we see that A_{∘} ⊀^{τ} B: otherwise, since

head(C) = head([E_{2}[[M_{∘}]]/x]C) = head(A)

we would have

A_{∘} ≺^{τ} B ⪯^{t} A

leading to A_{∘} ≺^{τ} A, a contradiction to the assumptions. From this, we see, using Corollary 5.2.2, that x ∉ FV(C), so [E_{2}[[M_{∘}]]/x]C = C. Applying the inductive hypothesis to E_{2}[[M_{∘}]], we obtain

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E_{2}[[Γ(M, M_{∘}) ⊢ ∘ : A_{∘}]] : B

and therefore

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{1} : Πx : B. C Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E_{2}[[Γ(M, M_{∘}) ⊢ ∘ : A_{∘}]] : B A_{∘} ⊀^{τ} C}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{1} E_{2}[[Γ(M, M_{∘}) ⊢ ∘ : A_{∘}]] : C}

When Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[M_{∘}]] : A, where E is not well-formed, replacing M_{∘} with another object M′_{∘} of the same type is not guaranteed to give rise to another object of type A, or even a well-formed object at all. One notable exception is when M_{∘} and M′_{∘} are pairwise convertible:

Proposition 6.1.7. Let M = E[[M_{∘}]] and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[M_{∘}]] : A,

Γ(M, M_{∘}) ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{∘} ⇒_{β} M′_{∘} implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[M_{∘}]] ⇒_{β} E[[M′_{∘}]]
Γ(M, M_{∘}) ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{∘} ⇒_{η} M′_{∘} implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[M_{∘}]] ⇒_{η} E[[M′_{∘}]]

Proof. Both statements are proved by a straightforward induction on the derivation of Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[M_{∘}]] : A.

When two environment are used to perform replacement of disjoint sub-expressions of the same object, the order in which this replacement is performed is immaterial; this simple remark is formalized by the following:

Definition 6.1.8. Given two environments E_{1} and E_{2} for a same object M, we say that E_{1} and E_{2} are disjoint, and write E_{1} ↑ E_{2}, if neither one is contained in the other, i.e. there is no E_{0} such that E_{1} = (E_{2}·E_{0}) or E_{2} = (E_{1} · E_{0}).

Proposition 6.1.9. Let E_{0}[[M_{0}]] = E_{1}[[M_{1}]], E_{0} ↑ E_{1}, where

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E_{i}[[Δ_{i} ⊢ ∘ : A_{i}]] : A (i = 0, 1)

Δ_{i} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{i} : A_{i} (i = 0, 1)

then for each object Δ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′_{0} : A_{0} there is an environment (E_{1})_{E_{0}[[M′_{0}]]},

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} (E_{1})_{E_{0}[[M′_{0}]]}[[Δ_{1} ⊢ ∘ : A_{1}]] : A

such that (E_{1})_{E_{0}[[M′_{0}]]}[[M_{1}]] = E_{0}[[M′_{0}]]. Moreover, given E_{2}[[M_{2}]] = E_{1}[[M_{1}]], and

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E_{2}[[Δ_{2} ⊢ ∘ : A_{2}]] : A  Δ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{2} : A_{2}  E_{2} ↑ E_{0}, E_{2} ↑ E_{1}

we also have (E_{1})_{E_{0}[[M′_{0}]]} ↑ (E_{2})_{E_{0}[[M′_{0}]]}.

Proof. By induction on the derivation of Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E_{0}[[Δ_{0} ⊢ ∘ : A_{0}]] : A.

The notion of disjoint environments is useful, for example, when considering objects [N/x]M, in cases when the object N can be rewritten to N′. Occurrences of N in [N/x]M are isolated by disjoint environments, so we can use Proposition 6.1.9 to rewrite all of them, in any order we choose, to eventually obtain [N′/x]M. However, for Proposition 6.1.9 to be applicable in these cases, we have to make sure that the environments are well-formed. It is easy to convince ourself that this is equivalent to checking well-formedness of all the environments isolating occurrences of x in M, and a sufficient condition for this to happen is given by the following:

Proposition 6.1.10. Let Γ, x : A_{∘}, Δ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : A, with A_{∘} ⊀^{τ} A, then M = M[[x]], where

Γ, x : A_{∘}, Δ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M[[Γ_{x} ⊢ ∘ : A_{∘}]] : A

for all occurrences of x in M (for some context Γ_{x} which depends on the occurrence).

Proof. By induction on the derivation of ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} Γ, x : A_{∘}, Δ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : A. The only two interesting cases are

• Case

\frac{Γ, x : A_{∘}, Δ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} B : type Γ, x : A_{∘}, Δ, y : B ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{1} : C B ⪯^{t} C}{Γ, x : A_{∘}, Δ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} λx : B. M_{1} : Πx : B. C}

Since our definition of environment does not allow the hole to appear inside a type, we have first to check that x ∉ FV(B). If that was the case, then we would conclude, by Corollary 5.2.2, A_{∘} ≺^{τ} B. Hence

A_{∘} ≺^{τ} B ⪯^{t} C

from which we derive A_{∘} ≺^{τ} C, and, since head(Πx : B. C) = head(C), A_{∘} ≺^{τ} A, a contradiction to the assumptions. Therefore it must be x ∈ FV(M_{1}), and the result follows by inductive hypothesis.

• Case

\frac{Γ, x : A_{∘}, Δ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{1} : Πx : B. C Γ, x : A_{∘}, Δ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{2} : B}{Γ, x : A_{∘}, Δ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{1} M_{2} : [M_{2}/x]C}

If the occurrence of x is in M_{1}, then the result is trivially obtained by inductive hypothesis, since head(Πx : B. C) = head([M_{2}/x]C). If the occurrence of x is in M_{2}, in order to apply the inductive hypothesis we have to show that A_{∘} ⊀^{τ} B. From the derivation of

Γ, x : A_{∘}, Δ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{1} : Πx : B. C

we conclude, by Type Consistency and inversion, B ⪯^{t} C.

If A_{∘} ≺^{τ} B, we would then have

A_{∘} ≺^{τ} B ⪯^{t} C

from which we conclude A_{∘} ≺^{τ} C, and, since head(C) = head([M_{2}/x]C), A_{∘} ≺^{τ} A, a contradiction.

Remark. Note that Proposition 6.1.10 is not subsumed by Proposition 6.1.6, although they share the same assumption and have similar results: in Proposition 6.1.10 we also show that all the free occurrences of x are isolated by some environment, i.e. that x does not appear free in any of the types of the λ-abstracted variables in M.

6.2 Rewriting

We have now all the machinery necessary to state a formal definition of rewriting. Such definition will have the same structure as the one in [71], but additional care is necessary, since now canonical forms are only unique modulo λ-equivalence, and therefore we will want the definition to be invariant with respect of the particular representative chosen in each equivalence class.

Definition 6.2.1 (Higher-order Term Rewriting Systems). A rewrite rule is a pair of objects l and r such that

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} l ⇓ A is a pattern  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} r : A  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ↓ type

We will denote a rewrite rule like the above by Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} l → r : A.

A set of rewrite rules R is a Higher-order Term Rewriting System (HTRS) provided that for any two rules

Γ_{i} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} l_{i} → r_{i} : A_{i} ∈ R (i = 1, 2)

we have A_{1} ⊀^{τ} A_{2}.

Definition 6.2.2. Given a set of rules R, we define

heads(R) =^{def} \{head(A) | Γ ⊢\begin{matrix}≺ \\ Γ,E \end{matrix} l → r : A ∈ R\}

Notation. We will often write R for heads(R), whenever the intended meaning is clear from the context.

Furthermore, we will extend the previously defined relations over type constants to sets by existential quantification; for example

a ≺^{τ} R iff ∃ (Γ ⊢\begin{matrix}≺ \\ Γ,E \end{matrix} l → r : A) ∈ R . a ≺^{τ} A
a ⊀^{t} R iff ∀ (Γ ⊢\begin{matrix}≺ \\ Γ,E \end{matrix} l → r : A) ∈ R . a ⊀^{t} A

Under these conventions, the condition for a set of rules R to be a HTRS can be concisely expressed by

R ⊀^{τ} R

Remark. The requirement R ⊀^{τ} R will be needed when defining critical pairs. See the remark following Definition 7.3.2 for more details.

Definition 6.2.3 (Rewriting). We say that M rewrites under the HTRS R to M′, and write

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{R} M′

provided that

M = E[[M_{∘}]]  M′ = E[[M′_{∘}]]
Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{∘} : A_{∘}  Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′_{∘} ⇓ A_{∘}
Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{∘} =_{βη} θl  Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′_{∘} =_{βη} θr
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[Γ_{∘} ⊢ ∘ : A_{∘}]] : A  Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ : Δ_{∘}

Δ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} l → r : C_{∘} ∈ R

Rewriting modulo E′, where E′ ⊆ E, is defined as

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{1} →_{R/E′βη} M_{2} iff ∃N_{i} s.t. Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{i} =_{E′βη} N_{i} (i = 1, 2) and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N_{1} →_{R} N_{2}

6.3 Canonical Rewriting

Although the definition of rewriting modulo E′ ⊆ E we just gave is the most natural one, it is not a very practical one to use. Too much freedom is left as to where to apply the rewrite step; rewriting may take place over an object that is not canonical, or even not β-normal. For this reason, we introduce another form of rewriting modulo an equivalence relation, where we force rewriting to take place only on canonical forms. We will also prove that the two definitions are equivalent, hence allowing us to use them interchangeably throughout the rest of this thesis.

Definition 6.3.1. We say M rewrites canonically modulo E′, in symbols

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{R_{E′βη}} M′

if

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{⇓} ≈_{E′} E[[M_{∘}]]  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} (M′)_{⇓} ≈_{E′} E[[M′_{∘}]]
Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{∘} ⇓ A_{∘}  Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′_{∘} ⇓ A_{∘}
Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{∘} =_{E′βη} θl  Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′_{∘} =_{E′βη} θr
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[Γ_{∘} ⊢ ∘ : A_{∘}]] : A  Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ : Δ_{∘}

Δ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} l → r : C_{∘} ∈ R

Using Corollary 4.4.21 and Weakening, one immediately sees that →_{R_{E′βη}} is well-defined, i.e. it is independent from the choice of the canonical representatives M_{⇓} and (M′)_{⇓}.

To study the properties of canonical rewriting, it is useful to first extend some of the definitions and results of Chapter 4 to environments:

Definition 6.3.2. Canonical and atomic environments are constructed using the judgments

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[Γ_{∘} ⊢ ∘ : A_{∘}]] ⇓ A E is a canonical environment
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[Γ_{∘} ⊢ ∘ : A_{∘}]] ↓ A E is an atomic environment

derived accordingly to the following inference system:

\frac{Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A_{∘} ↓ type}{Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} ∘[[Γ_{∘} ⊢ ∘ : A_{∘}]] ⇓ A_{∘}}  \frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[Γ_{∘} ⊢ ∘ : A_{∘}]] ↓ A Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ↓ type}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[Γ_{∘} ⊢ ∘ : A_{∘}]] ⇓ A}

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇓ type Γ, x : A ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[Γ_{∘} ⊢ ∘ : A_{∘}]] ⇓ B A ⪯^{t} B}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} λx : A. E[[Γ_{∘} ⊢ ∘ : A_{∘}]] ⇓ Πx : A. B}

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[Γ_{∘} ⊢ ∘ : A_{∘}]] ⇓ A Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A =_{Eβη} A′ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A′ : type}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[Γ_{∘} ⊢ ∘ : A_{∘}]] ⇓ A′}

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[Γ_{∘} ⊢ ∘ : A_{∘}]] ↓ Πx : A. B Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇓ A}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E M[[Γ_{∘} ⊢ ∘ : A_{∘}]] ↓ [M/x]B}

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ↓ Πx : A. B Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[Γ_{∘} ⊢ ∘ : A_{∘}]] ⇓ A A_{∘} ⊀^{τ} B}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M E[[Γ_{∘} ⊢ ∘ : A_{∘}]] ↓ B}

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[Γ_{∘} ⊢ ∘ : A_{∘}]] ↓ A Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A =_{Eβη} A′ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A′ : type}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[Γ_{∘} ⊢ ∘ : A_{∘}]] ↓ A′}

We state below a few basic properties of canonical and atomic environments. The proofs are easily obtained arguing by induction on the derivations, and are omitted here. Proposition 6.3.3.

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[Γ_{∘} ⊢ ∘ : A_{∘}]] ⇓ A implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[Γ_{∘} ⊢ ∘ : A_{∘}]] : A
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[Γ_{∘} ⊢ ∘ : A_{∘}]] ↓ A implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[Γ_{∘} ⊢ ∘ : A_{∘}]] : A

Proposition 6.3.4. Let Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{∘} ⇓ A_{∘},

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[Γ_{∘} ⊢ ∘ : A_{∘}]] ⇓ A implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[M_{∘}]] ⇓ A
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[Γ_{∘} ⊢ ∘ : A_{∘}]] ↓ A implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[M_{∘}]] ↓ A

Proposition 6.3.5. Let M = E[[M_{∘}]], where

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[Γ_{∘} ⊢ ∘ : A_{∘}]] : A Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{∘} ⇓ A_{∘} Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A_{∘} ↓ type

then

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇓ A implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[Γ_{∘} ⊢ ∘ : A_{∘}]] ⇓ A
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ↓ A implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[Γ_{∘} ⊢ ∘ : A_{∘}]] ↓ A

We want now to show equivalence of →_{R/E′βη}^{∗} and →_{R_{E′βη}}^{∗}. One direction is immediate: Proposition 6.3.6. We have

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{R_{E′βη}} M′ implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{R/E′βη} M′

Proof. Assume Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{R_{E′βη}} M′. By Definition 6.3.1, we have

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{⇓} ≈_{E′} E[[M_{∘}]]  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} (M′)_{⇓} ≈_{E′} E[[M′_{∘}]]
Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{∘} ⇓ A_{∘}  Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′_{∘} ⇓ A_{∘}
Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{∘} =_{E′βη} θl  Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′_{∘} =_{E′βη} θr
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[Γ_{∘} ⊢ ∘ : A_{∘}]] : A  Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ : Δ_{∘}

Δ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} l → r : C_{∘} ∈ R

Using Lemma 4.2.3, and Propositions 6.1.4 and 4.3.2, we see

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M =_{E′βη} E[[θl]]  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[θl]] →_{R} E[[θr]]  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′ =_{E′βη} E[[θr]]

Corollary 6.3.7. If →_{R/E′βη} is strongly normalizing, so is →_{R_{E′βη}} Proof. By Proposition 6.3.6, any infinite (→_{R_{E′βη}})-rewriting sequence is also a (→_{R/E′βη})-rewriting one.

Proving the other direction of the equivalence suggested by Proposition 6.3.6 is more involved, and requires some preliminary work. Definition 6.3.8. Let Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : A a well-formed object, we define

β(M) = {N | M →_{β}^{+} N}

the set of β-reducts of M. Given a well-formed type A or kind K, the sets β(A) and β(K) are similarly defined.

Remark. By Theorem 3.3.10, β-reduction is strong normalizing on well-formed expressions, so these are always finite, and therefore it makes sense to compute their size |β(M)|, |β(A)|, and |β(K)|. Lemma 6.3.9.

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{R} N′ and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒_{η} M′′ implies ∃N s. t. Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′ ⇒_{η}^{=} N and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′′ →_{R} N

In pictures:

\xymatrix{M \ar[r]^{R} \ar@{=>}[d]_{η} & M′ \ar@{=>}[d]^{η^{=}} \\ M′′ \ar@{-->}[r]_{R} & N}

Proof. By definition, Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{R} M′ if

M = E[[M_{∘}]]  M′ = E[[M′_{∘}]]
Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{∘} : A_{∘}  Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′_{∘} ⇓ A_{∘}
Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{∘} =_{βη} θ_{∘}l  Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′_{∘} =_{βη} θ_{∘}r

where

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[Γ_{∘} ⊢ ∘ : A_{∘}]] : A Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ : Δ_{∘} Δ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} l → r : C_{∘} ∈ R

We argue by induction on the derivation of Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[Γ_{∘} ⊢ ∘ : A_{∘}]] : A, using inversion on the derivation of

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒_{η} M′′.

The only non-trivial case is when Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[Γ_{∘} ⊢ ∘ : A_{∘}]] : Πx : B. C, and

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : Πx : B′. C′ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} B′ ⇓ type M not a λ}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒_{η} λx : B′. (M x)}

By Uniqueness of Types we conclude

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} B =_{Eβη} B′ Γ, x : B ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} C =_{Eβη} C′ B′ ⪯^{t} C

and from this the result follows, using the (well-formed) environment E′ = (λx : B′. E x). Corollary 6.3.10. We have

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{R}^{∗} M′ and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒_{η}^{∗} M′′ implies ∃N s. t. Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′ ⇒_{η}^{∗} N and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′′ →_{R}^{∗} N

Graphically:

\xymatrix{M \ar[r]^{R^{∗}} \ar@{=>}[d]_{η^{∗}} & M′ \ar@{=>}[d]^{η^{∗}} \\ M′′ \ar@{-->}[r]_{R^{∗}} & N}

Moreover, the rewrite sequences Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{R}^{∗} M′ and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′′ →_{R}^{∗} N are of the same length. Proof. By induction on the length of the sequence of rewriting steps and η-expansions, using Lemma 6.3.9.

Lemma 6.3.11. We have:

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{R} M′ and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒_{β} M′′ implies ∃N′ and N′′ s. t. \begin{cases}Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′ ⇒_{β}^{∗} N′ \\ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′′ →_{R}^{∗} N′′ \\ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N′ ⇒_{η}^{∗} N′′ \end{cases}

In pictures:

[figure: M; R; β; M′; β^{∗}; N′; η^{∗}; M′′; R^{∗}; N′′]

Moreover, |β(N′)| = |β(N′′)|. Proof. By definition, Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{R} M′ if

M = E[[M_{∘}]]  M′ = E[[M′_{∘}]]
Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{∘} : A_{∘}  Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′_{∘} ⇓ A_{∘}
Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{∘} =_{βη} θ_{∘}l  Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′_{∘} =_{βη} θ_{∘}r

where

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[Γ_{∘} ⊢ ∘ : A_{∘}]] : A Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ : Δ_{∘} Δ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} l → r : C_{∘} ∈ R

The proof then proceeds by induction on the structure of the derivation of Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[Γ_{∘} ⊢ ∘ : A_{∘}]] : A. As usual, we consider just a couple of representative cases:

• Case

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E_{1}[[Γ_{∘} ⊢ ∘ : A_{∘}]] : Πx : B. C Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{2} : B}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E_{1}[[Γ_{∘} ⊢ ∘ : A_{∘}]] M_{2} : [M_{2}/x]C}

If

M = E_{1}[[M_{∘}]] M_{2} →_{β} E_{1}[[M_{∘}]] M′′_{2} = M′′

then the result follows trivially, letting N′ = N′′ = E_{1}[[M′_{∘}]] M′′_{2}. Otherwise, if

M = E_{1}[[M_{∘}]] M_{2} →_{β} M′′_{1} M_{2} = M′′

the result follows by applying the inductive hypothesis to E[[M′_{∘}]] and M′′_{1}. The only interesting case is therefore

M = E_{1}[[M_{∘}]] M_{2} = (λx : B′. M_{3}) M_{2} →_{β} [M_{2}/x]M_{3} = M′′

By inversion, it can be shown E_{1} = λx : B′. E_{3}, where

Γ, x : B′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E_{3}[[Γ_{∘} ⊢ ∘ : A_{∘}]] : C′

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} Πx : B. C =_{Eβη} Π : B′. C′

and E_{3}[[M_{∘}]] = M_{3}. Note that this inversion property does not hold in general, and uses the assumption that all the rules in R are of base type. Applying Proposition 6.1.5 with θ = (id_{Γ}, x ↦ M_{2}), we see that the environment θE_{3} is well-formed, and (θE_{3})[[θM_{∘}]] = [M_{2}/x]M_{3}. By Lemma 4.2.3

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θM′_{∘} ⇒_{βη}^{∗} (θM′_{∘})_{⇓}  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} (θM′_{∘})_{⇓} ⇓ [M_{2}/x]A_{∘}

Without loss of generality, we can assume that N′′_{∘} = (θM′_{∘})_{⇓} is obtained by first reducing θM′_{∘} to its β-normal form N′_{∘}. Using Proposition 6.1.7,

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} (λx : B′. E_{3}[[M′_{∘}]]) M_{2} ⇒_{β} (θE_{3})[[θM′_{∘}]] ⇒_{β}^{∗} (θE_{3})[[N′_{∘}]]

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} (θE_{3})[[N′_{∘}]] ⇒_{η}^{∗} (θE_{3})[[N′′_{∘}]]

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} [M_{2}/x]M_{3} →_{R} (θE_{3})[[N′′_{∘}]]

Finally, since N′_{∘} is of base type, no new β-redexes are created by η-expanding N′ = (θE_{3})[[N′_{∘}]] to N′′ = (θE_{3})[[N′′_{∘}]]; hence |β(N′)| = |β(N′′)|.

• Case

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{1} : Πx : B. C Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E_{2}[[Γ_{∘} ⊢ ∘ : A_{∘}]] : B A_{∘} ⊀^{τ} C}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{1} E_{2}[[Γ_{∘} ⊢ ∘ : A_{∘}]] : C}

As before, the cases

M = M_{1} E_{2}[[M_{∘}]] →_{β} M′′_{1} E_{2}[[M_{∘}]] = M′′

and

M = M_{1} E_{2}[[M_{∘}]] →_{β} M_{1} M′′_{2} = M′′

are easily handled. The only non-trivial case is therefore again

M = (λx : B′. M_{3}) E_{2}[[M_{∘}]] →_{β} [E_{2}[[M_{∘}]]/x]M_{3} = M′′

where, by inversion on the derivation of Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} (λx : B′. M_{3}) : Πx : B. C, we conclude

Γ, x : B′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{3} : C′  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} B =_{Eβη} B′
B′ ⪯^{t} C′  Γ, x : B′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} C =_{Eβη} C′

From the derivation of Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E_{2}[[Γ_{∘} ⊢ ∘ : A_{∘}]] : B we obtain, by type conversion and Proposition 6.1.3, A_{∘} ⪯^{t} B′. We now see that it must be B′ ⊀^{τ} C, because otherwise we would have

A_{∘} ⪯^{t} B′ ≺^{τ} C

and therefore A_{∘} ≺^{τ} C, a contradiction to the assumptions. Hence B′ ⊀^{τ} C′, and we can apply Proposition 6.1.10 to obtain disjoint environments

Γ, x : B′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{3}[[Γ_{x} ⊢ ∘ : B]] : C′

From these, using Proposition 6.1.5 with θ = (id_{Γ}, x ↦ E_{2}[[M_{∘}]]), we get (still disjoint) environments

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} (θM_{3})[[θΓ_{x} ⊢ ∘ : θB′]] : θC′

Hence, by repeated applications of Proposition 6.1.9, we show

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} [E_{2}[[M_{∘}]]/x]M_{3} →_{R}^{∗} [E_{2}[[M′_{∘}]]/x]M_{3}

and therefore the result, letting N′ = N′′ = [E_{2}[[M′_{∘}]]/x]M_{3}.

Corollary 6.3.12. The following holds:

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{R}^{∗} M′ and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒_{β}^{∗} M′′ implies ∃N s. t. Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′ ⇒_{βη}^{∗} N and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′′ →_{R}^{∗} N

Pictorially, we have the following diagram:

\xymatrix{M \ar[r]^{R^{∗}} \ar@{=>}[d]_{β^{∗}} & M′ \ar@{=>}[d]^{βη^{∗}} \\ M′′ \ar@{-->}[r]_{R^{∗}} & N}

Proof. We argue by a double induction argument: the primary induction is on |β(M)|, the secondary one on the length of the rewriting sequence. The proof is obtained from Lemma 6.3.11 and Corollary 6.3.10 by diagram chasing:

[figure: M; R; β; M′_{1}; R^{∗}; β^{∗}; M′; βη^{∗}; P′_{1}; R^{∗}; η^{∗}; N′; η^{∗}; M′′_{1}; R^{∗}; β^{∗}; P′′_{1}; R^{∗}; N′′; βη^{∗}; M′′; R^{∗}; N]

Proposition 6.3.13. Let Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{R} M′, then

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇓ A implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′ ⇓ A
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ↓ A implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′ ↓ A

Proof. By definition, Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{R} M′ if there are

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[Γ_{∘} ⊢ ∘ : A_{∘}]] : A Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ : Δ_{∘} Δ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} l → r : C_{∘} ∈ R

such that

M = E[[M_{∘}]]  M′ = E[[M′_{∘}]]
Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{∘} : A_{∘}  Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′_{∘} ⇓ A_{∘}
Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{∘} =_{Eβη} θ_{∘}l  Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′_{∘} =_{Eβη} θ_{∘}r

By Proposition 6.3.5, from

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇓ A (resp. Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ↓ A)

we conclude

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[Γ_{∘} ⊢ ∘ : A_{∘}]] ⇓ A (resp. Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[Γ_{∘} ⊢ ∘ : A_{∘}]] ↓ A)

and the result follows by Proposition 6.3.4.

Theorem 6.3.14. We have

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{R/E′βη}^{∗} M′ if and only if Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{R_{E′βη}}^{∗} M′ or Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M =_{E′βη} M′

Proof. One direction is easily proven using Proposition 6.3.6.

For the other one, it suffices to show

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{R/E′βη} N implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{R_{E′βη}}^{∗} N

Assume Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{R/E′βη} N. By definition, there are objects M′ and N′ such that

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M =_{E′βη} M′  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′ →_{R} N′  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N′ =_{E′βη} N

Without loss of generality, we can assume that (M′)_{⇓} is obtained by first β-normalizing M, and then η-expanding all the non-saturated sub-objects. We can then apply Corollaries 6.3.12, 6.3.10, and Proposition 6.3.13, (in this order) to conclude

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} (M′)_{⇓} →_{R}^{∗} N′′

for some canonical objects N′′ such that Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N′′ =_{βη} N′.

By Theorem 4.4.20

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{⇓} ≈_{E′} (M′)_{⇓}  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N′′ ≈_{E′} N_{⇓}

hence the result.

We conclude this section by extending one final notion,E′λ-equivalence, to environments:

Definition 6.3.15. Let E′ ⊆ E, we define E′λ-equivalent environments by means of the judgment:

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E ≈_{E′} E′ E and E′ are E′λ-equivalent environments

built up from the rules:

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[Γ_{∘} ⊢ ∘ : A_{∘}]] : A}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E ≈_{E′} E′}  \frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E ≈_{E′} E′}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E′ ≈_{E′} E}  \frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E ≈_{E′} E′ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E′ ≈_{E′} E′′}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E ≈_{E′} E′′}

\overline{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} ∘ ≈_{E′} ∘}

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A =_{Eβη} A′ Γ, x : A ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[Γ_{∘} ⊢ ∘ : A_{∘}]] : B}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} λx : A. E ≈_{E′} λx : A′. E}  \frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A : type Γ, x : A ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E ≈_{E′} E′}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} λx : A. E ≈_{E′} λx : A. E′}

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E ≈_{E′} E′ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : A}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E M ≈_{E′} E′ M}  \frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[Γ_{∘} ⊢ ∘ : A_{∘}]] : A Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ≈_{E′} M′}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E M ≈_{E′} E M′}

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ≈_{E′} M′ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[Γ_{∘} ⊢ ∘ : A_{∘}]] : A}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M E ≈_{E′} M′ E}  \frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : A Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E ≈_{E′} E′}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M E ≈_{E′} M E′}

Proposition 6.3.16. Let Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{∘} : A_{∘}, then

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E ≈_{E′} E′ implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[M_{∘}]] ≈_{E′} E′[[M_{∘}]]

Proof. By a simple induction on the derivation of Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E ≈_{E′} E′.

6.4 Summary

The results about dependence relations proved previously are used here to formulate our definition of rewriting modulo an equational theory. In particular, dependence relations are used when defining environments (Definition 6.1.1) to rule out cases, like the one presented in Chapter 5, where replacement of sub-expressions invalidates the type of the overall expression.

We gave two definitions of rewriting; the first, in Section 6.2, is the most natural one, but not necessarily the most convenient to use in our study. The second one, canonical rewriting, introduced in Section 6.3, sets some restriction on the form of the expression that we allow to be rewritten. These restriction do not translate in a loss of generality: in the same section, we proved that the reflexive-transitive closures of these two relations coincide (Theorem 6.3.14).

Confluence for Simpler Equational Theories

In studying HTRSs, two properties that are of particular significance are confluence and strong normalization. If a HTRS possesses both of these properties, equivalence of any two expressions modulo E(R) (the equational theory generated from R by disregarding orientation) can be effectively computed by reducing both expressions to their R-normal forms. In this dissertation we will concentrate on the first of these two properties, confluence, although some of the results we present can be used in establishing strong normalization.

Testing confluence of a Term Rewriting System (TRS) using the definition is not practical, since it would require checking that the diagram

\xymatrix{M \ar[d]_{R^{∗}} \ar[r]^{R^{∗}} & M_{1} \ar@{-->}[d]^{R^{∗}} \\ M_{2} \ar@{-->}[r]_{R^{∗}} & N}

holds for all possible choice of well-formed objects M, M_{1}, M_{2}.

If we assume R to be strongly normalizing, our task is simplified somewhat, because by Newmann’s Lemma [53] it suffices to check for local confluence, i.e.

\xymatrix{M \ar[d]_{R} \ar[r]^{R} & M_{1} \ar@{-->}[d]^{R^{∗}} \\ M_{2} \ar@{-->}[r]_{R^{∗}} & N}

Still, this requires testing infinitely many triples of objects M, M_{1}, M_{2}. In this respect, one of the most fundamental contributions to the theory of TRSs can be considered Knuth and Bendix’s Critical Pair Criterion, which reduces the check for local confluence to a finite set of pairs of objects M_{1} and M_{2}.

When considering confluence modulo an equivalence relation, an adaptation of this criterion is available, due to Huet [29]. However, here, critical pairs coming from overlapping rules and equations have also to be considered. There are circumstances, of course, where examining some of these additional pairs is unnecessary, like for example when R and E are defined over disjoint signatures. However, these situations are quite rare and or difficult to check for. In this chapter, we will show how dependence relations allow us to isolate a frequently-occuring class of such cases.

7.1 Simpler Equational Theories

The class of problems we will discuss in this chapter are those where the equational theory E is defined on lower classes of types than the HTRS R. To make the notion of “lower class of types” more precise, we give the following definitions:

Definition 7.1.1. Let E an equational theory, we define

heads(E) =^{def} \{head(A) | Γ ⊢\begin{matrix}≺ \\ Σ \end{matrix} M = N : A ∈ E \}

Notation. As before with heads(R), we will often write, by abuse of notation, E for heads(E).

Definition 7.1.2. An equational theory E is said to be simpler than a HTRS R defined over it, provided that R ⪯̸^{t} E.

Remark. Informally speaking, an equational theory E is simpler if no object rewritable by R can appear as a sub-object of E.

In Chapter 6, we proved that rewriting modulo E is equivalent to canonical rewriting (modulo E), and therefore these two notions could be used interchangeably. In particular, one nice feature of the latter is that it commutes with βη-conversion:

[figure: M; βη; R_{Eβη}; M_{1}; βη; M_{2}; R_{Eβη}; N]

The above diagram fails to be true in general if we replace =_{βη} with =_{Eβη}. However, in the case of simpler E this can be shown to hold.

Proposition 7.1.3. Let M = E[[M_{∘}]], with

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ≈_{E′} M′  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[Γ_{∘} ⊢ ∘ : A_{∘}]] : A  Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{∘} : A_{∘}

if A_{∘} ⪯̸^{t} E′ then M′ = E′[[M′_{∘}]] for some environment E′ and object M′_{∘} such that

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E ≈_{E′} E′  Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{∘} ≈_{E′} M′_{∘}

Proof. By induction on the derivation of Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[Γ_{∘} ⊢ ∘ : A_{∘}]] : A. We examine a few cases:

• Case

\frac{Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A_{∘} : type Γ_{∘} ⊆ Γ}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} ∘[[Γ_{∘} ⊢ ∘ : A_{∘}]] : A_{∘}}

Immediate from the assumptions, by choosing E′ = ∘, M′_{∘} = M′.

• Case

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} B : type Γ, x : B ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E_{1}[[Γ_{∘} ⊢ ∘ : A_{∘}]] : C B ⪯^{t} C}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} λx : B. E_{1}[[Γ_{∘} ⊢ ∘ : A_{∘}]] : Πx : B. C}

By inversion on the derivation of Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ≈_{E′} M′, one shows M′ = λx : B′.M′_{1}, with

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} B =_{Eβη} B′  Γ, x : B′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E_{1}[[M_{∘}]] ≈_{E′} M′_{1}

We can therefore apply the inductive hypothesis, obtaining E′_{1} and M′_{∘} as required. Then, the result follows by letting E′ = λx : B′. E′_{1}:

\frac{\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} B =_{Eβη} B′ Γ, x : B ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E_{1}[[Γ_{∘} ⊢ ∘ : A_{∘}]] : C}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} λx : B. E_{1} ≈_{E′} λx : B′. E_{1}} \frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} B′ : type Γ, x : B′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E_{1} ≈_{E′} E′_{1}}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} λx : B′. E_{1} ≈_{E′} λx : B′. E′_{1}}}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} λx : B. E_{1} ≈_{E′} λx : B′. E′_{1}}

• Case

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{1} : Πx : B. C Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E_{2}[[Γ_{∘} ⊢ ∘ : A_{∘}]] : B A_{∘} ⊀^{τ} C}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{1} E_{2}[[Γ_{∘} ⊢ ∘ : A_{∘}]] : C}

Arguing by inversion on the derivation of Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ≈_{E′} M′, we can show M′ = M′_{1} M′_{2}, where

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{1} ≈_{E} M′_{1}  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E_{2}[[M_{∘}]] ≈_{E} M′_{2}

and the result follows again by inductive hypothesis. Note that the inversion property we used here is not true in general, since the derivation of

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{1} E_{2}[[M_{∘}]] ≈_{E′} M′

might be obtained by one or more top-level applications of the E′-conversion rule:

\frac{(Δ ⊢\begin{matrix}≺ \\ Σ \end{matrix} M_{∘} = M′_{∘} : C_{∘}) ∈ E′ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ : Δ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} U =_{βη} θM_{∘} Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} U′ =_{βη} θM′_{∘}}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} U ≈_{E′} U′}

We have to show that this is not the case. If it was, since (by Proposition 6.1.3) A_{∘} ⪯^{t} C, and

head(C) = head(θC_{∘}) = head(C_{∘})

we would have A_{∘} ⪯^{t} C_{∘}, a contradiction to the assumption A_{∘} ⪯̸^{t} E′.

Corollary 7.1.4. Let Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M =_{Eβη} N, then

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{R_{Eβη}} M′ implies ∃N′ s.t. Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N →_{R_{Eβη}} N′ and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′ =_{Eβη} N′

In pictures:

[figure: M; Eβη; R_{Eβη}; M′; Eβη; N; R_{Eβη}; N′]

Proof. By definition, Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{R_{Eβη}} M′ if

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{⇓} ≈_{E} E[[M_{∘}]]  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} (M′)_{⇓} ≈_{E} E[[M′_{∘}]]
Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{∘} ⇓ A_{∘}  Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′_{∘} ⇓ A_{∘}
Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{∘} =_{Eβη} θl  Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′_{∘} =_{Eβη} θr
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[Γ_{∘} ⊢ ∘ : A_{∘}]] : A  Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ : Δ_{∘}

Δ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} l → r : C_{∘} ∈ R

Using Theorem 4.4.20 we show

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{⇓} ≈_{E} N_{⇓}

Let E′ be the environment for N_{⇓} obtained by applying Proposition 7.1.3, it is easily seen that N′ = E′[[M′_{∘}]] is as required.

7.2 Generalized Patterns

In what follows, the assumption that all the LHSs in a HTRS are patterns will play, as we will see, a crucial role. Unfortunately, this property is not preserved by taking sub-objects (previously bound variables may become free), and for this reason it is ill-suited to proving properties by structural induction. Therefore, we introduce the following generalization:

Definition 7.2.1. Let Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇓ A (resp. Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ↓ A), and Γ′ ⊆ Γ, M is said to be a Γ′-pattern if every occurrence of a variable x ∈ dom(Γ′) in M appears enclosed in sub-objects of the form M_{∘} = x N_{1} N_{2} … N_{k}, where

Γ(M, M_{∘}) ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{∘} ⇓ type(Γ(M, M_{∘}))

and the N_{i} are all η-convertible to distinct variables y_{i} ∉ dom(Γ′). A sub-object M_{∘} of the above form is called a Γ′-generalized variable.

Another important notion that we will use throughout this dissertation is stability:

Definition 7.2.2. An object M is said to be Γ-stable if M = c M_{1} M_{2} … M_{k}, or M = x M_{1} M_{2} … M_{k} with x ∉ dom(Γ).

An environment E is Γ-stable if

E = (E_{1} · (M E_{2})) implies M is Γ-stable

What makes stability a key property is that, as the following fact shows, all the interesting environments of a Γ′-pattern are Γ′-stable.

Proposition 7.2.3. Assume M = E[[M_{∘}]], with

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇓ A (resp. Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ↓ A)) Γ′-pattern

for some Γ′ ⊆ Γ, and

Γ(M, M_{∘}) ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{∘} ⇓ A_{∘}

then E is Γ′-stable if and only if M_{∘} is not a proper sub-object occurrence of some Γ′-generalized variable in E[[M_{∘}]].

Proof. By a simple induction on the derivation of E[[M_{∘}]]. When dealing with the rule

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[M_{∘}]] ↓ A Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ↓ type}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[M_{∘}]] ⇓ A}

we check whether E[[M_{∘}]] is a Γ′-generalized variable. If it is, then we immediately verify that, unless E = ∘, E is not Γ′-stable. If E[[M_{∘}]] is not a Γ′-generalized variable, we proceed by inductive hypothesis.

Another useful property of Γ′-stable objects and environments is that their “structure” is preserved by those substitutions which are the identity on variables outside Γ′, in a sense made precise by the following:

Proposition 7.2.4. Let

Δ, Δ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ↓ A  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ : Δ,

if M is Δ-stable then there is an object M′ such that

Γ, θΔ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′ ↓ θA  Γ, θΔ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θM =_{βη} M′

Proof. We can consider θM as the object obtained by applying the (well-formed, by the assumptions) substitution

Γ, θΔ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} (θ, id_{Δ′}) : Δ, Δ′

The proof then proceeds by induction on the derivation of Δ, Δ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ↓ A.

• Case

\frac{(Δ, Δ′)(x) = A}{Δ, Δ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} x ↓ A}

By stability of M, we have x ∈ dom(Δ′), hence (θ, id_{Δ′})(x) = x, and therefore M′ = x is as required:

\frac{(Γ, θΔ′)(x) = θA}{Γ, θΔ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} x ↓ θA}

• Case

\frac{Δ, Δ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{1} ↓ Πx : B. C Δ, Δ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{2} ⇓ B}{Δ, Δ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{1} M_{2} ↓ [M_{2}/x]C}

By inductive hypothesis we get an object M′_{1} such that

Γ, θΔ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′_{1} ↓ θ(Πx : B. C)  Γ, θΔ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θM_{1} =_{βη} M′_{1}

Using Lemma 4.2.3, we have also

Γ, θΔ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} (θM_{2})_{⇓} ⇓ θB  Γ, θΔ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θM_{2} =_{βη} (θM_{2})_{⇓}

so we see M′ = M_{1} (θM_{2})_{⇓} is as required.

Corollary 7.2.5. Let M = E[[M_{∘}]], with

Δ, Δ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[M_{∘}]] ⇓ A  (resp. Δ, Δ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[M_{∘}]] ↓ A)

(Δ, Δ′)(M, M_{∘}) ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{∘} ⇓ A_{∘}

(Δ, Δ′)(M, M_{∘}) ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A_{∘} ⇓ type

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ : Δ

if E is Δ-stable then there is an environment (θE)_{⇓} such that

Γ, θΔ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} (θE)_{⇓}[[(θM_{∘})_{⇓}]] ⇓ θA  (resp. Γ, θΔ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} (θE)_{⇓}[[(θM_{∘})_{⇓}]] ↓ θA)

Γ, θΔ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ(E[[M_{∘}]]) =_{βη} (θE)_{⇓}[[(θM_{∘})_{⇓}]]

Proof. By induction on the derivation of well-typedness of E[[M_{∘}]]. We consider a few interesting cases: • Case

\frac{Δ, Δ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} B ⇓ type Δ, Δ′, x : B ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E_{1}[[M_{∘}]] ⇓ C B ⪯^{t} C}{Δ, Δ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} λx : B. E_{1}[[M_{∘}]] ⇓ Πx : B. C}

By inductive hypothesis, there is an environment (θE_{1})_{⇓} such that

Γ, θΔ′, x : θB ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} (θE_{1})_{⇓}[[(θM_{∘})_{⇓}]] ⇓ θC

Γ, θΔ′, x : θB ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ(E_{1}[[M_{∘}]]) =_{βη} (θE_{1})_{⇓}[[(θM_{∘})_{⇓}]]

By Lemma 4.2.3, we get

Γ, θΔ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} (θB)_{⇓} ⇓ type

Γ, θΔ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θB =_{βη} (θB)_{⇓}

From this, we see that the result follows letting (θE)_{⇓} = λx : (θB)_{⇓}. (θE_{1})_{⇓}.

• Case

\frac{Δ, Δ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ↓ Πx : B. C Δ, Δ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E_{1}[[M_{∘}]] ⇓ B A_{∘} ⊀^{τ} C}{Δ, Δ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M E_{1}[[M_{∘}]] ↓ C}

By the assumptions, M is stable, so we can apply Proposition 7.2.4 to obtain a M′ such that

Γ, θΔ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′ ↓ θ(Πx : B. C)

Γ, θΔ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θM =_{βη} M′

Also, by the inductive assumptions, there is an environment (θE_{1})_{⇓} such that

Γ, θΔ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} (θE_{1})_{⇓}[[(θM_{∘})_{⇓}]] ⇓ θB  Γ, θΔ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ(E_{1}[[M_{∘}]]) =_{βη} (θE_{1})_{⇓}[[(θM_{∘})_{⇓}]]

and therefore, taking (θE)_{⇓} = M′ (θE_{1})_{⇓}, we have the result.

7.3 Confluence for Simpler Equational Theories

At the core of most adaptations of most of the adaptations of Knuth and Bendix’s criterion there usually lies the same “key lemma”. Although its statement can be quite complex, the idea behind it is quite simple: when rewriting a object instance θM, one of the following, mutually-exclusive, situations must happen:

1. rewriting takes place inside one of the sub-objects θ(x) (where x ∈ dom(θ)) introduced by the substitution;

2. the object being replaced is θM′, where M′ is a non-variable sub-object of M. Pictorially:

We present here our version of the key lemma:

Lemma 7.3.1. Let M′ = E′[[M′_{∘}]], with

Δ, Δ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇓ A Δ-pattern  (resp. Δ, Δ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ↓ A Δ-pattern)
Γ, θΔ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E′[[M′_{∘}]] ⇓ θA  (resp. Γ, θΔ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E′[[M′_{∘}]] ↓ θA)

(Γ, θΔ′_{∘})(M′, M′_{∘}) ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′_{∘} ⇓ A′_{∘}

(Γ, θΔ′_{∘})(M′, M′_{∘}) ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A′_{∘} ⇓ type

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ : Δ

such that

Γ, θΔ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θM =_{E′βη} E′[[M′_{∘}]]

if A′_{∘} ⪯̸^{t} E′, then there is a Δ-stable environment E such that

1. either M = E[[M_{∘}]], and

Γ, θΔ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E′ ≈_{E′} (θE)_{⇓}  (Γ, θΔ′_{∘})(M′, M′_{∘}) ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θM_{∘} =_{E′βη} M′_{∘}

2. or M = E[[N]], where N = x N_{1} N_{2} … N_{k} is a Δ-generalized variable, and there is an environment E′_{∘} such that

Γ, θΔ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E′ ≈_{E′} ((θE)_{⇓} · E′_{∘})

Γ, θΔ′_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ(x) =_{E′βη} λy_{1} : A_{1} … λy_{k} : A_{k}. E′_{∘}[[M′_{∘}]]

Proof. By induction on the derivation of M. We examine some representative cases:

• Case

\frac{Δ, Δ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} B ⇓ type Δ, Δ′, x : B ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{1} ⇓ C B ⪯^{t} C}{Δ, Δ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} λx : B. M_{1} ⇓ Πx : B. C}

Since θM = λx : θB. θM_{1}, we have

Γ, θΔ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} λx : θB. θM_{1} =_{E′βη} E′[[M′_{∘}]]

Using Theorem 4.4.20 and the fact that all the equations in E′ are of base type, we easily see that E′ = λx : B′. E′_{1}, with

Γ, θΔ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θB =_{Eβη} B′  Γ, θΔ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} B′ ⇓ type
Γ, θΔ′, x : θB ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θM_{1} =_{E′βη} E′_{1}[[M′_{∘}]]  Γ, θΔ′, x : θB ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E′_{1}[[M′_{∘}]] ⇓ θC

We can therefore apply the inductive hypothesis to M_{1}, obtaining an environment E_{1} satisfying in the statement. We want to show that E = λx : B. E_{1} is as required. If E_{1} satisfies case (1) of the statement, then

Γ, θΔ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} λx : θB. E′_{1} ≈_{E′} λx : θB. (θE_{1})_{⇓}

Using the assumptions, Lemma 4.2.3, and Weakening

Γ, θΔ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} B′ =_{Eβη} θB  Γ, θΔ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θB =_{Eβη} (θB)_{⇓}

from which we see

Γ, θΔ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} λx : B′. E′_{1} ≈_{E′} λx : θB. E′_{1} Γ, θΔ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} λx : θB. (θE_{1})_{⇓} ≈_{E′} λx : (θB)_{⇓}. (θE_{1})_{⇓}

By transitivity

Γ, θΔ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} λx : B′. E′_{1} ≈_{E′} λx : (θB)_{⇓}. (θE_{1})_{⇓}

and hence, since (θE)_{⇓} = λx : (θB)_{⇓}. (E_{1})_{⇓}, the result. A similar proof shows that if E_{1} satisfies case (2), so does E.

\frac{Δ, Δ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ↓ A Δ, Δ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ↓ type}{Δ, Δ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇓ A}

There are two possibilities. If M is a Δ-generalized variable, then M = x N_{1} N_{2} … N_{k}, where N_{i} →_{η}^{∗} y_{i} ∈ dom(Δ′) are pairwise distinct variables. Let Δ′(y_{i}) = A_{i}, we easily see

Γ, θΔ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} (θ(x))_{⇓} ≈ λy_{1} : A_{1} … λy_{k} : A_{k}. (θM)_{⇓}

and therefore, using the assumptions and transitivity,

Γ, θΔ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ(x) =_{βη} λy_{1} : A_{1} … λy_{k} : A_{k}. E′[[M′_{∘}]]

From this we see that letting E = ∘ and E′_{∘} = E′, we satisfy case (2) of the statement. If M is not a Δ-generalized variable, then M is Δ-stable. Moreover, from Δ, Δ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ↓ type we conclude Γ, θΔ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} (θA)_{⇓} ↓ type, and hence, by inversion and type conversion,

Γ, θΔ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E′[[M′_{∘}]] ↓ θA,

and the result follows from the inductive assumptions.

• Case

\frac{Δ, Δ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{1} ↓ Πx : B. C Δ, Δ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{2} ⇓ B}{Δ, Δ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{1} M_{2} ↓ [M_{2}/x]C}

Since M is Δ-stable, so is M_{1} , so by Proposition 7.2.4 there is M′′_{1} such that

Γ, θΔ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′′_{1} ↓ θ(Πx : B. C)  Γ, θΔ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} (θM_{1})_{⇓} =_{βη} M′′_{1}

Hence we conclude

Γ, θΔ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′′_{1} (M_{2})_{⇓} ↓ θ([M_{2}/x]C).  Γ, θΔ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θM =_{βη} M′′_{1} (θM_{2})_{⇓}

Since, by the assumptions and Proposition 6.3.4,

Γ, θΔ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E′[[M′_{∘}]] ↓ θ([M_{2}/x]C),  Γ, θΔ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θM =_{βη} E′[[M′_{∘}]]

we have

Γ, θΔ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′′_{1} (θM_{2})_{⇓} ≈_{E′} E′[[M′_{∘}]]

We notice that both E′[[M′_{∘}]] and M′′_{1} (θM_{2})_{⇓} are atomic, and that, by the condition A′_{∘} ⪯̸^{t} E′, in the derivation above the E′-conversion rule cannot be applied directly. Under these circumstances, we are able to show that either E′ = E′_{1} M′_{2} or E′ = M′_{1} E′_{2}. We assume the latter; the proof for the former is similar. By inversion, and possibly type conversion, we get

Γ, θΔ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E′_{2}[[M′_{∘}]] ⇓ θB  Γ, θΔ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} (θM_{2})_{⇓} ≈_{E′} E′_{2}[[M′_{∘}]]

Γ, θΔ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′′_{1} ≈_{E′} M′_{1}

and hence, by Proposition 4.3.2,

Γ, θΔ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θM_{1} =_{E′βη} M′_{1}  Γ, θΔ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} (θM_{2}) =_{E′βη} E′_{2}[[M′_{∘}]]

By inductive hypothesis there is a canonical environment E_{2} satisfying the statement. Then E = M_{1} E_{2} is as required.

We introduce now the definition of critical pair generated by two rules in R:

Definition 7.3.2 (R|E|R-Critical Pair). Let R be a HTRS, E′ ⊆ E,

Δ_{i} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} l_{i} → r_{i} : C_{i} ∈ R  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ_{i} : Δ_{i} (i = 1, 2),

and E be a Δ_{1}-stable environment not isolating a generalized variable, and such that

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ_{1}l_{1} =_{E′βη} (θ_{1}E)_{⇓}[[θ_{2}l_{2}]]

then

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} <(θ_{1}E)_{⇓}[[θ_{2}r_{2}]], θ_{1}r_{1} >

is called a (R|E′|R)-critical pair.

A (R|E′|R)-critical pair Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} <M_{1}, M_{2} > is said to be trivial if there are objects N_{1} and N_{2} such that

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{i} →_{R/E′βη}^{∗} N_{i} (i = 1, 2)  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N_{1} =_{Eβη} N_{2}

Notation. When E′ = ·, (R|E′|R)-critical pairs will be called (R|R)-critical pairs.

Remark. It requires some work to see that the definition above actually corresponds to the usual one. First, by considering a renaming substitution if necessary, we can assume in practice

dom(Δ_{1}) ∩ dom(Δ_{2}) = ∅

and take θ = θ_{1} ∪ θ_{2} to be a most general E-unifier of the two objects.

Secondly, by Proposition 7.2.3, the assumption of stability of E corresponds to the requirement of overlaps not to occur below generalized variables.

Notice that, using the assumption R ⊀^{τ} R and Proposition 6.1.6, the environment E is always wellformed. Hence by Proposition 6.1.4 both objects of a critical pair are of type θC_{1}. Because we will be interested in HTRSs where all the critical pairs are trivial, and since →_{R/E′βη} requires both objects to be well typed, and of a same type, the cryptic requirement R ⊀^{τ} R that we imposed in Definition 6.2.1 seems now fully justified.

We have now all the ingredients to prove the Critical Pair Criterion for simpler equational theories:

Lemma 7.3.3. Let E′ ⊆ E be simpler than R, then all the (R|E′|R)-critical pairs are trivial iff

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{R_{E′βη}} N_{i} (i = 1, 2) implies ∃N′_{i} s. t. \begin{cases}Γ ⊢\begin{matrix}≺ \\ Σ \end{matrix} N_{i} →_{R/E′βη}^{∗} N′_{i} (i = 1, 2) \\ Γ ⊢\begin{matrix}≺ \\ Σ \end{matrix} N′_{1} =_{Eβη} N′_{2} \end{cases}

for all objects M, N_{1} and N_{2}. In pictures, the condition above corresponds to the commutativity of the following diagram:

[figure: M; R_{E′βη}; R_{E′βη}; N_{1}; (R/E′βη)^{∗}; N′_{1}; Eβη; N_{2}; (R/E′βη)^{∗}; N′_{2}]

Proof. We will start by proving the easy direction of this double implication. Assume the diagram above commutes for all choices of canonical objects, and let

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} <(θ_{1}E)_{⇓}[[θ_{2}r_{2}]], θ_{1}r_{1} >

be a (R|E′|R)-critical pair.

Let M = (θ_{1}E)_{⇓}[[θ_{2}l_{2}]], we have

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{R_{E′βη}} (θ_{1}E)_{⇓}[[θ_{2}r_{2}]]  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{R_{E′βη}} θ_{1}r_{1}

By the assumptions, we find objects N′_{i} such that

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} (θ_{1}E)_{⇓}[[θ_{2}r_{2}]] →_{R/E′βη}^{∗} N′_{1}  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ_{1}r_{1} →_{R/E′βη}^{∗} N′_{2}  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N′_{1} =_{Eβη} N′_{2}

so we conclude that the given critical pair is trivial.

Conversely, assume that all (R|E′|R)-critical pairs are trivial, and let M, N_{1}, N_{2} as in the statement. By unraveling the definitions, we get

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{⇓} ≈_{E′} E^{(i)}[[M_{∘}^{(i)}]]  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} (N_{i})_{⇓} ≈_{E′} E^{(i)}[[N_{∘}^{(i)}]]
Γ_{∘}^{(i)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{∘}^{(i)} ⇓ θ_{i}C_{∘}^{(i)}  Γ_{∘}^{(i)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N_{∘}^{(i)} ⇓ θ_{i}C_{∘}^{(i)}
Γ_{∘}^{(i)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{∘}^{(i)} =_{E′βη} θ_{i}l_{i}  Γ_{∘}^{(i)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N_{∘}^{(i)} =_{E′βη} θ_{i}r_{i}
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E^{(i)}[[Γ_{∘}^{(i)} ⊢ ∘ : θ_{i}C_{∘}^{(i)}]] ⇓ A  Γ_{∘}^{(i)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ_{i} : Δ_{∘}^{(i)}

Δ_{∘}^{(i)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} l_{i} → r_{i} : C_{∘}^{(i)} ∈ R

for i = 1, 2.

From the assumption R ⪯̸^{t} E′ it follows θ_{i}C_{∘}^{(i)} ⪯̸^{t} E′, so we can apply Proposition 7.1.3 obtaining environments E^{i} and objects M_{∘}^{i} such that

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E^{(i)} ≈_{E′} E^{i}  Γ_{∘}^{(i)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{∘}^{(i)} ≈_{E′} M_{∘}^{i}

and M_{⇓} = E^{i}[[M_{∘}^{i}]].

Since, by Propositions 4.3.2 and 6.3.16,

Γ_{∘}^{(i)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{∘}^{i} =_{E′βη} θ_{i}l_{i}  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} (N_{i})_{⇓} ≈_{E′} E^{i}[[N_{∘}^{(i)}]]

we will assume, without loss of generality, E^{(i)} = E^{i} and M_{∘}^{(i)} = M_{∘}^{i}, i.e. M_{⇓} = E^{(i)}[[M_{∘}^{(i)}]]. If E^{(1)} ↑ E^{(2)}, then, by Proposition 6.1.9 and Theorem 6.3.14, we easily show

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N_{i} →_{R/E′βη} N′_{i} (i = 1, 2)

where N′_{1} = N′_{2} = (E^{(1)})_{E^{(2)}[[N_{∘}^{(2)}]]}[[N_{∘}^{(1)}]].

Otherwise we can assume, without loss of generality, E^{(2)} = (E^{(1)} · E′) for some well-formed environment E′. Hence we have

Γ_{∘}^{(1)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{∘}^{(1)} =_{E′βη} E′[[M_{∘}^{(2)}]]

and it will suffice to prove the theorem for N_{1} = N_{∘}^{(1)} and N_{2} = E′[[N_{∘}^{(2)}]].

By transitivity,

Γ_{∘}^{(1)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ_{1}l_{1} =_{E′βη} E′[[M_{∘}^{(2)}]]

so we can find an environment E satisfying the statement of Lemma 7.3.1.

Assume E satisfies case (1) of the statement; then

Γ_{∘}^{(1)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E′ ≈_{E′} (θ_{1}E)_{⇓}

and therefore, by Propositions 6.1.4 and 6.3.16,

Γ_{∘}^{(1)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ_{1}l_{1} =_{E′βη} (θ_{1}E)_{⇓}[[θ_{2}l_{2}]]

Hence Γ_{∘}^{(1)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} < (θ_{1}E)_{⇓}[[θ_{2}l_{2}]], θ_{1}r_{1} > is a (R|E′|R)-critical pair; by the assumptions, it must be trivial, so there are N′_{1} and N′_{2} such that

Γ_{∘}^{(1)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} (θ_{1}E)_{⇓}[[θ_{2}l_{2}]] →_{R/E′βη}^{∗} N′_{1}  Γ_{∘}^{(1)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ_{1}r_{1} →_{R/E′βη}^{∗} N′_{2}

and Γ_{∘}^{(1)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N′_{1} =_{Eβη} N′_{2}.

Since, using again Propositions 6.1.4 and 6.3.16, we can show

Γ_{∘}^{(1)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E′[[N_{∘}^{(2)}]] =_{E′βη} (θ_{1}E)_{⇓}[[θ_{2}r_{2}]]  Γ_{∘}^{(1)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N_{∘}^{(1)} =_{E′βη} θ_{1}r_{1}

the result follows by invariance of →_{R/E′βη} with respect to E′- and βη-conversion.

The remaining possibility is that E satisfies part (2) of the statement of Lemma 7.3.1. In this case l_{1} = E[[U]], where U = x U_{1} U_{2} … U_{k} is a generalized variable, and there is an environment E_{∘} such that

Γ_{∘}^{(1)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E′ ≈_{E} ((θ_{1}E)_{⇓} · E_{∘})

Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ_{1}(x) =_{Eβη} λy_{1} : A_{1} … λy_{k} : A_{k}. E_{∘}[[M_{∘}^{(2)}]]

Let Δ_{∘}^{(1)}(x) = B, applying Proposition 6.1.3 to the (well-typed) environment E_{∘}, we conclude C_{∘}^{(2)} ⪯^{t} B. From this we immediately see B ⊀^{τ} C_{∘}^{(1)}: otherwise, we would have

C_{∘}^{(2)} ⪯^{t} B ≺^{τ} C_{∘}^{(1)}

implying C_{∘}^{(2)} ≺^{τ} C_{∘}^{(1)}, a contradiction to the assumption R ⊀^{τ} R.

Let l_{1} = E_{U′}[[U′]] where U′ = x U′_{1} U′_{2} … U′_{k} is any other occurrence of a generalized variable (with the same underlying variable x as U), we apply Proposition 6.1.6 to conclude

Δ_{∘}^{(1)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E_{U′}[[Δ_{∘}(l_{1}, U′) ⊢ ∘ : type(Δ_{∘}(l_{1}, U′))]] : C_{∘}^{(1)}

Moreover, all these environments E_{U′} are disjoint, and Δ_{∘}^{(1)}-stable by Proposition 7.2.3.

By Corollary 7.2.5 and Proposition 6.1.6, we see that

Δ_{∘}^{(1)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} ((θ_{1}E_{U′})_{⇓} · E_{∘})[[Γ_{∘}^{(2)} ⊢ ∘ : θ_{2}C_{∘}^{(2)}]] ⇓ θ_{1}C_{∘}^{(1)}

Using repeatedly Proposition 6.1.9, we show

Γ_{∘}^{(1)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E′[[θ_{2}r_{2}]] →_{R/βη}^{∗} θ′_{1}l_{1} →_{R} θ′_{1}r_{1}

where Γ_{∘}^{(1)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ′_{1} : Δ_{∘}^{(1)} is defined as:

θ′_{1}(z) = \begin{cases}θ_{1}(z) & z ≠ x \\ λy_{1} : A_{1} … y_{k} : A_{k}. E_{∘}[[N_{∘}^{(2)}]] & z = x \end{cases}

A similar argument, applied to r_{1} instead of l_{1}, shows

Γ_{∘}^{(1)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ_{1}r →_{R/βη}^{∗} θ′_{1}r

from which we see that N′_{1} = N′_{2} = θ′_{1}r are as required.

Theorem 7.3.4 (Critical Pair Criterion for Simpler Equational Theories). Let →_{R/Eβη} be strongly normalizing, with E simpler than R. Then all (R|E|R)-critical pairs are trivial iff rewriting modulo E is Church-Rosser, i.e.

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{R/Eβη}^{∗} M_{i} (i = 1, 2) implies ∃N s. t. M_{i} →_{R/Eβη}^{∗} N (i = 1, 2)

for all objects M, M_{1}, and M_{2}; or, in pictures, iff the following diagram commutes:

\xymatrix{M \ar[r]^{(R/Eβη)^{∗}} \ar[d]_{(R/Eβη)^{∗}} & M_{1} \ar@{-->}[d]^{(R/Eβη)^{∗}} \\ M_{2} \ar@{-->}[r]_{(R/Eβη)^{∗}} & N}

Proof. Assume →_{Eβη} is Church-Rosser, then all the (R|E|R)-critical pairs are trivial by Lemma 7.3.3 and Proposition 6.3.6.

Conversely, assume all (R|E|R)-critical pairs are trivial; by Theorem 6.3.14, it suffices to prove that →_{R_{Eβη}} is Church-Rosser. From the assumptions and Corollary 6.3.7 it follows that →_{R_{Eβη}} is strongly normalizing. Hence, by Newman’s Lemma, it suffices to show that canonical rewriting is locally Church-Rosser, i.e. that the diagram

\xymatrix{M \ar[r]^{R_{Eβη}} \ar[d]_{R_{Eβη}} & M′ \ar@{-->}[d]^{R_{Eβη}^{∗}} \\ M′′ \ar@{-->}[r]_{R_{Eβη}^{∗}} & N}

commutes. We use again Theorem 6.3.14 again to transform the problem to the diagram

\xymatrix{M \ar[r]^{R_{Eβη}} \ar[d]_{R_{Eβη}} & N_{1} \ar@{-->}[d]^{(R/Eβη)^{∗}} \\ N_{2} \ar@{-->}[r]_{(R/Eβη)^{∗}} & U}

whose commutativity is ensured, under the current assumptions, by Lemma 7.3.3

7.4 Internal Rewriting

From the proof of 7.3.3 we can extract a result that may simplify the task of determining if a given object is a (→_{R_{Eβη}})-normal form. We introduce first the following definition:

Definition 7.4.1. We say that M rewrites internally modulo E to N under R, and write

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{R[E]} N

if and only if

M_{⇓} = E[[M_{∘}]]  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N_{⇓} ≈ E[[N_{∘}]]
Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{∘} ⇓ θC_{∘}  Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N_{∘} ⇓ θC_{∘}
Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{∘} =_{Eβη} θl  Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N_{∘} =_{βη} θr
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[Γ_{∘} ⊢ ∘ : θC_{∘}]] ⇓ A  Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ : Δ_{∘}

Δ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} l → r : C_{∘} ∈ R

Remark. From the definition, it is easy to see that (→_{R[E]})-rewriting involves only E-pattern matching with the LHS of a rule, instead of E-conversion of the entire object, as in the case of →_{R_{Eβη}} and →_{R/Eβη}.

Lemma 7.4.2. Let E be simpler then R, then

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{R_{Eβη}}^{+} N implies ∃N′ s.t. Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{R[E]}^{+} N′ and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N′ =_{Eβη} N

Proof. It will suffice to prove the statement for one-step canonical rewriting, i.e.

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{R_{Eβη}} N_{1}

The result will then follow arguing by induction on the length of the rewriting sequence, and using invariance of canonical rewriting with respect to conversion.

By Definition 6.3.1,

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{⇓} →_{R_{Eβη}} N_{1}

if and only if

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{⇓} ≈_{E} E[[M_{∘}]]  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} (N_{1})_{⇓} ≈_{E} E[[N_{∘}]]
Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{∘} ⇓ θC_{∘}  Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N_{∘} ⇓ θC_{∘}
Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{∘} =_{Eβη} θl  Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N_{∘} =_{Eβη} θr
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E[[Γ_{∘} ⊢ ∘ : θC_{∘}]] ⇓ A  Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ : Δ_{∘}

Δ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} l → r : C_{∘} ∈ R

Using the assumption R ⪯̸^{t} E, we conclude θC_{∘} ⪯̸^{t} E. We can therefore apply Proposition 7.1.3 obtaining E′ and M′_{∘} such that

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E ≈_{E} E′  Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{∘} ≈_{E} M′_{∘}

and M_{⇓} = E′[[M′_{∘}]].

From Propositions 4.3.2 and 6.3.16 it follows

Γ_{∘}^{(i)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′_{∘} =_{Eβη} θl  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} (N_{1})_{⇓} ≈_{E} E′[[(θr)_{⇓}]]

so we see that, by letting N′_{1} = E′[[(θr)_{⇓}]], we have

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{R[E]} N′_{1}  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N_{1} =_{Eβη} N′_{1}

Theorem 7.4.3. Let E simpler than R, and assume →_{E/βη} strongly normalizing. Then all the R|E|Rcritical pairs are trivial if and only if →_{R[E]} is confluent modulo E- and βη-conversion, i.e.

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{1} =_{Eβη} M_{2} and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{i} →_{R[E]}^{∗} M′_{i} (i = 1, 2) implies ∃N_{1}, N_{2} s. t. \begin{cases}Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′_{i} →_{R[E]}^{∗} N_{i} \\ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N_{1} =_{Eβη} N_{2} \end{cases}

for all objects M_{i} and M′_{i}.

Graphically, confluence of →_{R[E]} modulo E- and βη-conversion corresponds to commutativity of the following diagram:

[figure: M_{1}; R[E]^{∗}; Eβη; M′_{1}; R[E]^{∗}; M_{2}; R[E]^{∗}; N′_{1}; Eβη; M′_{2}; R[E]^{∗}; N_{2}]

Proof. In light of Theorem 7.3.4, it suffices to show that →_{R[E]} is confluent modulo E- and βη-conversion if and only if →_{R/Eβη} is Church-Rosser.

Assume →_{R[E]} confluent modulo E- and βη-conversion, and

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{R/Eβη}^{∗} M_{i} (i = 1, 2)

Using Theorem 6.3.14 and Lemma 7.4.2 we conclude that, for some objects M′_{i},

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{R[E]}^{∗} M′_{i} and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′_{i} =_{Eβη}^{∗} M_{i} (i = 1, 2)

Hence there are objects N_{i} such that

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′_{i} →_{R[E]}^{∗} N_{i} (i = 1, 2) and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N_{1} =_{Eβη} N_{2}

and this gives us the result, since it is readily verified that

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{i} →_{R/Eβη}^{∗} N_{i} (i = 1, 2)

Conversely, assume →_{R/Eβη} is Church-Rosser, and furthermore

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{1} =_{Eβη} M_{2} and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{i} →_{R[E]}^{∗} M′_{i} (i = 1, 2)

By definition,

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{1} →_{R/Eβη}^{∗} M′_{i} (i = 1, 2)

hence there is an object N such that

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′_{i} →_{R/Eβη}^{∗} N (i = 1, 2)

Using Theorem 6.3.14 and Lemma 7.4.2 again, we get objects N_{1} and N_{2} such that

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′_{i} →_{R[E]}^{∗} N_{i} (i = 1, 2)  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N_{i} =_{Eβη} N (i = 1, 2)

which concludes the proof.

7.5 Completion by Stages

In Definition 6.2.1 we define well-formedness of a HTRS R by the condition R ⊀^{τ} R, and we proceed developing our theory in Chapter 7 and 8 relying on the assumption that the HTRSs we deal with are wellformed. The reader will wonder how important is this assumption in our constructions, and if it is possible to relax it under some special circumstances. The answer is affirmative, and in what follows we will describe a technique by us named “completion by stages” to establish confluence of some non-well-formed HTRSs.

Let R be a strong normalizing HTRS such that R ⊀^{τ} R, assume R can be partitioned into the disjoint union of HTRSs R_{i}:

R = R_{1} ⊔ R_{2} ⊔ ⋯ ⊔ R_{n}

verifying the following properties:

1. R_{i} is well-formed, i.e. R_{i} ⊀^{τ} R_{i};

2. R_{i} ⪯̸^{t} R_{j} for all j < i

For any such R we can establish confluence as follows. First, observe that each of the R_{i} is strong normalizing, since R is. We apply Theorem 7.4.3 to establish confluence of R_{1} modulo E_{1} = ·. Let E(R_{1}) the equational theory generated by R_{1},

E(R_{1}) = \{ Γ ⊢\begin{matrix}≺ \\ Σ \end{matrix} l = r : A | (Γ ⊢\begin{matrix}≺ \\ Σ \end{matrix} l → r : A) ∈ R_{1}\}

it is easily seen to be well-formed. Moreover, equality of expressions modulo E(R_{1}) is decidable (comparing normal forms). To establish confluence of R_{1} ⊔ R_{2} we apply again the Critical Pair Criterion, this time to R_{2}, and working modulo E_{2} = E(R_{1}).

In general, define

R_{<1} = ∅  R_{<(i+1)} = R_{i} ⊔ R_{<i}

and

E_{i} = \{Γ ⊢\begin{matrix}≺ \\ Σ \end{matrix} l = r : A | (Γ ⊢\begin{matrix}≺ \\ Σ \end{matrix} l = r : A) ∈ R_{<i}\}

In the i-th step, we try to establish to establish confluence of R_{<(i+1)} under the assumption that R_{<i} has already proven confluent. We do so by using the Critical Pair Criterion given in Chapter 7 to establish confluence of R_{i+1} modulo E_{i}.

What makes this technique applicable to a vast class of cases is the remark that the statement of Theorem 7.4.3 does not require any particular restriction on the syntactic structure of the equational theory, and specifically does not require both sides of the equations to be higher-order patterns. This is important, since very few interesting HTRSs in the literature happen to have pattern right-hand-sides. Example 5. To give an idea of how frequent cases tackled by this technique are, the following example is taken from [2], with a few modifications to adapt it to a dependent type setting.

Consider the signature

Σ = {nat, 0, s, double, list, nil, cons, map, doublelist}

Σ(nat) = type Σ(0) = nat Σ(s) = Πn : nat. nat Σ(double) = Πn : nat. nat Σ(list) = Πn : nat. type Σ(nil) = list 0 Σ(cons) = Πm : nat. Πn : nat. Πn : list m. list (s m) Σ(map) = Πm : nat. Πf : (Πn : nat. nat). Πn : (list m). list m Σ(doublelist) = Πm : nat. Πn : (list m). list m It can be easily verified that this signature is well-typed under the dependence relation

≺^{t} = ≺^{τ} = {(nat, list)}

We define on Σ the HTRS R with rules:

\begin{matrix}Γ_{0} & ⊢\begin{matrix}≺ \\ Σ \end{matrix} double 0 → 0 : nat \\ Γ_{1} & ⊢\begin{matrix}≺ \\ Σ \end{matrix} double (s x) → s (s x) : nat \end{matrix} \} R_{1}

\begin{matrix}Γ_{2} & ⊢\begin{matrix}≺ \\ Σ \end{matrix} map 0 F nil → nil : list 0 \\ Γ_{3} & ⊢\begin{matrix}≺ \\ Σ \end{matrix} map (s m) F (cons m y L) → cons m (F y) (map m F L) : list (s m) \\ Γ_{4} & ⊢\begin{matrix}≺ \\ Σ \end{matrix} doublelist m L → map m double L \end{matrix} \} R_{2}

where

Γ_{0} = ·  Γ_{3} = F : Πx : nat. nat, m : nat, y : nat, L : list m
Γ_{1} = x : nat  Γ_{4} = m : nat, L : list m
Γ_{2} = F : Πx : nat. nat

This is proven strong normalizing using the techniques described in the cited paper. R is clearly not wellformed in the sense of Definition 6.2.1, but it can be decomposed into the disjoint sum of two well-formed HTRSs R_{1} and R_{2}. Since R_{2} ⪯̸^{t} R_{1}, R can be proved confluent using completion by stages.

7.6 Summary

The Critical Pair Criterion reduces the problem of establishing confluence of a strongly normalizing HTRS R to checking joinability of special pairs of objects called critical pairs. In the case of confluence modulo an equational theory E, some of these pairs come, as we will see in detail in the next chapter, from overlapping rules in R with equations in E. However, there are special circumstances under which examinations of these pairs is unneeded. In this chapter we studied a large class of problems of these kind, which could be characterized by the fact that E is defined on more primitive types than R. This idea was made precise by the definition of simpler equational theory in Section 7.1.

In section 7.2, we introduced some technical tools used in the analysis of critical pairs. These focus on a generalization of the notion of higher-order patterns which is preserved by considering sub-objects. We used this machinery in Section 7.3 to prove our specialized version of the Critical Pair Lemma; we will see that it also plays an important role use in the development of the general version of the Critical Pair Criterion, described in the next chapter.

In Section 7.4 we presented the same results from a different perspective. We introduced the third and last rewriting notion of this dissertation; this is even more restrictive than canonical rewriting, and therefore more suitable to practical implementations. Most importantly, we showed that, in the case of simpler equational theories, these two are closely related, as we showed in Lemma 7.4.2.

Section 7.5 wrapped up the subject by presenting a technique, completion by stages, that is often useful to circumvent some of the restrictions we imposed in Definition 6.2.1 on the constructions of well-formed HTRSs.

Confluence for General Equational Theories

In this chapter we will deal with the general case, when the type classes of the equational theory E could be the same as the classes of the HTRS R being considered. As we will see, we will still be able to prove similar results to those presented in Chapter 7, provided that additional critical pairs, coming from the interaction between the rewriting system R and the equational theory E, are considered. In doing this, our strategy will consist in treating the equational theory as a bi-directional HTRS. Some further assumptions will also be needed:

Notation. Throughout this chapter, we will assume the following on the equational theories E and HTRSs R considered:

• for each equation Γ_{∘} ⊢\begin{matrix}≺ \\ Σ \end{matrix} M_{∘} = N_{∘} : A_{∘}, both objects M_{∘} and N_{∘} are (higher-order) patterns;

• we have R ⊀^{τ} E.

These restrictions can be seen as the analogues of those we formulated for HTRSs in Definition 6.2.3.

8.1 One-Step E-Conversion

We start by introducing a different, more “rewrite-like”, formulation of congruence modulo βη- and Econversion. The relation =_{Eβη} introduced in chapter 2 is ill-suited for our purposes, as it is intrinsically transitive, and therefore capable of performing several equational steps in parallel. We will need a more fine-grained notion, where only one E-conversion step is performed at a time. This motivates the following:

Definition 8.1.1. We define the judgments

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{E} M′ M E-converts to M′
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A →_{E} A′ A E-converts to A′

derived according to the set of rules listed in Figure 8.1

As usual, we will start by listing a few basic properties of this new judgment. The proofs, unless stated otherwise, will be obtained by a simple induction on the derivations.

Proposition 8.1.2.

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : A and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{E} M′ implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ≈_{E} M′
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A : K and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A →_{E} A′ implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ≈_{E} A′

\frac{(Δ ⊢\begin{matrix}≺ \\ Σ \end{matrix} M_{∘} = N_{∘} : A_{∘}) ∈ E Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ : Δ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M =_{βη} θM_{∘} Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N =_{βη} θN_{∘} Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N ⇓ θA_{∘}}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{E} N}

\frac{(Δ ⊢\begin{matrix}≺ \\ Σ \end{matrix} N_{∘} = M_{∘} : A_{∘}) ∈ E Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ : Δ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M =_{βη} θM_{∘} Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N =_{βη} θN_{∘} Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N ⇓ θA_{∘}}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{E} N}

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A →_{E} A′ Γ, x : A ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : B}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} λx : A. M →_{E} λx : A′. M}

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A : type Γ, x : A ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{E} M′}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} λx : A. M →_{E} λx : A. M′}

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{E} M′ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N : A}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M N →_{E} M′ N}  \frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : A Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N →_{E} N′}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M N →_{E} M N′}

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A →_{E} A′ Γ, x : A ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} B : type}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} Πx : A. B →_{E} Πx : A′. B}

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A : type Γ, x : A ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} B →_{E} B′}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} Πx : A. M →_{E} Πx : A. M′}

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A : K Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{E} M′}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A M →_{E} A M′}

Figure 8.1: One-step E-conversion

Proposition 8.1.3 (Weakening). Let ≺⊆≺′, Σ ⊆ Σ′, E ⊆ E′, , Γ ⊆ Γ′,

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{E} M′ implies Γ′ ⊢\begin{matrix}≺′ \\ Σ′,E′ \end{matrix} M →_{E′} M′
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A →_{E} A′ implies Γ′ ⊢\begin{matrix}≺′ \\ Σ′,E′ \end{matrix} A →_{E′} A′

Proposition 8.1.4. Let Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} C =_{Eβη} C′ : type,

Γ, x : C, Γ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{E} M′ implies Γ, x : C′, Γ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{E} M′
Γ, x : C, Γ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A →_{E} A′ implies Γ, x : C′, Γ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A →_{E} A′

Proposition 8.1.5. Let Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N : C,

Γ, x : C, Γ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{E} M′ implies ∃U′, U′′ s.t. \begin{cases}Γ, [N/x]Γ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} [N/x]M →_{E}^{∗} U′′ \\ Γ, [N/x]Γ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} [N/x]M′ ⇒_{β}^{∗} U′ \\ Γ, [N/x]Γ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} U′ ⇒_{η}^{∗} U′′ \end{cases}
Γ, x : C, Γ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A →_{E} A′ implies ∃D′, D′′ s.t. \begin{cases}Γ, [N/x]Γ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} [N/x]A →_{E}^{∗} D′′ \\ Γ, [N/x]Γ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} [N/x]A′ ⇒_{β}^{∗} D′ \\ Γ, [N/x]Γ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} D′ ⇒_{η}^{∗} D′′ \end{cases}

provided that M and A are well-formed expressions.

Moreover, |β(U′)| = |β(U′′)| and |β(D′)| = |β(D′′)|.

Proof. By induction on the derivations of Γ, x : C, Γ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{E} M′ and Γ, x : C, Γ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A →_{E} A′. The only non-trivial case is given by the E-conversion step:

• Case

\frac{(Δ ⊢\begin{matrix}≺ \\ Σ \end{matrix} M_{∘} = M′_{∘} : A_{∘}) ∈ E Γ, x : C, Γ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ_{∘} : Δ Γ, x : C, Γ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M =_{βη} θ_{∘}M_{∘} Γ, x : C, Γ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′ =_{βη} θ_{∘}M′_{∘} Γ, x : C, Γ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′ ⇓ θ_{∘}A_{∘}}{Γ, x : C, Γ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{E} M′}

Let θ = (id_{Γ}, x ↦ N, id_{Γ′}), under our assumptions Γ, [N/x]Γ′ ⊢\begin{matrix}≺ \\ Σ \end{matrix} θ : Γ, x : C, Γ′. Using Proposition 2.2.2

Γ, [N/x]Γ′ ⊢\begin{matrix}≺ \\ Σ \end{matrix} [N/x]M =_{βη} (θ · θ_{∘})M_{∘}

Γ, [N/x]Γ′ ⊢\begin{matrix}≺ \\ Σ \end{matrix} [N/x]M′ =_{βη} (θ · θ_{∘})M′_{∘}

Γ, [N/x]Γ′ ⊢\begin{matrix}≺ \\ Σ \end{matrix} (θ · θ_{∘}) : Δ

By Lemma 4.2.3,

Γ, [N/x]Γ′ ⊢\begin{matrix}≺ \\ Σ \end{matrix} θM′ ⇒_{βη}^{∗} (θM′)_{⇓}  Γ, [N/x]Γ′ ⊢\begin{matrix}≺ \\ Σ \end{matrix} (θM′)_{⇓} ⇓ (θ · θ_{∘})A_{∘}

and we can furthermore assume that U′′ = (θM′)_{⇓} is obtained by first β-reducing θM′ = [N/x]M′ to its normal form U′, and then η-expanding U′. Hence, using Proposition 4.1.7,

Γ, [N/x]Γ′ ⊢\begin{matrix}≺ \\ Σ \end{matrix} [N/x]M′ ⇒_{β}^{∗} U′ ⇒_{η}^{∗} U′′

Γ, [N/x]Γ′ ⊢\begin{matrix}≺ \\ Σ \end{matrix} [N/x]M →_{E}^{∗} U′′

Proposition 8.1.6. Let Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N : C and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N →_{E} N′

Γ, x : C, Γ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : A implies Γ, [N/x]Γ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} [N/x]M →_{E}^{∗} [N′/x]M
Γ, x : C, Γ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A : K implies Γ, [N/x]Γ′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} [N/x]A →_{E}^{∗} [N′/x]A

The notion of E-conversion given by Definition 8.1.1 is not, in general, symmetric. It is, however, when considered modulo βη-conversion:

Proposition 8.1.7.

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : A and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{E} M′ implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′ →_{E/βη} M
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A : K and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A →_{E} A′ implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A′ →_{E/βη} A

Proof. By induction on the derivations of Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{E} M′ and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A : K. The only interesting case is:

• Case

\frac{(Δ ⊢\begin{matrix}≺ \\ Σ \end{matrix} N_{∘} = M_{∘} : A_{∘}) ∈ E Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ : Δ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M =_{βη} θM_{∘} Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N =_{βη} θN_{∘} Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N ⇓ θA_{∘}}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{E} N}

By Lemma 4.2.3, we obtain

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{⇓} ⇓ θA_{∘}  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{⇓} =_{βη} M

and therefore Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{⇓} =_{βη} θM_{∘}, so we see that

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N →_{E} M_{⇓}  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{⇓} =_{βη} M

Corollary 8.1.8. We have

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{E/βη}^{∗} M′ iff Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′ →_{E/βη}^{∗} M
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A →_{E/βη}^{∗} A′ iff Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A′ →_{E/βη}^{∗} A

provided that M and A are well-formed expressions.

Proof. By induction on the length of the conversion sequences, using Proposition 8.1.7.

Theorem 8.1.9. The following holds for all well-formed expressions M and A

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M =_{Eβη} M′ iff Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{E/βη}^{∗} M′
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A =_{Eβη} A′ iff Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A →_{E/βη}^{∗} A′

Proof. One direction is given by Propositions 8.1.2 and 4.3.2; the other is obtained by induction on the derivations of Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M =_{Eβη} M′ and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A =_{Eβη} A′. We examine the most interesting cases:

• Case

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′ =_{Eβη} M}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M =_{Eβη} M′}

By inductive hypothesis we get Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′ →_{E/βη}^{∗} M, and the result follows by Corollary 8.1.8.

• Case

\frac{Δ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{∘} = M′_{∘} : A ∈ E Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ : Δ}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θM_{∘} =_{Eβη} θM′_{∘}}

By Lemma 4.2.3 we have

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} (θM′_{∘})_{⇓} =_{βη} θM′_{∘}  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} (θM′_{∘})_{⇓} ⇓ θA

and from this the result follows, since

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θM_{∘} →_{E} (θM′_{∘})_{⇓}

8.2 Canonical One-Step E-Conversion

While the alternative formulation of =_{Eβη} as reflexive transitive closure of →_{E/βη} is more convenient, still it is far from ideal, since βη-conversion gets in the way, making its use quite cumbersome. For this reason we introduce yet another notion, which overcome these difficulties by applying E-conversion only to objects in canonical form:

Definition 8.2.1. We say that the well-typed object M E-converts canonically modulo βη, and write

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{E_{βη}} N

provided that

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{⇓} ≈ M′  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′ →_{E} N′  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N_{⇓} ≈ N′

for some objects M′ and N′ such that Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′ ≈ N′ does not hold.

The similarity in notation between canonical E-conversion →_{E_{βη}} and canonical rewriting →_{R_{βη}} (see Definition 6.3.1) is far from being accidental. As a matter of fact, both relations serve similar purposes, and share most properties.

Proposition 8.2.2. The following holds:

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{E_{βη}} N implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{E/βη} N

Proof. It follows immediately from Definition 8.2.1, Lemma 4.2.3, and Proposition 4.3.2, since

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M =_{βη} M′  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′ →_{E} N′  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N′ =_{βη} N

To prove that →_{E/βη}^{∗} implies →_{E_{βη}}^{∗}, we will follow the same outline used in Chapter 6 for →_{R/Eβη} and →_{R_{Eβη}}, i.e. we will show first commutativity of →_{E} with respect to β-reduction and η-expansion.

Lemma 8.2.3.

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{E} M′ and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒_{η} M′′ implies ∃N s. t. Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′ ⇒_{η}^{=} N and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′′ →_{E} N
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A →_{E} A′ and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇒_{η} A′′ implies ∃B s. t. Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A′ ⇒_{η}^{=} B and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A′′ →_{E} B

provided that M and A are well-typed expressions.

In pictures, the following diagrams commute:

\xymatrix{M \ar[r]^{E} \ar@{=>}[d]_{η} & M′ \ar@{=>}[d]^{η^{=}} & A \ar[r]^{E} \ar@{=>}[d]_{η} & A′ \ar@{=>}[d]^{η^{=}} \\ M′′ \ar@{-->}[r]_{E} & N & A′′ \ar@{-->}[r]_{E} & B}

Proof. By induction on the derivations of Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{E} M′ and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A →_{E} A′. Most cases are trivial, as they follow through from the inductive hypothesis. Two interesting ones are:

• Case

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{1} →_{E} M′_{1} Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{2} : B}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{1} M_{2} →_{E} M′_{1} M_{2}}

If Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒^{I}_{η} M′′, then either M′′ = M′′_{1} M_{2}, with

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{1} ⇒_{η} M′′_{1}

in which case the result follows by inductive hypothesis, or M′′ = M_{1} M′′_{2}, with

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{2} ⇒_{η} M′′_{2}

and N = M′_{1} M′′_{2} is as required.

Otherwise, we must have M′′ = λx : B. M x, where

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : Πx : B. C  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} B ⇓ type

Using this assumptions, we can construct a derivation of

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} λx : B. M x →_{E} λx : B. M′ x

thus the result follows letting N = λx : B. M′ x.

• Case

\frac{(Δ ⊢\begin{matrix}≺ \\ Σ \end{matrix} M_{∘} = N_{∘} : C) ∈ E Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ : Δ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M =_{βη} θM_{∘} Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′ =_{βη} θN_{∘} Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′ ⇓ θC}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{E} M′}

We have Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′′ =_{βη} M, and by transitivity we get

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′′ →_{E} M′

so we see that in this case N = M′.

Corollary 8.2.4. For all well-formed objects Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : A

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{E}^{∗} M′ and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒_{η}^{∗} M′′ implies ∃N s. t. Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′ ⇒_{η}^{∗} N and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′′ →_{E}^{∗} N

In pictures, the following diagram commutes:

\xymatrix{M \ar[r]^{E^{∗}} \ar@{=>}[d]_{η^{∗}} & M′ \ar@{=>}[d]^{η^{∗}} \\ M′′ \ar@{-->}[r]_{E^{∗}} & N}

Moreover, the rewrite sequence Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{E}^{∗} M′ is of the same length as Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′′ →_{E}^{∗} N. Proof. By a simple induction on the length of the η-expansion sequence, using Lemma 8.2.3. Lemma 8.2.5. We have:

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{E} M′ and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒_{β} M′′ implies ∃N′ and N′′ s. t. \begin{cases}Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′ ⇒_{β}^{∗} N′ \\ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′′ →_{E}^{∗} N′′ \\ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N′ ⇒_{η}^{∗} N′′ \end{cases}
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A →_{E} A′ and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇒_{β} A′′ implies ∃B′ and B′′ s. t. \begin{cases}Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A′ ⇒_{β}^{∗} B′ \\ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A′′ →_{E}^{∗} B′′ \\ Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} B′ ⇒_{η}^{∗} B′′ \end{cases}

In pictures, the following diagrams commute:

[figure: M; E; β; M′; β^{∗}; N′; η^{∗}; M′′; E^{∗}; N′′; A; E; β; A′; β^{∗}; B′; η^{∗}; A′′; E^{∗}; B′′]

Moreover, |β(N′)| = |β(N′′)| and |β(B′)| = |β(B′′)|. Proof. By induction on the structure of the derivations of Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{E} M′ and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A →_{E} A′. We analyze in detail a few representative cases:

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{1} →_{E} M′_{1} Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{2} : C′′}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{1} M_{2} →_{E} M′_{1} M_{2}}

If

M = M_{1} M_{2} →_{β} M_{1} M′′_{2} = M′′

then the result follows trivially, letting N′ = N′′ = M′_{1} M′′_{2}. Otherwise, if

M = M_{1} M_{2} →_{β} M′′_{1} M_{2} = M′′

the result follows by applying the inductive hypothesis to M′_{1} and M′′_{1}. The only interesting case is therefore

M = M_{1} M_{2} = (λx : C. M_{3}) M_{2} →_{β} [M_{2}/x]M_{3} = M′′

By inversion on the derivation of Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{1} →_{E} M′_{1} it follows that either M′_{1} = λx : C′. M_{3}, with

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} C →_{E} C′

or M′_{1} = λx : C. M′_{3}, with

Γ, x : C′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{3} →_{E} M′_{3}

The former is easily handled by type conversion and Substitution. For the latter, from the derivation of well-typedness of M we get

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} C =_{Eβη} C′

so by type conversion Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{2} : C′, and we can apply Proposition 8.1.5, obtaining objects N′ and N′′ satisfying the statement:

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} [M_{2}/x]M_{3} ⇒_{E}^{∗} N′′

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} (λx : C′. M′_{3}) M_{2} ⇒_{β} [M_{2}/x]M′_{3} ⇒_{β}^{∗} N′

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N′ ⇒_{η}^{∗} N′′

• Case

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{1} : Πx : C.D Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{2} →_{E} M′_{2}}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M M_{2} →_{E} M M′_{2}}

As before, the cases

M = M_{1} M_{2} →_{β} M′′_{1} M_{2} = M′′

and

M = M_{1} M_{2} →_{β} M_{1} M′′_{2} = M′′

are easily handled. The remaining one is

M = (λx : C′. M_{3}) M_{2} →_{β} [M_{2}/x]M_{3} = M′′

where, by inversion on the derivation of Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} (λx : C′. M_{3}) : Πx : C.D (and possibly type conversion), we conclude

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{2} : C′  Γ, x : C′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{3} : D

We can therefore apply Proposition 8.1.6, concluding

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} [M_{2}/x]M_{3} ⇒_{E}^{∗} [M′_{2}/x]M_{3}

From this, the result follows by letting N′ = N′′ = [M′_{2}/x]M_{3}.

Corollary 8.2.6. We have:

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{E}^{∗} M′ and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇒_{β}^{∗} M′′ implies ∃N s. t. Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′ ⇒_{βη}^{∗} N and Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′′ →_{E}^{∗} N

Pictorially, the following diagram commutes:

\xymatrix{M \ar[r]^{E^{∗}} \ar@{=>}[d]_{β^{∗}} & M′ \ar@{=>}[d]^{βη^{∗}} \\ M′′ \ar@{-->}[r]_{E^{∗}} & N}

Proof. The proof is the same as the one of Corollary 6.3.12, where we replace →_{R} by →_{E}, Lemma 6.3.11 by 8.2.5, and Corollary 6.3.10 by 8.2.4.

Proposition 8.2.7. Let Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{E} M′, then

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ⇓ A implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′ ⇓ A  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ⇓ type implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A′ ⇓ type
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ↓ A implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′ ↓ A  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A ↓ K implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} A′ ↓ K

Proof. By induction on the derivation of M and A. We look only at one case:

• Case

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} B ⇓ type Γ, x : B ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{1} ⇓ C}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} λx : B. M_{1} ⇓ Πx : B. C}

We inspect the last inference used in the derivation of Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{E} M′. By type considerations, we see it cannot be neither one of the E-conversion rules. So either M′ = λx : B′. M_{1}, with

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} B →_{E} B′ Γ, x : B ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{1} : C}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} λx : B. M_{1} →_{E} λx : B′. M_{1}}

or M′ = λx : B. M′_{1}, with

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} B : type Γ, x : B ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{1} →_{E} M′_{1}}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} λx : B. M_{1} →_{E} λx : B. M′_{1}}

Assume the former; by inductive hypothesis

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} B′ ⇓ type

By Propositions 8.1.2 and 4.3.2,

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} B =_{Eβη} B′

so using Proposition 4.1.5,

Γ, x : B′ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{1} ⇓ C

and hence the result.

Theorem 8.2.8. We have

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{E/βη}^{∗} M′ iff Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{E_{βη}}^{∗} M′ or Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M =_{βη} M′

Proof. One direction is easily proven using Proposition 8.2.2. To prove the other, it suffices to show

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{E} N implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{E_{βη}}^{∗} N

By invariance of →_{E_{βη}} with respect to λ-conversion, we can assume that M_{⇓} is obtained by β-normalizing and then η-expanding. By using Corollaries 8.2.6 and 8.2.4, and Proposition 8.2.7 (in this order), we see

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{E} N implies Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{⇓} →_{E}^{∗} N′

for some canonical N′ such that Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N′ ≈ N_{⇓}. Hence, by Definition 8.2.1

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{E_{βη}}^{∗} N or Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M =_{βη} N

The following results will allow us to give →_{E} and →_{E_{βη}} formulations that are closer in form to those given for rewriteR and →_{R_{βη}} in Definitions 6.2.3 and 6.3.1.

Lemma 8.2.9. Let M and M′ well-formed, and such that Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M ≈ M′ does not hold, then

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{E} M′

if and only if there is an environment E such that

M = E[[M_{∘}]]  M′ = E[[M′_{∘}]]
Γ(M, M_{∘}) ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{∘} =_{βη} θN_{∘}  Γ(M, M_{∘}) ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′_{∘} =_{βη} θN′_{∘}
Γ(M, M_{∘}) ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N′_{∘} ⇓ θA_{∘}  Γ(M, M_{∘}) ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ : Δ_{∘}

where (Δ ⊢\begin{matrix}≺ \\ Σ \end{matrix} N_{∘} = N′_{∘} : A_{∘}) ∈ E or (Δ ⊢\begin{matrix}≺ \\ Σ \end{matrix} N′_{∘} = N_{∘} : A_{∘}) ∈ E.

Proof. Both directions are easily proved by induction on the derivation of Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : A. One subtle point of this proof is that in the derivation of Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{E} M′ the rule

\frac{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} B →_{E} B′ Γ, x : B ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{1} : C}{Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} λx : B. M_{1} →_{E} λx : B′. M_{1}}

is never used, since from Propositions 8.1.2 and 4.3.2 it follows

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} λx : B. M_{1} ≈ λx : B′. M_{1}

Hence the E-conversion step cannot happen inside the type of one of the λ-abstracted variable, and therefore it can be isolated by an environment E.

Remark. Note that the environment E in Lemma 8.2.9 needs not to be (and in most cases will not be) well-formed.

Corollary 8.2.10. Let Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : A, then

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{E_{βη}} M′

if and only if M and M′ are not pairwise βη-convertible and there is an environment E such that

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{⇓} ≈ E[[M_{∘}]]  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} (M′)_{⇓} ≈ E[[M′_{∘}]]
Γ(M, M_{∘}) ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{∘} ⇓ θA_{∘}  Γ(M, M_{∘}) ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′_{∘} ⇓ θA_{∘}
Γ(M, M_{∘}) ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{∘} =_{βη} θN_{∘}  Γ(M, M_{∘}) ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M′_{∘} =_{βη} θN′_{∘}

Γ(M, M_{∘}) ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ : Δ_{∘}

where (Δ ⊢\begin{matrix}≺ \\ Σ \end{matrix} N_{∘} = N′_{∘} : A_{∘}) ∈ E or (Δ ⊢\begin{matrix}≺ \\ Σ \end{matrix} N′_{∘} = N_{∘} : A_{∘}) ∈ E.

Proof. Immediate from Definition 8.2.1 and Corollary 8.2.10.

8.3 Confluence for General Equational Theories

We will now introduce two new types of critical pairs, coming from overlapping rules and equations:

Definition 8.3.1 (Equational Critical Pairs). Let R be a HTRS, and

(Δ_{1} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} l_{1} = r_{1} : C_{1}) ∈ E or (Δ_{1} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} r_{1} = l_{1} : C_{1}) ∈ E

Δ_{2} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} l_{2} → r_{2} : C_{2} ∈ R

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ_{i} : Δ_{i} (i = 1, 2)

If there is a Δ_{1}-stable environment E_{1}[[Γ_{∘} ⊢ ∘ : A_{∘}]] not isolating a generalized variable, and such that

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ_{1}l_{1} =_{βη} (θ_{1}E_{1})_{⇓}[[θ_{2}l_{2}]]

then

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} <(θ_{1}E)_{⇓}[[θ_{2}r_{2}]], θ_{1}r_{1} >

is a (R|E)-critical pair.

Similarly, given a Δ_{2}-stable environment E_{2}[[Γ_{∘} ⊢ ∘ : A_{∘}]] that does not isolate a generalized variable, and

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ_{2}l_{2} =_{βη} (θ_{2}E_{2})_{⇓}[[θ_{1}l_{1}]]

then

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} <(θ_{2}E)_{⇓}[[θ_{1}r_{1}]], θ_{2}r_{2} >

is called a (E|R)-critical pair.

Let Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} < M_{1}, M_{2} >: A be either a (E|R)- or a (R|E)-critical pair, it is said to be trivial if there are objects N_{1} and N_{2} such that

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{i} →_{R/βη}^{∗} N_{i} (i = 1, 2)  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N_{1} =_{Eβη} N_{2}

The key result of this chapter will be the following Lemma, due to G. Huet:

Lemma 8.3.2. Let →_{S} be a symmetric relation, =_{S} its reflexive-transitive closure, and →_{R} another relation such that →_{R/S} is strong normalizing. Then →_{R} is confluent modulo =_{S}, i.e.

M_{1} =_{S} M_{2} and M_{i} →_{R}^{∗} M′_{i} (i = 1, 2) implies ∃N_{1}, N_{2} s.t. M_{i} →_{R}^{∗} N_{i} (i = 1, 2) and N_{1} =_{S} N_{2}

for all objects M_{i} and M′_{i}, if and only if the conditions (A) and (B) are satisfied:

(A) For all objects M, M_{1}, M_{2},

M →_{R} M_{i} (i = 1, 2) implies ∃N_{1}, N_{2} s.t. M_{i} →_{R}^{∗} N_{i} (i = 1, 2) and N_{1} =_{S} N_{2}

(B) For all objects M, M_{1}, M_{2},

M →_{R} M_{1} and M →_{S} M_{2} implies ∃N_{1}, N_{2} s.t. M_{i} →_{R}^{∗} N_{i} (i = 1, 2) and N_{1} =_{S} N_{2}

Proof. A proof for a very general notion of rewriting, which encompasses ours, can be found in [29].

Confluence of →_{R} modulo =_{S} is actually a stronger property than →_{R/S} being Church-Rosser, as the following shows:

Proposition 8.3.3. Let →_{S} be a symmetric relation, and =_{S} its reflexive, transitive closure. Furthermore, assume →_{R} is confluent modulo =_{S} and →_{R/S} strong normalizing. Then →_{R/S} is Church-Rosser.

Proof. By Newman’s lemma, it suffices to show that →_{R/S} is locally Church-Rosser, i.e.

M →_{R/S} N_{i} (i = 1, 2) implies ∃N s.t. N_{i} →_{R/S}^{∗} N (i = 1, 2)

or, in pictures:

\xymatrix{M \ar[r]^{R/S} \ar[d]_{R/S} & N_{1} \ar@{-->}[d]^{(R/S)^{∗}} \\ N_{2} \ar@{-->}[r]_{(R/S)^{∗}} & N}

Then the proof is obtained by a simple diagram chasing:

[figure: M; S; S; M_{1}; R; S; M′_{1}; S; R^{∗}; N_{1}; (R/S)^{∗}; M_{2}; R; N′_{1}; S; S; M′_{2}; S; R^{∗}; N′_{2}; S; N_{2}; (R/S)^{∗}; N]

The objects M_{1}, M_{2}, M′_{1}, and M′_{2} are obtained by definition of →_{R/S}; N′_{1} and N′_{2} by confluence of →_{R} modulo =_{S}; finally, we can N = N′_{1} or N = N′_{2} at will.

Lemma 8.3.4. Let R be a HTRS, →_{R_{βη}} and →_{E_{βη}} satisfy condition (A) of Lemma 8.3.2 if and only if all the (R|R)-critical pairs are trivial.

Proof. It follows immediately from Lemma 7.3.3 (letting E′ = ·), and Theorem 6.3.14.

The analogue of Lemma 8.3.4 requires one additional restriction on the HTRS.

Definition 8.3.5. A well-typed object Γ ⊢\begin{matrix}≺ \\ Γ,E \end{matrix} M : A is said to be E-linear if each variable x ∈ dom(Γ) such that E ⪯^{t} Γ(x) appears free at most once in M.

A HTRS R is called left E-linear if

(Γ ⊢\begin{matrix}≺ \\ Γ,E \end{matrix} M : A) ∈ R implies l E-linear

Lemma 8.3.6. Let R be a left E-linear HTRS, →_{R_{βη}} and →_{E_{βη}} satisfy condition (B) of Lemma 8.3.2 if and only if all the (E|R)- and (R|E)-critical pairs are trivial.

Proof. Assume →_{R_{βη}} and →_{E_{βη}} satisfy condition (B) of Lemma 8.3.2, and let

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} <(θ_{1}E)_{⇓}[[θ_{2}r_{2}]], θ_{1}r_{1} >

be a (E|R)-critical pair.

Define M = (θ_{1}E)_{⇓}[[θ_{2}l_{2}]], we have, by the definitions and Corollary 8.2.10,

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{E_{βη}} (θ_{1}E)_{⇓}[[θ_{2}r_{2}]]  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{R_{βη}} θ_{1}r_{1}

By applying condition (B) of Lemma 8.3.2, we find objects P_{i} such that

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} (θ_{1}E)_{⇓}[[θ_{2}r_{2}]] →_{R_{βη}}^{∗} U_{1}  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ_{1}r_{1} →_{R_{βη}}^{∗} U_{1}  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} U_{1} →_{E_{βη}}^{∗} U_{2}

Using Theorems 6.3.14 and 8.2.8, we see then

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} (θ_{1}E)_{⇓}[[θ_{2}r_{2}]] →_{R/βη}^{∗} U_{1}  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ_{1}r_{1} →_{R/βη}^{∗} U_{1}  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} U_{1} =_{Eβη}^{∗} U_{2}

so the given critical pair is trivial. A similar proof shows that, under these same assumptions, all the (R|E)-critical pairs are also trivial.

Conversely, assume that all the (R|E)- and (E|R)-critical pairs are trivial, and moreover

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{E_{βη}} M_{1}  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M →_{R_{βη}} M_{2}

for some objects M, M_{1}, and M_{2}.

By Corollary 8.2.10, there is a (not necessarily well-typed) environment E^{(1)} such that

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{⇓} ≈ E^{(1)}[[M_{∘}^{(1)}]]  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} (M_{1})_{⇓} ≈ E^{(1)}[[N_{∘}^{(1)}]]
Γ_{∘}^{(1)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{∘}^{(1)} ⇓ θ_{1}C_{∘}^{(1)}  Γ_{∘}^{(1)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N_{∘}^{(1)} ⇓ θ_{1}C_{∘}^{(1)}
Γ_{∘}^{(1)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{∘}^{(1)} =_{βη} θ_{1}l_{1}  Γ_{∘}^{(1)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N_{∘}^{(1)} =_{βη} θ_{1}r_{1}

Γ_{∘}^{(1)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ_{1} : Δ_{∘}^{(1)}

where either (Δ_{∘}^{(1)} ⊢\begin{matrix}≺ \\ Σ \end{matrix} l_{1} = r_{1} : C_{∘}^{(1)}) ∈ E; or (Δ_{∘}^{(1)} ⊢\begin{matrix}≺ \\ Σ \end{matrix} r_{1} = l_{1} : C_{∘}^{(1)}) ∈ E; we will assume the former. Also, from Definition 6.3.1 we get

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{⇓} ≈ E^{(2)}[[M_{∘}^{(2)}]]  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} (M_{2})_{⇓} ≈ E^{(2)}[[N_{∘}^{(2)}]]
Γ_{∘}^{(2)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{∘}^{(2)} ⇓ θ_{2}C_{∘}^{(2)}  Γ_{∘}^{(2)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N_{∘}^{(2)} ⇓ θ_{2}C_{∘}^{(2)}
Γ_{∘}^{(2)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{∘}^{(2)} =_{βη} θ_{2}l_{2}  Γ_{∘}^{(2)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N_{∘}^{(2)} =_{βη} θ_{2}r_{2}
Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E^{(2)}[[Γ_{∘}^{(2)} ⊢ ∘ : θ_{2}C_{∘}^{(2)}]] ⇓ A  Γ_{∘}^{(2)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ_{2} : Δ_{∘}^{(2)}

Δ_{∘}^{(2)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} l_{2} → r_{2} : C_{∘}^{(2)} ∈ R

Applying Proposition 7.1.3 with E′ = ·, we obtain environments E^{i} and objects M_{∘}^{i} such that

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E^{(i)} ≈ E^{i}  Γ_{∘}^{(i)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{∘}^{(i)} ≈_{E′} M_{∘}^{i}

and M_{⇓} = E^{i}[[M_{∘}^{i}]], for i = 1, 2.

From Propositions 4.3.2 and 6.3.16, it follows

Γ_{∘}^{(i)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{∘}^{i} =_{E′βη} θ_{i}l_{i}  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} (M_{i})_{⇓} ≈_{E′} E^{i}[[N_{∘}^{(i)}]]

hence, without loss of generality, we can assume E^{(i)} = E^{i} and M_{∘}^{(i)} = M_{∘}^{i}, and therefore

M_{⇓} = E^{(i)}[[M_{∘}^{(i)}]]

We have three mutually disjoint cases to examine:

• Case E^{(1)} ↑ E^{(2)} If E^{(1)} and E^{(2)} are disjoint environment, it is not difficult to see that they will have a common reduct:

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{1} →_{R_{βη}} U  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{2} →_{E_{βη}} U

hence, taking N_{1} = U and N_{2} = M_{2}, we can show, using symmetry of →_{E_{βη}},

Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{i} →_{R_{βη}}^{∗} N_{i} (i = 1, 2)  Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N_{1} →_{E_{βη}}^{∗} N_{2}

which concludes this case.

• Case E^{(2)} = E^{(1)} · E′ It will suffice to prove that condition (B) holds for M_{1} = N_{∘}^{(1)} and M_{2} = E′[[N_{∘}^{(2)}]]. By induction on the derivation of we easily show that E’ is in this case well-formed. Since

Γ_{∘}^{(1)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ_{1}l_{1} =_{βη} E′[[M_{∘}^{(2)}]]

there is an environment E satisfying the statement of Lemma 7.3.1 for E′ = ·. If E satisfies case (1) of the statement, then

Γ_{∘}^{(1)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E′ ≈ (θ_{1}E)_{⇓}

and therefore, through Propositions 6.1.4 and 6.3.16, we show

Γ_{∘}^{(1)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ_{1}l_{1} =_{βη} (θ_{1}E)_{⇓}[[θ_{2}l_{2}]]

and Γ_{∘}^{(1)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} < (θ_{1}E)_{⇓}[[θ_{2}l_{2}]], θ_{1}r_{1} > is a (R|E)-critical pair. Under the current working assumptions, it must be trivial, so there are N_{1} and N_{2} such that

Γ_{∘}^{(1)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} (θ_{1}E)_{⇓}[[θ_{2}l_{2}]] →_{R/βη}^{∗} N_{1}  Γ_{∘}^{(1)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ_{1}r_{1} →_{R/βη}^{∗} N_{2}  Γ_{∘}^{(1)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N_{1} =_{Eβη} N_{2}

Using Theorems 6.3.14, 8.1.9 and 8.2.8, we show

Γ_{∘}^{(1)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{2} →_{R_{βη}}^{∗} N_{1}  Γ_{∘}^{(1)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{1} →_{R_{βη}}^{∗} N_{2}  Γ_{∘}^{(1)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N_{1} →_{E_{βη}}^{∗} N_{2}

If E satisfies part (2) of the statement of Lemma 7.3.1, then l_{1} = E[[U_{∘}]], where U_{∘} = x U_{1} U_{2} … U_{k} is a generalized variable, and

Γ_{∘}^{(1)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E′ ≈ ((θ_{1}E)_{⇓} · E_{∘})

Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ_{1}(x) =_{βη} λy_{1} : A_{1} … λy_{k} : A_{k}. E_{∘}[[M_{∘}^{(2)}]]

for some (well-typed) environment E_{∘}. Let Δ_{∘}^{(1)}(x) = B, applying Proposition 6.1.3 to the E_{∘}, we get C_{∘}^{(2)} ⪯^{t} B. From this we immediately see B ⊀^{τ} C_{∘}^{(1)}: otherwise, we would have

C_{∘}^{(2)} ⪯^{t} B ≺^{τ} C_{∘}^{(1)}

implying C_{∘}^{(2)} ≺^{τ} C_{∘}^{(1)}, a contradiction to the assumption R ⊀^{τ} E. Let l_{1} = E_{U′}[[U′]] where U′ = x U′_{1} U′_{2} … U′_{k} is any other occurrence of a generalized variable (with the same underlying variable x as U), we apply Proposition 6.1.6 to conclude

Δ_{∘}^{(1)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E_{U′}[[Δ_{∘}^{(1)}(l_{1}, U′) ⊢ ∘ : type(Δ_{∘}(l_{1}, U′))]] : C_{∘}^{(1)}

Moreover, all these environments E_{U_{∘}} are disjoint, and Δ_{∘}^{(1)}-stable by Proposition 7.2.3. By Corollary 7.2.5 and Proposition 6.1.6, we see that

Δ_{∘}^{(1)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} ((θ_{1}E_{U′})_{⇓} · E_{∘})[[Γ_{∘}^{(2)} ⊢ ∘ : θ_{2}C_{∘}^{(2)}]] ⇓ θ_{1}C_{∘}^{(1)}

Using repeatedly Proposition 6.1.9, we show

Γ_{∘}^{(1)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E′[[θ_{2}r_{2}]] →_{R/βη}^{∗} θ′_{1}l_{1}

where Γ_{∘}^{(1)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ′_{1} : Δ_{∘}^{(1)} is defined as:

θ′_{1}(z) = \begin{cases}θ_{1}(z) & z ≠ x \\ λy_{1} : A_{1} … y_{k} : A_{k}. E_{∘}[[N_{∘}^{(2)}]] & z = x \end{cases}

By applying a similar argument to r_{1} we show

Γ_{∘}^{(1)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ_{1}r →_{R/βη}^{∗} θ′_{1}r

Hence

Γ_{∘}^{(1)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{1} →_{R/βη}^{∗} θ′_{1}l_{1}  Γ_{∘}^{(1)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M_{2} →_{R/βη}^{∗} θ′_{1}r_{1}  Γ_{∘}^{(1)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ′_{1}l_{1} →_{E} θ′_{1}r_{1}

and we are done by Theorem 6.3.14.

• Case E^{(1)} = E^{(2)} · E′ The proof is similar to that of the previous case. Like before, we apply Lemma 7.3.1 to

Γ_{∘}^{(1)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ_{2}l_{2} =_{βη} E′[[M_{∘}^{(1)}]]

obtaining E. If E satisfies case (1) of the statement of Lemma 7.3.1, the result is easily seen to follow from the fact that all the (E|R)-critical pairs are trivial. Otherwise E satisfies case (2), and l_{2} = E[[U_{∘}]], where U = x U_{1} U_{2} … U_{k} is a generalized variable; moreover

Γ_{∘}^{(2)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E′ ≈_{E} ((θ_{2}E)_{⇓} · E_{∘})

Γ_{∘} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ_{1}(x) =_{Eβη} λy_{1} : A_{1} … λy_{k} : A_{k}. E_{∘}[[M_{∘}^{(1)}]]

for some (well-typed) environment E_{∘}. By linearity of l_{2}, U is the only sub-object where x appears free. Hence (θ_{2}E)_{⇓} = (θ′_{2}E)_{⇓}, where

θ′_{2}(z) = \begin{cases}θ_{2}(z) & z ≠ x \\ λy_{2} : A_{1} … y_{k} : A_{k}. E_{∘}[[N_{∘}^{(1)}]] & z = x \end{cases}

and therefore E′[[N_{∘}^{(1)}]] = (θ′_{2}l_{1})_{⇓}. Finally, using Lemma 8.2.9, one shows

Γ_{∘}^{(2)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} θ_{2}r_{2} →_{E}^{∗} θ′_{2}r_{2}

so we can conclude

Γ_{∘}^{(2)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} E′[[N_{∘}^{(1)}]] →_{R} θ′_{2}r_{2}  Γ_{∘}^{(2)} ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N_{∘}^{(2)} →_{E/βη}^{∗} θ′_{2}r_{2}

which is what we wanted to show.

Theorem 8.3.7 (Critical Pair Criterion). Let R be a left E-linear HTRS such that →_{R/Eβη} is strongly normalizing, then →_{R/βη} is confluent modulo E- and βη-conversion, i.e.

M_{1} =_{Eβη} M_{2} and M_{i} →_{R/βη}^{∗} M′_{i} (i = 1, 2) implies ∃N_{1}, N_{2} s.t. M_{i} →_{R/βη}^{∗} N_{i} (i = 1, 2) and N_{1} =_{Eβη} N_{2}

for all objects M_{i}, and M′_{i}, if and only if all the (R|R)-, (E|R)-, (R|E)-critical pairs are trivial.

Proof. In light of Theorems 6.3.14, 8.1.9 and 8.2.8, confluence of →_{R/βη} is confluent modulo Eβη-conversion is equivalent to confluence of →_{R_{βη}} modulo →_{E_{βη}}^{∗}. The result then follows from Lemmas 8.3.2, 8.3.4, and 8.3.6.

8.4 Summary

In this chapter we presented the general version of the Critical Pair Criterion. The key idea here was is to treat E-conversion as a symmetric, rewrite-like relation. For this purpose we introduced the notions of one-step E-conversion and canonical E-conversion in Sections 8.1 and 8.2. We can see these as the analogues of the concepts defined in Sections 6.2 and 6.3.

In Section 8.3 we defined new critical pairs, coming from superposing rules to equations ((E|R)-critical pairs) and equations to rules ((R|E)-critical pairs). Finally, we proved that, as long as all these new critical pairs, as well as the old (R|R)− ones we defined in the last chapter, are shown to be trivial, a strongly normalizing HTRS R is confluent modulo E.

106

Directions of Future Research

The results presented can be considered just the first step in the study of rewriting in the context of rich type systems. There are numerous directions toward which the research started here can be expanded; we list a few of them.

9.1 Implementations

One of our intents in pursuing this research was to justify equational extensions of the LF Calculus and its implementations. Many interesting applications of Twelf would greatly benefit from having algebraic manipulation of expressions during type reconstruction. A version of Twelf implementing some of the ideas presented here has already been implemented and it is currently being tested. A rewriting module for Twelf, capable of normalizing terms with respect to a given HTRS, as well as checking the critical pairs of the HTRS itself, is also currently being designed.

9.2 Other Confluence Criteria

There are still several systems which fall outside the scope of the results presented in this dissertation, as they do not happen to satisfy neither of the conditions on which the results of Chapters 7 and 8 relied upon.

Systems not dealt with by our results include the frequently-occurring cases of associative, and associativecommutative operators. These have been thoroughly studied for the first-order case [58]. Although the theoretical machinery we developed during our study should greatly facilitate the task of lifting these results to our calculus, there might be some additional problems that need to be tackled. For example, first-order binary operators often translate in n-ary ones (where n > 2) in LF, where the extra arguments are needed to correctly specify the type of the object at hand. Developing results for these cases may require providing the means for detecting these extra arguments, and separate them from the main ones.

Another interesting class of systems are orthogonal HTRSs, studied by Nipkow for the simply-typed calculus [55]. Confluence for orthogonal systems can be established even in cases where strong normalization cannot be attained. This seems promising for dealing with HTRS which contain “catch all” rules like the one presented at the end of Section 1.2, which are by our definitions not normalizing (not even in a weak sense).

9.3 Narrowing

The implementation of the equational extension of Twelf [58], we mentioned in Section 9.1 uses a constraintsolving approach. We endow the type reconstruction engine with decisions procedures for subsets of some interesting domains (e.g. rational arithmetic). The equational problems that can be formulated in the language but cannot be solved by these procedures are delayed as constraints until more information is available. While our approach is certainly efficient, it is not very flexible, since it does not allow the user to define his/her own equational theories or modify the existing ones. Rewriting-based languages like Maude [10] offer this ability, under the (mild) assumption that the equational theories introduced can be oriented into confluent, strongly normalizing ones. We believe the way to offer similar capabilities in Twelf is through higher-order narrowing. Narrowing strategies for the simply-typed lambda calculus have been studied by Prehofer [65, 66]; his work should be a good starting point in pursuing this line of research.

9.4 Termination

One area which holds promise of benefiting from the use of dependence relations, and therefore deserves further investigation, is the study of termination of HTRSs. A conspicuous number of techniques have been proposed in these last few years, some based on syntactic orderings [2, 39, 33], similar to or extending the first-order Recursive Path Ordering (RPO) [14], some others based on interpretations over well-founded structures [34, 68].

Among the higher-order extensions of RPO, it is deserving of mention some recent work by Jouannaud and Rubio [33]. Their technique is the first, to our knowledge, to fully take advantage of information coming from the type structure, and this seems to help it achieve better results than the other proposed methods. Their definition of Higher-Order RPO requires, in addition to the standard well-founded quasi-order over the symbols of the signature, another quasi-order over types, defined as follows:

Definition 9.4.1. The quasi-ordering on types ≤ satisfies the following properties:

1. its strict part < is well-founded

2. ≤ is compatible with the term structure: for all ground canonical terms Γ ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} M : A if N is contained in M, Γ(M, N) ⊢\begin{matrix}≺ \\ Σ,E \end{matrix} N : type(Γ(M, N)), we have type(Γ(M, N)) ≤ A

We have the following:

Proposition 9.4.2. Let ≺ = (≺^{τ} , ≺^{t}) be a dependence relation defined over a signature Σ, ⪯^{t} is a quasiordering on types, in the sense of Definition 9.4.1.

Proof. First, observe ⪯^{t} is by definition reflexive and transitive, hence a quasi-order. Its strict part is wellfounded, since defined on a finite set (the set of type family constants of Σ). Finally, its compatibility with the term structure has been shown in Lemma 5.2.1.

We believe that orderings like this that take advantage of the type structure of terms have a clear advantage over purely syntactic methods which are defined over untyped lambda-terms. Their main drawback, that is the need for an additional well-founded quasi-order to be specified, is eliminated here since this can be automatically obtained by computing minimal dependence relations. It might be worthwile investigating if some of the other orderings mentioned earlier can be modified to include quasi-orderings on types, and, if so, to evaluate the advantage in doing so.

Part III

Applications A Change in Notation

In this third and last part of the dissertation we present some applications of the theory to various fields of logic and theoretical computer science. Before we proceed, however, we feel necessary to make substantial changes to the notation we use. In presenting these examples, we will adopt a syntax which is very close to the one used in Twelf. There are many reasons for this change; we list here a couple.

One motive to this change is to emphasize that the concepts presented so far lend themselves to be implemented on a computer. Not only implementation of our ideas is possible, but often turns out to be necessary, given the large number of critical pairs that need to be considered for non-trivial systems. We will borrow the syntax for rewriting rules from ElfRW [20], a rewriting module for Elf written by Pfenning and Gehrke in 1995. ElfRW was designed to perform rewriting and critical pair checking of rewriting modulo an empty equational theory, using the theoretical results presented by us in [71]. A new module for Twelf, the successor of Elf, capable of rewriting modulo some special equational theories, is currently being designed.

A second reason for this notational change is that it will allow us to take advantage of the many syntaxsugaring features that Twelf offers to make our presentation more comprehensible. One particularly annoying characteristic of LF is the proliferation of arguments of higher-order constants. The presence of a fair degree of redundancy in LF signatures was already pointed out in [44]. The Twelf interpreter alleviates this problem by allowing the user to keep some of the arguments of functional objects implicit. These implicit arguments are kept hidden from the user, and the type reconstruction algorithm automatically generates them when parsing a signature. Keeping redundant information implicit benefits us, since we are able to write complex signature concisely, and the reader, allowing him/her to concentrate on the crucial point of the definitions we give without being distracted by irrelevant items.

10.1 Twelf Syntax

Twelf signatures are usually stored as text-only files, without any additional formatting or font information. For this reason, the syntax in which they are written differ from the one we adopted so far. In Figure 10.1, we give a list of conversion rules between the two notations.

Two features that we will use intensively will be the ability to write operators in prefix, postfix, and infix

Twelf  LF
[x: \underline{A} ] \underline{B}  λx : A. M
c \underline{M}_{1} … \underline{M}_{n} c M_{1} … M_{n}
\underline{A} ->  \underline{B}  Πx : A. B (x ∉ FV(B))
\{x: \underline{A} \} \underline{B}  Πx : A. B (x ∈ FV(B))
a \underline{M}_{1} … \underline{M}_{n} a M_{1} … M_{n}

Figure 10.1: Twelf/LF Syntax Conversion notation, and, as we mentioned earlier, the possibility of treating some arguments as implicit. Figure 10.2 show how both these features are used; the corresponding signature in our old notation can be seen in Figure 10.3.

As can also be noticed by looking at Figure 10.2, we will borrow from ElfRW the ability to tag rewrite rules with identifiers; as a matter of fact, we will also extend this notation to equations.

A description of the Twelf system beyond what presented so far is beyond the scope of this dissertation. For more information, we recommend the interested reader to consult [63].

obj   : type.
mor   : obj -> obj -> type.
id    : {O : obj} mor C O O.                    %prefix 10 id.
*     : mor O2 O3 -> mor O1 O2 -> mor O1 O3.    %infix right 5 *.
idl   : id O2 * F => F.
idr   : F * id O1 => F.
assoc : (F * G) * H => F * (G * H).

Figure 10.2: Signature and HTRS (New Notation)

dom(Σ) = {obj, morph, id, o}

Σ(obj) = type .
Σ(morph) = Πx_{1} : obj. Πx_{2} : obj. type
Σ(id) = Πx_{1} : obj. morph x_{1} x_{1}
Σ(o) = Πx_{1} : obj. Πx_{2} : obj. Πx_{3} : obj. Πy_{1} : morph x_{2} x_{3}. Πy_{2} : morph x_{1} x_{2}. morph x_{1} x_{3}

Figure 10.3: Signature (Old Notation)

Applications: Concurrent Processes

We show how the rewriting technique developed by us can be used to represent Milner’s action structures and process calculus. This is not meant to be a tutorial on these concepts; we assume familiarity of the reader with [50], on which most of the material presented in this chapter is based.

Furthermore, this can be considered more a case study than a demonstrating example: we will present some negative results, i.e. cases where the tools we developed were not sufficient to tackle the problem at hand. We believe that presenting failures (as well as successes) of our theory is useful, as they stress out its current limits, and suggest directions of further research.

11.1 Action Structures

Definition 11.1.1. Syntactically, a static action structure is built from a set of names X and basic actions Π. We will use letters x, y, z, u, v, w to denote names, and π for basic actions. Actions are formed from these sets according to the following BNF:

Actions a := π | id | a · b | a ⊗ b | ab_{x} a

In what follows, we use letters a, b, c, d to signify actions. Given an monoid of arities (M, ⋆, ϵ), freely generated by a set of prime arities Σ, and an assignment ρ of names to prime arities and of basic actions to ordered pairs of arities, such assignment is extended to generic actions by the following inference system:

\begin{matrix}\frac{ρ(π) = (m, n)}{π : m → n} & \overline{id_{m} : m → m} \\ \frac{a : k → l b : l → m}{a · b : k → m} & \frac{a : k → m b : l → n}{a ⊗ b : k ⋆ l → m ⋆ n} \end{matrix} ; \frac{a : l → m ρ(x) = k}{ab_{x} a : k ⋆ l → k ⋆ m}

(above, we subscripted the identity action id by its arity; we will recur to this expedient often, to improve clarity). Finally, we require actions to satisfy the following congruences:

a · id = a = id · a  a · (b · c) = (a · b) · c
a ⊗ id_{ϵ} = a = id_{ϵ} ⊗ a  a ⊗ (b ⊗ c) = (a ⊗ b) ⊗ c
id_{m} ⊗ id_{n} = id_{m⋆n}  (a · b) ⊗ (c · d) = (a ⊗ c) · (b ⊗ d)
ab_{x} id = id  ab_{x}(a · b) = (ab_{x} a) · (ab_{x} b)

To formalize static action structures in LF, we start by giving a signature for the monoid of the arities:

arity : type.
prime : type.
0 : arity.
` : prime -> arity.             %prefix 15 `.
+ : arity -> arity -> arity.    %infix right 10.

We also introduce an equational theory E_{M} for arities, where E_{M} = E(R_{M}) is the equational theory generated by the strongly normalizing and confluent HTRS given by the following rules:

ar1 : 0 + M => M.
ar2 : M + 0 => M.
ar3 : (K + L) + M => K + (L + M).

The well-formed signature Σ_{M} and equational theory E_{M} are then extended to accommodate static action structures, by adding new constants

name   : prime -> type.
action : arity -> arity -> type
id : {M : arity} action M M.                                  %prefix 15 id.
;  : action K L -> action L M -> action K M.                  %infix right 10 ;.
*  : action K M -> action L N -> action (K + L) (M + N).      %infix right 10 *.
ab : (name W -> action L M) -> action (` W + L) (` W + M).    %prefix 15 ab.

and equations

c1  : A ; id M == A.
c2  : id M ; A == A.
c3  : (A ; B) ; C == A ; (B ; C).
p1  : A * id 0 == A.
p2  : id 0 * A == A.
p3  : (A * B) * C == A * (B * C).
pf1 : id M * id N == id (M + N).
pf2 : (A ; B) * (C ; D) == (A * C) ; (B * D).
af1 : ab ([x:name W] id M) == id (` W + M).
af2 : ab ([x:name W] (A x) ; (B x)) == ab ([x:name W] A x) ; ab ([x:name W] B x).

We will call these new signature and equational theory Σ_{A} and E_{A}, respectively.

We would be tempted to try to show, in analogy to what we did for E_{M}, that E_{A} = E(R_{A}), by carefully choosing an orientation for the equations that make them into a confluent (modulo E_{M}) and terminating HTRS. Unfortunately, this turns out not to be the case. Consider the subset of zero-ary actions:

A_{ϵ,ϵ} = {a : m → n | m = n = ϵ}

It is easily shown that A_{ϵ,ϵ} is closed under · and ⊗. Hence, if X = ∅, this forms a (sub-) action structure. Over this subset, the operators · and ⊗ are easily seen to collapse into a single, associative-commutative one:

a · b = (id ⊗ a) · (b ⊗ id) = (id · b) ⊗ (a · id) = b ⊗ a = (b · id) ⊗ (id · a) = (b ⊗ id) · (id ⊗ a) = b · a

Although this may clash with our intuitive notion of · representing sequentiality, the above fact will be crucial, as we will see, in representing CCSs as action structures.

Definition 11.1.2. A (dynamic) action structure consists of an action structure A(Π, X, M, ρ) together with a action preorder ↘ called reaction such that

• each operator preserves reaction, e.g. a ↘ a′ implies a · b ↘ a′ · b and b · a ↘ b · a′; • id is inactive, i.e. id ↘ a implies a = id;

• reaction preserves arities, i.e. a ↘ a′ and a : m → n implies a′ : m → n.

Given their reductional nature, reactions will be modeled in LF as a HTRS R_{R}, whose confluence (modulo E_{A}) will have to be checked using the theory developed in Chapter 8.

11.2 Action structures for CCS

In Synchronous CCS [48], basic actions are formed taking positive and negative instances from a set of atomic particles Π_{0}. More formally, we have the following:

X = ∅
Π = \{π | π ∈ Π_{0}\} ∪ \{\overline{π} | π ∈ Π_{0}\}
M = {ϵ}
ρ(π) = ρ(\overline{π}) = (ϵ, ϵ) for all π ∈ Π_{0}

For every π ∈ Π_{0}, instances of π of opposite sign react canceling each other:

π ⊗ \overline{π} ↘ id

A LF signature for this action structure is given by defining a new type for the particles in Π, and two “signing” operators:

    particle : type.
    pos : particle -> action 0 0.    %prefix 15 pos.
    neg : particle -> action 0 0.    %prefix 15 neg.

Additionally, each π ∈ Π_{0} will be represented by an object constant of type particle.

Since all the actions lie inside A_{ϵ,ϵ}, as we showed before, it can be proved that ⊗ and · coincide for this action structure, and are both commutative. Therefore the equational theory E_{A} in this case simplifies to the one of a commutative monoid:

    ccs1 : A * B == B * A : action 0 0.
    ccs2 : (A * B) * C == A * (B * C).
    ccs3 : (id 0) * A == A.

Reactions are formalized by the single-rule HTRS R_{R}

    ccsr : pos M * neg M => id 0.

Unfortunately, the theoretical results proven in Chapter 8 are not strong enough to tackle theories with associative-commutative operators. However, in this specific instance we observe that, since X = ∅ and M = {ϵ}, the action structure for CCS can be described adequately by a first order theory. Hence we can apply the Peterson-Stickel method [58] to show that R_{R} is indeed confluent modulo E_{A}.

Action structures for Pure CCS [49] are defined similarly, but require the addition of a special particle τ. In the Pure CCS case, particles of opposite sign react producing τ, rather than the identity:

π ⊗ \overline{π} ↘ τ

The encoding into LF, and proof of confluence of the resulting system, are handled like before.

11.3 Process Calculus

Action structures can be used in more than one way to model concurrent processes. The first way is to use them to model each single transition of a process. A second approach is to model the whole process, as well as its individual transitions, as action structures. We take the first of these two approaches here, following [50].

Definition 11.3.1. Processes are defined over an action structure A, and formed according to the following syntax:

Processes P := a · P | P ⊗ P | (x)P
•P | 0 | P + P | ∂P |!P

We will use letters P, Q, R to denote processes. Each process is assigned an arity, according to the following rules:

\begin{matrix}\frac{a : m → n P : n}{a · P : m} & \frac{P : m Q : n}{P ⊗ Q : m ⋆ n} & \frac{ρ(x) = k P : m}{(x)P : k ⋆ m} \\ \frac{P : m}{_{•}P : m}  \overline{0 : m} & \frac{P : m Q : m}{P + Q : m} & \frac{P : m}{∂P : m}  \frac{P : ϵ}{!P : ϵ} \end{matrix}

Finally, processes must satisfy the following rules of structural congruence:

id · P = P  a · (b · P) = (a · b) · P
(x)(a · P) = (ab_{x} a) · (x)P  (a · P) ⊗ (b · Q) = (a ⊗ b) · (P ⊗ Q)

In formalizing the process calculus in LF, we choose, rather than overloading some of the already defined symbols, to prepend “#” to all the newly introduced constants:

proc : arity -> type.
#;  : action M N -> proc N -> proc M.
#*  : proc M -> proc N -> proc (M + N).
#ab : (name W -> proc M) -> proc (` W + M).
##  : proc M -> proc M.
#0  : proc M.
#+  : proc M -> proc M -> proc M.
#d  : proc M -> proc M.
#!  : proc 0 -> proc 0.

Structural congruence can be expressed by the following HTRS R_{p}:

pc1 : (id M) #; P => P.
pc2 : A #; (B #; P) => (A ; B) #; P.
pc3 : (A #; P) #* (B #; Q) => (A * B) #; (P #* Q).
pc4 : #ab ([x:name W] (A x) #; (P x)) => ab ([x:name W] A x) #; #ab ([x:name W] P x).

The proof of confluence of R_{P} is a nice application of the theory developed in this thesis, and therefore it is worth presenting it in some detail.

As we mentioned in Chapter 5, when typing a signature Σ, it is important to also determine what is the minimal dependence relation under which this is possible. In this case, it turns out to be the following:

                        prime, arity ≺^{τ} action, proc

                        prime ≺^{τ} name

                        prime ≺^{t} arity, name ≺^{t} action ≺^{t} proc

By the kinds assigned to action and proc, it must be arity ≺^{τ} action, proc. For similar reasons, we also have prime ≺^{τ} name. Typing the embedding ′ of primes into arities introduces the pair prime ≺^{t} arity. Hence

                               prime ≺^{t} arity ≺^{τ} action, proc

and therefore prime ≺^{τ} action, proc.

Finally, the sequential composition #; of an action and a process forces action ≺^{t} proc, and the two abstractions ab and #ab also require name ≺^{t} action, proc. Since ≺^{τ} ⊆ ≺^{t}, we conclude

                            prime ≺^{t} arity, name ≺^{t} action ≺^{t} proc

In Section 9.4 we mentioned how dependence relations can be used in the Recursive Path Ordering described in [33] to establish strong normalization. In this case, it can be verified that using the quasiordering on types ≺^{t} above, together with the symbol ordering

                                       #; < #* < #ab

is sufficient to prove strong normalization of R_{P}.

Once R_{P} has been shown terminating, we turn once again to the dependence relation ≺, to observe that proc ⪯̸^{t} action. Hence R_{P} ⪯̸^{t} E_{A}, and we can use Theorem 7.3.4 to establish confluence by examining all the (R_{P} |E_{A}|R_{P})-critical pairs. There are fifteen of them, and they all turn out to be trivial by applying congruences in E_{A}.

The proof of termination and confluence sketched above represent an elegant, independent proof to Propositions 5.7 and 5.8 in [50].

Definition 11.3.2 (Dynamic Process Calculus). Computation in the Process Calculus is performed by

a reduction preorder ↘ defined as the union of an action preorder ↘^{a} and a control preorder ↘^{c}. The action preorder is responsible for computation at the atomic level, i.e. inside actions:

a · P ↘^{a} a′ · P iff a ↘ a′

The control preorder regulates computation of processes:

•P ⊗ _{•}Q ↘^{c} _{•}(P ⊗ Q)  P + Q ↘^{c} P  ∂P ↘^{c} P  !P ↘^{c} P ⊗!P
(x)_{•}P ↘^{c} _{•}(x)P  P + Q ↘^{c} Q  ∂P ↘^{c} _{•}∂P  !P ↘^{c} _{•}!P

In LF, the action preorder can be adequately represented by the HTRS R_{R} defined before. Let E_{P} = E_{A} ∪ E(R_{P}), we introduce the following HTRS R_{C} for the control preorder:

    cp1 : (## P) #* (## Q) => ## (P #* Q).
    cp2 : #ab ([x:name W] ## (P x)) => ## (#ab [x:name W] P x).
    cp3 : P #+ Q => P.
    cp4 : P #+ Q => Q.
    cp5 : #d P => P.
    cp6 : #d P => ## (#d P).
    cp7 : #! P => P #* (#! P).
    cp8 : #! P => ## (#! P).

In general, R_{C} is neither normalizing (not even in a weak sense), nor confluent; this is as expected, since it is designed to model the behavior of non-deterministic, and possibly non-terminating, processes.

118

Applications: Categories

In this chapter we will show how categorical notions can be expressed by HTRSs. In doing so, the work done by W. Gehrke in [19] serves as our inspiration. However, the encoding he uses turns out not to be adequate in some cases: the HTRSs he obtains, albeit confluent and strong-normalizing, in some instances do not represent the categorical structures they intend to.

The encoding we will present here is adequate. However, the problem of orienting higher-order equations into rewrite rules becomes here more delicate: fewer, and different choices than the ones presented in [19] are possible, if confluence and termination are to be attained.

12.1 Categories

Definition 12.1.1. A category is specified by the following data:

• A collection of entities called objects.

• A collection of entities called morphisms. To each morphism we associate two objects: a source and a target. We will write f : a → b to indicate that the morphism f has source a and target b.

• A binary composition operator, that, given morphisms f : a → b and g : b → c, give raise to the morphism (g · f) : a → c. Composition is associative, i.e. for all morphisms f, g, h

(h · g) · f = h · (g · f)

whenever the composition above is defined.

• For each object a, an identity morphisms id_{a} : a → a. Identity morphisms act as unit element of composition, i.e. given any morphism f : a → b, the following holds:

id_{b} ·f = f = f · id_{a}

In what follows, we will have to deal with definitions that involve more than a single category. Hence we choose a LF representation that introduces a type for categories, allowing objects and morphisms to be indexed by the categories they belong to:

    cat   : type.
    obj   : cat -> type.
    mor   : {C : cat}  obj C -> obj C -> type.
    id    : {O : obj C} mor C O O.                        %prefix 10 id.
    *     : mor C O2 O3 -> mor C O1 O2 -> mor C O1 O3.    %infix right 5 *.

The associativity and unitary congruences can be expressed by the following HTRS:

    idl   : id O2 * F => F.
    idr   : F * id O1 => F.
    assoc : (F * G) * H => F * (G * H).

We will use the symbols Σ_{cat} and R_{cat} to denote the signature and HTRS just introduced.

Two important remarks about these signature and equational theory, which will hold true for all the other ones we will present in this chapter, are the following:

1. The rules are essentially first-order, with dependent-types annotations that restrict their applicability.

2. Term constants require a large number of auxiliary arguments; these are needed to specify the type of the main ones. For example, composition of morphism is represented by a LF functional object requiring six arguments; this does not agree with our intuitive notion of composition, which requires just two.

We use these observations to outline a different, and more effective, strategy to prove strong normalization. This goes through the definition of a map | · | from canonical LF terms to first-order untyped ones, such that

Γ ⊢\begin{matrix}≺ \\ Σ \end{matrix} M →_{R/βη} N : A implies |M| →_{|R|} |N|

where |R| is the TRS obtained by applying the transformation | · | to the HTRS R. Using such a map, the problem of establishing strong normalization for R can be reduced to proving it for |R|, which can be done using a wider array of (first-order) techniques.

We show that one map satisfying the above requirements is given the following:

|λx : A. M| = λ(|M|[⋆/x])
|c M_{1} M_{2} … M_{n}| = c(|M_{1}|, |M_{2}|, …, |M_{n}|)
|x M_{1} M_{2} … M_{n}| = @_{n+1}(x, |M_{1}|, |M_{2}|, |M_{n}|)

where λ, ⋆, @_{i}(i ≥ 0) are new function symbols required by the translation, and disjoint from those in dom(Σ).

By Remark 1, all the free variables of rules in R are of base type, and hence rewriting does not create new β-redexes. This being the case, it suffices to show than the map we defined satisfies

Γ ⊢\begin{matrix}≺ \\ Σ \end{matrix} M →_{R} N : A implies |M| →_{|R|} |N|

which is easily proved by induction on the environment E used in the rewriting step.

Although this map is as required, it is not optimal: as we noted in Remark 2, some of the arguments required by the LF constants serve no other purpose than to carry type information, and are therefore unneeded in the translation, where types have been stripped off. How to sort out which arguments should be carried in the translation? Dependence relations come to the rescue, once again: from Proposition 6.1.3 it follows that we can safely discard arguments of type A whenever morph ⪯̸^{t} A.

Hence, in an optimized version of the translation we have

|c M_{1} M_{2} … M_{n}| = c(|M_{k_{1}}|, |M_{k_{2}}|, …, |M_{k_{m}}|)  1 ≤ k_{1} < k_{2} < ⋯ < k_{m} ≤ n
|x M_{1} M_{2} … M_{n}| = @_{n+1}(x, |M_{k_{1}}|, |M_{k_{2}}|, …, |M_{k_{m}}|)  1 ≤ k_{1} < k_{2} < ⋯ < k_{m} ≤ n

where the k_{i} are the indices of the parameters that are “needed”, in the sense of the criterion described above.

In the specific case of Σ_{cat} and R_{cat}, a minimal dependence relation ≺ is given by

                   cat ≺^{τ} obj ≺^{τ} morph                   cat ≺^{t} obj ≺^{t} morph

This determines the following first-order translation:

|id C a| = id
|∗ C a b c f g| = f ∗ g

for which the rules |R_{cat}| take the familiar shape of those of a free monoid (M, ∗, id).

12.2 Functors

Definition 12.2.1. Let C and D two categories, a functor F from C to D (in symbols: F : C → D) is specified by:

• An operation taking objects a in C to objects F a in D.

• An operation taking morphism f : a → b in C to morphisms F f : F a → F b in D

such that

F id_{a} = id_{F a}  F (g · f) = (F g) · (F f)

We represent functors as a new type fun, dependent on two categories. The operations mentioned in the definition are represented by two object constants funObj and funMorph, parametric on a functor. We define the signature Σ_{fun}, obtained extending Σ_{fun} with constants:

    fun    : cat -> cat -> type.
    funObj : fun C D -> obj C -> obj D.
    funMor : {FF : fun C D} mor C O1 O2 -> mor D (funObj FF O1) (funObj FF O2).

The properties that funMorph is required to satisfy are expressed by the HTRS R_{fun} given by the union of R_{cat} and the following set of rules:

    fid : funMor FF (id O) |> id (funObj FF O).
    f*1 : (funMor FF F) * (funMor FF G) |> funMor FF (F * G).
    f*2 : (funMor FF F) * (funMor FF G) * H |> funMor FF (F * G) * H.

This HTRS can be proved to be terminating using the technique illustrated before. In particular, |R_{fun}|, is easily verified to be as follows:

x ∗ id → x
id ∗ x → x
(x ∗ y) ∗ z → x ∗ (y ∗ z)

                                     funMorph(id) → id
                          funMorph(x) ∗ funMorph(y) → funMorph(x ∗ y)
                      funMorph(x) ∗ (funMorph(y) ∗ z) → funMorph(x ∗ y) ∗ z

This first order TRS can be shown terminating by using, for example, the polynomial interpretation used by Gehrke in [19]:

ρ(id) = 1
ρ(x ∗ y) = ρ(x)ρ(y) + ρ(x)
ρ(funMorph(x)) = ρ(x) + 1

Since |R_{fun}| is strongly normalizing, so is R_{fun}, and therefore we can apply either one of the Critical Pair Criteria we presented in Chapters 7 and 8 (E = ∅ in this case, and R_{fun} is left-linear). All critical pairs are trivial, from which confluence of the system follows.

12.3 Natural Transformations

Definition 12.3.1. Let C, D be categories, and F, G : C → D two functors. A natural transformation η from F to G, written η : F → G, is specified by an operation which assigns to each object a in C a morphism η_{a} : F a → G a in D such that, for any morphism f : a → b in C we have

(G f) · η_{a} = η_{b} · (F f)

i.e. the following diagram commutes:

\xymatrix{F a \ar[r]^{η_{a}} \ar[d]_{F f} & G a \ar[d]^{Gf} \\ F b \ar[r]_{η_{b}} & G b}

In representing natural transformations, we follow the same approach used for functors: we introduce a new type nat, dependent on two functors (as well as the two categories these functors are defined upon), and we express the operation a ↦ η_{a} as with a constant natObj:

    nat    : fun C D -> fun C D -> type.
    natObj : nat FF GF -> {O : obj C} mor D (funObj FF O) (funObj GF O).

We call Σ_{nat} this extension of the signature Σ_{fun} used for functors. Two new rules are added to R_{fun}, forming a new HTRS R_{nat}:

    n1    : (funMor GF (F : fun O1 O2)) * (natObj FN O1) =>
                (natObj FN O2) * (funMor FF F).
    n2    : (funMor GF (F : fun O1 O2)) * (natObj FN O1) * H =>
                (natObj FN O2) * (funMor FF F) * H.

This is shown terminating and confluent by the same techniques used before.

12.4 Adjunctions

Definition 12.4.1. Let L : C → D and L : D → C two functors, we say that L is left adjoint to R or that R is right adjoint to L if

• There is a bijection ζ between morphisms L a → b in D and morphisms a → R b in C (for all objects a in C and b in D).

• ζ is natural in a and b, i.e given f : a′ → a in C, and g : L a → b and h : b → b′ in D, we have

ζ(h · g · (L f)) = (R h) · ζ(g) · f (∗)

Trying to translate this definition into a signature Σ_{adj} and a HTRS R_{adj}, it is useful to clarify what symbols and equations need to be used to describe an adjunction. First, observe that the (*) can be equivalently expressed by the two equations

ζ(h · g) = (R h) · ζ(g)  ζ(g · (L f)) = ζ(g) · f

Also, ζ is a bijection; hence, this implicitly assumes the existence of a map ζ^{−1}, and the equations

ζ^{−1}(ζ(f)) = f  ζ(ζ^{−1}(g)) = g

to hold for all f : L a → b and g : a → R b in D (with a in C and b in D).

Not all the equations and symbols above, however, are strictly needed, as shown by the following result, due to Curien [13]:

Lemma 12.4.2. An adjunction can be completely characterized by ϵ, L, and ζ, where

ϵ_{a} = ζ^{−1}(id_{R a})

The missing components can be expressed as follows:

R f = ζ(f · ϵ_{a})
ζ^{−1}(g) = ϵ_{b} · L g

Using this result, we will give a representation that

• will not use ζ^{−1}, and therefore will not represent this map in the signature;

• will not contain references to the functor R other than when it is used to act on objects in D. The signature Σ_{adj} will extend Σ_{nat} with the new constants

adj : fun C D -> fun D C -> type.
eps  : adj (L : fun C D) R -> {Y : obj D} morph D (funObj L (funObj R Y)) Y.
zeta : adj (L : fun C D) R -> morph D (funObj L X) Y -> morph C X (funObj R Y).

As usual, we will treat some of the arguments of the operators as implicit. The HTRS R_{adj} similarly extends R_{nat}, adding new rules

zeta1 : zeta (A : adj L R) ((eps A O2) * funMorph L F) => F.
zeta2 : zeta (A : adj L R) (eps A O) => id (funObj R O).
zeta3 : zeta (A : adj L R) F * G => zeta A (F * funMorph L G).
eps1 : (eps (A : adj L R) O2) * (funMorph L (zeta A F)) => F.
eps2 : (eps (A : adj L R) O2) * (funMorph L (zeta A F)) * H => F * H.

A simple (but long and tedious) check reveals R_{adj} to be stongly normalizing and confluent.

124

Intuitionistic Natural Deduction and Sequent Calculus

In this chapter we will present a process for converting between Natural Deduction and Sequent Calculus. The two directions of this conversion will both be implemented by confluent, strongly-normalizing HTRSs. One obstacle we will find in doing this is that the translation into sequent derivations requires the use of the cut rule. For this reason, we will also present a third system, which will transform any sequent derivation into a cut-free one; this is based on the work of F. Pfenning, who in [61] describes a representation of the cut-elimination theorem in the LF logical framework.

In pictures, the content of this chapter can be summarized as follows:

[figure: Natural Deduction; R_{SQ}; Sequent Calculus; R_{ND}; Sequent Calculus + Cut; R_{cut}]

13.1 Natural Deduction

Our first task is to fix a representation for logical formulas. We will restrict ourselves to the propositional calculus: while Twelf can easily accommodate for first-order logic, the meta-representation of inference rules involving quantifiers force us to consider some non-pattern expressions, which lie outside the (current) range of applicability of our tools. However, there is very little loss of generality in doing so: most of the proof-theoretical issues and concepts in the transformations we describe are well-represented by the the propositional fragment.

We will consider the full set of logical connectives and constants:

Formulas A := P | A_{1} ∧ A_{2} | A_{1} ⊃ A_{2} | A_{1} ∨ A_{2} | ¬A | ⊥ | ⊤

A Twelf signature for these, shown in Figure 13.1, is composed by a single type o for formulas, as well as object constants for each connective.

Natural Deduction [64] tries to reproduce in a formal context the process of logical inference used in most mathematical proofs. Judgments derived using this calculus are of the form

⊢ A

stating that the formula A is provable; its proof may rely on many outstanding assumptions, that have not been “discharged” during its development.

    o : type.
    true  : o.
    false : o.
    not : o -> o.            %prefix 10 not
    and : o -> o -> o.       %infix right 4 and
    or  : o -> o -> o.       %infix right 4 or
    imp : o -> o -> o.       %infix right 4 imp

Figure 13.1: A Signature for Propositional Formulas

The rules of inference of the for intuitionistic Natural Deduction can be neatly organized in two groups, introduction and elimination rules. Each connective and logical constant admits at most one rule of each group; moreover, introduction and elimination rules for any given connective are complementary, in the sense that any immediately consecutive application of the two is redundant, and can be safely removed from the proof. The complete list of rules in the calculus is given in Figure 13.2.

In Twelf, we introduce a new type nd, dependent on objects of type o, to represent the judgment ⊢ A. Rules of the calculus are implemented as functional objects, accepting (representations of) the antecedents as arguments, producing (a representation of) the consequent. For example, the rule

\frac{⊢ A ∧ B}{⊢ B} ∧E_{2}

translates into the object

    andE2   : nd (A and B) -> nd B.

The complete signature is given in Figure 13.3. A proof of the adequacy of this representation can be found, for example, in [60].

13.2 Sequent Calculus

Gentzen’s Sequent Calculus [21] has been an important tool for proof theoretical investigations and applications of logic in computer science. Although several formulations have been given over time, sequents are commonly found expressed as judgments of the form

Γ ⟶ Δ

signifying that the formulas in Γ entail those in Δ. The intuitionistic fragment is elegantly isolated by requiring Δ to be a singleton formula C.

Rules of the calculus can be grouped into five classes. A initial rule states that any formula immediately entail itself:

\overline{A ⟶ A} I

We have also left and right rules for each logical symbol, to perform steps of logical inference on the formulas on the left (i.e. Γ) or on the right (Δ), respectively, of the sequent.

Another class is formed by the so-called structural rules, which allow us to rearrange the order of Γ and Δ, as well as regulate the addition and removal of formulas from them. For intuitionistic logic, a common choice of structural rules are exchange, weakening, and contraction:

\frac{Γ_{1}, B, A, Γ_{2} ⟶ C}{Γ_{1}, A, B, Γ_{2} ⟶ C} ex  \frac{Γ_{1} ⟶ C}{Γ_{1}, Γ_{2} ⟶ C} wk  \frac{Γ, A, A ⟶ C}{Γ, A ⟶ C} ct

\begin{aligned}\frac{⊢ A  ⊢ B}{⊢ A ∧ B} ∧I & \frac{⊢ A ∧ B}{⊢ A} ∧E_{1}  \frac{⊢ A ∧ B}{⊢ B} ∧E_{2} \\ \frac{\overline{⊢ A} u ; ⋮ ; ⊢ B}{⊢ A ⊃ B} ⊃I^{u} & \frac{⊢ A  ⊢ A ⊃ B}{⊢ B} ⊃E \\ \frac{⊢ A}{⊢ A ∨ B} ∨I_{1}  \frac{⊢ B}{⊢ A ∨ B} ∨I_{2} & \frac{⊢ A ∨ B  \overline{⊢ A} u ; ⋮ ; ⊢ C  \overline{⊢ B} v ; ⋮ ; ⊢ C}{⊢ C} ∨E^{u,v} \\ \frac{\overline{⊢ A} u ; ⋮ ; ⊢ p}{⊢ ¬A} ¬I^{p} & \frac{⊢ ¬A  ⊢ A}{⊢ C} ¬E \\ \overline{⊢ ⊤} & ⊤I \\ \frac{⊢ ⊥}{⊢ C} & ⊥E \end{aligned}

Figure 13.2: Natural Deduction Rules

nd : o -> type.
andI    : nd A -> nd B -> nd (A and B).
andE1   : nd (A and B) -> nd A.
andE2   : nd (A and B) -> nd B.
impI    : (nd A -> nd B) -> nd (A imp B).
impE    : nd A -> nd (A imp B) -> nd B.
orI1    : nd A -> nd (A or B).
orI2    : nd B -> nd (A or B).
orE     : nd (A or B) -> (nd A -> nd C) -> (nd B -> nd C) -> nd C.
notI    : ({p : o} nd A -> nd p) -> nd (not A).
notE    : nd (not A) -> nd A -> nd C.
trueI   : nd (true).
falseE  : nd (false) -> nd C.

Figure 13.3: Signature for Natural Deduction Rules Finally, a rule commonly found in presentations of the sequent calculus is the cut rule:

\frac{Γ ⟶ Δ_{1}, A Γ, A ⟶ Δ_{2}}{Γ ⟶ Δ_{1}, Δ_{2}} cut

This is a derived rule, in the sense that derivations that use cut can be shown to always have “cut-free” correspondents (cut-elimination).

In picking a specific flavor of Sequent Calculus, our main criterion is ease of representation. Logical frameworks based on Hereditary Harrop Formulas or LF are traditionally biased toward Natural Deduction, and have some difficulties in representing sequents. Structural rules seem to be the culprit, and therefore efficient formulations of these is highly desirable. Multi-sets, where available, allow one to avoid using exchange explicitly, leading to a calculus with just weakening and contraction. The system that we will use here actually manages to eliminate these two rules too, by embedding the first into an extended version of the initial rule, and distributing the second over the left rules. By doing so we obtain G_{3}, a formulation for the Sequent Calculus first introduced by Kleene in [35] to obtain a decision procedure for the propositional fragment. The rules for G_{3}, taken from [61], are shown in Figure 13.4. The right rule for negation, ¬R^{p}, requires the use of a propositional parameter p; in order for the rule to be applicable, we require this not to appear in neither Γ nor A.

Pfenning’s clever idea in [61] was to represent G_{3} in Twelf using LF contexts to implement the (multisets) Γ of left formulas. Hence, we introduce two new types, hyp and conc, both dependent on objects of type o, and we represent a Sequent Calculus derivation as a proof object

x_{1} : hyp ⌈A_{1}⌉, …, x_{n} : hyp ⌈A_{n}⌉ ⊢\begin{matrix}≺ \\ Σ \end{matrix} M : conc ⌈C⌉

(above, we indicated with ⌈A⌉ the Twelf representation of the formula A). As in the case of Natural Deduction, rules of inference are encoded by functional objects which map premises into conclusions. Cases where a formula appears in the left side of an antecedent but not in the consequent are handled by lambdaabstraction. The Twelf signature for Sequent Calculus is given in Figure 13.5.

13.3 From Natural Deduction to Sequent Calculus

The key idea in translating natural deduction proofs into sequent calculus is to translate a derivation D of ⊢ C with undischarged assumptions Γ = A_{1}, A_{2}, …, A_{n} into a sequent calculus derivation G of Γ ⟶ C. In pictures:

[ D ; ⋮ ; ⊢ C ]_{Γ}  ⟹_{R}  G ; ⋮ ; Γ ⟶ C

Introduction rules translate directly into right rules. For example:

[ \begin{matrix}D_{1}  D_{2} \\ ⋮ & ⋮ \\ \frac{⊢ C_{1}  ⊢ C_{2}}{⊢ C_{1} ∧ C_{2}} & ∧I \end{matrix} ]_{Γ}  ⟹_{R}  \frac{[ D_{1} ; ⋮ ; ⊢ C_{1} ]_{Γ}  [ D_{2} ; ⋮ ; ⊢ C_{2} ]_{Γ}}{Γ ⟶ C_{1} ∧ C_{2}} ∧R

For elimination rules, the antecedent usually becomes the cut formula of the sequent derivation:

[ D ; ⋮ ; \frac{⊢ A ∧ B}{⊢ A} ∧E_{1} ]_{Γ}  ⟹_{R}  \frac{[ D ; ⋮ ; ⊢ A ∧ B ]_{Γ}  \frac{\overline{Γ, A ∧ B, A ⟶ A}^{I}}{Γ, A ∧ B ⟶ A} ∧L_{1}}{Γ ⟶ A} cut

\overline{Γ, A ⟶ A} I
\frac{Γ ⟶ A  Γ ⟶ B}{Γ ⟶ A ∧ B} ∧R  \begin{matrix}\frac{Γ, A ∧ B, A ⟶ C}{Γ, A ∧ B ⟶ C} & ∧L_{1} \\ \frac{Γ, A ∧ B, B ⟶ C}{Γ, A ∧ B ⟶ C} & ∧L_{2} \end{matrix}
\frac{Γ, A ⟶ B}{Γ ⟶ A ⊃ B} ⊃R  \frac{Γ, A ⊃ B ⟶ A  Γ, A ⊃ B, B ⟶ C}{Γ, A ⊃ B ⟶ C} ⊃L
\begin{matrix}\frac{Γ ⟶ A}{Γ ⟶ A ∨ B} & ∨R_{1} \\ \frac{Γ ⟶ B}{Γ ⟶ A ∨ B} & ∨R_{2} \end{matrix}  \frac{Γ, A ∨ B, A ⟶ C  Γ, A ∨ B, B ⟶ C}{Γ, A ∨ B ⟶ C} ∨L

\begin{matrix}\frac{Γ, A ⟶ p}{Γ ⟶ ¬A} ¬R^{p} & \frac{Γ, ¬A ⟶ A}{Γ, ¬A ⟶ C} ¬L \\ \overline{Γ ⟶ ⊤} & ⊤R \\ \overline{Γ, ⊥ ⟶ C} & ⊥L \end{matrix}

\frac{Γ ⟶ A  Γ, A ⟶ C}{Γ ⟶ C} cut

Figure 13.4: Sequent Calculus Rules

hyp  : o -> type.
conc : o -> type.
axiom  : hyp A -> conc A.
andl1  : (hyp A -> conc C)
         -> (hyp (A and B) -> conc C).
andl2  : (hyp B -> conc C)
         -> (hyp (A and B) -> conc C).
andr   : conc A
         -> conc B
         -> conc (A and B).
impl   : conc A
         -> (hyp B -> conc C)
         -> (hyp (A imp B) -> conc C).
impr   : (hyp A -> conc B)
          -> conc (A imp B).
orl    : (hyp A -> conc C)
          -> (hyp B -> conc C)
          -> (hyp (A or B) -> conc C).
orr1   : conc A
         -> conc (A or B).
orr2   : conc B
         -> conc (A or B).
notl   : conc A
         -> (hyp (not A) -> conc C).
notr   : ({p : o} hyp A -> conc p)
         -> conc (not A).
truer  : conc (true).
falsel : (hyp (false) -> conc C).
cut : {A : o} conc A
      -> (hyp A -> conc C)
      -> conc C.

Figure 13.5: Signature for Sequent Calculus Rules

When we look at the Twelf representations of both calculi, we realize that, in implementing this transformation of a HTRS, we have to be more subtle. The derivation D is encoded in LF as an object M such that

x_{1} : nd A_{1}, …, x_{n} : nd A_{n} ⊢\begin{matrix}≺ \\ Σ \end{matrix} M : nd C

On the other hand, G is encoded by N, where

y_{1} : hyp ⌈A_{1}⌉, …, y_{n} : hyp ⌈A_{n}⌉ ⊢\begin{matrix}≺ \\ Σ \end{matrix} N : conc ⌈C⌉

The translation will then have to be expressed by two complementary operators:

trSQ   : nd A -> conc A.
trSQ~1 : hyp A -> nd A.

and the term N we are looking for will be obtained by reducing

y_{1} : hyp ⌈A_{1}⌉, …, y_{n} : hyp ⌈A_{n}⌉ ⊢\begin{matrix}≺ \\ Σ \end{matrix} (trSQ M)[x_{i}/(trSQ~1 y)] : conc ⌈C⌉

into a trSQ- and trSQ~1-free term.

The complete HTRS is given in Figure 13.6. Note that, since these transformations are given by induction on the last inference used in the derivation, they are strongly-normalizing and trivially confluent (there are no critical overlaps).

13.4 From Sequent Calculus to Natural Deduction

Translating back from sequent calculus to natural deduction is done in a fundamentally similar way. Given a derivation G of Γ ⟶ C, we would like to obtain a proof D of ⊢ C with undischarged assumptions Γ = A_{1}, …, A_{n}. However, this principle does not scale well to considering left rules; proceeding, as before, in a bottom-up manner, we see that the left rules introduce new formulas in the set Γ. Although it is possible to treat these as fresh assumptions, they are actually logical consequences of pre-existing formulas in Γ. A better representation for the transformation makes use of an assignment Γ := \overline{I} that maps each of the assumptions A_{i} in Γ into a natural deduction derivation I_{i}:

[ G ; ⋮ ; Γ ⟶ C ]_{Γ:=\overline{I}}  ⟹_{R}  D ; ⋮ ; ⊢ C

In the case of left rules, we extend this assignment to the newly introduced formula by giving a derivation of it, which we construct making use of the other derivations the assignment provides us. To illustrate how this works, we give here the conversion rules for ∧L_{1} and ∧R:

[ G ; ⋮ ; \frac{Γ, A ∧ B, A ⟶ C}{Γ, A ∧ B ⟶ C} ∧L_{1} ]_{Γ:=\overline{I}, A∧B:=I_{0}} ⟹_{R}  [ G ; ⋮ ; Γ, A ∧ B, A ⟶ C ]_{Γ:=\overline{I}, A∧B:=I_{0}, A:= \frac{\begin{matrix}I_{0} \\ ⊢A∧B \end{matrix}}{⊢A} ∧E_{1}}

[ \begin{matrix}G_{1}  G_{2} \\ ⋮ & ⋮ \\ \frac{Γ ⟶ C_{1}  Γ ⟶ C_{2}}{Γ ⟶ C_{1} ∧ C_{2}} & ∧R \end{matrix} ]_{Γ:=\overline{I}} ⟹_{R}  \frac{[ G_{1} ; ⋮ ; Γ ⟶ C_{1} ]_{Γ:=\overline{I}}  [ G_{2} ; ⋮ ; Γ ⟶ C_{2} ]_{Γ:=\overline{I}}}{⊢ C_{1} ∧ C_{2}} ∧I

Representing this transformation in LF is done as before, by defining two complementary operators:

tr_var : trSQ (trSQ~1 H) => axiom H.
tr_andI : trSQ (andI D1 D2) => andr (trSQ D1) (trSQ D2).
tr_andE1 : trSQ (andE1 D)
           => cut (A and B) (trSQ D) ([h : hyp (A and B)] andl1 axiom h).
tr_andE2 : trSQ (andE2 D)
           => cut (A and B) (trSQ D) ([h : hyp (A and B)] andl2 axiom h).
tr_impI : trSQ (impI ([d : nd A] D d))
          => impr ([h : hyp A] trSQ (D (trSQ~1 h))).
tr_impE : trSQ (impE D1 D2)
          => cut (A imp B) (trSQ D2)
                 ([h : hyp (A imp B)] impl (trSQ D1) (axiom) h).
tr_orI1 : trSQ (orI1 D1) => orr1 (trSQ D1).
tr_orI2 : trSQ (orI2 D2) => orr2 (trSQ D2).
tr_orE  : trSQ (orE D ([d1 : nd A] D1 d1) ([d2 : nd B] D2 d2))
          => cut (A or B) (trSQ D)
                 ([h : hyp (A or B)] orl ([h1 : hyp A] trSQ (D1 (trSQ~1 h1)))
                                         ([h2 : hyp B] trSQ (D2 (trSQ~1 h2))) h).
tr_notI   : trSQ (notI ([p : o] [d : nd A] D p d))
            => notr ([p : o] [h : hyp A] trSQ (D p (trSQ~1 h))).
tr_notE   : trSQ (notE D1 D2)
            => cut (not A) (trSQ D1) ([h : hyp (not A)] notl (trSQ D2) h).
tr_trueI  : trSQ (trueI) => truer.
tr_falseE : trSQ (falseE D) => cut (false) (trSQ D) falsel.

Figure 13.6: Natural Deduction to Sequent Calculus HTRS

tr_axiom : trND (axiom (trND~1 G)) => G.
tr_andl1 : trND (andl1 ([h1 : hyp A] D1 h1) (trND~1 G))
           => trND (D1 (trND~1 (andE1 G))).
tr_andl2 : trND (andl2 ([h2 : hyp A] D2 h2) (trND~1 G))
           => trND (D2 (trND~1 (andE2 G))).
tr_andr : trND (andr D1 D2) => andI (trND D1) (trND D2).
tr_impl : trND (impl D1 ([h2 : hyp B] D2 h2) (trND~1 G))
          => trND (D2 (trND~1 (impE (trND D1) G))).
tr_impr : trND (impr ([h : hyp A] D h)) => impI ([d : nd A] trND (D (trND~1 d))).
tr_orl : trND (orl ([h1 : hyp A] D1 h1) ([h2 : hyp B] D2 h2) (trND~1 G))
         => orE G ([d1 : nd A] trND (D1 (trND~1 d1)))
                  ([d2 : nd B] trND (D2 (trND~1 d2))).
tr_orr1 : trND (orr1 D1) => orI1 (trND D1).
tr_orr2 : trND (orr2 D2) => orI2 (trND D2).
tr_notl : trND (notl D (trND~1 G)) => notE G (trND D).
tr_notr : trND (notr ([p : o] [h : hyp A] D p h))
          => notI ([p : o] [d : nd A] trND (D p (trND~1 d))).
tr_truer : trND (truer) => trueI.
tr_falsel : trND (falsel (trND~1 G)) => falseE G.

Figure 13.7: Sequent Calculus to Natural Deduction HTRS

trND   : conc A -> nd A.
trND~1 : nd A -> hyp A.

The inverse operator trND~1 takes here a more active role than before, since we use it to implement the assignment described before. The non-overlapping, strongly confluent HTRS that we obtain is listed in Figure 13.7.

13.5 Cut Elimination

The missing piece to our construction is the representation of a cut-elimination theorem as a confluent HTRS. In this section, we will adopt the proof presented by Pfenning in [61], turning it into a set of rewrite rules. Using an existing proof as a starting point has the advantage of freeing us from the burden of providing a termination ordering for the HTRS we produce: the same induction principle used by the proof will suffice in showing strong normalization. We are left to examine problems of confluence, which, however, given our background, we are better equipped to handle.

In constructing our HTRS, we start from the following:

Theorem 13.5.1 (Admissibility of Cut). Let D and G be cut-free derivations of Γ ⟶ A and Γ, A ⟶ C, respectively, then there exists a cut-free derivation of Γ ⟶ C.

This result allow us to see every instance of cut as a syntactic shorthand for a larger, cut-free derivation. From this perspective, a HTRS can be easily formulated as a list of directed definitional equalities, replacing the shorthand with the proof it stands for. Places in the proof where the inductive hypothesis is invoked on sub-derivations of D or G translate in our notation into (recursive) applications of cut, to be eventually eliminated by repeated applications of the rewriting rules.

The proof of Theorem 13.5.1, and correspondingly, our higher-order rules, can be divided into four classes

1. Initial Conversions

At least one of the derivation consists of a single application of the initial rule;

2. Essential Conversions: in both derivation, the cut formula is also the principal formula of the last inference step, i.e. the one that the inference rule operates upon;

3. Left Commutative Conversions: the cut formula is non-principal in D;

4. Right Commutative Conversions: the cut formula is non-principal in G.

Translating the Pfenning’s proof into rewrite rules, we obtain the system shown in Figures 13.9-13.12. Since the four classes above are not mutually exclusive, the system has critical overlaps. Unfortunately,

not all of these turn out to be trivial: specifically, critical pairs coming from overlapping left and right commutative conversions cannot be joined.

To complete the system by orienting critical pairs is not directly feasible, as there are rules like ri1 (see Figure 13.9) that have non-pattern right-hand-sides, and hence generate non-pattern pairs. It is possible, however, to come up with a slightly different proof for cut-elimination where all rules have pattern RHSs. Pursuing this technique led us to a system that could be completed, although not necessarily by a finite number of rules: orienting critical pairs generated rules that admitted new critical overlaps, that had to be oriented in rules, and so on. The completion process seemed to diverge, which discouraged any further attempt in this direction.

For this reason we investigated another solution, consisting in eliminating non-trivial critical pairs in the original system by removing some of the non-deterministic choices in the cut-elimination process. Specifically, we imposed that right commutative conversions could be applied in case all other cases fail, i.e. only to those cases where the cut formula is the principal formula in D.

Figure 13.8 shows how all four possible cases of cut-elimination of non-initial derivations are handled.

Principal in G  Non-Principal in G
Principal in D Essential Right-Commutative
Non-Principal in D Left-Commutative Left-Commutative

Figure 13.8: Cut Elimination for Non-Initial Derivations

Translating these ideas into our HTRS, what we need to do is to specialize each rule of Figure 13.12 to those cases where the derivation D ends with a right rule. For example,

    rr3  : cut A D ([h : hyp A] orr1 (G1 h)) => orr1 (cut A D G1).

is converted into

    rr3_1 : cut (A1 and A2) (andr D1 D2) ([h : hyp (A1 and A2)] orr1 (G1 h))
            => orr1 (cut (A1 and A2) (andr D1 D2) G1).
    rr3_2 : cut (A1 imp A2) (impr D1) ([h : hyp (A1 imp A2)] orr1 (G1 h))
            => orr1 (cut (A1 imp A2) (impr D1) G1).
    rr3_3 : cut (A1 or A2) (orr1 D1) ([h : hyp (A1 or A2)] orr1 (G1 h))
            => orr1 (cut (A1 or A2) (orr1 D1) G1).
    rr3_4 : cut (A1 or A2) (orr2 D2) ([h : hyp (A1 or A2)] orr1 (G1 h))
            => orr1 (cut (A1 or A2) (orr2 D2) G1).

rr3_5 : cut (not A1) (notr D1) ([h : hyp (not A1)] orr1 (G1 h))
        => orr1 (cut (not A1) (notr D1) G1).
rr3_6 : cut (true) (truer) ([h : hyp (true)] orr1 (G1 h))
        => orr1 (cut (true) (truer) G1).

The resulting HTRS admits has a fairly large number of critical pairs, 7459 to be precise, but they all can be shown to be trivial.

ri1 : cut A (axiom H) G => (G H).
ri2 : cut A D ([h : hyp A] axiom h) => D.

Figure 13.9: Cut Elimination - Initial Rules

re1 : cut (A1 and A2) (andr D1 D2)
          ([h : hyp (A1 and A2)] andl1 ([h1 : hyp A1] (G1 h1 h)) h)
      => cut A1 D1 ([h1 : hyp A1] cut (A1 and A2) (andr D1 D2) (G1 h1)).
re2 : cut (A1 and A2) (andr D1 D2)
          ([h : hyp (A1 and A2)] andl2 ([h2 : hyp A2] (G2 h2 h)) h)
      => cut A2 D2 ([h2 : hyp A2] cut (A1 and A2) (andr D1 D2) (G2 h2)).
re3 : cut (A1 imp A2) (impr D1)
          ([h : hyp (A1 imp A2)] impl (G1 h) ([h2 : hyp A2] G2 h2 h) h)
      => cut A2 (cut A1 (cut (A1 imp A2) (impr D1) G1) D1)
                  ([h2 : hyp A2] cut (A1 imp A2) (impr D1) (G2 h2)).
re4 : cut (A1 or A2) (orr1 D1)
          ([h : hyp (A1 or A2)] orl ([h1 : hyp A1] G1 h1 h)
                                    ([h2 : hyp A2] G2 h2 h) h)
      => cut A1 D1 ([h1 : hyp A1] cut (A1 or A2) (orr1 D1) (G1 h1)).
re5 : cut (A1 or A2) (orr2 D2)
          ([h : hyp (A1 or A2)] orl ([h1 : hyp A1] G1 h1 h)
                                    ([h2 : hyp A2] G2 h2 h) h)
      => cut A2 D2 ([h2 : hyp A2] cut (A1 or A2) (orr2 D2) (G2 h2)).
re6 : cut (not A1) (notr D1)
          ([h : hyp (not A1)] notl (G1 h) h)
      => cut A1 (cut (not A1) (notr D1) G1) (D1 C).

Figure 13.10: Cut Elimination - Essential Rules

rl1 : cut A (andl1 D1 H) G => andl1 ([h1 : hyp A1] cut A (D1 h1) G) H.
rl2 : cut A (andl2 D2 H) G => andl2 ([h2 : hyp A2] cut A (D2 h2) G) H.
rl3 : cut A (impl D1 D2 H) G => impl D1 ([h2 : hyp A2] cut A (D2 h2) G) H.
rl4 : cut A (orl D1 D2 H) G
      => orl ([h1 : hyp A1] cut A (D1 h1) G) ([h2 : hyp A2] cut A (D2 h2) G) H.
rl5 : cut A (notl D H) G => notl D H.
rl6 : cut A (falsel H) G => falsel H.

Figure 13.11: Cut Elimination - Left-commutative Rules

rr0  : cut A D ([h : hyp A] axiom H1) => axiom H1.
rr1  : cut A D ([h : hyp A] andr (G1 h) (G2 h)) => andr (cut A D G1) (cut A D G2).
rr2  : cut A D ([h : hyp A] impr ([h1 : hyp C1] G1 h1 h))
       => impr ([h1 : hyp C1] cut A D (G1 h1)).
rr3  : cut A D ([h : hyp A] orr1 (G1 h)) => orr1 (cut A D G1).
rr4  : cut A D ([h : hyp A] orr2 (G2 h)) => orr2 (cut A D G2).
rr5  : cut A D ([h : hyp A] notr (G h))
       => notr ([p : o][h1 : hyp C1] cut A D ([h : hyp A] G h p h1)).
rr6  : cut A D ([h : hyp (A1 and A2)] truer) => truer.
rr7  : cut A D ([h : hyp A] andl1 ([h1 : hyp B1] (G1 h1 h)) H)
       => andl1 ([h1 : hyp B1] cut A D (G1 h1)) H.
rr8  : cut A D ([h : hyp A] andl2 ([h2 : hyp B2] (G2 h2 h)) H)
       => andl2 ([h2 : hyp B2] cut A D (G2 h2)) H.
rr9  : cut A D ([h : hyp A] impl (G1 h) ([h2 : hyp B2] G2 h2 h) H)
       => impl (cut A D G1) ([h2 : hyp B2] cut A D (G2 h2)) H.
rr10 : cut A D ([h : hyp A] orl ([h1 : hyp B1] G1 h1 h) ([h2 : hyp B2] G2 h2 h) H)
       => orl ([h1 : hyp B1] cut A D (G1 h1)) ([h2 : hyp B2] cut A D (G2 h2)) H.
rr11 : cut A D ([h : hyp A] notl (G1 h) H) => notl (cut A D G1) H.
rr12 : cut A D ([h : hyp A] falsel H) => falsel H.

Figure 13.12: Cut Elimination - Right-commutative Rules 138

Index

E-conversion, 92

canonical, 94 FV(·), 9 Γ(·, ·), 30 η-expansion, 36

internal, 36 Π to be a, 9

⇒^{I}_{η}, 36

⇒_{η}, 36 ≈_{E}, 41 dom(·), 10 =_{E′βη}, 11

over substitutions, 14 λ to be a, 9 λ-equivalence, 41 ≺^{t}, 11

over types, 11 →_{E}, 92 →_{R[E]}, 87 →_{R}, 66 →_{E_{βη}}, 94 ≺^{τ}, 11

over types, 11 kind(Γ(·, ·)), 30 type(Γ(·, ·)), 30

atomic forms, 35

base type, 9

canonical forms, 35 critical pair, 83, 100

dependence relation, 11, 55–58 dependence relations

full, 14

environment Eλ-equivalence, 73 Γ-stable, 78 atomic, 67 canonical, 67

environments, 61–65 composition of, 61 disjoint, 64 for an object, 61 objects isolated by, 61

head, 11 HTRS, 66

narrowing, 107

pattern, 14 Γ-, 78

quasi-ordering on types, 108

rewriting, 66 canonical, 67 internal, 87 modulo E, 66 140

Bibliography

[1] Andrea Asperti and Giuseppe Longo. Categories, types, and structures: An introduction to category theory for the working computer scientist (MIT press, 1991). SIGACTN: SIGACT News (ACM Special Interest Group on Automata and Computability Theory), 22, 1991.

[2] Jürgen Avenhaus, Carlos Loría Sáenz, and Joachim Steinbach. A reduction ordering for higher-order terms. Technical Report SR-95-03, Fachbereich Informatik, Universität Kaiserlautern, 1995.

[3] Franz Baader and Tobias Nipkow. Rewriting and All That. Cambridge University Press, Shaftesbury Road, Cambridge, England, 1998.

[4] Leo Bachmair and Nachum Dershowitz. Completion for rewriting modulo a congruence. TCS: Theoretical Computer Science, 67, 1989.

[5] Franco Barbanera and Maribel Fernández. Modularity of termination and confluence in combinations of rewrite systems with λ_{ω}. In ICALP: Annual International Colloquium on Automata, Languages and Programming, 1993.

[6] Franco Barbanera, Maribel Fernández, and Herman Geuvers. Modularity of strong normalization and confluence in the algebraic lambda-cube. In LICS: IEEE Symposium on Logic in Computer Science, 1994.

[7] Hendrik Pieter Barendregt. The Lambda-Calculus: Its Syntax and Semantics. North-Holland, Amsterdam, 1980.

[8] Hendrik Pieter Barendregt. Lambda calculi with types. In Handbook of Logic in Computer Science, Volumes 1 (Background: Mathematical Structures) and 2 (Background: Computational Structures), Abramsky & Gabbay & Maibaum (Eds.), Clarendon, volume 2. Oxford University Press, 1992.

[9] Val Breazu-Tannen. Combining algebra and higher-order types. In Proc. IEEE Symp. on Logic in Computer Science, pages 82–90, 1988.

[10] Manuel Clavel, Francisco Duràn, Steven Eker, and Jose Meseguer. Principles of Maude. In Proceedings of the 1st International Workshop on Rewriting Logic and its Applications, Pacific Grove, California, September 1996.

[11] Robert Constable and Douglas Howe. NuPrl as a general logic. In P. Odifreddi, editor, Logic and Computation. Academic Press, 1990.

[12] Roberto Di Cosmo. On the power of simple diagrams. In Harald Ganzinger, editor, Proceedings of the 7th International Conference on Rewriting Techniques and Applications, pages 200–214, New Brunswick, New Jersey, July 1996. Springer-Verlag LNCS 1103.

[13] Pierre-Louis Curien. Categorical Combinators, Sequential Algorithms and Functional Programming. Progress in Theoretical Computer Science. Birkhauser, 1993.

[14] Nachum Dershowitz. Orderings for term-rewriting systems. TCS: Theoretical Computer Science, 17, 1982.

[15] M. Dincbas, P. Van Hentenryck, H. Simonis, A. Aggoun, T. Graf, and F. Berthier. The constraint logic programming language CHIP. In Proceedings of the International Conference on Fifth Generation Computer Systems, Tokyo, Japan, December 1988.

[16] Gilles Dowek, Amy Felty, Hugo Herbelin, Gérard Huet, Chet Murthy, Catherine Parent, Christine Paulin-Mohring, and Benjamin Werner. The Coq proof assistant user’s guide. Rapport Techniques 154, INRIA, Rocquencourt, France, 1993. Version 5.8.

[17] Gilles Dowek, Gérard Huet, and Benjamin Werner. On the definition of the eta-long normal form in the type systems of the cube Calculus of Constructions. In Herman Geuvers, editor, Informal Proceedings of the Workshop on Types for Proofs and Programs, Nijmegen, The Netherlands, May 1993.

[18] Thom Früwirth. Theory and practice of Constraint Handling Rules. Journal of Logic Programming, 37(1-3):95–138, October 1998.

[19] Wolfgang Gehrke. Decidability Results for Categorical Notions Related to Monads by Rewriting Techniques. PhD thesis, Research Institute for Symbolic Computation, Linz, Austria, May 1995. Available as RISC Report Number 95-30.

[20] Wolfgang Gehrke and Frank Pfenning. ElfRW distribution, 1996.

[21] Gerhard Gentzen. Investigations into logical deduction. In M. E. Szabo, editor, The Collected Papers of Gerhard Gentzen. North-Holland, 1969.

[22] Herman Geuvers. The Church-Rosser property for βη-reduction in typed λ-calculi. In A. Scedrov, editor, Seventh Annual IEEE Symposium on Logic in Computer Science, pages 453–460, Santa Cruz, California, June 1992.

[23] Neil Ghani. Eta-expansions in dependent type theory—the Calculus of Constructions. In R. Hindley, editor, Proceedings fo the Third International Conference on Typed Lambda Calculus and Applications (TLCA’97), Nancy, France, April 1997. Springer-Verlag LNCS.

[24] Joseph Goguen, Claude Kirchner, Helene Kirchner, Aristide Mégrelis, and José Meseguer. An introduction to OBJ3. In Jean-Pierre Jouannaud and Stephane Kaplan, editors, Proceedings of the Workshop on Conditional Term Rewriting Systems (Orsay, France), pages 258–263. Springer-Verlag LNCS 308, Berlin, 1988.

[25] Thérèse Hardin and Alain Laville. Proof of termination of the rewriting system SUBST on CCL. Theoretical Computer Science, 46:305–312, 1986.

[26] Robert Harper. An equational formulation of LF. Technical Report ECS-LFCS-88-67, University of Edinburgh, October 1988.

[27] Robert Harper, Furio Honsell, and Gordon Plotkin. A framework for defining logics. In Symposium on Logic in Computer Science, pages 194–204. IEEE Computer Society Press, June 1987.

[28] Robert Harper, Furio Honsell, and Gordon Plotkin. A framework for defining logics. Journal of the Association for Computing Machinery, 40(1):143–184, January 1993.

[29] Gérard Huet. Confluent reductions: abstract properties and applications to term rewrite systems. Journal of the Association for Computing Machinery, 27(4):787–821, October 1980.

[30] Gérard Huet. A complete proof of correctness of the Knuth-Bendix completeness algorithm. JCSS: Journal of Computer and System Sciences, 23, 1981.

[31] Gérard Huet and D. C. Oppen. Equations and Rewrite Rules: A Survey, pages 349–405. Academic Press, New York, 1980.

[32] Joxan Jaffar, Spiro Michayov, Peter Stuckey, and Roland Yap. The CLP(R) language and system. ACM Transactions on Programming Languages and Systems, 14(3):339–395, July 1992.

[33] Jean-Pierre Jouannaud and Albert Rubio. Rewrite orderings for higher-order terms in η-long β-normal form and the recursive path ordering. Theoretical Computer Science, 208:33–58, 1998.

[34] Stefan Kahrs. Towards a domain theory for termination proofs. In Jieh Hsiang, editor, Proceedings of the Sixth International Conference on Rewriting Techniques and Applications, pages 241–255, Kaiserslautern, Germany, April 1995. Springer-Verlag LNCS 914.

[35] Stephen C. Kleene. Introduction to Metamathematics. D. van Nostrand, Princeton, New Jersey, 1952.

[36] Jan Willem Klop. Term rewriting systems: a tutorial. Bulletin of the European Association for Theoretical Computer Science, 32:143–182, June 1987.

[37] Donald E. Knuth and Peter B. Bendix. Simple word problems in universal algebra. In John Leech, editor, Computational Problems in Abstract Algebra, pages 263–297. Pergamon Press, 1970.

[38] Zhaohui Luo and Robert Pollack. The LEGO proof development system: A user’s manual. Technical Report ECS-LFCS-92-211, University of Edinburgh, May 1992.

[39] Olav Lysne and Javier Piris. A termination ordering for higher order rewrite systems. In Jieh Hsiang, editor, Proceedings of the Sixth International Conference on Rewriting Techniques and Applications, pages 26–40, Kaiserslautern, Germany, April 1995. Springer-Verlag LNCS 914.

[40] Narciso Martì-Oliet and Jose Meseguer. Rewriting logic as a logical and semantical framework. Technical Report SRI-CSL-93-05, SRI International, August 1993.

[41] Per Martin-Löf. Constructive mathematics and computer programming. In Logic, Methodology and Philosophy of Science VI, pages 153–175. North-Holland, 1980.

[42] Per Martin-Löf. On the meanings of the logical constants and the justifications of the logical laws. Technical Report 2, Scuola di Specializzazione in Logica Matematica, Dipartimento di Matematica, Università di Siena, 1985.

[43] Per Martin-Löf. Truth of a propositions, evidence of a judgement, validity of a proof. Notes to a talk given at the workshop Theory of Meaning, Centro Fiorentino di Storia e Filosofia della Scienza, June 1985.

[44] Spiro Michaylov and Frank Pfenning. An empirical study of the runtime behavior of higher-order logic programs. In D. Miller, editor, Proceedings of the Workshop on the λProlog Programming Language, pages 257–271, Philadelphia, Pennsylvania, July 1992. University of Pennsylvania. Available as Technical Report MS-CIS-92-86.

[45] Spiro Michaylov and Frank Pfenning. Higher-order logic programming as constraint logic programming. In Position Papers for the First Workshop on Principles and Practice of Constraint Programming, pages 221–229, Newport, Rhode Island, April 1993. Brown University.

[46] Dale Miller. A theory of modules for logic programming. In Robert M. Keller, editor, Third Annual IEEE Symposium on Logic Programming, pages 106–114, Salt Lake City, Utah, September 1986.

[47] Dale Miller. A logic programming language with lambda-abstraction, function variables, and simple unification. In Peter Schroeder-Heister, editor, Proceedings of the International Workshop on Extensions of Logic Programming, pages 253–281, Tübingen, Germany, 1989. Springer-Verlag LNAI 475.

[48] Robin Milner. Calculi for synchrony and asynchrony. TCS: Theoretical Computer Science, 25, 1983.

[49] Robin Milner. Communication and Concurrency. Prentice Hall, New York, 1989.

[50] Robin Milner. Action structures and the π-calculus. In Proceedings of the NATO Summer School on Logic and Computation. Springer-Verlag, 1993.

[51] George C. Necula. Compiling with Proofs. PhD thesis, School of Computer Science, Carnegie Mellon University, September 1998. Available as Technical Report CMU-CS-98-154.

[52] R.P. Nederpelt. Strong Normalization in a Typed Lambda Calculus with Lambda Structured Types. PhD thesis, Eindhoven University of Technology, 1973.

[53] M. H. A. Newman. On theories with a combinatorial definition of equivalence. Annals of Mathematics, 43(2):223–243, 1942.

[54] Tobias Nipkow. Higher-order critical pairs. In G. Kahn, editor, Sixth Annual IEEE Symposium on Logic in Computer Science, pages 342–349, Amsterdam, The Netherlands, July 1991.

[55] Tobias Nipkow. Orthogonal higher-order rewrite systems are confluent. In M. Bezem and J.F. Groote, editors, Proceedings of the International Conference on Typed Lambda Calculi and Applications, pages 306–317, Utrecht, The Netherlands, May 1993.

[56] Tobias Nipkow and Zhenyu Qian. Modular higher-order E-unification. In R. V. Book, editor, Proc. 4th Int. Conf. Rewriting Techniques and Applications, pages 200–214. Springer-Verlag LNCS 488, 1991.

[57] Lawrence C. Paulson. Isabelle: The next 700 theorem provers. In P. Odifreddi, editor, Logic and Computer Science, pages 361–386. Academic Press, 1990.

[58] Gerald E. Peterson and Mark E. Stickel. Complete sets of reductions for some equational theories. Journal of the ACM, 28(2):233–264, April 1981.

[59] Frank Pfenning. Logic programming in the LF logical framework. In Gérard Huet and Gordon Plotkin, editors, Logical Frameworks, pages 149–181. Cambridge University Press, 1991.

[60] Frank Pfenning. Computation and deduction. Unpublished lecture notes, 277 pp. Revised May 1994, April 1996, May 1992.

[61] Frank Pfenning. A structural proof of cut elimination and its representation in a logical framework. Technical Report CMU-CS-94-218, Department of Computer Science, Carnegie Mellon University, November 1994.

[62] Frank Pfenning and Conal Elliott. Higher-order abstract syntax. In Proceedings of the ACM SIGPLAN ’88 Symposium on Language Design and Implementation, pages 199–208, Atlanta, Georgia, June 1988.

[63] Frank Pfenning and Carsten Schürmann. Twelf user’s guide. Technical report, Carnegie Mellon University, School of Computer Science, 1998. Available as Technical Report CMU-CS-98-173, Carnegie Mellon University.

[64] Dag Prawitz. Natural Deduction: a Proof-Theoretical Study. Almquist and Wiskell, 1965.

[65] Christian Prehofer. Higher-order narrowing. In Proceedings of the Ninth Annual IEEE Symposium on Logic in Computer Science, pages 507–516, Paris, France, July 1994. IEEE Computer Society Press.

[66] Christian Prehofer. Solving Higher-Order Equations: From Logic to Programming. PhD thesis, Technische Universität München, March 1995.

[67] Anne Salvesen. The Church-Rosser theorem for LF with βη-reduction. Unpublished notes to a talk given at the First Workshop on Logical Frameworks in Antibes, France, May 1990.

[68] J. van de Pol and H. Schwichtenberg. Strict functionals for termination proofs. In M. Dezani-Ciancaglini and G. Plotkin, editors, Proceedings of the International Conference on Typed Lambda Calculi and Applications, pages 350–364, Edinburgh, Scotland, April 1995. Springer-Verlag LNCS 902.

[69] Maartin H. van Emden and Robert Kowalski. The semantics of predicate logic as a programming language. Journal of the Association for Computing Machinery, 23(4):733–742, 1976.

[70] Vincent van Oostrom and Femke van Raamsdonk. Comparing combinatory reduction systems and higher-order rewrite systems. Technical Report IR-333, Vrije Universiteit Amsterdam, Computer Science, August 1993.

[71] Roberto Virga. Higher-order superposition for dependent types. In Harald Ganzinger, editor, Proceedings of the 7th International Conference on Rewriting Techniques and Applications, pages 123–137, New Brunswick, New Jersey, July 1996. Springer-Verlag LNCS 1103. Extended version available as Technical Report CMU-CS-95-150, May 1995.

[72] Roberto Virga. Twelf(X): Extending Twelf to rationals and beyond. Forthcoming, 1999.

[73] David H. D. Warren. An abstract PROLOG instruction set. Technical Report 309, Artificial Intelligence Center, Computer Science and Technology Division, SRI International, Menlo Park, CA, October 1983.

[74] David A. Wolfram. Rewriting, and equational unification: The higher-order cases. In Ronald V. Book, editor, Proceedings of the Fourth International Conference on Rewriting Techniques and Applications, pages 25–36, Como, Italy, April 1991. Springer-Verlag LNCS 488.