

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Theorem (termination of simply-typed λ-calculus expressions): Define the predicate Γ e ⇓∗^ which means that e when applied to any full sequence of inputs terminates. For example, if Γ e : • → • → •, then we require that for all expressions a and b of type • , e a b terminates. More formally,
(Γ e ⇓∗) ⇔ (Γ e : • ) ⇒ (∃v. e ⇓ v) ∧(Γ e : α → β) ⇒ (∀a. (Γ a : α) ∧ (Γ a ⇓∗) ⇒ (Γ e a ⇓∗))
Note that the fact that we eventually “run out” of arguments for e is critical, as this ensures that the we can only expand the subexpression (Γ ` e a ⇓∗) a bounded number of times.
Now consider any expression e; it may have one of three forms:
a free variable, x an application, e 1 e 2 a λ-abstraction, λx : α.e′
Case 1: e = x. If e is a free variable, then by definition, Γ ` e ⇓∗. This is because we cannot perform β-reduction on expressions of the form x a b.. ., hence provided a, b,... terminate, so does e.
Case 2: e = e 1 e 2. If e is an application, e 1 e 2 , we can assume inductively that Γ e 1 ⇓∗^ and Γ e 2 ⇓∗, where Γ e 1 : α → β and Γ e 2 : α. By definition of ⇓∗, we have that
(Γ e 1 ⇓∗) ⇔ ((Γ e 2 ⇓∗) ⇒ (Γ ` e 1 e 2 ⇓∗))
Therefore, Γ e 1 e 2 ⇓∗, i.e., Γ e ⇓∗.
Case 3: e = λx : α.e′. Next assume e = λx : α.e′. Observe that Γ e : α → β for some type β, thus Γ, x : α e′^ : β. By induction, we can assume that Γ, x : α e′^ ⇓∗. We will derive a lemma that we can use together with this inductive assumption to prove that Γ e ⇓∗. Note that by the definition of ⇓∗,
(Γ e ⇓∗) ⇔ (∀a. (Γ a : α) ∧ (Γ a ⇓∗) ⇒ (Γ e a ⇓∗))
Taking one step of β reduction,
(Γ e ⇓∗) ⇔ (∀a. (Γ a : α) ∧ (Γ a ⇓∗) ⇒ (Γ [x 7 → a]e′^ ⇓∗))
Lemma (termination extensionality): The well-typed expression [x 7 → a]e′^ terminates if and only if e′^ itself terminates, where x is a free variable of type α.
(∀a. (Γ a : α) ∧ (Γ a ⇓∗) ⇒ (Γ [x 7 → a]e′^ ⇓∗)) ⇔ (Γ, x : α e′^ ⇓∗)
We can prove this by a second induction, on the structure of e′.
Case 1L: e′^ = x (base case). In this case, the lemma statement simplifies to the following tautology (both sides of the ⇔ are true):
(∀a. (Γ a : α) ∧ (Γ a ⇓∗) ⇒ (Γ a ⇓∗)) ⇔ (Γ, x : α x ⇓∗)
Case 2L: e′^ = y 6 = x (base case). In this case, the lemma statement simplifies to the following tautology:
(∀a. (Γ a : α) ∧ (Γ a ⇓∗) ⇒ (Γ y ⇓∗)) ⇔ (Γ, x : α y ⇓∗)
Case 3L: e′^ = λx.e′′. In this case, the lemma statement simplifies to the following tautology:
(∀a. (Γ a : α) ∧ (Γ a ⇓∗) ⇒ (Γ λx.e′′^ ⇓∗)) ⇔ (Γ, x : α λx.e′′^ ⇓∗)
Case 4L: e′^ = λy : γ.e′′^ where x 6 = y. In this case, the lemma statement simplifies to the following:
(∀a. (Γ a : α)∧(Γ a ⇓∗) ⇒ (Γ λy : γ.[x 7 → a]e′′^ ⇓∗)) ⇔ (Γ, x : α λy : γ.e′′^ ⇓∗)
By induction, we can assume the following:
(Γ λy : γ.[x 7 → a]e′′^ ⇓∗) ⇔ (Γ, y : γ [x 7 → a]e′′^ ⇓∗) (Γ, x : α λy : γ.e′′^ ⇓∗) ⇔ (Γ, x : α, y : γ e′′^ ⇓∗)
Thus we can further simplify the lemma statement to:
(∀a. (Γ a : α)∧(Γ a ⇓∗) ⇒ (Γ, y : γ [x 7 → a]e′′^ ⇓∗)) ⇔ (Γ, x : α, y : γ e′′^ ⇓∗)
Now, via a second appeal to induction, the above is proven.
Case 5L: e′^ = e 1 e 2. This time, the lemma can be stated as follows:
(∀a. (Γ a : α)∧(Γ a ⇓∗) ⇒ (Γ [x 7 → a]e 1 e 2 ⇓∗)) ⇔ (Γ, x : α e 1 e 2 ⇓∗)
By the definitions of substitution and ⇓∗, the above can be restated as follows:
(∀a. (Γ a : α) ∧ (Γ a ⇓∗) ⇒ (Γ [x 7 → a]e 1 ⇓∗) ∧ (Γ [x 7 → a]e 2 ⇓∗)) ⇔ (Γ, x : α e 1 ⇓∗) ∧ (Γ, x : α e 2 ⇓∗)
The above is entailed by the following, more general statement:
(∀a. (Γ a : α) ∧ (Γ a ⇓∗) ⇒ (Γ [x 7 → a]e 1 ⇓∗)) ⇔ (Γ, x : α e 1 ⇓∗) ∧(∀a. (Γ a : α) ∧ (Γ a ⇓∗) ⇒ (Γ [x 7 → a]e 2 ⇓∗)) ⇔ (Γ, x : α e 2 ⇓∗)
Note that each of the two conjuncts above holds by induction.