| author | haftmann | 
| Tue, 12 May 2009 16:11:36 +0200 | |
| changeset 31121 | f79a0d03b75f | 
| parent 29300 | e841a9de5445 | 
| child 34915 | 7894c7dab132 | 
| permissions | -rw-r--r-- | 
| 25867 | 1  | 
(* *)  | 
2  | 
(* Formalisation of some typical SOS-proofs. *)  | 
|
3  | 
(* *)  | 
|
4  | 
(* This work was inspired by challenge suggested by Adam *)  | 
|
5  | 
(* Chlipala on the POPLmark mailing list. *)  | 
|
6  | 
(* *)  | 
|
7  | 
(* We thank Nick Benton for helping us with the *)  | 
|
8  | 
(* termination-proof for evaluation. *)  | 
|
9  | 
(* *)  | 
|
10  | 
(* The formalisation was done by Julien Narboux and *)  | 
|
11  | 
(* Christian Urban. *)  | 
|
| 22447 | 12  | 
|
13  | 
theory SOS  | 
|
| 28568 | 14  | 
imports "Nominal"  | 
| 22447 | 15  | 
begin  | 
16  | 
||
| 
23158
 
749b6870b1a1
introduced symmetric variants of the lemmas for alpha-equivalence
 
urbanc 
parents: 
22730 
diff
changeset
 | 
17  | 
atom_decl name  | 
| 22447 | 18  | 
|
| 25832 | 19  | 
text {* types and terms *}
 | 
| 22447 | 20  | 
nominal_datatype ty =  | 
| 25832 | 21  | 
TVar "nat"  | 
| 22447 | 22  | 
  | Arrow "ty" "ty" ("_\<rightarrow>_" [100,100] 100)
 | 
23  | 
||
24  | 
nominal_datatype trm =  | 
|
25  | 
Var "name"  | 
|
26  | 
  | Lam "\<guillemotleft>name\<guillemotright>trm" ("Lam [_]._" [100,100] 100)
 | 
|
27  | 
| App "trm" "trm"  | 
|
28  | 
||
| 25832 | 29  | 
lemma fresh_ty:  | 
| 22447 | 30  | 
fixes x::"name"  | 
31  | 
and T::"ty"  | 
|
32  | 
shows "x\<sharp>T"  | 
|
| 
26966
 
071f40487734
made the naming of the induction principles consistent: weak_induct is
 
urbanc 
parents: 
26806 
diff
changeset
 | 
33  | 
by (induct T rule: ty.induct)  | 
| 25832 | 34  | 
(auto simp add: fresh_nat)  | 
| 22447 | 35  | 
|
| 25832 | 36  | 
text {* Parallel and single substitution. *}
 | 
| 22447 | 37  | 
fun  | 
38  | 
lookup :: "(name\<times>trm) list \<Rightarrow> name \<Rightarrow> trm"  | 
|
39  | 
where  | 
|
40  | 
"lookup [] x = Var x"  | 
|
| 22502 | 41  | 
| "lookup ((y,e)#\<theta>) x = (if x=y then e else lookup \<theta> x)"  | 
| 22447 | 42  | 
|
| 25832 | 43  | 
lemma lookup_eqvt[eqvt]:  | 
| 22447 | 44  | 
fixes pi::"name prm"  | 
45  | 
shows "pi\<bullet>(lookup \<theta> X) = lookup (pi\<bullet>\<theta>) (pi\<bullet>X)"  | 
|
| 25832 | 46  | 
by (induct \<theta>) (auto simp add: eqvts)  | 
| 22447 | 47  | 
|
48  | 
lemma lookup_fresh:  | 
|
49  | 
fixes z::"name"  | 
|
| 25832 | 50  | 
assumes a: "z\<sharp>\<theta>" and b: "z\<sharp>x"  | 
| 22447 | 51  | 
shows "z \<sharp>lookup \<theta> x"  | 
| 25832 | 52  | 
using a b  | 
| 22447 | 53  | 
by (induct rule: lookup.induct) (auto simp add: fresh_list_cons)  | 
54  | 
||
55  | 
lemma lookup_fresh':  | 
|
56  | 
assumes "z\<sharp>\<theta>"  | 
|
57  | 
shows "lookup \<theta> z = Var z"  | 
|
58  | 
using assms  | 
|
59  | 
by (induct rule: lookup.induct)  | 
|
60  | 
(auto simp add: fresh_list_cons fresh_prod fresh_atm)  | 
|
61  | 
||
| 25832 | 62  | 
(* parallel substitution *)  | 
| 28568 | 63  | 
|
| 
29097
 
68245155eb58
Modified nominal_primrec to make it work with local theories, unified syntax
 
berghofe 
parents: 
28568 
diff
changeset
 | 
64  | 
nominal_primrec  | 
| 22447 | 65  | 
  psubst :: "(name\<times>trm) list \<Rightarrow> trm \<Rightarrow> trm"  ("_<_>" [95,95] 105)
 | 
| 
29097
 
68245155eb58
Modified nominal_primrec to make it work with local theories, unified syntax
 
berghofe 
parents: 
28568 
diff
changeset
 | 
66  | 
where  | 
| 22447 | 67  | 
"\<theta><(Var x)> = (lookup \<theta> x)"  | 
| 
29097
 
68245155eb58
Modified nominal_primrec to make it work with local theories, unified syntax
 
berghofe 
parents: 
28568 
diff
changeset
 | 
68  | 
| "\<theta><(App e\<^isub>1 e\<^isub>2)> = App (\<theta><e\<^isub>1>) (\<theta><e\<^isub>2>)"  | 
| 
 
68245155eb58
Modified nominal_primrec to make it work with local theories, unified syntax
 
berghofe 
parents: 
28568 
diff
changeset
 | 
69  | 
| "x\<sharp>\<theta> \<Longrightarrow> \<theta><(Lam [x].e)> = Lam [x].(\<theta><e>)"  | 
| 25832 | 70  | 
apply(finite_guess)+  | 
| 22472 | 71  | 
apply(rule TrueI)+  | 
72  | 
apply(simp add: abs_fresh)+  | 
|
| 25832 | 73  | 
apply(fresh_guess)+  | 
| 22472 | 74  | 
done  | 
| 22447 | 75  | 
|
76  | 
lemma psubst_eqvt[eqvt]:  | 
|
77  | 
fixes pi::"name prm"  | 
|
78  | 
and t::"trm"  | 
|
79  | 
shows "pi\<bullet>(\<theta><t>) = (pi\<bullet>\<theta>)<(pi\<bullet>t)>"  | 
|
| 
26966
 
071f40487734
made the naming of the induction principles consistent: weak_induct is
 
urbanc 
parents: 
26806 
diff
changeset
 | 
