Transitivity of Subtyping for Intersection Types

06/24/2019 ∙ by Jeremy G. Siek, et al. ∙ 0

The subtyping relation for intersection type systems traditionally employs a transitivity rule (Barendregt et al. 1983), which means that the subtyping judgment does not enjoy the subformula property. Laurent develops a sequent-style subtyping judgment, without transitivity, and proves transitivity via a sequence of six lemmas that culminate in cut-elimination (2018). This article presents a subtyping judgment, in regular style, that satisfies the subformula property, and presents a direct proof of transitivity. Borrowing from Laurent's system, the rule for function types is essentially the β-soundness property. The main lemma required for the transitivity proof is one that has been used to prove the inversion principle for subtyping of function types. The choice of induction principle for the proof of transitivity is subtle: we use well-founded induction on the lexicographical ordering of the sum of the depths of the first and last type followed by the sum of the sizes of the middle and last type. The article concludes with a proof that the new subtyping judgment is equivalent to that of Barendregt, Coppo, and Dezani-Ciancaglini.

READ FULL TEXT VIEW PDF
POST COMMENT

Comments

There are no comments yet.

Authors

page 1

page 2

page 3

page 4

This week in AI

Get the week's most popular data science and artificial intelligence research sent straight to your inbox every Saturday.

1 Introduction

Intersection types were invented by Coppo, Dezani-Ciancaglini, and Salle, as a tool for studying normalization in the lambda calculus (Coppo:1979aa). By varying the subtyping rules and atom types, researchers use intersection type systems to model many different calculi (Coppo:1980ab; Coppo:1981aa; Engeler:1981aa; Coppo:1984aa; Honsell:1992aa; Abramsky:1993fk; Plotkin:1993ab; Honsell:1999aa; Ishihara:2002aa; Rocca:2004aa; Dezani-Ciancaglini:2005aa; Alessi:2006aa). Perhaps the best-known of them is the BCD intersection type system of Barendregt:1983aa. For this article we focus on the BCD system, following the presentation of Barendregt:2013aa. We conjecture that our results apply to other intersection type systems as well.

The BCD intersection type systems extends the simply-typed lambda calculus with the addition of intersection types, written , a top type , and an infinite collection of type constants. Figure 1 defines the grammar of types.

Figure 1: Intersection Types

The BCD intersection type system includes a subsumption rule which states that a term in environment can be given type if it has type and is a subtype of , written .

Figure LABEL:fig:BCD-subtyping reviews the BCD rules for subtyping. Note that in the (trans) rule, the type that appears in the premises does not appear in the conclusion. Thus, the BCD subtyping judgment does not enjoy the subformula property. For other systems, it is straightforward to remove the (trans) rule, modify the other rules, and then then prove transitivity (Muehlboeck:2018aa). Unfortunately, the rule of the BCD system significantly complicates the situation.

The subformula property is a useful one. For example, the author is using intersection types to create a denotational semantics for the ISWIM language, which includes constants and primitive operations (Landin:1966la; G.-D.-Plotkin:1975on; Felleisen:2009aa). It seems that doing so requires placing extra conditions on types and it is much easier to do so when subtyping satisfies the subformula property.

Laurent:2018aa introduces the ISC sequent-style system, written , where is a sequence of types . The intuition is that corresponds to . The ISC system satisfies the subformula property and is equivalent to the BCD system. To prove this, Laurent establishes six lemmas that culminate in cut-elimination, from which transitivity follows.

This article presents a more direct route to the subformula property and transitivity. We present a subtyping relation and directly prove transitivity without using an auxiliary sequent-style system. Nevertheless, the intuitions are based on those of Laurent. The key to is a rule for function types based on the -soundness property (Barendregt:2013aa), just as in ISC. The definitions and results in this article have been machine checked in Agda.

We describe the new subtyping relation in Section 2, prove transitivity in Section 3, and prove its equivalence to BCD subtyping in Section 4. We make some concluding remarks in Section LABEL:sec:conclude.

