Syntactical Strong Normalization for Intersection Types with Term Rewriting Rules

Andreas Abel^{∗} Institut für Informatik Ludwig-Maximilians-Universität München

4 June 2007

Abstract We investigate the intersection type system of Coquand and Spiwack with rewrite rules and natural numbers and give an elementary proof of strong normalization which can be formalized in a weak metatheory.

1 Introduction

For typed λ-calculi which are used as languages for theorem provers, such as Agda, Coq, LEGO or Isabelle, normalization is a crucial property; the consistency of these provers depend on it. Usually, normalization is proven by a model construction, but recently, syntactical normalization proofs have received some interest [Val01, Dav01, JM03]. One advantage of syntactical proofs is that they explain better why a calculus is normalizing; in such proofs one can see what actually decreases in each reduction step. Another advantage is that they can be formalized in weak logical theories. For instance, a syntactic normalization proof [Abe04] of the simply-typed λ-calculus (STL) can be carried out in Twelf, a logical framework supporting higher-order abstract syntax, whose proof-theoretic strength is probably ω^{ω^{ω}}, well below primitive recursive arithmetic. The insight that normalization of very weak languages, like the STL, can be proven using just lexicographic structural induction over Σ_{1}-sentences, has recently lead to a full formalization of an intermediate language for SML in Twelf [LCH07].

In this work, we consider a λ-calculus with simple and intersection types and term rewriting and show strong normalization by structural means, that is, no model construction, instead finitary inductive definitions and lexicographic induction. For intersection types without term rewriting, similar normalization proofs exist [Val01, Mat00]. The present system originates from work of Coquand and Spiwack [CS06]; there it serves as the basis of a filter λ model which ultimately shows normalization of a dependently-typed logical framework with bar recursion. The filter λ model “translates” a term of the logical framework into sets of finite types the term can receive in the intersection type system. If all intersection-typable terms are strongly normalizing, then so are all terms of the logical framework whose denotation is not the empty set of types in the filter λ-model. Coquand and Spiwack prove normalization for the intersection type system using reducibility candidates; however, there should be a proof with weaker means. As Berger [Ber05] explained to me, the filter λ model which links the (strong) logical framework with the (presumably weak) intersection type systems uses proof-theoretically heavy tools, hence, the link between the intersection type system and strong normalization should be a lightweight one. This works tries to substantiate Berger’s intuition.

∗Research partially supported by the EU coordination action TYPES (510996).

2 Intersection Type System for Term Rewriting

As language, we consider the λ-calculus with constructors and functions defined by rewriting. For simplicity, we consider only the nullary constructor 0 and the unary constructor $ (successor) for natural numbers and functions f with rewrite rules of the shape

f(0) ⟶ \underline{z}  \underline{z} closed
f($x) ⟶ \underline{s}  FV(\underline{s}) ⊆ \{x\}.

The right hand sides \underline{z} and \underline{s} may mention f and other defined functions, thus, recursion is a priori unrestricted. Although we only consider natural numbers in the following, the techniques extend to all first-order data types, such as lists or finitely branching trees. Higher-order data types, such as infinitely branching trees and tree ordinals pose yet some technical problem. Thus, we do not cover the full language of Coquand and Spiwack. Note however that first-order datatypes (natural numbers and lists) are sufficient to treat the main application of the Coquand and Spiwack’s filter λ model, strong normalization of bar recursion.

The intersection type system does not know a type Nat of all natural numbers, however, it has one singleton type for each a natural number. We use the same constructors 0 and $ for these singleton types. The type E is the least type in the subtyping relation, it is inhabited by terms blocking reduction, such as f(λxt).

Types. Let I, J, K denote non-empty finite index sets and let i, j, k range over indices.

a, b, c ::= E | 0 | $a  ground types
A, B, C ::= a | ⋂_{i∈I}(A_{i} → B_{i}) types

The type A → B is a special case of the last alternative. A function type is a partial description of the graph of the function, for instance, the identity λxx could receive the type (0 → 0) ∩ ($0 → $0) ∩ ($$0 → $$0), or more generally the type ⋂_{i∈I}($^{i}0 → $^{i}0) for any finite set I of natural numbers.

