| author | huffman |
| Thu, 23 Aug 2007 18:52:44 +0200 | |
| changeset 24413 | 5073729e5c12 |
| parent 23970 | a252a7da82b9 |
| child 24899 | 08865bb87098 |
| permissions | -rw-r--r-- |
|
18263
7f75925498da
cleaned up all examples so that they work with the
urbanc
parents:
18106
diff
changeset
|
1 |
(* $Id$ *) |
| 18106 | 2 |
|
| 19496 | 3 |
theory SN |
|
21107
e69c0e82955a
new file for defining functions in the lambda-calculus
urbanc
parents:
19972
diff
changeset
|
4 |
imports Lam_Funs |
| 18106 | 5 |
begin |
6 |
||
| 18269 | 7 |
text {* Strong Normalisation proof from the Proofs and Types book *}
|
| 18106 | 8 |
|
9 |
section {* Beta Reduction *}
|
|
10 |
||
|
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22271
diff
changeset
|
11 |
lemma subst_rename: |
|
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22271
diff
changeset
|
12 |
assumes a: "c\<sharp>t1" |
|
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22271
diff
changeset
|
13 |
shows "t1[a::=t2] = ([(c,a)]\<bullet>t1)[c::=t2]" |
|
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22271
diff
changeset
|
14 |
using a |
|
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22271
diff
changeset
|
15 |
by (nominal_induct t1 avoiding: a c t2 rule: lam.induct) |
|
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22271
diff
changeset
|
16 |
(auto simp add: calc_atm fresh_atm abs_fresh) |
| 18106 | 17 |
|
| 18313 | 18 |
lemma forget: |
19 |
assumes a: "a\<sharp>t1" |
|
20 |
shows "t1[a::=t2] = t1" |
|
21 |
using a |
|
|
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22271
diff
changeset
|
22 |
by (nominal_induct t1 avoiding: a t2 rule: lam.induct) |
|
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22271
diff
changeset
|
23 |
(auto simp add: abs_fresh fresh_atm) |
| 18106 | 24 |
|
| 18313 | 25 |
lemma fresh_fact: |
26 |
fixes a::"name" |
|
| 23970 | 27 |
assumes a: "a\<sharp>t1" "a\<sharp>t2" |
| 22540 | 28 |
shows "a\<sharp>t1[b::=t2]" |
| 23970 | 29 |
using a |
|
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22271
diff
changeset
|
30 |
by (nominal_induct t1 avoiding: a b t2 rule: lam.induct) |
|
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22271
diff
changeset
|
31 |
(auto simp add: abs_fresh fresh_atm) |
| 18106 | 32 |
|
| 22540 | 33 |
lemma fresh_fact': |
34 |
fixes a::"name" |
|
35 |
assumes a: "a\<sharp>t2" |
|
36 |
shows "a\<sharp>t1[a::=t2]" |
|
37 |
using a |
|
38 |
by (nominal_induct t1 avoiding: a t2 rule: lam.induct) |
|
39 |
(auto simp add: abs_fresh fresh_atm) |
|
40 |
||
| 18383 | 41 |
lemma subst_lemma: |
| 18313 | 42 |
assumes a: "x\<noteq>y" |
43 |
and b: "x\<sharp>L" |
|
44 |
shows "M[x::=N][y::=L] = M[y::=L][x::=N[y::=L]]" |
|
45 |
using a b |
|
|
18659
2ff0ae57431d
changes to make use of the new induction principle proved by
urbanc
parents:
18654
diff
changeset
|
46 |
by (nominal_induct M avoiding: x y N L rule: lam.induct) |
| 18313 | 47 |
(auto simp add: fresh_fact forget) |
| 18106 | 48 |
|
|
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22271
diff
changeset
|
49 |
lemma id_subs: |
|
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22271
diff
changeset
|
50 |
shows "t[x::=Var x] = t" |
|
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22271
diff
changeset
|
51 |
by (nominal_induct t avoiding: x rule: lam.induct) |
|
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22271
diff
changeset
|
52 |
(simp_all add: fresh_atm) |
|
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22271
diff
changeset
|
53 |
|
| 23142 | 54 |
lemma psubst_subst: |
55 |
assumes h:"c\<sharp>\<theta>" |
|
56 |
shows "(\<theta><t>)[c::=s] = ((c,s)#\<theta>)<t>" |
|
57 |
using h |
|
58 |
by (nominal_induct t avoiding: \<theta> c s rule: lam.induct) |
|
59 |
(auto simp add: fresh_list_cons fresh_atm forget lookup_fresh lookup_fresh') |
|
60 |
||
| 23760 | 61 |
inductive |
| 23142 | 62 |
Beta :: "lam\<Rightarrow>lam\<Rightarrow>bool" (" _ \<longrightarrow>\<^isub>\<beta> _" [80,80] 80)
|
| 22271 | 63 |
where |
| 23970 | 64 |
b1[intro!]: "s1 \<longrightarrow>\<^isub>\<beta> s2 \<Longrightarrow> App s1 t \<longrightarrow>\<^isub>\<beta> App s2 t" |
65 |
| b2[intro!]: "s1\<longrightarrow>\<^isub>\<beta>s2 \<Longrightarrow> App t s1 \<longrightarrow>\<^isub>\<beta> App t s2" |
|
66 |
| b3[intro!]: "s1\<longrightarrow>\<^isub>\<beta>s2 \<Longrightarrow> Lam [a].s1 \<longrightarrow>\<^isub>\<beta> Lam [a].s2" |
|
67 |
| b4[intro!]: "a\<sharp>s2 \<Longrightarrow> App (Lam [a].s1) s2\<longrightarrow>\<^isub>\<beta> (s1[a::=s2])" |
|
|
22538
3ccb92dfb5e9
tuned proofs (taking full advantage of nominal_inductive)
urbanc
parents:
22531
diff
changeset
|
68 |
|
|
22730
8bcc8809ed3b
nominal_inductive no longer proves equivariance.
berghofe
parents:
22650
diff
changeset
|
69 |
equivariance Beta |
|
8bcc8809ed3b
nominal_inductive no longer proves equivariance.
berghofe
parents:
22650
diff
changeset
|
70 |
|
|
22538
3ccb92dfb5e9
tuned proofs (taking full advantage of nominal_inductive)
urbanc
parents:
22531
diff
changeset
|
71 |
nominal_inductive Beta |
| 22540 | 72 |
by (simp_all add: abs_fresh fresh_fact') |
| 18106 | 73 |
|
| 18378 | 74 |
lemma supp_beta: |
75 |
assumes a: "t\<longrightarrow>\<^isub>\<beta> s" |
|
76 |
shows "(supp s)\<subseteq>((supp t)::name set)" |
|
77 |
using a |
|
78 |
by (induct) |
|
79 |
(auto intro!: simp add: abs_supp lam.supp subst_supp) |
|
80 |
||
| 23970 | 81 |
lemma beta_abs: |
82 |
assumes a: "Lam [a].t\<longrightarrow>\<^isub>\<beta> t'" |
|
83 |
shows "\<exists>t''. t'=Lam [a].t'' \<and> t\<longrightarrow>\<^isub>\<beta> t''" |
|
84 |
using a |
|
85 |
apply - |
|
| 23760 | 86 |
apply(ind_cases "Lam [a].t \<longrightarrow>\<^isub>\<beta> t'") |
| 18106 | 87 |
apply(auto simp add: lam.distinct lam.inject) |
88 |
apply(auto simp add: alpha) |
|
89 |
apply(rule_tac x="[(a,aa)]\<bullet>s2" in exI) |
|
90 |
apply(rule conjI) |
|
91 |
apply(rule sym) |
|
92 |
apply(rule pt_bij2[OF pt_name_inst, OF at_name_inst]) |
|
93 |
apply(simp) |
|
94 |
apply(rule pt_name3) |
|
95 |
apply(simp add: at_ds5[OF at_name_inst]) |
|
96 |
apply(rule conjI) |
|
97 |
apply(simp add: pt_fresh_left[OF pt_name_inst, OF at_name_inst] calc_atm) |
|
98 |
apply(force dest!: supp_beta simp add: fresh_def) |
|
|
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:
22540
diff
changeset
|
99 |
apply(force intro!: eqvts) |
| 18106 | 100 |
done |
101 |
||
| 18313 | 102 |
lemma beta_subst: |
| 18106 | 103 |
assumes a: "M \<longrightarrow>\<^isub>\<beta> M'" |
104 |
shows "M[x::=N]\<longrightarrow>\<^isub>\<beta> M'[x::=N]" |
|
105 |
using a |
|
| 23142 | 106 |
by (nominal_induct M M' avoiding: x N rule: Beta.strong_induct) |
107 |
(auto simp add: fresh_atm subst_lemma fresh_fact) |
|
| 18106 | 108 |
|
| 18383 | 109 |
section {* types *}
|
110 |
||
|
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22271
diff
changeset
|
111 |
nominal_datatype ty = |
|
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22271
diff
changeset
|
112 |
TVar "nat" |
| 18106 | 113 |
| TArr "ty" "ty" (infix "\<rightarrow>" 200) |
114 |
||
| 23142 | 115 |
lemma perm_ty: |
| 18106 | 116 |
fixes pi ::"name prm" |
117 |
and \<tau> ::"ty" |
|
118 |
shows "pi\<bullet>\<tau> = \<tau>" |
|
|
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22271
diff
changeset
|
119 |
by (nominal_induct \<tau> rule: ty.induct) |
|
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22271
diff
changeset
|
120 |
(simp_all add: perm_nat_def) |
| 18106 | 121 |
|
122 |
lemma fresh_ty: |
|
123 |
fixes a ::"name" |
|
124 |
and \<tau> ::"ty" |
|
125 |
shows "a\<sharp>\<tau>" |
|
| 23142 | 126 |
by (simp add: fresh_def perm_ty supp_def) |
127 |
||
128 |
(* domain of a typing context *) |
|
129 |
||
130 |
fun |
|
131 |
"dom_ty" :: "(name\<times>ty) list \<Rightarrow> (name list)" |
|
132 |
where |
|
133 |
"dom_ty [] = []" |
|
134 |
| "dom_ty ((x,\<tau>)#\<Gamma>) = (x)#(dom_ty \<Gamma>)" |
|
135 |
||
| 18106 | 136 |
|
137 |
(* valid contexts *) |
|
138 |
||
| 23760 | 139 |
inductive |
| 23142 | 140 |
valid :: "(name\<times>ty) list \<Rightarrow> bool" |
| 22271 | 141 |
where |
142 |
v1[intro]: "valid []" |
|
143 |
| v2[intro]: "\<lbrakk>valid \<Gamma>;a\<sharp>\<Gamma>\<rbrakk>\<Longrightarrow> valid ((a,\<sigma>)#\<Gamma>)" |
|
| 18106 | 144 |
|
|
22538
3ccb92dfb5e9
tuned proofs (taking full advantage of nominal_inductive)
urbanc
parents:
22531
diff
changeset
|
145 |
equivariance valid |
| 18106 | 146 |
|
| 23760 | 147 |
inductive_cases valid_elim[elim]: "valid ((a,\<tau>)#\<Gamma>)" |
| 23142 | 148 |
|
| 18106 | 149 |
(* typing judgements *) |
150 |
||
|
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22271
diff
changeset
|
151 |
lemma fresh_context: |
| 18106 | 152 |
fixes \<Gamma> :: "(name\<times>ty)list" |
153 |
and a :: "name" |
|
| 18378 | 154 |
assumes a: "a\<sharp>\<Gamma>" |
155 |
shows "\<not>(\<exists>\<tau>::ty. (a,\<tau>)\<in>set \<Gamma>)" |
|
156 |
using a |
|
| 23970 | 157 |
by (induct \<Gamma>) |
158 |
(auto simp add: fresh_prod fresh_list_cons fresh_atm) |
|
| 18106 | 159 |
|
| 23760 | 160 |
inductive |
| 23142 | 161 |
typing :: "(name\<times>ty) list\<Rightarrow>lam\<Rightarrow>ty\<Rightarrow>bool" ("_ \<turnstile> _ : _" [60,60,60] 60)
|
| 22271 | 162 |
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:
22542
diff
changeset
|
163 |
t1[intro]: "\<lbrakk>valid \<Gamma>; (a,\<tau>)\<in>set \<Gamma>\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> Var a : \<tau>" |
|
0c5b22076fb3
tuned the proof of lemma pt_list_set_fresh (as suggested by Randy Pollack) and tuned the syntax for sub_contexts
urbanc
parents:
22542
diff
changeset
|
164 |
| t2[intro]: "\<lbrakk>\<Gamma> \<turnstile> t1 : \<tau>\<rightarrow>\<sigma>; \<Gamma> \<turnstile> t2 : \<tau>\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> App t1 t2 : \<sigma>" |
| 22271 | 165 |
| t3[intro]: "\<lbrakk>a\<sharp>\<Gamma>;((a,\<tau>)#\<Gamma>) \<turnstile> t : \<sigma>\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> Lam [a].t : \<tau>\<rightarrow>\<sigma>" |
| 18106 | 166 |
|
|
22730
8bcc8809ed3b
nominal_inductive no longer proves equivariance.
berghofe
parents:
22650
diff
changeset
|
167 |
equivariance typing |
|
8bcc8809ed3b
nominal_inductive no longer proves equivariance.
berghofe
parents:
22650
diff
changeset
|
168 |
|
|
22538
3ccb92dfb5e9
tuned proofs (taking full advantage of nominal_inductive)
urbanc
parents:
22531
diff
changeset
|
169 |
nominal_inductive typing |
|
3ccb92dfb5e9
tuned proofs (taking full advantage of nominal_inductive)
urbanc
parents:
22531
diff
changeset
|
170 |
by (simp_all add: abs_fresh fresh_ty) |
| 18106 | 171 |
|
|
21107
e69c0e82955a
new file for defining functions in the lambda-calculus
urbanc
parents:
19972
diff
changeset
|
172 |
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:
22542
diff
changeset
|
173 |
"sub" :: "(name\<times>ty) list \<Rightarrow> (name\<times>ty) list \<Rightarrow> bool" ("_ \<subseteq> _" [60,60] 60)
|
|
0c5b22076fb3
tuned the proof of lemma pt_list_set_fresh (as suggested by Randy Pollack) and tuned the syntax for sub_contexts
urbanc
parents:
22542
diff
changeset
|
174 |
where |
|
0c5b22076fb3
tuned the proof of lemma pt_list_set_fresh (as suggested by Randy Pollack) and tuned the syntax for sub_contexts
urbanc
parents:
22542
diff
changeset
|
175 |
"\<Gamma>1 \<subseteq> \<Gamma>2 \<equiv> \<forall>a \<sigma>. (a,\<sigma>)\<in>set \<Gamma>1 \<longrightarrow> (a,\<sigma>)\<in>set \<Gamma>2" |
| 18106 | 176 |
|
177 |
subsection {* some facts about beta *}
|
|
178 |
||
179 |
constdefs |
|
180 |
"NORMAL" :: "lam \<Rightarrow> bool" |
|
181 |
"NORMAL t \<equiv> \<not>(\<exists>t'. t\<longrightarrow>\<^isub>\<beta> t')" |
|
182 |
||
| 18383 | 183 |
lemma NORMAL_Var: |
184 |
shows "NORMAL (Var a)" |
|
185 |
proof - |
|
186 |
{ assume "\<exists>t'. (Var a) \<longrightarrow>\<^isub>\<beta> t'"
|
|
187 |
then obtain t' where "(Var a) \<longrightarrow>\<^isub>\<beta> t'" by blast |
|
188 |
hence False by (cases, auto) |
|
189 |
} |
|
190 |
thus "NORMAL (Var a)" by (force simp add: NORMAL_def) |
|
191 |
qed |
|
192 |
||
| 23970 | 193 |
inductive |
194 |
SN :: "lam \<Rightarrow> bool" |
|
195 |
where |
|
196 |
SN_intro: "(\<And>t'. t \<longrightarrow>\<^isub>\<beta> t' \<Longrightarrow> SN t') \<Longrightarrow> SN t" |
|
197 |
||
198 |
lemma SN_elim: |
|
199 |
assumes a: "SN M" |
|
200 |
shows "(\<forall>M. (\<forall>N. M \<longrightarrow>\<^isub>\<beta> N \<longrightarrow> P N)\<longrightarrow> P M) \<longrightarrow> P M" |
|
201 |
using a |
|
202 |
by (induct rule: SN.SN.induct) (blast) |
|
203 |
||
204 |
lemma SN_preserved: |
|
205 |
assumes a: "SN t1" "t1\<longrightarrow>\<^isub>\<beta> t2" |
|
206 |
shows "SN t2" |
|
207 |
using a |
|
208 |
by (cases) (auto) |
|
| 18106 | 209 |
|
| 23970 | 210 |
lemma double_SN_aux: |
211 |
assumes a: "SN a" |
|
212 |
and b: "SN b" |
|
213 |
and hyp: "\<And>x z. |
|
214 |
(\<And>y. x \<longrightarrow>\<^isub>\<beta> y \<Longrightarrow> SN y) \<Longrightarrow> |
|
215 |
(\<And>y. x \<longrightarrow>\<^isub>\<beta> y \<Longrightarrow> P y z) \<Longrightarrow> |
|
216 |
(\<And>u. z \<longrightarrow>\<^isub>\<beta> u \<Longrightarrow> SN u) \<Longrightarrow> |
|
217 |
(\<And>u. z \<longrightarrow>\<^isub>\<beta> u \<Longrightarrow> P x u) \<Longrightarrow> P x z" |
|
218 |
shows "P a b" |
|
219 |
proof - |
|
220 |
from a |
|
221 |
have r: "\<And>b. SN b \<Longrightarrow> P a b" |
|
222 |
proof (induct a rule: SN.SN.induct) |
|
223 |
case (SN_intro x) |
|
224 |
note SNI' = SN_intro |
|
225 |
have "SN b" by fact |
|
226 |
thus ?case |
|
227 |
proof (induct b rule: SN.SN.induct) |
|
228 |
case (SN_intro y) |
|
229 |
show ?case |
|
230 |
apply (rule hyp) |
|
231 |
apply (erule SNI') |
|
232 |
apply (erule SNI') |
|
233 |
apply (rule SN.SN_intro) |
|
234 |
apply (erule SN_intro)+ |
|
235 |
done |
|
236 |
qed |
|
237 |
qed |
|
238 |
from b show ?thesis by (rule r) |
|
239 |
qed |
|
| 18106 | 240 |
|
| 23970 | 241 |
lemma double_SN[consumes 2]: |
242 |
assumes a: "SN a" |
|
243 |
and b: "SN b" |
|
244 |
and c: "\<And>x z. \<lbrakk>\<And>y. x \<longrightarrow>\<^isub>\<beta> y \<Longrightarrow> P y z; \<And>u. z \<longrightarrow>\<^isub>\<beta> u \<Longrightarrow> P x u\<rbrakk> \<Longrightarrow> P x z" |
|
245 |
shows "P a b" |
|
246 |
using a b c |
|
247 |
apply(rule_tac double_SN_aux) |
|
248 |
apply(assumption)+ |
|
249 |
apply(blast) |
|
| 18106 | 250 |
done |
251 |
||
252 |
section {* Candidates *}
|
|
253 |
||
|
22440
7e4f4f19002f
deleted function for defining candidates and used nominal_primrec instead
urbanc
parents:
22420
diff
changeset
|
254 |
consts |
| 18106 | 255 |
RED :: "ty \<Rightarrow> lam set" |
|
22440
7e4f4f19002f
deleted function for defining candidates and used nominal_primrec instead
urbanc
parents:
22420
diff
changeset
|
256 |
|
|
7e4f4f19002f
deleted function for defining candidates and used nominal_primrec instead
urbanc
parents:
22420
diff
changeset
|
257 |
nominal_primrec |
|
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22271
diff
changeset
|
258 |
"RED (TVar X) = {t. SN(t)}"
|
|
22440
7e4f4f19002f
deleted function for defining candidates and used nominal_primrec instead
urbanc
parents:
22420
diff
changeset
|
259 |
"RED (\<tau>\<rightarrow>\<sigma>) = {t. \<forall>u. (u\<in>RED \<tau> \<longrightarrow> (App t u)\<in>RED \<sigma>)}"
|
| 23970 | 260 |
by (rule TrueI)+ |
|
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22271
diff
changeset
|
261 |
|
| 18106 | 262 |
constdefs |
263 |
NEUT :: "lam \<Rightarrow> bool" |
|
| 23970 | 264 |
"NEUT t \<equiv> (\<exists>a. t = Var a) \<or> (\<exists>t1 t2. t = App t1 t2)" |
| 18106 | 265 |
|
266 |
(* a slight hack to get the first element of applications *) |
|
| 23970 | 267 |
(* this is needed to get (SN t) from SN (App t s) *) |
| 23760 | 268 |
inductive |
| 23142 | 269 |
FST :: "lam\<Rightarrow>lam\<Rightarrow>bool" (" _ \<guillemotright> _" [80,80] 80)
|
| 22271 | 270 |
where |
|
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22271
diff
changeset
|
271 |
fst[intro!]: "(App t s) \<guillemotright> t" |
| 18106 | 272 |
|
| 23970 | 273 |
lemma SN_of_FST_of_App: |
274 |
assumes a: "SN (App t s)" |
|
275 |
shows "SN t" |
|
276 |
using a |
|
277 |
proof - |
|
278 |
from a have "\<forall>z. (App t s \<guillemotright> z) \<longrightarrow> SN z" |
|
279 |
by (induct rule: SN.SN.induct) |
|
280 |
(blast elim: FST.cases intro: SN_intro) |
|
281 |
then show "SN t" by blast |
|
282 |
qed |
|
| 18106 | 283 |
|
| 18383 | 284 |
section {* Candidates *}
|
285 |
||
| 18106 | 286 |
constdefs |
| 18383 | 287 |
"CR1" :: "ty \<Rightarrow> bool" |
| 23970 | 288 |
"CR1 \<tau> \<equiv> \<forall>t. (t\<in>RED \<tau> \<longrightarrow> SN t)" |
| 18106 | 289 |
|
| 18383 | 290 |
"CR2" :: "ty \<Rightarrow> bool" |
291 |
"CR2 \<tau> \<equiv> \<forall>t t'. (t\<in>RED \<tau> \<and> t \<longrightarrow>\<^isub>\<beta> t') \<longrightarrow> t'\<in>RED \<tau>" |
|
| 18106 | 292 |
|
| 18383 | 293 |
"CR3_RED" :: "lam \<Rightarrow> ty \<Rightarrow> bool" |
294 |
"CR3_RED t \<tau> \<equiv> \<forall>t'. t\<longrightarrow>\<^isub>\<beta> t' \<longrightarrow> t'\<in>RED \<tau>" |
|
| 18106 | 295 |
|
| 18383 | 296 |
"CR3" :: "ty \<Rightarrow> bool" |
297 |
"CR3 \<tau> \<equiv> \<forall>t. (NEUT t \<and> CR3_RED t \<tau>) \<longrightarrow> t\<in>RED \<tau>" |
|
| 18106 | 298 |
|
| 18383 | 299 |
"CR4" :: "ty \<Rightarrow> bool" |
300 |
"CR4 \<tau> \<equiv> \<forall>t. (NEUT t \<and> NORMAL t) \<longrightarrow>t\<in>RED \<tau>" |
|
| 18106 | 301 |
|
| 23970 | 302 |
lemma CR3_implies_CR4: |
303 |
assumes a: "CR3 \<tau>" |
|
304 |
shows "CR4 \<tau>" |
|
305 |
using a by (auto simp add: CR3_def CR3_RED_def CR4_def NORMAL_def) |
|
| 18106 | 306 |
|
| 23970 | 307 |
(* sub_induction in the arrow-type case for the next proof *) |
308 |
lemma sub_induction: |
|
309 |
assumes a: "SN(u)" |
|
310 |
and b: "u\<in>RED \<tau>" |
|
311 |
and c1: "NEUT t" |
|
312 |
and c2: "CR2 \<tau>" |
|
313 |
and c3: "CR3 \<sigma>" |
|
314 |
and c4: "CR3_RED t (\<tau>\<rightarrow>\<sigma>)" |
|
315 |
shows "(App t u)\<in>RED \<sigma>" |
|
316 |
using a b |
|
317 |
proof (induct) |
|
318 |
fix u |
|
319 |
assume as: "u\<in>RED \<tau>" |
|
320 |
assume ih: " \<And>u'. \<lbrakk>u \<longrightarrow>\<^isub>\<beta> u'; u' \<in> RED \<tau>\<rbrakk> \<Longrightarrow> App t u' \<in> RED \<sigma>" |
|
321 |
have "NEUT (App t u)" using c1 by (auto simp add: NEUT_def) |
|
322 |
moreover |
|
323 |
have "CR3_RED (App t u) \<sigma>" unfolding CR3_RED_def |
|
324 |
proof (intro strip) |
|
325 |
fix r |
|
326 |
assume red: "App t u \<longrightarrow>\<^isub>\<beta> r" |
|
327 |
moreover |
|
328 |
{ assume "\<exists>t'. t \<longrightarrow>\<^isub>\<beta> t' \<and> r = App t' u"
|
|
329 |
then obtain t' where a1: "t \<longrightarrow>\<^isub>\<beta> t'" and a2: "r = App t' u" by blast |
|
330 |
have "t'\<in>RED (\<tau>\<rightarrow>\<sigma>)" using c4 a1 by (simp add: CR3_RED_def) |
|
331 |
then have "App t' u\<in>RED \<sigma>" using as by simp |
|
332 |
then have "r\<in>RED \<sigma>" using a2 by simp |
|
333 |
} |
|
334 |
moreover |
|
335 |
{ assume "\<exists>u'. u \<longrightarrow>\<^isub>\<beta> u' \<and> r = App t u'"
|
|
336 |
then obtain u' where b1: "u \<longrightarrow>\<^isub>\<beta> u'" and b2: "r = App t u'" by blast |
|
337 |
have "u'\<in>RED \<tau>" using as b1 c2 by (auto simp add: CR2_def) |
|
338 |
with ih have "App t u' \<in> RED \<sigma>" using b1 by simp |
|
339 |
then have "r\<in>RED \<sigma>" using b2 by simp |
|
340 |
} |
|
341 |
moreover |
|
342 |
{ assume "\<exists>x t'. t = Lam [x].t'"
|
|
343 |
then obtain x t' where "t = Lam [x].t'" by blast |
|
344 |
then have "NEUT (Lam [x].t')" using c1 by simp |
|
345 |
then have "False" by (simp add: NEUT_def) |
|
346 |
then have "r\<in>RED \<sigma>" by simp |
|
347 |
} |
|
348 |
ultimately show "r \<in> RED \<sigma>" by (cases) (auto simp add: lam.inject) |
|
349 |
qed |
|
350 |
ultimately show "App t u \<in> RED \<sigma>" using c3 by (simp add: CR3_def) |
|
351 |
qed |
|
| 18106 | 352 |
|
| 23970 | 353 |
(* properties of the candiadates *) |
| 18383 | 354 |
lemma RED_props: |
355 |
shows "CR1 \<tau>" and "CR2 \<tau>" and "CR3 \<tau>" |
|
|
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22271
diff
changeset
|
356 |
proof (nominal_induct \<tau> rule: ty.induct) |
| 18611 | 357 |
case (TVar a) |
358 |
{ case 1 show "CR1 (TVar a)" by (simp add: CR1_def)
|
|
359 |
next |
|
| 23970 | 360 |
case 2 show "CR2 (TVar a)" by (auto intro: SN_preserved simp add: CR2_def) |
| 18611 | 361 |
next |
| 23970 | 362 |
case 3 show "CR3 (TVar a)" by (auto intro: SN_intro simp add: CR3_def CR3_RED_def) |
| 18611 | 363 |
} |
|
18599
e01112713fdc
changed PRO_RED proof to conform with the new induction rules
urbanc
parents:
18383
diff
changeset
|
364 |
next |
| 18611 | 365 |
case (TArr \<tau>1 \<tau>2) |
366 |
{ case 1
|
|
367 |
have ih_CR3_\<tau>1: "CR3 \<tau>1" by fact |
|
368 |
have ih_CR1_\<tau>2: "CR1 \<tau>2" by fact |
|
| 23970 | 369 |
show "CR1 (\<tau>1 \<rightarrow> \<tau>2)" unfolding CR1_def |
370 |
proof (simp, intro strip) |
|
| 18611 | 371 |
fix t |
372 |
assume a: "\<forall>u. u \<in> RED \<tau>1 \<longrightarrow> App t u \<in> RED \<tau>2" |
|
| 23970 | 373 |
from ih_CR3_\<tau>1 have "CR4 \<tau>1" by (simp add: CR3_implies_CR4) |
| 18611 | 374 |
moreover |
375 |
have "NEUT (Var a)" by (force simp add: NEUT_def) |
|
376 |
moreover |
|
377 |
have "NORMAL (Var a)" by (rule NORMAL_Var) |
|
378 |
ultimately have "(Var a)\<in> RED \<tau>1" by (simp add: CR4_def) |
|
379 |
with a have "App t (Var a) \<in> RED \<tau>2" by simp |
|
380 |
hence "SN (App t (Var a))" using ih_CR1_\<tau>2 by (simp add: CR1_def) |
|
| 23970 | 381 |
thus "SN(t)" by (rule SN_of_FST_of_App) |
| 18611 | 382 |
qed |
383 |
next |
|
384 |
case 2 |
|
385 |
have ih_CR1_\<tau>1: "CR1 \<tau>1" by fact |
|
386 |
have ih_CR2_\<tau>2: "CR2 \<tau>2" by fact |
|
| 23970 | 387 |
show "CR2 (\<tau>1 \<rightarrow> \<tau>2)" unfolding CR2_def |
388 |
proof (simp, intro strip) |
|
| 18611 | 389 |
fix t1 t2 u |
390 |
assume "(\<forall>u. u \<in> RED \<tau>1 \<longrightarrow> App t1 u \<in> RED \<tau>2) \<and> t1 \<longrightarrow>\<^isub>\<beta> t2" |
|
391 |
and "u \<in> RED \<tau>1" |
|
392 |
hence "t1 \<longrightarrow>\<^isub>\<beta> t2" and "App t1 u \<in> RED \<tau>2" by simp_all |
|
| 23970 | 393 |
thus "App t2 u \<in> RED \<tau>2" using ih_CR2_\<tau>2 by (auto simp add: CR2_def) |
| 18611 | 394 |
qed |
395 |
next |
|
396 |
case 3 |
|
397 |
have ih_CR1_\<tau>1: "CR1 \<tau>1" by fact |
|
398 |
have ih_CR2_\<tau>1: "CR2 \<tau>1" by fact |
|
399 |
have ih_CR3_\<tau>2: "CR3 \<tau>2" by fact |
|
| 23970 | 400 |
show "CR3 (\<tau>1 \<rightarrow> \<tau>2)" unfolding CR3_def |
401 |
proof (simp, intro strip) |
|
| 18611 | 402 |
fix t u |
403 |
assume a1: "u \<in> RED \<tau>1" |
|
404 |
assume a2: "NEUT t \<and> CR3_RED t (\<tau>1 \<rightarrow> \<tau>2)" |
|
| 23970 | 405 |
have "SN(u)" using a1 ih_CR1_\<tau>1 by (simp add: CR1_def) |
406 |
then show "(App t u)\<in>RED \<tau>2" using ih_CR2_\<tau>1 ih_CR3_\<tau>2 a1 a2 by (blast intro: sub_induction) |
|
| 18611 | 407 |
qed |
408 |
} |
|
| 18383 | 409 |
qed |
| 23970 | 410 |
|
411 |
(* not as simple as on paper, because of the stronger double_SN induction *) |
|
412 |
lemma abs_RED: |
|
413 |
assumes asm: "\<forall>s\<in>RED \<tau>. t[x::=s]\<in>RED \<sigma>" |
|
414 |
shows "Lam [x].t\<in>RED (\<tau>\<rightarrow>\<sigma>)" |
|
| 18106 | 415 |
proof - |
| 23970 | 416 |
have b1: "SN t" |
417 |
proof - |
|
418 |
have "Var x\<in>RED \<tau>" |
|
419 |
proof - |
|
420 |
have "CR4 \<tau>" by (simp add: RED_props CR3_implies_CR4) |
|
421 |
moreover |
|
422 |
have "NEUT (Var x)" by (auto simp add: NEUT_def) |
|
423 |
moreover |
|
424 |
have "NORMAL (Var x)" by (auto elim: Beta.cases simp add: NORMAL_def) |
|
425 |
ultimately show "Var x\<in>RED \<tau>" by (simp add: CR4_def) |
|
426 |
qed |
|
427 |
then have "t[x::=Var x]\<in>RED \<sigma>" using asm by simp |
|
428 |
then have "t\<in>RED \<sigma>" by (simp add: id_subs) |
|
429 |
moreover |
|
430 |
have "CR1 \<sigma>" by (simp add: RED_props) |
|
431 |
ultimately show "SN t" by (simp add: CR1_def) |
|
432 |
qed |
|
433 |
show "Lam [x].t\<in>RED (\<tau>\<rightarrow>\<sigma>)" |
|
434 |
proof (simp, intro strip) |
|
435 |
fix u |
|
436 |
assume b2: "u\<in>RED \<tau>" |
|
437 |
then have b3: "SN u" using RED_props by (auto simp add: CR1_def) |
|
438 |
show "App (Lam [x].t) u \<in> RED \<sigma>" using b1 b3 b2 asm |
|
439 |
proof(induct t u rule: double_SN) |
|
440 |
fix t u |
|
441 |
assume ih1: "\<And>t'. \<lbrakk>t \<longrightarrow>\<^isub>\<beta> t'; u\<in>RED \<tau>; \<forall>s\<in>RED \<tau>. t'[x::=s]\<in>RED \<sigma>\<rbrakk> \<Longrightarrow> App (Lam [x].t') u \<in> RED \<sigma>" |
|
442 |
assume ih2: "\<And>u'. \<lbrakk>u \<longrightarrow>\<^isub>\<beta> u'; u'\<in>RED \<tau>; \<forall>s\<in>RED \<tau>. t[x::=s]\<in>RED \<sigma>\<rbrakk> \<Longrightarrow> App (Lam [x].t) u' \<in> RED \<sigma>" |
|
443 |
assume as1: "u \<in> RED \<tau>" |
|
444 |
assume as2: "\<forall>s\<in>RED \<tau>. t[x::=s]\<in>RED \<sigma>" |
|
445 |
have "CR3_RED (App (Lam [x].t) u) \<sigma>" unfolding CR3_RED_def |
|
446 |
proof(intro strip) |
|
447 |
fix r |
|
448 |
assume red: "App (Lam [x].t) u \<longrightarrow>\<^isub>\<beta> r" |
|
449 |
moreover |
|
450 |
{ assume "\<exists>t'. t \<longrightarrow>\<^isub>\<beta> t' \<and> r = App (Lam [x].t') u"
|
|
451 |
then obtain t' where a1: "t \<longrightarrow>\<^isub>\<beta> t'" and a2: "r = App (Lam [x].t') u" by blast |
|
452 |
have "App (Lam [x].t') u\<in>RED \<sigma>" using ih1 a1 as1 as2 |
|
453 |
apply(auto) |
|
454 |
apply(drule_tac x="t'" in meta_spec) |
|
455 |
apply(simp) |
|
456 |
apply(drule meta_mp) |
|
457 |
apply(auto) |
|
458 |
apply(drule_tac x="s" in bspec) |
|
459 |
apply(simp) |
|
460 |
apply(subgoal_tac "CR2 \<sigma>") |
|
461 |
apply(unfold CR2_def)[1] |
|
462 |
apply(drule_tac x="t[x::=s]" in spec) |
|
463 |
apply(drule_tac x="t'[x::=s]" in spec) |
|
464 |
apply(simp add: beta_subst) |
|
465 |
apply(simp add: RED_props) |
|
466 |
done |
|
467 |
then have "r\<in>RED \<sigma>" using a2 by simp |
|
468 |
} |
|
469 |
moreover |
|
470 |
{ assume "\<exists>u'. u \<longrightarrow>\<^isub>\<beta> u' \<and> r = App (Lam [x].t) u'"
|
|
471 |
then obtain u' where b1: "u \<longrightarrow>\<^isub>\<beta> u'" and b2: "r = App (Lam [x].t) u'" by blast |
|
472 |
have "App (Lam [x].t) u'\<in>RED \<sigma>" using ih2 b1 as1 as2 |
|
473 |
apply(auto) |
|
474 |
apply(drule_tac x="u'" in meta_spec) |
|
475 |
apply(simp) |
|
476 |
apply(drule meta_mp) |
|
477 |
apply(subgoal_tac "CR2 \<tau>") |
|
478 |
apply(unfold CR2_def)[1] |
|
479 |
apply(drule_tac x="u" in spec) |
|
480 |
apply(drule_tac x="u'" in spec) |
|
481 |
apply(simp) |
|
482 |
apply(simp add: RED_props) |
|
483 |
apply(simp) |
|
484 |
done |
|
485 |
then have "r\<in>RED \<sigma>" using b2 by simp |
|
486 |
} |
|
487 |
moreover |
|
488 |
{ assume "r = t[x::=u]"
|
|
489 |
then have "r\<in>RED \<sigma>" using as1 as2 by auto |
|
490 |
} |
|
491 |
ultimately show "r \<in> RED \<sigma>" |
|
492 |
apply(cases) |
|
493 |
apply(auto simp add: lam.inject) |
|
494 |
apply(drule beta_abs) |
|
495 |
apply(auto simp add: alpha subst_rename) |
|
| 18106 | 496 |
done |
497 |
qed |
|
| 23970 | 498 |
moreover |
499 |
have "NEUT (App (Lam [x].t) u)" unfolding NEUT_def by (auto) |
|
500 |
ultimately show "App (Lam [x].t) u \<in> RED \<sigma>" using RED_props by (simp add: CR3_def) |
|
| 18106 | 501 |
qed |
502 |
qed |
|
| 23970 | 503 |
qed |
| 18106 | 504 |
|
| 22420 | 505 |
abbreviation |
506 |
mapsto :: "(name\<times>lam) list \<Rightarrow> name \<Rightarrow> lam \<Rightarrow> bool" ("_ maps _ to _" [55,55,55] 55)
|
|
507 |
where |
|
508 |
"\<theta> maps x to e\<equiv> (lookup \<theta> x) = e" |
|
509 |
||
510 |
abbreviation |
|
511 |
closes :: "(name\<times>lam) list \<Rightarrow> (name\<times>ty) list \<Rightarrow> bool" ("_ closes _" [55,55] 55)
|
|
512 |
where |
|
513 |
"\<theta> closes \<Gamma> \<equiv> \<forall>x T. ((x,T) \<in> set \<Gamma> \<longrightarrow> (\<exists>t. \<theta> maps x to t \<and> t \<in> RED T))" |
|
|
21107
e69c0e82955a
new file for defining functions in the lambda-calculus
urbanc
parents:
19972
diff
changeset
|
514 |
|
| 18106 | 515 |
lemma all_RED: |
| 22420 | 516 |
assumes a: "\<Gamma> \<turnstile> t : \<tau>" |
517 |
and b: "\<theta> closes \<Gamma>" |
|
518 |
shows "\<theta><t> \<in> RED \<tau>" |
|
| 18345 | 519 |
using a b |
| 23142 | 520 |
proof(nominal_induct avoiding: \<theta> rule: typing.strong_induct) |
521 |
case (t3 a \<Gamma> \<sigma> t \<tau> \<theta>) --"lambda case" |
|
522 |
have ih: "\<And>\<theta>. \<theta> closes ((a,\<sigma>)#\<Gamma>) \<Longrightarrow> \<theta><t> \<in> RED \<tau>" by fact |
|
523 |
have \<theta>_cond: "\<theta> closes \<Gamma>" by fact |
|
| 23393 | 524 |
have fresh: "a\<sharp>\<Gamma>" "a\<sharp>\<theta>" by fact+ |
| 23142 | 525 |
from ih have "\<forall>s\<in>RED \<sigma>. ((a,s)#\<theta>)<t> \<in> RED \<tau>" |
526 |
using fresh \<theta>_cond fresh_context by simp |
|
527 |
then have "\<forall>s\<in>RED \<sigma>. \<theta><t>[a::=s] \<in> RED \<tau>" |
|
528 |
using fresh by (simp add: psubst_subst) |
|
| 23970 | 529 |
then have "Lam [a].(\<theta><t>) \<in> RED (\<sigma> \<rightarrow> \<tau>)" by (simp only: abs_RED) |
| 23142 | 530 |
then show "\<theta><(Lam [a].t)> \<in> RED (\<sigma> \<rightarrow> \<tau>)" using fresh by simp |
531 |
qed auto |
|
| 18345 | 532 |
|
| 23142 | 533 |
section {* identity substitution generated from a context \<Gamma> *}
|
534 |
fun |
|
| 18382 | 535 |
"id" :: "(name\<times>ty) list \<Rightarrow> (name\<times>lam) list" |
| 23142 | 536 |
where |
| 18382 | 537 |
"id [] = []" |
| 23142 | 538 |
| "id ((x,\<tau>)#\<Gamma>) = (x,Var x)#(id \<Gamma>)" |
| 18382 | 539 |
|
| 23142 | 540 |
lemma id_maps: |
541 |
shows "(id \<Gamma>) maps a to (Var a)" |
|
542 |
by (induct \<Gamma>) (auto) |
|
| 18382 | 543 |
|
544 |
lemma id_fresh: |
|
545 |
fixes a::"name" |
|
546 |
assumes a: "a\<sharp>\<Gamma>" |
|
547 |
shows "a\<sharp>(id \<Gamma>)" |
|
548 |
using a |
|
| 23142 | 549 |
by (induct \<Gamma>) |
550 |
(auto simp add: fresh_list_nil fresh_list_cons) |
|
| 18382 | 551 |
|
552 |
lemma id_apply: |
|
| 22420 | 553 |
shows "(id \<Gamma>)<t> = t" |
| 23970 | 554 |
by (nominal_induct t avoiding: \<Gamma> rule: lam.induct) |
555 |
(auto simp add: id_maps id_fresh) |
|
| 18382 | 556 |
|
| 23142 | 557 |
lemma id_closes: |
| 22420 | 558 |
shows "(id \<Gamma>) closes \<Gamma>" |
| 18383 | 559 |
apply(auto) |
| 23142 | 560 |
apply(simp add: id_maps) |
| 22420 | 561 |
apply(subgoal_tac "CR3 T") --"A" |
| 23970 | 562 |
apply(drule CR3_implies_CR4) |
| 18382 | 563 |
apply(simp add: CR4_def) |
| 22420 | 564 |
apply(drule_tac x="Var x" in spec) |
| 18383 | 565 |
apply(force simp add: NEUT_def NORMAL_Var) |
|
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22271
diff
changeset
|
566 |
--"A" |
| 18383 | 567 |
apply(rule RED_props) |
| 18382 | 568 |
done |
569 |
||
| 18383 | 570 |
lemma typing_implies_RED: |
| 23142 | 571 |
assumes a: "\<Gamma> \<turnstile> t : \<tau>" |
| 18383 | 572 |
shows "t \<in> RED \<tau>" |
573 |
proof - |
|
| 22420 | 574 |
have "(id \<Gamma>)<t>\<in>RED \<tau>" |
| 18383 | 575 |
proof - |
| 23142 | 576 |
have "(id \<Gamma>) closes \<Gamma>" by (rule id_closes) |
| 18383 | 577 |
with a show ?thesis by (rule all_RED) |
578 |
qed |
|
579 |
thus"t \<in> RED \<tau>" by (simp add: id_apply) |
|
580 |
qed |
|
581 |
||
582 |
lemma typing_implies_SN: |
|
| 23142 | 583 |
assumes a: "\<Gamma> \<turnstile> t : \<tau>" |
| 18383 | 584 |
shows "SN(t)" |
585 |
proof - |
|
586 |
from a have "t \<in> RED \<tau>" by (rule typing_implies_RED) |
|
587 |
moreover |
|
588 |
have "CR1 \<tau>" by (rule RED_props) |
|
589 |
ultimately show "SN(t)" by (simp add: CR1_def) |
|
590 |
qed |
|
| 18382 | 591 |
|
592 |
end |