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