80  | 
by (nominal_induct t avoiding: \<theta> rule: trm.strong_induct)  | 
| 22472 | 81  | 
(perm_simp add: fresh_bij lookup_eqvt)+  | 
| 22447 | 82  | 
|
83  | 
lemma fresh_psubst:  | 
|
84  | 
fixes z::"name"  | 
|
85  | 
and t::"trm"  | 
|
86  | 
assumes "z\<sharp>t" and "z\<sharp>\<theta>"  | 
|
87  | 
shows "z\<sharp>(\<theta><t>)"  | 
|
88  | 
using assms  | 
|
| 
26966
 
071f40487734
made the naming of the induction principles consistent: weak_induct is
 
urbanc 
parents: 
26806 
diff
changeset
 | 
89  | 
by (nominal_induct t avoiding: z \<theta> t rule: trm.strong_induct)  | 
| 22447 | 90  | 
(auto simp add: abs_fresh lookup_fresh)  | 
91  | 
||
| 25832 | 92  | 
lemma psubst_empty[simp]:  | 
93  | 
shows "[]<t> = t"  | 
|
| 
26966
 
071f40487734
made the naming of the induction principles consistent: weak_induct is
 
urbanc 
parents: 
26806 
diff
changeset
 | 
94  | 
by (nominal_induct t rule: trm.strong_induct)  | 
| 25832 | 95  | 
(auto simp add: fresh_list_nil)  | 
96  | 
||
| 25867 | 97  | 
text {* Single substitution *}
 | 
| 22447 | 98  | 
abbreviation  | 
| 25832 | 99  | 
  subst :: "trm \<Rightarrow> name \<Rightarrow> trm \<Rightarrow> trm" ("_[_::=_]" [100,100,100] 100)
 | 
100  | 
where  | 
|
101  | 
"t[x::=t'] \<equiv> ([(x,t')])<t>"  | 
|
| 22447 | 102  | 
|
103  | 
lemma subst[simp]:  | 
|
104  | 
shows "(Var x)[y::=t'] = (if x=y then t' else (Var x))"  | 
|
105  | 
and "(App t\<^isub>1 t\<^isub>2)[y::=t'] = App (t\<^isub>1[y::=t']) (t\<^isub>2[y::=t'])"  | 
|
106  | 
and "x\<sharp>(y,t') \<Longrightarrow> (Lam [x].t)[y::=t'] = Lam [x].(t[y::=t'])"  | 
|
| 22472 | 107  | 
by (simp_all add: fresh_list_cons fresh_list_nil)  | 
| 22447 | 108  | 
|
109  | 
lemma fresh_subst:  | 
|
110  | 
fixes z::"name"  | 
|
| 28568 | 111  | 
shows "\<lbrakk>z\<sharp>s; (z=y \<or> z\<sharp>t)\<rbrakk> \<Longrightarrow> z\<sharp>t[y::=s]"  | 
112  | 
by (nominal_induct t avoiding: z y s rule: trm.strong_induct)  | 
|
113  | 
(auto simp add: abs_fresh fresh_prod fresh_atm)  | 
|
| 22447 | 114  | 
|
115  | 
lemma forget:  | 
|
| 25867 | 116  | 
assumes a: "x\<sharp>e"  | 
| 25832 | 117  | 
shows "e[x::=e'] = e"  | 
| 25867 | 118  | 
using a  | 
| 
26966
 
071f40487734
made the naming of the induction principles consistent: weak_induct is
 
urbanc 
parents: 
26806 
diff
changeset
 | 