A binary intersection A ∩ B is an associative commutative idempotent operation definable by induction on A and B.

\begin{aligned}E ∩ A & = & E \\ 0 ∩ $a & = & E \\ 0 ∩ ⋂_{i∈I}(A_{i} → B_{i}) & = & E \\ $a ∩ ⋂_{i∈I}(A_{i} → B_{i}) & = & E \end{aligned}  \begin{aligned}0 ∩ 0 & = & 0 \\ $a ∩ $a′ & = & $(a ∩ a′) \\ (A → B) ∩ (A → B′) & = & A → (B ∩ B′) \\ (⋂_{i∈I}(A_{i} → B_{i})) \\ ∩ (⋂_{i∈J}(A_{i} → B_{i})) & = & ⋂_{i∈I∪J}(A_{i} → B_{i}) \end{aligned}

In the last clause, we assume all A_{i} for i ∈ I ⊎ J different. This invariant can be ensured using the but-last clause.

A measure on types |A| is defined by |a| = 0 and | ⋂_{i∈I}(A_{i} → B_{i})| = max{|A_{i}| + 1, |B_{i}| | i ∈ I}.

Subtyping A ⊆ B is inductively given by the following rules [CS06].

\overline{E ⊆ A}  \overline{0 ⊆ 0}  \frac{a ⊆ b}{$a ⊆ $b}

\frac{A ⊆ B_{i} → C_{i} for all i ∈ I}{A ⊆ ⋂_{i∈I}(B_{i} → C_{i})} \frac{(⋂_{i∈J} B_{i}) ⊆ B}{⋂_{i∈I}(A_{i} → B_{i}) ⊆ A → B} J = \{i | A ⊆ A_{i}\} ≠ ∅

This definition of subtyping is syntax-directed, however, it coincides with the usual axiomatic presentation: reflexivity, transitivity, and the usual rules for binary intersection, A_{1} ∩ A_{2} ⊆ A_{i} and A ⊆ A_{1} & A ⊆ A_{2} ⟹ A ⊆ A_{1} ∩ A_{2}, are admissible; and the contravariant subtyping rule for function spaces is an instance of the last rule with I = J = {1}.

Typing The rules for the typing judgement Γ ⊢ t : A are taken from Coquand and Spiwack [CS06] and restricted to our set of constructors and function symbols. The first five rules are just intersection typing, the other five rules deal with constructors and functions.

\overline{Γ ⊢ x : Γ(x)}  \frac{Γ, x:A ⊢ t : B}{Γ ⊢ λxt : A → B}  \frac{Γ ⊢ r : A → B  Γ ⊢ s : A}{Γ ⊢ r s : B}

\frac{Γ ⊢ r : A  Γ ⊢ r : B}{Γ ⊢ r : A ∩ B}  \frac{Γ ⊢ r : A  A ⊆ B}{Γ ⊢ r : B}

\overline{Γ ⊢ 0 : 0}  \frac{Γ ⊢ r : a}{Γ ⊢ $r : $a}  \frac{Γ ⊢ r : A}{Γ ⊢ f(r) : E} A ≠ 0, $a

\frac{Γ ⊢ r : 0  Γ ⊢ \underline{z} : C}{Γ ⊢ f(r) : C} f(0) ⟶ \underline{z}  \frac{Γ ⊢ r : $a  Γ, x:a ⊢ \underline{s} : C}{Γ ⊢ f(r) : C} f($x) ⟶ \underline{s}

Observe that a recursive function f is typed “through its evaluation”. For instance, if f(0) ⟶ 0 and f($x) ⟶ $(f(x)), then f is the recursive identity, and to derive y : $^{n}0 ⊢ f(y) : $^{n}0 we must derive y : $^{m}0 ⊢ f(y) : $^{m}0 for all m < n first. Hence, the whole computation tree of a recursive function application is already present in its typing. Therefore, a proof of strong normalization should be easy, in principle not harder as for the STL. In the following we substantiate this claim; although technically a bit involved, the proof has low proof-theoretic complexity.

3 Strong Normalization

