Candidates for Substitution^{∗}

Healfdene Goguen

             hhg@dcs.ed.ac.uk

James McKinna

                                    jhm@dcs.ed.ac.uk

Laboratory for Foundations of Computer Science Department of Computer Science The King’s Buildings, University of Edinburgh, EH9 3JZ, Scotland

1 Introduction

Context morphisms, that is to say parallel substitutions with additional typing and well-formedness information, have emerged as an important tool in the semantics and metatheory of type theories: they are the basis for categorical semantics of type theory, they yield an appealing syntax for explaining proofs under hypotheses in the informal meaning theory for type theory, and most proofs of strong normalization use context morphisms to strengthen the inductive hypothesis.

Kripke term models [CG90, Gog94] are closed under weakening or context extension, and this is used to show the admissibility of parallel substitution. In this paper we explore a uniform proof of thinning and substitution which isolates several simple candidate-style conditions on context morphisms arising from the Kripke construction. The proof exploits the evident similarity of the properties of thinning and substitution, when considered more generally as a property of context morphisms.

We study this result in the context of Pure Type Systems ( PTS ), introduced as a general syntactic characterisation of type theories [Bar92]. PTS gives a framework for showing syntactic results, such as strengthening and subject reduction, for a broad class of systems [vBJ93, Geu93].

The second author gave an informal proof of closure under substitution and thinning for Geuvers’ systems (which extend the rules for PTS with both η -conversion, and strengthening as a rule of inference, complicating their meta-theory a good deal) using context morphisms [Geu93, p. 104]. This observation was made in the course of a long collaboration with Randy Pollack on machine-checking the meta-theory of PTS [MP97]. Indeed, their first proof of thinning for PTS [MP93] used a particular class of context morphisms, the renamings (see Lemma 1.2 below), motivated by the use of context morphisms in normalization proofs.

∗Submitted to Journal of Functional Programming

A distinctive feature of their approach to PTS, first introduced by Pollack, and motivated by considerations of syntax-directed systems [vBJMP94], is the use of an atomic weakening rule. This tightens the meta-theory, by making induction over derivations treat fewer cases. One consequence of this presentation is that it then requires some work to prove full weakening as an admissible rule (as a consequence of thinning).

The proof mentioned in Geuvers’ thesis required full weakening as a rule. The second author gave a strengthening of the hypotheses, given by the candidate closure conditions described below, which allows the proof to go through in the system with atomic weakening.

Postponing the substantive definitions until Section 2, we summarise our results as follows, with proofs in Section 3:

Lemma 1.1 (Closure under a candidate) Suppose S_{Γ}^{Δ} is a candidate for substitution. Then

γ ∈ S_{Γ}^{Δ}, Γ ⊢ M : A ⇒ Δ ⊢ M[γ] : A[γ]

Lemma 1.2 The family of renamings,

P_{Γ}^{Δ} =_{def} {ρ : Dom (Γ)⟶fin V | ρ : Δ ⟶ Γ}

is a candidate for substitution. Moreover, the least such containing the thinnings,

T_{Γ}^{Δ} =_{def} {τ : Dom (Γ)⟶fin V | ∀x∈Dom (Γ).τ(x) = x}.

Lemma 1.3 If the typing judgement is closed under thinnings,

τ ∈ T_{Γ}^{Δ}, Γ ⊢ M : A ⇒ Δ ⊢ M[τ] : A[τ]

then the family of all substitutions (context morphisms),

S_{Γ}^{Δ} =_{def} {γ : Dom (Γ)⟶fin T | γ : Δ ⟶ Γ}

is a candidate for substitution.

Corollary 1.4 The typing judgment is closed under parallel substitution.

Proof. Combine the above three lemmas, appealing twice to the candidate closure lemma.

2 Definitions

We now give the relevant definitions, which motivate the main results of the paper.

2.1 Pure Type Systems

PTS is a class of theories defining a typing judgement for explicitly labelled λ -terms, T , built in the usual way out of variables V and sorts S. The typing judgement is given by a set of derivation rules, presented in table 1, parameterized by two relations:

• axioms, A ⊆ S × S, written (s_{1}:s_{2}) ∈ A

• rules, R ⊆ S × S × S, written (s_{1}, s_{2}, s_{3}) ∈ R.

We write Γ ⊢ A for Γ ⊢ A : s for some s, and Δ ⊢ if Δ ⊢ s_{1} : s_{2} for some s_{1}, s_{2} (equivalently, if Δ ⊢ M : A for some M, A).