2 A New Subtyping Judgment

Our new subtyping judgment relies on several auxiliary notions that help us avoid the use of ellipses, which we define in Figure 2. These include the and functions, the and predicates, and the relations and . The and functions return the domain or codomain if is a function type, respectively. If is an intersection , then is the intersection of the domain of and . If is an atom, is undefined. Likewise for . For example, if , then and . When or appears in lemma or theorem statement, we implicitly assume that is a type such that and are defined. The predicate identifies types that are equivalent to . The predicate identifies types that have in their codomain. The relation indicates whether is syntactically a part of . The relation holds when every part of is a part of . We say that contains if .

Proposition 1.

If , then and .

toptop

Figure 3: Auxiliary Definitions

Figure 4: The New Subtyping Judgment

The new intersection subtyping judgment, , is defined in Figure 2. First, it does not include the (trans) rule. It also replaces the (refl) rule with reflexivity for atoms (refl). The most important rule is the one for function types , which subsumes and in BCD subtyping. The rule essentially turns the -soundness property into a subtyping rule. The rule says that a type is a subtype of a function type if a subset of , call it , has domain and codomain that are larger and smaller than and , respectively. The use of a subset of enables this rule to absorb uses of (incl) and (incl) on the left. The side conditions and are needed because of the rule, which in turn is needed to preserve types under -reduction. In a system that does not involve -reduction, the rule can be omitted, as well as those side conditions. The rules (lb) and (lb) adapt (incl) and (incl) to a system without transitivity, and have appeared many times in the literature (Bakel:1995aa). The rule generalizes the rule, replacing the on the left with any type , because for transitivity, any type is below . The rule also replaces the in the codomain on the right with any type that is equivalent to .

Before moving on, we make note of some basic facts regarding the relation and the predicate.

Proposition 2 (Basic Properties of ).
  1. (reflexivity)

  2. If , then and .

  3. If and , then .

  4. If and , then .

Proof.
  1. The proof of reflexivity is by induction on . In the case , we proceed by cases on whether . If it is, deduce by rule . Otherwise, apply rule

  2. The proof is by induction on the derivation of .

  3. The proof is by induction on . In the case where , either or , but in either case part 2 of this proposition fulfills the premise of the induction hypothesis, from which the conclusion follows.

  4. The proof is by induction on , using part 3 of this proposition in the cases for atoms and function types.

Proposition 3 (Properties of ).
  1. If then .

  2. If and , then .

  3. If and , then .

  4. If and , then .

  5. If , then .

Proof.
  1. The proof is a straightforward induction on .

  2. The proof is also a straightforward induction on .

  3. The proof is by induction on . The cases for atoms and function types are proved by part 2 of this proposition. In the case for , from , we have and (Proposition 1). Then by the induction hypotheses for and we have and , from which we conclude that .

  4. The proof is by induction on the derivation of . All of the cases are straightforward except for rule . In that case we have and some such that , , , , and . From the premise and part 3 of this proposition, we have . Then by part 1 we have . By the induction hypothesis for we conclude that .

  5. The proof is a straightforward induction on .

Next we turn to the subtyping inversion principle for function types. The idea is to generalize the rule with respect to the type on the right, allowing any type that contains a function type. The premises of are somewhat complex, so we package most of them into the following definition.

Definition 4 (factors).

We say factors if there exists some type such that , , , and .

Proposition 5 (Inversion Principle for Function Types).

If , , and , then factors .

Proof.

The proof is a straightforward induction on . ∎

3 Transitivity

The proof of transitivity relies on the following lemma, which is traditionally needed to prove the inversion principle for function types. However, it was not needed for our system because the rule is already quite close to the inversion principle. The lemma states that if every function type in A factors , then also factors .

Lemma 6.

If

  • for any , if and , then factors , and

  • ,

then factors .

Proof.

