|
1 |
|
2 theory BitCoded2 |
|
3 imports "Lexer" |
|
4 begin |
|
5 |
|
6 section \<open>Bit-Encodings\<close> |
|
7 |
|
8 datatype bit = Z | S |
|
9 |
|
10 fun |
|
11 code :: "val \<Rightarrow> bit list" |
|
12 where |
|
13 "code Void = []" |
|
14 | "code (Char c) = []" |
|
15 | "code (Left v) = Z # (code v)" |
|
16 | "code (Right v) = S # (code v)" |
|
17 | "code (Seq v1 v2) = (code v1) @ (code v2)" |
|
18 | "code (Stars []) = [S]" |
|
19 | "code (Stars (v # vs)) = (Z # code v) @ code (Stars vs)" |
|
20 |
|
21 |
|
22 fun |
|
23 Stars_add :: "val \<Rightarrow> val \<Rightarrow> val" |
|
24 where |
|
25 "Stars_add v (Stars vs) = Stars (v # vs)" |
|
26 |
|
27 function |
|
28 decode' :: "bit list \<Rightarrow> rexp \<Rightarrow> (val * bit list)" |
|
29 where |
|
30 "decode' ds ZERO = (Void, [])" |
|
31 | "decode' ds ONE = (Void, ds)" |
|
32 | "decode' ds (CHAR d) = (Char d, ds)" |
|
33 | "decode' [] (ALT r1 r2) = (Void, [])" |
|
34 | "decode' (Z # ds) (ALT r1 r2) = (let (v, ds') = decode' ds r1 in (Left v, ds'))" |
|
35 | "decode' (S # ds) (ALT r1 r2) = (let (v, ds') = decode' ds r2 in (Right v, ds'))" |
|
36 | "decode' ds (SEQ r1 r2) = (let (v1, ds') = decode' ds r1 in |
|
37 let (v2, ds'') = decode' ds' r2 in (Seq v1 v2, ds''))" |
|
38 | "decode' [] (STAR r) = (Void, [])" |
|
39 | "decode' (S # ds) (STAR r) = (Stars [], ds)" |
|
40 | "decode' (Z # ds) (STAR r) = (let (v, ds') = decode' ds r in |
|
41 let (vs, ds'') = decode' ds' (STAR r) |
|
42 in (Stars_add v vs, ds''))" |
|
43 by pat_completeness auto |
|
44 |
|
45 lemma decode'_smaller: |
|
46 assumes "decode'_dom (ds, r)" |
|
47 shows "length (snd (decode' ds r)) \<le> length ds" |
|
48 using assms |
|
49 apply(induct ds r) |
|
50 apply(auto simp add: decode'.psimps split: prod.split) |
|
51 using dual_order.trans apply blast |
|
52 by (meson dual_order.trans le_SucI) |
|
53 |
|
54 termination "decode'" |
|
55 apply(relation "inv_image (measure(%cs. size cs) <*lex*> measure(%s. size s)) (%(ds,r). (r,ds))") |
|
56 apply(auto dest!: decode'_smaller) |
|
57 by (metis less_Suc_eq_le snd_conv) |
|
58 |
|
59 definition |
|
60 decode :: "bit list \<Rightarrow> rexp \<Rightarrow> val option" |
|
61 where |
|
62 "decode ds r \<equiv> (let (v, ds') = decode' ds r |
|
63 in (if ds' = [] then Some v else None))" |
|
64 |
|
65 lemma decode'_code_Stars: |
|
66 assumes "\<forall>v\<in>set vs. \<Turnstile> v : r \<and> (\<forall>x. decode' (code v @ x) r = (v, x)) \<and> flat v \<noteq> []" |
|
67 shows "decode' (code (Stars vs) @ ds) (STAR r) = (Stars vs, ds)" |
|
68 using assms |
|
69 apply(induct vs) |
|
70 apply(auto) |
|
71 done |
|
72 |
|
73 lemma decode'_code: |
|
74 assumes "\<Turnstile> v : r" |
|
75 shows "decode' ((code v) @ ds) r = (v, ds)" |
|
76 using assms |
|
77 apply(induct v r arbitrary: ds) |
|
78 apply(auto) |
|
79 using decode'_code_Stars by blast |
|
80 |
|
81 lemma decode_code: |
|
82 assumes "\<Turnstile> v : r" |
|
83 shows "decode (code v) r = Some v" |
|
84 using assms unfolding decode_def |
|
85 by (smt append_Nil2 decode'_code old.prod.case) |
|
86 |
|
87 |
|
88 section {* Annotated Regular Expressions *} |
|
89 |
|
90 datatype arexp = |
|
91 AZERO |
|
92 | AONE "bit list" |
|
93 | ACHAR "bit list" char |
|
94 | ASEQ "bit list" arexp arexp |
|
95 | AALTs "bit list" "arexp list" |
|
96 | ASTAR "bit list" arexp |
|
97 |
|
98 abbreviation |
|
99 "AALT bs r1 r2 \<equiv> AALTs bs [r1, r2]" |
|
100 |
|
101 fun asize :: "arexp \<Rightarrow> nat" where |
|
102 "asize AZERO = 1" |
|
103 | "asize (AONE cs) = 1" |
|
104 | "asize (ACHAR cs c) = 1" |
|
105 | "asize (AALTs cs rs) = Suc (sum_list (map asize rs))" |
|
106 | "asize (ASEQ cs r1 r2) = Suc (asize r1 + asize r2)" |
|
107 | "asize (ASTAR cs r) = Suc (asize r)" |
|
108 |
|
109 fun |
|
110 erase :: "arexp \<Rightarrow> rexp" |
|
111 where |
|
112 "erase AZERO = ZERO" |
|
113 | "erase (AONE _) = ONE" |
|
114 | "erase (ACHAR _ c) = CHAR c" |
|
115 | "erase (AALTs _ []) = ZERO" |
|
116 | "erase (AALTs _ [r]) = (erase r)" |
|
117 | "erase (AALTs bs (r#rs)) = ALT (erase r) (erase (AALTs bs rs))" |
|
118 | "erase (ASEQ _ r1 r2) = SEQ (erase r1) (erase r2)" |
|
119 | "erase (ASTAR _ r) = STAR (erase r)" |
|
120 |
|
121 lemma decode_code_erase: |
|
122 assumes "\<Turnstile> v : (erase a)" |
|
123 shows "decode (code v) (erase a) = Some v" |
|
124 using assms |
|
125 by (simp add: decode_code) |
|
126 |
|
127 |
|
128 fun nonalt :: "arexp \<Rightarrow> bool" |
|
129 where |
|
130 "nonalt (AALTs bs2 rs) = False" |
|
131 | "nonalt r = True" |
|
132 |
|
133 |
|
134 fun good :: "arexp \<Rightarrow> bool" where |
|
135 "good AZERO = False" |
|
136 | "good (AONE cs) = True" |
|
137 | "good (ACHAR cs c) = True" |
|
138 | "good (AALTs cs []) = False" |
|
139 | "good (AALTs cs [r]) = False" |
|
140 | "good (AALTs cs (r1#r2#rs)) = (\<forall>r' \<in> set (r1#r2#rs). good r' \<and> nonalt r')" |
|
141 | "good (ASEQ _ AZERO _) = False" |
|
142 | "good (ASEQ _ (AONE _) _) = False" |
|
143 | "good (ASEQ _ _ AZERO) = False" |
|
144 | "good (ASEQ cs r1 r2) = (good r1 \<and> good r2)" |
|
145 | "good (ASTAR cs r) = True" |
|
146 |
|
147 |
|
148 |
|
149 |
|
150 fun fuse :: "bit list \<Rightarrow> arexp \<Rightarrow> arexp" where |
|
151 "fuse bs AZERO = AZERO" |
|
152 | "fuse bs (AONE cs) = AONE (bs @ cs)" |
|
153 | "fuse bs (ACHAR cs c) = ACHAR (bs @ cs) c" |
|
154 | "fuse bs (AALTs cs rs) = AALTs (bs @ cs) rs" |
|
155 | "fuse bs (ASEQ cs r1 r2) = ASEQ (bs @ cs) r1 r2" |
|
156 | "fuse bs (ASTAR cs r) = ASTAR (bs @ cs) r" |
|
157 |
|
158 lemma fuse_append: |
|
159 shows "fuse (bs1 @ bs2) r = fuse bs1 (fuse bs2 r)" |
|
160 apply(induct r) |
|
161 apply(auto) |
|
162 done |
|
163 |
|
164 |
|
165 fun intern :: "rexp \<Rightarrow> arexp" where |
|
166 "intern ZERO = AZERO" |
|
167 | "intern ONE = AONE []" |
|
168 | "intern (CHAR c) = ACHAR [] c" |
|
169 | "intern (ALT r1 r2) = AALT [] (fuse [Z] (intern r1)) |
|
170 (fuse [S] (intern r2))" |
|
171 | "intern (SEQ r1 r2) = ASEQ [] (intern r1) (intern r2)" |
|
172 | "intern (STAR r) = ASTAR [] (intern r)" |
|
173 |
|
174 |
|
175 fun retrieve :: "arexp \<Rightarrow> val \<Rightarrow> bit list" where |
|
176 "retrieve (AONE bs) Void = bs" |
|
177 | "retrieve (ACHAR bs c) (Char d) = bs" |
|
178 | "retrieve (AALTs bs [r]) v = bs @ retrieve r v" |
|
179 | "retrieve (AALTs bs (r#rs)) (Left v) = bs @ retrieve r v" |
|
180 | "retrieve (AALTs bs (r#rs)) (Right v) = bs @ retrieve (AALTs [] rs) v" |
|
181 | "retrieve (ASEQ bs r1 r2) (Seq v1 v2) = bs @ retrieve r1 v1 @ retrieve r2 v2" |
|
182 | "retrieve (ASTAR bs r) (Stars []) = bs @ [S]" |
|
183 | "retrieve (ASTAR bs r) (Stars (v#vs)) = |
|
184 bs @ [Z] @ retrieve r v @ retrieve (ASTAR [] r) (Stars vs)" |
|
185 |
|
186 |
|
187 |
|
188 fun |
|
189 bnullable :: "arexp \<Rightarrow> bool" |
|
190 where |
|
191 "bnullable (AZERO) = False" |
|
192 | "bnullable (AONE bs) = True" |
|
193 | "bnullable (ACHAR bs c) = False" |
|
194 | "bnullable (AALTs bs rs) = (\<exists>r \<in> set rs. bnullable r)" |
|
195 | "bnullable (ASEQ bs r1 r2) = (bnullable r1 \<and> bnullable r2)" |
|
196 | "bnullable (ASTAR bs r) = True" |
|
197 |
|
198 fun |
|
199 bmkeps :: "arexp \<Rightarrow> bit list" |
|
200 where |
|
201 "bmkeps(AONE bs) = bs" |
|
202 | "bmkeps(ASEQ bs r1 r2) = bs @ (bmkeps r1) @ (bmkeps r2)" |
|
203 | "bmkeps(AALTs bs [r]) = bs @ (bmkeps r)" |
|
204 | "bmkeps(AALTs bs (r#rs)) = (if bnullable(r) then bs @ (bmkeps r) else (bmkeps (AALTs bs rs)))" |
|
205 | "bmkeps(ASTAR bs r) = bs @ [S]" |
|
206 |
|
207 |
|
208 fun |
|
209 bder :: "char \<Rightarrow> arexp \<Rightarrow> arexp" |
|
210 where |
|
211 "bder c (AZERO) = AZERO" |
|
212 | "bder c (AONE bs) = AZERO" |
|
213 | "bder c (ACHAR bs d) = (if c = d then AONE bs else AZERO)" |
|
214 | "bder c (AALTs bs rs) = AALTs bs (map (bder c) rs)" |
|
215 | "bder c (ASEQ bs r1 r2) = |
|
216 (if bnullable r1 |
|
217 then AALT bs (ASEQ [] (bder c r1) r2) (fuse (bmkeps r1) (bder c r2)) |
|
218 else ASEQ bs (bder c r1) r2)" |
|
219 | "bder c (ASTAR bs r) = ASEQ bs (fuse [Z] (bder c r)) (ASTAR [] r)" |
|
220 |
|
221 |
|
222 fun |
|
223 bders :: "arexp \<Rightarrow> string \<Rightarrow> arexp" |
|
224 where |
|
225 "bders r [] = r" |
|
226 | "bders r (c#s) = bders (bder c r) s" |
|
227 |
|
228 lemma bders_append: |
|
229 "bders r (s1 @ s2) = bders (bders r s1) s2" |
|
230 apply(induct s1 arbitrary: r s2) |
|
231 apply(simp_all) |
|
232 done |
|
233 |
|
234 lemma bnullable_correctness: |
|
235 shows "nullable (erase r) = bnullable r" |
|
236 apply(induct r rule: erase.induct) |
|
237 apply(simp_all) |
|
238 done |
|
239 |
|
240 lemma erase_fuse: |
|
241 shows "erase (fuse bs r) = erase r" |
|
242 apply(induct r rule: erase.induct) |
|
243 apply(simp_all) |
|
244 done |
|
245 |
|
246 lemma erase_intern [simp]: |
|
247 shows "erase (intern r) = r" |
|
248 apply(induct r) |
|
249 apply(simp_all add: erase_fuse) |
|
250 done |
|
251 |
|
252 lemma erase_bder [simp]: |
|
253 shows "erase (bder a r) = der a (erase r)" |
|
254 apply(induct r rule: erase.induct) |
|
255 apply(simp_all add: erase_fuse bnullable_correctness) |
|
256 done |
|
257 |
|
258 lemma erase_bders [simp]: |
|
259 shows "erase (bders r s) = ders s (erase r)" |
|
260 apply(induct s arbitrary: r ) |
|
261 apply(simp_all) |
|
262 done |
|
263 |
|
264 lemma retrieve_encode_STARS: |
|
265 assumes "\<forall>v\<in>set vs. \<Turnstile> v : r \<and> code v = retrieve (intern r) v" |
|
266 shows "code (Stars vs) = retrieve (ASTAR [] (intern r)) (Stars vs)" |
|
267 using assms |
|
268 apply(induct vs) |
|
269 apply(simp_all) |
|
270 done |
|
271 |
|
272 lemma retrieve_fuse2: |
|
273 assumes "\<Turnstile> v : (erase r)" |
|
274 shows "retrieve (fuse bs r) v = bs @ retrieve r v" |
|
275 using assms |
|
276 apply(induct r arbitrary: v bs) |
|
277 apply(auto elim: Prf_elims)[4] |
|
278 defer |
|
279 using retrieve_encode_STARS |
|
280 apply(auto elim!: Prf_elims)[1] |
|
281 apply(case_tac vs) |
|
282 apply(simp) |
|
283 apply(simp) |
|
284 (* AALTs case *) |
|
285 apply(simp) |
|
286 apply(case_tac x2a) |
|
287 apply(simp) |
|
288 apply(auto elim!: Prf_elims)[1] |
|
289 apply(simp) |
|
290 apply(case_tac list) |
|
291 apply(simp) |
|
292 apply(auto) |
|
293 apply(auto elim!: Prf_elims)[1] |
|
294 done |
|
295 |
|
296 lemma retrieve_fuse: |
|
297 assumes "\<Turnstile> v : r" |
|
298 shows "retrieve (fuse bs (intern r)) v = bs @ retrieve (intern r) v" |
|
299 using assms |
|
300 by (simp_all add: retrieve_fuse2) |
|
301 |
|
302 |
|
303 lemma retrieve_code: |
|
304 assumes "\<Turnstile> v : r" |
|
305 shows "code v = retrieve (intern r) v" |
|
306 using assms |
|
307 apply(induct v r ) |
|
308 apply(simp_all add: retrieve_fuse retrieve_encode_STARS) |
|
309 done |
|
310 |
|
311 lemma r: |
|
312 assumes "bnullable (AALTs bs (a # rs))" |
|
313 shows "bnullable a \<or> (\<not> bnullable a \<and> bnullable (AALTs bs rs))" |
|
314 using assms |
|
315 apply(induct rs) |
|
316 apply(auto) |
|
317 done |
|
318 |
|
319 lemma r0: |
|
320 assumes "bnullable a" |
|
321 shows "bmkeps (AALTs bs (a # rs)) = bs @ (bmkeps a)" |
|
322 using assms |
|
323 by (metis bmkeps.simps(3) bmkeps.simps(4) list.exhaust) |
|
324 |
|
325 lemma r1: |
|
326 assumes "\<not> bnullable a" "bnullable (AALTs bs rs)" |
|
327 shows "bmkeps (AALTs bs (a # rs)) = bmkeps (AALTs bs rs)" |
|
328 using assms |
|
329 apply(induct rs) |
|
330 apply(auto) |
|
331 done |
|
332 |
|
333 lemma r2: |
|
334 assumes "x \<in> set rs" "bnullable x" |
|
335 shows "bnullable (AALTs bs rs)" |
|
336 using assms |
|
337 apply(induct rs) |
|
338 apply(auto) |
|
339 done |
|
340 |
|
341 lemma r3: |
|
342 assumes "\<not> bnullable r" |
|
343 " \<exists> x \<in> set rs. bnullable x" |
|
344 shows "retrieve (AALTs bs rs) (mkeps (erase (AALTs bs rs))) = |
|
345 retrieve (AALTs bs (r # rs)) (mkeps (erase (AALTs bs (r # rs))))" |
|
346 using assms |
|
347 apply(induct rs arbitrary: r bs) |
|
348 apply(auto)[1] |
|
349 apply(auto) |
|
350 using bnullable_correctness apply blast |
|
351 apply(auto simp add: bnullable_correctness mkeps_nullable retrieve_fuse2) |
|
352 apply(subst retrieve_fuse2[symmetric]) |
|
353 apply (smt bnullable.simps(4) bnullable_correctness erase.simps(5) erase.simps(6) insert_iff list.exhaust list.set(2) mkeps.simps(3) mkeps_nullable) |
|
354 apply(simp) |
|
355 apply(case_tac "bnullable a") |
|
356 apply (smt append_Nil2 bnullable.simps(4) bnullable_correctness erase.simps(5) erase.simps(6) fuse.simps(4) insert_iff list.exhaust list.set(2) mkeps.simps(3) mkeps_nullable retrieve_fuse2) |
|
357 apply(drule_tac x="a" in meta_spec) |
|
358 apply(drule_tac x="bs" in meta_spec) |
|
359 apply(drule meta_mp) |
|
360 apply(simp) |
|
361 apply(drule meta_mp) |
|
362 apply(auto) |
|
363 apply(subst retrieve_fuse2[symmetric]) |
|
364 apply(case_tac rs) |
|
365 apply(simp) |
|
366 apply(auto)[1] |
|
367 apply (simp add: bnullable_correctness) |
|
368 apply (metis append_Nil2 bnullable_correctness erase_fuse fuse.simps(4) list.set_intros(1) mkeps.simps(3) mkeps_nullable nullable.simps(4) r2) |
|
369 apply (simp add: bnullable_correctness) |
|
370 apply (metis append_Nil2 bnullable_correctness erase.simps(6) erase_fuse fuse.simps(4) list.set_intros(2) mkeps.simps(3) mkeps_nullable r2) |
|
371 apply(simp) |
|
372 done |
|
373 |
|
374 |
|
375 lemma t: |
|
376 assumes "\<forall>r \<in> set rs. nullable (erase r) \<longrightarrow> bmkeps r = retrieve r (mkeps (erase r))" |
|
377 "nullable (erase (AALTs bs rs))" |
|
378 shows " bmkeps (AALTs bs rs) = retrieve (AALTs bs rs) (mkeps (erase (AALTs bs rs)))" |
|
379 using assms |
|
380 apply(induct rs arbitrary: bs) |
|
381 apply(simp) |
|
382 apply(auto simp add: bnullable_correctness) |
|
383 apply(case_tac rs) |
|
384 apply(auto simp add: bnullable_correctness)[2] |
|
385 apply(subst r1) |
|
386 apply(simp) |
|
387 apply(rule r2) |
|
388 apply(assumption) |
|
389 apply(simp) |
|
390 apply(drule_tac x="bs" in meta_spec) |
|
391 apply(drule meta_mp) |
|
392 apply(auto)[1] |
|
393 prefer 2 |
|
394 apply(case_tac "bnullable a") |
|
395 apply(subst r0) |
|
396 apply blast |
|
397 apply(subgoal_tac "nullable (erase a)") |
|
398 prefer 2 |
|
399 using bnullable_correctness apply blast |
|
400 apply (metis (no_types, lifting) erase.simps(5) erase.simps(6) list.exhaust mkeps.simps(3) retrieve.simps(3) retrieve.simps(4)) |
|
401 apply(subst r1) |
|
402 apply(simp) |
|
403 using r2 apply blast |
|
404 apply(drule_tac x="bs" in meta_spec) |
|
405 apply(drule meta_mp) |
|
406 apply(auto)[1] |
|
407 apply(simp) |
|
408 using r3 apply blast |
|
409 apply(auto) |
|
410 using r3 by blast |
|
411 |
|
412 lemma bmkeps_retrieve: |
|
413 assumes "nullable (erase r)" |
|
414 shows "bmkeps r = retrieve r (mkeps (erase r))" |
|
415 using assms |
|
416 apply(induct r) |
|
417 apply(simp) |
|
418 apply(simp) |
|
419 apply(simp) |
|
420 apply(simp) |
|
421 defer |
|
422 apply(simp) |
|
423 apply(rule t) |
|
424 apply(auto) |
|
425 done |
|
426 |
|
427 lemma bder_retrieve: |
|
428 assumes "\<Turnstile> v : der c (erase r)" |
|
429 shows "retrieve (bder c r) v = retrieve r (injval (erase r) c v)" |
|
430 using assms |
|
431 apply(induct r arbitrary: v rule: erase.induct) |
|
432 apply(simp) |
|
433 apply(erule Prf_elims) |
|
434 apply(simp) |
|
435 apply(erule Prf_elims) |
|
436 apply(simp) |
|
437 apply(case_tac "c = ca") |
|
438 apply(simp) |
|
439 apply(erule Prf_elims) |
|
440 apply(simp) |
|
441 apply(simp) |
|
442 apply(erule Prf_elims) |
|
443 apply(simp) |
|
444 apply(erule Prf_elims) |
|
445 apply(simp) |
|
446 apply(simp) |
|
447 apply(rename_tac "r\<^sub>1" "r\<^sub>2" rs v) |
|
448 apply(erule Prf_elims) |
|
449 apply(simp) |
|
450 apply(simp) |
|
451 apply(case_tac rs) |
|
452 apply(simp) |
|
453 apply(simp) |
|
454 apply (smt Prf_elims(3) injval.simps(2) injval.simps(3) retrieve.simps(4) retrieve.simps(5) same_append_eq) |
|
455 apply(simp) |
|
456 apply(case_tac "nullable (erase r1)") |
|
457 apply(simp) |
|
458 apply(erule Prf_elims) |
|
459 apply(subgoal_tac "bnullable r1") |
|
460 prefer 2 |
|
461 using bnullable_correctness apply blast |
|
462 apply(simp) |
|
463 apply(erule Prf_elims) |
|
464 apply(simp) |
|
465 apply(subgoal_tac "bnullable r1") |
|
466 prefer 2 |
|
467 using bnullable_correctness apply blast |
|
468 apply(simp) |
|
469 apply(simp add: retrieve_fuse2) |
|
470 apply(simp add: bmkeps_retrieve) |
|
471 apply(simp) |
|
472 apply(erule Prf_elims) |
|
473 apply(simp) |
|
474 using bnullable_correctness apply blast |
|
475 apply(rename_tac bs r v) |
|
476 apply(simp) |
|
477 apply(erule Prf_elims) |
|
478 apply(clarify) |
|
479 apply(erule Prf_elims) |
|
480 apply(clarify) |
|
481 apply(subst injval.simps) |
|
482 apply(simp del: retrieve.simps) |
|
483 apply(subst retrieve.simps) |
|
484 apply(subst retrieve.simps) |
|
485 apply(simp) |
|
486 apply(simp add: retrieve_fuse2) |
|
487 done |
|
488 |
|
489 |
|
490 |
|
491 lemma MAIN_decode: |
|
492 assumes "\<Turnstile> v : ders s r" |
|
493 shows "Some (flex r id s v) = decode (retrieve (bders (intern r) s) v) r" |
|
494 using assms |
|
495 proof (induct s arbitrary: v rule: rev_induct) |
|
496 case Nil |
|
497 have "\<Turnstile> v : ders [] r" by fact |
|
498 then have "\<Turnstile> v : r" by simp |
|
499 then have "Some v = decode (retrieve (intern r) v) r" |
|
500 using decode_code retrieve_code by auto |
|
501 then show "Some (flex r id [] v) = decode (retrieve (bders (intern r) []) v) r" |
|
502 by simp |
|
503 next |
|
504 case (snoc c s v) |
|
505 have IH: "\<And>v. \<Turnstile> v : ders s r \<Longrightarrow> |
|
506 Some (flex r id s v) = decode (retrieve (bders (intern r) s) v) r" by fact |
|
507 have asm: "\<Turnstile> v : ders (s @ [c]) r" by fact |
|
508 then have asm2: "\<Turnstile> injval (ders s r) c v : ders s r" |
|
509 by (simp add: Prf_injval ders_append) |
|
510 have "Some (flex r id (s @ [c]) v) = Some (flex r id s (injval (ders s r) c v))" |
|
511 by (simp add: flex_append) |
|
512 also have "... = decode (retrieve (bders (intern r) s) (injval (ders s r) c v)) r" |
|
513 using asm2 IH by simp |
|
514 also have "... = decode (retrieve (bder c (bders (intern r) s)) v) r" |
|
515 using asm by (simp_all add: bder_retrieve ders_append) |
|
516 finally show "Some (flex r id (s @ [c]) v) = |
|
517 decode (retrieve (bders (intern r) (s @ [c])) v) r" by (simp add: bders_append) |
|
518 qed |
|
519 |
|
520 |
|
521 definition blex where |
|
522 "blex a s \<equiv> if bnullable (bders a s) then Some (bmkeps (bders a s)) else None" |
|
523 |
|
524 |
|
525 |
|
526 definition blexer where |
|
527 "blexer r s \<equiv> if bnullable (bders (intern r) s) then |
|
528 decode (bmkeps (bders (intern r) s)) r else None" |
|
529 |
|
530 lemma blexer_correctness: |
|
531 shows "blexer r s = lexer r s" |
|
532 proof - |
|
533 { define bds where "bds \<equiv> bders (intern r) s" |
|
534 define ds where "ds \<equiv> ders s r" |
|
535 assume asm: "nullable ds" |
|
536 have era: "erase bds = ds" |
|
537 unfolding ds_def bds_def by simp |
|
538 have mke: "\<Turnstile> mkeps ds : ds" |
|
539 using asm by (simp add: mkeps_nullable) |
|
540 have "decode (bmkeps bds) r = decode (retrieve bds (mkeps ds)) r" |
|
541 using bmkeps_retrieve |
|
542 using asm era by (simp add: bmkeps_retrieve) |
|
543 also have "... = Some (flex r id s (mkeps ds))" |
|
544 using mke by (simp_all add: MAIN_decode ds_def bds_def) |
|
545 finally have "decode (bmkeps bds) r = Some (flex r id s (mkeps ds))" |
|
546 unfolding bds_def ds_def . |
|
547 } |
|
548 then show "blexer r s = lexer r s" |
|
549 unfolding blexer_def lexer_flex |
|
550 apply(subst bnullable_correctness[symmetric]) |
|
551 apply(simp) |
|
552 done |
|
553 qed |
|
554 |
|
555 lemma asize0: |
|
556 shows "0 < asize r" |
|
557 apply(induct r) |
|
558 apply(auto) |
|
559 done |
|
560 |
|
561 lemma asize_fuse: |
|
562 shows "asize (fuse bs r) = asize r" |
|
563 apply(induct r) |
|
564 apply(auto) |
|
565 done |
|
566 |
|
567 lemma bder_fuse: |
|
568 shows "bder c (fuse bs a) = fuse bs (bder c a)" |
|
569 apply(induct a arbitrary: bs c) |
|
570 apply(simp_all) |
|
571 done |
|
572 |
|
573 lemma map_bder_fuse: |
|
574 shows "map (bder c \<circ> fuse bs1) as1 = map (fuse bs1) (map (bder c) as1)" |
|
575 apply(induct as1) |
|
576 apply(auto simp add: bder_fuse) |
|
577 done |
|
578 |
|
579 |
|
580 fun nonnested :: "arexp \<Rightarrow> bool" |
|
581 where |
|
582 "nonnested (AALTs bs2 []) = True" |
|
583 | "nonnested (AALTs bs2 ((AALTs bs1 rs1) # rs2)) = False" |
|
584 | "nonnested (AALTs bs2 (r # rs2)) = nonnested (AALTs bs2 rs2)" |
|
585 | "nonnested r = True" |
|
586 |
|
587 |
|
588 |
|
589 fun distinctBy :: "'a list \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> 'b set \<Rightarrow> 'a list" |
|
590 where |
|
591 "distinctBy [] f acc = []" |
|
592 | "distinctBy (x#xs) f acc = |
|
593 (if (f x) \<in> acc then distinctBy xs f acc |
|
594 else x # (distinctBy xs f ({f x} \<union> acc)))" |
|
595 |
|
596 fun flts :: "arexp list \<Rightarrow> arexp list" |
|
597 where |
|
598 "flts [] = []" |
|
599 | "flts (AZERO # rs) = flts rs" |
|
600 | "flts ((AALTs bs rs1) # rs) = (map (fuse bs) rs1) @ flts rs" |
|
601 | "flts (r1 # rs) = r1 # flts rs" |
|
602 |
|
603 |
|
604 fun spill :: "arexp list \<Rightarrow> arexp list" |
|
605 where |
|
606 "spill [] = []" |
|
607 | "spill ((AALTs bs rs1) # rs) = (map (fuse bs) rs1) @ spill rs" |
|
608 | "spill (r1 # rs) = r1 # spill rs" |
|
609 |
|
610 lemma spill_Cons: |
|
611 shows "spill (r # rs1) = spill [r] @ spill rs1" |
|
612 apply(induct r arbitrary: rs1) |
|
613 apply(auto) |
|
614 done |
|
615 |
|
616 lemma spill_append: |
|
617 shows "spill (rs1 @ rs2) = spill rs1 @ spill rs2" |
|
618 apply(induct rs1 arbitrary: rs2) |
|
619 apply(auto) |
|
620 by (metis append.assoc spill_Cons) |
|
621 |
|
622 fun bsimp_ASEQ :: "bit list \<Rightarrow> arexp \<Rightarrow> arexp \<Rightarrow> arexp" |
|
623 where |
|
624 "bsimp_ASEQ _ AZERO _ = AZERO" |
|
625 | "bsimp_ASEQ _ _ AZERO = AZERO" |
|
626 | "bsimp_ASEQ bs1 (AONE bs2) r2 = fuse (bs1 @ bs2) r2" |
|
627 | "bsimp_ASEQ bs1 r1 r2 = ASEQ bs1 r1 r2" |
|
628 |
|
629 |
|
630 fun bsimp_AALTs :: "bit list \<Rightarrow> arexp list \<Rightarrow> arexp" |
|
631 where |
|
632 "bsimp_AALTs _ [] = AZERO" |
|
633 | "bsimp_AALTs bs1 [r] = fuse bs1 r" |
|
634 | "bsimp_AALTs bs1 rs = AALTs bs1 rs" |
|
635 |
|
636 |
|
637 fun bsimp :: "arexp \<Rightarrow> arexp" |
|
638 where |
|
639 "bsimp (ASEQ bs1 r1 r2) = bsimp_ASEQ bs1 (bsimp r1) (bsimp r2)" |
|
640 | "bsimp (AALTs bs1 rs) = bsimp_AALTs bs1 (flts (map bsimp rs))" |
|
641 | "bsimp r = r" |
|
642 |
|
643 inductive contains :: "arexp \<Rightarrow> bit list \<Rightarrow> bool" ("_ >> _" [51, 50] 50) |
|
644 where |
|
645 "AONE bs >> bs" |
|
646 | "ACHAR bs c >> bs" |
|
647 | "\<lbrakk>a1 >> bs1; a2 >> bs2\<rbrakk> \<Longrightarrow> ASEQ bs a1 a2 >> bs @ bs1 @ bs2" |
|
648 | "r >> bs1 \<Longrightarrow> AALTs bs (r#rs) >> bs @ bs1" |
|
649 | "AALTs bs rs >> bs @ bs1 \<Longrightarrow> AALTs bs (r#rs) >> bs @ bs1" |
|
650 | "ASTAR bs r >> bs @ [S]" |
|
651 | "\<lbrakk>r >> bs1; ASTAR [] r >> bs2\<rbrakk> \<Longrightarrow> ASTAR bs r >> bs @ Z # bs1 @ bs2" |
|
652 |
|
653 lemma contains0: |
|
654 assumes "a >> bs" |
|
655 shows "(fuse bs1 a) >> bs1 @ bs" |
|
656 using assms |
|
657 apply(induct arbitrary: bs1) |
|
658 apply(auto intro: contains.intros) |
|
659 apply (metis append.assoc contains.intros(3)) |
|
660 apply (metis append.assoc contains.intros(4)) |
|
661 apply (metis append.assoc contains.intros(5)) |
|
662 apply (metis append.assoc contains.intros(6)) |
|
663 apply (metis append_assoc contains.intros(7)) |
|
664 done |
|
665 |
|
666 lemma contains1: |
|
667 assumes "\<forall>v\<in>set vs. \<Turnstile> v : r \<and> intern r >> code v" |
|
668 shows "ASTAR [] (intern r) >> code (Stars vs)" |
|
669 using assms |
|
670 apply(induct vs) |
|
671 apply(simp) |
|
672 using contains.simps apply blast |
|
673 apply(simp) |
|
674 apply(subst (2) append_Nil[symmetric]) |
|
675 apply(rule contains.intros) |
|
676 apply(auto) |
|
677 done |
|
678 |
|
679 |
|
680 lemma contains2: |
|
681 assumes "\<Turnstile> v : r" |
|
682 shows "(intern r) >> code v" |
|
683 using assms |
|
684 apply(induct) |
|
685 prefer 4 |
|
686 apply(simp) |
|
687 apply(rule contains.intros) |
|
688 prefer 4 |
|
689 apply(simp) |
|
690 apply(rule contains.intros) |
|
691 apply(simp) |
|
692 apply(subst (3) append_Nil[symmetric]) |
|
693 apply(rule contains.intros) |
|
694 apply(simp) |
|
695 apply(simp) |
|
696 apply(simp) |
|
697 apply(subst (9) append_Nil[symmetric]) |
|
698 apply(rule contains.intros) |
|
699 apply (metis append_Cons append_self_conv2 contains0) |
|
700 apply(simp) |
|
701 apply(subst (9) append_Nil[symmetric]) |
|
702 apply(rule contains.intros) |
|
703 back |
|
704 apply(rule contains.intros) |
|
705 apply(drule_tac ?bs1.0="[S]" in contains0) |
|
706 apply(simp) |
|
707 apply(simp) |
|
708 apply(case_tac vs) |
|
709 apply(simp) |
|
710 apply (metis append_Nil contains.intros(6)) |
|
711 using contains1 by blast |
|
712 |
|
713 lemma qq1: |
|
714 assumes "\<exists>r \<in> set rs. bnullable r" |
|
715 shows "bmkeps (AALTs bs (rs @ rs1)) = bmkeps (AALTs bs rs)" |
|
716 using assms |
|
717 apply(induct rs arbitrary: rs1 bs) |
|
718 apply(simp) |
|
719 apply(simp) |
|
720 by (metis Nil_is_append_conv bmkeps.simps(4) neq_Nil_conv r0 split_list_last) |
|
721 |
|
722 lemma qq2: |
|
723 assumes "\<forall>r \<in> set rs. \<not> bnullable r" "\<exists>r \<in> set rs1. bnullable r" |
|
724 shows "bmkeps (AALTs bs (rs @ rs1)) = bmkeps (AALTs bs rs1)" |
|
725 using assms |
|
726 apply(induct rs arbitrary: rs1 bs) |
|
727 apply(simp) |
|
728 apply(simp) |
|
729 by (metis append_assoc in_set_conv_decomp r1 r2) |
|
730 |
|
731 lemma qq2a: |
|
732 assumes "\<not> bnullable r" "\<exists>r \<in> set rs1. bnullable r" |
|
733 shows "bmkeps (AALTs bs (r # rs1)) = bmkeps (AALTs bs rs1)" |
|
734 using assms |
|
735 by (simp add: r1) |
|
736 |
|
737 lemma qq3: |
|
738 shows "bnullable (AALTs bs rs) = (\<exists>r \<in> set rs. bnullable r)" |
|
739 apply(induct rs arbitrary: bs) |
|
740 apply(simp) |
|
741 apply(simp) |
|
742 done |
|
743 |
|
744 lemma qq4: |
|
745 assumes "bnullable (AALTs bs rs)" |
|
746 shows "bmkeps (AALTs bs rs) = bs @ bmkeps (AALTs [] rs)" |
|
747 by (metis append_Nil2 assms bmkeps_retrieve bnullable_correctness erase_fuse fuse.simps(4) mkeps_nullable retrieve_fuse2) |
|
748 |
|
749 |
|
750 lemma contains3a: |
|
751 assumes "AALTs bs lst >> bs @ bs1" |
|
752 shows "AALTs bs (a # lst) >> bs @ bs1" |
|
753 using assms |
|
754 apply - |
|
755 by (simp add: contains.intros(5)) |
|
756 |
|
757 |
|
758 lemma contains3b: |
|
759 assumes "a >> bs1" |
|
760 shows "AALTs bs (a # lst) >> bs @ bs1" |
|
761 using assms |
|
762 apply - |
|
763 apply(rule contains.intros) |
|
764 apply(simp) |
|
765 done |
|
766 |
|
767 |
|
768 lemma contains3: |
|
769 assumes "\<And>x. \<lbrakk>x \<in> set rs; bnullable x\<rbrakk> \<Longrightarrow> x >> bmkeps x" "x \<in> set rs" "bnullable x" |
|
770 shows "AALTs bs rs >> bmkeps (AALTs bs rs)" |
|
771 using assms |
|
772 apply(induct rs arbitrary: bs x) |
|
773 apply simp |
|
774 by (metis contains.intros(4) contains.intros(5) list.set_intros(1) list.set_intros(2) qq3 qq4 r r0 r1) |
|
775 |
|
776 lemma cont1: |
|
777 assumes "\<And>v. \<Turnstile> v : erase r \<Longrightarrow> r >> retrieve r v" |
|
778 "\<forall>v\<in>set vs. \<Turnstile> v : erase r \<and> flat v \<noteq> []" |
|
779 shows "ASTAR bs r >> retrieve (ASTAR bs r) (Stars vs)" |
|
780 using assms |
|
781 apply(induct vs arbitrary: bs r) |
|
782 apply(simp) |
|
783 using contains.intros(6) apply auto[1] |
|
784 by (simp add: contains.intros(7)) |
|
785 |
|
786 lemma contains4: |
|
787 assumes "bnullable a" |
|
788 shows "a >> bmkeps a" |
|
789 using assms |
|
790 apply(induct a rule: bnullable.induct) |
|
791 apply(auto intro: contains.intros) |
|
792 using contains3 by blast |
|
793 |
|
794 lemma contains5: |
|
795 assumes "\<Turnstile> v : r" |
|
796 shows "(intern r) >> retrieve (intern r) v" |
|
797 using contains2[OF assms] retrieve_code[OF assms] |
|
798 by (simp) |
|
799 |
|
800 lemma contains6: |
|
801 assumes "\<Turnstile> v : (erase r)" |
|
802 shows "r >> retrieve r v" |
|
803 using assms |
|
804 apply(induct r arbitrary: v rule: erase.induct) |
|
805 apply(auto)[1] |
|
806 using Prf_elims(1) apply blast |
|
807 using Prf_elims(4) contains.intros(1) apply force |
|
808 using Prf_elims(5) contains.intros(2) apply force |
|
809 apply(auto)[1] |
|
810 using Prf_elims(1) apply blast |
|
811 apply(auto)[1] |
|
812 using contains3b contains3a apply blast |
|
813 prefer 2 |
|
814 apply(auto)[1] |
|
815 apply (metis Prf_elims(2) contains.intros(3) retrieve.simps(6)) |
|
816 prefer 2 |
|
817 apply(auto)[1] |
|
818 apply (metis Prf_elims(6) cont1) |
|
819 apply(simp) |
|
820 apply(erule Prf_elims) |
|
821 apply(auto) |
|
822 apply (simp add: contains3b) |
|
823 using retrieve_fuse2 contains3b contains3a |
|
824 apply(subst retrieve_fuse2[symmetric]) |
|
825 apply (metis append_Nil2 erase_fuse fuse.simps(4)) |
|
826 apply(simp) |
|
827 by (metis append_Nil2 erase_fuse fuse.simps(4)) |
|
828 |
|
829 lemma contains7: |
|
830 assumes "\<Turnstile> v : der c (erase r)" |
|
831 shows "(bder c r) >> retrieve r (injval (erase r) c v)" |
|
832 using bder_retrieve[OF assms(1)] retrieve_code[OF assms(1)] |
|
833 by (metis assms contains6 erase_bder) |
|
834 |
|
835 |
|
836 fun |
|
837 bders_simp :: "arexp \<Rightarrow> string \<Rightarrow> arexp" |
|
838 where |
|
839 "bders_simp r [] = r" |
|
840 | "bders_simp r (c # s) = bders_simp (bsimp (bder c r)) s" |
|
841 |
|
842 definition blexer_simp where |
|
843 "blexer_simp r s \<equiv> if bnullable (bders_simp (intern r) s) then |
|
844 decode (bmkeps (bders_simp (intern r) s)) r else None" |
|
845 |
|
846 |
|
847 |
|
848 |
|
849 |
|
850 lemma bders_simp_append: |
|
851 shows "bders_simp r (s1 @ s2) = bders_simp (bders_simp r s1) s2" |
|
852 apply(induct s1 arbitrary: r s2) |
|
853 apply(simp) |
|
854 apply(simp) |
|
855 done |
|
856 |
|
857 lemma bsimp_ASEQ_size: |
|
858 shows "asize (bsimp_ASEQ bs r1 r2) \<le> Suc (asize r1 + asize r2)" |
|
859 apply(induct bs r1 r2 rule: bsimp_ASEQ.induct) |
|
860 apply(auto) |
|
861 done |
|
862 |
|
863 |
|
864 |
|
865 lemma flts_size: |
|
866 shows "sum_list (map asize (flts rs)) \<le> sum_list (map asize rs)" |
|
867 apply(induct rs rule: flts.induct) |
|
868 apply(simp_all) |
|
869 by (simp add: asize_fuse comp_def) |
|
870 |
|
871 |
|
872 lemma bsimp_AALTs_size: |
|
873 shows "asize (bsimp_AALTs bs rs) \<le> Suc (sum_list (map asize rs))" |
|
874 apply(induct rs rule: bsimp_AALTs.induct) |
|
875 apply(auto simp add: asize_fuse) |
|
876 done |
|
877 |
|
878 |
|
879 lemma bsimp_size: |
|
880 shows "asize (bsimp r) \<le> asize r" |
|
881 apply(induct r) |
|
882 apply(simp_all) |
|
883 apply (meson Suc_le_mono add_mono_thms_linordered_semiring(1) bsimp_ASEQ_size le_trans) |
|
884 apply(rule le_trans) |
|
885 apply(rule bsimp_AALTs_size) |
|
886 apply(simp) |
|
887 apply(rule le_trans) |
|
888 apply(rule flts_size) |
|
889 by (simp add: sum_list_mono) |
|
890 |
|
891 lemma bsimp_asize0: |
|
892 shows "(\<Sum>x\<leftarrow>rs. asize (bsimp x)) \<le> sum_list (map asize rs)" |
|
893 apply(induct rs) |
|
894 apply(auto) |
|
895 by (simp add: add_mono bsimp_size) |
|
896 |
|
897 lemma bsimp_AALTs_size2: |
|
898 assumes "\<forall>r \<in> set rs. nonalt r" |
|
899 shows "asize (bsimp_AALTs bs rs) \<ge> sum_list (map asize rs)" |
|
900 using assms |
|
901 apply(induct rs rule: bsimp_AALTs.induct) |
|
902 apply(simp_all add: asize_fuse) |
|
903 done |
|
904 |
|
905 |
|
906 lemma qq: |
|
907 shows "map (asize \<circ> fuse bs) rs = map asize rs" |
|
908 apply(induct rs) |
|
909 apply(auto simp add: asize_fuse) |
|
910 done |
|
911 |
|
912 lemma flts_size2: |
|
913 assumes "\<exists>bs rs'. AALTs bs rs' \<in> set rs" |
|
914 shows "sum_list (map asize (flts rs)) < sum_list (map asize rs)" |
|
915 using assms |
|
916 apply(induct rs) |
|
917 apply(auto simp add: qq) |
|
918 apply (simp add: flts_size less_Suc_eq_le) |
|
919 apply(case_tac a) |
|
920 apply(auto simp add: qq) |
|
921 prefer 2 |
|
922 apply (simp add: flts_size le_imp_less_Suc) |
|
923 using less_Suc_eq by auto |
|
924 |
|
925 lemma bsimp_AALTs_size3: |
|
926 assumes "\<exists>r \<in> set (map bsimp rs). \<not>nonalt r" |
|
927 shows "asize (bsimp (AALTs bs rs)) < asize (AALTs bs rs)" |
|
928 using assms flts_size2 |
|
929 apply - |
|
930 apply(clarify) |
|
931 apply(simp) |
|
932 apply(drule_tac x="map bsimp rs" in meta_spec) |
|
933 apply(drule meta_mp) |
|
934 apply (metis list.set_map nonalt.elims(3)) |
|
935 apply(simp) |
|
936 apply(rule order_class.order.strict_trans1) |
|
937 apply(rule bsimp_AALTs_size) |
|
938 apply(simp) |
|
939 by (smt Suc_leI bsimp_asize0 comp_def le_imp_less_Suc le_trans map_eq_conv not_less_eq) |
|
940 |
|
941 |
|
942 |
|
943 |
|
944 lemma L_bsimp_ASEQ: |
|
945 "L (SEQ (erase r1) (erase r2)) = L (erase (bsimp_ASEQ bs r1 r2))" |
|
946 apply(induct bs r1 r2 rule: bsimp_ASEQ.induct) |
|
947 apply(simp_all) |
|
948 by (metis erase_fuse fuse.simps(4)) |
|
949 |
|
950 lemma L_bsimp_AALTs: |
|
951 "L (erase (AALTs bs rs)) = L (erase (bsimp_AALTs bs rs))" |
|
952 apply(induct bs rs rule: bsimp_AALTs.induct) |
|
953 apply(simp_all add: erase_fuse) |
|
954 done |
|
955 |
|
956 lemma L_erase_AALTs: |
|
957 shows "L (erase (AALTs bs rs)) = \<Union> (L ` erase ` (set rs))" |
|
958 apply(induct rs) |
|
959 apply(simp) |
|
960 apply(simp) |
|
961 apply(case_tac rs) |
|
962 apply(simp) |
|
963 apply(simp) |
|
964 done |
|
965 |
|
966 lemma L_erase_flts: |
|
967 shows "\<Union> (L ` erase ` (set (flts rs))) = \<Union> (L ` erase ` (set rs))" |
|
968 apply(induct rs rule: flts.induct) |
|
969 apply(simp_all) |
|
970 apply(auto) |
|
971 using L_erase_AALTs erase_fuse apply auto[1] |
|
972 by (simp add: L_erase_AALTs erase_fuse) |
|
973 |
|
974 |
|
975 lemma L_bsimp_erase: |
|
976 shows "L (erase r) = L (erase (bsimp r))" |
|
977 apply(induct r) |
|
978 apply(simp) |
|
979 apply(simp) |
|
980 apply(simp) |
|
981 apply(auto simp add: Sequ_def)[1] |
|
982 apply(subst L_bsimp_ASEQ[symmetric]) |
|
983 apply(auto simp add: Sequ_def)[1] |
|
984 apply(subst (asm) L_bsimp_ASEQ[symmetric]) |
|
985 apply(auto simp add: Sequ_def)[1] |
|
986 apply(simp) |
|
987 apply(subst L_bsimp_AALTs[symmetric]) |
|
988 defer |
|
989 apply(simp) |
|
990 apply(subst (2)L_erase_AALTs) |
|
991 apply(subst L_erase_flts) |
|
992 apply(auto) |
|
993 apply (simp add: L_erase_AALTs) |
|
994 using L_erase_AALTs by blast |
|
995 |
|
996 lemma bsimp_ASEQ0: |
|
997 shows "bsimp_ASEQ bs r1 AZERO = AZERO" |
|
998 apply(induct r1) |
|
999 apply(auto) |
|
1000 done |
|
1001 |
|
1002 |
|
1003 |
|
1004 lemma bsimp_ASEQ1: |
|
1005 assumes "r1 \<noteq> AZERO" "r2 \<noteq> AZERO" "\<forall>bs. r1 \<noteq> AONE bs" |
|
1006 shows "bsimp_ASEQ bs r1 r2 = ASEQ bs r1 r2" |
|
1007 using assms |
|
1008 apply(induct bs r1 r2 rule: bsimp_ASEQ.induct) |
|
1009 apply(auto) |
|
1010 done |
|
1011 |
|
1012 lemma bsimp_ASEQ2: |
|
1013 shows "bsimp_ASEQ bs (AONE bs1) r2 = fuse (bs @ bs1) r2" |
|
1014 apply(induct r2) |
|
1015 apply(auto) |
|
1016 done |
|
1017 |
|
1018 |
|
1019 lemma L_bders_simp: |
|
1020 shows "L (erase (bders_simp r s)) = L (erase (bders r s))" |
|
1021 apply(induct s arbitrary: r rule: rev_induct) |
|
1022 apply(simp) |
|
1023 apply(simp) |
|
1024 apply(simp add: ders_append) |
|
1025 apply(simp add: bders_simp_append) |
|
1026 apply(simp add: L_bsimp_erase[symmetric]) |
|
1027 by (simp add: der_correctness) |
|
1028 |
|
1029 lemma b1: |
|
1030 "bsimp_ASEQ bs1 (AONE bs) r = fuse (bs1 @ bs) r" |
|
1031 apply(induct r) |
|
1032 apply(auto) |
|
1033 done |
|
1034 |
|
1035 lemma b2: |
|
1036 assumes "bnullable r" |
|
1037 shows "bmkeps (fuse bs r) = bs @ bmkeps r" |
|
1038 by (simp add: assms bmkeps_retrieve bnullable_correctness erase_fuse mkeps_nullable retrieve_fuse2) |
|
1039 |
|
1040 lemma b3: |
|
1041 shows "bnullable r = bnullable (bsimp r)" |
|
1042 using L_bsimp_erase bnullable_correctness nullable_correctness by auto |
|
1043 |
|
1044 |
|
1045 lemma b4: |
|
1046 shows "bnullable (bders_simp r s) = bnullable (bders r s)" |
|
1047 by (metis L_bders_simp bnullable_correctness lexer.simps(1) lexer_correct_None option.distinct(1)) |
|
1048 |
|
1049 lemma q1: |
|
1050 assumes "\<forall>r \<in> set rs. bmkeps(bsimp r) = bmkeps r" |
|
1051 shows "map (\<lambda>r. bmkeps(bsimp r)) rs = map bmkeps rs" |
|
1052 using assms |
|
1053 apply(induct rs) |
|
1054 apply(simp) |
|
1055 apply(simp) |
|
1056 done |
|
1057 |
|
1058 lemma q3: |
|
1059 assumes "\<exists>r \<in> set rs. bnullable r" |
|
1060 shows "bmkeps (AALTs bs rs) = bmkeps (bsimp_AALTs bs rs)" |
|
1061 using assms |
|
1062 apply(induct bs rs rule: bsimp_AALTs.induct) |
|
1063 apply(simp) |
|
1064 apply(simp) |
|
1065 apply (simp add: b2) |
|
1066 apply(simp) |
|
1067 done |
|
1068 |
|
1069 |
|
1070 lemma fuse_empty: |
|
1071 shows "fuse [] r = r" |
|
1072 apply(induct r) |
|
1073 apply(auto) |
|
1074 done |
|
1075 |
|
1076 lemma flts_fuse: |
|
1077 shows "map (fuse bs) (flts rs) = flts (map (fuse bs) rs)" |
|
1078 apply(induct rs arbitrary: bs rule: flts.induct) |
|
1079 apply(auto simp add: fuse_append) |
|
1080 done |
|
1081 |
|
1082 lemma bsimp_ASEQ_fuse: |
|
1083 shows "fuse bs1 (bsimp_ASEQ bs2 r1 r2) = bsimp_ASEQ (bs1 @ bs2) r1 r2" |
|
1084 apply(induct r1 r2 arbitrary: bs1 bs2 rule: bsimp_ASEQ.induct) |
|
1085 apply(auto) |
|
1086 done |
|
1087 |
|
1088 lemma bsimp_AALTs_fuse: |
|
1089 assumes "\<forall>r \<in> set rs. fuse bs1 (fuse bs2 r) = fuse (bs1 @ bs2) r" |
|
1090 shows "fuse bs1 (bsimp_AALTs bs2 rs) = bsimp_AALTs (bs1 @ bs2) rs" |
|
1091 using assms |
|
1092 apply(induct bs2 rs arbitrary: bs1 rule: bsimp_AALTs.induct) |
|
1093 apply(auto) |
|
1094 done |
|
1095 |
|
1096 |
|
1097 |
|
1098 lemma bsimp_fuse: |
|
1099 shows "fuse bs (bsimp r) = bsimp (fuse bs r)" |
|
1100 apply(induct r arbitrary: bs) |
|
1101 apply(simp) |
|
1102 apply(simp) |
|
1103 apply(simp) |
|
1104 prefer 3 |
|
1105 apply(simp) |
|
1106 apply(simp) |
|
1107 apply (simp add: bsimp_ASEQ_fuse) |
|
1108 apply(simp) |
|
1109 by (simp add: bsimp_AALTs_fuse fuse_append) |
|
1110 |
|
1111 lemma bsimp_fuse_AALTs: |
|
1112 shows "fuse bs (bsimp (AALTs [] rs)) = bsimp (AALTs bs rs)" |
|
1113 apply(subst bsimp_fuse) |
|
1114 apply(simp) |
|
1115 done |
|
1116 |
|
1117 lemma bsimp_fuse_AALTs2: |
|
1118 shows "fuse bs (bsimp_AALTs [] rs) = bsimp_AALTs bs rs" |
|
1119 using bsimp_AALTs_fuse fuse_append by auto |
|
1120 |
|
1121 |
|
1122 lemma bsimp_ASEQ_idem: |
|
1123 assumes "bsimp (bsimp r1) = bsimp r1" "bsimp (bsimp r2) = bsimp r2" |
|
1124 shows "bsimp (bsimp_ASEQ x1 (bsimp r1) (bsimp r2)) = bsimp_ASEQ x1 (bsimp r1) (bsimp r2)" |
|
1125 using assms |
|
1126 apply(case_tac "bsimp r1 = AZERO") |
|
1127 apply(simp) |
|
1128 apply(case_tac "bsimp r2 = AZERO") |
|
1129 apply(simp) |
|
1130 apply (metis bnullable.elims(2) bnullable.elims(3) bsimp.simps(3) bsimp_ASEQ.simps(2) bsimp_ASEQ.simps(3) bsimp_ASEQ.simps(4) bsimp_ASEQ.simps(5) bsimp_ASEQ.simps(6)) |
|
1131 apply(case_tac "\<exists>bs. bsimp r1 = AONE bs") |
|
1132 apply(auto)[1] |
|
1133 apply(subst bsimp_ASEQ2) |
|
1134 apply(subst bsimp_ASEQ2) |
|
1135 apply (metis assms(2) bsimp_fuse) |
|
1136 apply(subst bsimp_ASEQ1) |
|
1137 apply(auto) |
|
1138 done |
|
1139 |
|
1140 |
|
1141 |
|
1142 lemma k0: |
|
1143 shows "flts (r # rs1) = flts [r] @ flts rs1" |
|
1144 apply(induct r arbitrary: rs1) |
|
1145 apply(auto) |
|
1146 done |
|
1147 |
|
1148 lemma k00: |
|
1149 shows "flts (rs1 @ rs2) = flts rs1 @ flts rs2" |
|
1150 apply(induct rs1 arbitrary: rs2) |
|
1151 apply(auto) |
|
1152 by (metis append.assoc k0) |
|
1153 |
|
1154 lemma k0a: |
|
1155 shows "flts [AALTs bs rs] = map (fuse bs) rs" |
|
1156 apply(simp) |
|
1157 done |
|
1158 |
|
1159 |
|
1160 lemma k0b: |
|
1161 assumes "nonalt r" "r \<noteq> AZERO" |
|
1162 shows "flts [r] = [r]" |
|
1163 using assms |
|
1164 apply(case_tac r) |
|
1165 apply(simp_all) |
|
1166 done |
|
1167 |
|
1168 lemma nn1: |
|
1169 assumes "nonnested (AALTs bs rs)" |
|
1170 shows "\<nexists>bs1 rs1. flts rs = [AALTs bs1 rs1]" |
|
1171 using assms |
|
1172 apply(induct rs rule: flts.induct) |
|
1173 apply(auto) |
|
1174 done |
|
1175 |
|
1176 lemma nn1q: |
|
1177 assumes "nonnested (AALTs bs rs)" |
|
1178 shows "\<nexists>bs1 rs1. AALTs bs1 rs1 \<in> set (flts rs)" |
|
1179 using assms |
|
1180 apply(induct rs rule: flts.induct) |
|
1181 apply(auto) |
|
1182 done |
|
1183 |
|
1184 lemma nn1qq: |
|
1185 assumes "nonnested (AALTs bs rs)" |
|
1186 shows "\<nexists>bs1 rs1. AALTs bs1 rs1 \<in> set rs" |
|
1187 using assms |
|
1188 apply(induct rs rule: flts.induct) |
|
1189 apply(auto) |
|
1190 done |
|
1191 |
|
1192 lemma nn10: |
|
1193 assumes "nonnested (AALTs cs rs)" |
|
1194 shows "nonnested (AALTs (bs @ cs) rs)" |
|
1195 using assms |
|
1196 apply(induct rs arbitrary: cs bs) |
|
1197 apply(simp_all) |
|
1198 apply(case_tac a) |
|
1199 apply(simp_all) |
|
1200 done |
|
1201 |
|
1202 lemma nn11a: |
|
1203 assumes "nonalt r" |
|
1204 shows "nonalt (fuse bs r)" |
|
1205 using assms |
|
1206 apply(induct r) |
|
1207 apply(auto) |
|
1208 done |
|
1209 |
|
1210 |
|
1211 lemma nn1a: |
|
1212 assumes "nonnested r" |
|
1213 shows "nonnested (fuse bs r)" |
|
1214 using assms |
|
1215 apply(induct bs r arbitrary: rule: fuse.induct) |
|
1216 apply(simp_all add: nn10) |
|
1217 done |
|
1218 |
|
1219 lemma n0: |
|
1220 shows "nonnested (AALTs bs rs) \<longleftrightarrow> (\<forall>r \<in> set rs. nonalt r)" |
|
1221 apply(induct rs arbitrary: bs) |
|
1222 apply(auto) |
|
1223 apply (metis list.set_intros(1) nn1qq nonalt.elims(3)) |
|
1224 apply (metis list.set_intros(2) nn1qq nonalt.elims(3)) |
|
1225 by (metis nonalt.elims(2) nonnested.simps(3) nonnested.simps(4) nonnested.simps(5) nonnested.simps(6) nonnested.simps(7)) |
|
1226 |
|
1227 |
|
1228 |
|
1229 |
|
1230 lemma nn1c: |
|
1231 assumes "\<forall>r \<in> set rs. nonnested r" |
|
1232 shows "\<forall>r \<in> set (flts rs). nonalt r" |
|
1233 using assms |
|
1234 apply(induct rs rule: flts.induct) |
|
1235 apply(auto) |
|
1236 apply(rule nn11a) |
|
1237 by (metis nn1qq nonalt.elims(3)) |
|
1238 |
|
1239 lemma nn1bb: |
|
1240 assumes "\<forall>r \<in> set rs. nonalt r" |
|
1241 shows "nonnested (bsimp_AALTs bs rs)" |
|
1242 using assms |
|
1243 apply(induct bs rs rule: bsimp_AALTs.induct) |
|
1244 apply(auto) |
|
1245 apply (metis nn11a nonalt.simps(1) nonnested.elims(3)) |
|
1246 using n0 by auto |
|
1247 |
|
1248 lemma nn1b: |
|
1249 shows "nonnested (bsimp r)" |
|
1250 apply(induct r) |
|
1251 apply(simp_all) |
|
1252 apply(case_tac "bsimp r1 = AZERO") |
|
1253 apply(simp) |
|
1254 apply(case_tac "bsimp r2 = AZERO") |
|
1255 apply(simp) |
|
1256 apply(subst bsimp_ASEQ0) |
|
1257 apply(simp) |
|
1258 apply(case_tac "\<exists>bs. bsimp r1 = AONE bs") |
|
1259 apply(auto)[1] |
|
1260 apply(subst bsimp_ASEQ2) |
|
1261 apply (simp add: nn1a) |
|
1262 apply(subst bsimp_ASEQ1) |
|
1263 apply(auto) |
|
1264 apply(rule nn1bb) |
|
1265 apply(auto) |
|
1266 by (metis (mono_tags, hide_lams) imageE nn1c set_map) |
|
1267 |
|
1268 lemma nn1d: |
|
1269 assumes "bsimp r = AALTs bs rs" |
|
1270 shows "\<forall>r1 \<in> set rs. \<forall> bs. r1 \<noteq> AALTs bs rs2" |
|
1271 using nn1b assms |
|
1272 by (metis nn1qq) |
|
1273 |
|
1274 lemma nn_flts: |
|
1275 assumes "nonnested (AALTs bs rs)" |
|
1276 shows "\<forall>r \<in> set (flts rs). nonalt r" |
|
1277 using assms |
|
1278 apply(induct rs arbitrary: bs rule: flts.induct) |
|
1279 apply(auto) |
|
1280 done |
|
1281 |
|
1282 |
|
1283 |
|
1284 lemma rt: |
|
1285 shows "sum_list (map asize (flts (map bsimp rs))) \<le> sum_list (map asize rs)" |
|
1286 apply(induct rs) |
|
1287 apply(simp) |
|
1288 apply(simp) |
|
1289 apply(subst k0) |
|
1290 apply(simp) |
|
1291 by (smt add_le_cancel_right add_mono bsimp_size flts.simps(1) flts_size k0 le_iff_add list.simps(9) map_append sum_list.Cons sum_list.append trans_le_add1) |
|
1292 |
|
1293 lemma bsimp_AALTs_qq: |
|
1294 assumes "1 < length rs" |
|
1295 shows "bsimp_AALTs bs rs = AALTs bs rs" |
|
1296 using assms |
|
1297 apply(case_tac rs) |
|
1298 apply(simp) |
|
1299 apply(case_tac list) |
|
1300 apply(simp_all) |
|
1301 done |
|
1302 |
|
1303 |
|
1304 lemma bsimp_AALTs1: |
|
1305 assumes "nonalt r" |
|
1306 shows "bsimp_AALTs bs (flts [r]) = fuse bs r" |
|
1307 using assms |
|
1308 apply(case_tac r) |
|
1309 apply(simp_all) |
|
1310 done |
|
1311 |
|
1312 lemma bbbbs: |
|
1313 assumes "good r" "r = AALTs bs1 rs" |
|
1314 shows "bsimp_AALTs bs (flts [r]) = AALTs bs (map (fuse bs1) rs)" |
|
1315 using assms |
|
1316 by (metis (no_types, lifting) Nil_is_map_conv append.left_neutral append_butlast_last_id bsimp_AALTs.elims butlast.simps(2) good.simps(4) good.simps(5) k0a map_butlast) |
|
1317 |
|
1318 lemma bbbbs1: |
|
1319 shows "nonalt r \<or> (\<exists>bs rs. r = AALTs bs rs)" |
|
1320 using nonalt.elims(3) by auto |
|
1321 |
|
1322 |
|
1323 lemma good_fuse: |
|
1324 shows "good (fuse bs r) = good r" |
|
1325 apply(induct r arbitrary: bs) |
|
1326 apply(auto) |
|
1327 apply(case_tac r1) |
|
1328 apply(simp_all) |
|
1329 apply(case_tac r2) |
|
1330 apply(simp_all) |
|
1331 apply(case_tac r2) |
|
1332 apply(simp_all) |
|
1333 apply(case_tac r2) |
|
1334 apply(simp_all) |
|
1335 apply(case_tac r2) |
|
1336 apply(simp_all) |
|
1337 apply(case_tac r1) |
|
1338 apply(simp_all) |
|
1339 apply(case_tac r2) |
|
1340 apply(simp_all) |
|
1341 apply(case_tac r2) |
|
1342 apply(simp_all) |
|
1343 apply(case_tac r2) |
|
1344 apply(simp_all) |
|
1345 apply(case_tac r2) |
|
1346 apply(simp_all) |
|
1347 apply(case_tac x2a) |
|
1348 apply(simp_all) |
|
1349 apply(case_tac list) |
|
1350 apply(simp_all) |
|
1351 apply(case_tac x2a) |
|
1352 apply(simp_all) |
|
1353 apply(case_tac list) |
|
1354 apply(simp_all) |
|
1355 done |
|
1356 |
|
1357 lemma good0: |
|
1358 assumes "rs \<noteq> Nil" "\<forall>r \<in> set rs. nonalt r" |
|
1359 shows "good (bsimp_AALTs bs rs) \<longleftrightarrow> (\<forall>r \<in> set rs. good r)" |
|
1360 using assms |
|
1361 apply(induct bs rs rule: bsimp_AALTs.induct) |
|
1362 apply(auto simp add: good_fuse) |
|
1363 done |
|
1364 |
|
1365 lemma good0a: |
|
1366 assumes "flts (map bsimp rs) \<noteq> Nil" "\<forall>r \<in> set (flts (map bsimp rs)). nonalt r" |
|
1367 shows "good (bsimp (AALTs bs rs)) \<longleftrightarrow> (\<forall>r \<in> set (flts (map bsimp rs)). good r)" |
|
1368 using assms |
|
1369 apply(simp) |
|
1370 apply(auto) |
|
1371 apply(subst (asm) good0) |
|
1372 apply(simp) |
|
1373 apply(auto) |
|
1374 apply(subst good0) |
|
1375 apply(simp) |
|
1376 apply(auto) |
|
1377 done |
|
1378 |
|
1379 lemma flts0: |
|
1380 assumes "r \<noteq> AZERO" "nonalt r" |
|
1381 shows "flts [r] \<noteq> []" |
|
1382 using assms |
|
1383 apply(induct r) |
|
1384 apply(simp_all) |
|
1385 done |
|
1386 |
|
1387 lemma flts1: |
|
1388 assumes "good r" |
|
1389 shows "flts [r] \<noteq> []" |
|
1390 using assms |
|
1391 apply(induct r) |
|
1392 apply(simp_all) |
|
1393 apply(case_tac x2a) |
|
1394 apply(simp) |
|
1395 apply(simp) |
|
1396 done |
|
1397 |
|
1398 lemma flts2: |
|
1399 assumes "good r" |
|
1400 shows "\<forall>r' \<in> set (flts [r]). good r' \<and> nonalt r'" |
|
1401 using assms |
|
1402 apply(induct r) |
|
1403 apply(simp) |
|
1404 apply(simp) |
|
1405 apply(simp) |
|
1406 prefer 2 |
|
1407 apply(simp) |
|
1408 apply(auto)[1] |
|
1409 apply (metis bsimp_AALTs.elims good.simps(4) good.simps(5) good.simps(6) good_fuse) |
|
1410 apply (metis bsimp_AALTs.elims good.simps(4) good.simps(5) good.simps(6) nn11a) |
|
1411 apply fastforce |
|
1412 apply(simp) |
|
1413 done |
|
1414 |
|
1415 |
|
1416 lemma flts3: |
|
1417 assumes "\<forall>r \<in> set rs. good r \<or> r = AZERO" |
|
1418 shows "\<forall>r \<in> set (flts rs). good r" |
|
1419 using assms |
|
1420 apply(induct rs arbitrary: rule: flts.induct) |
|
1421 apply(simp_all) |
|
1422 by (metis UnE flts2 k0a set_map) |
|
1423 |
|
1424 lemma flts3b: |
|
1425 assumes "\<exists>r\<in>set rs. good r" |
|
1426 shows "flts rs \<noteq> []" |
|
1427 using assms |
|
1428 apply(induct rs arbitrary: rule: flts.induct) |
|
1429 apply(simp) |
|
1430 apply(simp) |
|
1431 apply(simp) |
|
1432 apply(auto) |
|
1433 done |
|
1434 |
|
1435 lemma flts4: |
|
1436 assumes "bsimp_AALTs bs (flts rs) = AZERO" |
|
1437 shows "\<forall>r \<in> set rs. \<not> good r" |
|
1438 using assms |
|
1439 apply(induct rs arbitrary: bs rule: flts.induct) |
|
1440 apply(auto) |
|
1441 defer |
|
1442 apply (metis (no_types, lifting) Nil_is_append_conv append_self_conv2 bsimp_AALTs.elims butlast.simps(2) butlast_append flts3b nonalt.simps(1) nonalt.simps(2)) |
|
1443 apply (metis arexp.distinct(7) bsimp_AALTs.elims flts2 good.simps(1) good.simps(2) good0 k0b list.distinct(1) list.inject nonalt.simps(3)) |
|
1444 apply (metis arexp.distinct(3) arexp.distinct(7) bsimp_AALTs.elims fuse.simps(3) list.distinct(1) list.inject) |
|
1445 apply (metis arexp.distinct(7) bsimp_AALTs.elims good.simps(1) good_fuse list.distinct(1) list.inject) |
|
1446 apply (metis arexp.distinct(7) bsimp_AALTs.elims list.distinct(1) list.inject) |
|
1447 apply (metis arexp.distinct(7) bsimp_AALTs.elims flts2 good.simps(1) good.simps(33) good0 k0b list.distinct(1) list.inject nonalt.simps(6)) |
|
1448 by (metis (no_types, lifting) Nil_is_append_conv append_Nil2 arexp.distinct(7) bsimp_AALTs.elims butlast.simps(2) butlast_append flts1 flts2 good.simps(1) good0 k0a) |
|
1449 |
|
1450 |
|
1451 lemma flts_nil: |
|
1452 assumes "\<forall>y. asize y < Suc (sum_list (map asize rs)) \<longrightarrow> |
|
1453 good (bsimp y) \<or> bsimp y = AZERO" |
|
1454 and "\<forall>r\<in>set rs. \<not> good (bsimp r)" |
|
1455 shows "flts (map bsimp rs) = []" |
|
1456 using assms |
|
1457 apply(induct rs) |
|
1458 apply(simp) |
|
1459 apply(simp) |
|
1460 apply(subst k0) |
|
1461 apply(simp) |
|
1462 by force |
|
1463 |
|
1464 lemma flts_nil2: |
|
1465 assumes "\<forall>y. asize y < Suc (sum_list (map asize rs)) \<longrightarrow> |
|
1466 good (bsimp y) \<or> bsimp y = AZERO" |
|
1467 and "bsimp_AALTs bs (flts (map bsimp rs)) = AZERO" |
|
1468 shows "flts (map bsimp rs) = []" |
|
1469 using assms |
|
1470 apply(induct rs arbitrary: bs) |
|
1471 apply(simp) |
|
1472 apply(simp) |
|
1473 apply(subst k0) |
|
1474 apply(simp) |
|
1475 apply(subst (asm) k0) |
|
1476 apply(auto) |
|
1477 apply (metis flts.simps(1) flts.simps(2) flts4 k0 less_add_Suc1 list.set_intros(1)) |
|
1478 by (metis flts.simps(2) flts4 k0 less_add_Suc1 list.set_intros(1)) |
|
1479 |
|
1480 |
|
1481 |
|
1482 lemma good_SEQ: |
|
1483 assumes "r1 \<noteq> AZERO" "r2 \<noteq> AZERO" "\<forall>bs. r1 \<noteq> AONE bs" |
|
1484 shows "good (ASEQ bs r1 r2) = (good r1 \<and> good r2)" |
|
1485 using assms |
|
1486 apply(case_tac r1) |
|
1487 apply(simp_all) |
|
1488 apply(case_tac r2) |
|
1489 apply(simp_all) |
|
1490 apply(case_tac r2) |
|
1491 apply(simp_all) |
|
1492 apply(case_tac r2) |
|
1493 apply(simp_all) |
|
1494 apply(case_tac r2) |
|
1495 apply(simp_all) |
|
1496 done |
|
1497 |
|
1498 lemma good1: |
|
1499 shows "good (bsimp a) \<or> bsimp a = AZERO" |
|
1500 apply(induct a taking: asize rule: measure_induct) |
|
1501 apply(case_tac x) |
|
1502 apply(simp) |
|
1503 apply(simp) |
|
1504 apply(simp) |
|
1505 prefer 3 |
|
1506 apply(simp) |
|
1507 prefer 2 |
|
1508 (* AALTs case *) |
|
1509 apply(simp only:) |
|
1510 apply(case_tac "x52") |
|
1511 apply(simp) |
|
1512 thm good0a |
|
1513 (* AALTs list at least one - case *) |
|
1514 apply(simp only: ) |
|
1515 apply(frule_tac x="a" in spec) |
|
1516 apply(drule mp) |
|
1517 apply(simp) |
|
1518 (* either first element is good, or AZERO *) |
|
1519 apply(erule disjE) |
|
1520 prefer 2 |
|
1521 apply(simp) |
|
1522 (* in the AZERO case, the size is smaller *) |
|
1523 apply(drule_tac x="AALTs x51 list" in spec) |
|
1524 apply(drule mp) |
|
1525 apply(simp add: asize0) |
|
1526 apply(subst (asm) bsimp.simps) |
|
1527 apply(subst (asm) bsimp.simps) |
|
1528 apply(assumption) |
|
1529 (* in the good case *) |
|
1530 apply(frule_tac x="AALTs x51 list" in spec) |
|
1531 apply(drule mp) |
|
1532 apply(simp add: asize0) |
|
1533 apply(erule disjE) |
|
1534 apply(rule disjI1) |
|
1535 apply(simp add: good0) |
|
1536 apply(subst good0) |
|
1537 apply (metis Nil_is_append_conv flts1 k0) |
|
1538 apply (metis ex_map_conv list.simps(9) nn1b nn1c) |
|
1539 apply(simp) |
|
1540 apply(subst k0) |
|
1541 apply(simp) |
|
1542 apply(auto)[1] |
|
1543 using flts2 apply blast |
|
1544 apply(subst (asm) good0) |
|
1545 prefer 3 |
|
1546 apply(auto)[1] |
|
1547 apply auto[1] |
|
1548 apply (metis ex_map_conv nn1b nn1c) |
|
1549 (* in the AZERO case *) |
|
1550 apply(simp) |
|
1551 apply(frule_tac x="a" in spec) |
|
1552 apply(drule mp) |
|
1553 apply(simp) |
|
1554 apply(erule disjE) |
|
1555 apply(rule disjI1) |
|
1556 apply(subst good0) |
|
1557 apply(subst k0) |
|
1558 using flts1 apply blast |
|
1559 apply(auto)[1] |
|
1560 apply (metis (no_types, hide_lams) ex_map_conv list.simps(9) nn1b nn1c) |
|
1561 apply(auto)[1] |
|
1562 apply(subst (asm) k0) |
|
1563 apply(auto)[1] |
|
1564 using flts2 apply blast |
|
1565 apply(frule_tac x="AALTs x51 list" in spec) |
|
1566 apply(drule mp) |
|
1567 apply(simp add: asize0) |
|
1568 apply(erule disjE) |
|
1569 apply(simp) |
|
1570 apply(simp) |
|
1571 apply (metis add.left_commute flts_nil2 less_add_Suc1 less_imp_Suc_add list.distinct(1) list.set_cases nat.inject) |
|
1572 apply(subst (2) k0) |
|
1573 apply(simp) |
|
1574 (* SEQ case *) |
|
1575 apply(simp) |
|
1576 apply(case_tac "bsimp x42 = AZERO") |
|
1577 apply(simp) |
|
1578 apply(case_tac "bsimp x43 = AZERO") |
|
1579 apply(simp) |
|
1580 apply(subst (2) bsimp_ASEQ0) |
|
1581 apply(simp) |
|
1582 apply(case_tac "\<exists>bs. bsimp x42 = AONE bs") |
|
1583 apply(auto)[1] |
|
1584 apply(subst bsimp_ASEQ2) |
|
1585 using good_fuse apply force |
|
1586 apply(subst bsimp_ASEQ1) |
|
1587 apply(auto) |
|
1588 apply(subst good_SEQ) |
|
1589 apply(simp) |
|
1590 apply(simp) |
|
1591 apply(simp) |
|
1592 using less_add_Suc1 less_add_Suc2 by blast |
|
1593 |
|
1594 lemma good1a: |
|
1595 assumes "L(erase a) \<noteq> {}" |
|
1596 shows "good (bsimp a)" |
|
1597 using good1 assms |
|
1598 using L_bsimp_erase by force |
|
1599 |
|
1600 |
|
1601 |
|
1602 lemma flts_append: |
|
1603 "flts (xs1 @ xs2) = flts xs1 @ flts xs2" |
|
1604 apply(induct xs1 arbitrary: xs2 rule: rev_induct) |
|
1605 apply(auto) |
|
1606 apply(case_tac xs) |
|
1607 apply(auto) |
|
1608 apply(case_tac x) |
|
1609 apply(auto) |
|
1610 apply(case_tac x) |
|
1611 apply(auto) |
|
1612 done |
|
1613 |
|
1614 lemma g1: |
|
1615 assumes "good (bsimp_AALTs bs rs)" |
|
1616 shows "bsimp_AALTs bs rs = AALTs bs rs \<or> (\<exists>r. rs = [r] \<and> bsimp_AALTs bs [r] = fuse bs r)" |
|
1617 using assms |
|
1618 apply(induct rs arbitrary: bs) |
|
1619 apply(simp) |
|
1620 apply(case_tac rs) |
|
1621 apply(simp only:) |
|
1622 apply(simp) |
|
1623 apply(case_tac list) |
|
1624 apply(simp) |
|
1625 by simp |
|
1626 |
|
1627 lemma flts_0: |
|
1628 assumes "nonnested (AALTs bs rs)" |
|
1629 shows "\<forall>r \<in> set (flts rs). r \<noteq> AZERO" |
|
1630 using assms |
|
1631 apply(induct rs arbitrary: bs rule: flts.induct) |
|
1632 apply(simp) |
|
1633 apply(simp) |
|
1634 defer |
|
1635 apply(simp) |
|
1636 apply(simp) |
|
1637 apply(simp) |
|
1638 apply(simp) |
|
1639 apply(rule ballI) |
|
1640 apply(simp) |
|
1641 done |
|
1642 |
|
1643 lemma flts_0a: |
|
1644 assumes "nonnested (AALTs bs rs)" |
|
1645 shows "AZERO \<notin> set (flts rs)" |
|
1646 using assms |
|
1647 using flts_0 by blast |
|
1648 |
|
1649 lemma qqq1: |
|
1650 shows "AZERO \<notin> set (flts (map bsimp rs))" |
|
1651 by (metis ex_map_conv flts3 good.simps(1) good1) |
|
1652 |
|
1653 |
|
1654 fun nonazero :: "arexp \<Rightarrow> bool" |
|
1655 where |
|
1656 "nonazero AZERO = False" |
|
1657 | "nonazero r = True" |
|
1658 |
|
1659 lemma flts_concat: |
|
1660 shows "flts rs = concat (map (\<lambda>r. flts [r]) rs)" |
|
1661 apply(induct rs) |
|
1662 apply(auto) |
|
1663 apply(subst k0) |
|
1664 apply(simp) |
|
1665 done |
|
1666 |
|
1667 lemma flts_single1: |
|
1668 assumes "nonalt r" "nonazero r" |
|
1669 shows "flts [r] = [r]" |
|
1670 using assms |
|
1671 apply(induct r) |
|
1672 apply(auto) |
|
1673 done |
|
1674 |
|
1675 lemma flts_qq: |
|
1676 assumes "\<forall>y. asize y < Suc (sum_list (map asize rs)) \<longrightarrow> good y \<longrightarrow> bsimp y = y" |
|
1677 "\<forall>r'\<in>set rs. good r' \<and> nonalt r'" |
|
1678 shows "flts (map bsimp rs) = rs" |
|
1679 using assms |
|
1680 apply(induct rs) |
|
1681 apply(simp) |
|
1682 apply(simp) |
|
1683 apply(subst k0) |
|
1684 apply(subgoal_tac "flts [bsimp a] = [a]") |
|
1685 prefer 2 |
|
1686 apply(drule_tac x="a" in spec) |
|
1687 apply(drule mp) |
|
1688 apply(simp) |
|
1689 apply(auto)[1] |
|
1690 using good.simps(1) k0b apply blast |
|
1691 apply(auto)[1] |
|
1692 done |
|
1693 |
|
1694 lemma test: |
|
1695 assumes "good r" |
|
1696 shows "bsimp r = r" |
|
1697 using assms |
|
1698 apply(induct r taking: "asize" rule: measure_induct) |
|
1699 apply(erule good.elims) |
|
1700 apply(simp_all) |
|
1701 apply(subst k0) |
|
1702 apply(subst (2) k0) |
|
1703 apply(subst flts_qq) |
|
1704 apply(auto)[1] |
|
1705 apply(auto)[1] |
|
1706 apply (metis append_Cons append_Nil bsimp_AALTs.simps(3) good.simps(1) k0b) |
|
1707 apply force+ |
|
1708 apply (metis (no_types, lifting) add_Suc add_Suc_right asize.simps(5) bsimp.simps(1) bsimp_ASEQ.simps(19) less_add_Suc1 less_add_Suc2) |
|
1709 apply (metis add_Suc add_Suc_right arexp.distinct(5) arexp.distinct(7) asize.simps(4) asize.simps(5) bsimp.simps(1) bsimp.simps(2) bsimp_ASEQ1 good.simps(21) good.simps(8) less_add_Suc1 less_add_Suc2) |
|
1710 apply force+ |
|
1711 apply (metis (no_types, lifting) add_Suc add_Suc_right arexp.distinct(5) arexp.distinct(7) asize.simps(4) asize.simps(5) bsimp.simps(1) bsimp.simps(2) bsimp_ASEQ1 good.simps(25) good.simps(8) less_add_Suc1 less_add_Suc2) |
|
1712 apply (metis add_Suc add_Suc_right arexp.distinct(7) asize.simps(4) bsimp.simps(2) bsimp_ASEQ1 good.simps(26) good.simps(8) less_add_Suc1 less_add_Suc2) |
|
1713 apply force+ |
|
1714 done |
|
1715 |
|
1716 lemma test2: |
|
1717 assumes "good r" |
|
1718 shows "bsimp r = r" |
|
1719 using assms |
|
1720 apply(induct r taking: "asize" rule: measure_induct) |
|
1721 apply(case_tac x) |
|
1722 apply(simp_all) |
|
1723 defer |
|
1724 (* AALT case *) |
|
1725 apply(subgoal_tac "1 < length x52") |
|
1726 prefer 2 |
|
1727 apply(case_tac x52) |
|
1728 apply(simp) |
|
1729 apply(simp) |
|
1730 apply(case_tac list) |
|
1731 apply(simp) |
|
1732 apply(simp) |
|
1733 apply(subst bsimp_AALTs_qq) |
|
1734 prefer 2 |
|
1735 apply(subst flts_qq) |
|
1736 apply(auto)[1] |
|
1737 apply(auto)[1] |
|
1738 apply(case_tac x52) |
|
1739 apply(simp) |
|
1740 apply(simp) |
|
1741 apply(case_tac list) |
|
1742 apply(simp) |
|
1743 apply(simp) |
|
1744 apply(auto)[1] |
|
1745 apply (metis (no_types, lifting) bsimp_AALTs.elims good.simps(6) length_Cons length_pos_if_in_set list.size(3) nat_neq_iff) |
|
1746 apply(simp) |
|
1747 apply(case_tac x52) |
|
1748 apply(simp) |
|
1749 apply(simp) |
|
1750 apply(case_tac list) |
|
1751 apply(simp) |
|
1752 apply(simp) |
|
1753 apply(subst k0) |
|
1754 apply(simp) |
|
1755 apply(subst (2) k0) |
|
1756 apply(simp) |
|
1757 apply (simp add: Suc_lessI flts1 one_is_add) |
|
1758 (* SEQ case *) |
|
1759 apply(case_tac "bsimp x42 = AZERO") |
|
1760 apply simp |
|
1761 apply (metis asize.elims good.simps(10) good.simps(11) good.simps(12) good.simps(2) good.simps(7) good.simps(9) good_SEQ less_add_Suc1) |
|
1762 apply(case_tac "\<exists>bs'. bsimp x42 = AONE bs'") |
|
1763 apply(auto)[1] |
|
1764 defer |
|
1765 apply(case_tac "bsimp x43 = AZERO") |
|
1766 apply(simp) |
|
1767 apply (metis bsimp.elims bsimp.simps(3) good.simps(10) good.simps(11) good.simps(12) good.simps(8) good.simps(9) good_SEQ less_add_Suc2) |
|
1768 apply(auto) |
|
1769 apply (subst bsimp_ASEQ1) |
|
1770 apply(auto)[3] |
|
1771 apply(auto)[1] |
|
1772 apply (metis bsimp.simps(3) good.simps(2) good_SEQ less_add_Suc1) |
|
1773 apply (metis bsimp.simps(3) good.simps(2) good_SEQ less_add_Suc1 less_add_Suc2) |
|
1774 apply (subst bsimp_ASEQ2) |
|
1775 apply(drule_tac x="x42" in spec) |
|
1776 apply(drule mp) |
|
1777 apply(simp) |
|
1778 apply(drule mp) |
|
1779 apply (metis bsimp.elims bsimp.simps(3) good.simps(10) good.simps(11) good.simps(2) good_SEQ) |
|
1780 apply(simp) |
|
1781 done |
|
1782 |
|
1783 |
|
1784 lemma bsimp_idem: |
|
1785 shows "bsimp (bsimp r) = bsimp r" |
|
1786 using test good1 |
|
1787 by force |
|
1788 |
|
1789 |
|
1790 lemma contains_ex1: |
|
1791 assumes "a = AALTs bs1 [AZERO, AONE bs2]" "a >> bs" |
|
1792 shows "bsimp a >> bs" |
|
1793 using assms |
|
1794 apply(simp) |
|
1795 apply(erule contains.cases) |
|
1796 apply(auto) |
|
1797 using contains.simps apply blast |
|
1798 apply(erule contains.cases) |
|
1799 apply(auto) |
|
1800 using contains0 apply fastforce |
|
1801 using contains.simps by blast |
|
1802 |
|
1803 lemma contains_ex2: |
|
1804 assumes "a = AALTs bs1 [AZERO, AONE bs2, AALTs bs5 [AONE bs3, AZERO, AONE bs4]]" "a >> bs" |
|
1805 shows "bsimp a >> bs" |
|
1806 using assms |
|
1807 apply(simp) |
|
1808 apply(erule contains.cases) |
|
1809 apply(auto) |
|
1810 using contains.simps apply blast |
|
1811 apply(erule contains.cases) |
|
1812 apply(auto) |
|
1813 using contains3b apply blast |
|
1814 apply(erule contains.cases) |
|
1815 apply(auto) |
|
1816 apply(erule contains.cases) |
|
1817 apply(auto) |
|
1818 apply (metis append.left_neutral contains.intros(4) contains.intros(5) contains0 fuse.simps(2)) |
|
1819 apply(erule contains.cases) |
|
1820 apply(auto) |
|
1821 using contains.simps apply blast |
|
1822 apply(erule contains.cases) |
|
1823 apply(auto) |
|
1824 apply (metis append.left_neutral contains.intros(4) contains.intros(5) contains0 fuse.simps(2)) |
|
1825 apply(erule contains.cases) |
|
1826 apply(auto) |
|
1827 apply(erule contains.cases) |
|
1828 apply(auto) |
|
1829 done |
|
1830 |
|
1831 lemma contains48: |
|
1832 assumes "\<And>x2aa bs bs1. \<lbrakk>x2aa \<in> set x2a; fuse bs x2aa >> bs @ bs1\<rbrakk> \<Longrightarrow> x2aa >> bs1" |
|
1833 "AALTs (bs @ x1) x2a >> bs @ bs1" |
|
1834 shows "AALTs x1 x2a >> bs1" |
|
1835 using assms |
|
1836 apply(induct x2a arbitrary: bs x1 bs1) |
|
1837 apply(auto) |
|
1838 apply(erule contains.cases) |
|
1839 apply(auto) |
|
1840 apply(erule contains.cases) |
|
1841 apply(auto) |
|
1842 apply (simp add: contains.intros(4)) |
|
1843 using contains.intros(5) by blast |
|
1844 |
|
1845 |
|
1846 lemma contains49: |
|
1847 assumes "fuse bs a >> bs @ bs1" |
|
1848 shows "a >> bs1" |
|
1849 using assms |
|
1850 apply(induct a arbitrary: bs bs1) |
|
1851 apply(auto) |
|
1852 using contains.simps apply blast |
|
1853 apply(erule contains.cases) |
|
1854 apply(auto) |
|
1855 apply(rule contains.intros) |
|
1856 apply(erule contains.cases) |
|
1857 apply(auto) |
|
1858 apply(rule contains.intros) |
|
1859 apply(erule contains.cases) |
|
1860 apply(auto) |
|
1861 apply(rule contains.intros) |
|
1862 apply(auto)[2] |
|
1863 prefer 2 |
|
1864 apply(erule contains.cases) |
|
1865 apply(auto) |
|
1866 apply (simp add: contains.intros(6)) |
|
1867 using contains.intros(7) apply blast |
|
1868 using contains48 by blast |
|
1869 |
|
1870 lemma contains50: |
|
1871 assumes "bsimp_AALTs bs rs2 >> bs @ bs1" |
|
1872 shows "bsimp_AALTs bs (rs1 @ rs2) >> bs @ bs1" |
|
1873 using assms |
|
1874 apply(induct rs1 arbitrary: bs rs2 bs1) |
|
1875 apply(simp) |
|
1876 apply(auto) |
|
1877 apply(case_tac rs1) |
|
1878 apply(simp) |
|
1879 apply(case_tac rs2) |
|
1880 apply(simp) |
|
1881 using contains.simps apply blast |
|
1882 apply(simp) |
|
1883 apply(case_tac list) |
|
1884 apply(simp) |
|
1885 apply(rule contains.intros) |
|
1886 back |
|
1887 apply(rule contains.intros) |
|
1888 using contains49 apply blast |
|
1889 apply(simp) |
|
1890 using contains.intros(5) apply blast |
|
1891 apply(simp) |
|
1892 by (metis bsimp_AALTs.elims contains.intros(4) contains.intros(5) contains49 list.distinct(1)) |
|
1893 |
|
1894 lemma contains51: |
|
1895 assumes "bsimp_AALTs bs [r] >> bs @ bs1" |
|
1896 shows "bsimp_AALTs bs ([r] @ rs2) >> bs @ bs1" |
|
1897 using assms |
|
1898 apply(induct rs2 arbitrary: bs r bs1) |
|
1899 apply(simp) |
|
1900 apply(auto) |
|
1901 using contains.intros(4) contains49 by blast |
|
1902 |
|
1903 lemma contains51a: |
|
1904 assumes "bsimp_AALTs bs rs2 >> bs @ bs1" |
|
1905 shows "bsimp_AALTs bs (rs2 @ [r]) >> bs @ bs1" |
|
1906 using assms |
|
1907 apply(induct rs2 arbitrary: bs r bs1) |
|
1908 apply(simp) |
|
1909 apply(auto) |
|
1910 using contains.simps apply blast |
|
1911 apply(case_tac rs2) |
|
1912 apply(auto) |
|
1913 using contains3b contains49 apply blast |
|
1914 apply(case_tac list) |
|
1915 apply(auto) |
|
1916 apply(erule contains.cases) |
|
1917 apply(auto) |
|
1918 using contains.intros(4) apply auto[1] |
|
1919 apply(erule contains.cases) |
|
1920 apply(auto) |
|
1921 apply (simp add: contains.intros(4) contains.intros(5)) |
|
1922 apply (simp add: contains.intros(5)) |
|
1923 apply(erule contains.cases) |
|
1924 apply(auto) |
|
1925 apply (simp add: contains.intros(4)) |
|
1926 apply(erule contains.cases) |
|
1927 apply(auto) |
|
1928 using contains.intros(4) contains.intros(5) apply blast |
|
1929 using contains.intros(5) by blast |
|
1930 |
|
1931 lemma contains51b: |
|
1932 assumes "bsimp_AALTs bs rs >> bs @ bs1" |
|
1933 shows "bsimp_AALTs bs (rs @ rs2) >> bs @ bs1" |
|
1934 using assms |
|
1935 apply(induct rs2 arbitrary: bs rs bs1) |
|
1936 apply(simp) |
|
1937 using contains51a by fastforce |
|
1938 |
|
1939 |
|
1940 lemma contains51c: |
|
1941 assumes "AALTs (bs @ bs2) rs >> bs @ bs1" |
|
1942 shows "bsimp_AALTs bs (map (fuse bs2) rs) >> bs @ bs1" |
|
1943 using assms |
|
1944 apply(induct rs arbitrary: bs bs1 bs2) |
|
1945 apply(auto) |
|
1946 apply(erule contains.cases) |
|
1947 apply(auto) |
|
1948 apply(erule contains.cases) |
|
1949 apply(auto) |
|
1950 using contains0 contains51 apply auto[1] |
|
1951 by (metis append.left_neutral append_Cons contains50 list.simps(9)) |
|
1952 |
|
1953 |
|
1954 lemma contains51d: |
|
1955 assumes "fuse bs r >> bs @ bs1" |
|
1956 shows "bsimp_AALTs bs (flts [r]) >> bs @ bs1" |
|
1957 using assms |
|
1958 apply(induct r arbitrary: bs bs1) |
|
1959 apply(auto) |
|
1960 by (simp add: contains51c) |
|
1961 |
|
1962 lemma contains52: |
|
1963 assumes "\<exists>r \<in> set rs. (fuse bs r) >> bs @ bs1" |
|
1964 shows "bsimp_AALTs bs (flts rs) >> bs @ bs1" |
|
1965 using assms |
|
1966 apply(induct rs arbitrary: bs bs1) |
|
1967 apply(simp) |
|
1968 apply(auto) |
|
1969 defer |
|
1970 apply (metis contains50 k0) |
|
1971 apply(subst k0) |
|
1972 apply(rule contains51b) |
|
1973 using contains51d by blast |
|
1974 |
|
1975 lemma contains55: |
|
1976 assumes "a >> bs" |
|
1977 shows "bsimp a >> bs" |
|
1978 using assms |
|
1979 apply(induct a bs arbitrary:) |
|
1980 apply(auto intro: contains.intros) |
|
1981 apply(case_tac "bsimp a1 = AZERO") |
|
1982 apply(simp) |
|
1983 using contains.simps apply blast |
|
1984 apply(case_tac "bsimp a2 = AZERO") |
|
1985 apply(simp) |
|
1986 using contains.simps apply blast |
|
1987 apply(case_tac "\<exists>bs. bsimp a1 = AONE bs") |
|
1988 apply(auto)[1] |
|
1989 apply(rotate_tac 1) |
|
1990 apply(erule contains.cases) |
|
1991 apply(auto) |
|
1992 apply (simp add: b1 contains0 fuse_append) |
|
1993 apply (simp add: bsimp_ASEQ1 contains.intros(3)) |
|
1994 prefer 2 |
|
1995 apply(case_tac rs) |
|
1996 apply(simp) |
|
1997 using contains.simps apply blast |
|
1998 apply (metis contains50 k0) |
|
1999 (* AALTS case *) |
|
2000 apply(rule contains52) |
|
2001 apply(rule_tac x="bsimp r" in bexI) |
|
2002 apply(auto) |
|
2003 using contains0 by blast |
|
2004 |
|
2005 |
|
2006 lemma q3a: |
|
2007 assumes "\<exists>r \<in> set rs. bnullable r" |
|
2008 shows "bmkeps (AALTs bs (map (fuse bs1) rs)) = bmkeps (AALTs (bs@bs1) rs)" |
|
2009 using assms |
|
2010 apply(induct rs arbitrary: bs bs1) |
|
2011 apply(simp) |
|
2012 apply(simp) |
|
2013 apply(auto) |
|
2014 apply (metis append_assoc b2 bnullable_correctness erase_fuse r0) |
|
2015 apply(case_tac "bnullable a") |
|
2016 apply (metis append.assoc b2 bnullable_correctness erase_fuse r0) |
|
2017 apply(case_tac rs) |
|
2018 apply(simp) |
|
2019 apply(simp) |
|
2020 apply(auto)[1] |
|
2021 apply (metis bnullable_correctness erase_fuse)+ |
|
2022 done |
|
2023 |
|
2024 lemma qq4: |
|
2025 assumes "\<exists>x\<in>set list. bnullable x" |
|
2026 shows "\<exists>x\<in>set (flts list). bnullable x" |
|
2027 using assms |
|
2028 apply(induct list rule: flts.induct) |
|
2029 apply(auto) |
|
2030 by (metis UnCI bnullable_correctness erase_fuse imageI) |
|
2031 |
|
2032 |
|
2033 lemma qs3: |
|
2034 assumes "\<exists>r \<in> set rs. bnullable r" |
|
2035 shows "bmkeps (AALTs bs rs) = bmkeps (AALTs bs (flts rs))" |
|
2036 using assms |
|
2037 apply(induct rs arbitrary: bs taking: size rule: measure_induct) |
|
2038 apply(case_tac x) |
|
2039 apply(simp) |
|
2040 apply(simp) |
|
2041 apply(case_tac a) |
|
2042 apply(simp) |
|
2043 apply (simp add: r1) |
|
2044 apply(simp) |
|
2045 apply (simp add: r0) |
|
2046 apply(simp) |
|
2047 apply(case_tac "flts list") |
|
2048 apply(simp) |
|
2049 apply (metis L_erase_AALTs L_erase_flts L_flat_Prf1 L_flat_Prf2 Prf_elims(1) bnullable_correctness erase.simps(4) mkeps_nullable r2) |
|
2050 apply(simp) |
|
2051 apply (simp add: r1) |
|
2052 prefer 3 |
|
2053 apply(simp) |
|
2054 apply (simp add: r0) |
|
2055 prefer 2 |
|
2056 apply(simp) |
|
2057 apply(case_tac "\<exists>x\<in>set x52. bnullable x") |
|
2058 apply(case_tac "list") |
|
2059 apply(simp) |
|
2060 apply (metis b2 fuse.simps(4) q3a r2) |
|
2061 apply(erule disjE) |
|
2062 apply(subst qq1) |
|
2063 apply(auto)[1] |
|
2064 apply (metis bnullable_correctness erase_fuse) |
|
2065 apply(simp) |
|
2066 apply (metis b2 fuse.simps(4) q3a r2) |
|
2067 apply(simp) |
|
2068 apply(auto)[1] |
|
2069 apply(subst qq1) |
|
2070 apply (metis bnullable_correctness erase_fuse image_eqI set_map) |
|
2071 apply (metis b2 fuse.simps(4) q3a r2) |
|
2072 apply(subst qq1) |
|
2073 apply (metis bnullable_correctness erase_fuse image_eqI set_map) |
|
2074 apply (metis b2 fuse.simps(4) q3a r2) |
|
2075 apply(simp) |
|
2076 apply(subst qq2) |
|
2077 apply (metis bnullable_correctness erase_fuse imageE set_map) |
|
2078 prefer 2 |
|
2079 apply(case_tac "list") |
|
2080 apply(simp) |
|
2081 apply(simp) |
|
2082 apply (simp add: qq4) |
|
2083 apply(simp) |
|
2084 apply(auto) |
|
2085 apply(case_tac list) |
|
2086 apply(simp) |
|
2087 apply(simp) |
|
2088 apply (simp add: r0) |
|
2089 apply(case_tac "bnullable (ASEQ x41 x42 x43)") |
|
2090 apply(case_tac list) |
|
2091 apply(simp) |
|
2092 apply(simp) |
|
2093 apply (simp add: r0) |
|
2094 apply(simp) |
|
2095 using qq4 r1 r2 by auto |
|
2096 |
|
2097 |
|
2098 |
|
2099 lemma k1: |
|
2100 assumes "\<And>x2aa. \<lbrakk>x2aa \<in> set x2a; bnullable x2aa\<rbrakk> \<Longrightarrow> bmkeps x2aa = bmkeps (bsimp x2aa)" |
|
2101 "\<exists>x\<in>set x2a. bnullable x" |
|
2102 shows "bmkeps (AALTs x1 (flts x2a)) = bmkeps (AALTs x1 (flts (map bsimp x2a)))" |
|
2103 using assms |
|
2104 apply(induct x2a) |
|
2105 apply fastforce |
|
2106 apply(simp) |
|
2107 apply(subst k0) |
|
2108 apply(subst (2) k0) |
|
2109 apply(auto)[1] |
|
2110 apply (metis b3 k0 list.set_intros(1) qs3 r0) |
|
2111 by (smt b3 imageI insert_iff k0 list.set(2) qq3 qs3 r0 r1 set_map) |
|
2112 |
|
2113 |
|
2114 |
|
2115 lemma bmkeps_simp: |
|
2116 assumes "bnullable r" |
|
2117 shows "bmkeps r = bmkeps (bsimp r)" |
|
2118 using assms |
|
2119 apply(induct r) |
|
2120 apply(simp) |
|
2121 apply(simp) |
|
2122 apply(simp) |
|
2123 apply(simp) |
|
2124 prefer 3 |
|
2125 apply(simp) |
|
2126 apply(case_tac "bsimp r1 = AZERO") |
|
2127 apply(simp) |
|
2128 apply(auto)[1] |
|
2129 apply (metis L_bsimp_erase L_flat_Prf1 L_flat_Prf2 Prf_elims(1) bnullable_correctness erase.simps(1) mkeps_nullable) |
|
2130 apply(case_tac "bsimp r2 = AZERO") |
|
2131 apply(simp) |
|
2132 apply(auto)[1] |
|
2133 apply (metis L_bsimp_erase L_flat_Prf1 L_flat_Prf2 Prf_elims(1) bnullable_correctness erase.simps(1) mkeps_nullable) |
|
2134 apply(case_tac "\<exists>bs. bsimp r1 = AONE bs") |
|
2135 apply(auto)[1] |
|
2136 apply(subst b1) |
|
2137 apply(subst b2) |
|
2138 apply(simp add: b3[symmetric]) |
|
2139 apply(simp) |
|
2140 apply(subgoal_tac "bsimp_ASEQ x1 (bsimp r1) (bsimp r2) = ASEQ x1 (bsimp r1) (bsimp r2)") |
|
2141 prefer 2 |
|
2142 apply (smt b3 bnullable.elims(2) bsimp_ASEQ.simps(17) bsimp_ASEQ.simps(19) bsimp_ASEQ.simps(20) bsimp_ASEQ.simps(21) bsimp_ASEQ.simps(22) bsimp_ASEQ.simps(24) bsimp_ASEQ.simps(25) bsimp_ASEQ.simps(26) bsimp_ASEQ.simps(27) bsimp_ASEQ.simps(29) bsimp_ASEQ.simps(30) bsimp_ASEQ.simps(31)) |
|
2143 apply(simp) |
|
2144 apply(simp) |
|
2145 thm q3 |
|
2146 apply(subst q3[symmetric]) |
|
2147 apply simp |
|
2148 using b3 qq4 apply auto[1] |
|
2149 apply(subst qs3) |
|
2150 apply simp |
|
2151 using k1 by blast |
|
2152 |
|
2153 thm bmkeps_retrieve bmkeps_simp bder_retrieve |
|
2154 |
|
2155 lemma bmkeps_bder_AALTs: |
|
2156 assumes "\<exists>r \<in> set rs. bnullable (bder c r)" |
|
2157 shows "bmkeps (bder c (bsimp_AALTs bs rs)) = bmkeps (bsimp_AALTs bs (map (bder c) rs))" |
|
2158 using assms |
|
2159 apply(induct rs) |
|
2160 apply(simp) |
|
2161 apply(simp) |
|
2162 apply(auto) |
|
2163 apply(case_tac rs) |
|
2164 apply(simp) |
|
2165 apply (metis (full_types) Prf_injval bder_retrieve bmkeps_retrieve bnullable_correctness erase_bder erase_fuse mkeps_nullable retrieve_fuse2) |
|
2166 apply(simp) |
|
2167 apply(case_tac rs) |
|
2168 apply(simp_all) |
|
2169 done |
|
2170 |
|
2171 lemma bbs0: |
|
2172 shows "blexer_simp r [] = blexer r []" |
|
2173 apply(simp add: blexer_def blexer_simp_def) |
|
2174 done |
|
2175 |
|
2176 lemma bbs1: |
|
2177 shows "blexer_simp r [c] = blexer r [c]" |
|
2178 apply(simp add: blexer_def blexer_simp_def) |
|
2179 apply(auto) |
|
2180 defer |
|
2181 using b3 apply auto[1] |
|
2182 using b3 apply auto[1] |
|
2183 apply(subst bmkeps_simp[symmetric]) |
|
2184 apply(simp) |
|
2185 apply(simp) |
|
2186 done |
|
2187 |
|
2188 lemma oo: |
|
2189 shows "(case (blexer (der c r) s) of None \<Rightarrow> None | Some v \<Rightarrow> Some (injval r c v)) = blexer r (c # s)" |
|
2190 apply(simp add: blexer_correctness) |
|
2191 done |
|
2192 |
|
2193 |
|
2194 |
|
2195 |
|
2196 |
|
2197 fun flts2 :: "char \<Rightarrow> arexp list \<Rightarrow> arexp list" |
|
2198 where |
|
2199 "flts2 _ [] = []" |
|
2200 | "flts2 c (AZERO # rs) = flts2 c rs" |
|
2201 | "flts2 c (AONE _ # rs) = flts2 c rs" |
|
2202 | "flts2 c (ACHAR bs d # rs) = (if c = d then (ACHAR bs d # flts2 c rs) else flts2 c rs)" |
|
2203 | "flts2 c ((AALTs bs rs1) # rs) = (map (fuse bs) rs1) @ flts2 c rs" |
|
2204 | "flts2 c (ASEQ bs r1 r2 # rs) = (if (bnullable(r1) \<and> r2 = AZERO) then |
|
2205 flts2 c rs |
|
2206 else ASEQ bs r1 r2 # flts2 c rs)" |
|
2207 | "flts2 c (r1 # rs) = r1 # flts2 c rs" |
|
2208 |
|
2209 lemma flts2_k0: |
|
2210 shows "flts2 c (r # rs1) = flts2 c [r] @ flts2 c rs1" |
|
2211 apply(induct r arbitrary: c rs1) |
|
2212 apply(auto) |
|
2213 done |
|
2214 |
|
2215 lemma flts2_k00: |
|
2216 shows "flts2 c (rs1 @ rs2) = flts2 c rs1 @ flts2 c rs2" |
|
2217 apply(induct rs1 arbitrary: rs2 c) |
|
2218 apply(auto) |
|
2219 by (metis append.assoc flts2_k0) |
|
2220 |
|
2221 |
|
2222 lemma |
|
2223 shows "flts (map (bder c) rs) = (map (bder c) (flts2 c rs))" |
|
2224 apply(induct c rs rule: flts2.induct) |
|
2225 apply(simp) |
|
2226 apply(simp) |
|
2227 apply(simp) |
|
2228 apply(simp) |
|
2229 apply(simp) |
|
2230 apply(auto simp add: bder_fuse)[1] |
|
2231 defer |
|
2232 apply(simp) |
|
2233 apply(simp del: flts2.simps) |
|
2234 apply(rule conjI) |
|
2235 prefer 2 |
|
2236 apply(auto)[1] |
|
2237 apply(rule impI) |
|
2238 apply(subst flts2_k0) |
|
2239 apply(subst map_append) |
|
2240 apply(subst flts2.simps) |
|
2241 apply(simp only: flts2.simps) |
|
2242 apply(auto) |
|
2243 |
|
2244 |
|
2245 |
|
2246 lemma XXX2_helper: |
|
2247 assumes "\<forall>y. asize y < Suc (sum_list (map asize rs)) \<longrightarrow> good y \<longrightarrow> bsimp y = y" |
|
2248 "\<forall>r'\<in>set rs. good r' \<and> nonalt r'" |
|
2249 shows "flts (map (bsimp \<circ> bder c) (flts (map bsimp rs))) = flts (map (bsimp \<circ> bder c) rs)" |
|
2250 using assms |
|
2251 apply(induct rs arbitrary: c) |
|
2252 apply(simp) |
|
2253 apply(simp) |
|
2254 apply(subst k0) |
|
2255 apply(simp add: flts_append) |
|
2256 apply(subst (2) k0) |
|
2257 apply(simp add: flts_append) |
|
2258 apply(subgoal_tac "flts [a] = [a]") |
|
2259 prefer 2 |
|
2260 using good.simps(1) k0b apply blast |
|
2261 apply(simp) |
|
2262 done |
|
2263 |
|
2264 lemma bmkeps_good: |
|
2265 assumes "good a" |
|
2266 shows "bmkeps (bsimp a) = bmkeps a" |
|
2267 using assms |
|
2268 using test2 by auto |
|
2269 |
|
2270 |
|
2271 lemma xxx_bder: |
|
2272 assumes "good r" |
|
2273 shows "L (erase r) \<noteq> {}" |
|
2274 using assms |
|
2275 apply(induct r rule: good.induct) |
|
2276 apply(auto simp add: Sequ_def) |
|
2277 done |
|
2278 |
|
2279 lemma xxx_bder2: |
|
2280 assumes "L (erase (bsimp r)) = {}" |
|
2281 shows "bsimp r = AZERO" |
|
2282 using assms xxx_bder test2 good1 |
|
2283 by blast |
|
2284 |
|
2285 lemma XXX2aa: |
|
2286 assumes "good a" |
|
2287 shows "bsimp (bder c (bsimp a)) = bsimp (bder c a)" |
|
2288 using assms |
|
2289 by (simp add: test2) |
|
2290 |
|
2291 lemma XXX2aa_ders: |
|
2292 assumes "good a" |
|
2293 shows "bsimp (bders (bsimp a) s) = bsimp (bders a s)" |
|
2294 using assms |
|
2295 by (simp add: test2) |
|
2296 |
|
2297 lemma XXX4a: |
|
2298 shows "good (bders_simp (bsimp r) s) \<or> bders_simp (bsimp r) s = AZERO" |
|
2299 apply(induct s arbitrary: r rule: rev_induct) |
|
2300 apply(simp) |
|
2301 apply (simp add: good1) |
|
2302 apply(simp add: bders_simp_append) |
|
2303 apply (simp add: good1) |
|
2304 done |
|
2305 |
|
2306 lemma XXX4a_good: |
|
2307 assumes "good a" |
|
2308 shows "good (bders_simp a s) \<or> bders_simp a s = AZERO" |
|
2309 using assms |
|
2310 apply(induct s arbitrary: a rule: rev_induct) |
|
2311 apply(simp) |
|
2312 apply(simp add: bders_simp_append) |
|
2313 apply (simp add: good1) |
|
2314 done |
|
2315 |
|
2316 lemma XXX4a_good_cons: |
|
2317 assumes "s \<noteq> []" |
|
2318 shows "good (bders_simp a s) \<or> bders_simp a s = AZERO" |
|
2319 using assms |
|
2320 apply(case_tac s) |
|
2321 apply(auto) |
|
2322 using XXX4a by blast |
|
2323 |
|
2324 lemma XXX4b: |
|
2325 assumes "good a" "L (erase (bders_simp a s)) \<noteq> {}" |
|
2326 shows "good (bders_simp a s)" |
|
2327 using assms |
|
2328 apply(induct s arbitrary: a) |
|
2329 apply(simp) |
|
2330 apply(simp) |
|
2331 apply(subgoal_tac "L (erase (bder a aa)) = {} \<or> L (erase (bder a aa)) \<noteq> {}") |
|
2332 prefer 2 |
|
2333 apply(auto)[1] |
|
2334 apply(erule disjE) |
|
2335 apply(subgoal_tac "bsimp (bder a aa) = AZERO") |
|
2336 prefer 2 |
|
2337 using L_bsimp_erase xxx_bder2 apply auto[1] |
|
2338 apply(simp) |
|
2339 apply (metis L.simps(1) XXX4a erase.simps(1)) |
|
2340 apply(drule_tac x="bsimp (bder a aa)" in meta_spec) |
|
2341 apply(drule meta_mp) |
|
2342 apply simp |
|
2343 apply(rule good1a) |
|
2344 apply(auto) |
|
2345 done |
|
2346 |
|
2347 lemma bders_AZERO: |
|
2348 shows "bders AZERO s = AZERO" |
|
2349 and "bders_simp AZERO s = AZERO" |
|
2350 apply (induct s) |
|
2351 apply(auto) |
|
2352 done |
|
2353 |
|
2354 lemma LA: |
|
2355 assumes "\<Turnstile> v : ders s (erase r)" |
|
2356 shows "retrieve (bders r s) v = retrieve r (flex (erase r) id s v)" |
|
2357 using assms |
|
2358 apply(induct s arbitrary: r v rule: rev_induct) |
|
2359 apply(simp) |
|
2360 apply(simp add: bders_append ders_append) |
|
2361 apply(subst bder_retrieve) |
|
2362 apply(simp) |
|
2363 apply(drule Prf_injval) |
|
2364 by (simp add: flex_append) |
|
2365 |
|
2366 |
|
2367 lemma LB: |
|
2368 assumes "s \<in> (erase r) \<rightarrow> v" |
|
2369 shows "retrieve r v = retrieve r (flex (erase r) id s (mkeps (ders s (erase r))))" |
|
2370 using assms |
|
2371 apply(induct s arbitrary: r v rule: rev_induct) |
|
2372 apply(simp) |
|
2373 apply(subgoal_tac "v = mkeps (erase r)") |
|
2374 prefer 2 |
|
2375 apply (simp add: Posix1(1) Posix_determ Posix_mkeps nullable_correctness) |
|
2376 apply(simp) |
|
2377 apply(simp add: flex_append ders_append) |
|
2378 by (metis Posix_determ Posix_flex Posix_injval Posix_mkeps ders_snoc lexer_correctness(2) lexer_flex) |
|
2379 |
|
2380 lemma LB_sym: |
|
2381 assumes "s \<in> (erase r) \<rightarrow> v" |
|
2382 shows "retrieve r v = retrieve r (flex (erase r) id s (mkeps (erase (bders r s))))" |
|
2383 using assms |
|
2384 by (simp add: LB) |
|
2385 |
|
2386 |
|
2387 lemma LC: |
|
2388 assumes "s \<in> (erase r) \<rightarrow> v" |
|
2389 shows "retrieve r v = retrieve (bders r s) (mkeps (erase (bders r s)))" |
|
2390 apply(simp) |
|
2391 by (metis LA LB Posix1(1) assms lexer_correct_None lexer_flex mkeps_nullable) |
|
2392 |
|
2393 |
|
2394 lemma L0: |
|
2395 assumes "bnullable a" |
|
2396 shows "retrieve (bsimp a) (mkeps (erase (bsimp a))) = retrieve a (mkeps (erase a))" |
|
2397 using assms |
|
2398 by (metis b3 bmkeps_retrieve bmkeps_simp bnullable_correctness) |
|
2399 |
|
2400 thm bmkeps_retrieve |
|
2401 |
|
2402 lemma L0a: |
|
2403 assumes "s \<in> L(erase a)" |
|
2404 shows "retrieve (bsimp (bders a s)) (mkeps (erase (bsimp (bders a s)))) = |
|
2405 retrieve (bders a s) (mkeps (erase (bders a s)))" |
|
2406 using assms |
|
2407 by (metis L0 bnullable_correctness erase_bders lexer_correct_None lexer_flex) |
|
2408 |
|
2409 lemma L0aa: |
|
2410 assumes "s \<in> L (erase a)" |
|
2411 shows "[] \<in> erase (bsimp (bders a s)) \<rightarrow> mkeps (erase (bsimp (bders a s)))" |
|
2412 using assms |
|
2413 by (metis Posix_mkeps b3 bnullable_correctness erase_bders lexer_correct_None lexer_flex) |
|
2414 |
|
2415 lemma L0aaa: |
|
2416 assumes "[c] \<in> L (erase a)" |
|
2417 shows "[c] \<in> (erase a) \<rightarrow> flex (erase a) id [c] (mkeps (erase (bder c a)))" |
|
2418 using assms |
|
2419 by (metis bders.simps(1) bders.simps(2) erase_bders lexer_correct_None lexer_correct_Some lexer_flex option.inject) |
|
2420 |
|
2421 lemma L0aaaa: |
|
2422 assumes "[c] \<in> L (erase a)" |
|
2423 shows "[c] \<in> (erase a) \<rightarrow> flex (erase a) id [c] (mkeps (erase (bders a [c])))" |
|
2424 using assms |
|
2425 using L0aaa by auto |
|
2426 |
|
2427 |
|
2428 lemma L02: |
|
2429 assumes "bnullable (bder c a)" |
|
2430 shows "retrieve (bsimp a) (flex (erase (bsimp a)) id [c] (mkeps (erase (bder c (bsimp a))))) = |
|
2431 retrieve (bder c (bsimp a)) (mkeps (erase (bder c (bsimp a))))" |
|
2432 using assms |
|
2433 apply(simp) |
|
2434 using bder_retrieve L0 bmkeps_simp bmkeps_retrieve L0 LA LB |
|
2435 apply(subst bder_retrieve[symmetric]) |
|
2436 apply (metis L_bsimp_erase bnullable_correctness der_correctness erase_bder mkeps_nullable nullable_correctness) |
|
2437 apply(simp) |
|
2438 done |
|
2439 |
|
2440 lemma L02_bders: |
|
2441 assumes "bnullable (bders a s)" |
|
2442 shows "retrieve (bsimp a) (flex (erase (bsimp a)) id s (mkeps (erase (bders (bsimp a) s)))) = |
|
2443 retrieve (bders (bsimp a) s) (mkeps (erase (bders (bsimp a) s)))" |
|
2444 using assms |
|
2445 by (metis LA L_bsimp_erase bnullable_correctness ders_correctness erase_bders mkeps_nullable nullable_correctness) |
|
2446 |
|
2447 |
|
2448 |
|
2449 |
|
2450 lemma L03: |
|
2451 assumes "bnullable (bder c a)" |
|
2452 shows "retrieve (bder c (bsimp a)) (mkeps (erase (bder c (bsimp a)))) = |
|
2453 bmkeps (bsimp (bder c (bsimp a)))" |
|
2454 using assms |
|
2455 by (metis L0 L_bsimp_erase bmkeps_retrieve bnullable_correctness der_correctness erase_bder nullable_correctness) |
|
2456 |
|
2457 lemma L04: |
|
2458 assumes "bnullable (bder c a)" |
|
2459 shows "retrieve (bder c (bsimp a)) (mkeps (erase (bder c (bsimp a)))) = |
|
2460 retrieve (bsimp (bder c (bsimp a))) (mkeps (erase (bsimp (bder c (bsimp a)))))" |
|
2461 using assms |
|
2462 by (metis L0 L_bsimp_erase bnullable_correctness der_correctness erase_bder nullable_correctness) |
|
2463 |
|
2464 lemma L05: |
|
2465 assumes "bnullable (bder c a)" |
|
2466 shows "retrieve (bder c (bsimp a)) (mkeps (erase (bder c (bsimp a)))) = |
|
2467 retrieve (bsimp (bder c (bsimp a))) (mkeps (erase (bsimp (bder c (bsimp a)))))" |
|
2468 using assms |
|
2469 using L04 by auto |
|
2470 |
|
2471 lemma L06: |
|
2472 assumes "bnullable (bder c a)" |
|
2473 shows "bmkeps (bder c (bsimp a)) = bmkeps (bsimp (bder c (bsimp a)))" |
|
2474 using assms |
|
2475 by (metis L03 L_bsimp_erase bmkeps_retrieve bnullable_correctness der_correctness erase_bder nullable_correctness) |
|
2476 |
|
2477 lemma L07: |
|
2478 assumes "s \<in> L (erase r)" |
|
2479 shows "retrieve r (flex (erase r) id s (mkeps (ders s (erase r)))) |
|
2480 = retrieve (bders r s) (mkeps (erase (bders r s)))" |
|
2481 using assms |
|
2482 using LB LC lexer_correct_Some by auto |
|
2483 |
|
2484 lemma LXXX: |
|
2485 assumes "s \<in> (erase r) \<rightarrow> v" "s \<in> (erase (bsimp r)) \<rightarrow> v'" |
|
2486 shows "retrieve r v = retrieve (bsimp r) v'" |
|
2487 using assms |
|
2488 apply - |
|
2489 thm LC |
|
2490 apply(subst LC) |
|
2491 apply(assumption) |
|
2492 apply(subst L0[symmetric]) |
|
2493 using bnullable_correctness lexer_correctness(2) lexer_flex apply fastforce |
|
2494 apply(subst (2) LC) |
|
2495 apply(assumption) |
|
2496 apply(subst (2) L0[symmetric]) |
|
2497 using bnullable_correctness lexer_correctness(2) lexer_flex apply fastforce |
|
2498 |
|
2499 oops |
|
2500 |
|
2501 |
|
2502 lemma L07a: |
|
2503 assumes "s \<in> L (erase r)" |
|
2504 shows "retrieve (bsimp r) (flex (erase (bsimp r)) id s (mkeps (ders s (erase (bsimp r))))) |
|
2505 = retrieve r (flex (erase r) id s (mkeps (ders s (erase r))))" |
|
2506 using assms |
|
2507 apply(induct s arbitrary: r) |
|
2508 apply(simp) |
|
2509 using L0a apply force |
|
2510 apply(drule_tac x="(bder a r)" in meta_spec) |
|
2511 apply(drule meta_mp) |
|
2512 apply (metis L_bsimp_erase erase_bder lexer.simps(2) lexer_correct_None option.case(1)) |
|
2513 apply(drule sym) |
|
2514 apply(simp) |
|
2515 apply(subst (asm) bder_retrieve) |
|
2516 apply (metis Posix_Prf Posix_flex Posix_mkeps ders.simps(2) lexer_correct_None lexer_flex) |
|
2517 apply(simp only: flex_fun_apply) |
|
2518 apply(simp) |
|
2519 using L0[no_vars] bder_retrieve[no_vars] LA[no_vars] LC[no_vars] L07[no_vars] |
|
2520 oops |
|
2521 |
|
2522 lemma L08: |
|
2523 assumes "s \<in> L (erase r)" |
|
2524 shows "retrieve (bders (bsimp r) s) (mkeps (erase (bders (bsimp r) s))) |
|
2525 = retrieve (bders r s) (mkeps (erase (bders r s)))" |
|
2526 using assms |
|
2527 apply(induct s arbitrary: r) |
|
2528 apply(simp) |
|
2529 using L0 bnullable_correctness nullable_correctness apply blast |
|
2530 apply(simp add: bders_append) |
|
2531 apply(drule_tac x="(bder a (bsimp r))" in meta_spec) |
|
2532 apply(drule meta_mp) |
|
2533 apply (metis L_bsimp_erase erase_bder lexer.simps(2) lexer_correct_None option.case(1)) |
|
2534 apply(drule sym) |
|
2535 apply(simp) |
|
2536 apply(subst LA) |
|
2537 apply (metis L0aa L_bsimp_erase Posix1(1) ders.simps(2) ders_correctness erase_bder erase_bders mkeps_nullable nullable_correctness) |
|
2538 apply(subst LA) |
|
2539 using lexer_correct_None lexer_flex mkeps_nullable apply force |
|
2540 |
|
2541 using L0[no_vars] bder_retrieve[no_vars] LA[no_vars] LC[no_vars] L07[no_vars] |
|
2542 |
|
2543 thm L0[no_vars] bder_retrieve[no_vars] LA[no_vars] LC[no_vars] L07[no_vars] |
|
2544 oops |
|
2545 |
|
2546 lemma test: |
|
2547 assumes "s = [c]" |
|
2548 shows "retrieve (bders r s) v = XXX" and "YYY = retrieve r (flex (erase r) id s v)" |
|
2549 using assms |
|
2550 apply(simp only: bders.simps) |
|
2551 defer |
|
2552 using assms |
|
2553 apply(simp only: flex.simps id_simps) |
|
2554 using L0[no_vars] bder_retrieve[no_vars] LA[no_vars] LC[no_vars] |
|
2555 find_theorems "retrieve (bders _ _) _" |
|
2556 find_theorems "retrieve _ (mkeps _)" |
|
2557 oops |
|
2558 |
|
2559 lemma L06X: |
|
2560 assumes "bnullable (bder c a)" |
|
2561 shows "bmkeps (bder c (bsimp a)) = bmkeps (bder c a)" |
|
2562 using assms |
|
2563 apply(induct a arbitrary: c) |
|
2564 apply(simp) |
|
2565 apply(simp) |
|
2566 apply(simp) |
|
2567 prefer 3 |
|
2568 apply(simp) |
|
2569 prefer 2 |
|
2570 apply(simp) |
|
2571 |
|
2572 defer |
|
2573 oops |
|
2574 |
|
2575 lemma L06_2: |
|
2576 assumes "bnullable (bders a [c,d])" |
|
2577 shows "bmkeps (bders (bsimp a) [c,d]) = bmkeps (bsimp (bders (bsimp a) [c,d]))" |
|
2578 using assms |
|
2579 apply(simp) |
|
2580 by (metis L_bsimp_erase bmkeps_simp bnullable_correctness der_correctness erase_bder nullable_correctness) |
|
2581 |
|
2582 lemma L06_bders: |
|
2583 assumes "bnullable (bders a s)" |
|
2584 shows "bmkeps (bders (bsimp a) s) = bmkeps (bsimp (bders (bsimp a) s))" |
|
2585 using assms |
|
2586 by (metis L_bsimp_erase bmkeps_simp bnullable_correctness ders_correctness erase_bders nullable_correctness) |
|
2587 |
|
2588 lemma LLLL: |
|
2589 shows "L (erase a) = L (erase (bsimp a))" |
|
2590 and "L (erase a) = {flat v | v. \<Turnstile> v: (erase a)}" |
|
2591 and "L (erase a) = {flat v | v. \<Turnstile> v: (erase (bsimp a))}" |
|
2592 using L_bsimp_erase apply(blast) |
|
2593 apply (simp add: L_flat_Prf) |
|
2594 using L_bsimp_erase L_flat_Prf apply(auto)[1] |
|
2595 done |
|
2596 |
|
2597 |
|
2598 |
|
2599 lemma L07XX: |
|
2600 assumes "s \<in> L (erase a)" |
|
2601 shows "s \<in> erase a \<rightarrow> flex (erase a) id s (mkeps (ders s (erase a)))" |
|
2602 using assms |
|
2603 by (meson lexer_correct_None lexer_correctness(1) lexer_flex) |
|
2604 |
|
2605 lemma LX0: |
|
2606 assumes "s \<in> L r" |
|
2607 shows "decode (bmkeps (bders (intern r) s)) r = Some(flex r id s (mkeps (ders s r)))" |
|
2608 by (metis assms blexer_correctness blexer_def lexer_correct_None lexer_flex) |
|
2609 |
|
2610 |
|
2611 lemma L02_bders2: |
|
2612 assumes "bnullable (bders a s)" "s = [c]" |
|
2613 shows "retrieve (bders (bsimp a) s) (mkeps (erase (bders (bsimp a) s))) = |
|
2614 retrieve (bders a s) (mkeps (erase (bders a s)))" |
|
2615 using assms |
|
2616 apply(simp) |
|
2617 |
|
2618 apply(induct s arbitrary: a) |
|
2619 apply(simp) |
|
2620 using L0 apply auto[1] |
|
2621 oops |
|
2622 |
|
2623 thm bmkeps_retrieve bmkeps_simp Posix_mkeps |
|
2624 |
|
2625 lemma WQ1: |
|
2626 assumes "s \<in> L (der c r)" |
|
2627 shows "s \<in> der c r \<rightarrow> mkeps (ders s (der c r))" |
|
2628 using assms |
|
2629 oops |
|
2630 |
|
2631 lemma L02_bsimp: |
|
2632 assumes "bnullable (bders a s)" |
|
2633 shows "retrieve (bsimp a) (flex (erase (bsimp a)) id s (mkeps (erase (bders (bsimp a) s)))) = |
|
2634 retrieve a (flex (erase a) id s (mkeps (erase (bders a s))))" |
|
2635 using assms |
|
2636 apply(induct s arbitrary: a) |
|
2637 apply(simp) |
|
2638 apply (simp add: L0) |
|
2639 apply(simp) |
|
2640 apply(drule_tac x="bder a aa" in meta_spec) |
|
2641 apply(simp) |
|
2642 apply(subst (asm) bder_retrieve) |
|
2643 using Posix_Prf Posix_flex Posix_mkeps bnullable_correctness apply fastforce |
|
2644 apply(simp add: flex_fun_apply) |
|
2645 apply(drule sym) |
|
2646 apply(simp) |
|
2647 apply(subst flex_injval) |
|
2648 apply(subst bder_retrieve[symmetric]) |
|
2649 apply (metis L_bsimp_erase Posix_Prf Posix_flex Posix_mkeps bders.simps(2) bnullable_correctness ders.simps(2) erase_bders lexer_correct_None lexer_flex option.distinct(1)) |
|
2650 apply(simp only: erase_bder[symmetric] erase_bders[symmetric]) |
|
2651 apply(subst LB_sym[symmetric]) |
|
2652 apply(simp) |
|
2653 oops |
|
2654 |
|
2655 lemma L1: |
|
2656 assumes "s \<in> r \<rightarrow> v" |
|
2657 shows "decode (bmkeps (bders (intern r) s)) r = Some v" |
|
2658 using assms |
|
2659 by (metis blexer_correctness blexer_def lexer_correctness(1) option.distinct(1)) |
|
2660 |
|
2661 lemma L2: |
|
2662 assumes "s \<in> (der c r) \<rightarrow> v" |
|
2663 shows "decode (bmkeps (bders (intern r) (c # s))) r = Some (injval r c v)" |
|
2664 using assms |
|
2665 apply(subst bmkeps_retrieve) |
|
2666 using Posix1(1) lexer_correct_None lexer_flex apply fastforce |
|
2667 using MAIN_decode |
|
2668 apply(subst MAIN_decode[symmetric]) |
|
2669 apply(simp) |
|
2670 apply (meson Posix1(1) lexer_correct_None lexer_flex mkeps_nullable) |
|
2671 apply(simp) |
|
2672 apply(subgoal_tac "v = flex (der c r) id s (mkeps (ders s (der c r)))") |
|
2673 prefer 2 |
|
2674 apply (metis Posix_determ lexer_correctness(1) lexer_flex option.distinct(1)) |
|
2675 apply(simp) |
|
2676 apply(subgoal_tac "injval r c (flex (der c r) id s (mkeps (ders s (der c r)))) = |
|
2677 (flex (der c r) ((\<lambda>v. injval r c v) o id) s (mkeps (ders s (der c r))))") |
|
2678 apply(simp) |
|
2679 using flex_fun_apply by blast |
|
2680 |
|
2681 lemma L3: |
|
2682 assumes "s2 \<in> (ders s1 r) \<rightarrow> v" |
|
2683 shows "decode (bmkeps (bders (intern r) (s1 @ s2))) r = Some (flex r id s1 v)" |
|
2684 using assms |
|
2685 apply(induct s1 arbitrary: r s2 v rule: rev_induct) |
|
2686 apply(simp) |
|
2687 using L1 apply blast |
|
2688 apply(simp add: ders_append) |
|
2689 apply(drule_tac x="r" in meta_spec) |
|
2690 apply(drule_tac x="x # s2" in meta_spec) |
|
2691 apply(drule_tac x="injval (ders xs r) x v" in meta_spec) |
|
2692 apply(drule meta_mp) |
|
2693 defer |
|
2694 apply(simp) |
|
2695 apply(simp add: flex_append) |
|
2696 by (simp add: Posix_injval) |
|
2697 |
|
2698 |
|
2699 |
|
2700 lemma bders_snoc: |
|
2701 "bder c (bders a s) = bders a (s @ [c])" |
|
2702 apply(simp add: bders_append) |
|
2703 done |
|
2704 |
|
2705 |
|
2706 lemma QQ1: |
|
2707 shows "bsimp (bders (bsimp a) []) = bders_simp (bsimp a) []" |
|
2708 apply(simp) |
|
2709 apply(simp add: bsimp_idem) |
|
2710 done |
|
2711 |
|
2712 lemma QQ2: |
|
2713 shows "bsimp (bders (bsimp a) [c]) = bders_simp (bsimp a) [c]" |
|
2714 apply(simp) |
|
2715 done |
|
2716 |
|
2717 lemma XXX2a_long: |
|
2718 assumes "good a" |
|
2719 shows "bsimp (bder c (bsimp a)) = bsimp (bder c a)" |
|
2720 using assms |
|
2721 apply(induct a arbitrary: c taking: asize rule: measure_induct) |
|
2722 apply(case_tac x) |
|
2723 apply(simp) |
|
2724 apply(simp) |
|
2725 apply(simp) |
|
2726 prefer 3 |
|
2727 apply(simp) |
|
2728 apply(simp) |
|
2729 apply(auto)[1] |
|
2730 apply(case_tac "x42 = AZERO") |
|
2731 apply(simp) |
|
2732 apply(case_tac "x43 = AZERO") |
|
2733 apply(simp) |
|
2734 using test2 apply force |
|
2735 apply(case_tac "\<exists>bs. x42 = AONE bs") |
|
2736 apply(clarify) |
|
2737 apply(simp) |
|
2738 apply(subst bsimp_ASEQ1) |
|
2739 apply(simp) |
|
2740 using b3 apply force |
|
2741 using bsimp_ASEQ0 test2 apply force |
|
2742 thm good_SEQ test2 |
|
2743 apply (simp add: good_SEQ test2) |
|
2744 apply (simp add: good_SEQ test2) |
|
2745 apply(case_tac "x42 = AZERO") |
|
2746 apply(simp) |
|
2747 apply(case_tac "x43 = AZERO") |
|
2748 apply(simp) |
|
2749 apply (simp add: bsimp_ASEQ0) |
|
2750 apply(case_tac "\<exists>bs. x42 = AONE bs") |
|
2751 apply(clarify) |
|
2752 apply(simp) |
|
2753 apply(subst bsimp_ASEQ1) |
|
2754 apply(simp) |
|
2755 using bsimp_ASEQ0 test2 apply force |
|
2756 apply (simp add: good_SEQ test2) |
|
2757 apply (simp add: good_SEQ test2) |
|
2758 apply (simp add: good_SEQ test2) |
|
2759 (* AALTs case *) |
|
2760 apply(simp) |
|
2761 using test2 by fastforce |
|
2762 |
|
2763 lemma XXX2a_long_without_good: |
|
2764 assumes "a = AALTs bs0 [AALTs bs1 [AALTs bs2 [ASTAR [] (AONE bs7), AONE bs6, ASEQ bs3 (ACHAR bs4 d) (AONE bs5)]]]" |
|
2765 shows "bsimp (bder c (bsimp a)) = bsimp (bder c a)" |
|
2766 "bsimp (bder c (bsimp a)) = XXX" |
|
2767 "bsimp (bder c a) = YYY" |
|
2768 using assms |
|
2769 apply(simp) |
|
2770 using assms |
|
2771 apply(simp) |
|
2772 prefer 2 |
|
2773 using assms |
|
2774 apply(simp) |
|
2775 oops |
|
2776 |
|
2777 lemma bder_bsimp_AALTs: |
|
2778 shows "bder c (bsimp_AALTs bs rs) = bsimp_AALTs bs (map (bder c) rs)" |
|
2779 apply(induct bs rs rule: bsimp_AALTs.induct) |
|
2780 apply(simp) |
|
2781 apply(simp) |
|
2782 apply (simp add: bder_fuse) |
|
2783 apply(simp) |
|
2784 done |
|
2785 |
|
2786 lemma flts_nothing: |
|
2787 assumes "\<forall>r \<in> set rs. r \<noteq> AZERO" "\<forall>r \<in> set rs. nonalt r" |
|
2788 shows "flts rs = rs" |
|
2789 using assms |
|
2790 apply(induct rs rule: flts.induct) |
|
2791 apply(auto) |
|
2792 done |
|
2793 |
|
2794 lemma flts_flts: |
|
2795 assumes "\<forall>r \<in> set rs. good r" |
|
2796 shows "flts (flts rs) = flts rs" |
|
2797 using assms |
|
2798 apply(induct rs taking: "\<lambda>rs. sum_list (map asize rs)" rule: measure_induct) |
|
2799 apply(case_tac x) |
|
2800 apply(simp) |
|
2801 apply(simp) |
|
2802 apply(case_tac a) |
|
2803 apply(simp_all add: bder_fuse flts_append) |
|
2804 apply(subgoal_tac "\<forall>r \<in> set x52. r \<noteq> AZERO") |
|
2805 prefer 2 |
|
2806 apply (metis Nil_is_append_conv bsimp_AALTs.elims good.simps(1) good.simps(5) good0 list.distinct(1) n0 nn1b split_list_last test2) |
|
2807 apply(subgoal_tac "\<forall>r \<in> set x52. nonalt r") |
|
2808 prefer 2 |
|
2809 apply (metis n0 nn1b test2) |
|
2810 by (metis flts_fuse flts_nothing) |
|
2811 |
|
2812 |
|
2813 lemma PP: |
|
2814 assumes "bnullable (bders r s)" |
|
2815 shows "bmkeps (bders (bsimp r) s) = bmkeps (bders r s)" |
|
2816 using assms |
|
2817 apply(induct s arbitrary: r) |
|
2818 apply(simp) |
|
2819 using bmkeps_simp apply auto[1] |
|
2820 apply(simp add: bders_append bders_simp_append) |
|
2821 oops |
|
2822 |
|
2823 lemma PP: |
|
2824 assumes "bnullable (bders r s)" |
|
2825 shows "bmkeps (bders_simp (bsimp r) s) = bmkeps (bders r s)" |
|
2826 using assms |
|
2827 apply(induct s arbitrary: r rule: rev_induct) |
|
2828 apply(simp) |
|
2829 using bmkeps_simp apply auto[1] |
|
2830 apply(simp add: bders_append bders_simp_append) |
|
2831 apply(drule_tac x="bder a (bsimp r)" in meta_spec) |
|
2832 apply(drule_tac meta_mp) |
|
2833 defer |
|
2834 oops |
|
2835 |
|
2836 |
|
2837 lemma |
|
2838 assumes "asize (bsimp a) = asize a" "a = AALTs bs [AALTs bs2 [], AZERO, AONE bs3]" |
|
2839 shows "bsimp a = a" |
|
2840 using assms |
|
2841 apply(simp) |
|
2842 oops |
|
2843 |
|
2844 |
|
2845 lemma iii: |
|
2846 assumes "bsimp_AALTs bs rs \<noteq> AZERO" |
|
2847 shows "rs \<noteq> []" |
|
2848 using assms |
|
2849 apply(induct bs rs rule: bsimp_AALTs.induct) |
|
2850 apply(auto) |
|
2851 done |
|
2852 |
|
2853 lemma CT1_SEQ: |
|
2854 shows "bsimp (ASEQ bs a1 a2) = bsimp (ASEQ bs (bsimp a1) (bsimp a2))" |
|
2855 apply(simp add: bsimp_idem) |
|
2856 done |
|
2857 |
|
2858 lemma CT1: |
|
2859 shows "bsimp (AALTs bs as) = bsimp (AALTs bs (map bsimp as))" |
|
2860 apply(induct as arbitrary: bs) |
|
2861 apply(simp) |
|
2862 apply(simp) |
|
2863 by (simp add: bsimp_idem comp_def) |
|
2864 |
|
2865 lemma CT1a: |
|
2866 shows "bsimp (AALT bs a1 a2) = bsimp(AALT bs (bsimp a1) (bsimp a2))" |
|
2867 by (metis CT1 list.simps(8) list.simps(9)) |
|
2868 |
|
2869 lemma WWW2: |
|
2870 shows "bsimp (bsimp_AALTs bs1 (flts (map bsimp as1))) = |
|
2871 bsimp_AALTs bs1 (flts (map bsimp as1))" |
|
2872 by (metis bsimp.simps(2) bsimp_idem) |
|
2873 |
|
2874 lemma CT1b: |
|
2875 shows "bsimp (bsimp_AALTs bs as) = bsimp (bsimp_AALTs bs (map bsimp as))" |
|
2876 apply(induct bs as rule: bsimp_AALTs.induct) |
|
2877 apply(auto simp add: bsimp_idem) |
|
2878 apply (simp add: bsimp_fuse bsimp_idem) |
|
2879 by (metis bsimp_idem comp_apply) |
|
2880 |
|
2881 |
|
2882 |
|
2883 |
|
2884 (* CT *) |
|
2885 |
|
2886 lemma CTU: |
|
2887 shows "bsimp_AALTs bs as = li bs as" |
|
2888 apply(induct bs as rule: li.induct) |
|
2889 apply(auto) |
|
2890 done |
|
2891 |
|
2892 find_theorems "bder _ (bsimp_AALTs _ _)" |
|
2893 |
|
2894 lemma CTa: |
|
2895 assumes "\<forall>r \<in> set as. nonalt r \<and> r \<noteq> AZERO" |
|
2896 shows "flts as = as" |
|
2897 using assms |
|
2898 apply(induct as) |
|
2899 apply(simp) |
|
2900 apply(case_tac as) |
|
2901 apply(simp) |
|
2902 apply (simp add: k0b) |
|
2903 using flts_nothing by auto |
|
2904 |
|
2905 lemma CT0: |
|
2906 assumes "\<forall>r \<in> set as1. nonalt r \<and> r \<noteq> AZERO" |
|
2907 shows "flts [bsimp_AALTs bs1 as1] = flts (map (fuse bs1) as1)" |
|
2908 using assms CTa |
|
2909 apply(induct as1 arbitrary: bs1) |
|
2910 apply(simp) |
|
2911 apply(simp) |
|
2912 apply(case_tac as1) |
|
2913 apply(simp) |
|
2914 apply(simp) |
|
2915 proof - |
|
2916 fix a :: arexp and as1a :: "arexp list" and bs1a :: "bit list" and aa :: arexp and list :: "arexp list" |
|
2917 assume a1: "nonalt a \<and> a \<noteq> AZERO \<and> nonalt aa \<and> aa \<noteq> AZERO \<and> (\<forall>r\<in>set list. nonalt r \<and> r \<noteq> AZERO)" |
|
2918 assume a2: "\<And>as. \<forall>r\<in>set as. nonalt r \<and> r \<noteq> AZERO \<Longrightarrow> flts as = as" |
|
2919 assume a3: "as1a = aa # list" |
|
2920 have "flts [a] = [a]" |
|
2921 using a1 k0b by blast |
|
2922 then show "fuse bs1a a # fuse bs1a aa # map (fuse bs1a) list = flts (fuse bs1a a # fuse bs1a aa # map (fuse bs1a) list)" |
|
2923 using a3 a2 a1 by (metis (no_types) append.left_neutral append_Cons flts_fuse k00 k0b list.simps(9)) |
|
2924 qed |
|
2925 |
|
2926 |
|
2927 lemma CT01: |
|
2928 assumes "\<forall>r \<in> set as1. nonalt r \<and> r \<noteq> AZERO" "\<forall>r \<in> set as2. nonalt r \<and> r \<noteq> AZERO" |
|
2929 shows "flts [bsimp_AALTs bs1 as1, bsimp_AALTs bs2 as2] = flts ((map (fuse bs1) as1) @ (map (fuse bs2) as2))" |
|
2930 using assms CT0 |
|
2931 by (metis k0 k00) |
|
2932 |
|
2933 |
|
2934 |
|
2935 lemma CT_exp: |
|
2936 assumes "\<forall>a \<in> set as. bsimp (bder c (bsimp a)) = bsimp (bder c a)" |
|
2937 shows "map bsimp (map (bder c) as) = map bsimp (map (bder c) (map bsimp as))" |
|
2938 using assms |
|
2939 apply(induct as) |
|
2940 apply(auto) |
|
2941 done |
|
2942 |
|
2943 lemma asize_set: |
|
2944 assumes "a \<in> set as" |
|
2945 shows "asize a < Suc (sum_list (map asize as))" |
|
2946 using assms |
|
2947 apply(induct as arbitrary: a) |
|
2948 apply(auto) |
|
2949 using le_add2 le_less_trans not_less_eq by blast |
|
2950 |
|
2951 |
|
2952 lemma XXX2a_long_without_good: |
|
2953 shows "bsimp (bder c (bsimp a)) = bsimp (bder c a)" |
|
2954 apply(induct a arbitrary: c taking: "\<lambda>a. asize a" rule: measure_induct) |
|
2955 apply(case_tac x) |
|
2956 apply(simp) |
|
2957 apply(simp) |
|
2958 apply(simp) |
|
2959 prefer 3 |
|
2960 apply(simp) |
|
2961 (* AALT case *) |
|
2962 prefer 2 |
|
2963 apply(simp del: bsimp.simps) |
|
2964 apply(subst (2) CT1) |
|
2965 apply(subst CT_exp) |
|
2966 apply(auto)[1] |
|
2967 using asize_set apply blast |
|
2968 apply(subst CT1[symmetric]) |
|
2969 apply(simp) |
|
2970 oops |
|
2971 |
|
2972 lemma YY: |
|
2973 assumes "flts (map bsimp as1) = xs" |
|
2974 shows "flts (map bsimp (map (fuse bs1) as1)) = map (fuse bs1) xs" |
|
2975 using assms |
|
2976 apply(induct as1 arbitrary: bs1 xs) |
|
2977 apply(simp) |
|
2978 apply(auto) |
|
2979 by (metis bsimp_fuse flts_fuse k0 list.simps(9)) |
|
2980 |
|
2981 |
|
2982 lemma flts_nonalt: |
|
2983 assumes "flts (map bsimp xs) = ys" |
|
2984 shows "\<forall>y \<in> set ys. nonalt y" |
|
2985 using assms |
|
2986 apply(induct xs arbitrary: ys) |
|
2987 apply(auto) |
|
2988 apply(case_tac xs) |
|
2989 apply(auto) |
|
2990 using flts2 good1 apply fastforce |
|
2991 by (smt ex_map_conv list.simps(9) nn1b nn1c) |
|
2992 |
|
2993 |
|
2994 lemma WWW3: |
|
2995 shows "flts [bsimp_AALTs bs1 (flts (map bsimp as1))] = |
|
2996 flts (map bsimp (map (fuse bs1) as1))" |
|
2997 by (metis CT0 YY flts_nonalt flts_nothing qqq1) |
|
2998 |
|
2999 |
|
3000 |
|
3001 lemma WWW5: |
|
3002 shows "map (bsimp \<circ> bder c) as1 = map bsimp (map (bder c) as1)" |
|
3003 apply(induct as1) |
|
3004 apply(auto) |
|
3005 done |
|
3006 |
|
3007 lemma big0: |
|
3008 shows "bsimp (AALT x51 (AALTs bs1 as1) (AALTs bs2 as2)) = |
|
3009 bsimp (AALTs x51 ((map (fuse bs1) as1) @ (map (fuse bs2) as2)))" |
|
3010 by (smt WWW3 bsimp.simps(2) k0 k00 list.simps(8) list.simps(9) map_append) |
|
3011 |
|
3012 lemma bignA: |
|
3013 shows "bsimp (AALTs x51 (AALTs bs1 as1 # as2)) = |
|
3014 bsimp (AALTs x51 ((map (fuse bs1) as1) @ as2))" |
|
3015 apply(simp) |
|
3016 apply(subst k0) |
|
3017 apply(subst WWW3) |
|
3018 apply(simp add: flts_append) |
|
3019 done |
|
3020 |
|
3021 lemma XXX2a_long_without_good: |
|
3022 shows "bsimp (bder c (bsimp a)) = bsimp (bder c a)" |
|
3023 apply(induct a arbitrary: c taking: "\<lambda>a. asize a" rule: measure_induct) |
|
3024 apply(case_tac x) |
|
3025 apply(simp) |
|
3026 apply(simp) |
|
3027 apply(simp) |
|
3028 prefer 3 |
|
3029 apply(simp) |
|
3030 (* SEQ case *) |
|
3031 apply(simp only:) |
|
3032 apply(subst CT1_SEQ) |
|
3033 apply(simp only: bsimp.simps) |
|
3034 |
|
3035 (* AALT case *) |
|
3036 prefer 2 |
|
3037 apply(simp only:) |
|
3038 apply(case_tac "\<exists>a1 a2. x52 = [a1, a2]") |
|
3039 apply(clarify) |
|
3040 apply(simp del: bsimp.simps) |
|
3041 apply(subst (2) CT1) |
|
3042 apply(simp del: bsimp.simps) |
|
3043 apply(rule_tac t="bsimp (bder c a1)" and s="bsimp (bder c (bsimp a1))" in subst) |
|
3044 apply(simp del: bsimp.simps) |
|
3045 apply(rule_tac t="bsimp (bder c a2)" and s="bsimp (bder c (bsimp a2))" in subst) |
|
3046 apply(simp del: bsimp.simps) |
|
3047 apply(subst CT1a[symmetric]) |
|
3048 (* \<rightarrow> *) |
|
3049 apply(rule_tac t="AALT x51 (bder c (bsimp a1)) (bder c (bsimp a2))" |
|
3050 and s="bder c (AALT x51 (bsimp a1) (bsimp a2))" in subst) |
|
3051 apply(simp) |
|
3052 apply(subst bsimp.simps) |
|
3053 apply(simp del: bsimp.simps bder.simps) |
|
3054 |
|
3055 apply(subst bder_bsimp_AALTs) |
|
3056 apply(subst bsimp.simps) |
|
3057 apply(subst WWW2[symmetric]) |
|
3058 apply(subst bsimp_AALTs_qq) |
|
3059 defer |
|
3060 apply(subst bsimp.simps) |
|
3061 |
|
3062 (* <- *) |
|
3063 apply(subst bsimp.simps) |
|
3064 apply(simp del: bsimp.simps) |
|
3065 apply(case_tac "\<exists>bs1 as1. bsimp a1 = AALTs bs1 as1") |
|
3066 apply(case_tac "\<exists>bs2 as2. bsimp a2 = AALTs bs2 as2") |
|
3067 apply(clarify) |
|
3068 apply(simp only:) |
|
3069 apply(simp del: bsimp.simps bder.simps) |
|
3070 apply(subst bsimp_AALTs_qq) |
|
3071 prefer 2 |
|
3072 apply(simp del: bsimp.simps) |
|
3073 apply(subst big0) |
|
3074 apply(simp add: WWW4) |
|
3075 apply (m etis One_nat_def Suc_eq_plus1 Suc_lessI arexp.distinct(7) bsimp.simps(2) bsimp_AALTs.simps(1) bsimp_idem flts.simps(1) length_append length_greater_0_conv length_map not_add_less2 not_less_eq) |
|
3076 oops |
|
3077 |
|
3078 lemma XXX2a_long_without_good: |
|
3079 shows "bsimp (bder c (bsimp a)) = bsimp (bder c a)" |
|
3080 apply(induct a arbitrary: c taking: "\<lambda>a. asize a" rule: measure_induct) |
|
3081 apply(case_tac x) |
|
3082 apply(simp) |
|
3083 apply(simp) |
|
3084 apply(simp) |
|
3085 prefer 3 |
|
3086 apply(simp) |
|
3087 (* AALT case *) |
|
3088 prefer 2 |
|
3089 apply(subgoal_tac "nonnested (bsimp x)") |
|
3090 prefer 2 |
|
3091 using nn1b apply blast |
|
3092 apply(simp only:) |
|
3093 apply(drule_tac x="AALTs x51 (flts x52)" in spec) |
|
3094 apply(drule mp) |
|
3095 defer |
|
3096 apply(drule_tac x="c" in spec) |
|
3097 apply(simp) |
|
3098 apply(rotate_tac 2) |
|
3099 |
|
3100 apply(drule sym) |
|
3101 apply(simp) |
|
3102 |
|
3103 apply(simp only: bder.simps) |
|
3104 apply(simp only: bsimp.simps) |
|
3105 apply(subst bder_bsimp_AALTs) |
|
3106 apply(case_tac x52) |
|
3107 apply(simp) |
|
3108 apply(simp) |
|
3109 apply(case_tac list) |
|
3110 apply(simp) |
|
3111 apply(case_tac a) |
|
3112 apply(simp) |
|
3113 apply(simp) |
|
3114 apply(simp) |
|
3115 defer |
|
3116 apply(simp) |
|
3117 |
|
3118 |
|
3119 (* case AALTs list is not empty *) |
|
3120 apply(simp) |
|
3121 apply(subst k0) |
|
3122 apply(subst (2) k0) |
|
3123 apply(simp) |
|
3124 apply(case_tac "bsimp a = AZERO") |
|
3125 apply(subgoal_tac "bsimp (bder c a) = AZERO") |
|
3126 prefer 2 |
|
3127 using less_iff_Suc_add apply auto[1] |
|
3128 apply(simp) |
|
3129 apply(drule_tac x="AALTs x51 list" in spec) |
|
3130 apply(drule mp) |
|
3131 apply(simp add: asize0) |
|
3132 apply(drule_tac x="c" in spec) |
|
3133 apply(simp add: bder_bsimp_AALTs) |
|
3134 apply(case_tac "nonalt (bsimp a)") |
|
3135 prefer 2 |
|
3136 apply(drule_tac x="bsimp (AALTs x51 (a#list))" in spec) |
|
3137 apply(drule mp) |
|
3138 apply(rule order_class.order.strict_trans2) |
|
3139 apply(rule bsimp_AALTs_size3) |
|
3140 apply(auto)[1] |
|
3141 apply(simp) |
|
3142 apply(subst (asm) bsimp_idem) |
|
3143 apply(drule_tac x="c" in spec) |
|
3144 apply(simp) |
|
3145 find_theorems "_ < _ \<Longrightarrow> _ \<le> _ \<Longrightarrow>_ < _" |
|
3146 apply(rule le_trans) |
|
3147 apply(subgoal_tac "flts [bsimp a] = [bsimp a]") |
|
3148 prefer 2 |
|
3149 using k0b apply blast |
|
3150 apply(simp) |
|
3151 find_theorems "asize _ < asize _" |
|
3152 |
|
3153 using bder_bsimp_AALTs |
|
3154 apply(case_tac list) |
|
3155 apply(simp) |
|
3156 sledgeha mmer [timeout=6000] |
|
3157 |
|
3158 apply(case_tac "\<exists>r \<in> set (map bsimp x52). \<not>nonalt r") |
|
3159 apply(drule_tac x="bsimp (AALTs x51 x52)" in spec) |
|
3160 apply(drule mp) |
|
3161 using bsimp_AALTs_size3 apply blast |
|
3162 apply(drule_tac x="c" in spec) |
|
3163 apply(subst (asm) (2) test) |
|
3164 |
|
3165 apply(case_tac x52) |
|
3166 apply(simp) |
|
3167 apply(simp) |
|
3168 apply(case_tac "bsimp a = AZERO") |
|
3169 apply(simp) |
|
3170 apply(subgoal_tac "bsimp (bder c a) = AZERO") |
|
3171 prefer 2 |
|
3172 apply auto[1] |
|
3173 apply (metis L.simps(1) L_bsimp_erase der.simps(1) der_correctness erase.simps(1) erase_bder xxx_bder2) |
|
3174 apply(simp) |
|
3175 apply(drule_tac x="AALTs x51 list" in spec) |
|
3176 apply(drule mp) |
|
3177 apply(simp add: asize0) |
|
3178 apply(simp) |
|
3179 apply(case_tac list) |
|
3180 prefer 2 |
|
3181 apply(simp) |
|
3182 apply(case_tac "bsimp aa = AZERO") |
|
3183 apply(simp) |
|
3184 apply(subgoal_tac "bsimp (bder c aa) = AZERO") |
|
3185 prefer 2 |
|
3186 apply auto[1] |
|
3187 apply (metis add.left_commute bder.simps(1) bsimp.simps(3) less_add_Suc1) |
|
3188 apply(simp) |
|
3189 apply(drule_tac x="AALTs x51 (a#lista)" in spec) |
|
3190 apply(drule mp) |
|
3191 apply(simp add: asize0) |
|
3192 apply(simp) |
|
3193 apply (metis flts.simps(2) k0) |
|
3194 apply(subst k0) |
|
3195 apply(subst (2) k0) |
|
3196 |
|
3197 |
|
3198 using less_add_Suc1 apply fastforce |
|
3199 apply(subst k0) |
|
3200 |
|
3201 |
|
3202 apply(simp) |
|
3203 apply(case_tac "bsimp a = AZERO") |
|
3204 apply(simp) |
|
3205 apply(subgoal_tac "bsimp (bder c a) = AZERO") |
|
3206 prefer 2 |
|
3207 apply auto[1] |
|
3208 apply(simp) |
|
3209 apply(case_tac "nonalt (bsimp a)") |
|
3210 apply(subst bsimp_AALTs1) |
|
3211 apply(simp) |
|
3212 using less_add_Suc1 apply fastforce |
|
3213 |
|
3214 apply(subst bsimp_AALTs1) |
|
3215 |
|
3216 using nn11a apply b last |
|
3217 |
|
3218 (* SEQ case *) |
|
3219 apply(clarify) |
|
3220 apply(subst bsimp.simps) |
|
3221 apply(simp del: bsimp.simps) |
|
3222 apply(auto simp del: bsimp.simps)[1] |
|
3223 apply(subgoal_tac "bsimp x42 \<noteq> AZERO") |
|
3224 prefer 2 |
|
3225 using b3 apply force |
|
3226 apply(case_tac "bsimp x43 = AZERO") |
|
3227 apply(simp) |
|
3228 apply (simp add: bsimp_ASEQ0) |
|
3229 apply (metis bder.simps(1) bsimp.simps(3) bsimp_AALTs.simps(1) bsimp_fuse flts.simps(1) flts.simps(2) fuse.simps(1) less_add_Suc2) |
|
3230 apply(case_tac "\<exists>bs. bsimp x42 = AONE bs") |
|
3231 apply(clarify) |
|
3232 apply(simp) |
|
3233 apply(subst bsimp_ASEQ2) |
|
3234 apply(subgoal_tac "bsimp (bder c x42) = AZERO") |
|
3235 prefer 2 |
|
3236 using less_add_Suc1 apply fastforce |
|
3237 apply(simp) |
|
3238 apply(frule_tac x="x43" in spec) |
|
3239 apply(drule mp) |
|
3240 apply(simp) |
|
3241 apply(drule_tac x="c" in spec) |
|
3242 apply(subst bder_fuse) |
|
3243 apply(subst bsimp_fuse[symmetric]) |
|
3244 apply(simp) |
|
3245 apply(subgoal_tac "bmkeps x42 = bs") |
|
3246 prefer 2 |
|
3247 apply (simp add: bmkeps_simp) |
|
3248 apply(simp) |
|
3249 apply(subst bsimp_fuse[symmetric]) |
|
3250 apply(case_tac "nonalt (bsimp (bder c x43))") |
|
3251 apply(subst bsimp_AALTs1) |
|
3252 using nn11a apply blast |
|
3253 using fuse_append apply blast |
|
3254 apply(subgoal_tac "\<exists>bs rs. bsimp (bder c x43) = AALTs bs rs") |
|
3255 prefer 2 |
|
3256 using bbbbs1 apply blast |
|
3257 apply(clarify) |
|
3258 apply(simp) |
|
3259 apply(case_tac rs) |
|
3260 apply(simp) |
|
3261 apply (metis arexp.distinct(7) good.simps(4) good1) |
|
3262 apply(simp) |
|
3263 apply(case_tac list) |
|
3264 apply(simp) |
|
3265 apply (metis arexp.distinct(7) good.simps(5) good1) |
|
3266 apply(simp del: bsimp_AALTs.simps) |
|
3267 apply(simp only: bsimp_AALTs.simps) |
|
3268 apply(simp) |
|
3269 |
|
3270 |
|
3271 |
|
3272 |
|
3273 (* HERE *) |
|
3274 apply(case_tac "x42 = AZERO") |
|
3275 apply(simp) |
|
3276 apply(case_tac "bsimp x43 = AZERO") |
|
3277 apply(simp) |
|
3278 apply (simp add: bsimp_ASEQ0) |
|
3279 apply(subgoal_tac "bsimp (fuse (bmkeps x42) (bder c x43)) = AZERO") |
|
3280 apply(simp) |
|
3281 apply (met is bder.simps(1) bsimp.simps(3) bsimp_fuse fuse.simps(1) less_add_Suc2) |
|
3282 apply(case_tac "\<exists>bs. bsimp x42 = AONE bs") |
|
3283 apply(clarify) |
|
3284 apply(simp) |
|
3285 apply(subst bsimp_ASEQ2) |
|
3286 apply(subgoal_tac "bsimp (bder c x42) = AZERO") |
|
3287 apply(simp) |
|
3288 prefer 2 |
|
3289 using less_add_Suc1 apply fastforce |
|
3290 apply(subgoal_tac "bmkeps x42 = bs") |
|
3291 prefer 2 |
|
3292 apply (simp add: bmkeps_simp) |
|
3293 apply(simp) |
|
3294 apply(case_tac "nonalt (bsimp (bder c x43))") |
|
3295 apply (metis bder_fuse bsimp_AALTs.simps(1) bsimp_AALTs.simps(2) bsimp_fuse flts.simps(1) flts.simps(2) fuse.simps(1) fuse_append k0b less_add_Suc2 nn11a) |
|
3296 apply(subgoal_tac "nonnested (bsimp (bder c x43))") |
|
3297 prefer 2 |
|
3298 using nn1b apply blast |
|
3299 apply(case_tac x43) |
|
3300 apply(simp) |
|
3301 apply(simp) |
|
3302 apply(simp) |
|
3303 prefer 3 |
|
3304 apply(simp) |
|
3305 apply (metis arexp.distinct(25) arexp.distinct(7) arexp.distinct(9) bsimp_ASEQ.simps(1) bsimp_ASEQ.simps(11) bsimp_ASEQ1 nn11a nonalt.elims(3) nonalt.simps(6)) |
|
3306 apply(simp) |
|
3307 apply(auto)[1] |
|
3308 apply(case_tac "(bsimp (bder c x42a)) = AZERO") |
|
3309 apply(simp) |
|
3310 |
|
3311 apply(simp) |
|
3312 |
|
3313 |
|
3314 |
|
3315 apply(subgoal_tac "(\<exists>bs1 rs1. 1 < length rs1 \<and> bsimp (bder c x43) = AALTs bs1 rs1 ) \<or> |
|
3316 (\<exists>bs1 r. bsimp (bder c x43) = fuse bs1 r)") |
|
3317 prefer 2 |
|
3318 apply (metis fuse_empty) |
|
3319 apply(erule disjE) |
|
3320 prefer 2 |
|
3321 apply(clarify) |
|
3322 apply(simp only:) |
|
3323 apply(simp) |
|
3324 apply(simp add: fuse_append) |
|
3325 apply(subst bder_fuse) |
|
3326 apply(subst bsimp_fuse[symmetric]) |
|
3327 apply(subst bder_fuse) |
|
3328 apply(subst bsimp_fuse[symmetric]) |
|
3329 apply(subgoal_tac "bsimp (bder c (bsimp x43)) = bsimp (bder c x43)") |
|
3330 prefer 2 |
|
3331 using less_add_Suc2 apply bl ast |
|
3332 apply(simp only: ) |
|
3333 apply(subst bsimp_fuse[symmetric]) |
|
3334 apply(simp only: ) |
|
3335 |
|
3336 apply(simp only: fuse.simps) |
|
3337 apply(simp) |
|
3338 apply(case_tac rs1) |
|
3339 apply(simp) |
|
3340 apply (me tis arexp.distinct(7) fuse.simps(1) good.simps(4) good1 good_fuse) |
|
3341 apply(simp) |
|
3342 apply(case_tac list) |
|
3343 apply(simp) |
|
3344 apply (me tis arexp.distinct(7) fuse.simps(1) good.simps(5) good1 good_fuse) |
|
3345 apply(simp only: bsimp_AALTs.simps map_cons.simps) |
|
3346 apply(auto)[1] |
|
3347 |
|
3348 |
|
3349 |
|
3350 apply(subst bsimp_fuse[symmetric]) |
|
3351 apply(subgoal_tac "bmkeps x42 = bs") |
|
3352 prefer 2 |
|
3353 apply (simp add: bmkeps_simp) |
|
3354 |
|
3355 |
|
3356 apply(simp) |
|
3357 |
|
3358 using b3 apply force |
|
3359 using bsimp_ASEQ0 test2 apply fo rce |
|
3360 thm good_SEQ test2 |
|
3361 apply (simp add: good_SEQ test2) |
|
3362 apply (simp add: good_SEQ test2) |
|
3363 apply(case_tac "x42 = AZERO") |
|
3364 apply(simp) |
|
3365 apply(case_tac "x43 = AZERO") |
|
3366 apply(simp) |
|
3367 apply (simp add: bsimp_ASEQ0) |
|
3368 apply(case_tac "\<exists>bs. x42 = AONE bs") |
|
3369 apply(clarify) |
|
3370 apply(simp) |
|
3371 apply(subst bsimp_ASEQ1) |
|
3372 apply(simp) |
|
3373 using bsimp_ASEQ0 test2 apply fo rce |
|
3374 apply (simp add: good_SEQ test2) |
|
3375 apply (simp add: good_SEQ test2) |
|
3376 apply (simp add: good_SEQ test2) |
|
3377 (* AALTs case *) |
|
3378 apply(simp) |
|
3379 using test2 by fa st force |
|
3380 |
|
3381 |
|
3382 lemma XXX4ab: |
|
3383 shows "good (bders_simp (bsimp r) s) \<or> bders_simp (bsimp r) s = AZERO" |
|
3384 apply(induct s arbitrary: r rule: rev_induct) |
|
3385 apply(simp) |
|
3386 apply (simp add: good1) |
|
3387 apply(simp add: bders_simp_append) |
|
3388 apply (simp add: good1) |
|
3389 done |
|
3390 |
|
3391 lemma XXX4: |
|
3392 assumes "good a" |
|
3393 shows "bders_simp a s = bsimp (bders a s)" |
|
3394 using assms |
|
3395 apply(induct s arbitrary: a rule: rev_induct) |
|
3396 apply(simp) |
|
3397 apply (simp add: test2) |
|
3398 apply(simp add: bders_append bders_simp_append) |
|
3399 oops |
|
3400 |
|
3401 |
|
3402 lemma MAINMAIN: |
|
3403 "blexer r s = blexer_simp r s" |
|
3404 apply(induct s arbitrary: r) |
|
3405 apply(simp add: blexer_def blexer_simp_def) |
|
3406 apply(simp add: blexer_def blexer_simp_def del: bders.simps bders_simp.simps) |
|
3407 apply(auto simp del: bders.simps bders_simp.simps) |
|
3408 prefer 2 |
|
3409 apply (metis b4 bders.simps(2) bders_simp.simps(2)) |
|
3410 prefer 2 |
|
3411 apply (metis b4 bders.simps(2)) |
|
3412 apply(subst bmkeps_simp) |
|
3413 apply(simp) |
|
3414 apply(case_tac s) |
|
3415 apply(simp only: bders.simps) |
|
3416 apply(subst bders_simp.simps) |
|
3417 apply(simp) |
|
3418 oops |
|
3419 |
|
3420 |
|
3421 lemma |
|
3422 fixes n :: nat |
|
3423 shows "(\<Sum>i \<in> {0..n}. i) = n * (n + 1) div 2" |
|
3424 apply(induct n) |
|
3425 apply(simp) |
|
3426 apply(simp) |
|
3427 done |
|
3428 |
|
3429 |
|
3430 |
|
3431 |
|
3432 |
|
3433 end |