Remark 2.1 In this paper we shall treat free and bound variables and associated questions of α -conversion informally. As we shall observe in the proof of Lemma 1.1 below, context morphisms provide a useful mechanism for negotiating the switch between bound and free variables when dealing with binders under substitution.

Two elementary results about atomic subjects M in the typing judgement Γ ⊢ M : A are required:

start lemma Every axiom is derivable in every valid context

(s_{1}:s_{2}) ∈ A, Δ ⊢ ⇒ Δ ⊢ s_{1} : s_{2}

which follows by an easy induction on Δ ⊢ .

occurrence lemma Every free variable in a judgement is bound in the context

Γ ⊢ M : A ⇒ FV (M), FV (A) ⊆ Dom (Γ)

which follows by an easy induction on Γ ⊢ M : A .

Ax  • ⊢ s_{1} : s_{2}  (s_{1}:s_{2}) ∈ A

Start  \begin{matrix}Γ ⊢ A \\ Γ[x:A] ⊢ x : A \end{matrix}  x ∉ Γ

Weak  \begin{matrix}Γ ⊢ α : C  Γ ⊢ A \\ Γ[x:A] ⊢ α : C \end{matrix}  α ∈ P ∪ S , x ∉ Γ

Pi  \begin{matrix}Γ ⊢ A : s_{1} & Γ[x:A] ⊢ B : s_{2} \\ Γ ⊢ Πx:A.B : s_{3} \end{matrix}  (s_{1}, s_{2}, s_{3}) ∈ R

Lda  \begin{matrix}Γ[x:A] ⊢ M : B  Γ ⊢ Πx:A.B \\ Γ ⊢ λx:A.M : Πx:A.B \end{matrix}

App  \begin{matrix}Γ ⊢ M : Πx:A.B & Γ ⊢ N : A \\ Γ ⊢ M N : [N/x]B \end{matrix}

Conv  \begin{matrix}Γ ⊢ M : A  Γ ⊢ B \\ Γ ⊢ M : B \end{matrix}  A ≃_{β} B

Table 1: The Typing Rules of PTS

2.2 Context morphisms and parallel substitutions

The admissible rule of closure under substitution is usually stated for PTS via the notion of substitution for a single free variable. The proof of this, aside from the delicacies of α -conversion to which we have alluded above, requires an induction loading to go through. It is more convenient for our treatment to distinguish a parallel notion of substitution, based on finite mappings. The empty mapping, like the empty context, is denoted by •, and mapping extension by γ[x = M] .

Definition 2.2 Suppose γ : W⟶fin T is a finite mapping with domain W⊆fin V. Then for M ∈ T such that FV (M) ⊆ W, we define the action of the substitution γ on M, written M[γ] , by recursion on M:

• s[γ] =_{def} s;

• x[γ] =_{def} γ(x) ; • ( M N)[γ] =_{def} M[γ] N[γ] ;

• ( ⟨x:M⟩N)[γ] =_{def} ⟨y:M[γ]⟩N[γ[x = y]] ^{1}, where y is chosen fresh with respect to FV (N[γ]) \{x} in the usual way;

Remark 2.3 In the last of the above clauses we have adopted a Currystyle definition of the action on binders, in accordance with our decision to treat variable names informally. Such matters may be treated formally in a more elaborate fashion, following the lines of previous work of Pollack and the second author [MP93, Pol94, MP97]. The definition of the action changes, while the candidate closure conditions do not.

We may now encapsulate the above-mentioned induction loading once and for all, and moreover unify this notion of substitution with the notion of thinning, by introducing the following definition of context morphism, which both enforces validity of the domain context, and inductively ensures well-typedness of the substitution.

Definition 2.4 (Context morphism) A context morphism, usually written γ : Δ ⟶ Γ , is a finite mapping γ : Dom (Γ) ⟶fin T such that:

• • : Δ ⟶ • iff Δ ⊢ , and

• γ[x = M] : Δ ⟶ Γ[x:A] iff – γ : Δ ⟶ Γ , and Δ ⊢ M : A[γ] .

Example 2.5 Suppose Γ ⊢ N : A and Γ[x:A]Δ ⊢ M : B . Then

id_{Γ}[x = N]id_{Δ} : Γ, Δ[N] ⟶ Γ[x:A]Δ

is a context morphism. Closure under this morphism yields the substitution lemma in its usual form.

Example 2.6 Suppose that Γ, Δ are valid contexts, with Γ ⊆ Δ , where inclusion is defined naïvely by set-theoretic inclusion of finite maps (so that we embrace permutation of binders, as well as extensions). Then the thinnings,

T_{Γ}^{Δ} =_{def} {τ : Dom (Γ)⟶fin V | ∀x∈Dom (Γ).τ(x) = x}