The proof is by induction on .

  • Case is an atom. The statement is vacuously true.

  • Case is a function type. Then we conclude by applying the premise with and instantiated to and respectively.

  • Case . By the induction hypothesis for and for , we have that factors and so does . So there exists and such that , , , and similarly for . We need to show that factors . We choose the witness . Clearly we have and . Also, we have

    and

    Thus, we have that and , and this case is complete.

We now turn to the proof of transitivity, that if and , then . The proof is by well-founded induction on the lexicographical ordering of the sum of the depths of and followed by the sum of the sizes of and . To be precise, we define this ordering as follows.

where is

and is

Theorem 7 (Transitivity of ).

If and , then .

Proof.

The proof is by well-founded induction on the relation . We proceed by cases on the last rule applied in the derivation of .

Case (refl)

We have . From the premise we immediately conclude that .

Case (lb)

So , , and . We have (Proposition 2 part 2), so we conclude that by the induction hypothesis, noting that because .

Case (lb)

So , , and . We have (Proposition 2 part 2), so we conclude that by the induction hypothesis, noting that because and .

Case (glb)

We have , , and . By the induction hypothesis, we have and , noting that because , , , and . We conclude by rule (glb).

Case

So , , and there exists such that , , , and . From and , we have (Proposition 2 part 4). Thus, for any , factors (Proposition 5). We have satisfied the premises of Lemma 6, so factors . That means there exists such that , , , and . Then by the induction hypothesis, we have

noting that because and because . We conclude that by rule witnessed by .

Case

We have and conclude by rule .

Case

We have and . We conclude by rule .

4 Equivalence with BCD Subtyping

Having proved (trans), we next prove and and then show that is equivalent to .

Lemma 8 ().

If and , then .

Proof.

Consider whether or not.

Case

We conclude by rule .

Case

Consider whether or not.

Case

So (Prop. 3 part 4), but that is a contradiction.

Case

We conclude that by rule .

Lemma 9 ().

Proof.

We consider the cases for whether or .

Case and

Then and we conclude that by rule .

Case and

We conclude that by rule , choosing the witness and noting that by way of Proposition 3 part 5 and by Proposition 2 part 1.

Case and

We conclude that by rule , this time with witness and noting that by Proposition 2 part 1 and by way of Proposition 3 part 5.

Case and

Again we apply rule , but with witness .

We require one more lemma.

Lemma 10.

.

Proof.

The proof is by induction on . ∎

Now for the proof of equivalence

2 A New Subtyping Judgment

Our new subtyping judgment relies on several auxiliary notions that help us avoid the use of ellipses, which we define in Figure 2. These include the and functions, the and predicates, and the relations and . The and functions return the domain or codomain if is a function type, respectively. If is an intersection , then is the intersection of the domain of and . If is an atom, is undefined. Likewise for . For example, if , then and . When or appears in lemma or theorem statement, we implicitly assume that is a type such that and are defined. The predicate identifies types that are equivalent to . The predicate identifies types that have in their codomain. The relation indicates whether is syntactically a part of . The relation holds when every part of is a part of . We say that contains if .

Proposition 1.

If , then and .

toptop

Figure 3: Auxiliary Definitions

Figure 4: The New Subtyping Judgment

The new intersection subtyping judgment, , is defined in Figure 2. First, it does not include the (trans) rule. It also replaces the (refl) rule with reflexivity for atoms (refl). The most important rule is the one for function types , which subsumes and in BCD subtyping. The rule essentially turns the -soundness property into a subtyping rule. The rule says that a type is a subtype of a function type if a subset of , call it , has domain and codomain that are larger and smaller than and , respectively. The use of a subset of enables this rule to absorb uses of (incl) and (incl) on the left. The side conditions and are needed because of the rule, which in turn is needed to preserve types under -reduction. In a system that does not involve -reduction, the rule can be omitted, as well as those side conditions. The rules (lb) and (lb) adapt (incl) and (incl) to a system without transitivity, and have appeared many times in the literature (Bakel:1995aa). The rule generalizes the rule, replacing the on the left with any type , because for transitivity, any type is below . The rule also replaces the in the codomain on the right with any type that is equivalent to .

