NormSTLC 的规范化
(* Chapter written and maintained by Andrew Tolmach *)
Set Warnings "-notation-overridden,-parsing,-deprecated-hint-without-locality".
From Stdlib Require Import List.
From Stdlib Require Import Strings.String.
From PLF Require Import Maps.
From PLF Require Import Smallstep.
Hint Constructors multi : core.
Set Warnings "-notation-overridden,-parsing,-deprecated-hint-without-locality".
From Stdlib Require Import List.
From Stdlib Require Import Strings.String.
From PLF Require Import Maps.
From PLF Require Import Smallstep.
Hint Constructors multi : core.
本可选章节基于 [Pierce 2002] 第 12 章与
[Ahmed 2015]。查阅这些参考文献或许有用。
其中包含一些此处不再重复的解释与非形式化证明。
本章考察【简单类型 Lambda-演算|Simply Typed Lambda-Calculus】的
另一条基本理论性质:良型程序的求值保证在有限步内停机。
每个良型项都是【可规范化|Normalizable】的。
与迄今考察过的【类型安全性|Type Safety】性质不同,
【规范化|Normalization】性质并不能推广到完整的编程语言。
这类语言几乎总会包含一般递归(见 MoreStlc 一章)
或递归类型等特性,可用于写出不终止的程序。
不过,当我们考虑如 System F-omega 之类多态 Lambda-演算
版本的【元理论|Metatheory】时,规范化问题会在【类型】层面
重新出现。在该系统中,类型语言实际上包含一份简单类型
Lambda-演算的副本。因此,类型检查算法的终止取决于
类型表达式上的「规范化」操作保证终止。
研究规范化证明的另一原因是:它们是类型理论文献中最优美、
也最令人惊叹的数学之一。这些证明常常(如这里)涉及
【逻辑关系|Logical Relations】这一基本证明技术。
为让读者更多接触这种证明技术,我们在本章末尾还用它
来给出类型安全性的另一种证明。
这里考虑的演算是仅含单个基本类型 bool 并带有序对的
简单类型 Lambda-演算。对基本 Lambda-演算项,我们将给出
发展的大部分细节,把 bool 当作未解释的基本类型。
向布尔运算符与序对的推广则留给读者。
即便是基本演算,规范化也不易证明。
项的每次归约都可能在子项中复制可归约式。
练习: 2 stars,标准 (norm_fail)
若试图对良型项的大小做直截了当的归纳来证明规范化, 我们会在哪里失败?语言
(* 一个方便的策略。 *)
Ltac inv H := inversion H; subst; clear H.
Open Scope string.
Inductive ty : Type :=
| Ty_Bool : ty
| Ty_Arrow : ty → ty → ty
| Ty_Prod : ty → ty → ty.
Inductive tm : Type :=
(* pure STLC *)
| tm_var : string → tm
| tm_app : tm → tm → tm
| tm_abs : string → ty → tm → tm
(* booleans *)
| tm_true : tm
| tm_false : tm
| tm_if : tm → tm → tm → tm
(* pairs *)
| tm_pair : tm → tm → tm
| tm_fst : tm → tm
| tm_snd : tm → tm.
Declare Custom Entry stlc.
Notation "<{ e }>" := e (e custom stlc at level 99).
Notation "( x )" := x (in custom stlc, x at level 99).
Notation "x" := x (in custom stlc at level 0, x constr at level 0).
Notation "S -> T" := (Ty_Arrow S T) (in custom stlc at level 50, right associativity).
Notation "x y" := (tm_app x y) (in custom stlc at level 1, left associativity).
Notation "\ x : t , y" :=
(tm_abs x t y) (in custom stlc at level 90, x at level 99,
t custom stlc at level 99,
y custom stlc at level 99,
left associativity).
Coercion tm_var : string >-> tm.
Notation "{ x }" := x (in custom stlc at level 1, x constr).
Notation "'Bool'" := Ty_Bool (in custom stlc at level 0).
Notation "'if' x 'then' y 'else' z" :=
(tm_if x y z) (in custom stlc at level 89,
x custom stlc at level 99,
y custom stlc at level 99,
z custom stlc at level 99,
left associativity).
Notation "'true'" := true (at level 1).
Notation "'true'" := tm_true (in custom stlc at level 0).
Notation "'false'" := false (at level 1).
Notation "'false'" := tm_false (in custom stlc at level 0).
Notation "X * Y" :=
(Ty_Prod X Y) (in custom stlc at level 2, X custom stlc, Y custom stlc at level 0).
Notation "( x ',' y )" := (tm_pair x y) (in custom stlc at level 0,
x custom stlc at level 99,
y custom stlc at level 99).
Notation "t '.fst'" := (tm_fst t) (in custom stlc at level 1).
Notation "t '.snd'" := (tm_snd t) (in custom stlc at level 1).
| Ty_Bool : ty
| Ty_Arrow : ty → ty → ty
| Ty_Prod : ty → ty → ty.
Inductive tm : Type :=
(* pure STLC *)
| tm_var : string → tm
| tm_app : tm → tm → tm
| tm_abs : string → ty → tm → tm
(* booleans *)
| tm_true : tm
| tm_false : tm
| tm_if : tm → tm → tm → tm
(* pairs *)
| tm_pair : tm → tm → tm
| tm_fst : tm → tm
| tm_snd : tm → tm.
Declare Custom Entry stlc.
Notation "<{ e }>" := e (e custom stlc at level 99).
Notation "( x )" := x (in custom stlc, x at level 99).
Notation "x" := x (in custom stlc at level 0, x constr at level 0).
Notation "S -> T" := (Ty_Arrow S T) (in custom stlc at level 50, right associativity).
Notation "x y" := (tm_app x y) (in custom stlc at level 1, left associativity).
Notation "\ x : t , y" :=
(tm_abs x t y) (in custom stlc at level 90, x at level 99,
t custom stlc at level 99,
y custom stlc at level 99,
left associativity).
Coercion tm_var : string >-> tm.
Notation "{ x }" := x (in custom stlc at level 1, x constr).
Notation "'Bool'" := Ty_Bool (in custom stlc at level 0).
Notation "'if' x 'then' y 'else' z" :=
(tm_if x y z) (in custom stlc at level 89,
x custom stlc at level 99,
y custom stlc at level 99,
z custom stlc at level 99,
left associativity).
Notation "'true'" := true (at level 1).
Notation "'true'" := tm_true (in custom stlc at level 0).
Notation "'false'" := false (at level 1).
Notation "'false'" := tm_false (in custom stlc at level 0).
Notation "X * Y" :=
(Ty_Prod X Y) (in custom stlc at level 2, X custom stlc, Y custom stlc at level 0).
Notation "( x ',' y )" := (tm_pair x y) (in custom stlc at level 0,
x custom stlc at level 99,
y custom stlc at level 99).
Notation "t '.fst'" := (tm_fst t) (in custom stlc at level 1).
Notation "t '.snd'" := (tm_snd t) (in custom stlc at level 1).
Reserved Notation "'[' x ':=' s ']' t" (in custom stlc at level 20, x constr).
Fixpoint subst (x : string) (s : tm) (t : tm) : tm :=
match t with
| tm_var y ⇒
if x =? y then s else t
| <{ \ y : T, t1 }> ⇒
if x =? y then t else <{ \y:T, [x:=s] t1 }>
| <{t1 t2}> ⇒
<{ ([x:=s]t1) ([x:=s]t2)}>
| <{true}> ⇒
<{true}>
| <{false}> ⇒
<{false}>
| <{if t1 then t2 else t3}> ⇒
<{if ([x:=s] t1) then ([x:=s] t2) else ([x:=s] t3)}>
| <{(t1, t2)}> ⇒
<{( ([x:=s] t1), ([x:=s] t2) )}>
| <{t0.fst}> ⇒
<{ ([x:=s] t0).fst}>
| <{t0.snd}> ⇒
<{ ([x:=s] t0).snd}>
end
where "'[' x ':=' s ']' t" := (subst x s t) (in custom stlc).
Fixpoint subst (x : string) (s : tm) (t : tm) : tm :=
match t with
| tm_var y ⇒
if x =? y then s else t
| <{ \ y : T, t1 }> ⇒
if x =? y then t else <{ \y:T, [x:=s] t1 }>
| <{t1 t2}> ⇒
<{ ([x:=s]t1) ([x:=s]t2)}>
| <{true}> ⇒
<{true}>
| <{false}> ⇒
<{false}>
| <{if t1 then t2 else t3}> ⇒
<{if ([x:=s] t1) then ([x:=s] t2) else ([x:=s] t3)}>
| <{(t1, t2)}> ⇒
<{( ([x:=s] t1), ([x:=s] t2) )}>
| <{t0.fst}> ⇒
<{ ([x:=s] t0).fst}>
| <{t0.snd}> ⇒
<{ ([x:=s] t0).snd}>
end
where "'[' x ':=' s ']' t" := (subst x s t) (in custom stlc).
Inductive value : tm → Prop :=
| v_abs : ∀ x T2 t1,
value <{\x:T2, t1}>
| v_true :
value <{true}>
| v_false :
value <{false}>
| v_pair : ∀ v1 v2,
value v1 →
value v2 →
value <{(v1, v2)}>.
Hint Constructors value : core.
Reserved Notation "t '-->' t'" (at level 40).
Inductive step : tm → tm → Prop :=
| ST_AppAbs : ∀ x T2 t1 v2,
value v2 →
<{(\x:T2, t1) v2}> --> <{ [x:=v2]t1 }>
| ST_App1 : ∀ t1 t1' t2,
t1 --> t1' →
<{t1 t2}> --> <{t1' t2}>
| ST_App2 : ∀ v1 t2 t2',
value v1 →
t2 --> t2' →
<{v1 t2}> --> <{v1 t2'}>
| ST_IfTrue : ∀ t1 t2,
<{if true then t1 else t2}> --> t1
| ST_IfFalse : ∀ t1 t2,
<{if false then t1 else t2}> --> t2
| ST_If : ∀ t1 t1' t2 t3,
t1 --> t1' →
<{if t1 then t2 else t3}> --> <{if t1' then t2 else t3}>
| ST_Pair1 : ∀ t1 t1' t2,
t1 --> t1' →
<{ (t1,t2) }> --> <{ (t1' , t2) }>
| ST_Pair2 : ∀ v1 t2 t2',
value v1 →
t2 --> t2' →
<{ (v1, t2) }> --> <{ (v1, t2') }>
| ST_Fst1 : ∀ t0 t0',
t0 --> t0' →
<{ t0.fst }> --> <{ t0'.fst }>
| ST_FstPair : ∀ v1 v2,
value v1 →
value v2 →
<{ (v1,v2).fst }> --> v1
| ST_Snd1 : ∀ t0 t0',
t0 --> t0' →
<{ t0.snd }> --> <{ t0'.snd }>
| ST_SndPair : ∀ v1 v2,
value v1 →
value v2 →
<{ (v1,v2).snd }> --> v2
where "t '-->' t'" := (step t t').
Hint Constructors step : core.
Notation multistep := (multi step).
Notation "t1 '-->*' t2" := (multistep t1 t2) (at level 40).
Notation step_normal_form := (normal_form step).
Lemma value__normal : ∀ {t}, value t → step_normal_form t.
| v_abs : ∀ x T2 t1,
value <{\x:T2, t1}>
| v_true :
value <{true}>
| v_false :
value <{false}>
| v_pair : ∀ v1 v2,
value v1 →
value v2 →
value <{(v1, v2)}>.
Hint Constructors value : core.
Reserved Notation "t '-->' t'" (at level 40).
Inductive step : tm → tm → Prop :=
| ST_AppAbs : ∀ x T2 t1 v2,
value v2 →
<{(\x:T2, t1) v2}> --> <{ [x:=v2]t1 }>
| ST_App1 : ∀ t1 t1' t2,
t1 --> t1' →
<{t1 t2}> --> <{t1' t2}>
| ST_App2 : ∀ v1 t2 t2',
value v1 →
t2 --> t2' →
<{v1 t2}> --> <{v1 t2'}>
| ST_IfTrue : ∀ t1 t2,
<{if true then t1 else t2}> --> t1
| ST_IfFalse : ∀ t1 t2,
<{if false then t1 else t2}> --> t2
| ST_If : ∀ t1 t1' t2 t3,
t1 --> t1' →
<{if t1 then t2 else t3}> --> <{if t1' then t2 else t3}>
| ST_Pair1 : ∀ t1 t1' t2,
t1 --> t1' →
<{ (t1,t2) }> --> <{ (t1' , t2) }>
| ST_Pair2 : ∀ v1 t2 t2',
value v1 →
t2 --> t2' →
<{ (v1, t2) }> --> <{ (v1, t2') }>
| ST_Fst1 : ∀ t0 t0',
t0 --> t0' →
<{ t0.fst }> --> <{ t0'.fst }>
| ST_FstPair : ∀ v1 v2,
value v1 →
value v2 →
<{ (v1,v2).fst }> --> v1
| ST_Snd1 : ∀ t0 t0',
t0 --> t0' →
<{ t0.snd }> --> <{ t0'.snd }>
| ST_SndPair : ∀ v1 v2,
value v1 →
value v2 →
<{ (v1,v2).snd }> --> v2
where "t '-->' t'" := (step t t').
Hint Constructors step : core.
Notation multistep := (multi step).
Notation "t1 '-->*' t2" := (multistep t1 t2) (at level 40).
Notation step_normal_form := (normal_form step).
Lemma value__normal : ∀ {t}, value t → step_normal_form t.
Proof with eauto.
intros t H; induction H; intros [t' ST]; inversion ST...
Qed.
intros t H; induction H; intros [t' ST]; inversion ST...
Qed.
附带说明:提醒一下,在引理陈述中给一个或多个参数加上花括号。
这些参数要从其余参数【推断】出来。例如,在上面的引理中,
Rocq 可以从给出的 value t 推断 t。
这与普通多态函数中类型参数的推断完全类似。
它省去了显式应用该引理时的繁琐。
本章余下大部分引理陈述都采用这种风格。
Definition context := partial_map ty.
Reserved Notation "Gamma '|--' t '∈' T" (at level 40,
t custom stlc, T custom stlc at level 0).
Inductive has_type : context → tm → ty → Prop :=
(* 与之前相同: *)
(* pure STLC *)
| T_Var : ∀ Gamma x T1,
Gamma x = Some T1 →
Gamma |-- x \in T1
| T_Abs : ∀ Gamma x T1 T2 t1,
(x ⊢> T2 ; Gamma) |-- t1 \in T1 →
Gamma |-- \x:T2, t1 \in (T2 → T1)
| T_App : ∀ T1 T2 Gamma t1 t2,
Gamma |-- t1 \in (T2 → T1) →
Gamma |-- t2 \in T2 →
Gamma |-- t1 t2 \in T1
| T_True : ∀ Gamma,
Gamma |-- true \in Bool
| T_False : ∀ Gamma,
Gamma |-- false \in Bool
| T_If : ∀ t1 t2 t3 T1 Gamma,
Gamma |-- t1 \in Bool →
Gamma |-- t2 \in T1 →
Gamma |-- t3 \in T1 →
Gamma |-- if t1 then t2 else t3 \in T1
| T_Pair : ∀ Gamma t1 t2 T1 T2,
Gamma |-- t1 \in T1 →
Gamma |-- t2 \in T2 →
Gamma |-- (t1, t2) \in (T1 × T2)
| T_Fst : ∀ Gamma t0 T1 T2,
Gamma |-- t0 \in (T1 × T2) →
Gamma |-- t0.fst \in T1
| T_Snd : ∀ Gamma t0 T1 T2,
Gamma |-- t0 \in (T1 × T2) →
Gamma |-- t0.snd \in T2
where "Gamma '|--' t '∈' T" := (has_type Gamma t T).
Hint Constructors has_type : core.
Reserved Notation "Gamma '|--' t '∈' T" (at level 40,
t custom stlc, T custom stlc at level 0).
Inductive has_type : context → tm → ty → Prop :=
(* 与之前相同: *)
(* pure STLC *)
| T_Var : ∀ Gamma x T1,
Gamma x = Some T1 →
Gamma |-- x \in T1
| T_Abs : ∀ Gamma x T1 T2 t1,
(x ⊢> T2 ; Gamma) |-- t1 \in T1 →
Gamma |-- \x:T2, t1 \in (T2 → T1)
| T_App : ∀ T1 T2 Gamma t1 t2,
Gamma |-- t1 \in (T2 → T1) →
Gamma |-- t2 \in T2 →
Gamma |-- t1 t2 \in T1
| T_True : ∀ Gamma,
Gamma |-- true \in Bool
| T_False : ∀ Gamma,
Gamma |-- false \in Bool
| T_If : ∀ t1 t2 t3 T1 Gamma,
Gamma |-- t1 \in Bool →
Gamma |-- t2 \in T1 →
Gamma |-- t3 \in T1 →
Gamma |-- if t1 then t2 else t3 \in T1
| T_Pair : ∀ Gamma t1 t2 T1 T2,
Gamma |-- t1 \in T1 →
Gamma |-- t2 \in T2 →
Gamma |-- (t1, t2) \in (T1 × T2)
| T_Fst : ∀ Gamma t0 T1 T2,
Gamma |-- t0 \in (T1 × T2) →
Gamma |-- t0.fst \in T1
| T_Snd : ∀ Gamma t0 T1 T2,
Gamma |-- t0 \in (T1 × T2) →
Gamma |-- t0.snd \in T2
where "Gamma '|--' t '∈' T" := (has_type Gamma t T).
Hint Constructors has_type : core.
Lemma weakening : ∀ {Gamma Gamma' t T},
includedin Gamma Gamma' →
Gamma |-- t \in T →
Gamma' |-- t \in T.
Lemma weakening_empty : ∀ {Gamma t T},
empty |-- t \in T →
Gamma |-- t \in T.
includedin Gamma Gamma' →
Gamma |-- t \in T →
Gamma' |-- t \in T.
Proof.
intros Gamma Gamma' t T H Ht.
generalize dependent Gamma'.
induction Ht; eauto using includedin_update.
Qed.
intros Gamma Gamma' t T H Ht.
generalize dependent Gamma'.
induction Ht; eauto using includedin_update.
Qed.
Lemma weakening_empty : ∀ {Gamma t T},
empty |-- t \in T →
Gamma |-- t \in T.
Lemma substitution_preserves_typing : ∀ Gamma x U t v T,
(x ⊢> U ; Gamma) |-- t \in T →
empty |-- v \in U →
Gamma |-- [x:=v]t \in T.
(x ⊢> U ; Gamma) |-- t \in T →
empty |-- v \in U →
Gamma |-- [x:=v]t \in T.
Proof with eauto.
intros Gamma x U t v T Ht Hv.
generalize dependent Gamma. generalize dependent T.
induction t; intros T Gamma H;
(* 在每种情形中,我们都想得到 H 的推导 *)
inv H; simpl; eauto.
- (* var *)
rename s into y. destruct (eqb_spec x y); subst.
+ (* x=y *)
rewrite update_eq in H2.
injection H2 as H2; subst.
apply weakening_empty. assumption.
+ (* x<>y *)
apply T_Var. rewrite update_neq in H2; auto.
- (* abs *)
rename s into y, t into S.
destruct (eqb_spec x y); subst; apply T_Abs.
+ (* x=y *)
rewrite update_shadow in H5. assumption.
+ (* x<>y *)
apply IHt.
rewrite update_permute; auto.
Qed.
intros Gamma x U t v T Ht Hv.
generalize dependent Gamma. generalize dependent T.
induction t; intros T Gamma H;
(* 在每种情形中,我们都想得到 H 的推导 *)
inv H; simpl; eauto.
- (* var *)
rename s into y. destruct (eqb_spec x y); subst.
+ (* x=y *)
rewrite update_eq in H2.
injection H2 as H2; subst.
apply weakening_empty. assumption.
+ (* x<>y *)
apply T_Var. rewrite update_neq in H2; auto.
- (* abs *)
rename s into y, t into S.
destruct (eqb_spec x y); subst; apply T_Abs.
+ (* x=y *)
rewrite update_shadow in H5. assumption.
+ (* x<>y *)
apply IHt.
rewrite update_permute; auto.
Qed.
Theorem preservation : ∀ {t t' T},
empty |-- t \in T →
t --> t' →
empty |-- t' \in T.
empty |-- t \in T →
t --> t' →
empty |-- t' \in T.
Proof with eauto.
intros t t' T HT. generalize dependent t'.
remember empty as Gamma.
induction HT;
intros t' HE; subst; inversion HE; subst...
- (* T_App *)
inversion HE; subst...
+ (* ST_AppAbs *)
apply substitution_preserves_typing with T2...
inversion HT1...
- (* T_Fst *)
inversion HT...
- (* T_Snd *)
inversion HT...
Qed.
intros t t' T HT. generalize dependent t'.
remember empty as Gamma.
induction HT;
intros t' HE; subst; inversion HE; subst...
- (* T_App *)
inversion HE; subst...
+ (* ST_AppAbs *)
apply substitution_preserves_typing with T2...
inversion HT1...
- (* T_Fst *)
inversion HT...
- (* T_Snd *)
inversion HT...
Qed.
Inductive appears_free_in : string → tm → Prop :=
| afi_var : ∀ (x : string),
appears_free_in x <{ x }>
| afi_app1 : ∀ x t1 t2,
appears_free_in x t1 → appears_free_in x <{ t1 t2 }>
| afi_app2 : ∀ x t1 t2,
appears_free_in x t2 → appears_free_in x <{ t1 t2 }>
| afi_abs : ∀ x y T11 t12,
y ≠ x →
appears_free_in x t12 →
appears_free_in x <{ \y : T11, t12 }>
(* booleans *)
| afi_if0 : ∀ x t0 t1 t2,
appears_free_in x t0 →
appears_free_in x <{ if t0 then t1 else t2 }>
| afi_if1 : ∀ x t0 t1 t2,
appears_free_in x t1 →
appears_free_in x <{ if t0 then t1 else t2 }>
| afi_if2 : ∀ x t0 t1 t2,
appears_free_in x t2 →
appears_free_in x <{ if t0 then t1 else t2 }>
(* pairs *)
| afi_pair1 : ∀ x t1 t2,
appears_free_in x t1 →
appears_free_in x <{ (t1, t2) }>
| afi_pair2 : ∀ x t1 t2,
appears_free_in x t2 →
appears_free_in x <{ (t1 , t2) }>
| afi_fst : ∀ x t,
appears_free_in x t →
appears_free_in x <{ t.fst }>
| afi_snd : ∀ x t,
appears_free_in x t →
appears_free_in x <{ t.snd }>.
Hint Constructors appears_free_in : core.
Definition closed (t:tm) :=
∀ x, ¬ appears_free_in x t.
Lemma free_in_context : ∀ x {t T Gamma},
appears_free_in x t →
Gamma |-- t \in T →
Gamma x ≠ None.
Corollary typable_empty__closed : ∀ {t T},
empty |-- t \in T →
closed t.
| afi_var : ∀ (x : string),
appears_free_in x <{ x }>
| afi_app1 : ∀ x t1 t2,
appears_free_in x t1 → appears_free_in x <{ t1 t2 }>
| afi_app2 : ∀ x t1 t2,
appears_free_in x t2 → appears_free_in x <{ t1 t2 }>
| afi_abs : ∀ x y T11 t12,
y ≠ x →
appears_free_in x t12 →
appears_free_in x <{ \y : T11, t12 }>
(* booleans *)
| afi_if0 : ∀ x t0 t1 t2,
appears_free_in x t0 →
appears_free_in x <{ if t0 then t1 else t2 }>
| afi_if1 : ∀ x t0 t1 t2,
appears_free_in x t1 →
appears_free_in x <{ if t0 then t1 else t2 }>
| afi_if2 : ∀ x t0 t1 t2,
appears_free_in x t2 →
appears_free_in x <{ if t0 then t1 else t2 }>
(* pairs *)
| afi_pair1 : ∀ x t1 t2,
appears_free_in x t1 →
appears_free_in x <{ (t1, t2) }>
| afi_pair2 : ∀ x t1 t2,
appears_free_in x t2 →
appears_free_in x <{ (t1 , t2) }>
| afi_fst : ∀ x t,
appears_free_in x t →
appears_free_in x <{ t.fst }>
| afi_snd : ∀ x t,
appears_free_in x t →
appears_free_in x <{ t.snd }>.
Hint Constructors appears_free_in : core.
Definition closed (t:tm) :=
∀ x, ¬ appears_free_in x t.
Lemma free_in_context : ∀ x {t T Gamma},
appears_free_in x t →
Gamma |-- t \in T →
Gamma x ≠ None.
Proof with eauto.
intros x t T Gamma Hafi Htyp.
induction Htyp; inv Hafi...
- (* T_Var *)
rewrite H; intro X; inv X.
- (* T_Abs *)
pose proof (IHHtyp H4). rewrite update_neq in H; auto.
Qed.
intros x t T Gamma Hafi Htyp.
induction Htyp; inv Hafi...
- (* T_Var *)
rewrite H; intro X; inv X.
- (* T_Abs *)
pose proof (IHHtyp H4). rewrite update_neq in H; auto.
Qed.
Corollary typable_empty__closed : ∀ {t T},
empty |-- t \in T →
closed t.
Ltac solve_by_value_nf :=
match goal with | H : value ?v, H' : ?v --> ?v' ⊢ _ ⇒
exfalso; apply value__normal in H; eauto
end.
Lemma step_deterministic :
deterministic step.
match goal with | H : value ?v, H' : ?v --> ?v' ⊢ _ ⇒
exfalso; apply value__normal in H; eauto
end.
Lemma step_deterministic :
deterministic step.
Proof with eauto.
unfold deterministic.
intros t t' t'' E1 E2.
generalize dependent t''.
induction E1; intros t'' E2; inv E2;
try solve_by_invert; try f_equal; try solve_by_value_nf; eauto.
- inv E1; solve_by_value_nf.
- inv H2; solve_by_value_nf.
- inv E1; solve_by_value_nf.
- inv H2; solve_by_value_nf.
Qed.
unfold deterministic.
intros t t' t'' E1 E2.
generalize dependent t''.
induction E1; intros t'' E2; inv E2;
try solve_by_invert; try f_equal; try solve_by_value_nf; eauto.
- inv E1; solve_by_value_nf.
- inv H2; solve_by_value_nf.
- inv E1; solve_by_value_nf.
- inv H2; solve_by_value_nf.
Qed.
规范化
☐
(该证明不依赖于步进关系的精确细节,但在一个方向上你会想用
value__normal 与 step_deterministic。对非确定性语言该引理
或许仍成立,但证明会更难!)
练习: 3 stars,标准 (step_preserves_halting)
另一个有用且有启发性的事实:停机性质在走一步归约【或】 「撤销」一步归约下保持。补全本引理的证明。
☐
第一次证明尝试
Theorem normalization_try1: ∀ {t T},
empty |-- t \in T →
halts t.
Proof.
intros t T HT.
(* 我们想对定型假设做归纳。回想 Rocq 的 induction 策略迫使我们
先泛化到任意语境 Gamma,并单独跟踪 Gamma 实际上总是
empty 这一事实。 *)
remember empty as Gamma.
induction HT; subst Gamma; intros.
- (* Var *)
(* 该情形不可能,因为空环境中裸变量不可定型。 *)
rewrite apply_empty in H. inv H.
- (* Abs *)
(* 该情形立即成立,因为抽象已经是值 *)
apply value_halts.
econstructor.
- (* App *)
unfold halts.
(* 这是困难(其实不可能)的情形,但看看我们能走多远。
应用要归约到值,唯一方式是以某种方式用到 ST_AppAbs
规则。否则归约序列会卡在仍是应用的项上,而应用永不是值。
要让该规则适用,t1 必须归约到抽象项,t2 必须归约到值。
归纳假设让我们几乎到达那里…… *)
destruct (IHHT1 eq_refl) as [v1 [ST1 V1]].
destruct (IHHT2 eq_refl) as [v2 [ST2 V2]].
(* 我们仍需表明 v1 是抽象项。
这可通过反复使用保型性以及关于典范形式的一些推理做到。 *)
assert (HTV1: empty |-- v1 \in (T2 → T1)).
{ clear - HT1 ST1. induction ST1; eauto using preservation. }
assert (V1ABS: ∃ x, ∃ t, v1 = <{ \ x : T2 , t }>).
{ inv V1; inv HTV1; eauto. }
destruct V1ABS as [x [t E]]. subst v1.
(* 现在我们可通过反复使用 ST_App1 与 ST_App2,
表明归约会确实到达 ST_AppAbs 的一次使用。 *)
assert (ST11: <{ t1 t2 }> -->* <{ (\ x : T2, t) t2 }>).
{ clear - ST1. induction ST1; eauto. (* using ST_App1 *) }
assert (ST22: <{ (\ x: T2, t) t2 }> -->* <{ (\ x : T2, t) v2 }>).
{ clear - ST2. induction ST2; eauto. (* using ST_App2 *) }
assert (ST23: <{ t1 t2 }> -->* <{ (\ x : T2, t) v2 }>).
{ eapply multi_trans; eauto. }
assert (STT: <{ t1 t2 }> -->* <{ [ x:= v2 ] t }>).
{ eapply multi_trans; eauto. (* using ST_AppAbs *) }
(* 但我们只能走到这里。归纳假设对 <{ x := v2 t >} 没有给出
任何信息,因为它不是原项的语法子项。因此我们无法表明它最终
归约到值,对该情形也做不了更多。(姑且不论,其余情形实际上
都成功通过了。) *)
Abort.
empty |-- t \in T →
halts t.
Proof.
intros t T HT.
(* 我们想对定型假设做归纳。回想 Rocq 的 induction 策略迫使我们
先泛化到任意语境 Gamma,并单独跟踪 Gamma 实际上总是
empty 这一事实。 *)
remember empty as Gamma.
induction HT; subst Gamma; intros.
- (* Var *)
(* 该情形不可能,因为空环境中裸变量不可定型。 *)
rewrite apply_empty in H. inv H.
- (* Abs *)
(* 该情形立即成立,因为抽象已经是值 *)
apply value_halts.
econstructor.
- (* App *)
unfold halts.
(* 这是困难(其实不可能)的情形,但看看我们能走多远。
应用要归约到值,唯一方式是以某种方式用到 ST_AppAbs
规则。否则归约序列会卡在仍是应用的项上,而应用永不是值。
要让该规则适用,t1 必须归约到抽象项,t2 必须归约到值。
归纳假设让我们几乎到达那里…… *)
destruct (IHHT1 eq_refl) as [v1 [ST1 V1]].
destruct (IHHT2 eq_refl) as [v2 [ST2 V2]].
(* 我们仍需表明 v1 是抽象项。
这可通过反复使用保型性以及关于典范形式的一些推理做到。 *)
assert (HTV1: empty |-- v1 \in (T2 → T1)).
{ clear - HT1 ST1. induction ST1; eauto using preservation. }
assert (V1ABS: ∃ x, ∃ t, v1 = <{ \ x : T2 , t }>).
{ inv V1; inv HTV1; eauto. }
destruct V1ABS as [x [t E]]. subst v1.
(* 现在我们可通过反复使用 ST_App1 与 ST_App2,
表明归约会确实到达 ST_AppAbs 的一次使用。 *)
assert (ST11: <{ t1 t2 }> -->* <{ (\ x : T2, t) t2 }>).
{ clear - ST1. induction ST1; eauto. (* using ST_App1 *) }
assert (ST22: <{ (\ x: T2, t) t2 }> -->* <{ (\ x : T2, t) v2 }>).
{ clear - ST2. induction ST2; eauto. (* using ST_App2 *) }
assert (ST23: <{ t1 t2 }> -->* <{ (\ x : T2, t) v2 }>).
{ eapply multi_trans; eauto. }
assert (STT: <{ t1 t2 }> -->* <{ [ x:= v2 ] t }>).
{ eapply multi_trans; eauto. (* using ST_AppAbs *) }
(* 但我们只能走到这里。归纳假设对 <{ x := v2 t >} 没有给出
任何信息,因为它不是原项的语法子项。因此我们无法表明它最终
归约到值,对该情形也做不了更多。(姑且不论,其余情形实际上
都成功通过了。) *)
Abort.
N 关系
- N bool t 当且仅当 t 是类型 bool 的闭项,且 t 停机
在一个值上
- N (T1 → T2) t 当且仅当 t 是类型 T1 → T2 的闭项, t 停机在一个值上,并且对任何满足 N T1 s 的项 s, 我们有 N T2 (t s)。
Inductive N : ty → tm → Prop :=
| N_bool : ∀ b t, empty |-- t \in <{ Bool }> →
halts t →
N <{ Bool }> t
| N_arrow : ∀ T1 T2 t, empty |-- t \in <{ T1 → T2 }> →
halts t →
(∀ s, N T1 s → N T2 <{t s}>) →
N <{ T1 → T2 }> t. 不幸的是,Rocq 拒绝该定义,因为它违反了归纳定义的【严格正性】 要求。该要求说,被定义的类型不得出现在构造子参数类型中 箭头的左边。这里违反规则的是 N_arrow 的第三个参数,即 (∀ s, N T1 s → N T2 <{t s}>),具体说是其中的 N T1 s 部分。(应用该规则时,分隔构造子参数的最外层箭头 不计入。若计入,我们就根本不可能有真正的归纳性质了!) 该规则的理由是:用非正递归定义的类型可用于构造不终止的函数。 而正如我们所知,这对 Rocq 的逻辑可靠性将是一场灾难。 尽管本例中我们想要的关系可能完全无害, Rocq 仍会因它通不过正性检验而拒绝它。
练习: 3 stars,高级,特别有用 (N_products)
修正本定义的积情形。
Fixpoint N (T:ty) (t:tm) : Prop :=
empty |-- t \in T ∧ halts t ∧
(match T with
| <{ Bool }> ⇒ True
| <{ T1 → T2 }> ⇒ (∀ s, N T1 s → N T2 <{t s}> )
(* ... 处理积时编辑下一行 *)
| <{ T1 × T2 }> ⇒ False (* FILL IN HERE *)
end).
(* 不要修改下面这行: *)
Definition manual_grade_for_N_products : option (nat×string) := None.
☐
empty |-- t \in T ∧ halts t ∧
(match T with
| <{ Bool }> ⇒ True
| <{ T1 → T2 }> ⇒ (∀ s, N T1 s → N T2 <{t s}> )
(* ... 处理积时编辑下一行 *)
| <{ T1 × T2 }> ⇒ False (* FILL IN HERE *)
end).
(* 不要修改下面这行: *)
Definition manual_grade_for_N_products : option (nat×string) := None.
☐
Lemma N_halts : ∀ {T t}, N T t → halts t.
Lemma N_typable_empty : ∀ {T t}, N T t → empty |-- t \in T.
Lemma N_typable_empty : ∀ {T t}, N T t → empty |-- t \in T.
N_T 的成员关系在归约下不变
练习: 3 stars,标准 (step_preserves_N)
Lemma step_preserves_N: ∀ {T t t'}, (t --> t') → N T t → N T t'.
Proof.
induction T; intros t t' E Nt; simpl in Nt ⊢ *;
destruct Nt as [typable_empty_t [halts_t NN]].
- (* Bool *)
split;[|split].
+ eapply preservation; eauto.
+ apply (step_preserves_halting E); eauto.
+ auto.
- (* Arrow *)
split;[|split].
+ eapply preservation; eauto.
+ apply (step_preserves_halting E); eauto.
+ intros.
eapply IHT2.
× apply ST_App1. apply E.
× apply NN; auto.
(* 在这里填写 *) Admitted.
induction T; intros t t' E Nt; simpl in Nt ⊢ *;
destruct Nt as [typable_empty_t [halts_t NN]].
- (* Bool *)
split;[|split].
+ eapply preservation; eauto.
+ apply (step_preserves_halting E); eauto.
+ auto.
- (* Arrow *)
split;[|split].
+ eapply preservation; eauto.
+ apply (step_preserves_halting E); eauto.
+ intros.
eapply IHT2.
× apply ST_App1. apply E.
× apply NN; auto.
(* 在这里填写 *) Admitted.
☐
把多步归约推广到多步是平凡的:
Lemma multistep_preserves_N : ∀ {T t t'},
(t -->* t') → N T t → N T t'.
(t -->* t') → N T t → N T t'.
Proof.
intros T t t' STM; induction STM; intros.
- assumption.
- apply IHSTM. eapply step_preserves_N.
+ apply H.
+ assumption.
Qed.
intros T t t' STM; induction STM; intros.
- assumption.
- apply IHSTM. eapply step_preserves_N.
+ apply H.
+ assumption.
Qed.
在反方向上,我们必须补充 t 在走步【之前】具有类型 T 这一
事实作为附加假设。这是因为【主体扩张】对该语言不成立
(见 StlcProp)。
练习: 4 stars,标准,特别有用 (step_preserves_N')
Lemma step_preserves_N' : ∀ {T t t'},
empty |-- t \in T → (t --> t') → N T t' → N T t.
empty |-- t \in T → (t --> t') → N T t' → N T t.
Proof.
(* 在这里填写 *) Admitted.
(* 在这里填写 *) Admitted.
☐
Lemma multistep_preserves_N' : ∀ {T t} t',
empty |-- t \in T → (t -->* t') → N T t' → N T t.
empty |-- t \in T → (t -->* t') → N T t' → N T t.
Proof.
intros T t t' HT STM.
induction STM; intros.
assumption.
eapply step_preserves_N'. assumption. apply H. apply IHSTM.
eapply preservation; eauto. auto.
Qed.
intros T t t' HT STM.
induction STM; intros.
assumption.
eapply step_preserves_N'. assumption. apply H. apply IHSTM.
eapply preservation; eauto. auto.
Qed.
第二次证明尝试
Lemma typable_N_try1: ∀ t T,
empty |-- t \in T →
N T t.
Proof.
intros t T HT.
remember empty as Gamma. (* 与之前一样,我们必须这样做才能对
HT 做归纳。 *)
induction HT; subst Gamma; intros.
- (* Var *)
(* 该情形再次不可能,因为 t 是闭的。 *)
rewrite apply_empty in H. inv H.
- (* Abs *)
simpl; split; [| split].
+ econstructor; eauto.
+ eapply value_halts. econstructor.
+ intros s NS.
(* 这现在是困难的(子)情形。
清点我们所知的,首先观察到 s 归约到值 v *)
destruct (N_halts NS) as [v [STV V]].
(* 此外,利用 N 在归约下的不变性,我们知道 v 在 N T2 中。 *)
assert (NV: N T2 v) by (eapply multistep_preserves_N; eauto).
(* 还有,目标中的应用归约到一次替换。 *)
assert (ST: <{ (\ x : T2, t1) s }> -->* <{ [x := v] t1 }>).
{ eapply multi_trans with <{ (\ x : T2, t1) v }>.
- clear - STV. induction STV; eauto. (* using ST_App2 *)
- eapply multi_trans.
+ eapply multi_R; eapply ST_AppAbs; auto.
+ eapply multi_refl.
}
(* 而且目标中的应用是良型的 *)
assert (empty |-- (\x : T2, t1) s \in T1).
{ econstructor.
- econstructor; eauto.
- eapply N_typable_empty; eauto.
}
(* 现在我们可以用 N 在逆步下的不变性来简化目标。 *)
eapply multistep_preserves_N'; eauto.
(* 可惜,我们无法证明这个目标!若我们知道 t1 在 N 中,
目标会是合理的:把 N 项代入 N 体「应该」给出 N 结果。
而且因为 t1 是原应用的子项,我们或许希望归纳假设会告诉
我们关于它的有用信息。但事实上归纳假设 IHHT 完全无用,
因为其假设 ((x) ⊢> T2) = empty 为假!此外,IHHT 的
结论 N T1 t1 无论如何也说不通,因为 N 中所有项都是
闭的,而 t1 可能自由含 x。这一切都表明我们需要一个
更一般的、谈论开项的归纳假设。 *)
admit. (* impossible! *)
- (* App *)
(* 至少如我们所料,该情形现在是直接的 *)
eapply IHHT1; eauto.
Abort.
empty |-- t \in T →
N T t.
Proof.
intros t T HT.
remember empty as Gamma. (* 与之前一样,我们必须这样做才能对
HT 做归纳。 *)
induction HT; subst Gamma; intros.
- (* Var *)
(* 该情形再次不可能,因为 t 是闭的。 *)
rewrite apply_empty in H. inv H.
- (* Abs *)
simpl; split; [| split].
+ econstructor; eauto.
+ eapply value_halts. econstructor.
+ intros s NS.
(* 这现在是困难的(子)情形。
清点我们所知的,首先观察到 s 归约到值 v *)
destruct (N_halts NS) as [v [STV V]].
(* 此外,利用 N 在归约下的不变性,我们知道 v 在 N T2 中。 *)
assert (NV: N T2 v) by (eapply multistep_preserves_N; eauto).
(* 还有,目标中的应用归约到一次替换。 *)
assert (ST: <{ (\ x : T2, t1) s }> -->* <{ [x := v] t1 }>).
{ eapply multi_trans with <{ (\ x : T2, t1) v }>.
- clear - STV. induction STV; eauto. (* using ST_App2 *)
- eapply multi_trans.
+ eapply multi_R; eapply ST_AppAbs; auto.
+ eapply multi_refl.
}
(* 而且目标中的应用是良型的 *)
assert (empty |-- (\x : T2, t1) s \in T1).
{ econstructor.
- econstructor; eauto.
- eapply N_typable_empty; eauto.
}
(* 现在我们可以用 N 在逆步下的不变性来简化目标。 *)
eapply multistep_preserves_N'; eauto.
(* 可惜,我们无法证明这个目标!若我们知道 t1 在 N 中,
目标会是合理的:把 N 项代入 N 体「应该」给出 N 结果。
而且因为 t1 是原应用的子项,我们或许希望归纳假设会告诉
我们关于它的有用信息。但事实上归纳假设 IHHT 完全无用,
因为其假设 ((x) ⊢> T2) = empty 为假!此外,IHHT 的
结论 N T1 t1 无论如何也说不通,因为 N 中所有项都是
闭的,而 t1 可能自由含 x。这一切都表明我们需要一个
更一般的、谈论开项的归纳假设。 *)
admit. (* impossible! *)
- (* App *)
(* 至少如我们所料,该情形现在是直接的 *)
eapply IHHT1; eauto.
Abort.
闭多重替换与实例化
Definition env := list (string × tm).
Fixpoint msubst (ss:env) (t:tm) : tm :=
match ss with
| nil ⇒ t
| ((x,s)::ss') ⇒ msubst ss' <{ [x:=s]t }>
end.
Fixpoint msubst (ss:env) (t:tm) : tm :=
match ss with
| nil ⇒ t
| ((x,s)::ss') ⇒ msubst ss' <{ [x:=s]t }>
end.
我们需要类似的机制来反复扩展定型语境,
扩展用的是一列(变量,类型)对。我们称这列为【类型指派】。
与迄今使用的偏映射(在
Maps 中发展)相比,这是定型语境更具体的表示。
对许多目的而言,把映射表示成函数简单得吸引人。
但它有一个主要缺点:我们不能枚举映射的定义域,
也不能对它做归纳。我们【可以】对类型指派做归纳,
而事实证明这非常有用。
Definition tass := list (string × ty).
Fixpoint mupdate (Gamma : context) (xts : tass) : context :=
match xts with
| nil ⇒ Gamma
| ((x,v)::xts') ⇒ update (mupdate Gamma xts') x v
end.
Fixpoint mupdate (Gamma : context) (xts : tass) : context :=
match xts with
| nil ⇒ Gamma
| ((x,v)::xts') ⇒ update (mupdate Gamma xts') x v
end.
类型指派可方便地转换成定型语境。
最后,我们描述类型指派与值环境的组合。
两者具有相同定义域,且对应的类型与值元素相关。
我们称它为【实例化】。
我们把定义参数化在闭项上任意按类型索引的谓词 R 上。
这是因为实例化的许多性质不依赖 R 的具体选择。
(这将使我们在本章后面能把这些定义与性质复用到
N 之外的其他逻辑谓词上。)
Definition R_closed (R: ty → tm → Prop) :=
∀ T t, R T t → closed t.
Hint Unfold R_closed : core.
Inductive instantiation (R: ty → tm → Prop) (RC: R_closed R) :
tass → env → Prop :=
| V_nil :
instantiation R RC nil nil
| V_cons : ∀ x T v c e,
value v → R T v →
instantiation R RC c e →
instantiation R RC ((x,T)::c) ((x,v)::e).
Hint Constructors instantiation: core.
∀ T t, R T t → closed t.
Hint Unfold R_closed : core.
Inductive instantiation (R: ty → tm → Prop) (RC: R_closed R) :
tass → env → Prop :=
| V_nil :
instantiation R RC nil nil
| V_cons : ∀ x T v c e,
value v → R T v →
instantiation R RC c e →
instantiation R RC ((x,T)::c) ((x,v)::e).
Hint Constructors instantiation: core.
现在我们来证明这些定义的各种性质。
更多替换事实
练习: 3 stars,标准,可选 (vacuous_substitution)
Lemma vacuous_substitution : ∀ {t x},
¬ appears_free_in x t →
∀ t', <{ [x:=t']t }> = t.
¬ appears_free_in x t →
∀ t', <{ [x:=t']t }> = t.
Proof with eauto.
induction t; intros; simpl...
(* 在这里填写 *) Admitted.
induction t; intros; simpl...
(* 在这里填写 *) Admitted.
☐
对闭项做替换没有效果。
Lemma subst_not_afi : ∀ {t x v},
closed v → ¬ appears_free_in x <{ [x:=v]t }>.
closed v → ¬ appears_free_in x <{ [x:=v]t }>.
Proof.
(* 在这里填写 *) Admitted.
(* 在这里填写 *) Admitted.
☐
对同一变量替换两次没有效果。
Lemma swap_subst : ∀ {t x x1 v v1},
x ≠ x1 →
closed v → closed v1 →
<{ [x1:=v1]([x:=v]t) }> = <{ [x:=v]([x1:=v1]t) }>.
x ≠ x1 →
closed v → closed v1 →
<{ [x1:=v1]([x:=v]t) }> = <{ [x:=v]([x1:=v1]t) }>.
Proof with eauto.
induction t; intros; simpl.
- (* var *)
destruct (eqb_spec x s); destruct (eqb_spec x1 s).
+ subst. exfalso...
+ subst. simpl. rewrite eqb_refl. apply subst_closed...
+ subst. simpl. rewrite eqb_refl. symmetry. apply subst_closed...
+ simpl. rewrite <- eqb_neq in n; rewrite n.
rewrite <- eqb_neq in n0; rewrite n0...
(* 在这里填写 *) Admitted.
induction t; intros; simpl.
- (* var *)
destruct (eqb_spec x s); destruct (eqb_spec x1 s).
+ subst. exfalso...
+ subst. simpl. rewrite eqb_refl. apply subst_closed...
+ subst. simpl. rewrite eqb_refl. symmetry. apply subst_closed...
+ simpl. rewrite <- eqb_neq in n; rewrite n.
rewrite <- eqb_neq in n0; rewrite n0...
(* 在这里填写 *) Admitted.
☐
Fixpoint closed_env (e:env) :=
match e with
| nil ⇒ True
| (_,t)::e' ⇒ closed t ∧ closed_env e'
end.
Fixpoint remove (n:string) (e: env) : env :=
match e with
| nil ⇒ nil
| ((n',x)::nxs') ⇒
if n' =? n then remove n nxs'
else (n',x)::(remove n nxs')
end.
match e with
| nil ⇒ True
| (_,t)::e' ⇒ closed t ∧ closed_env e'
end.
Fixpoint remove (n:string) (e: env) : env :=
match e with
| nil ⇒ nil
| ((n',x)::nxs') ⇒
if n' =? n then remove n nxs'
else (n',x)::(remove n nxs')
end.
Lemma msubst_subst: ∀ {e x v t},
closed v →
closed_env e →
msubst e <{ [x:=v]t }> = <{ [x:=v] { msubst (remove x e) t } }> .
closed v →
closed_env e →
msubst e <{ [x:=v]t }> = <{ [x:=v] { msubst (remove x e) t } }> .
Proof.
(* 在这里填写 *) Admitted.
(* 在这里填写 *) Admitted.
☐
对闭项做多重替换没有效果。
接下来是一系列简单引理,刻画 msubst 如何分配到每种项形式上
Lemma msubst_abs: ∀ {ss x T t},
msubst ss <{ \ x : T, t }> = <{ \x : T, {msubst (remove x ss) t} }>.
msubst ss <{ \ x : T, t }> = <{ \x : T, {msubst (remove x ss) t} }>.
Proof.
induction ss; intros.
- reflexivity.
- destruct a. simpl. destruct (s =? x); simpl; auto.
Qed.
induction ss; intros.
- reflexivity.
- destruct a. simpl. destruct (s =? x); simpl; auto.
Qed.
Lemma msubst_app : ∀ {ss t1 t2},
msubst ss <{ t1 t2 }> = <{ {msubst ss t1} ({msubst ss t2}) }>.
msubst ss <{ t1 t2 }> = <{ {msubst ss t1} ({msubst ss t2}) }>.
Proof.
(* 在这里填写 *) Admitted.
(* 在这里填写 *) Admitted.
☐
为完成下面主引理的积情形,你会需要关于所有其他项构造子的
类似结果。证明与 msubst_app 极为相似。
实例化的一般性质
练习: 3 stars,标准,特别有用 (instantiation_msubst)
把 R 的一次实例化中的多重替换应用于类型 T 的变量, 得到满足 R T t 的项 t。
Lemma instantiation_msubst : ∀ {R RC c e},
instantiation R RC c e →
∀ x T,
tass_context c x = Some T →
R T (msubst e x).
instantiation R RC c e →
∀ x T,
tass_context c x = Some T →
R T (msubst e x).
Proof.
intros R RC c e V.
induction V; intros x' T' G.
(* 在这里填写 *) Admitted.
intros R RC c e V.
induction V; intros x' T' G.
(* 在这里填写 *) Admitted.
Lemma instantiation_env_closed : ∀ {R RC c e},
instantiation R RC c e →
closed_env e.
instantiation R RC c e →
closed_env e.
Proof.
(* 在这里填写 *) Admitted.
(* 在这里填写 *) Admitted.
☐
Lemma N_instantiation_preserves_typing : ∀ {c e},
instantiation N N_closed c e →
∀ Gamma t S, (mupdate Gamma c) |-- t \in S →
Gamma |-- { (msubst e t) } \in S.
instantiation N N_closed c e →
∀ Gamma t S, (mupdate Gamma c) |-- t \in S →
Gamma |-- { (msubst e t) } \in S.
Proof.
(* 在这里填写 *) Admitted.
(* 在这里填写 *) Admitted.
☐
Lemma multistep_App2 : ∀ {v t t'},
value v → (t -->* t') → <{ v t }> -->* <{ v t' }>.
value v → (t -->* t') → <{ v t }> -->* <{ v t' }>.
Proof.
(* 在这里填写 *) Admitted.
(* 在这里填写 *) Admitted.
☐
为完成下面主引理的条件与积情形,你会需要类似引理;按需添加
(证明本质上相同)。
Lemma typable_N : ∀ c {t T},
tass_context c |-- t \in T →
∀ e,
instantiation N N_closed c e →
N T (msubst e t).
tass_context c |-- t \in T →
∀ e,
instantiation N N_closed c e →
N T (msubst e t).
Proof.
intros c t T HT.
(* 在调用归纳之前,我们需要把假设的形式稍作泛化 *)
remember (tass_context c) as Gamma.
generalize dependent c.
induction HT; intros c HeqGamma e V;
try rewrite HeqGamma in *; clear HeqGamma.
- (* T_Var *)
eapply instantiation_msubst; eauto.
- (* T_Abs *)
simpl.
split;[|split].
+ eapply N_instantiation_preserves_typing; eauto.
+ rewrite msubst_abs. apply value_halts. apply v_abs.
+ intros.
destruct (N_halts H) as [v [P Q]].
pose proof (multistep_preserves_N P H).
apply multistep_preserves_N' with (msubst ((x,v)::e) t1).
× eapply T_App.
-- eapply N_instantiation_preserves_typing; eauto.
-- eapply N_typable_empty; auto.
× rewrite msubst_abs.
eapply multi_trans.
-- eapply multistep_App2; eauto.
-- eapply multi_R.
simpl. rewrite msubst_subst.
++ eapply ST_AppAbs; eauto.
++ eapply typable_empty__closed.
apply (N_typable_empty H0).
++ eapply instantiation_env_closed; eauto.
× eapply (IHHT ((x,T2)::c)).
-- auto.
-- constructor; auto.
- (* T_App *)
rewrite msubst_app.
edestruct IHHT1 as [_ [_ P1]]; eauto. fold N in P1.
apply P1. eapply IHHT2; auto.
(* 在这里填写 *) Admitted.
intros c t T HT.
(* 在调用归纳之前,我们需要把假设的形式稍作泛化 *)
remember (tass_context c) as Gamma.
generalize dependent c.
induction HT; intros c HeqGamma e V;
try rewrite HeqGamma in *; clear HeqGamma.
- (* T_Var *)
eapply instantiation_msubst; eauto.
- (* T_Abs *)
simpl.
split;[|split].
+ eapply N_instantiation_preserves_typing; eauto.
+ rewrite msubst_abs. apply value_halts. apply v_abs.
+ intros.
destruct (N_halts H) as [v [P Q]].
pose proof (multistep_preserves_N P H).
apply multistep_preserves_N' with (msubst ((x,v)::e) t1).
× eapply T_App.
-- eapply N_instantiation_preserves_typing; eauto.
-- eapply N_typable_empty; auto.
× rewrite msubst_abs.
eapply multi_trans.
-- eapply multistep_App2; eauto.
-- eapply multi_R.
simpl. rewrite msubst_subst.
++ eapply ST_AppAbs; eauto.
++ eapply typable_empty__closed.
apply (N_typable_empty H0).
++ eapply instantiation_env_closed; eauto.
× eapply (IHHT ((x,T2)::c)).
-- auto.
-- constructor; auto.
- (* T_App *)
rewrite msubst_app.
edestruct IHHT1 as [_ [_ P1]]; eauto. fold N in P1.
apply P1. eapply IHHT2; auto.
(* 在这里填写 *) Admitted.
☐
最终定理:
通过逻辑谓词的类型安全性(可选)
第一次证明尝试
Theorem type_soundness_try1: ∀ t T, empty |-- t \in T → safe t.
Proof.
remember empty as Gamma. (* 与之前一样,我们必须这样做才能对
HT 做归纳。 *)
intros t T HT.
unfold safe.
induction HT; subst Gamma; intros t' ST.
- (* T_Var *)
(* 该情形不可能,因为 t 在空环境中可定型。 *)
inv H.
- (* T_Abs *)
(* 该情形立即成立,因为 t 已是值(且不能再走步)。 *)
inv ST.
+ econstructor.
+ inv H.
- (* T_App *)
intros NFt'.
(* 这是困难情形。t' 成为值的唯一方式是 ST 序列以某种方式
用到了 ST_AppAbs 规则。否则它会卡在某种应用项上,
而应用永不是值。要让该规则适用,t1 必须归约到抽象项,
t2 必须归约到值。费些劲我们可以确立这些事实…… *)
(* 首先,我们可分析 ST,看到 t1 在通往 t' 的路上某处
必须走步到规范形式(经零次或多次 ST_App1)。 *)
assert (N1: ∃ t1', t1 -->* t1'
∧ step_normal_form t1'
∧ <{ t1' t2 }> -->* t').
{ admit. (* 可对 ST 归纳证明 *) }
destruct N1 as [t1' [ST1 [NF1 RST1]]].
(* 第一个归纳假设说 t1' 必须是值。 *)
assert (V1: value t1') by (eapply IHHT1; eauto).
(* 现在可用保型性表明 t1' 具有类型 Ty_Arrow。 *)
assert (HT1': empty |-- t1' \in (T2 → T1)).
{ clear - HT1 ST1. induction ST1; eauto using preservation. }
(* 而 Ty_Arrow 类型的值必须是抽象项。 *)
inversion HT1'; subst; try (inv V1; fail).
(* 现在分析 RST1,我们可看到 t2 在通往 t1' 的路上某处
必须走步到规范形式(经零次或多次 ST_App2)。 *)
assert (N2: ∃ t2', t2 -->* t2'
∧ step_normal_form t2'
∧ <{ (\ x: T2, t0) t2' }> -->* t').
{ admit. (* 可对 RST1 归纳证明 *) }
destruct N2 as [t2' [ST2 [NF2 RST2]]].
(* 由第二个归纳假设,t2' 必须是值。 *)
assert (V2: value t2') by (eapply IHHT2; eauto).
(* 现在我们终于有足够事实来应用 St_AppAbs 规则。 *)
assert (ONE: <{ (\ x: T2, t0) t2' }> --> <{ [x := t2'] t0 }>).
{ apply ST_AppAbs; eauto. }
(* 但遗憾的是,我们没有任何归纳假设告诉我们关于 t0 行为的
信息。更不用说 [x := t2'] t0,它甚至不是我们原项 t 的
语法子项。因此对该情形我们不能再推进。(其余情形实际上
都成功通过了。) *)
Abort.
Proof.
remember empty as Gamma. (* 与之前一样,我们必须这样做才能对
HT 做归纳。 *)
intros t T HT.
unfold safe.
induction HT; subst Gamma; intros t' ST.
- (* T_Var *)
(* 该情形不可能,因为 t 在空环境中可定型。 *)
inv H.
- (* T_Abs *)
(* 该情形立即成立,因为 t 已是值(且不能再走步)。 *)
inv ST.
+ econstructor.
+ inv H.
- (* T_App *)
intros NFt'.
(* 这是困难情形。t' 成为值的唯一方式是 ST 序列以某种方式
用到了 ST_AppAbs 规则。否则它会卡在某种应用项上,
而应用永不是值。要让该规则适用,t1 必须归约到抽象项,
t2 必须归约到值。费些劲我们可以确立这些事实…… *)
(* 首先,我们可分析 ST,看到 t1 在通往 t' 的路上某处
必须走步到规范形式(经零次或多次 ST_App1)。 *)
assert (N1: ∃ t1', t1 -->* t1'
∧ step_normal_form t1'
∧ <{ t1' t2 }> -->* t').
{ admit. (* 可对 ST 归纳证明 *) }
destruct N1 as [t1' [ST1 [NF1 RST1]]].
(* 第一个归纳假设说 t1' 必须是值。 *)
assert (V1: value t1') by (eapply IHHT1; eauto).
(* 现在可用保型性表明 t1' 具有类型 Ty_Arrow。 *)
assert (HT1': empty |-- t1' \in (T2 → T1)).
{ clear - HT1 ST1. induction ST1; eauto using preservation. }
(* 而 Ty_Arrow 类型的值必须是抽象项。 *)
inversion HT1'; subst; try (inv V1; fail).
(* 现在分析 RST1,我们可看到 t2 在通往 t1' 的路上某处
必须走步到规范形式(经零次或多次 ST_App2)。 *)
assert (N2: ∃ t2', t2 -->* t2'
∧ step_normal_form t2'
∧ <{ (\ x: T2, t0) t2' }> -->* t').
{ admit. (* 可对 RST1 归纳证明 *) }
destruct N2 as [t2' [ST2 [NF2 RST2]]].
(* 由第二个归纳假设,t2' 必须是值。 *)
assert (V2: value t2') by (eapply IHHT2; eauto).
(* 现在我们终于有足够事实来应用 St_AppAbs 规则。 *)
assert (ONE: <{ (\ x: T2, t0) t2' }> --> <{ [x := t2'] t0 }>).
{ apply ST_AppAbs; eauto. }
(* 但遗憾的是,我们没有任何归纳假设告诉我们关于 t0 行为的
信息。更不用说 [x := t2'] t0,它甚至不是我们原项 t 的
语法子项。因此对该情形我们不能再推进。(其余情形实际上
都成功通过了。) *)
Abort.
St 与 Sv 谓词
Fixpoint St (T:ty) (t: tm) : Prop :=
∀ t', t -->* t' → step_normal_form t' → Sv T t'
with Sv (T:ty) (t:tm) {struct T} : Prop :=
closed t ∧
(match T with
| <{ Bool }> ⇒ (t = <{ true }> ∨ t = <{ false }> )
| <{ T1 → T2 }> ⇒
∃ x t2,
t = <{ \x:T1,t2 }> ∧
∀ s, Sv T1 s → St T2 <{ [x:=s] t2 }>
| <{ T1 × T2 }> ⇒ ... (* 留给你填 *)
end).
练习: 3 stars,高级,特别有用 (Sv_products)
修正本定义的积情形。注:在你准备开始扩展后面的证明之前, 可以先跳过本练习。
Fixpoint Sv (T:ty) (t:tm) {struct T} : Prop :=
closed t ∧
(match T with
| <{ Bool }> ⇒ (t = <{ true }> ∨ t = <{ false }> )
| <{ T1 → T2 }> ⇒
∃ x t2, t = <{ \x:T1,t2 }> ∧
(∀ s, Sv T1 s →
(∀ t', <{ [x := s] t2 }> -->* t' →
step_normal_form t' →
Sv T2 t'))
(* ... 处理积时编辑下一行 *)
| <{ T1 × T2 }> ⇒ False (* FILL IN HERE *)
end).
(* 不要修改下面这行: *)
Definition manual_grade_for_Sv_products : option (nat×string) := None.
☐
closed t ∧
(match T with
| <{ Bool }> ⇒ (t = <{ true }> ∨ t = <{ false }> )
| <{ T1 → T2 }> ⇒
∃ x t2, t = <{ \x:T1,t2 }> ∧
(∀ s, Sv T1 s →
(∀ t', <{ [x := s] t2 }> -->* t' →
step_normal_form t' →
Sv T2 t'))
(* ... 处理积时编辑下一行 *)
| <{ T1 × T2 }> ⇒ False (* FILL IN HERE *)
end).
(* 不要修改下面这行: *)
Definition manual_grade_for_Sv_products : option (nat×string) := None.
☐
Sv T 与 St T 有时称为类型 T 的「值解释」与「项(或
表达式)解释」。它们刻画了【行为应如】该类型成员的值与项。
注意这些谓词并【不】要求(语法)良型性。这对逻辑谓词证明而言
不寻常,但在这里是恰当的。毕竟我们正试图从新原则证明
类型安全性。若确实要求良型性,我们仍能让证明通过,
但只能借助 substitution_preserves_typing 引理。
而该引理是证明保型性所需的主要结果。
用我们这里采取的方法,可进性与保型性都不需要。
不过,我们确实明确要求 Sv 只含闭项。(若对 St 施加同样
要求,证明仍成立,但并无好处。)
我们先从这些定义的几条简单推论开始:
练习: 2 stars,标准 (Sv_val)
一旦你定义了 Sv 的积情形,补全 Sv 中项是值这一证明。
Lemma Sv_val : ∀ {T t}, Sv T t → value t.
Proof.
induction T; intros.
- inv H. destruct H1; subst; auto.
- inv H. destruct H1 as [x [t2 [E _]]]; subst; auto.
(* 在这里填写 *) Admitted.
induction T; intros.
- inv H. destruct H1; subst; auto.
- inv H. destruct H1 as [x [t2 [E _]]]; subst; auto.
(* 在这里填写 *) Admitted.
☐
Sv 中的项也在 St 中。
Lemma Sv_St : ∀ {T t}, Sv T t → St T t.
Proof.
intros.
unfold St.
intros. pose proof (Sv_val H). eapply value__normal in H2.
inv H0; auto.
exfalso; eapply H2. eexists; eauto.
Qed.
intros.
unfold St.
intros. pose proof (Sv_val H). eapply value__normal in H2.
inv H0; auto.
exfalso; eapply H2. eexists; eauto.
Qed.
我们已成功在 St 中刻画了安全性。(这有时称为 St 的
「充分性」定理。)
与规范化证明一样,我们需要通过定义闭替换来处理开项。
实例化机制对 Sv 的作用与对 N 相同。
Definition has_semantic_type (Gamma: context) (t:tm) (T:ty) : Prop :=
∀ (c:tass), Gamma = tass_context c →
∀ (e:env), instantiation Sv Sv_closed c e →
St T (msubst e t).
Notation "Gamma '|==' t '∈' T" := (has_semantic_type Gamma t T) (at level 40,
t custom stlc, T custom stlc at level 0).
∀ (c:tass), Gamma = tass_context c →
∀ (e:env), instantiation Sv Sv_closed c e →
St T (msubst e t).
Notation "Gamma '|==' t '∈' T" := (has_semantic_type Gamma t T) (at level 40,
t custom stlc, T custom stlc at level 0).
语义定型示例
先来一个方便的引理。
Lemma empty_context : ∀ {R RC c e},
instantiation R RC c e →
tass_context c = empty →
e = nil.
instantiation R RC c e →
tass_context c = empty →
e = nil.
Proof.
intros.
destruct c.
- inv H. auto.
- exfalso.
unfold tass_context in H0.
simpl in H0. destruct p.
assert (((s) ⊢> t; (mupdate empty c) s) = empty s) by (rewrite H0; auto).
rewrite update_eq in H1. rewrite apply_empty in H1. inv H1.
Qed.
intros.
destruct c.
- inv H. auto.
- exfalso.
unfold tass_context in H0.
simpl in H0. destruct p.
assert (((s) ⊢> t; (mupdate empty c) s) = empty s) by (rewrite H0; auto).
rewrite update_eq in H1. rewrite apply_empty in H1. inv H1.
Qed.
在第一个例子中,条件的两臂类型不同,但表达式归约到
Bool 值。
Remark hst_ex1 : empty |== <{ if true then false else (false,false) }> \in Ty_Bool.
Proof.
unfold has_semantic_type.
intros.
erewrite empty_context; eauto.
simpl.
unfold St.
intros.
inv H1.
+ unfold step_normal_form in H2. exfalso; apply H2; eauto.
+ inv H3.
× inv H4.
-- unfold Sv. split.
++ unfold closed. intros. intro. inv H1.
++ right; auto.
-- inv H1.
× inv H8.
Qed.
unfold has_semantic_type.
intros.
erewrite empty_context; eauto.
simpl.
unfold St.
intros.
inv H1.
+ unfold step_normal_form in H2. exfalso; apply H2; eauto.
+ inv H3.
× inv H4.
-- unfold Sv. split.
++ unfold closed. intros. intro. inv H1.
++ right; auto.
-- inv H1.
× inv H8.
Qed.
在第二个例子中,该项根本不会归约到值(事实上,它归约到
自身!)。因此它不仅语法上类型错误。规范化定理还告诉我们,
不存在能【使】它语法良型的变量绑定类型选择。
但我们可以给它任何我们喜欢的语义类型。
Definition x : string := "x".
Hint Unfold x : core.
Remark hst_ex2: ∀ T, empty |== <{ (\ x : Bool, (x x)) (\x : Bool, (x x)) }> \in T.
End Examples.
Hint Unfold x : core.
Remark hst_ex2: ∀ T, empty |== <{ (\ x : Bool, (x x)) (\x : Bool, (x x)) }> \in T.
Proof.
unfold has_semantic_type.
intros.
erewrite empty_context; eauto.
simpl.
unfold St.
intros.
remember <{ (\ x : Bool, (x x)) (\ x : Bool, (x x)) }> as t.
induction H1.
+ subst x0. unfold step_normal_form in H2. exfalso; apply H2. eexists. eauto.
+ subst x0. inv H1.
× simpl in H3. simpl <{ [x := \ x : Bool, x x] x x }> in IHmulti.
eauto.
× inv H7.
× inv H8.
Qed.
unfold has_semantic_type.
intros.
erewrite empty_context; eauto.
simpl.
unfold St.
intros.
remember <{ (\ x : Bool, (x x)) (\ x : Bool, (x x)) }> as t.
induction H1.
+ subst x0. unfold step_normal_form in H2. exfalso; apply H2. eexists. eauto.
+ subst x0. inv H1.
× simpl in H3. simpl <{ [x := \ x : Bool, x x] x x }> in IHmulti.
eauto.
× inv H7.
× inv H8.
Qed.
End Examples.
替换与实例化的更多性质
练习: 4 stars,标准 (instantiation_closes)
Lemma instantiation_closes: ∀ R RC c e,
instantiation R RC c e →
∀ t T, tass_context c |-- t \in T →
closed (msubst e t).
instantiation R RC c e →
∀ t T, tass_context c |-- t \in T →
closed (msubst e t).
Proof.
(* 提示:一旦找到归纳假设的合适泛化,该证明就相当直截了当。 *)
(* 在这里填写 *) Admitted.
(* 提示:一旦找到归纳假设的合适泛化,该证明就相当直截了当。 *)
(* 在这里填写 *) Admitted.
☐
关于多步归约的反演引理
Lemma value_dec : ∀ t, value t ∨ ¬ value t.
Proof.
induction t; try (right; intro X; inv X; fail); try (left; auto; fail).
destruct IHt1; destruct IHt2;
try (right; intro X; inv X; contradiction);
try (left; auto; fail).
Qed.
induction t; try (right; intro X; inv X; fail); try (left; auto; fail).
destruct IHt1; destruct IHt2;
try (right; intro X; inv X; contradiction);
try (left; auto; fail).
Qed.
☐
现在可以进行反演引理本身了。所有证明都极为相似。
Lemma norm_App1 : ∀ {t1 t2 t'},
<{ t1 t2 }> -->* t' → step_normal_form t' →
∃ t1', t1 -->* t1'
∧ step_normal_form t1'
∧ <{ t1' t2 }> -->* t'.
<{ t1 t2 }> -->* t' → step_normal_form t' →
∃ t1', t1 -->* t1'
∧ step_normal_form t1'
∧ <{ t1' t2 }> -->* t'.
Proof.
intros until 1.
remember <{ t1 t2 }> as t.
generalize dependent t1.
induction H; intros; subst x.
- ∃ t1.
split; [|split]; eauto.
intros [t' P]; eauto.
- destruct (nf_dec t1) as [P|[t1' P]]; eauto.
edestruct (IHmulti t1') as [t1'' [P1 [P2 P3]]]; eauto.
eapply step_deterministic; eauto.
Qed.
intros until 1.
remember <{ t1 t2 }> as t.
generalize dependent t1.
induction H; intros; subst x.
- ∃ t1.
split; [|split]; eauto.
intros [t' P]; eauto.
- destruct (nf_dec t1) as [P|[t1' P]]; eauto.
edestruct (IHmulti t1') as [t1'' [P1 [P2 P3]]]; eauto.
eapply step_deterministic; eauto.
Qed.
Lemma norm_App2 : ∀ {v1 t2 t'},
<{ v1 t2 }> -->* t' → value v1 →
step_normal_form t' →
∃ t2', t2 -->* t2'
∧ step_normal_form t2'
∧ <{ v1 t2' }> -->* t'.
<{ v1 t2 }> -->* t' → value v1 →
step_normal_form t' →
∃ t2', t2 -->* t2'
∧ step_normal_form t2'
∧ <{ v1 t2' }> -->* t'.
Proof.
(* 在这里填写 *) Admitted.
(* 在这里填写 *) Admitted.
☐
按需为下面主证明中的其他项形式添加类似引理。
Lemma syntactic_type_semantic : ∀ {Gamma t T},
Gamma |-- t \in T →
Gamma |== t \in T.
Gamma |-- t \in T →
Gamma |== t \in T.
Proof.
unfold has_semantic_type.
intros Gamma t T HT.
induction HT; intros c E e V; try rewrite E in *; clear E.
- (* T_Var *)
eapply Sv_St.
eapply instantiation_msubst; eauto.
- (* T_Abs *)
unfold St.
rewrite msubst_abs.
intros.
inv H; [| inv H1].
unfold Sv; fold Sv; split.
+ rewrite <- msubst_abs. eapply instantiation_closes; eauto.
+ eexists. eexists. split; [eauto|].
intros s H.
pose proof (Sv_closed _ _ H).
pose proof (instantiation_env_closed V).
intros.
rewrite <- msubst_subst in H3; auto.
replace (msubst e <{ [x := s] t1 }>)
with (msubst ((x,s)::e) t1) in H3 by auto.
eapply (IHHT ((x,T2)::c)); eauto.
constructor; auto. eapply Sv_val; eauto.
- (* T_App *)
pose proof (IHHT1 _ eq_refl _ V).
pose proof (IHHT2 _ eq_refl _ V).
unfold St.
rewrite msubst_app.
intros.
destruct (norm_App1 H1 H2) as [t1' [S1 [S2 S3]]].
pose proof (H _ S1 S2).
inv H3. destruct H5 as [x [t11 [E P]]].
subst t1'.
assert (value <{ \x : T2, t11 }>) by eauto.
destruct (norm_App2 S3 H3 H2) as [t2' [Q1 [Q2 Q3]]].
pose proof (H0 _ Q1 Q2).
pose proof (P _ H5).
eapply H6; auto.
pose proof (Sv_val H5).
pose proof (ST_AppAbs x T2 t11 t2' H7).
inv Q3.
+ exfalso. eapply H2. eexists; eauto.
+ erewrite (step_deterministic _ _ _ H9 H8) in H10.
eauto.
(* 在这里填写 *) Admitted.
unfold has_semantic_type.
intros Gamma t T HT.
induction HT; intros c E e V; try rewrite E in *; clear E.
- (* T_Var *)
eapply Sv_St.
eapply instantiation_msubst; eauto.
- (* T_Abs *)
unfold St.
rewrite msubst_abs.
intros.
inv H; [| inv H1].
unfold Sv; fold Sv; split.
+ rewrite <- msubst_abs. eapply instantiation_closes; eauto.
+ eexists. eexists. split; [eauto|].
intros s H.
pose proof (Sv_closed _ _ H).
pose proof (instantiation_env_closed V).
intros.
rewrite <- msubst_subst in H3; auto.
replace (msubst e <{ [x := s] t1 }>)
with (msubst ((x,s)::e) t1) in H3 by auto.
eapply (IHHT ((x,T2)::c)); eauto.
constructor; auto. eapply Sv_val; eauto.
- (* T_App *)
pose proof (IHHT1 _ eq_refl _ V).
pose proof (IHHT2 _ eq_refl _ V).
unfold St.
rewrite msubst_app.
intros.
destruct (norm_App1 H1 H2) as [t1' [S1 [S2 S3]]].
pose proof (H _ S1 S2).
inv H3. destruct H5 as [x [t11 [E P]]].
subst t1'.
assert (value <{ \x : T2, t11 }>) by eauto.
destruct (norm_App2 S3 H3 H2) as [t2' [Q1 [Q2 Q3]]].
pose proof (H0 _ Q1 Q2).
pose proof (P _ H5).
eapply H6; auto.
pose proof (Sv_val H5).
pose proof (ST_AppAbs x T2 t11 t2' H7).
inv Q3.
+ exfalso. eapply H2. eexists; eauto.
+ erewrite (step_deterministic _ _ _ H9 H8) in H10.
eauto.
(* 在这里填写 *) Admitted.
☐