define a family of context morphisms.

1We employ the notation ⟨v:A⟩a of [MP97] to allow us to combine the cases of the two binders.

2.3 Candidates for substitution

We now turn to the definition of the crucial abstraction which underlies our proof of closure under substitution.

Definition 2.7 (Candidate for substitution) We say a family S_{Γ}^{Δ} of context morphisms γ : Δ ⟶ Γ is a candidate for substitution if and only if the following axioms S_{0} – S_{2} hold:

S_{0} if γ[x = M] ∈ S_{Γ[x:A]}^{Δ} , then γ ∈ S_{Γ}^{Δ} ;

S_{1} if γ ∈ S_{Γ}^{Δ} , y ∉ Dom (Δ) and Δ ⊢ B, then γ ∈ S_{Γ}^{Δ[y:B]} ; S_{2} if γ ∈ S_{Γ}^{Δ} , x ∉ Dom (Γ) and Δ ⊢ y : A[γ] , then

γ[x = y] ∈ S_{Γ[x:A]}^{Δ} .

The motivation for candidate axiom S_{0} is as a hygiene condition, whose proof in any given example will usually be immediate from the second clause in the definition of context morphism.

The motivation for candidate axioms S_{1} and S_{2} is a simple form of closure condition, namely that the candidate is closed under particularly simple extensions of the domain and range of a context morphism. The candidate axiom S_{1} arises as the familiar monotonicity condition in Kripke models. It would be trivial to validate if the typing judgement were to admit full weakening, by induction on the proof that γ is a context morphism.

Example 2.8 The thinnings fail to satisfy candidate axiom S_{2} , and so do not form a candidate for substitution. The thinning lemma would follow if we could show closure under the thinnings, but this will follow from Lemmas 1.1 and 1.2.

Remark 2.9 We may capture the combined effect of S_{1} and S_{2} in the following axiom:

S_{ext} if γ ∈ S_{Γ}^{Δ} , x ∉ Dom (Γ) , y ∉ Dom (Δ) and Δ ⊢ A[γ](†) , then γ[x = y] ∈ S_{Γ[x:A]}^{Δ[y:A[γ]]}

We may show that S_{0} + S_{ext} ⇒ S_{1} + S_{2} (with two uses of the welltypedness premise (†) ), and that S_{1} + S_{2} ⇒ S_{ext} , by appealing to atomic weakening. We shall see in the proof of Lemma 1.1 that it is perhaps more convenient to take the S_{0} + S_{ext} axiomatisation.

Remark 2.10 We have chosen a presentation which uses a named syntax for λ -terms, so the reader more familiar with a deBruijn representation may well wonder what all the fuss is about. After all, although the use of deBruijn terms would force us to incorporate explicit uses of the lift operator in all our definitions, this ostensibly achieves a harmony between the definition of the action γ[M] and the Lda rule. But we pay the price that the representation imposes an ordering on the bindings. This is essentially the temporal order on binding creation (instances of the Start rule) time. This not only makes the corresponding definition of the family T_{Γ}^{Δ} much more complicated (it cannot be given simply in terms of iterated composition of liftings, and makes testing the condition Γ ⊆ Δ a non-trivial computation), but it also obscures the rôle of candidate axiom S_{2} . This is where permutation may take place, since the premise Δ ⊢ y : A[γ] does not specify the creation time of y (nor even that it is well-typed by a sequence of instances of the Start and Wk rules: the Conv rule allows us to exploit possibly non-trivial computation in arriving at the type A[γ] for y).

3 Proofs of the main results

Proof of Lemma 1.1. The proof is by induction on Γ ⊢ M : A . The interesting cases are those of the Start and Lda (Pi is similar) rules. The App and Conv cases require elementary commutation of our parallel substitution notion with simple substitution and conversion respectively, and are not treated here.

Case Start: by assumption, we have γ ∈ S_{Γ[x:A]}^{Δ} , that is to say γ = δ[x = M] where Δ ⊢ M : A[δ] and δ ∈ S_{Γ}^{Δ} , by candidate axiom S_{0} . We are required to show that Δ ⊢ x[γ] : A[γ] , and this follows immediately, since x[γ] = M and A[γ] = A[δ] , because FV (A) ⊆ Dom (Γ) = Dom (δ) , by the occurrence lemma.