In this section, we extend the normalization proof of Joachimski and Matthes [JM03] to the intersection type system of the last section. To this end, we introduce a judgement Γ ⊢ t ⇑ C stating that Γ ⊢ t : C and t is strongly normalizing. That this judgement is closed under substitution and application will be the main technical lemma; remember that closure under application is the difficult part in strong normalization proofs and usually requires a Taitstyle logical relation argument. The basic idea behind the judgement is that typed weakly normalizing terms are closed under substitution: substituting the normal form v of a term of type A = A_{1} → ⋯ → A_{m} → B for x into the normal form w of another term can generate redexes if v contains subterms of the form x v_{1}^{A_{1}} … v_{n}^{A_{n}}. Considering such a new β-redex (λx′w′) v_{i}^{A_{i}}, we observe that its degree A_{i} is smaller than A. Thus, the new substitution of v_{i} into w′, which is necessary to reduce the redex, occurs with a smaller type; it might again create new redexes, however, with an even smaller type, so the whole process will eventually terminate. Watkins et. al. [WCPW03] coined the name hereditary substitutions for this process. Yet this normalization argument for the STL is quite old, Lévy [Lév76] attributes it to D. van Dalen.

SN: Atomic terms.

\overline{Γ ⊢ x ↓ Γ(x)} \frac{Γ ⊢ r ↓ ⋂_{i∈I}(A_{i} → B_{i}) Γ ⊢ s ⇑ A_{j} for all j ∈ J}{Γ ⊢ r s ↓ ⋂_{j∈J} B_{j}} J ⊆ I

SN: Neutral terms.

\frac{Γ ⊢ r ↓ A  A ⊆ B}{Γ ⊢ r ⇓ B}  \frac{Γ ⊢ r ⇓ 0  Γ ⊢ \underline{z} s⃗ ⇑ C}{Γ ⊢ f(r) s⃗ ⇓ C} f(0) ⟶ \underline{z}

\frac{Γ ⊢ r ⇓ $a  Γ, x:a ⊢ \underline{s} s⃗ ⇑ C}{Γ ⊢ f(r) s⃗ ⇓ C} \begin{matrix}f($x) ⟶ \underline{s} \\ x ∉ FV(s⃗) \end{matrix}

SN: Values, blocked terms, and weak head expansions.

\frac{Γ ⊢ r ⇓ A A ⊆ B}{Γ ⊢ r ⇑ B} \frac{Γ, x:A_{i} ⊢ t ⇑ B_{i} for all i ∈ I}{Γ ⊢ λxt ⇑ ⋂_{i∈I}(A_{i} → B_{i})} \overline{Γ ⊢ 0 ⇑ 0} \frac{Γ ⊢ r ⇑ a}{Γ ⊢ $r ⇑ $a}

\frac{Γ ⊢ r ⇑ A}{Γ ⊢ f(r) ⇑ E} A ≠ 0, $a  \frac{Γ ⊢ r ⇑ E  Γ ⊢ s ⇑ A}{Γ ⊢ r s ⇑ E}

\frac{Γ ⊢ s ⇑ A  Γ ⊢ E[[s/x]t] ⇑ C}{Γ ⊢ E[(λxt) s] ⇑ C}  \frac{Γ ⊢ E[\underline{z}] ⇑ C}{Γ ⊢ E[f(0)] ⇑ C} f(0) ⟶ \underline{z}

\frac{Γ ⊢ r ⇑ A Γ ⊢ E[[r/x]\underline{s}] ⇑ C}{Γ ⊢ E[f($r)] ⇑ C} f($x) ⟶ \underline{s}

Figure 1: Inductive characterization of SN.

The crucial property of STL which makes hereditary substitutions work is that in an atomic term x s_{1} … s_{n}, the types of all s_{i} are smaller than the type of x. In the presence of term rewriting, we can have terms like f(x) s with a variable in the head, but now the type of s is no longer guaranteed to be smaller than the type of x. Let us call such terms neutral; they are of shape E[x] where E[] is an evaluation context given by the grammar

E[] ::= [] | E[] s | f(E[]).

