author | urbanc |
Wed, 28 Mar 2007 18:25:23 +0200 | |
changeset 22541 | c33b542394f3 |
parent 22534 | bd4b954e85ee |
child 22542 | 8279a25ad0ae |
permissions | -rw-r--r-- |
22447 | 1 |
(* "$Id$" *) |
2 |
(* *) |
|
22472 | 3 |
(* Formalisation of some typical SOS-proofs *) |
22447 | 4 |
(* *) |
22472 | 5 |
(* This work arose from challenge suggested by Adam *) |
6 |
(* Chlipala suggested on the POPLmark mailing list. *) |
|
7 |
(* *) |
|
8 |
(* We thank Nick Benton for helping us with the *) |
|
9 |
(* termination-proof for evaluation. *) |
|
22447 | 10 |
|
11 |
theory SOS |
|
22534 | 12 |
imports "../Nominal" |
22447 | 13 |
begin |
14 |
||
15 |
atom_decl name |
|
16 |
||
17 |
nominal_datatype data = |
|
18 |
DNat |
|
19 |
| DProd "data" "data" |
|
20 |
| DSum "data" "data" |
|
21 |
||
22 |
nominal_datatype ty = |
|
23 |
Data "data" |
|
24 |
| Arrow "ty" "ty" ("_\<rightarrow>_" [100,100] 100) |
|
25 |
||
26 |
nominal_datatype trm = |
|
27 |
Var "name" |
|
28 |
| Lam "\<guillemotleft>name\<guillemotright>trm" ("Lam [_]._" [100,100] 100) |
|
29 |
| App "trm" "trm" |
|
30 |
| Const "nat" |
|
31 |
| Pr "trm" "trm" |
|
32 |
| Fst "trm" |
|
33 |
| Snd "trm" |
|
34 |
| InL "trm" |
|
35 |
| InR "trm" |
|
36 |
| Case "trm" "\<guillemotleft>name\<guillemotright>trm" "\<guillemotleft>name\<guillemotright>trm" ("Case _ of inl _ \<rightarrow> _ | inr _ \<rightarrow> _" [100,100,100,100,100] 100) |
|
37 |
||
38 |
lemma in_eqvt[eqvt]: |
|
39 |
fixes pi::"name prm" |
|
40 |
and x::"'a::pt_name" |
|
41 |
assumes "x\<in>X" |
|
42 |
shows "pi\<bullet>x \<in> pi\<bullet>X" |
|
43 |
using assms by (perm_simp add: pt_set_bij1a[OF pt_name_inst, OF at_name_inst]) |
|
44 |
||
45 |
lemma perm_data[simp]: |
|
46 |
fixes D::"data" |
|
47 |
and pi::"name prm" |
|
48 |
shows "pi\<bullet>D = D" |
|
49 |
by (induct D rule: data.induct_weak) (simp_all) |
|
50 |
||
51 |
lemma perm_ty[simp]: |
|
52 |
fixes T::"ty" |
|
53 |
and pi::"name prm" |
|
54 |
shows "pi\<bullet>T = T" |
|
55 |
by (induct T rule: ty.induct_weak) (simp_all) |
|
56 |
||
57 |
lemma fresh_ty[simp]: |
|
58 |
fixes x::"name" |
|
59 |
and T::"ty" |
|
60 |
shows "x\<sharp>T" |
|
61 |
by (simp add: fresh_def supp_def) |
|
62 |
||
63 |
text {* substitution *} |
|
64 |
||
65 |
fun |
|
66 |
lookup :: "(name\<times>trm) list \<Rightarrow> name \<Rightarrow> trm" |
|
67 |
where |
|
68 |
"lookup [] x = Var x" |
|
22502 | 69 |
| "lookup ((y,e)#\<theta>) x = (if x=y then e else lookup \<theta> x)" |
22447 | 70 |
|
71 |
lemma lookup_eqvt: |
|
72 |
fixes pi::"name prm" |
|
73 |
and \<theta>::"(name\<times>trm) list" |
|
74 |
and X::"name" |
|
75 |
shows "pi\<bullet>(lookup \<theta> X) = lookup (pi\<bullet>\<theta>) (pi\<bullet>X)" |
|
76 |
by (induct \<theta>, auto simp add: perm_bij) |
|
77 |
||
78 |
lemma lookup_fresh: |
|
79 |
fixes z::"name" |
|
80 |
assumes "z\<sharp>\<theta>" and "z\<sharp>x" |
|
81 |
shows "z \<sharp>lookup \<theta> x" |
|
82 |
using assms |
|
83 |
by (induct rule: lookup.induct) (auto simp add: fresh_list_cons) |
|
84 |
||
85 |
lemma lookup_fresh': |
|
86 |
assumes "z\<sharp>\<theta>" |
|
87 |
shows "lookup \<theta> z = Var z" |
|
88 |
using assms |
|
89 |
by (induct rule: lookup.induct) |
|
90 |
(auto simp add: fresh_list_cons fresh_prod fresh_atm) |
|
91 |
||
22472 | 92 |
text {* Parallel Substitution *} |
93 |
||
22447 | 94 |
consts |
95 |
psubst :: "(name\<times>trm) list \<Rightarrow> trm \<Rightarrow> trm" ("_<_>" [95,95] 105) |
|
96 |
||
97 |
nominal_primrec |
|
98 |
"\<theta><(Var x)> = (lookup \<theta> x)" |
|
99 |
"\<theta><(App e\<^isub>1 e\<^isub>2)> = App (\<theta><e\<^isub>1>) (\<theta><e\<^isub>2>)" |
|
100 |
"x\<sharp>\<theta> \<Longrightarrow> \<theta><(Lam [x].e)> = Lam [x].(\<theta><e>)" |
|
101 |
"\<theta><(Const n)> = Const n" |
|
102 |
"\<theta><(Pr e\<^isub>1 e\<^isub>2)> = Pr (\<theta><e\<^isub>1>) (\<theta><e\<^isub>2>)" |
|
103 |
"\<theta><(Fst e)> = Fst (\<theta><e>)" |
|
104 |
"\<theta><(Snd e)> = Snd (\<theta><e>)" |
|
105 |
"\<theta><(InL e)> = InL (\<theta><e>)" |
|
106 |
"\<theta><(InR e)> = InR (\<theta><e>)" |
|
107 |
"\<lbrakk>y\<noteq>x; x\<sharp>(e,e\<^isub>2,\<theta>); y\<sharp>(e,e\<^isub>1,\<theta>)\<rbrakk> |
|
22472 | 108 |
\<Longrightarrow> \<theta><Case e of inl x \<rightarrow> e\<^isub>1 | inr y \<rightarrow> e\<^isub>2> = (Case (\<theta><e>) of inl x \<rightarrow> (\<theta><e\<^isub>1>) | inr y \<rightarrow> (\<theta><e\<^isub>2>))" |
109 |
apply(finite_guess add: lookup_eqvt)+ |
|
110 |
apply(rule TrueI)+ |
|
111 |
apply(simp add: abs_fresh)+ |
|
112 |
apply(fresh_guess add: fs_name1 lookup_eqvt)+ |
|
113 |
done |
|
22447 | 114 |
|
115 |
lemma psubst_eqvt[eqvt]: |
|
116 |
fixes pi::"name prm" |
|
117 |
and t::"trm" |
|
118 |
shows "pi\<bullet>(\<theta><t>) = (pi\<bullet>\<theta>)<(pi\<bullet>t)>" |
|
22472 | 119 |
by (nominal_induct t avoiding: \<theta> rule: trm.induct) |
120 |
(perm_simp add: fresh_bij lookup_eqvt)+ |
|
22447 | 121 |
|
122 |
lemma fresh_psubst: |
|
123 |
fixes z::"name" |
|
124 |
and t::"trm" |
|
125 |
assumes "z\<sharp>t" and "z\<sharp>\<theta>" |
|
126 |
shows "z\<sharp>(\<theta><t>)" |
|
127 |
using assms |
|
128 |
by (nominal_induct t avoiding: z \<theta> t rule: trm.induct) |
|
129 |
(auto simp add: abs_fresh lookup_fresh) |
|
130 |
||
131 |
abbreviation |
|
132 |
subst :: "trm \<Rightarrow> name \<Rightarrow> trm \<Rightarrow> trm" ("_[_::=_]" [100,100,100] 100) |
|
133 |
where "t[x::=t'] \<equiv> ([(x,t')])<t>" |
|
134 |
||
135 |
lemma subst[simp]: |
|
136 |
shows "(Var x)[y::=t'] = (if x=y then t' else (Var x))" |
|
137 |
and "(App t\<^isub>1 t\<^isub>2)[y::=t'] = App (t\<^isub>1[y::=t']) (t\<^isub>2[y::=t'])" |
|
138 |
and "x\<sharp>(y,t') \<Longrightarrow> (Lam [x].t)[y::=t'] = Lam [x].(t[y::=t'])" |
|
139 |
and "(Const n)[y::=t'] = Const n" |
|
140 |
and "(Pr e\<^isub>1 e\<^isub>2)[y::=t'] = Pr (e\<^isub>1[y::=t']) (e\<^isub>2[y::=t'])" |
|
141 |
and "(Fst e)[y::=t'] = Fst (e[y::=t'])" |
|
142 |
and "(Snd e)[y::=t'] = Snd (e[y::=t'])" |
|
143 |
and "(InL e)[y::=t'] = InL (e[y::=t'])" |
|
144 |
and "(InR e)[y::=t'] = InR (e[y::=t'])" |
|
145 |
and "\<lbrakk>z\<noteq>x; x\<sharp>(y,e,e\<^isub>2,t'); z\<sharp>(y,e,e\<^isub>1,t')\<rbrakk> |
|
146 |
\<Longrightarrow> (Case e of inl x \<rightarrow> e\<^isub>1 | inr z \<rightarrow> e\<^isub>2)[y::=t'] = |
|
147 |
(Case (e[y::=t']) of inl x \<rightarrow> (e\<^isub>1[y::=t']) | inr z \<rightarrow> (e\<^isub>2[y::=t']))" |
|
22472 | 148 |
by (simp_all add: fresh_list_cons fresh_list_nil) |
22447 | 149 |
|
150 |
lemma subst_eqvt[eqvt]: |
|
151 |
fixes pi::"name prm" |
|
152 |
and t::"trm" |
|
153 |
shows "pi\<bullet>(t[x::=t']) = (pi\<bullet>t)[(pi\<bullet>x)::=(pi\<bullet>t')]" |
|
154 |
by (nominal_induct t avoiding: x t' rule: trm.induct) |
|
155 |
(perm_simp add: fresh_bij)+ |
|
156 |
||
157 |
lemma fresh_subst: |
|
158 |
fixes z::"name" |
|
159 |
and t\<^isub>1::"trm" |
|
160 |
and t2::"trm" |
|
161 |
assumes "z\<sharp>t\<^isub>1" and "z\<sharp>t\<^isub>2" |
|
162 |
shows "z\<sharp>t\<^isub>1[y::=t\<^isub>2]" |
|
163 |
using assms |
|
164 |
by (nominal_induct t\<^isub>1 avoiding: z y t\<^isub>2 rule: trm.induct) |
|
165 |
(auto simp add: abs_fresh fresh_atm) |
|
166 |
||
167 |
lemma fresh_subst': |
|
168 |
fixes z::"name" |
|
169 |
and t\<^isub>1::"trm" |
|
170 |
and t2::"trm" |
|
171 |
assumes "z\<sharp>[y].t\<^isub>1" and "z\<sharp>t\<^isub>2" |
|
172 |
shows "z\<sharp>t\<^isub>1[y::=t\<^isub>2]" |
|
173 |
using assms |
|
174 |
by (nominal_induct t\<^isub>1 avoiding: y t\<^isub>2 z rule: trm.induct) |
|
175 |
(auto simp add: abs_fresh fresh_nat fresh_atm) |
|
176 |
||
177 |
lemma forget: |
|
178 |
fixes x::"name" |
|
179 |
and L::"trm" |
|
180 |
assumes "x\<sharp>L" |
|
181 |
shows "L[x::=P] = L" |
|
182 |
using assms |
|
183 |
by (nominal_induct L avoiding: x P rule: trm.induct) |
|
184 |
(auto simp add: fresh_atm abs_fresh) |
|
185 |
||
186 |
lemma psubst_empty[simp]: |
|
187 |
shows "[]<t> = t" |
|
188 |
by (nominal_induct t rule: trm.induct, auto simp add:fresh_list_nil) |
|
189 |
||
190 |
lemma psubst_subst_psubst: |
|
191 |
assumes h:"x\<sharp>\<theta>" |
|
192 |
shows "\<theta><e>[x::=e'] = ((x,e')#\<theta>)<e>" |
|
193 |
using h |
|
194 |
apply(nominal_induct e avoiding: \<theta> x e' rule: trm.induct) |
|
195 |
apply(auto simp add: fresh_list_cons fresh_atm forget lookup_fresh lookup_fresh' fresh_psubst) |
|
196 |
done |
|
197 |
||
198 |
lemma fresh_subst_fresh: |
|
199 |
assumes "a\<sharp>e" |
|
200 |
shows "a\<sharp>t[a::=e]" |
|
201 |
using assms |
|
202 |
by (nominal_induct t avoiding: a e rule: trm.induct) |
|
203 |
(auto simp add: fresh_atm abs_fresh fresh_nat) |
|
204 |
||
22472 | 205 |
text {* Typing-Judgements *} |
22447 | 206 |
|
207 |
inductive2 |
|
208 |
valid :: "(name \<times> 'a::pt_name) list \<Rightarrow> bool" |
|
209 |
where |
|
210 |
v_nil[intro]: "valid []" |
|
211 |
| v_cons[intro]: "\<lbrakk>valid \<Gamma>;x\<sharp>\<Gamma>\<rbrakk> \<Longrightarrow> valid ((x,T)#\<Gamma>)" |
|
212 |
||
22534 | 213 |
equivariance valid |
22447 | 214 |
|
215 |
inductive_cases2 |
|
216 |
valid_cons_inv_auto[elim]:"valid ((x,T)#\<Gamma>)" |
|
217 |
||
218 |
abbreviation |
|
219 |
"sub" :: "(name\<times>ty) list \<Rightarrow> (name\<times>ty) list \<Rightarrow> bool" ("_ \<lless> _" [55,55] 55) |
|
220 |
where |
|
221 |
"\<Gamma>\<^isub>1 \<lless> \<Gamma>\<^isub>2 \<equiv> \<forall>x T. (x,T)\<in>set \<Gamma>\<^isub>1 \<longrightarrow> (x,T)\<in>set \<Gamma>\<^isub>2" |
|
222 |
||
223 |
lemma type_unicity_in_context: |
|
224 |
assumes asm1: "(x,t\<^isub>2) \<in> set ((x,t\<^isub>1)#\<Gamma>)" |
|
225 |
and asm2: "valid ((x,t\<^isub>1)#\<Gamma>)" |
|
226 |
shows "t\<^isub>1=t\<^isub>2" |
|
227 |
proof - |
|
228 |
from asm2 have "x\<sharp>\<Gamma>" by (cases, auto) |
|
229 |
then have "(x,t\<^isub>2) \<notin> set \<Gamma>" |
|
230 |
by (induct \<Gamma>) (auto simp add: fresh_list_cons fresh_prod fresh_atm) |
|
231 |
then have "(x,t\<^isub>2) = (x,t\<^isub>1)" using asm1 by auto |
|
232 |
then show "t\<^isub>1 = t\<^isub>2" by auto |
|
233 |
qed |
|
234 |
||
235 |
lemma case_distinction_on_context: |
|
236 |
fixes \<Gamma>::"(name \<times> ty) list" |
|
237 |
assumes asm1: "valid ((m,t)#\<Gamma>)" |
|
238 |
and asm2: "(n,U) \<in> set ((m,T)#\<Gamma>)" |
|
239 |
shows "(n,U) = (m,T) \<or> ((n,U) \<in> set \<Gamma> \<and> n \<noteq> m)" |
|
240 |
proof - |
|
241 |
from asm2 have "(n,U) \<in> set [(m,T)] \<or> (n,U) \<in> set \<Gamma>" by auto |
|
242 |
moreover |
|
243 |
{ assume eq: "m=n" |
|
244 |
assume "(n,U) \<in> set \<Gamma>" |
|
245 |
then have "\<not> n\<sharp>\<Gamma>" |
|
246 |
by (induct \<Gamma>) (auto simp add: fresh_list_cons fresh_prod fresh_atm) |
|
247 |
moreover have "m\<sharp>\<Gamma>" using asm1 by auto |
|
248 |
ultimately have False using eq by auto |
|
249 |
} |
|
250 |
ultimately show ?thesis by auto |
|
251 |
qed |
|
252 |
||
253 |
inductive2 |
|
254 |
typing :: "(name\<times>ty) list\<Rightarrow>trm\<Rightarrow>ty\<Rightarrow>bool" ("_ \<turnstile> _ : _" [60,60,60] 60) |
|
255 |
where |
|
256 |
t_Var[intro]: "\<lbrakk>valid \<Gamma>; (x,T)\<in>set \<Gamma>\<rbrakk>\<Longrightarrow> \<Gamma> \<turnstile> Var x : T" |
|
257 |
| 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" |
|
258 |
| 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" |
|
259 |
| t_Const[intro]: "valid \<Gamma> \<Longrightarrow> \<Gamma> \<turnstile> Const n : Data(DNat)" |
|
260 |
| t_Pr[intro]: "\<lbrakk>\<Gamma> \<turnstile> e\<^isub>1 : Data(S\<^isub>1); \<Gamma> \<turnstile> e\<^isub>2 : Data(S\<^isub>2)\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> Pr e\<^isub>1 e\<^isub>2 : Data (DProd S\<^isub>1 S\<^isub>2)" |
|
261 |
| t_Fst[intro]: "\<lbrakk>\<Gamma> \<turnstile> e : Data(DProd S\<^isub>1 S\<^isub>2)\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> Fst e : Data(S\<^isub>1)" |
|
262 |
| t_Snd[intro]: "\<lbrakk>\<Gamma> \<turnstile> e : Data(DProd S\<^isub>1 S\<^isub>2)\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> Snd e : Data(S\<^isub>2)" |
|
263 |
| t_InL[intro]: "\<lbrakk>\<Gamma> \<turnstile> e : Data(S\<^isub>1)\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> InL e : Data(DSum S\<^isub>1 S\<^isub>2)" |
|
264 |
| t_InR[intro]: "\<lbrakk>\<Gamma> \<turnstile> e : Data(S\<^isub>2)\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> InR e : Data(DSum S\<^isub>1 S\<^isub>2)" |
|
265 |
| t_Case[intro]: "\<lbrakk>x\<^isub>1\<sharp>(\<Gamma>,e,e\<^isub>2,x\<^isub>2); x\<^isub>2\<sharp>(\<Gamma>,e,e\<^isub>1,x\<^isub>1); \<Gamma> \<turnstile> e: Data(DSum S\<^isub>1 S\<^isub>2); |
|
266 |
(x\<^isub>1,Data(S\<^isub>1))#\<Gamma> \<turnstile> e\<^isub>1 : T; (x\<^isub>2,Data(S\<^isub>2))#\<Gamma> \<turnstile> e\<^isub>2 : T\<rbrakk> |
|
267 |
\<Longrightarrow> \<Gamma> \<turnstile> (Case e of inl x\<^isub>1 \<rightarrow> e\<^isub>1 | inr x\<^isub>2 \<rightarrow> e\<^isub>2) : T" |
|
268 |
||
22531 | 269 |
nominal_inductive typing |
270 |
by (simp_all add: abs_fresh fresh_prod fresh_atm) |
|
271 |
||
22534 | 272 |
lemmas typing_eqvt' = typing_eqvt[simplified] |
22531 | 273 |
|
22472 | 274 |
lemma typing_implies_valid: |
22447 | 275 |
assumes "\<Gamma> \<turnstile> t : T" |
276 |
shows "valid \<Gamma>" |
|
277 |
using assms |
|
278 |
by (induct) (auto) |
|
279 |
||
280 |
declare trm.inject [simp add] |
|
281 |
declare ty.inject [simp add] |
|
282 |
declare data.inject [simp add] |
|
283 |
||
284 |
inductive_cases2 t_Lam_inv_auto[elim]: "\<Gamma> \<turnstile> Lam [x].t : T" |
|
285 |
inductive_cases2 t_Var_inv_auto[elim]: "\<Gamma> \<turnstile> Var x : T" |
|
286 |
inductive_cases2 t_App_inv_auto[elim]: "\<Gamma> \<turnstile> App x y : T" |
|
287 |
inductive_cases2 t_Const_inv_auto[elim]: "\<Gamma> \<turnstile> Const n : T" |
|
288 |
inductive_cases2 t_Fst_inv_auto[elim]: "\<Gamma> \<turnstile> Fst x : T" |
|
289 |
inductive_cases2 t_Snd_inv_auto[elim]: "\<Gamma> \<turnstile> Snd x : T" |
|
290 |
inductive_cases2 t_InL_inv_auto[elim]: "\<Gamma> \<turnstile> InL x : T" |
|
291 |
inductive_cases2 t_InL_inv_auto'[elim]: "\<Gamma> \<turnstile> InL x : Data (DSum T\<^isub>1 T2)" |
|
292 |
inductive_cases2 t_InR_inv_auto[elim]: "\<Gamma> \<turnstile> InR x : T" |
|
293 |
inductive_cases2 t_InR_inv_auto'[elim]: "\<Gamma> \<turnstile> InR x : Data (DSum T\<^isub>1 T2)" |
|
294 |
inductive_cases2 t_Pr_inv_auto[elim]: "\<Gamma> \<turnstile> Pr x y : T" |
|
295 |
inductive_cases2 t_Pr_inv_auto'[elim]: "\<Gamma> \<turnstile> Pr e\<^isub>1 e\<^isub>2 : Data (DProd \<sigma>1 \<sigma>\<^isub>2)" |
|
296 |
inductive_cases2 t_Case_inv_auto[elim]: "\<Gamma> \<turnstile> Case e of inl x\<^isub>1 \<rightarrow> e\<^isub>1 | inr x\<^isub>2 \<rightarrow> e\<^isub>2 : T" |
|
297 |
||
298 |
declare trm.inject [simp del] |
|
299 |
declare ty.inject [simp del] |
|
300 |
declare data.inject [simp del] |
|
301 |
||
22534 | 302 |
lemma t_Lam_elim[elim]: |
22447 | 303 |
assumes a1:"\<Gamma> \<turnstile> Lam [x].t : T" |
304 |
and a2: "x\<sharp>\<Gamma>" |
|
305 |
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" |
|
306 |
proof - |
|
307 |
from a1 obtain x' t' T\<^isub>1 T\<^isub>2 |
|
308 |
where b1: "x'\<sharp>\<Gamma>" and b2: "(x',T\<^isub>1)#\<Gamma> \<turnstile> t' : T\<^isub>2" and b3: "[x'].t' = [x].t" and b4: "T=T\<^isub>1\<rightarrow>T\<^isub>2" |
|
309 |
by auto |
|
310 |
obtain c::"name" where "c\<sharp>(\<Gamma>,x,x',t,t')" by (erule exists_fresh[OF fs_name1]) |
|
311 |
then have fs: "c\<sharp>\<Gamma>" "c\<noteq>x" "c\<noteq>x'" "c\<sharp>t" "c\<sharp>t'" by (simp_all add: fresh_atm[symmetric]) |
|
312 |
then have b5: "[(x',c)]\<bullet>t'=[(x,c)]\<bullet>t" using b3 fs by (simp add: alpha') |
|
313 |
have "([(x,c)]\<bullet>[(x',c)]\<bullet>((x',T\<^isub>1)#\<Gamma>)) \<turnstile> ([(x,c)]\<bullet>[(x',c)]\<bullet>t') : T\<^isub>2" using b2 |
|
314 |
by (simp only: typing_eqvt[simplified perm_ty]) |
|
315 |
then have "(x,T\<^isub>1)#\<Gamma> \<turnstile> t : T\<^isub>2" using fs b1 a2 b5 by (perm_simp add: calc_atm) |
|
316 |
then show ?thesis using prems b4 by simp |
|
317 |
qed |
|
318 |
||
22534 | 319 |
lemma t_Case_elim[elim]: |
22447 | 320 |
assumes "\<Gamma> \<turnstile> Case e of inl x\<^isub>1 \<rightarrow> e\<^isub>1 | inr x\<^isub>2 \<rightarrow> e\<^isub>2 : T" and "x\<^isub>1\<sharp>\<Gamma>" and "x\<^isub>2\<sharp>\<Gamma>" |
321 |
obtains \<sigma>\<^isub>1 \<sigma>\<^isub>2 where "\<Gamma> \<turnstile> e : Data (DSum \<sigma>\<^isub>1 \<sigma>\<^isub>2)" |
|
322 |
and "(x\<^isub>1, Data \<sigma>\<^isub>1)#\<Gamma> \<turnstile> e\<^isub>1 : T" |
|
323 |
and "(x\<^isub>2, Data \<sigma>\<^isub>2)#\<Gamma> \<turnstile> e\<^isub>2 : T" |
|
324 |
proof - |
|
325 |
have f:"x\<^isub>1\<sharp>\<Gamma>" "x\<^isub>2\<sharp>\<Gamma>" by fact |
|
326 |
have "\<Gamma> \<turnstile> Case e of inl x\<^isub>1 \<rightarrow> e\<^isub>1 | inr x\<^isub>2 \<rightarrow> e\<^isub>2 : T" by fact |
|
327 |
then obtain \<sigma>\<^isub>1 \<sigma>\<^isub>2 x\<^isub>1' x\<^isub>2' e\<^isub>1' e\<^isub>2' where |
|
328 |
h:"\<Gamma> \<turnstile> e : Data (DSum \<sigma>\<^isub>1 \<sigma>\<^isub>2)" and |
|
329 |
h1:"(x\<^isub>1',Data \<sigma>\<^isub>1)#\<Gamma> \<turnstile> e\<^isub>1' : T" and |
|
330 |
h2:"(x\<^isub>2',Data \<sigma>\<^isub>2)#\<Gamma> \<turnstile> e\<^isub>2' : T" and |
|
331 |
e1:"[x\<^isub>1].e\<^isub>1=[x\<^isub>1'].e\<^isub>1'" and e2:"[x\<^isub>2].e\<^isub>2=[x\<^isub>2'].e\<^isub>2'" |
|
332 |
by auto |
|
333 |
obtain c::name where f':"c \<sharp> (x\<^isub>1,x\<^isub>1',e\<^isub>1,e\<^isub>1',\<Gamma>)" by (erule exists_fresh[OF fs_name1]) |
|
334 |
have e1':"[(x\<^isub>1,c)]\<bullet>e\<^isub>1 = [(x\<^isub>1',c)]\<bullet>e\<^isub>1'" using e1 f' by (auto simp add: alpha' fresh_prod fresh_atm) |
|
22531 | 335 |
have "[(x\<^isub>1',c)]\<bullet>((x\<^isub>1',Data \<sigma>\<^isub>1)# \<Gamma>) \<turnstile> [(x\<^isub>1',c)]\<bullet>e\<^isub>1' : T" using h1 typing_eqvt' by blast |
22447 | 336 |
then have x:"(c,Data \<sigma>\<^isub>1)#( [(x\<^isub>1',c)]\<bullet>\<Gamma>) \<turnstile> [(x\<^isub>1',c)]\<bullet>e\<^isub>1': T" using f' |
337 |
by (auto simp add: fresh_atm calc_atm) |
|
22472 | 338 |
have "x\<^isub>1' \<sharp> \<Gamma>" using h1 typing_implies_valid by auto |
22447 | 339 |
then have "(c,Data \<sigma>\<^isub>1)#\<Gamma> \<turnstile> [(x\<^isub>1 ,c)]\<bullet>e\<^isub>1 : T" using f' x e1' by (auto simp add: perm_fresh_fresh) |
22531 | 340 |
then have "[(x\<^isub>1,c)]\<bullet>((c,Data \<sigma>\<^isub>1)#\<Gamma>) \<turnstile> [(x\<^isub>1,c)]\<bullet>[(x\<^isub>1 ,c)]\<bullet>e\<^isub>1 : T" using typing_eqvt' by blast |
22447 | 341 |
then have "([(x\<^isub>1,c)]\<bullet>(c,Data \<sigma>\<^isub>1)) #\<Gamma> \<turnstile> [(x\<^isub>1,c)]\<bullet>[(x\<^isub>1 ,c)]\<bullet>e\<^isub>1 : T" using f f' |
342 |
by (auto simp add: perm_fresh_fresh) |
|
343 |
then have "([(x\<^isub>1,c)]\<bullet>(c,Data \<sigma>\<^isub>1)) #\<Gamma> \<turnstile> e\<^isub>1 : T" by perm_simp |
|
344 |
then have g1:"(x\<^isub>1, Data \<sigma>\<^isub>1)#\<Gamma> \<turnstile> e\<^isub>1 : T" using f' by (auto simp add: fresh_atm calc_atm fresh_prod) |
|
345 |
(* The second part of the proof is the same *) |
|
346 |
obtain c::name where f':"c \<sharp> (x\<^isub>2,x\<^isub>2',e\<^isub>2,e\<^isub>2',\<Gamma>)" by (erule exists_fresh[OF fs_name1]) |
|
347 |
have e2':"[(x\<^isub>2,c)]\<bullet>e\<^isub>2 = [(x\<^isub>2',c)]\<bullet>e\<^isub>2'" using e2 f' by (auto simp add: alpha' fresh_prod fresh_atm) |
|
22531 | 348 |
have "[(x\<^isub>2',c)]\<bullet>((x\<^isub>2',Data \<sigma>\<^isub>2)# \<Gamma>) \<turnstile> [(x\<^isub>2',c)]\<bullet>e\<^isub>2' : T" using h2 typing_eqvt' by blast |
22447 | 349 |
then have x:"(c,Data \<sigma>\<^isub>2)#([(x\<^isub>2',c)]\<bullet>\<Gamma>) \<turnstile> [(x\<^isub>2',c)]\<bullet>e\<^isub>2': T" using f' |
350 |
by (auto simp add: fresh_atm calc_atm) |
|
22472 | 351 |
have "x\<^isub>2' \<sharp> \<Gamma>" using h2 typing_implies_valid by auto |
22447 | 352 |
then have "(c,Data \<sigma>\<^isub>2)#\<Gamma> \<turnstile> [(x\<^isub>2 ,c)]\<bullet>e\<^isub>2 : T" using f' x e2' by (auto simp add: perm_fresh_fresh) |
22531 | 353 |
then have "[(x\<^isub>2,c)]\<bullet>((c,Data \<sigma>\<^isub>2)#\<Gamma>) \<turnstile> [(x\<^isub>2,c)]\<bullet>[(x\<^isub>2 ,c)]\<bullet>e\<^isub>2 : T" using typing_eqvt' by blast |
22447 | 354 |
then have "([(x\<^isub>2,c)]\<bullet>(c,Data \<sigma>\<^isub>2))#\<Gamma> \<turnstile> [(x\<^isub>2,c)]\<bullet>[(x\<^isub>2 ,c)]\<bullet>e\<^isub>2 : T" using f f' |
355 |
by (auto simp add: perm_fresh_fresh) |
|
356 |
then have "([(x\<^isub>2,c)]\<bullet>(c,Data \<sigma>\<^isub>2)) #\<Gamma> \<turnstile> e\<^isub>2 : T" by perm_simp |
|
357 |
then have g2:"(x\<^isub>2,Data \<sigma>\<^isub>2)#\<Gamma> \<turnstile> e\<^isub>2 : T" using f' by (auto simp add: fresh_atm calc_atm fresh_prod) |
|
358 |
show ?thesis using g1 g2 prems by auto |
|
359 |
qed |
|
360 |
||
361 |
lemma weakening: |
|
362 |
assumes "\<Gamma>\<^isub>1 \<turnstile> e: T" and "valid \<Gamma>\<^isub>2" and "\<Gamma>\<^isub>1 \<lless> \<Gamma>\<^isub>2" |
|
363 |
shows "\<Gamma>\<^isub>2 \<turnstile> e: T" |
|
364 |
using assms |
|
22534 | 365 |
proof(nominal_induct \<Gamma>\<^isub>1 e T avoiding: \<Gamma>\<^isub>2 rule: typing.strong_induct) |
22447 | 366 |
case (t_Lam x \<Gamma>\<^isub>1 T\<^isub>1 t T\<^isub>2 \<Gamma>\<^isub>2) |
367 |
have ih: "\<lbrakk>valid ((x,T\<^isub>1)#\<Gamma>\<^isub>2); (x,T\<^isub>1)#\<Gamma>\<^isub>1 \<lless> (x,T\<^isub>1)#\<Gamma>\<^isub>2\<rbrakk> \<Longrightarrow> (x,T\<^isub>1)#\<Gamma>\<^isub>2 \<turnstile> t : T\<^isub>2" by fact |
|
368 |
have H1: "valid \<Gamma>\<^isub>2" by fact |
|
369 |
have H2: "\<Gamma>\<^isub>1 \<lless> \<Gamma>\<^isub>2" by fact |
|
370 |
have fs: "x\<sharp>\<Gamma>\<^isub>2" by fact |
|
371 |
then have "valid ((x,T\<^isub>1)#\<Gamma>\<^isub>2)" using H1 by auto |
|
372 |
moreover have "(x,T\<^isub>1)#\<Gamma>\<^isub>1 \<lless> (x,T\<^isub>1)#\<Gamma>\<^isub>2" using H2 by auto |
|
373 |
ultimately have "(x,T\<^isub>1)#\<Gamma>\<^isub>2 \<turnstile> t : T\<^isub>2" using ih by simp |
|
374 |
thus "\<Gamma>\<^isub>2 \<turnstile> Lam [x].t : T\<^isub>1\<rightarrow>T\<^isub>2" using fs by auto |
|
375 |
next |
|
376 |
case (t_Case x\<^isub>1 \<Gamma>\<^isub>1 e e\<^isub>2 x\<^isub>2 e\<^isub>1 S\<^isub>1 S\<^isub>2 T \<Gamma>\<^isub>2) |
|
377 |
then have ih\<^isub>1: "valid ((x\<^isub>1,Data S\<^isub>1)#\<Gamma>\<^isub>2) \<Longrightarrow> (x\<^isub>1,Data S\<^isub>1)#\<Gamma>\<^isub>2 \<turnstile> e\<^isub>1 : T" |
|
378 |
and ih\<^isub>2: "valid ((x\<^isub>2,Data S\<^isub>2)#\<Gamma>\<^isub>2) \<Longrightarrow> (x\<^isub>2,Data S\<^isub>2)#\<Gamma>\<^isub>2 \<turnstile> e\<^isub>2 : T" |
|
379 |
and ih\<^isub>3: "\<Gamma>\<^isub>2 \<turnstile> e : Data (DSum S\<^isub>1 S\<^isub>2)" by auto |
|
380 |
have fs\<^isub>1: "x\<^isub>1\<sharp>\<Gamma>\<^isub>2" "x\<^isub>1\<sharp>e" "x\<^isub>1\<sharp>e\<^isub>2" "x\<^isub>1\<sharp>x\<^isub>2" by fact |
|
381 |
have fs\<^isub>2: "x\<^isub>2\<sharp>\<Gamma>\<^isub>2" "x\<^isub>2\<sharp>e" "x\<^isub>2\<sharp>e\<^isub>1" "x\<^isub>2\<sharp>x\<^isub>1" by fact |
|
382 |
have "valid \<Gamma>\<^isub>2" by fact |
|
383 |
then have "valid ((x\<^isub>1,Data S\<^isub>1)#\<Gamma>\<^isub>2)" and "valid ((x\<^isub>2,Data S\<^isub>2)#\<Gamma>\<^isub>2)" using fs\<^isub>1 fs\<^isub>2 by auto |
|
384 |
then have "(x\<^isub>1, Data S\<^isub>1)#\<Gamma>\<^isub>2 \<turnstile> e\<^isub>1 : T" and "(x\<^isub>2, Data S\<^isub>2)#\<Gamma>\<^isub>2 \<turnstile> e\<^isub>2 : T" using ih\<^isub>1 ih\<^isub>2 by simp_all |
|
385 |
with ih\<^isub>3 show "\<Gamma>\<^isub>2 \<turnstile> Case e of inl x\<^isub>1 \<rightarrow> e\<^isub>1 | inr x\<^isub>2 \<rightarrow> e\<^isub>2 : T" using fs\<^isub>1 fs\<^isub>2 by auto |
|
386 |
qed (auto) |
|
387 |
||
388 |
lemma context_exchange: |
|
389 |
assumes a: "(x\<^isub>1,T\<^isub>1)#(x\<^isub>2,T\<^isub>2)#\<Gamma> \<turnstile> e : T" |
|
390 |
shows "(x\<^isub>2,T\<^isub>2)#(x\<^isub>1,T\<^isub>1)#\<Gamma> \<turnstile> e : T" |
|
391 |
proof - |
|
22472 | 392 |
from a have "valid ((x\<^isub>1,T\<^isub>1)#(x\<^isub>2,T\<^isub>2)#\<Gamma>)" by (simp add: typing_implies_valid) |
22447 | 393 |
then have "x\<^isub>1\<noteq>x\<^isub>2" "x\<^isub>1\<sharp>\<Gamma>" "x\<^isub>2\<sharp>\<Gamma>" "valid \<Gamma>" |
394 |
by (auto simp: fresh_list_cons fresh_atm[symmetric]) |
|
395 |
then have "valid ((x\<^isub>2,T\<^isub>2)#(x\<^isub>1,T\<^isub>1)#\<Gamma>)" |
|
396 |
by (auto simp: fresh_list_cons fresh_atm) |
|
397 |
moreover |
|
398 |
have "(x\<^isub>1,T\<^isub>1)#(x\<^isub>2,T\<^isub>2)#\<Gamma> \<lless> (x\<^isub>2,T\<^isub>2)#(x\<^isub>1,T\<^isub>1)#\<Gamma>" by auto |
|
399 |
ultimately show "(x\<^isub>2,T\<^isub>2)#(x\<^isub>1,T\<^isub>1)#\<Gamma> \<turnstile> e : T" using a by (auto intro: weakening) |
|
400 |
qed |
|
401 |
||
402 |
lemma typing_var_unicity: |
|
403 |
assumes "(x,t\<^isub>1)#\<Gamma> \<turnstile> Var x : t\<^isub>2" |
|
404 |
shows "t\<^isub>1=t\<^isub>2" |
|
405 |
proof - |
|
406 |
have "(x,t\<^isub>2) \<in> set ((x,t\<^isub>1)#\<Gamma>)" and "valid ((x,t\<^isub>1)#\<Gamma>)" using assms by auto |
|
407 |
thus "t\<^isub>1=t\<^isub>2" by (simp only: type_unicity_in_context) |
|
408 |
qed |
|
409 |
||
410 |
lemma typing_substitution: |
|
411 |
fixes \<Gamma>::"(name \<times> ty) list" |
|
412 |
assumes "(x,T')#\<Gamma> \<turnstile> e : T" |
|
413 |
and "\<Gamma> \<turnstile> e': T'" |
|
414 |
shows "\<Gamma> \<turnstile> e[x::=e'] : T" |
|
415 |
using assms |
|
416 |
proof (nominal_induct e avoiding: \<Gamma> e' x arbitrary: T rule: trm.induct) |
|
417 |
case (Var y \<Gamma> e' x T) |
|
418 |
have h1: "(x,T')#\<Gamma> \<turnstile> Var y : T" by fact |
|
419 |
have h2: "\<Gamma> \<turnstile> e' : T'" by fact |
|
420 |
show "\<Gamma> \<turnstile> (Var y)[x::=e'] : T" |
|
421 |
proof (cases "x=y") |
|
422 |
case True |
|
423 |
assume as: "x=y" |
|
424 |
then have "T=T'" using h1 typing_var_unicity by auto |
|
425 |
then show "\<Gamma> \<turnstile> (Var y)[x::=e'] : T" using as h2 by simp |
|
426 |
next |
|
427 |
case False |
|
428 |
assume as: "x\<noteq>y" |
|
429 |
have "(y,T) \<in> set ((x,T')#\<Gamma>)" using h1 by auto |
|
430 |
then have "(y,T) \<in> set \<Gamma>" using as by auto |
|
431 |
moreover |
|
22472 | 432 |
have "valid \<Gamma>" using h2 by (simp only: typing_implies_valid) |
22447 | 433 |
ultimately show "\<Gamma> \<turnstile> (Var y)[x::=e'] : T" using as by (simp add: t_Var) |
434 |
qed |
|
435 |
next |
|
436 |
case (Lam y t \<Gamma> e' x T) |
|
437 |
have vc: "y\<sharp>\<Gamma>" "y\<sharp>x" "y\<sharp>e'" by fact |
|
438 |
have pr1: "\<Gamma> \<turnstile> e' : T'" by fact |
|
439 |
have pr2: "(x,T')#\<Gamma> \<turnstile> Lam [y].t : T" by fact |
|
440 |
then obtain T\<^isub>1 T\<^isub>2 where pr2': "(y,T\<^isub>1)#(x,T')#\<Gamma> \<turnstile> t : T\<^isub>2" and eq: "T = T\<^isub>1\<rightarrow>T\<^isub>2" |
|
441 |
using vc by (auto simp add: fresh_list_cons) |
|
442 |
then have pr2'':"(x,T')#(y,T\<^isub>1)#\<Gamma> \<turnstile> t : T\<^isub>2" by (simp add: context_exchange) |
|
443 |
have ih: "\<lbrakk>(x,T')#(y,T\<^isub>1)#\<Gamma> \<turnstile> t : T\<^isub>2; (y,T\<^isub>1)#\<Gamma> \<turnstile> e' : T'\<rbrakk> \<Longrightarrow> (y,T\<^isub>1)#\<Gamma> \<turnstile> t[x::=e'] : T\<^isub>2" by fact |
|
22472 | 444 |
have "valid \<Gamma>" using pr1 by (simp add: typing_implies_valid) |
22447 | 445 |
then have "valid ((y,T\<^isub>1)#\<Gamma>)" using vc by auto |
446 |
then have "(y,T\<^isub>1)#\<Gamma> \<turnstile> e' : T'" using pr1 by (auto intro: weakening) |
|
447 |
then have "(y,T\<^isub>1)#\<Gamma> \<turnstile> t[x::=e'] : T\<^isub>2" using ih pr2'' by simp |
|
448 |
then have "\<Gamma> \<turnstile> Lam [y].(t[x::=e']) : T\<^isub>1\<rightarrow>T\<^isub>2" using vc by (auto intro: t_Lam) |
|
449 |
thus "\<Gamma> \<turnstile> (Lam [y].t)[x::=e'] : T" using vc eq by simp |
|
450 |
next |
|
451 |
case (Case t\<^isub>1 x\<^isub>1 t\<^isub>2 x\<^isub>2 t3 \<Gamma> e' x T) |
|
452 |
have vc: "x\<^isub>1\<sharp>\<Gamma>" "x\<^isub>1\<sharp>e'" "x\<^isub>1\<sharp>x""x\<^isub>1\<sharp>t\<^isub>1" "x\<^isub>1\<sharp>t3" "x\<^isub>2\<sharp>\<Gamma>" |
|
453 |
"x\<^isub>2\<sharp>e'" "x\<^isub>2\<sharp>x" "x\<^isub>2\<sharp>t\<^isub>1" "x\<^isub>2\<sharp>t\<^isub>2" "x\<^isub>2\<noteq>x\<^isub>1" by fact |
|
454 |
have as1: "\<Gamma> \<turnstile> e' : T'" by fact |
|
455 |
have as2: "(x,T')#\<Gamma> \<turnstile> Case t\<^isub>1 of inl x\<^isub>1 \<rightarrow> t\<^isub>2 | inr x\<^isub>2 \<rightarrow> t3 : T" by fact |
|
456 |
then obtain S\<^isub>1 S\<^isub>2 where |
|
457 |
h1:"(x,T')#\<Gamma> \<turnstile> t\<^isub>1 : Data (DSum S\<^isub>1 S\<^isub>2)" and |
|
458 |
h2:"(x\<^isub>1,Data S\<^isub>1)#(x,T')#\<Gamma> \<turnstile> t\<^isub>2 : T" and |
|
459 |
h3:"(x\<^isub>2,Data S\<^isub>2)#(x,T')#\<Gamma> \<turnstile> t3 : T" |
|
460 |
using vc by (auto simp add: fresh_list_cons) |
|
461 |
have ih1: "\<lbrakk>(x,T')#\<Gamma> \<turnstile> t\<^isub>1 : T; \<Gamma> \<turnstile> e' : T'\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> t\<^isub>1[x::=e'] : T" |
|
462 |
and ih2: "\<lbrakk>(x,T')#(x\<^isub>1,Data S\<^isub>1)#\<Gamma> \<turnstile> t\<^isub>2:T; (x\<^isub>1,Data S\<^isub>1)#\<Gamma> \<turnstile> e':T'\<rbrakk> \<Longrightarrow> (x\<^isub>1,Data S\<^isub>1)#\<Gamma> \<turnstile> t\<^isub>2[x::=e']:T" |
|
463 |
and ih3: "\<lbrakk>(x,T')#(x\<^isub>2,Data S\<^isub>2)#\<Gamma> \<turnstile> t3:T; (x\<^isub>2,Data S\<^isub>2)#\<Gamma> \<turnstile> e':T'\<rbrakk> \<Longrightarrow> (x\<^isub>2,Data S\<^isub>2)#\<Gamma> \<turnstile> t3[x::=e']:T" |
|
464 |
by fact |
|
465 |
from h2 have h2': "(x,T')#(x\<^isub>1,Data S\<^isub>1)#\<Gamma> \<turnstile> t\<^isub>2 : T" by (rule context_exchange) |
|
466 |
from h3 have h3': "(x,T')#(x\<^isub>2,Data S\<^isub>2)#\<Gamma> \<turnstile> t3 : T" by (rule context_exchange) |
|
467 |
have "\<Gamma> \<turnstile> t\<^isub>1[x::=e'] : Data (DSum S\<^isub>1 S\<^isub>2)" using h1 ih1 as1 by simp |
|
468 |
moreover |
|
22472 | 469 |
have "valid ((x\<^isub>1,Data S\<^isub>1)#\<Gamma>)" using h2' by (auto dest: typing_implies_valid) |
22447 | 470 |
then have "(x\<^isub>1,Data S\<^isub>1)#\<Gamma> \<turnstile> e' : T'" using as1 by (auto simp add: weakening) |
471 |
then have "(x\<^isub>1,Data S\<^isub>1)#\<Gamma> \<turnstile> t\<^isub>2[x::=e'] : T" using ih2 h2' by simp |
|
472 |
moreover |
|
22472 | 473 |
have "valid ((x\<^isub>2,Data S\<^isub>2)#\<Gamma>)" using h3' by (auto dest: typing_implies_valid) |
22447 | 474 |
then have "(x\<^isub>2,Data S\<^isub>2)#\<Gamma> \<turnstile> e' : T'" using as1 by (auto simp add: weakening) |
475 |
then have "(x\<^isub>2,Data S\<^isub>2)#\<Gamma> \<turnstile> t3[x::=e'] : T" using ih3 h3' by simp |
|
476 |
ultimately have "\<Gamma> \<turnstile> Case (t\<^isub>1[x::=e']) of inl x\<^isub>1 \<rightarrow> (t\<^isub>2[x::=e']) | inr x\<^isub>2 \<rightarrow> (t3[x::=e']) : T" |
|
477 |
using vc by (auto simp add: fresh_atm fresh_subst) |
|
478 |
thus "\<Gamma> \<turnstile> (Case t\<^isub>1 of inl x\<^isub>1 \<rightarrow> t\<^isub>2 | inr x\<^isub>2 \<rightarrow> t3)[x::=e'] : T" using vc by simp |
|
479 |
qed (simp, fast)+ |
|
480 |
||
481 |
text {* Big-Step Evaluation *} |
|
482 |
||
483 |
inductive2 |
|
484 |
big :: "trm\<Rightarrow>trm\<Rightarrow>bool" ("_ \<Down> _" [80,80] 80) |
|
485 |
where |
|
486 |
b_Lam[intro]: "Lam [x].e \<Down> Lam [x].e" |
|
487 |
| 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'" |
|
488 |
| b_Const[intro]: "Const n \<Down> Const n" |
|
489 |
| b_Pr[intro]: "\<lbrakk>e\<^isub>1\<Down>e\<^isub>1'; e\<^isub>2\<Down>e\<^isub>2'\<rbrakk> \<Longrightarrow> Pr e\<^isub>1 e\<^isub>2 \<Down> Pr e\<^isub>1' e\<^isub>2'" |
|
490 |
| b_Fst[intro]: "e\<Down>Pr e\<^isub>1 e\<^isub>2 \<Longrightarrow> Fst e\<Down>e\<^isub>1" |
|
491 |
| b_Snd[intro]: "e\<Down>Pr e\<^isub>1 e\<^isub>2 \<Longrightarrow> Snd e\<Down>e\<^isub>2" |
|
492 |
| b_InL[intro]: "e\<Down>e' \<Longrightarrow> InL e \<Down> InL e'" |
|
493 |
| b_InR[intro]: "e\<Down>e' \<Longrightarrow> InR e \<Down> InR e'" |
|
494 |
| b_CaseL[intro]: "\<lbrakk>x\<^isub>1\<sharp>(e,e\<^isub>2,e'',x\<^isub>2); x\<^isub>2\<sharp>(e,e\<^isub>1,e'',x\<^isub>1) ; e\<Down>InL e'; e\<^isub>1[x\<^isub>1::=e']\<Down>e''\<rbrakk> |
|
495 |
\<Longrightarrow> Case e of inl x\<^isub>1 \<rightarrow> e\<^isub>1 | inr x\<^isub>2 \<rightarrow> e\<^isub>2 \<Down> e''" |
|
496 |
| b_CaseR[intro]: "\<lbrakk>x\<^isub>1\<sharp>(e,e\<^isub>2,e'',x\<^isub>2); x\<^isub>2\<sharp>(e,e\<^isub>1,e'',x\<^isub>1) ; e\<Down>InR e'; e\<^isub>2[x\<^isub>2::=e']\<Down>e''\<rbrakk> |
|
497 |
\<Longrightarrow> Case e of inl x\<^isub>1 \<rightarrow> e\<^isub>1 | inr x\<^isub>2 \<rightarrow> e\<^isub>2 \<Down> e''" |
|
498 |
||
499 |
nominal_inductive big |
|
22531 | 500 |
by (simp_all add: abs_fresh fresh_prod fresh_atm) |
22472 | 501 |
|
502 |
lemma big_eqvt': |
|
503 |
fixes pi::"name prm" |
|
504 |
assumes a: "(pi\<bullet>t) \<Down> (pi\<bullet>t')" |
|
505 |
shows "t \<Down> t'" |
|
506 |
using a |
|
507 |
apply - |
|
508 |
apply(drule_tac pi="rev pi" in big_eqvt) |
|
509 |
apply(perm_simp) |
|
510 |
done |
|
511 |
||
22447 | 512 |
lemma fresh_preserved: |
513 |
fixes x::name |
|
514 |
fixes t::trm |
|
515 |
fixes t'::trm |
|
516 |
assumes "e \<Down> e'" and "x\<sharp>e" |
|
517 |
shows "x\<sharp>e'" |
|
518 |
using assms by (induct) (auto simp add:fresh_subst') |
|
519 |
||
520 |
declare trm.inject [simp add] |
|
521 |
declare ty.inject [simp add] |
|
522 |
declare data.inject [simp add] |
|
523 |
||
524 |
inductive_cases2 b_App_inv_auto[elim]: "App e\<^isub>1 e\<^isub>2 \<Down> t" |
|
525 |
inductive_cases2 b_Case_inv_auto[elim]: "Case e of inl x\<^isub>1 \<rightarrow> e\<^isub>1 | inr x\<^isub>2 \<rightarrow> e\<^isub>2 \<Down> t" |
|
526 |
inductive_cases2 b_Lam_inv_auto[elim]: "Lam[x].t \<Down> t" |
|
527 |
inductive_cases2 b_Const_inv_auto[elim]: "Const n \<Down> t" |
|
528 |
inductive_cases2 b_Fst_inv_auto[elim]: "Fst e \<Down> t" |
|
529 |
inductive_cases2 b_Snd_inv_auto[elim]: "Snd e \<Down> t" |
|
530 |
inductive_cases2 b_InL_inv_auto[elim]: "InL e \<Down> t" |
|
531 |
inductive_cases2 b_InR_inv_auto[elim]: "InR e \<Down> t" |
|
532 |
inductive_cases2 b_Pr_inv_auto[elim]: "Pr e\<^isub>1 e\<^isub>2 \<Down> t" |
|
533 |
||
534 |
declare trm.inject [simp del] |
|
535 |
declare ty.inject [simp del] |
|
536 |
declare data.inject [simp del] |
|
537 |
||
538 |
lemma b_App_elim[elim]: |
|
539 |
assumes "App e\<^isub>1 e\<^isub>2 \<Down> e'" and "x\<sharp>(e\<^isub>1,e\<^isub>2,e')" |
|
540 |
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'" |
|
541 |
using assms |
|
542 |
apply - |
|
543 |
apply(erule b_App_inv_auto) |
|
544 |
apply(drule_tac pi="[(xa,x)]" in big_eqvt) |
|
545 |
apply(drule_tac pi="[(xa,x)]" in big_eqvt) |
|
546 |
apply(drule_tac pi="[(xa,x)]" 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
|
547 |
apply(perm_simp add: calc_atm eqvts) |
22447 | 548 |
done |
549 |
||
550 |
lemma b_CaseL_elim[elim]: |
|
22472 | 551 |
assumes "Case e of inl x\<^isub>1 \<rightarrow> e\<^isub>1 | inr x\<^isub>2 \<rightarrow> e\<^isub>2 \<Down> e''" |
552 |
and "\<And> t. \<not> e \<Down> InR t" |
|
553 |
and "x\<^isub>1\<sharp>e''" "x\<^isub>1\<sharp>e" "x\<^isub>2\<sharp>e''" "x\<^isub>1\<sharp>e" |
|
22447 | 554 |
obtains e' where "e \<Down> InL e'" and "e\<^isub>1[x\<^isub>1::=e'] \<Down> e''" |
555 |
using assms |
|
556 |
apply - |
|
22472 | 557 |
apply(rule b_Case_inv_auto) |
558 |
apply(auto) |
|
559 |
apply(simp add: alpha) |
|
560 |
apply(auto) |
|
561 |
apply(drule_tac x="[(x\<^isub>1,x\<^isub>1')]\<bullet>e'" in meta_spec) |
|
562 |
apply(drule meta_mp) |
|
563 |
apply(rule_tac pi="[(x\<^isub>1,x\<^isub>1')]" in big_eqvt') |
|
564 |
apply(perm_simp add: fresh_prod) |
|
565 |
apply(drule meta_mp) |
|
566 |
apply(rule_tac pi="[(x\<^isub>1,x\<^isub>1')]" 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
|
567 |
apply(perm_simp add: eqvts calc_atm) |
22472 | 568 |
apply(assumption) |
569 |
apply(drule_tac x="[(x\<^isub>1,x\<^isub>1')]\<bullet>e'" in meta_spec) |
|
570 |
apply(drule meta_mp) |
|
571 |
apply(rule_tac pi="[(x\<^isub>1,x\<^isub>1')]" in big_eqvt') |
|
572 |
apply(perm_simp add: fresh_prod) |
|
573 |
apply(drule meta_mp) |
|
574 |
apply(rule_tac pi="[(x\<^isub>1,x\<^isub>1')]" 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
|
575 |
apply(perm_simp add: eqvts calc_atm) |
22472 | 576 |
apply(assumption) |
577 |
done |
|
22447 | 578 |
|
579 |
lemma b_CaseR_elim[elim]: |
|
22472 | 580 |
assumes "Case e of inl x\<^isub>1 \<rightarrow> e\<^isub>1 | inr x\<^isub>2 \<rightarrow> e\<^isub>2 \<Down> e''" |
581 |
and "\<And> t. \<not> e \<Down> InL t" |
|
582 |
and "x\<^isub>1\<sharp>e''" "x\<^isub>1\<sharp>e" "x\<^isub>2\<sharp>e''" "x\<^isub>2\<sharp>e" |
|
22447 | 583 |
obtains e' where "e \<Down> InR e'" and "e\<^isub>2[x\<^isub>2::=e'] \<Down> e''" |
22472 | 584 |
using assms |
22447 | 585 |
apply - |
22472 | 586 |
apply(rule b_Case_inv_auto) |
587 |
apply(auto) |
|
588 |
apply(simp add: alpha) |
|
589 |
apply(auto) |
|
590 |
apply(drule_tac x="[(x\<^isub>2,x\<^isub>2')]\<bullet>e'" in meta_spec) |
|
591 |
apply(drule meta_mp) |
|
592 |
apply(rule_tac pi="[(x\<^isub>2,x\<^isub>2')]" in big_eqvt') |
|
593 |
apply(perm_simp add: fresh_prod) |
|
594 |
apply(drule meta_mp) |
|
595 |
apply(rule_tac pi="[(x\<^isub>2,x\<^isub>2')]" 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
|
596 |
apply(perm_simp add: eqvts calc_atm) |
22472 | 597 |
apply(assumption) |
598 |
apply(drule_tac x="[(x\<^isub>2,x\<^isub>2')]\<bullet>e'" in meta_spec) |
|
599 |
apply(drule meta_mp) |
|
600 |
apply(rule_tac pi="[(x\<^isub>2,x\<^isub>2')]" in big_eqvt') |
|
601 |
apply(perm_simp add: fresh_prod) |
|
602 |
apply(drule meta_mp) |
|
603 |
apply(rule_tac pi="[(x\<^isub>2,x\<^isub>2')]" 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
|
604 |
apply(perm_simp add: eqvts calc_atm) |
22472 | 605 |
apply(assumption) |
606 |
done |
|
22447 | 607 |
|
608 |
inductive2 |
|
609 |
val :: "trm\<Rightarrow>bool" |
|
610 |
where |
|
611 |
v_Lam[intro]: "val (Lam [x].e)" |
|
612 |
| v_Const[intro]: "val (Const n)" |
|
613 |
| v_Pr[intro]: "\<lbrakk>val e\<^isub>1; val e\<^isub>2\<rbrakk> \<Longrightarrow> val (Pr e\<^isub>1 e\<^isub>2)" |
|
614 |
| v_InL[intro]: "val e \<Longrightarrow> val (InL e)" |
|
615 |
| v_InR[intro]: "val e \<Longrightarrow> val (InR e)" |
|
616 |
||
617 |
declare trm.inject [simp add] |
|
618 |
declare ty.inject [simp add] |
|
619 |
declare data.inject [simp add] |
|
620 |
||
621 |
inductive_cases2 v_Const_inv_auto[elim]: "val (Const n)" |
|
622 |
inductive_cases2 v_Pr_inv_auto[elim]: "val (Pr e\<^isub>1 e\<^isub>2)" |
|
623 |
inductive_cases2 v_InL_inv_auto[elim]: "val (InL e)" |
|
624 |
inductive_cases2 v_InR_inv_auto[elim]: "val (InR e)" |
|
625 |
inductive_cases2 v_Fst_inv_auto[elim]: "val (Fst e)" |
|
626 |
inductive_cases2 v_Snd_inv_auto[elim]: "val (Snd e)" |
|
627 |
inductive_cases2 v_Case_inv_auto[elim]: "val (Case e of inl x\<^isub>1 \<rightarrow> e\<^isub>1 | inr x\<^isub>2 \<rightarrow> e\<^isub>2)" |
|
628 |
inductive_cases2 v_Var_inv_auto[elim]: "val (Var x)" |
|
629 |
inductive_cases2 v_Lam_inv_auto[elim]: "val (Lam [x].e)" |
|
630 |
inductive_cases2 v_App_inv_auto[elim]: "val (App e\<^isub>1 e\<^isub>2)" |
|
631 |
||
632 |
declare trm.inject [simp del] |
|
633 |
declare ty.inject [simp del] |
|
634 |
declare data.inject [simp del] |
|
635 |
||
636 |
lemma subject_reduction: |
|
22472 | 637 |
assumes a: "e \<Down> e'" |
638 |
and b: "\<Gamma> \<turnstile> e : T" |
|
22447 | 639 |
shows "\<Gamma> \<turnstile> e' : T" |
22472 | 640 |
using a b |
22534 | 641 |
proof (nominal_induct avoiding: \<Gamma> arbitrary: T rule: big.strong_induct) |
642 |
case (b_App x e\<^isub>1 e\<^isub>2 e' e e\<^isub>2' \<Gamma> T) |
|
22447 | 643 |
have vc: "x\<sharp>\<Gamma>" by fact |
644 |
have "\<Gamma> \<turnstile> App e\<^isub>1 e\<^isub>2 : T" by fact |
|
22472 | 645 |
then obtain T' where |
22447 | 646 |
a1: "\<Gamma> \<turnstile> e\<^isub>1 : T'\<rightarrow>T" and |
647 |
a2: "\<Gamma> \<turnstile> e\<^isub>2 : T'" by auto |
|
22472 | 648 |
have ih1: "\<Gamma> \<turnstile> e\<^isub>1 : T' \<rightarrow> T \<Longrightarrow> \<Gamma> \<turnstile> Lam [x].e : T' \<rightarrow> T" by fact |
22447 | 649 |
have ih2: "\<Gamma> \<turnstile> e\<^isub>2 : T' \<Longrightarrow> \<Gamma> \<turnstile> e\<^isub>2' : T'" by fact |
650 |
have ih3: "\<Gamma> \<turnstile> e[x::=e\<^isub>2'] : T \<Longrightarrow> \<Gamma> \<turnstile> e' : T" by fact |
|
651 |
have "\<Gamma> \<turnstile> Lam [x].e : T'\<rightarrow>T" using ih1 a1 by simp |
|
652 |
then have "((x,T')#\<Gamma>) \<turnstile> e : T" using vc by (auto simp add: ty.inject) |
|
653 |
moreover |
|
654 |
have "\<Gamma> \<turnstile> e\<^isub>2': T'" using ih2 a2 by simp |
|
655 |
ultimately have "\<Gamma> \<turnstile> e[x::=e\<^isub>2'] : T" by (simp add: typing_substitution) |
|
656 |
thus "\<Gamma> \<turnstile> e' : T" using ih3 by simp |
|
657 |
next |
|
658 |
case (b_CaseL x\<^isub>1 e e\<^isub>2 e'' x\<^isub>2 e\<^isub>1 e' \<Gamma>) |
|
659 |
have vc: "x\<^isub>1\<sharp>\<Gamma>" "x\<^isub>2\<sharp>\<Gamma>" by fact |
|
660 |
have "\<Gamma> \<turnstile> Case e of inl x\<^isub>1 \<rightarrow> e\<^isub>1 | inr x\<^isub>2 \<rightarrow> e\<^isub>2 : T" by fact |
|
661 |
then obtain S\<^isub>1 S\<^isub>2 e\<^isub>1' e\<^isub>2' where |
|
662 |
a1: "\<Gamma> \<turnstile> e : Data (DSum S\<^isub>1 S\<^isub>2)" and |
|
663 |
a2: "((x\<^isub>1,Data S\<^isub>1)#\<Gamma>) \<turnstile> e\<^isub>1 : T" using vc by auto |
|
664 |
have ih1:"\<Gamma> \<turnstile> e : Data (DSum S\<^isub>1 S\<^isub>2) \<Longrightarrow> \<Gamma> \<turnstile> InL e' : Data (DSum S\<^isub>1 S\<^isub>2)" by fact |
|
665 |
have ih2:"\<Gamma> \<turnstile> e\<^isub>1[x\<^isub>1::=e'] : T \<Longrightarrow> \<Gamma> \<turnstile> e'' : T " by fact |
|
666 |
have "\<Gamma> \<turnstile> InL e' : Data (DSum S\<^isub>1 S\<^isub>2)" using ih1 a1 by simp |
|
667 |
then have "\<Gamma> \<turnstile> e' : Data S\<^isub>1" by auto |
|
668 |
then have "\<Gamma> \<turnstile> e\<^isub>1[x\<^isub>1::=e'] : T" using a2 by (simp add: typing_substitution) |
|
669 |
then show "\<Gamma> \<turnstile> e'' : T" using ih2 by simp |
|
670 |
next |
|
671 |
case (b_CaseR x\<^isub>1 e e\<^isub>2 e'' x\<^isub>2 e\<^isub>1 e' \<Gamma> T) |
|
672 |
then show "\<Gamma> \<turnstile> e'' : T" by (blast intro: typing_substitution) |
|
673 |
qed (blast)+ |
|
674 |
||
22472 | 675 |
lemma unicity_of_evaluation: |
676 |
assumes a: "e \<Down> e\<^isub>1" |
|
677 |
and b: "e \<Down> e\<^isub>2" |
|
22447 | 678 |
shows "e\<^isub>1 = e\<^isub>2" |
22472 | 679 |
using a b |
22534 | 680 |
proof (nominal_induct e e\<^isub>1 avoiding: e\<^isub>2 rule: big.strong_induct) |
22447 | 681 |
case (b_Lam x e t\<^isub>2) |
682 |
have "Lam [x].e \<Down> t\<^isub>2" by fact |
|
683 |
thus "Lam [x].e = t\<^isub>2" by (cases, simp_all add: trm.inject) |
|
684 |
next |
|
22534 | 685 |
case (b_App x e\<^isub>1 e\<^isub>2 e' e\<^isub>1' e\<^isub>2' t\<^isub>2) |
22447 | 686 |
have ih1: "\<And>t. e\<^isub>1 \<Down> t \<Longrightarrow> Lam [x].e\<^isub>1' = t" by fact |
687 |
have ih2:"\<And>t. e\<^isub>2 \<Down> t \<Longrightarrow> e\<^isub>2' = t" by fact |
|
688 |
have ih3: "\<And>t. e\<^isub>1'[x::=e\<^isub>2'] \<Down> t \<Longrightarrow> e' = t" by fact |
|
22472 | 689 |
have app: "App e\<^isub>1 e\<^isub>2 \<Down> t\<^isub>2" by fact |
690 |
have vc: "x\<sharp>e\<^isub>1" "x\<sharp>e\<^isub>2" by fact |
|
22447 | 691 |
then have "x \<sharp> App e\<^isub>1 e\<^isub>2" by auto |
22472 | 692 |
then have vc': "x\<sharp>t\<^isub>2" using fresh_preserved app by blast |
693 |
from vc 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" |
|
694 |
using app by (auto simp add: fresh_prod) |
|
695 |
then have "Lam [x]. f\<^isub>1 = Lam [x]. e\<^isub>1'" using ih1 by simp |
|
696 |
then |
|
697 |
have "f\<^isub>1 = e\<^isub>1'" by (auto simp add: trm.inject alpha) |
|
698 |
moreover |
|
699 |
have "f\<^isub>2 = e\<^isub>2'" using x2 ih2 by simp |
|
22447 | 700 |
ultimately have "e\<^isub>1'[x::=e\<^isub>2'] \<Down> t\<^isub>2" using x3 by simp |
701 |
thus ?case using ih3 by simp |
|
702 |
next |
|
22472 | 703 |
case (b_CaseL x\<^isub>1 e e\<^isub>2 e'' x\<^isub>2 e\<^isub>1 e' t\<^isub>2) |
704 |
have fs: "x\<^isub>1\<sharp>e" "x\<^isub>1\<sharp>t\<^isub>2" "x\<^isub>2\<sharp>e" "x\<^isub>2\<sharp>t\<^isub>2" by fact |
|
705 |
have ih1:"\<And>t. e \<Down> t \<Longrightarrow> InL e' = t" by fact |
|
22447 | 706 |
have ih2:"\<And>t. e\<^isub>1[x\<^isub>1::=e'] \<Down> t \<Longrightarrow> e'' = t" by fact |
22472 | 707 |
have ha: "\<not>(\<exists>t. e \<Down> InR t)" using ih1 by force |
22447 | 708 |
have "Case e of inl x\<^isub>1 \<rightarrow> e\<^isub>1 | inr x\<^isub>2 \<rightarrow> e\<^isub>2 \<Down> t\<^isub>2" by fact |
22472 | 709 |
then obtain f' where "e \<Down> InL f'" and h: "e\<^isub>1[x\<^isub>1::=f']\<Down>t\<^isub>2" using ha fs by auto |
710 |
then have "InL f' = InL e'" using ih1 by simp |
|
711 |
then have "f' = e'" by (simp add: trm.inject) |
|
22447 | 712 |
then have "e\<^isub>1[x\<^isub>1::=e'] \<Down> t\<^isub>2" using h by simp |
22472 | 713 |
then show "e'' = t\<^isub>2" using ih2 by simp |
22447 | 714 |
next |
715 |
case (b_CaseR x\<^isub>1 e e\<^isub>2 e'' x\<^isub>2 e\<^isub>1 e' t\<^isub>2 ) |
|
22472 | 716 |
have fs: "x\<^isub>1\<sharp>e" "x\<^isub>1\<sharp>t\<^isub>2" "x\<^isub>2\<sharp>e" "x\<^isub>2\<sharp>t\<^isub>2" by fact |
717 |
have ih1: "\<And>t. e \<Down> t \<Longrightarrow> InR e' = t" by fact |
|
718 |
have ih2: "\<And>t. e\<^isub>2[x\<^isub>2::=e'] \<Down> t \<Longrightarrow> e'' = t" by fact |
|
719 |
have ha: "\<not>(\<exists>t. e \<Down> InL t)" using ih1 by force |
|
22447 | 720 |
have "Case e of inl x\<^isub>1 \<rightarrow> e\<^isub>1 | inr x\<^isub>2 \<rightarrow> e\<^isub>2 \<Down> t\<^isub>2" by fact |
22472 | 721 |
then obtain f' where "e \<Down> InR f'" and h: "e\<^isub>2[x\<^isub>2::=f']\<Down>t\<^isub>2" using ha fs by auto |
722 |
then have "InR f' = InR e'" using ih1 by simp |
|
22447 | 723 |
then have "e\<^isub>2[x\<^isub>2::=e'] \<Down> t\<^isub>2" using h by (simp add: trm.inject) |
22472 | 724 |
thus "e'' = t\<^isub>2" using ih2 by simp |
22534 | 725 |
next |
726 |
case b_Const |
|
727 |
then show ?case by force |
|
728 |
next |
|
729 |
case b_Pr |
|
730 |
then show ?case by blast |
|
731 |
next |
|
732 |
case b_Fst |
|
733 |
then show ?case by (force simp add: trm.inject) |
|
734 |
next |
|
735 |
case b_Snd |
|
736 |
then show ?case by (force simp add: trm.inject) |
|
737 |
next |
|
738 |
case b_InL |
|
739 |
then show ?case by blast |
|
740 |
next |
|
741 |
case b_InR |
|
742 |
then show ?case by blast |
|
743 |
qed |
|
22447 | 744 |
|
745 |
lemma not_val_App[simp]: |
|
746 |
shows |
|
747 |
"\<not> val (App e\<^isub>1 e\<^isub>2)" |
|
748 |
"\<not> val (Fst e)" |
|
749 |
"\<not> val (Snd e)" |
|
750 |
"\<not> val (Var x)" |
|
751 |
"\<not> val (Case e of inl x\<^isub>1 \<rightarrow> e\<^isub>1 | inr x\<^isub>2 \<rightarrow> e\<^isub>2)" |
|
752 |
by auto |
|
753 |
||
22472 | 754 |
lemma reduces_evaluates_to_values: |
22447 | 755 |
assumes h:"t \<Down> t'" |
756 |
shows "val t'" |
|
22472 | 757 |
using h by (induct) (auto) |
22447 | 758 |
|
22472 | 759 |
lemma type_prod_evaluates_to_pairs: |
760 |
assumes a: "\<Gamma> \<turnstile> t : Data (DProd S\<^isub>1 S\<^isub>2)" |
|
761 |
and b: "t \<Down> t'" |
|
22447 | 762 |
obtains t\<^isub>1 t\<^isub>2 where "t' = Pr t\<^isub>1 t\<^isub>2" |
763 |
proof - |
|
764 |
have "\<Gamma> \<turnstile> t' : Data (DProd S\<^isub>1 S\<^isub>2)" using assms subject_reduction by simp |
|
765 |
moreover |
|
22472 | 766 |
have "val t'" using reduces_evaluates_to_values assms by simp |
22447 | 767 |
ultimately obtain t\<^isub>1 t\<^isub>2 where "t' = Pr t\<^isub>1 t\<^isub>2" by (cases, auto simp add:ty.inject data.inject) |
768 |
thus ?thesis using prems by auto |
|
769 |
qed |
|
770 |
||
22472 | 771 |
lemma type_sum_evaluates_to_ins: |
22447 | 772 |
assumes "\<Gamma> \<turnstile> t : Data (DSum \<sigma>\<^isub>1 \<sigma>\<^isub>2)" and "t \<Down> t'" |
22472 | 773 |
shows "(\<exists>t''. t' = InL t'') \<or> (\<exists>t''. t' = InR t'')" |
22447 | 774 |
proof - |
775 |
have "\<Gamma> \<turnstile> t' : Data (DSum \<sigma>\<^isub>1 \<sigma>\<^isub>2)" using assms subject_reduction by simp |
|
776 |
moreover |
|
22472 | 777 |
have "val t'" using reduces_evaluates_to_values assms by simp |
22447 | 778 |
ultimately obtain t'' where "t' = InL t'' \<or> t' = InR t''" |
779 |
by (cases, auto simp add:ty.inject data.inject) |
|
780 |
thus ?thesis by auto |
|
781 |
qed |
|
782 |
||
22472 | 783 |
lemma type_arrow_evaluates_to_lams: |
22447 | 784 |
assumes "\<Gamma> \<turnstile> t : \<sigma> \<rightarrow> \<tau>" and "t \<Down> t'" |
785 |
obtains x t'' where "t' = Lam [x]. t''" |
|
786 |
proof - |
|
787 |
have "\<Gamma> \<turnstile> t' : \<sigma> \<rightarrow> \<tau>" using assms subject_reduction by simp |
|
788 |
moreover |
|
22472 | 789 |
have "val t'" using reduces_evaluates_to_values assms by simp |
22447 | 790 |
ultimately obtain x t'' where "t' = Lam [x]. t''" by (cases, auto simp add:ty.inject data.inject) |
791 |
thus ?thesis using prems by auto |
|
792 |
qed |
|
793 |
||
22472 | 794 |
lemma type_nat_evaluates_to_consts: |
22447 | 795 |
assumes "\<Gamma> \<turnstile> t : Data DNat" and "t \<Down> t'" |
796 |
obtains n where "t' = Const n" |
|
797 |
proof - |
|
798 |
have "\<Gamma> \<turnstile> t' : Data DNat " using assms subject_reduction by simp |
|
22472 | 799 |
moreover have "val t'" using reduces_evaluates_to_values assms by simp |
22447 | 800 |
ultimately obtain n where "t' = Const n" by (cases, auto simp add:ty.inject data.inject) |
801 |
thus ?thesis using prems by auto |
|
802 |
qed |
|
803 |
||
804 |
consts |
|
805 |
V' :: "data \<Rightarrow> trm set" |
|
806 |
||
807 |
nominal_primrec |
|
808 |
"V' (DNat) = {Const n | n. n \<in> (UNIV::nat set)}" |
|
809 |
"V' (DProd S\<^isub>1 S\<^isub>2) = {Pr x y | x y. x \<in> V' S\<^isub>1 \<and> y \<in> V' S\<^isub>2}" |
|
810 |
"V' (DSum S\<^isub>1 S\<^isub>2) = {InL x | x. x \<in> V' S\<^isub>1} \<union> {InR y | y. y \<in> V' S\<^isub>2}" |
|
811 |
apply(rule TrueI)+ |
|
812 |
done |
|
813 |
||
814 |
lemma Vprimes_are_values : |
|
815 |
fixes S::"data" |
|
816 |
assumes h: "e \<in> V' S" |
|
817 |
shows "val e" |
|
818 |
using h |
|
819 |
by (nominal_induct S arbitrary: e rule:data.induct) |
|
820 |
(auto) |
|
821 |
||
22472 | 822 |
lemma V'_eqvt: |
823 |
fixes pi::"name prm" |
|
824 |
assumes a: "v \<in> V' S" |
|
825 |
shows "(pi\<bullet>v) \<in> V' S" |
|
826 |
using a |
|
827 |
by (nominal_induct S arbitrary: v rule: data.induct) |
|
828 |
(auto simp add: trm.inject) |
|
829 |
||
22447 | 830 |
consts |
831 |
V :: "ty \<Rightarrow> trm set" |
|
832 |
||
833 |
nominal_primrec |
|
834 |
"V (Data S) = V' S" |
|
835 |
"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}" |
|
836 |
apply(rule TrueI)+ |
|
837 |
done |
|
838 |
||
22472 | 839 |
lemma V_eqvt: |
840 |
fixes pi::"name prm" |
|
841 |
assumes a: "x\<in>V T" |
|
842 |
shows "(pi\<bullet>x)\<in>V T" |
|
843 |
using a |
|
844 |
apply(nominal_induct T arbitrary: pi x rule: ty.induct) |
|
845 |
apply(auto simp add: trm.inject perm_set_def) |
|
846 |
apply(perm_simp add: V'_eqvt) |
|
847 |
apply(rule_tac x="pi\<bullet>xa" in exI) |
|
848 |
apply(rule_tac x="pi\<bullet>e" in exI) |
|
849 |
apply(simp) |
|
850 |
apply(auto) |
|
851 |
apply(drule_tac x="(rev pi)\<bullet>v" in bspec) |
|
852 |
apply(force) |
|
853 |
apply(auto) |
|
854 |
apply(rule_tac x="pi\<bullet>v'" in exI) |
|
855 |
apply(auto) |
|
856 |
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
|
857 |
apply(perm_simp add: eqvts) |
22472 | 858 |
done |
859 |
||
22447 | 860 |
lemma V_arrow_elim_weak[elim] : |
861 |
assumes h:"u \<in> (V (T\<^isub>1 \<rightarrow> T\<^isub>2))" |
|
862 |
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" |
|
863 |
using h by (auto) |
|
864 |
||
865 |
lemma V_arrow_elim_strong[elim]: |
|
866 |
fixes c::"'a::fs_name" |
|
22472 | 867 |
assumes h: "u \<in> V (T\<^isub>1 \<rightarrow> T\<^isub>2)" |
868 |
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 | 869 |
using h |
870 |
apply - |
|
871 |
apply(erule V_arrow_elim_weak) |
|
22472 | 872 |
apply(subgoal_tac "\<exists>a'::name. a'\<sharp>(a,t,c)") (*A*) |
22447 | 873 |
apply(erule exE) |
874 |
apply(drule_tac x="a'" in meta_spec) |
|
22472 | 875 |
apply(drule_tac x="[(a,a')]\<bullet>t" in meta_spec) |
876 |
apply(drule meta_mp) |
|
22447 | 877 |
apply(simp) |
22472 | 878 |
apply(drule meta_mp) |
879 |
apply(simp add: trm.inject alpha fresh_left fresh_prod calc_atm fresh_atm) |
|
22447 | 880 |
apply(perm_simp) |
22472 | 881 |
apply(force) |
882 |
apply(drule meta_mp) |
|
883 |
apply(rule ballI) |
|
884 |
apply(drule_tac x="[(a,a')]\<bullet>v" in bspec) |
|
885 |
apply(simp add: V_eqvt) |
|
22447 | 886 |
apply(auto) |
22472 | 887 |
apply(rule_tac x="[(a,a')]\<bullet>v'" in exI) |
888 |
apply(auto) |
|
889 |
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
|
890 |
apply(perm_simp add: eqvts calc_atm) |
22472 | 891 |
apply(simp add: V_eqvt) |
892 |
(*A*) |
|
22447 | 893 |
apply(rule exists_fresh') |
22472 | 894 |
apply(simp add: fin_supp) |
22447 | 895 |
done |
896 |
||
897 |
lemma V_are_values : |
|
898 |
fixes T::"ty" |
|
899 |
assumes h:"e \<in> V T" |
|
900 |
shows "val e" |
|
901 |
using h by (nominal_induct T arbitrary: e rule:ty.induct, auto simp add: Vprimes_are_values) |
|
902 |
||
903 |
lemma values_reduce_to_themselves: |
|
904 |
assumes h:"val v" |
|
905 |
shows "v \<Down> v" |
|
906 |
using h by (induct,auto) |
|
907 |
||
908 |
lemma Vs_reduce_to_themselves[simp]: |
|
909 |
assumes h:"v \<in> V T" |
|
910 |
shows "v \<Down> v" |
|
911 |
using h by (simp add: values_reduce_to_themselves V_are_values) |
|
912 |
||
913 |
lemma V_sum: |
|
914 |
assumes h:"x \<in> V (Data (DSum S\<^isub>1 S\<^isub>2))" |
|
915 |
shows "(\<exists> y. x= InL y \<and> y \<in> V' S\<^isub>1) \<or> (\<exists> y. x= InR y \<and> y \<in> V' S\<^isub>2)" |
|
916 |
using h by simp |
|
917 |
||
918 |
abbreviation |
|
919 |
mapsto :: "(name\<times>trm) list \<Rightarrow> name \<Rightarrow> trm \<Rightarrow> bool" ("_ maps _ to _" [55,55,55] 55) |
|
920 |
where |
|
921 |
"\<theta> maps x to e\<equiv> (lookup \<theta> x) = e" |
|
922 |
||
923 |
abbreviation |
|
924 |
v_closes :: "(name\<times>trm) list \<Rightarrow> (name\<times>ty) list \<Rightarrow> bool" ("_ Vcloses _" [55,55] 55) |
|
925 |
where |
|
926 |
"\<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)))" |
|
927 |
||
928 |
lemma monotonicity: |
|
929 |
fixes m::"name" |
|
930 |
fixes \<theta>::"(name \<times> trm) list" |
|
931 |
assumes h1: "\<theta> Vcloses \<Gamma>" |
|
932 |
and h2: "e \<in> V T" |
|
933 |
and h3: "valid ((x,T)#\<Gamma>)" |
|
934 |
shows "(x,e)#\<theta> Vcloses (x,T)#\<Gamma>" |
|
935 |
proof(intro strip) |
|
936 |
fix x' T' |
|
937 |
assume "(x',T') \<in> set ((x,T)#\<Gamma>)" |
|
938 |
then have "((x',T')=(x,T)) \<or> ((x',T')\<in>set \<Gamma> \<and> x'\<noteq>x)" using h3 |
|
939 |
by (rule_tac case_distinction_on_context) |
|
940 |
moreover |
|
941 |
{ (* first case *) |
|
942 |
assume "(x',T') = (x,T)" |
|
943 |
then have "\<exists>e'. ((x,e)#\<theta>) maps x to e' \<and> e' \<in> V T'" using h2 by auto |
|
944 |
} |
|
945 |
moreover |
|
946 |
{ (* second case *) |
|
947 |
assume "(x',T') \<in> set \<Gamma>" and neq:"x' \<noteq> x" |
|
948 |
then have "\<exists>e'. \<theta> maps x' to e' \<and> e' \<in> V T'" using h1 by auto |
|
949 |
then have "\<exists>e'. ((x,e)#\<theta>) maps x' to e' \<and> e' \<in> V T'" using neq by auto |
|
950 |
} |
|
951 |
ultimately show "\<exists>e'. ((x,e)#\<theta>) maps x' to e' \<and> e' \<in> V T'" by blast |
|
952 |
qed |
|
953 |
||
954 |
lemma termination_aux: |
|
955 |
fixes T :: "ty" |
|
956 |
fixes \<Gamma> :: "(name \<times> ty) list" |
|
957 |
fixes \<theta> :: "(name \<times> trm) list" |
|
958 |
fixes e :: "trm" |
|
959 |
assumes h1: "\<Gamma> \<turnstile> e : T" |
|
960 |
and h2: "\<theta> Vcloses \<Gamma>" |
|
961 |
shows "\<exists>v. \<theta><e> \<Down> v \<and> v \<in> V T" |
|
962 |
using h2 h1 |
|
963 |
proof(nominal_induct e avoiding: \<Gamma> \<theta> arbitrary: T rule: trm.induct) |
|
964 |
case (App e\<^isub>1 e\<^isub>2 \<Gamma> \<theta> T) |
|
965 |
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 |
|
966 |
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 |
|
967 |
have as\<^isub>1:"\<theta> Vcloses \<Gamma>" by fact |
|
968 |
have as\<^isub>2: "\<Gamma> \<turnstile> App e\<^isub>1 e\<^isub>2 : T" by fact |
|
969 |
from as\<^isub>2 obtain T' where "\<Gamma> \<turnstile> e\<^isub>1 : T' \<rightarrow> T" and "\<Gamma> \<turnstile> e\<^isub>2 : T'" by auto |
|
970 |
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)" |
|
971 |
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 |
|
972 |
from "(i)" obtain x e' |
|
973 |
where "v\<^isub>1 = Lam[x].e'" |
|
974 |
and "(iii)": "(\<forall>v \<in> (V T').\<exists> v'. e'[x::=v] \<Down> v' \<and> v' \<in> V T)" |
|
975 |
and "(iv)": "\<theta><e\<^isub>1> \<Down> Lam [x].e'" |
|
976 |
and fr: "x\<sharp>(\<theta>,e\<^isub>1,e\<^isub>2)" by blast |
|
977 |
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) |
|
978 |
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 |
|
979 |
from fr\<^isub>2 "(ii)" have "x\<sharp>v\<^isub>2" by (simp add: fresh_preserved) |
|
980 |
then have "x\<sharp>e'[x::=v\<^isub>2]" by (simp add: fresh_subst_fresh) |
|
981 |
then have fr\<^isub>3: "x\<sharp>v\<^isub>3" using "(v)" by (simp add: fresh_preserved) |
|
982 |
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 |
|
983 |
with "(iv)" "(ii)" "(v)" have "App (\<theta><e\<^isub>1>) (\<theta><e\<^isub>2>) \<Down> v\<^isub>3" by auto |
|
984 |
then show "\<exists>v. \<theta><App e\<^isub>1 e\<^isub>2> \<Down> v \<and> v \<in> V T" using "(v)" by auto |
|
985 |
next |
|
986 |
case (Pr t\<^isub>1 t\<^isub>2 \<Gamma> \<theta> T) |
|
987 |
have "\<Gamma> \<turnstile> Pr t\<^isub>1 t\<^isub>2 : T" by fact |
|
988 |
then obtain T\<^isub>a T\<^isub>b where ta:"\<Gamma> \<turnstile> t\<^isub>1 : Data T\<^isub>a" and "\<Gamma> \<turnstile> t\<^isub>2 : Data T\<^isub>b" |
|
989 |
and eq:"T=Data (DProd T\<^isub>a T\<^isub>b)" by auto |
|
990 |
have h:"\<theta> Vcloses \<Gamma>" by fact |
|
991 |
then obtain v\<^isub>1 v\<^isub>2 where "\<theta><t\<^isub>1> \<Down> v\<^isub>1 \<and> v\<^isub>1 \<in> V (Data T\<^isub>a)" "\<theta><t\<^isub>2> \<Down> v\<^isub>2 \<and> v\<^isub>2 \<in> V (Data T\<^isub>b)" |
|
992 |
using prems by blast |
|
993 |
thus "\<exists>v. \<theta><Pr t\<^isub>1 t\<^isub>2> \<Down> v \<and> v \<in> V T" using eq by auto |
|
22472 | 994 |
next |
22447 | 995 |
case (Lam x e \<Gamma> \<theta> T) |
996 |
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 |
|
997 |
have as\<^isub>1: "\<theta> Vcloses \<Gamma>" by fact |
|
998 |
have as\<^isub>2: "\<Gamma> \<turnstile> Lam [x].e : T" by fact |
|
999 |
have fs: "x\<sharp>\<Gamma>" "x\<sharp>\<theta>" by fact |
|
1000 |
from as\<^isub>2 fs obtain T\<^isub>1 T\<^isub>2 |
|
1001 |
where "(i)": "(x,T\<^isub>1)#\<Gamma> \<turnstile> e:T\<^isub>2" and "(ii)": "T = T\<^isub>1 \<rightarrow> T\<^isub>2" by auto |
|
22472 | 1002 |
from "(i)" have "(iii)": "valid ((x,T\<^isub>1)#\<Gamma>)" by (simp add: typing_implies_valid) |
22447 | 1003 |
have "\<forall>v \<in> (V T\<^isub>1). \<exists>v'. (\<theta><e>)[x::=v] \<Down> v' \<and> v' \<in> V T\<^isub>2" |
1004 |
proof |
|
1005 |
fix v |
|
1006 |
assume "v \<in> (V T\<^isub>1)" |
|
1007 |
with "(iii)" as\<^isub>1 have "(x,v)#\<theta> Vcloses (x,T\<^isub>1)#\<Gamma>" using monotonicity by auto |
|
1008 |
with ih "(i)" obtain v' where "((x,v)#\<theta>)<e> \<Down> v' \<and> v' \<in> V T\<^isub>2" by blast |
|
22472 | 1009 |
then have "\<theta><e>[x::=v] \<Down> v' \<and> v' \<in> V T\<^isub>2" using fs by (simp add: psubst_subst_psubst) |
22447 | 1010 |
then show "\<exists>v'. \<theta><e>[x::=v] \<Down> v' \<and> v' \<in> V T\<^isub>2" by auto |
1011 |
qed |
|
1012 |
then have "Lam[x].\<theta><e> \<in> V (T\<^isub>1 \<rightarrow> T\<^isub>2)" by auto |
|
1013 |
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 |
|
1014 |
thus "\<exists>v. \<theta><Lam [x].e> \<Down> v \<and> v \<in> V T" using "(ii)" by auto |
|
1015 |
next |
|
1016 |
case (Case t' n\<^isub>1 t\<^isub>1 n\<^isub>2 t\<^isub>2 \<Gamma> \<theta> T) |
|
1017 |
have f: "n\<^isub>1\<sharp>\<Gamma>" "n\<^isub>1\<sharp>\<theta>" "n\<^isub>2\<sharp>\<Gamma>" "n\<^isub>2\<sharp>\<theta>" "n\<^isub>2\<noteq>n\<^isub>1" "n\<^isub>1\<sharp>t'" |
|
1018 |
"n\<^isub>1\<sharp>t\<^isub>2" "n\<^isub>2\<sharp>t'" "n\<^isub>2\<sharp>t\<^isub>1" by fact |
|
1019 |
have h:"\<theta> Vcloses \<Gamma>" by fact |
|
1020 |
have th:"\<Gamma> \<turnstile> Case t' of inl n\<^isub>1 \<rightarrow> t\<^isub>1 | inr n\<^isub>2 \<rightarrow> t\<^isub>2 : T" by fact |
|
1021 |
then obtain S\<^isub>1 S\<^isub>2 where |
|
1022 |
hm:"\<Gamma> \<turnstile> t' : Data (DSum S\<^isub>1 S\<^isub>2)" and |
|
22472 | 1023 |
hl:"(n\<^isub>1,Data S\<^isub>1)#\<Gamma> \<turnstile> t\<^isub>1 : T" and |
1024 |
hr:"(n\<^isub>2,Data S\<^isub>2)#\<Gamma> \<turnstile> t\<^isub>2 : T" using f by auto |
|
22447 | 1025 |
then obtain v\<^isub>0 where ht':"\<theta><t'> \<Down> v\<^isub>0" and hS:"v\<^isub>0 \<in> V (Data (DSum S\<^isub>1 S\<^isub>2))" using prems h by blast |
1026 |
(* We distinguish between the cases InL and InR *) |
|
22472 | 1027 |
{ fix v\<^isub>0' |
22447 | 1028 |
assume eqc:"v\<^isub>0 = InL v\<^isub>0'" and "v\<^isub>0' \<in> V' S\<^isub>1" |
1029 |
then have inc: "v\<^isub>0' \<in> V (Data S\<^isub>1)" by auto |
|
22472 | 1030 |
have "valid \<Gamma>" using th typing_implies_valid by auto |
22447 | 1031 |
then moreover have "valid ((n\<^isub>1,Data S\<^isub>1)#\<Gamma>)" using f by auto |
1032 |
then moreover have "(n\<^isub>1,v\<^isub>0')#\<theta> Vcloses (n\<^isub>1,Data S\<^isub>1)#\<Gamma>" |
|
1033 |
using inc h monotonicity by blast |
|
22472 | 1034 |
moreover |
1035 |
have ih:"\<And>\<Gamma> \<theta> T. \<lbrakk>\<theta> Vcloses \<Gamma>; \<Gamma> \<turnstile> t\<^isub>1 : T\<rbrakk> \<Longrightarrow> \<exists>v. \<theta><t\<^isub>1> \<Down> v \<and> v \<in> V T" by fact |
|
1036 |
ultimately obtain v\<^isub>1 where ho: "((n\<^isub>1,v\<^isub>0')#\<theta>)<t\<^isub>1> \<Down> v\<^isub>1 \<and> v\<^isub>1 \<in> V T" using hl by blast |
|
22447 | 1037 |
then have r:"\<theta><t\<^isub>1>[n\<^isub>1::=v\<^isub>0'] \<Down> v\<^isub>1 \<and> v\<^isub>1 \<in> V T" using psubst_subst_psubst f by simp |
1038 |
then moreover have "n\<^isub>1\<sharp>(\<theta><t'>,\<theta><t\<^isub>2>,v\<^isub>1,n\<^isub>2)" |
|
1039 |
proof - |
|
1040 |
have "n\<^isub>1\<sharp>v\<^isub>0" using ht' fresh_preserved fresh_psubst f by auto |
|
1041 |
then have "n\<^isub>1\<sharp>v\<^isub>0'" using eqc by auto |
|
1042 |
then have "n\<^isub>1\<sharp>v\<^isub>1" using f r fresh_preserved fresh_subst_fresh by blast |
|
1043 |
thus "n\<^isub>1\<sharp>(\<theta><t'>,\<theta><t\<^isub>2>,v\<^isub>1,n\<^isub>2)" using f by (simp add: fresh_atm fresh_psubst) |
|
1044 |
qed |
|
1045 |
moreover have "n\<^isub>2\<sharp>(\<theta><t'>,\<theta><t\<^isub>1>,v\<^isub>1,n\<^isub>1)" |
|
1046 |
proof - |
|
1047 |
have "n\<^isub>2\<sharp>v\<^isub>0" using ht' fresh_preserved fresh_psubst f by auto |
|
1048 |
then have "n\<^isub>2\<sharp>v\<^isub>0'" using eqc by auto |
|
1049 |
then have "n\<^isub>2\<sharp>((n\<^isub>1,v\<^isub>0')#\<theta>)" using f fresh_list_cons fresh_atm by force |
|
1050 |
then have "n\<^isub>2\<sharp>((n\<^isub>1,v\<^isub>0')#\<theta>)<t\<^isub>1>" using f fresh_psubst by auto |
|
1051 |
moreover then have "n\<^isub>2 \<sharp> v\<^isub>1" using fresh_preserved ho by auto |
|
1052 |
ultimately show "n\<^isub>2\<sharp>(\<theta><t'>,\<theta><t\<^isub>1>,v\<^isub>1,n\<^isub>1)" using f by (simp add: fresh_psubst fresh_atm) |
|
1053 |
qed |
|
1054 |
ultimately have "Case \<theta><t'> of inl n\<^isub>1 \<rightarrow> \<theta><t\<^isub>1> | inr n\<^isub>2 \<rightarrow> \<theta><t\<^isub>2> \<Down> v\<^isub>1 \<and> v\<^isub>1 \<in> V T" using ht' eqc by auto |
|
1055 |
moreover |
|
1056 |
have "Case \<theta><t'> of inl n\<^isub>1 \<rightarrow> \<theta><t\<^isub>1> | inr n\<^isub>2 \<rightarrow> \<theta><t\<^isub>2> = \<theta><Case t' of inl n\<^isub>1 \<rightarrow> t\<^isub>1 | inr n\<^isub>2 \<rightarrow> t\<^isub>2>" |
|
1057 |
using f by auto |
|
1058 |
ultimately have "\<exists>v. \<theta><Case t' of inl n\<^isub>1 \<rightarrow> t\<^isub>1 | inr n\<^isub>2 \<rightarrow> t\<^isub>2> \<Down> v \<and> v \<in> V T" by auto |
|
1059 |
} |
|
1060 |
moreover |
|
22472 | 1061 |
{ fix v\<^isub>0' |
22447 | 1062 |
assume eqc:"v\<^isub>0 = InR v\<^isub>0'" and "v\<^isub>0' \<in> V' S\<^isub>2" |
1063 |
then have inc:"v\<^isub>0' \<in> V (Data S\<^isub>2)" by auto |
|
22472 | 1064 |
have "valid \<Gamma>" using th typing_implies_valid by auto |
22447 | 1065 |
then moreover have "valid ((n\<^isub>2,Data S\<^isub>2)#\<Gamma>)" using f by auto |
1066 |
then moreover have "(n\<^isub>2,v\<^isub>0')#\<theta> Vcloses (n\<^isub>2,Data S\<^isub>2)#\<Gamma>" |
|
1067 |
using inc h monotonicity by blast |
|
1068 |
moreover have ih:"\<And>\<Gamma> \<theta> T. \<lbrakk>\<theta> Vcloses \<Gamma>; \<Gamma> \<turnstile> t\<^isub>2 : T\<rbrakk> \<Longrightarrow> \<exists>v. \<theta><t\<^isub>2> \<Down> v \<and> v \<in> V T" by fact |
|
1069 |
ultimately obtain v\<^isub>2 where ho:"((n\<^isub>2,v\<^isub>0')#\<theta>)<t\<^isub>2> \<Down> v\<^isub>2 \<and> v\<^isub>2 \<in> V T" using hr by blast |
|
1070 |
then have r:"\<theta><t\<^isub>2>[n\<^isub>2::=v\<^isub>0'] \<Down> v\<^isub>2 \<and> v\<^isub>2 \<in> V T" using psubst_subst_psubst f by simp |
|
1071 |
moreover have "n\<^isub>1\<sharp>(\<theta><t'>,\<theta><t\<^isub>2>,v\<^isub>2,n\<^isub>2)" |
|
1072 |
proof - |
|
1073 |
have "n\<^isub>1\<sharp>\<theta><t'>" using fresh_psubst f by simp |
|
1074 |
then have "n\<^isub>1\<sharp>v\<^isub>0" using ht' fresh_preserved by auto |
|
1075 |
then have "n\<^isub>1\<sharp>v\<^isub>0'" using eqc by auto |
|
1076 |
then have "n\<^isub>1\<sharp>((n\<^isub>2,v\<^isub>0')#\<theta>)" using f fresh_list_cons fresh_atm by force |
|
1077 |
then have "n\<^isub>1\<sharp>((n\<^isub>2,v\<^isub>0')#\<theta>)<t\<^isub>2>" using f fresh_psubst by auto |
|
1078 |
moreover then have "n\<^isub>1\<sharp>v\<^isub>2" using fresh_preserved ho by auto |
|
1079 |
ultimately show "n\<^isub>1 \<sharp> (\<theta><t'>,\<theta><t\<^isub>2>,v\<^isub>2,n\<^isub>2)" using f by (simp add: fresh_psubst fresh_atm) |
|
1080 |
qed |
|
1081 |
moreover have "n\<^isub>2 \<sharp> (\<theta><t'>,\<theta><t\<^isub>1>,v\<^isub>2,n\<^isub>1)" |
|
1082 |
proof - |
|
1083 |
have "n\<^isub>2\<sharp>\<theta><t'>" using fresh_psubst f by simp |
|
1084 |
then have "n\<^isub>2\<sharp>v\<^isub>0" using ht' fresh_preserved by auto |
|
1085 |
then have "n\<^isub>2\<sharp>v\<^isub>0'" using eqc by auto |
|
1086 |
then have "n\<^isub>2\<sharp>\<theta><t\<^isub>2>[n\<^isub>2::=v\<^isub>0']" using f fresh_subst_fresh by auto |
|
1087 |
then have "n\<^isub>2\<sharp>v\<^isub>2" using f fresh_preserved r by blast |
|
1088 |
then show "n\<^isub>2\<sharp>(\<theta><t'>,\<theta><t\<^isub>1>,v\<^isub>2,n\<^isub>1)" using f by (simp add: fresh_atm fresh_psubst) |
|
1089 |
qed |
|
1090 |
ultimately have "Case \<theta><t'> of inl n\<^isub>1 \<rightarrow> \<theta><t\<^isub>1> | inr n\<^isub>2 \<rightarrow> \<theta><t\<^isub>2> \<Down> v\<^isub>2 \<and> v\<^isub>2 \<in> V T" using ht' eqc by auto |
|
1091 |
then have "\<exists>v. \<theta><Case t' of inl n\<^isub>1 \<rightarrow> t\<^isub>1 | inr n\<^isub>2 \<rightarrow> t\<^isub>2> \<Down> v \<and> v \<in> V T" using f by auto |
|
22472 | 1092 |
} |
22447 | 1093 |
ultimately show "\<exists>v. \<theta><Case t' of inl n\<^isub>1 \<rightarrow> t\<^isub>1 | inr n\<^isub>2 \<rightarrow> t\<^isub>2> \<Down> v \<and> v \<in> V T" using hS V_sum by blast |
1094 |
qed (force)+ |
|
1095 |
||
1096 |
theorem termination_of_evaluation: |
|
1097 |
assumes a: "[] \<turnstile> e : T" |
|
1098 |
shows "\<exists>v. e \<Down> v \<and> val v" |
|
1099 |
proof - |
|
1100 |
from a have "\<exists>v. (([]::(name \<times> trm) list)<e>) \<Down> v \<and> v \<in> V T" |
|
1101 |
by (rule termination_aux) (auto) |
|
1102 |
thus "\<exists>v. e \<Down> v \<and> val v" using V_are_values by auto |
|
1103 |
qed |
|
1104 |
||
1105 |
end |