Before moving on, we make note of some basic facts regarding the relation and the predicate.

Proposition 2 (Basic Properties of ).
  1. (reflexivity)

  2. If , then and .

  3. If and , then .

  4. If and , then .

Proof.
  1. The proof of reflexivity is by induction on . In the case , we proceed by cases on whether . If it is, deduce by rule . Otherwise, apply rule

  2. The proof is by induction on the derivation of .

  3. The proof is by induction on . In the case where , either or , but in either case part 2 of this proposition fulfills the premise of the induction hypothesis, from which the conclusion follows.

  4. The proof is by induction on , using part 3 of this proposition in the cases for atoms and function types.

Proposition 3 (Properties of ).
  1. If then .

  2. If and , then .

  3. If and , then .

  4. If and , then .

  5. If , then .

Proof.
  1. The proof is a straightforward induction on .

  2. The proof is also a straightforward induction on .

  3. The proof is by induction on . The cases for atoms and function types are proved by part 2 of this proposition. In the case for , from , we have and (Proposition 1). Then by the induction hypotheses for and we have and , from which we conclude that .

  4. The proof is by induction on the derivation of . All of the cases are straightforward except for rule . In that case we have and some such that , , , , and . From the premise and part 3 of this proposition, we have . Then by part 1 we have . By the induction hypothesis for we conclude that .

  5. The proof is a straightforward induction on .

Next we turn to the subtyping inversion principle for function types. The idea is to generalize the rule with respect to the type on the right, allowing any type that contains a function type. The premises of are somewhat complex, so we package most of them into the following definition.

Definition 4 (factors).

We say factors if there exists some type such that , , , and .

Proposition 5 (Inversion Principle for Function Types).

If , , and , then factors .

Proof.

The proof is a straightforward induction on . ∎

3 Transitivity

The proof of transitivity relies on the following lemma, which is traditionally needed to prove the inversion principle for function types. However, it was not needed for our system because the rule is already quite close to the inversion principle. The lemma states that if every function type in A factors , then also factors .

Lemma 6.

If

  • for any , if and , then factors , and

  • ,

then factors .

Proof.

The proof is by induction on .

  • Case is an atom. The statement is vacuously true.

  • Case is a function type. Then we conclude by applying the premise with and instantiated to and respectively.

  • Case . By the induction hypothesis for and for , we have that factors and so does . So there exists and such that , , , and similarly for . We need to show that factors . We choose the witness . Clearly we have and . Also, we have

    and

    Thus, we have that and , and this case is complete.

We now turn to the proof of transitivity, that if and , then . The proof is by well-founded induction on the lexicographical ordering of the sum of the depths of and followed by the sum of the sizes of and . To be precise, we define this ordering as follows.

where is

and is

Theorem 7 (Transitivity of ).

If and , then .

Proof.

The proof is by well-founded induction on the relation . We proceed by cases on the last rule applied in the derivation of .

Case (refl)

We have . From the premise we immediately conclude that .

Case (lb)

So , , and . We have (Proposition 2 part 2), so we conclude that by the induction hypothesis, noting that because .

Case (lb)

So , , and . We have (Proposition 2 part 2), so we conclude that by the induction hypothesis, noting that because and .

Case (glb)

We have , , and . By the induction hypothesis, we have and , noting that because , , , and . We conclude by rule (glb).

Case

So , , and there exists such that , , , and . From and , we have (Proposition 2 part 4). Thus, for any , factors (Proposition 5). We have satisfied the premises of Lemma 6, so factors . That means there exists such that , , , and . Then by the induction hypothesis, we have

noting that because and because . We conclude that by rule witnessed by .

Case

We have and conclude by rule .

Case

We have and . We conclude by rule .

4 Equivalence with BCD Subtyping

Having proved (trans), we next prove and and then show that is equivalent to .

Lemma 8 ().

If and , then .

Proof.

Consider whether or not.

Case

We conclude by rule .

Case

Consider whether or not.

Case

So (Prop. 3 part 4), but that is a contradiction.

Case