The termination argument of hereditary substitutions does no longer apply. However, we can salvage our substitution lemma by the following observation: For neutral terms of the shape t = E[f(y s⃗)], substitution for y might simplify the atomic part y s⃗ to 0 or $r. In the first case t is s.n. if E[\underline{z}] is, and in the second case, if E[[r/x]\underline{s}] is.

Taking these thoughts into account we simultaneously define the three judgements (see Fig. 1):

Γ ⊢ t ↓ A t is s.n. and atomic of type A
Γ ⊢ t ⇓ A t is s.n. and neutral of type A
Γ ⊢ t ⇑ A t is s.n. of type A

Lemma 1 (Weakening) Let Γ′ ⊆ Γ.

1. If D :: Γ ⊢ t ↓ B then Γ′ ⊢ t ↓ A for some A ⊆ B.

2. If D :: Γ ⊢ t ⇓ B then Γ′ ⊢ t ⇓ B.

3. If D :: Γ ⊢ t ⇑ B and B ⊆ C then Γ′ ⊢ t ⇑ C.

Proof. Simultaneously by induction on D. □

The three judgements are closed under intersection: For R ∈ {↓, ⇓, ⇑}, Γ ⊢ t R A and Γ ⊢ t R B imply Γ ⊢ t R A ∩ B, which can be proven simultaneously for all three R by induction.

Now we come to the crucial substitution lemma. Substitution for x in a derivation of

\frac{Γ, x:A ⊢ r ⇓ $b Γ, x:A, y:b ⊢ \underline{s} t⃗ ⇑ C}{Γ, x:A ⊢ f(r) t⃗ ⇓ C} f($y) ⟶ \underline{s}

might trigger a substitution for y which in turn might trigger new substitutions. To establish termination of this process we require y to be of base type b. This is the reason why we disallow higher-order datatypes, which can have elements of higher types as arguments to their constructors. We generalize the substitution lemma of Joachimski and Matthes [JM03] to simultaneous substitution, but only one substituted variable may be of higher type.

Lemma 2 (Substitution and application) Let Γ ⊢ s ⇑ A and Γ ⊢ s_{i} ⇑ a_{i} for i ∈ I. Let r′ = [s/x][s⃗/x⃗]r. Let R ∈ {⇓, ⇑}.

1. If D :: Γ, x: A, x⃗: a⃗ ⊢ r ↓ C then either Γ ⊢ r′ ↓ C, or Γ ⊢ r′ ⇑ C and |C| ≤ |A|.

2. If D :: Γ, x:A, x⃗:a⃗ ⊢ r R C then Γ ⊢ r′ ⇑ C.

3. If D :: Γ ⊢ r R ⋂_{i∈I}(A_{i} → C_{i}) and A = A_{j} then Γ ⊢ r s R C_{j}.

Proof. By lexicographic induction on (|A|, D). For Prop. 1 consider the cases:

Case Γ, x:A, x⃗:a⃗ ⊢ x ↓ A. Then r′ = s and Γ ⊢ r′ ⇑ A with |A| ≤ |A|.

Case Γ, x:A, x⃗:a⃗ ⊢ x_{i} ↓ a_{i}. Then r′ = s_{i} and Γ ⊢ r′ ⇑ a_{i}, and |a_{i}| = 0 ≤ |A|.

Case Γ, x:A, x⃗:a⃗ ⊢ y ↓ B for y ∉ {x, x⃗}. Then r′ = y and Γ ⊢ r′ ↓ B.

Case J ⊆ I and

\frac{Γ, x:A, x⃗:a⃗ ⊢ t ↓ ⋂_{i∈I}(A_{i} → B_{i}) Γ, x:A, x⃗:a⃗ ⊢ u ⇑ A_{i} for all i ∈ J}{Γ, x:A, x⃗:a⃗ ⊢ t u ↓ ⋂_{i∈J} B_{i}}

Let t′ = [s/x][s⃗/x⃗]t and u′ = [s/x][s⃗/x⃗]u. By second induction hypothesis, Γ ⊢ u′ ⇑ A_{i} for all i ∈ J. We distinguish cases on the first induction hypothesis:

Subcase Γ ⊢ t′ ↓ ⋂_{i∈I}(A_{i} → B_{i}). Then Γ ⊢ t′ u′ ↓ ⋂_{i∈J} B_{i}.

Subcase Γ ⊢ t′ ⇑ ⋂_{i∈I}(A_{i} → B_{i}) and | ⋂_{i∈I}(A_{i} → B_{i})| ≤ |A|. Then for each i ∈ J, we have |A_{j}| < |A| and, thus, can apply induction hypothesis 3 to obtain Γ ⊢ t′ u′ ⇑ B_{i} and |B_{i}| ≤ |A|. Thus, | ⋂_{i∈J} B_{i}| ≤ |A|, and by closure unter intersection, Γ ⊢ t′ u′ ⇑ ⋂_{i∈J} B_{i}.

The principal case of Proposition 2 is:

Case f($y) ⟶ \underline{s}, y ∉ FV(t⃗) and

\frac{Γ, x:A, x⃗:a⃗ ⊢ r ⇓ $b Γ, x:A, x⃗:a⃗, y:b ⊢ \underline{s} t⃗ ⇑ C}{Γ, x:A, x⃗:a⃗ ⊢ f(r) t⃗ ⇓ C}

By induction hypothesis, D′ :: Γ ⊢ r′ ⇑ $b. Let t′_{j} = [s/x][s⃗/x⃗]t_{j} for all j. We show Γ ⊢ f(r′) t⃗′ ⇑ C by a local induction on D′.

Subcase r′ = $r′′ and Γ ⊢ r′′ ⇑ b. Then by main induction hypothesis Γ ⊢ ([r′′/y]\underline{s}) t⃗′ ⇑ C which implies Γ ⊢ f($r′′) t⃗′ ⇑ C.

Subcase r′ = E[(λzt)u] and

\frac{Γ ⊢ u ⇑ A′ Γ ⊢ E[[u/z]t] ⇑ $b}{Γ ⊢ E[(λzt) u] ⇑ $b}

Let E′[] = f(E[]) t⃗′. By local induction hypothesis, Γ ⊢ E′[[u/z]t] ⇑ C, hence, Γ ⊢ E′[(λzt) u] ⇑ C. The other cases of weak head expansions are treated analogously.

Subcase

\frac{Γ ⊢ r′ ⇓ $b′ b′ ⊆ b}{Γ ⊢ r′ ⇑ $b}

By main induction hypothesis, Γ, y: b ⊢ \underline{s} t⃗′ ⇑ C. By the weakening lemma, Γ, y:b′ ⊢ \underline{s} t⃗′ ⇑ C, which entails Γ ⊢ f(r′) t⃗′ ⇓ C.

Subcase

\frac{Γ ⊢ r′ ⇓ E E ⊆ $b}{Γ ⊢ r′ ⇑ $b}

Then Γ ⊢ f(r′) ⇑ E, which implies Γ ⊢ f(r′) t⃗′ ⇑ E by iterated application. We conclude Γ ⊢ f(r′) t⃗′ ⇑ C by weakening.

The principal case for Proposition 3 is:

Case

\frac{Γ, x:A_{i} ⊢ t ⇑ C_{i} for all i ∈ I}{Γ ⊢ λxt ⇑ ⋂_{i∈I}(A_{i} → C_{i})}

By Prop. 2, Γ ⊢ [s/x]t ⇑ C_{j}. By weak head expansion, Γ ⊢ (λxt) s ⇑ C_{j}.

□

Lemma 3 (Recursion)

1. If D :: Γ ⊢ r ⇑ 0 and Γ ⊢ \underline{z} ⇑ C then Γ ⊢ f(r) ⇑ C.

2. If D :: Γ ⊢ r ⇑ $a and Γ, x:a ⊢ \underline{s} ⇑ C then Γ ⊢ f(r) ⇑ C.

Proof. Each by induction on D. This essentially repeats proofs carried out for Proposition 2 in the previous lemma. □

Now we have shown that the judgement ⇑ is closed under all eliminations (intersection elim., application, recursion), hence, each well-typed term is in ⇑:

Theorem 4 If Γ ⊢ t : C then Γ ⊢ t ⇑ C.

Proof. By induction on Γ ⊢ t : C. □

It remains to show that if Γ ⊢ t ⇑ C then t is indeed strongly normalizing. Consider the following rule:

\frac{Γ ⊢ r ⇑ A}{Γ ⊢ f(r) ⇑ E} A ≠ 0, $a.

To show strong normalization of f(r) from s.n. of r we additionally need to know that r will never reduce to 0 or $r′ for some r′.

Theorem 5 Let R ∈ {↓, ⇓, ⇑} and Γ ⊢ t R C. Then t is strongly normalizing. If R ≠ ⇑, then t is neutral. Otherwise,

1. if C ≠ 0, then t −̸→^{∗} 0,

2. if C ≠ $c, then t −̸→^{∗} $t′ for any t′, and

3. if C ≠ ⋂_{i∈I}(A_{i} → B_{i}), then t −̸→^{∗} λxt′ for any t′.

Proof. By induction on Γ ⊢ t R C. For each rule we do a local Noetherian induction on the strong normalization of the terms in the premises. □

4 Conclusion

We have proven strong normalization for a λ-calculus with intersection types and term rewriting without the use of reducibility candidates or Tait-style saturated sets. The proof is technically involved, but can be formalized in a weak metatheory. Formalization in Twelf is not directly possible, not because Twelf’s induction principles are not strong enough, but because we use constructs like ⋂_{i∈I}(A_{i} → B_{i}) or simultaneous substitutions, which are not representable in Twelf, at least not directly.

We have partially answered our conjecture in the affirmative, that the intersection type system of Coquand and Spiwack [CS06] can be proven normalizing with simple means. What remains is an extension to higher-order datatypes. Also, our proof relies substantially on a deterministic weak head reduction relation, it is therefore not clear how we could handle overlapping patterns, an extension Coquand and Spiwack discuss in the conclusion of their article. Neither they nor we handle non-computational rewrite rules like (x+y)+z ⟶ x+(y+z).

Riba [Rib07] considers a similar system, without datatypes yet with rewrite rules, and with union types. He shows that the elimination rule for union types can lead to diverging terms in some cases, and isolates conditions when these cases cannot occur. It would be interesting to see whether our proof could be extended to union types, and where Riba’s conditions materialize in the proof.

Thanks to Thierry Coquand for interesting discussions.

References

[Abe04] Andreas Abel. Weak normalization for the simply-typed lambdacalculus in Twelf. In LFM’04, 2004.

[Ber05] Ulrich Berger. Continuous semantics for strong normalization. In CiE’05, volume 3526 of LNCS, pages 23–34. Springer, 2005.

[CS06] Thierry Coquand and Arnaud Spiwack. A proof of strong normalisation using domain theory. In LICS’06, pages 307–316. IEEE CS Press, 2006.

[Dav01] René David. Normalization without reducibility. APAL, 107(1– 3):121–130, 2001.

[JM03] Felix Joachimski and Ralph Matthes. Short proofs of normalization. AML, 42(1):59–87, 2003.

[LCH07] Daniel K. Lee, Karl Crary, and Robert Harper. Towards a mechanized metatheory of Standard ML. In POPL’07, pages 173–184. ACM, 2007.

[Lév76] Jean-Jacques Lévy. An algebraic interpretation of the λβKcalculus; and an application of a labelled λ-calculus. TCS, 2(1):97– 114, 1976.

[Mat00] Ralph Matthes. Characterizing strongly normalizing terms of a calculus with generalized applications via intersection types. In ITRS’00, pages 339–354. Carleton Scientific, 2000.

[Rib07] Colin Riba. Strong normalization as safe interaction. In Logics in Computer Science, LICS’07, 2007. To appear.

[Val01] Silvio Valentini. An elementary proof of strong normalization for intersection types. AML, 40(7):475–488, October 2001.

[WCPW03] Kevin Watkins, Iliano Cervesato, Frank Pfenning, and David Walker. A concurrent logical framework I: Judgements and properties. Technical report, School of Computer Science, Carnegie Mellon University, Pittsburgh, 2003.