4.4 Progress
5.2.1 Reduction Basics
We begin with simple results about the reduction relations for PCCθ. These lemmas are all proved by a straightforward structural induction, so we omit the details. In principle, dozens of lemmas about reduction are needed for the proofs in later sections. For readability, we have stated only the lemmas that are actually used in proofs that appear in detail below.
Lemma 5.2.1 (Parallel reduction inversion for@). If A@θ V∗ B@θ then AV∗ B.
Lemma 5.2.2 (Parallel reduction inversion for arrows). If (x : A1) → A2 V∗ (x :
B1)→B2 then A1 V∗ B1 and A2 V∗ B2.
Lemma 5.2.3 (Application evaluation inversion). Suppose b a j v. Then there exist i1, i2, i3 ∈N such that 1 +i1+i2+i3 =j and a i2 v0 and either
• b i1 λx:A.b0 for some b0 such that [v0/x]b0 i3 v,
• or b i1 recf (x:A).b0 for some b0 such that[v0/x][recf (x:A).b0/f]b0 i3 v.
Lemma 5.2.4 (pcase evaluation inversion). Suppose pcasez a of hx,yi ⇒ b j
v. Then there exist i1, i2 ∈ N such that 1 +i1 +i2 = j and a i1 hv1,v2i and
[v1/x][v2/y][refl/z]b i2 v.
Lemma 5.2.5 (Term substitution preserves head forms). If hd(A) = hf, then for any v and x, hd([v/x]A) =hf.
Lemma 5.2.6. For any v, x and v0, [v0/x]v is a value.
Lemma 5.2.7(Term substitution preserves mobility). IfMob(A)thenMob([a/x]A).
Lemma 5.2.8 (V preserves valuehood). If v Va then a is a value.
Lemma 5.2.9 (V preserves valuehood of types). IfV VA then A is a value.
Lemma 5.2.10 (V∗ preserves head forms). If hd(A) = hf and A V∗ B then
hd(B) =hf.
1The mechanized proof for the LFθ system from Chapter 4, for example, involves approximately
400 individual lemmas and theorems. So, even stating every lemma needed would be a monumental task.
Lemma 5.2.11. Suppose a1 Va2. Then,
• [a1/x]b V[a2/x]b for any b, and
• [a1/x]B V[a2/x]B for any B, and
• [a1/x]k V[a2/x]k for any k.
Lemma 5.2.12. Suppose A1 VA2. Then,
• [A1/x]b V[A2/x]b for any b, and
• [A1/x]B V[A2/x]B for any B, and
• [A1/x]k V[A2/x]k for any k.
Lemma 5.2.13. Suppose a1 V∗ a2. Then,
• [a1/x]b V∗ [a2/x]b for any b, and
• [a1/x]B V∗ [a2/x]B for any B, and
• [a1/x]k V∗ [a2/x]k for any k.
Lemma 5.2.14. Suppose A1 V∗ A2. Then,
• [A1/x]b V∗ [A2/x]b for any b, and
• [A1/x]B V∗ [A2/x]B for any B, and
• [A1/x]k V∗ [A2/x]k for any k.
Lemma 5.2.15. For any value v and variable x, • If a V∗ b then [v/x]a V∗ [v/x]b, and
• If AV∗ B then [v/x]AV∗ [v/x]B, and • If k1 V∗ k2 then [v/x]k1 V∗ [v/x]k2.
For types, it will be convenient to generalize this last lemma slightly to the case where the type is not a value itself but does reduce to a value. We obtain a similar result, since in any case of the original reduction that made use of the fact that x is a value, we may insert some extra reduction steps to reduce the substituted type to a value.
Lemma 5.2.16. Suppose B V∗ V for some type B and type value V. Then, for any variable x,
• If A1 V∗ A2 then [B/x]A1 V∗ [V/x]A2, and
• If k1 V∗ k2 then [B/x]k1 V∗ [V/x]k2.
Lemma 5.2.17 (Confluence). IfA V∗ A1 and AV∗ A2, then there is some B such
that A1 V∗ B and A2 V∗ B.
Lemma 5.2.18 ( is a subrelation of V).
• If a b, then a Vb. • If A B, then AVB.
Lemma 5.2.19 ( ∗ andV∗ agree on normalization). IfAV∗ V then there is some valueV0 such thatA ∗ V0.
5.2.2
Typing Basics
In this section, we prove several preliminaries about the typing relation that are necessary for the substitution, inversion, and preservation results to come. These lemmas are mostly proved by mutual induction on the three typing judgements, so we state all three parts together. Several of them (weakening, substitution) additionally have two versions: one for terms and one for types.
Lemma 5.2.20(Term variable weakening). SupposeΓ`B :?σ andx /∈dom(Γ1,Γ2).
• If Γ1,Γ2 `θ a :A then Γ1,x :B,Γ2 `θ a :A.
• If Γ1,Γ2 `A:k then Γ1,x :B,Γ2 `A:k.
• If Γ1,Γ2 `k then Γ1,x :B,Γ2 `k.
Proof. By mutual induction on the three typing derivations.
Lemma 5.2.21 (Type variable weakening). Suppose Γ`k and x /∈dom(Γ1,Γ2).
• If Γ1,Γ2 `θ a :A then Γ1,x :k,Γ2 `θ a :A.
• If Γ1,Γ2 `A:k then Γ1,x :k,Γ2 `A:k.
• If Γ1,Γ2 `k then Γ1,x :k,Γ2 `k.
Proof. By mutual induction on the three typing derivations.
Lemma 5.2.22 (Context regularity). For any Γ,θ, a, A, and k, • If Γ`θ a :A then `Γ.
• If Γ`k then `Γ.
Proof. By mutual induction on the three typing derivations. In the case of TMu, it is also necessary to observe that, if ` Γ,x : k, then ` Γ. This is immediate by inversion of the definition of `Γ.
Lemma 5.2.23 (Context inversion for term variables). If` Γ1,x :A,Γ2, then Γ1 `
A:?σ.
Proof. By induction on the derivation of `Γ1,x :A,Γ2.
Lemma 5.2.24(Context inversion for type variables). If`Γ1,x :k,Γ2, thenΓ1 `k.
Proof. By induction on the derivation of `Γ1,x :k,Γ2.
Lemma 5.2.25 (Regularity). For any Γ,θ, a, A and k, • If Γ`θ a :A then Γ`A:?
σ.
• If Γ`A:k thenΓ`k or k=?σ.
Proof. By mutual induction on the derivations D :: Γ `θ a : A and E :: Γ ` A :
k. In almost all cases, the desired result is available immediately as an induction hypothesis or premise of the typing rule. In a few cases, it is also necessary to employ TMonoPoly. The remaining cases are straightforward.
• D= (x :A)∈Γ `Γ
Γ`θ x :A EVar
We must show that Γ`A:?σ. We know that Γhas the form Γ1,x :A,Γ2 for
some Γ1 and Γ2. By Lemma 5.2.23, it follows that Γ1 `A:?σ. The desired result
then follows by weakening (Lemma 5.2.20).
• D= `Γ
Γ`L Z:Nat EZero
We must showΓ`Nat:?σ, which is immediate byTNat and TMonoPoly.
• D=
a V∗ c b V∗ c
Γ`θ1 a :A Γ`θ2 b :B
Γ`L refl:a =b ERefl
We must show that Γ ` a = b : ?σ. By TMonoPoly, it will be enough to
show that Γ`a =b :?τ. By TEq, it is enough to show that a and b have types
in the programmatic fragment. This follows from the two typing hypotheses of ERefl, using ESub when θ1 orθ2 isL.
• D=
AV∗ C B V∗ C Γ`A:k1 Γ`B :k2
Γ`Ltrefl :A =B EReflT
We must show that Γ `A = B :?σ. By TMonoPoly, it is enough to show
that Γ ` A = B : ?τ. By TTEq, this follows directly from the two kinding
hypotheses of EReflT.
• D=
D0 Γ`θ a :A
Γ`P a :A@θ EBoxP
We must show that Γ ` A@θ : ?σ. By TAt, it is is enough to show that
Γ`A:?σ, which is precisely the induction hypothesis for D0.
• EBoxL and EBoxLV are similar to the previous case.
• D= (x :k)∈Γ `Γ
Γ`x :k TVar
We must show thatΓ`k. We know thatΓ has the formΓ1,x :k,Γ2 for some
Γ1 and Γ2. By Lemma 5.2.24, it follows that Γ1 ` k. The desired result then
follows by weakening (Lemma 5.2.21).
• D=
Γ`A:s Mob(A) Γ,x :A`B :s
Γ`(x :A)→B :s TArrComp
We must show that either Γ ` s or s is ?σ. But s is either ?τ or ?σ. In the
latter case the result is immediate. Ifs is?τ, then by ruleKSortit will be enough
to show `Γ, which follows by context regularity (Lemma 5.2.22). • TSigma, TSum and TAt are similar to the previous case.
Lemma 5.2.26 (?σ is untyped). There is no derivation of Γ`?σ.
Proof. By inspection of the inference rules for Γ`k.
Lemma 5.2.27 (Context conversion for terms). Suppose Γ1 `L p : b1 = b2 and
Γ1 `[b2/y]B :?σ.
• If Γ1,x : [b1/y]B,Γ2 `θ a :A then Γ1,x : [b2/y]B,Γ2 `θ a :A.
• If Γ1,x : [b1/y]B,Γ2 `A:k then Γ1,x : [b2/y]B,Γ2 `A:k.
Proof. By mutual induction on the three typing derivations. The only interesting case is the one for term variables:
• D=
(z :A)∈Γ1,x : [b1/y]B,Γ2 `Γ1,x : [b1/y]B,Γ2
Γ1,x : [b1/y]B,Γ2 `θ z :A
EVar
Either z = x or not. If not, the result immediate. So suppose z = x. Then A is [b1/y]B and we must show that Γ1,x : [b2/y]B,Γ2 `θ z : [b1/y]B. But
Γ1,x : [b2/y]B,Γ2 `θ z : [b2/y]B by EVar, and the result follows by EConv.
Lemma 5.2.28 (Value boxing). IfΓ`θ0
v :A then Γ`θ v :A@θ0, for any θ and θ0.
Proof. We break down the possible logicalities individually: • If θ =P, this is an instance of EBoxP.
• If θ =θ0 =L, this is an instance of EBoxL.
• If θ =L and θ0 =P, this is an instance of EBoxLV.
Lemma 5.2.29. If `Γ1,x :A,Γ2 then Mob(A).
Proof. By induction on the derivation of `Γ1,x :A,Γ2.