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