Case Lda: by assumption, we have γ ∈ S_{Γ}^{Δ} , and by induction hypothesis, we have ∀γ, Δ. γ ∈ S_{Γ}^{Δ} ⇒ Δ ⊢ ( Πx:A.B)[γ] : s[γ] and ∀δ, Ξ. δ ∈ S_{Γ[x:A]}^{Ξ} ⇒ Ξ ⊢ M[δ] : B[δ] . We are required to show that Δ ⊢ ( λx:A.M)[γ] : ( Πx:A.B)[γ] . By the Lda rule, it suffices to show, for y ∉ Dom (Δ) , that Δ[y:A[γ]] ⊢ M[γ[x = y]] : B[γ[x = y]] . Accordingly, we take δ =_{def} γ[x = y] , and Ξ =_{def} Δ[y:A[γ]] , and appeal to the second induction hypothesis. It is at this point alone (and at the corresponding point in the Pi case), that we make appeal to candidate axiom S_{ext} , in order to ensure that δ ∈ S_{Γ[x:A]}^{Ξ} . It remains to show the well-typedness premise (†) of candidate axiom S_{ext} , namely Δ ⊢ A[γ] .

But this follows by inversion, since by the first induction hypothesis, we may show that Δ ⊢ ( Πx:A.B)[γ] : s[γ] .

Proof of Lemma 1.2. The verification of candidate axioms S_{0} and S_{2} is immediate from the definitions of context morphism and the family P_{Γ}^{Δ} , while candidate axiom S_{1} requires a little work, namely induction on the proof that ρ ∈ P_{Γ}^{Δ} , together with an appeal to atomic weakening in both the base and step cases. The inclusion, and the fact that it is strict, and minimal, is again immediate.

Proof of Lemma 1.3. Immediate from previous considerations: the thinnings yield the instances of full weakening required to validate candidate axiom S_{1} .

4 Conclusions

We have given a simple and uniform proof of two meta-theoretic properties of PTS , thinning and substitution. We began by noticing that the notion of context morphism can be used to express the two properties. We identified several candidate-style conditions on sets of context morphisms, and showed that the judgements of PTS are closed under sets which satisfy these conditions. Finally, we showed that these conditions are satisfied by the class of renamings, and that the class of all context morphisms also satisfies them, knowing that the judgements of PTS are closed under renamings.

We analysed an originally blocked proof, that the judgements are closed under thinnings, and can now observe the rôle of renamings in proofs of this kind: the renamings are exactly the least set of context morphisms containing the thinnings, and closed under the candidate conditions.

Acknowledgements Our work has throughout been influenced by the ideas of Thierry Coquand. We are also grateful to our other colleagues in the EU Esprit Working Group “TYPES”, especially Randy Pollack, Zhaohui Luo, and Herman Geuvers.

References

[Bar92] Henk Barendregt. Lambda calculi with types. In Abramsky, Gabbai, and Maibaum, editors, Handbook of Logic in Computer Science, volume II. Oxford University Press, 1992.

[CG90] Thierry Coquand and Jean Gallier. A proof of strong normalization for the theory of constructions using a Kripke-like interpretation. In Workshop on Logical Frameworks–Preliminary Proceedings, 1990.

[Geu93] Herman Geuvers. Logics and Type Systems. PhD thesis, Department of Mathematics and Computer Science, University of Nijmegen, 1993.

[Gog94] Healfdene Goguen. A Typed Operational Semantics for Type Theory. PhD thesis, University of Edinburgh, August 1994.

[MP93] James McKinna and Robert Pollack. Pure Type Systems formalized. In M.Bezem and J.F.Groote, editors, Proceedings of the International Conference on Typed Lambda Calculi and Applications, TLCA’93, Utrecht, number 664 in LNCS, pages 289–305. Springer-Verlag, March 1993.

[MP97]  James McKinna and Robert Pollack.  Some λ -calculus

and type theory formalized. Journal of Automated Reasoning, 1997. Submitted for publication in the special issue on formal proof. Available by anonymous ftp from

ftp://ftp.dcs.ed.ac.uk/pub/lego/McKinnaPollack97.ps.gz.

[Pol94]  Robert Pollack.  The Theory of LEGO: A Proof

Checker for the Extended Calculus of Constructions. PhD thesis, University of Edinburgh, 1994.

ftp://ftp.dcs.ed.ac.uk/pub/lego/thesis-pollack.ps.Z.

[vBJ93] L.S. van Benthem Jutting. Typing in Pure Type Systems. Information and Computation, 105(1):30–41, July 1993.

[vBJMP94] L.S. van Benthem Jutting, James McKinna, and Robert Pollack. Checking algorithms for Pure Type Systems. In Henk Barendregt and Tobias Nipkow, editors, Types for Proofs and Programs: International Workshop TYPES’93, Nijmegen, May 1993, Selected Papers, volume 806 of LNCS, pages 19–61. Springer-Verlag, 1994.