author | huffman |
Mon, 23 Jan 2012 17:29:19 +0100 | |
changeset 46317 | 80dccedd6c14 |
parent 46129 | 229fcbebf732 |
child 47397 | d654c73e4b12 |
permissions | -rw-r--r-- |
27623 | 1 |
(* Title: HOL/Nominal/Examples/Standardization.thy |
2 |
Author: Stefan Berghofer and Tobias Nipkow |
|
3 |
Copyright 2005, 2008 TU Muenchen |
|
4 |
*) |
|
5 |
||
6 |
header {* Standardization *} |
|
7 |
||
8 |
theory Standardization |
|
45966 | 9 |
imports "../Nominal" |
27623 | 10 |
begin |
11 |
||
12 |
text {* |
|
13 |
The proof of the standardization theorem, as well as most of the theorems about |
|
14 |
lambda calculus in the following sections, are taken from @{text "HOL/Lambda"}. |
|
15 |
*} |
|
16 |
||
17 |
subsection {* Lambda terms *} |
|
18 |
||
19 |
atom_decl name |
|
20 |
||
21 |
nominal_datatype lam = |
|
22 |
Var "name" |
|
23 |
| App "lam" "lam" (infixl "\<degree>" 200) |
|
24 |
| Lam "\<guillemotleft>name\<guillemotright>lam" ("Lam [_]._" [0, 10] 10) |
|
25 |
||
29097
68245155eb58
Modified nominal_primrec to make it work with local theories, unified syntax
berghofe
parents:
27623
diff
changeset
|
26 |
instantiation lam :: size |
68245155eb58
Modified nominal_primrec to make it work with local theories, unified syntax
berghofe
parents:
27623
diff
changeset
|
27 |
begin |
27623 | 28 |
|
29097
68245155eb58
Modified nominal_primrec to make it work with local theories, unified syntax
berghofe
parents:
27623
diff
changeset
|
29 |
nominal_primrec size_lam |
68245155eb58
Modified nominal_primrec to make it work with local theories, unified syntax
berghofe
parents:
27623
diff
changeset
|
30 |
where |
27623 | 31 |
"size (Var n) = 0" |
29097
68245155eb58
Modified nominal_primrec to make it work with local theories, unified syntax
berghofe
parents:
27623
diff
changeset
|
32 |
| "size (t \<degree> u) = size t + size u + 1" |
68245155eb58
Modified nominal_primrec to make it work with local theories, unified syntax
berghofe
parents:
27623
diff
changeset
|
33 |
| "size (Lam [x].t) = size t + 1" |
27623 | 34 |
apply finite_guess+ |
35 |
apply (rule TrueI)+ |
|
36 |
apply (simp add: fresh_nat) |
|
37 |
apply fresh_guess+ |
|
38 |
done |
|
39 |
||
29097
68245155eb58
Modified nominal_primrec to make it work with local theories, unified syntax
berghofe
parents:
27623
diff
changeset
|
40 |
instance .. |
68245155eb58
Modified nominal_primrec to make it work with local theories, unified syntax
berghofe
parents:
27623
diff
changeset
|
41 |
|
68245155eb58
Modified nominal_primrec to make it work with local theories, unified syntax
berghofe
parents:
27623
diff
changeset
|
42 |
end |
27623 | 43 |
|
44 |
nominal_primrec |
|
29097
68245155eb58
Modified nominal_primrec to make it work with local theories, unified syntax
berghofe
parents:
27623
diff
changeset
|
45 |
subst :: "lam \<Rightarrow> name \<Rightarrow> lam \<Rightarrow> lam" ("_[_::=_]" [300, 0, 0] 300) |
68245155eb58
Modified nominal_primrec to make it work with local theories, unified syntax
berghofe
parents:
27623
diff
changeset
|
46 |
where |
27623 | 47 |
subst_Var: "(Var x)[y::=s] = (if x=y then s else (Var x))" |
29097
68245155eb58
Modified nominal_primrec to make it work with local theories, unified syntax
berghofe
parents:
27623
diff
changeset
|
48 |
| subst_App: "(t\<^isub>1 \<degree> t\<^isub>2)[y::=s] = t\<^isub>1[y::=s] \<degree> t\<^isub>2[y::=s]" |
68245155eb58
Modified nominal_primrec to make it work with local theories, unified syntax
berghofe
parents:
27623
diff
changeset
|
49 |
| subst_Lam: "x \<sharp> (y, s) \<Longrightarrow> (Lam [x].t)[y::=s] = (Lam [x].(t[y::=s]))" |
27623 | 50 |
apply(finite_guess)+ |
51 |
apply(rule TrueI)+ |
|
52 |
apply(simp add: abs_fresh) |
|
53 |
apply(fresh_guess)+ |
|
54 |
done |
|
55 |
||
56 |
lemma subst_eqvt [eqvt]: |
|
57 |
"(pi::name prm) \<bullet> (t[x::=u]) = (pi \<bullet> t)[(pi \<bullet> x)::=(pi \<bullet> u)]" |
|
58 |
by (nominal_induct t avoiding: x u rule: lam.strong_induct) |
|
59 |
(perm_simp add: fresh_bij)+ |
|
60 |
||
61 |
lemma subst_rename: |
|
62 |
"y \<sharp> t \<Longrightarrow> ([(y, x)] \<bullet> t)[y::=u] = t[x::=u]" |
|
63 |
by (nominal_induct t avoiding: x y u rule: lam.strong_induct) |
|
64 |
(simp_all add: fresh_atm calc_atm abs_fresh) |
|
65 |
||
66 |
lemma fresh_subst: |
|
67 |
"(x::name) \<sharp> t \<Longrightarrow> x \<sharp> u \<Longrightarrow> x \<sharp> t[y::=u]" |
|
68 |
by (nominal_induct t avoiding: x y u rule: lam.strong_induct) |
|
69 |
(auto simp add: abs_fresh fresh_atm) |
|
70 |
||
71 |
lemma fresh_subst': |
|
72 |
"(x::name) \<sharp> u \<Longrightarrow> x \<sharp> t[x::=u]" |
|
73 |
by (nominal_induct t avoiding: x u rule: lam.strong_induct) |
|
74 |
(auto simp add: abs_fresh fresh_atm) |
|
75 |
||
76 |
lemma subst_forget: "(x::name) \<sharp> t \<Longrightarrow> t[x::=u] = t" |
|
77 |
by (nominal_induct t avoiding: x u rule: lam.strong_induct) |
|
78 |
(auto simp add: abs_fresh fresh_atm) |
|
79 |
||
80 |
lemma subst_subst: |
|
81 |
"x \<noteq> y \<Longrightarrow> x \<sharp> v \<Longrightarrow> t[y::=v][x::=u[y::=v]] = t[x::=u][y::=v]" |
|
82 |
by (nominal_induct t avoiding: x y u v rule: lam.strong_induct) |
|
83 |
(auto simp add: fresh_subst subst_forget) |
|
84 |
||
85 |
declare subst_Var [simp del] |
|
86 |
||
87 |
lemma subst_eq [simp]: "(Var x)[x::=u] = u" |
|
88 |
by (simp add: subst_Var) |
|
89 |
||
90 |
lemma subst_neq [simp]: "x \<noteq> y \<Longrightarrow> (Var x)[y::=u] = Var x" |
|
91 |
by (simp add: subst_Var) |
|
92 |
||
93 |
inductive beta :: "lam \<Rightarrow> lam \<Rightarrow> bool" (infixl "\<rightarrow>\<^sub>\<beta>" 50) |
|
94 |
where |
|
95 |
beta: "x \<sharp> t \<Longrightarrow> (Lam [x].s) \<degree> t \<rightarrow>\<^sub>\<beta> s[x::=t]" |
|
96 |
| appL [simp, intro!]: "s \<rightarrow>\<^sub>\<beta> t \<Longrightarrow> s \<degree> u \<rightarrow>\<^sub>\<beta> t \<degree> u" |
|
97 |
| appR [simp, intro!]: "s \<rightarrow>\<^sub>\<beta> t \<Longrightarrow> u \<degree> s \<rightarrow>\<^sub>\<beta> u \<degree> t" |
|
98 |
| abs [simp, intro!]: "s \<rightarrow>\<^sub>\<beta> t \<Longrightarrow> (Lam [x].s) \<rightarrow>\<^sub>\<beta> (Lam [x].t)" |
|
99 |
||
100 |
equivariance beta |
|
101 |
nominal_inductive beta |
|
102 |
by (simp_all add: abs_fresh fresh_subst') |
|
103 |
||
104 |
lemma better_beta [simp, intro!]: "(Lam [x].s) \<degree> t \<rightarrow>\<^sub>\<beta> s[x::=t]" |
|
105 |
proof - |
|
106 |
obtain y::name where y: "y \<sharp> (x, s, t)" |
|
107 |
by (rule exists_fresh) (rule fin_supp) |
|
108 |
then have "y \<sharp> t" by simp |
|
109 |
then have "(Lam [y]. [(y, x)] \<bullet> s) \<degree> t \<rightarrow>\<^sub>\<beta> ([(y, x)] \<bullet> s)[y::=t]" |
|
110 |
by (rule beta) |
|
111 |
moreover from y have "(Lam [x].s) = (Lam [y]. [(y, x)] \<bullet> s)" |
|
112 |
by (auto simp add: lam.inject alpha' fresh_prod fresh_atm) |
|
113 |
ultimately show ?thesis using y by (simp add: subst_rename) |
|
114 |
qed |
|
115 |
||
116 |
abbreviation |
|
117 |
beta_reds :: "lam \<Rightarrow> lam \<Rightarrow> bool" (infixl "\<rightarrow>\<^sub>\<beta>\<^sup>*" 50) where |
|
118 |
"s \<rightarrow>\<^sub>\<beta>\<^sup>* t \<equiv> beta\<^sup>*\<^sup>* s t" |
|
119 |
||
120 |
||
121 |
subsection {* Application of a term to a list of terms *} |
|
122 |
||
123 |
abbreviation |
|
124 |
list_application :: "lam \<Rightarrow> lam list \<Rightarrow> lam" (infixl "\<degree>\<degree>" 150) where |
|
125 |
"t \<degree>\<degree> ts \<equiv> foldl (op \<degree>) t ts" |
|
126 |
||
127 |
lemma apps_eq_tail_conv [iff]: "(r \<degree>\<degree> ts = s \<degree>\<degree> ts) = (r = s)" |
|
128 |
by (induct ts rule: rev_induct) (auto simp add: lam.inject) |
|
129 |
||
130 |
lemma Var_eq_apps_conv [iff]: "(Var m = s \<degree>\<degree> ss) = (Var m = s \<and> ss = [])" |
|
131 |
by (induct ss arbitrary: s) auto |
|
132 |
||
133 |
lemma Var_apps_eq_Var_apps_conv [iff]: |
|
134 |
"(Var m \<degree>\<degree> rs = Var n \<degree>\<degree> ss) = (m = n \<and> rs = ss)" |
|
135 |
apply (induct rs arbitrary: ss rule: rev_induct) |
|
136 |
apply (simp add: lam.inject) |
|
137 |
apply blast |
|
138 |
apply (induct_tac ss rule: rev_induct) |
|
139 |
apply (auto simp add: lam.inject) |
|
140 |
done |
|
141 |
||
142 |
lemma App_eq_foldl_conv: |
|
143 |
"(r \<degree> s = t \<degree>\<degree> ts) = |
|
144 |
(if ts = [] then r \<degree> s = t |
|
145 |
else (\<exists>ss. ts = ss @ [s] \<and> r = t \<degree>\<degree> ss))" |
|
146 |
apply (rule_tac xs = ts in rev_exhaust) |
|
147 |
apply (auto simp add: lam.inject) |
|
148 |
done |
|
149 |
||
150 |
lemma Abs_eq_apps_conv [iff]: |
|
151 |
"((Lam [x].r) = s \<degree>\<degree> ss) = ((Lam [x].r) = s \<and> ss = [])" |
|
152 |
by (induct ss rule: rev_induct) auto |
|
153 |
||
154 |
lemma apps_eq_Abs_conv [iff]: "(s \<degree>\<degree> ss = (Lam [x].r)) = (s = (Lam [x].r) \<and> ss = [])" |
|
155 |
by (induct ss rule: rev_induct) auto |
|
156 |
||
157 |
lemma Abs_App_neq_Var_apps [iff]: |
|
158 |
"(Lam [x].s) \<degree> t \<noteq> Var n \<degree>\<degree> ss" |
|
159 |
by (induct ss arbitrary: s t rule: rev_induct) (auto simp add: lam.inject) |
|
160 |
||
161 |
lemma Var_apps_neq_Abs_apps [iff]: |
|
162 |
"Var n \<degree>\<degree> ts \<noteq> (Lam [x].r) \<degree>\<degree> ss" |
|
163 |
apply (induct ss arbitrary: ts rule: rev_induct) |
|
164 |
apply simp |
|
165 |
apply (induct_tac ts rule: rev_induct) |
|
166 |
apply (auto simp add: lam.inject) |
|
167 |
done |
|
168 |
||
169 |
lemma ex_head_tail: |
|
170 |
"\<exists>ts h. t = h \<degree>\<degree> ts \<and> ((\<exists>n. h = Var n) \<or> (\<exists>x u. h = (Lam [x].u)))" |
|
171 |
apply (induct t rule: lam.induct) |
|
39459 | 172 |
apply (metis foldl_Nil) |
173 |
apply (metis foldl_Cons foldl_Nil foldl_append) |
|
174 |
apply (metis foldl_Nil) |
|
27623 | 175 |
done |
176 |
||
177 |
lemma size_apps [simp]: |
|
178 |
"size (r \<degree>\<degree> rs) = size r + foldl (op +) 0 (map size rs) + length rs" |
|
179 |
by (induct rs rule: rev_induct) auto |
|
180 |
||
181 |
lemma lem0: "(0::nat) < k \<Longrightarrow> m \<le> n \<Longrightarrow> m < n + k" |
|
182 |
by simp |
|
183 |
||
184 |
lemma subst_map [simp]: |
|
185 |
"(t \<degree>\<degree> ts)[x::=u] = t[x::=u] \<degree>\<degree> map (\<lambda>t. t[x::=u]) ts" |
|
186 |
by (induct ts arbitrary: t) simp_all |
|
187 |
||
188 |
lemma app_last: "(t \<degree>\<degree> ts) \<degree> u = t \<degree>\<degree> (ts @ [u])" |
|
189 |
by simp |
|
190 |
||
191 |
lemma perm_apps [eqvt]: |
|
192 |
"(pi::name prm) \<bullet> (t \<degree>\<degree> ts) = ((pi \<bullet> t) \<degree>\<degree> (pi \<bullet> ts))" |
|
193 |
by (induct ts rule: rev_induct) (auto simp add: append_eqvt) |
|
194 |
||
195 |
lemma fresh_apps [simp]: "(x::name) \<sharp> (t \<degree>\<degree> ts) = (x \<sharp> t \<and> x \<sharp> ts)" |
|
196 |
by (induct ts rule: rev_induct) |
|
197 |
(auto simp add: fresh_list_append fresh_list_nil fresh_list_cons) |
|
198 |
||
199 |
text {* A customized induction schema for @{text "\<degree>\<degree>"}. *} |
|
200 |
||
201 |
lemma lem: |
|
202 |
assumes "\<And>n ts (z::'a::fs_name). (\<And>z. \<forall>t \<in> set ts. P z t) \<Longrightarrow> P z (Var n \<degree>\<degree> ts)" |
|
203 |
and "\<And>x u ts z. x \<sharp> z \<Longrightarrow> (\<And>z. P z u) \<Longrightarrow> (\<And>z. \<forall>t \<in> set ts. P z t) \<Longrightarrow> P z ((Lam [x].u) \<degree>\<degree> ts)" |
|
204 |
shows "size t = n \<Longrightarrow> P z t" |
|
205 |
apply (induct n arbitrary: t z rule: nat_less_induct) |
|
206 |
apply (cut_tac t = t in ex_head_tail) |
|
207 |
apply clarify |
|
208 |
apply (erule disjE) |
|
209 |
apply clarify |
|
210 |
apply (rule assms) |
|
211 |
apply clarify |
|
212 |
apply (erule allE, erule impE) |
|
213 |
prefer 2 |
|
214 |
apply (erule allE, erule impE, rule refl, erule spec) |
|
46129 | 215 |
apply simp |
216 |
apply (clarsimp simp add: foldr_conv_foldl [symmetric] foldr_def fold_plus_listsum_rev listsum_map_remove1) |
|
27623 | 217 |
apply clarify |
218 |
apply (subgoal_tac "\<exists>y::name. y \<sharp> (x, u, z)") |
|
39459 | 219 |
prefer 2 |
220 |
apply (blast intro: exists_fresh' fin_supp) |
|
27623 | 221 |
apply (erule exE) |
222 |
apply (subgoal_tac "(Lam [x].u) = (Lam [y].([(y, x)] \<bullet> u))") |
|
223 |
prefer 2 |
|
224 |
apply (auto simp add: lam.inject alpha' fresh_prod fresh_atm)[] |
|
225 |
apply (simp (no_asm_simp)) |
|
226 |
apply (rule assms) |
|
227 |
apply (simp add: fresh_prod) |
|
228 |
apply (erule allE, erule impE) |
|
229 |
prefer 2 |
|
230 |
apply (erule allE, erule impE, rule refl, erule spec) |
|
231 |
apply simp |
|
232 |
apply clarify |
|
233 |
apply (erule allE, erule impE) |
|
234 |
prefer 2 |
|
39459 | 235 |
apply blast |
236 |
apply (force intro: le_imp_less_Suc trans_le_add1 trans_le_add2 elem_le_sum) |
|
27623 | 237 |
done |
238 |
||
239 |
theorem Apps_lam_induct: |
|
240 |
assumes "\<And>n ts (z::'a::fs_name). (\<And>z. \<forall>t \<in> set ts. P z t) \<Longrightarrow> P z (Var n \<degree>\<degree> ts)" |
|
241 |
and "\<And>x u ts z. x \<sharp> z \<Longrightarrow> (\<And>z. P z u) \<Longrightarrow> (\<And>z. \<forall>t \<in> set ts. P z t) \<Longrightarrow> P z ((Lam [x].u) \<degree>\<degree> ts)" |
|
242 |
shows "P z t" |
|
243 |
apply (rule_tac t = t and z = z in lem) |
|
244 |
prefer 3 |
|
245 |
apply (rule refl) |
|
246 |
using assms apply blast+ |
|
247 |
done |
|
248 |
||
249 |
||
250 |
subsection {* Congruence rules *} |
|
251 |
||
252 |
lemma apps_preserves_beta [simp]: |
|
253 |
"r \<rightarrow>\<^sub>\<beta> s \<Longrightarrow> r \<degree>\<degree> ss \<rightarrow>\<^sub>\<beta> s \<degree>\<degree> ss" |
|
254 |
by (induct ss rule: rev_induct) auto |
|
255 |
||
256 |
lemma rtrancl_beta_Abs [intro!]: |
|
257 |
"s \<rightarrow>\<^sub>\<beta>\<^sup>* s' \<Longrightarrow> (Lam [x].s) \<rightarrow>\<^sub>\<beta>\<^sup>* (Lam [x].s')" |
|
258 |
by (induct set: rtranclp) (blast intro: rtranclp.rtrancl_into_rtrancl)+ |
|
259 |
||
260 |
lemma rtrancl_beta_AppL: |
|
261 |
"s \<rightarrow>\<^sub>\<beta>\<^sup>* s' \<Longrightarrow> s \<degree> t \<rightarrow>\<^sub>\<beta>\<^sup>* s' \<degree> t" |
|
262 |
by (induct set: rtranclp) (blast intro: rtranclp.rtrancl_into_rtrancl)+ |
|
263 |
||
264 |
lemma rtrancl_beta_AppR: |
|
265 |
"t \<rightarrow>\<^sub>\<beta>\<^sup>* t' \<Longrightarrow> s \<degree> t \<rightarrow>\<^sub>\<beta>\<^sup>* s \<degree> t'" |
|
266 |
by (induct set: rtranclp) (blast intro: rtranclp.rtrancl_into_rtrancl)+ |
|
267 |
||
268 |
lemma rtrancl_beta_App [intro]: |
|
269 |
"s \<rightarrow>\<^sub>\<beta>\<^sup>* s' \<Longrightarrow> t \<rightarrow>\<^sub>\<beta>\<^sup>* t' \<Longrightarrow> s \<degree> t \<rightarrow>\<^sub>\<beta>\<^sup>* s' \<degree> t'" |
|
270 |
by (blast intro!: rtrancl_beta_AppL rtrancl_beta_AppR intro: rtranclp_trans) |
|
271 |
||
272 |
||
273 |
subsection {* Lifting an order to lists of elements *} |
|
274 |
||
275 |
definition |
|
276 |
step1 :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> 'a list \<Rightarrow> 'a list \<Rightarrow> bool" where |
|
277 |
"step1 r = |
|
278 |
(\<lambda>ys xs. \<exists>us z z' vs. xs = us @ z # vs \<and> r z' z \<and> ys = |
|
279 |
us @ z' # vs)" |
|
280 |
||
281 |
lemma not_Nil_step1 [iff]: "\<not> step1 r [] xs" |
|
282 |
apply (unfold step1_def) |
|
283 |
apply blast |
|
284 |
done |
|
285 |
||
286 |
lemma not_step1_Nil [iff]: "\<not> step1 r xs []" |
|
287 |
apply (unfold step1_def) |
|
288 |
apply blast |
|
289 |
done |
|
290 |
||
291 |
lemma Cons_step1_Cons [iff]: |
|
292 |
"(step1 r (y # ys) (x # xs)) = |
|
293 |
(r y x \<and> xs = ys \<or> x = y \<and> step1 r ys xs)" |
|
294 |
apply (unfold step1_def) |
|
295 |
apply (rule iffI) |
|
296 |
apply (erule exE) |
|
297 |
apply (rename_tac ts) |
|
298 |
apply (case_tac ts) |
|
44890
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
nipkow
parents:
39779
diff
changeset
|
299 |
apply fastforce |
27623 | 300 |
apply force |
301 |
apply (erule disjE) |
|
302 |
apply blast |
|
303 |
apply (blast intro: Cons_eq_appendI) |
|
304 |
done |
|
305 |
||
306 |
lemma append_step1I: |
|
307 |
"step1 r ys xs \<and> vs = us \<or> ys = xs \<and> step1 r vs us |
|
308 |
\<Longrightarrow> step1 r (ys @ vs) (xs @ us)" |
|
309 |
apply (unfold step1_def) |
|
310 |
apply auto |
|
311 |
apply blast |
|
312 |
apply (blast intro: append_eq_appendI) |
|
313 |
done |
|
314 |
||
315 |
lemma Cons_step1E [elim!]: |
|
316 |
assumes "step1 r ys (x # xs)" |
|
317 |
and "\<And>y. ys = y # xs \<Longrightarrow> r y x \<Longrightarrow> R" |
|
318 |
and "\<And>zs. ys = x # zs \<Longrightarrow> step1 r zs xs \<Longrightarrow> R" |
|
319 |
shows R |
|
320 |
using assms |
|
321 |
apply (cases ys) |
|
322 |
apply (simp add: step1_def) |
|
323 |
apply blast |
|
324 |
done |
|
325 |
||
326 |
lemma Snoc_step1_SnocD: |
|
327 |
"step1 r (ys @ [y]) (xs @ [x]) |
|
328 |
\<Longrightarrow> (step1 r ys xs \<and> y = x \<or> ys = xs \<and> r y x)" |
|
329 |
apply (unfold step1_def) |
|
330 |
apply (clarify del: disjCI) |
|
331 |
apply (rename_tac vs) |
|
332 |
apply (rule_tac xs = vs in rev_exhaust) |
|
333 |
apply force |
|
334 |
apply simp |
|
335 |
apply blast |
|
336 |
done |
|
337 |
||
338 |
||
339 |
subsection {* Lifting beta-reduction to lists *} |
|
340 |
||
341 |
abbreviation |
|
342 |
list_beta :: "lam list \<Rightarrow> lam list \<Rightarrow> bool" (infixl "[\<rightarrow>\<^sub>\<beta>]\<^sub>1" 50) where |
|
343 |
"rs [\<rightarrow>\<^sub>\<beta>]\<^sub>1 ss \<equiv> step1 beta rs ss" |
|
344 |
||
345 |
lemma head_Var_reduction: |
|
346 |
"Var n \<degree>\<degree> rs \<rightarrow>\<^sub>\<beta> v \<Longrightarrow> \<exists>ss. rs [\<rightarrow>\<^sub>\<beta>]\<^sub>1 ss \<and> v = Var n \<degree>\<degree> ss" |
|
347 |
apply (induct u \<equiv> "Var n \<degree>\<degree> rs" v arbitrary: rs set: beta) |
|
348 |
apply simp |
|
349 |
apply (rule_tac xs = rs in rev_exhaust) |
|
350 |
apply simp |
|
351 |
apply (atomize, force intro: append_step1I iff: lam.inject) |
|
352 |
apply (rule_tac xs = rs in rev_exhaust) |
|
353 |
apply simp |
|
354 |
apply (auto 0 3 intro: disjI2 [THEN append_step1I] simp add: lam.inject) |
|
355 |
done |
|
356 |
||
357 |
lemma apps_betasE [case_names appL appR beta, consumes 1]: |
|
358 |
assumes major: "r \<degree>\<degree> rs \<rightarrow>\<^sub>\<beta> s" |
|
359 |
and cases: "\<And>r'. r \<rightarrow>\<^sub>\<beta> r' \<Longrightarrow> s = r' \<degree>\<degree> rs \<Longrightarrow> R" |
|
360 |
"\<And>rs'. rs [\<rightarrow>\<^sub>\<beta>]\<^sub>1 rs' \<Longrightarrow> s = r \<degree>\<degree> rs' \<Longrightarrow> R" |
|
361 |
"\<And>t u us. (x \<sharp> r \<Longrightarrow> r = (Lam [x].t) \<and> rs = u # us \<and> s = t[x::=u] \<degree>\<degree> us) \<Longrightarrow> R" |
|
362 |
shows R |
|
363 |
proof - |
|
364 |
from major have |
|
365 |
"(\<exists>r'. r \<rightarrow>\<^sub>\<beta> r' \<and> s = r' \<degree>\<degree> rs) \<or> |
|
366 |
(\<exists>rs'. rs [\<rightarrow>\<^sub>\<beta>]\<^sub>1 rs' \<and> s = r \<degree>\<degree> rs') \<or> |
|
367 |
(\<exists>t u us. x \<sharp> r \<longrightarrow> r = (Lam [x].t) \<and> rs = u # us \<and> s = t[x::=u] \<degree>\<degree> us)" |
|
368 |
apply (nominal_induct u \<equiv> "r \<degree>\<degree> rs" s avoiding: x r rs rule: beta.strong_induct) |
|
369 |
apply (simp add: App_eq_foldl_conv) |
|
370 |
apply (split split_if_asm) |
|
371 |
apply simp |
|
372 |
apply blast |
|
373 |
apply simp |
|
374 |
apply (rule impI)+ |
|
375 |
apply (rule disjI2) |
|
376 |
apply (rule disjI2) |
|
377 |
apply (subgoal_tac "r = [(xa, x)] \<bullet> (Lam [x].s)") |
|
378 |
prefer 2 |
|
379 |
apply (simp add: perm_fresh_fresh) |
|
380 |
apply (drule conjunct1) |
|
381 |
apply (subgoal_tac "r = (Lam [xa]. [(xa, x)] \<bullet> s)") |
|
382 |
prefer 2 |
|
383 |
apply (simp add: calc_atm) |
|
384 |
apply (thin_tac "r = ?t") |
|
385 |
apply simp |
|
386 |
apply (rule exI) |
|
387 |
apply (rule conjI) |
|
388 |
apply (rule refl) |
|
389 |
apply (simp add: abs_fresh fresh_atm fresh_left calc_atm subst_rename) |
|
390 |
apply (drule App_eq_foldl_conv [THEN iffD1]) |
|
391 |
apply (split split_if_asm) |
|
392 |
apply simp |
|
393 |
apply blast |
|
394 |
apply (force intro!: disjI1 [THEN append_step1I] simp add: fresh_list_append) |
|
395 |
apply (drule App_eq_foldl_conv [THEN iffD1]) |
|
396 |
apply (split split_if_asm) |
|
397 |
apply simp |
|
398 |
apply blast |
|
399 |
apply (clarify, auto 0 3 intro!: exI intro: append_step1I) |
|
400 |
done |
|
401 |
with cases show ?thesis by blast |
|
402 |
qed |
|
403 |
||
404 |
lemma apps_preserves_betas [simp]: |
|
405 |
"rs [\<rightarrow>\<^sub>\<beta>]\<^sub>1 ss \<Longrightarrow> r \<degree>\<degree> rs \<rightarrow>\<^sub>\<beta> r \<degree>\<degree> ss" |
|
406 |
apply (induct rs arbitrary: ss rule: rev_induct) |
|
407 |
apply simp |
|
408 |
apply simp |
|
409 |
apply (rule_tac xs = ss in rev_exhaust) |
|
410 |
apply simp |
|
411 |
apply simp |
|
412 |
apply (drule Snoc_step1_SnocD) |
|
413 |
apply blast |
|
414 |
done |
|
415 |
||
416 |
||
417 |
subsection {* Standard reduction relation *} |
|
418 |
||
419 |
text {* |
|
420 |
Based on lecture notes by Ralph Matthes, |
|
421 |
original proof idea due to Ralph Loader. |
|
422 |
*} |
|
423 |
||
424 |
declare listrel_mono [mono_set] |
|
425 |
||
426 |
lemma listrelp_eqvt [eqvt]: |
|
46317 | 427 |
fixes f :: "'a::pt_name \<Rightarrow> 'b::pt_name \<Rightarrow> bool" |
27623 | 428 |
assumes xy: "listrelp f (x::'a::pt_name list) y" |
429 |
shows "listrelp ((pi::name prm) \<bullet> f) (pi \<bullet> x) (pi \<bullet> y)" using xy |
|
45966 | 430 |
by induct (simp_all add: listrelp.intros perm_app [symmetric]) |
27623 | 431 |
|
432 |
inductive |
|
433 |
sred :: "lam \<Rightarrow> lam \<Rightarrow> bool" (infixl "\<rightarrow>\<^sub>s" 50) |
|
434 |
and sredlist :: "lam list \<Rightarrow> lam list \<Rightarrow> bool" (infixl "[\<rightarrow>\<^sub>s]" 50) |
|
435 |
where |
|
436 |
"s [\<rightarrow>\<^sub>s] t \<equiv> listrelp op \<rightarrow>\<^sub>s s t" |
|
437 |
| Var: "rs [\<rightarrow>\<^sub>s] rs' \<Longrightarrow> Var x \<degree>\<degree> rs \<rightarrow>\<^sub>s Var x \<degree>\<degree> rs'" |
|
438 |
| Abs: "x \<sharp> (ss, ss') \<Longrightarrow> r \<rightarrow>\<^sub>s r' \<Longrightarrow> ss [\<rightarrow>\<^sub>s] ss' \<Longrightarrow> (Lam [x].r) \<degree>\<degree> ss \<rightarrow>\<^sub>s (Lam [x].r') \<degree>\<degree> ss'" |
|
439 |
| Beta: "x \<sharp> (s, ss, t) \<Longrightarrow> r[x::=s] \<degree>\<degree> ss \<rightarrow>\<^sub>s t \<Longrightarrow> (Lam [x].r) \<degree> s \<degree>\<degree> ss \<rightarrow>\<^sub>s t" |
|
440 |
||
441 |
equivariance sred |
|
442 |
nominal_inductive sred |
|
443 |
by (simp add: abs_fresh)+ |
|
444 |
||
445 |
lemma better_sred_Abs: |
|
446 |
assumes H1: "r \<rightarrow>\<^sub>s r'" |
|
447 |
and H2: "ss [\<rightarrow>\<^sub>s] ss'" |
|
448 |
shows "(Lam [x].r) \<degree>\<degree> ss \<rightarrow>\<^sub>s (Lam [x].r') \<degree>\<degree> ss'" |
|
449 |
proof - |
|
450 |
obtain y::name where y: "y \<sharp> (x, r, r', ss, ss')" |
|
451 |
by (rule exists_fresh) (rule fin_supp) |
|
452 |
then have "y \<sharp> (ss, ss')" by simp |
|
453 |
moreover from H1 have "[(y, x)] \<bullet> (r \<rightarrow>\<^sub>s r')" by (rule perm_boolI) |
|
454 |
then have "([(y, x)] \<bullet> r) \<rightarrow>\<^sub>s ([(y, x)] \<bullet> r')" by (simp add: eqvts) |
|
455 |
ultimately have "(Lam [y]. [(y, x)] \<bullet> r) \<degree>\<degree> ss \<rightarrow>\<^sub>s (Lam [y]. [(y, x)] \<bullet> r') \<degree>\<degree> ss'" using H2 |
|
456 |
by (rule sred.Abs) |
|
457 |
moreover from y have "(Lam [x].r) = (Lam [y]. [(y, x)] \<bullet> r)" |
|
458 |
by (auto simp add: lam.inject alpha' fresh_prod fresh_atm) |
|
459 |
moreover from y have "(Lam [x].r') = (Lam [y]. [(y, x)] \<bullet> r')" |
|
460 |
by (auto simp add: lam.inject alpha' fresh_prod fresh_atm) |
|
461 |
ultimately show ?thesis by simp |
|
462 |
qed |
|
463 |
||
464 |
lemma better_sred_Beta: |
|
465 |
assumes H: "r[x::=s] \<degree>\<degree> ss \<rightarrow>\<^sub>s t" |
|
466 |
shows "(Lam [x].r) \<degree> s \<degree>\<degree> ss \<rightarrow>\<^sub>s t" |
|
467 |
proof - |
|
468 |
obtain y::name where y: "y \<sharp> (x, r, s, ss, t)" |
|
469 |
by (rule exists_fresh) (rule fin_supp) |
|
470 |
then have "y \<sharp> (s, ss, t)" by simp |
|
471 |
moreover from y H have "([(y, x)] \<bullet> r)[y::=s] \<degree>\<degree> ss \<rightarrow>\<^sub>s t" |
|
472 |
by (simp add: subst_rename) |
|
473 |
ultimately have "(Lam [y].[(y, x)] \<bullet> r) \<degree> s \<degree>\<degree> ss \<rightarrow>\<^sub>s t" |
|
474 |
by (rule sred.Beta) |
|
475 |
moreover from y have "(Lam [x].r) = (Lam [y]. [(y, x)] \<bullet> r)" |
|
476 |
by (auto simp add: lam.inject alpha' fresh_prod fresh_atm) |
|
477 |
ultimately show ?thesis by simp |
|
478 |
qed |
|
479 |
||
480 |
lemmas better_sred_intros = sred.Var better_sred_Abs better_sred_Beta |
|
481 |
||
482 |
lemma refl_listrelp: "\<forall>x\<in>set xs. R x x \<Longrightarrow> listrelp R xs xs" |
|
483 |
by (induct xs) (auto intro: listrelp.intros) |
|
484 |
||
485 |
lemma refl_sred: "t \<rightarrow>\<^sub>s t" |
|
486 |
by (nominal_induct t rule: Apps_lam_induct) (auto intro: refl_listrelp better_sred_intros) |
|
487 |
||
488 |
lemma listrelp_conj1: "listrelp (\<lambda>x y. R x y \<and> S x y) x y \<Longrightarrow> listrelp R x y" |
|
489 |
by (erule listrelp.induct) (auto intro: listrelp.intros) |
|
490 |
||
491 |
lemma listrelp_conj2: "listrelp (\<lambda>x y. R x y \<and> S x y) x y \<Longrightarrow> listrelp S x y" |
|
492 |
by (erule listrelp.induct) (auto intro: listrelp.intros) |
|
493 |
||
494 |
lemma listrelp_app: |
|
495 |
assumes xsys: "listrelp R xs ys" |
|
496 |
shows "listrelp R xs' ys' \<Longrightarrow> listrelp R (xs @ xs') (ys @ ys')" using xsys |
|
497 |
by (induct arbitrary: xs' ys') (auto intro: listrelp.intros) |
|
498 |
||
499 |
lemma lemma1: |
|
500 |
assumes r: "r \<rightarrow>\<^sub>s r'" and s: "s \<rightarrow>\<^sub>s s'" |
|
501 |
shows "r \<degree> s \<rightarrow>\<^sub>s r' \<degree> s'" using r |
|
502 |
proof induct |
|
503 |
case (Var rs rs' x) |
|
504 |
then have "rs [\<rightarrow>\<^sub>s] rs'" by (rule listrelp_conj1) |
|
505 |
moreover have "[s] [\<rightarrow>\<^sub>s] [s']" by (iprover intro: s listrelp.intros) |
|
506 |
ultimately have "rs @ [s] [\<rightarrow>\<^sub>s] rs' @ [s']" by (rule listrelp_app) |
|
507 |
hence "Var x \<degree>\<degree> (rs @ [s]) \<rightarrow>\<^sub>s Var x \<degree>\<degree> (rs' @ [s'])" by (rule sred.Var) |
|
508 |
thus ?case by (simp only: app_last) |
|
509 |
next |
|
510 |
case (Abs x ss ss' r r') |
|
511 |
from Abs(4) have "ss [\<rightarrow>\<^sub>s] ss'" by (rule listrelp_conj1) |
|
512 |
moreover have "[s] [\<rightarrow>\<^sub>s] [s']" by (iprover intro: s listrelp.intros) |
|
513 |
ultimately have "ss @ [s] [\<rightarrow>\<^sub>s] ss' @ [s']" by (rule listrelp_app) |
|
514 |
with `r \<rightarrow>\<^sub>s r'` have "(Lam [x].r) \<degree>\<degree> (ss @ [s]) \<rightarrow>\<^sub>s (Lam [x].r') \<degree>\<degree> (ss' @ [s'])" |
|
515 |
by (rule better_sred_Abs) |
|
516 |
thus ?case by (simp only: app_last) |
|
517 |
next |
|
518 |
case (Beta x u ss t r) |
|
519 |
hence "r[x::=u] \<degree>\<degree> (ss @ [s]) \<rightarrow>\<^sub>s t \<degree> s'" by (simp only: app_last) |
|
520 |
hence "(Lam [x].r) \<degree> u \<degree>\<degree> (ss @ [s]) \<rightarrow>\<^sub>s t \<degree> s'" by (rule better_sred_Beta) |
|
521 |
thus ?case by (simp only: app_last) |
|
522 |
qed |
|
523 |
||
524 |
lemma lemma1': |
|
525 |
assumes ts: "ts [\<rightarrow>\<^sub>s] ts'" |
|
526 |
shows "r \<rightarrow>\<^sub>s r' \<Longrightarrow> r \<degree>\<degree> ts \<rightarrow>\<^sub>s r' \<degree>\<degree> ts'" using ts |
|
527 |
by (induct arbitrary: r r') (auto intro: lemma1) |
|
528 |
||
529 |
lemma listrelp_betas: |
|
530 |
assumes ts: "listrelp op \<rightarrow>\<^sub>\<beta>\<^sup>* ts ts'" |
|
531 |
shows "\<And>t t'. t \<rightarrow>\<^sub>\<beta>\<^sup>* t' \<Longrightarrow> t \<degree>\<degree> ts \<rightarrow>\<^sub>\<beta>\<^sup>* t' \<degree>\<degree> ts'" using ts |
|
532 |
by induct auto |
|
533 |
||
534 |
lemma lemma2: |
|
535 |
assumes t: "t \<rightarrow>\<^sub>s u" |
|
536 |
shows "t \<rightarrow>\<^sub>\<beta>\<^sup>* u" using t |
|
537 |
by induct (auto dest: listrelp_conj2 |
|
538 |
intro: listrelp_betas apps_preserves_beta converse_rtranclp_into_rtranclp) |
|
539 |
||
540 |
lemma lemma3: |
|
541 |
assumes r: "r \<rightarrow>\<^sub>s r'" |
|
542 |
shows "s \<rightarrow>\<^sub>s s' \<Longrightarrow> r[x::=s] \<rightarrow>\<^sub>s r'[x::=s']" using r |
|
543 |
proof (nominal_induct avoiding: x s s' rule: sred.strong_induct) |
|
544 |
case (Var rs rs' y) |
|
545 |
hence "map (\<lambda>t. t[x::=s]) rs [\<rightarrow>\<^sub>s] map (\<lambda>t. t[x::=s']) rs'" |
|
546 |
by induct (auto intro: listrelp.intros Var) |
|
547 |
moreover have "Var y[x::=s] \<rightarrow>\<^sub>s Var y[x::=s']" |
|
548 |
by (cases "y = x") (auto simp add: Var intro: refl_sred) |
|
549 |
ultimately show ?case by simp (rule lemma1') |
|
550 |
next |
|
551 |
case (Abs y ss ss' r r') |
|
552 |
then have "r[x::=s] \<rightarrow>\<^sub>s r'[x::=s']" by fast |
|
553 |
moreover from Abs(8) `s \<rightarrow>\<^sub>s s'` have "map (\<lambda>t. t[x::=s]) ss [\<rightarrow>\<^sub>s] map (\<lambda>t. t[x::=s']) ss'" |
|
554 |
by induct (auto intro: listrelp.intros Abs) |
|
555 |
ultimately show ?case using Abs(6) `y \<sharp> x` `y \<sharp> s` `y \<sharp> s'` |
|
556 |
by simp (rule better_sred_Abs) |
|
557 |
next |
|
558 |
case (Beta y u ss t r) |
|
559 |
thus ?case by (auto simp add: subst_subst fresh_atm intro: better_sred_Beta) |
|
560 |
qed |
|
561 |
||
562 |
lemma lemma4_aux: |
|
563 |
assumes rs: "listrelp (\<lambda>t u. t \<rightarrow>\<^sub>s u \<and> (\<forall>r. u \<rightarrow>\<^sub>\<beta> r \<longrightarrow> t \<rightarrow>\<^sub>s r)) rs rs'" |
|
564 |
shows "rs' [\<rightarrow>\<^sub>\<beta>]\<^sub>1 ss \<Longrightarrow> rs [\<rightarrow>\<^sub>s] ss" using rs |
|
565 |
proof (induct arbitrary: ss) |
|
566 |
case Nil |
|
567 |
thus ?case by cases (auto intro: listrelp.Nil) |
|
568 |
next |
|
569 |
case (Cons x y xs ys) |
|
570 |
note Cons' = Cons |
|
571 |
show ?case |
|
572 |
proof (cases ss) |
|
573 |
case Nil with Cons show ?thesis by simp |
|
574 |
next |
|
575 |
case (Cons y' ys') |
|
576 |
hence ss: "ss = y' # ys'" by simp |
|
577 |
from Cons Cons' have "y \<rightarrow>\<^sub>\<beta> y' \<and> ys' = ys \<or> y' = y \<and> ys [\<rightarrow>\<^sub>\<beta>]\<^sub>1 ys'" by simp |
|
578 |
hence "x # xs [\<rightarrow>\<^sub>s] y' # ys'" |
|
579 |
proof |
|
580 |
assume H: "y \<rightarrow>\<^sub>\<beta> y' \<and> ys' = ys" |
|
581 |
with Cons' have "x \<rightarrow>\<^sub>s y'" by blast |
|
582 |
moreover from Cons' have "xs [\<rightarrow>\<^sub>s] ys" by (iprover dest: listrelp_conj1) |
|
583 |
ultimately have "x # xs [\<rightarrow>\<^sub>s] y' # ys" by (rule listrelp.Cons) |
|
584 |
with H show ?thesis by simp |
|
585 |
next |
|
586 |
assume H: "y' = y \<and> ys [\<rightarrow>\<^sub>\<beta>]\<^sub>1 ys'" |
|
587 |
with Cons' have "x \<rightarrow>\<^sub>s y'" by blast |
|
588 |
moreover from H have "xs [\<rightarrow>\<^sub>s] ys'" by (blast intro: Cons') |
|
589 |
ultimately show ?thesis by (rule listrelp.Cons) |
|
590 |
qed |
|
591 |
with ss show ?thesis by simp |
|
592 |
qed |
|
593 |
qed |
|
594 |
||
595 |
lemma lemma4: |
|
596 |
assumes r: "r \<rightarrow>\<^sub>s r'" |
|
597 |
shows "r' \<rightarrow>\<^sub>\<beta> r'' \<Longrightarrow> r \<rightarrow>\<^sub>s r''" using r |
|
598 |
proof (nominal_induct avoiding: r'' rule: sred.strong_induct) |
|
599 |
case (Var rs rs' x) |
|
600 |
then obtain ss where rs: "rs' [\<rightarrow>\<^sub>\<beta>]\<^sub>1 ss" and r'': "r'' = Var x \<degree>\<degree> ss" |
|
601 |
by (blast dest: head_Var_reduction) |
|
602 |
from Var(1) [simplified] rs have "rs [\<rightarrow>\<^sub>s] ss" by (rule lemma4_aux) |
|
603 |
hence "Var x \<degree>\<degree> rs \<rightarrow>\<^sub>s Var x \<degree>\<degree> ss" by (rule sred.Var) |
|
604 |
with r'' show ?case by simp |
|
605 |
next |
|
606 |
case (Abs x ss ss' r r') |
|
607 |
from `(Lam [x].r') \<degree>\<degree> ss' \<rightarrow>\<^sub>\<beta> r''` show ?case |
|
608 |
proof (cases rule: apps_betasE [where x=x]) |
|
609 |
case (appL s) |
|
610 |
then obtain r''' where s: "s = (Lam [x].r''')" and r''': "r' \<rightarrow>\<^sub>\<beta> r'''" using `x \<sharp> r''` |
|
611 |
by (cases rule: beta.strong_cases) (auto simp add: abs_fresh lam.inject alpha) |
|
612 |
from r''' have "r \<rightarrow>\<^sub>s r'''" by (blast intro: Abs) |
|
613 |
moreover from Abs have "ss [\<rightarrow>\<^sub>s] ss'" by (iprover dest: listrelp_conj1) |
|
614 |
ultimately have "(Lam [x].r) \<degree>\<degree> ss \<rightarrow>\<^sub>s (Lam [x].r''') \<degree>\<degree> ss'" by (rule better_sred_Abs) |
|
615 |
with appL s show "(Lam [x].r) \<degree>\<degree> ss \<rightarrow>\<^sub>s r''" by simp |
|
616 |
next |
|
617 |
case (appR rs') |
|
618 |
from Abs(6) [simplified] `ss' [\<rightarrow>\<^sub>\<beta>]\<^sub>1 rs'` |
|
619 |
have "ss [\<rightarrow>\<^sub>s] rs'" by (rule lemma4_aux) |
|
620 |
with `r \<rightarrow>\<^sub>s r'` have "(Lam [x].r) \<degree>\<degree> ss \<rightarrow>\<^sub>s (Lam [x].r') \<degree>\<degree> rs'" by (rule better_sred_Abs) |
|
621 |
with appR show "(Lam [x].r) \<degree>\<degree> ss \<rightarrow>\<^sub>s r''" by simp |
|
622 |
next |
|
623 |
case (beta t u' us') |
|
624 |
then have Lam_eq: "(Lam [x].r') = (Lam [x].t)" and ss': "ss' = u' # us'" |
|
625 |
and r'': "r'' = t[x::=u'] \<degree>\<degree> us'" |
|
626 |
by (simp_all add: abs_fresh) |
|
627 |
from Abs(6) ss' obtain u us where |
|
628 |
ss: "ss = u # us" and u: "u \<rightarrow>\<^sub>s u'" and us: "us [\<rightarrow>\<^sub>s] us'" |
|
629 |
by cases (auto dest!: listrelp_conj1) |
|
630 |
have "r[x::=u] \<rightarrow>\<^sub>s r'[x::=u']" using `r \<rightarrow>\<^sub>s r'` and u by (rule lemma3) |
|
631 |
with us have "r[x::=u] \<degree>\<degree> us \<rightarrow>\<^sub>s r'[x::=u'] \<degree>\<degree> us'" by (rule lemma1') |
|
632 |
hence "(Lam [x].r) \<degree> u \<degree>\<degree> us \<rightarrow>\<^sub>s r'[x::=u'] \<degree>\<degree> us'" by (rule better_sred_Beta) |
|
633 |
with ss r'' Lam_eq show "(Lam [x].r) \<degree>\<degree> ss \<rightarrow>\<^sub>s r''" by (simp add: lam.inject alpha) |
|
634 |
qed |
|
635 |
next |
|
636 |
case (Beta x s ss t r) |
|
637 |
show ?case |
|
638 |
by (rule better_sred_Beta) (rule Beta)+ |
|
639 |
qed |
|
640 |
||
641 |
lemma rtrancl_beta_sred: |
|
642 |
assumes r: "r \<rightarrow>\<^sub>\<beta>\<^sup>* r'" |
|
643 |
shows "r \<rightarrow>\<^sub>s r'" using r |
|
644 |
by induct (iprover intro: refl_sred lemma4)+ |
|
645 |
||
646 |
||
647 |
subsection {* Terms in normal form *} |
|
648 |
||
649 |
lemma listsp_eqvt [eqvt]: |
|
650 |
assumes xs: "listsp p (xs::'a::pt_name list)" |
|
651 |
shows "listsp ((pi::name prm) \<bullet> p) (pi \<bullet> xs)" using xs |
|
652 |
apply induct |
|
653 |
apply simp |
|
654 |
apply simp |
|
655 |
apply (rule listsp.intros) |
|
656 |
apply (drule_tac pi=pi in perm_boolI) |
|
657 |
apply perm_simp |
|
658 |
apply assumption |
|
659 |
done |
|
660 |
||
661 |
inductive NF :: "lam \<Rightarrow> bool" |
|
662 |
where |
|
663 |
App: "listsp NF ts \<Longrightarrow> NF (Var x \<degree>\<degree> ts)" |
|
664 |
| Abs: "NF t \<Longrightarrow> NF (Lam [x].t)" |
|
665 |
||
666 |
equivariance NF |
|
667 |
nominal_inductive NF |
|
668 |
by (simp add: abs_fresh) |
|
669 |
||
670 |
lemma Abs_NF: |
|
671 |
assumes NF: "NF ((Lam [x].t) \<degree>\<degree> ts)" |
|
672 |
shows "ts = []" using NF |
|
673 |
proof cases |
|
674 |
case (App us i) |
|
675 |
thus ?thesis by (simp add: Var_apps_neq_Abs_apps [THEN not_sym]) |
|
676 |
next |
|
677 |
case (Abs u) |
|
678 |
thus ?thesis by simp |
|
679 |
qed |
|
680 |
||
681 |
text {* |
|
682 |
@{term NF} characterizes exactly the terms that are in normal form. |
|
683 |
*} |
|
684 |
||
685 |
lemma NF_eq: "NF t = (\<forall>t'. \<not> t \<rightarrow>\<^sub>\<beta> t')" |
|
686 |
proof |
|
687 |
assume H: "NF t" |
|
688 |
show "\<forall>t'. \<not> t \<rightarrow>\<^sub>\<beta> t'" |
|
689 |
proof |
|
690 |
fix t' |
|
691 |
from H show "\<not> t \<rightarrow>\<^sub>\<beta> t'" |
|
692 |
proof (nominal_induct avoiding: t' rule: NF.strong_induct) |
|
693 |
case (App ts t) |
|
694 |
show ?case |
|
695 |
proof |
|
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
29097
diff
changeset
|
696 |
assume "Var t \<degree>\<degree> ts \<rightarrow>\<^sub>\<beta> t'" |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
29097
diff
changeset
|
697 |
then obtain rs where "ts [\<rightarrow>\<^sub>\<beta>]\<^sub>1 rs" |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
29097
diff
changeset
|
698 |
by (iprover dest: head_Var_reduction) |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
29097
diff
changeset
|
699 |
with App show False |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
29097
diff
changeset
|
700 |
by (induct rs arbitrary: ts) (auto del: in_listspD) |
27623 | 701 |
qed |
702 |
next |
|
703 |
case (Abs t x) |
|
704 |
show ?case |
|
705 |
proof |
|
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
29097
diff
changeset
|
706 |
assume "(Lam [x].t) \<rightarrow>\<^sub>\<beta> t'" |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
29097
diff
changeset
|
707 |
then show False using Abs |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
29097
diff
changeset
|
708 |
by (cases rule: beta.strong_cases) (auto simp add: abs_fresh lam.inject alpha) |
27623 | 709 |
qed |
710 |
qed |
|
711 |
qed |
|
712 |
next |
|
713 |
assume H: "\<forall>t'. \<not> t \<rightarrow>\<^sub>\<beta> t'" |
|
714 |
then show "NF t" |
|
715 |
proof (nominal_induct t rule: Apps_lam_induct) |
|
716 |
case (1 n ts) |
|
717 |
then have "\<forall>ts'. \<not> ts [\<rightarrow>\<^sub>\<beta>]\<^sub>1 ts'" |
|
718 |
by (iprover intro: apps_preserves_betas) |
|
719 |
with 1(1) have "listsp NF ts" |
|
720 |
by (induct ts) (auto simp add: in_listsp_conv_set) |
|
721 |
then show ?case by (rule NF.App) |
|
722 |
next |
|
723 |
case (2 x u ts) |
|
724 |
show ?case |
|
725 |
proof (cases ts) |
|
39459 | 726 |
case Nil thus ?thesis by (metis 2 NF.Abs abs foldl_Nil) |
27623 | 727 |
next |
728 |
case (Cons r rs) |
|
729 |
have "(Lam [x].u) \<degree> r \<rightarrow>\<^sub>\<beta> u[x::=r]" .. |
|
730 |
then have "(Lam [x].u) \<degree> r \<degree>\<degree> rs \<rightarrow>\<^sub>\<beta> u[x::=r] \<degree>\<degree> rs" |
|
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
29097
diff
changeset
|
731 |
by (rule apps_preserves_beta) |
27623 | 732 |
with Cons have "(Lam [x].u) \<degree>\<degree> ts \<rightarrow>\<^sub>\<beta> u[x::=r] \<degree>\<degree> rs" |
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
29097
diff
changeset
|
733 |
by simp |
27623 | 734 |
with 2 show ?thesis by iprover |
735 |
qed |
|
736 |
qed |
|
737 |
qed |
|
738 |
||
739 |
||
740 |
subsection {* Leftmost reduction and weakly normalizing terms *} |
|
741 |
||
742 |
inductive |
|
743 |
lred :: "lam \<Rightarrow> lam \<Rightarrow> bool" (infixl "\<rightarrow>\<^sub>l" 50) |
|
744 |
and lredlist :: "lam list \<Rightarrow> lam list \<Rightarrow> bool" (infixl "[\<rightarrow>\<^sub>l]" 50) |
|
745 |
where |
|
746 |
"s [\<rightarrow>\<^sub>l] t \<equiv> listrelp op \<rightarrow>\<^sub>l s t" |
|
747 |
| Var: "rs [\<rightarrow>\<^sub>l] rs' \<Longrightarrow> Var x \<degree>\<degree> rs \<rightarrow>\<^sub>l Var x \<degree>\<degree> rs'" |
|
748 |
| Abs: "r \<rightarrow>\<^sub>l r' \<Longrightarrow> (Lam [x].r) \<rightarrow>\<^sub>l (Lam [x].r')" |
|
749 |
| Beta: "r[x::=s] \<degree>\<degree> ss \<rightarrow>\<^sub>l t \<Longrightarrow> (Lam [x].r) \<degree> s \<degree>\<degree> ss \<rightarrow>\<^sub>l t" |
|
750 |
||
751 |
lemma lred_imp_sred: |
|
752 |
assumes lred: "s \<rightarrow>\<^sub>l t" |
|
753 |
shows "s \<rightarrow>\<^sub>s t" using lred |
|
754 |
proof induct |
|
755 |
case (Var rs rs' x) |
|
756 |
then have "rs [\<rightarrow>\<^sub>s] rs'" |
|
757 |
by induct (iprover intro: listrelp.intros)+ |
|
758 |
then show ?case by (rule sred.Var) |
|
759 |
next |
|
760 |
case (Abs r r' x) |
|
761 |
from `r \<rightarrow>\<^sub>s r'` |
|
762 |
have "(Lam [x].r) \<degree>\<degree> [] \<rightarrow>\<^sub>s (Lam [x].r') \<degree>\<degree> []" using listrelp.Nil |
|
763 |
by (rule better_sred_Abs) |
|
764 |
then show ?case by simp |
|
765 |
next |
|
766 |
case (Beta r x s ss t) |
|
767 |
from `r[x::=s] \<degree>\<degree> ss \<rightarrow>\<^sub>s t` |
|
768 |
show ?case by (rule better_sred_Beta) |
|
769 |
qed |
|
770 |
||
771 |
inductive WN :: "lam \<Rightarrow> bool" |
|
772 |
where |
|
773 |
Var: "listsp WN rs \<Longrightarrow> WN (Var n \<degree>\<degree> rs)" |
|
774 |
| Lambda: "WN r \<Longrightarrow> WN (Lam [x].r)" |
|
775 |
| Beta: "WN ((r[x::=s]) \<degree>\<degree> ss) \<Longrightarrow> WN (((Lam [x].r) \<degree> s) \<degree>\<degree> ss)" |
|
776 |
||
777 |
lemma listrelp_imp_listsp1: |
|
778 |
assumes H: "listrelp (\<lambda>x y. P x) xs ys" |
|
779 |
shows "listsp P xs" using H |
|
780 |
by induct auto |
|
781 |
||
782 |
lemma listrelp_imp_listsp2: |
|
783 |
assumes H: "listrelp (\<lambda>x y. P y) xs ys" |
|
784 |
shows "listsp P ys" using H |
|
785 |
by induct auto |
|
786 |
||
787 |
lemma lemma5: |
|
788 |
assumes lred: "r \<rightarrow>\<^sub>l r'" |
|
789 |
shows "WN r" and "NF r'" using lred |
|
790 |
by induct |
|
791 |
(iprover dest: listrelp_conj1 listrelp_conj2 |
|
792 |
listrelp_imp_listsp1 listrelp_imp_listsp2 intro: WN.intros |
|
793 |
NF.intros)+ |
|
794 |
||
795 |
lemma lemma6: |
|
796 |
assumes wn: "WN r" |
|
797 |
shows "\<exists>r'. r \<rightarrow>\<^sub>l r'" using wn |
|
798 |
proof induct |
|
799 |
case (Var rs n) |
|
800 |
then have "\<exists>rs'. rs [\<rightarrow>\<^sub>l] rs'" |
|
801 |
by induct (iprover intro: listrelp.intros)+ |
|
802 |
then show ?case by (iprover intro: lred.Var) |
|
803 |
qed (iprover intro: lred.intros)+ |
|
804 |
||
805 |
lemma lemma7: |
|
806 |
assumes r: "r \<rightarrow>\<^sub>s r'" |
|
807 |
shows "NF r' \<Longrightarrow> r \<rightarrow>\<^sub>l r'" using r |
|
808 |
proof induct |
|
809 |
case (Var rs rs' x) |
|
810 |
from `NF (Var x \<degree>\<degree> rs')` have "listsp NF rs'" |
|
811 |
by cases simp_all |
|
812 |
with Var(1) have "rs [\<rightarrow>\<^sub>l] rs'" |
|
813 |
proof induct |
|
814 |
case Nil |
|
815 |
show ?case by (rule listrelp.Nil) |
|
816 |
next |
|
39459 | 817 |
case (Cons x y xs ys) |
27623 | 818 |
hence "x \<rightarrow>\<^sub>l y" and "xs [\<rightarrow>\<^sub>l] ys" by (auto del: in_listspD) |
819 |
thus ?case by (rule listrelp.Cons) |
|
820 |
qed |
|
821 |
thus ?case by (rule lred.Var) |
|
822 |
next |
|
823 |
case (Abs x ss ss' r r') |
|
824 |
from `NF ((Lam [x].r') \<degree>\<degree> ss')` |
|
825 |
have ss': "ss' = []" by (rule Abs_NF) |
|
826 |
from Abs(4) have ss: "ss = []" using ss' |
|
827 |
by cases simp_all |
|
828 |
from ss' Abs have "NF (Lam [x].r')" by simp |
|
829 |
hence "NF r'" by (cases rule: NF.strong_cases) (auto simp add: abs_fresh lam.inject alpha) |
|
830 |
with Abs have "r \<rightarrow>\<^sub>l r'" by simp |
|
831 |
hence "(Lam [x].r) \<rightarrow>\<^sub>l (Lam [x].r')" by (rule lred.Abs) |
|
832 |
with ss ss' show ?case by simp |
|
833 |
next |
|
834 |
case (Beta x s ss t r) |
|
835 |
hence "r[x::=s] \<degree>\<degree> ss \<rightarrow>\<^sub>l t" by simp |
|
836 |
thus ?case by (rule lred.Beta) |
|
837 |
qed |
|
838 |
||
839 |
lemma WN_eq: "WN t = (\<exists>t'. t \<rightarrow>\<^sub>\<beta>\<^sup>* t' \<and> NF t')" |
|
840 |
proof |
|
841 |
assume "WN t" |
|
842 |
then have "\<exists>t'. t \<rightarrow>\<^sub>l t'" by (rule lemma6) |
|
843 |
then obtain t' where t': "t \<rightarrow>\<^sub>l t'" .. |
|
844 |
then have NF: "NF t'" by (rule lemma5) |
|
845 |
from t' have "t \<rightarrow>\<^sub>s t'" by (rule lred_imp_sred) |
|
846 |
then have "t \<rightarrow>\<^sub>\<beta>\<^sup>* t'" by (rule lemma2) |
|
847 |
with NF show "\<exists>t'. t \<rightarrow>\<^sub>\<beta>\<^sup>* t' \<and> NF t'" by iprover |
|
848 |
next |
|
849 |
assume "\<exists>t'. t \<rightarrow>\<^sub>\<beta>\<^sup>* t' \<and> NF t'" |
|
850 |
then obtain t' where t': "t \<rightarrow>\<^sub>\<beta>\<^sup>* t'" and NF: "NF t'" |
|
851 |
by iprover |
|
852 |
from t' have "t \<rightarrow>\<^sub>s t'" by (rule rtrancl_beta_sred) |
|
853 |
then have "t \<rightarrow>\<^sub>l t'" using NF by (rule lemma7) |
|
854 |
then show "WN t" by (rule lemma5) |
|
855 |
qed |
|
856 |
||
857 |
end |