119  | 
by (nominal_induct e avoiding: x e' rule: trm.strong_induct)  | 
| 25867 | 120  | 
(auto simp add: fresh_atm abs_fresh)  | 
| 22447 | 121  | 
|
122  | 
lemma psubst_subst_psubst:  | 
|
| 25867 | 123  | 
assumes h: "x\<sharp>\<theta>"  | 
| 25832 | 124  | 
shows "\<theta><e>[x::=e'] = ((x,e')#\<theta>)<e>"  | 
125  | 
using h  | 
|
| 
26966
 
071f40487734
made the naming of the induction principles consistent: weak_induct is
 
urbanc 
parents: 
26806 
diff
changeset
 | 
126  | 
by (nominal_induct e avoiding: \<theta> x e' rule: trm.strong_induct)  | 
| 25867 | 127  | 
(auto simp add: fresh_list_cons fresh_atm forget lookup_fresh lookup_fresh')  | 
| 22447 | 128  | 
|
| 25832 | 129  | 
text {* Typing Judgements *}
 | 
| 22447 | 130  | 
|
| 23760 | 131  | 
inductive  | 
| 25832 | 132  | 
valid :: "(name\<times>ty) list \<Rightarrow> bool"  | 
| 22447 | 133  | 
where  | 
| 25832 | 134  | 
v_nil[intro]: "valid []"  | 
135  | 
| v_cons[intro]: "\<lbrakk>valid \<Gamma>;x\<sharp>\<Gamma>\<rbrakk> \<Longrightarrow> valid ((x,T)#\<Gamma>)"  | 
|
| 22447 | 136  | 
|
| 22534 | 137  | 
equivariance valid  | 
| 22447 | 138  | 
|
| 25832 | 139  | 
inductive_cases  | 
| 28568 | 140  | 
valid_elim[elim]: "valid ((x,T)#\<Gamma>)"  | 
| 22447 | 141  | 
|
| 28568 | 142  | 
lemma valid_insert:  | 
143  | 
assumes a: "valid (\<Delta>@[(x,T)]@\<Gamma>)"  | 
|
144  | 
shows "valid (\<Delta> @ \<Gamma>)"  | 
|
145  | 
using a  | 
|
146  | 
by (induct \<Delta>)  | 
|
147  | 
(auto simp add: fresh_list_append fresh_list_cons elim!: valid_elim)  | 
|
| 22447 | 148  | 
|
| 28568 | 149  | 
lemma fresh_set:  | 
150  | 
shows "y\<sharp>xs = (\<forall>x\<in>set xs. y\<sharp>x)"  | 
|
151  | 
by (induct xs) (simp_all add: fresh_list_nil fresh_list_cons)  | 
|
152  | 
||
153  | 
lemma context_unique:  | 
|
154  | 
assumes a1: "valid \<Gamma>"  | 
|
155  | 
and a2: "(x,T) \<in> set \<Gamma>"  | 
|
156  | 
and a3: "(x,U) \<in> set \<Gamma>"  | 
|
157  | 
shows "T = U"  | 
|
158  | 
using a1 a2 a3  | 
|
159  | 
by (induct) (auto simp add: fresh_set fresh_prod fresh_atm)  | 
|
| 22447 | 160  | 
|
| 25867 | 161  | 
text {* Typing Relation *}
 | 
162  | 
||
| 23760 | 163  | 
inductive  | 
| 22447 | 164  | 
  typing :: "(name\<times>ty) list\<Rightarrow>trm\<Rightarrow>ty\<Rightarrow>bool" ("_ \<turnstile> _ : _" [60,60,60] 60) 
 | 
165  | 
where  | 
|
| 25832 | 166  | 
t_Var[intro]: "\<lbrakk>valid \<Gamma>; (x,T)\<in>set \<Gamma>\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> Var x : T"  | 
167  | 
| t_App[intro]: "\<lbrakk>\<Gamma> \<turnstile> e\<^isub>1 : T\<^isub>1\<rightarrow>T\<^isub>2; \<Gamma> \<turnstile> e\<^isub>2 : T\<^isub>1\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> App e\<^isub>1 e\<^isub>2 : T\<^isub>2"  | 
|
| 22447 | 168  | 
| t_Lam[intro]: "\<lbrakk>x\<sharp>\<Gamma>; (x,T\<^isub>1)#\<Gamma> \<turnstile> e : T\<^isub>2\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> Lam [x].e : T\<^isub>1\<rightarrow>T\<^isub>2"  | 
169  | 
||
| 
22730
 
8bcc8809ed3b
nominal_inductive no longer proves equivariance.
 
berghofe 
parents: 
22650 
diff
changeset
 | 
170  | 
equivariance typing  | 
| 
 
8bcc8809ed3b
nominal_inductive no longer proves equivariance.
 
berghofe 
parents: 
22650 
diff
changeset
 | 
171  | 
|
| 22531 | 172  | 
nominal_inductive typing  | 
| 25832 | 173  | 
by (simp_all add: abs_fresh fresh_ty)  | 
| 22531 | 174  | 
|
| 22472 | 175  | 
lemma typing_implies_valid:  | 
| 25832 | 176  | 
assumes a: "\<Gamma> \<turnstile> t : T"  | 
| 22447 | 177  | 
shows "valid \<Gamma>"  | 
| 28568 | 178  | 
using a by (induct) (auto)  | 
179  | 
||
180  | 
||
181  | 
lemma t_App_elim:  | 
|
182  | 
assumes a: "\<Gamma> \<turnstile> App t1 t2 : T"  | 
|
183  | 
obtains T' where "\<Gamma> \<turnstile> t1 : T' \<rightarrow> T" and "\<Gamma> \<turnstile> t2 : T'"  | 
|
184  | 
using a  | 
|
185  | 
by (cases) (auto simp add: trm.inject)  | 
|
| 22447 | 186  | 
|
| 25832 | 187  | 
lemma t_Lam_elim:  | 
| 25867 | 188  | 
assumes a: "\<Gamma> \<turnstile> Lam [x].t : T" "x\<sharp>\<Gamma>"  | 
| 22447 | 189  | 
obtains T\<^isub>1 and T\<^isub>2 where "(x,T\<^isub>1)#\<Gamma> \<turnstile> t : T\<^isub>2" and "T=T\<^isub>1\<rightarrow>T\<^isub>2"  | 
| 25867 | 190  | 
using a  | 
| 25832 | 191  | 
by (cases rule: typing.strong_cases [where x="x"])  | 
192  | 
(auto simp add: abs_fresh fresh_ty alpha trm.inject)  | 
|
| 22447 | 193  | 
|
| 25832 | 194  | 
abbreviation  | 
195  | 
  "sub_context" :: "(name\<times>ty) list \<Rightarrow> (name\<times>ty) list \<Rightarrow> bool" ("_ \<subseteq> _" [55,55] 55)
 | 
|
196  | 
where  | 
|
197  | 
"\<Gamma>\<^isub>1 \<subseteq> \<Gamma>\<^isub>2 \<equiv> \<forall>x T. (x,T)\<in>set \<Gamma>\<^isub>1 \<longrightarrow> (x,T)\<in>set \<Gamma>\<^isub>2"  | 
|
| 22447 | 198  | 
|
199  | 
lemma weakening:  | 
|
| 25832 | 200  | 
fixes \<Gamma>\<^isub>1 \<Gamma>\<^isub>2::"(name\<times>ty) list"  | 
| 
22650
 
0c5b22076fb3
tuned the proof of lemma pt_list_set_fresh (as suggested by Randy Pollack) and tuned the syntax for sub_contexts
 
urbanc 
parents: 
22594 
diff
changeset
 | 
201  | 
assumes "\<Gamma>\<^isub>1 \<turnstile> e: T" and "valid \<Gamma>\<^isub>2" and "\<Gamma>\<^isub>1 \<subseteq> \<Gamma>\<^isub>2"  | 
| 22447 | 202  | 
shows "\<Gamma>\<^isub>2 \<turnstile> e: T"  | 
203  | 
using assms  | 
|
| 22534 | 204  | 
proof(nominal_induct \<Gamma>\<^isub>1 e T avoiding: \<Gamma>\<^isub>2 rule: typing.strong_induct)  | 
| 22447 | 205  | 
case (t_Lam x \<Gamma>\<^isub>1 T\<^isub>1 t T\<^isub>2 \<Gamma>\<^isub>2)  | 
| 25832 | 206  | 
have vc: "x\<sharp>\<Gamma>\<^isub>2" by fact  | 
| 
22650
 
0c5b22076fb3
tuned the proof of lemma pt_list_set_fresh (as suggested by Randy Pollack) and tuned the syntax for sub_contexts
 
urbanc 
parents: 
22594 
diff
changeset
 | 
207  | 
have ih: "\<lbrakk>valid ((x,T\<^isub>1)#\<Gamma>\<^isub>2); (x,T\<^isub>1)#\<Gamma>\<^isub>1 \<subseteq> (x,T\<^isub>1)#\<Gamma>\<^isub>2\<rbrakk> \<Longrightarrow> (x,T\<^isub>1)#\<Gamma>\<^isub>2 \<turnstile> t : T\<^isub>2" by fact  | 
| 25832 | 208  | 
have "valid \<Gamma>\<^isub>2" by fact  | 
209  | 
then have "valid ((x,T\<^isub>1)#\<Gamma>\<^isub>2)" using vc by auto  | 
|
210  | 
moreover  | 
|
211  | 
have "\<Gamma>\<^isub>1 \<subseteq> \<Gamma>\<^isub>2" by fact  | 
|
212  | 
then have "(x,T\<^isub>1)#\<Gamma>\<^isub>1 \<subseteq> (x,T\<^isub>1)#\<Gamma>\<^isub>2" by simp  | 
|
| 22447 | 213  | 
ultimately have "(x,T\<^isub>1)#\<Gamma>\<^isub>2 \<turnstile> t : T\<^isub>2" using ih by simp  | 
| 25832 | 214  | 
with vc show "\<Gamma>\<^isub>2 \<turnstile> Lam [x].t : T\<^isub>1\<rightarrow>T\<^isub>2" by auto  | 
| 22447 | 215  | 
qed (auto)  | 
216  | 
||
| 28568 | 217  | 
lemma type_substitutivity_aux:  | 
218  | 
assumes a: "(\<Delta>@[(x,T')]@\<Gamma>) \<turnstile> e : T"  | 
|
219  | 
and b: "\<Gamma> \<turnstile> e' : T'"  | 
|
220  | 
shows "(\<Delta>@\<Gamma>) \<turnstile> e[x::=e'] : T"  | 
|
221  | 
using a b  | 
|
222  | 
proof (nominal_induct \<Gamma>\<equiv>"\<Delta>@[(x,T')]@\<Gamma>" e T avoiding: e' \<Delta> rule: typing.strong_induct)  | 
|
223  | 
case (t_Var \<Gamma>' y T e' \<Delta>)  | 
|
224  | 
then have a1: "valid (\<Delta>@[(x,T')]@\<Gamma>)"  | 
|
225  | 
and a2: "(y,T) \<in> set (\<Delta>@[(x,T')]@\<Gamma>)"  | 
|
226  | 
and a3: "\<Gamma> \<turnstile> e' : T'" by simp_all  | 
|
227  | 
from a1 have a4: "valid (\<Delta>@\<Gamma>)" by (rule valid_insert)  | 
|
228  | 
  { assume eq: "x=y"
 | 
|
229  | 
from a1 a2 have "T=T'" using eq by (auto intro: context_unique)  | 
|
230  | 
with a3 have "\<Delta>@\<Gamma> \<turnstile> Var y[x::=e'] : T" using eq a4 by (auto intro: weakening)  | 
|
231  | 
}  | 
|
232  | 
moreover  | 
|
233  | 
  { assume ineq: "x\<noteq>y"
 | 
|
234  | 
from a2 have "(y,T) \<in> set (\<Delta>@\<Gamma>)" using ineq by simp  | 
|
235  | 
then have "\<Delta>@\<Gamma> \<turnstile> Var y[x::=e'] : T" using ineq a4 by auto  | 
|
236  | 
}  | 
|
237  | 
ultimately show "\<Delta>@\<Gamma> \<turnstile> Var y[x::=e'] : T" by blast  | 
|
238  | 
qed (force simp add: fresh_list_append fresh_list_cons)+  | 
|
| 22447 | 239  | 
|
| 28568 | 240  | 
corollary type_substitutivity:  | 
241  | 
assumes a: "(x,T')#\<Gamma> \<turnstile> e : T"  | 
|
242  | 
and b: "\<Gamma> \<turnstile> e' : T'"  | 
|
| 22447 | 243  | 
shows "\<Gamma> \<turnstile> e[x::=e'] : T"  | 
| 28568 | 244  | 
using a b type_substitutivity_aux[where \<Delta>="[]"]  | 
245  | 
by (auto)  | 
|
| 25832 | 246  | 
|
247  | 
text {* Values *}
 | 
|
248  | 
inductive  | 
|
249  | 
val :: "trm\<Rightarrow>bool"  | 
|
250  | 
where  | 
|
251  | 
v_Lam[intro]: "val (Lam [x].e)"  | 
|
252  | 
||
253  | 
equivariance val  | 
|
254  | 
||
255  | 
lemma not_val_App[simp]:  | 
|
256  | 
shows  | 
|
257  | 
"\<not> val (App e\<^isub>1 e\<^isub>2)"  | 
|
258  | 
"\<not> val (Var x)"  | 
|
259  | 
by (auto elim: val.cases)  | 
|
| 22447 | 260  | 
|
261  | 
text {* Big-Step Evaluation *}
 | 
|
262  | 
||
| 23760 | 263  | 
inductive  | 
| 22447 | 264  | 
  big :: "trm\<Rightarrow>trm\<Rightarrow>bool" ("_ \<Down> _" [80,80] 80) 
 | 
265  | 
where  | 
|
266  | 
b_Lam[intro]: "Lam [x].e \<Down> Lam [x].e"  | 
|
267  | 
| b_App[intro]: "\<lbrakk>x\<sharp>(e\<^isub>1,e\<^isub>2,e'); e\<^isub>1\<Down>Lam [x].e; e\<^isub>2\<Down>e\<^isub>2'; e[x::=e\<^isub>2']\<Down>e'\<rbrakk> \<Longrightarrow> App e\<^isub>1 e\<^isub>2 \<Down> e'"  | 
|
268  | 
||
| 
22730
 
8bcc8809ed3b
nominal_inductive no longer proves equivariance.
 
berghofe 
parents: 
22650 
diff
changeset
 | 
269  | 
equivariance big  | 
| 
 
8bcc8809ed3b
nominal_inductive no longer proves equivariance.
 
berghofe 
parents: 
22650 
diff
changeset
 | 
270  | 
|
| 22447 | 271  | 
nominal_inductive big  | 
| 25832 | 272  | 
by (simp_all add: abs_fresh)  | 
| 22447 | 273  | 
|
| 25832 | 274  | 
lemma big_preserves_fresh:  | 
275  | 
fixes x::"name"  | 
|
276  | 
assumes a: "e \<Down> e'" "x\<sharp>e"  | 
|
277  | 
shows "x\<sharp>e'"  | 
|
278  | 
using a by (induct) (auto simp add: abs_fresh fresh_subst)  | 
|
| 22447 | 279  | 
|
| 25832 | 280  | 
lemma b_App_elim:  | 
281  | 
assumes a: "App e\<^isub>1 e\<^isub>2 \<Down> e'" "x\<sharp>(e\<^isub>1,e\<^isub>2,e')"  | 
|
282  | 
obtains f\<^isub>1 and f\<^isub>2 where "e\<^isub>1 \<Down> Lam [x]. f\<^isub>1" "e\<^isub>2 \<Down> f\<^isub>2" "f\<^isub>1[x::=f\<^isub>2] \<Down> e'"  | 
|
283  | 
using a  | 
|
284  | 
by (cases rule: big.strong_cases[where x="x" and xa="x"])  | 
|
285  | 
(auto simp add: trm.inject)  | 
|
| 22447 | 286  | 
|
287  | 
lemma subject_reduction:  | 
|
| 25832 | 288  | 
assumes a: "e \<Down> e'" and b: "\<Gamma> \<turnstile> e : T"  | 
| 22447 | 289  | 
shows "\<Gamma> \<turnstile> e' : T"  | 
| 22472 | 290  | 
using a b  | 
| 22534 | 291  | 
proof (nominal_induct avoiding: \<Gamma> arbitrary: T rule: big.strong_induct)  | 
292  | 
case (b_App x e\<^isub>1 e\<^isub>2 e' e e\<^isub>2' \<Gamma> T)  | 
|
| 22447 | 293  | 
have vc: "x\<sharp>\<Gamma>" by fact  | 
294  | 
have "\<Gamma> \<turnstile> App e\<^isub>1 e\<^isub>2 : T" by fact  | 
|
| 25832 | 295  | 
then obtain T' where a1: "\<Gamma> \<turnstile> e\<^isub>1 : T'\<rightarrow>T" and a2: "\<Gamma> \<turnstile> e\<^isub>2 : T'"  | 
296  | 
by (cases) (auto simp add: trm.inject)  | 
|
| 22472 | 297  | 
have ih1: "\<Gamma> \<turnstile> e\<^isub>1 : T' \<rightarrow> T \<Longrightarrow> \<Gamma> \<turnstile> Lam [x].e : T' \<rightarrow> T" by fact  | 
| 22447 | 298  | 
have ih2: "\<Gamma> \<turnstile> e\<^isub>2 : T' \<Longrightarrow> \<Gamma> \<turnstile> e\<^isub>2' : T'" by fact  | 
299  | 
have ih3: "\<Gamma> \<turnstile> e[x::=e\<^isub>2'] : T \<Longrightarrow> \<Gamma> \<turnstile> e' : T" by fact  | 
|
300  | 
have "\<Gamma> \<turnstile> Lam [x].e : T'\<rightarrow>T" using ih1 a1 by simp  | 
|
| 25832 | 301  | 
then have "((x,T')#\<Gamma>) \<turnstile> e : T" using vc  | 
302  | 
by (auto elim: t_Lam_elim simp add: ty.inject)  | 
|
| 22447 | 303  | 
moreover  | 
304  | 
have "\<Gamma> \<turnstile> e\<^isub>2': T'" using ih2 a2 by simp  | 
|
| 28568 | 305  | 
ultimately have "\<Gamma> \<turnstile> e[x::=e\<^isub>2'] : T" by (simp add: type_substitutivity)  | 
| 22447 | 306  | 
thus "\<Gamma> \<turnstile> e' : T" using ih3 by simp  | 
| 28568 | 307  | 
qed (blast)  | 
308  | 
||
309  | 
lemma subject_reduction2:  | 
|
310  | 
assumes a: "e \<Down> e'" and b: "\<Gamma> \<turnstile> e : T"  | 
|
311  | 
shows "\<Gamma> \<turnstile> e' : T"  | 
|
312  | 
using a b  | 
|
313  | 
by (nominal_induct avoiding: \<Gamma> T rule: big.strong_induct)  | 
|
314  | 
(force elim: t_App_elim t_Lam_elim simp add: ty.inject type_substitutivity)+  | 
|
| 22447 | 315  | 
|
| 22472 | 316  | 
lemma unicity_of_evaluation:  | 
317  | 
assumes a: "e \<Down> e\<^isub>1"  | 
|
318  | 
and b: "e \<Down> e\<^isub>2"  | 
|
| 22447 | 319  | 
shows "e\<^isub>1 = e\<^isub>2"  | 
| 22472 | 320  | 
using a b  | 
| 22534 | 321  | 
proof (nominal_induct e e\<^isub>1 avoiding: e\<^isub>2 rule: big.strong_induct)  | 
| 22447 | 322  | 
case (b_Lam x e t\<^isub>2)  | 
323  | 
have "Lam [x].e \<Down> t\<^isub>2" by fact  | 
|
324  | 
thus "Lam [x].e = t\<^isub>2" by (cases, simp_all add: trm.inject)  | 
|
325  | 
next  | 
|
| 22534 | 326  | 
case (b_App x e\<^isub>1 e\<^isub>2 e' e\<^isub>1' e\<^isub>2' t\<^isub>2)  | 
| 22447 | 327  | 
have ih1: "\<And>t. e\<^isub>1 \<Down> t \<Longrightarrow> Lam [x].e\<^isub>1' = t" by fact  | 
328  | 
have ih2:"\<And>t. e\<^isub>2 \<Down> t \<Longrightarrow> e\<^isub>2' = t" by fact  | 
|
329  | 
have ih3: "\<And>t. e\<^isub>1'[x::=e\<^isub>2'] \<Down> t \<Longrightarrow> e' = t" by fact  | 
|
| 22472 | 330  | 
have app: "App e\<^isub>1 e\<^isub>2 \<Down> t\<^isub>2" by fact  | 
| 29300 | 331  | 
have vc: "x\<sharp>e\<^isub>1" "x\<sharp>e\<^isub>2" "x\<sharp>t\<^isub>2" by fact+  | 
| 25832 | 332  | 
then have "x\<sharp>App e\<^isub>1 e\<^isub>2" by auto  | 
333  | 
from app vc obtain f\<^isub>1 f\<^isub>2 where x1: "e\<^isub>1 \<Down> Lam [x]. f\<^isub>1" and x2: "e\<^isub>2 \<Down> f\<^isub>2" and x3: "f\<^isub>1[x::=f\<^isub>2] \<Down> t\<^isub>2"  | 
|
| 28568 | 334  | 
by (auto elim!: b_App_elim)  | 
| 22472 | 335  | 
then have "Lam [x]. f\<^isub>1 = Lam [x]. e\<^isub>1'" using ih1 by simp  | 
336  | 
then  | 
|
337  | 
have "f\<^isub>1 = e\<^isub>1'" by (auto simp add: trm.inject alpha)  | 
|
338  | 
moreover  | 
|
339  | 
have "f\<^isub>2 = e\<^isub>2'" using x2 ih2 by simp  | 
|
| 22447 | 340  | 
ultimately have "e\<^isub>1'[x::=e\<^isub>2'] \<Down> t\<^isub>2" using x3 by simp  | 
| 25832 | 341  | 
thus "e' = t\<^isub>2" using ih3 by simp  | 
342  | 
qed  | 
|
| 22447 | 343  | 
|
| 22472 | 344  | 
lemma reduces_evaluates_to_values:  | 
| 28568 | 345  | 
assumes h: "t \<Down> t'"  | 
| 22447 | 346  | 
shows "val t'"  | 
| 28568 | 347  | 
using h by (induct) (auto)  | 
| 22447 | 348  | 
|
| 25832 | 349  | 
(* Valuation *)  | 
| 22447 | 350  | 
|
351  | 
nominal_primrec  | 
|
| 
29097
 
68245155eb58
Modified nominal_primrec to make it work with local theories, unified syntax
 
berghofe 
parents: 
28568 
diff
changeset
 | 
352  | 
V :: "ty \<Rightarrow> trm set"  | 
| 
 
68245155eb58
Modified nominal_primrec to make it work with local theories, unified syntax
 
berghofe 
parents: 
28568 
diff
changeset
 | 
353  | 
where  | 
| 25832 | 354  | 
  "V (TVar x) = {e. val e}"
 | 
| 
29097
 
68245155eb58
Modified nominal_primrec to make it work with local theories, unified syntax
 
berghofe 
parents: 
28568 
diff
changeset
 | 
355  | 
| "V (T\<^isub>1 \<rightarrow> T\<^isub>2) = {Lam [x].e | x e. \<forall> v \<in> (V T\<^isub>1). \<exists> v'. e[x::=v] \<Down> v' \<and> v' \<in> V T\<^isub>2}"
 | 
| 25832 | 356  | 
by (rule TrueI)+  | 
| 22447 | 357  | 
|
| 22472 | 358  | 
lemma V_eqvt:  | 
359  | 
fixes pi::"name prm"  | 
|
360  | 
assumes a: "x\<in>V T"  | 
|
361  | 
shows "(pi\<bullet>x)\<in>V T"  | 
|
362  | 
using a  | 
|
| 
26966
 
071f40487734
made the naming of the induction principles consistent: weak_induct is
 
urbanc 
parents: 
26806 
diff
changeset
 | 
363  | 
apply(nominal_induct T arbitrary: pi x rule: ty.strong_induct)  | 
| 26806 | 364  | 
apply(auto simp add: trm.inject)  | 
| 25832 | 365  | 
apply(simp add: eqvts)  | 
| 22472 | 366  | 
apply(rule_tac x="pi\<bullet>xa" in exI)  | 
367  | 
apply(rule_tac x="pi\<bullet>e" in exI)  | 
|
368  | 
apply(simp)  | 
|
369  | 
apply(auto)  | 
|
370  | 
apply(drule_tac x="(rev pi)\<bullet>v" in bspec)  | 
|
371  | 
apply(force)  | 
|
372  | 
apply(auto)  | 
|
373  | 
apply(rule_tac x="pi\<bullet>v'" in exI)  | 
|
374  | 
apply(auto)  | 
|
| 22542 | 375  | 
apply(drule_tac pi="pi" in big.eqvt)  | 
| 
22541
 
c33b542394f3
the name for the collection of equivariance lemmas is now eqvts (changed from eqvt) in order to avoid clashes with eqvt-lemmas generated in nominal_inductive
 
urbanc 
parents: 
22534 
diff
changeset
 | 
376  | 
apply(perm_simp add: eqvts)  | 
| 22472 | 377  | 
done  | 
378  | 
||
| 25832 | 379  | 
lemma V_arrow_elim_weak:  | 
| 25867 | 380  | 
assumes h:"u \<in> V (T\<^isub>1 \<rightarrow> T\<^isub>2)"  | 
| 28568 | 381  | 
obtains a t where "u = Lam [a].t" and "\<forall> v \<in> (V T\<^isub>1). \<exists> v'. t[a::=v] \<Down> v' \<and> v' \<in> V T\<^isub>2"  | 
| 22447 | 382  | 
using h by (auto)  | 
383  | 
||
| 25832 | 384  | 
lemma V_arrow_elim_strong:  | 
| 22447 | 385  | 
fixes c::"'a::fs_name"  | 
| 22472 | 386  | 
assumes h: "u \<in> V (T\<^isub>1 \<rightarrow> T\<^isub>2)"  | 
| 28568 | 387  | 
obtains a t where "a\<sharp>c" "u = Lam [a].t" "\<forall>v \<in> (V T\<^isub>1). \<exists> v'. t[a::=v] \<Down> v' \<and> v' \<in> V T\<^isub>2"  | 
| 22447 | 388  | 
using h  | 
389  | 
apply -  | 
|
390  | 
apply(erule V_arrow_elim_weak)  | 
|
| 22472 | 391  | 
apply(subgoal_tac "\<exists>a'::name. a'\<sharp>(a,t,c)") (*A*)  | 
| 22447 | 392  | 
apply(erule exE)  | 
393  | 
apply(drule_tac x="a'" in meta_spec)  | 
|
| 22472 | 394  | 
apply(drule_tac x="[(a,a')]\<bullet>t" in meta_spec)  | 
395  | 
apply(drule meta_mp)  | 
|
| 22447 | 396  | 
apply(simp)  | 
| 22472 | 397  | 
apply(drule meta_mp)  | 
398  | 
apply(simp add: trm.inject alpha fresh_left fresh_prod calc_atm fresh_atm)  | 
|
| 22447 | 399  | 
apply(perm_simp)  | 
| 22472 | 400  | 
apply(force)  | 
401  | 
apply(drule meta_mp)  | 
|
402  | 
apply(rule ballI)  | 
|
403  | 
apply(drule_tac x="[(a,a')]\<bullet>v" in bspec)  | 
|
404  | 
apply(simp add: V_eqvt)  | 
|
| 22447 | 405  | 
apply(auto)  | 
| 22472 | 406  | 
apply(rule_tac x="[(a,a')]\<bullet>v'" in exI)  | 
407  | 
apply(auto)  | 
|
| 22542 | 408  | 
apply(drule_tac pi="[(a,a')]" in big.eqvt)  | 
| 
22541
 
c33b542394f3
the name for the collection of equivariance lemmas is now eqvts (changed from eqvt) in order to avoid clashes with eqvt-lemmas generated in nominal_inductive
 
urbanc 
parents: 
22534 
diff
changeset
 | 
409  | 
apply(perm_simp add: eqvts calc_atm)  | 
| 22472 | 410  | 
apply(simp add: V_eqvt)  | 
411  | 
(*A*)  | 
|
| 22447 | 412  | 
apply(rule exists_fresh')  | 
| 22472 | 413  | 
apply(simp add: fin_supp)  | 
| 22447 | 414  | 
done  | 
415  | 
||
| 25832 | 416  | 
lemma Vs_are_values:  | 
417  | 
assumes a: "e \<in> V T"  | 
|
| 22447 | 418  | 
shows "val e"  | 
| 
26966
 
071f40487734
made the naming of the induction principles consistent: weak_induct is
 
urbanc 
parents: 
26806 
diff
changeset
 | 
419  | 
using a by (nominal_induct T arbitrary: e rule: ty.strong_induct) (auto)  | 
| 22447 | 420  | 
|
421  | 
lemma values_reduce_to_themselves:  | 
|
| 25832 | 422  | 
assumes a: "val v"  | 
| 22447 | 423  | 
shows "v \<Down> v"  | 
| 25832 | 424  | 
using a by (induct) (auto)  | 
| 22447 | 425  | 
|
| 25832 | 426  | 
lemma Vs_reduce_to_themselves:  | 
427  | 
assumes a: "v \<in> V T"  | 
|
428  | 
shows "v \<Down> v"  | 
|
429  | 
using a by (simp add: values_reduce_to_themselves Vs_are_values)  | 
|
| 22447 | 430  | 
|
| 25832 | 431  | 
text {* '\<theta> maps x to e' asserts that \<theta> substitutes x with e *}
 | 
| 22447 | 432  | 
abbreviation  | 
| 25832 | 433  | 
  mapsto :: "(name\<times>trm) list \<Rightarrow> name \<Rightarrow> trm \<Rightarrow> bool" ("_ maps _ to _" [55,55,55] 55) 
 | 
| 22447 | 434  | 
where  | 
| 25832 | 435  | 
"\<theta> maps x to e \<equiv> (lookup \<theta> x) = e"  | 
| 22447 | 436  | 
|
437  | 
abbreviation  | 
|
438  | 
  v_closes :: "(name\<times>trm) list \<Rightarrow> (name\<times>ty) list \<Rightarrow> bool" ("_ Vcloses _" [55,55] 55) 
 | 
|
439  | 
where  | 
|
| 25832 | 440  | 
"\<theta> Vcloses \<Gamma> \<equiv> \<forall>x T. (x,T) \<in> set \<Gamma> \<longrightarrow> (\<exists>v. \<theta> maps x to v \<and> v \<in> V T)"  | 
| 22447 | 441  | 
|
| 28568 | 442  | 
lemma case_distinction_on_context:  | 
443  | 
fixes \<Gamma>::"(name\<times>ty) list"  | 
|
444  | 
assumes asm1: "valid ((m,t)#\<Gamma>)"  | 
|
445  | 
and asm2: "(n,U) \<in> set ((m,T)#\<Gamma>)"  | 
|
446  | 
shows "(n,U) = (m,T) \<or> ((n,U) \<in> set \<Gamma> \<and> n \<noteq> m)"  | 
|
447  | 
proof -  | 
|
448  | 
from asm2 have "(n,U) \<in> set [(m,T)] \<or> (n,U) \<in> set \<Gamma>" by auto  | 
|
449  | 
moreover  | 
|
450  | 
  { assume eq: "m=n"
 | 
|
451  | 
assume "(n,U) \<in> set \<Gamma>"  | 
|
452  | 
then have "\<not> n\<sharp>\<Gamma>"  | 
|
453  | 
by (induct \<Gamma>) (auto simp add: fresh_list_cons fresh_prod fresh_atm)  | 
|
454  | 
moreover have "m\<sharp>\<Gamma>" using asm1 by auto  | 
|
455  | 
ultimately have False using eq by auto  | 
|
456  | 
}  | 
|
457  | 
ultimately show ?thesis by auto  | 
|
458  | 
qed  | 
|
459  | 
||
| 22447 | 460  | 
lemma monotonicity:  | 
461  | 
fixes m::"name"  | 
|
462  | 
fixes \<theta>::"(name \<times> trm) list"  | 
|
463  | 
assumes h1: "\<theta> Vcloses \<Gamma>"  | 
|
464  | 
and h2: "e \<in> V T"  | 
|
465  | 
and h3: "valid ((x,T)#\<Gamma>)"  | 
|
466  | 
shows "(x,e)#\<theta> Vcloses (x,T)#\<Gamma>"  | 
|
467  | 
proof(intro strip)  | 
|
468  | 
fix x' T'  | 
|
469  | 
assume "(x',T') \<in> set ((x,T)#\<Gamma>)"  | 
|
470  | 
then have "((x',T')=(x,T)) \<or> ((x',T')\<in>set \<Gamma> \<and> x'\<noteq>x)" using h3  | 
|
471  | 
by (rule_tac case_distinction_on_context)  | 
|
472  | 
moreover  | 
|
473  | 
  { (* first case *)
 | 
|
474  | 
assume "(x',T') = (x,T)"  | 
|
475  | 
then have "\<exists>e'. ((x,e)#\<theta>) maps x to e' \<and> e' \<in> V T'" using h2 by auto  | 
|
476  | 
}  | 
|
477  | 
moreover  | 
|
478  | 
  { (* second case *)
 | 
|
479  | 
assume "(x',T') \<in> set \<Gamma>" and neq:"x' \<noteq> x"  | 
|
480  | 
then have "\<exists>e'. \<theta> maps x' to e' \<and> e' \<in> V T'" using h1 by auto  | 
|
481  | 
then have "\<exists>e'. ((x,e)#\<theta>) maps x' to e' \<and> e' \<in> V T'" using neq by auto  | 
|
482  | 
}  | 
|
483  | 
ultimately show "\<exists>e'. ((x,e)#\<theta>) maps x' to e' \<and> e' \<in> V T'" by blast  | 
|
484  | 
qed  | 
|
485  | 
||
486  | 
lemma termination_aux:  | 
|
487  | 
assumes h1: "\<Gamma> \<turnstile> e : T"  | 
|
488  | 
and h2: "\<theta> Vcloses \<Gamma>"  | 
|
489  | 
shows "\<exists>v. \<theta><e> \<Down> v \<and> v \<in> V T"  | 
|
490  | 
using h2 h1  | 
|
| 
26966
 
071f40487734
made the naming of the induction principles consistent: weak_induct is
 
urbanc 
parents: 
26806 
diff
changeset
 | 
491  | 
proof(nominal_induct e avoiding: \<Gamma> \<theta> arbitrary: T rule: trm.strong_induct)  | 
| 22447 | 492  | 
case (App e\<^isub>1 e\<^isub>2 \<Gamma> \<theta> T)  | 
| 28568 | 493  | 
have ih\<^isub>1: "\<And>\<theta> \<Gamma> T. \<lbrakk>\<theta> Vcloses \<Gamma>; \<Gamma> \<turnstile> e\<^isub>1 : T\<rbrakk> \<Longrightarrow> \<exists>v. \<theta><e\<^isub>1> \<Down> v \<and> v \<in> V T" by fact  | 
494  | 
have ih\<^isub>2: "\<And>\<theta> \<Gamma> T. \<lbrakk>\<theta> Vcloses \<Gamma>; \<Gamma> \<turnstile> e\<^isub>2 : T\<rbrakk> \<Longrightarrow> \<exists>v. \<theta><e\<^isub>2> \<Down> v \<and> v \<in> V T" by fact  | 
|
495  | 
have as\<^isub>1: "\<theta> Vcloses \<Gamma>" by fact  | 
|
| 22447 | 496  | 
have as\<^isub>2: "\<Gamma> \<turnstile> App e\<^isub>1 e\<^isub>2 : T" by fact  | 
| 28568 | 497  | 
then obtain T' where "\<Gamma> \<turnstile> e\<^isub>1 : T' \<rightarrow> T" and "\<Gamma> \<turnstile> e\<^isub>2 : T'" by (auto elim: t_App_elim)  | 
| 22447 | 498  | 
then obtain v\<^isub>1 v\<^isub>2 where "(i)": "\<theta><e\<^isub>1> \<Down> v\<^isub>1" "v\<^isub>1 \<in> V (T' \<rightarrow> T)"  | 
| 28568 | 499  | 
and "(ii)": "\<theta><e\<^isub>2> \<Down> v\<^isub>2" "v\<^isub>2 \<in> V T'" using ih\<^isub>1 ih\<^isub>2 as\<^isub>1 by blast  | 
| 22447 | 500  | 
from "(i)" obtain x e'  | 
| 28568 | 501  | 
where "v\<^isub>1 = Lam [x].e'"  | 
| 22447 | 502  | 
and "(iii)": "(\<forall>v \<in> (V T').\<exists> v'. e'[x::=v] \<Down> v' \<and> v' \<in> V T)"  | 
503  | 
and "(iv)": "\<theta><e\<^isub>1> \<Down> Lam [x].e'"  | 
|
| 25832 | 504  | 
and fr: "x\<sharp>(\<theta>,e\<^isub>1,e\<^isub>2)" by (blast elim: V_arrow_elim_strong)  | 
| 22447 | 505  | 
from fr have fr\<^isub>1: "x\<sharp>\<theta><e\<^isub>1>" and fr\<^isub>2: "x\<sharp>\<theta><e\<^isub>2>" by (simp_all add: fresh_psubst)  | 
506  | 
from "(ii)" "(iii)" obtain v\<^isub>3 where "(v)": "e'[x::=v\<^isub>2] \<Down> v\<^isub>3" "v\<^isub>3 \<in> V T" by auto  | 
|
| 25832 | 507  | 
from fr\<^isub>2 "(ii)" have "x\<sharp>v\<^isub>2" by (simp add: big_preserves_fresh)  | 
| 28568 | 508  | 
then have "x\<sharp>e'[x::=v\<^isub>2]" by (simp add: fresh_subst)  | 
| 25832 | 509  | 
then have fr\<^isub>3: "x\<sharp>v\<^isub>3" using "(v)" by (simp add: big_preserves_fresh)  | 
| 22447 | 510  | 
from fr\<^isub>1 fr\<^isub>2 fr\<^isub>3 have "x\<sharp>(\<theta><e\<^isub>1>,\<theta><e\<^isub>2>,v\<^isub>3)" by simp  | 
511  | 
with "(iv)" "(ii)" "(v)" have "App (\<theta><e\<^isub>1>) (\<theta><e\<^isub>2>) \<Down> v\<^isub>3" by auto  | 
|
512  | 
then show "\<exists>v. \<theta><App e\<^isub>1 e\<^isub>2> \<Down> v \<and> v \<in> V T" using "(v)" by auto  | 
|
513  | 
next  | 
|
514  | 
case (Lam x e \<Gamma> \<theta> T)  | 
|
515  | 
have ih:"\<And>\<theta> \<Gamma> T. \<lbrakk>\<theta> Vcloses \<Gamma>; \<Gamma> \<turnstile> e : T\<rbrakk> \<Longrightarrow> \<exists>v. \<theta><e> \<Down> v \<and> v \<in> V T" by fact  | 
|
516  | 
have as\<^isub>1: "\<theta> Vcloses \<Gamma>" by fact  | 
|
517  | 
have as\<^isub>2: "\<Gamma> \<turnstile> Lam [x].e : T" by fact  | 
|
| 29300 | 518  | 
have fs: "x\<sharp>\<Gamma>" "x\<sharp>\<theta>" by fact+  | 
| 22447 | 519  | 
from as\<^isub>2 fs obtain T\<^isub>1 T\<^isub>2  | 
| 25832 | 520  | 
where "(i)": "(x,T\<^isub>1)#\<Gamma> \<turnstile> e:T\<^isub>2" and "(ii)": "T = T\<^isub>1 \<rightarrow> T\<^isub>2" using fs  | 
| 28568 | 521  | 
by (auto elim: t_Lam_elim)  | 
| 22472 | 522  | 
from "(i)" have "(iii)": "valid ((x,T\<^isub>1)#\<Gamma>)" by (simp add: typing_implies_valid)  | 
| 22447 | 523  | 
have "\<forall>v \<in> (V T\<^isub>1). \<exists>v'. (\<theta><e>)[x::=v] \<Down> v' \<and> v' \<in> V T\<^isub>2"  | 
524  | 
proof  | 
|
525  | 
fix v  | 
|
526  | 
assume "v \<in> (V T\<^isub>1)"  | 
|
527  | 
with "(iii)" as\<^isub>1 have "(x,v)#\<theta> Vcloses (x,T\<^isub>1)#\<Gamma>" using monotonicity by auto  | 
|
528  | 
with ih "(i)" obtain v' where "((x,v)#\<theta>)<e> \<Down> v' \<and> v' \<in> V T\<^isub>2" by blast  | 
|
| 22472 | 529  | 
then have "\<theta><e>[x::=v] \<Down> v' \<and> v' \<in> V T\<^isub>2" using fs by (simp add: psubst_subst_psubst)  | 
| 22447 | 530  | 
then show "\<exists>v'. \<theta><e>[x::=v] \<Down> v' \<and> v' \<in> V T\<^isub>2" by auto  | 
531  | 
qed  | 
|
532  | 
then have "Lam[x].\<theta><e> \<in> V (T\<^isub>1 \<rightarrow> T\<^isub>2)" by auto  | 
|
| 28568 | 533  | 
then have "\<theta><Lam [x].e> \<Down> Lam [x].\<theta><e> \<and> Lam [x].\<theta><e> \<in> V (T\<^isub>1\<rightarrow>T\<^isub>2)" using fs by auto  | 
| 22447 | 534  | 
thus "\<exists>v. \<theta><Lam [x].e> \<Down> v \<and> v \<in> V T" using "(ii)" by auto  | 
535  | 
next  | 
|
| 25832 | 536  | 
case (Var x \<Gamma> \<theta> T)  | 
537  | 
have "\<Gamma> \<turnstile> (Var x) : T" by fact  | 
|
538  | 
then have "(x,T)\<in>set \<Gamma>" by (cases) (auto simp add: trm.inject)  | 
|
539  | 
with prems have "\<theta><Var x> \<Down> \<theta><Var x> \<and> \<theta><Var x>\<in> V T"  | 
|
540  | 
by (auto intro!: Vs_reduce_to_themselves)  | 
|
541  | 
then show "\<exists>v. \<theta><Var x> \<Down> v \<and> v \<in> V T" by auto  | 
|
542  | 
qed  | 
|
| 22447 | 543  | 
|
544  | 
theorem termination_of_evaluation:  | 
|
545  | 
assumes a: "[] \<turnstile> e : T"  | 
|
546  | 
shows "\<exists>v. e \<Down> v \<and> val v"  | 
|
547  | 
proof -  | 
|
| 25832 | 548  | 
from a have "\<exists>v. []<e> \<Down> v \<and> v \<in> V T" by (rule termination_aux) (auto)  | 
549  | 
thus "\<exists>v. e \<Down> v \<and> val v" using Vs_are_values by auto  | 
|
| 22447 | 550  | 
qed  | 
551  | 
||
552  | 
end  |